Re: New questionnaire on your usage of Sawfish

Christopher Roy Bratusek <zanghar freenet de> writes:

>> An alternate approach would be to use the gravity to decide the 0,0
>> point for the initial placement.  I'd be happy to come up with a
>> patch, if desired.
> Yes. If you wrap a matcher around gravity or modify gravity directly
> is you decision.

I can't use the gravity to specify the origin for position since gravity
may not be set yet, so here's a slightly different approach.  With the
patch below it's possible to specify a gravity instead of x,y
coordinates as a position, in which case the gravity is set and the
window is placed in the appropriate position: in a corner, centered on
an edge, or at the center of the screen.  It also sets the gravity if a
negative x or y are provided.

One problem is that the patch doesn't make this functionality available
to the configuration interface, and I don't know how easy that would be
to do.  It would be possible to separate this out to a different match
setter, though that would presumably require adding to the hack at line
303 (presumably that has something to do with placement code?).

diff --git a/lisp/sawfish/wm/ext/match-window.jl b/lisp/sawfish/wm/ext/match-window.jl
index 9c2afb0..81b77b8 100644
--- a/lisp/sawfish/wm/ext/match-window.jl
+++ b/lisp/sawfish/wm/ext/match-window.jl
@@ -347,14 +347,38 @@
   (define-match-window-setter 'position
    (lambda (w prop value)
      (declare (unused prop))
-     (let ((x (car value))
-	   (y (cdr value)))
+     (let* ((size (window-frame-dimensions w))
+            (x (if (symbolp value)
+                   (cond ((memq value '(east south-east north-east))
+                          (- (screen-width) (car size)))
+                         ((memq value '(north center south))
+                          (- (quotient (screen-width) 2)
+                             (quotient (car size) 2)))
+                         (t 0)) 
+                 (car value)))
+            (y (if (symbolp value)
+                   (cond ((memq value '(south south-east south-west))
+                          (- (screen-height) (cdr size)))
+                         ((memq value '(east center west))
+                          (- (quotient (screen-height) 2)
+                             (quotient (cdr size) 2)))
+                         (t 0))
+                 (cdr value)))
+            (gravity (cond ((symbolp value)
+                            value)
+                           ((and (< x 0) (< y 0))
+                            'south-east)
+                           ((< x 0)
+                            'north-east)
+                           ((< y 0)
+                            'south-west)
+                           (t nil))))
+       (when gravity
+         (window-put w 'gravity gravity))
        (when (< x 0)
-	 ;; XXX should change placement gravity
-	 (setq x (+ (screen-width) x)))
+	 (setq x (+ (- (screen-width) (car size)) x)))
        (when (< y 0)
-	 ;; XXX should change placement gravity
-	 (setq y (+ (screen-height) y)))
+	 (setq y (+ (- (screen-height) (cdr size)) y)))
        (move-window-to w x y))))
   (define-match-window-setter 'dimensions

Jeremy Hankins <nowan nowan org>
PGP fingerprint: 748F 4D16 538E 75D6 8333  9E10 D212 B5ED 37D0 0A03

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