mirror of
https://github.com/mintycube/slock.git
synced 2024-10-22 14:05:51 +02:00
Adding xresources patch
This commit is contained in:
parent
2cf80900da
commit
4c905a9c07
@ -15,6 +15,8 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/)
|
|||||||
|
|
||||||
### Changelog:
|
### Changelog:
|
||||||
|
|
||||||
|
2019-11-27 - Added xresources patch
|
||||||
|
|
||||||
2019-10-17 - Added capscolor, control clear, dpms, mediakeys, message, pam auth, quickcancel patches
|
2019-10-17 - Added capscolor, control clear, dpms, mediakeys, message, pam auth, quickcancel patches
|
||||||
|
|
||||||
2019-10-16 - Introduced [flexipatch-finalizer](https://github.com/bakkeby/flexipatch-finalizer)
|
2019-10-16 - Introduced [flexipatch-finalizer](https://github.com/bakkeby/flexipatch-finalizer)
|
||||||
@ -52,3 +54,6 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/)
|
|||||||
- [unlockscreen](https://tools.suckless.org/slock/patches/unlock_screen/)
|
- [unlockscreen](https://tools.suckless.org/slock/patches/unlock_screen/)
|
||||||
- this patch keeps the screen unlocked, but keeps the input locked
|
- this patch keeps the screen unlocked, but keeps the input locked
|
||||||
- that is, the screen is not affected by slock, but users will not be able to interact with the X session unless they enter the correct password
|
- that is, the screen is not affected by slock, but users will not be able to interact with the X session unless they enter the correct password
|
||||||
|
|
||||||
|
- [xresources](https://tools.suckless.org/slock/patches/xresources/)
|
||||||
|
- this patch adds the ability to get colors via Xresources
|
19
config.def.h
19
config.def.h
@ -11,9 +11,26 @@ static const char *colorname[NUMCOLS] = {
|
|||||||
#endif // CAPSCOLOR_PATCH
|
#endif // CAPSCOLOR_PATCH
|
||||||
#if PAMAUTH_PATCH
|
#if PAMAUTH_PATCH
|
||||||
[PAM] = "#9400D3", /* waiting for PAM */
|
[PAM] = "#9400D3", /* waiting for PAM */
|
||||||
#endif // CAPSCOLOR_PATCH
|
#endif // PAMAUTH_PATCH
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if XRESOURCES_PATCH
|
||||||
|
/*
|
||||||
|
* Xresources preferences to load at startup
|
||||||
|
*/
|
||||||
|
ResourcePref resources[] = {
|
||||||
|
{ "color0", STRING, &colorname[INIT] },
|
||||||
|
{ "color4", STRING, &colorname[INPUT] },
|
||||||
|
{ "color1", STRING, &colorname[FAILED] },
|
||||||
|
#if CAPSCOLOR_PATCH
|
||||||
|
{ "color3", STRING, &colorname[CAPS] },
|
||||||
|
#endif // CAPSCOLOR_PATCH
|
||||||
|
#if PAMAUTH_PATCH
|
||||||
|
{ "color5", STRING, &colorname[PAM] },
|
||||||
|
#endif // PAMAUTH_PATCH
|
||||||
|
};
|
||||||
|
#endif // XRESOURCES_PATCH
|
||||||
|
|
||||||
/* treat a cleared input like a wrong password (color) */
|
/* treat a cleared input like a wrong password (color) */
|
||||||
static const int failonclear = 1;
|
static const int failonclear = 1;
|
||||||
|
|
||||||
|
@ -10,3 +10,7 @@
|
|||||||
#if PAMAUTH_PATCH
|
#if PAMAUTH_PATCH
|
||||||
#include "pamauth.c"
|
#include "pamauth.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if XRESOURCES_PATCH
|
||||||
|
#include "xresources.c"
|
||||||
|
#endif
|
@ -2,3 +2,7 @@
|
|||||||
#if PAMAUTH_PATCH
|
#if PAMAUTH_PATCH
|
||||||
#include "pamauth.h"
|
#include "pamauth.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if XRESOURCES_PATCH
|
||||||
|
#include "xresources.h"
|
||||||
|
#endif
|
52
patch/xresources.c
Normal file
52
patch/xresources.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
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", "slock", name);
|
||||||
|
snprintf(fullclass, sizeof(fullclass), "%s.%s", "Slock", 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
|
||||||
|
config_init(Display *dpy)
|
||||||
|
{
|
||||||
|
char *resm;
|
||||||
|
XrmDatabase db;
|
||||||
|
ResourcePref *p;
|
||||||
|
|
||||||
|
XrmInitialize();
|
||||||
|
resm = XResourceManagerString(dpy);
|
||||||
|
if (!resm)
|
||||||
|
return;
|
||||||
|
|
||||||
|
db = XrmGetStringDatabase(resm);
|
||||||
|
for (p = resources; p < resources + LEN(resources); p++)
|
||||||
|
resource_load(db, p->name, p->type, p->dst);
|
||||||
|
}
|
17
patch/xresources.h
Normal file
17
patch/xresources.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include <X11/Xresource.h>
|
||||||
|
|
||||||
|
/* macros */
|
||||||
|
#define LEN(a) (sizeof(a) / sizeof(a)[0])
|
||||||
|
|
||||||
|
/* Xresources preferences */
|
||||||
|
enum resource_type {
|
||||||
|
STRING = 0,
|
||||||
|
INTEGER = 1,
|
||||||
|
FLOAT = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
enum resource_type type;
|
||||||
|
void *dst;
|
||||||
|
} ResourcePref;
|
@ -73,3 +73,8 @@
|
|||||||
* https://tools.suckless.org/slock/patches/unlock_screen/
|
* https://tools.suckless.org/slock/patches/unlock_screen/
|
||||||
*/
|
*/
|
||||||
#define UNLOCKSCREEN_PATCH 0
|
#define UNLOCKSCREEN_PATCH 0
|
||||||
|
|
||||||
|
/* This patch adds the ability to get colors via Xresources.
|
||||||
|
* https://tools.suckless.org/slock/patches/xresources/
|
||||||
|
*/
|
||||||
|
#define XRESOURCES_PATCH 0
|
||||||
|
4
slock.c
4
slock.c
@ -514,6 +514,10 @@ main(int argc, char **argv) {
|
|||||||
if (setuid(duid) < 0)
|
if (setuid(duid) < 0)
|
||||||
die("slock: setuid: %s\n", strerror(errno));
|
die("slock: setuid: %s\n", strerror(errno));
|
||||||
|
|
||||||
|
#if XRESOURCES_PATCH
|
||||||
|
config_init(dpy);
|
||||||
|
#endif // XRESOURCES_PATCH
|
||||||
|
|
||||||
/* check for Xrandr support */
|
/* check for Xrandr support */
|
||||||
rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
|
rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user