stumpwm-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[STUMP] [PATCH] Renumbering of groups


From: Nils Anspach
Subject: [STUMP] [PATCH] Renumbering of groups
Date: Sat, 27 Nov 2010 03:50:30 +0100

Hello list,

the following patches (against HEAD) add functions for altering the 
current numbering of groups. More specifically, they allow to reset 
the number of a given group or to swap it with that of another group.
They also take care of the convention that hidden groups should start 
with a dot, while visible group should not, if the sign of the group
number is to change during the alteration.

The user commands 'gnumber' and 'gswap' are convenient ways of acces-
sing these functions (e.g. via key bindings).

Additionally, the lowest possible index for visible groups is changed
from one to zero (which is compliant with the indexing of windows,
heads, ...).

Nils
diff --git a/group.lisp b/group.lisp
index 99c6d28..be77c5d 100644
--- a/group.lisp
+++ b/group.lisp
@@ -111,7 +111,7 @@ otherwise specified."
 
 (defun find-free-group-number (screen)
   "Return a free group number in SCREEN."
-  (find-free-number (mapcar 'group-number (screen-groups screen)) 1))
+  (find-free-number (mapcar 'group-number (screen-groups screen))))
 
 (defun find-free-hidden-group-number (screen)
   "Return a free hidden group number for SCREEN. Hidden group numbers
@@ -121,7 +121,7 @@ start at -1 and go down."
 (defun non-hidden-groups (groups)
   "Return only those groups that are not hidden."
   (remove-if (lambda (g)
-               (< (group-number g) 1))
+               (minusp (group-number g)))
              groups))
 
 (defun netwm-group-id (group)
@@ -291,10 +291,43 @@ Groups are known as \"virtual desktops\" in the NETWM 
standard."
           (switch-to-group ng))
         ng)))
 
-(defun find-group (screen name)
-  "Return the group with the name, NAME. Or NIL if none exists."
+(defmethod find-group ((screen screen) (name string))
+  "Returns the group with name NAME, or NIL if no such group exists."
   (find name (screen-groups screen) :key 'group-name :test 'string=))
 
+(defmethod find-group ((screen screen) (number integer))
+  "Returns the group with number NUMBER, or NIL if no such group
+exists."
+  (find number (screen-groups screen) :key #'group-number))
+
+(defun change-group-number (group new-num)
+  "Changes the number of group GROUP to NEW-NUM."
+  (check-type group group)
+  (check-type new-num integer)
+  (if (find-group (group-screen group) new-num)
+      (message "^1*^BError: Number already in use.")
+      (progn
+       (cond ((and (minusp new-num)
+                   (char/= (char (group-name group) 0) #\.)) ; change to 
hidden group
+              (setf (group-name group) (concat "." (group-name group))))
+             ((and (>= new-num 0)
+                   (char= (char (group-name group) 0) #\.)) ; change from 
hidden group
+              (setf (group-name group) (subseq (group-name group) 1))))
+       (setf (group-number group) new-num))))
+
+(defun swap-group-numbers (group-1 group-2)
+  "Swaps the numbers of groups GROUP-1 and GROUP-2."
+  (check-type group-1 group)
+  (check-type group-2 group)
+  (let* ((gnum-1 (group-number group-1))
+        (gnum-2 (group-number group-2))
+        (gnum-2* (if (>= gnum-2 0) ; intermediate storage of gnum-2
+                     (find-free-group-number (group-screen group-2))
+                     (find-free-hidden-group-number (group-screen group-2)))))
+    (setf (group-number group-2) gnum-2*)
+    (change-group-number group-1 gnum-2)
+    (change-group-number group-2 gnum-1)))
+
 ;;; Group commands
 
 ;; FIXME: groups are to screens exactly as windows are to
@@ -322,7 +355,7 @@ current window of the current group to the new one."
   "Create a new group with the specified name. The new group becomes the
 current group. If @var{name} begins with a dot (``.'') the group new
 group will be created in the hidden state. Hidden groups have group
-numbers less than one and are invisible to from gprev, gnext, and, optionally,
+numbers less than zero and are invisible to from gprev, gnext, and, optionally,
 groups and vgroups commands."
   (add-group (current-screen) name))
 
@@ -464,3 +497,12 @@ The windows will be moved to group \"^B^2*~a^n\"
   (if (eq from (current-group))
       (message "^B^3*Cannot merge group with itself!")
       (merge-groups from (current-group))))
+
+(defcommand gnumber (new-num) ((:number "New number of group: "))
+  "Changes the number of the current group to number NEW-NUM."
+  (change-group-number (current-group) new-num))
+
+(defcommand gswap (target-group) ((:group "Swap with group: "))
+  "Swaps the number of the current group with that of group
+TARGET-GROUP."
+  (swap-group-numbers (current-group) target-group))
\ No newline at end of file
diff --git a/screen.lisp b/screen.lisp
index 92782e2..0a77183 100644
--- a/screen.lisp
+++ b/screen.lisp
@@ -429,7 +429,7 @@ FOCUS-WINDOW is an extra window used for 
_NET_SUPPORTING_WM_CHECK."
                                      "*")))
            (group (make-instance 'tile-group
                    :screen screen
-                   :number 1
+                   :number 0
                    :name *default-group-name*)))
       ;; Create our screen structure
       ;; The focus window is mapped at all times
-- 
1.7.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]