add .Xresources support to speedwm status

This commit is contained in:
speedie 2022-12-19 23:27:53 +01:00
parent b0b2a697a2
commit da23f22fa5
8 changed files with 132 additions and 9 deletions

View file

@ -531,6 +531,10 @@ Below is a list of all .Xresources values you can define.
- speedwm.tag.urgentwindows: 1 - speedwm.tag.urgentwindows: 1
- speedwm.tiling.resizehints: 0 - speedwm.tiling.resizehints: 0
- speedwm.run.shell: /bin/sh - speedwm.run.shell: /bin/sh
- speedwm.status.hideemptymodule: 1
- speedwm.status.leftpadding:
- speedwm.status.rightpadding:
- speedwm.status.separator:
## Signals ## Signals

View file

@ -276,6 +276,16 @@ speedwm.tiling.resizehints: 0 ! Enable resize hints (0/1)
!! Shell to run commands with (<char>) !! Shell to run commands with (<char>)
speedwm.run.shell: /bin/sh speedwm.run.shell: /bin/sh
!! Status options
!!
!! Note that these only apply if you use the built-in speedwm status (status)
speedwm.status.hideemptymodule: 1
/*
speedwm.status.leftpadding:
speedwm.status.rightpadding:
speedwm.status.separator:
*/
!! You have reached the bottom of the speedwm config file. !! You have reached the bottom of the speedwm config file.
!! It may be used as a reference for writing a config file from scratch, or simply copied somewhere and edited. !! It may be used as a reference for writing a config file from scratch, or simply copied somewhere and edited.
!! Defaults here should more or less represent the settings in the speedwm source code. !! Defaults here should more or less represent the settings in the speedwm source code.

View file

@ -9,7 +9,7 @@
[ -e "../options.mk" ] && [ -z "$VERSION" ] && VERSION="$(grep "VERSION" ../options.mk | head -n 1 | awk '{ print $3 }')" [ -e "../options.mk" ] && [ -z "$VERSION" ] && VERSION="$(grep "VERSION" ../options.mk | head -n 1 | awk '{ print $3 }')"
[ "$VIEWER" = "-o" ] && VIEWER="cat" [ "$VIEWER" = "-o" ] && VIEWER="cat"
[ -e "${DOCDIR}/${PREFIX}example.Xresources" ] && sed 's|\(!*\)!.*|\1|' ${DOCDIR}/${PREFIX}example.Xresources | grep -v "!" | grep "speedwm" > "/tmp/example.Xresources" && \ [ -e "${DOCDIR}/${PREFIX}example.Xresources" ] && sed 's|\(!*\)!.*|\1|' ${DOCDIR}/${PREFIX}example.Xresources | grep -vE "!|/[*]" | grep "speedwm" > "/tmp/example.Xresources" && \
sed "s/speedwm[.]/- speedwm./g" /tmp/example.Xresources > /tmp/example.Xresources.tmp && \ sed "s/speedwm[.]/- speedwm./g" /tmp/example.Xresources > /tmp/example.Xresources.tmp && \
mv /tmp/example.Xresources.tmp /tmp/example.Xresources mv /tmp/example.Xresources.tmp /tmp/example.Xresources

View file

@ -1053,6 +1053,14 @@ speedwm.tag.urgentwindows: 1
speedwm.tiling.resizehints: 0 speedwm.tiling.resizehints: 0
.IP \[bu] 2 .IP \[bu] 2
speedwm.run.shell: /bin/sh speedwm.run.shell: /bin/sh
.IP \[bu] 2
speedwm.status.hideemptymodule: 1
.IP \[bu] 2
speedwm.status.leftpadding:
.IP \[bu] 2
speedwm.status.rightpadding:
.IP \[bu] 2
speedwm.status.separator:
.SS Signals .SS Signals
.PP .PP
Thanks to the `fsignal' patch available on suckless.org\[cq]s website, Thanks to the `fsignal' patch available on suckless.org\[cq]s website,

View file

@ -432,6 +432,12 @@ typedef struct {
void *dst; void *dst;
} ResourcePref; } ResourcePref;
typedef struct {
char *name;
enum resource_type type;
void *dst;
} StatusResourcePref;
/* function declarations */ /* function declarations */
static void applyrules(Client *c); static void applyrules(Client *c);
static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc); static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc);

View file

