From bb668c1bdfb2937e2ca987426aac6cfe1b544fc9 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Sat, 5 Dec 2020 12:10:33 +0100 Subject: Add slock mediakeys and xautolock --- modules/slock.nix | 14 +++++++++-- platforms/linux/xorg/default.nix | 1 + platforms/linux/xorg/dwm-mediakeys.diff | 13 +++++++++++ platforms/linux/xorg/slock/slock-mediakeys.diff | 31 +++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 platforms/linux/xorg/dwm-mediakeys.diff create mode 100644 platforms/linux/xorg/slock/slock-mediakeys.diff diff --git a/modules/slock.nix b/modules/slock.nix index df6f23c..85c78de 100644 --- a/modules/slock.nix +++ b/modules/slock.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ config, pkgs, ... }: let slock = pkgs.slock.overrideAttrs(oldAttrs: { @@ -11,9 +11,19 @@ let # ../platforms/linux/xorg/slock/slock-pam_auth-20190207-35633d4.diff ../platforms/linux/xorg/slock/slock-capscolor-20170106-2d2a21a.diff ../platforms/linux/xorg/slock/slock-dpms-1.4.diff + ../platforms/linux/xorg/slock/slock-mediakeys.diff ]; }); in { environment.systemPackages = [ slock ]; - security.wrappers.slock.source = "${slock}/bin/slock"; + security.wrappers.slock.source = "${slock.out}/bin/slock"; + services.xserver.xautolock = { + enable = true; + locker = "${config.security.wrapperDir}/slock"; + enableNotifier = true; + notifier = "${pkgs.libnotify}/bin/notify-send \"Locking in 10 seconds\""; + killer = "/run/current-system/systemd/bin/systemctl suspend-then-hibernate"; + killtime = 30; + extraOptions = [ "-detectsleep" ]; + }; } diff --git a/platforms/linux/xorg/default.nix b/platforms/linux/xorg/default.nix index 13abb32..9303fee 100644 --- a/platforms/linux/xorg/default.nix +++ b/platforms/linux/xorg/default.nix @@ -11,6 +11,7 @@ let ./dwm-systray.diff ./dwm-center.diff ./dwm-autostart.diff + ./dwm-mediakeys.diff # Patch for slock mediakeys # ./dwm-rounded.diff - Resize dont work ]; header_config_file = ./config.h; diff --git a/platforms/linux/xorg/dwm-mediakeys.diff b/platforms/linux/xorg/dwm-mediakeys.diff new file mode 100644 index 0000000..0ec5336 --- /dev/null +++ b/platforms/linux/xorg/dwm-mediakeys.diff @@ -0,0 +1,13 @@ +diff --git a/dwm.c b/dwm.c +index 2e43282..1565695 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -1847,7 +1847,7 @@ setup(void) + wa.cursor = cursor[CurNormal]->cursor; + wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask + |ButtonPressMask|PointerMotionMask|EnterWindowMask +- |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask; ++ |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask|KeyPressMask; + XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); + XSelectInput(dpy, root, wa.event_mask); + grabkeys(); diff --git a/platforms/linux/xorg/slock/slock-mediakeys.diff b/platforms/linux/xorg/slock/slock-mediakeys.diff new file mode 100644 index 0000000..098eb02 --- /dev/null +++ b/platforms/linux/xorg/slock/slock-mediakeys.diff @@ -0,0 +1,31 @@ +diff --git a/slock.c b/slock.c +index 5ae738c..bd54be2 100644 +--- a/slock.c ++++ b/slock.c +@@ -18,6 +18,7 @@ + #include + #include + #include ++#include + + #include "arg.h" + #include "util.h" +@@ -157,6 +158,18 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, + IsPrivateKeypadKey(ksym)) + continue; + switch (ksym) { ++ case XF86XK_AudioPlay: ++ case XF86XK_AudioStop: ++ case XF86XK_AudioPrev: ++ case XF86XK_AudioNext: ++ case XF86XK_AudioRaiseVolume: ++ case XF86XK_AudioLowerVolume: ++ case XF86XK_AudioMute: ++ case XF86XK_AudioMicMute: ++ case XF86XK_MonBrightnessDown: ++ case XF86XK_MonBrightnessUp: ++ XSendEvent(dpy, DefaultRootWindow(dpy), True, KeyPressMask, &ev); ++ break; + case XK_Return: + passwd[len] = '\0'; + errno = 0; -- cgit 1.4.1