commit a5a2d7c6c9bf4043fb55b77aa1a4515648b5f03c
parent dabf6a25ab01107fc1e0464ee6a3e369d1626f97
Author: Mahdi Mirzade <[email protected]>
Date: Thu, 7 Apr 2022 03:29:24 +0430
alpha, bar height, tab number, live Xres reload
Diffstat:
10 files changed, 809 insertions(+), 82 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -1,66 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-
-/* appearance */
-static const char font[] = "monospace:size=9";
-static const char* normbgcolor = "#222222";
-static const char* normfgcolor = "#cccccc";
-static const char* selbgcolor = "#555555";
-static const char* selfgcolor = "#ffffff";
-static const char* urgbgcolor = "#111111";
-static const char* urgfgcolor = "#cc0000";
-static const char before[] = "<";
-static const char after[] = ">";
-static const char titletrim[] = "...";
-static const int tabwidth = 200;
-static const Bool foreground = True;
-static Bool urgentswitch = False;
-
-/*
- * Where to place a new tab when it is opened. When npisrelative is True,
- * then the current position is changed + newposition. If npisrelative
- * is False, then newposition is an absolute position.
- */
-static int newposition = 0;
-static Bool npisrelative = False;
-
-#define SETPROP(p) { \
- .v = (char *[]){ "/bin/sh", "-c", \
- "prop=\"`xwininfo -children -id $1 | grep '^ 0x' |" \
- "sed -e's@^ *\\(0x[0-9a-f]*\\) \"\\([^\"]*\\)\".*@\\1 \\2@' |" \
- "xargs -0 printf %b | dmenu -l 10 -w $1`\" &&" \
- "xprop -id $1 -f $0 8s -set $0 \"$prop\"", \
- p, winid, NULL \
- } \
-}
-
-#define MODKEY ControlMask
-static Key keys[] = {
- /* modifier key function argument */
- { MODKEY|ShiftMask, XK_Return, focusonce, { 0 } },
- { MODKEY|ShiftMask, XK_Return, spawn, { 0 } },
-
- { MODKEY|ShiftMask, XK_l, rotate, { .i = +1 } },
- { MODKEY|ShiftMask, XK_h, rotate, { .i = -1 } },
- { MODKEY|ShiftMask, XK_j, movetab, { .i = -1 } },
- { MODKEY|ShiftMask, XK_k, movetab, { .i = +1 } },
- { MODKEY, XK_Tab, rotate, { .i = 0 } },
-
- { MODKEY, XK_grave, spawn, SETPROP("_TABBED_SELECT_TAB") },
- { MODKEY, XK_1, move, { .i = 0 } },
- { MODKEY, XK_2, move, { .i = 1 } },
- { MODKEY, XK_3, move, { .i = 2 } },
- { MODKEY, XK_4, move, { .i = 3 } },
- { MODKEY, XK_5, move, { .i = 4 } },
- { MODKEY, XK_6, move, { .i = 5 } },
- { MODKEY, XK_7, move, { .i = 6 } },
- { MODKEY, XK_8, move, { .i = 7 } },
- { MODKEY, XK_9, move, { .i = 8 } },
- { MODKEY, XK_0, move, { .i = 9 } },
-
- { MODKEY, XK_q, killclient, { 0 } },
-
- { MODKEY, XK_u, focusurgent, { 0 } },
- { MODKEY|ShiftMask, XK_u, toggle, { .v = (void*) &urgentswitch } },
-
- { 0, XK_F11, fullscreen, { 0 } },
-};
diff --git a/config.h b/config.h
@@ -0,0 +1,79 @@
+/* See LICENSE file for copyright and license details. */
+
+/* appearance */
+static const char* font = "monospace:size=9";
+static const char* normbgcolor = "#222222";
+static const char* normfgcolor = "#cccccc";
+static const char* selbgcolor = "#555555";
+static const char* selfgcolor = "#ffffff";
+static const char* urgbgcolor = "#111111";
+static const char* urgfgcolor = "#cc0000";
+static const char before[] = "<";
+static const char after[] = ">";
+static const char titletrim[] = "...";
+static const int tabwidth = 150;
+static const Bool foreground = True;
+static Bool urgentswitch = False;
+
+static const int clientNumber = 1;
+static const int barHeight = 0;
+
+/*
+ * Where to place a new tab when it is opened. When npisrelative is True,
+ * then the current position is changed + newposition. If npisrelative
+ * is False, then newposition is an absolute position.
+ */
+static int newposition = 1;
+static Bool npisrelative = True;
+
+#define SETPROP(p) { \
+ .v = (char *[]){ "/bin/sh", "-c", \
+ "prop=\"`xwininfo -children -id $1 | grep '^ 0x' |" \
+ "sed -e's@^ *\\(0x[0-9a-f]*\\) \"\\([^\"]*\\)\".*@\\1 \\2@' |" \
+ "xargs -0 printf %b | dmenu -l 10 -w $1`\" &&" \
+ "xprop -id $1 -f $0 8s -set $0 \"$prop\"", \
+ p, winid, NULL \
+ } \
+}
+
+#define MODKEY ControlMask
+static Key keys[] = {
+ /* modifier key function argument */
+ { MODKEY|Mod1Mask, XK_Return, focusonce, { 0 } },
+ { MODKEY|Mod1Mask, XK_Return, spawn, { 0 } },
+
+ { MODKEY|Mod1Mask, XK_l, rotate, { .i = +1 } },
+ { MODKEY|Mod1Mask, XK_h, rotate, { .i = -1 } },
+ { MODKEY|Mod1Mask, XK_j, movetab, { .i = -1 } },
+ { MODKEY|Mod1Mask, XK_k, movetab, { .i = +1 } },
+ { MODKEY, XK_Tab, rotate, { .i = 0 } },
+
+ { MODKEY, XK_grave, spawn, SETPROP("_TABBED_SELECT_TAB") },
+ { MODKEY, XK_1, move, { .i = 0 } },
+ { MODKEY, XK_2, move, { .i = 1 } },
+ { MODKEY, XK_3, move, { .i = 2 } },
+ { MODKEY, XK_4, move, { .i = 3 } },
+ { MODKEY, XK_5, move, { .i = 4 } },
+ { MODKEY, XK_6, move, { .i = 5 } },
+ { MODKEY, XK_7, move, { .i = 6 } },
+ { MODKEY, XK_8, move, { .i = 7 } },
+ { MODKEY, XK_9, move, { .i = 8 } },
+ { MODKEY, XK_0, move, { .i = 9 } },
+
+ //{ MODKEY, XK_d, killclient, { 0 } },
+ { MODKEY, XK_q, killclient, { 0 } },
+
+ { MODKEY, XK_u, focusurgent, { 0 } },
+ { MODKEY|Mod1Mask, XK_u, toggle, { .v = (void*) &urgentswitch } },
+
+ { 0, XK_F11, fullscreen, { 0 } },
+
+ { MODKEY, XK_Alt_L, showbar, { .i = 1 } },
+ { Mod1Mask, XK_Control_L, showbar, { .i = 1 } },
+};
+
+static Key keyreleases[] = {
+ /* modifier key function argument */
+ { MODKEY|Mod1Mask, XK_Alt_L, showbar, { .i = 0 } },
+ { MODKEY|Mod1Mask, XK_Control_L, showbar, { .i = 0 } },
+};
diff --git a/config.mk b/config.mk
@@ -18,7 +18,7 @@ FREETYPEINC = /usr/include/freetype2
# includes and libs
INCS = -I. -I/usr/include -I$(X11INC) -I${FREETYPEINC}
-LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${FREETYPELIBS}
+LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${FREETYPELIBS} -lXrender
# flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE
diff --git a/patches/alpha.diff b/patches/alpha.diff
@@ -0,0 +1,122 @@
+diff --git a/config.mk b/config.mk
+index 3a71529..095cead 100644
+--- a/config.mk
++++ b/config.mk
+@@ -9,7 +9,7 @@ MANPREFIX = ${PREFIX}/share/man
+
+ # includes and libs
+ INCS = -I. -I/usr/include -I/usr/include/freetype2
+-LIBS = -L/usr/lib -lc -lX11 -lfontconfig -lXft
++LIBS = -L/usr/lib -lc -lX11 -lfontconfig -lXft -lXrender
+
+ # flags
+ CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE
+diff --git a/tabbed.c b/tabbed.c
+index 9a44795..b4d47d1 100644
+--- a/tabbed.c
++++ b/tabbed.c
+@@ -170,6 +170,9 @@ static char **cmd;
+ static char *wmname = "tabbed";
+ static const char *geometry;
+
++static Colormap cmap;
++static Visual *visual = NULL;
++
+ char *argv0;
+
+ /* configuration, allows nested code to access above variables */
+@@ -255,8 +258,8 @@ configurenotify(const XEvent *e)
+ ww = ev->width;
+ wh = ev->height;
+ XFreePixmap(dpy, dc.drawable);
+- dc.drawable = XCreatePixmap(dpy, root, ww, wh,
+- DefaultDepth(dpy, screen));
++ dc.drawable = XCreatePixmap(dpy, win, ww, wh,
++ 32);
+ if (sel > -1)
+ resize(sel, ww, wh - bh);
+ XSync(dpy, False);
+@@ -399,7 +402,7 @@ drawtext(const char *text, XftColor col[ColLast])
+ ;
+ }
+
+- d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
++ d = XftDrawCreate(dpy, dc.drawable, visual, cmap);
+ XftDrawStringUtf8(d, &col[ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len);
+ XftDrawDestroy(d);
+ }
+@@ -564,7 +567,7 @@ getcolor(const char *colstr)
+ {
+ XftColor color;
+
+- if (!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color))
++ if (!XftColorAllocName(dpy, visual, cmap, colstr, &color))
+ die("%s: cannot allocate color '%s'\n", argv0, colstr);
+
+ return color;
+@@ -1016,18 +1019,60 @@ setup(void)
+ wy = dh + wy - wh - 1;
+ }
+
++ XVisualInfo *vis;
++ XRenderPictFormat *fmt;
++ int nvi;
++ int i;
++
++ XVisualInfo tpl = {
++ .screen = screen,
++ .depth = 32,
++ .class = TrueColor
++ };
++
++ vis = XGetVisualInfo(dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &tpl, &nvi);
++ for(i = 0; i < nvi; i ++) {
++ fmt = XRenderFindVisualFormat(dpy, vis[i].visual);
++ if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
++ visual = vis[i].visual;
++ break;
++ }
++ }
++
++ XFree(vis);
++
++ if (! visual) {
++ fprintf(stderr, "Couldn't find ARGB visual.\n");
++ exit(1);
++ }
++
++ cmap = XCreateColormap( dpy, root, visual, None);
+ dc.norm[ColBG] = getcolor(normbgcolor);
+ dc.norm[ColFG] = getcolor(normfgcolor);
+ dc.sel[ColBG] = getcolor(selbgcolor);
+ dc.sel[ColFG] = getcolor(selfgcolor);
+ dc.urg[ColBG] = getcolor(urgbgcolor);
+ dc.urg[ColFG] = getcolor(urgfgcolor);
+- dc.drawable = XCreatePixmap(dpy, root, ww, wh,
+- DefaultDepth(dpy, screen));
+- dc.gc = XCreateGC(dpy, root, 0, 0);
+
+- win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0,
+- dc.norm[ColFG].pixel, dc.norm[ColBG].pixel);
++ XSetWindowAttributes attrs;
++ attrs.background_pixel = dc.norm[ColBG].pixel;
++ attrs.border_pixel = dc.norm[ColFG].pixel;
++ attrs.bit_gravity = NorthWestGravity;
++ attrs.event_mask = FocusChangeMask | KeyPressMask
++ | ExposureMask | VisibilityChangeMask | StructureNotifyMask
++ | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
++ attrs.background_pixmap = None ;
++ attrs.colormap = cmap;
++
++ win = XCreateWindow(dpy, root, wx, wy,
++ ww, wh, 0, 32, InputOutput,
++ visual, CWBackPixmap | CWBorderPixel | CWBitGravity
++ | CWEventMask | CWColormap, &attrs);
++
++ dc.drawable = XCreatePixmap(dpy, win, ww, wh,
++ 32);
++ dc.gc = XCreateGC(dpy, dc.drawable, 0, 0);
++
+ XMapRaised(dpy, win);
+ XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask |
+ ButtonPressMask | ExposureMask | KeyPressMask |
diff --git a/patches/tabbed-bar-height-0.6.diff b/patches/tabbed-bar-height-0.6.diff
@@ -0,0 +1,24 @@
+diff --color -up tabbed-0.6-clean/config.def.h tabbed-0.6-modified/config.def.h
+--- tabbed-0.6-clean/config.def.h 2014-01-21 10:22:03.000000000 -0800
++++ tabbed-0.6-modified/config.def.h 2021-03-30 20:23:45.752478278 -0700
+@@ -10,7 +10,7 @@ static const char before[] = "<";
+ static const char after[] = ">";
+ static const int tabwidth = 200;
+ static const Bool foreground = True;
+-
++static const int barHeight = 24;
+ /*
+ * Where to place a new tab when it is opened. When npisrelative is True,
+ * then the current position is changed + newposition. If npisrelative
+diff --color -up tabbed-0.6-clean/tabbed.c tabbed-0.6-modified/tabbed.c
+--- tabbed-0.6-clean/tabbed.c 2014-01-21 10:22:03.000000000 -0800
++++ tabbed-0.6-modified/tabbed.c 2021-03-30 20:24:23.712477426 -0700
+@@ -920,7 +920,7 @@ setup(void) {
+ screen = DefaultScreen(dpy);
+ root = RootWindow(dpy, screen);
+ initfont(font);
+- bh = dc.h = dc.font.height + 2;
++ bh = dc.h = barHeight;
+
+ /* init atoms */
+ wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
diff --git a/patches/tabbed-clientnumber-20160702-bc23614.diff b/patches/tabbed-clientnumber-20160702-bc23614.diff
@@ -0,0 +1,23 @@
+diff --git a/tabbed.c b/tabbed.c
+index 9a44795..657909e 100644
+--- a/tabbed.c
++++ b/tabbed.c
+@@ -318,6 +318,7 @@ drawbar(void)
+ XftColor *col;
+ int c, cc, fc, width;
+ char *name = NULL;
++ char tabtitle[256];
+
+ if (nclients == 0) {
+ dc.x = 0;
+@@ -359,7 +360,9 @@ drawbar(void)
+ } else {
+ col = clients[c]->urgent ? dc.urg : dc.norm;
+ }
+- drawtext(clients[c]->name, col);
++ snprintf(tabtitle, sizeof(tabtitle), "%d: %s",
++ c + 1, clients[c]->name);
++ drawtext(tabtitle, col);
+ dc.x += dc.w;
+ clients[c]->tabx = dc.x;
+ }
diff --git a/patches/tabbed-hidetabs-20191216-b5f9ec6.diff b/patches/tabbed-hidetabs-20191216-b5f9ec6.diff
@@ -0,0 +1,105 @@
+From 52708d468acace9543d01e6d8afae799f8d6fccd Mon Sep 17 00:00:00 2001
+From: LeelaPakanati <[email protected]>
+Date: Mon, 16 Dec 2019 18:57:32 -0500
+Subject: [PATCH] Add hide tabs feature
+
+---
+ config.def.h | 7 +++++--
+ tabbed.c | 24 +++++++++++++++++++++---
+ 2 files changed, 26 insertions(+), 5 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 7bfda30..bb7ef0e 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -63,10 +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 */
+- { 0, XK_Shift_L, NULL, { 0 } },
+-
++ { MODKEY|ShiftMask, XK_Shift_L, showbar, { .i = 0 } },
++ { MODKEY|ShiftMask, XK_Control_L, showbar, { .i = 0 } },
+ };
+diff --git a/tabbed.c b/tabbed.c
+index fe38b9d..352dab2 100644
+--- a/tabbed.c
++++ b/tabbed.c
+@@ -127,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);
+@@ -154,7 +155,7 @@ static void (*handler[LASTEvent]) (const XEvent *) = {
+ [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,
+@@ -171,6 +172,7 @@ static char winid[64];
+ static char **cmd;
+ static char *wmname = "tabbed";
+ static const char *geometry;
++static Bool barvisibility = False;
+
+ char *argv0;
+
+@@ -317,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;
+@@ -1003,7 +1014,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);
+@@ -1096,6 +1107,13 @@ setup(void)
+ focus(-1);
+ }
+
++void
++showbar(const Arg *arg)
++{
++ barvisibility = arg->i;
++ drawbar();
++}
++
+ void
+ sigchld(int unused)
+ {
+--
+2.24.0
+
diff --git a/patches/tabbed-keyrelease-20191216-b5f9ec6.diff b/patches/tabbed-keyrelease-20191216-b5f9ec6.diff
@@ -0,0 +1,96 @@
+From 6c58b480b7b6ce6a28beafc60a096069fbd51532 Mon Sep 17 00:00:00 2001
+From: LeelaPakanati <LeelaPakanati.gmail.com>
+Date: Fri, 13 Dec 2019 16:56:42 -0500
+Subject: [PATCH] Add function handling at keyrelease
+
+---
+ config.def.h | 6 ++++++
+ tabbed.c | 30 +++++++++++++++++++++++++++++-
+ 2 files changed, 35 insertions(+), 1 deletion(-)
+
+diff --git a/config.def.h b/config.def.h
+index defa426..7bfda30 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -64,3 +64,9 @@ static Key keys[] = {
+
+ { 0, XK_F11, fullscreen, { 0 } },
+ };
++
++static Key keyreleases[] = {
++ /* modifier key function argument */
++ { 0, XK_Shift_L, NULL, { 0 } },
++
++};
+diff --git a/tabbed.c b/tabbed.c
+index ff3ada0..fe38b9d 100644
+--- 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);
+@@ -149,6 +150,7 @@ static void (*handler[LASTEvent]) (const XEvent *) = {
+ [Expose] = expose,
+ [FocusIn] = focusin,
+ [KeyPress] = keypress,
++ [KeyRelease] = keyrelease,
+ [MapRequest] = maprequest,
+ [PropertyNotify] = propertynotify,
+ };
+@@ -664,6 +666,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)
+ {
+@@ -714,6 +732,16 @@ 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;
+
+@@ -1036,7 +1064,7 @@ setup(void)
+ XMapRaised(dpy, win);
+ XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask |
+ ButtonPressMask | ExposureMask | KeyPressMask |
+- PropertyChangeMask | StructureNotifyMask |
++ KeyReleaseMask | PropertyChangeMask | StructureNotifyMask |
+ SubstructureRedirectMask);
+ xerrorxlib = XSetErrorHandler(xerror);
+
+--
+2.24.0
+
diff --git a/patches/tabbed-xresources-20210317-dabf6a2.diff b/patches/tabbed-xresources-20210317-dabf6a2.diff
@@ -0,0 +1,178 @@
+From 8c48f1564c555bbd21758a3a70a9984e61c34a35 Mon Sep 17 00:00:00 2001
+From: 6d6f7274686f6e <[email protected]>
+Date: Wed, 17 Mar 2021 10:59:18 +0100
+Subject: [PATCH] xresources support
+
+---
+ config.def.h | 27 ++++++++++++++------
+ tabbed.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 89 insertions(+), 7 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index defa426..244e288 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -1,13 +1,13 @@
+ /* See LICENSE file for copyright and license details. */
+
+ /* appearance */
+-static const char font[] = "monospace:size=9";
+-static const char* normbgcolor = "#222222";
+-static const char* normfgcolor = "#cccccc";
+-static const char* selbgcolor = "#555555";
+-static const char* selfgcolor = "#ffffff";
+-static const char* urgbgcolor = "#111111";
+-static const char* urgfgcolor = "#cc0000";
++static char font[] = "monospace:size=9";
++static char* normbgcolor = "#222222";
++static char* normfgcolor = "#cccccc";
++static char* selbgcolor = "#555555";
++static char* selfgcolor = "#ffffff";
++static char* urgbgcolor = "#111111";
++static char* urgfgcolor = "#cc0000";
+ static const char before[] = "<";
+ static const char after[] = ">";
+ static const char titletrim[] = "...";
+@@ -33,6 +33,19 @@ static Bool npisrelative = False;
+ } \
+ }
+
++/*
++ * Xresources preferences to load at startup
++ */
++ResourcePref resources[] = {
++ { "font", STRING, &font },
++ { "color0", STRING, &normbgcolor },
++ { "color4", STRING, &normfgcolor },
++ { "color4", STRING, &selbgcolor },
++ { "color7", STRING, &selfgcolor },
++ { "color2", STRING, &urgbgcolor },
++ { "color3", STRING, &urgfgcolor },
++};
++
+ #define MODKEY ControlMask
+ static Key keys[] = {
+ /* modifier key function argument */
+diff --git a/tabbed.c b/tabbed.c
+index eafe28a..c5bffc7 100644
+--- a/tabbed.c
++++ b/tabbed.c
+@@ -13,6 +13,7 @@
+ #include <X11/Xatom.h>
+ #include <X11/Xlib.h>
+ #include <X11/Xproto.h>
++#include <X11/Xresource.h>
+ #include <X11/Xutil.h>
+ #include <X11/XKBlib.h>
+ #include <X11/Xft/Xft.h>
+@@ -85,11 +86,26 @@ typedef struct {
+ Bool urgent;
+ Bool closed;
+ } Client;
++
++/* Xresources preferences */
++enum resource_type {
++ STRING = 0,
++ INTEGER = 1,
++ FLOAT = 2
++};
++
++typedef struct {
++ char *name;
++ enum resource_type type;
++ void *dst;
++} ResourcePref;
++
+
+ /* function declarations */
+ static void buttonpress(const XEvent *e);
+ static void cleanup(void);
+ static void clientmessage(const XEvent *e);
++static void config_init(void);
+ static void configurenotify(const XEvent *e);
+ static void configurerequest(const XEvent *e);
+ static void createnotify(const XEvent *e);
+@@ -120,6 +136,7 @@ static void move(const Arg *arg);
+ static void movetab(const Arg *arg);
+ static void propertynotify(const XEvent *e);
+ static void resize(int c, int w, int h);
++static int resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
+ static void rotate(const Arg *arg);
+ static void run(void);
+ static void sendxembed(int c, long msg, long detail, long d1, long d2);
+@@ -245,6 +262,23 @@ clientmessage(const XEvent *e)
+ }
+ }
+
++void
++config_init(void)
++{
++ char *resm;
++ XrmDatabase db;
++ ResourcePref *p;
++
++ XrmInitialize();
++ resm = XResourceManagerString(dpy);
++ if (!resm)
++ return;
++
++ db = XrmGetStringDatabase(resm);
++ for (p = resources; p < resources + LENGTH(resources); p++)
++ resource_load(db, p->name, p->type, p->dst);
++}
++
+ void
+ configurenotify(const XEvent *e)
+ {
+@@ -897,6 +931,40 @@ resize(int c, int w, int h)
+ (XEvent *)&ce);
+ }
+
++int
++resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
++{
++ char **sdst = dst;
++ int *idst = dst;
++ float *fdst = dst;
++
++ char fullname[256];
++ char fullclass[256];
++ char *type;
++ XrmValue ret;
++
++ snprintf(fullname, sizeof(fullname), "%s.%s", "tabbed", name);
++ snprintf(fullclass, sizeof(fullclass), "%s.%s", "tabbed", name);
++ fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
++
++ XrmGetResource(db, fullname, fullclass, &type, &ret);
++ if (ret.addr == NULL || strncmp("String", type, 64))
++ return 1;
++
++ switch (rtype) {
++ case STRING:
++ *sdst = ret.addr;
++ break;
++ case INTEGER:
++ *idst = strtoul(ret.addr, NULL, 10);
++ break;
++ case FLOAT:
++ *fdst = strtof(ret.addr, NULL);
++ break;
++ }
++ return 0;
++}
++
+ void
+ rotate(const Arg *arg)
+ {
+@@ -1354,6 +1422,7 @@ main(int argc, char *argv[])
+ if (!(dpy = XOpenDisplay(NULL)))
+ die("%s: cannot open display\n", argv0);
+
++ config_init();
+ setup();
+ printf("0x%lx\n", win);
+ fflush(NULL);
+--
+2.30.2
+
diff --git a/tabbed.c b/tabbed.c
@@ -16,6 +16,7 @@
#include <X11/Xutil.h>
#include <X11/XKBlib.h>
#include <X11/Xft/Xft.h>
+#include <X11/Xresource.h>
#include "arg.h"
@@ -47,6 +48,15 @@
#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
#define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height)
+#define XRESOURCE_LOAD_META(NAME) \
+ if(!XrmGetResource(xrdb, "tabbed." NAME, "tabbed." NAME, &type, &ret)) \
+ XrmGetResource(xrdb, "*." NAME, "*." NAME, &type, &ret); \
+ if (ret.addr != NULL && !strncmp("String", type, 64))
+
+#define XRESOURCE_LOAD_STRING(NAME, DST) \
+ XRESOURCE_LOAD_META(NAME) \
+ DST = ret.addr;
+
enum { ColFG, ColBG, ColLast }; /* color */
enum { WMProtocols, WMDelete, WMName, WMState, WMFullscreen,
XEmbed, WMSelectTab, WMLast }; /* default atoms */
@@ -113,6 +123,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 +137,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);
@@ -135,6 +147,9 @@ static void updatenumlockmask(void);
static void updatetitle(int c);
static int xerror(Display *dpy, XErrorEvent *ee);
static void xsettitle(Window w, const char *str);
+static void xrdb_load(void);
+static void reload(int sig);
+static void writecolors(void);
/* variables */
static int screen;
@@ -149,10 +164,11 @@ static void (*handler[LASTEvent]) (const XEvent *) = {
[Expose] = expose,
[FocusIn] = focusin,
[KeyPress] = keypress,
+ [KeyRelease] = keyrelease,
[MapRequest] = maprequest,
[PropertyNotify] = propertynotify,
};
-static int bh, obh, wx, wy, ww, wh;
+static int bh, obh, wx, wy, ww, wh, vbh;
static unsigned int numlockmask;
static Bool running = True, nextfocus, doinitspawn = True,
fillagain = False, closelastclient = False,
@@ -169,9 +185,15 @@ static char winid[64];
static char **cmd;
static char *wmname = "tabbed";
static const char *geometry;
+static Bool barvisibility = False;
+
+static Colormap cmap;
+static Visual *visual = NULL;
char *argv0;
+static int colors_changed = 0;
+
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -254,8 +276,7 @@ configurenotify(const XEvent *e)
ww = ev->width;
wh = ev->height;
XFreePixmap(dpy, dc.drawable);
- dc.drawable = XCreatePixmap(dpy, root, ww, wh,
- DefaultDepth(dpy, screen));
+ dc.drawable = XCreatePixmap(dpy, win, ww, wh, 32);
if (!obh && (wh <= bh)) {
obh = bh;
@@ -324,8 +345,20 @@ void
drawbar(void)
{
XftColor *col;
- int c, cc, fc, width;
+ int c, cc, fc, width, nbh;
char *name = NULL;
+ char tabtitle[256];
+
+ 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 (colors_changed == 1) writecolors();
if (nclients == 0) {
dc.x = 0;
@@ -367,7 +400,9 @@ drawbar(void)
} else {
col = clients[c]->urgent ? dc.urg : dc.norm;
}
- drawtext(clients[c]->name, col);
+ snprintf(tabtitle, sizeof(tabtitle), "%d: %s",
+ c + 1, clients[c]->name);
+ drawtext(tabtitle, col);
dc.x += dc.w;
clients[c]->tabx = dc.x;
}
@@ -407,7 +442,7 @@ drawtext(const char *text, XftColor col[ColLast])
;
}
- d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
+ d = XftDrawCreate(dpy, dc.drawable, visual, cmap);
XftDrawStringUtf8(d, &col[ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len);
XftDrawDestroy(d);
}
@@ -575,7 +610,7 @@ getcolor(const char *colstr)
{
XftColor color;
- if (!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color))
+ if (!XftColorAllocName(dpy, visual, cmap, colstr, &color))
die("%s: cannot allocate color '%s'\n", argv0, colstr);
return color;
@@ -674,6 +709,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;
@@ -723,6 +774,16 @@ 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;
@@ -984,7 +1045,10 @@ setup(void)
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
initfont(font);
- bh = dc.h = dc.font.height + 2;
+ if (barHeight)
+ vbh = dc.h = barHeight;
+ else
+ vbh = dc.h = dc.font.height + 2;
/* init atoms */
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
@@ -1030,22 +1094,63 @@ setup(void)
wy = dh + wy - wh - 1;
}
+ XVisualInfo *vis;
+ XRenderPictFormat *fmt;
+ int nvi;
+ int i;
+
+ XVisualInfo tpl = {
+ .screen = screen,
+ .depth = 32,
+ .class = TrueColor
+ };
+
+ vis = XGetVisualInfo(dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &tpl, &nvi);
+ for(i = 0; i < nvi; i ++) {
+ fmt = XRenderFindVisualFormat(dpy, vis[i].visual);
+ if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
+ visual = vis[i].visual;
+ break;
+ }
+ }
+
+ XFree(vis);
+
+ if (! visual) {
+ fprintf(stderr, "Couldn't find ARGB visual.\n");
+ exit(1);
+ }
+
+ cmap = XCreateColormap( dpy, root, visual, None);
dc.norm[ColBG] = getcolor(normbgcolor);
dc.norm[ColFG] = getcolor(normfgcolor);
dc.sel[ColBG] = getcolor(selbgcolor);
dc.sel[ColFG] = getcolor(selfgcolor);
dc.urg[ColBG] = getcolor(urgbgcolor);
dc.urg[ColFG] = getcolor(urgfgcolor);
- dc.drawable = XCreatePixmap(dpy, root, ww, wh,
- DefaultDepth(dpy, screen));
- dc.gc = XCreateGC(dpy, root, 0, 0);
-
- win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0,
- dc.norm[ColFG].pixel, dc.norm[ColBG].pixel);
+ XSetWindowAttributes attrs;
+ attrs.background_pixel = dc.norm[ColBG].pixel;
+ attrs.border_pixel = dc.norm[ColFG].pixel;
+ attrs.bit_gravity = NorthWestGravity;
+ attrs.event_mask = FocusChangeMask | KeyPressMask
+ | ExposureMask | VisibilityChangeMask | StructureNotifyMask
+ | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
+ attrs.background_pixmap = None ;
+ attrs.colormap = cmap;
+
+ win = XCreateWindow(dpy, root, wx, wy,
+ ww, wh, 0, 32, InputOutput,
+ visual, CWBackPixmap | CWBorderPixel | CWBitGravity
+ | CWEventMask | CWColormap, &attrs);
+
+ dc.drawable = XCreatePixmap(dpy, win, ww, wh,
+ 32);
+ dc.gc = XCreateGC(dpy, dc.drawable, 0, 0);
+
XMapRaised(dpy, win);
XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask |
ButtonPressMask | ExposureMask | KeyPressMask |
- PropertyChangeMask | StructureNotifyMask |
+ KeyReleaseMask | PropertyChangeMask | StructureNotifyMask |
SubstructureRedirectMask);
xerrorxlib = XSetErrorHandler(xerror);
@@ -1079,6 +1184,13 @@ setup(void)
}
void
+showbar(const Arg *arg)
+{
+ barvisibility = arg->i;
+ drawbar();
+}
+
+void
sigchld(int unused)
{
if (signal(SIGCHLD, sigchld) == SIG_ERR)
@@ -1273,6 +1385,58 @@ usage(void)
" [-u color] [-U color] command...\n", argv0);
}
+void
+xrdb_load(void)
+{
+ /* XXX */
+ char *xrm;
+ char *type;
+ XrmDatabase xrdb;
+ XrmValue ret;
+ Display *dpy;
+
+ if(!(dpy = XOpenDisplay(NULL)))
+ die("Can't open display\n");
+
+ XrmInitialize();
+ xrm = XResourceManagerString(dpy);
+
+ if (xrm != NULL) {
+ xrdb = XrmGetStringDatabase(xrm);
+
+ XRESOURCE_LOAD_STRING("color8", normbgcolor);
+ XRESOURCE_LOAD_STRING("color7", normfgcolor);
+
+ XRESOURCE_LOAD_STRING("color0", selbgcolor);
+ XRESOURCE_LOAD_STRING("color15", selfgcolor);
+
+ XRESOURCE_LOAD_STRING("color8", urgbgcolor);
+ XRESOURCE_LOAD_STRING("color6", urgfgcolor);
+
+ XRESOURCE_LOAD_STRING("font", font);
+ }
+ XFlush(dpy);
+}
+
+void
+reload(int sig) {
+ xrdb_load();
+ colors_changed=1;
+ signal(SIGUSR1, reload);
+}
+
+void
+writecolors(void) {
+ dc.norm[ColBG] = getcolor(normbgcolor);
+ dc.norm[ColFG] = getcolor(normfgcolor);
+ dc.sel[ColBG] = getcolor(selbgcolor);
+ dc.sel[ColFG] = getcolor(selfgcolor);
+ dc.urg[ColBG] = getcolor(urgbgcolor);
+ dc.urg[ColFG] = getcolor(urgfgcolor);
+
+ colors_changed = 0;
+}
+
int
main(int argc, char *argv[])
{
@@ -1354,6 +1518,8 @@ main(int argc, char *argv[])
if (!(dpy = XOpenDisplay(NULL)))
die("%s: cannot open display\n", argv0);
+ xrdb_load();
+ signal(SIGUSR1, reload);
setup();
printf("0x%lx\n", win);
fflush(NULL);