This repository has been archived on 2021-03-07. You can view files and clone it, but cannot push or open issues or pull requests.
sowm/patches/sowm-handlebar.patch

185 lines
5.1 KiB
Diff

diff --git a/config.def.h b/config.def.h
index cae2009..7e422a9 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 48222c6..551c8eb 100644
--- a/sowm.c
+++ b/sowm.c
@@ -55,6 +55,10 @@ static unsigned int ww, wh;
static Display *d;
static XButtonEvent mouse;
+static Window hb = 0;
+static XColor hbc;
+static int hba = 0;
+
static void (*events[LASTEvent])(XEvent *e) = {
[ButtonPress] = button_press,
[ButtonRelease] = button_release,
@@ -77,8 +81,37 @@ 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) {
+ 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) return;
+ XUnmapWindow(d, hb);
+ XDestroyWindow(d, hb);
+ hb = 0;
+}
+
void win_focus(client *c) {
+ if (hba) return;
cur = c;
+ configure_hb_for_window(c->w);
XSetInputFocus(d, cur->w, RevertToParent, CurrentTime);
}
@@ -95,7 +128,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));
@@ -107,6 +155,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) {
@@ -122,6 +172,14 @@ void key_press(XEvent *e) {
}
void button_press(XEvent *e) {
+ if (e->xbutton.window == hb) {
+ mouse = e->xbutton;
+ hba = 1;
+ 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);
@@ -131,6 +189,7 @@ void button_press(XEvent *e) {
void button_release() {
mouse.subwindow = 0;
+ hba = 0;
}
void win_add(Window w) {
@@ -160,6 +219,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;
@@ -180,6 +241,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() {
@@ -188,9 +251,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) {
@@ -207,6 +272,8 @@ void win_to_ws(const Arg arg) {
XUnmapWindow(d, cur->w);
ws_save(tmp);
+ destroy_hb();
+
if (list) win_focus(list);
}
@@ -240,6 +307,8 @@ void ws_go(const Arg arg) {
ws_sel(arg.i);
+ destroy_hb();
+
if (list) win_focus(list); else cur = 0;
}
@@ -303,6 +372,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);
}