From 6924454836b3a9432def2749f093ea060ac82e97 Mon Sep 17 00:00:00 2001 From: Johann Haarhoff Date: Fri, 28 Aug 2009 21:31:26 +0200 Subject: [PATCH] Left Half / Right Half Maximize This adds Left Half / Right Half Maximize capability to WindowMaker. It allows you to maximize a window to only the left or right half of your screen. It is useful on widescreen displays where one might to bring up two different windows side-by-side. --- WPrefs.app/KeyboardShortcuts.c | 4 +++ src/actions.c | 16 +++++++-- src/actions.h | 6 ++-- src/defaults.c | 4 +++ src/event.c | 26 ++++++++++++++ src/keybind.h | 82 +++++++++++++++++++++--------------------- src/window.h | 2 +- 7 files changed, 94 insertions(+), 46 deletions(-) diff --git a/WPrefs.app/KeyboardShortcuts.c b/WPrefs.app/KeyboardShortcuts.c index ed0aff1c..919d73b5 100644 --- a/WPrefs.app/KeyboardShortcuts.c +++ b/WPrefs.app/KeyboardShortcuts.c @@ -72,6 +72,8 @@ static char *keyOptions[] = { "MaximizeKey", "VMaximizeKey", "HMaximizeKey", + "LHMaximizeKey", + "RHMaximizeKey", "RaiseKey", "LowerKey", "RaiseLowerKey", @@ -473,6 +475,8 @@ static void createPanel(Panel * p) WMAddListItem(panel->actLs, _("Maximize active window")); WMAddListItem(panel->actLs, _("Maximize active window vertically")); WMAddListItem(panel->actLs, _("Maximize active window horizontally")); + WMAddListItem(panel->actLs, _("Maximize active window left half")); + WMAddListItem(panel->actLs, _("Maximize active window right half")); WMAddListItem(panel->actLs, _("Raise active window")); WMAddListItem(panel->actLs, _("Lower active window")); WMAddListItem(panel->actLs, _("Raise/Lower window under mouse pointer")); diff --git a/src/actions.c b/src/actions.c index 1ecb2939..fc3d0cd9 100644 --- a/src/actions.c +++ b/src/actions.c @@ -394,7 +394,7 @@ void wMaximizeWindow(WWindow * wwin, int directions) wUnshadeWindow(wwin); } /* Only save directions, not kbd or xinerama hints */ - directions &= (MAX_HORIZONTAL | MAX_VERTICAL); + directions &= (MAX_HORIZONTAL|MAX_VERTICAL|MAX_LEFTHALF|MAX_RIGHTHALF); changed_h = ((wwin->flags.maximized ^ directions) & MAX_HORIZONTAL); changed_v = ((wwin->flags.maximized ^ directions) & MAX_VERTICAL); @@ -407,7 +407,7 @@ void wMaximizeWindow(WWindow * wwin, int directions) * allow succesive maximizations in different directions without * the need to first do an un-maximize (to avoid flicker). */ - if (!(wwin->flags.maximized & MAX_HORIZONTAL)) { + if (!(wwin->flags.maximized & (MAX_HORIZONTAL|MAX_LEFTHALF|MAX_RIGHTHALF))) { wwin->old_geometry.x = wwin->frame_x; } if (!(wwin->flags.maximized & MAX_VERTICAL)) { @@ -426,6 +426,16 @@ void wMaximizeWindow(WWindow * wwin, int directions) if (HAS_BORDER(wwin)) new_width -= FRAME_BORDER_WIDTH * 2; new_x = usableArea.x1; + } else if (directions & MAX_LEFTHALF) { + new_width = (usableArea.x2 - usableArea.x1)/2; + if (HAS_BORDER(wwin)) + new_width -= FRAME_BORDER_WIDTH * 2; + new_x = usableArea.x1; + } else if (directions & MAX_RIGHTHALF) { + new_width = (usableArea.x2 - usableArea.x1)/2; + if (HAS_BORDER(wwin)) + new_width -= FRAME_BORDER_WIDTH * 2; + new_x = usableArea.x1+((usableArea.x2 - usableArea.x1)/2); } else if (shrink_h) { new_x = wwin->old_geometry.x; new_width = wwin->old_geometry.width; @@ -478,7 +488,7 @@ void wUnmaximizeWindow(WWindow * wwin) wwin->flags.skip_next_animation = 1; wUnshadeWindow(wwin); } - x = ((wwin->flags.maximized & MAX_HORIZONTAL) && wwin->old_geometry.x) ? + x = ((wwin->flags.maximized & (MAX_HORIZONTAL|MAX_LEFTHALF|MAX_RIGHTHALF)) && wwin->old_geometry.x) ? wwin->old_geometry.x : wwin->frame_x; y = ((wwin->flags.maximized & MAX_VERTICAL) && wwin->old_geometry.y) ? wwin->old_geometry.y : wwin->frame_y; diff --git a/src/actions.h b/src/actions.h index 1674dc83..f420078b 100644 --- a/src/actions.h +++ b/src/actions.h @@ -26,8 +26,10 @@ #define MAX_HORIZONTAL 1 #define MAX_VERTICAL 2 -#define MAX_IGNORE_XINERAMA 4 -#define MAX_KEYBOARD 8 +#define MAX_LEFTHALF 4 +#define MAX_RIGHTHALF 8 +#define MAX_IGNORE_XINERAMA 16 +#define MAX_KEYBOARD 32 void wSetFocusTo(WScreen *scr, WWindow *wwin); diff --git a/src/defaults.c b/src/defaults.c index 1dec523d..ef1fb715 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -579,6 +579,10 @@ WDefaultEntry optionList[] = { NULL, getKeybind, setKeyGrab}, {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE, NULL, getKeybind, setKeyGrab}, + {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE, + NULL, getKeybind, setKeyGrab}, + {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE, + NULL, getKeybind, setKeyGrab}, {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE, NULL, getKeybind, setKeyGrab}, {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER, diff --git a/src/event.c b/src/event.c index 2069ee50..da831491 100644 --- a/src/event.c +++ b/src/event.c @@ -1471,6 +1471,32 @@ static void handleKeyPress(XEvent * event) } } break; + case WKBD_LHMAXIMIZE: + if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) { + int newdir = (MAX_VERTICAL|MAX_LEFTHALF); + + CloseWindowMenu(scr); + + if (wwin->flags.maximized == newdir) { + wUnmaximizeWindow(wwin); + } else { + wMaximizeWindow(wwin, newdir|MAX_KEYBOARD); + } + } + break; + case WKBD_RHMAXIMIZE: + if (ISMAPPED(wwin) && ISFOCUSED(wwin) && IS_RESIZABLE(wwin)) { + int newdir = (MAX_VERTICAL|MAX_RIGHTHALF); + + CloseWindowMenu(scr); + + if (wwin->flags.maximized == newdir) { + wUnmaximizeWindow(wwin); + } else { + wMaximizeWindow(wwin, newdir|MAX_KEYBOARD); + } + } + break; case WKBD_RAISE: if (ISMAPPED(wwin) && ISFOCUSED(wwin)) { CloseWindowMenu(scr); diff --git a/src/keybind.h b/src/keybind.h index 4165b484..d129a69f 100644 --- a/src/keybind.h +++ b/src/keybind.h @@ -32,57 +32,59 @@ #define WKBD_MAXIMIZE 6 #define WKBD_VMAXIMIZE 7 #define WKBD_HMAXIMIZE 8 -#define WKBD_SELECT 9 +#define WKBD_LHMAXIMIZE 9 +#define WKBD_RHMAXIMIZE 10 +#define WKBD_SELECT 11 /* Clip */ -#define WKBD_CLIPLOWER 10 -#define WKBD_CLIPRAISE 11 -#define WKBD_CLIPRAISELOWER 12 +#define WKBD_CLIPLOWER 12 +#define WKBD_CLIPRAISE 13 +#define WKBD_CLIPRAISELOWER 14 /* window */ -#define WKBD_RAISE 13 -#define WKBD_LOWER 14 -#define WKBD_RAISELOWER 15 -#define WKBD_MOVERESIZE 16 -#define WKBD_SHADE 17 +#define WKBD_RAISE 15 +#define WKBD_LOWER 16 +#define WKBD_RAISELOWER 17 +#define WKBD_MOVERESIZE 18 +#define WKBD_SHADE 19 /* window, menu */ -#define WKBD_CLOSE 18 +#define WKBD_CLOSE 20 /* window */ -#define WKBD_FOCUSNEXT 19 -#define WKBD_FOCUSPREV 20 +#define WKBD_FOCUSNEXT 21 +#define WKBD_FOCUSPREV 22 -#define WKBD_WORKSPACE1 21 -#define WKBD_WORKSPACE2 22 -#define WKBD_WORKSPACE3 23 -#define WKBD_WORKSPACE4 24 -#define WKBD_WORKSPACE5 25 -#define WKBD_WORKSPACE6 26 -#define WKBD_WORKSPACE7 27 -#define WKBD_WORKSPACE8 28 -#define WKBD_WORKSPACE9 29 -#define WKBD_WORKSPACE10 30 -#define WKBD_NEXTWORKSPACE 31 -#define WKBD_PREVWORKSPACE 32 -#define WKBD_NEXTWSLAYER 33 -#define WKBD_PREVWSLAYER 34 +#define WKBD_WORKSPACE1 23 +#define WKBD_WORKSPACE2 24 +#define WKBD_WORKSPACE3 25 +#define WKBD_WORKSPACE4 26 +#define WKBD_WORKSPACE5 27 +#define WKBD_WORKSPACE6 28 +#define WKBD_WORKSPACE7 29 +#define WKBD_WORKSPACE8 30 +#define WKBD_WORKSPACE9 31 +#define WKBD_WORKSPACE10 32 +#define WKBD_NEXTWORKSPACE 33 +#define WKBD_PREVWORKSPACE 34 +#define WKBD_NEXTWSLAYER 35 +#define WKBD_PREVWSLAYER 36 /* window shortcuts */ -#define WKBD_WINDOW1 35 -#define WKBD_WINDOW2 36 -#define WKBD_WINDOW3 37 -#define WKBD_WINDOW4 38 -#define WKBD_WINDOW5 39 -#define WKBD_WINDOW6 40 -#define WKBD_WINDOW7 41 -#define WKBD_WINDOW8 42 -#define WKBD_WINDOW9 43 -#define WKBD_WINDOW10 44 +#define WKBD_WINDOW1 37 +#define WKBD_WINDOW2 38 +#define WKBD_WINDOW3 39 +#define WKBD_WINDOW4 40 +#define WKBD_WINDOW5 41 +#define WKBD_WINDOW6 42 +#define WKBD_WINDOW7 43 +#define WKBD_WINDOW8 44 +#define WKBD_WINDOW9 45 +#define WKBD_WINDOW10 46 -#define WKBD_SWITCH_SCREEN 45 +#define WKBD_SWITCH_SCREEN 47 #ifdef KEEP_XKB_LOCK_STATUS -# define WKBD_TOGGLE 46 -# define WKBD_TMP 47 +# define WKBD_TOGGLE 48 +# define WKBD_TMP 49 #else -# define WKBD_TMP 46 +# define WKBD_TMP 48 #endif #ifdef VIRTUAL_DESKTOP diff --git a/src/window.h b/src/window.h index f729fd9c..5e69eb2e 100644 --- a/src/window.h +++ b/src/window.h @@ -258,7 +258,7 @@ typedef struct WWindow { unsigned int miniaturized:1; unsigned int hidden:1; unsigned int shaded:1; - unsigned int maximized:2; + unsigned int maximized:4; unsigned int fullscreen:1; unsigned int omnipresent:1; -- 2.11.4.GIT