+/**
+ * This sets up the given TildaWindow for the capability of real
+ * transparency, if the X server is capable of it. */
+static void
+tilda_window_setup_real_transparency (TildaWindow *self)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ GdkScreen *screen;
+ GdkColormap *colormap;
+
+ screen = gtk_widget_get_screen (GTK_WIDGET(self->window));
+ colormap = gdk_screen_get_rgba_colormap (screen);
+
+ /* If possible, set the RGBA colormap so VTE can use real alpha
+ * channels for transparency. */
+ if (colormap != NULL && gdk_screen_is_composited (screen))
+ {
+ gtk_widget_set_colormap (GTK_WIDGET(self->window), colormap);
+ self->have_real_transparency = TRUE;
+ return;
+ }
+
+ self->have_real_transparency = FALSE;
+}
+
+/* Center the given TildaWindow in the horizontal axis */
+static void
+tilda_window_center_horizontally (TildaWindow *self)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ const gint screen_center = gdk_screen_width() / 2;
+ const gint tilda_center = self->width / 2;
+ const gint center_coord = screen_center - tilda_center;
+
+ g_object_set (G_OBJECT(self), "x-position", center_coord, NULL);
+}
+
+/* Center the given TildaWindow in the vertical axis */
+static void
+tilda_window_center_vertically (TildaWindow *self)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ const gint screen_center = gdk_screen_height() / 2;
+ const gint tilda_center = self->height / 2;
+ const gint center_coord = screen_center - tilda_center;
+
+ g_object_set (G_OBJECT(self), "y-position", center_coord, NULL);
+}
+
+static void
+tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(data));
+
+ TildaWindow *self = TILDA_WINDOW(data);
+ TildaTerminal *tt;
+
+ // FIXME: this doesn't handle animation!
+
+ switch (self->state)
+ {
+ case WINDOW_UP: /* Pull the window up */
+
+ /* Bugfix: having this here keeps the tilda window from being
+ * hidden if you turn off "stick", pull it down on workspace 1,
+ * switch to workspace 2, then pull it up and back down. Without
+ * this, something in metacity (at least) hides the window. Stupid. */
+ gtk_window_deiconify (GTK_WINDOW(self->window));
+
+ /* Re-set the window properties that do not linger after hiding the
+ * window. I know this looks stupid, but it keeps all of the state-
+ * changing code in the place it belongs: the property-setting code. */
+ g_object_set (G_OBJECT(self),
+ "keep-above", self->keep_above,
+ "stick", self->stick,
+ NULL);
+ gtk_window_present_with_time (GTK_WINDOW(self->window),
+ tomboy_keybinder_get_current_event_time());
+
+ /* 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));
+
+ self->state = WINDOW_DOWN;
+ break;
+
+ case WINDOW_DOWN: /* Pull the window up */
+
+ gtk_widget_hide (GTK_WIDGET(self->window));
+
+ self->state = WINDOW_UP;
+ break;
+
+ default:
+ debug_printf ("ERROR: 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)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ 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);
+
+ 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;
+}
+