Make `exwm-workspace--current-index' private

Users should not mess with this variable.
This commit is contained in:
Urbano Ustero 2015-08-27 19:44:12 +02:00
parent 405059c677
commit 483d77b60f
2 changed files with 13 additions and 14 deletions

View file

@ -27,6 +27,8 @@
;;; Code: ;;; Code:
(defvar exwm-workspace--list nil "List of all workspaces (Emacs frames).") (defvar exwm-workspace--list nil "List of all workspaces (Emacs frames).")
(defvar exwm-workspace--current nil "Current active workspace.")
(defvar exwm-workspace--current-index 0 "Index of current active workspace.")
(defun exwm-workspace--count () (defun exwm-workspace--count ()
"Retrieve total number of workspaces." "Retrieve total number of workspaces."
@ -85,9 +87,6 @@
sequence "")) sequence ""))
sequence)))) sequence))))
(defvar exwm-workspace--current nil "Current active workspace.")
(defvar exwm-workspace-current-index 0 "Index of current active workspace.")
(defun exwm-workspace--switch-map-by-number (&optional prefix-digits) (defun exwm-workspace--switch-map-by-number (&optional prefix-digits)
"Allow selecting a workspace by number. "Allow selecting a workspace by number.
@ -140,18 +139,18 @@ The optional FORCE option is for internal use only."
(let* ((history-add-new-input nil) ;prevent modifying history (let* ((history-add-new-input nil) ;prevent modifying history
(idx (read-from-minibuffer (idx (read-from-minibuffer
"Workspace: " (elt exwm-workspace--switch-history "Workspace: " (elt exwm-workspace--switch-history
exwm-workspace-current-index) exwm-workspace--current-index)
exwm-workspace--switch-map nil exwm-workspace--switch-map nil
`(exwm-workspace--switch-history `(exwm-workspace--switch-history
. ,(1+ exwm-workspace-current-index))))) . ,(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 (when index
(unless (and (<= 0 index) (< index (exwm-workspace--count))) (unless (and (<= 0 index) (< index (exwm-workspace--count)))
(user-error "[EXWM] Workspace index out of range: %d" index)) (user-error "[EXWM] Workspace index out of range: %d" index))
(when (or force (/= exwm-workspace-current-index index)) (when (or force (/= exwm-workspace--current-index index))
(let ((frame (elt exwm-workspace--list index))) (let ((frame (elt exwm-workspace--list index)))
(setq exwm-workspace--current frame (setq exwm-workspace--current frame
exwm-workspace-current-index index) exwm-workspace--current-index index)
(select-frame-set-input-focus frame) (select-frame-set-input-focus frame)
;; Move mouse when necessary ;; Move mouse when necessary
(let ((position (mouse-pixel-position)) (let ((position (mouse-pixel-position))
@ -188,7 +187,7 @@ The optional FORCE option is for internal use only."
"Fix unexpected frame switch." "Fix unexpected frame switch."
(let ((index (cl-position (selected-frame) exwm-workspace--list))) (let ((index (cl-position (selected-frame) exwm-workspace--list)))
(exwm--log "Focus on workspace %s" index) (exwm--log "Focus on workspace %s" index)
(when (and index (/= index exwm-workspace-current-index)) (when (and index (/= index exwm-workspace--current-index))
(exwm--log "Workspace was switched unexpectedly") (exwm--log "Workspace was switched unexpectedly")
(exwm-workspace-switch index)))) (exwm-workspace-switch index))))
@ -199,10 +198,10 @@ The optional FORCE option is for internal use only."
(let* ((history-add-new-input nil) ;prevent modifying history (let* ((history-add-new-input nil) ;prevent modifying history
(idx (read-from-minibuffer (idx (read-from-minibuffer
"Workspace: " (elt exwm-workspace--switch-history "Workspace: " (elt exwm-workspace--switch-history
exwm-workspace-current-index) exwm-workspace--current-index)
exwm-workspace--switch-map nil exwm-workspace--switch-map nil
`(exwm-workspace--switch-history `(exwm-workspace--switch-history
. ,(1+ exwm-workspace-current-index))))) . ,(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 id (setq id (exwm--buffer->id (window-buffer))))
(unless (and (<= 0 index) (< index (exwm-workspace--count))) (unless (and (<= 0 index) (< index (exwm-workspace--count)))
@ -211,7 +210,7 @@ The optional FORCE option is for internal use only."
(let ((frame (elt exwm-workspace--list index))) (let ((frame (elt exwm-workspace--list index)))
(when (not (equal exwm--frame frame)) (when (not (equal exwm--frame frame))
(let ((name (replace-regexp-in-string "^\\s-*" "" (buffer-name)))) (let ((name (replace-regexp-in-string "^\\s-*" "" (buffer-name))))
(exwm-workspace-rename-buffer (if (= index exwm-workspace-current-index) (exwm-workspace-rename-buffer (if (= index exwm-workspace--current-index)
name name
(concat " " name)))) (concat " " name))))
(setq exwm--frame frame) (setq exwm--frame frame)
@ -301,14 +300,14 @@ The optional FORCE option is for internal use only."
;; frame from the workspace list, so as not to confuse the indices. ;; frame from the workspace list, so as not to confuse the indices.
(let* ((index (cl-position frame exwm-workspace--list)) (let* ((index (cl-position frame exwm-workspace--list))
(lastp (= index (1- (length exwm-workspace--list))))) (lastp (= index (1- (length exwm-workspace--list)))))
(when (= index exwm-workspace-current-index) (when (= index exwm-workspace--current-index)
;; As we are removing this workspace, the one on its left is its natural ;; As we are removing this workspace, the one on its left is its natural
;; substitutes... except when this is already the last one and there is ;; substitutes... except when this is already the last one and there is
;; none on its left. ;; none on its left.
(exwm-workspace-switch (+ index (if lastp -1 +1))) (exwm-workspace-switch (+ index (if lastp -1 +1)))
;; Now delete it from the workspace list, and update current index. ;; Now delete it from the workspace list, and update current index.
(setq exwm-workspace--list (delete frame exwm-workspace--list)) (setq exwm-workspace--list (delete frame exwm-workspace--list))
(cl-incf exwm-workspace-current-index (if lastp 0 -1)))) (cl-incf exwm-workspace--current-index (if lastp 0 -1))))
;; Update EWMH properties. ;; Update EWMH properties.
(exwm-workspace--update-ewmh-props) (exwm-workspace--update-ewmh-props)
;; Update switch history. ;; Update switch history.

View file

@ -489,7 +489,7 @@
(when (memq xcb:Atom:_NET_WM_STATE_DEMANDS_ATTENTION props) (when (memq xcb:Atom:_NET_WM_STATE_DEMANDS_ATTENTION props)
(when (= action xcb:ewmh:_NET_WM_STATE_ADD) (when (= action xcb:ewmh:_NET_WM_STATE_ADD)
(let ((idx (cl-position exwm--frame exwm-workspace--list))) (let ((idx (cl-position exwm--frame exwm-workspace--list)))
(unless (= idx exwm-workspace-current-index) (unless (= idx exwm-workspace--current-index)
(set-frame-parameter exwm--frame 'exwm--urgency t) (set-frame-parameter exwm--frame 'exwm--urgency t)
(exwm-workspace--update-switch-history)))) (exwm-workspace--update-switch-history))))
;; xcb:ewmh:_NET_WM_STATE_REMOVE? ;; xcb:ewmh:_NET_WM_STATE_REMOVE?