FG42/lisp/fg42/x.el

67 lines
2.0 KiB
EmacsLisp

;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2023 Sameer Rahmani <lxsameer@gnu.org>
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://devheroes.codes/FG42/FG42
;; Version: 3.0.0
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; 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)
(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