mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge pull request #111 from Luminarys/master
Added in proper resize locking
This commit is contained in:
		
						commit
						1c38b7a8d2
					
				
					 3 changed files with 69 additions and 17 deletions
				
			
		| 
						 | 
					@ -37,13 +37,19 @@ extern struct pointer_state {
 | 
				
			||||||
	struct pointer_tiling {
 | 
						struct pointer_tiling {
 | 
				
			||||||
		bool resize;
 | 
							bool resize;
 | 
				
			||||||
		swayc_t *init_view;
 | 
							swayc_t *init_view;
 | 
				
			||||||
		struct wlc_origin *lock_pos;
 | 
							struct wlc_origin lock_pos;
 | 
				
			||||||
	} tiling;
 | 
						} tiling;
 | 
				
			||||||
	struct pointer_lock {
 | 
						struct pointer_lock {
 | 
				
			||||||
 | 
							// Lock movement for certain edges
 | 
				
			||||||
		bool left;
 | 
							bool left;
 | 
				
			||||||
		bool right;
 | 
							bool right;
 | 
				
			||||||
		bool top;
 | 
							bool top;
 | 
				
			||||||
		bool bottom;
 | 
							bool bottom;
 | 
				
			||||||
 | 
							// Lock movement in certain directions
 | 
				
			||||||
 | 
							bool temp_left;
 | 
				
			||||||
 | 
							bool temp_right;
 | 
				
			||||||
 | 
							bool temp_up;
 | 
				
			||||||
 | 
							bool temp_down;
 | 
				
			||||||
	} lock;
 | 
						} lock;
 | 
				
			||||||
} pointer_state;
 | 
					} pointer_state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -421,16 +421,42 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if (pointer_state.tiling.resize && view) {
 | 
						} else if (pointer_state.tiling.resize && view) {
 | 
				
			||||||
		if (view != pointer_state.tiling.init_view) {
 | 
							bool valid = true;
 | 
				
			||||||
			// Quit out of the resize
 | 
							double dx = mouse_origin.x - prev_pos.x;
 | 
				
			||||||
			//pointer_state.tiling.init_view = NULL;
 | 
							double dy = mouse_origin.y - prev_pos.y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ((dx < 0 || mouse_origin.x < pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_left) {
 | 
				
			||||||
 | 
								changed_tiling = true;
 | 
				
			||||||
 | 
								valid = false;
 | 
				
			||||||
 | 
							} else if (dx > 0 && pointer_state.lock.temp_left) {
 | 
				
			||||||
 | 
								pointer_state.lock.temp_left = false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!view->is_floating && view == pointer_state.tiling.init_view) {
 | 
					
 | 
				
			||||||
 | 
							if ((dx > 0 || mouse_origin.x > pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_right) {
 | 
				
			||||||
 | 
								changed_tiling = true;
 | 
				
			||||||
 | 
								valid = false;
 | 
				
			||||||
 | 
							} else if (dx < 0 && pointer_state.lock.temp_right) {
 | 
				
			||||||
 | 
								pointer_state.lock.temp_right = false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ((dy < 0 || mouse_origin.y < pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_up) {
 | 
				
			||||||
 | 
								changed_tiling = true;
 | 
				
			||||||
 | 
								valid = false;
 | 
				
			||||||
 | 
							} else if (dy > 0 && pointer_state.lock.temp_up) {
 | 
				
			||||||
 | 
								pointer_state.lock.temp_up = false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ((dy > 0 || mouse_origin.y > pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_down) {
 | 
				
			||||||
 | 
								changed_tiling = true;
 | 
				
			||||||
 | 
								valid = false;
 | 
				
			||||||
 | 
							} else if (dy < 0 && pointer_state.lock.temp_down) {
 | 
				
			||||||
 | 
								pointer_state.lock.temp_down = false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!view->is_floating && valid) {
 | 
				
			||||||
			// Handle layout resizes -- Find the biggest parent container then apply resizes to that
 | 
								// Handle layout resizes -- Find the biggest parent container then apply resizes to that
 | 
				
			||||||
			// and its bordering siblings
 | 
								// and its bordering siblings
 | 
				
			||||||
			swayc_t *parent = view;
 | 
								swayc_t *parent = view;
 | 
				
			||||||
			double dx = mouse_origin.x - prev_pos.x;
 | 
					 | 
				
			||||||
			double dy = mouse_origin.y - prev_pos.y;
 | 
					 | 
				
			||||||
			if (!pointer_state.lock.bottom) {
 | 
								if (!pointer_state.lock.bottom) {
 | 
				
			||||||
				while (parent->type != C_WORKSPACE) {
 | 
									while (parent->type != C_WORKSPACE) {
 | 
				
			||||||
					// TODO: Absolute value is a bad hack here to compensate for rounding. Find a better
 | 
										// TODO: Absolute value is a bad hack here to compensate for rounding. Find a better
 | 
				
			||||||
| 
						 | 
					@ -442,14 +468,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
 | 
									if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
 | 
				
			||||||
					sway_log(L_DEBUG, "Top is locked, found biggest valid parent at: %p", parent);
 | 
					 | 
				
			||||||
					swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN);
 | 
										swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN);
 | 
				
			||||||
					if (sibling) {
 | 
										if (sibling) {
 | 
				
			||||||
						sway_log(L_DEBUG, "Found sibling at: %p", sibling);
 | 
					 | 
				
			||||||
						if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) {
 | 
											if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) {
 | 
				
			||||||
							recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM);
 | 
												recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM);
 | 
				
			||||||
							recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP);
 | 
												recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP);
 | 
				
			||||||
							changed_tiling = true;
 | 
												changed_tiling = true;
 | 
				
			||||||
 | 
											} else {
 | 
				
			||||||
 | 
												pointer_state.tiling.lock_pos.y = mouse_origin.y;
 | 
				
			||||||
 | 
												if (parent->height < min_sane_h) {
 | 
				
			||||||
 | 
													pointer_state.lock.temp_up = true;
 | 
				
			||||||
 | 
												} else if (sibling->height < min_sane_h) {
 | 
				
			||||||
 | 
													pointer_state.lock.temp_down = true;
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -462,14 +493,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
 | 
									if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
 | 
				
			||||||
					sway_log(L_DEBUG, "Bot is locked, found biggest valid parent at: %p", parent);
 | 
					 | 
				
			||||||
					swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP);
 | 
										swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP);
 | 
				
			||||||
					if (sibling) {
 | 
										if (sibling) {
 | 
				
			||||||
						sway_log(L_DEBUG, "Found sibling at: %p", sibling);
 | 
					 | 
				
			||||||
						if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) {
 | 
											if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) {
 | 
				
			||||||
							recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP);
 | 
												recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP);
 | 
				
			||||||
							recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM);
 | 
												recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM);
 | 
				
			||||||
							changed_tiling = true;
 | 
												changed_tiling = true;
 | 
				
			||||||
 | 
											} else {
 | 
				
			||||||
 | 
												pointer_state.tiling.lock_pos.y = mouse_origin.y;
 | 
				
			||||||
 | 
												if (parent->height < min_sane_h) {
 | 
				
			||||||
 | 
													pointer_state.lock.temp_down = true;
 | 
				
			||||||
 | 
												} else if (sibling->height < min_sane_h) {
 | 
				
			||||||
 | 
													pointer_state.lock.temp_up = true;
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -486,14 +522,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
 | 
									if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
 | 
				
			||||||
					sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent);
 | 
					 | 
				
			||||||
					swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT);
 | 
										swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT);
 | 
				
			||||||
					if (sibling) {
 | 
										if (sibling) {
 | 
				
			||||||
						sway_log(L_DEBUG, "Found sibling at: %p", sibling);
 | 
					 | 
				
			||||||
						if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) {
 | 
											if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) {
 | 
				
			||||||
							recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT);
 | 
												recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT);
 | 
				
			||||||
							recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT);
 | 
												recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT);
 | 
				
			||||||
							changed_tiling = true;
 | 
												changed_tiling = true;
 | 
				
			||||||
 | 
											} else {
 | 
				
			||||||
 | 
												pointer_state.tiling.lock_pos.x = mouse_origin.x;
 | 
				
			||||||
 | 
												if (parent->width < min_sane_w) {
 | 
				
			||||||
 | 
													pointer_state.lock.temp_left = true;
 | 
				
			||||||
 | 
												} else if (sibling->width < min_sane_w) {
 | 
				
			||||||
 | 
													pointer_state.lock.temp_right = true;
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -506,14 +547,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
 | 
									if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
 | 
				
			||||||
					sway_log(L_DEBUG, "Right is locked, found biggest valid parent at: %p", parent);
 | 
					 | 
				
			||||||
					swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT);
 | 
										swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT);
 | 
				
			||||||
					if (sibling) {
 | 
										if (sibling) {
 | 
				
			||||||
						sway_log(L_DEBUG, "Found sibling at: %p", sibling);
 | 
					 | 
				
			||||||
						if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) {
 | 
											if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) {
 | 
				
			||||||
							recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT);
 | 
												recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT);
 | 
				
			||||||
							recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT);
 | 
												recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT);
 | 
				
			||||||
							changed_tiling = true;
 | 
												changed_tiling = true;
 | 
				
			||||||
 | 
											} else {
 | 
				
			||||||
 | 
												pointer_state.tiling.lock_pos.x = mouse_origin.x;
 | 
				
			||||||
 | 
												if (parent->width < min_sane_w) {
 | 
				
			||||||
 | 
													pointer_state.lock.temp_right = true;
 | 
				
			||||||
 | 
												} else if (sibling->width < min_sane_w) {
 | 
				
			||||||
 | 
													pointer_state.lock.temp_left = true;
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -611,7 +657,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
 | 
				
			||||||
			pointer_state.floating.resize = false;
 | 
								pointer_state.floating.resize = false;
 | 
				
			||||||
			pointer_state.tiling.resize = false;
 | 
								pointer_state.tiling.resize = false;
 | 
				
			||||||
			pointer_state.tiling.init_view = NULL;
 | 
								pointer_state.tiling.init_view = NULL;
 | 
				
			||||||
			pointer_state.lock = (struct pointer_lock){false ,false ,false ,false};
 | 
								pointer_state.lock = (struct pointer_lock){false ,false ,false ,false, false, false, false, false};
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ void release_key(keycode key) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, 0}, {0, 0, 0, 0}};
 | 
					struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, {0, 0}}, {0, 0, 0, 0, 0, 0, 0, 0}};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct wlc_geometry saved_floating;
 | 
					static struct wlc_geometry saved_floating;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue