View Full Version : Mouse Gestures plugin
mikedee
November 17th, 2006, 05:15 PM
Here is a very basic mouse gestures plugin. There are 8 different gestures, up down left right and the diagonals. The default binding is Shift + Super + right mouse button (button 3).
The default mouse gestures are rotate right and left attched to mouse left and mouse right.
To change the actions, enter the correct plugin and action name to initiate. eg if you want the down gesture to be show desktop then change these options like this.
down_plugin = showdesktop
down_action = initiate
You will need to experiment with different actions, some may not work but most should (rotate_right_window doesnt work, but put_viewport_right will work - this gives you a throw window to next viewport type of effect)
I have intentionally kept it simple, the browser gestures seem over complicated to me.
http://www.anykeysoftware.co.uk/compiz/plugins/mousegestures.tar.gz
RYX
November 17th, 2006, 05:28 PM
Cool - I quickly read through the code and it looks good. Will try it later ...
I have created something similar in flash/actionscript some time ago and used a slightly different way of recognizing gestures:
- During the mouse is moved and the hotkey is active, I read the current position in certain intervals and check them for directional changes
- The directional changes are then saved in a string like "L R B B L TL"
- Whenever the mousebutton is released and pressed again, another gesture is started (so they can be combined together) until the hotkey is released
- The string also contains an indicator for the position of a gesture related to the last one (so if it was above, below, ...)
- Finally you have a string like "L:RBRLL: LTRT_LR" (fictional) which can be used as a "code" to be assigned to any action ...
It was only an experiment but it worked really well. If I can find the AS-code, I'll post it here ...
:)
Haisen
November 17th, 2006, 05:48 PM
As a user of All-in-One Gesture (http://perso.orange.fr/marc.boullet/ext/extensions-en.html), I'm really interessed in this plugin.
Thanks mikedee.
mikedee
November 17th, 2006, 06:28 PM
I originally looked at writing this to track the mouse position by reading XEvents and then storing the differences and adding them to a variable then reading them on deactivation (ie. mouse up).
I quickly decided to make it very simple for a few reasons.
1. I am a simple type of guy, I don't ask for much :)
2. That method would require a lot of memory allocation, string manipulation etc etc, I am still a beginner in C and I thought that it would end up buggy and crashy. This method is fairly bug free (well, should be).
3. I thought that this plugin could be used by other developers to help them learn, it has a few important features including reading the mouse position, demonstrating how to use the deactivate method (you need to add CompActionStateTermButton to the action state mask) and working with other plugins.
I would be more than happy to rename this one or just use it as an example if someone wanted to write a more complicated version. My future plans for this are to include core actions like close/max/minimize window etc and maybe to make it easier to cancel an action, that is one benefit for me of the complicated system.
In case anyone is interested, my initial version was wrapping the handleEvent and looking out for MotionNotify events, for some reason these events are only passed through when the window is being moved. I am not sure if I was doing something wrong or if it is a feature. My solution was to wrap the donePaintScreen function and then call the mouse functions here.
RYX
November 17th, 2006, 07:31 PM
What I proposed sounds more difficult than it actually is. And I don't like complicated stuff, either ... but drawing Z/N/T-shaped gestures is really cool. The directional changes simply need to get connected with lines to show the gesture on the screen. Maybe I can find the time to extend your plugin (somewhen).
And I think the problem with the MotionNotify-event is that compiz itself hasn't registered for the needed event-mask (due to performance issues?) ... there is some option to retrieve more frequent notfiy-events, but I'd rather use an interval-function (a setInterval-function would be a useful addition to the core anyway ...) that gets the current position any 100ms and gets cleared when the "hotkey" is released (and started when its pressed).
:)
mikedee
November 17th, 2006, 07:43 PM
a setInterval-function would be a useful addition to the core anyway ...
CompTimeoutHandle
compAddTimeout (int time,
CallBackProc callBack,
void *closure);
void
compRemoveTimeout (CompTimeoutHandle handle);
;)
RYX
November 17th, 2006, 07:52 PM
Yes, I know the timeout. :)
It only runs once after a given timeout and then exits. What I mean with a setInterval-function is a function like "setInterval(interval, callback, args)" that executes callback with args after each interval milliseconds ... until the judgement day if not cleared ... (so like in DOM-JavaScript)
:)
mikedee
November 30th, 2006, 04:03 PM
Just a quick note to say I have updated this to have more than 1 stroke per gesture. I will still keep this simple one here for a while in case anyone wants it but I recommend the newer one.
http://forum.go-compiz.org/viewtopic.php?t=143
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.