mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Minor fixes to tiling drag implementation
* Make container_add_sibling's `after` argument a boolean. * Use a constant for drop layout border * Make thickness an int * Add button state check * Move comments in seat_end_move_tiling
This commit is contained in:
		
							parent
							
								
									df95c61044
								
							
						
					
					
						commit
						679c7eb08c
					
				
					 4 changed files with 19 additions and 15 deletions
				
			
		| 
						 | 
					@ -283,7 +283,7 @@ void container_insert_child(struct sway_container *parent,
 | 
				
			||||||
 * Side should be 0 to add before, or 1 to add after.
 | 
					 * Side should be 0 to add before, or 1 to add after.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void container_add_sibling(struct sway_container *parent,
 | 
					void container_add_sibling(struct sway_container *parent,
 | 
				
			||||||
		struct sway_container *child, int side);
 | 
							struct sway_container *child, bool after);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void container_detach(struct sway_container *child);
 | 
					void container_detach(struct sway_container *child);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,10 @@
 | 
				
			||||||
#include "sway/tree/workspace.h"
 | 
					#include "sway/tree/workspace.h"
 | 
				
			||||||
#include "wlr-layer-shell-unstable-v1-protocol.h"
 | 
					#include "wlr-layer-shell-unstable-v1-protocol.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// When doing a tiling drag, this is the thickness of the dropzone
 | 
				
			||||||
 | 
					// when dragging to the edge of a layout container.
 | 
				
			||||||
 | 
					#define DROP_LAYOUT_BORDER 30
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint32_t get_current_time_msec() {
 | 
					static uint32_t get_current_time_msec() {
 | 
				
			||||||
	struct timespec now;
 | 
						struct timespec now;
 | 
				
			||||||
	clock_gettime(CLOCK_MONOTONIC, &now);
 | 
						clock_gettime(CLOCK_MONOTONIC, &now);
 | 
				
			||||||
| 
						 | 
					@ -229,7 +233,7 @@ static void handle_move_floating_motion(struct sway_seat *seat,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void resize_box(struct wlr_box *box, enum wlr_edges edge,
 | 
					static void resize_box(struct wlr_box *box, enum wlr_edges edge,
 | 
				
			||||||
		size_t thickness) {
 | 
							int thickness) {
 | 
				
			||||||
	switch (edge) {
 | 
						switch (edge) {
 | 
				
			||||||
	case WLR_EDGE_TOP:
 | 
						case WLR_EDGE_TOP:
 | 
				
			||||||
		box->height = thickness;
 | 
							box->height = thickness;
 | 
				
			||||||
| 
						 | 
					@ -297,15 +301,17 @@ static void handle_move_tiling_motion(struct sway_seat *seat,
 | 
				
			||||||
		con->parent ? container_get_box(con->parent, &parent) :
 | 
							con->parent ? container_get_box(con->parent, &parent) :
 | 
				
			||||||
			workspace_get_box(con->workspace, &parent);
 | 
								workspace_get_box(con->workspace, &parent);
 | 
				
			||||||
		if (layout == L_HORIZ || layout == L_TABBED) {
 | 
							if (layout == L_HORIZ || layout == L_TABBED) {
 | 
				
			||||||
			if (cursor->cursor->y < parent.y + 30) {
 | 
								if (cursor->cursor->y < parent.y + DROP_LAYOUT_BORDER) {
 | 
				
			||||||
				edge = WLR_EDGE_TOP;
 | 
									edge = WLR_EDGE_TOP;
 | 
				
			||||||
			} else if (cursor->cursor->y > parent.y + parent.height - 30) {
 | 
								} else if (cursor->cursor->y > parent.y + parent.height
 | 
				
			||||||
 | 
										- DROP_LAYOUT_BORDER) {
 | 
				
			||||||
				edge = WLR_EDGE_BOTTOM;
 | 
									edge = WLR_EDGE_BOTTOM;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else if (layout == L_VERT || layout == L_STACKED) {
 | 
							} else if (layout == L_VERT || layout == L_STACKED) {
 | 
				
			||||||
			if (cursor->cursor->x < parent.x + 30) {
 | 
								if (cursor->cursor->x < parent.x + DROP_LAYOUT_BORDER) {
 | 
				
			||||||
				edge = WLR_EDGE_LEFT;
 | 
									edge = WLR_EDGE_LEFT;
 | 
				
			||||||
			} else if (cursor->cursor->x > parent.x + parent.width - 30) {
 | 
								} else if (cursor->cursor->x > parent.x + parent.width
 | 
				
			||||||
 | 
										- DROP_LAYOUT_BORDER) {
 | 
				
			||||||
				edge = WLR_EDGE_RIGHT;
 | 
									edge = WLR_EDGE_RIGHT;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -313,7 +319,7 @@ static void handle_move_tiling_motion(struct sway_seat *seat,
 | 
				
			||||||
			seat->op_target_node = node_get_parent(&con->node);
 | 
								seat->op_target_node = node_get_parent(&con->node);
 | 
				
			||||||
			seat->op_target_edge = edge;
 | 
								seat->op_target_edge = edge;
 | 
				
			||||||
			node_get_box(seat->op_target_node, &seat->op_drop_box);
 | 
								node_get_box(seat->op_target_node, &seat->op_drop_box);
 | 
				
			||||||
			resize_box(&seat->op_drop_box, edge, 30);
 | 
								resize_box(&seat->op_drop_box, edge, DROP_LAYOUT_BORDER);
 | 
				
			||||||
			desktop_damage_box(&seat->op_drop_box);
 | 
								desktop_damage_box(&seat->op_drop_box);
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -890,8 +896,8 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Handle moving a tiling container
 | 
						// Handle moving a tiling container
 | 
				
			||||||
	if (config->tiling_drag && mod_pressed && !is_floating_or_child &&
 | 
						if (config->tiling_drag && mod_pressed && state == WLR_BUTTON_PRESSED &&
 | 
				
			||||||
			!cont->is_fullscreen) {
 | 
								!is_floating_or_child && !cont->is_fullscreen) {
 | 
				
			||||||
		seat_pointer_notify_button(seat, time_msec, button, state);
 | 
							seat_pointer_notify_button(seat, time_msec, button, state);
 | 
				
			||||||
		seat_begin_move_tiling(seat, cont, button);
 | 
							seat_begin_move_tiling(seat, cont, button);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1050,9 +1050,8 @@ static void seat_end_move_tiling(struct sway_seat *seat) {
 | 
				
			||||||
	// Moving container into empty workspace
 | 
						// Moving container into empty workspace
 | 
				
			||||||
	if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) {
 | 
						if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) {
 | 
				
			||||||
		workspace_add_tiling(new_ws, con);
 | 
							workspace_add_tiling(new_ws, con);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Moving container before/after another
 | 
					 | 
				
			||||||
	} else if (target_node->type == N_CONTAINER) {
 | 
						} else if (target_node->type == N_CONTAINER) {
 | 
				
			||||||
 | 
							// Moving container before/after another
 | 
				
			||||||
		struct sway_container *target = target_node->sway_container;
 | 
							struct sway_container *target = target_node->sway_container;
 | 
				
			||||||
		enum sway_container_layout layout = container_parent_layout(target);
 | 
							enum sway_container_layout layout = container_parent_layout(target);
 | 
				
			||||||
		if (edge && !is_parallel(layout, edge)) {
 | 
							if (edge && !is_parallel(layout, edge)) {
 | 
				
			||||||
| 
						 | 
					@ -1061,9 +1060,8 @@ static void seat_end_move_tiling(struct sway_seat *seat) {
 | 
				
			||||||
			container_split(target, new_layout);
 | 
								container_split(target, new_layout);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		container_add_sibling(target, con, after);
 | 
							container_add_sibling(target, con, after);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Target is a workspace which requires splitting
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 | 
							// Target is a workspace which requires splitting
 | 
				
			||||||
		enum sway_container_layout new_layout = edge == WLR_EDGE_TOP ||
 | 
							enum sway_container_layout new_layout = edge == WLR_EDGE_TOP ||
 | 
				
			||||||
			edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ;
 | 
								edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ;
 | 
				
			||||||
		workspace_split(new_ws, new_layout);
 | 
							workspace_split(new_ws, new_layout);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1093,13 +1093,13 @@ void container_insert_child(struct sway_container *parent,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void container_add_sibling(struct sway_container *fixed,
 | 
					void container_add_sibling(struct sway_container *fixed,
 | 
				
			||||||
		struct sway_container *active, int side) {
 | 
							struct sway_container *active, bool after) {
 | 
				
			||||||
	if (active->workspace) {
 | 
						if (active->workspace) {
 | 
				
			||||||
		container_detach(active);
 | 
							container_detach(active);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	list_t *siblings = container_get_siblings(fixed);
 | 
						list_t *siblings = container_get_siblings(fixed);
 | 
				
			||||||
	int index = list_find(siblings, fixed);
 | 
						int index = list_find(siblings, fixed);
 | 
				
			||||||
	list_insert(siblings, index + side, active);
 | 
						list_insert(siblings, index + after, active);
 | 
				
			||||||
	active->parent = fixed->parent;
 | 
						active->parent = fixed->parent;
 | 
				
			||||||
	active->workspace = fixed->workspace;
 | 
						active->workspace = fixed->workspace;
 | 
				
			||||||
	container_for_each_child(active, set_workspace, NULL);
 | 
						container_for_each_child(active, set_workspace, NULL);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue