2015-08-03 14:26:53 +02:00
|
|
|
|
;;; exwm-randr.el --- RandR Module for EXWM -*- lexical-binding: t -*-
|
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; Copyright (C) 2015 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:
|
|
|
|
|
|
|
|
|
|
;; 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-13 06:02:44 +02:00
|
|
|
|
;; To use this module, first load/enable it and properly configure the variable
|
|
|
|
|
;; `exwm-randr-workspace-output-plist':
|
|
|
|
|
;; (require 'exwm-randr)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
;; (setq exwm-randr-workspace-output-plist '(0 "VGA1"))
|
2015-08-13 06:02:44 +02:00
|
|
|
|
;; (exwm-randr-enable)
|
2015-08-03 14:26:53 +02:00
|
|
|
|
;; Then configure RandR with 'xrandr':
|
|
|
|
|
;; $ xrandr --output VGA1 --left-of LVDS1 --auto
|
|
|
|
|
;; With above lines, workspace 0 should be assigned to the output named "VGA1",
|
|
|
|
|
;; staying at the left of other workspaces on the output "LVDS1".
|
|
|
|
|
|
|
|
|
|
;; 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)
|
|
|
|
|
(eval-when-compile (require 'exwm-workspace))
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
|
|
|
|
(defvar exwm-randr-workspace-output-plist nil)
|
|
|
|
|
|
|
|
|
|
(defun exwm-randr--refresh ()
|
|
|
|
|
"Refresh workspaces according to the updated RandR info."
|
2015-09-11 15:00:27 +02:00
|
|
|
|
(let (output-name geometry output-plist default-geometry workareas viewports)
|
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))
|
2015-08-03 14:26:53 +02:00
|
|
|
|
(unless default-geometry ;assume the first output as primary
|
2015-08-26 11:25:21 +02:00
|
|
|
|
(setq default-geometry geometry)))))))
|
2015-08-03 14:26:53 +02:00
|
|
|
|
(cl-assert (<= 2 (length output-plist)))
|
|
|
|
|
(dotimes (i exwm-workspace-number)
|
|
|
|
|
(let* ((output (plist-get exwm-randr-workspace-output-plist i))
|
|
|
|
|
(geometry (lax-plist-get output-plist output))
|
|
|
|
|
(frame (elt exwm-workspace--list i)))
|
|
|
|
|
(unless geometry
|
|
|
|
|
(setq geometry default-geometry
|
|
|
|
|
output nil))
|
|
|
|
|
(set-frame-parameter frame 'exwm-randr-output output)
|
2015-08-26 11:25:21 +02:00
|
|
|
|
(set-frame-parameter frame 'exwm-geometry geometry)
|
|
|
|
|
(with-slots (x y width height) geometry
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ConfigureWindow
|
|
|
|
|
:window (frame-parameter frame 'exwm-outer-id)
|
|
|
|
|
:value-mask (logior xcb:ConfigWindow:X
|
|
|
|
|
xcb:ConfigWindow:Y
|
|
|
|
|
xcb:ConfigWindow:Width
|
|
|
|
|
xcb:ConfigWindow:Height)
|
|
|
|
|
:x x :y y :width width :height height))
|
|
|
|
|
(setq workareas (nconc workareas (list x y width height))
|
|
|
|
|
viewports (nconc viewports (list x y))))))
|
|
|
|
|
;; Update _NET_WORKAREA
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_WORKAREA
|
|
|
|
|
:window exwm--root :data (vconcat workareas)))
|
|
|
|
|
;; Update _NET_DESKTOP_VIEWPORT
|
|
|
|
|
(xcb:+request exwm--connection
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_DESKTOP_VIEWPORT
|
|
|
|
|
:window exwm--root
|
|
|
|
|
:data (vconcat viewports)))
|
2015-08-03 14:26:53 +02:00
|
|
|
|
(xcb:flush exwm--connection)))
|
|
|
|
|
|
|
|
|
|
(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)
|
|
|
|
|
(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-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
|
|
|
|
|
;; :enable (logior
|
|
|
|
|
;; xcb:randr:NotifyMask:ScreenChange
|
|
|
|
|
;; xcb:randr:NotifyMask:OutputChange
|
|
|
|
|
;; xcb:randr:NotifyMask:OutputProperty
|
|
|
|
|
;; xcb:randr:NotifyMask:CrtcChange)
|
|
|
|
|
))
|
|
|
|
|
(xcb:flush exwm--connection)))))
|
|
|
|
|
|
2015-08-13 06:02:44 +02:00
|
|
|
|
(defun exwm-randr-enable ()
|
|
|
|
|
"Enable RandR support for EXWM."
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(add-hook 'exwm-init-hook #'exwm-randr--init))
|
2015-08-13 06:02:44 +02:00
|
|
|
|
|
2015-08-03 14:26:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'exwm-randr)
|
|
|
|
|
|
|
|
|
|
;;; exwm-randr.el ends here
|