Move the monitor function to X module

This commit is contained in:
Sameer Rahmani 2023-05-31 23:37:29 +01:00
parent f1e0d5b052
commit 8d67672291
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
1 changed files with 36 additions and 1 deletions

View File

@ -21,11 +21,46 @@
;;
;;; Commentary:
;;; Code:
(require 'seq)
(defvar fg42/monitors nil
"A plist containing monitor resolution profiles.
for example:
'(:hdmi-only
(\"--output HDMI-1 --primary\"
\"--output eDP-1 --off\")
:hdmi-main
(\"--output HDMI-1 --primary\"
\"--output eDP-1 --mode 1920x1080 --left-of HDMI-1\")
:edp-only
(\"--output eDP-1 --mode 1920x1080\"
\"--output HDMI-1 --off\"))")
(defun fg42/get-x11-selection-text ()
"Return the X11 selection paste text."
(interactive)
(x-get-selection 'PRIMARY))
(gui-get-selection 'PRIMARY))
(defun monitor-profiles ()
"Parse the `fg42/monitors' profiles."
(mapcar
#'car
(seq-partition fg42/monitors 2)))
(defun monitor (mon)
"Switch to the given monitor resolution profile MON."
(interactive
(list (completing-read
"Monitor Profole: "
(monitor-profiles))))
(let ((cmd (mapconcat (lambda (x) (format "xrandr %s" x))
(plist-get fg42/monitors (intern (format "%s" mon)))
" && ")))
(message "Setting monitor profile: %s" cmd)
(async-shell-command cmd "*xrandr*")))
(provide 'fg42/x)
;;; x.el ends here