[compiz] Edge + Mouse button draft patches

Mike Dransfield mike at blueroot.co.uk
Mon Oct 16 03:55:44 PDT 2006


Attached are my draft patches to add edge + mouse button to the
actions

It is useful because the edge bindings are too easily triggered, an edge +
mouse button is good because it confirms the action.  An additional side
benefit is that the mouse wheel can be used for rotating the cube and for
the switcher (it is an excellent alternative to alt-tab).

I wanted to share the patches before cleaning them up because I wanted
to check if there were any problems that I have missed.

The only problem that I can see is that if you want to have the default
edge-only action then you have to set the button to Button0 (does
anyone have a Button0?), this is because of the way compiz deals
with the button bindings.  I do not mind this limitation too much
but I would like to hear if I am doing something wrong.
-------------- next part --------------
diff --git a/include/compiz.h b/include/compiz.h
index 61a9de5..f3c6e6c 100644
--- a/include/compiz.h
+++ b/include/compiz.h
@@ -751,6 +751,8 @@ struct _CompDisplay {
 
     HandleEventProc handleEvent;
 
+    unsigned int mouseOnEdge;
+
     CompPrivate *privates;
 };
 
-------------- next part --------------
diff --git a/src/event.c b/src/event.c
index 2d182be..b228dde 100644
--- a/src/event.c
+++ b/src/event.c
@@ -266,12 +266,18 @@ triggerButtonPressBindings (CompDisplay 
 	{
 	    if (action->button.button == event->xbutton.button)
 	    {
-		bindMods = virtualToRealModMask (d, action->button.modifiers);
+		/* if it has an edge mask set then make sure the mouse 
+		   is on that corner as well */
+		if (!option->value.action.edgeMask ||
+		    (option->value.action.edgeMask & d->mouseOnEdge))
+		{
+		    bindMods = virtualToRealModMask (d, action->button.modifiers);
 
-		if ((bindMods & modMask) == (event->xbutton.state & modMask))
-		    if ((*action->initiate) (d, action, state,
-					     argument, nArgument))
-			return TRUE;
+		    if ((bindMods & modMask) == (event->xbutton.state & modMask))
+		        if ((*action->initiate) (d, action, state,
+			  		         argument, nArgument))
+			    return TRUE;
+		}
 	    }
 	}
 
@@ -556,6 +562,9 @@ isEdgeEnterAction (CompOption      *opti
     if (!option->value.action.initiate)
 	return FALSE;
 
+    if (option->value.action.button.button)
+	return FALSE;
+
     *action = &option->value.action;
 
     return TRUE;
@@ -802,6 +811,8 @@ handleActionEvent (CompDisplay *d,
 		    }
 		}
 
+                d->mouseOnEdge = 0;
+
 		edgeWindow = None;
 
 		o[0].value.i = event->xcrossing.window;
@@ -844,6 +855,8 @@ handleActionEvent (CompDisplay *d,
 
 	    if (edge)
 	    {
+                d->mouseOnEdge = edge;
+
 		state = CompActionStateInitEdge;
 
 		edgeWindow = event->xcrossing.window;
-------------- next part --------------
diff --git a/plugins/rotate.c b/plugins/rotate.c
index 152e1d6..6952722 100644
--- a/plugins/rotate.c
+++ b/plugins/rotate.c
@@ -1774,6 +1774,7 @@ rotateDisplayInitOptions (RotateDisplay 
     o->value.action.state	 |= CompActionStateInitKey;
     o->value.action.state	 |= CompActionStateInitButton;
     o->value.action.type	  = CompBindingTypeKey;
+    o->value.action.button.button = 0;
     o->value.action.key.modifiers = ROTATE_RIGHT_MODIFIERS_DEFAULT;
     o->value.action.key.keycode   =
 	XKeysymToKeycode (display,
@@ -1902,6 +1903,7 @@ #define ROTATE_TO_OPTION(n)						 \
     o->value.action.initiate	  = rotateEdgeFlipLeft;
     o->value.action.terminate	  = rotateFlipTerminate;
     o->value.action.bell	  = FALSE;
+    o->value.action.button.button = 0;
     o->value.action.edgeMask	  = 1 << SCREEN_EDGE_LEFT;
     o->value.action.state	  = CompActionStateInitEdge;
     o->value.action.state	 |= CompActionStateInitEdgeDnd;
@@ -1918,6 +1920,7 @@ #define ROTATE_TO_OPTION(n)						 \
     o->value.action.initiate	  = rotateEdgeFlipRight;
     o->value.action.terminate	  = rotateFlipTerminate;
     o->value.action.bell	  = FALSE;
+    o->value.action.button.button = 0;
     o->value.action.edgeMask	  = 1 << SCREEN_EDGE_RIGHT;
     o->value.action.state	  = CompActionStateInitEdge;
     o->value.action.state	 |= CompActionStateInitEdgeDnd;
-------------- next part --------------
diff --git a/plugins/scale.c b/plugins/scale.c
index 7095c2d..94e4258 100644
--- a/plugins/scale.c
+++ b/plugins/scale.c
@@ -1075,11 +1075,14 @@ scaleInitiate (CompDisplay     *d,
 		damageScreen (s);
 	    }
 
-	    if (state & CompActionStateInitButton)
-		action->state |= CompActionStateTermButton;
+	    if (!(action->edgeMask & d->mouseOnEdge))
+	    {
+	        if (state & CompActionStateInitButton)
+		    action->state |= CompActionStateTermButton;
 
-	    if (state & CompActionStateInitKey)
-		action->state |= CompActionStateTermKey;
+	        if (state & CompActionStateInitKey)
+		    action->state |= CompActionStateTermKey;
+	    }
 	}
     }
 
@@ -1372,9 +1375,11 @@ scaleDisplayInitOptions (ScaleDisplay *s
     o->value.action.terminate	  = scaleTerminate;
     o->value.action.bell	  = FALSE;
     o->value.action.edgeMask	  = (1 << SCREEN_EDGE_TOPRIGHT);
-    o->value.action.state	  = CompActionStateInitEdge;
     o->value.action.type	  = CompBindingTypeKey;
+    o->value.action.state	  = CompActionStateInitEdge;
     o->value.action.state	 |= CompActionStateInitKey;
+    o->value.action.state	 |= CompActionStateInitButton;
+    o->value.action.button.button = 3;
     o->value.action.key.modifiers = SCALE_INITIATE_MODIFIERS_DEFAULT;
     o->value.action.key.keycode   =
 	XKeysymToKeycode (display,
-------------- next part --------------
diff --git a/plugins/switcher.c b/plugins/switcher.c
index f5808ee..e451325 100644
--- a/plugins/switcher.c
+++ b/plugins/switcher.c
@@ -931,11 +931,14 @@ switchNext (CompDisplay     *d,
 	{
 	    switchInitiate (s, FALSE);
 
-	    if (state & CompActionStateInitKey)
-		action->state |= CompActionStateTermKey;
+	    if (!(action->edgeMask & d->mouseOnEdge))
+	    {
+	        if (state & CompActionStateInitKey)
+		    action->state |= CompActionStateTermKey;
 
-	    if (state & CompActionStateInitButton)
-		action->state |= CompActionStateTermButton;
+	        if (state & CompActionStateInitButton)
+		    action->state |= CompActionStateTermButton;
+	    }
 	}
 
 	switchToWindow (s, TRUE);
@@ -965,11 +968,14 @@ switchPrev (CompDisplay     *d,
 	{
 	    switchInitiate (s, FALSE);
 
-	    if (state & CompActionStateInitKey)
-		action->state |= CompActionStateTermKey;
+	    if (!(action->edgeMask & d->mouseOnEdge))
+	    {
+	        if (state & CompActionStateInitKey)
+		    action->state |= CompActionStateTermKey;
 
-	    if (state & CompActionStateInitButton)
-		action->state |= CompActionStateTermButton;
+	        if (state & CompActionStateInitButton)
+		    action->state |= CompActionStateTermButton;
+	    }
 	}
 
 	switchToWindow (s, FALSE);
@@ -1871,12 +1877,15 @@ switchDisplayInitOptions (SwitchDisplay 
     o->value.action.initiate	  = switchNext;
     o->value.action.terminate	  = switchTerminate;
     o->value.action.bell	  = FALSE;
-    o->value.action.edgeMask	  = 0;
+    o->value.action.edgeMask	  = (1 << SCREEN_EDGE_TOP);
     o->value.action.state	  = CompActionStateInitKey;
     o->value.action.state	 |= CompActionStateInitButton;
+    o->value.action.state	 |= CompActionStateInitEdge;
+    o->value.action.state	 |= CompActionStateTermEdge;
     o->value.action.type	  = CompBindingTypeKey;
+    o->value.action.button.button = 5;
     o->value.action.key.modifiers = SWITCH_NEXT_MODIFIERS_DEFAULT;
-    o->value.action.key.keycode   =
+    o->value.action.key.keycode   = 
 	XKeysymToKeycode (display,
 			  XStringToKeysym (SWITCH_NEXT_KEY_DEFAULT));
 
@@ -1889,10 +1898,13 @@ switchDisplayInitOptions (SwitchDisplay 
     o->value.action.initiate	  = switchPrev;
     o->value.action.terminate	  = switchTerminate;
     o->value.action.bell	  = FALSE;
-    o->value.action.edgeMask	  = 0;
+    o->value.action.edgeMask	  = (1 << SCREEN_EDGE_TOP);
     o->value.action.state	  = CompActionStateInitKey;
     o->value.action.state	 |= CompActionStateInitButton;
+    o->value.action.state	 |= CompActionStateInitEdge;
+    o->value.action.state	 |= CompActionStateTermEdge;
     o->value.action.type	  = CompBindingTypeKey;
+    o->value.action.button.button = 4;
     o->value.action.key.modifiers = SWITCH_PREV_MODIFIERS_DEFAULT;
     o->value.action.key.keycode   =
 	XKeysymToKeycode (display,


More information about the compiz mailing list