From c07648d3f9226db04db0711fc62693f5317e9609 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Mon, 3 Aug 2020 15:53:34 +0200 Subject: [PATCH] Adding keypress_feedback patch --- README.md | 5 +++++ config.def.h | 16 ++++++++++++++++ patch/include.c | 4 ++++ patch/include.h | 4 ++++ patch/keypress_feedback.c | 28 ++++++++++++++++++++++++++++ patch/keypress_feedback.h | 1 + patches.def.h | 16 +++++++++++----- slock.c | 16 ++++++++++++++++ 8 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 patch/keypress_feedback.c create mode 100644 patch/keypress_feedback.h diff --git a/README.md b/README.md index f520784672a5a908c9a3e895b5254cbe2c5cce3c..2495481c22238f23e28e79581ae0f5abb7b0a49e 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/) ### Changelog: +2020-08-03 - Added keypress_feedback patch + 2019-11-27 - Added xresources patch 2019-10-17 - Added capscolor, control clear, dpms, mediakeys, message, pam auth, quickcancel patches @@ -34,6 +36,9 @@ Refer to [https://tools.suckless.org/slock/](https://tools.suckless.org/slock/) - 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 diff --git a/config.def.h b/config.def.h index 992c52316fb72ca931092f679be194541c280bf0..56674322799a8696ac94d512755ac4a9e233cc77 100644 --- a/config.def.h +++ b/config.def.h @@ -12,6 +12,9 @@ static const char *colorname[NUMCOLS] = { #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 XRESOURCES_PATCH @@ -44,6 +47,19 @@ static const int controlkeyclear = 0; 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 MESSAGE_PATCH /* default message */ static const char * message = "Suckless: Software that sucks less."; diff --git a/patch/include.c b/patch/include.c index 7bd5cd04881a4be5ca8559239852476d06f3309f..1cb977bf9bd0ac85647091dcd33e3b5ce92cde2a 100644 --- a/patch/include.c +++ b/patch/include.c @@ -3,6 +3,10 @@ #include "message.c" #endif +#if KEYPRESS_FEEDBACK_PATCH +#include "keypress_feedback.c" +#endif + #if PAMAUTH_PATCH #include "pamauth.c" #endif diff --git a/patch/include.h b/patch/include.h index e3422e6a468d8802c5d2fd484829fdea77bb86d2..5f43fa78821f2121c4e42406de0cb56284f5af8b 100644 --- a/patch/include.h +++ b/patch/include.h @@ -3,6 +3,10 @@ #include "pamauth.h" #endif +#if KEYPRESS_FEEDBACK_PATCH +#include "keypress_feedback.h" +#endif + #if XRESOURCES_PATCH #include "xresources.h" #endif \ No newline at end of file diff --git a/patch/keypress_feedback.c b/patch/keypress_feedback.c new file mode 100644 index 0000000000000000000000000000000000000000..09cfc0ae2b2f538e7dc537d3da947cd27792aaf0 --- /dev/null +++ b/patch/keypress_feedback.c @@ -0,0 +1,28 @@ +static void +draw_key_feedback(Display *dpy, struct lock **locks, int screen) +{ + XGCValues gr_values; + + Window win = locks[screen]->win; + Window root_win; + + gr_values.foreground = locks[screen]->colors[BLOCKS]; + GC gc = XCreateGC(dpy, win, GCForeground, &gr_values); + + int width = blocks_width, height = blocks_height; + if (blocks_height == 0 || blocks_width == 0) { + int _x, _y; + unsigned int screen_width, screen_height, _b, _d; + XGetGeometry(dpy, win, &root_win, &_x, &_y, &screen_width, &screen_height, &_b, &_d); + width = blocks_width ? blocks_width : screen_width; + height = blocks_height ? blocks_height : screen_height; + } + + unsigned int block_width = width / blocks_count; + unsigned int position = rand() % blocks_count; + + XClearWindow(dpy, win); + XFillRectangle(dpy, win, gc, blocks_x + position*block_width, blocks_y, width, height); + + XFreeGC(dpy, gc); +} \ No newline at end of file diff --git a/patch/keypress_feedback.h b/patch/keypress_feedback.h new file mode 100644 index 0000000000000000000000000000000000000000..be2069016f2caf52ea90fd9405295f31c6ceaa72 --- /dev/null +++ b/patch/keypress_feedback.h @@ -0,0 +1 @@ +static void draw_key_feedback(Display *dpy, struct lock **locks, int screen); \ No newline at end of file diff --git a/patches.def.h b/patches.def.h index 4809d49758826aeb19719dd16b255586d2f5e04b..91bba23d9a17ff6e48bfa7bb2ef6b2ee40f3dfee 100644 --- a/patches.def.h +++ b/patches.def.h @@ -23,13 +23,19 @@ #define CONTROLCLEAR_PATCH 0 /* 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/ -*/ + * 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 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/ diff --git a/slock.c b/slock.c index a9a22c7c25ce539f818c5dbb611ca6df090d7818..9497925bb63c5e10b75c768fb106256472369c13 100644 --- a/slock.c +++ b/slock.c @@ -20,6 +20,9 @@ #include #include "patches.h" +#if KEYPRESS_FEEDBACK_PATCH +#include +#endif // KEYPRESS_FEEDBACK_PATCH #if CAPSCOLOR_PATCH #include #endif // CAPSCOLOR_PATCH @@ -52,6 +55,9 @@ enum { #if PAMAUTH_PATCH PAM, #endif // PAMAUTH_PATCH + #if KEYPRESS_FEEDBACK_PATCH + BLOCKS, + #endif // KEYPRESS_FEEDBACK_PATCH NUMCOLS }; @@ -301,6 +307,11 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, memcpy(passwd + len, buf, num); len += num; } + #if KEYPRESS_FEEDBACK_PATCH + if (blocks_enabled) + for (screen = 0; screen < nscreens; screen++) + draw_key_feedback(dpy, locks, screen); + #endif // KEYPRESS_FEEDBACK_PATCH break; } #if CAPSCOLOR_PATCH @@ -521,6 +532,11 @@ main(int argc, char **argv) { config_init(dpy); #endif // XRESOURCES_PATCH + #if KEYPRESS_FEEDBACK_PATCH + time_t t; + srand((unsigned) time(&t)); + #endif // KEYPRESS_FEEDBACK_PATCH + /* check for Xrandr support */ rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);