From 13dd901aed12f475bd785d87ee014323c92958ac Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Wed, 5 Jan 2022 04:04:48 +0100 Subject: [PATCH 1/3] lockscreen managed by home role --- defaults/main.yaml | 10 ++++++---- files/bin/screensaver | 2 ++ tasks/apt.yaml | 2 ++ tasks/clean.yaml | 6 ++++++ tasks/lockscreen.yaml | 17 +++++++++++++++++ tasks/main.yaml | 4 +++- tasks/screensaver.yaml | 7 ------- templates/i3/i3.config.j2 | 8 ++++---- templates/lockscreen/lockscreen.env.j2 | 5 +++++ templates/lockscreen/lockscreen.service.j2 | 14 ++++++++++++++ templates/x11/xsession.reload.fish.j2 | 7 ++++++- 11 files changed, 65 insertions(+), 17 deletions(-) create mode 100755 files/bin/screensaver create mode 100644 tasks/lockscreen.yaml delete mode 100644 tasks/screensaver.yaml create mode 100644 templates/lockscreen/lockscreen.env.j2 create mode 100644 templates/lockscreen/lockscreen.service.j2 diff --git a/defaults/main.yaml b/defaults/main.yaml index 74c486c..2f6fe18 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -45,10 +45,12 @@ system_suspend_command: systemctl suspend system_reboot_command: systemctl reboot system_poweroff_command: systemctl poweroff -session_lock_enabled: "{{ (home_profile != 'presentation') and (home_profile != 'vdesk') }}" -session_lock_command: xset s activate -session_enable_screensaver_command: /usr/local/bin/screensaver-enable -session_disable_screensaver_command: /usr/local/bin/screensaver-disable +lockscreen_enabled: "{{ (home_profile != 'presentation') and (home_profile != 'vdesk') }}" +lockscreen_lock_command: xset s activate +lockscreen_timeout: 300 +lockscreen_locktime: 30 + +display_sleeptime: 300 file_browser_command: thunar calculator_command: "{{default_browser}} --new-window https://www.geogebra.org/calculator" diff --git a/files/bin/screensaver b/files/bin/screensaver new file mode 100755 index 0000000..2b3cadc --- /dev/null +++ b/files/bin/screensaver @@ -0,0 +1,2 @@ +#!/bin/sh +exec /usr/libexec/xscreensaver/glmatrix -density 50 -no-rotate $@ diff --git a/tasks/apt.yaml b/tasks/apt.yaml index 2905e59..0257037 100644 --- a/tasks/apt.yaml +++ b/tasks/apt.yaml @@ -5,3 +5,5 @@ pkg: - socat - fish + - xsecurelock + - xss-lock diff --git a/tasks/clean.yaml b/tasks/clean.yaml index 981ea56..b8eae7b 100644 --- a/tasks/clean.yaml +++ b/tasks/clean.yaml @@ -62,3 +62,9 @@ path: ~/.config/systemd/user/autostart-desktop-app@.service state: absent notify: systemd daemon-reload + +- name: screensaver graphical-session service disabled + systemd: + name: screensaver.service + enabled: false + scope: user diff --git a/tasks/lockscreen.yaml b/tasks/lockscreen.yaml new file mode 100644 index 0000000..eed364a --- /dev/null +++ b/tasks/lockscreen.yaml @@ -0,0 +1,17 @@ +--- + +- name: lockscreen environment + template: + src: lockscreen/lockscreen.env.j2 + dest: ~/.lockscreen.env + +- name: lockscreen graphical-session service + template: + src: lockscreen/lockscreen.service.j2 + dest: ~/.config/systemd/user/lockscreen.service + +- name: lockscreen graphical-session service enabled + systemd: + name: lockscreen.service + enabled: "{{ lockscreen_enabled }}" + scope: user diff --git a/tasks/main.yaml b/tasks/main.yaml index f7a266e..0eb9bef 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -6,7 +6,6 @@ - import_tasks: ssh.yaml - import_tasks: tmux.yaml - import_tasks: pulseaudio.yaml -- import_tasks: screensaver.yaml - import_tasks: git.yaml - import_tasks: timer.yaml @@ -18,6 +17,9 @@ - import_tasks: i3.yaml tags: - i3 + - import_tasks: lockscreen.yaml + tags: + - lockscreen - import_tasks: workspaces.yaml - import_tasks: icons.yaml - import_tasks: background.yaml diff --git a/tasks/screensaver.yaml b/tasks/screensaver.yaml deleted file mode 100644 index afb3463..0000000 --- a/tasks/screensaver.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- - -- name: screensaver graphical-session service enabled - systemd: - name: screensaver.service - enabled: "{{ session_lock_enabled }}" - scope: user diff --git a/templates/i3/i3.config.j2 b/templates/i3/i3.config.j2 index ee61da7..e28bc4f 100644 --- a/templates/i3/i3.config.j2 +++ b/templates/i3/i3.config.j2 @@ -22,7 +22,7 @@ floating_modifier $mod ### default/local mode ## special keys -bindsym XF86Sleep exec {{i3_exec_command_prefix}} {{session_lock_command}} +bindsym XF86Sleep exec {{i3_exec_command_prefix}} {{lockscreen_lock_command}} bindsym XF86Mail exec {{i3_exec_command_prefix}} {{mail_command}} bindsym XF86HomePage exec {{i3_exec_command_prefix}} {{default_browser}} bindsym XF86Calculator exec {{i3_exec_command_prefix}} {{calculator_command}} @@ -173,7 +173,7 @@ bindsym $mod+KP_Add exec {{points_up_command}} mode "remote" { bindcode $mod+9 mode "default" - bindsym XF86Sleep exec {{session_lock_command}} + bindsym XF86Sleep exec {{lockscreen_lock_command}} # The middle button over a titlebar kills the window bindsym --release button2 kill @@ -200,8 +200,8 @@ mode "session" { bindsym r reload; exec --no-startup-id ~/.xsession.reload.fish; mode "default"; {{on_focus_workspace}} bindsym R reload; exec --no-startup-id ~/.xsession.reload.fish; mode "default"; {{on_focus_workspace}} bindsym s exec --no-startup-id {{system_suspend_command}}; mode "default"; {{on_focus_workspace}} - bindsym l exec --no-startup-id {{session_lock_command}}; mode "default"; {{on_focus_workspace}} - bindcode 49 exec --no-startup-id {{session_lock_command}}; mode "default"; {{on_focus_workspace}} + bindsym l exec --no-startup-id {{lockscreen_lock_command}}; mode "default"; {{on_focus_workspace}} + bindcode 49 exec --no-startup-id {{lockscreen_lock_command}}; mode "default"; {{on_focus_workspace}} bindsym e exec --no-startup-id {{session_enable_screensaver_command}}; mode "default"; {{on_focus_workspace}} bindsym d exec --no-startup-id {{session_disable_screensaver_command}}; mode "default"; {{on_focus_workspace}} bindsym b exec --no-startup-id xsetroot -solid black; mode "default"; {{on_focus_workspace}} diff --git a/templates/lockscreen/lockscreen.env.j2 b/templates/lockscreen/lockscreen.env.j2 new file mode 100644 index 0000000..c64a2a3 --- /dev/null +++ b/templates/lockscreen/lockscreen.env.j2 @@ -0,0 +1,5 @@ +{{ ansible_managed | comment }} + +XSECURELOCK_SAVER=%h/bin/screensaver +XSECURELOCK_AUTH_BACKGROUND_COLOR={{home_base_color_hue|hsv2rgb(66,47)}} +XSECURELOCK_SWITCH_USER_COMMAND=dm-tool switch-to-greeter diff --git a/templates/lockscreen/lockscreen.service.j2 b/templates/lockscreen/lockscreen.service.j2 new file mode 100644 index 0000000..771535e --- /dev/null +++ b/templates/lockscreen/lockscreen.service.j2 @@ -0,0 +1,14 @@ +{{ ansible_managed | comment }} + +[Unit] +Description=Screensaver +PartOf=graphical-session.target + +[Service] +Type=simple +ExecStart=/usr/bin/xss-lock -l -- xsecurelock +Restart=always +EnvironmentFile=%h/.lockscreen.env + +[Install] +WantedBy=graphical-session.target diff --git a/templates/x11/xsession.reload.fish.j2 b/templates/x11/xsession.reload.fish.j2 index 2d9a466..eff6f6c 100644 --- a/templates/x11/xsession.reload.fish.j2 +++ b/templates/x11/xsession.reload.fish.j2 @@ -20,7 +20,12 @@ xrdb -merge ~/.Xresources rofi -theme ~/.config/rofi/theme -dump-xresources > ~/.config/rofi/config # screensaver settings -/usr/local/bin/screensaver-settings +xset s on +xset +dpms +xset s {{ lockscreen_timeout | int }} {{ lockscreen_locktime | int }} + +# DPMS options +xset dpms {{ display_sleeptime | int }} {{ display_sleeptime | int }} {{ display_sleeptime | int }} # allow hosts {% for xhost in home_xhosts_allow %} From b9229cfa99c1f3a016cae7ef49b53c3be5ab50c5 Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Wed, 5 Jan 2022 04:05:47 +0100 Subject: [PATCH 2/3] fix screensaver settings --- templates/i3/i3.config.j2 | 2 -- 1 file changed, 2 deletions(-) diff --git a/templates/i3/i3.config.j2 b/templates/i3/i3.config.j2 index e971fc0..47506c1 100644 --- a/templates/i3/i3.config.j2 +++ b/templates/i3/i3.config.j2 @@ -201,8 +201,6 @@ mode "session" { bindsym s exec --no-startup-id {{system_suspend_command}}; mode "default"; {{on_focus_workspace}} bindsym l exec --no-startup-id {{lockscreen_lock_command}}; mode "default"; {{on_focus_workspace}} bindcode 49 exec --no-startup-id {{lockscreen_lock_command}}; mode "default"; {{on_focus_workspace}} - bindsym e exec --no-startup-id {{session_enable_screensaver_command}}; mode "default"; {{on_focus_workspace}} - bindsym d exec --no-startup-id {{session_disable_screensaver_command}}; mode "default"; {{on_focus_workspace}} bindsym b exec --no-startup-id xsetroot -solid black; mode "default"; {{on_focus_workspace}} bindsym Shift+R exec --no-startup-id {{system_reboot_command}}; mode "default"; {{on_focus_workspace}} bindsym Shift+P exec --no-startup-id {{system_poweroff_command}}; mode "default"; {{on_focus_workspace}} From 0fd8476a446e3a1c940f13f87bc050af272b221e Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Wed, 5 Jan 2022 10:07:52 +0100 Subject: [PATCH 3/3] lockscreen --- tasks/clean.yaml | 1 + tasks/lockscreen.yaml | 7 +++++++ templates/i3/i3.config.j2 | 4 ++-- templates/lockscreen/lockscreen-auto.service.j2 | 13 +++++++++++++ templates/lockscreen/lockscreen.env.j2 | 2 +- templates/lockscreen/lockscreen.service.j2 | 6 +++--- 6 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 templates/lockscreen/lockscreen-auto.service.j2 diff --git a/tasks/clean.yaml b/tasks/clean.yaml index b8eae7b..6344576 100644 --- a/tasks/clean.yaml +++ b/tasks/clean.yaml @@ -67,4 +67,5 @@ systemd: name: screensaver.service enabled: false + state: stopped scope: user diff --git a/tasks/lockscreen.yaml b/tasks/lockscreen.yaml index eed364a..32e76e5 100644 --- a/tasks/lockscreen.yaml +++ b/tasks/lockscreen.yaml @@ -9,6 +9,13 @@ template: src: lockscreen/lockscreen.service.j2 dest: ~/.config/systemd/user/lockscreen.service + notify: systemd daemon-reload + +- name: lockscreen-auto graphical-session service + template: + src: lockscreen/lockscreen-auto.service.j2 + dest: ~/.config/systemd/user/lockscreen-auto.service + notify: systemd daemon-reload - name: lockscreen graphical-session service enabled systemd: diff --git a/templates/i3/i3.config.j2 b/templates/i3/i3.config.j2 index e971fc0..c8b1b5a 100644 --- a/templates/i3/i3.config.j2 +++ b/templates/i3/i3.config.j2 @@ -201,8 +201,8 @@ mode "session" { bindsym s exec --no-startup-id {{system_suspend_command}}; mode "default"; {{on_focus_workspace}} bindsym l exec --no-startup-id {{lockscreen_lock_command}}; mode "default"; {{on_focus_workspace}} bindcode 49 exec --no-startup-id {{lockscreen_lock_command}}; mode "default"; {{on_focus_workspace}} - bindsym e exec --no-startup-id {{session_enable_screensaver_command}}; mode "default"; {{on_focus_workspace}} - bindsym d exec --no-startup-id {{session_disable_screensaver_command}}; mode "default"; {{on_focus_workspace}} + bindsym e exec --no-startup-id systemctl --user start lockscreen.service; mode "default"; {{on_focus_workspace}} + bindsym d exec --no-startup-id systemctl --user stop lockscreen.service; mode "default"; {{on_focus_workspace}} bindsym b exec --no-startup-id xsetroot -solid black; mode "default"; {{on_focus_workspace}} bindsym Shift+R exec --no-startup-id {{system_reboot_command}}; mode "default"; {{on_focus_workspace}} bindsym Shift+P exec --no-startup-id {{system_poweroff_command}}; mode "default"; {{on_focus_workspace}} diff --git a/templates/lockscreen/lockscreen-auto.service.j2 b/templates/lockscreen/lockscreen-auto.service.j2 new file mode 100644 index 0000000..aded42e --- /dev/null +++ b/templates/lockscreen/lockscreen-auto.service.j2 @@ -0,0 +1,13 @@ +{{ ansible_managed | comment }} + +[Unit] +Description=Screensaver +PartOf=graphical-session.target + +[Service] +Type=simple +ExecStart=/usr/bin/xss-lock -l -- systemctl --user start lockscreen.service +Restart=always + +[Install] +WantedBy=graphical-session.target diff --git a/templates/lockscreen/lockscreen.env.j2 b/templates/lockscreen/lockscreen.env.j2 index c64a2a3..d0ccad1 100644 --- a/templates/lockscreen/lockscreen.env.j2 +++ b/templates/lockscreen/lockscreen.env.j2 @@ -1,5 +1,5 @@ {{ ansible_managed | comment }} -XSECURELOCK_SAVER=%h/bin/screensaver +#XSECURELOCK_SAVER=$HOME/bin/screensaver XSECURELOCK_AUTH_BACKGROUND_COLOR={{home_base_color_hue|hsv2rgb(66,47)}} XSECURELOCK_SWITCH_USER_COMMAND=dm-tool switch-to-greeter diff --git a/templates/lockscreen/lockscreen.service.j2 b/templates/lockscreen/lockscreen.service.j2 index 771535e..b288491 100644 --- a/templates/lockscreen/lockscreen.service.j2 +++ b/templates/lockscreen/lockscreen.service.j2 @@ -5,9 +5,9 @@ Description=Screensaver PartOf=graphical-session.target [Service] -Type=simple -ExecStart=/usr/bin/xss-lock -l -- xsecurelock -Restart=always +Type=notify +ExecStart=xsecurelock -- systemd-notify --ready +NotifyAccess=all EnvironmentFile=%h/.lockscreen.env [Install]