From 3f2f84456997a46e047adbf45c4c44b628ae1377 Mon Sep 17 00:00:00 2001 From: Chris Feng Date: Wed, 9 Sep 2015 19:08:51 +0800 Subject: Add a command to interactively move X window to the current workspace * exwm-workspace.el (exwm-workspace-move-window): Hide buffer on the original Emacs window when moving an X window to the current workspace. * exwm-workspace.el: New function exwm-workspace-switch-to-window for interactively moving an X window on another workspace to the current one. --- exwm-workspace.el | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'exwm-workspace.el') diff --git a/exwm-workspace.el b/exwm-workspace.el index 2ea8d1fb169b..5fae713f5709 100644 --- a/exwm-workspace.el +++ b/exwm-workspace.el @@ -174,7 +174,7 @@ The optional FORCE option is for internal use only." (user-error "[EXWM] Workspace index out of range: %d" index)) (with-current-buffer (exwm--id->buffer id) (let ((frame (elt exwm-workspace--list index))) - (when (not (equal exwm--frame frame)) + (unless (eq exwm--frame frame) (let ((name (replace-regexp-in-string "^\\s-*" "" (buffer-name)))) (exwm-workspace-rename-buffer (if (= index exwm-workspace-current-index) name (concat " " name)))) @@ -191,7 +191,12 @@ The optional FORCE option is for internal use only." :x 0 :y 0)) (xcb:flush exwm--connection)) ;; Move the window itself - (bury-buffer) + (if (/= index exwm-workspace-current-index) + (bury-buffer) + (set-window-buffer (get-buffer-window (current-buffer) t) + (or (get-buffer "*scratch*") + (prog1 (get-buffer-create "*scratch*") + (set-buffer-major-mode "*scratch*"))))) (exwm-layout--hide id) (xcb:+request exwm--connection (make-instance 'xcb:ReparentWindow @@ -203,6 +208,28 @@ The optional FORCE option is for internal use only." (exwm--id->buffer id))))) (exwm-workspace--update-switch-history))) +(defun exwm-workspace-switch-to-window () + "Make the current Emacs window display another X window." + (interactive) + ;; Show all buffers + (dolist (pair exwm--id-buffer-alist) + (with-current-buffer (cdr pair) + (when (= ?\s (aref (buffer-name) 0)) + (rename-buffer (substring (buffer-name) 1))))) + (let ((buffer (read-buffer "Switch to window: " nil t))) + (when buffer + (with-current-buffer buffer + (when (and (eq major-mode 'exwm-mode) + (not (eq exwm--frame exwm-workspace--current))) + (exwm-workspace-move-window exwm-workspace-current-index + exwm--id))))) + ;; Hide buffers on other workspaces + (dolist (pair exwm--id-buffer-alist) + (with-current-buffer (cdr pair) + (unless (or (eq exwm--frame exwm-workspace--current) + (= ?\s (aref (buffer-name) 0))) + (rename-buffer (concat " " (buffer-name))))))) + (defun exwm-workspace-rename-buffer (newname) "Rename a buffer." (let ((hidden (= ?\s (aref newname 0))) -- cgit 1.4.1