Fix emacsclient issues

* exwm-workspace.el (exwm-workspace--client-p): New function for testing
emacsclient frames.
(exwm-workspace--update-minibuffer-height)
(exwm-workspace--on-minibuffer-setup)
(exwm-workspace--on-minibuffer-exit, exwm-workspace--on-echo-area-dirty)
(exwm-workspace--on-echo-area-clear):
* exwm-input.el (exwm-input--on-buffer-list-update)
(exwm-input--on-minibuffer-setup):
* exwm-layout.el (exwm-layout--on-minibuffer-setup)
(exwm-layout--on-echo-area-change):
Use it.

* exwm-workspace.el (exwm-workspace--add-frame-as-workspace): Always
clear the 'client' frame parameter.
(exwm-workspace--init): Fix a typo.
This commit is contained in:
Chris Feng 2016-08-01 19:53:04 +08:00
parent e7ff9a9f90
commit f04b041cae
3 changed files with 42 additions and 32 deletions

View file

@ -79,6 +79,9 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.")
(exwm-input--set-active-window id) (exwm-input--set-active-window id)
(xcb:flush exwm--connection)))) (xcb:flush exwm--connection))))
(declare-function exwm-workspace--client-p "exwm-workspace.el"
(&optional frame))
(defvar exwm-input--update-focus-window nil "The (Emacs) window to be focused. (defvar exwm-input--update-focus-window nil "The (Emacs) window to be focused.
This value should always be overwritten.") This value should always be overwritten.")
@ -87,7 +90,7 @@ This value should always be overwritten.")
"Run in `buffer-list-update-hook' to track input focus." "Run in `buffer-list-update-hook' to track input focus."
(when (and (not (minibufferp)) ;Do not set input focus on minibuffer window. (when (and (not (minibufferp)) ;Do not set input focus on minibuffer window.
(eq (current-buffer) (window-buffer)) ;e.g. `with-temp-buffer'. (eq (current-buffer) (window-buffer)) ;e.g. `with-temp-buffer'.
(frame-parameter nil 'exwm-outer-id)) ;e.g. emacsclient frame. (not (exwm-workspace--client-p)))
(setq exwm-input--update-focus-window (selected-window)) (setq exwm-input--update-focus-window (selected-window))
(exwm-input--update-focus-defer))) (exwm-input--update-focus-defer)))
@ -183,8 +186,9 @@ This value should always be overwritten.")
(defun exwm-input--on-minibuffer-setup () (defun exwm-input--on-minibuffer-setup ()
"Run in `minibuffer-setup-hook' to set input focus." "Run in `minibuffer-setup-hook' to set input focus."
;; Set input focus on the Emacs frame (unless (exwm-workspace--client-p)
(x-focus-frame (window-frame (minibuffer-selected-window)))) ;; Set input focus on the Emacs frame
(x-focus-frame (window-frame (minibuffer-selected-window)))))
(defun exwm-input--set-active-window (&optional id) (defun exwm-input--set-active-window (&optional id)
"Set _NET_ACTIVE_WINDOW." "Set _NET_ACTIVE_WINDOW."

View file

@ -375,9 +375,12 @@ selected by `other-buffer'."
(exwm-layout--set-client-list-stacking) (exwm-layout--set-client-list-stacking)
(xcb:flush exwm--connection)))) (xcb:flush exwm--connection))))
(declare-function exwm-workspace--client-p "exwm-workspace.el"
(&optional frame))
(defun exwm-layout--on-minibuffer-setup () (defun exwm-layout--on-minibuffer-setup ()
"Refresh layout when minibuffer grows." "Refresh layout when minibuffer grows."
(when (frame-parameter nil 'exwm-outer-id) (unless (exwm-workspace--client-p)
(run-with-idle-timer 0.01 nil ;FIXME (run-with-idle-timer 0.01 nil ;FIXME
(lambda () (lambda ()
(when (< 1 (window-height (minibuffer-window))) (when (< 1 (window-height (minibuffer-window)))
@ -386,8 +389,7 @@ selected by `other-buffer'."
(defun exwm-layout--on-echo-area-change (&optional dirty) (defun exwm-layout--on-echo-area-change (&optional dirty)
"Run when message arrives or in `echo-area-clear-hook' to refresh layout." "Run when message arrives or in `echo-area-clear-hook' to refresh layout."
(when (and (current-message) (when (and (current-message)
;; Exclude non-graphical frames. (not (exwm-workspace--client-p))
(frame-parameter nil 'exwm-outer-id)
(or (cl-position ?\n (current-message)) (or (cl-position ?\n (current-message))
(> (length (current-message)) (> (length (current-message))
(frame-width exwm-workspace--current)))) (frame-width exwm-workspace--current))))

View file

@ -48,6 +48,10 @@ NIL if FRAME is not a workspace"
"Return t if FRAME is a workspace." "Return t if FRAME is a workspace."
(memq frame exwm-workspace--list)) (memq frame exwm-workspace--list))
(defsubst exwm-workspace--client-p (&optional frame)
"Return non-nil if FRAME is an emacsclient frame."
(frame-parameter frame 'client))
(defun exwm-workspace--workspace-from-frame-or-index (frame-or-index) (defun exwm-workspace--workspace-from-frame-or-index (frame-or-index)
"Retrieve the workspace frame from FRAME-OR-INDEX." "Retrieve the workspace frame from FRAME-OR-INDEX."
(cond (cond
@ -882,24 +886,25 @@ Please check `exwm-workspace--minibuffer-own-frame-p' first."
(defun exwm-workspace--update-minibuffer-height (&optional echo-area) (defun exwm-workspace--update-minibuffer-height (&optional echo-area)
"Update the minibuffer frame height." "Update the minibuffer frame height."
(let ((height (unless (exwm-workspace--client-p)
(with-current-buffer (let ((height
(window-buffer (minibuffer-window exwm-workspace--minibuffer)) (with-current-buffer
(max 1 (window-buffer (minibuffer-window exwm-workspace--minibuffer))
(if echo-area (max 1
(let ((width (frame-width exwm-workspace--minibuffer)) (if echo-area
(result 0)) (let ((width (frame-width exwm-workspace--minibuffer))
(mapc (lambda (i) (result 0))
(setq result (mapc (lambda (i)
(+ result (setq result
(ceiling (1+ (length i)) width)))) (+ result
(split-string (or (current-message) "") "\n")) (ceiling (1+ (length i)) width))))
result) (split-string (or (current-message) "") "\n"))
(count-screen-lines)))))) result)
(when (and (integerp max-mini-window-height) (count-screen-lines))))))
(> height max-mini-window-height)) (when (and (integerp max-mini-window-height)
(setq height max-mini-window-height)) (> height max-mini-window-height))
(set-frame-height exwm-workspace--minibuffer height))) (setq height max-mini-window-height))
(set-frame-height exwm-workspace--minibuffer height))))
(defun exwm-workspace--on-ConfigureNotify (data _synthetic) (defun exwm-workspace--on-ConfigureNotify (data _synthetic)
"Adjust the container to fit the minibuffer frame." "Adjust the container to fit the minibuffer frame."
@ -986,8 +991,7 @@ Please check `exwm-workspace--minibuffer-own-frame-p' first."
(defun exwm-workspace--on-minibuffer-setup () (defun exwm-workspace--on-minibuffer-setup ()
"Run in minibuffer-setup-hook to show the minibuffer and its container." "Run in minibuffer-setup-hook to show the minibuffer and its container."
(when (and (= 1 (minibuffer-depth)) (when (and (= 1 (minibuffer-depth))
;; Exclude non-graphical frames. (not (exwm-workspace--client-p)))
(frame-parameter nil 'exwm-outer-id))
(add-hook 'post-command-hook #'exwm-workspace--update-minibuffer-height) (add-hook 'post-command-hook #'exwm-workspace--update-minibuffer-height)
(exwm-workspace--show-minibuffer)) (exwm-workspace--show-minibuffer))
;; FIXME: This is a temporary fix for the *Completions* buffer not ;; FIXME: This is a temporary fix for the *Completions* buffer not
@ -1008,8 +1012,7 @@ Please check `exwm-workspace--minibuffer-own-frame-p' first."
(defun exwm-workspace--on-minibuffer-exit () (defun exwm-workspace--on-minibuffer-exit ()
"Run in minibuffer-exit-hook to hide the minibuffer container." "Run in minibuffer-exit-hook to hide the minibuffer container."
(when (and (= 1 (minibuffer-depth)) (when (and (= 1 (minibuffer-depth))
;; Exclude non-graphical frames. (not (exwm-workspace--client-p)))
(frame-parameter nil 'exwm-outer-id))
(remove-hook 'post-command-hook #'exwm-workspace--update-minibuffer-height) (remove-hook 'post-command-hook #'exwm-workspace--update-minibuffer-height)
(exwm-workspace--hide-minibuffer))) (exwm-workspace--hide-minibuffer)))
@ -1018,8 +1021,7 @@ Please check `exwm-workspace--minibuffer-own-frame-p' first."
(defun exwm-workspace--on-echo-area-dirty () (defun exwm-workspace--on-echo-area-dirty ()
"Run when new message arrives to show the echo area and its container." "Run when new message arrives to show the echo area and its container."
(when (and (not (active-minibuffer-window)) (when (and (not (active-minibuffer-window))
;; Exclude non-graphical frames. (not (exwm-workspace--client-p))
(frame-parameter nil 'exwm-outer-id)
(or (current-message) (or (current-message)
cursor-in-echo-area)) cursor-in-echo-area))
(exwm-workspace--update-minibuffer-height t) (exwm-workspace--update-minibuffer-height t)
@ -1033,7 +1035,7 @@ Please check `exwm-workspace--minibuffer-own-frame-p' first."
(defun exwm-workspace--on-echo-area-clear () (defun exwm-workspace--on-echo-area-clear ()
"Run in echo-area-clear-hook to hide echo area container." "Run in echo-area-clear-hook to hide echo area container."
(when (frame-parameter nil 'exwm-outer-id) ;Exclude non-graphical frames. (unless (exwm-workspace--client-p)
(unless (active-minibuffer-window) (unless (active-minibuffer-window)
(exwm-workspace--hide-minibuffer)) (exwm-workspace--hide-minibuffer))
(when exwm-workspace--display-echo-area-timer (when exwm-workspace--display-echo-area-timer
@ -1153,6 +1155,8 @@ Please check `exwm-workspace--minibuffer-own-frame-p' first."
(set-frame-parameter frame 'exwm-outer-id outer-id) (set-frame-parameter frame 'exwm-outer-id outer-id)
(set-frame-parameter frame 'exwm-container container) (set-frame-parameter frame 'exwm-container container)
(set-frame-parameter frame 'exwm-workspace workspace) (set-frame-parameter frame 'exwm-workspace workspace)
;; In case it's created by emacsclient.
(set-frame-parameter frame 'client nil)
;; Copy RandR frame parameters from the first workspace to ;; Copy RandR frame parameters from the first workspace to
;; prevent potential problems. The values do not matter here as ;; prevent potential problems. The values do not matter here as
;; they'll be updated by the RandR module later. ;; they'll be updated by the RandR module later.
@ -1324,7 +1328,7 @@ applied to all subsequently created X frames."
(unless (frame-parameter i 'window-id) (unless (frame-parameter i 'window-id)
(setq initial-workspaces (delq i initial-workspaces)))) (setq initial-workspaces (delq i initial-workspaces))))
(setq exwm-workspace--client (setq exwm-workspace--client
(frame-parameter (car exwm-workspace--list) 'client)) (frame-parameter (car initial-workspaces) 'client))
(let ((f (car initial-workspaces))) (let ((f (car initial-workspaces)))
;; Remove the possible internal border. ;; Remove the possible internal border.
(set-frame-parameter f 'internal-border-width 0) (set-frame-parameter f 'internal-border-width 0)