From 8d67672291d044ba463f16bfd6182b56990325a2 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Wed, 31 May 2023 23:37:29 +0100 Subject: [PATCH] Move the monitor function to X module --- core/fg42/x.el | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/core/fg42/x.el b/core/fg42/x.el index ff116d9..31123ea 100644 --- a/core/fg42/x.el +++ b/core/fg42/x.el @@ -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