2015-07-17 13:16:08 +02:00
|
|
|
|
;;; exwm.el --- Emacs X Window Manager -*- lexical-binding: t -*-
|
|
|
|
|
|
2024-01-08 01:00:00 +01:00
|
|
|
|
;; Copyright (C) 2015-2024 Free Software Foundation, Inc.
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
|
|
|
|
;; Author: Chris Feng <chris.w.feng@gmail.com>
|
2021-10-29 02:00:00 +02:00
|
|
|
|
;; Maintainer: Adrián Medraño Calvo <adrian@medranocalvo.com>
|
2023-10-06 02:00:00 +02:00
|
|
|
|
;; Version: 0.28
|
2023-12-30 01:55:25 +01:00
|
|
|
|
;; Package-Requires: ((emacs "26.1") (xelb "0.18"))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Keywords: unix
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; URL: https://github.com/ch11ng/exwm
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; This file is part of GNU Emacs.
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2015-07-17 13:16:08 +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-07-17 13:16:08 +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-07-17 13:16:08 +02:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Overview
|
|
|
|
|
;; --------
|
2016-07-19 04:36:14 +02:00
|
|
|
|
;; EXWM (Emacs X Window Manager) is a full-featured tiling X window manager
|
|
|
|
|
;; for Emacs built on top of [XELB](https://github.com/ch11ng/xelb).
|
|
|
|
|
;; It features:
|
2016-02-19 10:12:43 +01:00
|
|
|
|
;; + Fully keyboard-driven operations
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; + Hybrid layout modes (tiling & stacking)
|
2016-07-19 04:36:14 +02:00
|
|
|
|
;; + Dynamic workspace support
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; + ICCCM/EWMH compliance
|
2016-07-19 04:36:14 +02:00
|
|
|
|
;; + (Optional) RandR (multi-monitor) support
|
2016-08-15 16:59:48 +02:00
|
|
|
|
;; + (Optional) Built-in system tray
|
2024-01-09 09:43:07 +01:00
|
|
|
|
;; + (Optional) Builtin input method
|
|
|
|
|
;; + (Optional) Background setting support
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
|
|
|
|
;; Installation & configuration
|
|
|
|
|
;; ----------------------------
|
|
|
|
|
;; Here are the minimal steps to get EXWM working:
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; 1. Install XELB and EXWM, and make sure they are in `load-path'.
|
|
|
|
|
;; 2. In '~/.emacs', add following lines (please modify accordingly):
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;;
|
|
|
|
|
;; (require 'exwm)
|
2015-10-28 11:55:49 +01:00
|
|
|
|
;; (require 'exwm-config)
|
2020-05-10 02:00:00 +02:00
|
|
|
|
;; (exwm-config-example)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;;
|
2015-10-28 11:55:49 +01:00
|
|
|
|
;; 3. Link or copy the file 'xinitrc' to '~/.xinitrc'.
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; 4. Launch EXWM in a console (e.g. tty1) with
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;;
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; xinit -- vt01
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;;
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;; You should additionally hide the menu-bar, tool-bar, etc to increase the
|
|
|
|
|
;; usable space. Please check the wiki (https://github.com/ch11ng/exwm/wiki)
|
|
|
|
|
;; for more detailed instructions on installation, configuration, usage, etc.
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
|
|
|
|
;; References:
|
|
|
|
|
;; + dwm (http://dwm.suckless.org/)
|
|
|
|
|
;; + i3 wm (https://i3wm.org/)
|
|
|
|
|
;; + Also see references within each required library.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2015-09-27 13:31:00 +02:00
|
|
|
|
(require 'server)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(require 'exwm-core)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(require 'exwm-workspace)
|
|
|
|
|
(require 'exwm-layout)
|
|
|
|
|
(require 'exwm-floating)
|
|
|
|
|
(require 'exwm-manage)
|
|
|
|
|
(require 'exwm-input)
|
|
|
|
|
|
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 nil
|
|
|
|
|
"Emacs X Window Manager."
|
|
|
|
|
:tag "EXWM"
|
|
|
|
|
:version "25.3"
|
|
|
|
|
:group 'applications
|
|
|
|
|
:prefix "exwm-")
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-init-hook nil
|
|
|
|
|
"Normal hook run when EXWM has just finished initialization."
|
|
|
|
|
:type 'hook)
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-exit-hook nil
|
|
|
|
|
"Normal hook run just before EXWM exits."
|
|
|
|
|
:type 'hook)
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-update-class-hook nil
|
|
|
|
|
"Normal hook run when window class is updated."
|
|
|
|
|
:type 'hook)
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-update-title-hook nil
|
|
|
|
|
"Normal hook run when window title is updated."
|
|
|
|
|
:type 'hook)
|
|
|
|
|
|
2023-12-29 15:38:33 +01:00
|
|
|
|
(defcustom exwm-blocking-subrs
|
|
|
|
|
(list #'x-file-dialog #'x-popup-dialog #'x-select-font
|
|
|
|
|
#'message-box #'message-or-box)
|
2018-02-18 17:04:27 +01:00
|
|
|
|
"Subrs (primitives) that would normally block EXWM."
|
|
|
|
|
:type '(repeat function))
|
|
|
|
|
|
2019-03-10 01:00:00 +01:00
|
|
|
|
(defcustom exwm-replace 'ask
|
|
|
|
|
"Whether to replace existing window manager."
|
|
|
|
|
:type '(radio (const :tag "Ask" ask)
|
|
|
|
|
(const :tag "Replace by default" t)
|
|
|
|
|
(const :tag "Do not replace" nil)))
|
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(defconst exwm--server-name "server-exwm"
|
|
|
|
|
"Name of the subordinate Emacs server.")
|
|
|
|
|
|
2023-12-30 01:55:25 +01:00
|
|
|
|
(defvar exwm--server-timeout 1
|
2024-01-09 19:46:50 +01:00
|
|
|
|
"Number of seconds to wait for the subordinate Emacs server to exit.
|
|
|
|
|
After this time, the server will be killed.")
|
2023-12-30 01:55:25 +01:00
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(defvar exwm--server-process nil "Process of the subordinate Emacs server.")
|
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-reset ()
|
2018-02-18 17:04:27 +01:00
|
|
|
|
"Reset the state of the selected window (non-fullscreen, line-mode, etc)."
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(interactive)
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2015-08-06 08:41:28 +02:00
|
|
|
|
(with-current-buffer (window-buffer)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(when (derived-mode-p 'exwm-mode)
|
2018-03-04 05:23:37 +01:00
|
|
|
|
(when (exwm-layout--fullscreen-p)
|
2016-08-12 13:27:26 +02:00
|
|
|
|
(exwm-layout-unset-fullscreen))
|
2015-08-08 14:12:07 +02:00
|
|
|
|
;; Force refresh
|
|
|
|
|
(exwm-layout--refresh)
|
2016-04-03 06:24:50 +02:00
|
|
|
|
(call-interactively #'exwm-input-grab-keyboard))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2016-07-30 13:01:33 +02:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun exwm-restart ()
|
|
|
|
|
"Restart EXWM."
|
|
|
|
|
(interactive)
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2021-12-09 01:00:00 +01:00
|
|
|
|
(when (exwm--confirm-kill-emacs "Restart?" 'no-check)
|
2016-08-01 13:49:43 +02:00
|
|
|
|
(let* ((attr (process-attributes (emacs-pid)))
|
|
|
|
|
(args (cdr (assq 'args attr)))
|
|
|
|
|
(ppid (cdr (assq 'ppid attr)))
|
|
|
|
|
(pargs (cdr (assq 'args (process-attributes ppid)))))
|
|
|
|
|
(cond
|
|
|
|
|
((= ppid 1)
|
|
|
|
|
;; The parent is the init process. This probably means this
|
|
|
|
|
;; instance is an emacsclient. Anyway, start a control instance
|
|
|
|
|
;; to manage the subsequent ones.
|
|
|
|
|
(call-process (car command-line-args))
|
|
|
|
|
(kill-emacs))
|
|
|
|
|
((string= args pargs)
|
|
|
|
|
;; This is a subordinate instance. Return a magic number to
|
|
|
|
|
;; inform the parent (control instance) to start another one.
|
|
|
|
|
(kill-emacs ?R))
|
|
|
|
|
(t
|
|
|
|
|
;; This is the control instance. Keep starting subordinate
|
|
|
|
|
;; instances until told to exit.
|
|
|
|
|
;; Run `server-force-stop' if it exists.
|
|
|
|
|
(run-hooks 'kill-emacs-hook)
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(while (= ?R (shell-command-on-region (point) (point) args))))
|
|
|
|
|
(kill-emacs))))))
|
2016-07-30 13:01:33 +02:00
|
|
|
|
|
2018-02-19 15:34:03 +01:00
|
|
|
|
(defun exwm--update-desktop (xwin)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update _NET_WM_DESKTOP.
|
|
|
|
|
Argument XWIN contains the X window of the `exwm-mode' buffer."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" xwin)
|
2018-02-19 15:34:03 +01:00
|
|
|
|
(with-current-buffer (exwm--id->buffer xwin)
|
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:get-_NET_WM_DESKTOP
|
|
|
|
|
:window xwin)))
|
|
|
|
|
desktop)
|
|
|
|
|
(when reply
|
|
|
|
|
(setq desktop (slot-value reply 'value))
|
|
|
|
|
(cond
|
2018-04-15 23:52:39 +02:00
|
|
|
|
((eq desktop 4294967295.)
|
2018-02-19 15:34:03 +01:00
|
|
|
|
(unless (or (not exwm--floating-frame)
|
|
|
|
|
(eq exwm--frame exwm-workspace--current)
|
|
|
|
|
(and exwm--desktop
|
|
|
|
|
(= desktop exwm--desktop)))
|
|
|
|
|
(exwm-layout--show xwin (frame-root-window exwm--floating-frame)))
|
|
|
|
|
(setq exwm--desktop desktop))
|
|
|
|
|
((and desktop
|
|
|
|
|
(< desktop (exwm-workspace--count))
|
|
|
|
|
(if exwm--desktop
|
|
|
|
|
(/= desktop exwm--desktop)
|
|
|
|
|
(/= desktop (exwm-workspace--position exwm--frame))))
|
|
|
|
|
(exwm-workspace-move-window desktop xwin))
|
|
|
|
|
(t
|
|
|
|
|
(exwm-workspace--set-desktop xwin)))))))
|
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm--update-window-type (id &optional force)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update `exwm-window-type' from _NET_WM_WINDOW_TYPE.
|
|
|
|
|
Argument ID contains the X window of the `exwm-mode' buffer.
|
|
|
|
|
|
|
|
|
|
When FORCE is nil the update only takes place if
|
|
|
|
|
`exwm-window-type' is unset."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2015-08-10 08:23:37 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(unless (and exwm-window-type (not force))
|
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:get-_NET_WM_WINDOW_TYPE
|
|
|
|
|
:window id))))
|
|
|
|
|
(when reply ;nil when destroyed
|
|
|
|
|
(setq exwm-window-type (append (slot-value reply 'value) nil)))))))
|
|
|
|
|
|
|
|
|
|
(defun exwm--update-class (id &optional force)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update `exwm-instance-name' and `exwm-class' from WM_CLASS.
|
|
|
|
|
Argument ID contains the X window of the `exwm-mode' buffer.
|
|
|
|
|
|
|
|
|
|
When FORCE is nil the update only takes place if any of
|
|
|
|
|
`exwm-instance-name' or `exwm-class' is unset."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2015-08-10 08:23:37 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(unless (and exwm-instance-name exwm-class-name (not force))
|
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:icccm:get-WM_CLASS :window id))))
|
|
|
|
|
(when reply ;nil when destroyed
|
|
|
|
|
(setq exwm-instance-name (slot-value reply 'instance-name)
|
|
|
|
|
exwm-class-name (slot-value reply 'class-name))
|
|
|
|
|
(when (and exwm-instance-name exwm-class-name)
|
|
|
|
|
(run-hooks 'exwm-update-class-hook)))))))
|
|
|
|
|
|
|
|
|
|
(defun exwm--update-utf8-title (id &optional force)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update `exwm-title' from _NET_WM_NAME.
|
|
|
|
|
Argument ID contains the X window of the `exwm-mode' buffer.
|
|
|
|
|
|
|
|
|
|
When FORCE is nil the update only takes place if `exwm-title' is
|
|
|
|
|
unset."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2015-08-10 08:23:37 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(when (or force (not exwm-title))
|
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:get-_NET_WM_NAME :window id))))
|
|
|
|
|
(when reply ;nil when destroyed
|
|
|
|
|
(setq exwm-title (slot-value reply 'value))
|
|
|
|
|
(when exwm-title
|
|
|
|
|
(setq exwm--title-is-utf8 t)
|
|
|
|
|
(run-hooks 'exwm-update-title-hook)))))))
|
|
|
|
|
|
|
|
|
|
(defun exwm--update-ctext-title (id &optional force)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update `exwm-title' from WM_NAME.
|
|
|
|
|
Argument ID contains the X window of the `exwm-mode' buffer.
|
|
|
|
|
|
|
|
|
|
When FORCE is nil the update only takes place if `exwm-title' is
|
|
|
|
|
unset."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2015-08-10 08:23:37 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(unless (or exwm--title-is-utf8
|
|
|
|
|
(and exwm-title (not force)))
|
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:icccm:get-WM_NAME :window id))))
|
|
|
|
|
(when reply ;nil when destroyed
|
|
|
|
|
(setq exwm-title (slot-value reply 'value))
|
|
|
|
|
(when exwm-title
|
|
|
|
|
(run-hooks 'exwm-update-title-hook)))))))
|
|
|
|
|
|
|
|
|
|
(defun exwm--update-title (id)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update _NET_WM_NAME or WM_NAME.
|
|
|
|
|
Argument ID contains the X window of the `exwm-mode' buffer."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(exwm--update-utf8-title id)
|
|
|
|
|
(exwm--update-ctext-title id))
|
|
|
|
|
|
|
|
|
|
(defun exwm--update-transient-for (id &optional force)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update `exwm-transient-for' from WM_TRANSIENT_FOR.
|
|
|
|
|
Argument ID contains the X window of the `exwm-mode' buffer.
|
|
|
|
|
|
|
|
|
|
When FORCE is nil the update only takes place if `exwm-title' is
|
|
|
|
|
unset."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2015-08-10 08:23:37 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(unless (and exwm-transient-for (not force))
|
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:icccm:get-WM_TRANSIENT_FOR
|
|
|
|
|
:window id))))
|
|
|
|
|
(when reply ;nil when destroyed
|
|
|
|
|
(setq exwm-transient-for (slot-value reply 'value)))))))
|
|
|
|
|
|
|
|
|
|
(defun exwm--update-normal-hints (id &optional force)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update normal hints from WM_NORMAL_HINTS.
|
|
|
|
|
Argument ID contains the X window of the `exwm-mode' buffer.
|
|
|
|
|
|
|
|
|
|
When FORCE is nil the update only takes place all of
|
|
|
|
|
`exwm--normal-hints-x exwm--normal-hints-y',
|
|
|
|
|
`exwm--normal-hints-width exwm--normal-hints-height',
|
|
|
|
|
`exwm--normal-hints-min-width exwm--normal-hints-min-height' and
|
|
|
|
|
`exwm--normal-hints-max-width exwm--normal-hints-max-height' are
|
|
|
|
|
unset."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2015-08-10 08:23:37 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(unless (and (not force)
|
|
|
|
|
(or exwm--normal-hints-x exwm--normal-hints-y
|
|
|
|
|
exwm--normal-hints-width exwm--normal-hints-height
|
|
|
|
|
exwm--normal-hints-min-width exwm--normal-hints-min-height
|
|
|
|
|
exwm--normal-hints-max-width exwm--normal-hints-max-height
|
|
|
|
|
;; FIXME: other fields
|
|
|
|
|
))
|
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:icccm:get-WM_NORMAL_HINTS
|
|
|
|
|
:window id))))
|
|
|
|
|
(when (and reply (slot-value reply 'flags)) ;nil when destroyed
|
|
|
|
|
(with-slots (flags x y width height min-width min-height max-width
|
|
|
|
|
max-height base-width base-height ;; win-gravity
|
|
|
|
|
)
|
|
|
|
|
reply
|
|
|
|
|
(unless (= 0 (logand flags xcb:icccm:WM_SIZE_HINTS:USPosition))
|
|
|
|
|
(setq exwm--normal-hints-x x exwm--normal-hints-y y))
|
|
|
|
|
(unless (= 0 (logand flags xcb:icccm:WM_SIZE_HINTS:USSize))
|
|
|
|
|
(setq exwm--normal-hints-width width
|
|
|
|
|
exwm--normal-hints-height height))
|
|
|
|
|
(unless (= 0 (logand flags xcb:icccm:WM_SIZE_HINTS:PMinSize))
|
|
|
|
|
(setq exwm--normal-hints-min-width min-width
|
|
|
|
|
exwm--normal-hints-min-height min-height))
|
|
|
|
|
(unless (= 0 (logand flags xcb:icccm:WM_SIZE_HINTS:PMaxSize))
|
|
|
|
|
(setq exwm--normal-hints-max-width max-width
|
|
|
|
|
exwm--normal-hints-max-height max-height))
|
|
|
|
|
(unless (or exwm--normal-hints-min-width
|
|
|
|
|
(= 0 (logand flags xcb:icccm:WM_SIZE_HINTS:PBaseSize)))
|
|
|
|
|
(setq exwm--normal-hints-min-width base-width
|
|
|
|
|
exwm--normal-hints-min-height base-height))
|
|
|
|
|
;; (unless (= 0 (logand flags xcb:icccm:WM_SIZE_HINTS:PWinGravity))
|
|
|
|
|
;; (setq exwm--normal-hints-win-gravity win-gravity))
|
|
|
|
|
(setq exwm--fixed-size
|
|
|
|
|
(and exwm--normal-hints-min-width
|
|
|
|
|
exwm--normal-hints-min-height
|
|
|
|
|
exwm--normal-hints-max-width
|
|
|
|
|
exwm--normal-hints-max-height
|
|
|
|
|
(/= 0 exwm--normal-hints-min-width)
|
|
|
|
|
(/= 0 exwm--normal-hints-min-height)
|
|
|
|
|
(= exwm--normal-hints-min-width
|
|
|
|
|
exwm--normal-hints-max-width)
|
|
|
|
|
(= exwm--normal-hints-min-height
|
|
|
|
|
exwm--normal-hints-max-height)))))))))
|
|
|
|
|
|
|
|
|
|
(defun exwm--update-hints (id &optional force)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update hints from WM_HINTS.
|
|
|
|
|
Argument ID contains the X window of the `exwm-mode' buffer.
|
|
|
|
|
|
|
|
|
|
When FORCE is nil the update only takes place if both of
|
|
|
|
|
`exwm--hints-input' and `exwm--hints-urgency' are unset."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2015-08-10 08:23:37 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(unless (and (not force) exwm--hints-input exwm--hints-urgency)
|
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:icccm:get-WM_HINTS :window id))))
|
|
|
|
|
(when (and reply (slot-value reply 'flags)) ;nil when destroyed
|
2016-07-13 12:51:32 +02:00
|
|
|
|
(with-slots (flags input initial-state) reply
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(when flags
|
|
|
|
|
(unless (= 0 (logand flags xcb:icccm:WM_HINTS:InputHint))
|
|
|
|
|
(setq exwm--hints-input (when input (= 1 input))))
|
2016-07-13 12:51:32 +02:00
|
|
|
|
(unless (= 0 (logand flags xcb:icccm:WM_HINTS:StateHint))
|
|
|
|
|
(setq exwm-state initial-state))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(unless (= 0 (logand flags xcb:icccm:WM_HINTS:UrgencyHint))
|
|
|
|
|
(setq exwm--hints-urgency t))))
|
|
|
|
|
(when (and exwm--hints-urgency
|
|
|
|
|
(not (eq exwm--frame exwm-workspace--current)))
|
2016-07-21 06:41:51 +02:00
|
|
|
|
(unless (frame-parameter exwm--frame 'exwm-urgency)
|
|
|
|
|
(set-frame-parameter exwm--frame 'exwm-urgency t)
|
2015-09-17 13:48:50 +02:00
|
|
|
|
(setq exwm-workspace--switch-history-outdated t))))))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
|
|
|
|
(defun exwm--update-protocols (id &optional force)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update `exwm--protocols' from WM_PROTOCOLS.
|
|
|
|
|
Argument ID contains the X window of the `exwm-mode' buffer.
|
|
|
|
|
|
|
|
|
|
When FORCE is nil the update only takes place if `exwm--protocols'
|
|
|
|
|
is unset."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2015-08-10 08:23:37 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(unless (and exwm--protocols (not force))
|
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:icccm:get-WM_PROTOCOLS
|
|
|
|
|
:window id))))
|
|
|
|
|
(when reply ;nil when destroyed
|
|
|
|
|
(setq exwm--protocols (append (slot-value reply 'value) nil)))))))
|
|
|
|
|
|
2016-07-15 14:04:56 +02:00
|
|
|
|
(defun exwm--update-struts-legacy (id)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update struts of X window ID from _NET_WM_STRUT."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2016-07-15 14:04:56 +02:00
|
|
|
|
(let ((pair (assq id exwm-workspace--id-struts-alist))
|
|
|
|
|
reply struts)
|
|
|
|
|
(unless (and pair (< 4 (length (cdr pair))))
|
|
|
|
|
(setq reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:get-_NET_WM_STRUT
|
|
|
|
|
:window id)))
|
|
|
|
|
(when reply
|
|
|
|
|
(setq struts (slot-value reply 'value))
|
2016-08-12 14:28:05 +02:00
|
|
|
|
(if pair
|
|
|
|
|
(setcdr pair struts)
|
|
|
|
|
(push (cons id struts) exwm-workspace--id-struts-alist))
|
2016-07-15 14:04:56 +02:00
|
|
|
|
(exwm-workspace--update-struts))
|
2016-08-15 12:42:35 +02:00
|
|
|
|
;; Update workareas.
|
2016-07-16 08:34:57 +02:00
|
|
|
|
(exwm-workspace--update-workareas)
|
2016-07-12 12:35:51 +02:00
|
|
|
|
;; Update workspaces.
|
|
|
|
|
(dolist (f exwm-workspace--list)
|
2016-07-16 08:34:57 +02:00
|
|
|
|
(exwm-workspace--set-fullscreen f)))))
|
2016-07-12 12:35:51 +02:00
|
|
|
|
|
2016-07-15 14:04:56 +02:00
|
|
|
|
(defun exwm--update-struts-partial (id)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update struts of X window ID from _NET_WM_STRUT_PARTIAL."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2016-07-12 12:35:51 +02:00
|
|
|
|
(let ((reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:get-_NET_WM_STRUT_PARTIAL
|
2016-07-15 14:04:56 +02:00
|
|
|
|
:window id)))
|
|
|
|
|
struts pair)
|
|
|
|
|
(when reply
|
|
|
|
|
(setq struts (slot-value reply 'value)
|
|
|
|
|
pair (assq id exwm-workspace--id-struts-alist))
|
2016-08-12 14:28:05 +02:00
|
|
|
|
(if pair
|
|
|
|
|
(setcdr pair struts)
|
|
|
|
|
(push (cons id struts) exwm-workspace--id-struts-alist))
|
2016-07-15 14:04:56 +02:00
|
|
|
|
(exwm-workspace--update-struts))
|
2016-08-15 12:42:35 +02:00
|
|
|
|
;; Update workareas.
|
2016-07-16 08:34:57 +02:00
|
|
|
|
(exwm-workspace--update-workareas)
|
2016-07-12 12:35:51 +02:00
|
|
|
|
;; Update workspaces.
|
|
|
|
|
(dolist (f exwm-workspace--list)
|
2016-07-16 08:34:57 +02:00
|
|
|
|
(exwm-workspace--set-fullscreen f))))
|
2016-07-12 12:35:51 +02:00
|
|
|
|
|
2016-07-15 14:04:56 +02:00
|
|
|
|
(defun exwm--update-struts (id)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Update struts of X window ID from _NET_WM_STRUT_PARTIAL or _NET_WM_STRUT."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2016-07-15 14:04:56 +02:00
|
|
|
|
(exwm--update-struts-partial id)
|
|
|
|
|
(exwm--update-struts-legacy id))
|
2016-07-12 12:35:51 +02:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(defun exwm--on-PropertyNotify (data _synthetic)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Handle PropertyNotify event.
|
|
|
|
|
DATA contains unmarshalled PropertyNotify event data."
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(let ((obj (make-instance 'xcb:PropertyNotify))
|
2015-09-04 03:09:59 +02:00
|
|
|
|
atom id buffer)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:unmarshal obj data)
|
|
|
|
|
(setq id (slot-value obj 'window)
|
2016-08-09 07:34:29 +02:00
|
|
|
|
atom (slot-value obj 'atom))
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "atom=%s(%s)" (x-get-atom-name atom exwm-workspace--current) atom)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(setq buffer (exwm--id->buffer id))
|
2016-07-12 12:35:51 +02:00
|
|
|
|
(if (not (buffer-live-p buffer))
|
|
|
|
|
;; Properties of unmanaged X windows.
|
|
|
|
|
(cond ((= atom xcb:Atom:_NET_WM_STRUT)
|
2016-07-15 14:04:56 +02:00
|
|
|
|
(exwm--update-struts-legacy id))
|
2016-07-12 12:35:51 +02:00
|
|
|
|
((= atom xcb:Atom:_NET_WM_STRUT_PARTIAL)
|
2016-07-15 14:04:56 +02:00
|
|
|
|
(exwm--update-struts-partial id)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(cond ((= atom xcb:Atom:_NET_WM_WINDOW_TYPE)
|
|
|
|
|
(exwm--update-window-type id t))
|
|
|
|
|
((= atom xcb:Atom:WM_CLASS)
|
|
|
|
|
(exwm--update-class id t))
|
|
|
|
|
((= atom xcb:Atom:_NET_WM_NAME)
|
|
|
|
|
(exwm--update-utf8-title id t))
|
|
|
|
|
((= atom xcb:Atom:WM_NAME)
|
|
|
|
|
(exwm--update-ctext-title id t))
|
|
|
|
|
((= atom xcb:Atom:WM_TRANSIENT_FOR)
|
|
|
|
|
(exwm--update-transient-for id t))
|
|
|
|
|
((= atom xcb:Atom:WM_NORMAL_HINTS)
|
|
|
|
|
(exwm--update-normal-hints id t))
|
|
|
|
|
((= atom xcb:Atom:WM_HINTS)
|
|
|
|
|
(exwm--update-hints id t))
|
|
|
|
|
((= atom xcb:Atom:WM_PROTOCOLS)
|
|
|
|
|
(exwm--update-protocols id t))
|
2015-08-08 14:12:07 +02:00
|
|
|
|
((= atom xcb:Atom:_NET_WM_USER_TIME)) ;ignored
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(t
|
|
|
|
|
(exwm--log "Unhandled: %s(%d)"
|
|
|
|
|
(x-get-atom-name atom exwm-workspace--current)
|
|
|
|
|
atom)))))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(defun exwm--on-ClientMessage (raw-data _synthetic)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Handle ClientMessage event.
|
|
|
|
|
RAW-DATA contains unmarshalled ClientMessage event data."
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(let ((obj (make-instance 'xcb:ClientMessage))
|
|
|
|
|
type id data)
|
|
|
|
|
(xcb:unmarshal obj raw-data)
|
|
|
|
|
(setq type (slot-value obj 'type)
|
|
|
|
|
id (slot-value obj 'window)
|
|
|
|
|
data (slot-value (slot-value obj 'data) 'data32))
|
2022-10-12 10:47:11 +02:00
|
|
|
|
(exwm--log "atom=%s(%s) id=#x%x data=%s" (x-get-atom-name type exwm-workspace--current)
|
|
|
|
|
type (or id 0) data)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(cond
|
2016-07-19 04:30:21 +02:00
|
|
|
|
;; _NET_NUMBER_OF_DESKTOPS.
|
|
|
|
|
((= type xcb:Atom:_NET_NUMBER_OF_DESKTOPS)
|
|
|
|
|
(let ((current (exwm-workspace--count))
|
|
|
|
|
(requested (elt data 0)))
|
|
|
|
|
;; Only allow increasing/decreasing the workspace number by 1.
|
|
|
|
|
(cond
|
|
|
|
|
((< current requested)
|
|
|
|
|
(make-frame))
|
|
|
|
|
((and (> current requested)
|
|
|
|
|
(> current 1))
|
2019-06-30 02:00:00 +02:00
|
|
|
|
(let ((frame (car (last exwm-workspace--list))))
|
|
|
|
|
(delete-frame frame))))))
|
2016-07-13 12:51:32 +02:00
|
|
|
|
;; _NET_CURRENT_DESKTOP.
|
|
|
|
|
((= type xcb:Atom:_NET_CURRENT_DESKTOP)
|
|
|
|
|
(exwm-workspace-switch (elt data 0)))
|
|
|
|
|
;; _NET_ACTIVE_WINDOW.
|
|
|
|
|
((= type xcb:Atom:_NET_ACTIVE_WINDOW)
|
2018-11-18 01:00:00 +01:00
|
|
|
|
(let ((buffer (exwm--id->buffer id))
|
|
|
|
|
iconic window)
|
2022-10-12 10:47:11 +02:00
|
|
|
|
(if (buffer-live-p buffer)
|
|
|
|
|
;; Either an `exwm-mode' buffer (an X window) or a floating frame.
|
2016-07-13 12:51:32 +02:00
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(when (eq exwm--frame exwm-workspace--current)
|
2019-09-22 02:00:00 +02:00
|
|
|
|
(if exwm--floating-frame
|
|
|
|
|
(select-frame exwm--floating-frame)
|
|
|
|
|
(setq iconic (exwm-layout--iconic-state-p))
|
|
|
|
|
(when iconic
|
|
|
|
|
;; State change: iconic => normal.
|
|
|
|
|
(set-window-buffer (frame-selected-window exwm--frame)
|
|
|
|
|
(current-buffer)))
|
|
|
|
|
;; Focus transfer.
|
|
|
|
|
(setq window (get-buffer-window nil t))
|
|
|
|
|
(when (or iconic
|
|
|
|
|
(not (eq window (selected-window))))
|
2022-10-12 10:47:11 +02:00
|
|
|
|
(select-window window)))))
|
|
|
|
|
;; A workspace.
|
|
|
|
|
(dolist (f exwm-workspace--list)
|
|
|
|
|
(when (eq id (frame-parameter f 'exwm-outer-id))
|
|
|
|
|
(x-focus-frame f t))))))
|
2016-07-13 12:51:32 +02:00
|
|
|
|
;; _NET_CLOSE_WINDOW.
|
|
|
|
|
((= type xcb:Atom:_NET_CLOSE_WINDOW)
|
|
|
|
|
(let ((buffer (exwm--id->buffer id)))
|
|
|
|
|
(when (buffer-live-p buffer)
|
2019-08-25 02:00:00 +02:00
|
|
|
|
(exwm--defer 0 #'kill-buffer buffer))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; _NET_WM_MOVERESIZE
|
|
|
|
|
((= type xcb:Atom:_NET_WM_MOVERESIZE)
|
|
|
|
|
(let ((direction (elt data 2))
|
|
|
|
|
(buffer (exwm--id->buffer id)))
|
2016-07-21 06:41:51 +02:00
|
|
|
|
(unless (and buffer
|
|
|
|
|
(not (buffer-local-value 'exwm--floating-frame buffer)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(cond ((= direction
|
|
|
|
|
xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_KEYBOARD)
|
|
|
|
|
;; FIXME
|
|
|
|
|
)
|
|
|
|
|
((= direction
|
|
|
|
|
xcb:ewmh:_NET_WM_MOVERESIZE_MOVE_KEYBOARD)
|
|
|
|
|
;; FIXME
|
|
|
|
|
)
|
|
|
|
|
((= direction xcb:ewmh:_NET_WM_MOVERESIZE_CANCEL)
|
|
|
|
|
(exwm-floating--stop-moveresize))
|
2019-12-15 01:00:00 +01:00
|
|
|
|
;; In case it's a workspace frame.
|
|
|
|
|
((and (not buffer)
|
|
|
|
|
(catch 'break
|
|
|
|
|
(dolist (f exwm-workspace--list)
|
|
|
|
|
(when (or (eq id (frame-parameter f 'exwm-outer-id))
|
|
|
|
|
(eq id (frame-parameter f 'exwm-id)))
|
|
|
|
|
(throw 'break t)))
|
|
|
|
|
nil)))
|
|
|
|
|
(t
|
|
|
|
|
;; In case it's a floating frame,
|
|
|
|
|
;; move the corresponding X window instead.
|
|
|
|
|
(unless buffer
|
|
|
|
|
(catch 'break
|
|
|
|
|
(dolist (pair exwm--id-buffer-alist)
|
|
|
|
|
(with-current-buffer (cdr pair)
|
|
|
|
|
(when
|
|
|
|
|
(and exwm--floating-frame
|
|
|
|
|
(or (eq id
|
|
|
|
|
(frame-parameter exwm--floating-frame
|
|
|
|
|
'exwm-outer-id))
|
|
|
|
|
(eq id
|
|
|
|
|
(frame-parameter exwm--floating-frame
|
|
|
|
|
'exwm-id))))
|
|
|
|
|
(setq id exwm--id)
|
|
|
|
|
(throw 'break nil))))))
|
|
|
|
|
;; Start to move it.
|
|
|
|
|
(exwm-floating--start-moveresize id direction))))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; _NET_REQUEST_FRAME_EXTENTS
|
|
|
|
|
((= type xcb:Atom:_NET_REQUEST_FRAME_EXTENTS)
|
|
|
|
|
(let ((buffer (exwm--id->buffer id))
|
2016-09-23 12:41:43 +02:00
|
|
|
|
top btm)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(if (or (not buffer)
|
2016-07-21 06:41:51 +02:00
|
|
|
|
(not (buffer-local-value 'exwm--floating-frame buffer)))
|
2016-09-23 12:41:43 +02:00
|
|
|
|
(setq top 0
|
|
|
|
|
btm 0)
|
|
|
|
|
(setq top (window-header-line-height)
|
|
|
|
|
btm (window-mode-line-height)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_FRAME_EXTENTS
|
2016-09-23 12:41:43 +02:00
|
|
|
|
:window id
|
|
|
|
|
:left 0
|
|
|
|
|
:right 0
|
|
|
|
|
:top top
|
|
|
|
|
:bottom btm)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:flush exwm--connection))
|
2016-07-13 12:51:32 +02:00
|
|
|
|
;; _NET_WM_DESKTOP.
|
|
|
|
|
((= type xcb:Atom:_NET_WM_DESKTOP)
|
|
|
|
|
(let ((buffer (exwm--id->buffer id)))
|
|
|
|
|
(when (buffer-live-p buffer)
|
|
|
|
|
(exwm-workspace-move-window (elt data 0) id))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; _NET_WM_STATE
|
|
|
|
|
((= type xcb:Atom:_NET_WM_STATE)
|
|
|
|
|
(let ((action (elt data 0))
|
|
|
|
|
(props (list (elt data 1) (elt data 2)))
|
|
|
|
|
(buffer (exwm--id->buffer id))
|
|
|
|
|
props-new)
|
2015-08-24 21:09:42 +02:00
|
|
|
|
;; only support _NET_WM_STATE_FULLSCREEN / _NET_WM_STATE_ADD for frames
|
|
|
|
|
(when (and (not buffer)
|
|
|
|
|
(memq xcb:Atom:_NET_WM_STATE_FULLSCREEN props)
|
|
|
|
|
(= action xcb:ewmh:_NET_WM_STATE_ADD))
|
2018-02-20 15:09:27 +01:00
|
|
|
|
(xcb:+request
|
|
|
|
|
exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_WM_STATE
|
|
|
|
|
:window id
|
2018-03-04 05:23:37 +01:00
|
|
|
|
:data (vector xcb:Atom:_NET_WM_STATE_FULLSCREEN)))
|
2018-02-20 15:09:27 +01:00
|
|
|
|
(xcb:flush exwm--connection))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(when buffer ;ensure it's managed
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
;; _NET_WM_STATE_FULLSCREEN
|
2015-08-06 06:32:14 +02:00
|
|
|
|
(when (or (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN props)
|
|
|
|
|
(memq xcb:Atom:_NET_WM_STATE_ABOVE props))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(cond ((= action xcb:ewmh:_NET_WM_STATE_ADD)
|
2018-03-04 05:23:37 +01:00
|
|
|
|
(unless (exwm-layout--fullscreen-p)
|
2016-08-12 13:27:26 +02:00
|
|
|
|
(exwm-layout-set-fullscreen id))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(push xcb:Atom:_NET_WM_STATE_FULLSCREEN props-new))
|
|
|
|
|
((= action xcb:ewmh:_NET_WM_STATE_REMOVE)
|
2018-03-04 05:23:37 +01:00
|
|
|
|
(when (exwm-layout--fullscreen-p)
|
2016-08-12 13:27:26 +02:00
|
|
|
|
(exwm-layout-unset-fullscreen id)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
((= action xcb:ewmh:_NET_WM_STATE_TOGGLE)
|
2018-03-04 05:23:37 +01:00
|
|
|
|
(if (exwm-layout--fullscreen-p)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(exwm-layout-unset-fullscreen id)
|
|
|
|
|
(exwm-layout-set-fullscreen id)
|
|
|
|
|
(push xcb:Atom:_NET_WM_STATE_FULLSCREEN props-new)))))
|
|
|
|
|
;; _NET_WM_STATE_DEMANDS_ATTENTION
|
|
|
|
|
;; FIXME: check (may require other properties set)
|
|
|
|
|
(when (memq xcb:Atom:_NET_WM_STATE_DEMANDS_ATTENTION props)
|
|
|
|
|
(when (= action xcb:ewmh:_NET_WM_STATE_ADD)
|
2016-07-17 14:00:00 +02:00
|
|
|
|
(unless (eq exwm--frame exwm-workspace--current)
|
2016-07-21 06:41:51 +02:00
|
|
|
|
(set-frame-parameter exwm--frame 'exwm-urgency t)
|
2016-07-17 14:00:00 +02:00
|
|
|
|
(setq exwm-workspace--switch-history-outdated t)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; xcb:ewmh:_NET_WM_STATE_REMOVE?
|
|
|
|
|
;; xcb:ewmh:_NET_WM_STATE_TOGGLE?
|
|
|
|
|
)
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_WM_STATE
|
|
|
|
|
:window id :data (vconcat props-new)))
|
|
|
|
|
(xcb:flush exwm--connection)))))
|
|
|
|
|
((= type xcb:Atom:WM_PROTOCOLS)
|
|
|
|
|
(let ((type (elt data 0)))
|
|
|
|
|
(cond ((= type xcb:Atom:_NET_WM_PING)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(setq exwm-manage--ping-lock nil))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(t (exwm--log "Unhandled WM_PROTOCOLS of type: %d" type)))))
|
2016-07-13 12:51:32 +02:00
|
|
|
|
((= type xcb:Atom:WM_CHANGE_STATE)
|
|
|
|
|
(let ((buffer (exwm--id->buffer id)))
|
|
|
|
|
(when (and (buffer-live-p buffer)
|
|
|
|
|
(= (elt data 0) xcb:icccm:WM_STATE:IconicState))
|
|
|
|
|
(with-current-buffer buffer
|
2019-06-16 02:00:00 +02:00
|
|
|
|
(if exwm--floating-frame
|
|
|
|
|
(call-interactively #'exwm-floating-hide)
|
|
|
|
|
(bury-buffer))))))
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(t
|
|
|
|
|
(exwm--log "Unhandled: %s(%d)"
|
|
|
|
|
(x-get-atom-name type exwm-workspace--current) type)))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(defun exwm--on-SelectionClear (data _synthetic)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Handle SelectionClear events.
|
|
|
|
|
DATA contains unmarshalled SelectionClear event data."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(let ((obj (make-instance 'xcb:SelectionClear))
|
|
|
|
|
owner selection)
|
|
|
|
|
(xcb:unmarshal obj data)
|
|
|
|
|
(setq owner (slot-value obj 'owner)
|
|
|
|
|
selection (slot-value obj 'selection))
|
|
|
|
|
(when (and (eq owner exwm--wmsn-window)
|
|
|
|
|
(eq selection xcb:Atom:WM_S0))
|
|
|
|
|
(exwm-exit))))
|
|
|
|
|
|
2021-12-09 01:00:00 +01:00
|
|
|
|
(defun exwm--on-delete-terminal (terminal)
|
|
|
|
|
"Handle terminal being deleted without Emacs being killed.
|
2023-08-18 02:00:00 +02:00
|
|
|
|
This function is Hooked to `delete-terminal-functions'.
|
|
|
|
|
|
|
|
|
|
TERMINAL is the terminal being (or that has been) deleted.
|
|
|
|
|
|
2021-12-09 01:00:00 +01:00
|
|
|
|
This may happen when invoking `save-buffers-kill-terminal' within an emacsclient
|
|
|
|
|
session."
|
|
|
|
|
(when (eq terminal exwm--terminal)
|
|
|
|
|
(exwm-exit)))
|
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm--init-icccm-ewmh ()
|
|
|
|
|
"Initialize ICCCM/EWMH support."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Handle PropertyNotify event
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(xcb:+event exwm--connection 'xcb:PropertyNotify #'exwm--on-PropertyNotify)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Handle relevant client messages
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(xcb:+event exwm--connection 'xcb:ClientMessage #'exwm--on-ClientMessage)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
;; Handle SelectionClear
|
|
|
|
|
(xcb:+event exwm--connection 'xcb:SelectionClear #'exwm--on-SelectionClear)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Set _NET_SUPPORTED
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_SUPPORTED
|
|
|
|
|
:window exwm--root
|
2016-07-13 12:51:32 +02:00
|
|
|
|
:data (vector
|
|
|
|
|
;; Root windows properties.
|
|
|
|
|
xcb:Atom:_NET_SUPPORTED
|
|
|
|
|
xcb:Atom:_NET_CLIENT_LIST
|
|
|
|
|
xcb:Atom:_NET_CLIENT_LIST_STACKING
|
|
|
|
|
xcb:Atom:_NET_NUMBER_OF_DESKTOPS
|
|
|
|
|
xcb:Atom:_NET_DESKTOP_GEOMETRY
|
|
|
|
|
xcb:Atom:_NET_DESKTOP_VIEWPORT
|
|
|
|
|
xcb:Atom:_NET_CURRENT_DESKTOP
|
|
|
|
|
;; xcb:Atom:_NET_DESKTOP_NAMES
|
|
|
|
|
xcb:Atom:_NET_ACTIVE_WINDOW
|
2016-08-15 12:42:35 +02:00
|
|
|
|
;; xcb:Atom:_NET_WORKAREA
|
2016-07-13 12:51:32 +02:00
|
|
|
|
xcb:Atom:_NET_SUPPORTING_WM_CHECK
|
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
|
|
|
|
;; xcb:Atom:_NET_VIRTUAL_ROOTS
|
2016-07-13 12:51:32 +02:00
|
|
|
|
;; xcb:Atom:_NET_DESKTOP_LAYOUT
|
|
|
|
|
;; xcb:Atom:_NET_SHOWING_DESKTOP
|
|
|
|
|
|
|
|
|
|
;; Other root window messages.
|
|
|
|
|
xcb:Atom:_NET_CLOSE_WINDOW
|
|
|
|
|
;; xcb:Atom:_NET_MOVERESIZE_WINDOW
|
|
|
|
|
xcb:Atom:_NET_WM_MOVERESIZE
|
|
|
|
|
;; xcb:Atom:_NET_RESTACK_WINDOW
|
|
|
|
|
xcb:Atom:_NET_REQUEST_FRAME_EXTENTS
|
|
|
|
|
|
|
|
|
|
;; Application window properties.
|
|
|
|
|
xcb:Atom:_NET_WM_NAME
|
|
|
|
|
;; xcb:Atom:_NET_WM_VISIBLE_NAME
|
|
|
|
|
;; xcb:Atom:_NET_WM_ICON_NAME
|
|
|
|
|
;; xcb:Atom:_NET_WM_VISIBLE_ICON_NAME
|
|
|
|
|
xcb:Atom:_NET_WM_DESKTOP
|
|
|
|
|
;;
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE
|
|
|
|
|
;; xcb:Atom:_NET_WM_WINDOW_TYPE_DESKTOP
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_DOCK
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_TOOLBAR
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_MENU
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_UTILITY
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_SPLASH
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_DIALOG
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_DROPDOWN_MENU
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_POPUP_MENU
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_TOOLTIP
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_NOTIFICATION
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_COMBO
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_DND
|
|
|
|
|
xcb:Atom:_NET_WM_WINDOW_TYPE_NORMAL
|
|
|
|
|
;;
|
|
|
|
|
xcb:Atom:_NET_WM_STATE
|
2016-09-22 13:08:13 +02:00
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_MODAL
|
2016-07-13 12:51:32 +02:00
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_STICKY
|
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_MAXIMIZED_VERT
|
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_MAXIMIZED_HORZ
|
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_SHADED
|
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_SKIP_TASKBAR
|
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_SKIP_PAGER
|
2020-03-29 01:00:00 +01:00
|
|
|
|
xcb:Atom:_NET_WM_STATE_HIDDEN
|
2016-07-13 12:51:32 +02:00
|
|
|
|
xcb:Atom:_NET_WM_STATE_FULLSCREEN
|
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_ABOVE
|
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_BELOW
|
|
|
|
|
xcb:Atom:_NET_WM_STATE_DEMANDS_ATTENTION
|
|
|
|
|
;; xcb:Atom:_NET_WM_STATE_FOCUSED
|
|
|
|
|
;;
|
|
|
|
|
xcb:Atom:_NET_WM_ALLOWED_ACTIONS
|
|
|
|
|
xcb:Atom:_NET_WM_ACTION_MOVE
|
|
|
|
|
xcb:Atom:_NET_WM_ACTION_RESIZE
|
|
|
|
|
xcb:Atom:_NET_WM_ACTION_MINIMIZE
|
|
|
|
|
;; xcb:Atom:_NET_WM_ACTION_SHADE
|
|
|
|
|
;; xcb:Atom:_NET_WM_ACTION_STICK
|
|
|
|
|
;; xcb:Atom:_NET_WM_ACTION_MAXIMIZE_HORZ
|
|
|
|
|
;; xcb:Atom:_NET_WM_ACTION_MAXIMIZE_VERT
|
|
|
|
|
xcb:Atom:_NET_WM_ACTION_FULLSCREEN
|
|
|
|
|
xcb:Atom:_NET_WM_ACTION_CHANGE_DESKTOP
|
|
|
|
|
xcb:Atom:_NET_WM_ACTION_CLOSE
|
|
|
|
|
;; xcb:Atom:_NET_WM_ACTION_ABOVE
|
|
|
|
|
;; xcb:Atom:_NET_WM_ACTION_BELOW
|
|
|
|
|
;;
|
|
|
|
|
xcb:Atom:_NET_WM_STRUT
|
|
|
|
|
xcb:Atom:_NET_WM_STRUT_PARTIAL
|
|
|
|
|
;; xcb:Atom:_NET_WM_ICON_GEOMETRY
|
|
|
|
|
;; xcb:Atom:_NET_WM_ICON
|
|
|
|
|
xcb:Atom:_NET_WM_PID
|
|
|
|
|
;; xcb:Atom:_NET_WM_HANDLED_ICONS
|
|
|
|
|
;; xcb:Atom:_NET_WM_USER_TIME
|
|
|
|
|
;; xcb:Atom:_NET_WM_USER_TIME_WINDOW
|
|
|
|
|
xcb:Atom:_NET_FRAME_EXTENTS
|
|
|
|
|
;; xcb:Atom:_NET_WM_OPAQUE_REGION
|
|
|
|
|
;; xcb:Atom:_NET_WM_BYPASS_COMPOSITOR
|
|
|
|
|
|
|
|
|
|
;; Window manager protocols.
|
|
|
|
|
xcb:Atom:_NET_WM_PING
|
|
|
|
|
;; xcb:Atom:_NET_WM_SYNC_REQUEST
|
|
|
|
|
;; xcb:Atom:_NET_WM_FULLSCREEN_MONITORS
|
|
|
|
|
|
|
|
|
|
;; Other properties.
|
|
|
|
|
xcb:Atom:_NET_WM_FULL_PLACEMENT)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Create a child window for setting _NET_SUPPORTING_WM_CHECK
|
|
|
|
|
(let ((new-id (xcb:generate-id exwm--connection)))
|
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
|
|
|
|
(setq exwm--guide-window new-id)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:CreateWindow
|
2016-08-12 13:18:32 +02:00
|
|
|
|
:depth 0
|
|
|
|
|
:wid new-id
|
|
|
|
|
:parent exwm--root
|
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
|
|
|
|
:x -1
|
|
|
|
|
:y -1
|
2016-08-12 13:18:32 +02:00
|
|
|
|
:width 1
|
|
|
|
|
:height 1
|
|
|
|
|
:border-width 0
|
|
|
|
|
:class xcb:WindowClass:InputOnly
|
|
|
|
|
:visual 0
|
|
|
|
|
:value-mask xcb:CW:OverrideRedirect
|
2015-07-17 13:16:08 +02:00
|
|
|
|
:override-redirect 1))
|
2020-04-15 02:00:00 +02:00
|
|
|
|
;; Set _NET_WM_NAME. Must be set to the name of the window manager, as
|
|
|
|
|
;; required by wm-spec.
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_WM_NAME
|
2020-04-15 02:00:00 +02:00
|
|
|
|
:window new-id :data "EXWM"))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(dolist (i (list exwm--root new-id))
|
|
|
|
|
;; Set _NET_SUPPORTING_WM_CHECK
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_SUPPORTING_WM_CHECK
|
2018-08-13 14:00:00 +02:00
|
|
|
|
:window i :data new-id))))
|
2016-08-12 14:30:07 +02:00
|
|
|
|
;; Set _NET_DESKTOP_VIEWPORT (we don't support large desktop).
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_DESKTOP_VIEWPORT
|
|
|
|
|
:window exwm--root
|
|
|
|
|
:data [0 0]))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:flush exwm--connection))
|
|
|
|
|
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(defun exwm--wmsn-acquire (replace)
|
|
|
|
|
"Acquire the WM_Sn selection.
|
|
|
|
|
|
|
|
|
|
REPLACE specifies what to do in case there already is a window
|
2018-03-08 18:06:39 +01:00
|
|
|
|
manager. If t, replace it, if nil, abort and ask the user if `ask'."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "%s" replace)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(with-slots (owner)
|
|
|
|
|
(xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:GetSelectionOwner
|
|
|
|
|
:selection xcb:Atom:WM_S0))
|
|
|
|
|
(when (/= owner xcb:Window:None)
|
|
|
|
|
(when (eq replace 'ask)
|
2018-03-08 18:06:39 +01:00
|
|
|
|
(setq replace (yes-or-no-p "Replace existing window manager? ")))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(when (not replace)
|
2019-03-10 01:00:00 +01:00
|
|
|
|
(user-error "Other window manager detected")))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(let ((new-owner (xcb:generate-id exwm--connection)))
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:CreateWindow
|
|
|
|
|
:depth 0
|
|
|
|
|
:wid new-owner
|
|
|
|
|
:parent exwm--root
|
|
|
|
|
:x -1
|
|
|
|
|
:y -1
|
|
|
|
|
:width 1
|
|
|
|
|
:height 1
|
|
|
|
|
:border-width 0
|
|
|
|
|
:class xcb:WindowClass:CopyFromParent
|
|
|
|
|
:visual 0
|
|
|
|
|
:value-mask 0
|
|
|
|
|
:override-redirect 0))
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_WM_NAME
|
2018-08-13 14:00:00 +02:00
|
|
|
|
:window new-owner :data "EXWM: exwm--wmsn-window"))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(xcb:+request-checked+request-check exwm--connection
|
|
|
|
|
(make-instance 'xcb:SetSelectionOwner
|
|
|
|
|
:selection xcb:Atom:WM_S0
|
|
|
|
|
:owner new-owner
|
|
|
|
|
:time xcb:Time:CurrentTime))
|
|
|
|
|
(with-slots (owner)
|
|
|
|
|
(xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:GetSelectionOwner
|
|
|
|
|
:selection xcb:Atom:WM_S0))
|
|
|
|
|
(unless (eq owner new-owner)
|
|
|
|
|
(error "Could not acquire ownership of WM selection")))
|
|
|
|
|
;; Wait for the other window manager to terminate.
|
|
|
|
|
(when (/= owner xcb:Window:None)
|
|
|
|
|
(let (reply)
|
2018-03-08 18:06:39 +01:00
|
|
|
|
(cl-dotimes (i exwm--wmsn-acquire-timeout)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(setq reply (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:GetGeometry :drawable owner)))
|
|
|
|
|
(when (not reply)
|
|
|
|
|
(cl-return))
|
|
|
|
|
(message "Waiting for other window manager to quit... %ds" i)
|
|
|
|
|
(sleep-for 1))
|
|
|
|
|
(when reply
|
|
|
|
|
(error "Other window manager did not release selection in time"))))
|
|
|
|
|
;; announce
|
|
|
|
|
(let* ((cmd (make-instance 'xcb:ClientMessageData
|
|
|
|
|
:data32 (vector xcb:Time:CurrentTime
|
|
|
|
|
xcb:Atom:WM_S0
|
|
|
|
|
new-owner
|
|
|
|
|
0
|
|
|
|
|
0)))
|
|
|
|
|
(cm (make-instance 'xcb:ClientMessage
|
|
|
|
|
:window exwm--root
|
|
|
|
|
:format 32
|
|
|
|
|
:type xcb:Atom:MANAGER
|
|
|
|
|
:data cmd))
|
|
|
|
|
(se (make-instance 'xcb:SendEvent
|
|
|
|
|
:propagate 0
|
|
|
|
|
:destination exwm--root
|
|
|
|
|
:event-mask xcb:EventMask:NoEvent
|
|
|
|
|
:event (xcb:marshal cm exwm--connection))))
|
|
|
|
|
(xcb:+request exwm--connection se))
|
|
|
|
|
(setq exwm--wmsn-window new-owner))))
|
|
|
|
|
|
2018-03-06 01:00:00 +01:00
|
|
|
|
;;;###autoload
|
2018-03-10 10:28:43 +01:00
|
|
|
|
(cl-defun exwm-init (&optional frame)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Initialize EXWM.
|
|
|
|
|
FRAME, if given, indicates the X display EXWM should manage."
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(interactive)
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "%s" frame)
|
2016-05-23 13:13:42 +02:00
|
|
|
|
(if frame
|
|
|
|
|
;; The frame might not be selected if it's created by emacslicnet.
|
|
|
|
|
(select-frame-set-input-focus frame)
|
|
|
|
|
(setq frame (selected-frame)))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(when (not (eq 'x (framep frame)))
|
2018-03-10 10:28:43 +01:00
|
|
|
|
(message "[EXWM] Not running under X environment")
|
|
|
|
|
(cl-return-from exwm-init))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(when exwm--connection
|
2018-03-10 10:28:43 +01:00
|
|
|
|
(exwm--log "EXWM already running")
|
|
|
|
|
(cl-return-from exwm-init))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(condition-case err
|
|
|
|
|
(progn
|
|
|
|
|
(exwm-enable 'undo) ;never initialize again
|
2021-12-09 01:00:00 +01:00
|
|
|
|
(setq exwm--terminal (frame-terminal frame))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(setq exwm--connection (xcb:connect))
|
|
|
|
|
(set-process-query-on-exit-flag (slot-value exwm--connection 'process)
|
|
|
|
|
nil) ;prevent query message on exit
|
|
|
|
|
(setq exwm--root
|
|
|
|
|
(slot-value (car (slot-value
|
|
|
|
|
(xcb:get-setup exwm--connection) 'roots))
|
|
|
|
|
'root))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
;; Initialize ICCCM/EWMH support
|
|
|
|
|
(xcb:icccm:init exwm--connection t)
|
|
|
|
|
(xcb:ewmh:init exwm--connection t)
|
|
|
|
|
;; Try to register window manager selection.
|
2019-03-10 01:00:00 +01:00
|
|
|
|
(exwm--wmsn-acquire exwm-replace)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(when (xcb:+request-checked+request-check exwm--connection
|
|
|
|
|
(make-instance 'xcb:ChangeWindowAttributes
|
2018-03-08 18:06:39 +01:00
|
|
|
|
:window exwm--root
|
|
|
|
|
:value-mask xcb:CW:EventMask
|
|
|
|
|
:event-mask
|
|
|
|
|
xcb:EventMask:SubstructureRedirect))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(error "Other window manager is running"))
|
2015-11-02 04:19:59 +01:00
|
|
|
|
;; Disable some features not working well with EXWM
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(setq use-dialog-box nil
|
|
|
|
|
confirm-kill-emacs #'exwm--confirm-kill-emacs)
|
2021-12-09 01:00:00 +01:00
|
|
|
|
(advice-add 'save-buffers-kill-terminal
|
|
|
|
|
:before-while #'exwm--confirm-kill-terminal)
|
|
|
|
|
;; Clean up if the terminal is deleted.
|
|
|
|
|
(add-hook 'delete-terminal-functions 'exwm--on-delete-terminal)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(exwm--lock)
|
|
|
|
|
(exwm--init-icccm-ewmh)
|
|
|
|
|
(exwm-layout--init)
|
|
|
|
|
(exwm-floating--init)
|
|
|
|
|
(exwm-manage--init)
|
2016-02-03 05:12:24 +01:00
|
|
|
|
(exwm-workspace--init)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(exwm-input--init)
|
|
|
|
|
(exwm--unlock)
|
2016-02-12 07:10:11 +01:00
|
|
|
|
(exwm-workspace--post-init)
|
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
|
|
|
|
(exwm-input--post-init)
|
2019-02-05 01:00:00 +01:00
|
|
|
|
(run-hooks 'exwm-init-hook)
|
2015-08-24 21:09:42 +02:00
|
|
|
|
;; Manage existing windows
|
2019-02-05 01:00:00 +01:00
|
|
|
|
(exwm-manage--scan))
|
2019-03-10 01:00:00 +01:00
|
|
|
|
(user-error)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
((quit error)
|
|
|
|
|
(exwm-exit)
|
|
|
|
|
;; Rethrow error
|
2018-03-10 10:28:43 +01:00
|
|
|
|
(warn "[EXWM] EXWM fails to start (%s: %s)" (car err) (cdr err)))))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2018-03-06 01:00:00 +01:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun exwm-exit ()
|
2016-05-23 13:13:42 +02:00
|
|
|
|
"Exit EXWM."
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(interactive)
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2016-05-23 13:13:42 +02:00
|
|
|
|
(run-hooks 'exwm-exit-hook)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(setq confirm-kill-emacs nil)
|
2016-05-23 13:13:42 +02:00
|
|
|
|
;; Exit modules.
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(when exwm--connection
|
2023-06-09 02:00:00 +02:00
|
|
|
|
(exwm-input--exit)
|
|
|
|
|
(exwm-manage--exit)
|
|
|
|
|
(exwm-workspace--exit)
|
|
|
|
|
(exwm-floating--exit)
|
|
|
|
|
(exwm-layout--exit)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(xcb:flush exwm--connection)
|
|
|
|
|
(xcb:disconnect exwm--connection))
|
2021-12-09 01:00:00 +01:00
|
|
|
|
(setq exwm--connection nil)
|
|
|
|
|
(setq exwm--terminal nil)
|
|
|
|
|
(exwm--log "Exited"))
|
2016-05-23 13:13:42 +02:00
|
|
|
|
|
2019-09-08 02:00:00 +02:00
|
|
|
|
;;;###autoload
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-enable (&optional undo)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
"Enable/Disable EXWM."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "%s" undo)
|
2015-09-27 13:31:00 +02:00
|
|
|
|
(pcase undo
|
|
|
|
|
(`undo ;prevent reinitialization
|
|
|
|
|
(remove-hook 'window-setup-hook #'exwm-init)
|
|
|
|
|
(remove-hook 'after-make-frame-functions #'exwm-init))
|
|
|
|
|
(`undo-all ;attempt to revert everything
|
|
|
|
|
(remove-hook 'window-setup-hook #'exwm-init)
|
|
|
|
|
(remove-hook 'after-make-frame-functions #'exwm-init)
|
|
|
|
|
(remove-hook 'kill-emacs-hook #'exwm--server-stop)
|
|
|
|
|
(dolist (i exwm-blocking-subrs)
|
|
|
|
|
(advice-remove i #'exwm--server-eval-at)))
|
|
|
|
|
(_ ;enable EXWM
|
2016-07-30 04:17:57 +02:00
|
|
|
|
(setq frame-resize-pixelwise t ;mandatory; before init
|
|
|
|
|
window-resize-pixelwise t)
|
2016-07-30 12:59:19 +02:00
|
|
|
|
;; Ignore unrecognized command line arguments. This can be helpful
|
|
|
|
|
;; when EXWM is launched by some session manager.
|
|
|
|
|
(push #'vector command-line-functions)
|
2019-09-14 02:00:00 +02:00
|
|
|
|
;; In case EXWM is to be started from a graphical Emacs instance.
|
|
|
|
|
(add-hook 'window-setup-hook #'exwm-init t)
|
|
|
|
|
;; In case EXWM is to be started with emacsclient.
|
|
|
|
|
(add-hook 'after-make-frame-functions #'exwm-init t)
|
|
|
|
|
;; Manage the subordinate Emacs server.
|
2015-09-27 13:31:00 +02:00
|
|
|
|
(add-hook 'kill-emacs-hook #'exwm--server-stop)
|
|
|
|
|
(dolist (i exwm-blocking-subrs)
|
|
|
|
|
(advice-add i :around #'exwm--server-eval-at)))))
|
|
|
|
|
|
|
|
|
|
(defun exwm--server-stop ()
|
|
|
|
|
"Stop the subordinate Emacs server."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2015-09-27 13:31:00 +02:00
|
|
|
|
(when exwm--server-process
|
2023-12-30 01:55:25 +01:00
|
|
|
|
(when (process-live-p exwm--server-process)
|
|
|
|
|
(cl-loop
|
|
|
|
|
initially (signal-process exwm--server-process 'TERM)
|
|
|
|
|
while (process-live-p exwm--server-process)
|
|
|
|
|
repeat (* 10 exwm--server-timeout)
|
|
|
|
|
do (sit-for 0.1)))
|
2015-09-27 13:31:00 +02:00
|
|
|
|
(delete-process exwm--server-process)
|
|
|
|
|
(setq exwm--server-process nil)))
|
|
|
|
|
|
2023-08-18 02:00:00 +02:00
|
|
|
|
(defun exwm--server-eval-at (function &rest args)
|
|
|
|
|
"Wrapper of `server-eval-at' used to advice subrs.
|
|
|
|
|
FUNCTION is the function to be evaluated, ARGS are the arguments."
|
2015-09-27 13:31:00 +02:00
|
|
|
|
;; Start the subordinate Emacs server if it's not alive
|
2023-08-18 02:00:00 +02:00
|
|
|
|
(exwm--log "%s %s" function args)
|
2015-09-27 13:31:00 +02:00
|
|
|
|
(unless (server-running-p exwm--server-name)
|
|
|
|
|
(when exwm--server-process (delete-process exwm--server-process))
|
|
|
|
|
(setq exwm--server-process
|
|
|
|
|
(start-process exwm--server-name
|
|
|
|
|
nil
|
|
|
|
|
(car command-line-args) ;The executable file
|
2016-03-25 06:57:42 +01:00
|
|
|
|
"-d" (frame-parameter nil 'display)
|
2015-09-27 13:31:00 +02:00
|
|
|
|
"-Q"
|
2023-12-30 01:55:25 +01:00
|
|
|
|
(concat "--fg-daemon=" exwm--server-name)
|
2015-09-27 13:31:00 +02:00
|
|
|
|
"--eval"
|
|
|
|
|
;; Create an invisible frame
|
|
|
|
|
"(make-frame '((window-system . x) (visibility)))"))
|
|
|
|
|
(while (not (server-running-p exwm--server-name))
|
|
|
|
|
(sit-for 0.001)))
|
|
|
|
|
(server-eval-at
|
|
|
|
|
exwm--server-name
|
|
|
|
|
`(progn (select-frame (car (frame-list)))
|
2023-08-18 02:00:00 +02:00
|
|
|
|
(let ((result ,(nconc (list (make-symbol (subr-name function)))
|
|
|
|
|
args)))
|
2015-09-27 13:31:00 +02:00
|
|
|
|
(pcase (type-of result)
|
|
|
|
|
;; Return the name of a buffer
|
|
|
|
|
(`buffer (buffer-name result))
|
|
|
|
|
;; We blindly convert all font objects to their XLFD names. This
|
|
|
|
|
;; might cause problems of course, but it still has a chance to
|
|
|
|
|
;; work (whereas directly passing font objects would merely
|
|
|
|
|
;; raise errors).
|
|
|
|
|
((or `font-entity `font-object `font-spec)
|
|
|
|
|
(font-xlfd-name result))
|
|
|
|
|
;; Passing following types makes little sense
|
|
|
|
|
((or `compiled-function `finalizer `frame `hash-table `marker
|
|
|
|
|
`overlay `process `window `window-configuration))
|
|
|
|
|
;; Passing the name of a subr
|
|
|
|
|
(`subr (make-symbol (subr-name result)))
|
|
|
|
|
;; For other types, return the value as-is.
|
|
|
|
|
(t result))))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2021-12-09 01:00:00 +01:00
|
|
|
|
(defun exwm--confirm-kill-terminal (&optional _)
|
|
|
|
|
"Confirm before killing terminal."
|
|
|
|
|
;; This is invoked instead of `save-buffers-kill-emacs' (C-x C-c) on client
|
|
|
|
|
;; frames.
|
2021-12-09 01:00:00 +01:00
|
|
|
|
(if (exwm--terminal-p)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
(exwm--confirm-kill-emacs "Kill terminal?")
|
2021-12-09 01:00:00 +01:00
|
|
|
|
t))
|
|
|
|
|
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(defun exwm--confirm-kill-emacs (prompt &optional force)
|
2023-08-18 02:00:00 +02:00
|
|
|
|
"Confirm before exiting Emacs.
|
|
|
|
|
PROMPT a reason to present to the user.
|
|
|
|
|
If FORCE is nil, ask the user for confirmation.
|
|
|
|
|
If FORCE is the symbol `no-check', ask if there are unsaved buffers.
|
|
|
|
|
If FORCE is any other non-nil value, force killing of Emacs."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(when (cond
|
|
|
|
|
((and force (not (eq force 'no-check)))
|
|
|
|
|
;; Force killing Emacs.
|
|
|
|
|
t)
|
|
|
|
|
((or (eq force 'no-check) (not exwm--id-buffer-alist))
|
|
|
|
|
;; Check if there's any unsaved file.
|
|
|
|
|
(pcase (catch 'break
|
|
|
|
|
(let ((kill-emacs-query-functions
|
|
|
|
|
(append kill-emacs-query-functions
|
|
|
|
|
(list (lambda ()
|
|
|
|
|
(throw 'break 'break))))))
|
|
|
|
|
(save-buffers-kill-emacs)))
|
|
|
|
|
(`break (y-or-n-p prompt))
|
|
|
|
|
(x x)))
|
|
|
|
|
(t
|
2021-12-09 01:00:00 +01:00
|
|
|
|
(yes-or-no-p (format "[EXWM] %d X window(s) will be destroyed. %s"
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(length exwm--id-buffer-alist) prompt))))
|
|
|
|
|
;; Run `kill-emacs-hook' (`server-force-stop' excluded) before Emacs
|
|
|
|
|
;; frames are unmapped so that errors (if any) can be visible.
|
|
|
|
|
(if (memq #'server-force-stop kill-emacs-hook)
|
|
|
|
|
(progn
|
|
|
|
|
(setq kill-emacs-hook (delq #'server-force-stop kill-emacs-hook))
|
|
|
|
|
(run-hooks 'kill-emacs-hook)
|
|
|
|
|
(setq kill-emacs-hook (list #'server-force-stop)))
|
|
|
|
|
(run-hooks 'kill-emacs-hook)
|
|
|
|
|
(setq kill-emacs-hook nil))
|
|
|
|
|
;; Exit each module, destroying all resources created by this connection.
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(exwm-exit)
|
2018-03-06 01:00:00 +01:00
|
|
|
|
;; Set the return value.
|
|
|
|
|
t))
|
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'exwm)
|
|
|
|
|
|
|
|
|
|
;;; exwm.el ends here
|