From 7cb7bfaa448003466315ccc21d08b71f5c77df70 Mon Sep 17 00:00:00 2001 From: Mark Murawski Date: Sun, 19 Nov 2017 19:37:37 +0100 Subject: Support 'vertical' Workspace warping 'Vertical' Workspace warping is a variant of the existing Workspace warping feature: When a user drags a window to the edge of the Screen, the window is warped to the next / previous workspace. 'Vertical' Workspace warping detects a drag towards the upper / lower border of the screen and warps the current workspace about an 'offset'. Example given, lets say the user has 9 workspaces and considers them to form a 3x3 grid: +-+-+-+ |1|2|3| +-+-+-+ |4|5|6| +-+-+-+ |7|8|9| +-+-+-+ An 'offset' of 3 warps from workspaces 2 to workspace 5 (or 8), when a window is dragged to the bottom / top border. New configuration ressources: session.screenN.workspacewarpingvertical: true session.screenN.workspacewarpingverticaloffset: X --- src/Screen.hh | 2 ++ src/ScreenResource.cc | 2 ++ src/ScreenResource.hh | 4 +++- src/Window.cc | 66 +++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/Screen.hh b/src/Screen.hh index 30fbb4a..15eb349 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -95,6 +95,8 @@ public: bool isRootColormapInstalled() const { return root_colormap_installed; } bool isScreenManaged() const { return m_state.managed; } bool isWorkspaceWarping() const { return (m_workspaces_list.size() > 1) && *resource.workspace_warping; } + bool isWorkspaceWarpingVertical() const { return *resource.workspace_warping_vertical; } + int getWorkspaceWarpingVerticalOffset() const { return *resource.workspace_warping_vertical_offset; } bool doAutoRaise() const { return *resource.auto_raise; } bool clickRaises() const { return *resource.click_raises; } bool doOpaqueMove() const { return *resource.opaque_move; } diff --git a/src/ScreenResource.cc b/src/ScreenResource.cc index dbf532b..c188648 100644 --- a/src/ScreenResource.cc +++ b/src/ScreenResource.cc @@ -88,6 +88,8 @@ ScreenResource::ScreenResource(FbTk::ResourceManager& rm, max_disable_move(rm, false, scrname+".maxDisableMove", altscrname+".MaxDisableMove"), max_disable_resize(rm, false, scrname+".maxDisableResize", altscrname+".MaxDisableResize"), workspace_warping(rm, true, scrname+".workspacewarping", altscrname+".WorkspaceWarping"), + workspace_warping_vertical(rm, true, scrname+".workspacewarpingvertical", altscrname+".WorkspaceWarpingVertical"), + workspace_warping_vertical_offset(rm, 1, scrname+".workspacewarpingverticaloffset", altscrname+".WorkspaceWarpingVerticalOffset"), show_window_pos(rm, false, scrname+".showwindowposition", altscrname+".ShowWindowPosition"), auto_raise(rm, true, scrname+".autoRaise", altscrname+".AutoRaise"), click_raises(rm, true, scrname+".clickRaises", altscrname+".ClickRaises"), diff --git a/src/ScreenResource.hh b/src/ScreenResource.hh index 7f1e621..bc782e1 100644 --- a/src/ScreenResource.hh +++ b/src/ScreenResource.hh @@ -37,6 +37,7 @@ struct ScreenResource { max_disable_move, max_disable_resize, workspace_warping, + workspace_warping_vertical, show_window_pos, auto_raise, click_raises; @@ -53,7 +54,8 @@ struct ScreenResource { menu_alpha, menu_delay, tab_width, - tooltip_delay; + tooltip_delay, + workspace_warping_vertical_offset; FbTk::Resource allow_remote_actions; FbTk::Resource clientmenu_use_pixmap; FbTk::Resource tabs_use_pixmap; diff --git a/src/Window.cc b/src/Window.cc index 23c9789..6714d0a 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -2539,6 +2539,10 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) { // Warp to next or previous workspace?, must have moved sideways some int moved_x = me.x_root - m_last_resize_x; + + // Warp to a workspace offset (if treating workspaces like a grid) + int moved_y = me.y_root - m_last_resize_y; + // save last event point m_last_resize_x = me.x_root; m_last_resize_y = me.y_root; @@ -2554,25 +2558,57 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) { } } - if (moved_x && screen().isWorkspaceWarping()) { + + // check for warping + // + // +--monitor-1--+--monitor-2---+ + // |w | w| + // |w | w| + // +-------------+--------------+ + // + // mouse-warping is enabled, the mouse needs to be in the "warp_pad" + // zone. + // + const int warp_pad = screen().getEdgeSnapThreshold(); + const int workspaces = screen().numberOfWorkspaces(); + const bool is_warping = screen().isWorkspaceWarping(); + const bool is_warping_vertical = screen().isWorkspaceWarpingVertical(); + + if ((moved_x || moved_y) && is_warping) { unsigned int cur_id = screen().currentWorkspaceID(); unsigned int new_id = cur_id; - const int warpPad = screen().getEdgeSnapThreshold(); - // 1) if we're inside the border threshold - // 2) if we moved in the right direction - if (me.x_root >= int(screen().width()) - warpPad - 1 && - moved_x > 0) { - //warp right - new_id = (cur_id + 1) % screen().numberOfWorkspaces(); - m_last_resize_x = 0; // move mouse back to x=0 - } else if (me.x_root <= warpPad && - moved_x < 0) { - //warp left - new_id = (cur_id + screen().numberOfWorkspaces() - 1) % screen().numberOfWorkspaces(); - m_last_resize_x = screen().width() - 1; // move mouse to screen width - 1 + + // border threshold + int bt_right = int(screen().width()) - warp_pad - 1; + int bt_left = warp_pad; + int bt_top = int(screen().height()) - warp_pad - 1; + int bt_bottom = warp_pad; + + if (moved_x) { + if (me.x_root >= bt_right && moved_x > 0) { //warp right + new_id = (cur_id + 1) % workspaces; + m_last_resize_x = 0; + } else if (me.x_root <= bt_left && moved_x < 0) { //warp left + new_id = (cur_id + -1) % workspaces; + m_last_resize_x = screen().width() - 1; + } } - if (new_id != cur_id) { + if (moved_y && is_warping_vertical) { + + const int warp_offset = screen().getWorkspaceWarpingVerticalOffset(); + + if (me.y_root >= bt_top && moved_y > 0) { // warp down + new_id = (cur_id + warp_offset) % workspaces; + m_last_resize_y = 0; + } else if (me.y_root <= bt_bottom && moved_y < 0) { // warp up + new_id = (cur_id + workspaces - warp_offset) % workspaces; + m_last_resize_y = screen().height() - 1; + } + } + + // if we are warping + if (new_id != cur_id) { // remove motion events from queue to avoid repeated warps while (XCheckTypedEvent(display, MotionNotify, &e)) { // might as well update the y-coordinate -- cgit v0.11.2