2015-08-03 14:26:53 +02:00
|
|
|
|
;;; exwm-randr.el --- RandR Module for EXWM -*- lexical-binding: t -*-
|
|
|
|
|
|
2017-12-31 13:49:37 +01:00
|
|
|
|
;; Copyright (C) 2015-2018 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
|
|
|
|
|
;; `exwm-randr-workspace-output-plist' and `exwm-randr-screen-change-hook'
|
|
|
|
|
;; as follows:
|
|
|
|
|
;;
|
2015-08-13 06:02:44 +02:00
|
|
|
|
;; (require 'exwm-randr)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
;; (setq exwm-randr-workspace-output-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)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(require 'exwm-core)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(defgroup exwm-randr nil
|
|
|
|
|
"RandR."
|
|
|
|
|
:version "25.3"
|
|
|
|
|
: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)
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-randr-workspace-output-plist nil
|
|
|
|
|
"Plist mapping workspace to output.
|
|
|
|
|
|
|
|
|
|
If an output is not available, the workspaces mapped to it are displayed on
|
|
|
|
|
the primary output until it becomes available. Unspecified workspaces are
|
|
|
|
|
all mapped to the primary output. For example, with the following value
|
|
|
|
|
workspace other than 1 and 3 would always be displayed on the primary output
|
|
|
|
|
where workspace 1 and 3 would be displayed on their corresponding output
|
|
|
|
|
whenever the outputs are available.
|
|
|
|
|
|
|
|
|
|
'(1 \"HDMI-1\" 3 \"DP-1\")
|
|
|
|
|
|
|
|
|
|
The outputs available can be identified by running the 'xrandr' utility with
|
|
|
|
|
the first one in result being the primary output."
|
|
|
|
|
:type '(plist :key-type integer :value-type string))
|
2016-02-19 10:12:43 +01:00
|
|
|
|
|
2016-07-12 12:35:51 +02:00
|
|
|
|
(defvar exwm-workspace--fullscreen-frame-count)
|
2016-02-19 10:12:43 +01:00
|
|
|
|
(defvar exwm-workspace--list)
|
2018-02-22 15:21:54 +01:00
|
|
|
|
(declare-function exwm-workspace--active-p "exwm-workspace.el" (frame))
|
2016-07-17 14:00:00 +02:00
|
|
|
|
(declare-function exwm-workspace--count "exwm-workspace.el")
|
2018-02-22 15:21:54 +01:00
|
|
|
|
(declare-function exwm-workspace--set-active "exwm-workspace.el"
|
|
|
|
|
(frame active))
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(declare-function exwm-workspace--set-desktop-geometry "exwm-workspace.el" ())
|
2016-07-16 08:34:57 +02:00
|
|
|
|
(declare-function exwm-workspace--set-fullscreen "exwm-workspace.el" (frame))
|
2016-07-21 06:48:12 +02:00
|
|
|
|
(declare-function exwm-workspace--show-minibuffer "exwm-workspace.el" ())
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(declare-function exwm-workspace--update-workareas "exwm-workspace.el" ())
|
2016-02-19 10:12:43 +01:00
|
|
|
|
|
2015-08-03 14:26:53 +02:00
|
|
|
|
(defun exwm-randr--refresh ()
|
|
|
|
|
"Refresh workspaces according to the updated RandR info."
|
2018-02-21 17:31:57 +01:00
|
|
|
|
(let (output-name geometry output-plist primary-output default-geometry
|
|
|
|
|
container-output-alist container-frame-alist)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
;; Query all outputs
|
|
|
|
|
(with-slots (config-timestamp outputs)
|
|
|
|
|
(xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:randr:GetScreenResources
|
|
|
|
|
:window exwm--root))
|
|
|
|
|
(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))
|
2015-09-11 15:00:27 +02:00
|
|
|
|
(setf output-name ;UTF-8 encoded
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(decode-coding-string (apply #'unibyte-string name) 'utf-8))
|
2015-08-03 14:26:53 +02:00
|
|
|
|
(if (or (/= connection xcb:randr:Connection:Connected)
|
|
|
|
|
(= 0 crtc)) ;FIXME
|
2015-09-11 15:00:27 +02:00
|
|
|
|
(plist-put output-plist output-name nil)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
(with-slots (x y width height)
|
|
|
|
|
(xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:randr:GetCrtcInfo
|
|
|
|
|
:crtc crtc
|
|
|
|
|
:config-timestamp config-timestamp))
|
2015-08-26 11:25:21 +02:00
|
|
|
|
(setq geometry (make-instance 'xcb:RECTANGLE
|
|
|
|
|
:x x :y y
|
|
|
|
|
:width width :height height)
|
2015-09-11 15:00:27 +02:00
|
|
|
|
output-plist (plist-put output-plist output-name geometry))
|
2018-02-20 15:17:22 +01:00
|
|
|
|
(unless primary-output
|
|
|
|
|
(setq primary-output output-name
|
|
|
|
|
default-geometry geometry)))))))
|
2016-02-06 09:47:30 +01:00
|
|
|
|
(exwm--log "(randr) outputs: %s" output-plist)
|
2016-02-07 03:22:33 +01:00
|
|
|
|
(when output-plist
|
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))
|
2016-02-07 03:22:33 +01:00
|
|
|
|
(let* ((output (plist-get exwm-randr-workspace-output-plist i))
|
|
|
|
|
(geometry (lax-plist-get output-plist output))
|
2018-02-21 17:31:57 +01:00
|
|
|
|
(frame (elt exwm-workspace--list i))
|
|
|
|
|
(container (frame-parameter frame 'exwm-container)))
|
2016-02-07 03:22:33 +01:00
|
|
|
|
(unless geometry
|
|
|
|
|
(setq geometry default-geometry
|
2018-02-20 15:17:22 +01:00
|
|
|
|
output primary-output))
|
2018-02-21 17:31:57 +01:00
|
|
|
|
(setq container-output-alist (nconc `((,container . ,output))
|
|
|
|
|
container-output-alist)
|
|
|
|
|
container-frame-alist (nconc `((,container . ,frame))
|
|
|
|
|
container-frame-alist))
|
2016-02-07 03:22:33 +01:00
|
|
|
|
(set-frame-parameter frame 'exwm-randr-output output)
|
2016-07-16 08:34:57 +02:00
|
|
|
|
(set-frame-parameter frame 'exwm-geometry 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-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)))
|
|
|
|
|
(let ((output (cdr (assq xwin container-output-alist))))
|
|
|
|
|
(when output
|
|
|
|
|
(setq container-output-alist
|
|
|
|
|
(rassq-delete-all output container-output-alist))
|
2018-02-22 15:21:54 +01:00
|
|
|
|
(exwm-workspace--set-active (cdr (assq xwin container-frame-alist))
|
|
|
|
|
t))))
|
2016-08-15 12:42:35 +02:00
|
|
|
|
;; Update workareas.
|
2016-07-16 08:34:57 +02:00
|
|
|
|
(exwm-workspace--update-workareas)
|
|
|
|
|
;; Resize workspace.
|
|
|
|
|
(dolist (f exwm-workspace--list)
|
|
|
|
|
(exwm-workspace--set-fullscreen f))
|
2016-07-21 06:48:12 +02:00
|
|
|
|
;; Raise the minibuffer if it's active.
|
|
|
|
|
(when (and (active-minibuffer-window)
|
|
|
|
|
(exwm-workspace--minibuffer-own-frame-p))
|
|
|
|
|
(exwm-workspace--show-minibuffer))
|
2016-07-13 12:51:32 +02:00
|
|
|
|
;; Set _NET_DESKTOP_GEOMETRY.
|
|
|
|
|
(exwm-workspace--set-desktop-geometry)
|
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
|
|
|
|
|
|
|
|
|
(defun exwm-randr--init ()
|
|
|
|
|
"Initialize RandR extension and EXWM RandR module."
|
|
|
|
|
(if (= 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 2))
|
|
|
|
|
(if (or (/= major-version 1) (< minor-version 2))
|
|
|
|
|
(error "[EXWM] The server only support RandR version up to %d.%d"
|
|
|
|
|
major-version minor-version)
|
2016-02-06 09:47:30 +01:00
|
|
|
|
;; External monitor(s) may already be connected.
|
|
|
|
|
(run-hooks 'exwm-randr-screen-change-hook)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
(exwm-randr--refresh)
|
|
|
|
|
(xcb:+event exwm--connection 'xcb:randr:ScreenChangeNotify
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(lambda (_data _synthetic)
|
2015-08-13 06:02:44 +02:00
|
|
|
|
(exwm--log "(RandR) ScreenChangeNotify")
|
2015-11-01 03:54:20 +01:00
|
|
|
|
(run-hooks 'exwm-randr-screen-change-hook)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
(exwm-randr--refresh)))
|
|
|
|
|
;; (xcb:+event exwm--connection 'xcb:randr:Notify
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; (lambda (_data _synthetic)
|
2015-08-13 06:02:44 +02:00
|
|
|
|
;; (exwm--log "(RandR) Notify")
|
2015-08-03 14:26:53 +02:00
|
|
|
|
;; (exwm-randr--refresh)))
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:randr:SelectInput
|
|
|
|
|
:window exwm--root
|
|
|
|
|
:enable xcb:randr:NotifyMask:ScreenChange
|
2015-09-27 13:31:00 +02:00
|
|
|
|
;; :enable (eval-when-compile
|
|
|
|
|
;; (logior
|
|
|
|
|
;; xcb:randr:NotifyMask:ScreenChange
|
|
|
|
|
;; xcb:randr:NotifyMask:OutputChange
|
|
|
|
|
;; xcb:randr:NotifyMask:OutputProperty
|
|
|
|
|
;; xcb:randr:NotifyMask:CrtcChange))
|
2015-08-03 14:26:53 +02:00
|
|
|
|
))
|
2016-07-19 04:34:38 +02:00
|
|
|
|
(xcb:flush exwm--connection)
|
2017-01-02 17:14:33 +01:00
|
|
|
|
(add-hook 'exwm-workspace-list-change-hook #'exwm-randr--refresh))))
|
|
|
|
|
;; Prevent frame parameters introduced by this module from being
|
|
|
|
|
;; saved/restored.
|
Make X windows container-less
; This is an attempt to make (managed) X windows container-less, i.e. direct children of the root window. This is mainly to make EXWM compatible with third-party compositors. Other issues like wrong absolute position should also get resolved by the way. The workspace containers ("virtual roots") are also removed. However Emacs frames are still wrapped in containers to avoid unexpected stack reordering.
* exwm-cm.el: Make this module obsolete as EXWM supports third-party compositors now.
* exwm-core.el (exwm--container):
* exwm-floating.el (exwm-floating--set-floating)
(exwm-floating--unset-floating, exwm-floating-hide)
(exwm-floating--start-moveresize, exwm-floating--stop-moveresize)
(exwm-floating--do-moveresize, exwm-floating-move):
* exwm-input.el (exwm-input--update-focus):
* exwm-layout.el (exwm-layout--show, exwm-layout--hide)
(exwm-layout-set-fullscreen, exwm-layout-unset-fullscreen):
* exwm-manage.el (exwm-manage--manage-window, exwm-manage--unmanage-window)
(exwm-manage--kill-buffer-query-function, exwm-manage--kill-client):
* exwm-workspace.el (exwm-workspace--set-fullscreen, exwm-workspace-switch)
(exwm-workspace-move-window, exwm-workspace--add-frame-as-workspace)
(exwm-workspace--remove-frame-as-workspace): Make adaptions for container-less X windows.
* exwm-workspace.el (exwm-workspace--update-ewmh-props):
* exwm.el (exwm--init-icccm-ewmh, exwm--exit-icccm-ewmh): No longer use virtual roots.
* exwm-input.el (exwm-input--on-workspace-list-change)
(exwm-input--update-global-prefix-keys, exwm-input--init, exwm-input--exit): From now on global key bindings are grabbed on the root window so it's no long required to re-grab them each time the workspace list changes. As a result `exwm-input--on-workspace-list-change' and its corresponding references are discarded. It remains to be seen if this change will raise input focus issues.
* exwm-manage.el (exwm-manage--manage-window): Explicitly set the workspace for newly managed X windows.
* exwm-floating.el (exwm-floating--set-floating): Avoid implicit reference to the current workspace.
* exwm-core.el (exwm--set-geometry): New function for setting the geometry of an X window.
* exwm-layout.el (exwm-layout--resize-container): Replaced by `exwm-layout--resize-container'.
* exwm-core.el (exwm--guide-window): New global variable recording the guide X window.
* exwm.el (exwm--init-icccm-ewmh): Set it.
* exwm-input.el (exwm-input--post-init): New function containing staffs for initialization but should better get called after the event loop starts.
* exwm.el (exwm-init): Use it.
2018-02-17 18:04:04 +01:00
|
|
|
|
(dolist (i '(exwm-randr-output))
|
2017-01-02 17:14:33 +01:00
|
|
|
|
(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."
|
|
|
|
|
(remove-hook 'exwm-workspace-list-change-hook #'exwm-randr--refresh))
|
2016-05-23 13:13:42 +02:00
|
|
|
|
|
2015-08-13 06:02:44 +02:00
|
|
|
|
(defun exwm-randr-enable ()
|
|
|
|
|
"Enable RandR support for EXWM."
|
2016-05-23 13:13:42 +02:00
|
|
|
|
(add-hook 'exwm-init-hook #'exwm-randr--init)
|
|
|
|
|
(add-hook 'exwm-exit-hook #'exwm-randr--exit))
|
2015-08-13 06:02:44 +02:00
|
|
|
|
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'exwm-randr)
|
|
|
|
|
|
|
|
|
|
;;; exwm-randr.el ends here
|