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
|
||||
#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:
|
||||
|
||||
2021-06-08 - Added the color message patch
|
||||
|
||||
2020-08-03 - Added alpha, keypress_feedback and blur_pixelated_screen patches
|
||||
|
||||
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/)
|
||||
- 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/)
|
||||
- with this patch slock will no 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 and don't want to spoil the detection of failed unlocking attempts
|
||||
- with this patch slock will no 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 and
|
||||
don't want to spoil the detection of failed unlocking attempts
|
||||
|
||||
- [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
|
||||
- the monitor will automatically be activated by pressing a key or moving the mouse and the password can be entered then
|
||||
- interacts with the Display Power Signaling and automatically shuts down the monitor after a
|
||||
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/)
|
||||
- draws random blocks on the screen to display keypress feedback
|
||||
|
||||
- [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/)
|
||||
- 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/)
|
||||
- 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
|
||||
- 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/)
|
||||
- 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/)
|
||||
- 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
|
||||
|
@ -76,7 +76,7 @@ static const int blocks_y = 0;
|
||||
static const int blocks_count = 10;
|
||||
#endif // KEYPRESS_FEEDBACK_PATCH
|
||||
|
||||
#if MESSAGE_PATCH
|
||||
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||
/* default message */
|
||||
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) */
|
||||
static const char * font_name = "6x10";
|
||||
#endif // MESSAGE_PATCH
|
||||
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||
|
||||
#if PAMAUTH_PATCH
|
||||
/* PAM service that's used for authentication */
|
||||
|
@ -10,7 +10,7 @@ MANPREFIX = ${PREFIX}/share/man
|
||||
X11INC = /usr/X11R6/include
|
||||
X11LIB = /usr/X11R6/lib
|
||||
|
||||
# Uncomment for message patch / MESSAGE_PATCH
|
||||
# Uncomment for message patch / MESSAGE_PATCH / COLORMESSAGE_PATCH
|
||||
#XINERAMA=-lXinerama
|
||||
|
||||
# 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"
|
||||
#endif
|
||||
|
||||
#if MESSAGE_PATCH
|
||||
#if COLOR_MESSAGE_PATCH
|
||||
#include "colormessage.c"
|
||||
#elif MESSAGE_PATCH
|
||||
#include "message.c"
|
||||
#endif
|
||||
|
||||
|
@ -26,7 +26,7 @@ writemessage(Display *dpy, Window win, int screen)
|
||||
tab_size = 8 * XTextWidth(fontinfo, " ", 1);
|
||||
|
||||
XAllocNamedColor(dpy, DefaultColormap(dpy, screen),
|
||||
text_color, &color, &dummy);
|
||||
text_color, &color, &dummy);
|
||||
|
||||
gr_values.font = fontinfo->fid;
|
||||
gr_values.foreground = color.pixel;
|
||||
@ -90,5 +90,5 @@ writemessage(Display *dpy, Window win, int screen)
|
||||
|
||||
/* xsi should not be NULL anyway if Xinerama is active, but to be safe */
|
||||
if (XineramaIsActive(dpy) && xsi != NULL)
|
||||
XFree(xsi);
|
||||
XFree(xsi);
|
||||
}
|
@ -28,6 +28,22 @@
|
||||
*/
|
||||
#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
|
||||
* 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
|
||||
|
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]);
|
||||
#endif // BLUR_PIXELATED_SCREEN_PATCH
|
||||
XClearWindow(dpy, locks[screen]->win);
|
||||
#if MESSAGE_PATCH
|
||||
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||
writemessage(dpy, locks[screen]->win, screen);
|
||||
#endif // MESSAGE_PATCH
|
||||
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||
}
|
||||
oldc = color;
|
||||
}
|
||||
@ -471,11 +471,11 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
#if MESSAGE_PATCH
|
||||
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||
die("usage: slock [-v] [-f] [-m message] [cmd [arg ...]]\n");
|
||||
#else
|
||||
die("usage: slock [-v] [cmd [arg ...]]\n");
|
||||
#endif // MESSAGE_PATCH
|
||||
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||
}
|
||||
|
||||
int
|
||||
@ -492,15 +492,15 @@ main(int argc, char **argv) {
|
||||
#if DPMS_PATCH
|
||||
CARD16 standby, suspend, off;
|
||||
#endif // DPMS_PATCH
|
||||
#if MESSAGE_PATCH
|
||||
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||
int i, count_fonts;
|
||||
char **font_names;
|
||||
#endif // MESSAGE_PATCH
|
||||
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||
ARGBEGIN {
|
||||
case 'v':
|
||||
fprintf(stderr, "slock-"VERSION"\n");
|
||||
return 0;
|
||||
#if MESSAGE_PATCH
|
||||
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||
case 'm':
|
||||
message = EARGF(usage());
|
||||
break;
|
||||
@ -512,7 +512,7 @@ main(int argc, char **argv) {
|
||||
fprintf(stderr, "%s\n", *(font_names+i));
|
||||
}
|
||||
return 0;
|
||||
#endif // MESSAGE_PATCH
|
||||
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||
default:
|
||||
usage();
|
||||
} ARGEND
|
||||
@ -576,9 +576,9 @@ main(int argc, char **argv) {
|
||||
die("slock: out of memory\n");
|
||||
for (nlocks = 0, s = 0; s < nscreens; s++) {
|
||||
if ((locks[s] = lockscreen(dpy, &rr, s)) != NULL) {
|
||||
#if MESSAGE_PATCH
|
||||
#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH
|
||||
writemessage(dpy, locks[s]->win, s);
|
||||
#endif // MESSAGE_PATCH
|
||||
#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH
|
||||
nlocks++;
|
||||
} else {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user