tabbed

tab interface for application supporting Xembed
git clone git://mfeller.io/tabbed.git
Log | Files | Refs | README | LICENSE

commit 1edbba3f31f7aa37639410f230f8293eb2e9bff9
parent b5f9ec647aae2d9a1d3bd586eb7523a4e0a329a3
Author: Mark Feller <mfeller@recurly.com>
Date:   Mon, 30 Mar 2020 22:47:17 -0600

make tabs autohide

Signed-off-by: Mark Feller <mfeller@recurly.com>

Diffstat:
Mconfig.def.h | 11++++++++++-
Mtabbed.c | 51++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ /* appearance */ -static const char font[] = "monospace:size=9"; +static const char font[] = "Fira Mono:size=10"; static const char* normbgcolor = "#222222"; static const char* normfgcolor = "#cccccc"; static const char* selbgcolor = "#555555"; @@ -63,4 +63,13 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_u, toggle, { .v = (void*) &urgentswitch } }, { 0, XK_F11, fullscreen, { 0 } }, + + { MODKEY, XK_Shift_L, showbar, { .i = 1 } }, + { ShiftMask, XK_Control_L, showbar, { .i = 1 } }, +}; + +static Key keyreleases[] = { + /* modifier key function argument */ + { MODKEY|ShiftMask, XK_Shift_L, showbar, { .i = 0 } }, + { MODKEY|ShiftMask, XK_Control_L, showbar, { .i = 0 } }, }; diff --git a/tabbed.c b/tabbed.c @@ -113,6 +113,7 @@ static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); static void initfont(const char *fontstr); static Bool isprotodel(int c); static void keypress(const XEvent *e); +static void keyrelease(const XEvent *e); static void killclient(const Arg *arg); static void manage(Window win); static void maprequest(const XEvent *e); @@ -126,6 +127,7 @@ static void sendxembed(int c, long msg, long detail, long d1, long d2); static void setcmd(int argc, char *argv[], int); static void setup(void); static void sigchld(int unused); +static void showbar(const Arg *arg); static void spawn(const Arg *arg); static int textnw(const char *text, unsigned int len); static void toggle(const Arg *arg); @@ -149,10 +151,11 @@ static void (*handler[LASTEvent]) (const XEvent *) = { [Expose] = expose, [FocusIn] = focusin, [KeyPress] = keypress, + [KeyRelease] = keyrelease, [MapRequest] = maprequest, [PropertyNotify] = propertynotify, }; -static int bh, wx, wy, ww, wh; +static int bh, wx, wy, ww, wh, vbh; static unsigned int numlockmask; static Bool running = True, nextfocus, doinitspawn = True, fillagain = False, closelastclient = False, @@ -169,6 +172,7 @@ static char winid[64]; static char **cmd; static char *wmname = "tabbed"; static const char *geometry; +static Bool barvisibility = False; char *argv0; @@ -315,9 +319,18 @@ void drawbar(void) { XftColor *col; - int c, cc, fc, width; + int c, cc, fc, width, nbh; char *name = NULL; + nbh = barvisibility ? vbh : 0; + if (nbh != bh) { + bh = nbh; + for (c = 0; c < nclients; c++) + XMoveResizeWindow(dpy, clients[c]->win, 0, bh, ww, wh-bh); + } + + if (bh == 0) return; + if (nclients == 0) { dc.x = 0; dc.w = ww; @@ -665,6 +678,22 @@ keypress(const XEvent *e) } void +keyrelease(const XEvent *e) +{ + const XKeyEvent *ev = &e->xkey; + unsigned int i; + KeySym keysym; + + keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0); + for (i = 0; i < LENGTH(keyreleases); i++) { + if (keysym == keyreleases[i].keysym && + CLEANMASK(keyreleases[i].mod) == CLEANMASK(ev->state) && + keyreleases[i].func) + keyreleases[i].func(&(keyreleases[i].arg)); + } +} + +void killclient(const Arg *arg) { XEvent ev; @@ -714,6 +743,15 @@ manage(Window w) } } + for (i = 0; i < LENGTH(keyreleases); i++) { + if ((code = XKeysymToKeycode(dpy, keyreleases[i].keysym))) { + for (j = 0; j < LENGTH(modifiers); j++) + XGrabKey(dpy, code, keyreleases[i].mod | + modifiers[j], w, True, + GrabModeAsync, GrabModeAsync); + } + } + c = ecalloc(1, sizeof *c); c->win = w; @@ -975,7 +1013,7 @@ setup(void) screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); initfont(font); - bh = dc.h = dc.font.height + 2; + vbh = dc.h = dc.font.height + 2; /* init atoms */ wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); @@ -1069,6 +1107,13 @@ setup(void) } void +showbar(const Arg *arg) +{ + barvisibility = arg->i; + drawbar(); +} + +void sigchld(int unused) { if (signal(SIGCHLD, sigchld) == SIG_ERR)