diff options
| author | aura <boneyaard@gmail.com> | 2024-10-25 12:39:54 +0200 |
|---|---|---|
| committer | aura <boneyaard@gmail.com> | 2024-10-25 12:39:54 +0200 |
| commit | 562fa9c12377c5ef7bbe4c764babd0bc02b5b930 (patch) | |
| tree | 826f4090f6866f2644e3c9d06838a8f2cde4a060 | |
| parent | 9e8813e111cbe6c1088f6abbc771a29470f05fc2 (diff) | |
window snapping
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | openbox/client.h | 5 | ||||
| -rw-r--r-- | openbox/moveresize.c | 67 |
3 files changed, 72 insertions, 2 deletions
@@ -109,3 +109,5 @@ obt/tests/ddtest obt/tests/linktest obt/tests/watchtest obt/obt_unittests +openbox/.cache/clangd/index +openbox/compile_commands.json diff --git a/openbox/client.h b/openbox/client.h index 11a01400..3b33a544 100644 --- a/openbox/client.h +++ b/openbox/client.h @@ -81,7 +81,10 @@ struct _ObClient /*! The window's decorations. NULL while the window is being managed! */ struct _ObFrame *frame; - + /*! The window is snapped to fill the left side of the screen */ + gboolean snapped_left; + /*! The window is snapped to fill the right side of the screen */ + gboolean snapped_right; /*! The number of unmap events to ignore on the window */ gint ignore_unmaps; diff --git a/openbox/moveresize.c b/openbox/moveresize.c index d12a64de..586484ab 100644 --- a/openbox/moveresize.c +++ b/openbox/moveresize.c @@ -372,7 +372,7 @@ void moveresize_end(gboolean cancel) static void do_move(gboolean keyboard, gint keydist) { - gint resist; + gint resist, x, y; if (keyboard) resist = keydist - 1; /* resist for one key press */ else resist = config_resist_win; @@ -380,6 +380,71 @@ static void do_move(gboolean keyboard, gint keydist) if (!keyboard) resist = config_resist_edge; resist_move_monitors(moveresize_client, resist, &cur_x, &cur_y); + screen_pointer_pos(&x, &y); + + const Rect* a = screen_physical_area_active(); + gint h = RECT_BOTTOM(*a) - RECT_TOP(*a); + gint w = RECT_RIGHT(*a) - RECT_LEFT(*a); + + if (moveresize_client->max_horz && moveresize_client->max_vert && y > 0) + { + client_maximize(moveresize_client, FALSE, 0); + start_cx = 0; + start_cy = 0; + start_x = ((x - cur_x) * moveresize_client->area.width) / cur_w; + start_y = y; + cur_x = x - start_x; + cur_y = y - start_y; + cur_w = moveresize_client->area.width; + cur_h = moveresize_client->area.height; + } + else if (y == 0 && !moveresize_client->snapped_left && !moveresize_client->snapped_right) { + client_maximize(moveresize_client, TRUE, 0); + } + else if (x == 0 && !moveresize_client->snapped_left && !moveresize_client->max_horz && !moveresize_client->max_vert) { + moveresize_client->pre_max_area.x = cur_x; + moveresize_client->pre_max_area.y = cur_y; + moveresize_client->pre_max_area.width = cur_w; + moveresize_client->pre_max_area.height = cur_h; + client_maximize(moveresize_client, TRUE, 2); + moveresize_client->snapped_left = TRUE; + } + else if (x > 0 && moveresize_client->snapped_left && !moveresize_client->max_horz) { + cur_x = moveresize_client->pre_max_area.x; + cur_y = moveresize_client->pre_max_area.y; + cur_w = moveresize_client->pre_max_area.width; + cur_h = moveresize_client->pre_max_area.height; + client_maximize(moveresize_client, FALSE, 2); + moveresize_client->snapped_left = FALSE; + } + else if (x == w && !moveresize_client->snapped_right && !moveresize_client->max_horz && !moveresize_client->max_vert) { + moveresize_client->pre_max_area.x = cur_x; + moveresize_client->pre_max_area.y = cur_y; + moveresize_client->pre_max_area.width = cur_w; + moveresize_client->pre_max_area.height = cur_h; + client_maximize(moveresize_client, TRUE, 2); + moveresize_client->snapped_right = TRUE; + } + else if (x < w && moveresize_client->snapped_right && !moveresize_client->max_horz) { + cur_x = moveresize_client->pre_max_area.x; + cur_y = moveresize_client->pre_max_area.y; + cur_w = moveresize_client->pre_max_area.width; + cur_h = moveresize_client->pre_max_area.height; + client_maximize(moveresize_client, FALSE, 2); + moveresize_client->snapped_right = FALSE; + } + + if (moveresize_client->snapped_left) { + cur_x = 0; + cur_y = 0; + cur_w = (w / 2) - 1; + } + else if (moveresize_client->snapped_right) { + cur_x = w / 2; + cur_y = 0; + cur_w = w / 2; + } + client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h, TRUE, FALSE, FALSE); if (config_resize_popup_show == 2) /* == "Always" */ |
