X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=tilda-window.c;h=dcef0f5b32776bc3530fe90e8dbafd286f36d7a2;hb=2b17e21d2ac627242479945521f7a8e65c51d5b5;hp=f9b1ba5ca122d7bcfcee71099106657cc28c2fb8;hpb=3390da90c845629c6c0c0b1c333555404bac5c53;p=tilda-gobject.git diff --git a/tilda-window.c b/tilda-window.c index f9b1ba5..dcef0f5 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -1,6 +1,8 @@ -#include +#include /* for strcmp() */ +#include /* for gdk_x11_window_set_user_time() */ #include "tilda.h" +#include "tilda-controller.h" #include "tilda-window.h" #include "tilda-window-dbus-glue.h" #include "tomboykeybinder.h" @@ -64,6 +66,22 @@ tilda_window_find_next_free_terminal_number (TildaWindow *self) return 0; } +/** + * Clean up and remove self completely from the program + * + * Should only be used by DBus... + */ +gboolean +tilda_window_close (TildaWindow *self) +{ + debug_enter (); + debug_assert (TILDA_IS_WINDOW(self)); + + tilda_controller_remove_window (TILDA_CONTROLLER(self->controller), self->number); + + return TRUE; +} + gboolean tilda_window_add_terminal (TildaWindow *self) { @@ -88,6 +106,9 @@ tilda_window_add_terminal (TildaWindow *self) if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) > 1) gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE); + /* Focus the VTE Terminal */ + gtk_widget_grab_focus (tt->vte_term); + return TRUE; } @@ -136,7 +157,7 @@ tilda_window_remove_terminal (TildaWindow *self, gint terminal_number) if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) < 1) { debug_printf ("no terminals left, closing window %d\n", self->number); - tilda_del_window (self->number); + tilda_controller_remove_window (TILDA_CONTROLLER(self->controller), self->number); } /* Leave the loop, we're done */ @@ -211,7 +232,12 @@ tilda_window_keybinding_cb (const gchar *keystr, gpointer data) TildaWindow *self = TILDA_WINDOW(data); TildaTerminal *tt; - // FIXME: this doesn't handle animation! + /* This call sets the X11 window property _NET_WM_USER_TIME, which GTK+ normally + * sets for us. However, because this callback is activated via a global keybinding, + * we see the event before GDK / GTK+ does. Therefore, to get the focus, we must + * set the property ourselves. */ + gdk_x11_window_set_user_time (GTK_WIDGET(self->window)->window, + tomboy_keybinder_get_current_event_time()); switch (self->state) { @@ -230,8 +256,7 @@ tilda_window_keybinding_cb (const gchar *keystr, gpointer data) "keep-above", self->keep_above, "stick", self->stick, NULL); - gtk_window_present_with_time (GTK_WINDOW(self->window), - tomboy_keybinder_get_current_event_time()); + gtk_widget_show (GTK_WIDGET(self->window)); /* Focusing the term here works perfectly, near as I can tell */ tt = tilda_window_find_current_terminal (self); @@ -273,6 +298,12 @@ tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key) if (new_key == NULL || strcmp("", new_key) == 0) return FALSE; + /* Check that no other windows are using the key */ + // FIXME: there should be a hidden option to disable this. Maybe some people want + // to have logs in two Tildas, and just show them with one key. Crazy... + if (tilda_controller_global_key_in_use(TILDA_CONTROLLER(self->controller), new_key)) + return FALSE; + /* Unbind if we were set */ if (self->key) tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb); @@ -326,6 +357,7 @@ static GObjectClass *parent_class = NULL; enum tilda_window_properties { TILDA_WINDOW_NUMBER = 1, + TILDA_WINDOW_CONTROLLER, TILDA_WINDOW_KEY, @@ -364,6 +396,7 @@ tilda_window_instance_init (GTypeInstance *instance, /* Somewhat of a "poison" value, incase we don't set this */ self->number = 0xdeadbeef; + self->controller = NULL; self->state = WINDOW_UP; } @@ -383,6 +416,11 @@ tilda_window_set_property (GObject *object, debug_printf ("window number: %d\n", self->number); break; + case TILDA_WINDOW_CONTROLLER: + self->controller = g_value_get_pointer (value); + debug_printf ("window controller: 0x%x\n", self->controller); + break; + case TILDA_WINDOW_KEY: tilda_window_try_to_bind_key (self, g_value_get_string (value)); debug_printf ("window key %s\n", self->key); @@ -496,6 +534,10 @@ tilda_window_get_property (GObject *object, g_value_set_int (value, self->number); break; + case TILDA_WINDOW_CONTROLLER: + g_value_set_pointer (value, self->controller); + break; + case TILDA_WINDOW_KEY: g_value_set_string (value, self->key); break; @@ -592,10 +634,13 @@ tilda_window_constructor (GType type, tilda_window_setup_real_transparency (self); gtk_container_add (GTK_CONTAINER(self->window), self->notebook); + g_object_set (G_OBJECT(self->notebook), "can-focus", FALSE, NULL); gtk_widget_show (self->notebook); // FIXME: Remove these, and replace with reads from the config system - g_object_set (G_OBJECT(self), "key", "F2", NULL); + gchar *mykey = g_strdup_printf ("F%d", self->number+3); // TERRIBLE HACK + g_object_set (G_OBJECT(self), "key", mykey, NULL); + g_free (mykey); g_object_set (G_OBJECT(self), "x-position", 0, "y-position", 0, NULL); g_object_set (G_OBJECT(self), "height", 400, "width", 1680, NULL); g_object_set (G_OBJECT(self), "keep-above", TRUE, "stick", TRUE, NULL); @@ -620,15 +665,6 @@ tilda_window_constructor (GType type, return obj; } -static void -my_unref (gpointer data, gpointer user_data) -{ - debug_enter (); - - // FIXME: This function should probably be eliminated. It /is/ rather ugly - g_object_unref (G_OBJECT(data)); -} - static void tilda_window_dispose (GObject *obj) { @@ -649,9 +685,13 @@ tilda_window_dispose (GObject *obj) * NOTE: See the following for how to deal with GtkObject-derived things: * http://library.gnome.org/devel/gtk/unstable/GtkObject.html */ - g_ptr_array_foreach (self->terms, my_unref, NULL); + g_ptr_array_foreach (self->terms, g_object_unref, NULL); gtk_widget_destroy (self->window); + /* Unbind if we were set */ + if (self->key) + tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb); + /* Chain up to the parent class */ G_OBJECT_CLASS (parent_class)->dispose (obj); } @@ -707,6 +747,15 @@ tilda_window_class_init (gpointer g_class, TILDA_WINDOW_NUMBER, pspec); + pspec = g_param_spec_pointer ("controller", + _("Pointer to window's controlling TildaController"), + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + + g_object_class_install_property (gobject_class, + TILDA_WINDOW_CONTROLLER, + pspec); + pspec = g_param_spec_string ("key", _("Window's drop-down keybinding"), NULL,