@ -3,6 +3,10 @@
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#include "toggle.h"
#if USEXRESOURCES
#include <X11/Xresource.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -23,6 +27,16 @@ typedef struct {
unsigned int interval; unsigned int interval;
unsigned int signal; unsigned int signal;
} Module; } Module;
enum resource_type {
STRING = 0,
INTEGER = 1,
FLOAT = 2
};
typedef struct {
char *name;
enum resource_type type;
void *dst;
} StatusResourcePref;
/* this is only here so we can use status.h for clickstatus too */ /* this is only here so we can use status.h for clickstatus too */
typedef struct { typedef struct {
char* mcommand; char* mcommand;
@ -58,6 +72,14 @@ static volatile int statusContinue = 1;
static pthread_mutex_t write_mut = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t write_mut = PTHREAD_MUTEX_INITIALIZER;
static void (*writestatus) () = setroot; static void (*writestatus) () = setroot;
/* Xresources
* Basically dwmblocks version of https://dwm.suckless.org/patches/xresources/dwm-xresources-20210827-138b405.diff
*/
#if USEXRESOURCES
static void load_xresources(void);
static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
#endif
void replace(char *str, char old, char new) void replace(char *str, char old, char new)
{ {
@ -304,6 +326,66 @@ statusloop()
} }
} }
#if USEXRESOURCES
void
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
{
char *sdst = NULL;
int *idst = NULL;
float *fdst = NULL;
sdst = dst;
idst = dst;
fdst = dst;
char fullname[256];
char *type;
XrmValue ret;
snprintf(fullname, sizeof(fullname), "%s.%s", "speedwm.status", name);
fullname[sizeof(fullname) - 1] = '\0';
XrmGetResource(db, fullname, "*", &type, &ret);
if (!(ret.addr == NULL || strncmp("String", type, 64)))
{
switch (rtype) {
case STRING:
strcpy(sdst, ret.addr);
break;
case INTEGER:
*idst = strtoul(ret.addr, NULL, 10);
break;
case FLOAT:
*fdst = strtof(ret.addr, NULL);
break;
}
}
}
void
load_xresources(void)
{
char *resm;
XrmDatabase db;
StatusResourcePref *p;
Display *d = XOpenDisplay(NULL);
if (d) {
dpy = d;
}
resm = XResourceManagerString(dpy);
if (!resm)
return;
db = XrmGetStringDatabase(resm);
for (p = res; p < res + LENGTH(res); p++)
resource_load(db, p->name, p->type, p->dst);
XCloseDisplay(dpy);
}
#endif
#ifndef __OpenBSD__ #ifndef __OpenBSD__
void sighandler(int signum) void sighandler(int signum)
{ {
@ -339,6 +421,11 @@ int main(int argc, char** argv)
} }
} }
#if USEXRESOURCES
XrmInitialize();
load_xresources();
#endif
signal(SIGTERM, termhandler); signal(SIGTERM, termhandler);
signal(SIGINT, termhandler); signal(SIGINT, termhandler);
statusloop(); statusloop();

View file

@ -24,9 +24,9 @@ static const Module modules[] = {
{ "<\x03", "module_bat --print", 2, 3 }, { "<\x03", "module_bat --print", 2, 3 },
{ "<\x04", "module_vol --print", 1, 4 }, { "<\x04", "module_vol --print", 1, 4 },
{ "<\x05", "module_ram --print", 6, 5 }, { "<\x05", "module_ram --print", 6, 5 },
//{ "<\x01", "module_net --print", 10, 6 }, { "<\x01", "module_net --print", 10, 6 },
{ "<\x02", "module_temp --print", 5, 7 }, { "<\x02", "module_temp --print", 5, 7 },
//{ "<\x03", "module_weather --print", 60, 8 }, { "<\x03", "module_weather --print", 60, 8 },
{ "<\x04", "module_music --print", 1, 9 }, { "<\x04", "module_music --print", 1, 9 },
{ "<\x05", "module_dfmpeg --print", 5, 10 }, { "<\x05", "module_dfmpeg --print", 5, 10 },
{ "<\x01", "module_news --print", 30, 11 }, { "<\x01", "module_news --print", 30, 11 },
@ -76,3 +76,11 @@ static const ClickStatus clickstatuss[] = {
{ "module_news --click", 11 }, { "module_news --click", 11 },
{ "module_email --click", 12 }, { "module_email --click", 12 },
}; };
/* .Xresources values to load */
StatusResourcePref res[] = {
{ "hideemptymodule", INTEGER, &hideemptymodule },
{ "leftpadding", STRING, &leftpadding },
{ "rightpadding", STRING, &rightpadding },
{ "separator", STRING, &separator },
};