From 0b7a277b22c4b30e16b49c91fff52e0da5a16c74 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Wed, 27 Nov 2019 13:51:36 +0100 Subject: [PATCH 1/8] Add handlebar patch --- patches/sowm-handlebar.patch | 173 +++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 patches/sowm-handlebar.patch diff --git a/patches/sowm-handlebar.patch b/patches/sowm-handlebar.patch new file mode 100644 index 0000000..269f881 --- /dev/null +++ b/patches/sowm-handlebar.patch @@ -0,0 +1,173 @@ +diff --git a/config.def.h b/config.def.h +index aaaf38d..bcf49d8 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -3,6 +3,9 @@ + + #define MOD Mod4Mask + ++const int handle_bar_thickness = 20; ++const char *handlebar_colour = "#ffffff"; ++ + const char* menu[] = {"dmenu_run", 0}; + const char* term[] = {"st", 0}; + const char* scrot[] = {"scr", 0}; +diff --git a/sowm.c b/sowm.c +index bc14c4e..abe94a4 100644 +--- a/sowm.c ++++ b/sowm.c +@@ -54,6 +54,9 @@ static unsigned int ww, wh; + static Display *d; + static XButtonEvent mouse; + ++static Window hb = (Window)NULL; ++static XColor hbc; ++ + static void (*events[LASTEvent])(XEvent *e) = { + [ButtonPress] = button_press, + [ButtonRelease] = button_release, +@@ -75,8 +78,36 @@ static void (*events[LASTEvent])(XEvent *e) = { + XGetGeometry(d, W, &(Window){0}, gx, gy, gw, gh, \ + &(unsigned int){0}, &(unsigned int){0}) + ++void configure_hb_for_window(Window w) { ++ XWindowAttributes wa; ++ XGetWindowAttributes(d, w, &wa); ++ if (hb == (Window)NULL) { ++ int s = DefaultScreen(d); ++ hb = XCreateSimpleWindow(d, RootWindow(d, s), ++ wa.x, wa.y - handle_bar_thickness, ++ wa.width + 2*wa.border_width, handle_bar_thickness, ++ 0, ++ hbc.pixel, hbc.pixel); ++ XMapWindow(d, hb); ++ XGrabButton(d, AnyButton, AnyModifier, hb, True, ++ ButtonPressMask|ButtonReleaseMask|PointerMotionMask, ++ GrabModeAsync, GrabModeAsync, 0, 0); ++ } else ++ XMoveResizeWindow(d, hb, wa.x, wa.y - handle_bar_thickness, ++ wa.width, handle_bar_thickness); ++ XRaiseWindow(d, hb); ++} ++ ++void destroy_hb(void) { ++ if (hb == (Window)NULL) return; ++ XUnmapWindow(d, hb); ++ XDestroyWindow(d, hb); ++ hb = (Window)NULL; ++} ++ + void win_focus(client *c) { + cur = c; ++ configure_hb_for_window(c->w); + XSetInputFocus(d, cur->w, RevertToParent, CurrentTime); + } + +@@ -93,7 +124,22 @@ void notify_enter(XEvent *e) { + } + + void notify_motion(XEvent *e) { +- if (!mouse.subwindow || cur->f) return; ++ if (e->xmotion.window == hb) { ++ while(XCheckTypedEvent(d, MotionNotify, e)); ++ ++ int xd = e->xbutton.x_root - mouse.x_root; ++ int yd = e->xbutton.y_root - mouse.y_root; ++ ++ XMoveResizeWindow(d, cur->w, ++ wx + (mouse.button == 1 ? xd : 0), ++ wy + (mouse.button == 1 ? yd : 0), ++ ww + (mouse.button == 3 ? xd : 0), ++ wh + (mouse.button == 3 ? yd : 0)); ++ ++ configure_hb_for_window(cur->w); ++ } ++ ++ if (!mouse.subwindow || mouse.subwindow == hb || cur->f) return; + + while(XCheckTypedEvent(d, MotionNotify, e)); + +@@ -105,6 +151,8 @@ void notify_motion(XEvent *e) { + wy + (mouse.button == 1 ? yd : 0), + ww + (mouse.button == 3 ? xd : 0), + wh + (mouse.button == 3 ? yd : 0)); ++ ++ if (mouse.subwindow == cur->w) configure_hb_for_window(cur->w); + } + + void key_press(XEvent *e) { +@@ -116,6 +164,13 @@ void key_press(XEvent *e) { + } + + void button_press(XEvent *e) { ++ if (e->xbutton.window == hb) { ++ mouse = e->xbutton; ++ win_size(cur->w, &wx, &wy, &ww, &wh); ++ XRaiseWindow(d, cur->w); ++ return; ++ } ++ + if (!e->xbutton.subwindow) return; + + win_size(e->xbutton.subwindow, &wx, &wy, &ww, &wh); +@@ -154,6 +209,8 @@ void win_del(Window w) { + + for win if (c->w == w) x = c; + ++ if ( x == cur ) destroy_hb(); ++ + if (!list || !x) return; + if (x->prev == x) list = 0; + if (list == x) list = x->next; +@@ -174,6 +231,8 @@ void win_center() { + win_size(cur->w, &(int){0}, &(int){0}, &ww, &wh); + + XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2); ++ ++ configure_hb_for_window(cur->w); + } + + void win_fs() { +@@ -182,9 +241,11 @@ void win_fs() { + if ((cur->f = cur->f ? 0 : 1)) { + win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh); + XMoveResizeWindow(d, cur->w, 0, 0, sw, sh); +- +- } else ++ destroy_hb(); ++ } else { + XMoveResizeWindow(d, cur->w, cur->wx, cur->wy, cur->ww, cur->wh); ++ configure_hb_for_window(cur->w); ++ } + } + + void win_to_ws(const Arg arg) { +@@ -201,6 +262,8 @@ void win_to_ws(const Arg arg) { + XUnmapWindow(d, cur->w); + ws_save(tmp); + ++ destroy_hb(); ++ + if (list) win_focus(list); + } + +@@ -227,6 +290,8 @@ void ws_go(const Arg arg) { + + ws_sel(arg.i); + ++ destroy_hb(); ++ + if (list) win_focus(list); else cur = 0; + } + +@@ -290,6 +355,10 @@ int main(void) { + ButtonPressMask|ButtonReleaseMask|PointerMotionMask, + GrabModeAsync, GrabModeAsync, 0, 0); + ++ Colormap cm = DefaultColormap(d, s); ++ XParseColor(d, cm, handlebar_colour, &hbc); ++ XAllocColor(d, cm, &hbc); ++ + while (1 && !XNextEvent(d, &ev)) + if (events[ev.type]) events[ev.type](&ev); + } From 8ff3eee8748cf5e43d276bbd3481bb0436d890a0 Mon Sep 17 00:00:00 2001 From: Leon Plickat Date: Thu, 28 Nov 2019 00:47:39 +0100 Subject: [PATCH 2/8] Style --- patches/sowm-handlebar.patch | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/patches/sowm-handlebar.patch b/patches/sowm-handlebar.patch index 269f881..837ef09 100644 --- a/patches/sowm-handlebar.patch +++ b/patches/sowm-handlebar.patch @@ -13,14 +13,14 @@ index aaaf38d..bcf49d8 100644 const char* term[] = {"st", 0}; const char* scrot[] = {"scr", 0}; diff --git a/sowm.c b/sowm.c -index bc14c4e..abe94a4 100644 +index bc14c4e..42bd732 100644 --- a/sowm.c +++ b/sowm.c @@ -54,6 +54,9 @@ static unsigned int ww, wh; static Display *d; static XButtonEvent mouse; -+static Window hb = (Window)NULL; ++static Window hb = 0; +static XColor hbc; + static void (*events[LASTEvent])(XEvent *e) = { @@ -33,7 +33,7 @@ index bc14c4e..abe94a4 100644 +void configure_hb_for_window(Window w) { + XWindowAttributes wa; + XGetWindowAttributes(d, w, &wa); -+ if (hb == (Window)NULL) { ++ if (!hb) { + int s = DefaultScreen(d); + hb = XCreateSimpleWindow(d, RootWindow(d, s), + wa.x, wa.y - handle_bar_thickness, @@ -51,10 +51,10 @@ index bc14c4e..abe94a4 100644 +} + +void destroy_hb(void) { -+ if (hb == (Window)NULL) return; ++ if (!hb) return; + XUnmapWindow(d, hb); + XDestroyWindow(d, hb); -+ hb = (Window)NULL; ++ hb = 0; +} + void win_focus(client *c) { @@ -114,7 +114,7 @@ index bc14c4e..abe94a4 100644 for win if (c->w == w) x = c; -+ if ( x == cur ) destroy_hb(); ++ if (x == cur) destroy_hb(); + if (!list || !x) return; if (x->prev == x) list = 0; From f7fd37e3267021c63cac08c74249268a483ebfae Mon Sep 17 00:00:00 2001 From: Seungheon Oh Date: Sat, 14 Dec 2019 01:56:48 -0600 Subject: [PATCH 3/8] Patch: Rectangle style window launcher/mover --- patches/sowm-rect-to-move.patch | 116 ++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 patches/sowm-rect-to-move.patch diff --git a/patches/sowm-rect-to-move.patch b/patches/sowm-rect-to-move.patch new file mode 100644 index 0000000..6d66aeb --- /dev/null +++ b/patches/sowm-rect-to-move.patch @@ -0,0 +1,116 @@ +diff --git a/sowm.c b/sowm.c +index bc14c4e..83ed0fb 100644 +--- a/sowm.c ++++ b/sowm.c +@@ -65,6 +65,9 @@ static void (*events[LASTEvent])(XEvent *e) = { + [MotionNotify] = notify_motion + }; + ++ ++Window WaitingWindow; ++ + #include "config.h" + + #define win (client *t=0, *c=list; c && t!=list->prev; t=c, c=c->next) +@@ -75,6 +78,23 @@ static void (*events[LASTEvent])(XEvent *e) = { + XGetGeometry(d, W, &(Window){0}, gx, gy, gw, gh, \ + &(unsigned int){0}, &(unsigned int){0}) + ++#define abs(a) a < 0 ? -a : a ++ ++void draw_outline(int x1, int y1, int x2, int y2) { ++ XClearWindow(d, RootWindow(d, DefaultScreen(d))); ++ ++ GC gc = XCreateGC(d, RootWindow(d, DefaultScreen(d)), 0, NULL); ++ if(!gc)return; ++ ++ XSetForeground(d, gc, WhitePixel(d, DefaultScreen(d))); ++ XDrawLine(d, RootWindow(d, DefaultScreen(d)), gc, x1, y1, x1, y2); ++ XDrawLine(d, RootWindow(d, DefaultScreen(d)), gc, x1, y1, x2, y1); ++ XDrawLine(d, RootWindow(d, DefaultScreen(d)), gc, x1, y2, x2, y2); ++ XDrawLine(d, RootWindow(d, DefaultScreen(d)), gc, x2, y1, x2, y2); ++ XFreeGC(d, gc); ++ XFlush(d); ++} ++ + void win_focus(client *c) { + cur = c; + XSetInputFocus(d, cur->w, RevertToParent, CurrentTime); +@@ -93,7 +113,10 @@ void notify_enter(XEvent *e) { + } + + void notify_motion(XEvent *e) { +- if (!mouse.subwindow || cur->f) return; ++ if (!mouse.subwindow || cur->f) { ++ draw_outline(mouse.x_root, mouse.y_root, e->xbutton.x_root, e->xbutton.y_root); ++ return; ++ } + + while(XCheckTypedEvent(d, MotionNotify, e)); + +@@ -116,15 +139,42 @@ void key_press(XEvent *e) { + } + + void button_press(XEvent *e) { +- if (!e->xbutton.subwindow) return; ++ mouse = e->xbutton; + ++ if (!e->xbutton.subwindow) return; + win_size(e->xbutton.subwindow, &wx, &wy, &ww, &wh); + XRaiseWindow(d, e->xbutton.subwindow); +- mouse = e->xbutton; + } + +-void button_release() { +- mouse.subwindow = 0; ++void button_release(XEvent *e) { ++ XClearWindow(d, RootWindow(d, DefaultScreen(d))); ++ ++ if(WaitingWindow){ ++ XSelectInput(d, WaitingWindow, StructureNotifyMask|EnterWindowMask); ++ win_size(WaitingWindow, &wx, &wy, &ww, &wh); ++ win_add(WaitingWindow); ++ cur = list->prev; ++ ++ XMoveResizeWindow(d, cur->w, ++ mouse.x_root, ++ mouse.y_root, ++ abs(e->xbutton.x_root - mouse.x_root), ++ abs(e->xbutton.y_root - mouse.y_root)); ++ ++ XMapWindow(d, WaitingWindow); ++ win_focus(list->prev); ++ ++ WaitingWindow = 0; ++ ++ } else if(!mouse.subwindow && cur) { ++ XMoveResizeWindow(d, cur->w, ++ mouse.x_root, ++ mouse.y_root, ++ abs(e->xbutton.x_root - mouse.x_root), ++ abs(e->xbutton.y_root - mouse.y_root)); ++ ++ mouse.subwindow = 0; ++ } + } + + void win_add(Window w) { +@@ -244,17 +294,7 @@ void configure_request(XEvent *e) { + } + + void map_request(XEvent *e) { +- Window w = e->xmaprequest.window; +- +- XSelectInput(d, w, StructureNotifyMask|EnterWindowMask); +- win_size(w, &wx, &wy, &ww, &wh); +- win_add(w); +- cur = list->prev; +- +- if (wx + wy == 0) win_center(); +- +- XMapWindow(d, w); +- win_focus(list->prev); ++ WaitingWindow = e->xmaprequest.window; + } + + void run(const Arg arg) { From 8acd15de63032c3ba87a376f07b06ae220063b81 Mon Sep 17 00:00:00 2001 From: Seungheon Oh Date: Sat, 14 Dec 2019 02:00:37 -0600 Subject: [PATCH 4/8] README.md: Installation 4th step for applying patch --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f0e1de4..4f6db91 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ An itsy bitsy floating window manager (*220~ sloc / 24kb compiled!*). 3) Copy it to your path or run `make install`. - `DESTDIR` and `PREFIX` are supported. +4) (Optional) Apply patch with `git apply patches/patch-name` + ## Thanks From 62959ded52b3ac806e2c27178397f7c560db772b Mon Sep 17 00:00:00 2001 From: Seungheon Oh Date: Sat, 14 Dec 2019 21:58:12 -0600 Subject: [PATCH 5/8] README.md: Instruction for applying multiple patches --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f6db91..bb52953 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ An itsy bitsy floating window manager (*220~ sloc / 24kb compiled!*). 2) Run `make` to build `sowm`. 3) Copy it to your path or run `make install`. - `DESTDIR` and `PREFIX` are supported. - 4) (Optional) Apply patch with `git apply patches/patch-name` + - In case of applying multiple patches, it has to be done **manually**. ## Thanks From 1d376513914a0eca4c5d50b63afc1efbdf2a36c3 Mon Sep 17 00:00:00 2001 From: Seungheon Oh Date: Sat, 14 Dec 2019 22:41:15 -0600 Subject: [PATCH 6/8] Patch: Wheel for resizing window --- patches/sowm-wheelresize.patch | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 patches/sowm-wheelresize.patch diff --git a/patches/sowm-wheelresize.patch b/patches/sowm-wheelresize.patch new file mode 100644 index 0000000..28a2ff8 --- /dev/null +++ b/patches/sowm-wheelresize.patch @@ -0,0 +1,43 @@ +diff --git a/config.def.h b/config.def.h +index aaaf38d..5a95d71 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -2,6 +2,7 @@ + #define CONFIG_H + + #define MOD Mod4Mask ++#define WheelResizeStep 5 + + const char* menu[] = {"dmenu_run", 0}; + const char* term[] = {"st", 0}; +diff --git a/sowm.c b/sowm.c +index bc14c4e..3b95c28 100644 +--- a/sowm.c ++++ b/sowm.c +@@ -120,6 +120,17 @@ void button_press(XEvent *e) { + + win_size(e->xbutton.subwindow, &wx, &wy, &ww, &wh); + XRaiseWindow(d, e->xbutton.subwindow); ++ ++ int sd = 0; ++ if(e->xbutton.button == Button4) sd = WheelResizeStep; ++ else if(e->xbutton.button == Button5) sd = -WheelResizeStep; ++ ++ XMoveResizeWindow(d, e->xbutton.subwindow, ++ wx - sd, ++ wy - sd, ++ ww + sd*2, ++ wh + sd*2); ++ + mouse = e->xbutton; + } + +@@ -285,7 +296,7 @@ int main(void) { + XGrabKey(d, XKeysymToKeycode(d, keys[i].keysym), keys[i].mod, + root, True, GrabModeAsync, GrabModeAsync); + +- for (int i=1; i<4; i+=2) ++ for (int i=1; i<6; i++) + XGrabButton(d, i, MOD, root, True, + ButtonPressMask|ButtonReleaseMask|PointerMotionMask, + GrabModeAsync, GrabModeAsync, 0, 0); From 3efaa6decc5ac1bac1cb0005efff58555b7df523 Mon Sep 17 00:00:00 2001 From: Seungheon Oh Date: Sat, 14 Dec 2019 23:16:33 -0600 Subject: [PATCH 7/8] Patch: Bug fix --- patches/sowm-rect-to-move.patch | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/patches/sowm-rect-to-move.patch b/patches/sowm-rect-to-move.patch index 6d66aeb..42146cf 100644 --- a/patches/sowm-rect-to-move.patch +++ b/patches/sowm-rect-to-move.patch @@ -1,5 +1,5 @@ diff --git a/sowm.c b/sowm.c -index bc14c4e..83ed0fb 100644 +index bc14c4e..4ae3a8f 100644 --- a/sowm.c +++ b/sowm.c @@ -65,6 +65,9 @@ static void (*events[LASTEvent])(XEvent *e) = { @@ -16,7 +16,7 @@ index bc14c4e..83ed0fb 100644 XGetGeometry(d, W, &(Window){0}, gx, gy, gw, gh, \ &(unsigned int){0}, &(unsigned int){0}) -+#define abs(a) a < 0 ? -a : a ++#define ABS(N) (((N)<0)?-(N):(N)) + +void draw_outline(int x1, int y1, int x2, int y2) { + XClearWindow(d, RootWindow(d, DefaultScreen(d))); @@ -48,7 +48,7 @@ index bc14c4e..83ed0fb 100644 while(XCheckTypedEvent(d, MotionNotify, e)); -@@ -116,15 +139,42 @@ void key_press(XEvent *e) { +@@ -116,15 +139,43 @@ void key_press(XEvent *e) { } void button_press(XEvent *e) { @@ -73,10 +73,10 @@ index bc14c4e..83ed0fb 100644 + cur = list->prev; + + XMoveResizeWindow(d, cur->w, -+ mouse.x_root, -+ mouse.y_root, -+ abs(e->xbutton.x_root - mouse.x_root), -+ abs(e->xbutton.y_root - mouse.y_root)); ++ e->xbutton.x_root > mouse.x_root ? mouse.x_root : e->xbutton.x_root, ++ e->xbutton.y_root > mouse.y_root ? mouse.y_root : e->xbutton.y_root, ++ ABS(mouse.x_root - e->xbutton.x_root), ++ ABS(mouse.y_root - e->xbutton.y_root)); + + XMapWindow(d, WaitingWindow); + win_focus(list->prev); @@ -84,18 +84,19 @@ index bc14c4e..83ed0fb 100644 + WaitingWindow = 0; + + } else if(!mouse.subwindow && cur) { ++ + XMoveResizeWindow(d, cur->w, -+ mouse.x_root, -+ mouse.y_root, -+ abs(e->xbutton.x_root - mouse.x_root), -+ abs(e->xbutton.y_root - mouse.y_root)); ++ e->xbutton.x_root > mouse.x_root ? mouse.x_root : e->xbutton.x_root, ++ e->xbutton.y_root > mouse.y_root ? mouse.y_root : e->xbutton.y_root, ++ ABS(mouse.x_root - e->xbutton.x_root), ++ ABS(mouse.y_root - e->xbutton.y_root)); + + mouse.subwindow = 0; + } } void win_add(Window w) { -@@ -244,17 +294,7 @@ void configure_request(XEvent *e) { +@@ -244,17 +295,7 @@ void configure_request(XEvent *e) { } void map_request(XEvent *e) { From dcaf873fecdafb278439db3fe8fdd7190e846148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ki=C3=ABd=20Llaentenn?= <32681240+kiedtl@users.noreply.github.com> Date: Sun, 15 Dec 2019 18:53:52 -0500 Subject: [PATCH 8/8] add win_prev() --- sowm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sowm.c b/sowm.c index bc14c4e..47a7a28 100644 --- a/sowm.c +++ b/sowm.c @@ -42,6 +42,7 @@ static void win_center(); static void win_del(Window w); static void win_fs(); static void win_kill(); +static void win_prev(); static void win_next(); static void win_to_ws(const Arg arg); static void ws_go(const Arg arg); @@ -204,6 +205,13 @@ void win_to_ws(const Arg arg) { if (list) win_focus(list); } +void win_prev() { + if (!cur) return; + + XRaiseWindow(d, cur->prev->w); + win_focus(cur->prev); +} + void win_next() { if (!cur) return;