diff --git a/.gitignore b/.gitignore index d79332d..322fc66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ slock *.o dwm -config.h -patches.h diff --git a/README.md b/README.md index 4de370b..a2e1532 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,11 @@ -Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this slock 1.5 (a34d8fb, -2023-10-06) 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. +

slock

-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. - -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. - ---- - -### Changelog: - -2022-03-28 - Added the background image patch - -2021-09-13 - Added the dwm logo patch - -2021-09-09 - Added the auto-timeout, failure-command and secret-password patches - -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 - -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) - -### Patches included: - - - [alpha](https://github.com/khuedoan/slock) - - enables transparency for slock - - intended to be combined with a compositor that can blur the transparent background - - - [auto-timeout](https://tools.suckless.org/slock/patches/auto-timeout/) - - allows for a command to be executed after a specified time of inactivity - - - [background_image](https://tools.suckless.org/slock/patches/background-image/) - - sets the lockscreen picture to a background image +Personal build of slock generated using [slock-flexipatch](https://github.com/bakkeby/slock-flexipatch.git) +### Patches applied: - [blur_pixelated_screen](https://tools.suckless.org/slock/patches/blur-pixelated-screen/) - sets the lockscreen picture to a blured or pixelated screenshot - - [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 @@ -79,39 +21,9 @@ slock tool, how to install it and how it works. - [dwmlogo](https://tools.suckless.org/slock/patches/dwmlogo/) - draws the dwm logo which changes color based on the state - - [failure-command](https://tools.suckless.org/slock/patches/failure-command/) - - allows for a command to be run after a specified number of incorrect attempts - - - [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 - - [message](https://tools.suckless.org/slock/patches/message/) - - this patch lets you add a custom message to your lock screen - - - [pam-auth](https://tools.suckless.org/slock/patches/pam_auth/) - - replaces shadow support with PAM authentication support - - - [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.) - - - [secret-password](https://tools.suckless.org/slock/patches/secret-password/) - - allows for commands to be executed when the user enters special passwords - - - [terminalkeys](https://tools.suckless.org/slock/patches/terminalkeys/) - - 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 - - [xresources](https://tools.suckless.org/slock/patches/xresources/) - this patch adds the ability to get colors via Xresources diff --git a/config.h b/config.h new file mode 100644 index 0000000..b038ed7 --- /dev/null +++ b/config.h @@ -0,0 +1,164 @@ +/* user and group to drop privileges to */ +static const char *user = "nobody"; +static const char *group = "nobody"; // use "nobody" for arch + +static const char *colorname[NUMCOLS] = { + #if DWM_LOGO_PATCH && !BLUR_PIXELATED_SCREEN_PATCH + [BACKGROUND] = "#2d2d2d", /* after initialization */ + #endif // DWM_LOGO_PATCH + [INIT] = "black", /* after initialization */ + [INPUT] = "#005577", /* during input */ + [FAILED] = "#CC3333", /* wrong password */ + #if CAPSCOLOR_PATCH + [CAPS] = "red", /* CapsLock on */ + #endif // CAPSCOLOR_PATCH + #if PAMAUTH_PATCH + [PAM] = "#9400D3", /* waiting for PAM */ + #endif // PAMAUTH_PATCH + #if KEYPRESS_FEEDBACK_PATCH + [BLOCKS] = "#ffffff", /* key feedback block */ + #endif // KEYPRESS_FEEDBACK_PATCH +}; + +#if MESSAGE_PATCH || COLOR_MESSAGE_PATCH +/* default message */ +static const char * message = "Suckless: Software that sucks less."; + +/* text color */ +static const char * text_color = "#ffffff"; + +/* text size (must be a valid size) */ +static const char * font_name = "6x10"; +#endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH + +#if BACKGROUND_IMAGE_PATCH +/* Background image path, should be available to the user above */ +static const char * background_image = ""; +#endif // BACKGROUND_IMAGE_PATCH + +#if DWM_LOGO_PATCH +/* insert grid pattern with scale 1:1, the size can be changed with logosize */ +static const int logosize = 8; +static const int logow = 12; /* grid width and height for right center alignment*/ +static const int logoh = 6; + +static XRectangle rectangles[] = { + /* x y w h */ + { 0, 3, 1, 3 }, + { 1, 3, 2, 1 }, + { 0, 5, 8, 1 }, + { 3, 0, 1, 5 }, + { 5, 3, 1, 2 }, + { 7, 3, 1, 2 }, + { 8, 3, 4, 1 }, + { 9, 4, 1, 2 }, + { 11, 4, 1, 2 }, +}; +#endif // DWM_LOGO_PATCH + +#if XRESOURCES_PATCH +/* + * Xresources preferences to load at startup + */ +ResourcePref resources[] = { + #if DWM_LOGO_PATCH && !BLUR_PIXELATED_SCREEN_PATCH + { "background", STRING, &colorname[BACKGROUND] }, + #endif //DWM_LOGO_PATCH + #if BACKGROUND_IMAGE_PATCH + { "bg_image", STRING, &background_image }, + #endif // BACKGROUND_IMAGE_PATCH + { "locked", STRING, &colorname[INIT] }, + { "input", STRING, &colorname[INPUT] }, + { "failed", STRING, &colorname[FAILED] }, + #if CAPSCOLOR_PATCH + { "capslock", STRING, &colorname[CAPS] }, + #endif // CAPSCOLOR_PATCH + #if PAMAUTH_PATCH + { "pamauth", STRING, &colorname[PAM] }, + #endif // PAMAUTH_PATCH + #if MESSAGE_PATCH || COLOR_MESSAGE_PATCH + { "message", STRING, &message }, + { "text_color", STRING, &text_color }, + { "font_name", STRING, &font_name }, + #endif // MESSAGE_PATCH | COLOR_MESSAGE_PATCH +}; +#endif // XRESOURCES_PATCH + +#if ALPHA_PATCH +/* lock screen opacity */ +static const float alpha = 0.9; +#endif // ALPHA_PATCH + +/* treat a cleared input like a wrong password (color) */ +static const int failonclear = 1; + +#if AUTO_TIMEOUT_PATCH +/* length of time (seconds) until */ +static const int timeoffset = 60; + +/* should [command] be run only once? */ +static const int runonce = 0; + +/* command to be run after [time] has passed */ +static const char *command = "doas poweroff"; +#endif // AUTO_TIMEOUT_PATCH + +#if FAILURE_COMMAND_PATCH +/* number of failed password attempts until failcommand is executed. + Set to 0 to disable */ +static const int failcount = 0; + +/* command to be executed after [failcount] failed password attempts */ +static const char *failcommand = "shutdown"; +#endif // FAILURE_COMMAND_PATCH + +#if SECRET_PASSWORD_PATCH +static const secretpass scom[] = { + /* Password command */ + { "shutdown", "doas poweroff"}, +}; +#endif // SECRET_PASSWORD_PATCH + +#if BLUR_PIXELATED_SCREEN_PATCH +/* Enable blur */ +#define BLUR +/* Set blur radius */ +static const int blurRadius = 5; +/* Enable Pixelation */ +//#define PIXELATION +/* Set pixelation radius */ +static const int pixelSize = 10; +#endif // BLUR_PIXELATED_SCREEN_PATCH + +#if CONTROLCLEAR_PATCH +/* allow control key to trigger fail on clear */ +static const int controlkeyclear = 1; +#endif // CONTROLCLEAR_PATCH + +#if DPMS_PATCH +/* time in seconds before the monitor shuts down */ +static const int monitortime = 5; +#endif // DPMS_PATCH + +#if KEYPRESS_FEEDBACK_PATCH +static short int blocks_enabled = 1; // 0 = don't show blocks +static const int blocks_width = 0; // 0 = full width +static const int blocks_height = 16; + +// position +static const int blocks_x = 0; +static const int blocks_y = 0; + +// Number of blocks +static const int blocks_count = 10; +#endif // KEYPRESS_FEEDBACK_PATCH + +#if PAMAUTH_PATCH +/* PAM service that's used for authentication */ +static const char* pam_service = "login"; +#endif // PAMAUTH_PATCH + +#if QUICKCANCEL_PATCH +/* time in seconds to cancel lock with mouse movement */ +static const int timetocancel = 4; +#endif // QUICKCANCEL_PATCH diff --git a/config.mk b/config.mk index 6299928..ff74f8d 100644 --- a/config.mk +++ b/config.mk @@ -17,14 +17,14 @@ X11LIB = /usr/X11R6/lib #NETBSD=-D_NETBSD_SOURCE # Uncomment for message patch / MESSAGE_PATCH / COLORMESSAGE_PATCH / DWM_LOGO_PATCH -#XINERAMA=-lXinerama -#XINERAMAFLAGS = -DXINERAMA +XINERAMA=-lXinerama +XINERAMAFLAGS = -DXINERAMA # Uncomment for pam auth patch / PAMAUTH_PATCH #PAM=-lpam # Uncomment for blur pixelated screen and background image patches / BLUR_PIXELATED_SCREEN_PATCH, BACKGROUND_IMAGE_PATCH -#IMLIB=-lImlib2 +IMLIB=-lImlib2 # includes and libs INCS = -I. -I/usr/include -I${X11INC} diff --git a/patches.h b/patches.h new file mode 100644 index 0000000..62a722c --- /dev/null +++ b/patches.h @@ -0,0 +1,145 @@ +/* + * This file contains patch control flags. + * + * In principle you should be able to mix and match any patches + * you may want. In cases where patches are logically incompatible + * one patch may take precedence over the other as noted in the + * relevant descriptions. + */ + +/* Patches */ + +/* This patch enables transparency for slock. This is intended to be combined + * with a compositor that can blur the transparent background. + * Extrapolated from https://github.com/khuedoan/slock + * https://github.com/khuedoan/slock/commit/5e7a95b50fd72efcf2a40d487278749a17cbb146 + */ +#define ALPHA_PATCH 0 + +/* This patch allows for a command to be executed after a specified time of inactivity. + * https://tools.suckless.org/slock/patches/auto-timeout/ + */ +#define AUTO_TIMEOUT_PATCH 0 + +/* This patch adds a background image for slock. + * This patch depends on the Imlib2 library, uncomment the relevant line in + * config.mk when enabling this patch. + * This patch is a variant of the blur pixelated screen patch and takes precedence over that. + * https://tools.suckless.org/slock/patches/background-image/ + */ +#define BACKGROUND_IMAGE_PATCH 0 + +/* This patch sets the lockscreen picture to a blured or pixelated screenshot. + * This patch depends on the Imlib2 library, uncomment the relevant line in + * config.mk when enabling this patch. + * The background image patch takes precedence over this patch. + * https://tools.suckless.org/slock/patches/blur-pixelated-screen/ + */ +#define BLUR_PIXELATED_SCREEN_PATCH 1 + +/* This patch introduces an additional color to indicate the state of Caps Lock. + * https://tools.suckless.org/slock/patches/capscolor/ + */ +#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 + * and don't want to spoil the detection of failed unlocking attempts. + * https://tools.suckless.org/slock/patches/control-clear/ + */ +#define CONTROLCLEAR_PATCH 1 + +/* This patch 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. + * https://tools.suckless.org/slock/patches/dpms/ + */ +#define DPMS_PATCH 1 + +/* This patch draws the dwm logo which changes color based on the state. + * https://tools.suckless.org/slock/patches/dwmlogo/ + */ +#define DWM_LOGO_PATCH 1 + +/* This patch allows for a command to be run after a specified number of incorrect attempts. + * https://tools.suckless.org/slock/patches/failure-command/ + */ +#define FAILURE_COMMAND_PATCH 0 + +/* Draws random blocks on the screen to display keypress feedback. + * https://tools.suckless.org/slock/patches/keypress-feedback/ + * https://patch-diff.githubusercontent.com/raw/phenax/bslock/pull/2.diff + */ +#define KEYPRESS_FEEDBACK_PATCH 0 + +/* This patch allows media keys to be used while the screen is locked. Allows for volume + * to be adjusted or to skip to the next song without having to unlock the screen first. + * https://tools.suckless.org/slock/patches/mediakeys/ + */ +#define MEDIAKEYS_PATCH 1 + +/* This patch lets you add a message to your lock screen. You can place a default message + * in config.h and you can also pass a message with the -m command line option. + * 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/message/ + */ +#define MESSAGE_PATCH 0 + +/* Replaces shadow support with PAM authentication support. + * Change variable pam_service in config.def.h to the corresponding PAM service. + * The default configuration is for ArchLinux's login service. + * If you enable this then you also need to add the -lpam library to the LIBS configuration + * in config.mk. Look for and uncomment the PAM placeholder. + * https://tools.suckless.org/slock/patches/pam_auth/ + */ +#define PAMAUTH_PATCH 0 + +/* 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.). + * https://tools.suckless.org/slock/patches/quickcancel/ + */ +#define QUICKCANCEL_PATCH 0 + +/* This patch allows for commands to be executed when the user enters special passwords. + * https://tools.suckless.org/slock/patches/secret-password/ + */ +#define SECRET_PASSWORD_PATCH 0 + +/* Adds key commands that are commonly used in terminal applications (in particular the + * login prompt) to slock. + * https://tools.suckless.org/slock/patches/terminalkeys/ + */ +#define TERMINALKEYS_PATCH 0 + +/* 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. + * https://tools.suckless.org/slock/patches/unlock_screen/ + */ +#define UNLOCKSCREEN_PATCH 0 + +/* This patch adds the ability to get colors via Xresources. + * https://tools.suckless.org/slock/patches/xresources/ + */ +#define XRESOURCES_PATCH 1