add .Xresources support to speedwm status
This commit is contained in:
parent
b0b2a697a2
commit
da23f22fa5
10
Makefile
10
Makefile
|
@ -127,7 +127,7 @@ install: all
|
||||||
modules_install:
|
modules_install:
|
||||||
cp -f modules/module_* ${DESTDIR}${PREFIX}/bin
|
cp -f modules/module_* ${DESTDIR}${PREFIX}/bin
|
||||||
chmod +x ${DESTDIR}${PREFIX}/bin/module_*
|
chmod +x ${DESTDIR}${PREFIX}/bin/module_*
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -rf ${DESTDIR}${PREFIX}/bin/speedwm* ${DESTDIR}${PREFIX}/bin/speedwm-stellar ${DESTDIR}${PREFIX}/bin/module_*
|
rm -rf ${DESTDIR}${PREFIX}/bin/speedwm* ${DESTDIR}${PREFIX}/bin/speedwm-stellar ${DESTDIR}${PREFIX}/bin/module_*
|
||||||
rm -rf ${DESTDIR}${MANPREFIX}/man1/speedwm.1
|
rm -rf ${DESTDIR}${MANPREFIX}/man1/speedwm.1
|
||||||
|
@ -205,7 +205,7 @@ upload:
|
||||||
|
|
||||||
page:
|
page:
|
||||||
make page_php
|
make page_php
|
||||||
|
|
||||||
page_html:
|
page_html:
|
||||||
chmod +x scripts/speedwm-mkpage
|
chmod +x scripts/speedwm-mkpage
|
||||||
chmod +x scripts/speedwm-help
|
chmod +x scripts/speedwm-help
|
||||||
|
@ -223,7 +223,7 @@ page_install:
|
||||||
make previmg_install
|
make previmg_install
|
||||||
make css_install
|
make css_install
|
||||||
@echo "Copied readme.html/php to ${PAGEDIR}."
|
@echo "Copied readme.html/php to ${PAGEDIR}."
|
||||||
|
|
||||||
previmg_install:
|
previmg_install:
|
||||||
[ -f docs/preview.png ] && cp -f docs/preview.png ${PAGEDIR}
|
[ -f docs/preview.png ] && cp -f docs/preview.png ${PAGEDIR}
|
||||||
@echo "Copied preview image to ${PAGEDIR}/preview.png"
|
@echo "Copied preview image to ${PAGEDIR}/preview.png"
|
||||||
|
@ -242,7 +242,7 @@ html:
|
||||||
chmod +x scripts/speedwm-mkpage
|
chmod +x scripts/speedwm-mkpage
|
||||||
chmod +x scripts/speedwm-help
|
chmod +x scripts/speedwm-help
|
||||||
./scripts/speedwm-mkpage --make-html
|
./scripts/speedwm-mkpage --make-html
|
||||||
|
|
||||||
php:
|
php:
|
||||||
chmod +x scripts/speedwm-mkpage
|
chmod +x scripts/speedwm-mkpage
|
||||||
chmod +x scripts/speedwm-help
|
chmod +x scripts/speedwm-help
|
||||||
|
@ -253,7 +253,7 @@ markdown:
|
||||||
chmod +x scripts/speedwm-mkpage
|
chmod +x scripts/speedwm-mkpage
|
||||||
chmod +x scripts/speedwm-help
|
chmod +x scripts/speedwm-help
|
||||||
./scripts/speedwm-mkpage --make-markdown
|
./scripts/speedwm-mkpage --make-markdown
|
||||||
|
|
||||||
man:
|
man:
|
||||||
chmod +x scripts/speedwm-mkpage
|
chmod +x scripts/speedwm-mkpage
|
||||||
chmod +x scripts/speedwm-help
|
chmod +x scripts/speedwm-help
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ FORMATMANPAGE() {
|
||||||
mv ../README.md ../README.md.orig
|
mv ../README.md ../README.md.orig
|
||||||
printf "%% speedwm(1) $VERSION | speedie's window manager.\n" > ../README.md
|
printf "%% speedwm(1) $VERSION | speedie's window manager.\n" > ../README.md
|
||||||
grep -v "docs/preview" ../README.md.orig >> ../README.md
|
grep -v "docs/preview" ../README.md.orig >> ../README.md
|
||||||
|
|
||||||
pandoc --standalone --to man ../README.md -o ../speedwm.1
|
pandoc --standalone --to man ../README.md -o ../speedwm.1
|
||||||
|
|
||||||
printf "Man page generated at ../speedwm.1.\n"
|
printf "Man page generated at ../speedwm.1.\n"
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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);
|
||||||
|
|
87
status.c
87
status.c
|
@ -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();
|
||||||
|
|
12
status.h
12
status.h
|
@ -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 },
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue