2015-08-03 14:26:53 +02:00
|
|
|
|
;;; exwm-randr.el --- RandR Module for EXWM -*- lexical-binding: t -*-
|
|
|
|
|
|
2024-01-08 01:00:00 +01:00
|
|
|
|
;; Copyright (C) 2015-2024 Free Software Foundation, Inc.
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
|
|
|
|
;; Author: Chris Feng <chris.w.feng@gmail.com>
|
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; This file is part of GNU Emacs.
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2015-08-03 14:26:53 +02:00
|
|
|
|
;; 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.
|
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2015-08-03 14:26:53 +02:00
|
|
|
|
;; 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
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2017-02-05 10:50:52 +01:00
|
|
|
|
;; This module adds RandR support for EXWM. Currently it requires external
|
|
|
|
|
;; tools such as xrandr(1) to properly configure RandR first. This
|
|
|
|
|
;; dependency may be removed in the future, but more work is needed before
|
|
|
|
|
;; that.
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
2015-11-01 03:54:20 +01:00
|
|
|
|
;; To use this module, load, enable it and configure
|
2018-11-04 01:00:00 +01:00
|
|
|
|
;; `exwm-randr-workspace-monitor-plist' and `exwm-randr-screen-change-hook'
|
2015-11-01 03:54:20 +01:00
|
|
|
|
;; as follows:
|
|
|
|
|
;;
|
2015-08-13 06:02:44 +02:00
|
|
|
|
;; (require 'exwm-randr)
|
2018-11-04 01:00:00 +01:00
|
|
|
|
;; (setq exwm-randr-workspace-monitor-plist '(0 "VGA1"))
|
2015-11-01 03:54:20 +01:00
|
|
|
|
;; (add-hook 'exwm-randr-screen-change-hook
|
|
|
|
|
;; (lambda ()
|
|
|
|
|
;; (start-process-shell-command
|
|
|
|
|
;; "xrandr" nil "xrandr --output VGA1 --left-of LVDS1 --auto")))
|
2015-08-13 06:02:44 +02:00
|
|
|
|
;; (exwm-randr-enable)
|
2015-11-01 03:54:20 +01:00
|
|
|
|
;;
|
2015-08-03 14:26:53 +02:00
|
|
|
|
;; With above lines, workspace 0 should be assigned to the output named "VGA1",
|
2015-11-01 03:54:20 +01:00
|
|
|
|
;; staying at the left of other workspaces on the output "LVDS1". Please refer
|
|
|
|
|
;; to xrandr(1) for the configuration of RandR.
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
|
|
|
|
;; References:
|
|
|
|
|
;; + RandR (http://www.x.org/archive/X11R7.7/doc/randrproto/randrproto.txt)
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'xcb-randr)
|
2019-02-06 01:00:00 +01:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(require 'exwm-core)
|
2019-02-06 01:00:00 +01:00
|
|
|
|
(require 'exwm-workspace)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
2023-08-18 02:00:00 +02:00
|
|
|
|
(declare-function x-get-atom-name "C source code" (VALUE &optional FRAME))
|
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(defgroup exwm-randr nil
|
|
|
|
|
"RandR."
|
|
|
|
|
:group 'exwm)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(defcustom exwm-randr-refresh-hook nil
|
|
|
|
|
"Normal hook run when the RandR module just refreshed."
|
|
|
|
|
:type 'hook)
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-randr-screen-change-hook nil
|
|
|
|
|
"Normal hook run when screen changes."
|
|
|
|
|
:type 'hook)
|
|
|
|
|
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(defcustom exwm-randr-workspace-monitor-plist nil
|
|
|
|
|
"Plist mapping workspaces to monitors.
|
2018-02-18 17:04:27 +01:00
|
|
|
|
|
2018-11-04 01:00:00 +01:00
|
|
|
|
In RandR 1.5 a monitor is a rectangle region decoupled from the physical
|
|
|
|
|
size of screens, and can be identified with `xrandr --listmonitors' (name of
|
|
|
|
|
the primary monitor is prefixed with an `*'). When no monitor is created it
|
|
|
|
|
automatically fallback to RandR 1.2 output which represents the physical
|
|
|
|
|
screen size. RandR 1.5 monitors can be created with `xrandr --setmonitor'.
|
|
|
|
|
For example, to split an output (`LVDS-1') of size 1280x800 into two
|
|
|
|
|
side-by-side monitors one could invoke (the digits after `/' are size in mm)
|
2018-02-18 17:04:27 +01:00
|
|
|
|
|
2018-11-04 01:00:00 +01:00
|
|
|
|
xrandr --setmonitor *LVDS-1-L 640/135x800/163+0+0 LVDS-1
|
|
|
|
|
xrandr --setmonitor LVDS-1-R 640/135x800/163+640+0 none
|
2018-02-18 17:04:27 +01:00
|
|
|
|
|
2018-11-04 01:00:00 +01:00
|
|
|
|
If a monitor is not active, the workspaces mapped to it are displayed on the
|
|
|
|
|
primary monitor until it becomes active (if ever). Unspecified workspaces
|
|
|
|
|
are all mapped to the primary monitor. For example, with the following
|
|
|
|
|
setting workspace other than 1 and 3 would always be displayed on the
|
|
|
|
|
primary monitor where workspace 1 and 3 would be displayed on their
|
|
|
|
|
corresponding monitors whenever the monitors are active.
|
|
|
|
|
|
|
|
|
|
\\='(1 \"HDMI-1\" 3 \"DP-1\")"
|
2018-02-18 17:04:27 +01:00
|
|
|
|
:type '(plist :key-type integer :value-type string))
|
2016-02-19 10:12:43 +01:00
|
|
|
|
|
2018-11-18 01:00:00 +01:00
|
|
|
|
(defvar exwm-randr--last-timestamp 0 "Used for debouncing events.")
|
|
|
|
|
|
2018-12-03 17:25:11 +01:00
|
|
|
|
(defvar exwm-randr--prev-screen-change-seqnum nil
|
|
|
|
|
"The most recent ScreenChangeNotify sequence number.")
|
2016-02-19 10:12:43 +01:00
|
|
|
|
|
2019-04-14 02:00:00 +02:00
|
|
|
|
(defvar exwm-randr--compatibility-mode nil
|
|
|
|
|
"Non-nil when the server does not support RandR 1.5 protocol.")
|
|
|
|
|
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(defun exwm-randr--get-monitors ()
|
2019-04-14 02:00:00 +02:00
|
|
|
|
"Get RandR 1.5 monitors."
|
2018-11-18 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2019-04-14 02:00:00 +02:00
|
|
|
|
(let (monitor-name geometry monitor-geometry-alist primary-monitor)
|
2018-11-18 01:00:00 +01:00
|
|
|
|
(with-slots (timestamp monitors)
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:randr:GetMonitors
|
|
|
|
|
:window exwm--root
|
|
|
|
|
:get-active 1))
|
2018-11-18 01:00:00 +01:00
|
|
|
|
(when (> timestamp exwm-randr--last-timestamp)
|
|
|
|
|
(setq exwm-randr--last-timestamp timestamp))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(dolist (monitor monitors)
|
|
|
|
|
(with-slots (name primary x y width height) monitor
|
|
|
|
|
(setq monitor-name (x-get-atom-name name)
|
|
|
|
|
geometry (make-instance 'xcb:RECTANGLE
|
|
|
|
|
:x x
|
|
|
|
|
:y y
|
|
|
|
|
:width width
|
|
|
|
|
:height height)
|
2019-03-24 01:00:00 +01:00
|
|
|
|
monitor-geometry-alist (cons (cons monitor-name geometry)
|
|
|
|
|
monitor-geometry-alist))
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "%s: %sx%s+%s+%s" monitor-name x y width height)
|
2018-11-18 01:00:00 +01:00
|
|
|
|
;; Save primary monitor when available (fallback to the first one).
|
|
|
|
|
(when (or (/= 0 primary)
|
|
|
|
|
(not primary-monitor))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(setq primary-monitor monitor-name)))))
|
|
|
|
|
(exwm--log "Primary monitor: %s" primary-monitor)
|
2019-04-14 02:00:00 +02:00
|
|
|
|
(list primary-monitor monitor-geometry-alist
|
|
|
|
|
(exwm-randr--get-monitor-alias primary-monitor
|
|
|
|
|
monitor-geometry-alist))))
|
|
|
|
|
|
|
|
|
|
(defun exwm-randr--get-outputs ()
|
|
|
|
|
"Get RandR 1.2 outputs.
|
|
|
|
|
|
|
|
|
|
Only used when RandR 1.5 is not supported by the server."
|
|
|
|
|
(exwm--log)
|
|
|
|
|
(let (output-name geometry output-geometry-alist primary-output)
|
|
|
|
|
(with-slots (config-timestamp outputs)
|
|
|
|
|
(xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:randr:GetScreenResourcesCurrent
|
|
|
|
|
:window exwm--root))
|
|
|
|
|
(when (> config-timestamp exwm-randr--last-timestamp)
|
|
|
|
|
(setq exwm-randr--last-timestamp config-timestamp))
|
|
|
|
|
(dolist (output outputs)
|
|
|
|
|
(with-slots (crtc connection name)
|
|
|
|
|
(xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:randr:GetOutputInfo
|
|
|
|
|
:output output
|
|
|
|
|
:config-timestamp config-timestamp))
|
|
|
|
|
(when (and (= connection xcb:randr:Connection:Connected)
|
|
|
|
|
(/= crtc 0))
|
|
|
|
|
(with-slots (x y width height)
|
|
|
|
|
(xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:randr:GetCrtcInfo
|
|
|
|
|
:crtc crtc
|
|
|
|
|
:config-timestamp config-timestamp))
|
|
|
|
|
(setq output-name (decode-coding-string
|
|
|
|
|
(apply #'unibyte-string name) 'utf-8)
|
|
|
|
|
geometry (make-instance 'xcb:RECTANGLE
|
|
|
|
|
:x x
|
|
|
|
|
:y y
|
|
|
|
|
:width width
|
|
|
|
|
:height height)
|
|
|
|
|
output-geometry-alist (cons (cons output-name geometry)
|
|
|
|
|
output-geometry-alist))
|
|
|
|
|
(exwm--log "%s: %sx%s+%s+%s" output-name x y width height)
|
|
|
|
|
;; The primary output is the first one.
|
|
|
|
|
(unless primary-output
|
|
|
|
|
(setq primary-output output-name)))))))
|
|
|
|
|
(exwm--log "Primary output: %s" primary-output)
|
|
|
|
|
(list primary-output output-geometry-alist
|
|
|
|
|
(exwm-randr--get-monitor-alias primary-output
|
|
|
|
|
output-geometry-alist))))
|
|
|
|
|
|
|
|
|
|
(defun exwm-randr--get-monitor-alias (primary-monitor monitor-geometry-alist)
|
|
|
|
|
"Generate monitor aliases using PRIMARY-MONITOR MONITOR-GEOMETRY-ALIST.
|
|
|
|
|
|
|
|
|
|
In a mirroring setup some monitors overlap and should be treated as one."
|
|
|
|
|
(let (monitor-position-alist monitor-alias-alist monitor-name geometry)
|
2019-03-24 01:00:00 +01:00
|
|
|
|
(setq monitor-position-alist (with-slots (x y)
|
|
|
|
|
(cdr (assoc primary-monitor
|
|
|
|
|
monitor-geometry-alist))
|
|
|
|
|
(list (cons primary-monitor (vector x y)))))
|
|
|
|
|
(setq monitor-alias-alist (list (cons primary-monitor primary-monitor)))
|
|
|
|
|
(dolist (pair monitor-geometry-alist)
|
|
|
|
|
(setq monitor-name (car pair)
|
|
|
|
|
geometry (cdr pair))
|
|
|
|
|
(unless (assoc monitor-name monitor-alias-alist)
|
|
|
|
|
(let* ((position (vector (slot-value geometry 'x)
|
|
|
|
|
(slot-value geometry 'y)))
|
|
|
|
|
(alias (car (rassoc position monitor-position-alist))))
|
|
|
|
|
(if alias
|
|
|
|
|
(setq monitor-alias-alist (cons (cons monitor-name alias)
|
|
|
|
|
monitor-alias-alist))
|
|
|
|
|
(setq monitor-position-alist (cons (cons monitor-name position)
|
|
|
|
|
monitor-position-alist)
|
|
|
|
|
monitor-alias-alist (cons (cons monitor-name monitor-name)
|
|
|
|
|
monitor-alias-alist))))))
|
2019-04-14 02:00:00 +02:00
|
|
|
|
monitor-alias-alist))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
|
2018-11-11 01:00:00 +01:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun exwm-randr-refresh ()
|
2015-08-03 14:26:53 +02:00
|
|
|
|
"Refresh workspaces according to the updated RandR info."
|
2018-11-11 01:00:00 +01:00
|
|
|
|
(interactive)
|
2018-11-18 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2019-04-14 02:00:00 +02:00
|
|
|
|
(let* ((result (if exwm-randr--compatibility-mode
|
|
|
|
|
(exwm-randr--get-outputs)
|
|
|
|
|
(exwm-randr--get-monitors)))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(primary-monitor (elt result 0))
|
2019-03-24 01:00:00 +01:00
|
|
|
|
(monitor-geometry-alist (elt result 1))
|
|
|
|
|
(monitor-alias-alist (elt result 2))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
container-monitor-alist container-frame-alist)
|
2019-03-24 01:00:00 +01:00
|
|
|
|
(when (and primary-monitor monitor-geometry-alist)
|
2016-07-16 08:34:57 +02:00
|
|
|
|
(when exwm-workspace--fullscreen-frame-count
|
|
|
|
|
;; Not all workspaces are fullscreen; reset this counter.
|
|
|
|
|
(setq exwm-workspace--fullscreen-frame-count 0))
|
2016-07-17 14:00:00 +02:00
|
|
|
|
(dotimes (i (exwm-workspace--count))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(let* ((monitor (plist-get exwm-randr-workspace-monitor-plist i))
|
2019-03-24 01:00:00 +01:00
|
|
|
|
(geometry (cdr (assoc monitor monitor-geometry-alist)))
|
2018-02-21 17:31:57 +01:00
|
|
|
|
(frame (elt exwm-workspace--list i))
|
|
|
|
|
(container (frame-parameter frame 'exwm-container)))
|
2019-03-24 01:00:00 +01:00
|
|
|
|
(if geometry
|
|
|
|
|
;; Unify monitor names in case it's a mirroring setup.
|
|
|
|
|
(setq monitor (cdr (assoc monitor monitor-alias-alist)))
|
|
|
|
|
;; Missing monitors fallback to the primary one.
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(setq monitor primary-monitor
|
2019-03-24 01:00:00 +01:00
|
|
|
|
geometry (cdr (assoc primary-monitor
|
|
|
|
|
monitor-geometry-alist))))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(setq container-monitor-alist (nconc
|
|
|
|
|
`((,container . ,(intern monitor)))
|
|
|
|
|
container-monitor-alist)
|
2018-02-21 17:31:57 +01:00
|
|
|
|
container-frame-alist (nconc `((,container . ,frame))
|
|
|
|
|
container-frame-alist))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(set-frame-parameter frame 'exwm-randr-monitor monitor)
|
2016-07-16 08:34:57 +02:00
|
|
|
|
(set-frame-parameter frame 'exwm-geometry geometry)))
|
2018-03-09 17:12:47 +01:00
|
|
|
|
;; Update workareas.
|
|
|
|
|
(exwm-workspace--update-workareas)
|
|
|
|
|
;; Resize workspace.
|
|
|
|
|
(dolist (f exwm-workspace--list)
|
|
|
|
|
(exwm-workspace--set-fullscreen f))
|
|
|
|
|
(xcb:flush exwm--connection)
|
|
|
|
|
;; Raise the minibuffer if it's active.
|
|
|
|
|
(when (and (active-minibuffer-window)
|
|
|
|
|
(exwm-workspace--minibuffer-own-frame-p))
|
|
|
|
|
(exwm-workspace--show-minibuffer))
|
|
|
|
|
;; Set _NET_DESKTOP_GEOMETRY.
|
|
|
|
|
(exwm-workspace--set-desktop-geometry)
|
2018-02-22 15:21:54 +01:00
|
|
|
|
;; Update active/inactive workspaces.
|
|
|
|
|
(dolist (w exwm-workspace--list)
|
|
|
|
|
(exwm-workspace--set-active w nil))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
;; Mark the workspace on the top of each monitor as active.
|
2018-02-21 17:31:57 +01:00
|
|
|
|
(dolist (xwin
|
|
|
|
|
(reverse
|
|
|
|
|
(slot-value (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:QueryTree
|
|
|
|
|
:window exwm--root))
|
|
|
|
|
'children)))
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(let ((monitor (cdr (assq xwin container-monitor-alist))))
|
|
|
|
|
(when monitor
|
|
|
|
|
(setq container-monitor-alist
|
|
|
|
|
(rassq-delete-all monitor container-monitor-alist))
|
2018-02-22 15:21:54 +01:00
|
|
|
|
(exwm-workspace--set-active (cdr (assq xwin container-frame-alist))
|
|
|
|
|
t))))
|
2016-02-19 10:12:43 +01:00
|
|
|
|
(xcb:flush exwm--connection)
|
|
|
|
|
(run-hooks 'exwm-randr-refresh-hook))))
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
2018-12-03 17:25:11 +01:00
|
|
|
|
(defun exwm-randr--on-ScreenChangeNotify (data _synthetic)
|
2018-11-18 01:00:00 +01:00
|
|
|
|
"Handle `ScreenChangeNotify' event.
|
|
|
|
|
|
|
|
|
|
Run `exwm-randr-screen-change-hook' (usually user scripts to configure RandR)."
|
|
|
|
|
(exwm--log)
|
2018-12-03 17:25:11 +01:00
|
|
|
|
(let ((evt (make-instance 'xcb:randr:ScreenChangeNotify)))
|
|
|
|
|
(xcb:unmarshal evt data)
|
|
|
|
|
(let ((seqnum (slot-value evt '~sequence)))
|
|
|
|
|
(unless (equal seqnum exwm-randr--prev-screen-change-seqnum)
|
|
|
|
|
(setq exwm-randr--prev-screen-change-seqnum seqnum)
|
|
|
|
|
(run-hooks 'exwm-randr-screen-change-hook)))))
|
2018-11-18 01:00:00 +01:00
|
|
|
|
|
|
|
|
|
(defun exwm-randr--on-Notify (data _synthetic)
|
|
|
|
|
"Handle `CrtcChangeNotify' and `OutputChangeNotify' events.
|
|
|
|
|
|
|
|
|
|
Refresh when any CRTC/output changes."
|
|
|
|
|
(exwm--log)
|
|
|
|
|
(let ((evt (make-instance 'xcb:randr:Notify))
|
|
|
|
|
notify)
|
|
|
|
|
(xcb:unmarshal evt data)
|
|
|
|
|
(with-slots (subCode u) evt
|
|
|
|
|
(cl-case subCode
|
|
|
|
|
(xcb:randr:Notify:CrtcChange
|
|
|
|
|
(setq notify (slot-value u 'cc)))
|
|
|
|
|
(xcb:randr:Notify:OutputChange
|
|
|
|
|
(setq notify (slot-value u 'oc))))
|
|
|
|
|
(when notify
|
|
|
|
|
(with-slots (timestamp) notify
|
|
|
|
|
(when (> timestamp exwm-randr--last-timestamp)
|
|
|
|
|
(exwm-randr-refresh)
|
|
|
|
|
(setq exwm-randr--last-timestamp timestamp)))))))
|
|
|
|
|
|
|
|
|
|
(defun exwm-randr--on-ConfigureNotify (data _synthetic)
|
|
|
|
|
"Handle `ConfigureNotify' event.
|
|
|
|
|
|
|
|
|
|
Refresh when any RandR 1.5 monitor changes."
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2018-11-18 01:00:00 +01:00
|
|
|
|
(let ((evt (make-instance 'xcb:ConfigureNotify)))
|
|
|
|
|
(xcb:unmarshal evt data)
|
|
|
|
|
(with-slots (window) evt
|
|
|
|
|
(when (eq window exwm--root)
|
|
|
|
|
(exwm-randr-refresh)))))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
|
2015-08-03 14:26:53 +02:00
|
|
|
|
(defun exwm-randr--init ()
|
|
|
|
|
"Initialize RandR extension and EXWM RandR module."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2019-04-14 02:00:00 +02:00
|
|
|
|
(when (= 0 (slot-value (xcb:get-extension-data exwm--connection 'xcb:randr)
|
|
|
|
|
'present))
|
|
|
|
|
(error "[EXWM] RandR extension is not supported by the server"))
|
|
|
|
|
(with-slots (major-version minor-version)
|
|
|
|
|
(xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:randr:QueryVersion
|
|
|
|
|
:major-version 1 :minor-version 5))
|
|
|
|
|
(cond ((and (= major-version 1) (= minor-version 5))
|
|
|
|
|
(setq exwm-randr--compatibility-mode nil))
|
|
|
|
|
((and (= major-version 1) (>= minor-version 2))
|
|
|
|
|
(setq exwm-randr--compatibility-mode t))
|
|
|
|
|
(t
|
|
|
|
|
(error "[EXWM] The server only support RandR version up to %d.%d"
|
|
|
|
|
major-version minor-version)))
|
|
|
|
|
;; External monitor(s) may already be connected.
|
|
|
|
|
(run-hooks 'exwm-randr-screen-change-hook)
|
|
|
|
|
(exwm-randr-refresh)
|
|
|
|
|
;; Listen for `ScreenChangeNotify' to notify external tools to
|
|
|
|
|
;; configure RandR and `CrtcChangeNotify/OutputChangeNotify' to
|
|
|
|
|
;; refresh the workspace layout.
|
|
|
|
|
(xcb:+event exwm--connection 'xcb:randr:ScreenChangeNotify
|
|
|
|
|
#'exwm-randr--on-ScreenChangeNotify)
|
|
|
|
|
(xcb:+event exwm--connection 'xcb:randr:Notify
|
|
|
|
|
#'exwm-randr--on-Notify)
|
|
|
|
|
(xcb:+event exwm--connection 'xcb:ConfigureNotify
|
|
|
|
|
#'exwm-randr--on-ConfigureNotify)
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:randr:SelectInput
|
|
|
|
|
:window exwm--root
|
|
|
|
|
:enable (logior
|
|
|
|
|
xcb:randr:NotifyMask:ScreenChange
|
|
|
|
|
xcb:randr:NotifyMask:CrtcChange
|
|
|
|
|
xcb:randr:NotifyMask:OutputChange)))
|
|
|
|
|
(xcb:flush exwm--connection)
|
|
|
|
|
(add-hook 'exwm-workspace-list-change-hook #'exwm-randr-refresh))
|
2017-01-02 17:14:33 +01:00
|
|
|
|
;; Prevent frame parameters introduced by this module from being
|
|
|
|
|
;; saved/restored.
|
2018-11-04 01:00:00 +01:00
|
|
|
|
(dolist (i '(exwm-randr-monitor))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(unless (assq i frameset-filter-alist)
|
|
|
|
|
(push (cons i :never) frameset-filter-alist))))
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
2016-05-23 13:13:42 +02:00
|
|
|
|
(defun exwm-randr--exit ()
|
2016-07-19 04:34:38 +02:00
|
|
|
|
"Exit the RandR module."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2018-11-18 01:00:00 +01:00
|
|
|
|
(remove-hook 'exwm-workspace-list-change-hook #'exwm-randr-refresh))
|
2016-05-23 13:13:42 +02:00
|
|
|
|
|
2024-05-29 19:58:45 +02:00
|
|
|
|
;;;###autoload(autoload 'exwm-randr-mode "exwm-randr" nil t)
|
|
|
|
|
(exwm--define-global-minor-mode randr
|
|
|
|
|
"Global minor mode for toggling EXWM RandR support.")
|
|
|
|
|
|
2015-08-13 06:02:44 +02:00
|
|
|
|
(defun exwm-randr-enable ()
|
|
|
|
|
"Enable RandR support for EXWM."
|
2024-05-29 19:58:45 +02:00
|
|
|
|
(add-hook 'exwm-init-hook #'exwm-randr-mode)
|
|
|
|
|
(add-hook 'exwm-exit-hook (apply-partially #'exwm-randr-mode -1))
|
|
|
|
|
(when exwm--connection (exwm-randr-mode)))
|
|
|
|
|
(make-obsolete #'exwm-randr-enable "Use `exwm-randr-mode' instead." "0.40")
|
2015-08-13 06:02:44 +02:00
|
|
|
|
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'exwm-randr)
|
|
|
|
|
|
|
|
|
|
;;; exwm-randr.el ends here
|