Fix system tray issues after updating workspaces

* exwm-workspace.el (exwm-workspace-switch-hook): New hook run by
`exwm-workspace-switch'.
* exwm-randr.el (exwm-randr-refresh-hook): New hook run by
`exwm-randr--refresh'.
* exwm-systemtray.el (exwm-systemtray--on-randr-refresh)
(exwm-systemtray--on-workspace-switch, exwm-systemtray--init): Update the
system tray in `exwm-randr-refresh-hook' and `exwm-workspace-switch-hook'.

* exwm-layout.el (exwm-layout--set-frame-fullscreen):
* exwm-workspace.el (exwm-workspace--post-init): Wait until all workspace
frames are set fullscreen.

* exwm-workspace.el (exwm-workspace--current-width)
(exwm-workspace--current-height): New functions for retrieving the width
and height of the current workspace.
* exwm-layout.el (exwm-layout-set-fullscreen):
* exwm-manage.el (exwm-manage--manage-window)
(exwm-manage--on-ConfigureRequest):
* exwm-systemtray.el (exwm-systemtray--refresh, exwm-systemtray--init):
* exwm-workspace.le (exwm-workspace--resize-minibuffer-frame)
(exwm-workspace--on-ConfigureNotify): Switch to
`exwm-workspace--current-width' and `exwm-workspace--current-height'.

* exwm-core.el:
* exwm-floating.el:
* exwm-floating.el:
* exwm-input.el:
* exwm-layout.el:
* exwm-manage.el:
* exwm-randr.el:
* exwm-systemtray.el:
* exwm-workspace.el:
* exwm.el:
Clean up loading file.  Set/Unset some functions as commands.

* README.md: Add intro to system tray.
This commit is contained in:
Chris Feng 2016-02-19 17:12:43 +08:00
parent bfd43feb49
commit fc589b899b
10 changed files with 160 additions and 91 deletions

View file

