stumpwm-devel
[Top][All Lists]
Advanced

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

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


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

Shawn wrote:
>>      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
> 
> I thought stumpwm already did this using the netwm desktop property
> and the x,y location of the windows. You have found this not to be so?

It has some limitations. After restart I may have a slightly other
frame/group layout. Data from the layout saving methods you mention will
be lost forever in that case.

Also I noticed that even moving some code in my .stumpwmrc to start-hook
doesn't help it to renumber windows correctly (partly because modeline
is incapable of either being sane clock or right-aligning and modeline
replacement xterms are easier to restart than to check). It is still
easier to re-load .stumpwmrc, but it re-creates all the groups and that
also loses the rest of layout information.

Maybe once it is included it should be expanded to allow multiple saved
layouts. Obviously using just (x,y) to do that would be a failure.

> (map 'string 'character (window-property window prop))

OK.

> (xlib:get-property (window-xwin window) prop :type :string :result-type 
> 'string :transform #'xlib:card8->char)

I somehow feel it will not be any better (new-clx will call the same
functions). We have needed abstraction (window-property) already.

> This would be better written as a setf function: 
> 
> (defun (setf window-string-property) (value window prop) ...)
> 
> and used this way:
> 
> (setf (window-string-property window prop) value)

Heh, HyperSpec made me doubt that it should work (I wanted to check
parameter order). Strangely, it works.

> This looks a little nicer:
> 
> (apply 'append (mapcar #'screen-groups *screen-list*))

OK

>> +(defcommand all-placement-to-properties () ()
>> +  "Save all window placement data to properties"
>> +  (mapcar #'placement-to-properties (all-windows)))
> 
> you should use mapc, which doesn't accumulate the return values.

OK.


Merged and corrected patch attached.
>From cbee3e3a2b0ba4deea250e08daa86d70289fbf0e Mon Sep 17 00:00:00 2001
From: 38a938c2 <address@hidden>
Date: Mon, 1 Sep 2008 08:16:09 +0400
Subject: [PATCH] Added commands to save/load placement information using window 
properties. Good when restarting stumpwm..

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

diff --git a/group.lisp b/group.lisp
index a6a1d38..db8a9a1 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 #'append
+    (mapcar #'screen-groups *screen-list*)))
diff --git a/window.lisp b/window.lisp
index 841999f..4a521c3 100644
--- a/window.lisp
+++ b/window.lisp
@@ -383,6 +383,15 @@ _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"
+  (map 'string 'character (window-property window prop))
+  )
+
+(defun (setf window-string-property) (value window prop)
+  "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 #'=))
 
@@ -1533,3 +1542,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))
+        )
+    (setf (window-string-property win :stumpwm-group-name) (group-name gr))
+    (setf (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"
+  (mapc #'placement-to-properties (all-windows)))
+
+(defcommand all-placement-by-properties () ()
+  "Load all window placement data from properties"
+  (mapc #'placement-by-properties (all-windows)))
-- 
1.6.0


reply via email to

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