diff options
author | David Reveman <davidr@novell.com> | 2007-09-04 14:02:55 -0400 |
---|---|---|
committer | David Reveman <davidr@novell.com> | 2007-09-04 14:02:55 -0400 |
commit | fc1bbc90c6dbf57303c3a234ddf9c149379df15e (patch) | |
tree | dd252f511fd654ab4c106c78186b1607cc33b7da /plugins | |
parent | 36b283d33788e3d3899294704029a206e9c1943a (diff) |
Remove setDisplayOptionForPlugin and setScreenOptionForPlugin
functions. Add setOptionForPlugin to core object.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/cube.c | 85 | ||||
-rw-r--r-- | plugins/dbus.c | 589 | ||||
-rw-r--r-- | plugins/fuse.c | 195 | ||||
-rw-r--r-- | plugins/gconf.c | 427 | ||||
-rw-r--r-- | plugins/ini.c | 383 | ||||
-rw-r--r-- | plugins/kconfig.cpp | 441 |
6 files changed, 738 insertions, 1382 deletions
diff --git a/plugins/cube.c b/plugins/cube.c index fdcac107..581542b5 100644 --- a/plugins/cube.c +++ b/plugins/cube.c @@ -65,6 +65,7 @@ v[3] /= v[3]; static CompMetadata cubeMetadata; +static int cubeCorePrivateIndex; static int cubeDisplayPrivateIndex; #define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption)) @@ -1942,23 +1943,30 @@ cubeOutputChangeNotify (CompScreen *s) } static Bool -cubeSetScreenOptionForPlugin (CompScreen *s, - const char *plugin, - const char *name, - CompOptionValue *value) +cubeSetOptionForPlugin (CompObject *o, + const char *plugin, + const char *name, + CompOptionValue *value) { Bool status; - CUBE_SCREEN (s); + CUBE_CORE (&core); - UNWRAP (cs, s, setScreenOptionForPlugin); - status = (*s->setScreenOptionForPlugin) (s, plugin, name, value); - WRAP (cs, s, setScreenOptionForPlugin, cubeSetScreenOptionForPlugin); + UNWRAP (cc, &core, setOptionForPlugin); + status = (*core.setOptionForPlugin) (o, plugin, name, value); + WRAP (cc, &core, setOptionForPlugin, cubeSetOptionForPlugin); - if (status && strcmp (plugin, "core") == 0 && strcmp (name, "hsize") == 0) + if (status && o->type == COMP_OBJECT_TYPE_SCREEN) { - cubeUpdateGeometry (s, s->hsize, cs->invert); - cubeUnloadBackgrounds (s); + if (strcmp (plugin, "core") == 0 && strcmp (name, "hsize") == 0) + { + CompScreen *s = (CompScreen *) o; + + CUBE_SCREEN (s); + + cubeUpdateGeometry (s, s->hsize, cs->invert); + cubeUnloadBackgrounds (s); + } } return status; @@ -2001,6 +2009,46 @@ cubeSetDisplayOption (CompPlugin *plugin, return FALSE; } +static Bool +cubeInitCore (CompPlugin *p, + CompCore *c) +{ + CubeCore *cc; + + if (!checkPluginABI ("core", CORE_ABIVERSION)) + return FALSE; + + cc = malloc (sizeof (CubeCore)); + if (!cc) + return FALSE; + + cubeDisplayPrivateIndex = allocateDisplayPrivateIndex (); + if (cubeDisplayPrivateIndex < 0) + { + free (cc); + return FALSE; + } + + WRAP (cc, &core, setOptionForPlugin, cubeSetOptionForPlugin); + + c->object.privates[cubeCorePrivateIndex].ptr = cc; + + return TRUE; +} + +static void +cubeFiniCore (CompPlugin *p, + CompCore *c) +{ + CUBE_CORE (c); + + UNWRAP (cc, &core, setOptionForPlugin); + + freeDisplayPrivateIndex (cubeDisplayPrivateIndex); + + free (cc); +} + static const CompMetadataOptionInfo cubeDisplayOptionInfo[] = { { "abi", "int", 0, 0, 0 }, { "index", "int", 0, 0, 0 }, @@ -2017,9 +2065,6 @@ cubeInitDisplay (CompPlugin *p, { CubeDisplay *cd; - if (!checkPluginABI ("core", CORE_ABIVERSION)) - return FALSE; - cd = malloc (sizeof (CubeDisplay)); if (!cd) return FALSE; @@ -2189,7 +2234,6 @@ cubeInitScreen (CompPlugin *p, WRAP (cs, s, paintBackground, cubePaintBackground); WRAP (cs, s, paintWindow, cubePaintWindow); WRAP (cs, s, applyScreenTransform, cubeApplyScreenTransform); - WRAP (cs, s, setScreenOptionForPlugin, cubeSetScreenOptionForPlugin); WRAP (cs, s, outputChangeNotify, cubeOutputChangeNotify); WRAP (cs, s, initWindowWalker, cubeInitWindowWalker); @@ -2212,7 +2256,6 @@ cubeFiniScreen (CompPlugin *p, UNWRAP (cs, s, paintBackground); UNWRAP (cs, s, paintWindow); UNWRAP (cs, s, applyScreenTransform); - UNWRAP (cs, s, setScreenOptionForPlugin); UNWRAP (cs, s, outputChangeNotify); UNWRAP (cs, s, initWindowWalker); @@ -2231,7 +2274,7 @@ cubeInitObject (CompPlugin *p, CompObject *o) { static InitPluginObjectProc dispTab[] = { - (InitPluginObjectProc) 0, /* InitCore */ + (InitPluginObjectProc) cubeInitCore, (InitPluginObjectProc) cubeInitDisplay, (InitPluginObjectProc) cubeInitScreen }; @@ -2244,7 +2287,7 @@ cubeFiniObject (CompPlugin *p, CompObject *o) { static FiniPluginObjectProc dispTab[] = { - (FiniPluginObjectProc) 0, /* FiniCore */ + (FiniPluginObjectProc) cubeFiniCore, (FiniPluginObjectProc) cubeFiniDisplay, (FiniPluginObjectProc) cubeFiniScreen }; @@ -2294,8 +2337,8 @@ cubeInit (CompPlugin *p) CUBE_SCREEN_OPTION_NUM)) return FALSE; - cubeDisplayPrivateIndex = allocateDisplayPrivateIndex (); - if (cubeDisplayPrivateIndex < 0) + cubeCorePrivateIndex = allocateCorePrivateIndex (); + if (cubeCorePrivateIndex < 0) { compFiniMetadata (&cubeMetadata); return FALSE; @@ -2309,7 +2352,7 @@ cubeInit (CompPlugin *p) static void cubeFini (CompPlugin *p) { - freeDisplayPrivateIndex (cubeDisplayPrivateIndex); + freeCorePrivateIndex (cubeCorePrivateIndex); compFiniMetadata (&cubeMetadata); } diff --git a/plugins/dbus.c b/plugins/dbus.c index 5e61f507..11d28bd9 100644 --- a/plugins/dbus.c +++ b/plugins/dbus.c @@ -59,27 +59,14 @@ static CompMetadata dbusMetadata; static int corePrivateIndex; typedef struct _DbusCore { - InitPluginForObjectProc initPluginForObject; -} DbusCore; - -static int displayPrivateIndex; - -typedef struct _DbusDisplay { - int screenPrivateIndex; - DBusConnection *connection; CompWatchFdHandle watchFdHandle; CompFileWatchHandle fileWatch[DBUS_FILE_WATCH_NUM]; - SetDisplayOptionForPluginProc setDisplayOptionForPlugin; - InitPluginForDisplayProc initPluginForDisplay; -} DbusDisplay; - -typedef struct _DbusScreen { - SetScreenOptionForPluginProc setScreenOptionForPlugin; - InitPluginForScreenProc initPluginForScreen; -} DbusScreen; + InitPluginForObjectProc initPluginForObject; + SetOptionForPluginProc setOptionForPlugin; +} DbusCore; static DBusHandlerResult dbusHandleMessage (DBusConnection *, DBusMessage *, @@ -96,28 +83,15 @@ static DBusObjectPathVTable dbusMessagesVTable = { #define DBUS_CORE(c) \ DbusCore *dc = GET_DBUS_CORE (c) -#define GET_DBUS_DISPLAY(d) \ - ((DbusDisplay *) (d)->object.privates[displayPrivateIndex].ptr) - -#define DBUS_DISPLAY(d) \ - DbusDisplay *dd = GET_DBUS_DISPLAY (d) - -#define GET_DBUS_SCREEN(s, dd) \ - ((DbusScreen *) (s)->object.privates[(dd)->screenPrivateIndex].ptr) - -#define DBUS_SCREEN(s) \ - DbusScreen *ds = GET_DBUS_SCREEN (s, GET_DBUS_DISPLAY (s->display)) - static CompOption * -dbusGetOptionsFromPath (CompDisplay *d, - char **path, - CompScreen **returnScreen, +dbusGetOptionsFromPath (char **path, + CompObject **returnObject, CompMetadata **returnMetadata, int *nOption) { - CompObject *object = &d->object; CompPlugin *p; + CompObject *object; if (strcmp (path[1], "allscreens")) { @@ -127,7 +101,7 @@ dbusGetOptionsFromPath (CompDisplay *d, if (sscanf (path[1], "screen%d", &screenNum) != 1) return FALSE; - for (s = d->screens; s; s = s->next) + for (s = compDisplays->screens; s; s = s->next) if (s->screenNum == screenNum) break; @@ -135,16 +109,15 @@ dbusGetOptionsFromPath (CompDisplay *d, return NULL; object = &s->object; - - if (returnScreen) - *returnScreen = s; } else { - if (returnScreen) - *returnScreen = NULL; + object = &compDisplays->object; } + if (returnObject) + *returnObject = object; + for (p = getPlugins (); p; p = p->next) if (strcmp (p->vTable->name, path[0]) == 0) break; @@ -274,8 +247,7 @@ dbusIntrospectEndRoot (xmlTextWriterPtr writer) /* introspection handlers */ static Bool dbusHandleRootIntrospectMessage (DBusConnection *connection, - DBusMessage *message, - CompDisplay *d) + DBusMessage *message) { char **plugins, **pluginName; int nPlugins; @@ -359,9 +331,8 @@ dbusHandleRootIntrospectMessage (DBusConnection *connection, static Bool dbusHandlePluginIntrospectMessage (DBusConnection *connection, - DBusMessage *message, - CompDisplay *d, - char **path) + DBusMessage *message, + char **path) { CompScreen *s; char screenName[256]; @@ -376,7 +347,7 @@ dbusHandlePluginIntrospectMessage (DBusConnection *connection, dbusIntrospectAddNode (writer, "allscreens"); - for (s = d->screens; s; s = s->next) + for (s = compDisplays->screens; s; s = s->next) { sprintf (screenName, "screen%d", s->screenNum); dbusIntrospectAddNode (writer, screenName); @@ -419,7 +390,6 @@ dbusHandlePluginIntrospectMessage (DBusConnection *connection, static Bool dbusHandleScreenIntrospectMessage (DBusConnection *connection, DBusMessage *message, - CompDisplay *d, char **path) { CompOption *option = NULL; @@ -439,7 +409,7 @@ dbusHandleScreenIntrospectMessage (DBusConnection *connection, dbusIntrospectEndInterface (writer); - option = dbusGetOptionsFromPath (d, path, NULL, NULL, &nOptions); + option = dbusGetOptionsFromPath (path, NULL, NULL, &nOptions); if (option) { while (nOptions--) @@ -486,7 +456,6 @@ dbusHandleScreenIntrospectMessage (DBusConnection *connection, static Bool dbusHandleOptionIntrospectMessage (DBusConnection *connection, DBusMessage *message, - CompDisplay *d, char **path) { CompOption *option; @@ -504,7 +473,7 @@ dbusHandleOptionIntrospectMessage (DBusConnection *connection, dbusIntrospectStartRoot (writer); dbusIntrospectStartInterface (writer); - option = dbusGetOptionsFromPath (d, path, NULL, NULL, &nOptions); + option = dbusGetOptionsFromPath (path, NULL, NULL, &nOptions); if (!option) { xmlFreeTextWriter (writer); @@ -678,14 +647,14 @@ dbusHandleOptionIntrospectMessage (DBusConnection *connection, static Bool dbusHandleActionMessage (DBusConnection *connection, DBusMessage *message, - CompDisplay *d, char **path, Bool activate) { + CompObject *object; CompOption *option; int nOption; - option = dbusGetOptionsFromPath (d, path, NULL, NULL, &nOption); + option = dbusGetOptionsFromPath (path, &object, NULL, &nOption); if (!option) return FALSE; @@ -700,6 +669,9 @@ dbusHandleActionMessage (DBusConnection *connection, if (!isActionOption (option)) return FALSE; + if (object->type != COMP_OBJECT_TYPE_DISPLAY) + return FALSE; + if (activate) { if (!option->value.action.initiate) @@ -812,14 +784,14 @@ dbusHandleActionMessage (DBusConnection *connection, if (activate) { - (*option->value.action.initiate) (d, + (*option->value.action.initiate) (GET_CORE_DISPLAY (object), &option->value.action, 0, argument, nArgument); } else { - (*option->value.action.terminate) (d, + (*option->value.action.terminate) (GET_CORE_DISPLAY (object), &option->value.action, 0, argument, nArgument); @@ -869,7 +841,7 @@ dbusTryGetValueWithType (DBusMessageIter *iter, } static Bool -dbusGetOptionValue (CompDisplay *display, +dbusGetOptionValue (CompObject *object, DBusMessageIter *iter, CompOptionType type, CompOptionValue *value) @@ -916,7 +888,7 @@ dbusGetOptionValue (CompDisplay *display, DBUS_TYPE_STRING, &s)) { - stringToKeyAction (display, s, &value->action); + stringToKeyAction (GET_CORE_DISPLAY (object), s, &value->action); return TRUE; } break; @@ -925,7 +897,8 @@ dbusGetOptionValue (CompDisplay *display, DBUS_TYPE_STRING, &s)) { - stringToButtonAction (display, s, &value->action); + stringToButtonAction (GET_CORE_DISPLAY (object), + s, &value->action); return TRUE; } break; @@ -997,14 +970,13 @@ dbusGetOptionValue (CompDisplay *display, static Bool dbusHandleSetOptionMessage (DBusConnection *connection, DBusMessage *message, - CompDisplay *d, char **path) { - CompScreen *s; + CompObject *object; CompOption *option; int nOption; - option = dbusGetOptionsFromPath (d, path, &s, NULL, &nOption); + option = dbusGetOptionsFromPath (path, &object, NULL, &nOption); if (!option) return FALSE; @@ -1027,7 +999,7 @@ dbusHandleSetOptionMessage (DBusConnection *connection, do { - if (dbusGetOptionValue (d, + if (dbusGetOptionValue (object, &aiter, option->value.list.type, &tmpValue)) @@ -1050,25 +1022,16 @@ dbusHandleSetOptionMessage (DBusConnection *connection, } else if (dbus_message_iter_init (message, &iter)) { - status = dbusGetOptionValue (d, &iter, option->type, &value); + status = dbusGetOptionValue (object, &iter, option->type, + &value); } if (status) { - if (s) - { - (*s->setScreenOptionForPlugin) (s, - path[0], - option->name, - &value); - } - else - { - (*d->setDisplayOptionForPlugin) (d, - path[0], - option->name, - &value); - } + (*core.setOptionForPlugin) (object, + path[0], + option->name, + &value); if (!dbus_message_get_no_reply (message)) { @@ -1097,7 +1060,7 @@ dbusHandleSetOptionMessage (DBusConnection *connection, } static void -dbusAppendSimpleOptionValue (CompDisplay *display, +dbusAppendSimpleOptionValue (CompObject *object, DBusMessage *message, CompOptionType type, CompOptionValue *value) @@ -1139,7 +1102,7 @@ dbusAppendSimpleOptionValue (CompDisplay *display, } break; case CompOptionTypeKey: - s = keyActionToString (display, &value->action); + s = keyActionToString ((CompDisplay *) object, &value->action); if (s) { dbus_message_append_args (message, @@ -1149,7 +1112,7 @@ dbusAppendSimpleOptionValue (CompDisplay *display, } break; case CompOptionTypeButton: - s = buttonActionToString (display, &value->action); + s = buttonActionToString ((CompDisplay *) object, &value->action); if (s) { dbus_message_append_args (message, @@ -1188,7 +1151,7 @@ dbusAppendSimpleOptionValue (CompDisplay *display, } static void -dbusAppendListOptionValue (CompDisplay *display, +dbusAppendListOptionValue (CompObject *object, DBusMessage *message, CompOptionType type, CompOptionValue *value) @@ -1244,7 +1207,8 @@ dbusAppendListOptionValue (CompDisplay *display, &value->list.value[i].s); break; case CompOptionTypeKey: - s = keyActionToString (display, &value->list.value[i].action); + s = keyActionToString ((CompDisplay *) object, + &value->list.value[i].action); if (s) { dbus_message_iter_append_basic (&listIter, sig[0], &s); @@ -1252,7 +1216,8 @@ dbusAppendListOptionValue (CompDisplay *display, } break; case CompOptionTypeButton: - s = buttonActionToString (display, &value->list.value[i].action); + s = buttonActionToString ((CompDisplay *) object, + &value->list.value[i].action); if (s) { dbus_message_iter_append_basic (&listIter, sig[0], &s); @@ -1297,18 +1262,18 @@ dbusAppendListOptionValue (CompDisplay *display, } static void -dbusAppendOptionValue (CompDisplay *d, +dbusAppendOptionValue (CompObject *object, DBusMessage *message, CompOptionType type, CompOptionValue *value) { if (type == CompOptionTypeList) { - dbusAppendListOptionValue (d, message, type, value); + dbusAppendListOptionValue (object, message, type, value); } else { - dbusAppendSimpleOptionValue (d, message, type, value); + dbusAppendSimpleOptionValue (object, message, type, value); } } @@ -1325,22 +1290,22 @@ dbusAppendOptionValue (CompDisplay *d, static Bool dbusHandleGetOptionMessage (DBusConnection *connection, DBusMessage *message, - CompDisplay *d, char **path) { - CompScreen *s; + CompObject *object; CompOption *option; int nOption = 0; DBusMessage *reply = NULL; - option = dbusGetOptionsFromPath (d, path, &s, NULL, &nOption); + option = dbusGetOptionsFromPath (path, &object, NULL, &nOption); while (nOption--) { if (strcmp (option->name, path[2]) == 0) { reply = dbus_message_new_method_return (message); - dbusAppendOptionValue (d, reply, option->type, &option->value); + dbusAppendOptionValue (object, reply, option->type, + &option->value); break; } @@ -1373,15 +1338,14 @@ dbusHandleGetOptionMessage (DBusConnection *connection, static Bool dbusHandleListMessage (DBusConnection *connection, DBusMessage *message, - CompDisplay *d, char **path) { - CompScreen *s; + CompObject *object; CompOption *option; int nOption = 0; DBusMessage *reply; - option = dbusGetOptionsFromPath (d, path, &s, NULL, &nOption); + option = dbusGetOptionsFromPath (path, &object, NULL, &nOption); reply = dbus_message_new_method_return (message); @@ -1414,16 +1378,15 @@ dbusHandleListMessage (DBusConnection *connection, static Bool dbusHandleGetMetadataMessage (DBusConnection *connection, DBusMessage *message, - CompDisplay *d, char **path) { - CompScreen *s; + CompObject *object; CompOption *option; int nOption = 0; DBusMessage *reply = NULL; CompMetadata *m; - option = dbusGetOptionsFromPath (d, path, &s, &m, &nOption); + option = dbusGetOptionsFromPath (path, &object, &m, &nOption); while (nOption--) { @@ -1441,7 +1404,7 @@ dbusHandleGetMetadataMessage (DBusConnection *connection, if (m) { - if (s) + if (object->type == COMP_OBJECT_TYPE_SCREEN) { shortDesc = compGetShortScreenOptionDescription (m, option); longDesc = compGetLongScreenOptionDescription (m, option); @@ -1546,8 +1509,7 @@ dbusHandleGetMetadataMessage (DBusConnection *connection, */ static Bool dbusHandleGetPluginsMessage (DBusConnection *connection, - DBusMessage *message, - CompDisplay *d) + DBusMessage *message) { DBusMessage *reply; char **plugins, **p; @@ -1594,8 +1556,7 @@ dbusHandleGetPluginsMessage (DBusConnection *connection, */ static Bool dbusHandleGetPluginMetadataMessage (DBusConnection *connection, - DBusMessage *message, - CompDisplay *d) + DBusMessage *message) { DBusMessage *reply; DBusMessageIter iter; @@ -1708,9 +1669,8 @@ dbusHandleMessage (DBusConnection *connection, DBusMessage *message, void *userData) { - CompDisplay *d = (CompDisplay *) userData; - Bool status = FALSE; - char **path; + Bool status = FALSE; + char **path; if (!dbus_message_get_path_decomposed (message, &path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -1724,10 +1684,11 @@ dbusHandleMessage (DBusConnection *connection, /* root messages */ if (!path[3]) { - if (dbus_message_is_method_call (message, DBUS_INTERFACE_INTROSPECTABLE, + if (dbus_message_is_method_call (message, + DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) { - if (dbusHandleRootIntrospectMessage (connection, message, d)) + if (dbusHandleRootIntrospectMessage (connection, message)) { dbus_free_string_array (path); return DBUS_HANDLER_RESULT_HANDLED; @@ -1736,7 +1697,7 @@ dbusHandleMessage (DBusConnection *connection, else if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE, COMPIZ_DBUS_GET_PLUGIN_METADATA_MEMBER_NAME)) { - if (dbusHandleGetPluginMetadataMessage (connection, message, d)) + if (dbusHandleGetPluginMetadataMessage (connection, message)) { dbus_free_string_array (path); return DBUS_HANDLER_RESULT_HANDLED; @@ -1745,7 +1706,7 @@ dbusHandleMessage (DBusConnection *connection, else if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE, COMPIZ_DBUS_GET_PLUGINS_MEMBER_NAME)) { - if (dbusHandleGetPluginsMessage (connection, message, d)) + if (dbusHandleGetPluginsMessage (connection, message)) { dbus_free_string_array (path); return DBUS_HANDLER_RESULT_HANDLED; @@ -1758,10 +1719,11 @@ dbusHandleMessage (DBusConnection *connection, /* plugin message */ else if (!path[4]) { - if (dbus_message_is_method_call (message, DBUS_INTERFACE_INTROSPECTABLE, + if (dbus_message_is_method_call (message, + DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) { - if (dbusHandlePluginIntrospectMessage (connection, message, d, + if (dbusHandlePluginIntrospectMessage (connection, message, &path[3])) { dbus_free_string_array (path); @@ -1775,10 +1737,11 @@ dbusHandleMessage (DBusConnection *connection, /* screen message */ else if (!path[5]) { - if (dbus_message_is_method_call (message, DBUS_INTERFACE_INTROSPECTABLE, + if (dbus_message_is_method_call (message, + DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) { - if (dbusHandleScreenIntrospectMessage (connection, message, d, + if (dbusHandleScreenIntrospectMessage (connection, message, &path[3])) { dbus_free_string_array (path); @@ -1788,7 +1751,7 @@ dbusHandleMessage (DBusConnection *connection, else if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE, COMPIZ_DBUS_LIST_MEMBER_NAME)) { - if (dbusHandleListMessage (connection, message, d, &path[3])) + if (dbusHandleListMessage (connection, message, &path[3])) { dbus_free_string_array (path); return DBUS_HANDLER_RESULT_HANDLED; @@ -1802,36 +1765,34 @@ dbusHandleMessage (DBusConnection *connection, if (dbus_message_is_method_call (message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) { - status = dbusHandleOptionIntrospectMessage (connection, message, d, + status = dbusHandleOptionIntrospectMessage (connection, message, &path[3]); } else if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE, COMPIZ_DBUS_ACTIVATE_MEMBER_NAME)) { - status = dbusHandleActionMessage (connection, message, d, &path[3], - TRUE); + status = dbusHandleActionMessage (connection, message, &path[3], TRUE); } else if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE, COMPIZ_DBUS_DEACTIVATE_MEMBER_NAME)) { - status = dbusHandleActionMessage (connection, message, d, &path[3], + status = dbusHandleActionMessage (connection, message, &path[3], FALSE); } else if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE, COMPIZ_DBUS_SET_MEMBER_NAME)) { - status = dbusHandleSetOptionMessage (connection, message, d, &path[3]); + status = dbusHandleSetOptionMessage (connection, message, &path[3]); } else if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE, COMPIZ_DBUS_GET_MEMBER_NAME)) { - status = dbusHandleGetOptionMessage (connection, message, d, &path[3]); + status = dbusHandleGetOptionMessage (connection, message, &path[3]); } else if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE, COMPIZ_DBUS_GET_METADATA_MEMBER_NAME)) { - status = dbusHandleGetMetadataMessage (connection, message, d, - &path[3]); + status = dbusHandleGetMetadataMessage (connection, message, &path[3]); } dbus_free_string_array (path); @@ -1845,15 +1806,14 @@ dbusHandleMessage (DBusConnection *connection, static Bool dbusProcessMessages (void *data) { - CompDisplay *d = (CompDisplay *) data; DBusDispatchStatus status; - DBUS_DISPLAY (d); + DBUS_CORE (&core); do { - dbus_connection_read_write_dispatch (dd->connection, 0); - status = dbus_connection_get_dispatch_status (dd->connection); + dbus_connection_read_write_dispatch (dc->connection, 0); + status = dbus_connection_get_dispatch_status (dc->connection); } while (status == DBUS_DISPATCH_DATA_REMAINS); @@ -1861,57 +1821,42 @@ dbusProcessMessages (void *data) } static void -dbusSendChangeSignalForOption (CompDisplay *d, - CompOptionType type, - CompOptionValue *value, - const char *path) +dbusSendChangeSignalForOption (CompObject *object, + CompOption *o, + const char *plugin) { DBusMessage *signal; + char *name, path[256]; - DBUS_DISPLAY (d); + DBUS_CORE (&core); + + if (!o) + return; + + name = compObjectName (object); + if (name) + { + sprintf (path, "%s/%s/%s%s/%s", COMPIZ_DBUS_ROOT_PATH, + plugin, compObjectTypeName (object->type), name, o->name); + + free (name); + } + else + sprintf (path, "%s/%s/%s/%s", COMPIZ_DBUS_ROOT_PATH, + plugin, compObjectTypeName (object->type), o->name); signal = dbus_message_new_signal (path, COMPIZ_DBUS_SERVICE_NAME, COMPIZ_DBUS_CHANGED_SIGNAL_NAME); - dbusAppendOptionValue (d, signal, type, value); + dbusAppendOptionValue (object, signal, o->type, &o->value); - dbus_connection_send (dd->connection, signal, NULL); - dbus_connection_flush (dd->connection); + dbus_connection_send (dc->connection, signal, NULL); + dbus_connection_flush (dc->connection); dbus_message_unref (signal); } -static void -dbusSendChangeSignalForDisplayOption (CompDisplay *d, - CompOption *o, - const char *plugin) -{ - char path[256]; - - if (o) - { - sprintf (path, "%s/%s/allscreens/%s", COMPIZ_DBUS_ROOT_PATH, - plugin, o->name); - dbusSendChangeSignalForOption (d, o->type, &o->value, path); - } -} - -static void -dbusSendChangeSignalForScreenOption (CompScreen *s, - CompOption *o, - const char *plugin) -{ - char path[256]; - - if (o) - { - sprintf (path, "%s/%s/screens%d/%s", COMPIZ_DBUS_ROOT_PATH, - plugin, s->screenNum, o->name); - dbusSendChangeSignalForOption (s->display, o->type, &o->value, path); - } -} - static Bool dbusGetPathDecomposed (char *data, char ***path) @@ -1967,7 +1912,6 @@ dbusGetPathDecomposed (char *data, static Bool dbusRegisterOptions (DBusConnection *connection, - CompDisplay *d, char *screenPath) { CompOption *option = NULL; @@ -1977,7 +1921,7 @@ dbusRegisterOptions (DBusConnection *connection, dbusGetPathDecomposed (screenPath, &path); - option = dbusGetOptionsFromPath (d, &path[3], NULL, NULL, &nOptions); + option = dbusGetOptionsFromPath (&path[3], NULL, NULL, &nOptions); if (!option) { free(path); @@ -1989,7 +1933,7 @@ dbusRegisterOptions (DBusConnection *connection, snprintf (objectPath, 256, "%s/%s", screenPath, option->name); dbus_connection_register_object_path (connection, objectPath, - &dbusMessagesVTable, d); + &dbusMessagesVTable, 0); option++; } @@ -2000,7 +1944,6 @@ dbusRegisterOptions (DBusConnection *connection, static Bool dbusUnregisterOptions (DBusConnection *connection, - CompDisplay *d, char *screenPath) { CompOption *option = NULL; @@ -2010,7 +1953,7 @@ dbusUnregisterOptions (DBusConnection *connection, dbusGetPathDecomposed (screenPath, &path); - option = dbusGetOptionsFromPath (d, &path[3], NULL, NULL, &nOptions); + option = dbusGetOptionsFromPath (&path[3], NULL, NULL, &nOptions); free (path); @@ -2078,7 +2021,7 @@ dbusRegisterPluginsForDisplay (DBusConnection *connection, snprintf (path, 256, "%s/%s/allscreens", COMPIZ_DBUS_ROOT_PATH, pl->value[nPlugins].s); dbusRegisterPluginForDisplay (connection, d, pl->value[nPlugins].s); - dbusRegisterOptions (connection, d, path); + dbusRegisterOptions (connection, path); } } @@ -2100,7 +2043,7 @@ dbusRegisterPluginsForScreen (DBusConnection *connection, pl->value[nPlugins].s, s->screenNum); dbusRegisterPluginForScreen (connection, s, pl->value[nPlugins].s); - dbusRegisterOptions (connection, s->display, path); + dbusRegisterOptions (connection, path); } } @@ -2114,7 +2057,7 @@ dbusUnregisterPluginForDisplay (DBusConnection *connection, snprintf (objectPath, 256, "%s/%s/%s", COMPIZ_DBUS_ROOT_PATH, pluginName, "allscreens"); - dbusUnregisterOptions (connection, d, objectPath); + dbusUnregisterOptions (connection, objectPath); dbus_connection_unregister_object_path (connection, objectPath); snprintf (objectPath, 256, "%s/%s", COMPIZ_DBUS_ROOT_PATH, pluginName); @@ -2146,7 +2089,7 @@ dbusUnregisterPluginForScreen (DBusConnection *connection, snprintf (objectPath, 256, "%s/%s/screen%d", COMPIZ_DBUS_ROOT_PATH, pluginName, s->screenNum); - dbusUnregisterOptions (connection, s->display, objectPath); + dbusUnregisterOptions (connection, objectPath); dbus_connection_unregister_object_path (connection, objectPath); } @@ -2171,11 +2114,11 @@ dbusInitPluginForDisplay (CompPlugin *p, { char objectPath[256]; - DBUS_DISPLAY (d); + DBUS_CORE (&core); snprintf (objectPath, 256, "%s/%s/%s", COMPIZ_DBUS_ROOT_PATH, p->vTable->name, "allscreens"); - dbusRegisterOptions (dd->connection, d, objectPath); + dbusRegisterOptions (dc->connection, objectPath); return TRUE; } @@ -2186,11 +2129,11 @@ dbusInitPluginForScreen (CompPlugin *p, { char objectPath[256]; - DBUS_DISPLAY (s->display); + DBUS_CORE (&core); snprintf (objectPath, 256, "%s/%s/screen%d", COMPIZ_DBUS_ROOT_PATH, p->vTable->name, s->screenNum); - dbusRegisterOptions (dd->connection, s->display, objectPath); + dbusRegisterOptions (dc->connection, objectPath); return TRUE; } @@ -2221,19 +2164,19 @@ dbusInitPluginForObject (CompPlugin *p, return status; } -static Bool -dbusSetDisplayOptionForPlugin (CompDisplay *d, - const char *plugin, - const char *name, - CompOptionValue *value) +static CompBool +dbusSetOptionForPlugin (CompObject *object, + const char *plugin, + const char *name, + CompOptionValue *value) { Bool status; - DBUS_DISPLAY (d); + DBUS_CORE (&core); - UNWRAP (dd, d, setDisplayOptionForPlugin); - status = (*d->setDisplayOptionForPlugin) (d, plugin, name, value); - WRAP (dd, d, setDisplayOptionForPlugin, dbusSetDisplayOptionForPlugin); + UNWRAP (dc, &core, setOptionForPlugin); + status = (*core.setOptionForPlugin) (object, plugin, name, value); + WRAP (dc, &core, setOptionForPlugin, dbusSetOptionForPlugin); if (status) { @@ -2245,25 +2188,26 @@ dbusSetDisplayOptionForPlugin (CompDisplay *d, CompOption *option; int nOption; - option = (*p->vTable->getObjectOptions) (p, &d->object, &nOption); - dbusSendChangeSignalForDisplayOption (d, - compFindOption (option, - nOption, - name, 0), - p->vTable->name); + option = (*p->vTable->getObjectOptions) (p, object, &nOption); + dbusSendChangeSignalForOption (object, + compFindOption (option, + nOption, + name, 0), + p->vTable->name); - if (strcmp (p->vTable->name, "core") == 0 && + if (object->type == COMP_OBJECT_TYPE_DISPLAY && + strcmp (p->vTable->name, "core") == 0 && strcmp (name, "active_plugins") == 0) { CompScreen *s; - dbusUnregisterPluginsForDisplay (dd->connection, d); - dbusRegisterPluginsForDisplay (dd->connection, d); + dbusUnregisterPluginsForDisplay (dc->connection, compDisplays); + dbusRegisterPluginsForDisplay (dc->connection, compDisplays); - for (s = d->screens; s; s = s->next) + for (s = compDisplays->screens; s; s = s->next) { - dbusUnregisterPluginsForScreen (dd->connection, s); - dbusRegisterPluginsForScreen (dd->connection, s); + dbusUnregisterPluginsForScreen (dc->connection, s); + dbusRegisterPluginsForScreen (dc->connection, s); } } } @@ -2272,57 +2216,20 @@ dbusSetDisplayOptionForPlugin (CompDisplay *d, return status; } -static Bool -dbusSetScreenOptionForPlugin (CompScreen *s, - const char *plugin, - const char *name, - CompOptionValue *value) -{ - Bool status; - - DBUS_SCREEN (s); - - UNWRAP (ds, s, setScreenOptionForPlugin); - status = (*s->setScreenOptionForPlugin) (s, plugin, name, value); - WRAP (ds, s, setScreenOptionForPlugin, dbusSetScreenOptionForPlugin); - - if (status) - { - CompPlugin *p; - - p = findActivePlugin (plugin); - if (p && p->vTable->getObjectOptions) - { - CompOption *option; - int nOption; - - option = (*p->vTable->getObjectOptions) (p, &s->object, &nOption); - dbusSendChangeSignalForScreenOption (s, - compFindOption (option, - nOption, - name, 0), - p->vTable->name); - } - } - - return status; -} - static void dbusSendPluginsChangedSignal (const char *name, void *closure) { - CompDisplay *d = (CompDisplay *) closure; DBusMessage *signal; - DBUS_DISPLAY (d); + DBUS_CORE (&core); signal = dbus_message_new_signal (COMPIZ_DBUS_ROOT_PATH, COMPIZ_DBUS_SERVICE_NAME, COMPIZ_DBUS_PLUGINS_CHANGED_SIGNAL_NAME); - dbus_connection_send (dd->connection, signal, NULL); - dbus_connection_flush (dd->connection); + dbus_connection_send (dc->connection, signal, NULL); + dbus_connection_flush (dc->connection); dbus_message_unref (signal); } @@ -2331,7 +2238,11 @@ static Bool dbusInitCore (CompPlugin *p, CompCore *c) { - DbusCore *dc; + DbusCore *dc; + DBusError error; + dbus_bool_t status; + int fd, ret, mask; + char *home, *plugindir; if (!checkPluginABI ("core", CORE_ABIVERSION)) return FALSE; @@ -2340,69 +2251,21 @@ dbusInitCore (CompPlugin *p, if (!dc) return FALSE; - displayPrivateIndex = allocateDisplayPrivateIndex (); - if (displayPrivateIndex < 0) - { - free (dc); - return FALSE; - } - - WRAP (dc, c, initPluginForObject, dbusInitPluginForObject); - - c->object.privates[corePrivateIndex].ptr = dc; - - return TRUE; -} - -static void -dbusFiniCore (CompPlugin *p, - CompCore *c) -{ - DBUS_CORE (c); - - UNWRAP (dc, c, initPluginForObject); - - freeDisplayPrivateIndex (displayPrivateIndex); - - free (dc); -} - -static Bool -dbusInitDisplay (CompPlugin *p, - CompDisplay *d) -{ - DbusDisplay *dd; - DBusError error; - dbus_bool_t status; - int fd, ret, mask; - char *home, *plugindir, objectPath[256]; - - dd = malloc (sizeof (DbusDisplay)); - if (!dd) - return FALSE; - - dd->screenPrivateIndex = allocateScreenPrivateIndex (d); - if (dd->screenPrivateIndex < 0) - { - free (dd); - return FALSE; - } - dbus_error_init (&error); - dd->connection = dbus_bus_get (DBUS_BUS_SESSION, &error); + dc->connection = dbus_bus_get (DBUS_BUS_SESSION, &error); if (dbus_error_is_set (&error)) { - compLogMessage (d, "dbus", CompLogLevelError, + compLogMessage (NULL, "dbus", CompLogLevelError, "dbus_bus_get error: %s", error.message); dbus_error_free (&error); - free (dd); + free (dc); return FALSE; } - ret = dbus_bus_request_name (dd->connection, + ret = dbus_bus_request_name (dc->connection, COMPIZ_DBUS_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING | DBUS_NAME_FLAG_ALLOW_REPLACEMENT, @@ -2410,12 +2273,12 @@ dbusInitDisplay (CompPlugin *p, if (dbus_error_is_set (&error)) { - compLogMessage (d, "dbus", CompLogLevelError, + compLogMessage (NULL, "dbus", CompLogLevelError, "dbus_bus_request_name error: %s", error.message); - /* dbus_connection_unref (dd->connection); */ + /* dbus_connection_unref (dc->connection); */ dbus_error_free (&error); - free (dd); + free (dc); return FALSE; } @@ -2424,45 +2287,45 @@ dbusInitDisplay (CompPlugin *p, if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - compLogMessage (d, "dbus", CompLogLevelError, + compLogMessage (NULL, "dbus", CompLogLevelError, "dbus_bus_request_name reply is not primary owner"); - /* dbus_connection_unref (dd->connection); */ - free (dd); + /* dbus_connection_unref (dc->connection); */ + free (dc); return FALSE; } - status = dbus_connection_get_unix_fd (dd->connection, &fd); + status = dbus_connection_get_unix_fd (dc->connection, &fd); if (!status) { - compLogMessage (d, "dbus", CompLogLevelError, + compLogMessage (NULL, "dbus", CompLogLevelError, "dbus_connection_get_unix_fd failed"); - /* dbus_connection_unref (dd->connection); */ - free (dd); + /* dbus_connection_unref (dc->connection); */ + free (dc); return FALSE; } - dd->watchFdHandle = compAddWatchFd (fd, + dc->watchFdHandle = compAddWatchFd (fd, POLLIN | POLLPRI | POLLHUP | POLLERR, dbusProcessMessages, - d); + 0); mask = NOTIFY_CREATE_MASK | NOTIFY_DELETE_MASK | NOTIFY_MOVE_MASK; - dd->fileWatch[DBUS_FILE_WATCH_CURRENT] = + dc->fileWatch[DBUS_FILE_WATCH_CURRENT] = addFileWatch (".", mask, dbusSendPluginsChangedSignal, - (void *) d); - dd->fileWatch[DBUS_FILE_WATCH_PLUGIN] = + 0); + dc->fileWatch[DBUS_FILE_WATCH_PLUGIN] = addFileWatch (PLUGINDIR, mask, dbusSendPluginsChangedSignal, - (void *) d); - dd->fileWatch[DBUS_FILE_WATCH_HOME] = 0; + 0); + dc->fileWatch[DBUS_FILE_WATCH_HOME] = 0; home = getenv ("HOME"); if (home) @@ -2472,32 +2335,76 @@ dbusInitDisplay (CompPlugin *p, { sprintf (plugindir, "%s/%s", home, HOME_PLUGINDIR); - dd->fileWatch[DBUS_FILE_WATCH_HOME] = + dc->fileWatch[DBUS_FILE_WATCH_HOME] = addFileWatch (plugindir, mask, dbusSendPluginsChangedSignal, - (void *) d); + 0); free (plugindir); } } - WRAP (dd, d, setDisplayOptionForPlugin, dbusSetDisplayOptionForPlugin); + WRAP (dc, c, initPluginForObject, dbusInitPluginForObject); - d->object.privates[displayPrivateIndex].ptr = dd; + printf ("init dbus core\n"); + + c->object.privates[corePrivateIndex].ptr = dc; /* register the objects */ - dbus_connection_register_object_path (dd->connection, + dbus_connection_register_object_path (dc->connection, COMPIZ_DBUS_ROOT_PATH, - &dbusMessagesVTable, d); + &dbusMessagesVTable, 0); + + return TRUE; +} + +static void +dbusFiniCore (CompPlugin *p, + CompCore *c) +{ + int i; + + DBUS_CORE (c); + + for (i = 0; i < DBUS_FILE_WATCH_NUM; i++) + removeFileWatch (dc->fileWatch[i]); + + compRemoveWatchFd (dc->watchFdHandle); + + dbus_bus_release_name (dc->connection, COMPIZ_DBUS_SERVICE_NAME, NULL); + + /* + can't unref the connection returned by dbus_bus_get as it's + shared and we can't know if it's closed or not. + + dbus_connection_unref (dc->connection); + */ + + printf ("fini dbus core\n"); + + UNWRAP (dc, c, initPluginForObject); + + free (dc); +} + +static Bool +dbusInitDisplay (CompPlugin *p, + CompDisplay *d) +{ + char objectPath[256]; + + DBUS_CORE (&core); /* register core 'plugin' */ - dbusRegisterPluginForDisplay (dd->connection, d, "core"); - dbusRegisterPluginsForDisplay (dd->connection, d); + dbusRegisterPluginForDisplay (dc->connection, d, "core"); + dbusRegisterPluginsForDisplay (dc->connection, d); snprintf (objectPath, 256, "%s/core/allscreens", COMPIZ_DBUS_ROOT_PATH); - dbusRegisterOptions (dd->connection, d, objectPath); + dbusRegisterOptions (dc->connection, objectPath); + + printf ("init dbus display\n"); return TRUE; } @@ -2507,39 +2414,22 @@ dbusFiniDisplay (CompPlugin *p, CompDisplay *d) { CompScreen *s; - int i; - DBUS_DISPLAY (d); + DBUS_CORE (&core); - dbusUnregisterPluginForDisplay (dd->connection, d, "core"); - dbusUnregisterPluginsForDisplay (dd->connection, d); + dbusUnregisterPluginForDisplay (dc->connection, d, "core"); + dbusUnregisterPluginsForDisplay (dc->connection, d); /* we must unregister the screens here not in finiScreen because when finiScreen is called the connection has been dropped */ for (s = d->screens; s; s = s->next) { - dbusUnregisterPluginForScreen (dd->connection, s, "core"); - dbusUnregisterPluginsForScreen (dd->connection, s); + dbusUnregisterPluginForScreen (dc->connection, s, "core"); + dbusUnregisterPluginsForScreen (dc->connection, s); } - for (i = 0; i < DBUS_FILE_WATCH_NUM; i++) - removeFileWatch (dd->fileWatch[i]); - - compRemoveWatchFd (dd->watchFdHandle); - - dbus_bus_release_name (dd->connection, COMPIZ_DBUS_SERVICE_NAME, NULL); - - /* - can't unref the connection returned by dbus_bus_get as it's - shared and we can't know if it's closed or not. - - dbus_connection_unref (dd->connection); - */ - - UNWRAP (dd, d, setDisplayOptionForPlugin); - - free (dd); + printf ("fini dbus display\n"); } static Bool @@ -2547,24 +2437,17 @@ dbusInitScreen (CompPlugin *p, CompScreen *s) { char objectPath[256]; - DbusScreen *ds; - - DBUS_DISPLAY (s->display); - - ds = malloc (sizeof (DbusScreen)); - if (!ds) - return FALSE; - WRAP (ds, s, setScreenOptionForPlugin, dbusSetScreenOptionForPlugin); - - s->object.privates[dd->screenPrivateIndex].ptr = ds; + DBUS_CORE (&core); snprintf (objectPath, 256, "%s/%s/screen%d", COMPIZ_DBUS_ROOT_PATH, "core", s->screenNum); - dbusRegisterPluginForScreen (dd->connection, s, "core"); - dbusRegisterPluginsForScreen (dd->connection, s); - dbusRegisterOptions (dd->connection, s->display, objectPath); + dbusRegisterPluginForScreen (dc->connection, s, "core"); + dbusRegisterPluginsForScreen (dc->connection, s); + dbusRegisterOptions (dc->connection, objectPath); + + printf ("init dbus screen\n"); return TRUE; } @@ -2573,11 +2456,7 @@ static void dbusFiniScreen (CompPlugin *p, CompScreen *s) { - DBUS_SCREEN (s); - - UNWRAP (ds, s, setScreenOptionForPlugin); - - free (ds); + printf ("fini dbus screen\n"); } static CompBool @@ -2626,7 +2505,7 @@ dbusInit (CompPlugin *p) static void dbusFini (CompPlugin *p) { - freeCorePrivateIndex (displayPrivateIndex); + freeCorePrivateIndex (corePrivateIndex); compFiniMetadata (&dbusMetadata); } diff --git a/plugins/fuse.c b/plugins/fuse.c index d366b386..2e90173e 100644 --- a/plugins/fuse.c +++ b/plugins/fuse.c @@ -211,29 +211,35 @@ fuseLookupChild (FuseInode *inode, return NULL; } -static CompOption * -fuseGetDisplayOptionsFromInode (CompDisplay *d, - FuseInode *inode, - int *nOption) +static CompObject * +fuseGetObjectFromInode (FuseInode *inode) { - CompOption *option = NULL; - - if (inode->type & FUSE_INODE_TYPE_PLUGIN) + if (inode->type & FUSE_INODE_TYPE_SCREEN) { - CompPlugin *p; + CompScreen *s; + int screenNum = -1; - p = findActivePlugin (inode->name); - if (p && p->vTable->getObjectOptions) - option = (*p->vTable->getObjectOptions) (p, &d->object, nOption); + sscanf (inode->name, "screen%d", &screenNum); + + for (s = compDisplays->screens; s; s = s->next) + if (s->screenNum == screenNum) + break; + + if (s) + return &s->object; + } + else if (inode->type & FUSE_INODE_TYPE_DISPLAY) + { + return &compDisplays->object; } - return option; + return NULL; } static CompOption * -fuseGetScreenOptionsFromInode (CompScreen *s, - FuseInode *inode, - int *nOption) +fuseGetOptionsFromInode (CompObject *object, + FuseInode *inode, + int *nOption) { CompOption *option = NULL; @@ -243,55 +249,30 @@ fuseGetScreenOptionsFromInode (CompScreen *s, p = findActivePlugin (inode->name); if (p && p->vTable->getObjectOptions) - option = (*p->vTable->getObjectOptions) (p, &s->object, nOption); + option = (*p->vTable->getObjectOptions) (p, object, nOption); } return option; } static CompOption * -fuseGetOptionsFromInode (CompDisplay *d, - FuseInode *inode, - int *nOption) -{ - CompOption *option = NULL; - - if (inode->type & FUSE_INODE_TYPE_SCREEN) - { - CompScreen *s; - int screenNum = -1; - - sscanf (inode->name, "screen%d", &screenNum); - - for (s = d->screens; s; s = s->next) - if (s->screenNum == screenNum) - break; - - if (s) - option = fuseGetScreenOptionsFromInode (s, inode->parent, nOption); - } - else if (inode->type & FUSE_INODE_TYPE_DISPLAY) - { - option = fuseGetDisplayOptionsFromInode (d, inode->parent, nOption); - } - - return option; -} - -static CompOption * -fuseGetOptionFromInode (CompDisplay *d, - FuseInode *inode) +fuseGetOptionFromInode (FuseInode *inode) { if (inode->type & (FUSE_INODE_TYPE_OPTION | FUSE_INODE_TYPE_ITEMS)) { + CompObject *object; CompOption *option; int nOption; if (inode->type & FUSE_INODE_TYPE_ITEMS) inode = inode->parent; - option = fuseGetOptionsFromInode (d, inode->parent, &nOption); + object = fuseGetObjectFromInode (inode); + if (!object) + return NULL; + + option = fuseGetOptionsFromInode (object, inode->parent, &nOption); if (option) { while (nOption--) @@ -308,8 +289,7 @@ fuseGetOptionFromInode (CompDisplay *d, } static char * -fuseGetStringFromInode (CompDisplay *d, - FuseInode *inode) +fuseGetStringFromInode (FuseInode *inode) { CompOption *option; char str[256]; @@ -317,7 +297,7 @@ fuseGetStringFromInode (CompDisplay *d, if (!inode->parent) return NULL; - option = fuseGetOptionFromInode (d, inode->parent); + option = fuseGetOptionFromInode (inode->parent); if (!option) return NULL; @@ -368,9 +348,9 @@ fuseGetStringFromInode (CompDisplay *d, case CompOptionTypeColor: return colorToString (value->c); case CompOptionTypeKey: - return keyActionToString (d, &value->action); + return keyActionToString (compDisplays, &value->action); case CompOptionTypeButton: - return buttonActionToString (d, &value->action); + return buttonActionToString (compDisplays, &value->action); case CompOptionTypeEdge: return edgeMaskToString (value->action.edgeMask); case CompOptionTypeBell: @@ -446,12 +426,12 @@ fuseUpdateInode (CompDisplay *d, { int n; - if (fuseGetDisplayOptionsFromInode (d, inode, &n)) - fuseAddInode (inode, FUSE_INODE_TYPE_DISPLAY, "allscreen"); + if (fuseGetOptionsFromInode (&d->object, inode, &n)) + fuseAddInode (inode, FUSE_INODE_TYPE_DISPLAY, "allscreens"); for (s = d->screens; s; s = s->next) { - if (fuseGetScreenOptionsFromInode (s, inode, &n)) + if (fuseGetOptionsFromInode (&s->object, inode, &n)) { sprintf (str, "screen%d", s->screenNum); fuseAddInode (inode, FUSE_INODE_TYPE_SCREEN, str); @@ -460,22 +440,28 @@ fuseUpdateInode (CompDisplay *d, } else if (inode->type & (FUSE_INODE_TYPE_DISPLAY | FUSE_INODE_TYPE_SCREEN)) { - int nOption; + CompObject *object; - option = fuseGetOptionsFromInode (d, inode, &nOption); - if (option) + object = fuseGetObjectFromInode (inode); + if (object) { - while (nOption--) + int nOption; + + option = fuseGetOptionsFromInode (object, inode->parent, &nOption); + if (option) { - fuseAddInode (inode, FUSE_INODE_TYPE_OPTION, option->name); + while (nOption--) + { + fuseAddInode (inode, FUSE_INODE_TYPE_OPTION, option->name); - option++; + option++; + } } } } else if (inode->type & FUSE_INODE_TYPE_OPTION) { - option = fuseGetOptionFromInode (d, inode); + option = fuseGetOptionFromInode (inode); if (option) { fuseAddInode (inode, FUSE_INODE_TYPE_TYPE, "type"); @@ -510,7 +496,7 @@ fuseUpdateInode (CompDisplay *d, } else if (inode->type & FUSE_INODE_TYPE_ITEMS) { - option = fuseGetOptionFromInode (d, inode->parent); + option = fuseGetOptionFromInode (inode->parent); if (option && option->type == CompOptionTypeList) { FuseInode *c, *next; @@ -558,7 +544,7 @@ fuseInodeStat (CompDisplay *d, stbuf->st_nlink = 1; stbuf->st_size = 0; - str = fuseGetStringFromInode (d, inode); + str = fuseGetStringFromInode (inode); if (str) { stbuf->st_size = strlen (str); @@ -606,7 +592,7 @@ fuseInitValue (CompOptionValue *value, } static Bool -fuseInitValueFromString (CompDisplay *display, +fuseInitValueFromString (CompObject *object, CompOptionValue *value, CompOptionType type, char *str) @@ -629,10 +615,10 @@ fuseInitValueFromString (CompDisplay *display, return FALSE; break; case CompOptionTypeKey: - stringToKeyAction (display, str, &value->action); + stringToKeyAction (GET_CORE_DISPLAY (object), str, &value->action); break; case CompOptionTypeButton: - stringToButtonAction (display, str, &value->action); + stringToButtonAction (GET_CORE_DISPLAY (object), str, &value->action); break; case CompOptionTypeEdge: value->action.edgeMask = stringToEdgeMask (str); @@ -652,25 +638,28 @@ fuseInitValueFromString (CompDisplay *display, } static void -fuseSetInodeOptionUsingString (CompDisplay *d, - FuseInode *inode, - char *str) +fuseSetInodeOptionUsingString (FuseInode *inode, + char *str) { CompOption *option; - option = fuseGetOptionFromInode (d, inode->parent); + option = fuseGetOptionFromInode (inode->parent); if (option) { CompOptionValue value; - CompScreen *s = NULL; - FuseInode *objectInode; + CompObject *object; + const char *pluginName; if (inode->type & FUSE_INODE_TYPE_VALUE) { - if (!fuseInitValueFromString (d, &value, option->type, str)) + object = fuseGetObjectFromInode (inode->parent->parent); + if (!object) + return; + + if (!fuseInitValueFromString (object, &value, option->type, str)) return; - objectInode = inode->parent->parent; + pluginName = inode->parent->parent->parent->name; } else if (inode->type & FUSE_INODE_TYPE_ITEM_VALUE) { @@ -682,6 +671,10 @@ fuseSetInodeOptionUsingString (CompDisplay *d, if (item >= nValue) return; + object = fuseGetObjectFromInode (inode->parent->parent->parent); + if (!object) + return; + value.list.value = malloc (sizeof (CompOptionValue) * nValue); if (!value.list.value) return; @@ -693,7 +686,7 @@ fuseSetInodeOptionUsingString (CompDisplay *d, { if (i == item) { - if (!fuseInitValueFromString (d, + if (!fuseInitValueFromString (object, &value.list.value[i], value.list.type, str)) @@ -717,38 +710,14 @@ fuseSetInodeOptionUsingString (CompDisplay *d, return; } - objectInode = inode->parent->parent->parent; + pluginName = inode->parent->parent->parent->parent->name; } else { return; } - if (objectInode->type & FUSE_INODE_TYPE_SCREEN) - { - int screenNum = -1; - - sscanf (objectInode->name, "screen%d", &screenNum); - - for (s = d->screens; s; s = s->next) - if (s->screenNum == screenNum) - break; - } - - if (s) - { - (*s->setScreenOptionForPlugin) (s, - objectInode->parent->name, - option->name, - &value); - } - else - { - (*d->setDisplayOptionForPlugin) (d, - objectInode->parent->name, - option->name, - &value); - } + (*core.setOptionForPlugin) (object, pluginName, option->name, &value); compFiniOptionValue (&value, option->type); } @@ -934,8 +903,7 @@ compiz_open (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { - CompDisplay *d = (CompDisplay *) fuse_req_userdata (req); - FuseInode *inode; + FuseInode *inode; inode = fuseFindInode (inodes, ino, ~0); if (!inode) @@ -959,7 +927,7 @@ compiz_open (fuse_req_t req, if (fi->flags & O_TRUNC) data = strdup (""); else - data = fuseGetStringFromInode (d, inode); + data = fuseGetStringFromInode (inode); if (data) { @@ -1000,13 +968,12 @@ compiz_read (fuse_req_t req, off_t off, struct fuse_file_info *fi) { - CompDisplay *d = (CompDisplay *) fuse_req_userdata (req); - FuseInode *inode; - char *str = NULL; + FuseInode *inode; + char *str = NULL; inode = fuseFindInode (inodes, ino, ~0); if (inode) - str = fuseGetStringFromInode (d, inode); + str = fuseGetStringFromInode (inode); if (str) { @@ -1068,8 +1035,6 @@ compiz_release (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { - CompDisplay *d = (CompDisplay *) fuse_req_userdata (req); - if (fi->fh) { FuseWriteBuffer *wb = (FuseWriteBuffer *) (uintptr_t) fi->fh; @@ -1078,7 +1043,7 @@ compiz_release (fuse_req_t req, inode = fuseFindInode (inodes, ino, WRITE_MASK); if (inode && wb->dirty) { - fuseSetInodeOptionUsingString (d, inode, wb->data); + fuseSetInodeOptionUsingString (inode, wb->data); inode->flags &= ~FUSE_INODE_FLAG_TRUNC; } @@ -1096,8 +1061,6 @@ compiz_fsync (fuse_req_t req, int datasync, struct fuse_file_info *fi) { - CompDisplay *d = (CompDisplay *) fuse_req_userdata (req); - if (fi->fh) { FuseWriteBuffer *wb = (FuseWriteBuffer *) (uintptr_t) fi->fh; @@ -1106,7 +1069,7 @@ compiz_fsync (fuse_req_t req, inode = fuseFindInode (inodes, ino, WRITE_MASK); if (inode && wb->dirty) { - fuseSetInodeOptionUsingString (d, inode, wb->data); + fuseSetInodeOptionUsingString (inode, wb->data); inode->flags &= ~FUSE_INODE_FLAG_TRUNC; diff --git a/plugins/gconf.c b/plugins/gconf.c index fff23942..edd539dc 100644 --- a/plugins/gconf.c +++ b/plugins/gconf.c @@ -46,26 +46,13 @@ int gconf_value_compare (const GConfValue *value_a, static int corePrivateIndex; typedef struct _GConfCore { - InitPluginForObjectProc initPluginForObject; -} GConfCore; - -static int displayPrivateIndex; - -typedef struct _GConfDisplay { - int screenPrivateIndex; - - InitPluginForDisplayProc initPluginForDisplay; - SetDisplayOptionForPluginProc setDisplayOptionForPlugin; - GConfClient *client; CompTimeoutHandle reloadHandle; -} GConfDisplay; -typedef struct _GConfScreen { - InitPluginForScreenProc initPluginForScreen; - SetScreenOptionForPluginProc setScreenOptionForPlugin; -} GConfScreen; + InitPluginForObjectProc initPluginForObject; + SetOptionForPluginProc setOptionForPlugin; +} GConfCore; #define GET_GCONF_CORE(c) \ ((GConfCore *) (c)->object.privates[corePrivateIndex].ptr) @@ -73,18 +60,39 @@ typedef struct _GConfScreen { #define GCONF_CORE(c) \ GConfCore *gc = GET_GCONF_CORE (c) -#define GET_GCONF_DISPLAY(d) \ - ((GConfDisplay *) (d)->object.privates[displayPrivateIndex].ptr) -#define GCONF_DISPLAY(d) \ - GConfDisplay *gd = GET_GCONF_DISPLAY (d) +static gchar * +gconfGetKey (CompObject *object, + const gchar *plugin, + const gchar *option) +{ + const gchar *type; + gchar *key, *name, *objectName; -#define GET_GCONF_SCREEN(s, gd) \ - ((GConfScreen *) (s)->object.privates[(gd)->screenPrivateIndex].ptr) + type = compObjectTypeName (object->type); + if (strcmp (type, "display") == 0) + type = "allscreens"; -#define GCONF_SCREEN(s) \ - GConfScreen *gs = GET_GCONF_SCREEN (s, \ - GET_GCONF_DISPLAY (s->display)) + name = compObjectName (object); + if (name) + { + objectName = g_strdup_printf ("%s%s", type, name); + free (name); + } + else + objectName = g_strdup (type); + + if (strcmp (plugin, "core") == 0) + key = g_strjoin ("/", "/apps", APP_NAME, "general", objectName, + "options", option, NULL); + else + key = g_strjoin ("/", "/apps", APP_NAME, "plugins", plugin, objectName, + "options", option, NULL); + + g_free (objectName); + + return key; +} static GConfValueType gconfTypeFromCompType (CompOptionType type) @@ -114,7 +122,7 @@ gconfTypeFromCompType (CompOptionType type) } static void -gconfSetValue (CompDisplay *d, +gconfSetValue (CompObject *object, CompOptionValue *value, CompOptionType type, GConfValue *gvalue) @@ -143,7 +151,7 @@ gconfSetValue (CompDisplay *d, case CompOptionTypeKey: { gchar *action; - action = keyActionToString (d, &value->action); + action = keyActionToString (GET_CORE_DISPLAY (object), &value->action); gconf_value_set_string (gvalue, action); free (action); @@ -151,7 +159,8 @@ gconfSetValue (CompDisplay *d, case CompOptionTypeButton: { gchar *action; - action = buttonActionToString (d, &value->action); + action = buttonActionToString (GET_CORE_DISPLAY (object), + &value->action); gconf_value_set_string (gvalue, action); free (action); @@ -181,28 +190,22 @@ gconfSetValue (CompDisplay *d, } static void -gconfSetOption (CompDisplay *d, +gconfSetOption (CompObject *object, CompOption *o, - const gchar *plugin, - const gchar *object) + const gchar *plugin) { GConfValueType type = gconfTypeFromCompType (o->type); GConfValue *gvalue, *existingValue = NULL; gchar *key; - GCONF_DISPLAY (d); + GCONF_CORE (&core); if (type == GCONF_VALUE_INVALID) return; - if (strcmp (plugin, "core") == 0) - key = g_strjoin ("/", "/apps", APP_NAME, "general", object, "options", - o->name, NULL); - else - key = g_strjoin ("/", "/apps", APP_NAME, "plugins", plugin, object, - "options", o->name, NULL); + key = gconfGetKey (object, plugin, o->name); - existingValue = gconf_client_get (gd->client, key, NULL); + existingValue = gconf_client_get (gc->client, key, NULL); gvalue = gconf_value_new (type); if (o->type == CompOptionTypeList) @@ -216,7 +219,8 @@ gconfSetOption (CompDisplay *d, for (i = 0; i < o->value.list.nValue; i++) { gv = gconf_value_new (type); - gconfSetValue (d, &o->value.list.value[i], o->value.list.type, gv); + gconfSetValue (object, &o->value.list.value[i], + o->value.list.type, gv); list = g_slist_append (list, gv); } @@ -224,7 +228,7 @@ gconfSetOption (CompDisplay *d, gconf_value_set_list (gvalue, list); if (!existingValue || gconf_value_compare (existingValue, gvalue)) - gconf_client_set (gd->client, key, gvalue, NULL); + gconf_client_set (gc->client, key, gvalue, NULL); for (node = list; node; node = node->next) gconf_value_free ((GConfValue *) node->data); @@ -233,10 +237,10 @@ gconfSetOption (CompDisplay *d, } else { - gconfSetValue (d, &o->value, o->type, gvalue); + gconfSetValue (object, &o->value, o->type, gvalue); if (!existingValue || gconf_value_compare (existingValue, gvalue)) - gconf_client_set (gd->client, key, gvalue, NULL); + gconf_client_set (gc->client, key, gvalue, NULL); } gconf_value_free (gvalue); @@ -248,7 +252,7 @@ gconfSetOption (CompDisplay *d, } static Bool -gconfGetValue (CompDisplay *d, +gconfGetValue (CompObject *object, CompOptionValue *value, CompOptionType type, GConfValue *gvalue) @@ -302,7 +306,7 @@ gconfGetValue (CompDisplay *d, action = gconf_value_get_string (gvalue); - stringToKeyAction (d, action, &value->action); + stringToKeyAction (GET_CORE_DISPLAY (object), action, &value->action); return TRUE; } else if (type == CompOptionTypeButton && @@ -312,7 +316,8 @@ gconfGetValue (CompDisplay *d, action = gconf_value_get_string (gvalue); - stringToButtonAction (d, action, &value->action); + stringToButtonAction (GET_CORE_DISPLAY (object), action, + &value->action); return TRUE; } else if (type == CompOptionTypeEdge && @@ -347,7 +352,7 @@ gconfGetValue (CompDisplay *d, } static Bool -gconfReadOptionValue (CompDisplay *d, +gconfReadOptionValue (CompObject *object, GConfEntry *entry, CompOption *o, CompOptionValue *value) @@ -381,7 +386,7 @@ gconfReadOptionValue (CompDisplay *d, { for (i = 0; i < n; i++) { - if (!gconfGetValue (d, + if (!gconfGetValue (object, &value->list.value[i], o->value.list.type, (GConfValue *) list->data)) @@ -402,7 +407,7 @@ gconfReadOptionValue (CompDisplay *d, } else { - if (!gconfGetValue (d, value, o->type, gvalue)) + if (!gconfGetValue (object, value, o->type, gvalue)) return FALSE; } @@ -412,73 +417,31 @@ gconfReadOptionValue (CompDisplay *d, } static void -gconfGetDisplayOption (CompDisplay *d, - CompOption *o, - const char *plugin) +gconfGetOption (CompObject *object, + CompOption *o, + const char *plugin) { GConfEntry *entry; gchar *key; - GCONF_DISPLAY (d); + GCONF_CORE (&core); - if (strcmp (plugin, "core") == 0) - key = g_strjoin ("/", "/apps", APP_NAME, "general", "allscreens", - "options", o->name, NULL); - else - key = g_strjoin ("/", "/apps", APP_NAME, "plugins", plugin, - "allscreens", "options", o->name, NULL); + key = gconfGetKey (object, plugin, o->name); - entry = gconf_client_get_entry (gd->client, key, NULL, TRUE, NULL); + entry = gconf_client_get_entry (gc->client, key, NULL, TRUE, NULL); if (entry) { CompOptionValue value; - if (gconfReadOptionValue (d, entry, o, &value)) + if (gconfReadOptionValue (object, entry, o, &value)) { - (*d->setDisplayOptionForPlugin) (d, plugin, o->name, &value); + (*core.setOptionForPlugin) (object, plugin, o->name, &value); compFiniOptionValue (&value, o->type); } else { - gconfSetOption (d, o, plugin, "allscreens"); - } - } - - g_free (key); -} - -static void -gconfGetScreenOption (CompScreen *s, - CompOption *o, - const char *plugin, - const char *screen) -{ - GConfEntry *entry; - gchar *key; - - GCONF_DISPLAY (s->display); - - if (strcmp (plugin, "core") == 0) - key = g_strjoin ("/", "/apps", APP_NAME, "general", screen, "options", - o->name, NULL); - else - key = g_strjoin ("/", "/apps", APP_NAME, "plugins", plugin, screen, - "options", o->name, NULL); - - entry = gconf_client_get_entry (gd->client, key, NULL, TRUE, NULL); - if (entry) - { - CompOptionValue value; - - if (gconfReadOptionValue (s->display, entry, o, &value)) - { - (*s->setScreenOptionForPlugin) (s, plugin, o->name, &value); - compFiniOptionValue (&value, o->type); - } - else - { - gconfSetOption (s->display, o, plugin, screen); + gconfSetOption (object, o, plugin); } } @@ -488,13 +451,13 @@ gconfGetScreenOption (CompScreen *s, static Bool gconfReload (void *closure) { - CompDisplay *d = (CompDisplay *) closure; + CompDisplay *d = compDisplays; CompScreen *s; CompPlugin *p; CompOption *option; int nOption; - GCONF_DISPLAY (d); + GCONF_CORE (&core); for (p = getPlugins (); p; p = p->next) { @@ -503,46 +466,36 @@ gconfReload (void *closure) option = (*p->vTable->getObjectOptions) (p, &d->object, &nOption); while (nOption--) - gconfGetDisplayOption (d, option++, p->vTable->name); - } + gconfGetOption (&d->object, option++, p->vTable->name); - for (s = d->screens; s; s = s->next) - { - gchar *screen = g_strdup_printf ("screen%d", s->screenNum); - - for (p = getPlugins (); p; p = p->next) + for (s = d->screens; s; s = s->next) { - if (!p->vTable->getObjectOptions) - continue; - option = (*p->vTable->getObjectOptions) (p, &s->object, &nOption); while (nOption--) - gconfGetScreenOption (s, option++, p->vTable->name, screen); + gconfGetOption (&s->object, option++, p->vTable->name); } - - g_free (screen); } - gd->reloadHandle = 0; + gc->reloadHandle = 0; return FALSE; } static Bool -gconfSetDisplayOptionForPlugin (CompDisplay *d, - const char *plugin, - const char *name, - CompOptionValue *value) +gconfSetOptionForPlugin (CompObject *object, + const char *plugin, + const char *name, + CompOptionValue *value) { - Bool status; + CompBool status; - GCONF_DISPLAY (d); + GCONF_CORE (&core); - UNWRAP (gd, d, setDisplayOptionForPlugin); - status = (*d->setDisplayOptionForPlugin) (d, plugin, name, value); - WRAP (gd, d, setDisplayOptionForPlugin, gconfSetDisplayOptionForPlugin); + UNWRAP (gc, &core, setOptionForPlugin); + status = (*core.setOptionForPlugin) (object, plugin, name, value); + WRAP (gc, &core, setOptionForPlugin, gconfSetOptionForPlugin); - if (status && !gd->reloadHandle) + if (status && !gc->reloadHandle) { CompPlugin *p; @@ -552,55 +505,10 @@ gconfSetDisplayOptionForPlugin (CompDisplay *d, CompOption *option; int nOption; - option = (*p->vTable->getObjectOptions) (p, &d->object, &nOption); + option = (*p->vTable->getObjectOptions) (p, object, &nOption); option = compFindOption (option, nOption, name, 0); if (option) - gconfSetOption (d, option, p->vTable->name, "allscreens"); - } - } - - return status; -} - -static Bool -gconfSetScreenOptionForPlugin (CompScreen *s, - const char *plugin, - const char *name, - CompOptionValue *value) -{ - Bool status; - - GCONF_SCREEN (s); - - UNWRAP (gs, s, setScreenOptionForPlugin); - status = (*s->setScreenOptionForPlugin) (s, plugin, name, value); - WRAP (gs, s, setScreenOptionForPlugin, gconfSetScreenOptionForPlugin); - - if (status) - { - GCONF_DISPLAY (s->display); - - if (!gd->reloadHandle) - { - CompPlugin *p; - - p = findActivePlugin (plugin); - if (p && p->vTable->getObjectOptions) - { - CompOption *option; - int nOption; - gchar *screen; - - screen = g_strdup_printf ("screen%d", s->screenNum); - - option = (*p->vTable->getObjectOptions) (p, &s->object, - &nOption); - option = compFindOption (option, nOption, name, 0); - if (option) - gconfSetOption (s->display, option, plugin, screen); - - g_free (screen); - } + gconfSetOption (object, option, p->vTable->name); } } @@ -608,37 +516,6 @@ gconfSetScreenOptionForPlugin (CompScreen *s, } static CompBool -gconfInitPluginForDisplay (CompPlugin *p, - CompDisplay *d) -{ - CompOption *option; - int nOption; - - option = (*p->vTable->getObjectOptions) (p, &d->object, &nOption); - while (nOption--) - gconfGetDisplayOption (d, option++, p->vTable->name); - - return TRUE; -} - -static CompBool -gconfInitPluginForScreen (CompPlugin *p, - CompScreen *s) -{ - CompOption *option; - int nOption; - gchar *screen = g_strdup_printf ("screen%d", s->screenNum); - - option = (*p->vTable->getObjectOptions) (p, &s->object, &nOption); - while (nOption--) - gconfGetScreenOption (s, option++, p->vTable->name, screen); - - g_free (screen); - - return TRUE; -} - -static CompBool gconfInitPluginForObject (CompPlugin *p, CompObject *o) { @@ -650,15 +527,19 @@ gconfInitPluginForObject (CompPlugin *p, status = (*core.initPluginForObject) (p, o); WRAP (gc, &core, initPluginForObject, gconfInitPluginForObject); + /* display and screen options are only supported yet */ + if (o->type != COMP_OBJECT_TYPE_DISPLAY && + o->type != COMP_OBJECT_TYPE_SCREEN) + return status; + if (status && p->vTable->getObjectOptions) { - static InitPluginForObjectProc dispTab[] = { - (InitPluginForObjectProc) 0, /* InitPluginForCore */ - (InitPluginForObjectProc) gconfInitPluginForDisplay, - (InitPluginForObjectProc) gconfInitPluginForScreen - }; + CompOption *option; + int nOption; - RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o)); + option = (*p->vTable->getObjectOptions) (p, o, &nOption); + while (nOption--) + gconfGetOption (o, option++, p->vTable->name); } return status; @@ -670,7 +551,7 @@ gconfKeyChanged (GConfClient *client, GConfEntry *entry, gpointer user_data) { - CompDisplay *display = (CompDisplay *) user_data; + CompDisplay *display = compDisplays; CompScreen *screen = NULL; CompPlugin *plugin = NULL; CompOption *option = NULL; @@ -755,12 +636,12 @@ gconfKeyChanged (GConfClient *client, { CompOptionValue value; - if (gconfReadOptionValue (display, entry, option, &value)) + if (gconfReadOptionValue (&screen->object, entry, option, &value)) { - (*screen->setScreenOptionForPlugin) (screen, - plugin->vTable->name, - option->name, - &value); + (*core.setOptionForPlugin) (&screen->object, + plugin->vTable->name, + option->name, + &value); compFiniOptionValue (&value, option->type); } @@ -778,12 +659,12 @@ gconfKeyChanged (GConfClient *client, { CompOptionValue value; - if (gconfReadOptionValue (display, entry, option, &value)) + if (gconfReadOptionValue (&display->object, entry, option, &value)) { - (*display->setDisplayOptionForPlugin) (display, - plugin->vTable->name, - option->name, - &value); + (*core.setOptionForPlugin) (&display->object, + plugin->vTable->name, + option->name, + &value); compFiniOptionValue (&value, option->type); } @@ -828,14 +709,20 @@ gconfInitCore (CompPlugin *p, if (!gc) return FALSE; - displayPrivateIndex = allocateDisplayPrivateIndex (); - if (displayPrivateIndex < 0) - { - free (gc); - return FALSE; - } + g_type_init (); + + gc->client = gconf_client_get_default (); + + gconf_client_add_dir (gc->client, "/apps/" APP_NAME, + GCONF_CLIENT_PRELOAD_NONE, NULL); + + gc->reloadHandle = compAddTimeout (0, gconfReload, 0); + + gconf_client_notify_add (gc->client, "/apps/" APP_NAME, gconfKeyChanged, + c, NULL, NULL); WRAP (gc, c, initPluginForObject, gconfInitPluginForObject); + WRAP (gc, c, setOptionForPlugin, gconfSetOptionForPlugin); c->object.privates[corePrivateIndex].ptr = gc; @@ -850,8 +737,6 @@ gconfFiniCore (CompPlugin *p, UNWRAP (gc, c, initPluginForObject); - freeDisplayPrivateIndex (displayPrivateIndex); - free (gc); } @@ -859,96 +744,18 @@ static Bool gconfInitDisplay (CompPlugin *p, CompDisplay *d) { - GConfDisplay *gd; - - gd = malloc (sizeof (GConfDisplay)); - if (!gd) - return FALSE; - - gd->screenPrivateIndex = allocateScreenPrivateIndex (d); - if (gd->screenPrivateIndex < 0) - { - free (gd); - return FALSE; - } - - g_type_init (); - - gd->client = gconf_client_get_default (); - - gconf_client_add_dir (gd->client, "/apps/" APP_NAME, - GCONF_CLIENT_PRELOAD_NONE, NULL); - - gd->reloadHandle = compAddTimeout (0, gconfReload, (void *) d); - - WRAP (gd, d, setDisplayOptionForPlugin, gconfSetDisplayOptionForPlugin); - - d->object.privates[displayPrivateIndex].ptr = gd; - - gconf_client_notify_add (gd->client, "/apps/" APP_NAME, gconfKeyChanged, - d, NULL, NULL); - gconfSendGLibNotify (d); return TRUE; } -static void -gconfFiniDisplay (CompPlugin *p, - CompDisplay *d) -{ - GCONF_DISPLAY (d); - - if (gd->reloadHandle) - compRemoveTimeout (gd->reloadHandle); - - g_object_unref (gd->client); - - UNWRAP (gd, d, setDisplayOptionForPlugin); - - freeScreenPrivateIndex (d, gd->screenPrivateIndex); - - free (gd); -} - -static Bool -gconfInitScreen (CompPlugin *p, - CompScreen *s) -{ - GConfScreen *gs; - - GCONF_DISPLAY (s->display); - - gs = malloc (sizeof (GConfScreen)); - if (!gs) - return FALSE; - - WRAP (gs, s, setScreenOptionForPlugin, gconfSetScreenOptionForPlugin); - - s->object.privates[gd->screenPrivateIndex].ptr = gs; - - return TRUE; -} - -static void -gconfFiniScreen (CompPlugin *p, - CompScreen *s) -{ - GCONF_SCREEN (s); - - UNWRAP (gs, s, setScreenOptionForPlugin); - - free (gs); -} - static CompBool gconfInitObject (CompPlugin *p, CompObject *o) { static InitPluginObjectProc dispTab[] = { (InitPluginObjectProc) gconfInitCore, - (InitPluginObjectProc) gconfInitDisplay, - (InitPluginObjectProc) gconfInitScreen + (InitPluginObjectProc) gconfInitDisplay }; RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o)); @@ -959,9 +766,7 @@ gconfFiniObject (CompPlugin *p, CompObject *o) { static FiniPluginObjectProc dispTab[] = { - (FiniPluginObjectProc) gconfFiniCore, - (FiniPluginObjectProc) gconfFiniDisplay, - (FiniPluginObjectProc) gconfFiniScreen + (FiniPluginObjectProc) gconfFiniCore }; DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o)); diff --git a/plugins/ini.c b/plugins/ini.c index 9044df25..0f3d4edd 100644 --- a/plugins/ini.c +++ b/plugins/ini.c @@ -44,24 +44,14 @@ ((IniCore *) (c)->object.privates[corePrivateIndex].ptr) #define INI_CORE(c) \ IniCore *ic = GET_INI_CORE (c) -#define GET_INI_DISPLAY(d) \ - ((IniDisplay *) (d)->object.privates[displayPrivateIndex].ptr) -#define INI_DISPLAY(d) \ - IniDisplay *id = GET_INI_DISPLAY (d) -#define GET_INI_SCREEN(s, id) \ - ((IniScreen *) (s)->object.privates[(id)->screenPrivateIndex].ptr) -#define INI_SCREEN(s) \ - IniScreen *is = GET_INI_SCREEN (s, GET_INI_DISPLAY (s->display)) #define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption)) static int corePrivateIndex; -static int displayPrivateIndex; static CompMetadata iniMetadata; -static Bool iniSaveOptions (CompDisplay *d, - int screen, +static Bool iniSaveOptions (CompObject *object, const char *plugin); /* @@ -84,39 +74,23 @@ struct _IniFileData { * IniCore */ typedef struct _IniCore { - InitPluginForObjectProc initPluginForObject; -} IniCore; - -/* - * IniDisplay - */ -typedef struct _IniDisplay { - int screenPrivateIndex; - - CompFileWatchHandle directoryWatch; - - SetDisplayOptionForPluginProc setDisplayOptionForPlugin; + CompFileWatchHandle directoryWatch; - IniFileData *fileData; -} IniDisplay; + IniFileData *fileData; -/* - * IniScreeen - */ -typedef struct _IniScreen { - SetScreenOptionForPluginProc setScreenOptionForPlugin; -} IniScreen; + InitPluginForObjectProc initPluginForObject; + SetOptionForPluginProc setOptionForPlugin; +} IniCore; static IniFileData * -iniGetFileDataFromFilename (CompDisplay *d, - const char *filename) +iniGetFileDataFromFilename (const char *filename) { int len, i; int pluginSep = 0, screenSep = 0; char *pluginStr, *screenStr; IniFileData *fd; - INI_DISPLAY (d); + INI_CORE (&core); if (!filename) return NULL; @@ -129,7 +103,7 @@ iniGetFileDataFromFilename (CompDisplay *d, if ((filename[0]=='.') || (filename[len-1]=='~')) return NULL; - for (fd = id->fileData; fd; fd = fd->next) + for (fd = ic->fileData; fd; fd = fd->next) if (strcmp (fd->filename, filename) == 0) return fd; @@ -164,7 +138,7 @@ iniGetFileDataFromFilename (CompDisplay *d, fd->next = newFd; else */ - id->fileData = newFd; + ic->fileData = newFd; newFd->prev = fd; newFd->next = NULL; @@ -192,7 +166,7 @@ iniGetFileDataFromFilename (CompDisplay *d, if (strcmp (screenStr, "allscreens") == 0) newFd->screen = -1; else - newFd->screen = atoi(&screenStr[6]); + newFd->screen = atoi (&screenStr[6]); newFd->blockReads = FALSE; newFd->blockWrites = FALSE; @@ -273,8 +247,7 @@ iniGetHomeDir (char **homeDir) } static Bool -iniGetFilename (CompDisplay *d, - int screen, +iniGetFilename (CompObject *object, const char *plugin, char **filename) { @@ -286,21 +259,19 @@ iniGetFilename (CompDisplay *d, if (!screenStr) return FALSE; - if (screen > -1) + if (object->type == COMP_OBJECT_TYPE_SCREEN) { - for (s = d->screens; s ; s = s->next) - if (s && (s->screenNum == screen)) + for (s = compDisplays->screens; s; s = s->next) + if (&s->object == object) break; if (!s) { - compLogMessage (d, "ini", CompLogLevelWarn, - "Invalid screen number passed " \ - "to iniGetFilename %d", screen); free(screenStr); return FALSE; } - snprintf (screenStr, 12, "screen%d", screen); + + snprintf (screenStr, 12, "screen%d", s->screenNum); } else { @@ -467,14 +438,12 @@ iniMakeDirectories (void) } static Bool -iniLoadOptionsFromFile (CompDisplay *d, - FILE *optionFile, - const char *plugin, - int screen, - Bool *reSave) +iniLoadOptionsFromFile (FILE *optionFile, + CompObject *object, + const char *plugin, + Bool *reSave) { CompOption *option = NULL, *o; - CompScreen *s = NULL; CompPlugin *p = NULL; CompOptionValue value; char *optionName = NULL, *optionValue = NULL; @@ -487,7 +456,7 @@ iniLoadOptionsFromFile (CompDisplay *d, p = findActivePlugin (plugin); if (!p) { - compLogMessage (d, "ini", CompLogLevelWarn, + compLogMessage (NULL, "ini", CompLogLevelWarn, "Could not find running plugin " \ "%s (iniLoadOptionsFromFile)", plugin); return FALSE; @@ -498,28 +467,8 @@ iniLoadOptionsFromFile (CompDisplay *d, return FALSE; } - if (screen > -1) - { - for (s = d->screens; s; s = s->next) - if (s && s->screenNum == screen) - break; - - if (!s) - { - compLogMessage (d, "ini", CompLogLevelWarn, - "Invalid screen number passed to " \ - "iniLoadOptionsFromFile %d", screen); - return FALSE; - } - } - if (p->vTable->getObjectOptions) - { - if (s) - option = (*p->vTable->getObjectOptions) (p, &s->object, &nOption); - else - option = (*p->vTable->getObjectOptions) (p, &d->object, &nOption); - } + option = (*p->vTable->getObjectOptions) (p, object, &nOption); while (fgets (tmp, MAX_OPTION_LENGTH, optionFile) != NULL) { @@ -527,8 +476,9 @@ iniLoadOptionsFromFile (CompDisplay *d, if (!iniParseLine (tmp, &optionName, &optionValue)) { - compLogMessage (d, "ini", CompLogLevelWarn, - "Ignoring line '%s' in %s %i", tmp, plugin, screen); + compLogMessage (NULL, "ini", CompLogLevelWarn, + "Ignoring line '%s' in %s", + tmp, plugin); continue; } @@ -562,11 +512,13 @@ iniLoadOptionsFromFile (CompDisplay *d, break; case CompOptionTypeKey: hasValue = TRUE; - stringToKeyAction (d, optionValue, &value.action); + stringToKeyAction (GET_CORE_DISPLAY (object), + optionValue, &value.action); break; case CompOptionTypeButton: hasValue = TRUE; - stringToButtonAction (d, optionValue, &value.action); + stringToButtonAction (GET_CORE_DISPLAY (object), + optionValue, &value.action); break; case CompOptionTypeEdge: hasValue = TRUE; @@ -577,7 +529,9 @@ iniLoadOptionsFromFile (CompDisplay *d, value.action.bell = (Bool) atoi (optionValue); break; case CompOptionTypeList: - hasValue = csvToList (d, optionValue, &value.list, value.list.type); + hasValue = csvToList (GET_CORE_DISPLAY (object), + optionValue, + &value.list, value.list.type); break; case CompOptionTypeMatch: hasValue = TRUE; @@ -590,15 +544,11 @@ iniLoadOptionsFromFile (CompDisplay *d, if (hasValue) { - if (s) - status = (*s->setScreenOptionForPlugin) (s, - plugin, - optionName, - &value); - else - status = (*d->setDisplayOptionForPlugin) (d, plugin, - optionName, - &value); + status = (*core.setOptionForPlugin) (object, + plugin, + optionName, + &value); + if (o->type == CompOptionTypeMatch) { matchFini (&value.match); @@ -625,28 +575,22 @@ iniLoadOptionsFromFile (CompDisplay *d, } static Bool -iniSaveOptions (CompDisplay *d, - int screen, - const char *plugin) +iniSaveOptions (CompObject *object, + const char *plugin) { CompScreen *s = NULL; CompOption *option = NULL; int nOption = 0; char *filename, *directory, *fullPath, *strVal = NULL; - if (screen > -1) + if (object->type == COMP_OBJECT_TYPE_SCREEN) { - for (s = d->screens; s; s = s->next) - if (s && s->screenNum == screen) + for (s = compDisplays->screens; s; s = s->next) + if (&s->object == object) break; if (!s) - { - compLogMessage (d, "ini", CompLogLevelWarn, - "Invalid screen number passed to " \ - "iniSaveOptions %d", screen); return FALSE; - } } if (plugin) @@ -656,10 +600,7 @@ iniSaveOptions (CompDisplay *d, if (!p) return FALSE; - if (s) - option = (*p->vTable->getObjectOptions) (p, &s->object, &nOption); - else - option = (*p->vTable->getObjectOptions) (p, &d->object, &nOption); + option = (*p->vTable->getObjectOptions) (p, object, &nOption); } else { @@ -669,12 +610,12 @@ iniSaveOptions (CompDisplay *d, if (!option) return FALSE; - if (!iniGetFilename (d, screen, plugin, &filename)) + if (!iniGetFilename (object, plugin, &filename)) return FALSE; IniFileData *fileData; - fileData = iniGetFileDataFromFilename (d, filename); + fileData = iniGetFileDataFromFilename (filename); if (!fileData || (fileData && fileData->blockWrites)) { free (filename); @@ -701,7 +642,7 @@ iniSaveOptions (CompDisplay *d, if (!optionFile) { - compLogMessage (d, "ini", CompLogLevelError, + compLogMessage (NULL, "ini", CompLogLevelError, "Failed to write to %s, check you " \ "have the correct permissions", fullPath); free (filename); @@ -730,7 +671,8 @@ iniSaveOptions (CompDisplay *d, case CompOptionTypeEdge: case CompOptionTypeBell: case CompOptionTypeMatch: - strVal = iniOptionValueToString (d, &option->value, option->type); + strVal = iniOptionValueToString (GET_CORE_DISPLAY (object), + &option->value, option->type); if (strVal) { fprintf (optionFile, "%s=%s\n", option->name, strVal); @@ -764,7 +706,8 @@ iniSaveOptions (CompDisplay *d, for (i = 0; i < option->value.list.nValue; i++) { - itemVal = iniOptionValueToString (d, + itemVal = + iniOptionValueToString (GET_CORE_DISPLAY (object), &option->value.list.value[i], option->value.list.type); if (!firstInList) @@ -783,7 +726,7 @@ iniSaveOptions (CompDisplay *d, break; } default: - compLogMessage (d, "ini", CompLogLevelWarn, + compLogMessage (NULL, "ini", CompLogLevelWarn, "Unknown list option type %d, %s\n", option->value.list.type, optionTypeToString (option->value.list.type)); @@ -809,9 +752,8 @@ iniSaveOptions (CompDisplay *d, } static Bool -iniLoadOptions (CompDisplay *d, - int screen, - const char *plugin) +iniLoadOptions (CompObject *object, + const char *plugin) { char *filename, *directory, *fullPath; FILE *optionFile; @@ -822,10 +764,10 @@ iniLoadOptions (CompDisplay *d, optionFile = NULL; fileData = NULL; - if (!iniGetFilename (d, screen, plugin, &filename)) + if (!iniGetFilename (object, plugin, &filename)) return FALSE; - fileData = iniGetFileDataFromFilename (d, filename); + fileData = iniGetFileDataFromFilename (filename); if (!fileData || (fileData && fileData->blockReads)) { free(filename); @@ -855,7 +797,7 @@ iniLoadOptions (CompDisplay *d, if (!optionFile) { - if (!plugin && (screen == -1)) + if (!plugin && object->type == COMP_OBJECT_TYPE_DISPLAY) { CompOptionValue value; value.list.value = malloc (NUM_DEFAULT_PLUGINS * sizeof (CompListValue)); @@ -867,7 +809,7 @@ iniLoadOptions (CompDisplay *d, return FALSE; } - if (!csvToList (d, DEFAULT_PLUGINS, + if (!csvToList (GET_CORE_DISPLAY (object), DEFAULT_PLUGINS, &value.list, CompOptionTypeString)) { @@ -879,19 +821,20 @@ iniLoadOptions (CompDisplay *d, value.list.type = CompOptionTypeString; - compLogMessage (d, "ini", CompLogLevelWarn, + compLogMessage (NULL, "ini", CompLogLevelWarn, "Could not open main display config file %s", fullPath); - compLogMessage (d, "ini", CompLogLevelWarn, + compLogMessage (NULL, "ini", CompLogLevelWarn, "Loading default plugins (%s)", DEFAULT_PLUGINS); - (*d->setDisplayOptionForPlugin) (d, "core", "active_plugins", - &value); + (*core.setOptionForPlugin) (&compDisplays->object, + "core", "active_plugins", + &value); free (value.list.value); fileData->blockWrites = FALSE; - iniSaveOptions (d, screen, plugin); + iniSaveOptions (object, plugin); fileData->blockWrites = TRUE; @@ -907,13 +850,13 @@ iniLoadOptions (CompDisplay *d, } else { - compLogMessage (d, "ini", CompLogLevelWarn, + compLogMessage (NULL, "ini", CompLogLevelWarn, "Could not open config file %s - using " \ "defaults for %s", fullPath, (plugin)?plugin:"core"); fileData->blockWrites = FALSE; - iniSaveOptions (d, screen, plugin); + iniSaveOptions (object, plugin); fileData->blockWrites = TRUE; @@ -930,7 +873,7 @@ iniLoadOptions (CompDisplay *d, fileData->blockWrites = TRUE; - loadRes = iniLoadOptionsFromFile (d, optionFile, plugin, screen, &reSave); + loadRes = iniLoadOptionsFromFile (optionFile, object, plugin, &reSave); fileData->blockWrites = FALSE; @@ -939,7 +882,7 @@ iniLoadOptions (CompDisplay *d, if (loadRes && reSave) { fileData->blockReads = TRUE; - iniSaveOptions (d, screen, plugin); + iniSaveOptions (object, plugin); fileData->blockReads = FALSE; } @@ -954,26 +897,37 @@ static void iniFileModified (const char *name, void *closure) { - CompDisplay *d; IniFileData *fd; - d = (CompDisplay *) closure; - - fd = iniGetFileDataFromFilename (d, name); + fd = iniGetFileDataFromFilename (name); if (fd) { - iniLoadOptions (d, fd->screen, fd->plugin); + if (fd->screen < 0) + { + iniLoadOptions (&compDisplays->object, fd->plugin); + } + else + { + CompScreen *s; + + for (s = compDisplays->screens; s; s = s->next) + if (s->screenNum == fd->screen) + break; + + if (s) + iniLoadOptions (&s->object, fd->plugin); + } } } static void -iniFreeFileData (CompDisplay *d) +iniFreeFileData (void) { IniFileData *fd, *tmp; - INI_DISPLAY (d); + INI_CORE (&core); - fd = id->fileData; + fd = ic->fileData; while (fd) { @@ -991,7 +945,7 @@ static Bool iniInitPluginForDisplay (CompPlugin *p, CompDisplay *d) { - iniLoadOptions (d, -1, p->vTable->name); + iniLoadOptions (&d->object, p->vTable->name); return TRUE; } @@ -1000,7 +954,7 @@ static Bool iniInitPluginForScreen (CompPlugin *p, CompScreen *s) { - iniLoadOptions (s->display, s->screenNum, p->vTable->name); + iniLoadOptions (&s->object, p->vTable->name); return TRUE; } @@ -1031,45 +985,19 @@ iniInitPluginForObject (CompPlugin *p, return status; } -static Bool -iniSetDisplayOptionForPlugin (CompDisplay *d, - const char *plugin, - const char *name, - CompOptionValue *value) -{ - Bool status; - - INI_DISPLAY (d); - - UNWRAP (id, d, setDisplayOptionForPlugin); - status = (*d->setDisplayOptionForPlugin) (d, plugin, name, value); - WRAP (id, d, setDisplayOptionForPlugin, iniSetDisplayOptionForPlugin); - - if (status) - { - CompPlugin *p; - - p = findActivePlugin (plugin); - if (p && p->vTable->getObjectOptions) - iniSaveOptions (d, -1, plugin); - } - - return status; -} - -static Bool -iniSetScreenOptionForPlugin (CompScreen *s, - const char *plugin, - const char *name, - CompOptionValue *value) +static CompBool +iniSetOptionForPlugin (CompObject *object, + const char *plugin, + const char *name, + CompOptionValue *value) { - Bool status; + CompBool status; - INI_SCREEN (s); + INI_CORE (&core); - UNWRAP (is, s, setScreenOptionForPlugin); - status = (*s->setScreenOptionForPlugin) (s, plugin, name, value); - WRAP (is, s, setScreenOptionForPlugin, iniSetScreenOptionForPlugin); + UNWRAP (ic, &core, setOptionForPlugin); + status = (*core.setOptionForPlugin) (object, plugin, name, value); + WRAP (ic, &core, setOptionForPlugin, iniSetOptionForPlugin); if (status) { @@ -1077,7 +1005,7 @@ iniSetScreenOptionForPlugin (CompScreen *s, p = findActivePlugin (plugin); if (p && p->vTable->getObjectOptions) - iniSaveOptions (s->display, s->screenNum, plugin); + iniSaveOptions (object, plugin); } return status; @@ -1088,6 +1016,7 @@ iniInitCore (CompPlugin *p, CompCore *c) { IniCore *ic; + char *homeDir; if (!checkPluginABI ("core", CORE_ABIVERSION)) return FALSE; @@ -1096,14 +1025,21 @@ iniInitCore (CompPlugin *p, if (!ic) return FALSE; - displayPrivateIndex = allocateDisplayPrivateIndex (); - if (displayPrivateIndex < 0) + ic->fileData = NULL; + ic->directoryWatch = 0; + + if (iniGetHomeDir (&homeDir)) { - free (ic); - return FALSE; + ic->directoryWatch = addFileWatch (homeDir, + NOTIFY_DELETE_MASK | + NOTIFY_CREATE_MASK | + NOTIFY_MODIFY_MASK, + iniFileModified, 0); + free (homeDir); } WRAP (ic, c, initPluginForObject, iniInitPluginForObject); + WRAP (ic, c, setOptionForPlugin, iniSetOptionForPlugin); c->object.privates[corePrivateIndex].ptr = ic; @@ -1118,7 +1054,10 @@ iniFiniCore (CompPlugin *p, UNWRAP (ic, c, initPluginForObject); - freeDisplayPrivateIndex (displayPrivateIndex); + if (ic->directoryWatch) + removeFileWatch (ic->directoryWatch); + + iniFreeFileData (); free (ic); } @@ -1126,92 +1065,19 @@ iniFiniCore (CompPlugin *p, static Bool iniInitDisplay (CompPlugin *p, CompDisplay *d) { - IniDisplay *id; - char *homeDir; - - if (!checkPluginABI ("core", CORE_ABIVERSION)) - return FALSE; - - id = malloc (sizeof (IniDisplay)); - if (!id) - return FALSE; - - id->screenPrivateIndex = allocateScreenPrivateIndex (d); - if (id->screenPrivateIndex < 0) - { - free (id); - return FALSE; - } - - id->fileData = NULL; - id->directoryWatch = 0; - - WRAP (id, d, setDisplayOptionForPlugin, iniSetDisplayOptionForPlugin); - - d->object.privates[displayPrivateIndex].ptr = id; - - iniLoadOptions (d, -1, NULL); - - if (iniGetHomeDir (&homeDir)) - { - id->directoryWatch = addFileWatch (homeDir, - NOTIFY_DELETE_MASK | - NOTIFY_CREATE_MASK | - NOTIFY_MODIFY_MASK, - iniFileModified, (void *) d); - free (homeDir); - } + iniLoadOptions (&d->object, NULL); return TRUE; } -static void -iniFiniDisplay (CompPlugin *p, CompDisplay *d) -{ - INI_DISPLAY (d); - - if (id->directoryWatch) - removeFileWatch (id->directoryWatch); - - iniFreeFileData (d); - - freeScreenPrivateIndex (d, id->screenPrivateIndex); - - UNWRAP (id, d, setDisplayOptionForPlugin); - - free (id); -} - static Bool iniInitScreen (CompPlugin *p, CompScreen *s) { - IniScreen *is; - - INI_DISPLAY (s->display); - - is = malloc (sizeof (IniScreen)); - if (!is) - return FALSE; - - s->object.privates[id->screenPrivateIndex].ptr = is; - - WRAP (is, s, setScreenOptionForPlugin, iniSetScreenOptionForPlugin); - - iniLoadOptions (s->display, s->screenNum, NULL); + iniLoadOptions (&s->object, NULL); return TRUE; } -static void -iniFiniScreen (CompPlugin *p, CompScreen *s) -{ - INI_SCREEN (s); - - UNWRAP (is, s, setScreenOptionForPlugin); - - free (is); -} - static CompBool iniInitObject (CompPlugin *p, CompObject *o) @@ -1230,9 +1096,7 @@ iniFiniObject (CompPlugin *p, CompObject *o) { static FiniPluginObjectProc dispTab[] = { - (FiniPluginObjectProc) iniFiniCore, - (FiniPluginObjectProc) iniFiniDisplay, - (FiniPluginObjectProc) iniFiniScreen + (FiniPluginObjectProc) iniFiniCore }; DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o)); @@ -1245,11 +1109,11 @@ iniInit (CompPlugin *p) 0, 0, 0, 0)) return FALSE; - displayPrivateIndex = allocateDisplayPrivateIndex (); - if (displayPrivateIndex < 0) + corePrivateIndex = allocateCorePrivateIndex (); + if (corePrivateIndex < 0) { compFiniMetadata (&iniMetadata); - return FALSE; + return FALSE; } compAddMetadataFromFile (&iniMetadata, p->vTable->name); @@ -1260,8 +1124,7 @@ iniInit (CompPlugin *p) static void iniFini (CompPlugin *p) { - if (displayPrivateIndex >= 0) - freeDisplayPrivateIndex (displayPrivateIndex); + freeCorePrivateIndex (corePrivateIndex); } static CompMetadata * diff --git a/plugins/kconfig.cpp b/plugins/kconfig.cpp index 1238e521..f471f201 100644 --- a/plugins/kconfig.cpp +++ b/plugins/kconfig.cpp @@ -34,26 +34,15 @@ static CompMetadata kconfigMetadata; static int corePrivateIndex; typedef struct _KconfigCore { - InitPluginForObjectProc initPluginForObject; -} KconfigCore; - -static int displayPrivateIndex; - -typedef struct _KconfigDisplay { - int screenPrivateIndex; - - SetDisplayOptionForPluginProc setDisplayOptionForPlugin; - KConfig *config; CompTimeoutHandle syncHandle; CompTimeoutHandle reloadHandle; CompFileWatchHandle fileWatch; -} KconfigDisplay; -typedef struct _KconfigScreen { - SetScreenOptionForPluginProc setScreenOptionForPlugin; -} KconfigScreen; + InitPluginForObjectProc initPluginForObject; + SetOptionForPluginProc setOptionForPlugin; +} KconfigCore; #define GET_KCONFIG_CORE(c) \ ((KconfigCore *) (c)->object.privates[corePrivateIndex].ptr) @@ -61,18 +50,6 @@ typedef struct _KconfigScreen { #define KCONFIG_CORE(c) \ KconfigCore *kc = GET_KCONFIG_CORE (c) -#define GET_KCONFIG_DISPLAY(d) \ - ((KconfigDisplay *) (d)->object.privates[displayPrivateIndex].ptr) - -#define KCONFIG_DISPLAY(d) \ - KconfigDisplay *kd = GET_KCONFIG_DISPLAY (d) - -#define GET_KCONFIG_SCREEN(s, kd) \ - ((KconfigScreen *) (s)->object.privates[(kd)->screenPrivateIndex].ptr) - -#define KCONFIG_SCREEN(s) \ - KconfigScreen *ks = GET_KCONFIG_SCREEN (s, \ - GET_KCONFIG_DISPLAY (s->display)) static void kconfigRcChanged (const char *name, @@ -81,13 +58,11 @@ kconfigRcChanged (const char *name, static Bool kconfigRcSync (void *closure) { - CompDisplay *d = (CompDisplay *) closure; - - KCONFIG_DISPLAY (d); + KCONFIG_CORE (&core); - kd->config->sync (); + kc->config->sync (); - kd->syncHandle = 0; + kc->syncHandle = 0; return FALSE; } @@ -109,7 +84,7 @@ kconfigValueToBool (CompOptionType type, } static QString -kconfigValueToString (CompDisplay *d, +kconfigValueToString (CompObject *object, CompOptionType type, CompOptionValue *value) { @@ -138,7 +113,7 @@ kconfigValueToString (CompDisplay *d, case CompOptionTypeKey: { char *action; - action = keyActionToString (d, &value->action); + action = keyActionToString (GET_CORE_DISPLAY (object), &value->action); if (action) { str = QString (action); @@ -148,7 +123,8 @@ kconfigValueToString (CompDisplay *d, case CompOptionTypeButton: { char *action; - action = buttonActionToString (d, &value->action); + action = buttonActionToString (GET_CORE_DISPLAY (object), + &value->action); if (action) { str = QString (action); @@ -185,29 +161,44 @@ kconfigValueToString (CompDisplay *d, return str; } +static QString +kconfigObjectString (CompObject *object) +{ + QString objectName (QString (compObjectTypeName (object->type))); + char *name; + + name = compObjectName (object); + if (name) + { + objectName += name; + free (name); + } + + return objectName; +} + static void -kconfigSetOption (CompDisplay *d, +kconfigSetOption (CompObject *object, CompOption *o, - const char *plugin, - const char *object) + const char *plugin) { - QString group (QString (plugin) + "_" + QString (object)); + QString group (QString (plugin) + "_" + kconfigObjectString (object)); - KCONFIG_DISPLAY (d); + KCONFIG_CORE (&core); - kd->config->setGroup (group); + kc->config->setGroup (group); switch (o->type) { case CompOptionTypeBool: case CompOptionTypeBell: - kd->config->writeEntry (o->name, + kc->config->writeEntry (o->name, kconfigValueToBool (o->type, &o->value)); break; case CompOptionTypeInt: - kd->config->writeEntry (o->name, o->value.i); + kc->config->writeEntry (o->name, o->value.i); break; case CompOptionTypeFloat: - kd->config->writeEntry (o->name, (double) o->value.f); + kc->config->writeEntry (o->name, (double) o->value.f); break; case CompOptionTypeString: case CompOptionTypeColor: @@ -215,8 +206,9 @@ kconfigSetOption (CompDisplay *d, case CompOptionTypeButton: case CompOptionTypeEdge: case CompOptionTypeMatch: - kd->config->writeEntry (o->name, - kconfigValueToString (d, o->type, &o->value)); + kc->config->writeEntry (o->name, + kconfigValueToString (object, o->type, + &o->value)); break; case CompOptionTypeList: { int i; @@ -228,7 +220,7 @@ kconfigSetOption (CompDisplay *d, for (i = 0; i < o->value.list.nValue; i++) list += o->value.list.value[i].i; - kd->config->writeEntry (o->name, list); + kc->config->writeEntry (o->name, list); } break; case CompOptionTypeBool: case CompOptionTypeFloat: @@ -242,11 +234,11 @@ kconfigSetOption (CompDisplay *d, QStringList list; for (i = 0; i < o->value.list.nValue; i++) - list += kconfigValueToString (d, + list += kconfigValueToString (object, o->value.list.type, &o->value.list.value[i]); - kd->config->writeEntry (o->name, list); + kc->config->writeEntry (o->name, list); } break; case CompOptionTypeAction: case CompOptionTypeList: @@ -257,12 +249,12 @@ kconfigSetOption (CompDisplay *d, return; } - if (!kd->syncHandle) - kd->syncHandle = compAddTimeout (0, kconfigRcSync, (void *) d); + if (!kc->syncHandle) + kc->syncHandle = compAddTimeout (0, kconfigRcSync, 0); } static Bool -kconfigStringToValue (CompDisplay *d, +kconfigStringToValue (CompObject *object, QString str, CompOptionType type, CompOptionValue *value) @@ -284,10 +276,12 @@ kconfigStringToValue (CompDisplay *d, return FALSE; break; case CompOptionTypeKey: - stringToKeyAction (d, str.ascii (), &value->action); + stringToKeyAction (GET_CORE_DISPLAY (object), str.ascii (), + &value->action); break; case CompOptionTypeButton: - stringToButtonAction (d, str.ascii (), &value->action); + stringToButtonAction (GET_CORE_DISPLAY (object), str.ascii (), + &value->action); break; case CompOptionTypeEdge: value->action.edgeMask = stringToEdgeMask (str.ascii ()); @@ -323,7 +317,7 @@ kconfigBoolToValue (bool b, } static Bool -kconfigReadOptionValue (CompDisplay *d, +kconfigReadOptionValue (CompObject *object, KConfig *config, CompOption *o, CompOptionValue *value) @@ -347,7 +341,8 @@ kconfigReadOptionValue (CompDisplay *d, case CompOptionTypeButton: case CompOptionTypeEdge: case CompOptionTypeMatch: - if (!kconfigStringToValue (d, config->readEntry (o->name), o->type, + if (!kconfigStringToValue (object, + config->readEntry (o->name), o->type, value)) return FALSE; break; @@ -400,7 +395,7 @@ kconfigReadOptionValue (CompDisplay *d, { for (i = 0; i < n; i++) { - if (!kconfigStringToValue (d, + if (!kconfigStringToValue (object, list[i], value->list.type, &value->list.value[i])) @@ -431,75 +426,46 @@ kconfigReadOptionValue (CompDisplay *d, } static void -kconfigGetDisplayOption (CompDisplay *d, - CompOption *o, - const char *plugin) +kconfigGetOption (CompObject *object, + CompOption *o, + const char *plugin) { - QString group (QString (plugin) + "_display"); + QString group (QString (plugin) + "_" + + kconfigObjectString (object)); const QString name (o->name); - KCONFIG_DISPLAY (d); - - kd->config->setGroup (group); - - if (kd->config->hasKey (name)) - { - CompOptionValue value; - - if (kconfigReadOptionValue (d, kd->config, o, &value)) - { - (*d->setDisplayOptionForPlugin) (d, plugin, o->name, &value); - compFiniOptionValue (&value, o->type); - } - } - else - { - kconfigSetOption (d, o, plugin, "display"); - } -} - -static void -kconfigGetScreenOption (CompScreen *s, - CompOption *o, - const char *plugin, - const char *screen) -{ - QString group (QString (plugin) + "_" + QString (screen)); - const QString name (o->name); - - KCONFIG_DISPLAY (s->display); + KCONFIG_CORE (&core); - kd->config->setGroup (group); + kc->config->setGroup (group); - if (kd->config->hasKey (name)) + if (kc->config->hasKey (name)) { CompOptionValue value; - if (kconfigReadOptionValue (s->display, kd->config, o, &value)) + if (kconfigReadOptionValue (object, kc->config, o, &value)) { - (*s->setScreenOptionForPlugin) (s, plugin, o->name, &value); - + (*core.setOptionForPlugin) (object, plugin, o->name, &value); compFiniOptionValue (&value, o->type); } } else { - kconfigSetOption (s->display, o, plugin, screen); + kconfigSetOption (object, o, plugin); } } static Bool kconfigRcReload (void *closure) { - CompDisplay *d = (CompDisplay *) closure; + CompDisplay *d = compDisplays; CompScreen *s; CompPlugin *p; CompOption *option; int nOption; - KCONFIG_DISPLAY (d); + KCONFIG_CORE (&core); - kd->config->reparseConfiguration (); + kc->config->reparseConfiguration (); for (p = getPlugins (); p; p = p->next) { @@ -508,26 +474,17 @@ kconfigRcReload (void *closure) option = (*p->vTable->getObjectOptions) (p, &d->object, &nOption); while (nOption--) - kconfigGetDisplayOption (d, option++, p->vTable->name); - } - - for (s = d->screens; s; s = s->next) - { - QString screen ("screen" + QString::number (s->screenNum)); + kconfigGetOption (&d->object, option++, p->vTable->name); - for (p = getPlugins (); p; p = p->next) + for (s = d->screens; s; s = s->next) { - if (!p->vTable->getObjectOptions) - continue; - option = (*p->vTable->getObjectOptions) (p, &s->object, &nOption); while (nOption--) - kconfigGetScreenOption (s, option++, p->vTable->name, - screen.ascii ()); + kconfigGetOption (&s->object, option++, p->vTable->name); } } - kd->reloadHandle = 0; + kc->reloadHandle = 0; return FALSE; } @@ -536,32 +493,30 @@ static void kconfigRcChanged (const char *name, void *closure) { - CompDisplay *d = (CompDisplay *) closure; - - KCONFIG_DISPLAY (d); - if (strcmp (name, COMPIZ_KCONFIG_RC) == 0) { - if (!kd->reloadHandle) - kd->reloadHandle = compAddTimeout (0, kconfigRcReload, closure); + KCONFIG_CORE (&core); + + if (!kc->reloadHandle) + kc->reloadHandle = compAddTimeout (0, kconfigRcReload, closure); } } -static Bool -kconfigSetDisplayOptionForPlugin (CompDisplay *d, - const char *plugin, - const char *name, - CompOptionValue *value) +static CompBool +kconfigSetOptionForPlugin (CompObject *object, + const char *plugin, + const char *name, + CompOptionValue *value) { - Bool status; + CompBool status; - KCONFIG_DISPLAY (d); + KCONFIG_CORE (&core); - UNWRAP (kd, d, setDisplayOptionForPlugin); - status = (*d->setDisplayOptionForPlugin) (d, plugin, name, value); - WRAP (kd, d, setDisplayOptionForPlugin, kconfigSetDisplayOptionForPlugin); + UNWRAP (kc, &core, setOptionForPlugin); + status = (*core.setOptionForPlugin) (object, plugin, name, value); + WRAP (kc, &core, setOptionForPlugin, kconfigSetOptionForPlugin); - if (status && !kd->reloadHandle) + if (status && !kc->reloadHandle) { CompPlugin *p; @@ -571,54 +526,10 @@ kconfigSetDisplayOptionForPlugin (CompDisplay *d, CompOption *option; int nOption; - option = (*p->vTable->getObjectOptions) (p, &d->object, &nOption); + option = (*p->vTable->getObjectOptions) (p, object, &nOption); option = compFindOption (option, nOption, name, 0); if (option) - kconfigSetOption (d, option, p->vTable->name, "display"); - } - } - - return status; -} - -static Bool -kconfigSetScreenOptionForPlugin (CompScreen *s, - const char *plugin, - const char *name, - CompOptionValue *value) -{ - Bool status; - - KCONFIG_SCREEN (s); - - UNWRAP (ks, s, setScreenOptionForPlugin); - status = (*s->setScreenOptionForPlugin) (s, plugin, name, value); - WRAP (ks, s, setScreenOptionForPlugin, kconfigSetScreenOptionForPlugin); - - if (status) - { - KCONFIG_DISPLAY (s->display); - - if (!kd->reloadHandle) - { - CompPlugin *p; - - p = findActivePlugin (plugin); - if (p && p->vTable->getObjectOptions) - { - CompOption *option; - int nOption; - QString screen ("screen"); - - screen += QString::number (s->screenNum); - - option = (*p->vTable->getObjectOptions) (p, &s->object, - &nOption); - option = compFindOption (option, nOption, name, 0); - if (option) - kconfigSetOption (s->display, option, plugin, - screen.ascii ()); - } + kconfigSetOption (object, option, p->vTable->name); } } @@ -626,37 +537,6 @@ kconfigSetScreenOptionForPlugin (CompScreen *s, } static CompBool -kconfigInitPluginForDisplay (CompPlugin *p, - CompDisplay *d) -{ - CompOption *option; - int nOption; - - option = (*p->vTable->getObjectOptions) (p, &d->object, &nOption); - while (nOption--) - kconfigGetDisplayOption (d, option++, p->vTable->name); - - return TRUE; -} - -static CompBool -kconfigInitPluginForScreen (CompPlugin *p, - CompScreen *s) -{ - CompOption *option; - int nOption; - QString screen ("screen"); - - screen += QString::number (s->screenNum); - - option = (*p->vTable->getObjectOptions) (p, &s->object, &nOption); - while (nOption--) - kconfigGetScreenOption (s, option++, p->vTable->name, screen.ascii ()); - - return TRUE; -} - -static CompBool kconfigInitPluginForObject (CompPlugin *p, CompObject *o) { @@ -668,15 +548,19 @@ kconfigInitPluginForObject (CompPlugin *p, status = (*core.initPluginForObject) (p, o); WRAP (kc, &core, initPluginForObject, kconfigInitPluginForObject); + /* display and screen options are only supported yet */ + if (o->type != COMP_OBJECT_TYPE_DISPLAY && + o->type != COMP_OBJECT_TYPE_SCREEN) + return status; + if (status && p->vTable->getObjectOptions) { - static InitPluginForObjectProc dispTab[] = { - (InitPluginForObjectProc) 0, /* InitPluginForCore */ - (InitPluginForObjectProc) kconfigInitPluginForDisplay, - (InitPluginForObjectProc) kconfigInitPluginForScreen - }; + CompOption *option; + int nOption; - RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o)); + option = (*p->vTable->getObjectOptions) (p, o, &nOption); + while (nOption--) + kconfigGetOption (o, option++, p->vTable->name); } return status; @@ -687,6 +571,7 @@ kconfigInitCore (CompPlugin *p, CompCore *c) { KconfigCore *kc; + QString dir; if (!checkPluginABI ("core", CORE_ABIVERSION)) return FALSE; @@ -695,137 +580,59 @@ kconfigInitCore (CompPlugin *p, if (!kc) return FALSE; - displayPrivateIndex = allocateDisplayPrivateIndex (); - if (displayPrivateIndex < 0) + kc->config = new KConfig (COMPIZ_KCONFIG_RC); + if (!kc->config) { delete kc; return FALSE; } - WRAP (kc, c, initPluginForObject, kconfigInitPluginForObject); - - c->object.privates[corePrivateIndex].ptr = kc; - - return TRUE; -} - -static void -kconfigFiniCore (CompPlugin *p, - CompCore *c) -{ - KCONFIG_CORE (c); - - UNWRAP (kc, c, initPluginForObject); - - freeDisplayPrivateIndex (displayPrivateIndex); - - delete kc; -} - -static Bool -kconfigInitDisplay (CompPlugin *p, - CompDisplay *d) -{ - KconfigDisplay *kd; - QString dir; - - kd = new KconfigDisplay; - if (!kd) - return FALSE; - - kd->config = new KConfig (COMPIZ_KCONFIG_RC); - if (!kd->config) - { - delete kd; - return FALSE; - } - - kd->screenPrivateIndex = allocateScreenPrivateIndex (d); - if (kd->screenPrivateIndex < 0) - { - delete kd->config; - delete kd; - return FALSE; - } - - kd->reloadHandle = compAddTimeout (0, kconfigRcReload, (void *) d); - kd->syncHandle = 0; - kd->fileWatch = 0; + kc->reloadHandle = compAddTimeout (0, kconfigRcReload, 0); + kc->syncHandle = 0; + kc->fileWatch = 0; dir = KGlobal::dirs ()->saveLocation ("config", QString::null, false); if (QFile::exists (dir)) { - kd->fileWatch = addFileWatch (dir.ascii (), ~0, kconfigRcChanged, - (void *) d); + kc->fileWatch = addFileWatch (dir.ascii (), ~0, kconfigRcChanged, 0); } else { - compLogMessage (d, "kconfig", CompLogLevelWarn, "Bad access \"%s\"", + compLogMessage (0, "kconfig", CompLogLevelWarn, "Bad access \"%s\"", dir.ascii ()); } - WRAP (kd, d, setDisplayOptionForPlugin, kconfigSetDisplayOptionForPlugin); + WRAP (kc, c, initPluginForObject, kconfigInitPluginForObject); + WRAP (kc, c, setOptionForPlugin, kconfigSetOptionForPlugin); - d->object.privates[displayPrivateIndex].ptr = kd; + c->object.privates[corePrivateIndex].ptr = kc; return TRUE; } static void -kconfigFiniDisplay (CompPlugin *p, - CompDisplay *d) +kconfigFiniCore (CompPlugin *p, + CompCore *c) { - KCONFIG_DISPLAY (d); + KCONFIG_CORE (c); - UNWRAP (kd, d, setDisplayOptionForPlugin); + UNWRAP (kc, c, initPluginForObject); - if (kd->reloadHandle) - compRemoveTimeout (kd->reloadHandle); + if (kc->reloadHandle) + compRemoveTimeout (kc->reloadHandle); - if (kd->syncHandle) + if (kc->syncHandle) { - compRemoveTimeout (kd->syncHandle); - kconfigRcSync (d); + compRemoveTimeout (kc->syncHandle); + kconfigRcSync (0); } - if (kd->fileWatch) - removeFileWatch (kd->fileWatch); - - freeScreenPrivateIndex (d, kd->screenPrivateIndex); + if (kc->fileWatch) + removeFileWatch (kc->fileWatch); - delete kd->config; - delete kd; -} - -static Bool -kconfigInitScreen (CompPlugin *p, - CompScreen *s) -{ - KconfigScreen *ks; - - KCONFIG_DISPLAY (s->display); - - ks = new KconfigScreen; - if (!ks) - return FALSE; - - WRAP (ks, s, setScreenOptionForPlugin, kconfigSetScreenOptionForPlugin); - - s->object.privates[kd->screenPrivateIndex].ptr = ks; - - return TRUE; -} - -static void -kconfigFiniScreen (CompPlugin *p, - CompScreen *s) -{ - KCONFIG_SCREEN (s); - - UNWRAP (ks, s, setScreenOptionForPlugin); - - delete ks; + delete kc->config; + delete kc; } static CompBool @@ -833,9 +640,7 @@ kconfigInitObject (CompPlugin *p, CompObject *o) { static InitPluginObjectProc dispTab[] = { - (InitPluginObjectProc) kconfigInitCore, - (InitPluginObjectProc) kconfigInitDisplay, - (InitPluginObjectProc) kconfigInitScreen + (InitPluginObjectProc) kconfigInitCore }; RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o)); @@ -846,9 +651,7 @@ kconfigFiniObject (CompPlugin *p, CompObject *o) { static FiniPluginObjectProc dispTab[] = { - (FiniPluginObjectProc) kconfigFiniCore, - (FiniPluginObjectProc) kconfigFiniDisplay, - (FiniPluginObjectProc) kconfigFiniScreen + (FiniPluginObjectProc) kconfigFiniCore }; DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o)); |