mirror of
https://github.com/mintycube/slock.git
synced 2024-10-22 14:05:51 +02:00
Adding color message patch ref. #3
This commit is contained in:
parent
ce8387f52c
commit
d2be9eb632
51
README.md
51
README.md
@ -1,20 +1,33 @@
|
|||||||
Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this slock 1.4 (701aa9, 2017-03-25) project has a different take on patching. It uses preprocessor directives to decide whether or not to include a patch during build time. Essentially this means that this build, for better or worse, contains both the patched _and_ the original code. The aim being that you can select which patches to include and the build will contain that code and nothing more.
|
Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this slock 1.4 (701aa9,
|
||||||
|
2017-03-25) project has a different take on patching. It uses preprocessor directives to decide
|
||||||
|
whether or not to include a patch during build time. Essentially this means that this build, for
|
||||||
|
better or worse, contains both the patched _and_ the original code. The aim being that you can
|
||||||
|
select which patches to include and the build will contain that code and nothing more.
|
||||||
|
|
||||||
For example to include the `capscolor` patch then you would only need to flip this setting from 0 to 1 in [patches.h](https://github.com/bakkeby/slock-flexipatch/blob/master/patches.h):
|
For example to include the `capscolor` patch then you would only need to flip this setting from 0
|
||||||
|
to 1 in [patches.h](https://github.com/bakkeby/slock-flexipatch/blob/master/patches.h):
|
||||||
```c
|
```c
|
||||||
#define CAPSCOLOR_PATCH 1
|
#define CAPSCOLOR_PATCH 1
|
||||||
```
|
```
|
||||||
|
|
||||||
Once you have found out what works for you and what doesn't then you should be in a better position to choose patches should you want to start patching from scratch.
|
Once you have found out what works for you and what doesn't then you should be in a better position
|
||||||
|
to choose patches should you want to start patching from scratch.
|
||||||
|
|
||||||
Alternatively if you have found the patches you want, but don't want the rest of the flexipatch entanglement on your plate then you may want to have a look at [flexipatch-finalizer](https://github.com/bakkeby/flexipatch-finalizer); a custom pre-processor tool that removes all the unused flexipatch code leaving you with a build that contains the patches you selected.
|
Alternatively if you have found the patches you want, but don't want the rest of the flexipatch
|
||||||
|
entanglement on your plate then you may want to have a look at
|
||||||
|
[flexipatch-finalizer](https://github.com/bakkeby/flexipatch-finalizer); a custom pre-processor
|
||||||
|
tool that removes all the unused flexipatch code leaving you with a build that contains the patches
|
||||||
|
you selected.
|
||||||
|
|
||||||
Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/) for details on the slock tool, how to install it and how it works.
|
Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/) for details on the
|
||||||
|
slock tool, how to install it and how it works.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Changelog:
|
### Changelog:
|
||||||
|
|
||||||
|
2021-06-08 - Added the color message patch
|
||||||
|
|
||||||
2020-08-03 - Added alpha, keypress_feedback and blur_pixelated_screen patches
|
2020-08-03 - Added alpha, keypress_feedback and blur_pixelated_screen patches
|
||||||
|
|
||||||
2019-11-27 - Added xresources patch
|
2019-11-27 - Added xresources patch
|
||||||
@ -35,19 +48,28 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/)
|
|||||||
- [capscolor](https://tools.suckless.org/slock/patches/capscolor/)
|
- [capscolor](https://tools.suckless.org/slock/patches/capscolor/)
|
||||||
- adds an additional color to indicate the state of Caps Lock
|
- adds an additional color to indicate the state of Caps Lock
|
||||||
|
|
||||||
|
- [color-message](https://tools.suckless.org/slock/patches/colormessage/)
|
||||||
|
- based on the message patch this patch lets you add a message to your lock screen using
|
||||||
|
24-bit color ANSI escape codes
|
||||||
|
|
||||||
- [control-clear](https://tools.suckless.org/slock/patches/control-clear/)
|
- [control-clear](https://tools.suckless.org/slock/patches/control-clear/)
|
||||||
- with this patch slock will no longer change to the failure color if a control key is pressed while the buffer is empty
|
- with this patch slock will no longer change to the failure color if a control key is pressed
|
||||||
- this may be useful if, for example, you wake your monitor up by pressing a control key and don't want to spoil the detection of failed unlocking attempts
|
while the buffer is empty
|
||||||
|
- this may be useful if, for example, you wake your monitor up by pressing a control key and
|
||||||
|
don't want to spoil the detection of failed unlocking attempts
|
||||||
|
|
||||||
- [dpms](https://tools.suckless.org/slock/patches/dpms/)
|
- [dpms](https://tools.suckless.org/slock/patches/dpms/)
|
||||||
- interacts with the Display Power Signaling and automatically shuts down the monitor after a configurable amount of seconds
|
- interacts with the Display Power Signaling and automatically shuts down the monitor after a
|
||||||
- the monitor will automatically be activated by pressing a key or moving the mouse and the password can be entered then
|
configurable amount of seconds
|
||||||
|
- the monitor will automatically be activated by pressing a key or moving the mouse and the
|
||||||
|
password can be entered then
|
||||||
|
|
||||||
- [keypress_feedback](https://tools.suckless.org/slock/patches/keypress-feedback/)
|
- [keypress_feedback](https://tools.suckless.org/slock/patches/keypress-feedback/)
|
||||||
- draws random blocks on the screen to display keypress feedback
|
- draws random blocks on the screen to display keypress feedback
|
||||||
|
|
||||||
- [mediakeys](https://tools.suckless.org/slock/patches/mediakeys/)
|
- [mediakeys](https://tools.suckless.org/slock/patches/mediakeys/)
|
||||||
- allows media keys to be used while the screen is locked, e.g. adjust volume or skip to the next song without having to unlock the screen first
|
- allows media keys to be used while the screen is locked, e.g. adjust volume or skip to the
|
||||||
|
next song without having to unlock the screen first
|
||||||
|
|
||||||
- [message](https://tools.suckless.org/slock/patches/message/)
|
- [message](https://tools.suckless.org/slock/patches/message/)
|
||||||
- this patch lets you add a custom message to your lock screen
|
- this patch lets you add a custom message to your lock screen
|
||||||
@ -58,14 +80,17 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/)
|
|||||||
- [quickcancel](https://tools.suckless.org/slock/patches/quickcancel/)
|
- [quickcancel](https://tools.suckless.org/slock/patches/quickcancel/)
|
||||||
- cancel slock by moving the mouse within a certain time-period after slock started
|
- cancel slock by moving the mouse within a certain time-period after slock started
|
||||||
- the time-period can be defined in seconds with the setting timetocancel in the config.h
|
- the time-period can be defined in seconds with the setting timetocancel in the config.h
|
||||||
- this can be useful if you forgot to disable xautolock during an activity that requires no input (e.g. reading text, watching video, etc.)
|
- this can be useful if you forgot to disable xautolock during an activity that requires no
|
||||||
|
input (e.g. reading text, watching video, etc.)
|
||||||
|
|
||||||
- [terminalkeys](https://tools.suckless.org/slock/patches/terminalkeys/)
|
- [terminalkeys](https://tools.suckless.org/slock/patches/terminalkeys/)
|
||||||
- adds key commands that are commonly used in terminal applications (in particular the login prompt)
|
- adds key commands that are commonly used in terminal applications (in particular the login
|
||||||
|
prompt)
|
||||||
|
|
||||||
- [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/)
|
- [xresources](https://tools.suckless.org/slock/patches/xresources/)
|
||||||
- this patch adds the ability to get colors via Xresources
|
- this patch adds the ability to get colors via Xresources
|
||||||
|
@ -76,7 +76,7 @@ static const int blocks_y = 0;
|
|||||||
static const int blocks_count = 10;
|
static const int blocks_count = 10;
|
||||||
#endif // KEYPRESS_FEEDBACK_PATCH
|
#endif // KEYPRESS_FEEDBACK_PATCH
|
||||||
|
|
||||||
#if MESSAGE_PATCH
|
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||||
/* default message */
|
/* default message */
|
||||||
static const char * message = "Suckless: Software that sucks less.";
|
static const char * message = "Suckless: Software that sucks less.";
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ static const char * text_color = "#ffffff";
|
|||||||
|
|
||||||
/* text size (must be a valid size) */
|
/* text size (must be a valid size) */
|
||||||
static const char * font_name = "6x10";
|
static const char * font_name = "6x10";
|
||||||
#endif // MESSAGE_PATCH
|
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||||
|
|
||||||
#if PAMAUTH_PATCH
|
#if PAMAUTH_PATCH
|
||||||
/* PAM service that's used for authentication */
|
/* PAM service that's used for authentication */
|
||||||
|
@ -10,7 +10,7 @@ MANPREFIX = ${PREFIX}/share/man
|
|||||||
X11INC = /usr/X11R6/include
|
X11INC = /usr/X11R6/include
|
||||||
X11LIB = /usr/X11R6/lib
|
X11LIB = /usr/X11R6/lib
|
||||||
|
|
||||||
# Uncomment for message patch / MESSAGE_PATCH
|
# Uncomment for message patch / MESSAGE_PATCH / COLORMESSAGE_PATCH
|
||||||
#XINERAMA=-lXinerama
|
#XINERAMA=-lXinerama
|
||||||
|
|
||||||
# Uncomment for pam auth patch / PAMAUTH_PATCH
|
# Uncomment for pam auth patch / PAMAUTH_PATCH
|
||||||
|
128
patch/colormessage.c
Normal file
128
patch/colormessage.c
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
#include <X11/extensions/Xinerama.h>
|
||||||
|
|
||||||
|
/* global count to prevent repeated error messages */
|
||||||
|
int count_error = 0;
|
||||||
|
|
||||||
|
static int
|
||||||
|
readescapedint(const char *str, int *i) {
|
||||||
|
int n = 0;
|
||||||
|
if (str[*i])
|
||||||
|
++*i;
|
||||||
|
while(str[*i] && str[*i] != ';' && str[*i] != 'm') {
|
||||||
|
n = 10 * n + str[*i] - '0';
|
||||||
|
++*i;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
writemessage(Display *dpy, Window win, int screen)
|
||||||
|
{
|
||||||
|
int len, line_len, width, height, s_width, s_height, i, k, tab_size, r, g, b, escaped_int, curr_line_len;
|
||||||
|
XGCValues gr_values;
|
||||||
|
XFontStruct *fontinfo;
|
||||||
|
XColor color, dummy;
|
||||||
|
XineramaScreenInfo *xsi;
|
||||||
|
GC gc;
|
||||||
|
fontinfo = XLoadQueryFont(dpy, font_name);
|
||||||
|
|
||||||
|
if (fontinfo == NULL) {
|
||||||
|
if (count_error == 0) {
|
||||||
|
fprintf(stderr, "slock: Unable to load font \"%s\"\n", font_name);
|
||||||
|
fprintf(stderr, "slock: Try listing fonts with 'slock -f'\n");
|
||||||
|
count_error++;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tab_size = 8 * XTextWidth(fontinfo, " ", 1);
|
||||||
|
|
||||||
|
XAllocNamedColor(dpy, DefaultColormap(dpy, screen),
|
||||||
|
text_color, &color, &dummy);
|
||||||
|
|
||||||
|
gr_values.font = fontinfo->fid;
|
||||||
|
gr_values.foreground = color.pixel;
|
||||||
|
gc=XCreateGC(dpy,win,GCFont+GCForeground, &gr_values);
|
||||||
|
|
||||||
|
/* To prevent "Uninitialized" warnings. */
|
||||||
|
xsi = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start formatting and drawing text
|
||||||
|
*/
|
||||||
|
|
||||||
|
len = strlen(message);
|
||||||
|
|
||||||
|
/* Max max line length (cut at '\n') */
|
||||||
|
line_len = curr_line_len = 0;
|
||||||
|
k = 0;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
if (message[i] == '\n') {
|
||||||
|
curr_line_len = 0;
|
||||||
|
k++;
|
||||||
|
} else if (message[i] == 0x1b) {
|
||||||
|
while (i < len && message[i] != 'm') {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i == len)
|
||||||
|
die("slock: unclosed escape sequence\n");
|
||||||
|
} else {
|
||||||
|
curr_line_len += XTextWidth(fontinfo, message + i, 1);
|
||||||
|
if (curr_line_len > line_len)
|
||||||
|
line_len = curr_line_len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* If there is only one line */
|
||||||
|
if (line_len == 0)
|
||||||
|
line_len = len;
|
||||||
|
|
||||||
|
if (XineramaIsActive(dpy)) {
|
||||||
|
xsi = XineramaQueryScreens(dpy, &i);
|
||||||
|
s_width = xsi[0].width;
|
||||||
|
s_height = xsi[0].height;
|
||||||
|
} else {
|
||||||
|
s_width = DisplayWidth(dpy, screen);
|
||||||
|
s_height = DisplayHeight(dpy, screen);
|
||||||
|
}
|
||||||
|
height = s_height*3/7 - (k*20)/3;
|
||||||
|
width = (s_width - line_len)/2;
|
||||||
|
|
||||||
|
line_len = 0;
|
||||||
|
/* print the text while parsing 24 bit color ANSI escape codes*/
|
||||||
|
for (i = k = 0; i < len; i++) {
|
||||||
|
switch (message[i]) {
|
||||||
|
case '\n':
|
||||||
|
line_len = 0;
|
||||||
|
while (message[i + 1] == '\t') {
|
||||||
|
line_len += tab_size;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
break;
|
||||||
|
case 0x1b:
|
||||||
|
i++;
|
||||||
|
if (message[i] == '[') {
|
||||||
|
escaped_int = readescapedint(message, &i);
|
||||||
|
if (escaped_int == 39)
|
||||||
|
continue;
|
||||||
|
if (escaped_int != 38)
|
||||||
|
die("slock: unknown escape sequence%d\n", escaped_int);
|
||||||
|
if (readescapedint(message, &i) != 2)
|
||||||
|
die("slock: only 24 bit color supported\n");
|
||||||
|
r = readescapedint(message, &i) & 0xff;
|
||||||
|
g = readescapedint(message, &i) & 0xff;
|
||||||
|
b = readescapedint(message, &i) & 0xff;
|
||||||
|
XSetForeground(dpy, gc, r << 16 | g << 8 | b);
|
||||||
|
} else
|
||||||
|
die("slock: unknown escape sequence\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
XDrawString(dpy, win, gc, width + line_len, height + 20 * k, message + i, 1);
|
||||||
|
line_len += XTextWidth(fontinfo, message + i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* xsi should not be NULL anyway if Xinerama is active, but to be safe */
|
||||||
|
if (XineramaIsActive(dpy) && xsi != NULL)
|
||||||
|
XFree(xsi);
|
||||||
|
}
|
@ -3,7 +3,9 @@
|
|||||||
#include "blur_pixelated_screen.c"
|
#include "blur_pixelated_screen.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MESSAGE_PATCH
|
#if COLOR_MESSAGE_PATCH
|
||||||
|
#include "colormessage.c"
|
||||||
|
#elif MESSAGE_PATCH
|
||||||
#include "message.c"
|
#include "message.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -28,6 +28,22 @@
|
|||||||
*/
|
*/
|
||||||
#define CAPSCOLOR_PATCH 0
|
#define CAPSCOLOR_PATCH 0
|
||||||
|
|
||||||
|
/* Based on the message patch this patch lets you add a message to your lock screen using 24 bit
|
||||||
|
* color ANSI escape codes.
|
||||||
|
*
|
||||||
|
* You can place a default message in config.h and you can also pass a message with the -m command
|
||||||
|
* line option.
|
||||||
|
*
|
||||||
|
* Practical example:
|
||||||
|
* slock -m "$(printf "text colored \x1b[38;2;0;255;0m green\x1b[39m\n")"
|
||||||
|
*
|
||||||
|
* If you enable this then you also need to add the -lXinerama library to the LIBS
|
||||||
|
* configuration in config.mk. Look for and uncomment the XINERAMA placeholder.
|
||||||
|
*
|
||||||
|
* https://tools.suckless.org/slock/patches/colormessage/
|
||||||
|
*/
|
||||||
|
#define COLOR_MESSAGE_PATCH 0
|
||||||
|
|
||||||
/* Adds an additional configuration parameter, controlkeyclear. When set to 1, slock will no
|
/* Adds an additional configuration parameter, controlkeyclear. When set to 1, slock will no
|
||||||
* longer change to the failure color if a control key is pressed while the buffer is empty.
|
* longer change to the failure color if a control key is pressed while the buffer is empty.
|
||||||
* This may be useful if, for example, you wake your monitor up by pressing a control key
|
* This may be useful if, for example, you wake your monitor up by pressing a control key
|
||||||
|
20
slock.c
20
slock.c
@ -338,9 +338,9 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
|
|||||||
locks[screen]->colors[color]);
|
locks[screen]->colors[color]);
|
||||||
#endif // BLUR_PIXELATED_SCREEN_PATCH
|
#endif // BLUR_PIXELATED_SCREEN_PATCH
|
||||||
XClearWindow(dpy, locks[screen]->win);
|
XClearWindow(dpy, locks[screen]->win);
|
||||||
#if MESSAGE_PATCH
|
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||||
writemessage(dpy, locks[screen]->win, screen);
|
writemessage(dpy, locks[screen]->win, screen);
|
||||||
#endif // MESSAGE_PATCH
|
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||||
}
|
}
|
||||||
oldc = color;
|
oldc = color;
|
||||||
}
|
}
|
||||||
@ -471,11 +471,11 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
|
|||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
#if MESSAGE_PATCH
|
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||||
die("usage: slock [-v] [-f] [-m message] [cmd [arg ...]]\n");
|
die("usage: slock [-v] [-f] [-m message] [cmd [arg ...]]\n");
|
||||||
#else
|
#else
|
||||||
die("usage: slock [-v] [cmd [arg ...]]\n");
|
die("usage: slock [-v] [cmd [arg ...]]\n");
|
||||||
#endif // MESSAGE_PATCH
|
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -492,15 +492,15 @@ main(int argc, char **argv) {
|
|||||||
#if DPMS_PATCH
|
#if DPMS_PATCH
|
||||||
CARD16 standby, suspend, off;
|
CARD16 standby, suspend, off;
|
||||||
#endif // DPMS_PATCH
|
#endif // DPMS_PATCH
|
||||||
#if MESSAGE_PATCH
|
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||||
int i, count_fonts;
|
int i, count_fonts;
|
||||||
char **font_names;
|
char **font_names;
|
||||||
#endif // MESSAGE_PATCH
|
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'v':
|
case 'v':
|
||||||
fprintf(stderr, "slock-"VERSION"\n");
|
fprintf(stderr, "slock-"VERSION"\n");
|
||||||
return 0;
|
return 0;
|
||||||
#if MESSAGE_PATCH
|
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||||
case 'm':
|
case 'm':
|
||||||
message = EARGF(usage());
|
message = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
@ -512,7 +512,7 @@ main(int argc, char **argv) {
|
|||||||
fprintf(stderr, "%s\n", *(font_names+i));
|
fprintf(stderr, "%s\n", *(font_names+i));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#endif // MESSAGE_PATCH
|
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND
|
} ARGEND
|
||||||
@ -576,9 +576,9 @@ main(int argc, char **argv) {
|
|||||||
die("slock: out of memory\n");
|
die("slock: out of memory\n");
|
||||||
for (nlocks = 0, s = 0; s < nscreens; s++) {
|
for (nlocks = 0, s = 0; s < nscreens; s++) {
|
||||||
if ((locks[s] = lockscreen(dpy, &rr, s)) != NULL) {
|
if ((locks[s] = lockscreen(dpy, &rr, s)) != NULL) {
|
||||||
#if MESSAGE_PATCH
|
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||||
writemessage(dpy, locks[s]->win, s);
|
writemessage(dpy, locks[s]->win, s);
|
||||||
#endif // MESSAGE_PATCH
|
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||||
nlocks++;
|
nlocks++;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user