Add a basic pull() workalike
authorIra W. Snyder <devel@irasnyder.com>
Wed, 16 Jan 2008 07:05:45 +0000 (23:05 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Wed, 16 Jan 2008 07:05:45 +0000 (23:05 -0800)
This really needs to be expanded into the full pull() that the
old Tilda has, but this is great for testing.

tilda-window.c
tilda-window.h
tilda.c

index 884c844..3455112 100644 (file)
@@ -131,6 +131,82 @@ tilda_window_setup_real_transparency (TildaWindow *self)
        self->have_real_transparency = FALSE;
 }
 
+static void
+tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
+{
+       TildaWindow *self = TILDA_WINDOW(data);
+       g_print ("tilda_window_keybinding_cb() called! -- window %d\n", self->number);
+
+       // FIXME: this doesn't handle animation!
+
+       switch (self->state)
+       {
+               case WINDOW_UP:
+                       /* Pull Down */
+                       tomboy_window_present_hardcore (GTK_WINDOW(self->window));
+                       self->state = WINDOW_DOWN;
+                       break;
+
+               case WINDOW_DOWN:
+                       /* Pull Up */
+                       gtk_widget_hide (GTK_WIDGET(self->window));
+                       self->state = WINDOW_UP;
+                       break;
+
+               default:
+                       g_printerr ("FIXME: the window is in a bad state!\n");
+
+                       /* Pretend we're down, for good measure.... */
+                       self->state = WINDOW_DOWN;
+                       break;
+       }
+}
+
+/**
+ * Attempt to bind the new_key to show this window.
+ *
+ * Return: TRUE if successful, FALSE otherwise.
+ */
+static gboolean
+tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key)
+{
+       gboolean ret = FALSE;
+
+       /* Make sure the new key is not null in any way */
+       if (new_key == NULL || strcmp("", new_key) == 0)
+               return FALSE;
+
+       /* Unbind if we were set */
+       if (self->key)
+               tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb, self);
+
+       ret = tomboy_keybinder_bind (new_key, tilda_window_keybinding_cb, self);
+
+       /* If it was successful, update the self->key variable and be done with it */
+       if (ret)
+       {
+               g_free (self->key);
+               self->key = g_strdup (new_key);
+               return TRUE;
+       }
+
+       g_printerr ("Keybinding unsuccessful. Reverting to original key\n");
+
+       /* Not successful, so rebind the old key, and return FALSE */
+       if (self->key != NULL && strcmp("",self->key) != 0)
+       {
+               ret = tomboy_keybinder_bind (self->key, tilda_window_keybinding_cb, self);
+
+               /* Check that it went ok */
+               if (!ret)
+                       g_printerr ("Unable to bind original key as well! Oh shit...\n");
+       }
+       else
+               g_printerr ("No original key to revert to!\n");
+
+       return FALSE;
+}
+
 static void
 tilda_window_dbus_register_object (TildaWindow *tw)
 {
@@ -188,6 +264,8 @@ tilda_window_instance_init (GTypeInstance *instance,
 
        /* Somewhat of a "poison" value, incase we don't set this */
        self->number = 0xdeadbeef;
+
+       self->state = WINDOW_UP;
 }
 
 static void
@@ -206,7 +284,7 @@ tilda_window_set_property (GObject      *object,
                        break;
 
                case TILDA_WINDOW_KEY:
-                       self->key = g_value_dup_string (value);
+                       tilda_window_try_to_bind_key (self, g_value_get_string (value));
                        g_print ("window key: %s\n", self->key);
                        break;
 
@@ -419,6 +497,7 @@ tilda_window_constructor (GType                  type,
        tilda_window_add_term (self);
        tilda_window_add_term (self);
        gtk_widget_show_all (self->window);
+       self->state = WINDOW_DOWN;
 
        return obj;
 }
index e3ed508..0ff0b1f 100644 (file)
@@ -42,6 +42,7 @@ struct _TildaWindow {
        GPtrArray *terms;
 
        gint number;
+       enum window_states { WINDOW_UP, WINDOW_DOWN } state;
 
        gchar *key;
 
diff --git a/tilda.c b/tilda.c
index bbb3285..04c965a 100644 (file)
--- a/tilda.c
+++ b/tilda.c
@@ -112,6 +112,9 @@ int main (int argc, char *argv[])
        /* Initialize GTK+ (and the GObject system) */
        gtk_init (&argc, &argv);
 
+       /* Initialize the keybinder */
+       tomboy_keybinder_init ();
+
        /* Start our connection to DBus */
        tilda_initialize_dbus ();