#include "tilda-window.h"
#include "tilda-window-dbus-glue.h"
+/**
+ * Find the TildaTerminal corresponding to the currently selected
+ * tab in self->notebook. This could go away if TildaTerminal were
+ * a proper subclass of GtkWidget.
+ */
+static TildaTerminal *
+tilda_window_find_current_terminal (TildaWindow *self)
+{
+ gint i;
+ TildaTerminal *ret;
+ gint current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(self->notebook));
+ GtkWidget *box = gtk_notebook_get_nth_page (GTK_NOTEBOOK(self->notebook), current_page);
+
+ for (i=0; i<self->terms->len; ++i)
+ {
+ ret = g_ptr_array_index (self->terms, i);
+
+ if (ret->hbox == box)
+ return ret;
+ }
+
+ g_printerr ("FIXME: unable to find current terminal!\n");
+ return NULL;
+}
+
static gint
tilda_window_find_next_free_terminal_number (TildaWindow *tw)
{
self->have_real_transparency = FALSE;
}
+static void
+tilda_window_keybinding_cb (const gchar *keystr, gpointer 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:
+ 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)
{
TILDA_WINDOW_KEY,
- TILDA_WINDOW_MIN_HEIGHT,
- TILDA_WINDOW_MIN_WIDTH,
- TILDA_WINDOW_MAX_HEIGHT,
- TILDA_WINDOW_MAX_WIDTH,
+ TILDA_WINDOW_HEIGHT,
+ TILDA_WINDOW_WIDTH,
TILDA_WINDOW_X_POSITION,
TILDA_WINDOW_Y_POSITION,
TILDA_WINDOW_ANIMATION_DELAY,
TILDA_WINDOW_KEEP_ABOVE,
- TILDA_WINDOW_SHOW_IN_TASKBAR,
- TILDA_WINDOW_PINNED,
+ TILDA_WINDOW_SKIP_TASKBAR_HINT,
+ TILDA_WINDOW_STICK,
TILDA_WINDOW_HIDDEN_AT_START,
TILDA_WINDOW_CENTERED_HORIZONTALLY,
TILDA_WINDOW_CENTERED_VERTICALLY,
/* Somewhat of a "poison" value, incase we don't set this */
self->number = 0xdeadbeef;
+
+ self->state = WINDOW_UP;
}
static void
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;
- case TILDA_WINDOW_MIN_HEIGHT:
- self->min_height = g_value_get_int (value);
- g_print ("window min height: %d\n", self->min_height);
+ case TILDA_WINDOW_HEIGHT:
+ self->height = g_value_get_int (value);
+ gtk_widget_set_size_request (self->window, self->width, self->height);
+ gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
+ g_print ("window height: %d\n", self->height);
break;
- case TILDA_WINDOW_MIN_WIDTH:
- self->min_width = g_value_get_int (value);
- g_print ("window min width: %d\n", self->min_width);
- break;
-
- case TILDA_WINDOW_MAX_HEIGHT:
- self->max_height = g_value_get_int (value);
- g_print ("window max height: %d\n", self->max_height);
- break;
-
- case TILDA_WINDOW_MAX_WIDTH:
- self->max_width = g_value_get_int (value);
- g_print ("window max width: %d\n", self->max_width);
+ case TILDA_WINDOW_WIDTH:
+ self->width = g_value_get_int (value);
+ gtk_widget_set_size_request (self->window, self->width, self->height);
+ gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
+ g_print ("window width: %d\n", self->width);
break;
case TILDA_WINDOW_X_POSITION:
self->x_position = g_value_get_int (value);
+ gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
g_print ("window x position: %d\n", self->x_position);
break;
case TILDA_WINDOW_Y_POSITION:
self->y_position = g_value_get_int (value);
+ gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
g_print ("window y position: %d\n", self->y_position);
break;
case TILDA_WINDOW_TAB_POSITION:
self->tab_position = g_value_get_int (value);
+ gtk_notebook_set_tab_pos (GTK_NOTEBOOK(self->notebook), self->tab_position);
g_print ("window tab position: %d\n", self->tab_position);
break;
case TILDA_WINDOW_KEEP_ABOVE:
self->keep_above = g_value_get_boolean (value);
+ gtk_window_set_keep_above (GTK_WINDOW(self->window), self->keep_above);
g_print ("window keep above: %d\n", self->keep_above);
break;
- case TILDA_WINDOW_SHOW_IN_TASKBAR:
- self->show_in_taskbar = g_value_get_boolean (value);
- g_print ("window show in taskbar: %d\n", self->show_in_taskbar);
+ case TILDA_WINDOW_SKIP_TASKBAR_HINT:
+ self->skip_taskbar_hint = g_value_get_boolean (value);
+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW(self->window), self->skip_taskbar_hint);
+ g_print ("window skip taskbar hint: %d\n", self->skip_taskbar_hint);
break;
- case TILDA_WINDOW_PINNED:
- self->pinned = g_value_get_boolean (value);
- g_print ("window pinned: %d\n", self->pinned);
+ case TILDA_WINDOW_STICK:
+ self->stick = g_value_get_boolean (value);
+
+ /* This is moderately ugly, but GTK+ does it this way... */
+ self->stick ? gtk_window_stick (GTK_WINDOW(self->window))
+ : gtk_window_unstick (GTK_WINDOW(self->window));
+ g_print ("window stick: %d\n", self->stick);
break;
case TILDA_WINDOW_HIDDEN_AT_START:
g_value_set_string (value, self->key);
break;
- case TILDA_WINDOW_MIN_HEIGHT:
- g_value_set_int (value, self->min_height);
- break;
-
- case TILDA_WINDOW_MIN_WIDTH:
- g_value_set_int (value, self->min_width);
- break;
-
- case TILDA_WINDOW_MAX_HEIGHT:
- g_value_set_int (value, self->max_height);
+ case TILDA_WINDOW_HEIGHT:
+ g_value_set_int (value, self->height);
break;
- case TILDA_WINDOW_MAX_WIDTH:
- g_value_set_int (value, self->max_width);
+ case TILDA_WINDOW_WIDTH:
+ g_value_set_int (value, self->width);
break;
case TILDA_WINDOW_X_POSITION:
g_value_set_boolean (value, self->keep_above);
break;
- case TILDA_WINDOW_SHOW_IN_TASKBAR:
- g_value_set_boolean (value, self->show_in_taskbar);
+ case TILDA_WINDOW_SKIP_TASKBAR_HINT:
+ g_value_set_boolean (value, self->skip_taskbar_hint);
break;
- case TILDA_WINDOW_PINNED:
- g_value_set_boolean (value, self->pinned);
+ case TILDA_WINDOW_STICK:
+ g_value_set_boolean (value, self->stick);
break;
case TILDA_WINDOW_HIDDEN_AT_START:
gtk_container_add (GTK_CONTAINER(self->window), self->notebook);
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);
+ 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);
+ g_object_set (G_OBJECT(self), "hidden-at-start", FALSE, NULL);
+
+ gtk_window_set_decorated (GTK_WINDOW(self->window), FALSE);
+
+ // FIXME: It should be configurable how many terms we add at startup
tilda_window_add_term (self);
tilda_window_add_term (self);
- gtk_widget_show_all (self->window);
+
+ /* Show us if we're ready. If not, just remain hidden. All sub-widgets must
+ * be gtk_widget_show()n by this point. */
+ if (!self->hidden_at_start)
+ {
+ gtk_widget_show (self->window);
+ self->state = WINDOW_DOWN;
+ }
+ else
+ self->state = WINDOW_UP;
return obj;
}
TILDA_WINDOW_KEY,
pspec);
- pspec = g_param_spec_int ("min-height",
- "Window's minimum height",
- NULL,
- 0,
- INT_MAX,
- 0,
- G_PARAM_READWRITE);
-
- g_object_class_install_property (gobject_class,
- TILDA_WINDOW_MIN_HEIGHT,
- pspec);
-
- pspec = g_param_spec_int ("min-width",
- "Window's minimum width",
- NULL,
- 0,
- INT_MAX,
- 0,
- G_PARAM_READWRITE);
-
- g_object_class_install_property (gobject_class,
- TILDA_WINDOW_MIN_WIDTH,
- pspec);
-
- pspec = g_param_spec_int ("max-height",
- "Window's maximum height",
+ pspec = g_param_spec_int ("height",
+ "Window's height",
NULL,
0,
INT_MAX,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
- TILDA_WINDOW_MAX_HEIGHT,
+ TILDA_WINDOW_HEIGHT,
pspec);
- pspec = g_param_spec_int ("max-width",
- "Window's maximum width",
+ pspec = g_param_spec_int ("width",
+ "Window's width",
NULL,
0,
INT_MAX,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
- TILDA_WINDOW_MAX_WIDTH,
+ TILDA_WINDOW_WIDTH,
pspec);
pspec = g_param_spec_int ("x-position",
TILDA_WINDOW_KEEP_ABOVE,
pspec);
- pspec = g_param_spec_boolean ("show-in-taskbar",
- "Show this window in the taskbar",
+ pspec = g_param_spec_boolean ("skip-taskbar-hint",
+ "Hide this window in the taskbar if TRUE",
NULL,
FALSE,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
- TILDA_WINDOW_SHOW_IN_TASKBAR,
+ TILDA_WINDOW_SKIP_TASKBAR_HINT,
pspec);
- pspec = g_param_spec_boolean ("pinned",
+ pspec = g_param_spec_boolean ("stick",
"Display this window on all workspaces",
NULL,
FALSE,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
- TILDA_WINDOW_PINNED,
+ TILDA_WINDOW_STICK,
pspec);
pspec = g_param_spec_boolean ("hidden-at-start",