summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2006-07-09 01:19:34 -0400
committerKristian Høgsberg <krh@redhat.com>2006-07-09 01:19:34 -0400
commit17ddf22b324b38125d2ae51a86f7e5b4aa3b1eef (patch)
tree0e1799c02ab77693774ca69512f53efdeaa7cfdd
parent6e1e33449b905bf74da6a62a94fb7b480072f269 (diff)
Add gconf keys to control physics constants.
-rw-r--r--dock.c102
-rw-r--r--kiba.schemas45
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
@@ -860,28 +860,48 @@ set_position_from_string (KibaDock *dock, const char *string)
}
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,
GConfEntry *entry,
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
@@ -18,6 +18,51 @@
</schema>
<schema>
+ <applyto>/apps/kiba/options/elasticity</applyto>
+ <key>/schemas/apps/kiba/options/elasticity</key>
+ <owner>kiba</owner>
+ <type>float</type>
+ <default>0.9</default>
+
+ <locale name="C">
+ <short>Elasticity of objects.</short>
+ <long>
+ Determinces bounce-back amount.
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
+ <applyto>/apps/kiba/options/friction</applyto>
+ <key>/schemas/apps/kiba/options/friction</key>
+ <owner>kiba</owner>
+ <type>float</type>
+ <default>150</default>
+
+ <locale name="C">
+ <short>Friction coefficient.</short>
+ <long>
+ Determines slow-down due to friction.
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
+ <applyto>/apps/kiba/options/k</applyto>
+ <key>/schemas/apps/kiba/options/k</key>
+ <owner>kiba</owner>
+ <type>float</type>
+ <default>0.8</default>
+
+ <locale name="C">
+ <short>Spring constant.</short>
+ <long>
+ Determines the stiffness of the springs.
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
<key>/schemas/apps/kiba/launchers/file</key>
<owner>kiba</owner>
<type>string</type>