X-Git-Url: https://www.irasnyder.com/gitweb/?p=tilda-gobject.git;a=blobdiff_plain;f=tilda-window.c;h=44a04e8e2fd3bea7b7dfef00bd047900601aca5a;hp=e3cd897d8ec43e9bacdc87dd5fa34d8c285c58f9;hb=HEAD;hpb=db28d73b3b8c0246b2414754764184e83ec9f227 diff --git a/tilda-window.c b/tilda-window.c index e3cd897..44a04e8 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -67,6 +67,26 @@ tilda_window_find_next_free_terminal_number (TildaWindow *self) return 0; } +static void +tilda_window_show_hide_tabs_if_appropriate (TildaWindow *self) +{ + debug_enter (); + debug_assert (TILDA_IS_WINDOW(self)); + + /* If we only have one tab, we have a choice to make, otherwise, always show tabs */ + if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) <= 1) + { + if (self->always_show_tabs) + gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE); + else + gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), FALSE); + } + else + { + gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE); + } +} + /** * Clean up and remove self completely from the program * @@ -102,13 +122,13 @@ tilda_window_add_terminal (TildaWindow *self) g_ptr_array_add (self->terms, tt); label = gtk_label_new ("Tilda"); - notebook_index = gtk_notebook_prepend_page (GTK_NOTEBOOK(self->notebook), tt->hbox, label); + notebook_index = gtk_notebook_append_page (GTK_NOTEBOOK(self->notebook), tt->hbox, label); gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(self->notebook), tt->hbox, self->full_width_tabs, TRUE, GTK_PACK_START); gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), notebook_index); - if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) > 1) - gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE); + /* Always show tabs if we have > 1 tab open */ + tilda_window_show_hide_tabs_if_appropriate (self); /* Focus the VTE Terminal */ gtk_widget_grab_focus (tt->vte_term); @@ -150,8 +170,7 @@ tilda_window_remove_terminal (TildaWindow *self, gint terminal_number) gtk_notebook_remove_page (GTK_NOTEBOOK (self->notebook), notebook_index); /* We should hide the tabs if there is only one tab left */ - if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) == 1) - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (self->notebook), FALSE); + tilda_window_show_hide_tabs_if_appropriate (self); /* Remove the term from our lists, then free it */ g_ptr_array_remove_fast (self->terms, tt); @@ -227,6 +246,65 @@ tilda_window_center_vertically (TildaWindow *self) g_object_set (G_OBJECT(self), "y-position", center_coord, NULL); } +/* Shamelessly adapted (read: ripped off) from gdk_window_focus() and + * http://code.google.com/p/ttm/ trunk/src/window.c set_active() + * + * Also, more thanks to halfline and marnanel from irc.gnome.org #gnome + * for their help in figuring this out. + * + * Thank you. + */ + +/* This function will make sure that tilda window becomes active (gains + * the focus) when it is called. + * + * This has to be the worst possible way of making this work, but it was the + * only way to get metacity to play nicely. All the other WM's are so nice, + * why oh why does metacity hate us so? + */ +static void +tilda_window_set_active (TildaWindow *self) +{ + debug_enter (); + debug_assert (TILDA_IS_WINDOW(self)); + + Display *x11_display = GDK_WINDOW_XDISPLAY( self->window->window ); + Window *x11_window = GDK_WINDOW_XWINDOW( self->window->window ); + Window *x11_root_window = GDK_WINDOW_XWINDOW( gtk_widget_get_root_window (self->window) ); + GdkScreen *screen = gtk_widget_get_screen (self->window); + + XEvent event; + long mask = SubstructureRedirectMask | SubstructureNotifyMask; + + if (gdk_x11_screen_supports_net_wm_hint (screen, + gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW"))) + { + event.xclient.type = ClientMessage; + event.xclient.serial = 0; + event.xclient.send_event = True; + event.xclient.display = x11_display; + event.xclient.window = x11_window; + event.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW"); + + event.xclient.format = 32; + event.xclient.data.l[0] = 2; /* pager */ + event.xclient.data.l[1] = tomboy_keybinder_get_current_event_time(); /* timestamp */ + event.xclient.data.l[2] = 0; + event.xclient.data.l[3] = 0; + event.xclient.data.l[4] = 0; + + XSendEvent (x11_display, x11_root_window, False, mask, &event); + } + else + { + /* The WM doesn't support the EWMH standards. We'll print a warning and + * try this, though it probably won't work... */ + g_printerr (_("WARNING: Window manager (%s) does not support EWMH hints\n"), + gdk_x11_screen_get_window_manager_name (screen)); + XRaiseWindow (x11_display, x11_window); + } +} + static void tilda_window_keybinding_cb (const gchar *keystr, gpointer data) { @@ -262,6 +340,9 @@ tilda_window_keybinding_cb (const gchar *keystr, gpointer data) NULL); gtk_widget_show (GTK_WIDGET(self->window)); + /* Bugfix: this code fixes metacity-2.22 */ + tilda_window_set_active (self); + /* Focusing the term here works perfectly, near as I can tell */ tt = tilda_window_find_current_terminal (self); gtk_widget_grab_focus (GTK_WIDGET(tt->vte_term)); @@ -689,6 +770,8 @@ enum tilda_window_properties { TILDA_WINDOW_CENTERED_HORIZONTALLY, TILDA_WINDOW_CENTERED_VERTICALLY, TILDA_WINDOW_FULL_WIDTH_TABS, + TILDA_WINDOW_ALWAYS_SHOW_TABS, + TILDA_WINDOW_ALWAYS_SHOW_BORDER, TILDA_WINDOW_HAVE_REAL_TRANSPARENCY, }; @@ -978,6 +1061,18 @@ tilda_window_set_property (GObject *object, debug_printf ("window full width tabs: %d\n", self->full_width_tabs); break; + case TILDA_WINDOW_ALWAYS_SHOW_TABS: + self->always_show_tabs = g_value_get_boolean (value); + tilda_window_show_hide_tabs_if_appropriate (self); + debug_printf ("window always show tabs: %d\n", self->always_show_tabs); + break; + + case TILDA_WINDOW_ALWAYS_SHOW_BORDER: + self->always_show_border = g_value_get_boolean (value); + gtk_notebook_set_show_border (GTK_NOTEBOOK(self->notebook), self->always_show_border); + debug_printf ("window always show border: %d\n", self->always_show_border); + break; + case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY: self->have_real_transparency = g_value_get_boolean (value); debug_printf ("window have real transp: %d\n", self->have_real_transparency); @@ -1140,6 +1235,14 @@ tilda_window_get_property (GObject *object, g_value_set_boolean (value, self->full_width_tabs); break; + case TILDA_WINDOW_ALWAYS_SHOW_TABS: + g_value_set_boolean (value, self->always_show_tabs); + break; + + case TILDA_WINDOW_ALWAYS_SHOW_BORDER: + g_value_set_boolean (value, self->always_show_border); + break; + case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY: g_value_set_boolean (value, self->have_real_transparency); break; @@ -1232,20 +1335,20 @@ tilda_window_constructor (GType type, tilda_window_set_property_from_config (self, "centered-horizontally"); tilda_window_set_property_from_config (self, "centered-vertically"); tilda_window_set_property_from_config (self, "full-width-tabs"); + tilda_window_set_property_from_config (self, "always-show-tabs"); + tilda_window_set_property_from_config (self, "always-show-border"); /* Add the initial terminal(s) */ for (i=0; iinitial_terminals; ++i) tilda_window_add_terminal (self); - /* Show us if we're ready. If not, just remain hidden. All sub-widgets must - * be gtk_widget_show()n by this point. */ + /* Realize the window (only sets up X resources), and set its current state */ + gtk_widget_realize (self->window); + self->state = WINDOW_UP; + + /* If we should be shown now, do a mock call of the global callback */ if (!self->hidden_at_start) - { - gtk_widget_show (self->window); - self->state = WINDOW_DOWN; - } - else - self->state = WINDOW_UP; + tilda_window_keybinding_cb (NULL, self); /* Register this object with DBus */ tilda_window_dbus_register_object (self); @@ -1689,6 +1792,26 @@ tilda_window_class_init (gpointer g_class, TILDA_WINDOW_FULL_WIDTH_TABS, pspec); + pspec = g_param_spec_boolean ("always-show-tabs", + _("Always show the tab bar, regardless of the number of open tabs"), + NULL, + TRUE, + G_PARAM_READWRITE); + + g_object_class_install_property (gobject_class, + TILDA_WINDOW_ALWAYS_SHOW_TABS, + pspec); + + pspec = g_param_spec_boolean ("always-show-border", + _("Always show the window borders, regardless of the number of open tabs"), + NULL, + TRUE, + G_PARAM_READWRITE); + + g_object_class_install_property (gobject_class, + TILDA_WINDOW_ALWAYS_SHOW_BORDER, + pspec); + pspec = g_param_spec_boolean ("have-real-transparency", NULL, NULL, FALSE, G_PARAM_READABLE);