aboutsummaryrefslogtreecommitdiff
path: root/modules/system-commands.el
diff options
context:
space:
mode:
Diffstat (limited to 'modules/system-commands.el')
-rw-r--r--modules/system-commands.el59
1 files changed, 27 insertions, 32 deletions
diff --git a/modules/system-commands.el b/modules/system-commands.el
index dba4d40e2..de5e88535 100644
--- a/modules/system-commands.el
+++ b/modules/system-commands.el
@@ -6,18 +6,18 @@
;; Layer: 3 (Domain Workflow).
;; Category: D/S.
;; Load shape: eager.
-;; Eager reason: registers the C-; ! system-command keymap; high-impact commands
+;; Eager reason: binds C-; ! to the system-command menu; high-impact commands
;; that should run only by command (command-loaded target).
-;; Top-level side effects: defines a system-command keymap under cj/custom-keymap.
-;; Runtime requires: keybindings, rx.
+;; Top-level side effects: binds C-; ! to the system-command menu in cj/custom-keymap.
+;; Runtime requires: keybindings, host-environment, rx.
;; Direct test load: yes (requires keybindings explicitly).
;;
;; System commands for logout, lock, suspend, shutdown, reboot, and Emacs
-;; exit/restart. Provides both a keymap (C-; !) and a completing-read menu.
+;; exit/restart. C-; ! opens a completing-read menu of all commands.
;;
;; Commands include:
;; - Logout (terminate user session)
-;; - Lock screen (slock)
+;; - Lock screen (hyprlock on Wayland, slock on X11)
;; - Suspend (systemctl suspend)
;; - Shutdown (systemctl poweroff)
;; - Reboot (systemctl reboot)
@@ -28,12 +28,20 @@
;;
;;; Code:
-;; `keybindings' provides `cj/custom-keymap', which is referenced at load
-;; time by the `keymap-set' call at the tail of this file. An
+;; `keybindings' provides `cj/custom-keymap' and `cj/register-command',
+;; referenced at load time by the binding call at the tail of this file. An
;; `eval-when-compile' require would silence the byte-compiler but leave
;; the load-time reference void if anything required `system-commands'
;; before `keybindings'. Make the dependency explicit.
(require 'keybindings)
+;; `host-environment' provides `env-wayland-p', referenced at load time by the
+;; `lockscreen-cmd' defvar below to pick the session-appropriate locker. A hard
+;; require keeps the module loadable on its own (tests, byte-compile) rather
+;; than relying on init.el's load order.
+(require 'host-environment)
+;; `system-lib' provides `cj/confirm-strong', used at runtime by the `strong'
+;; confirm branch of `cj/system-cmd' for irreversible actions (shutdown/reboot).
+(require 'system-lib)
(eval-when-compile (require 'subr-x))
(require 'rx)
@@ -71,7 +79,7 @@ If CMD is deemed dangerous, ask for confirmation."
;; Strong confirm for irreversible actions (shutdown, reboot):
;; require an explicit "yes", so a stray RET/space can't trigger them.
((eq confirm 'strong)
- (unless (yes-or-no-p (format "Really run %s (%s)? " label cmdstr))
+ (unless (cj/confirm-strong (format "Really run %s (%s)? " label cmdstr))
(user-error "Aborted")))
;; Quick (Y/n) confirm for recoverable actions (logout, suspend).
(confirm
@@ -102,7 +110,13 @@ actions like shutdown and reboot), nil for no confirmation."
;; Define system commands
(cj/defsystem-command cj/system-cmd-logout logout-cmd "loginctl terminate-user $(whoami)" t)
-(cj/defsystem-command cj/system-cmd-lock lockscreen-cmd "slock")
+;; slock is X11-only and can't grab a Wayland session. On Wayland, lock via
+;; the session manager (`loginctl lock-session') rather than spawning a locker
+;; directly: logind emits the Lock signal, hypridle catches it and runs its
+;; lock_cmd (hyprlock), the same path idle/before-sleep locking already uses.
+;; X11 machines keep slock.
+(cj/defsystem-command cj/system-cmd-lock lockscreen-cmd
+ (if (env-wayland-p) "loginctl lock-session" "slock"))
(cj/defsystem-command cj/system-cmd-suspend suspend-cmd "systemctl suspend" t)
(cj/defsystem-command cj/system-cmd-shutdown shutdown-cmd "systemctl poweroff" strong)
(cj/defsystem-command cj/system-cmd-reboot reboot-cmd "systemctl reboot" strong)
@@ -167,29 +181,10 @@ daemon alive rather than killing the session blindly."
(when-let ((cmd (alist-get choice commands nil nil #'equal)))
(call-interactively cmd))))
-(defvar-keymap cj/system-command-map
- :doc "Keymap for system commands."
- "!" #'cj/system-command-menu
- "L" #'cj/system-cmd-logout
- "r" #'cj/system-cmd-reboot
- "s" #'cj/system-cmd-shutdown
- "S" #'cj/system-cmd-suspend
- "l" #'cj/system-cmd-lock
- "E" #'cj/system-cmd-exit-emacs
- "e" #'cj/system-cmd-restart-emacs)
-(cj/register-prefix-map "!" cj/system-command-map)
-
-(with-eval-after-load 'which-key
- (which-key-add-key-based-replacements
- "C-; !" "system commands"
- "C-; ! !" "system command menu"
- "C-; ! L" "logout"
- "C-; ! E" "exit Emacs"
- "C-; ! S" "suspend"
- "C-; ! e" "restart Emacs"
- "C-; ! l" "lock screen"
- "C-; ! r" "reboot"
- "C-; ! s" "shutdown"))
+;; C-; ! opens the completing-read menu directly. The per-command leaf
+;; keys (s/r/e/l/L/E/S) were removed 2026-06-28 to reclaim the key
+;; real-estate; every command stays reachable through the menu.
+(cj/register-command "!" #'cj/system-command-menu "system commands")
(provide 'system-commands)
;;; system-commands.el ends here