2 #include "tilda-window.h"
3 #include "tilda-window-dbus-glue.h"
6 tilda_window_find_next_free_terminal_number (TildaWindow *tw)
11 for (i=0; i<INT_MAX; ++i)
15 for (j=0; j<tw->terms->len; ++j)
17 TildaTerminal *tt = g_ptr_array_index (tw->terms, j);
34 tilda_window_add_term (TildaWindow *tw)
39 number = tilda_window_find_next_free_terminal_number (tw);
40 tt = g_object_new (TILDA_TYPE_TERMINAL,
42 "window-number", tw->number,
45 g_ptr_array_add (tw->terms, tt);
47 GtkWidget *label = gtk_label_new ("Tilda");
48 gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(tw->notebook), tt->hbox, label);
49 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(tw->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END);
50 //gtk_notebook_set_current_page (GTK_NOTEBOOK(tw->notebook), index);
52 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(tw->notebook)) > 1)
53 gtk_notebook_set_show_tabs (GTK_NOTEBOOK(tw->notebook), TRUE);
59 * Remove the TildaTerminal with the given number from the given
62 * Return: TRUE on success, FALSE otherwise.
65 tilda_window_remove_term (TildaWindow *tw, gint terminal_number)
69 for (i=0; i<tw->terms->len; ++i)
71 TildaTerminal *tt = g_ptr_array_index (tw->terms, i);
73 if (tt->number == terminal_number)
75 gint notebook_index = gtk_notebook_page_num (GTK_NOTEBOOK(tw->notebook), tt->hbox);
77 /* Make sure the index was valid */
78 if (notebook_index == -1)
80 g_printerr ("DEBUG ERROR: Bad Notebook Tab\n");
84 /* Actually remove the terminal */
85 gtk_notebook_remove_page (GTK_NOTEBOOK (tw->notebook), notebook_index);
87 /* We should hide the tabs if there is only one tab left */
88 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) == 1)
89 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (tw->notebook), FALSE);
92 // FIXME FIXME FIXME: need to actually do the stuff below
93 /* With no pages left, it's time to leave the program */
94 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) < 1)
98 /* Remove the term from our lists, then free it */
99 g_ptr_array_remove_fast (tw->terms, tt);
100 g_object_unref (G_OBJECT(tt));
102 /* Leave the loop, we're done */
111 * This sets up the given TildaWindow for the capability of real
112 * transparency, if the X server is capable of it. */
114 tilda_window_setup_real_transparency (TildaWindow *self)
117 GdkColormap *colormap;
119 screen = gtk_widget_get_screen (GTK_WIDGET(self->window));
120 colormap = gdk_screen_get_rgba_colormap (screen);
122 /* If possible, set the RGBA colormap so VTE can use real alpha
123 * channels for transparency. */
124 if (colormap != NULL && gdk_screen_is_composited (screen))
126 gtk_widget_set_colormap (GTK_WIDGET(self->window), colormap);
127 self->have_real_transparency = TRUE;
131 self->have_real_transparency = FALSE;
135 tilda_window_dbus_register_object (TildaWindow *tw)
139 // Register this object with DBus
140 object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d", tw->number);
141 dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tw));
142 g_free (object_path);
145 /*******************************************************************************
146 * ALL GOBJECT STUFF BELOW PLEASE
147 ******************************************************************************/
149 static GObjectClass *parent_class = NULL;
151 enum tilda_window_properties {
152 TILDA_WINDOW_NUMBER = 1,
156 TILDA_WINDOW_MIN_HEIGHT,
157 TILDA_WINDOW_MIN_WIDTH,
158 TILDA_WINDOW_MAX_HEIGHT,
159 TILDA_WINDOW_MAX_WIDTH,
160 TILDA_WINDOW_X_POSITION,
161 TILDA_WINDOW_Y_POSITION,
163 TILDA_WINDOW_TAB_POSITION,
164 TILDA_WINDOW_ANIMATION_ORIENTATION,
165 TILDA_WINDOW_ANIMATION_DELAY,
167 TILDA_WINDOW_KEEP_ABOVE,
168 TILDA_WINDOW_SHOW_IN_TASKBAR,
170 TILDA_WINDOW_HIDDEN_AT_START,
171 TILDA_WINDOW_CENTERED_HORIZONTALLY,
172 TILDA_WINDOW_CENTERED_VERTICALLY,
174 TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
178 tilda_window_instance_init (GTypeInstance *instance,
181 TildaWindow *self = (TildaWindow *) instance;
182 self->dispose_has_run = FALSE;
184 /* Initialize all properties */
185 self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
186 self->notebook = gtk_notebook_new ();
187 self->terms = g_ptr_array_new ();
189 /* Somewhat of a "poison" value, incase we don't set this */
190 self->number = 0xdeadbeef;
194 tilda_window_set_property (GObject *object,
199 TildaWindow *self = (TildaWindow *) object;
201 switch (property_id) {
203 case TILDA_WINDOW_NUMBER:
204 self->number = g_value_get_int (value);
205 g_print ("window number: %d\n", self->number);
208 case TILDA_WINDOW_KEY:
209 self->key = g_value_dup_string (value);
210 g_print ("window key: %s\n", self->key);
213 case TILDA_WINDOW_MIN_HEIGHT:
214 self->min_height = g_value_get_int (value);
215 g_print ("window min height: %d\n", self->min_height);
218 case TILDA_WINDOW_MIN_WIDTH:
219 self->min_width = g_value_get_int (value);
220 g_print ("window min width: %d\n", self->min_width);
223 case TILDA_WINDOW_MAX_HEIGHT:
224 self->max_height = g_value_get_int (value);
225 g_print ("window max height: %d\n", self->max_height);
228 case TILDA_WINDOW_MAX_WIDTH:
229 self->max_width = g_value_get_int (value);
230 g_print ("window max width: %d\n", self->max_width);
233 case TILDA_WINDOW_X_POSITION:
234 self->x_position = g_value_get_int (value);
235 g_print ("window x position: %d\n", self->x_position);
238 case TILDA_WINDOW_Y_POSITION:
239 self->y_position = g_value_get_int (value);
240 g_print ("window y position: %d\n", self->y_position);
243 case TILDA_WINDOW_TAB_POSITION:
244 self->tab_position = g_value_get_int (value);
245 g_print ("window tab position: %d\n", self->tab_position);
248 case TILDA_WINDOW_ANIMATION_ORIENTATION:
249 self->animation_orientation = g_value_get_int (value);
250 g_print ("window animation orientation: %d\n", self->animation_orientation);
253 case TILDA_WINDOW_ANIMATION_DELAY:
254 self->animation_delay = g_value_get_int (value);
255 g_print ("window animation delay: %d\n", self->animation_delay);
258 case TILDA_WINDOW_KEEP_ABOVE:
259 self->keep_above = g_value_get_boolean (value);
260 g_print ("window keep above: %d\n", self->keep_above);
263 case TILDA_WINDOW_SHOW_IN_TASKBAR:
264 self->show_in_taskbar = g_value_get_boolean (value);
265 g_print ("window show in taskbar: %d\n", self->show_in_taskbar);
268 case TILDA_WINDOW_PINNED:
269 self->pinned = g_value_get_boolean (value);
270 g_print ("window pinned: %d\n", self->pinned);
273 case TILDA_WINDOW_HIDDEN_AT_START:
274 self->hidden_at_start = g_value_get_boolean (value);
275 g_print ("window hidden at start: %d\n", self->hidden_at_start);
278 case TILDA_WINDOW_CENTERED_HORIZONTALLY:
279 self->centered_horizontally = g_value_get_boolean (value);
280 g_print ("window centered horizontally: %d\n", self->centered_horizontally);
283 case TILDA_WINDOW_CENTERED_VERTICALLY:
284 self->centered_vertically = g_value_get_boolean (value);
285 g_print ("window centered vertically: %d\n", self->centered_vertically);
288 case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
289 self->have_real_transparency = g_value_get_boolean (value);
290 g_print ("window have real transp: %d\n", self->have_real_transparency);
294 /* We don't have this property */
295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
301 tilda_window_get_property (GObject *object,
306 TildaWindow *self = (TildaWindow *) object;
308 switch (property_id) {
310 case TILDA_WINDOW_NUMBER:
311 g_value_set_int (value, self->number);
314 case TILDA_WINDOW_KEY:
315 g_value_set_string (value, self->key);
318 case TILDA_WINDOW_MIN_HEIGHT:
319 g_value_set_int (value, self->min_height);
322 case TILDA_WINDOW_MIN_WIDTH:
323 g_value_set_int (value, self->min_width);
326 case TILDA_WINDOW_MAX_HEIGHT:
327 g_value_set_int (value, self->max_height);
330 case TILDA_WINDOW_MAX_WIDTH:
331 g_value_set_int (value, self->max_width);
334 case TILDA_WINDOW_X_POSITION:
335 g_value_set_int (value, self->x_position);
338 case TILDA_WINDOW_Y_POSITION:
339 g_value_set_int (value, self->y_position);
342 case TILDA_WINDOW_TAB_POSITION:
343 g_value_set_int (value, self->tab_position);
346 case TILDA_WINDOW_ANIMATION_ORIENTATION:
347 g_value_set_int (value, self->animation_orientation);
350 case TILDA_WINDOW_ANIMATION_DELAY:
351 g_value_set_int (value, self->animation_delay);
354 case TILDA_WINDOW_KEEP_ABOVE:
355 g_value_set_boolean (value, self->keep_above);
358 case TILDA_WINDOW_SHOW_IN_TASKBAR:
359 g_value_set_boolean (value, self->show_in_taskbar);
362 case TILDA_WINDOW_PINNED:
363 g_value_set_boolean (value, self->pinned);
366 case TILDA_WINDOW_HIDDEN_AT_START:
367 g_value_set_boolean (value, self->hidden_at_start);
370 case TILDA_WINDOW_CENTERED_HORIZONTALLY:
371 g_value_set_boolean (value, self->centered_horizontally);
374 case TILDA_WINDOW_CENTERED_VERTICALLY:
375 g_value_set_boolean (value, self->centered_vertically);
378 case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
379 g_value_set_boolean (value, self->have_real_transparency);
383 /* We don't have this property */
384 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
390 tilda_window_constructor (GType type,
391 guint n_construct_properties,
392 GObjectConstructParam *construct_properties)
397 /* Invoke parent constructor */
398 TildaWindowClass *klass;
399 klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
400 obj = parent_class->constructor (type,
401 n_construct_properties,
402 construct_properties);
404 /* Do other stuff here. The object is ready to go now, and all
405 * ctor properties have been set.
407 * TODO: This is the place to do DBus-init */
408 self = TILDA_WINDOW(obj);
410 /* Register this object with DBus */
411 tilda_window_dbus_register_object (self);
413 /* Try to set up real transparency */
414 tilda_window_setup_real_transparency (self);
416 gtk_container_add (GTK_CONTAINER(self->window), self->notebook);
417 gtk_widget_show (self->notebook);
419 tilda_window_add_term (self);
420 tilda_window_add_term (self);
421 gtk_widget_show_all (self->window);
427 my_unref (gpointer data, gpointer user_data)
429 g_object_unref (G_OBJECT(data));
433 tilda_window_dispose (GObject *obj)
435 TildaWindow *self = (TildaWindow *) obj;
437 /* We don't want to run dispose twice, so just return immediately */
438 if (self->dispose_has_run)
442 * In dispose, you are supposed to free all types referenced from this
443 * object which might themselves hold a reference to self. Generally,
444 * the most simple solution is to unref all members on which you own a
447 * NOTE: See the following for how to deal with GtkObject-derived things:
448 * http://library.gnome.org/devel/gtk/unstable/GtkObject.html
450 g_ptr_array_foreach (self->terms, my_unref, NULL);
451 gtk_widget_destroy (self->window);
453 /* Chain up to the parent class */
454 G_OBJECT_CLASS (parent_class)->dispose (obj);
458 tilda_window_finalize (GObject *obj)
460 TildaWindow *self = (TildaWindow *) obj;
463 * Here, complete the object's destruction.
464 * You might not need to do much...
466 // TODO: g_free() any primitives here
467 g_ptr_array_free (self->terms, TRUE);
470 /* Chain up to the parent class */
471 G_OBJECT_CLASS (parent_class)->finalize (obj);
475 tilda_window_class_init (gpointer g_class,
476 gpointer g_class_data)
478 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
479 TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
482 /* Hook our functions to this type */
483 gobject_class->set_property = tilda_window_set_property;
484 gobject_class->get_property = tilda_window_get_property;
485 gobject_class->dispose = tilda_window_dispose;
486 gobject_class->finalize = tilda_window_finalize;
487 gobject_class->constructor = tilda_window_constructor;
489 parent_class = g_type_class_peek_parent (klass);
491 /* Install all of the properties */
492 pspec = g_param_spec_int ("number",
494 "Set window's number",
496 INT_MAX, // max value
498 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
500 g_object_class_install_property (gobject_class,
504 pspec = g_param_spec_string ("key",
505 "Window's drop-down keybinding",
510 g_object_class_install_property (gobject_class,
514 pspec = g_param_spec_int ("min-height",
515 "Window's minimum height",
522 g_object_class_install_property (gobject_class,
523 TILDA_WINDOW_MIN_HEIGHT,
526 pspec = g_param_spec_int ("min-width",
527 "Window's minimum width",
534 g_object_class_install_property (gobject_class,
535 TILDA_WINDOW_MIN_WIDTH,
538 pspec = g_param_spec_int ("max-height",
539 "Window's maximum height",
546 g_object_class_install_property (gobject_class,
547 TILDA_WINDOW_MAX_HEIGHT,
550 pspec = g_param_spec_int ("max-width",
551 "Window's maximum width",
558 g_object_class_install_property (gobject_class,
559 TILDA_WINDOW_MAX_WIDTH,
562 pspec = g_param_spec_int ("x-position",
563 "Window's x position",
570 g_object_class_install_property (gobject_class,
571 TILDA_WINDOW_X_POSITION,
574 pspec = g_param_spec_int ("y-position",
575 "Window's y position",
582 g_object_class_install_property (gobject_class,
583 TILDA_WINDOW_Y_POSITION,
586 pspec = g_param_spec_int ("tab-position",
587 "Window's tab position",
594 g_object_class_install_property (gobject_class,
595 TILDA_WINDOW_TAB_POSITION,
598 pspec = g_param_spec_int ("animation-orientation",
599 "Window's animation orientation",
606 g_object_class_install_property (gobject_class,
607 TILDA_WINDOW_ANIMATION_ORIENTATION,
610 pspec = g_param_spec_int ("animation-delay",
611 "Amount of time in milliseconds between animation intervals",
618 g_object_class_install_property (gobject_class,
619 TILDA_WINDOW_ANIMATION_DELAY,
622 pspec = g_param_spec_boolean ("keep-above",
623 "Keep this window above all others",
628 g_object_class_install_property (gobject_class,
629 TILDA_WINDOW_KEEP_ABOVE,
632 pspec = g_param_spec_boolean ("show-in-taskbar",
633 "Show this window in the taskbar",
638 g_object_class_install_property (gobject_class,
639 TILDA_WINDOW_SHOW_IN_TASKBAR,
642 pspec = g_param_spec_boolean ("pinned",
643 "Display this window on all workspaces",
648 g_object_class_install_property (gobject_class,
652 pspec = g_param_spec_boolean ("hidden-at-start",
653 "Hide the window when it is first created",
658 g_object_class_install_property (gobject_class,
659 TILDA_WINDOW_HIDDEN_AT_START,
662 pspec = g_param_spec_boolean ("centered-horizontally",
663 "Center the window horizontally",
668 g_object_class_install_property (gobject_class,
669 TILDA_WINDOW_CENTERED_HORIZONTALLY,
672 pspec = g_param_spec_boolean ("centered-vertically",
673 "Center the window vertically",
678 g_object_class_install_property (gobject_class,
679 TILDA_WINDOW_CENTERED_VERTICALLY,
682 pspec = g_param_spec_boolean ("have-real-transparency",
683 NULL, NULL, FALSE, G_PARAM_READABLE);
685 g_object_class_install_property (gobject_class,
686 TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
689 /* TODO: more properties */
691 /* Hook the TildaWindow type into DBus */
692 dbus_g_object_type_install_info (tilda_window_get_type(), &dbus_glib_tilda_window_object_info);
696 tilda_window_get_type (void)
698 static GType type = 0;
702 static const GTypeInfo info = {
703 sizeof (TildaWindowClass),
704 NULL, /* base_init */
705 NULL, /* base_finalize */
706 tilda_window_class_init, /* class_init */
707 NULL, /* class_finalize */
708 NULL, /* class_data */
709 sizeof (TildaWindow),
711 tilda_window_instance_init, /* instance_init */
714 type = g_type_register_static (G_TYPE_OBJECT,
725 int main (int argc, char *argv[])
728 gint test_number = INT_MIN;
730 /* Initialize the GObject type system */
732 gtk_init (&argc, &argv);
734 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 10, NULL);
735 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
736 g_assert (test_number == 10);
738 g_object_unref (G_OBJECT (tw));
740 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 22, NULL);
741 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
742 g_assert (test_number == 22);
746 g_object_unref (G_OBJECT (tw));
753 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */