PDA

View Full Version : Getting String Restriction Dbus


Guest
December 21st, 2006, 09:24 PM
I'm having some trouble getting dbus support into compiz-settings, the problem is with a string restriction I don't know how many restrictions there are so the dbus method i'm using at the moment doesn't work.

Here's how i'm getting a float restriction
CompOptionFloatRestriction * backend_get_float_restriction(gchar * plugin, gchar * screen, gchar * key) {

DBusGProxy *proxy;
GError *error;
gchar * dbus_path;
double MinValue;
double MaxValue;
double Precision;

dbus_path = g_strdup_printf("/org/freedesktop/compiz/%s/%s/%s", plugin, screen, key);

/* Create a proxy object for the dbus */
proxy = dbus_g_proxy_new_for_name (DbusConnection,
DbusDomain,
dbus_path,
DbusDomain);

/* Call ListNames method, wait for reply */
error = NULL;
if (!dbus_g_proxy_call (proxy, "getMetadata", &error, G_TYPE_INVALID,
G_TYPE_STRING, NULL,
G_TYPE_STRING, NULL,
G_TYPE_STRING, NULL,
G_TYPE_DOUBLE, &MinValue,
G_TYPE_DOUBLE, &MaxValue,
G_TYPE_DOUBLE, &Precision,
G_TYPE_INVALID))
{
dbus_error(error);
return NULL;
}


CompOptionFloatRestriction * float_restriction = malloc(sizeof(CompOptionFloatRestriction));
float_restriction->min = MinValue;
float_restriction->max = MaxValue;
float_restriction->precision = Precision;

g_free(dbus_path);
g_object_unref (proxy);

return float_restriction;
}

This works fine because i know there is only going to be min, max and precision options. Is their a way to get the options without knowing how many there are? i.e. put them in an array or something?

Guest
December 21st, 2006, 09:54 PM
Actually should the string restrictions not be returned in a dbus array? I think this is a problem with the dbus plugin.

then you can simply do
dbus_g_proxy_call (proxy, "getMetadata", &error, G_TYPE_INVALID,
G_TYPE_STRV, &name_list, G_TYPE_INVALID)

Amaranth
December 21st, 2006, 11:31 PM
http://dbus.freedesktop.org/doc/dbus/api/html/group__DBusMessage.html#g974a0f898df186afc6b61c976 b4d84b5

This appears to be what you need. It sucks, I know.

mikedee
December 22nd, 2006, 12:06 AM
Ill sort out a patch for you to work from, I already have the code to send an array or a dictionary so it will not take long.

Are there any other functions you need that are not in current git?

mikedee
December 27th, 2006, 02:13 AM
Here it is, I have checked it briefly and it seems to work, you probably want to test it for ones without restrictions.

If everything is OK then Ill see if it can be accepted on the mailing list.

Its all in a self contained package, just untar and make install

http://www.anykeysoftware.co.uk/compiz/plugins/dbus-array.tar.gz

mikedee
December 28th, 2006, 02:05 PM
These changes are all in head now :)

Amaranth
December 28th, 2006, 02:05 PM
This just got committed in git, along with getPluginMetadata. :)

mikedee
December 28th, 2006, 02:14 PM
jinx ! :D

Amaranth
December 28th, 2006, 02:18 PM
Hehe, I was reading your mail when davidr's came in. Oh, and I guess getPluginMetadata has been in there for awhile but it's been updated to output arrays too.

I think all we really need from dbus now is a way to access _all_ plugins instead of just active ones.

mikedee
December 28th, 2006, 02:33 PM
Oh, and I guess getPluginMetadata has been in there for awhile but it's been updated to output arrays too.

Nah - its a new one, its only been there a few days :)

I think all we really need from dbus now is a way to access _all_ plugins instead of just active ones.

All of this is 'in the works', also reading and changing settings with dbus when compiz is not running should be on its way (no idea when though - its fairly low priority and might need some major structural changes to how compiz starts)

Guest
December 28th, 2006, 08:07 PM
Just for reference here's how you get a dbus array from an iter (it took me a while to figure this out so it might save some a bit of time)

GSList * get_string_list(DBusMessageIter *iter)
{
GSList * list = NULL;

while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
const char *value;
char *t;
dbus_message_iter_get_basic(iter, &value);
t = g_strdup(value);
list = g_slist_append(list, t);
dbus_message_iter_next(iter);
}

return list;
}

if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY) {
GSList * list = NULL;
DBusMessageIter sub_iter;
dbus_message_iter_recurse(&iter, &sub_iter);
list = (gpointer *) get_string_list(&sub_iter);
}