Skip to content

Commit

Permalink
Merge branch 'drop-client-p' into externals/exwm
Browse files Browse the repository at this point in the history
  • Loading branch information
medranocalvo committed Nov 22, 2022
2 parents 6408a74 + d6f62ff commit 1c706da
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 150 deletions.
8 changes: 8 additions & 0 deletions exwm-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Here are some predefined candidates:

(defvar exwm--connection nil "X connection.")

(defvar exwm--terminal nil
"Terminal corresponding to `exwm--connection'.")

(defvar exwm--wmsn-window nil
"An X window owning the WM_S0 selection.")

Expand Down Expand Up @@ -177,6 +180,11 @@ least SECS seconds later."
,function
,@args))

(defsubst exwm--terminal-p (&optional frame)
"Return t when FRAME's terminal is EXWM's terminal.
If FRAME is null, use selected frame."
(eq exwm--terminal (frame-terminal frame)))

(defun exwm--get-client-event-mask ()
"Return event mask set on all managed windows."
(logior xcb:EventMask:StructureNotify
Expand Down
46 changes: 24 additions & 22 deletions exwm-input.el
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ Current buffer will be the `exwm-mode' buffer when this hook runs.")
(declare-function exwm-layout--iconic-state-p "exwm-layout.el" (&optional id))
(declare-function exwm-layout--show "exwm-layout.el" (id &optional window))
(declare-function exwm-reset "exwm.el" ())
(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"
Expand Down Expand Up @@ -296,8 +294,9 @@ ARGS are additional arguments to CALLBACK."

(defun exwm-input--on-buffer-list-update ()
"Run in `buffer-list-update-hook' to track input focus."
(when (and (not (exwm-workspace--client-p))
(not exwm-input--skip-buffer-list-update))
(when (and ; this hook is called incesantly; place cheap tests on top
(not exwm-input--skip-buffer-list-update)
(exwm--terminal-p)) ; skip other terminals, e.g. TTY client frames
(exwm--log "current-buffer=%S selected-window=%S"
(current-buffer) (selected-window))
(redirect-frame-focus (selected-frame) nil)
Expand Down Expand Up @@ -1100,30 +1099,33 @@ One use is to access the keymap bound to KEYS (as prefix keys) in char-mode."

(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)
(not (exwm-workspace--client-p))
(eq exwm--selected-input-mode 'char-mode))
(exwm-input--grab-keyboard exwm--id))))
(let* ((window (or (minibuffer-selected-window) ; minibuffer-setup-hook
(selected-window))) ; echo-area-clear-hook
(frame (window-frame window)))
(when (exwm--terminal-p frame)
(with-current-buffer (window-buffer window)
(when (and (derived-mode-p 'exwm-mode)
(eq exwm--selected-input-mode 'char-mode))
(exwm--log "Grab #x%x window=%s frame=%s" exwm--id window frame)
(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)
(not (exwm-workspace--client-p))
(eq exwm--selected-input-mode 'char-mode)
(eq exwm--input-mode 'line-mode))
(exwm-input--release-keyboard exwm--id))))
(let* ((window (or (minibuffer-selected-window) ; minibuffer-setup-hook
(selected-window))) ; echo-area-clear-hook
(frame (window-frame window)))
(when (exwm--terminal-p frame)
(with-current-buffer (window-buffer window)
(when (and (derived-mode-p 'exwm-mode)
(eq exwm--selected-input-mode 'char-mode)
(eq exwm--input-mode 'line-mode))
(exwm--log "Release #x%x window=%s frame=%s" exwm--id window frame)
(exwm-input--release-keyboard exwm--id))))))

(defun exwm-input--on-echo-area-dirty ()
"Run when new message arrives to grab keyboard if necessary."
(when (and (not (active-minibuffer-window))
(not (exwm-workspace--client-p))
cursor-in-echo-area)
(when (and cursor-in-echo-area
(not (active-minibuffer-window)))
(exwm--log)
(exwm-input--on-minibuffer-setup)))

Expand Down
27 changes: 15 additions & 12 deletions exwm-layout.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
(declare-function exwm-input--grab-keyboard "exwm-input.el")
(declare-function exwm-input-grab-keyboard "exwm-input.el")
(declare-function exwm-workspace--active-p "exwm-workspace.el" (frame))
(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))
Expand Down Expand Up @@ -405,22 +403,27 @@ selected by `other-buffer'."
(defun exwm-layout--on-minibuffer-setup ()
"Refresh layout when minibuffer grows."
(exwm--log)
(unless (exwm-workspace--client-p)
;; Only when the minibuffer's frame is an EXWM frame.
;; FIXME: would it be enough checking for workspace frames?
(when (exwm--terminal-p)
(exwm--defer 0 (lambda ()
(when (< 1 (window-height (minibuffer-window)))
(exwm-layout--refresh))))))

(defun exwm-layout--on-echo-area-change (&optional dirty)
"Run when message arrives or in `echo-area-clear-hook' to refresh layout."
(when (and (current-message)
(not (exwm-workspace--client-p))
(or (cl-position ?\n (current-message))
(> (length (current-message))
(frame-width exwm-workspace--current))))
(exwm--log)
(if dirty
(exwm-layout--refresh)
(exwm--defer 0 #'exwm-layout--refresh))))
(let ((frame (window-frame (minibuffer-window)))
(msg (current-message)))
;; Check whether the frame where current window's minibuffer resides (not
;; current window's frame for floating windows!) must be adjusted.
(when (and msg
(exwm--terminal-p frame)
(or (cl-position ?\n msg)
(> (length msg) (frame-width frame))))
(exwm--log)
(if dirty
(exwm-layout--refresh exwm-workspace--current)
(exwm--defer 0 #'exwm-layout--refresh exwm-workspace--current)))))

;;;###autoload
(defun exwm-layout-enlarge-window (delta &optional horizontal)
Expand Down
Loading

0 comments on commit 1c706da

Please sign in to comment.