From 17ddf22b324b38125d2ae51a86f7e5b4aa3b1eef Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Sun, 9 Jul 2006 01:19:34 -0400 Subject: Add gconf keys to control physics constants. --- dock.c | 102 +++++++++++++++++++++++++++++++++++++++++------------------ kiba.schemas | 45 ++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 31 deletions(-) diff --git a/dock.c b/dock.c index e4321f8..5676f63 100644 --- a/dock.c +++ b/dock.c @@ -859,6 +859,38 @@ set_position_from_string (KibaDock *dock, const char *string) printf ("invalid position\n"); } +static void +set_option (KibaDock *dock, GConfEntry *entry) +{ + const char *value; + char *key; + int i; + struct { const char *name; size_t offset; } options[] = { + { "elasticity", G_STRUCT_OFFSET (Model, elasticity) }, + { "friction", G_STRUCT_OFFSET (Model, friction) }, + { "k", G_STRUCT_OFFSET (Model, k) } + }; + + if (strcmp (entry->key, KIBA_GCONF_PATH "/options/position") == 0 && + entry->value != NULL && + entry->value->type == GCONF_VALUE_STRING) + { + value = gconf_value_get_string (entry->value); + set_position_from_string (dock, value); + } + else for (i = 0; i < G_N_ELEMENTS (options); i++) { + key = g_strdup_printf (KIBA_GCONF_PATH "/options/%s", options[i].name); + if (strcmp (entry->key, key) == 0 && + entry->value != NULL && + entry->value->type == GCONF_VALUE_FLOAT) + { + G_STRUCT_MEMBER (double, &dock->model, options[i].offset) = + gconf_value_get_float (entry->value); + } + g_free (key); + } +} + static void options_changed_callback(GConfClient *client, guint cnxn_id, @@ -866,22 +898,10 @@ options_changed_callback(GConfClient *client, gpointer user_data) { KibaDock *dock; - const char *value; dock = KIBA_DOCK (user_data); - if (strcmp (entry->key, KIBA_GCONF_PATH "/options/position") == 0) - { - if (entry->value == NULL || entry->value->type != GCONF_VALUE_STRING) - { - printf ("unset or wrong type\n"); - } - else - { - value = gconf_value_get_string (entry->value); - set_position_from_string (dock, value); - } - } + set_option (dock, entry); } static void @@ -911,7 +931,6 @@ launchers_changed_callback(GConfClient *client, path = g_strdup (entry->key); last_slash = strrchr (path, '/'); *last_slash = '\0'; - printf ("entry: key = %s, path = %s\n", entry->key, path); launcher = kiba_launcher_new (dock, path); g_free (path); @@ -925,10 +944,9 @@ launchers_changed_callback(GConfClient *client, } static void -add_launchers (KibaDock *dock, GConfClient *gconf_client) +init_from_gconf (KibaDock *dock, GConfClient *gconf_client, GError **error) { - GSList *launchers, *l; - GError *error = NULL; + GSList *launchers, *options, *l; KibaLauncher *launcher; GdkScreen *screen; int width, height; @@ -939,12 +957,9 @@ add_launchers (KibaDock *dock, GConfClient *gconf_client) launchers = gconf_client_all_dirs (gconf_client, KIBA_GCONF_PATH "/launchers", - &error); - if (error != NULL) - { - printf ("error getting launchers: %s\n", error->message); - g_free (error->message); - } + error); + if (*error != NULL) + return; for (l = launchers; l != NULL; l = l->next) { @@ -957,6 +972,19 @@ add_launchers (KibaDock *dock, GConfClient *gconf_client) g_random_int_range (0, width), g_random_int_range (0, height)); } + + options = gconf_client_all_entries (gconf_client, + KIBA_GCONF_PATH "/options", + error); + if (*error != NULL) + return; + + for (l = options; l != NULL; l = l->next) + { + GConfEntry *entry = l->data; + + set_option (dock, entry); + } } int main (int argc, char *argv[]) @@ -964,7 +992,6 @@ int main (int argc, char *argv[]) GtkWidget *dock; GConfClient *gconf_client; GError *error = NULL; - char *position; gtk_init (&argc, &argv); @@ -975,23 +1002,36 @@ int main (int argc, char *argv[]) gconf_client_add_dir (gconf_client, KIBA_GCONF_PATH, GCONF_CLIENT_PRELOAD_NONE, &error); - position = gconf_client_get_string (gconf_client, - KIBA_GCONF_PATH "/options/position", - &error); - set_position_from_string (KIBA_DOCK (dock), position); - g_free (position); - gconf_client_notify_add(gconf_client, KIBA_GCONF_PATH "/options", options_changed_callback, dock, NULL, &error); + if (error != NULL) + { + g_error ("Failed to listen for " + KIBA_GCONF_PATH "/options notifications: %s", + error->message); + exit (1); + } gconf_client_notify_add(gconf_client, KIBA_GCONF_PATH "/launchers", launchers_changed_callback, dock, NULL, &error); + if (error != NULL) + { + g_error ("Failed to listen for " + KIBA_GCONF_PATH "/launchers notifications: %s", + error->message); + exit (1); + } - add_launchers (KIBA_DOCK (dock), gconf_client); + init_from_gconf (KIBA_DOCK (dock), gconf_client, &error); + if (error != NULL) + { + g_error ("Failed to read config from gconf: %s", error->message); + exit (1); + } gtk_widget_show (dock); diff --git a/kiba.schemas b/kiba.schemas index 3edf52f..b7688bd 100644 --- a/kiba.schemas +++ b/kiba.schemas @@ -17,6 +17,51 @@ + + /apps/kiba/options/elasticity + /schemas/apps/kiba/options/elasticity + kiba + float + 0.9 + + + Elasticity of objects. + + Determinces bounce-back amount. + + + + + + /apps/kiba/options/friction + /schemas/apps/kiba/options/friction + kiba + float + 150 + + + Friction coefficient. + + Determines slow-down due to friction. + + + + + + /apps/kiba/options/k + /schemas/apps/kiba/options/k + kiba + float + 0.8 + + + Spring constant. + + Determines the stiffness of the springs. + + + + /schemas/apps/kiba/launchers/file kiba -- cgit v1.2.3