Sawfish
Advertisement
Browse all patches

Author[]

Andrea Vettorello

Synopsis[]

With this patch Sawfish honors aspect ratios when resizing a window interactively.

Patch testing[]

I've only tested it with MPlayer, xprop can reveal if a window requests a specific aspect ratio. Without the patch, one can modify the height or width of an MPlayer output window independently, with the patch applied modifying the height of the window should change the width too and vice versa.

P.S. in the MPlayer case, content scaling depends on video output used. (^__^)

  1. Copy/paste the patch listed below into some file, eg. TEST.diff.
  2. If you don't have sawfish sources yet, have one, as described get it from GIT repo.
  3. Go into the directory where sawfish sources reside, eg. cd sawfish
  4. Test if the patch applies cleanly with this command:
    patch -p1 --ignore-whitespace --dry-run < TEST.diff
    in case of problems try also: -p0 or -p2
  5. If it applies cleanly, then remove the --dry-run from above command and run it again, otherwise ask on the mailing list.
  6. Compile sawfish: ./autogen.sh && make
  7. Install it for testing, but it depends on your linux distribution.
    1. It is always better to install sawfish as your distribution package, but it is different for each distribution.
    2. So you may try make install, which will install sawifish in /usr/local/share/sawfish/ (if you have write access). But then make sure that you run the correct version and delete it from that directory afterwards, to avoid any conflicts.
  8. Se also

PS: edit this template if you feel that those instructions can be improved.

Patch[]

Index: lisp/sawfish/wm/windows.jl
===================================================================
--- lisp/sawfish/wm/windows.jl	(revision 4294)
+++ lisp/sawfish/wm/windows.jl	(working copy)
@@ -39,6 +39,7 @@
 	     warp-cursor-to-window
 	     activate-window
 	     constrain-dimension-to-hints
+	     constrain-aspect-to-hints
 	     resize-window-with-hints
 	     resize-window-with-hints*
 	     window-gravity
@@ -265,6 +266,13 @@
 		   (+ (* (ceiling (/ (- x bottom) inc)) inc) bottom)))))
       (clamp x (or minimum base 1) maximum)))
 
+  (define (constrain-aspect-to-hints a old-b dimension min-aspect max-aspect)
+    (let ((min-ratio (/ (cadr min-aspect) (cddr min-aspect)))
+          (max-ratio (/ (cadr max-aspect) (cddr min-aspect))))
+      (if (eq dimension 'y)
+          (clamp old-b (floor (* a min-ratio)) (floor (* a max-ratio)))
+        (clamp old-b (floor (/ a max-ratio)) (floor (/ a min-ratio))))))
+
   (define (resize-window-with-hints w cols rows #!optional hints)
     "Resize window W to COLS x ROWS, using the window's size hints to define
 the row and column size, and the minimum possible size.
Index: lisp/sawfish/wm/commands/move-resize.jl
===================================================================
--- lisp/sawfish/wm/commands/move-resize.jl	(revision 4294)
+++ lisp/sawfish/wm/commands/move-resize.jl	(working copy)
@@ -308,7 +308,10 @@
 		 ((x-base (or (cdr (assq 'base-width move-resize-hints)) 0))
 		  (x-inc (or (cdr (assq 'width-inc move-resize-hints)) 1))
 		  (y-base (or (cdr (assq 'base-height move-resize-hints)) 0))
-		  (y-inc (or (cdr (assq 'height-inc move-resize-hints)) 1)))
+		  (y-inc (or (cdr (assq 'height-inc move-resize-hints)) 1))
+		  (min-aspect (assq 'min-aspect move-resize-hints))
+		  (max-aspect (assq 'max-aspect move-resize-hints)))
+               
 	       (when (memq resize-edge-mode '(grab border-grab))
 		 (add-edges ptr-x ptr-y))
 	       (cond
@@ -317,13 +320,23 @@
 		       (constrain-dimension-to-hints
 			(+ move-resize-old-width
 			   (- ptr-x move-resize-old-ptr-x))
-			'x move-resize-hints)))
+			'x move-resize-hints))
+                 (when (or min-aspect max-aspect)
+                   (setq move-resize-height
+                         (constrain-aspect-to-hints
+                          move-resize-width
+                          move-resize-old-height 'x min-aspect max-aspect))))
+                
 		((memq 'left move-resize-moving-edges)
 		 (setq move-resize-width
 		       (constrain-dimension-to-hints
 			(+ move-resize-old-width
-			   (- move-resize-old-ptr-x ptr-x))
-			'x move-resize-hints))
+			   (- move-resize-old-ptr-x ptr-x)) 'x move-resize-hints))
+                 (when (or min-aspect max-aspect)
+                   (setq move-resize-height
+                         (constrain-aspect-to-hints
+                          move-resize-width
+                          move-resize-old-height 'x min-aspect max-aspect)))
 		 (setq move-resize-x (- move-resize-old-x
 					(- move-resize-width
 					   move-resize-old-width)))))
@@ -333,13 +346,24 @@
 		       (constrain-dimension-to-hints
 			(+ move-resize-old-height
 			   (- ptr-y move-resize-old-ptr-y))
-			'y move-resize-hints)))
+			'y move-resize-hints))
+                 (when (or min-aspect max-aspect)
+                   (setq move-resize-width
+                         (constrain-aspect-to-hints
+                          move-resize-height
+                          move-resize-old-width 'y min-aspect max-aspect)))
+                 )
 		((memq 'top move-resize-moving-edges)
 		 (setq move-resize-height
 		       (constrain-dimension-to-hints
 			(+ move-resize-old-height
 			   (- move-resize-old-ptr-y ptr-y))
 			'y move-resize-hints))
+                 (when (or min-aspect max-aspect)
+                   (setq move-resize-width
+                         (constrain-aspect-to-hints
+                          move-resize-height
+                          move-resize-old-width 'y min-aspect max-aspect)))
 		 (setq move-resize-y (- move-resize-old-y
 					(- move-resize-height
 					   move-resize-old-height)))))

Community's reasons for inclusion or rejection[]

Patch submitters, please vote also! Yes, obviously your vote will be positive, but it's the place to give your explanation why this patch is good for all Sawfish users, and why it is correct - good reasons for inclusion.

When voting anonymously please write your name, so that it can be associated with your posts on the mailing list. If you are logged in you can sign yourself by typing four tilda characters: ~~~~.

  • Please vote with: Yes vote: yes., No vote: no., Try vote: let's try in experimental., Wtf vote: pondering. or Suspend wait for next release.
  • Yes vote: yes. As the author I'm biased, anyway I would like to hear comments on how to improve it; Metacity seems to change gravity according to the edge used to resize a window, for example setting north gravity when using the bottom edge. --Aav 13:47, 8 October 2008 (UTC)
Advertisement