about summary refs log tree commit diff
path: root/exwm-workspace.el
diff options
context:
space:
mode:
Diffstat (limited to 'exwm-workspace.el')
-rw-r--r--exwm-workspace.el58
1 files changed, 32 insertions, 26 deletions
diff --git a/exwm-workspace.el b/exwm-workspace.el
index f4e1dd19509f..9cf1ff050900 100644
--- a/exwm-workspace.el
+++ b/exwm-workspace.el
@@ -1,31 +1,36 @@
 ;;; exwm-workspace.el --- Workspace Module for EXWM  -*- lexical-binding: t -*-
 
-;; Copyright (C) 2015 Chris Feng
+;; Copyright (C) 2015 Free Software Foundation, Inc.
 
 ;; Author: Chris Feng <chris.w.feng@gmail.com>
-;; Keywords: unix
 
-;; This file is not part of GNU Emacs.
+;; This file is part of GNU Emacs.
 
-;; This file is free software: you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; the Free Software Foundation, either version 3 of the License, or
 ;; (at your option) any later version.
 
-;; This file is distributed in the hope that it will be useful,
+;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 ;; This module adds workspace support for EXWM.
 
+;; Todo:
+;; + Auto hide minibuffer, or allow users to place it elsewhere.
+;; + Add system tray support.
+
 ;;; Code:
 
+(require 'exwm-core)
+
 (defvar exwm-workspace-number 4 "Number of workspaces (1 ~ 10).")
 (defvar exwm-workspace--list nil "List of all workspaces (Emacs frames).")
 (defvar exwm-workspace--switch-map
@@ -42,23 +47,24 @@
     (define-key map "\C-e" (lambda ()
                              (interactive)
                              (goto-history-element exwm-workspace-number)))
-    (define-key map "\C-g" 'abort-recursive-edit)
-    (define-key map "\C-]" 'abort-recursive-edit)
-    (define-key map "\C-j" 'exit-minibuffer)
-    ;; (define-key map "\C-m" 'exit-minibuffer) ;not working
-    (define-key map [return] 'exit-minibuffer)
-    (define-key map " " 'exit-minibuffer)
-    (define-key map "\C-f" 'previous-history-element)
-    (define-key map "\C-b" 'next-history-element)
+    (define-key map "\C-g" #'abort-recursive-edit)
+    (define-key map "\C-]" #'abort-recursive-edit)
+    (define-key map "\C-j" #'exit-minibuffer)
+    ;; (define-key map "\C-m" #'exit-minibuffer) ;not working
+    (define-key map [return] #'exit-minibuffer)
+    (define-key map " " #'exit-minibuffer)
+    (define-key map "\C-f" #'previous-history-element)
+    (define-key map "\C-b" #'next-history-element)
     ;; Alternative keys
-    (define-key map [right] 'previous-history-element)
-    (define-key map [left] 'next-history-element)
+    (define-key map [right] #'previous-history-element)
+    (define-key map [left] #'next-history-element)
     map)
   "Keymap used for interactively switch workspace.")
 
 (defvar exwm-workspace--switch-history nil
   "History for `read-from-minibuffer' to interactively switch workspace.")
 
+;;;###autoload
 (defun exwm-workspace--update-switch-history ()
   "Update the history for switching workspace to reflect the latest status."
   (let ((sequence (number-sequence 0 (1- exwm-workspace-number)))
@@ -95,14 +101,14 @@ The optional FORCE option is for internal use only."
   (interactive
    (list
     (unless (and (eq major-mode 'exwm-mode) exwm--fullscreen) ;it's invisible
-      (let* ((history-add-new-input nil)  ;prevent modifying history
+      (let* ((history-add-new-input nil) ;prevent modifying history
              (idx (read-from-minibuffer
                    "Workspace: " (elt exwm-workspace--switch-history
                                       exwm-workspace-current-index)
                    exwm-workspace--switch-map nil
                    `(exwm-workspace--switch-history
                      . ,(1+ exwm-workspace-current-index)))))
-        (cl-position idx exwm-workspace--switch-history :test 'equal)))))
+        (cl-position idx exwm-workspace--switch-history :test #'equal)))))
   (when index
     (unless (and (<= 0 index) (< index exwm-workspace-number))
       (user-error "[EXWM] Workspace index out of range: %d" index))
@@ -150,6 +156,7 @@ The optional FORCE option is for internal use only."
       (exwm--log "Workspace was switched unexpectedly")
       (exwm-workspace-switch index))))
 
+;;;###autoload
 (defun exwm-workspace-move-window (index &optional id)
   "Move window ID to workspace INDEX."
   (interactive
@@ -161,7 +168,7 @@ The optional FORCE option is for internal use only."
                  exwm-workspace--switch-map nil
                  `(exwm-workspace--switch-history
                    . ,(1+ exwm-workspace-current-index)))))
-      (cl-position idx exwm-workspace--switch-history :test 'equal))))
+      (cl-position idx exwm-workspace--switch-history :test #'equal))))
   (unless id (setq id (exwm--buffer->id (window-buffer))))
   (unless (and (<= 0 index) (< index exwm-workspace-number))
     (user-error "[EXWM] Workspace index out of range: %d" index))
@@ -169,9 +176,8 @@ The optional FORCE option is for internal use only."
     (let ((frame (elt exwm-workspace--list index)))
       (when (not (equal 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))))
+          (exwm-workspace-rename-buffer
+           (if (= index exwm-workspace-current-index) name (concat " " name))))
         (setq exwm--frame frame)
         (if exwm--floating-frame
             ;; Move the floating frame is enough
@@ -232,14 +238,14 @@ The optional FORCE option is for internal use only."
     ;; Prevent user from deleting this frame by accident
     (set-frame-parameter (car exwm-workspace--list) 'client nil))
   ;; Create remaining frames
-  (dotimes (i (1- exwm-workspace-number))
+  (dotimes (_ (1- exwm-workspace-number))
     (nconc exwm-workspace--list
            (list (make-frame '((window-system . x)
                                (visibility . nil))))))
   ;; Configure workspaces
   (dolist (i exwm-workspace--list)
-    (let ((window-id (string-to-int (frame-parameter i 'window-id)))
-          (outer-id (string-to-int (frame-parameter i 'outer-window-id))))
+    (let ((window-id (string-to-number (frame-parameter i 'window-id)))
+          (outer-id (string-to-number (frame-parameter i 'outer-window-id))))
       ;; Save window IDs
       (set-frame-parameter i 'exwm-window-id window-id)
       (set-frame-parameter i 'exwm-outer-id outer-id)
@@ -263,7 +269,7 @@ The optional FORCE option is for internal use only."
     (set-frame-parameter i 'fullscreen 'fullboth))
   (raise-frame (car exwm-workspace--list))
   ;; Handle unexpected frame switch
-  (add-hook 'focus-in-hook 'exwm-workspace--on-focus-in)
+  (add-hook 'focus-in-hook #'exwm-workspace--on-focus-in)
   ;; Set _NET_VIRTUAL_ROOTS
   (xcb:+request exwm--connection
       (make-instance 'xcb:ewmh:set-_NET_VIRTUAL_ROOTS