shod

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e770f50d8f3a2dca798affa820b21d4907a5b341
parent e8184fa2479b80c133d89bca678d5d8589e4a258
Author: Lucas de Sena <lucas@seninha.org>
Date:   Tue, 11 Oct 2022 16:33:32 -0300

update resources at runtime

Diffstat:
Mshod.c | 84++++++-------------------------------------------------------------------------
Mshod.h | 3+++
Mxdock.c | 2+-
Mxdraw.c | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mxevents.c | 20+++++++++++++++++++-
Mxnotif.c | 2+-
Mxutil.c | 3+--
Mxutil.h | 1-
8 files changed, 112 insertions(+), 84 deletions(-)

diff --git a/shod.c b/shod.c @@ -98,78 +98,6 @@ siginthandler(int signo) running = 0; } -/* read xrdb for configuration options */ -static void -getresources(void) -{ - long n; - char *type; - XrmValue xval; - - if (xrm == NULL || xdb == NULL) - return; - - if (XrmGetResource(xdb, "shod.faceName", "*", &type, &xval) == True) - config.font = xval.addr; - if (XrmGetResource(xdb, "shod.foreground", "*", &type, &xval) == True) - config.foreground = xval.addr; - - if (XrmGetResource(xdb, "shod.dockBackground", "*", &type, &xval) == True) - config.dockcolors[COLOR_DEF] = xval.addr; - if (XrmGetResource(xdb, "shod.dockBorder", "*", &type, &xval) == True) - config.dockcolors[COLOR_ALT] = xval.addr; - - if (XrmGetResource(xdb, "shod.activeBackground", "*", &type, &xval) == True) - config.bordercolors[FOCUSED][COLOR_MID] = xval.addr; - if (XrmGetResource(xdb, "shod.activeTopShadowColor", "*", &type, &xval) == True) - config.bordercolors[FOCUSED][COLOR_LIGHT] = xval.addr; - if (XrmGetResource(xdb, "shod.activeBottomShadowColor", "*", &type, &xval) == True) - config.bordercolors[FOCUSED][COLOR_DARK] = xval.addr; - - if (XrmGetResource(xdb, "shod.inactiveBackground", "*", &type, &xval) == True) - config.bordercolors[UNFOCUSED][COLOR_MID] = xval.addr; - if (XrmGetResource(xdb, "shod.inactiveTopShadowColor", "*", &type, &xval) == True) - config.bordercolors[UNFOCUSED][COLOR_LIGHT] = xval.addr; - if (XrmGetResource(xdb, "shod.inactiveBottomShadowColor", "*", &type, &xval) == True) - config.bordercolors[UNFOCUSED][COLOR_DARK] = xval.addr; - - if (XrmGetResource(xdb, "shod.urgentBackground", "*", &type, &xval) == True) - config.bordercolors[URGENT][COLOR_MID] = xval.addr; - if (XrmGetResource(xdb, "shod.urgentTopShadowColor", "*", &type, &xval) == True) - config.bordercolors[URGENT][COLOR_LIGHT] = xval.addr; - if (XrmGetResource(xdb, "shod.urgentBottomShadowColor", "*", &type, &xval) == True) - config.bordercolors[URGENT][COLOR_DARK] = xval.addr; - - if (XrmGetResource(xdb, "shod.borderWidth", "*", &type, &xval) == True) - if ((n = strtol(xval.addr, NULL, 10)) > 0 && n < 100) - config.borderwidth = n; - if (XrmGetResource(xdb, "shod.shadowThickness", "*", &type, &xval) == True) - if ((n = strtol(xval.addr, NULL, 10)) > 0 && n < 100) - config.shadowthickness = n; - if (XrmGetResource(xdb, "shod.titleWidth", "*", &type, &xval) == True) - if ((n = strtol(xval.addr, NULL, 10)) > 0 && n < 100) - config.titlewidth = n; - if (XrmGetResource(xdb, "shod.dockWidth", "*", &type, &xval) == True) - if ((n = strtol(xval.addr, NULL, 10)) > 0) - config.dockwidth = n; - if (XrmGetResource(xdb, "shod.dockSpace", "*", &type, &xval) == True) - if ((n = strtol(xval.addr, NULL, 10)) > 0) - config.dockspace = n; - if (XrmGetResource(xdb, "shod.dockGravity", "*", &type, &xval) == True) - config.dockgravity = xval.addr; - if (XrmGetResource(xdb, "shod.notifGap", "*", &type, &xval) == True) - if ((n = strtol(xval.addr, NULL, 10)) > 0) - config.notifgap = n; - if (XrmGetResource(xdb, "shod.notifGravity", "*", &type, &xval) == True) - config.notifgravity = xval.addr; - if (XrmGetResource(xdb, "shod.numOfDesktops", "*", &type, &xval) == True) - if ((n = strtol(xval.addr, NULL, 10)) > 0 && n < 100) - config.ndesktops = n; - if (XrmGetResource(xdb, "shod.snapProximity", "*", &type, &xval) == True) - if ((n = strtol(xval.addr, NULL, 10)) >= 0 && n < 100) - config.snap = n; -} - /* read command-line options */ static char * getoptions(int argc, char *argv[]) @@ -258,8 +186,9 @@ initroot(void) /* Select SubstructureRedirect events on root window */ swa.cursor = wm.cursors[CURSOR_NORMAL]; - swa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask - | StructureNotifyMask | ButtonPressMask; + swa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask + | StructureNotifyMask | ButtonPressMask + | PropertyChangeMask; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &swa); /* Set focus to root window */ @@ -393,7 +322,7 @@ int main(int argc, char *argv[]) { XEvent ev; - char *filename, *wmname; + char *filename, *wmname, *xrm; if (!setlocale(LC_ALL, "") || !XSupportsLocale()) warnx("warning: no locale support"); @@ -401,8 +330,8 @@ main(int argc, char *argv[]) xinitvisual(); xiniterrfunc(xerror, &xerrorxlib); XrmInitialize(); - if ((xrm = XResourceManagerString(dpy)) != NULL) - xdb = XrmGetStringDatabase(xrm); + xrm = XResourceManagerString(dpy); + setresources(xrm); clientswa.colormap = colormap; clientswa.border_pixel = BlackPixel(dpy, screen); clientswa.background_pixel = BlackPixel(dpy, screen); @@ -414,7 +343,6 @@ main(int argc, char *argv[]) wmname = argv[0]; else wmname = WMNAME; - getresources(); filename = getoptions(argc, argv); /* check sloppy focus */ diff --git a/shod.h b/shod.h @@ -689,10 +689,12 @@ void menuplace(struct Monitor *mon, struct Menu *menu); void dockappconfigure(struct Dockapp *dapp, unsigned int valuemask, XWindowChanges *wc); void barstrut(struct Bar *bar); void notifplace(void); +void notifdecorate(struct Notification *n); void splashplace(struct Monitor *mon, struct Splash *splash); void splashhide(struct Splash *splash, int hide); void splashrise(struct Splash *splash); void dockupdate(void); +void dockdecorate(void); /* monitor routines */ struct Monitor *getmon(int x, int y); @@ -735,6 +737,7 @@ void buttonrightdecorate(Window button, Pixmap pix, int style, int pressed); void copypixmap(Window win); void inittheme(void); void cleantheme(void); +void setresources(char *xrm); /* window management routines */ Managefunc managedockapp; diff --git a/xdock.c b/xdock.c @@ -1,7 +1,7 @@ #include "shod.h" /* decorate dock */ -static void +void dockdecorate(void) { if (dock.pw != dock.w || dock.ph != dock.h || dock.pix == None) diff --git a/xdraw.c b/xdraw.c @@ -767,5 +767,86 @@ inittheme(void) void cleantheme(void) { + int i; + XftFontClose(dpy, theme.font); + for (i = 0; i < STYLE_LAST; i++) { + XFreeColors(dpy, colormap, theme.border[i], COLOR_LAST, 0); + XftColorFree(dpy, visual, colormap, &theme.fg[i][0]); + XftColorFree(dpy, visual, colormap, &theme.fg[i][1]); + } + XFreeColors(dpy, colormap, theme.dock, 2, 0); + XFreeGC(dpy, gc); +} + +void +setresources(char *xrm) +{ + long n; + char *type; + XrmValue xval; + + XrmDestroyDatabase(xdb); + if (xrm == NULL || (xdb = XrmGetStringDatabase(xrm)) == NULL) + return; + + if (XrmGetResource(xdb, "shod.faceName", "*", &type, &xval) == True) + config.font = xval.addr; + if (XrmGetResource(xdb, "shod.foreground", "*", &type, &xval) == True) + config.foreground = xval.addr; + + if (XrmGetResource(xdb, "shod.dockBackground", "*", &type, &xval) == True) + config.dockcolors[COLOR_DEF] = xval.addr; + if (XrmGetResource(xdb, "shod.dockBorder", "*", &type, &xval) == True) + config.dockcolors[COLOR_ALT] = xval.addr; + + if (XrmGetResource(xdb, "shod.activeBackground", "*", &type, &xval) == True) + config.bordercolors[FOCUSED][COLOR_MID] = xval.addr; + if (XrmGetResource(xdb, "shod.activeTopShadowColor", "*", &type, &xval) == True) + config.bordercolors[FOCUSED][COLOR_LIGHT] = xval.addr; + if (XrmGetResource(xdb, "shod.activeBottomShadowColor", "*", &type, &xval) == True) + config.bordercolors[FOCUSED][COLOR_DARK] = xval.addr; + + if (XrmGetResource(xdb, "shod.inactiveBackground", "*", &type, &xval) == True) + config.bordercolors[UNFOCUSED][COLOR_MID] = xval.addr; + if (XrmGetResource(xdb, "shod.inactiveTopShadowColor", "*", &type, &xval) == True) + config.bordercolors[UNFOCUSED][COLOR_LIGHT] = xval.addr; + if (XrmGetResource(xdb, "shod.inactiveBottomShadowColor", "*", &type, &xval) == True) + config.bordercolors[UNFOCUSED][COLOR_DARK] = xval.addr; + + if (XrmGetResource(xdb, "shod.urgentBackground", "*", &type, &xval) == True) + config.bordercolors[URGENT][COLOR_MID] = xval.addr; + if (XrmGetResource(xdb, "shod.urgentTopShadowColor", "*", &type, &xval) == True) + config.bordercolors[URGENT][COLOR_LIGHT] = xval.addr; + if (XrmGetResource(xdb, "shod.urgentBottomShadowColor", "*", &type, &xval) == True) + config.bordercolors[URGENT][COLOR_DARK] = xval.addr; + + if (XrmGetResource(xdb, "shod.borderWidth", "*", &type, &xval) == True) + if ((n = strtol(xval.addr, NULL, 10)) > 0 && n < 100) + config.borderwidth = n; + if (XrmGetResource(xdb, "shod.shadowThickness", "*", &type, &xval) == True) + if ((n = strtol(xval.addr, NULL, 10)) > 0 && n < 100) + config.shadowthickness = n; + if (XrmGetResource(xdb, "shod.titleWidth", "*", &type, &xval) == True) + if ((n = strtol(xval.addr, NULL, 10)) > 0 && n < 100) + config.titlewidth = n; + if (XrmGetResource(xdb, "shod.dockWidth", "*", &type, &xval) == True) + if ((n = strtol(xval.addr, NULL, 10)) > 0) + config.dockwidth = n; + if (XrmGetResource(xdb, "shod.dockSpace", "*", &type, &xval) == True) + if ((n = strtol(xval.addr, NULL, 10)) > 0) + config.dockspace = n; + if (XrmGetResource(xdb, "shod.dockGravity", "*", &type, &xval) == True) + config.dockgravity = xval.addr; + if (XrmGetResource(xdb, "shod.notifGap", "*", &type, &xval) == True) + if ((n = strtol(xval.addr, NULL, 10)) > 0) + config.notifgap = n; + if (XrmGetResource(xdb, "shod.notifGravity", "*", &type, &xval) == True) + config.notifgravity = xval.addr; + if (XrmGetResource(xdb, "shod.numOfDesktops", "*", &type, &xval) == True) + if ((n = strtol(xval.addr, NULL, 10)) > 0 && n < 100) + config.ndesktops = n; + if (XrmGetResource(xdb, "shod.snapProximity", "*", &type, &xval) == True) + if ((n = strtol(xval.addr, NULL, 10)) >= 0 && n < 100) + config.snap = n; } diff --git a/xevents.c b/xevents.c @@ -392,7 +392,7 @@ getwintype(Window win, Window *leader, struct Tab **tab, int *state, XRectangle } /* get window type (and other info) from X resources */ - if (xrm != NULL && xdb != NULL) { + if (xdb != NULL) { /* check for window type */ (void)snprintf(buf, NAMEMAXLEN, "shod.%s.%s.%s.type", rule[CLASS], rule[INSTANCE], rule[ROLE]); if (XrmGetResource(xdb, buf, "*", &ds, &xval) == True && xval.addr != NULL) { @@ -1690,11 +1690,29 @@ static void xeventpropertynotify(XEvent *e) { XPropertyEvent *ev; + XTextProperty prop; + struct Container *c; struct Object *obj; struct Tab *tab; struct Menu *menu; ev = &e->xproperty; + if (ev->window == root && ev->atom == XA_RESOURCE_MANAGER) { + if (!XGetTextProperty(dpy, root, &prop, XA_RESOURCE_MANAGER)) + return; + setresources(prop.value); + XFree(prop.value); + cleantheme(); + inittheme(); + TAILQ_FOREACH(c, &wm.focusq, entry) + containerdecorate(c, NULL, NULL, 1, C); + TAILQ_FOREACH(obj, &wm.menuq, entry) + menudecorate((struct Menu *)obj, 0); + TAILQ_FOREACH(obj, &wm.notifq, entry) + notifdecorate((struct Notification *)obj); + dockdecorate(); + return; + } if (ev->state == PropertyDelete) return; obj = getmanaged(ev->window); diff --git a/xnotif.c b/xnotif.c @@ -29,7 +29,7 @@ notifnew(Window win, int w, int h) } /* decorate notification */ -static void +void notifdecorate(struct Notification *n) { /* (re)create pixmap */ diff --git a/xutil.c b/xutil.c @@ -62,12 +62,11 @@ static char *atomnames[ATOM_LAST] = { Visual *visual; Colormap colormap; unsigned int depth; -XrmDatabase xdb; +XrmDatabase xdb = NULL; Display *dpy; Window root; Atom atoms[ATOM_LAST]; int screen; -char *xrm; int max(int x, int y) diff --git a/xutil.h b/xutil.h @@ -80,7 +80,6 @@ extern Display *dpy; extern Window root; extern Atom atoms[ATOM_LAST]; extern int screen; -extern char *xrm; int max(int x, int y); int min(int x, int y);