This is the same patch I submitted back in February, but applied to the master branch of Carlos' git repo (http://repo.or.cz/w/wmaker-crm.git). Resubmitting on Carlos' request.
>From fe5dc8e74caa27d10fc5500494f3a46533199af1 Mon Sep 17 00:00:00 2001
From: klaasvakie <[email protected]>
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. This 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.

Known-Bugs: Some applications "forget" their previous sizes when closed in the
maximized state. Problem will be fixed soon.
---
 WPrefs.app/KeyboardShortcuts.c |    4 ++
 src/actions.c                  |   32 +++++++--------
 src/actions.h                  |    6 ++-
 src/defaults.c                 |    4 ++
 src/event.c                    |   26 +++++++++++++
 src/keybind.h                  |   82 ++++++++++++++++++++-------------------
 src/window.h                   |    2 +-
 7 files changed, 96 insertions(+), 60 deletions(-)

diff --git a/WPrefs.app/KeyboardShortcuts.c b/WPrefs.app/KeyboardShortcuts.c
index ed0aff1..919d73b 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 1ecb293..8a38f10 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -361,7 +361,6 @@ void wMaximizeWindow(WWindow * wwin, int directions)
 {
        int new_x, new_y;
        unsigned int new_width, new_height;
-       int changed_h, changed_v, shrink_h, shrink_v;
        WArea usableArea, totalArea;
 
        if (!IS_RESIZABLE(wwin))
@@ -394,12 +393,7 @@ void wMaximizeWindow(WWindow * wwin, int directions)
                wUnshadeWindow(wwin);
        }
        /* Only save directions, not kbd or xinerama hints */
-       directions &= (MAX_HORIZONTAL | MAX_VERTICAL);
-
-       changed_h = ((wwin->flags.maximized ^ directions) & MAX_HORIZONTAL);
-       changed_v = ((wwin->flags.maximized ^ directions) & MAX_VERTICAL);
-       shrink_h = (changed_h && (directions & MAX_HORIZONTAL) == 0);
-       shrink_v = (changed_v && (directions & MAX_VERTICAL) == 0);
+       directions &= (MAX_HORIZONTAL|MAX_VERTICAL|MAX_LEFTHALF|MAX_RIGHTHALF);
 
        if (wwin->flags.maximized) {
                /* if already maximized in some direction, we only update the
@@ -407,7 +401,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,12 +420,19 @@ void wMaximizeWindow(WWindow * wwin, int directions)
                if (HAS_BORDER(wwin))
                        new_width -= FRAME_BORDER_WIDTH * 2;
                new_x = usableArea.x1;
-       } else if (shrink_h) {
+       } 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 {
                new_x = wwin->old_geometry.x;
                new_width = wwin->old_geometry.width;
-       } else {
-               new_x = wwin->frame_x;
-               new_width = wwin->frame->core->width;
        }
 
        if (directions & MAX_VERTICAL) {
@@ -443,12 +444,9 @@ void wMaximizeWindow(WWindow * wwin, int directions)
                        new_y -= wwin->frame->top_width;
                        new_height += wwin->frame->bottom_width - 1;
                }
-       } else if (shrink_v) {
+       } else {
                new_y = wwin->old_geometry.y;
                new_height = wwin->old_geometry.height;
-       } else {
-               new_y = wwin->frame_y;
-               new_height = wwin->frame->core->height;
        }
 
        if (!WFLAGP(wwin, full_maximize)) {
@@ -478,7 +476,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 1674dc8..f420078 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 1dec523..ef1fb71 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 2069ee5..da83149 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 4165b48..d129a69 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 f729fd9..5e69eb2 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;
 
-- 
1.6.0.3

Reply via email to