Allow showing buffers on other workspaces and moving an X window by switching

to its buffer

* exwm-workspace.el (exwm-workspace-show-all-buffers, exwm-workspace-switch)
  (exwm-workspace-move-window, exwm-workspace-switch-to-buffer): Show buffers
  on other workspaces if `exwm-workspace-show-all-buffers' is non-nil.

* exwm-layout.el (exwm-layout-show-all-buffers, exwm-layout--refresh): Allow
  moving an X window by switch to its corresponding buffer from another
  workspace when `exwm-layout-show-all-buffers' is non-nil.
* exwm.el (exwm--ido-buffer-window-other-frame): Handle the case when
  `exwm-layout-show-all-buffers' is non-nil.

* exwm-floating.el (exwm-floating--set-floating): Handle the case when
  *scratch* buffer is killed.

* exwm-workspace.el (exwm-workspace-switch-to-buffer): Renamed from
  `exwm-workspace-switch-to-window' to better reflect its role.
This commit is contained in:
Chris Feng 2015-09-16 21:32:38 +08:00
parent 576a676f1f
commit b458d5ac30
4 changed files with 58 additions and 33 deletions

View file

@ -67,7 +67,10 @@
exwm-workspace--current))) exwm-workspace--current)))
(original-id (frame-parameter original-frame 'exwm-window-id)) (original-id (frame-parameter original-frame 'exwm-window-id))
;; Create new frame ;; Create new frame
(frame (with-current-buffer "*scratch*" (frame (with-current-buffer
(or (get-buffer "*scratch*")
(prog1 (get-buffer-create "*scratch*")
(set-buffer-major-mode "*scratch*")))
(prog2 (prog2
(exwm--lock) (exwm--lock)
(make-frame (make-frame

View file

@ -194,10 +194,15 @@
:height height)) :height height))
(xcb:flush exwm--connection)))) (xcb:flush exwm--connection))))
(defvar exwm-layout-show-all-buffers nil
"Non-nil to allow switching to buffers on other workspaces.")
(defun exwm-layout--refresh () (defun exwm-layout--refresh ()
"Refresh layout." "Refresh layout."
(let ((frame (selected-frame)) (let ((frame (selected-frame))
(placeholder (get-buffer "*scratch*")) (placeholder (or (get-buffer "*scratch*")
(prog1 (get-buffer-create "*scratch*")
(set-buffer-major-mode "*scratch*"))))
windows) windows)
(if (not (memq frame exwm-workspace--list)) (if (not (memq frame exwm-workspace--list))
(if (frame-parameter frame 'exwm-window-id) (if (frame-parameter frame 'exwm-window-id)
@ -221,19 +226,25 @@
;; Refresh the whole workspace ;; Refresh the whole workspace
;; Workspaces other than the active one can also be refreshed (RandR) ;; Workspaces other than the active one can also be refreshed (RandR)
(exwm--log "Refresh workspace %s" frame) (exwm--log "Refresh workspace %s" frame)
(unless placeholder ;create the *scratch* buffer if it's killed
(setq placeholder (get-buffer-create "*scratch*"))
(set-buffer-major-mode placeholder))
(dolist (pair exwm--id-buffer-alist) (dolist (pair exwm--id-buffer-alist)
(with-current-buffer (cdr pair) (with-current-buffer (cdr pair)
;; Exclude windows on other workspaces and floating frames (when (and (not exwm--floating-frame) ;exclude floating X windows
(when (and (eq frame exwm--frame) (not exwm--floating-frame)) (or exwm-layout-show-all-buffers
;; Exclude X windows on other workspaces
(eq frame exwm--frame)))
(setq windows (get-buffer-window-list (current-buffer) 0)) (setq windows (get-buffer-window-list (current-buffer) 0))
(if (not windows) (if (not windows)
(exwm-layout--hide exwm--id) (when (eq frame exwm--frame) ;for exwm-layout-show-all-buffers
(exwm-layout--hide exwm--id))
(if (eq frame exwm--frame)
(exwm-layout--show exwm--id (car windows)) (exwm-layout--show exwm--id (car windows))
(dolist (i (cdr windows)) (exwm-workspace-move-window
(set-window-buffer i placeholder)))))) (cl-position frame exwm-workspace--list) exwm--id))
(let ((window (car windows)))
;; Make sure this buffer is not displayed elsewhere
(dolist (i (get-buffer-window-list (current-buffer) 0 t))
(unless (eq i window)
(set-window-buffer i placeholder))))))))
;; Make sure windows floating / on other workspaces are excluded ;; Make sure windows floating / on other workspaces are excluded
(dolist (window (window-list frame 0)) (dolist (window (window-list frame 0))
(with-current-buffer (window-buffer window) (with-current-buffer (window-buffer window)

View file

@ -93,6 +93,8 @@
(defvar exwm-workspace--current nil "Current active workspace.") (defvar exwm-workspace--current nil "Current active workspace.")
(defvar exwm-workspace-current-index 0 "Index of current active workspace.") (defvar exwm-workspace-current-index 0 "Index of current active workspace.")
(defvar exwm-workspace-show-all-buffers nil
"Non-nil to show buffers on other workspaces.")
(defun exwm-workspace-switch (index &optional force) (defun exwm-workspace-switch (index &optional force)
"Switch to workspace INDEX. Query for INDEX if it's not specified. "Switch to workspace INDEX. Query for INDEX if it's not specified.
@ -131,12 +133,14 @@ The optional FORCE option is for internal use only."
(set-mouse-pixel-position frame x y))) (set-mouse-pixel-position frame x y)))
(setq default-minibuffer-frame frame) (setq default-minibuffer-frame frame)
;; Hide windows in other workspaces by preprending a space ;; Hide windows in other workspaces by preprending a space
(unless exwm-workspace-show-all-buffers
(dolist (i exwm--id-buffer-alist) (dolist (i exwm--id-buffer-alist)
(with-current-buffer (cdr i) (with-current-buffer (cdr i)
(let ((name (replace-regexp-in-string "^\\s-*" "" (buffer-name)))) (let ((name (replace-regexp-in-string "^\\s-*" ""
(buffer-name))))
(exwm-workspace-rename-buffer (if (eq frame exwm--frame) (exwm-workspace-rename-buffer (if (eq frame exwm--frame)
name name
(concat " " name)))))) (concat " " name)))))))
;; Update demands attention flag ;; Update demands attention flag
(set-frame-parameter frame 'exwm--urgency nil) (set-frame-parameter frame 'exwm--urgency nil)
;; Update switch workspace history ;; Update switch workspace history
@ -175,9 +179,12 @@ The optional FORCE option is for internal use only."
(with-current-buffer (exwm--id->buffer id) (with-current-buffer (exwm--id->buffer id)
(let ((frame (elt exwm-workspace--list index))) (let ((frame (elt exwm-workspace--list index)))
(unless (eq exwm--frame frame) (unless (eq exwm--frame frame)
(unless exwm-workspace-show-all-buffers
(let ((name (replace-regexp-in-string "^\\s-*" "" (buffer-name)))) (let ((name (replace-regexp-in-string "^\\s-*" "" (buffer-name))))
(exwm-workspace-rename-buffer (exwm-workspace-rename-buffer
(if (= index exwm-workspace-current-index) name (concat " " name)))) (if (= index exwm-workspace-current-index)
name
(concat " " name)))))
(setq exwm--frame frame) (setq exwm--frame frame)
(if exwm--floating-frame (if exwm--floating-frame
;; Move the floating frame is enough ;; Move the floating frame is enough
@ -208,15 +215,16 @@ The optional FORCE option is for internal use only."
(exwm--id->buffer id))))) (exwm--id->buffer id)))))
(exwm-workspace--update-switch-history))) (exwm-workspace--update-switch-history)))
(defun exwm-workspace-switch-to-window () (defun exwm-workspace-switch-to-buffer ()
"Make the current Emacs window display another X window." "Make the current Emacs window display another buffer."
(interactive) (interactive)
;; Show all buffers ;; Show all buffers
(unless exwm-workspace-show-all-buffers
(dolist (pair exwm--id-buffer-alist) (dolist (pair exwm--id-buffer-alist)
(with-current-buffer (cdr pair) (with-current-buffer (cdr pair)
(when (= ?\s (aref (buffer-name) 0)) (when (= ?\s (aref (buffer-name) 0))
(rename-buffer (substring (buffer-name) 1))))) (rename-buffer (substring (buffer-name) 1))))))
(let ((buffer (read-buffer "Switch to window: " nil t))) (let ((buffer (read-buffer "Switch to buffer: " nil t)))
(when buffer (when buffer
(with-current-buffer buffer (with-current-buffer buffer
(if (and (eq major-mode 'exwm-mode) (if (and (eq major-mode 'exwm-mode)
@ -225,11 +233,12 @@ The optional FORCE option is for internal use only."
exwm--id) exwm--id)
(switch-to-buffer buffer))))) (switch-to-buffer buffer)))))
;; Hide buffers on other workspaces ;; Hide buffers on other workspaces
(unless exwm-workspace-show-all-buffers
(dolist (pair exwm--id-buffer-alist) (dolist (pair exwm--id-buffer-alist)
(with-current-buffer (cdr pair) (with-current-buffer (cdr pair)
(unless (or (eq exwm--frame exwm-workspace--current) (unless (or (eq exwm--frame exwm-workspace--current)
(= ?\s (aref (buffer-name) 0))) (= ?\s (aref (buffer-name) 0)))
(rename-buffer (concat " " (buffer-name))))))) (rename-buffer (concat " " (buffer-name))))))))
(defun exwm-workspace-rename-buffer (newname) (defun exwm-workspace-rename-buffer (newname)
"Rename a buffer." "Rename a buffer."

View file

@ -538,7 +538,9 @@
(defun exwm--ido-buffer-window-other-frame (orig-fun buffer) (defun exwm--ido-buffer-window-other-frame (orig-fun buffer)
"Wrapper for `ido-buffer-window-other-frame' to exclude invisible windows." "Wrapper for `ido-buffer-window-other-frame' to exclude invisible windows."
(with-current-buffer buffer (with-current-buffer buffer
(if (eq major-mode 'exwm-mode) (if (and (eq major-mode 'exwm-mode)
(or exwm--floating-frame
(not exwm-layout-show-all-buffers)))
;; `ido-mode' works well with `exwm-mode' buffers ;; `ido-mode' works well with `exwm-mode' buffers
(funcall orig-fun buffer) (funcall orig-fun buffer)
;; Other buffers should be selected within the same workspace ;; Other buffers should be selected within the same workspace