PDA

View Full Version : [dbus?] Accessing more advanced functionality


murb
April 19th, 2007, 03:56 PM
Currently I am working on a project for which it would be nice to have access to the function responsible for actual turning the cube in small steps. I would like to control the cube from an external program, just as I am able to do with my mouse by <Control><Alt>+Dragging the mouse ('Initiate rotation'). I probably will implement it in the python language, since my knowledge of C is falling short a bit :s . My problem is not really talking using dbus to compiz, but the fact that the function that I am looking for is not documented.

so using dsend.sh (

dbus-send --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/$1/allscreens/$2 org.freedesktop.compiz.activate string:'root' int32:`xwininfo -root | grep id: | awk '{ print $4 }'` $3 $4 $5 $6 $7 $8 $9

), I am able to e.g. rotate the screen 90 degrees to the left:

./dsend.sh rotate rotate_right


still what I would need is a function that is able to to set the cube in an intermediate position, something like e.g.:


./dsend.sh rotate rotate_to string:'angle' int32:43


which would then result in a rotation to 43 degrees to, euh, right for example. Anyhow, I am looking for something that could give me this type of access to the cube's rotation state. And then probably some 'stop initiate rotation' function, which would position the cube correctly, making it usable again for normal interaction on one of the faces nearby.

I have tried browsing the source code in order to find this functionality, but... well I got kind of lost in the code... so. Help is greatly appreciated!

Recommending another approach is no problem at all (since my approach accessing from an external program), may not be the best one. But then still I would kind of like to know in which direction I should be looking.

Thank you very much in forward.

bellansy
July 17th, 2007, 10:03 AM
Just to tell I'm exactly searching the same way of controling the cube, it could really be interesting
murb, could you let me know if you've find a way.
Thank you!

RYX
July 17th, 2007, 11:00 AM
The "rotate_to_angle"-function needs to be added to the cube-plugin and has to be set as a new CompAction, then you can call it over dbus similar to the other functions (rotate_to, rotate_left, ...). I think it shouldn't be that difficult to understand by looking at how the other initiate-functions are written ...

The only thing you need to keep in mind is that you first have to implement the functions you want to call over dbus, then make them available as CompOptions of type CompAction, then you can call them over dbus (if you have dbus-plugin loaded).

:)

bellansy
July 17th, 2007, 12:18 PM
unfortunately I'm not a compiz developer, just a python developper wanting to interact with compiz :s
So even if I see what should be done in theory, I think I will loose a lot of time only to compile even an existing example :s
Do you think this dbus link with the function will be integrated in a future relaese?
Thank you by advance !!

RYX
July 17th, 2007, 01:09 PM
I am only a script-coder myself and I have very limited skills in coding C, otherwise I could help you with that. I am not sure if anyone will implement such a function sooner or later, but it should be fairly easy to do.

The availability through dbus exists automatically (through the dbus-plugin's magic) once you have created the function and defined an action which uses the function as its initiate-method. It sounds a bit more difficult than it is :) ...

The only thing you need to find out is how to tell the cube to move to a certain angle, which shouldn't be difficult as well. The cube-sourcecode is a real monster, but you only need to check the initiate-functions (you can safely ignore al gl*-calls)and then base your own function on that. If the function works, it would maybe even make its way upstream - who knows.

However - I'd understand if you simply wait for someone to implement it :D ...

mikedee
July 17th, 2007, 03:13 PM
There is probably not much chance of this being accepted to the rotate plugin because its not much use in that context.

The good news is that it would be very very easy to write a plugin yourself which provides this function. Its only one simple function, you just have to wrap the cube getRotation method.

You can do this in either C or Python, the method will automatically be available via dbus, the x and v angles can be read in the options that are passed to the action initiate function.

See rot.py in the python plugin for more info, just copy and paste it then modify to read the values in the rotInitiate function. The principle is the same in C except you set the x and v by reference rather than returning them as an array.

zebulon
July 18th, 2007, 11:03 AM
I'm also interesting in such a way to control the cube !

I actually use dsend.sh to control the rotation of the cube but I'd prefer to do it directly via dbus.

Could you tell me a bit more about how to do ?
I don't understand why the "activate method" is not accessible via dbus-viewer and so I can't invoke it.
My example is:

with dsend:
dbus-send --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/rotate/allscreens/rotate_to org.freedesktop.compiz.activate string:'root' int32:`xwininfo -root |grep id: | awk '{ print $4 }'` string:'face' int32:1

with java:
Bus: org.freedesktop.org
Object: /org/freedesktop/compiz/rotate/allscreens/rotate_to

compiz b = (compiz) conn.getRemoteObject("org.freedesktop.compiz","/org/freedesktop/compiz/rotate/allscreens/rotate_to", compiz.class);
compiz.activate ????? //how to call it ??

compiz.java[class] is the java interface which binds the dbus methods

PS: I use dbus-java bindings to do so. I successfully use dbus-java to control other dbus application

Thanks for your help!

zebulon
July 18th, 2007, 03:25 PM
I auto reply me
I've finally add a new method in compiz.java
The prototype is :
/**
* @param a "root"
* @param b xwininfo -root |grep id: | awk '{ print $4 }'
* @param c "face"
* @param d 1,2,3 ...
*/
public void activate(String a, int b, String c, int d);

Just call it with for example:
b.activate("root", 77, "face", 0) and the cube rotate !!!

Hope this help

But unfortunately I can't specify the angle ...