From 7e731ccb4c0a61f1b396375d131303754ebaeb95 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 20 Feb 2020 19:28:09 +0200 Subject: [PATCH] sowm: added titlebar feature --- a/config.def.h.orig +++ b/config.def.h @@ -3,6 +3,8 @@ #define MOD Mod4Mask #define ROUND_CORNERS 20 +#define TH 90 +#define TC 255 + (255<<8) + (255<<16) const char* menu[] = {"dmenu_run", 0}; const char* term[] = {"st", 0}; --- a/sowm.h +++ b/sowm.h @@ -30,7 +30,7 @@ typedef struct client { struct client *next, *prev; int f, wx, wy; unsigned int ww, wh; - Window w; + Window w, t; } client; void button_press(XEvent *e); --- a/sowm.c.orig +++ b/sowm.c @@ -1,6 +1,7 @@ // sowm - An itsy bitsy floating window manager. #include +#include #include #include #include @@ -8,6 +9,7 @@ #include #include #include +#include #include "sowm.h" @@ -45,6 +47,27 @@ MAX(10, wh + (r ? m == 'n' ? -arg.i : m == 's' ? arg.i : 0 : 0))); } +void title_add(client *c) { + if (c->t) return; + + XClassHint cl; + XGetClassHint(d, c->w, &cl); + + if (!strcmp(cl.res_name, "no-title")) return; + + win_size(c->w, &wx, &wy, &ww, &wh); + c->t = XCreateSimpleWindow(d, root, wx, wy - TH, ww, TH, 0, TC, TC); + XMapWindow(d, c->t); +} + +void title_del(client *c) { + if (!c->t) return; + + XUnmapWindow(d, c->t); + XDestroyWindow(d, c->t); + c->t = 0; +} + void win_focus(client *c) { cur = c; XSetInputFocus(d, cur->w, RevertToParent, CurrentTime); @@ -65,6 +88,11 @@ void notify_motion(XEvent *e) { if (!mouse.subwindow || cur->f) return; + if (mouse.subwindow == cur->t) { + mouse.subwindow = cur->w; + win_size(cur->w, &wx, &wy, &ww, &wh); + } + while(XCheckTypedEvent(d, MotionNotify, e)); int xd = e->xbutton.x_root - mouse.x_root; @@ -75,7 +103,12 @@ wy + (mouse.button == 1 ? yd : 0), MAX(1, ww + (mouse.button == 3 ? xd : 0)), MAX(1, wh + (mouse.button == 3 ? yd : 0))); - + + if (cur->t) XMoveResizeWindow(d, cur->t, + wx + (mouse.button == 1 ? xd : 0), + wy + (mouse.button == 1 ? yd : 0) - TH, + MAX(1, ww + (mouse.button == 3 ? xd : 0)), TH); + if (mouse.button == 3) win_round_corners(mouse.subwindow, ROUND_CORNERS); } @@ -134,6 +167,7 @@ if (x->next) x->next->prev = x->prev; if (x->prev) x->prev->next = x->next; + title_del(x); free(x); ws_save(ws); } @@ -155,6 +189,8 @@ win_size(cur->w, &(int){0}, &(int){0}, &ww, &wh); XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2); + + if (cur->t) XMoveWindow(d, cur->t, (sw - ww) / 2, (sh - wh - TH * 2) / 2); } void win_fs(const Arg arg) { @@ -163,9 +199,12 @@ 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); + XRaiseWindow(d, cur->w); + title_del(cur); } else { XMoveResizeWindow(d, cur->w, cur->wx, cur->wy, cur->ww, cur->wh); + title_add(cur); } win_round_corners(cur->w, cur->f ? 0 : ROUND_CORNERS); @@ -216,6 +255,7 @@ ws_sel(tmp); win_del(cur->w); XUnmapWindow(d, cur->w); + title_del(cur); ws_save(tmp); if (list) win_focus(list); @@ -225,6 +265,10 @@ if (!cur) return; XRaiseWindow(d, cur->prev->w); + + if (cur->prev->t) + XRaiseWindow(d, cur->prev->t); + win_focus(cur->prev); } @@ -232,6 +276,10 @@ if (!cur) return; XRaiseWindow(d, cur->next->w); + + if (cur->next->t) + XRaiseWindow(d, cur->next->t); + win_focus(cur->next); } @@ -243,11 +291,17 @@ ws_save(ws); ws_sel(arg.i); - for win XMapWindow(d, c->w); + for win { + XMapWindow(d, c->w); + title_add(c); + } ws_sel(tmp); - for win XUnmapWindow(d, c->w); + for win { + XUnmapWindow(d, c->w); + title_del(c); + } ws_sel(arg.i); @@ -282,6 +336,7 @@ win_round_corners(w, ROUND_CORNERS); XMapWindow(d, w); win_focus(list->prev); + title_add(cur); } void run(const Arg arg) {