Skip to content

Commit

Permalink
Added capscolor, control clear, dpms, mediakeys, message, pam auth, q…
Browse files Browse the repository at this point in the history
…uickcancel patches
  • Loading branch information
bakkeby committed Oct 17, 2019
1 parent 35633d4 commit 2cf8090
Show file tree
Hide file tree
Showing 12 changed files with 518 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
dwm
config.h
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this slock 1.4 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):
```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:
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:
- [capscolor](https://tools.suckless.org/slock/patches/capscolor/)
- adds an additional color to indicate the state of Caps Lock
- [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
- [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
- [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.)
- [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
37 changes: 37 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,44 @@ static const char *colorname[NUMCOLS] = {
[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 // CAPSCOLOR_PATCH
};

/* treat a cleared input like a wrong password (color) */
static const int failonclear = 1;

#if CONTROLCLEAR_PATCH
/* allow control key to trigger fail on clear */
static const int controlkeyclear = 0;
#endif // CONTROLCLEAR_PATCH

#if DPMS_PATCH
/* time in seconds before the monitor shuts down */
static const int monitortime = 5;
#endif // DPMS_PATCH

#if 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

#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
8 changes: 7 additions & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib

# Uncomment for message patch / MESSAGE_PATCH
#XINERAMA=-lXinerama

# Uncomment for pam auth patch / PAMAUTH_PATCH
#PAM=-lpam

# includes and libs
INCS = -I. -I/usr/include -I${X11INC}
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr ${XINERAMA} ${PAM}

# flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
Expand Down
9 changes: 9 additions & 0 deletions patch/dpms.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <X11/extensions/dpms.h>

static void
monitorreset(Display* dpy, CARD16 standby, CARD16 suspend, CARD16 off)
{
DPMSSetTimeouts(dpy, standby, suspend, off);
DPMSForceLevel(dpy, DPMSModeOn);
XFlush(dpy);
}
12 changes: 12 additions & 0 deletions patch/include.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Patches */
#if DPMS_PATCH
#include "dpms.c"
#endif

#if MESSAGE_PATCH
#include "message.c"
#endif

#if PAMAUTH_PATCH
#include "pamauth.c"
#endif
4 changes: 4 additions & 0 deletions patch/include.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Patches */
#if PAMAUTH_PATCH
#include "pamauth.h"
#endif
94 changes: 94 additions & 0 deletions patch/message.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <X11/extensions/Xinerama.h>

/* global count to prevent repeated error messages */
int count_error = 0;

static void
writemessage(Display *dpy, Window win, int screen)
{
int len, line_len, width, height, s_width, s_height, i, j, k, tab_replace, tab_size;
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 = 0;
k = 0;
for (i = j = 0; i < len; i++) {
if (message[i] == '\n') {
if (i - j > line_len)
line_len = i - j;
k++;
i++;
j = i;
}
}
/* 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 - XTextWidth(fontinfo, message, line_len))/2;

/* Look for '\n' and print the text between them. */
for (i = j = k = 0; i <= len; i++) {
/* i == len is the special case for the last line */
if (i == len || message[i] == '\n') {
tab_replace = 0;
while (message[j] == '\t' && j < i) {
tab_replace++;
j++;
}

XDrawString(dpy, win, gc, width + tab_size*tab_replace, height + 20*k, message + j, i - j);
while (i < len && message[i] == '\n') {
i++;
j = i;
k++;
}
}
}

/* xsi should not be NULL anyway if Xinerama is active, but to be safe */
if (XineramaIsActive(dpy) && xsi != NULL)
XFree(xsi);
}
27 changes: 27 additions & 0 deletions patch/pamauth.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
char passwd[256];

static int
pam_conv(int num_msg, const struct pam_message **msg,
struct pam_response **resp, void *appdata_ptr)
{
int retval = PAM_CONV_ERR;
for (int i=0; i<num_msg; i++) {
if (msg[i]->msg_style == PAM_PROMPT_ECHO_OFF &&
strncmp(msg[i]->msg, "Password: ", 10) == 0) {
struct pam_response *resp_msg = malloc(sizeof(struct pam_response));
if (!resp_msg)
die("malloc failed\n");
char *password = malloc(strlen(passwd) + 1);
if (!password)
die("malloc failed\n");
memset(password, 0, strlen(passwd) + 1);
strcpy(password, passwd);
resp_msg->resp_retcode = 0;
resp_msg->resp = password;
resp[i] = resp_msg;
retval = PAM_SUCCESS;
}
}
return retval;
}

5 changes: 5 additions & 0 deletions patch/pamauth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <security/pam_appl.h>
#include <security/pam_misc.h>

static int pam_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr);
struct pam_conv pamc = {pam_conv, NULL};
75 changes: 75 additions & 0 deletions patches.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 introduces an additional color to indicate the state of Caps Lock.
* https://tools.suckless.org/slock/patches/capscolor/
*/
#define CAPSCOLOR_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 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/
*/
#define DPMS_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 0

/* 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

/* 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
Loading

0 comments on commit 2cf8090

Please sign in to comment.