Add various per-application configurations

* exwm-manage.el (exwm-manage-configurations): Add options for
fullscreen mode and floating & tiling mode-line formats.
(exwm-manage--manage-window): Add support for configuring
line-mode/char-mode, prefix keys, simulation keys and fullscreen mode.
* exwm-floating.el (exwm-floating--set-floating): Add support for
configuring the geometry, mode-line format and border width of a
floating X window.
(exwm-floating--unset-floating): Add support for configuring the
mode-line format of a tiling X window.
This commit is contained in:
Chris Feng 2018-03-03 01:00:28 +08:00
parent 0d1a323124
commit e141ee6847
2 changed files with 78 additions and 14 deletions

View file

@ -176,7 +176,32 @@ This is also used by X window containers.")
(when (= 0 height) (setq height (/ height* 2))) (when (= 0 height) (setq height (/ height* 2)))
;; Make sure at least half of the window is visible ;; Make sure at least half of the window is visible
(unless (< y* (+ y (/ height 2)) (+ y* height*)) (unless (< y* (+ y (/ height 2)) (+ y* height*))
(setq y (+ y* (/ (- height* height) 2)))))) (setq y (+ y* (/ (- height* height) 2)))))
;; The geometry can be overridden by user options.
(let ((x** (plist-get exwm--configurations 'x))
(y** (plist-get exwm--configurations 'y))
(width** (plist-get exwm--configurations 'width))
(height** (plist-get exwm--configurations 'height)))
(if (integerp x**)
(setq x (+ x* x**))
(when (and (floatp x**)
(>= 1 x** 0))
(setq x (+ x* (round (* x** width*))))))
(if (integerp y**)
(setq y (+ y* y**))
(when (and (floatp y**)
(>= 1 y** 0))
(setq y (+ y* (round (* y** height*))))))
(if (integerp width**)
(setq width width**)
(when (and (floatp width**)
(> 1 width** 0))
(setq width (max 1 (round (* width** width*))))))
(if (integerp height**)
(setq height height**)
(when (and (floatp height**)
(> 1 height** 0))
(setq height (max 1 (round (* height** height*))))))))
(exwm--set-geometry id x y nil nil) (exwm--set-geometry id x y nil nil)
(xcb:flush exwm--connection) (xcb:flush exwm--connection)
(exwm--log "Floating geometry (corrected): %dx%d%+d%+d" width height x y) (exwm--log "Floating geometry (corrected): %dx%d%+d%+d" width height x y)
@ -189,13 +214,23 @@ This is also used by X window containers.")
(frame-width (+ width (- (frame-pixel-width frame) (frame-width (+ width (- (frame-pixel-width frame)
(- (elt edges 2) (elt edges 0))))) (- (elt edges 2) (elt edges 0)))))
(frame-height (+ height (- (frame-pixel-height frame) (frame-height (+ height (- (frame-pixel-height frame)
(- (elt edges 3) (elt edges 1)))))) (- (elt edges 3) (elt edges 1)))))
;; Check `exwm--mwm-hints-decorations'. (floating-mode-line (plist-get exwm--configurations
(unless exwm--mwm-hints-decorations 'floating-mode-line)))
(setq frame-height (- frame-height (window-mode-line-height (if floating-mode-line
(frame-root-window frame))) (setq exwm--mode-line-format (or exwm--mode-line-format
exwm--mode-line-format mode-line-format mode-line-format)
mode-line-format nil)) mode-line-format floating-mode-line)
(if (and (not (plist-member exwm--configurations 'floating-mode-line))
exwm--mwm-hints-decorations)
(when exwm--mode-line-format
(setq mode-line-format exwm--mode-line-format))
;; The mode-line need to be hidden in floating mode.
(setq frame-height (- frame-height (window-mode-line-height
(frame-root-window frame)))
exwm--mode-line-format (or exwm--mode-line-format
mode-line-format)
mode-line-format nil)))
(set-frame-size frame frame-width frame-height t) (set-frame-size frame frame-width frame-height t)
;; Create the frame container as the parent of the frame. ;; Create the frame container as the parent of the frame.
(xcb:+request exwm--connection (xcb:+request exwm--connection
@ -207,7 +242,14 @@ This is also used by X window containers.")
:y (- y (elt edges 1)) :y (- y (elt edges 1))
:width width :width width
:height height :height height
:border-width exwm-floating-border-width :border-width
(with-current-buffer (exwm--id->buffer id)
(let ((border-witdh (plist-get exwm--configurations
'border-width)))
(if (and (integerp border-witdh)
(>= border-witdh 0))
border-witdh
exwm-floating-border-width)))
:class xcb:WindowClass:InputOutput :class xcb:WindowClass:InputOutput
:visual 0 :visual 0
:value-mask (logior xcb:CW:BackPixmap :value-mask (logior xcb:CW:BackPixmap
@ -326,7 +368,14 @@ This is also used by X window containers.")
(delete-frame exwm--floating-frame)))) (delete-frame exwm--floating-frame))))
(with-current-buffer buffer (with-current-buffer buffer
(setq window-size-fixed nil (setq window-size-fixed nil
exwm--floating-frame nil)) exwm--floating-frame nil)
(if (not (plist-member exwm--configurations 'tiling-mode-line))
(when exwm--mode-line-format
(setq mode-line-format exwm--mode-line-format))
(setq exwm--mode-line-format (or exwm--mode-line-format
mode-line-format)
mode-line-format (plist-get exwm--configurations
'tiling-mode-line))))
;; Only show X windows in normal state. ;; Only show X windows in normal state.
(unless (exwm-layout--iconic-state-p) (unless (exwm-layout--iconic-state-p)
(pop-to-buffer-same-window buffer))) (pop-to-buffer-same-window buffer)))

View file

@ -60,6 +60,9 @@ You can still make the X windows floating afterwards."
(const :tag "Width" width) (const :tag "Width" width)
(const :tag "Height" height) (const :tag "Height" height)
(const :tag "Border width" border-width) (const :tag "Border width" border-width)
(const :tag "Fullscreen" fullscreen)
(const :tag "Floating mode-line" floating-mode-line)
(const :tag "Tiling mode-line" tiling-mode-line)
(const :tag "Char-mode" char-mode) (const :tag "Char-mode" char-mode)
(const :tag "Prefix keys" prefix-keys) (const :tag "Prefix keys" prefix-keys)
(const :tag "Simulation keys" simulation-keys) (const :tag "Simulation keys" simulation-keys)
@ -83,6 +86,7 @@ You can still make the X windows floating afterwards."
(defvar exwm-manage--ping-lock nil (defvar exwm-manage--ping-lock nil
"Non-nil indicates EXWM is pinging a window.") "Non-nil indicates EXWM is pinging a window.")
(defvar exwm-input-prefix-keys)
(defvar exwm-workspace--current) (defvar exwm-workspace--current)
(defvar exwm-workspace--id-struts-alist) (defvar exwm-workspace--id-struts-alist)
(defvar exwm-workspace--list) (defvar exwm-workspace--list)
@ -101,6 +105,7 @@ You can still make the X windows floating afterwards."
(declare-function exwm-floating--set-floating "exwm-floating.el" (id)) (declare-function exwm-floating--set-floating "exwm-floating.el" (id))
(declare-function exwm-floating--unset-floating "exwm-floating.el" (id)) (declare-function exwm-floating--unset-floating "exwm-floating.el" (id))
(declare-function exwm-input-grab-keyboard "exwm-input.el") (declare-function exwm-input-grab-keyboard "exwm-input.el")
(declare-function exwm-input-set-local-simulation-keys "exwm-input.el")
(declare-function exwm-layout--iconic-state-p "exwm-layout.el" (&optional id)) (declare-function exwm-layout--iconic-state-p "exwm-layout.el" (&optional id))
(declare-function exwm-workspace--count "exwm-workspace.el" ()) (declare-function exwm-workspace--count "exwm-workspace.el" ())
(declare-function exwm-workspace--position "exwm-workspace.el" (frame)) (declare-function exwm-workspace--position "exwm-workspace.el" (frame))
@ -295,14 +300,24 @@ You can still make the X windows floating afterwards."
exwm-window-type))) exwm-window-type)))
(exwm-floating--set-floating id) (exwm-floating--set-floating id)
(exwm-floating--unset-floating id))) (exwm-floating--unset-floating id)))
(exwm-input-grab-keyboard id) (if (plist-get exwm--configurations 'char-mode)
(exwm-input-release-keyboard id)
(exwm-input-grab-keyboard id))
(let ((simulation-keys (plist-get exwm--configurations 'simulation-keys))
(prefix-keys (plist-get exwm--configurations 'prefix-keys)))
(with-current-buffer (exwm--id->buffer id)
(when simulation-keys
(exwm-input-set-local-simulation-keys simulation-keys))
(when prefix-keys
(setq-local exwm-input-prefix-keys prefix-keys))))
(setq exwm-workspace--switch-history-outdated t) (setq exwm-workspace--switch-history-outdated t)
(exwm--update-desktop id) (exwm--update-desktop id)
(exwm-manage--update-ewmh-state id) (exwm-manage--update-ewmh-state id)
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
(when (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state) (when (or (plist-get exwm--configurations 'fullscreen)
(setq exwm--ewmh-state (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state))
(delq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state)) (setq exwm--ewmh-state (delq xcb:Atom:_NET_WM_STATE_FULLSCREEN
exwm--ewmh-state))
(exwm-layout-set-fullscreen id)) (exwm-layout-set-fullscreen id))
(run-hooks 'exwm-manage-finish-hook))))) (run-hooks 'exwm-manage-finish-hook)))))