about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2015-09-09T11·08+0800
committerChris Feng <chris.w.feng@gmail.com>2015-09-09T11·08+0800
commit3f2f84456997a46e047adbf45c4c44b628ae1377 (patch)
tree6af6ca59093b2523320044236a87d077cfd7ad73
parent5373c1df1a8432f6a54e8ded8c9a145842c067e2 (diff)
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.
-rw-r--r--exwm-workspace.el31
1 files changed, 29 insertions, 2 deletions
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)))