#include "tilda-window.h"
#include "tilda-window-dbus-glue.h"
+static gint
+tilda_window_find_next_free_terminal_number (TildaWindow *tw)
+{
+ gint i, j;
+ gboolean found;
+
+ for (i=0; i<INT_MAX; ++i)
+ {
+ found = FALSE;
+
+ for (j=0; j<tw->terms->len; ++j)
+ {
+ TildaTerminal *tt = g_ptr_array_index (tw->terms, j);
+
+ if (tt->number == i)
+ {
+ found = TRUE;
+ break;
+ }
+ }
+
+ if (!found)
+ return i;
+ }
+
+ return 0;
+}
+
static gboolean
tilda_window_add_term (TildaWindow *tw)
{
- // FIXME: this is totally bad, but it's a good hack for feasability
- static gint mynumber = 0;
- TildaTerminal *tt = g_object_new (TILDA_TYPE_TERMINAL,
- "number", mynumber++,
- "window-number", tw->number,
- "parent-window", tw,
- NULL);
+ gint number;
+ TildaTerminal *tt;
+
+ number = tilda_window_find_next_free_terminal_number (tw);
+ tt = g_object_new (TILDA_TYPE_TERMINAL,
+ "number", number,
+ "window-number", tw->number,
+ "parent-window", tw,
+ NULL);
g_ptr_array_add (tw->terms, tt);
GtkWidget *label = gtk_label_new ("Tilda");
return TRUE;
}
-static gboolean
-tilda_window_remove_term (TildaWindow *tw, int number)
+/**
+ * Remove the TildaTerminal with the given number from the given
+ * TildaWindow.
+ *
+ * Return: TRUE on success, FALSE otherwise.
+ */
+gboolean
+tilda_window_remove_term (TildaWindow *tw, gint terminal_number)
{
- int i;
+ gint i;
for (i=0; i<tw->terms->len; ++i)
{
TildaTerminal *tt = g_ptr_array_index (tw->terms, i);
- if (tt->number == number)
- g_print ("Need to remove window %d terminal %d\n", tw->number, tt->number);
+ if (tt->number == terminal_number)
+ {
+ gint notebook_index = gtk_notebook_page_num (GTK_NOTEBOOK(tw->notebook), tt->hbox);
+
+ /* Make sure the index was valid */
+ if (notebook_index == -1)
+ {
+ g_printerr ("DEBUG ERROR: Bad Notebook Tab\n");
+ return FALSE;
+ }
+
+ /* Actually remove the terminal */
+ gtk_notebook_remove_page (GTK_NOTEBOOK (tw->notebook), notebook_index);
+
+ /* We should hide the tabs if there is only one tab left */
+ if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) == 1)
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (tw->notebook), FALSE);
+
+#if 0
+ // FIXME FIXME FIXME: need to actually do the stuff below
+ /* With no pages left, it's time to leave the program */
+ if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) < 1)
+ gtk_main_quit ();
+#endif
+
+ /* Remove the term from our lists, then free it */
+ g_ptr_array_remove_fast (tw->terms, tt);
+ g_object_unref (G_OBJECT(tt));
+
+ /* Leave the loop, we're done */
+ break;
+ }
}
return TRUE;
}
+/**
+ * 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)
+{
+ 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;
+}
+
+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)
{
enum tilda_window_properties {
TILDA_WINDOW_NUMBER = 1,
+
+ TILDA_WINDOW_KEY,
+
+ TILDA_WINDOW_MIN_HEIGHT,
+ TILDA_WINDOW_MIN_WIDTH,
+ TILDA_WINDOW_MAX_HEIGHT,
+ TILDA_WINDOW_MAX_WIDTH,
+ TILDA_WINDOW_X_POSITION,
+ TILDA_WINDOW_Y_POSITION,
+
+ TILDA_WINDOW_TAB_POSITION,
+ TILDA_WINDOW_ANIMATION_ORIENTATION,
+ TILDA_WINDOW_ANIMATION_DELAY,
+
+ TILDA_WINDOW_KEEP_ABOVE,
+ TILDA_WINDOW_SHOW_IN_TASKBAR,
+ TILDA_WINDOW_PINNED,
+ TILDA_WINDOW_HIDDEN_AT_START,
+ TILDA_WINDOW_CENTERED_HORIZONTALLY,
+ TILDA_WINDOW_CENTERED_VERTICALLY,
+
+ TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
};
static void
/* Somewhat of a "poison" value, incase we don't set this */
self->number = 0xdeadbeef;
+
+ self->state = WINDOW_UP;
}
static void
g_print ("window number: %d\n", self->number);
break;
+ case TILDA_WINDOW_KEY:
+ 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);
+ 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);
+ 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);
+ g_print ("window tab position: %d\n", self->tab_position);
+ break;
+
+ case TILDA_WINDOW_ANIMATION_ORIENTATION:
+ self->animation_orientation = g_value_get_int (value);
+ g_print ("window animation orientation: %d\n", self->animation_orientation);
+ break;
+
+ case TILDA_WINDOW_ANIMATION_DELAY:
+ self->animation_delay = g_value_get_int (value);
+ g_print ("window animation delay: %d\n", self->animation_delay);
+ break;
+
+ case TILDA_WINDOW_KEEP_ABOVE:
+ self->keep_above = g_value_get_boolean (value);
+ 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);
+ break;
+
+ case TILDA_WINDOW_PINNED:
+ self->pinned = g_value_get_boolean (value);
+ g_print ("window pinned: %d\n", self->pinned);
+ break;
+
+ case TILDA_WINDOW_HIDDEN_AT_START:
+ self->hidden_at_start = g_value_get_boolean (value);
+ g_print ("window hidden at start: %d\n", self->hidden_at_start);
+ break;
+
+ case TILDA_WINDOW_CENTERED_HORIZONTALLY:
+ self->centered_horizontally = g_value_get_boolean (value);
+ g_print ("window centered horizontally: %d\n", self->centered_horizontally);
+ break;
+
+ case TILDA_WINDOW_CENTERED_VERTICALLY:
+ self->centered_vertically = g_value_get_boolean (value);
+ g_print ("window centered vertically: %d\n", self->centered_vertically);
+ break;
+
+ case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
+ self->have_real_transparency = g_value_get_boolean (value);
+ g_print ("window have real transp: %d\n", self->have_real_transparency);
+ break;
+
default:
/* We don't have this property */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
g_value_set_int (value, self->number);
break;
+ case TILDA_WINDOW_KEY:
+ 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);
+ break;
+
+ case TILDA_WINDOW_MAX_WIDTH:
+ g_value_set_int (value, self->max_width);
+ break;
+
+ case TILDA_WINDOW_X_POSITION:
+ g_value_set_int (value, self->x_position);
+ break;
+
+ case TILDA_WINDOW_Y_POSITION:
+ g_value_set_int (value, self->y_position);
+ break;
+
+ case TILDA_WINDOW_TAB_POSITION:
+ g_value_set_int (value, self->tab_position);
+ break;
+
+ case TILDA_WINDOW_ANIMATION_ORIENTATION:
+ g_value_set_int (value, self->animation_orientation);
+ break;
+
+ case TILDA_WINDOW_ANIMATION_DELAY:
+ g_value_set_int (value, self->animation_delay);
+ break;
+
+ case TILDA_WINDOW_KEEP_ABOVE:
+ g_value_set_boolean (value, self->keep_above);
+ break;
+
+ case TILDA_WINDOW_SHOW_IN_TASKBAR:
+ g_value_set_boolean (value, self->show_in_taskbar);
+ break;
+
+ case TILDA_WINDOW_PINNED:
+ g_value_set_boolean (value, self->pinned);
+ break;
+
+ case TILDA_WINDOW_HIDDEN_AT_START:
+ g_value_set_boolean (value, self->hidden_at_start);
+ break;
+
+ case TILDA_WINDOW_CENTERED_HORIZONTALLY:
+ g_value_set_boolean (value, self->centered_horizontally);
+ break;
+
+ case TILDA_WINDOW_CENTERED_VERTICALLY:
+ g_value_set_boolean (value, self->centered_vertically);
+ break;
+
+ case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
+ g_value_set_boolean (value, self->have_real_transparency);
+ break;
+
default:
/* We don't have this property */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
/* Register this object with DBus */
tilda_window_dbus_register_object (self);
+ /* Try to set up real transparency */
+ tilda_window_setup_real_transparency (self);
+
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);
+
+ tilda_window_add_term (self);
tilda_window_add_term (self);
gtk_widget_show_all (self->window);
+ self->state = WINDOW_DOWN;
return obj;
}
TILDA_WINDOW_NUMBER,
pspec);
+ pspec = g_param_spec_string ("key",
+ "Window's drop-down keybinding",
+ NULL,
+ NULL,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ 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",
+ NULL,
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_MAX_HEIGHT,
+ pspec);
+
+ pspec = g_param_spec_int ("max-width",
+ "Window's maximum width",
+ NULL,
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_MAX_WIDTH,
+ pspec);
+
+ pspec = g_param_spec_int ("x-position",
+ "Window's x position",
+ NULL,
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_X_POSITION,
+ pspec);
+
+ pspec = g_param_spec_int ("y-position",
+ "Window's y position",
+ NULL,
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_Y_POSITION,
+ pspec);
+
+ pspec = g_param_spec_int ("tab-position",
+ "Window's tab position",
+ NULL,
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_TAB_POSITION,
+ pspec);
+
+ pspec = g_param_spec_int ("animation-orientation",
+ "Window's animation orientation",
+ NULL,
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_ANIMATION_ORIENTATION,
+ pspec);
+
+ pspec = g_param_spec_int ("animation-delay",
+ "Amount of time in milliseconds between animation intervals",
+ NULL,
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_ANIMATION_DELAY,
+ pspec);
+
+ pspec = g_param_spec_boolean ("keep-above",
+ "Keep this window above all others",
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_KEEP_ABOVE,
+ pspec);
+
+ pspec = g_param_spec_boolean ("show-in-taskbar",
+ "Show this window in the taskbar",
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_SHOW_IN_TASKBAR,
+ pspec);
+
+ pspec = g_param_spec_boolean ("pinned",
+ "Display this window on all workspaces",
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_PINNED,
+ pspec);
+
+ pspec = g_param_spec_boolean ("hidden-at-start",
+ "Hide the window when it is first created",
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_HIDDEN_AT_START,
+ pspec);
+
+ pspec = g_param_spec_boolean ("centered-horizontally",
+ "Center the window horizontally",
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_CENTERED_HORIZONTALLY,
+ pspec);
+
+ pspec = g_param_spec_boolean ("centered-vertically",
+ "Center the window vertically",
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_CENTERED_VERTICALLY,
+ pspec);
+
+ pspec = g_param_spec_boolean ("have-real-transparency",
+ NULL, NULL, FALSE, G_PARAM_READABLE);
+
+ g_object_class_install_property (gobject_class,
+ TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
+ pspec);
+
/* TODO: more properties */
/* Hook the TildaWindow type into DBus */