2015-07-17 13:16:08 +02:00
|
|
|
|
;;; exwm-input.el --- Input Module for EXWM -*- lexical-binding: t -*-
|
|
|
|
|
|
2019-02-01 01:00:00 +01:00
|
|
|
|
;; Copyright (C) 2015-2019 Free Software Foundation, Inc.
|
2015-07-17 13:16:08 +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-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:
|
|
|
|
|
|
|
|
|
|
;; This module deals with key/mouse matters, including:
|
|
|
|
|
;; + Input focus,
|
|
|
|
|
;; + Key/Button event handling,
|
|
|
|
|
;; + Key events filtering and simulation.
|
|
|
|
|
|
|
|
|
|
;; Todo:
|
|
|
|
|
;; + Pointer simulation mode (e.g. 'C-c 1'/'C-c 2' for single/double click,
|
|
|
|
|
;; move with arrow keys).
|
|
|
|
|
;; + Simulation keys to mimic Emacs key bindings for text edit (redo, select,
|
2017-02-05 10:50:52 +01:00
|
|
|
|
;; cancel, clear, etc). Some of them are not present on common keyboard
|
|
|
|
|
;; (keycode = 0). May need to use XKB extension.
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'xcb-keysyms)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(require 'exwm-core)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(defgroup exwm-input nil
|
|
|
|
|
"Input."
|
|
|
|
|
:version "25.3"
|
|
|
|
|
:group 'exwm)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(defcustom exwm-input-prefix-keys
|
2018-02-25 17:23:40 +01:00
|
|
|
|
'(?\C-x ?\C-u ?\C-h ?\M-x ?\M-` ?\M-& ?\M-:)
|
|
|
|
|
"List of prefix keys EXWM should forward to Emacs when in line-mode.
|
|
|
|
|
|
|
|
|
|
The point is to make keys like 'C-x C-f' forwarded to Emacs in line-mode.
|
|
|
|
|
There is no need to add prefix keys for global/simulation keys or those
|
|
|
|
|
defined in `exwm-mode-map' here."
|
2018-02-18 17:04:27 +01:00
|
|
|
|
:type '(repeat key-sequence)
|
|
|
|
|
:get (lambda (symbol)
|
|
|
|
|
(mapcar #'vector (default-value symbol)))
|
|
|
|
|
:set (lambda (symbol value)
|
|
|
|
|
(set symbol (mapcar (lambda (i)
|
|
|
|
|
(if (sequencep i)
|
|
|
|
|
(aref i 0)
|
|
|
|
|
i))
|
|
|
|
|
value))))
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-input-move-event 's-down-mouse-1
|
|
|
|
|
"Emacs event to start moving a window."
|
|
|
|
|
:type 'key-sequence
|
|
|
|
|
:get (lambda (symbol)
|
|
|
|
|
(let ((value (default-value symbol)))
|
|
|
|
|
(if (mouse-event-p value)
|
|
|
|
|
value
|
|
|
|
|
(vector value))))
|
|
|
|
|
:set (lambda (symbol value)
|
|
|
|
|
(set symbol (if (sequencep value)
|
|
|
|
|
(aref value 0)
|
|
|
|
|
value))))
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-input-resize-event 's-down-mouse-3
|
|
|
|
|
"Emacs event to start resizing a window."
|
|
|
|
|
:type 'key-sequence
|
|
|
|
|
:get (lambda (symbol)
|
|
|
|
|
(let ((value (default-value symbol)))
|
|
|
|
|
(if (mouse-event-p value)
|
|
|
|
|
value
|
|
|
|
|
(vector value))))
|
|
|
|
|
:set (lambda (symbol value)
|
|
|
|
|
(set symbol (if (sequencep value)
|
|
|
|
|
(aref value 0)
|
|
|
|
|
value))))
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-input-line-mode-passthrough nil
|
2018-10-08 14:00:00 +02:00
|
|
|
|
"Non-nil makes 'line-mode' forward all events to Emacs."
|
2018-02-18 17:04:27 +01:00
|
|
|
|
:type 'boolean)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
;; Input focus update requests should be accumulated for a short time
|
|
|
|
|
;; interval so that only the last one need to be processed. This not
|
|
|
|
|
;; improves the overall performance, but avoids the problem of input
|
|
|
|
|
;; focus loop, which is a result of the interaction with Emacs frames.
|
|
|
|
|
;;
|
|
|
|
|
;; FIXME: The time interval is hard to decide and perhaps machine-dependent.
|
|
|
|
|
;; A value too small can cause redundant updates of input focus,
|
|
|
|
|
;; and even worse, dead loops. OTOH a large value would bring
|
|
|
|
|
;; laggy experience.
|
|
|
|
|
(defconst exwm-input--update-focus-interval 0.01
|
|
|
|
|
"Time interval (in seconds) for accumulating input focus update requests.")
|
|
|
|
|
|
|
|
|
|
(defvar exwm-input--during-command nil
|
|
|
|
|
"Indicate whether between `pre-command-hook' and `post-command-hook'.")
|
2016-08-06 15:38:43 +02:00
|
|
|
|
|
2017-12-10 10:58:13 +01:00
|
|
|
|
(defvar exwm-input--global-keys nil "Global key bindings.")
|
2018-02-18 17:04:27 +01:00
|
|
|
|
|
2017-12-10 10:58:13 +01:00
|
|
|
|
(defvar exwm-input--global-prefix-keys nil
|
|
|
|
|
"List of prefix keys of global key bindings.")
|
2018-02-18 17:04:27 +01:00
|
|
|
|
|
|
|
|
|
(defvar exwm-input--line-mode-cache nil "Cache for incomplete key sequence.")
|
|
|
|
|
|
|
|
|
|
(defvar exwm-input--local-simulation-keys nil
|
|
|
|
|
"Whether simulation keys are local.")
|
|
|
|
|
|
2017-12-10 10:58:13 +01:00
|
|
|
|
(defvar exwm-input--simulation-keys nil "Simulation keys in line-mode.")
|
2018-02-18 17:04:27 +01:00
|
|
|
|
|
2018-12-16 01:00:00 +01:00
|
|
|
|
(defvar exwm-input--skip-buffer-list-update nil
|
|
|
|
|
"Skip the upcoming 'buffer-list-update'.")
|
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(defvar exwm-input--temp-line-mode nil
|
|
|
|
|
"Non-nil indicates it's in temporary line-mode for char-mode.")
|
|
|
|
|
|
|
|
|
|
(defvar exwm-input--timestamp-atom nil)
|
|
|
|
|
|
|
|
|
|
(defvar exwm-input--timestamp-callback nil)
|
|
|
|
|
|
|
|
|
|
(defvar exwm-input--timestamp-window nil)
|
|
|
|
|
|
|
|
|
|
(defvar exwm-input--update-focus-defer-timer nil "Timer for polling the lock.")
|
|
|
|
|
|
|
|
|
|
(defvar exwm-input--update-focus-lock nil
|
|
|
|
|
"Lock for solving input focus update contention.")
|
|
|
|
|
|
|
|
|
|
(defvar exwm-input--update-focus-timer nil
|
|
|
|
|
"Timer for deferring the update of input focus.")
|
|
|
|
|
|
|
|
|
|
(defvar exwm-input--update-focus-window nil "The (Emacs) window to be focused.
|
|
|
|
|
This value should always be overwritten.")
|
|
|
|
|
|
2019-08-18 02:00:00 +02:00
|
|
|
|
(defvar exwm-input--echo-area-timer nil "Timer for detecting echo area dirty.")
|
|
|
|
|
|
2018-11-03 13:00:00 +01:00
|
|
|
|
(defvar exwm-input--event-hook nil
|
|
|
|
|
"Hook to run when EXWM receives an event.")
|
|
|
|
|
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(defvar exwm-workspace--current)
|
|
|
|
|
(declare-function exwm-floating--do-moveresize "exwm-floating.el"
|
|
|
|
|
(data _synthetic))
|
|
|
|
|
(declare-function exwm-floating--start-moveresize "exwm-floating.el"
|
|
|
|
|
(id &optional type))
|
|
|
|
|
(declare-function exwm-floating--stop-moveresize "exwm-floating.el"
|
|
|
|
|
(&rest _args))
|
|
|
|
|
(declare-function exwm-layout--iconic-state-p "exwm-layout.el" (&optional id))
|
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
|
|
|
|
(declare-function exwm-layout--show "exwm-layout.el" (id &optional window))
|
2018-03-08 18:06:39 +01:00
|
|
|
|
(declare-function exwm-reset "exwm.el" ())
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(declare-function exwm-workspace--client-p "exwm-workspace.el"
|
|
|
|
|
(&optional frame))
|
|
|
|
|
(declare-function exwm-workspace--minibuffer-own-frame-p "exwm-workspace.el")
|
|
|
|
|
(declare-function exwm-workspace--workspace-p "exwm-workspace.el" (workspace))
|
|
|
|
|
(declare-function exwm-workspace-switch "exwm-workspace.el"
|
|
|
|
|
(frame-or-index &optional force))
|
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
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-input--set-focus (id)
|
|
|
|
|
"Set input focus to window ID in a proper way."
|
2015-08-16 20:53:04 +02:00
|
|
|
|
(when (exwm--id->buffer id)
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "id=#x%x" id)
|
2016-08-14 06:24:40 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(exwm-input--update-timestamp
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(lambda (timestamp id send-input-focus wm-take-focus)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(when send-input-focus
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:SetInputFocus
|
|
|
|
|
:revert-to xcb:InputFocus:Parent
|
|
|
|
|
:focus id
|
|
|
|
|
:time timestamp)))
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(when wm-take-focus
|
|
|
|
|
(let ((event (make-instance 'xcb:icccm:WM_TAKE_FOCUS
|
|
|
|
|
:window id
|
|
|
|
|
:time timestamp)))
|
|
|
|
|
(setq event (xcb:marshal event exwm--connection))
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:icccm:SendEvent
|
|
|
|
|
:destination id
|
|
|
|
|
:event event))))
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(exwm-input--set-active-window id)
|
|
|
|
|
(xcb:flush exwm--connection))
|
|
|
|
|
id
|
|
|
|
|
(or exwm--hints-input
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(not (memq xcb:Atom:WM_TAKE_FOCUS exwm--protocols)))
|
|
|
|
|
(memq xcb:Atom:WM_TAKE_FOCUS exwm--protocols)))))
|
2016-08-09 07:34:29 +02:00
|
|
|
|
|
|
|
|
|
(defun exwm-input--update-timestamp (callback &rest args)
|
|
|
|
|
"Fetch the latest timestamp from the server and feed it to CALLBACK.
|
|
|
|
|
|
|
|
|
|
ARGS are additional arguments to CALLBACK."
|
|
|
|
|
(setq exwm-input--timestamp-callback (cons callback args))
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log)
|
2016-08-09 07:34:29 +02:00
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ChangeProperty
|
|
|
|
|
:mode xcb:PropMode:Replace
|
|
|
|
|
:window exwm-input--timestamp-window
|
|
|
|
|
:property exwm-input--timestamp-atom
|
|
|
|
|
:type xcb:Atom:CARDINAL
|
|
|
|
|
:format 32
|
|
|
|
|
:data-len 0
|
|
|
|
|
:data nil))
|
|
|
|
|
(xcb:flush exwm--connection))
|
|
|
|
|
|
|
|
|
|
(defun exwm-input--on-PropertyNotify (data _synthetic)
|
|
|
|
|
"Handle PropertyNotify events."
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log)
|
2016-08-09 07:34:29 +02:00
|
|
|
|
(when exwm-input--timestamp-callback
|
|
|
|
|
(let ((obj (make-instance 'xcb:PropertyNotify)))
|
|
|
|
|
(xcb:unmarshal obj data)
|
|
|
|
|
(when (= exwm-input--timestamp-window
|
|
|
|
|
(slot-value obj 'window))
|
|
|
|
|
(apply (car exwm-input--timestamp-callback)
|
|
|
|
|
(slot-value obj 'time)
|
|
|
|
|
(cdr exwm-input--timestamp-callback))
|
|
|
|
|
(setq exwm-input--timestamp-callback nil)))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2019-06-16 02:00:00 +02:00
|
|
|
|
(defvar exwm-input--last-enter-notify-position nil)
|
|
|
|
|
|
2017-12-31 13:53:58 +01:00
|
|
|
|
(defun exwm-input--on-EnterNotify (data _synthetic)
|
|
|
|
|
"Handle EnterNotify events."
|
|
|
|
|
(let ((evt (make-instance 'xcb:EnterNotify))
|
|
|
|
|
buffer window frame frame-xid edges fake-evt)
|
|
|
|
|
(xcb:unmarshal evt data)
|
|
|
|
|
(with-slots (time root event root-x root-y event-x event-y state) evt
|
|
|
|
|
(setq buffer (exwm--id->buffer event)
|
|
|
|
|
window (get-buffer-window buffer t))
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "buffer=%s; window=%s" buffer window)
|
2019-06-16 02:00:00 +02:00
|
|
|
|
(when (and buffer window (not (eq window (selected-window)))
|
|
|
|
|
(not (equal exwm-input--last-enter-notify-position
|
|
|
|
|
(vector root-x root-y))))
|
2017-12-31 13:53:58 +01:00
|
|
|
|
(setq frame (window-frame window)
|
|
|
|
|
frame-xid (frame-parameter frame 'exwm-id))
|
|
|
|
|
(unless (eq frame exwm-workspace--current)
|
|
|
|
|
(if (exwm-workspace--workspace-p frame)
|
|
|
|
|
;; The X window is on another workspace.
|
|
|
|
|
(exwm-workspace-switch frame)
|
|
|
|
|
(with-current-buffer buffer
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(when (and (derived-mode-p 'exwm-mode)
|
2017-12-31 13:53:58 +01:00
|
|
|
|
(not (eq exwm--frame exwm-workspace--current)))
|
|
|
|
|
;; The floating X window is on another workspace.
|
|
|
|
|
(exwm-workspace-switch exwm--frame)))))
|
|
|
|
|
;; Send a fake MotionNotify event to Emacs.
|
|
|
|
|
(setq edges (window-inside-pixel-edges window)
|
|
|
|
|
fake-evt (make-instance 'xcb:MotionNotify
|
|
|
|
|
:detail 0
|
|
|
|
|
:time time
|
|
|
|
|
:root root
|
|
|
|
|
:event frame-xid
|
|
|
|
|
:child xcb:Window:None
|
|
|
|
|
:root-x root-x
|
|
|
|
|
:root-y root-y
|
|
|
|
|
:event-x (+ event-x (elt edges 0))
|
|
|
|
|
:event-y (+ event-y (elt edges 1))
|
|
|
|
|
:state state
|
|
|
|
|
:same-screen 1))
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:SendEvent
|
|
|
|
|
:propagate 0
|
|
|
|
|
:destination frame-xid
|
|
|
|
|
:event-mask xcb:EventMask:NoEvent
|
|
|
|
|
:event (xcb:marshal fake-evt exwm--connection)))
|
2019-06-16 02:00:00 +02:00
|
|
|
|
(xcb:flush exwm--connection))
|
|
|
|
|
(setq exwm-input--last-enter-notify-position (vector root-x root-y)))))
|
2017-12-31 13:53:58 +01:00
|
|
|
|
|
2017-11-26 13:26:57 +01:00
|
|
|
|
(defun exwm-input--on-keysyms-update ()
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2017-11-26 13:26:57 +01:00
|
|
|
|
(let ((exwm-input--global-prefix-keys nil))
|
|
|
|
|
(exwm-input--update-global-prefix-keys)))
|
|
|
|
|
|
2015-08-12 12:09:35 +02:00
|
|
|
|
(defun exwm-input--on-buffer-list-update ()
|
2016-07-21 06:51:37 +02:00
|
|
|
|
"Run in `buffer-list-update-hook' to track input focus."
|
2017-11-05 15:31:27 +01:00
|
|
|
|
(when (and (not (eq this-command #'handle-switch-frame))
|
2018-12-16 01:00:00 +01:00
|
|
|
|
(not exwm-input--skip-buffer-list-update)
|
2017-11-05 15:31:27 +01:00
|
|
|
|
(not (exwm-workspace--client-p))
|
2019-08-11 02:00:00 +02:00
|
|
|
|
(eq (current-buffer) (window-buffer)))
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "current-buffer=%S selected-window=%S"
|
|
|
|
|
(current-buffer) (selected-window))
|
2017-11-19 07:51:45 +01:00
|
|
|
|
(redirect-frame-focus (selected-frame) nil)
|
2016-07-21 06:51:37 +02:00
|
|
|
|
(setq exwm-input--update-focus-window (selected-window))
|
|
|
|
|
(exwm-input--update-focus-defer)))
|
|
|
|
|
|
|
|
|
|
(defun exwm-input--update-focus-defer ()
|
|
|
|
|
"Defer updating input focus."
|
|
|
|
|
(when exwm-input--update-focus-defer-timer
|
|
|
|
|
(cancel-timer exwm-input--update-focus-defer-timer))
|
|
|
|
|
(if exwm-input--update-focus-lock
|
|
|
|
|
(setq exwm-input--update-focus-defer-timer
|
2017-11-19 07:51:45 +01:00
|
|
|
|
(exwm--defer 0 #'exwm-input--update-focus-defer))
|
2016-07-21 06:51:37 +02:00
|
|
|
|
(setq exwm-input--update-focus-defer-timer nil)
|
|
|
|
|
(when exwm-input--update-focus-timer
|
|
|
|
|
(cancel-timer exwm-input--update-focus-timer))
|
|
|
|
|
(setq exwm-input--update-focus-timer
|
2017-11-24 15:47:42 +01:00
|
|
|
|
;; Attempt to accumulate successive events close enough.
|
|
|
|
|
(run-with-timer exwm-input--update-focus-interval
|
|
|
|
|
nil
|
|
|
|
|
#'exwm-input--update-focus-commit
|
|
|
|
|
exwm-input--update-focus-window))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2017-11-19 07:51:45 +01:00
|
|
|
|
(defun exwm-input--update-focus-commit (window)
|
|
|
|
|
"Commit updating input focus."
|
|
|
|
|
(setq exwm-input--update-focus-lock t)
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(exwm-input--update-focus window)
|
|
|
|
|
(setq exwm-input--update-focus-lock nil)))
|
|
|
|
|
|
2016-07-21 06:51:37 +02:00
|
|
|
|
(defun exwm-input--update-focus (window)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
"Update input focus."
|
2016-10-06 06:47:56 +02:00
|
|
|
|
(when (window-live-p window)
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "focus-window=%s focus-buffer=%s" window (window-buffer window))
|
2016-07-21 06:51:37 +02:00
|
|
|
|
(with-current-buffer (window-buffer window)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(if (derived-mode-p 'exwm-mode)
|
2015-09-20 04:51:58 +02:00
|
|
|
|
(if (not (eq exwm--frame exwm-workspace--current))
|
2016-10-06 13:26:53 +02:00
|
|
|
|
(progn
|
|
|
|
|
(set-frame-parameter exwm--frame 'exwm-selected-window window)
|
2017-11-19 07:51:45 +01:00
|
|
|
|
(exwm--defer 0 #'exwm-workspace-switch exwm--frame))
|
2015-08-13 09:33:02 +02:00
|
|
|
|
(exwm--log "Set focus on #x%x" exwm--id)
|
2016-02-06 05:59:33 +01:00
|
|
|
|
(when exwm--floating-frame
|
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
|
|
|
|
;; Adjust stacking orders of the floating X window.
|
2016-07-19 13:23:37 +02:00
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ConfigureWindow
|
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
|
|
|
|
:window exwm--id
|
2016-07-19 13:23:37 +02:00
|
|
|
|
:value-mask xcb:ConfigWindow:StackMode
|
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
|
|
|
|
:stack-mode xcb:StackMode:TopIf))
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ConfigureWindow
|
|
|
|
|
:window (frame-parameter exwm--floating-frame
|
|
|
|
|
'exwm-container)
|
|
|
|
|
:value-mask (logior
|
|
|
|
|
xcb:ConfigWindow:Sibling
|
|
|
|
|
xcb:ConfigWindow:StackMode)
|
|
|
|
|
:sibling exwm--id
|
|
|
|
|
:stack-mode xcb:StackMode:Below))
|
2016-07-13 12:51:32 +02:00
|
|
|
|
;; This floating X window might be hide by `exwm-floating-hide'.
|
|
|
|
|
(when (exwm-layout--iconic-state-p)
|
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-layout--show exwm--id window))
|
|
|
|
|
(xcb:flush exwm--connection))
|
|
|
|
|
(exwm-input--set-focus exwm--id))
|
2016-07-21 06:51:37 +02:00
|
|
|
|
(when (eq (selected-window) window)
|
|
|
|
|
(exwm--log "Focus on %s" window)
|
2016-07-30 04:00:11 +02:00
|
|
|
|
(if (and (exwm-workspace--workspace-p (selected-frame))
|
|
|
|
|
(not (eq (selected-frame) exwm-workspace--current)))
|
|
|
|
|
;; The focus is on another workspace (e.g. it got clicked)
|
|
|
|
|
;; so switch to it.
|
2016-10-06 13:26:53 +02:00
|
|
|
|
(progn
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "Switching to %s's workspace %s (%s)"
|
|
|
|
|
window
|
|
|
|
|
(window-frame window)
|
|
|
|
|
(selected-frame))
|
2016-10-06 13:26:53 +02:00
|
|
|
|
(set-frame-parameter (selected-frame) 'exwm-selected-window
|
|
|
|
|
window)
|
2017-11-19 07:51:45 +01:00
|
|
|
|
(exwm--defer 0 #'exwm-workspace-switch (selected-frame)))
|
2016-07-30 04:00:11 +02:00
|
|
|
|
;; The focus is still on the current workspace.
|
2016-10-06 06:47:56 +02:00
|
|
|
|
(if (not (and (exwm-workspace--minibuffer-own-frame-p)
|
|
|
|
|
(minibufferp)))
|
2017-11-19 07:51:45 +01:00
|
|
|
|
(x-focus-frame (window-frame window))
|
2016-10-06 06:47:56 +02:00
|
|
|
|
;; X input focus should be set on the previously selected
|
|
|
|
|
;; frame.
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(x-focus-frame (window-frame (minibuffer-window))))
|
2016-07-30 04:00:11 +02:00
|
|
|
|
(exwm-input--set-active-window)
|
2017-11-19 07:51:45 +01:00
|
|
|
|
(xcb:flush exwm--connection)))))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2016-07-13 12:51:32 +02:00
|
|
|
|
(defun exwm-input--set-active-window (&optional id)
|
|
|
|
|
"Set _NET_ACTIVE_WINDOW."
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log)
|
2016-07-13 12:51:32 +02:00
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_ACTIVE_WINDOW
|
|
|
|
|
:window exwm--root
|
|
|
|
|
:data (or id xcb:Window:None))))
|
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(defun exwm-input--on-ButtonPress (data _synthetic)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
"Handle ButtonPress event."
|
|
|
|
|
(let ((obj (make-instance 'xcb:ButtonPress))
|
2016-07-22 06:31:22 +02:00
|
|
|
|
(mode xcb:Allow:SyncPointer)
|
2017-09-10 12:00:01 +02:00
|
|
|
|
button-event window buffer frame)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:unmarshal obj data)
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "major-mode=%s buffer=%s"
|
2018-08-19 02:00:00 +02:00
|
|
|
|
major-mode (buffer-name (current-buffer)))
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(with-slots (detail event state) obj
|
2017-09-10 12:00:01 +02:00
|
|
|
|
(setq button-event (xcb:keysyms:keysym->event exwm--connection
|
|
|
|
|
detail state)
|
2018-10-08 14:00:00 +02:00
|
|
|
|
buffer (exwm--id->buffer event)
|
|
|
|
|
window (get-buffer-window buffer t))
|
2017-09-10 12:00:01 +02:00
|
|
|
|
(cond ((and (eq button-event exwm-input-move-event)
|
2019-01-20 01:00:00 +01:00
|
|
|
|
buffer
|
2016-07-22 06:31:22 +02:00
|
|
|
|
;; Either an undecorated or a floating X window.
|
|
|
|
|
(with-current-buffer buffer
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(or (not (derived-mode-p 'exwm-mode))
|
2016-07-22 06:31:22 +02:00
|
|
|
|
exwm--floating-frame)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Move
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(exwm-floating--start-moveresize
|
|
|
|
|
event xcb:ewmh:_NET_WM_MOVERESIZE_MOVE))
|
2017-09-10 12:00:01 +02:00
|
|
|
|
((and (eq button-event exwm-input-resize-event)
|
2019-01-20 01:00:00 +01:00
|
|
|
|
buffer
|
2016-07-22 06:31:22 +02:00
|
|
|
|
(with-current-buffer buffer
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(or (not (derived-mode-p 'exwm-mode))
|
2016-07-22 06:31:22 +02:00
|
|
|
|
exwm--floating-frame)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Resize
|
|
|
|
|
(exwm-floating--start-moveresize event))
|
2019-01-20 01:00:00 +01:00
|
|
|
|
(buffer
|
2015-08-13 01:54:19 +02:00
|
|
|
|
;; Click to focus
|
2016-07-22 06:31:22 +02:00
|
|
|
|
(unless (eq window (selected-window))
|
|
|
|
|
(setq frame (window-frame window))
|
|
|
|
|
(unless (eq frame exwm-workspace--current)
|
|
|
|
|
(if (exwm-workspace--workspace-p frame)
|
|
|
|
|
;; The X window is on another workspace
|
|
|
|
|
(exwm-workspace-switch frame)
|
|
|
|
|
(with-current-buffer buffer
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(when (and (derived-mode-p 'exwm-mode)
|
2016-07-22 06:31:22 +02:00
|
|
|
|
(not (eq exwm--frame
|
|
|
|
|
exwm-workspace--current)))
|
|
|
|
|
;; The floating X window is on another workspace
|
|
|
|
|
(exwm-workspace-switch exwm--frame)))))
|
|
|
|
|
;; It has been reported that the `window' may have be deleted
|
|
|
|
|
(if (window-live-p window)
|
|
|
|
|
(select-window window)
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(setq window (get-buffer-window buffer t))
|
2016-07-22 06:31:22 +02:00
|
|
|
|
(when window (select-window window))))
|
2019-01-20 01:00:00 +01:00
|
|
|
|
;; Also process keybindings.
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(when (derived-mode-p 'exwm-mode)
|
2018-10-21 14:00:00 +02:00
|
|
|
|
(cl-case exwm--input-mode
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(line-mode
|
2019-01-20 01:00:00 +01:00
|
|
|
|
(setq mode (exwm-input--on-ButtonPress-line-mode
|
|
|
|
|
buffer button-event)))
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(char-mode
|
2019-01-20 01:00:00 +01:00
|
|
|
|
(setq mode (exwm-input--on-ButtonPress-char-mode)))))))
|
|
|
|
|
(t
|
|
|
|
|
;; Replay this event by default.
|
|
|
|
|
(setq mode xcb:Allow:ReplayPointer))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:AllowEvents :mode mode :time xcb:Time:CurrentTime))
|
2018-11-03 13:00:00 +01:00
|
|
|
|
(xcb:flush exwm--connection))
|
|
|
|
|
(run-hooks 'exwm-input--event-hook))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(defun exwm-input--on-KeyPress (data _synthetic)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
"Handle KeyPress event."
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(let ((obj (make-instance 'xcb:KeyPress)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:unmarshal obj data)
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "major-mode=%s buffer=%s"
|
2018-10-08 14:00:00 +02:00
|
|
|
|
major-mode (buffer-name (current-buffer)))
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(if (derived-mode-p 'exwm-mode)
|
2018-10-21 14:00:00 +02:00
|
|
|
|
(cl-case exwm--input-mode
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(line-mode
|
|
|
|
|
(exwm-input--on-KeyPress-line-mode obj data))
|
|
|
|
|
(char-mode
|
|
|
|
|
(exwm-input--on-KeyPress-char-mode obj data)))
|
2018-11-03 13:00:00 +01:00
|
|
|
|
(exwm-input--on-KeyPress-char-mode obj)))
|
|
|
|
|
(run-hooks 'exwm-input--event-hook))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2018-02-21 17:26:04 +01:00
|
|
|
|
(defun exwm-input--on-CreateNotify (data _synthetic)
|
|
|
|
|
"Handle CreateNotify events."
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log)
|
2018-02-21 17:26:04 +01:00
|
|
|
|
(let ((evt (make-instance 'xcb:CreateNotify)))
|
|
|
|
|
(xcb:unmarshal evt data)
|
|
|
|
|
(with-slots (window) evt
|
|
|
|
|
(exwm-input--grab-global-prefix-keys window))))
|
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-input--update-global-prefix-keys ()
|
|
|
|
|
"Update `exwm-input--global-prefix-keys'."
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(when exwm--connection
|
2018-02-21 17:26:04 +01:00
|
|
|
|
(let ((original exwm-input--global-prefix-keys))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(setq exwm-input--global-prefix-keys nil)
|
|
|
|
|
(dolist (i exwm-input--global-keys)
|
|
|
|
|
(cl-pushnew (elt i 0) exwm-input--global-prefix-keys))
|
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
|
|
|
|
(unless (equal original exwm-input--global-prefix-keys)
|
2018-02-21 17:26:04 +01:00
|
|
|
|
(apply #'exwm-input--grab-global-prefix-keys
|
|
|
|
|
(slot-value (xcb:+request-unchecked+reply exwm--connection
|
|
|
|
|
(make-instance 'xcb:QueryTree
|
|
|
|
|
:window exwm--root))
|
|
|
|
|
'children))))))
|
|
|
|
|
|
|
|
|
|
(defun exwm-input--grab-global-prefix-keys (&rest xwins)
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(let ((req (make-instance 'xcb:GrabKey
|
|
|
|
|
:owner-events 0
|
2018-02-21 17:26:04 +01:00
|
|
|
|
:grab-window nil
|
2018-07-14 18:00:00 +02:00
|
|
|
|
:modifiers nil
|
|
|
|
|
:key nil
|
|
|
|
|
:pointer-mode xcb:GrabMode:Async
|
|
|
|
|
:keyboard-mode xcb:GrabMode:Async))
|
2019-08-05 02:00:00 +02:00
|
|
|
|
keysyms keycode alt-modifier)
|
2018-02-21 17:26:04 +01:00
|
|
|
|
(dolist (k exwm-input--global-prefix-keys)
|
2019-09-22 02:00:00 +02:00
|
|
|
|
(setq keysyms (xcb:keysyms:event->keysyms exwm--connection k))
|
|
|
|
|
(if (not keysyms)
|
|
|
|
|
(warn "Key unavailable: %s" (key-description (vector k)))
|
|
|
|
|
(setq keycode (xcb:keysyms:keysym->keycode exwm--connection
|
|
|
|
|
(caar keysyms)))
|
|
|
|
|
(exwm--log "Grabbing key=%s (keysyms=%s keycode=%s)"
|
|
|
|
|
(single-key-description k) keysyms keycode)
|
|
|
|
|
(dolist (keysym keysyms)
|
|
|
|
|
(setf (slot-value req 'modifiers) (cdr keysym)
|
|
|
|
|
(slot-value req 'key) keycode)
|
|
|
|
|
;; Also grab this key with num-lock mask set.
|
|
|
|
|
(when (and (/= 0 xcb:keysyms:num-lock-mask)
|
|
|
|
|
(= 0 (logand (cdr keysym) xcb:keysyms:num-lock-mask)))
|
|
|
|
|
(setf alt-modifier (logior (cdr keysym)
|
|
|
|
|
xcb:keysyms:num-lock-mask)))
|
|
|
|
|
(dolist (xwin xwins)
|
|
|
|
|
(setf (slot-value req 'grab-window) xwin)
|
|
|
|
|
(xcb:+request exwm--connection req)
|
|
|
|
|
(when alt-modifier
|
|
|
|
|
(setf (slot-value req 'modifiers) alt-modifier)
|
|
|
|
|
(xcb:+request exwm--connection req))))))
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(xcb:flush exwm--connection)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2018-02-25 17:15:44 +01:00
|
|
|
|
(defun exwm-input--set-key (key command)
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "key: %s, command: %s" key command)
|
2018-02-25 17:15:44 +01:00
|
|
|
|
(global-set-key key command)
|
|
|
|
|
(cl-pushnew key exwm-input--global-keys))
|
|
|
|
|
|
|
|
|
|
(defcustom exwm-input-global-keys nil
|
|
|
|
|
"Global keys.
|
|
|
|
|
|
|
|
|
|
It is an alist of the form (key . command), meaning giving KEY (a key
|
|
|
|
|
sequence) a global binding as COMMAND.
|
|
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
* Setting the value directly (rather than customizing it) after EXWM
|
|
|
|
|
finishes initialization has no effect."
|
|
|
|
|
:type '(alist :key-type key-sequence :value-type function)
|
|
|
|
|
:set (lambda (symbol value)
|
|
|
|
|
(when (boundp symbol)
|
|
|
|
|
(dolist (i (symbol-value symbol))
|
|
|
|
|
(global-unset-key (car i))))
|
|
|
|
|
(set symbol value)
|
|
|
|
|
(setq exwm-input--global-keys nil)
|
|
|
|
|
(dolist (i value)
|
|
|
|
|
(exwm-input--set-key (car i) (cdr i)))
|
|
|
|
|
(when exwm--connection
|
|
|
|
|
(exwm-input--update-global-prefix-keys))))
|
|
|
|
|
|
2017-12-31 14:01:23 +01:00
|
|
|
|
;;;###autoload
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-input-set-key (key command)
|
2018-02-18 17:04:27 +01:00
|
|
|
|
"Set a global key binding.
|
|
|
|
|
|
|
|
|
|
The new key binding only takes effect in real time when this command is
|
2018-02-25 17:15:44 +01:00
|
|
|
|
called interactively, and is lost when this session ends unless it's
|
|
|
|
|
specifically saved in the Customize interface for `exwm-input-global-keys'.
|
|
|
|
|
|
|
|
|
|
In configuration you should customize or set `exwm-input-global-keys'
|
|
|
|
|
instead."
|
2016-02-19 10:12:43 +01:00
|
|
|
|
(interactive "KSet key globally: \nCSet key %s to command: ")
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log)
|
2018-02-25 17:15:44 +01:00
|
|
|
|
(setq exwm-input-global-keys (append exwm-input-global-keys
|
|
|
|
|
(list (cons key command))))
|
|
|
|
|
(exwm-input--set-key key command)
|
2016-07-17 06:46:19 +02:00
|
|
|
|
(when (called-interactively-p 'any)
|
|
|
|
|
(exwm-input--update-global-prefix-keys)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2017-11-08 18:17:58 +01:00
|
|
|
|
;; Putting (t . EVENT) into `unread-command-events' does not really work
|
2019-02-06 01:00:00 +01:00
|
|
|
|
;; as documented for Emacs < 26.2.
|
2016-07-15 02:11:33 +02:00
|
|
|
|
(eval-and-compile
|
2019-02-11 01:00:00 +01:00
|
|
|
|
(if (or (< emacs-major-version 26)
|
|
|
|
|
(and (= emacs-major-version 26)
|
|
|
|
|
(< emacs-minor-version 2)))
|
2016-07-15 02:11:33 +02:00
|
|
|
|
(defsubst exwm-input--unread-event (event)
|
|
|
|
|
(setq unread-command-events
|
|
|
|
|
(append unread-command-events (list event))))
|
|
|
|
|
(defsubst exwm-input--unread-event (event)
|
|
|
|
|
(setq unread-command-events
|
|
|
|
|
(append unread-command-events `((t . ,event)))))))
|
|
|
|
|
|
2018-04-01 17:30:19 +02:00
|
|
|
|
(defun exwm-input--mimic-read-event (event)
|
|
|
|
|
"Process EVENT as if it were returned by `read-event'."
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log)
|
2018-04-01 17:30:19 +02:00
|
|
|
|
(unless (eq 0 extra-keyboard-modifiers)
|
|
|
|
|
(setq event (event-convert-list (append (event-modifiers
|
|
|
|
|
extra-keyboard-modifiers)
|
|
|
|
|
event))))
|
|
|
|
|
(when (characterp event)
|
|
|
|
|
(let ((event* (when keyboard-translate-table
|
|
|
|
|
(aref keyboard-translate-table event))))
|
|
|
|
|
(when event*
|
|
|
|
|
(setq event event*))))
|
|
|
|
|
event)
|
|
|
|
|
|
2018-01-14 16:48:29 +01:00
|
|
|
|
(cl-defun exwm-input--translate (key)
|
|
|
|
|
(let (translation)
|
|
|
|
|
(dolist (map (list input-decode-map
|
|
|
|
|
local-function-key-map
|
|
|
|
|
key-translation-map))
|
|
|
|
|
(setq translation (lookup-key map key))
|
|
|
|
|
(if (functionp translation)
|
|
|
|
|
(cl-return-from exwm-input--translate (funcall translation nil))
|
|
|
|
|
(when (vectorp translation)
|
|
|
|
|
(cl-return-from exwm-input--translate translation)))))
|
|
|
|
|
key)
|
|
|
|
|
|
2018-11-25 01:00:00 +01:00
|
|
|
|
(defun exwm-input--cache-event (event &optional temp-line-mode)
|
2016-10-06 06:47:56 +02:00
|
|
|
|
"Cache EVENT."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "%s" event)
|
2016-10-06 06:47:56 +02:00
|
|
|
|
(setq exwm-input--line-mode-cache
|
|
|
|
|
(vconcat exwm-input--line-mode-cache (vector event)))
|
2018-01-14 16:48:29 +01:00
|
|
|
|
;; Attempt to translate this key sequence.
|
|
|
|
|
(setq exwm-input--line-mode-cache
|
|
|
|
|
(exwm-input--translate exwm-input--line-mode-cache))
|
2018-10-08 14:00:00 +02:00
|
|
|
|
;; When the key sequence is complete (not a keymap).
|
|
|
|
|
;; Note that `exwm-input--line-mode-cache' might get translated to nil, for
|
|
|
|
|
;; example 'mouse--down-1-maybe-follows-link' does this.
|
2018-11-25 01:00:00 +01:00
|
|
|
|
(if (and exwm-input--line-mode-cache
|
|
|
|
|
(keymapp (key-binding exwm-input--line-mode-cache)))
|
|
|
|
|
;; Grab keyboard temporarily to intercept the complete key sequence.
|
|
|
|
|
(when temp-line-mode
|
|
|
|
|
(setq exwm-input--temp-line-mode t)
|
|
|
|
|
(exwm-input--grab-keyboard))
|
2016-10-06 06:47:56 +02:00
|
|
|
|
(setq exwm-input--line-mode-cache nil)
|
|
|
|
|
(when exwm-input--temp-line-mode
|
|
|
|
|
(setq exwm-input--temp-line-mode nil)
|
2018-04-01 17:30:19 +02:00
|
|
|
|
(exwm-input--release-keyboard))))
|
2016-10-06 06:47:56 +02:00
|
|
|
|
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(defun exwm-input--event-passthrough-p (event)
|
|
|
|
|
"Whether EVENT should be passed to Emacs.
|
|
|
|
|
Current buffer must be an `exwm-mode' buffer."
|
|
|
|
|
(or exwm-input-line-mode-passthrough
|
|
|
|
|
exwm-input--during-command
|
|
|
|
|
;; Forward the event when there is an incomplete key
|
|
|
|
|
;; sequence or when the minibuffer is active.
|
|
|
|
|
exwm-input--line-mode-cache
|
|
|
|
|
(eq (active-minibuffer-window) (selected-window))
|
|
|
|
|
;;
|
|
|
|
|
(memq event exwm-input--global-prefix-keys)
|
|
|
|
|
(memq event exwm-input-prefix-keys)
|
|
|
|
|
(when overriding-terminal-local-map
|
|
|
|
|
(lookup-key overriding-terminal-local-map
|
|
|
|
|
(vector event)))
|
|
|
|
|
(lookup-key (current-local-map) (vector event))
|
|
|
|
|
(gethash event exwm-input--simulation-keys)))
|
|
|
|
|
|
2016-07-29 11:05:09 +02:00
|
|
|
|
(defun exwm-input--on-KeyPress-line-mode (key-press raw-data)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
"Parse X KeyPress event to Emacs key event and then feed the command loop."
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(with-slots (detail state) key-press
|
|
|
|
|
(let ((keysym (xcb:keysyms:keycode->keysym exwm--connection detail state))
|
|
|
|
|
event raw-event mode)
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "%s" keysym)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(when (and (/= 0 (car keysym))
|
|
|
|
|
(setq raw-event (xcb:keysyms:keysym->event
|
|
|
|
|
exwm--connection (car keysym)
|
|
|
|
|
(logand state (lognot (cdr keysym)))))
|
|
|
|
|
(setq event (exwm-input--mimic-read-event raw-event))
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(exwm-input--event-passthrough-p event))
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(setq mode xcb:Allow:AsyncKeyboard)
|
|
|
|
|
(exwm-input--cache-event event)
|
|
|
|
|
(exwm-input--unread-event raw-event))
|
|
|
|
|
(unless mode
|
|
|
|
|
(if (= 0 (logand #x6000 state)) ;Check the 13~14 bits.
|
|
|
|
|
;; Not an XKB state; just replay it.
|
|
|
|
|
(setq mode xcb:Allow:ReplayKeyboard)
|
|
|
|
|
;; An XKB state; sent it with SendEvent.
|
|
|
|
|
;; FIXME: Can this also be replayed?
|
|
|
|
|
;; FIXME: KeyRelease events are lost.
|
|
|
|
|
(setq mode xcb:Allow:AsyncKeyboard)
|
2016-07-29 11:05:09 +02:00
|
|
|
|
(xcb:+request exwm--connection
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(make-instance 'xcb:SendEvent
|
|
|
|
|
:propagate 0
|
|
|
|
|
:destination (slot-value key-press 'event)
|
|
|
|
|
:event-mask xcb:EventMask:NoEvent
|
|
|
|
|
:event raw-data)))
|
2016-09-22 13:10:38 +02:00
|
|
|
|
;; Make Emacs aware of this event when defining keyboard macros.
|
|
|
|
|
(when (and defining-kbd-macro event)
|
|
|
|
|
(set-transient-map '(keymap (t . (lambda () (interactive)))))
|
|
|
|
|
(exwm-input--unread-event event)))
|
2015-08-26 09:27:31 +02:00
|
|
|
|
(xcb:+request exwm--connection
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(make-instance 'xcb:AllowEvents
|
|
|
|
|
:mode mode
|
|
|
|
|
:time xcb:Time:CurrentTime))
|
2015-08-26 09:27:31 +02:00
|
|
|
|
(xcb:flush exwm--connection))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2016-07-29 11:05:09 +02:00
|
|
|
|
(defun exwm-input--on-KeyPress-char-mode (key-press &optional _raw-data)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
"Handle KeyPress event in char-mode."
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(with-slots (detail state) key-press
|
|
|
|
|
(let ((keysym (xcb:keysyms:keycode->keysym exwm--connection detail state))
|
|
|
|
|
event raw-event)
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "%s" keysym)
|
2016-07-29 11:05:09 +02:00
|
|
|
|
(when (and (/= 0 (car keysym))
|
2018-04-01 17:30:19 +02:00
|
|
|
|
(setq raw-event (xcb:keysyms:keysym->event
|
|
|
|
|
exwm--connection (car keysym)
|
|
|
|
|
(logand state (lognot (cdr keysym)))))
|
|
|
|
|
(setq event (exwm-input--mimic-read-event raw-event)))
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(if (not (derived-mode-p 'exwm-mode))
|
2018-04-01 17:30:19 +02:00
|
|
|
|
(exwm-input--unread-event raw-event)
|
2018-11-25 01:00:00 +01:00
|
|
|
|
(exwm-input--cache-event event t)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(exwm-input--unread-event raw-event)))))
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:AllowEvents
|
|
|
|
|
:mode xcb:Allow:AsyncKeyboard
|
|
|
|
|
:time xcb:Time:CurrentTime))
|
|
|
|
|
(xcb:flush exwm--connection))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(defun exwm-input--on-ButtonPress-line-mode (buffer button-event)
|
|
|
|
|
"Handle button events in line mode.
|
|
|
|
|
BUFFER is the `exwm-mode' buffer the event was generated
|
|
|
|
|
on. BUTTON-EVENT is the X event converted into an Emacs event.
|
|
|
|
|
|
|
|
|
|
The return value is used as event_mode to release the original
|
|
|
|
|
button event."
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(let ((read-event (exwm-input--mimic-read-event button-event)))
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "%s" read-event)
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(if (and read-event
|
|
|
|
|
(exwm-input--event-passthrough-p read-event))
|
|
|
|
|
;; The event should be forwarded to emacs
|
|
|
|
|
(progn
|
|
|
|
|
(exwm-input--cache-event read-event)
|
|
|
|
|
(exwm-input--unread-event button-event)
|
|
|
|
|
xcb:Allow:SyncPointer)
|
|
|
|
|
;; The event should be replayed
|
|
|
|
|
xcb:Allow:ReplayPointer))))
|
|
|
|
|
|
|
|
|
|
(defun exwm-input--on-ButtonPress-char-mode ()
|
|
|
|
|
"Handle button events in char-mode.
|
|
|
|
|
The return value is used as event_mode to release the original
|
|
|
|
|
button event."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2018-10-08 14:00:00 +02:00
|
|
|
|
xcb:Allow:ReplayPointer)
|
|
|
|
|
|
2016-03-07 01:00:00 +01:00
|
|
|
|
(defun exwm-input--update-mode-line (id)
|
|
|
|
|
"Update the propertized `mode-line-process' for window ID."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "#x%x" id)
|
2016-03-07 01:00:00 +01:00
|
|
|
|
(let (help-echo cmd mode)
|
2018-10-21 14:00:00 +02:00
|
|
|
|
(cl-case exwm--input-mode
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(line-mode
|
2016-03-07 01:00:00 +01:00
|
|
|
|
(setq mode "line"
|
|
|
|
|
help-echo "mouse-1: Switch to char-mode"
|
2019-03-24 01:00:00 +01:00
|
|
|
|
cmd (lambda ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(exwm-input-release-keyboard id))))
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(char-mode
|
2016-03-07 01:00:00 +01:00
|
|
|
|
(setq mode "char"
|
|
|
|
|
help-echo "mouse-1: Switch to line-mode"
|
2019-03-24 01:00:00 +01:00
|
|
|
|
cmd (lambda ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(exwm-input-grab-keyboard id)))))
|
2016-03-07 01:00:00 +01:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
|
|
|
|
(setq mode-line-process
|
|
|
|
|
`(": "
|
|
|
|
|
(:propertize ,mode
|
|
|
|
|
help-echo ,help-echo
|
|
|
|
|
mouse-face mode-line-highlight
|
|
|
|
|
local-map
|
|
|
|
|
(keymap
|
|
|
|
|
(mode-line
|
|
|
|
|
keymap
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(down-mouse-1 . ,cmd))))))
|
|
|
|
|
(force-mode-line-update))))
|
2016-03-07 01:00:00 +01:00
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-input--grab-keyboard (&optional id)
|
|
|
|
|
"Grab all key events on window ID."
|
|
|
|
|
(unless id (setq id (exwm--buffer->id (window-buffer))))
|
2015-08-16 20:53:04 +02:00
|
|
|
|
(when id
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "id=#x%x" id)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(when (xcb:+request-checked+request-check exwm--connection
|
|
|
|
|
(make-instance 'xcb:GrabKey
|
|
|
|
|
:owner-events 0
|
|
|
|
|
:grab-window id
|
|
|
|
|
:modifiers xcb:ModMask:Any
|
|
|
|
|
:key xcb:Grab:Any
|
|
|
|
|
:pointer-mode xcb:GrabMode:Async
|
|
|
|
|
:keyboard-mode xcb:GrabMode:Sync))
|
|
|
|
|
(exwm--log "Failed to grab keyboard for #x%x" id))
|
2019-08-18 02:00:00 +02:00
|
|
|
|
(let ((buffer (exwm--id->buffer id)))
|
|
|
|
|
(when buffer
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(setq exwm--input-mode 'line-mode))))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
|
|
|
|
(defun exwm-input--release-keyboard (&optional id)
|
|
|
|
|
"Ungrab all key events on window ID."
|
|
|
|
|
(unless id (setq id (exwm--buffer->id (window-buffer))))
|
2015-08-16 20:53:04 +02:00
|
|
|
|
(when id
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "id=#x%x" id)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(when (xcb:+request-checked+request-check exwm--connection
|
|
|
|
|
(make-instance 'xcb:UngrabKey
|
|
|
|
|
:key xcb:Grab:Any
|
|
|
|
|
:grab-window id
|
|
|
|
|
:modifiers xcb:ModMask:Any))
|
|
|
|
|
(exwm--log "Failed to release keyboard for #x%x" id))
|
2018-02-21 17:26:04 +01:00
|
|
|
|
(exwm-input--grab-global-prefix-keys id)
|
2019-08-18 02:00:00 +02:00
|
|
|
|
(let ((buffer (exwm--id->buffer id)))
|
|
|
|
|
(when buffer
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(setq exwm--input-mode 'char-mode))))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;;;###autoload
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-input-grab-keyboard (&optional id)
|
|
|
|
|
"Switch to line-mode."
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(interactive (list (when (derived-mode-p 'exwm-mode)
|
|
|
|
|
(exwm--buffer->id (window-buffer)))))
|
2016-03-07 01:00:00 +01:00
|
|
|
|
(when id
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "id=#x%x" id)
|
2018-10-21 14:00:00 +02:00
|
|
|
|
(setq exwm--selected-input-mode 'line-mode)
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(exwm-input--grab-keyboard id)
|
|
|
|
|
(exwm-input--update-mode-line id)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;;;###autoload
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-input-release-keyboard (&optional id)
|
|
|
|
|
"Switch to char-mode."
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(interactive (list (when (derived-mode-p 'exwm-mode)
|
|
|
|
|
(exwm--buffer->id (window-buffer)))))
|
2016-03-07 01:00:00 +01:00
|
|
|
|
(when id
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "id=#x%x" id)
|
2018-10-21 14:00:00 +02:00
|
|
|
|
(setq exwm--selected-input-mode 'char-mode)
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(exwm-input--release-keyboard id)
|
|
|
|
|
(exwm-input--update-mode-line id)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2016-08-24 13:21:17 +02:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun exwm-input-toggle-keyboard (&optional id)
|
|
|
|
|
"Toggle between 'line-mode' and 'char-mode'."
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(interactive (list (when (derived-mode-p 'exwm-mode)
|
|
|
|
|
(exwm--buffer->id (window-buffer)))))
|
2016-08-24 13:21:17 +02:00
|
|
|
|
(when id
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "id=#x%x" id)
|
2016-08-24 13:21:17 +02:00
|
|
|
|
(with-current-buffer (exwm--id->buffer id)
|
2018-10-21 14:00:00 +02:00
|
|
|
|
(cl-case exwm--input-mode
|
2018-10-08 14:00:00 +02:00
|
|
|
|
(line-mode
|
|
|
|
|
(exwm-input-release-keyboard id))
|
|
|
|
|
(char-mode
|
|
|
|
|
(exwm-reset))))))
|
2016-08-24 13:21:17 +02:00
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-input--fake-key (event)
|
|
|
|
|
"Fake a key event equivalent to Emacs event EVENT."
|
2019-08-05 02:00:00 +02:00
|
|
|
|
(let* ((keysyms (xcb:keysyms:event->keysyms exwm--connection event))
|
2015-10-28 13:38:06 +01:00
|
|
|
|
keycode id)
|
2019-08-05 02:00:00 +02:00
|
|
|
|
(when (= 0 (caar keysyms))
|
2015-10-28 13:38:06 +01:00
|
|
|
|
(user-error "[EXWM] Invalid key: %s" (single-key-description event)))
|
|
|
|
|
(setq keycode (xcb:keysyms:keysym->keycode exwm--connection
|
2019-08-05 02:00:00 +02:00
|
|
|
|
(caar keysyms)))
|
2016-07-29 11:05:09 +02:00
|
|
|
|
(when (/= 0 keycode)
|
2015-10-28 13:38:06 +01:00
|
|
|
|
(setq id (exwm--buffer->id (window-buffer (selected-window))))
|
2018-08-13 14:00:00 +02:00
|
|
|
|
(exwm--log "id=#x%x event=%s keycode" id event keycode)
|
2015-09-20 04:51:58 +02:00
|
|
|
|
(dolist (class '(xcb:KeyPress xcb:KeyRelease))
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:SendEvent
|
|
|
|
|
:propagate 0 :destination id
|
|
|
|
|
:event-mask xcb:EventMask:NoEvent
|
|
|
|
|
:event (xcb:marshal
|
|
|
|
|
(make-instance class
|
|
|
|
|
:detail keycode
|
|
|
|
|
:time xcb:Time:CurrentTime
|
|
|
|
|
:root exwm--root :event id
|
|
|
|
|
:child 0
|
|
|
|
|
:root-x 0 :root-y 0
|
|
|
|
|
:event-x 0 :event-y 0
|
2019-08-05 02:00:00 +02:00
|
|
|
|
:state (cdar keysyms)
|
2015-09-20 04:51:58 +02:00
|
|
|
|
:same-screen 1)
|
|
|
|
|
exwm--connection)))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:flush exwm--connection)))
|
|
|
|
|
|
2015-09-04 03:09:59 +02:00
|
|
|
|
;;;###autoload
|
2019-06-30 18:21:24 +02:00
|
|
|
|
(cl-defun exwm-input-send-next-key (times &optional end-key)
|
2018-02-18 17:04:27 +01:00
|
|
|
|
"Send next key to client window.
|
|
|
|
|
|
|
|
|
|
EXWM will prompt for the key to send. This command can be prefixed to send
|
2019-06-30 18:21:24 +02:00
|
|
|
|
multiple keys. If END-KEY is non-nil, stop sending keys if it's pressed."
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(interactive "p")
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(unless (derived-mode-p 'exwm-mode)
|
2018-03-10 10:28:43 +01:00
|
|
|
|
(cl-return-from exwm-input-send-next-key))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(when (> times 12) (setq times 12))
|
|
|
|
|
(let (key keys)
|
|
|
|
|
(dotimes (i times)
|
|
|
|
|
;; Skip events not from keyboard
|
2017-02-24 16:25:02 +01:00
|
|
|
|
(let ((exwm-input-line-mode-passthrough t))
|
2017-02-19 23:53:43 +01:00
|
|
|
|
(catch 'break
|
|
|
|
|
(while t
|
2019-06-30 18:21:24 +02:00
|
|
|
|
(setq key (read-key (format "Send key: %s (%d/%d) %s"
|
2017-02-19 23:53:43 +01:00
|
|
|
|
(key-description keys)
|
2019-06-30 18:21:24 +02:00
|
|
|
|
(1+ i) times
|
|
|
|
|
(if end-key
|
|
|
|
|
(concat "To exit, press: "
|
|
|
|
|
(key-description
|
|
|
|
|
(list end-key)))
|
|
|
|
|
""))))
|
2017-02-19 23:53:43 +01:00
|
|
|
|
(unless (listp key) (throw 'break nil)))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(setq keys (vconcat keys (vector key)))
|
2019-06-30 18:21:24 +02:00
|
|
|
|
(when (eq key end-key) (cl-return-from exwm-input-send-next-key))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(exwm-input--fake-key key))))
|
|
|
|
|
|
2018-02-25 17:19:28 +01:00
|
|
|
|
(defun exwm-input--set-simulation-keys (simulation-keys &optional no-refresh)
|
|
|
|
|
"Set simulation keys."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "%s" simulation-keys)
|
2018-02-25 17:19:28 +01:00
|
|
|
|
(unless no-refresh
|
2018-03-04 05:21:53 +01:00
|
|
|
|
;; Unbind simulation keys.
|
|
|
|
|
(let ((hash (buffer-local-value 'exwm-input--simulation-keys
|
|
|
|
|
(current-buffer))))
|
|
|
|
|
(when (hash-table-p hash)
|
|
|
|
|
(maphash (lambda (key _value)
|
|
|
|
|
(when (sequencep key)
|
|
|
|
|
(if exwm-input--local-simulation-keys
|
|
|
|
|
(local-unset-key key)
|
|
|
|
|
(define-key exwm-mode-map key nil))))
|
|
|
|
|
hash)))
|
|
|
|
|
;; Abandon the old hash table.
|
2018-02-25 17:19:28 +01:00
|
|
|
|
(setq exwm-input--simulation-keys (make-hash-table :test #'equal)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(dolist (i simulation-keys)
|
2018-02-20 14:57:49 +01:00
|
|
|
|
(let ((original (vconcat (car i)))
|
|
|
|
|
(simulated (cdr i)))
|
|
|
|
|
(setq simulated (if (sequencep simulated)
|
|
|
|
|
(append simulated nil)
|
|
|
|
|
(list simulated)))
|
|
|
|
|
;; The key stored is a key sequence (vector).
|
|
|
|
|
;; The value stored is a list of key events.
|
|
|
|
|
(puthash original simulated exwm-input--simulation-keys)
|
|
|
|
|
;; Also mark the prefix key as used.
|
|
|
|
|
(puthash (aref original 0) t exwm-input--simulation-keys)))
|
|
|
|
|
;; Update keymaps.
|
|
|
|
|
(maphash (lambda (key _value)
|
|
|
|
|
(when (sequencep key)
|
|
|
|
|
(if exwm-input--local-simulation-keys
|
|
|
|
|
(local-set-key key #'exwm-input-send-simulation-key)
|
|
|
|
|
(define-key exwm-mode-map key
|
|
|
|
|
#'exwm-input-send-simulation-key))))
|
|
|
|
|
exwm-input--simulation-keys))
|
|
|
|
|
|
2018-02-25 17:19:28 +01:00
|
|
|
|
(defun exwm-input-set-simulation-keys (simulation-keys)
|
|
|
|
|
"Please customize or set `exwm-input-simulation-keys' instead."
|
|
|
|
|
(declare (obsolete nil "26"))
|
|
|
|
|
(exwm-input--set-simulation-keys simulation-keys))
|
|
|
|
|
|
2018-02-20 14:57:49 +01:00
|
|
|
|
(defcustom exwm-input-simulation-keys nil
|
|
|
|
|
"Simulation keys.
|
|
|
|
|
|
|
|
|
|
It is an alist of the form (original-key . simulated-key), where both
|
|
|
|
|
original-key and simulated-key are key sequences. Original-key is what you
|
|
|
|
|
type to an X window in line-mode which then gets translated to simulated-key
|
|
|
|
|
by EXWM and forwarded to the X window.
|
|
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
* Setting the value directly (rather than customizing it) after EXWM
|
|
|
|
|
finishes initialization has no effect.
|
|
|
|
|
* Original-keys consist of multiple key events are only supported in Emacs
|
2019-02-06 01:00:00 +01:00
|
|
|
|
26.2 and later.
|
2018-02-20 14:57:49 +01:00
|
|
|
|
* A minority of applications do not accept simulated keys by default. It's
|
|
|
|
|
required to customize them to accept events sent by SendEvent.
|
|
|
|
|
* The predefined examples in the Customize interface are not guaranteed to
|
|
|
|
|
work for all applications. This can be tweaked on a per application basis
|
|
|
|
|
with `exwm-input-set-local-simulation-keys'."
|
2019-02-02 01:55:24 +01:00
|
|
|
|
:type '(alist :key-type (key-sequence :tag "Original")
|
|
|
|
|
:value-type (choice (key-sequence :tag "User-defined")
|
|
|
|
|
(key-sequence :tag "Move left" [left])
|
2018-02-20 14:57:49 +01:00
|
|
|
|
(key-sequence :tag "Move right" [right])
|
|
|
|
|
(key-sequence :tag "Move up" [up])
|
|
|
|
|
(key-sequence :tag "Move down" [down])
|
|
|
|
|
(key-sequence :tag "Move to BOL" [home])
|
|
|
|
|
(key-sequence :tag "Move to EOL" [end])
|
|
|
|
|
(key-sequence :tag "Page up" [prior])
|
|
|
|
|
(key-sequence :tag "Page down" [next])
|
|
|
|
|
(key-sequence :tag "Copy" [C-c])
|
|
|
|
|
(key-sequence :tag "Paste" [C-v])
|
|
|
|
|
(key-sequence :tag "Delete" [delete])
|
|
|
|
|
(key-sequence :tag "Delete to EOL"
|
2019-02-02 01:55:24 +01:00
|
|
|
|
[S-end delete])))
|
2018-02-20 14:57:49 +01:00
|
|
|
|
:set (lambda (symbol value)
|
|
|
|
|
(set symbol value)
|
2018-02-25 17:19:28 +01:00
|
|
|
|
(exwm-input--set-simulation-keys value)))
|
|
|
|
|
|
2019-10-02 02:00:00 +02:00
|
|
|
|
(defcustom exwm-input-pre-post-command-blacklist '(exit-minibuffer)
|
|
|
|
|
"Commands impossible to detect with `post-command-hook'."
|
|
|
|
|
:type '(repeat function))
|
|
|
|
|
|
2018-02-25 17:19:28 +01:00
|
|
|
|
(cl-defun exwm-input--read-keys (prompt stop-key)
|
|
|
|
|
(let ((cursor-in-echo-area t)
|
|
|
|
|
keys key)
|
|
|
|
|
(while (not (eq key stop-key))
|
|
|
|
|
(setq key (read-key (format "%s (terminate with %s): %s"
|
|
|
|
|
prompt
|
|
|
|
|
(key-description (vector stop-key))
|
|
|
|
|
(key-description keys)))
|
|
|
|
|
keys (vconcat keys (vector key))))
|
|
|
|
|
(substring keys 0 -1)))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun exwm-input-set-simulation-key (original-key simulated-key)
|
|
|
|
|
"Set a simulation key.
|
|
|
|
|
|
|
|
|
|
The simulation key takes effect in real time, but is lost when this session
|
|
|
|
|
ends unless it's specifically saved in the Customize interface for
|
|
|
|
|
`exwm-input-simulation-keys'."
|
|
|
|
|
(interactive
|
|
|
|
|
(let (original simulated)
|
|
|
|
|
(setq original (exwm-input--read-keys "Original keys" ?\C-g))
|
|
|
|
|
(when original
|
|
|
|
|
(setq simulated (exwm-input--read-keys
|
|
|
|
|
(format "Simulate %s as" (key-description original))
|
|
|
|
|
?\C-g)))
|
|
|
|
|
(list original simulated)))
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log "original: %s, simulated: %s" original-key simulated-key)
|
2018-02-25 17:19:28 +01:00
|
|
|
|
(when (and original-key simulated-key)
|
|
|
|
|
(let ((entry `((,original-key . ,simulated-key))))
|
|
|
|
|
(setq exwm-input-simulation-keys (append exwm-input-simulation-keys
|
|
|
|
|
entry))
|
|
|
|
|
(exwm-input--set-simulation-keys entry t))))
|
2018-02-20 14:57:49 +01:00
|
|
|
|
|
|
|
|
|
(defun exwm-input--unset-simulation-keys ()
|
|
|
|
|
"Clear simulation keys and key bindings defined."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2018-02-20 14:57:49 +01:00
|
|
|
|
(when (hash-table-p exwm-input--simulation-keys)
|
|
|
|
|
(maphash (lambda (key _value)
|
|
|
|
|
(when (sequencep key)
|
|
|
|
|
(define-key exwm-mode-map key nil)))
|
|
|
|
|
exwm-input--simulation-keys)
|
|
|
|
|
(clrhash exwm-input--simulation-keys)))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2016-06-17 12:45:34 +02:00
|
|
|
|
(defun exwm-input-set-local-simulation-keys (simulation-keys)
|
|
|
|
|
"Set buffer-local simulation keys.
|
|
|
|
|
|
2018-02-25 17:19:28 +01:00
|
|
|
|
SIMULATION-KEYS is an alist of the form (original-key . simulated-key),
|
|
|
|
|
where both ORIGINAL-KEY and SIMULATED-KEY are key sequences."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2016-06-17 12:45:34 +02:00
|
|
|
|
(make-local-variable 'exwm-input--simulation-keys)
|
|
|
|
|
(use-local-map (copy-keymap exwm-mode-map))
|
|
|
|
|
(let ((exwm-input--local-simulation-keys t))
|
2018-02-25 17:19:28 +01:00
|
|
|
|
(exwm-input--set-simulation-keys simulation-keys)))
|
2016-06-17 12:45:34 +02:00
|
|
|
|
|
2016-02-19 10:12:43 +01:00
|
|
|
|
;;;###autoload
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(cl-defun exwm-input-send-simulation-key (times)
|
2018-02-20 14:57:49 +01:00
|
|
|
|
"Fake a key event according to the last input key sequence."
|
2015-08-05 08:10:44 +02:00
|
|
|
|
(interactive "p")
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2018-02-18 17:04:27 +01:00
|
|
|
|
(unless (derived-mode-p 'exwm-mode)
|
2018-03-10 10:28:43 +01:00
|
|
|
|
(cl-return-from exwm-input-send-simulation-key))
|
2018-02-20 14:57:49 +01:00
|
|
|
|
(let ((keys (gethash (this-single-command-keys)
|
|
|
|
|
exwm-input--simulation-keys)))
|
|
|
|
|
(dotimes (_ times)
|
|
|
|
|
(dolist (key keys)
|
|
|
|
|
(exwm-input--fake-key key)))))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2016-05-23 13:13:42 +02:00
|
|
|
|
(defun exwm-input--on-pre-command ()
|
|
|
|
|
"Run in `pre-command-hook'."
|
2019-10-02 02:00:00 +02:00
|
|
|
|
(unless (memq this-command exwm-input-pre-post-command-blacklist)
|
2018-03-23 16:53:05 +01:00
|
|
|
|
(setq exwm-input--during-command t)))
|
2016-05-23 13:13:42 +02:00
|
|
|
|
|
|
|
|
|
(defun exwm-input--on-post-command ()
|
|
|
|
|
"Run in `post-command-hook'."
|
|
|
|
|
(setq exwm-input--during-command nil))
|
|
|
|
|
|
2019-08-18 02:00:00 +02:00
|
|
|
|
(defun exwm-input--on-minibuffer-setup ()
|
|
|
|
|
"Run in `minibuffer-setup-hook' to grab keyboard if necessary."
|
|
|
|
|
(exwm--log)
|
|
|
|
|
(with-current-buffer
|
|
|
|
|
(window-buffer (frame-selected-window exwm-workspace--current))
|
|
|
|
|
(when (and (derived-mode-p 'exwm-mode)
|
|
|
|
|
(eq exwm--selected-input-mode 'char-mode))
|
|
|
|
|
(exwm-input--grab-keyboard exwm--id))))
|
|
|
|
|
|
|
|
|
|
(defun exwm-input--on-minibuffer-exit ()
|
|
|
|
|
"Run in `minibuffer-exit-hook' to release keyboard if necessary."
|
|
|
|
|
(exwm--log)
|
|
|
|
|
(with-current-buffer
|
|
|
|
|
(window-buffer (frame-selected-window exwm-workspace--current))
|
|
|
|
|
(when (and (derived-mode-p 'exwm-mode)
|
|
|
|
|
(eq exwm--selected-input-mode 'char-mode)
|
|
|
|
|
(eq exwm--input-mode 'line-mode))
|
|
|
|
|
(exwm-input--release-keyboard exwm--id))))
|
|
|
|
|
|
|
|
|
|
(defun exwm-input--on-echo-area-dirty ()
|
|
|
|
|
"Run when new message arrives to grab keyboard if necessary."
|
|
|
|
|
(exwm--log)
|
|
|
|
|
(when (and (not (active-minibuffer-window))
|
|
|
|
|
(not (exwm-workspace--client-p))
|
|
|
|
|
cursor-in-echo-area)
|
|
|
|
|
(exwm-input--on-minibuffer-setup)))
|
|
|
|
|
|
|
|
|
|
(defun exwm-input--on-echo-area-clear ()
|
|
|
|
|
"Run in `echo-area-clear-hook' to release keyboard if necessary."
|
|
|
|
|
(exwm--log)
|
|
|
|
|
(unless (current-message)
|
|
|
|
|
(exwm-input--on-minibuffer-exit)))
|
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(defun exwm-input--init ()
|
|
|
|
|
"Initialize the keyboard module."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Refresh keyboard mapping
|
2017-11-26 13:26:57 +01:00
|
|
|
|
(xcb:keysyms:init exwm--connection #'exwm-input--on-keysyms-update)
|
2016-08-09 07:34:29 +02:00
|
|
|
|
;; Create the X window and intern the atom used to fetch timestamp.
|
|
|
|
|
(setq exwm-input--timestamp-window (xcb:generate-id exwm--connection))
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:CreateWindow
|
|
|
|
|
:depth 0
|
|
|
|
|
:wid exwm-input--timestamp-window
|
|
|
|
|
:parent exwm--root
|
|
|
|
|
:x -1
|
|
|
|
|
:y -1
|
|
|
|
|
:width 1
|
|
|
|
|
:height 1
|
|
|
|
|
:border-width 0
|
|
|
|
|
:class xcb:WindowClass:CopyFromParent
|
|
|
|
|
:visual 0
|
|
|
|
|
:value-mask xcb:CW:EventMask
|
|
|
|
|
:event-mask xcb:EventMask:PropertyChange))
|
2018-03-06 01:00:00 +01:00
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:ewmh:set-_NET_WM_NAME
|
|
|
|
|
:window exwm-input--timestamp-window
|
|
|
|
|
:data "EXWM: exwm-input--timestamp-window"))
|
2019-02-06 01:00:00 +01:00
|
|
|
|
(setq exwm-input--timestamp-atom (exwm--intern-atom "_TIME"))
|
2018-02-25 17:15:44 +01:00
|
|
|
|
;; Initialize global keys.
|
|
|
|
|
(dolist (i exwm-input-global-keys)
|
|
|
|
|
(exwm-input--set-key (car i) (cdr i)))
|
2018-02-20 14:57:49 +01:00
|
|
|
|
;; Initialize simulation keys.
|
|
|
|
|
(when exwm-input-simulation-keys
|
2018-02-25 17:19:28 +01:00
|
|
|
|
(exwm-input--set-simulation-keys exwm-input-simulation-keys))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Attach event listeners
|
2016-08-09 07:34:29 +02:00
|
|
|
|
(xcb:+event exwm--connection 'xcb:PropertyNotify
|
|
|
|
|
#'exwm-input--on-PropertyNotify)
|
2018-02-21 17:26:04 +01:00
|
|
|
|
(xcb:+event exwm--connection 'xcb:CreateNotify #'exwm-input--on-CreateNotify)
|
2018-07-14 18:00:00 +02:00
|
|
|
|
(xcb:+event exwm--connection 'xcb:KeyPress #'exwm-input--on-KeyPress)
|
2015-09-04 03:09:59 +02:00
|
|
|
|
(xcb:+event exwm--connection 'xcb:ButtonPress #'exwm-input--on-ButtonPress)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
(xcb:+event exwm--connection 'xcb:ButtonRelease
|
2015-09-04 03:09:59 +02:00
|
|
|
|
#'exwm-floating--stop-moveresize)
|
|
|
|
|
(xcb:+event exwm--connection 'xcb:MotionNotify
|
|
|
|
|
#'exwm-floating--do-moveresize)
|
2017-12-31 13:53:58 +01:00
|
|
|
|
(when mouse-autoselect-window
|
|
|
|
|
(xcb:+event exwm--connection 'xcb:EnterNotify
|
|
|
|
|
#'exwm-input--on-EnterNotify))
|
2016-02-06 05:59:33 +01:00
|
|
|
|
;; Control `exwm-input--during-command'
|
2016-05-23 13:13:42 +02:00
|
|
|
|
(add-hook 'pre-command-hook #'exwm-input--on-pre-command)
|
|
|
|
|
(add-hook 'post-command-hook #'exwm-input--on-post-command)
|
2019-08-18 02:00:00 +02:00
|
|
|
|
;; Grab/Release keyboard when minibuffer/echo becomes active/inactive.
|
|
|
|
|
(add-hook 'minibuffer-setup-hook #'exwm-input--on-minibuffer-setup)
|
|
|
|
|
(add-hook 'minibuffer-exit-hook #'exwm-input--on-minibuffer-exit)
|
|
|
|
|
(setq exwm-input--echo-area-timer
|
|
|
|
|
(run-with-idle-timer 0 t #'exwm-input--on-echo-area-dirty))
|
|
|
|
|
(add-hook 'echo-area-clear-hook #'exwm-input--on-echo-area-clear)
|
2015-07-17 13:16:08 +02:00
|
|
|
|
;; Update focus when buffer list updates
|
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
|
|
|
|
(add-hook 'buffer-list-update-hook #'exwm-input--on-buffer-list-update))
|
|
|
|
|
|
|
|
|
|
(defun exwm-input--post-init ()
|
|
|
|
|
"The second stage in the initialization of the input module."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
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--update-global-prefix-keys))
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
2016-05-23 13:13:42 +02:00
|
|
|
|
(defun exwm-input--exit ()
|
|
|
|
|
"Exit the input module."
|
2018-12-02 01:00:00 +01:00
|
|
|
|
(exwm--log)
|
2018-02-20 14:57:49 +01:00
|
|
|
|
(exwm-input--unset-simulation-keys)
|
2016-05-23 13:13:42 +02:00
|
|
|
|
(remove-hook 'pre-command-hook #'exwm-input--on-pre-command)
|
|
|
|
|
(remove-hook 'post-command-hook #'exwm-input--on-post-command)
|
2019-08-18 02:00:00 +02:00
|
|
|
|
(remove-hook 'minibuffer-setup-hook #'exwm-input--on-minibuffer-setup)
|
|
|
|
|
(remove-hook 'minibuffer-exit-hook #'exwm-input--on-minibuffer-exit)
|
|
|
|
|
(when exwm-input--echo-area-timer
|
|
|
|
|
(cancel-timer exwm-input--echo-area-timer)
|
|
|
|
|
(setq exwm-input--echo-area-timer nil))
|
|
|
|
|
(remove-hook 'echo-area-clear-hook #'exwm-input--on-echo-area-clear)
|
2016-07-30 04:06:00 +02:00
|
|
|
|
(remove-hook 'buffer-list-update-hook #'exwm-input--on-buffer-list-update)
|
2016-07-30 13:01:33 +02:00
|
|
|
|
(when exwm-input--update-focus-defer-timer
|
|
|
|
|
(cancel-timer exwm-input--update-focus-defer-timer))
|
|
|
|
|
(when exwm-input--update-focus-timer
|
2019-09-22 02:00:00 +02:00
|
|
|
|
(cancel-timer exwm-input--update-focus-timer))
|
|
|
|
|
;; Make input focus working even without a WM.
|
|
|
|
|
(xcb:+request exwm--connection
|
|
|
|
|
(make-instance 'xcb:SetInputFocus
|
|
|
|
|
:revert-to xcb:InputFocus:PointerRoot
|
|
|
|
|
:focus exwm--root
|
|
|
|
|
:time xcb:Time:CurrentTime))
|
|
|
|
|
(xcb:flush exwm--connection))
|
2016-05-23 13:13:42 +02:00
|
|
|
|
|
2015-07-17 13:16:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'exwm-input)
|
|
|
|
|
|
|
|
|
|
;;; exwm-input.el ends here
|