@ -3,11 +3,12 @@
EXWM (Emacs X Window Manager) is a full-featured tiling X window manager for 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). Emacs built on top of [XELB](https://github.com/ch11ng/xelb).
It features: It features:
+ Fully keyboard-driven operation + Fully keyboard-driven operations
+ Hybrid layout modes (tiling & stacking) + Hybrid layout modes (tiling & stacking)
+ Workspace support + Workspace support
+ ICCCM/EWMH compliance + ICCCM/EWMH compliance
+ Basic RandR support (optional) + (Optional) RandR (multi-monitor) support
+ (Optional) system tray
Please check the [User Guide](https://github.com/ch11ng/exwm/wiki) Please check the [User Guide](https://github.com/ch11ng/exwm/wiki)
for more details. for more details.

View file

@ -78,6 +78,9 @@
(logior xcb:EventMask:StructureNotify xcb:EventMask:PropertyChange)) (logior xcb:EventMask:StructureNotify xcb:EventMask:PropertyChange))
"Event mask set on all managed windows.") "Event mask set on all managed windows.")
(declare-function exwm-input--on-KeyPress-line-mode "exwm-input.el"
(key-press))
;; Internal variables ;; Internal variables
(defvar-local exwm--id nil) ;window ID (defvar-local exwm--id nil) ;window ID
(defvar-local exwm--container nil) ;container (defvar-local exwm--container nil) ;container
@ -110,7 +113,7 @@
(defvar-local exwm--normal-hints-max-height nil) (defvar-local exwm--normal-hints-max-height nil)
;; (defvar-local exwm--normal-hints-win-gravity nil) ;; (defvar-local exwm--normal-hints-win-gravity nil)
;; WM_HINTS ;; WM_HINTS
(defvar-local exwm--hints-input nil) ;FIXME (defvar-local exwm--hints-input nil)
(defvar-local exwm--hints-urgency nil) (defvar-local exwm--hints-urgency nil)
;; _MOTIF_WM_HINTS ;; _MOTIF_WM_HINTS
(defvar-local exwm--mwm-hints nil) (defvar-local exwm--mwm-hints nil)
@ -126,6 +129,8 @@
map) map)
"Keymap for `exwm-mode'.") "Keymap for `exwm-mode'.")
(declare-function exwm-manage--kill-buffer-query-function "exwm-manage.el")
(define-derived-mode exwm-mode nil "EXWM" (define-derived-mode exwm-mode nil "EXWM"
"Major mode for managing X windows. "Major mode for managing X windows.

View file

@ -28,7 +28,6 @@
(require 'xcb-cursor) (require 'xcb-cursor)
(require 'exwm-core) (require 'exwm-core)
(eval-when-compile (require 'exwm-workspace))
(defvar exwm-floating-border-width 1 "Border width of the floating window.") (defvar exwm-floating-border-width 1 "Border width of the floating window.")
(defvar exwm-floating-border-color "navy" (defvar exwm-floating-border-color "navy"
@ -50,12 +49,17 @@
(defvar exwm-floating--cursor-bottom-left nil) (defvar exwm-floating--cursor-bottom-left nil)
(defvar exwm-floating--cursor-left nil) (defvar exwm-floating--cursor-left nil)
(declare-function exwm-layout--refresh "exwm-layout.el") (defvar exwm-workspace--current)
(defvar exwm-workspace--list)
(defvar exwm-workspace-current-index)
(defvar exwm-workspace--switch-history-outdated)
(defvar exwm-workspace-minibuffer-position)
(declare-function exwm-layout--refresh "exwm-layout.el")
(declare-function exwm-layout--show "exwm-layout.el")
;;;###autoload
(defun exwm-floating--set-floating (id) (defun exwm-floating--set-floating (id)
"Make window ID floating." "Make window ID floating."
(interactive)
(let ((window (get-buffer-window (exwm--id->buffer id)))) (let ((window (get-buffer-window (exwm--id->buffer id))))
(when window ;window in non-floating state (when window ;window in non-floating state
(set-window-buffer window (other-buffer)))) ;hide it first (set-window-buffer window (other-buffer)))) ;hide it first
@ -194,10 +198,8 @@
(select-frame-set-input-focus frame)) (select-frame-set-input-focus frame))
(run-hooks 'exwm-floating-setup-hook)) (run-hooks 'exwm-floating-setup-hook))
;;;###autoload
(defun exwm-floating--unset-floating (id) (defun exwm-floating--unset-floating (id)
"Make window ID non-floating." "Make window ID non-floating."
(interactive)
(let ((buffer (exwm--id->buffer id))) (let ((buffer (exwm--id->buffer id)))
(with-current-buffer buffer (with-current-buffer buffer
;; Reparent the frame back to the root window. ;; Reparent the frame back to the root window.
@ -257,7 +259,6 @@
(defvar exwm-floating--moveresize-calculate nil (defvar exwm-floating--moveresize-calculate nil
"Calculate move/resize parameters [buffer event-mask x y width height].") "Calculate move/resize parameters [buffer event-mask x y width height].")
;;;###autoload
(defun exwm-floating--start-moveresize (id &optional type) (defun exwm-floating--start-moveresize (id &optional type)
"Start move/resize." "Start move/resize."
(let ((buffer (exwm--id->buffer id)) (let ((buffer (exwm--id->buffer id))
@ -404,7 +405,6 @@
:cursor cursor :cursor cursor
:time xcb:Time:CurrentTime))))))) :time xcb:Time:CurrentTime)))))))
;;;###autoload
(defun exwm-floating--stop-moveresize (&rest _args) (defun exwm-floating--stop-moveresize (&rest _args)
"Stop move/resize." "Stop move/resize."
(xcb:+request exwm--connection (xcb:+request exwm--connection
@ -434,7 +434,6 @@
(xcb:flush exwm--connection) (xcb:flush exwm--connection)
(setq exwm-floating--moveresize-calculate nil)) (setq exwm-floating--moveresize-calculate nil))
;;;###autoload
(defun exwm-floating--do-moveresize (data _synthetic) (defun exwm-floating--do-moveresize (data _synthetic)
"Perform move/resize." "Perform move/resize."
(when exwm-floating--moveresize-calculate (when exwm-floating--moveresize-calculate

View file

@ -37,7 +37,6 @@
(require 'xcb-keysyms) (require 'xcb-keysyms)
(require 'exwm-core) (require 'exwm-core)
(eval-when-compile (require 'exwm-workspace))
(defvar exwm-input-move-event 's-down-mouse-1 (defvar exwm-input-move-event 's-down-mouse-1
"Emacs event to start moving a window.") "Emacs event to start moving a window.")
@ -94,6 +93,11 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
exwm-input--timer exwm-input--timer
(run-with-idle-timer 0.01 nil #'exwm-input--update-focus))))) (run-with-idle-timer 0.01 nil #'exwm-input--update-focus)))))
(defvar exwm-workspace--current)
(defvar exwm-workspace--switch-history-outdated)
(defvar exwm-workspace-current-index)
(defvar exwm-workspace--minibuffer)
(defun exwm-input--update-focus () (defun exwm-input--update-focus ()
"Update input focus." "Update input focus."
(when (window-live-p exwm-input--focus-window) (when (window-live-p exwm-input--focus-window)
@ -158,6 +162,11 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
(setq exwm-input--temp-line-mode nil) (setq exwm-input--temp-line-mode nil)
(exwm-input--release-keyboard)))) (exwm-input--release-keyboard))))
(declare-function exwm-floating--start-moveresize "exwm-floating.el"
(id &optional type))
(defvar exwm-workspace--list)
(defun exwm-input--on-ButtonPress (data _synthetic) (defun exwm-input--on-ButtonPress (data _synthetic)
"Handle ButtonPress event." "Handle ButtonPress event."
(let ((obj (make-instance 'xcb:ButtonPress)) (let ((obj (make-instance 'xcb:ButtonPress))
@ -262,6 +271,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
(defun exwm-input-set-key (key command) (defun exwm-input-set-key (key command)
"Set a global key binding." "Set a global key binding."
(interactive "KSet key globally: \nCSet key %s to command: ")
(global-set-key key command) (global-set-key key command)
(cl-pushnew key exwm-input--global-keys)) (cl-pushnew key exwm-input--global-keys))
@ -273,7 +283,6 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
(defvar exwm-input--during-command nil (defvar exwm-input--during-command nil
"Indicate whether between `pre-command-hook' and `post-command-hook'.") "Indicate whether between `pre-command-hook' and `post-command-hook'.")
;;;###autoload
(defun exwm-input--on-KeyPress-line-mode (key-press) (defun exwm-input--on-KeyPress-line-mode (key-press)
"Parse X KeyPress event to Emacs key event and then feed the command loop." "Parse X KeyPress event to Emacs key event and then feed the command loop."
(with-slots (detail state) key-press (with-slots (detail state) key-press
@ -443,12 +452,13 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
(defun exwm-input-set-simulation-keys (simulation-keys) (defun exwm-input-set-simulation-keys (simulation-keys)
"Set simulation keys. "Set simulation keys.
SIMULATION-KEYS is a list of alist (key-sequence1 . key-sequence2)." SIMULATION-KEYS is an alist of the form (original-key . simulated-key)."
(setq exwm-input--simulation-keys nil) (setq exwm-input--simulation-keys nil)
(dolist (i simulation-keys) (dolist (i simulation-keys)
(cl-pushnew `(,(vconcat (car i)) . ,(cdr i)) exwm-input--simulation-keys)) (cl-pushnew `(,(vconcat (car i)) . ,(cdr i)) exwm-input--simulation-keys))
(exwm-input--update-simulation-prefix-keys)) (exwm-input--update-simulation-prefix-keys))
;;;###autoload
(defun exwm-input-send-simulation-key (times) (defun exwm-input-send-simulation-key (times)
"Fake a key event according to last input key sequence." "Fake a key event according to last input key sequence."
(interactive "p") (interactive "p")
@ -461,6 +471,11 @@ SIMULATION-KEYS is a list of alist (key-sequence1 . key-sequence2)."
(dolist (j pair) (dolist (j pair)
(exwm-input--fake-key j)))))) (exwm-input--fake-key j))))))
(declare-function exwm-floating--stop-moveresize "exwm-floating.el"
(&rest _args))
(declare-function exwm-floating--do-moveresize "exwm-floating.el"
(data _synthetic))
(defun exwm-input--init () (defun exwm-input--init ()
"Initialize the keyboard module." "Initialize the keyboard module."
;; Refresh keyboard mapping ;; Refresh keyboard mapping

View file

@ -26,7 +26,6 @@
;;; Code: ;;; Code:
(require 'exwm-core) (require 'exwm-core)
(eval-when-compile (require 'exwm-workspace))
(defvar exwm-floating-border-width) (defvar exwm-floating-border-width)
@ -51,7 +50,6 @@
xcb:ConfigWindow:Height)) xcb:ConfigWindow:Height))
:width width :height height)))) :width width :height height))))
;;;###autoload
(defun exwm-layout--show (id &optional window) (defun exwm-layout--show (id &optional window)
"Show window ID exactly fit in the Emacs window WINDOW." "Show window ID exactly fit in the Emacs window WINDOW."
(exwm--log "Show #x%x in %s" id window) (exwm--log "Show #x%x in %s" id window)
@ -112,7 +110,6 @@
exwm--connection)))) exwm--connection))))
(xcb:flush exwm--connection)) (xcb:flush exwm--connection))
;;;###autoload
(defun exwm-layout--hide (id) (defun exwm-layout--hide (id)
"Hide window ID." "Hide window ID."
(unless (eq xcb:icccm:WM_STATE:IconicState ;already hidden (unless (eq xcb:icccm:WM_STATE:IconicState ;already hidden
@ -137,6 +134,9 @@
:icon xcb:Window:None)) :icon xcb:Window:None))
(xcb:flush exwm--connection))) (xcb:flush exwm--connection)))
(defvar exwm-workspace--current)
(defvar exwm-workspace--list)
;;;###autoload ;;;###autoload
(defun exwm-layout-set-fullscreen (&optional id) (defun exwm-layout-set-fullscreen (&optional id)
"Make window ID fullscreen." "Make window ID fullscreen."
@ -153,9 +153,8 @@
(vector (slot-value geometry 'x) (slot-value geometry 'y)))) (vector (slot-value geometry 'x) (slot-value geometry 'y))))
(xcb:flush exwm--connection)) (xcb:flush exwm--connection))
(exwm-layout--resize-container exwm--id exwm--container 0 0 (exwm-layout--resize-container exwm--id exwm--container 0 0
(frame-pixel-width exwm-workspace--current) (exwm-workspace--current-width)
(frame-pixel-height (exwm-workspace--current-height))
exwm-workspace--current))
(xcb:+request exwm--connection (xcb:+request exwm--connection
(make-instance 'xcb:ewmh:set-_NET_WM_STATE (make-instance 'xcb:ewmh:set-_NET_WM_STATE
:window exwm--id :window exwm--id
@ -164,6 +163,7 @@
(setq exwm--fullscreen t) (setq exwm--fullscreen t)
(exwm-input-release-keyboard))) (exwm-input-release-keyboard)))
;;;###autoload
(defun exwm-layout-unset-fullscreen (&optional id) (defun exwm-layout-unset-fullscreen (&optional id)
"Restore window from fullscreen state." "Restore window from fullscreen state."
(interactive) (interactive)
@ -187,6 +187,9 @@
(setq exwm--fullscreen nil) (setq exwm--fullscreen nil)
(exwm-input-grab-keyboard))) (exwm-input-grab-keyboard)))
(defvar exwm-layout--fullscreen-frame-count 0
"Count the fullscreen workspace frames.")
;; This function is superficially similar to `exwm-layout-set-fullscreen', but ;; This function is superficially similar to `exwm-layout-set-fullscreen', but
;; they do very different things: `exwm-layout--set-frame-fullscreen' resizes a ;; they do very different things: `exwm-layout--set-frame-fullscreen' resizes a
;; frame to the actual monitor size, `exwm-layout-set-fullscreen' resizes an X ;; frame to the actual monitor size, `exwm-layout-set-fullscreen' resizes an X
@ -207,7 +210,8 @@
(exwm-workspace--minibuffer-own-frame-p)) (exwm-workspace--minibuffer-own-frame-p))
(exwm-workspace--resize-minibuffer-frame width height)) (exwm-workspace--resize-minibuffer-frame width height))
(exwm-layout--resize-container id workspace x y width height) (exwm-layout--resize-container id workspace x y width height)
(xcb:flush exwm--connection)))) (xcb:flush exwm--connection)))
(cl-incf exwm-layout--fullscreen-frame-count))
(defvar exwm-layout-show-all-buffers nil (defvar exwm-layout-show-all-buffers nil
"Non-nil to allow switching to buffers on other workspaces.") "Non-nil to allow switching to buffers on other workspaces.")
@ -297,6 +301,7 @@
(exwm-layout--refresh) (exwm-layout--refresh)
(run-with-idle-timer 0.01 nil #'exwm-layout--refresh)))) ;FIXME (run-with-idle-timer 0.01 nil #'exwm-layout--refresh)))) ;FIXME
;;;###autoload
(defun exwm-layout-enlarge-window (delta &optional horizontal) (defun exwm-layout-enlarge-window (delta &optional horizontal)
"Make the selected window DELTA pixels taller. "Make the selected window DELTA pixels taller.
@ -371,6 +376,7 @@ windows."
:height height)) :height height))
(xcb:flush exwm--connection)))))) (xcb:flush exwm--connection))))))
;;;###autoload
(defun exwm-layout-enlarge-window-horizontally (delta) (defun exwm-layout-enlarge-window-horizontally (delta)
"Make the selected window DELTA pixels wider. "Make the selected window DELTA pixels wider.
@ -378,6 +384,7 @@ See also `exwm-layout-enlarge-window'."
(interactive "p") (interactive "p")
(exwm-layout-enlarge-window delta t)) (exwm-layout-enlarge-window delta t))
;;;###autoload
(defun exwm-layout-shrink-window (delta) (defun exwm-layout-shrink-window (delta)
"Make the selected window DELTA pixels lower. "Make the selected window DELTA pixels lower.
@ -385,6 +392,7 @@ See also `exwm-layout-enlarge-window'."
(interactive "p") (interactive "p")
(exwm-layout-enlarge-window (- delta))) (exwm-layout-enlarge-window (- delta)))
;;;###autoload
(defun exwm-layout-shrink-window-horizontally (delta) (defun exwm-layout-shrink-window-horizontally (delta)
"Make the selected window DELTA pixels narrower. "Make the selected window DELTA pixels narrower.
@ -392,6 +400,7 @@ See also `exwm-layout-enlarge-window'."
(interactive "p") (interactive "p")
(exwm-layout-enlarge-window (- delta) t)) (exwm-layout-enlarge-window (- delta) t))
;;;###autoload
(defun exwm-layout-hide-mode-line () (defun exwm-layout-hide-mode-line ()
"Hide mode-line." "Hide mode-line."
(interactive) (interactive)
@ -409,6 +418,7 @@ See also `exwm-layout-enlarge-window'."
mode-line-height) mode-line-height)
nil t))))) nil t)))))
;;;###autoload
(defun exwm-layout-show-mode-line () (defun exwm-layout-show-mode-line ()
"Show mode-line." "Show mode-line."
(interactive) (interactive)

View file

@ -27,7 +27,6 @@
;;; Code: ;;; Code:
(require 'exwm-core) (require 'exwm-core)
(eval-when-compile (require 'exwm-workspace))
(defvar exwm-manage-finish-hook nil (defvar exwm-manage-finish-hook nil
"Normal hook run after a window is just managed, in the context of the "Normal hook run after a window is just managed, in the context of the
@ -59,6 +58,20 @@ corresponding buffer.")
(when reply (when reply
(setq exwm--mwm-hints (append (slot-value reply 'value) nil))))))) (setq exwm--mwm-hints (append (slot-value reply 'value) nil)))))))
(defvar exwm-workspace--current)
(defvar exwm-workspace--switch-history-outdated)
(declare-function exwm--update-window-type "exwm.el" (id &optional force))
(declare-function exwm--update-class "exwm.el" (id &optional force))
(declare-function exwm--update-transient-for "exwm.el" (id &optional force))
(declare-function exwm--update-normal-hints "exwm.el" (id &optional force))
(declare-function exwm--update-title "exwm.el" (id))
(declare-function exwm--update-hints "exwm.el" (id &optional force))
(declare-function exwm--update-protocols "exwm.el" (id &optional force))
(declare-function exwm--update-state "exwm.el" (id &optional force))
(declare-function exwm-floating--set-floating "exwm-floating.el" (id))
(declare-function exwm-floating--unset-floating "exwm-floating.el" (id))
(defun exwm-manage--manage-window (id) (defun exwm-manage--manage-window (id)
"Manage window ID." "Manage window ID."
(exwm--log "Try to manage #x%x" id) (exwm--log "Try to manage #x%x" id)
@ -130,12 +143,9 @@ corresponding buffer.")
:value-mask (eval-when-compile :value-mask (eval-when-compile
(logior xcb:ConfigWindow:X (logior xcb:ConfigWindow:X
xcb:ConfigWindow:Y)) xcb:ConfigWindow:Y))
:x (/ (- (frame-pixel-width :x (/ (- (exwm-workspace--current-width) width)
exwm-workspace--current)
width)
2) 2)
:y (/ (- (frame-pixel-height :y (/ (- (exwm-workspace--current-height)
exwm-workspace--current)
height) height)
2))))) 2)))))
(xcb:flush exwm--connection) (xcb:flush exwm--connection)
@ -200,7 +210,6 @@ corresponding buffer.")
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
(run-hooks 'exwm-manage-finish-hook))))) (run-hooks 'exwm-manage-finish-hook)))))
;;;###autoload
(defun exwm-manage--unmanage-window (id &optional withdraw-only) (defun exwm-manage--unmanage-window (id &optional withdraw-only)
"Unmanage window ID." "Unmanage window ID."
(let ((buffer (exwm--id->buffer id))) (let ((buffer (exwm--id->buffer id)))
@ -284,7 +293,6 @@ corresponding buffer.")
"Non-nil indicates EXWM is pinging a window.") "Non-nil indicates EXWM is pinging a window.")
(defvar exwm-manage-ping-timeout 3 "Seconds to wait before killing a client.") (defvar exwm-manage-ping-timeout 3 "Seconds to wait before killing a client.")
;;;###autoload
(defun exwm-manage--kill-buffer-query-function () (defun exwm-manage--kill-buffer-query-function ()
"Run in `kill-buffer-query-functions'." "Run in `kill-buffer-query-functions'."
(catch 'return (catch 'return
@ -359,7 +367,6 @@ Would you like to kill it? "
(defun exwm-manage--kill-client (&optional id) (defun exwm-manage--kill-client (&optional id)
"Kill an X client." "Kill an X client."
(interactive)
(unless id (setq id (exwm--buffer->id (current-buffer)))) (unless id (setq id (exwm--buffer->id (current-buffer))))
(let* ((response (xcb:+request-unchecked+reply exwm--connection (let* ((response (xcb:+request-unchecked+reply exwm--connection
(make-instance 'xcb:ewmh:get-_NET_WM_PID :window id))) (make-instance 'xcb:ewmh:get-_NET_WM_PID :window id)))
@ -390,8 +397,8 @@ Would you like to kill it? "
(setq edges (setq edges
(if exwm--fullscreen (if exwm--fullscreen
(list 0 0 (list 0 0
(frame-pixel-width exwm-workspace--current) (exwm-workspace--current-width)
(frame-pixel-height exwm-workspace--current)) (exwm-workspace--current-height))
(window-inside-absolute-pixel-edges (window-inside-absolute-pixel-edges
(get-buffer-window buffer t)))) (get-buffer-window buffer t))))
(exwm--log "Reply with ConfigureNotify (edges): %s" edges) (exwm--log "Reply with ConfigureNotify (edges): %s" edges)

View file

@ -48,11 +48,19 @@
(require 'xcb-randr) (require 'xcb-randr)
(require 'exwm-core) (require 'exwm-core)
(require 'exwm-layout)
(eval-when-compile (require 'exwm-workspace))
(defvar exwm-randr-workspace-output-plist nil) (defvar exwm-randr-workspace-output-plist nil)
(defvar exwm-randr-refresh-hook nil
"Normal hook run when the RandR module just refreshed.")
(defvar exwm-workspace-minibuffer-position)
(defvar exwm-layout--fullscreen-frame-count)
(defvar exwm-workspace-number)
(defvar exwm-workspace--list)
(declare-function exwm-layout--set-frame-fullscreen "exwm-layout.el" (frame))
(defun exwm-randr--refresh () (defun exwm-randr--refresh ()
"Refresh workspaces according to the updated RandR info." "Refresh workspaces according to the updated RandR info."
(let (output-name geometry output-plist default-geometry workareas (let (output-name geometry output-plist default-geometry workareas
@ -89,6 +97,7 @@
(setq workarea-offset (if exwm-workspace-minibuffer-position (setq workarea-offset (if exwm-workspace-minibuffer-position
0 0
(window-pixel-height (minibuffer-window)))) (window-pixel-height (minibuffer-window))))
(setq exwm-layout--fullscreen-frame-count 0)
(dotimes (i exwm-workspace-number) (dotimes (i exwm-workspace-number)
(let* ((output (plist-get exwm-randr-workspace-output-plist i)) (let* ((output (plist-get exwm-randr-workspace-output-plist i))
(geometry (lax-plist-get output-plist output)) (geometry (lax-plist-get output-plist output))
@ -98,15 +107,8 @@
output nil)) output nil))
(set-frame-parameter frame 'exwm-randr-output output) (set-frame-parameter frame 'exwm-randr-output output)
(set-frame-parameter frame 'exwm-geometry geometry) (set-frame-parameter frame 'exwm-geometry geometry)
(exwm-layout--set-frame-fullscreen frame)
(with-slots (x y width height) geometry (with-slots (x y width height) geometry
(exwm-layout--resize-container (frame-parameter frame
'exwm-outer-id)
(frame-parameter frame
'exwm-workspace)
x y width height)
(when (and (eq frame exwm-workspace--current)
(exwm-workspace--minibuffer-own-frame-p))
(exwm-workspace--resize-minibuffer-frame width height))
(setq workareas (setq workareas
(nconc workareas (list x y width (- height (nconc workareas (list x y width (- height
workarea-offset))) workarea-offset)))
@ -120,7 +122,8 @@
(make-instance 'xcb:ewmh:set-_NET_DESKTOP_VIEWPORT (make-instance 'xcb:ewmh:set-_NET_DESKTOP_VIEWPORT
:window exwm--root :window exwm--root
:data (vconcat viewports))) :data (vconcat viewports)))
(xcb:flush exwm--connection)))) (xcb:flush exwm--connection)
(run-hooks 'exwm-randr-refresh-hook))))
(defvar exwm-randr-screen-change-hook nil (defvar exwm-randr-screen-change-hook nil
"Normal hook run when screen changes.") "Normal hook run when screen changes.")

View file

@ -33,7 +33,6 @@
(require 'xcb-xembed) (require 'xcb-xembed)
(require 'xcb-systemtray) (require 'xcb-systemtray)
(require 'exwm-core) (require 'exwm-core)
(require 'exwm-workspace)
(defclass exwm-systemtray--icon () (defclass exwm-systemtray--icon ()
((width :initarg :width) ((width :initarg :width)
@ -161,7 +160,7 @@ You shall use the default value if using auto-hide minibuffer.")
:window exwm-systemtray--embedder :window exwm-systemtray--embedder
:value-mask (logior xcb:ConfigWindow:X :value-mask (logior xcb:ConfigWindow:X
xcb:ConfigWindow:Width) xcb:ConfigWindow:Width)
:x (- (frame-pixel-width exwm-workspace--current) x) :x (- (exwm-workspace--current-width) x)
:width x)) :width x))
(when map (when map
(xcb:+request exwm-systemtray--connection (xcb:+request exwm-systemtray--connection
@ -173,7 +172,7 @@ You shall use the default value if using auto-hide minibuffer.")
(let ((obj (make-instance 'xcb:DestroyNotify))) (let ((obj (make-instance 'xcb:DestroyNotify)))
(xcb:unmarshal obj data) (xcb:unmarshal obj data)
(with-slots (window) obj (with-slots (window) obj
(when (alist-get window exwm-systemtray--list) (when (assoc window exwm-systemtray--list)
(exwm-systemtray--unembed window))))) (exwm-systemtray--unembed window)))))
(defun exwm-systemtray--on-ReparentNotify (data _synthetic) (defun exwm-systemtray--on-ReparentNotify (data _synthetic)
@ -182,7 +181,7 @@ You shall use the default value if using auto-hide minibuffer.")
(xcb:unmarshal obj data) (xcb:unmarshal obj data)
(with-slots (window parent) obj (with-slots (window parent) obj
(when (and (/= parent exwm-systemtray--embedder) (when (and (/= parent exwm-systemtray--embedder)
(alist-get window exwm-systemtray--list)) (assoc window exwm-systemtray--list))
(exwm-systemtray--unembed window))))) (exwm-systemtray--unembed window)))))
(defun exwm-systemtray--on-ResizeRequest (data _synthetic) (defun exwm-systemtray--on-ResizeRequest (data _synthetic)
@ -191,7 +190,7 @@ You shall use the default value if using auto-hide minibuffer.")
attr) attr)
(xcb:unmarshal obj data) (xcb:unmarshal obj data)
(with-slots (window width height) obj (with-slots (window width height) obj
(when (setq attr (alist-get window exwm-systemtray--list)) (when (setq attr (cdr (assoc window exwm-systemtray--list)))
(with-slots ((width* width) (with-slots ((width* width)
(height* height)) (height* height))
attr attr
@ -220,7 +219,7 @@ You shall use the default value if using auto-hide minibuffer.")
(with-slots (window atom state) obj (with-slots (window atom state) obj
(when (and (eq state xcb:Property:NewValue) (when (and (eq state xcb:Property:NewValue)
(eq atom xcb:Atom:_XEMBED_INFO) (eq atom xcb:Atom:_XEMBED_INFO)
(setq attr (alist-get window exwm-systemtray--list))) (setq attr (cdr (assoc window exwm-systemtray--list))))
(setq info (xcb:+request-unchecked+reply exwm-systemtray--connection (setq info (xcb:+request-unchecked+reply exwm-systemtray--connection
(make-instance 'xcb:xembed:get-_XEMBED_INFO (make-instance 'xcb:xembed:get-_XEMBED_INFO
:window window))) :window window)))
@ -256,8 +255,12 @@ You shall use the default value if using auto-hide minibuffer.")
(t (t
(exwm--log "(System Tray) Unknown opcode message: %s" obj))))))) (exwm--log "(System Tray) Unknown opcode message: %s" obj)))))))
(defun exwm-systemtray--on-exwm-workspace-switch () (defvar exwm-workspace-minibuffer-position)
"Reparent the system tray in `exwm-workspace-switch-hook'." (defvar exwm-workspace--current)
(defun exwm-systemtray--on-workspace-switch ()
"Reparent/Refresh the system tray in `exwm-workspace-switch-hook'."
(unless exwm-workspace-minibuffer-position
(xcb:+request exwm-systemtray--connection (xcb:+request exwm-systemtray--connection
(make-instance 'xcb:ReparentWindow (make-instance 'xcb:ReparentWindow
:window exwm-systemtray--embedder :window exwm-systemtray--embedder
@ -265,11 +268,23 @@ You shall use the default value if using auto-hide minibuffer.")
(frame-parameter exwm-workspace--current (frame-parameter exwm-workspace--current
'window-id)) 'window-id))
:x 0 :x 0
:y (- (frame-pixel-height exwm-workspace--current) :y (- (exwm-workspace--current-height)
exwm-systemtray-height))) exwm-systemtray-height))))
(exwm-systemtray--refresh))
(defun exwm-systemtray--on-randr-refresh ()
"Reposition/Refresh the system tray in `exwm-randr-refresh-hook'."
(unless exwm-workspace-minibuffer-position
(xcb:+request exwm-systemtray--connection
(make-instance 'xcb:ConfigureWindow
:window exwm-systemtray--embedder
:value-mask xcb:ConfigWindow:Y
:y (- (exwm-workspace--current-height)
exwm-systemtray-height))))
(exwm-systemtray--refresh)) (exwm-systemtray--refresh))
(defvar xcb:Atom:_NET_SYSTEM_TRAY_S0) (defvar xcb:Atom:_NET_SYSTEM_TRAY_S0)
(defvar exwm-workspace--minibuffer)
(defun exwm-systemtray--init () (defun exwm-systemtray--init ()
"Initialize system tray module." "Initialize system tray module."
@ -335,8 +350,7 @@ You shall use the default value if using auto-hide minibuffer.")
(setq parent (string-to-number (frame-parameter exwm-workspace--current (setq parent (string-to-number (frame-parameter exwm-workspace--current
'window-id)) 'window-id))
;; Bottom aligned. ;; Bottom aligned.
y (- (frame-pixel-height exwm-workspace--current) y (- (exwm-workspace--current-height) exwm-systemtray-height)))
exwm-systemtray-height)))
(xcb:+request exwm-systemtray--connection (xcb:+request exwm-systemtray--connection
(make-instance 'xcb:ReparentWindow (make-instance 'xcb:ReparentWindow
:window id :parent parent :x 0 :y y)) :window id :parent parent :x 0 :y y))
@ -356,10 +370,9 @@ You shall use the default value if using auto-hide minibuffer.")
#'exwm-systemtray--on-PropertyNotify) #'exwm-systemtray--on-PropertyNotify)
(xcb:+event exwm-systemtray--connection 'xcb:ClientMessage (xcb:+event exwm-systemtray--connection 'xcb:ClientMessage
#'exwm-systemtray--on-ClientMessage) #'exwm-systemtray--on-ClientMessage)
;; Add hook to reparent the embedder. ;; Add hook to move/reparent the embedder.
(unless exwm-workspace-minibuffer-position (add-hook 'exwm-workspace-switch-hook #'exwm-systemtray--on-workspace-switch)
(add-hook 'exwm-workspace-switch-hook (add-hook 'exwm-randr-refresh-hook #'exwm-systemtray--on-randr-refresh))
#'exwm-systemtray--on-exwm-workspace-switch)))
(defun exwm-systemtray-enable () (defun exwm-systemtray-enable ()
"Enable system tray support for EXWM." "Enable system tray support for EXWM."

View file

@ -62,7 +62,6 @@
(defvar exwm-workspace--switch-history-outdated nil (defvar exwm-workspace--switch-history-outdated nil
"Non-nil to indicate `exwm-workspace--switch-history' is outdated.") "Non-nil to indicate `exwm-workspace--switch-history' is outdated.")
;;;###autoload
(defun exwm-workspace--update-switch-history () (defun exwm-workspace--update-switch-history ()
"Update the history for switching workspace to reflect the latest status." "Update the history for switching workspace to reflect the latest status."
(when exwm-workspace--switch-history-outdated (when exwm-workspace--switch-history-outdated
@ -108,6 +107,22 @@ Value nil means to use the default position which is fixed at bottom, while
(defvar exwm-workspace--display-echo-area-timer nil (defvar exwm-workspace--display-echo-area-timer nil
"Timer for auto-hiding echo area.") "Timer for auto-hiding echo area.")
;;;###autoload
(defun exwm-workspace--current-width ()
"Return the width of current workspace."
(let ((geometry (frame-parameter exwm-workspace--current 'exwm-geometry)))
(if geometry
(slot-value geometry 'width)
(x-display-pixel-width))))
;;;###autoload
(defun exwm-workspace--current-height ()
"Return the height of current workspace."
(let ((geometry (frame-parameter exwm-workspace--current 'exwm-geometry)))
(if geometry
(slot-value geometry 'height)
(x-display-pixel-height))))
;;;###autoload ;;;###autoload
(defun exwm-workspace--minibuffer-own-frame-p () (defun exwm-workspace--minibuffer-own-frame-p ()
"Reports whether the minibuffer is displayed in its own frame." "Reports whether the minibuffer is displayed in its own frame."
@ -122,9 +137,9 @@ workspace frame."
(cl-assert (exwm-workspace--minibuffer-own-frame-p)) (cl-assert (exwm-workspace--minibuffer-own-frame-p))
(let ((y (if (eq exwm-workspace-minibuffer-position 'top) (let ((y (if (eq exwm-workspace-minibuffer-position 'top)
0 0
(- (or height (frame-pixel-height exwm-workspace--current)) (- (or height (exwm-workspace--current-height))
(frame-pixel-height exwm-workspace--minibuffer)))) (frame-pixel-height exwm-workspace--minibuffer))))
(width (or width (frame-pixel-width exwm-workspace--current))) (width (or width (exwm-workspace--current-width)))
(container (frame-parameter exwm-workspace--minibuffer (container (frame-parameter exwm-workspace--minibuffer
'exwm-container))) 'exwm-container)))
(xcb:+request exwm--connection (xcb:+request exwm--connection
@ -206,6 +221,8 @@ The optional FORCE option is for internal use only."
(xcb:flush exwm--connection)) (xcb:flush exwm--connection))
(run-hooks 'exwm-workspace-switch-hook)))) (run-hooks 'exwm-workspace-switch-hook))))
(declare-function exwm-layout--hide "exwm-layout.el" (id))
;;;###autoload ;;;###autoload
(defun exwm-workspace-move-window (index &optional id) (defun exwm-workspace-move-window (index &optional id)
"Move window ID to workspace INDEX." "Move window ID to workspace INDEX."
@ -266,6 +283,7 @@ The optional FORCE option is for internal use only."
(exwm--id->buffer id))))) (exwm--id->buffer id)))))
(setq exwm-workspace--switch-history-outdated t))) (setq exwm-workspace--switch-history-outdated t)))
;;;###autoload
(defun exwm-workspace-switch-to-buffer () (defun exwm-workspace-switch-to-buffer ()
"Make the current Emacs window display another buffer." "Make the current Emacs window display another buffer."
(interactive) (interactive)
@ -348,10 +366,10 @@ The optional FORCE option is for internal use only."
window) window)
(when (and (floatp max-mini-window-height) (when (and (floatp max-mini-window-height)
(> height (* max-mini-window-height (> height (* max-mini-window-height
(frame-pixel-height exwm-workspace--current)))) (exwm-workspace--current-height))))
(setq height (floor (setq height (floor
(* max-mini-window-height (* max-mini-window-height
(frame-pixel-height exwm-workspace--current)))) (exwm-workspace--current-height))))
(xcb:+request exwm--connection (xcb:+request exwm--connection
(make-instance 'xcb:ConfigureWindow (make-instance 'xcb:ConfigureWindow
:window window :window window
@ -361,7 +379,7 @@ The optional FORCE option is for internal use only."
(setq value-mask xcb:ConfigWindow:Height (setq value-mask xcb:ConfigWindow:Height
y 0) y 0)
(setq value-mask (logior xcb:ConfigWindow:Y xcb:ConfigWindow:Height) (setq value-mask (logior xcb:ConfigWindow:Y xcb:ConfigWindow:Height)
y (- (frame-pixel-height exwm-workspace--current) height))) y (- (exwm-workspace--current-height) height)))
(xcb:+request exwm--connection (xcb:+request exwm--connection
(make-instance 'xcb:ConfigureWindow (make-instance 'xcb:ConfigureWindow
:window (frame-parameter exwm-workspace--minibuffer :window (frame-parameter exwm-workspace--minibuffer
@ -457,6 +475,8 @@ This functions is modified from `display-buffer-reuse-window' and
(cancel-timer exwm-workspace--display-echo-area-timer) (cancel-timer exwm-workspace--display-echo-area-timer)
(setq exwm-workspace--display-echo-area-timer nil))) (setq exwm-workspace--display-echo-area-timer nil)))
(declare-function exwm-manage--unmanage-window "exwm-manage.el")
(defun exwm-workspace--confirm-kill-emacs (prompt) (defun exwm-workspace--confirm-kill-emacs (prompt)
"Confirm before exiting Emacs." "Confirm before exiting Emacs."
(when (pcase (length exwm--id-buffer-alist) (when (pcase (length exwm--id-buffer-alist)
@ -611,13 +631,17 @@ This functions is modified from `display-buffer-reuse-window' and
;; Switch to the first workspace ;; Switch to the first workspace
(exwm-workspace-switch 0 t)) (exwm-workspace-switch 0 t))
(defvar exwm-layout--fullscreen-frame-count)
(defun exwm-workspace--post-init () (defun exwm-workspace--post-init ()
"The second stage in the initialization of the workspace module." "The second stage in the initialization of the workspace module."
;; Delay making the workspaces fullscreen until Emacs becomes idle ;; Make the workspaces fullscreen.
(run-with-idle-timer 0 nil
(lambda ()
(dolist (i exwm-workspace--list) (dolist (i exwm-workspace--list)
(set-frame-parameter i 'fullscreen 'fullboth))))) (set-frame-parameter i 'fullscreen 'fullboth))
;; Wait until all workspace frames are resized.
(with-timeout (1)
(while (< exwm-layout--fullscreen-frame-count exwm-workspace-number)
(accept-process-output nil 0.1))))

16
exwm.el
View file

@ -30,11 +30,12 @@
;; -------- ;; --------
;; EXWM (Emacs X Window Manager) is a full-featured tiling X window manager for ;; EXWM (Emacs X Window Manager) is a full-featured tiling X window manager for
;; Emacs built on top of XELB. It features: ;; Emacs built on top of XELB. It features:
;; + Fully keyboard-driven operation ;; + Fully keyboard-driven operations
;; + Hybrid layout modes (tiling & stacking) ;; + Hybrid layout modes (tiling & stacking)
;; + Workspace support ;; + Workspace support
;; + ICCCM/EWMH compliance ;; + ICCCM/EWMH compliance
;; + Basic RandR support (optional) ;; ++ (Optional) RandR (multi-monitor) support
;; ++ (Optional) system tray
;; Installation & configuration ;; Installation & configuration
;; ---------------------------- ;; ----------------------------
@ -70,6 +71,7 @@
(require 'exwm-manage) (require 'exwm-manage)
(require 'exwm-input) (require 'exwm-input)
;;;###autoload
(defun exwm-reset () (defun exwm-reset ()
"Reset window to standard state: non-fullscreen, line-mode." "Reset window to standard state: non-fullscreen, line-mode."
(interactive) (interactive)
@ -80,7 +82,6 @@
(exwm-layout--refresh) (exwm-layout--refresh)
(exwm-input-grab-keyboard)))) (exwm-input-grab-keyboard))))
;;;###autoload
(defun exwm--update-window-type (id &optional force) (defun exwm--update-window-type (id &optional force)
"Update _NET_WM_WINDOW_TYPE." "Update _NET_WM_WINDOW_TYPE."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
@ -94,7 +95,6 @@
(defvar exwm-update-class-hook nil (defvar exwm-update-class-hook nil
"Normal hook run when window class is updated.") "Normal hook run when window class is updated.")
;;;###autoload
(defun exwm--update-class (id &optional force) (defun exwm--update-class (id &optional force)
"Update WM_CLASS." "Update WM_CLASS."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
@ -110,7 +110,6 @@
(defvar exwm-update-title-hook nil (defvar exwm-update-title-hook nil
"Normal hook run when window title is updated.") "Normal hook run when window title is updated.")
;;;###autoload
(defun exwm--update-utf8-title (id &optional force) (defun exwm--update-utf8-title (id &optional force)
"Update _NET_WM_NAME." "Update _NET_WM_NAME."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
@ -123,7 +122,6 @@
(setq exwm--title-is-utf8 t) (setq exwm--title-is-utf8 t)
(run-hooks 'exwm-update-title-hook))))))) (run-hooks 'exwm-update-title-hook)))))))
;;;###autoload
(defun exwm--update-ctext-title (id &optional force) (defun exwm--update-ctext-title (id &optional force)
"Update WM_NAME." "Update WM_NAME."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
@ -136,13 +134,11 @@
(when exwm-title (when exwm-title
(run-hooks 'exwm-update-title-hook))))))) (run-hooks 'exwm-update-title-hook)))))))
;;;###autoload
(defun exwm--update-title (id) (defun exwm--update-title (id)
"Update _NET_WM_NAME or WM_NAME." "Update _NET_WM_NAME or WM_NAME."
(exwm--update-utf8-title id) (exwm--update-utf8-title id)
(exwm--update-ctext-title id)) (exwm--update-ctext-title id))
;;;###autoload
(defun exwm--update-transient-for (id &optional force) (defun exwm--update-transient-for (id &optional force)
"Update WM_TRANSIENT_FOR." "Update WM_TRANSIENT_FOR."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
@ -153,7 +149,6 @@
(when reply ;nil when destroyed (when reply ;nil when destroyed
(setq exwm-transient-for (slot-value reply 'value))))))) (setq exwm-transient-for (slot-value reply 'value)))))))
;;;###autoload
(defun exwm--update-normal-hints (id &optional force) (defun exwm--update-normal-hints (id &optional force)
"Update WM_NORMAL_HINTS." "Update WM_NORMAL_HINTS."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
@ -201,7 +196,6 @@
(= exwm--normal-hints-min-height (= exwm--normal-hints-min-height
exwm--normal-hints-max-height))))))))) exwm--normal-hints-max-height)))))))))
;;;###autoload
(defun exwm--update-hints (id &optional force) (defun exwm--update-hints (id &optional force)
"Update WM_HINTS." "Update WM_HINTS."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
@ -221,7 +215,6 @@
(set-frame-parameter exwm--frame 'exwm--urgency t) (set-frame-parameter exwm--frame 'exwm--urgency t)
(setq exwm-workspace--switch-history-outdated t)))))))) (setq exwm-workspace--switch-history-outdated t))))))))
;;;###autoload
(defun exwm--update-protocols (id &optional force) (defun exwm--update-protocols (id &optional force)
"Update WM_PROTOCOLS." "Update WM_PROTOCOLS."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
@ -232,7 +225,6 @@
(when reply ;nil when destroyed (when reply ;nil when destroyed
(setq exwm--protocols (append (slot-value reply 'value) nil))))))) (setq exwm--protocols (append (slot-value reply 'value) nil)))))))
;;;###autoload
(defun exwm--update-state (id &optional force) (defun exwm--update-state (id &optional force)
"Update WM_STATE." "Update WM_STATE."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)