Hi there,

Being a long term tiling WM user switching to Unity, I found Grid plugin be an appropriate alternative for full-featured tiling window manager on top of Compiz. However, it does not play well with most frequent use cases on not-so-big laptop screen: 4×4 fixed grid layout leaves very little spaces to any window. In most cases, I use different layout, where one window is about 2/3 of screen width or height and another window occupies the rest 1/3. For example, I often split my screen vertically (2:1) and use right part of the screen for IM and left one for browser or mail client. In other cases, I need horizontal 2:1 splitting (e.g. to have terminal emulator and some PDF documents open).

Current Grid implementation uses grid with equal-sized cells by default. Pressing the same key combination multiple times allows one to make a window 2/3 or 1/3 of the workspace width, but it can be not very convenient to cycle between these modes by pressing key several times, and it does not allow e.g. horizontal 2:1 splitting.

The same issues are discussed on the wiki:

http://wiki.compiz.org/Plugins/Grid:

 * Make the grid size reconfigurable instead of the fixed 33%,50%,66%
   sizes (ie. Maybe an even better option is to retain the 2x3 grid,
   but allow the user to specify how big the grid blocks are.)
 * Perhaps assign a layout per workspace or hotkey to switch between
   grid sizes
 * Keyboard shortcuts to switch focus based on window position
 * In addition to the horizontal 1/2 and 2/3 cycle, it would be great
   to have a vertical 1/3 and 2/3 cycle. -- Unfortunately that gives a
   cycle of length 9 when combined with the horizontal cycle. Unless
   you can think of better shortcut keys.


So I believe that possibility to control the layout will be useful. The easiest way to do it is to control the relative width and height of one (e.g. left top) cell. If the user prefer 2:1 horizontal splitting and 1:1 vertical splitting, they can adjust this cell to be 66% wide and 50% tall, and so on.

The proposed patch implements this approach, adding two new options: relative width of left top cell and its relative height. Given that numbers, we calculate corresponding grid coordinates and use them when asked to send a window to a particular cell.

I'll be very grateful for the review.

--
Sincerely yours,
Ilya V. Schurov.
>From fae76cf0571e548d605869ba5b60e4d21ff20071 Mon Sep 17 00:00:00 2001
From: "Ilya V. Schurov" <[email protected]>
Date: Thu, 5 Apr 2012 00:15:49 +0400
Subject: [PATCH] Adding an option to control relative sizes of grid cells

---
 grid.xml.in  |   17 +++++++++++++++++
 src/grid.cpp |   49 +++++++++++++++++++++++++++++++++++++++++--------
 src/grid.h   |   17 +++++++++++++++++
 3 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/grid.xml.in b/grid.xml.in
index 97917e5..c2f447f 100644
--- a/grid.xml.in
+++ b/grid.xml.in
@@ -559,6 +559,23 @@
 			    <alpha>0x4f4f</alpha>
 			</default>
 		</option>
+	   </group>
+	   <group>
+	   	<_short>Layout</_short>
+		<option name="main_cell_width" type="int">
+			<_short>Main cell width</_short>
+			<_long>Width of the main (left top) cell, in percentages</_long>
+			<default>50</default>
+			<min>0</min>
+			<max>100</max>
+		</option>
+		<option name="main_cell_height" type="int">
+			<_short>Main cell height</_short>
+			<_long>Height of the main (left top) cell, in percentages</_long>
+			<default>50</default>
+			<min>0</min>
+			<max>100</max>
+		</option>
 	    </group>
 	</options>
     </plugin>
diff --git a/src/grid.cpp b/src/grid.cpp
index 1cae228..9937a7e 100644
--- a/src/grid.cpp
+++ b/src/grid.cpp
@@ -43,6 +43,9 @@ static const GridProps gridProps[] =
     {0,0, 1,1},
 };
 
+
+
+
 CompRect
 GridScreen::slotToRect (CompWindow      *w,
 			const CompRect& slot)
@@ -123,12 +126,41 @@ GridScreen::initiateCommon (CompAction         *action,
 {
     Window     xid;
     CompWindow *cw = 0;
-
+	
     xid = CompOption::getIntOptionNamed (option, "window");
     cw  = screen->findWindow (xid);
 
     if (where == GridUnknown || screen->otherGrabExist ("move", NULL))
-	return false;
+	    return false;
+
+    /* relative width and height of the main (left top) cell
+     * as a double number from 0 to 1 
+     */
+    double mcWidth=optionGetMainCellWidth()/100.;
+    double mcHeight=optionGetMainCellHeight()/100.;
+
+    double scWidth=1-mcWidth;
+    double scHeight=1-mcHeight;
+
+    GridCellRelative gridCellsRelative[]=
+    {
+	{0,0,1,1},
+
+	{0,       mcHeight, mcWidth,scHeight},
+	{0,       mcHeight, 1,      scHeight},
+	{mcWidth, mcHeight, scWidth,scHeight},
+
+
+	{0,       0, mcWidth,  1},
+	{0,       0, 1,        1},
+	{mcWidth, 0, scWidth,  1},
+
+	{0,       0, mcWidth,  mcHeight},
+	{0,       0, 1,        mcHeight},
+	{mcWidth, 0, scWidth,  mcHeight},
+
+	{0,0,1,1}
+    };
 
     if (cw)
     {
@@ -140,6 +172,7 @@ GridScreen::initiateCommon (CompAction         *action,
 	    gw->resizeCount = 0;
 
 	props = gridProps[where];
+	GridCellRelative cellRel=gridCellsRelative[where];
 
 	/* get current available area */
 	if (cw == mGrabWindow)
@@ -190,12 +223,12 @@ GridScreen::initiateCommon (CompAction         *action,
 	 */
 
 	/* slice and dice to get desired slot - including decorations */
-	desiredSlot.setY (workarea.y () + props.gravityDown *
-			  (workarea.height () / props.numCellsY));
-	desiredSlot.setHeight (workarea.height () / props.numCellsY);
-	desiredSlot.setX (workarea.x () + props.gravityRight *
-			  (workarea.width () / props.numCellsX));
-	desiredSlot.setWidth (workarea.width () / props.numCellsX);
+	desiredSlot.setY (workarea.y () + cellRel.top *
+			  workarea.height () );
+	desiredSlot.setHeight (workarea.height () * cellRel.height);
+	desiredSlot.setX (workarea.x () + cellRel.left *
+			  (workarea.width ()));
+	desiredSlot.setWidth (workarea.width () * cellRel.width);
 
 	/* Adjust for constraints and decorations */
 	desiredRect = constrainSize (cw, desiredSlot);
diff --git a/src/grid.h b/src/grid.h
index a1d8ad7..1f3e185 100644
--- a/src/grid.h
+++ b/src/grid.h
@@ -32,6 +32,12 @@
 
 #define SNAPOFF_THRESHOLD 50
 
+/* cheet sheet:
+ * 0
+ * 7 8 9
+ * 4 5 6
+ * 1 2 3
+ */
 typedef enum
 {
     GridUnknown = 0,
@@ -55,6 +61,17 @@ typedef struct _GridProps
     int numCellsY;
 } GridProps;
 
+/* this struct defines a cell in a relative coordinates
+ * it's elements are numbers from 0 to 1
+ */
+typedef struct _GridCellRelative
+{
+    double left;
+    double top;
+    double width;
+    double height;
+} GridCellRelative;
+	
 enum Edges
 {
     NoEdge = 0,
-- 
1.7.9.1

_______________________________________________
dev mailing list
[email protected]
http://lists.compiz.org/mailman/listinfo/dev

Reply via email to