stumpwm-devel
[Top][All Lists]
Advanced

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

[STUMP] [PATCH] Using window properties to store window placement.


From: Michael Raskin
Subject: [STUMP] [PATCH] Using window properties to store window placement.
Date: Mon, 01 Sep 2008 02:17:17 +0400
User-agent: Thunderbird 2.0.0.14 (X11/20080825)

                Hello
        That patch adds commands that allow to mark windows via dedicated
properties and later place them in the same groups/frames they occupied
earlier using that information. The best part is that you do not need to
have continuous history of running StumpWM: it can be used across
StumpWM reload if you need to do it the hard way (with killing StumpWM)
or you can save needed layout and not fear a possible crash. You could
dump frame layout earlier, this patch allows you to preserve windows.
        The patch is split in two, as the first small part (functions for
window properties that are meant to hold strings) seems useful per se.
>From 0710dee27623fdbadb02d1b414f05c807e1a7dd5 Mon Sep 17 00:00:00 2001
From: 38a938c2 <address@hidden>
Date: Sun, 31 Aug 2008 23:24:13 +0400
Subject: [PATCH] Added functions to work with string-valued X window properties

---
 window.lisp |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/window.lisp b/window.lisp
index 841999f..1756b8e 100644
--- a/window.lisp
+++ b/window.lisp
@@ -383,6 +383,18 @@ _NET_WM_STATE_DEMANDS_ATTENTION set"
 (defun window-property (window prop)
   (xlib:get-property (window-xwin window) prop))
 
+(defun window-string-property (window prop)
+  "Get window property and convert it to string"
+  (apply #'concatenate
+         (cons 'string
+               (mapcar 'string
+                       (mapcar 'character
+                               (window-property window prop))))))
+
+(defun set-window-string-property (window prop value)
+  "Set window property to value specified by a string"
+  (xlib:change-property (window-xwin window) prop value :string 8 :transform 
'char-code))
+
 (defun find-wm-state (xwin state)
   (find (xlib:find-atom *display* state) (xlib:get-property xwin 
:_NET_WM_STATE) :test #'=))
 
-- 
1.6.0

>From ba2d92921aad90722ec45850ac58bb48a955d321 Mon Sep 17 00:00:00 2001
From: 38a938c2 <address@hidden>
Date: Mon, 1 Sep 2008 00:39:10 +0400
Subject: [PATCH] Added commands to save/load placement information using window 
properties. Good when restarting stumpwm..

---
 group.lisp  |    5 +++++
 window.lisp |   27 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/group.lisp b/group.lisp
index a6a1d38..afe40e6 100644
--- a/group.lisp
+++ b/group.lisp
@@ -399,3 +399,8 @@ 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))))
+
+(defun all-groups ()
+  "List all the known groups on all screens"
+  (apply #'concatenate (cons 'list
+    (mapcar #'screen-groups *screen-list*))))
diff --git a/window.lisp b/window.lisp
index 1756b8e..e02fbad 100644
--- a/window.lisp
+++ b/window.lisp
@@ -1545,3 +1545,30 @@ be used to override the default window formatting."
   (if (current-window)
       (message "~a" (format-expand *window-formatters* fmt (current-window)))
       (message "No Current Window")))
+
+(defcommand placement-to-properties (&optional (window nil)) ()
+  "Create X window properties to hold current window position"
+  (let* ((win (if window window (current-window)))
+        (gr (window-group win))
+        (fr (window-frame win))
+        )
+    (set-window-string-property win :stumpwm-group-name (group-name gr))
+    (set-window-string-property win :stumpwm-frame-number (format nil "~s " 
(frame-number fr)))))
+
+(defcommand placement-by-properties (&optional (window nil)) ()
+  "Read X window properties we have set and place window according to them"
+  (let* ((win (if window window (current-window)))
+        (grname (window-string-property win :stumpwm-group-name))
+        (group (find-if (lambda (g) (equal (group-name g) grname)) 
(all-groups)))
+        (frnum (ignore-errors (parse-integer (window-string-property win 
:stumpwm-frame-number))))
+        (frame (if group (find-if (lambda (f) (equal (frame-number f) frnum)) 
(group-frames group)) nil)))
+    (when group (move-window-to-group win group))
+    (when frame (pull-window win frame))))
+
+(defcommand all-placement-to-properties () ()
+  "Save all window placement data to properties"
+  (mapcar #'placement-to-properties (all-windows)))
+
+(defcommand all-placement-by-properties () ()
+  "Load all window placement data from properties"
+  (mapcar #'placement-by-properties (all-windows)))
-- 
1.6.0


reply via email to

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