tabbed

Mahdi's build of tabbed
git clone git://mahdi.pw/tabbed.git
Log | Files | Refs | README | LICENSE

commit 8c74a563817d58ca9634a665efd3426a8e8955fb
parent 1fea079791467a8168303a99f247ea0f8cbaf972
Author: Mahdi Mirzade <[email protected]>
Date:   Wed, 12 Oct 2022 21:35:26 +0330

Update to 0.7, config.h: mark keys as const

Diffstat:
Mconfig.h | 14++++++++------
Mconfig.mk | 4++--
Dpatches/alpha.diff | 122-------------------------------------------------------------------------------
Mtabbed.c | 112++++++++++++++++++++++++++++---------------------------------------------------
4 files changed, 50 insertions(+), 202 deletions(-)

diff --git a/config.h b/config.h @@ -1,9 +1,11 @@ /* See LICENSE file for copyright and license details. */ /* appearance */ -#define HIDETABS 0 +#define HIDE_TABS 0 -static const char* font = "monospace:size=9"; +static const int bottom_tabs = 0; + +static const char* font = "monospace:size=10"; static const char* normbgcolor = "#222222"; static const char* normfgcolor = "#cccccc"; static const char* selbgcolor = "#555555"; @@ -39,7 +41,7 @@ static Bool npisrelative = True; } #define MODKEY ControlMask -static Key keys[] = { +static const Key keys[] = { /* modifier key function argument */ { MODKEY|Mod1Mask, XK_Return, focusonce, { 0 } }, { MODKEY|Mod1Mask, XK_Return, spawn, { 0 } }, @@ -69,15 +71,15 @@ static Key keys[] = { { 0, XK_F11, fullscreen, { 0 } }, - #if HIDETABS + #if HIDE_TABS { MODKEY, XK_Alt_L, showbar, { .i = 1 } }, { Mod1Mask, XK_Control_L, showbar, { .i = 1 } }, #endif }; -static Key keyreleases[] = { +static const Key keyreleases[] = { /* modifier key function argument */ - #if HIDETABS + #if HIDE_TABS { MODKEY|Mod1Mask, XK_Alt_L, showbar, { .i = 0 } }, { MODKEY|Mod1Mask, XK_Control_L, showbar, { .i = 0 } }, #else diff --git a/config.mk b/config.mk @@ -1,5 +1,5 @@ # tabbed version -VERSION = 0.6 +VERSION = 0.7 # Customize below to fit your system @@ -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} -lXrender +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${FREETYPELIBS} # flags CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE diff --git a/patches/alpha.diff b/patches/alpha.diff @@ -1,122 +0,0 @@ -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/tabbed.c b/tabbed.c @@ -48,7 +48,7 @@ #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) #define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height) -#define XRESOURCE_LOAD_META(NAME) \ +#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)) @@ -185,15 +185,12 @@ static char winid[64]; static char **cmd; static char *wmname = "tabbed"; static const char *geometry; -#if HIDETABS +#if HIDE_TABS static Bool barvisibility = False; #else static Bool barvisibility = True; #endif -static Colormap cmap; -static Visual *visual = NULL; - char *argv0; static int colors_changed = 0; @@ -208,8 +205,13 @@ buttonpress(const XEvent *e) int i, fc; Arg arg; - if (ev->y < 0 || ev->y > bh) - return; + if (bottom_tabs > 0) { + if (ev->y < wh - bh) + return; + } else { + if (ev->y < 0 || ev->y > bh) + return; + } if (((fc = getfirsttab()) > 0 && ev->x < TEXTW(before)) || ev->x < 0) return; @@ -280,7 +282,8 @@ configurenotify(const XEvent *e) ww = ev->width; wh = ev->height; XFreePixmap(dpy, dc.drawable); - dc.drawable = XCreatePixmap(dpy, win, ww, wh, 32); + dc.drawable = XCreatePixmap(dpy, win, ww, wh, + DefaultDepth(dpy, screen)); if (!obh && (wh <= bh)) { obh = bh; @@ -353,27 +356,29 @@ drawbar(void) char *name = NULL; char tabtitle[256]; - #if HIDETABS + #if HIDE_TABS nbh = barvisibility && nclients > 1 ? vbh : 0; #else nbh = nclients > 1 ? vbh : 0; #endif - if (nbh != bh) { - bh = nbh; - for (c = 0; c < nclients; c++) - XMoveResizeWindow(dpy, clients[c]->win, 0, bh, ww, wh-bh); - } + if (nbh != bh) { + bh = nbh; + for (c = 0; c < nclients; c++) + XMoveResizeWindow(dpy, clients[c]->win, 0, bottom_tabs > 0 ? 0 : bh, ww, wh-bh); + } - if (bh == 0) return; + if (bh == 0) + return; - if (colors_changed == 1) writecolors(); + if (colors_changed == 1) + writecolors(); if (nclients == 0) { dc.x = 0; dc.w = ww; XFetchName(dpy, win, &name); drawtext(name ? name : "", dc.norm); - XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, ww, bh, 0, 0); + XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, ww, bh, 0, bottom_tabs > 0 ? wh - bh : 0); XSync(dpy, False); return; @@ -417,7 +422,7 @@ drawbar(void) dc.x += dc.w; clients[c]->tabx = dc.x; } - XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, ww, bh, 0, 0); + XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, ww, bh, 0, bottom_tabs > 0 ? wh - bh : 0); XSync(dpy, False); } @@ -453,7 +458,7 @@ drawtext(const char *text, XftColor col[ColLast]) ; } - d = XftDrawCreate(dpy, dc.drawable, visual, cmap); + d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen)); XftDrawStringUtf8(d, &col[ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len); XftDrawDestroy(d); } @@ -621,7 +626,7 @@ getcolor(const char *colstr) { XftColor color; - if (!XftColorAllocName(dpy, visual, cmap, colstr, &color)) + if (!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color)) die("%s: cannot allocate color '%s'\n", argv0, colstr); return color; @@ -953,7 +958,7 @@ resize(int c, int w, int h) XWindowChanges wc; ce.x = 0; - ce.y = wc.y = bh; + ce.y = wc.y = bottom_tabs > 0 ? 0 : bh; ce.width = wc.width = w; ce.height = wc.height = h; ce.type = ConfigureNotify; @@ -1105,58 +1110,18 @@ 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); - 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); + 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); XMapRaised(dpy, win); XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask | @@ -1415,15 +1380,18 @@ xrdb_load(void) if (xrm != NULL) { xrdb = XrmGetStringDatabase(xrm); - XRESOURCE_LOAD_STRING("color0", normbgcolor); - XRESOURCE_LOAD_STRING("color12", normfgcolor); + XRESOURCE_LOAD_STRING("background", normbgcolor); + XRESOURCE_LOAD_STRING("foreground", normfgcolor); - XRESOURCE_LOAD_STRING("color12", selbgcolor); - XRESOURCE_LOAD_STRING("color0", selfgcolor); + XRESOURCE_LOAD_STRING("color8", selbgcolor); + XRESOURCE_LOAD_STRING("foreground", selfgcolor); - XRESOURCE_LOAD_STRING("color0", urgbgcolor); + XRESOURCE_LOAD_STRING("background", urgbgcolor); XRESOURCE_LOAD_STRING("color1", urgfgcolor); + //XRESOURCE_LOAD_STRING("color0", urgbgcolor); + //XRESOURCE_LOAD_STRING("color1", urgfgcolor); + XRESOURCE_LOAD_STRING("font", font); } XFlush(dpy);