1 #include <gdk/gdkx.h> /* for gdk_x11_window_set_user_time() */
5 #include "tilda-config.h"
6 #include "tilda-controller.h"
7 #include "tilda-window.h"
8 #include "tilda-window-dbus-glue.h"
9 #include "tomboykeybinder.h"
12 * Find the TildaTerminal corresponding to the currently selected
13 * tab in self->notebook. This could go away if TildaTerminal were
14 * a proper subclass of GtkWidget.
16 static TildaTerminal *
17 tilda_window_find_current_terminal (TildaWindow *self)
20 debug_assert (TILDA_IS_WINDOW(self));
24 gint current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(self->notebook));
25 GtkWidget *box = gtk_notebook_get_nth_page (GTK_NOTEBOOK(self->notebook), current_page);
27 for (i=0; i<self->terms->len; ++i)
29 ret = g_ptr_array_index (self->terms, i);
35 debug_printf ("ERROR: unable to find current terminal!\n");
40 tilda_window_find_next_free_terminal_number (TildaWindow *self)
43 debug_assert (TILDA_IS_WINDOW(self));
48 for (i=0; i<INT_MAX; ++i)
52 for (j=0; j<self->terms->len; ++j)
54 TildaTerminal *tt = g_ptr_array_index (self->terms, j);
71 * Clean up and remove self completely from the program
73 * Should only be used by DBus...
76 tilda_window_close (TildaWindow *self)
79 debug_assert (TILDA_IS_WINDOW(self));
81 tilda_controller_remove_window (TILDA_CONTROLLER(self->controller), self->number);
87 tilda_window_add_terminal (TildaWindow *self)
90 debug_assert (TILDA_IS_WINDOW(self));
95 number = tilda_window_find_next_free_terminal_number (self);
96 tt = g_object_new (TILDA_TYPE_TERMINAL,
98 "parent-window", self,
100 g_ptr_array_add (self->terms, tt);
102 GtkWidget *label = gtk_label_new ("Tilda");
103 gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(self->notebook), tt->hbox, label);
104 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(self->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END);
105 gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), index);
107 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) > 1)
108 gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE);
110 /* Focus the VTE Terminal */
111 gtk_widget_grab_focus (tt->vte_term);
117 * Remove the TildaTerminal with the given number from the given
120 * Return: TRUE on success, FALSE otherwise.
123 tilda_window_remove_terminal (TildaWindow *self, gint terminal_number)
126 debug_assert (TILDA_IS_WINDOW(self));
127 debug_assert (terminal_number >= 0);
131 for (i=0; i<self->terms->len; ++i)
133 TildaTerminal *tt = g_ptr_array_index (self->terms, i);
135 if (tt->number == terminal_number)
137 gint notebook_index = gtk_notebook_page_num (GTK_NOTEBOOK(self->notebook), tt->hbox);
139 /* Make sure the index was valid */
140 if (notebook_index == -1)
142 debug_printf ("ERROR: Bad Notebook Tab\n");
146 /* Actually remove the terminal */
147 gtk_notebook_remove_page (GTK_NOTEBOOK (self->notebook), notebook_index);
149 /* We should hide the tabs if there is only one tab left */
150 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) == 1)
151 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (self->notebook), FALSE);
153 /* Remove the term from our lists, then free it */
154 g_ptr_array_remove_fast (self->terms, tt);
155 g_object_unref (G_OBJECT(tt));
157 /* With no pages left, it's time to remove this window */
158 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) < 1)
160 debug_printf ("no terminals left, closing window %d\n", self->number);
161 tilda_controller_remove_window (TILDA_CONTROLLER(self->controller), self->number);
164 /* Leave the loop, we're done */
173 * This sets up the given TildaWindow for the capability of real
174 * transparency, if the X server is capable of it. */
176 tilda_window_setup_real_transparency (TildaWindow *self)
179 debug_assert (TILDA_IS_WINDOW(self));
182 GdkColormap *colormap;
184 screen = gtk_widget_get_screen (GTK_WIDGET(self->window));
185 colormap = gdk_screen_get_rgba_colormap (screen);
187 /* If possible, set the RGBA colormap so VTE can use real alpha
188 * channels for transparency. */
189 if (colormap != NULL && gdk_screen_is_composited (screen))
191 gtk_widget_set_colormap (GTK_WIDGET(self->window), colormap);
192 self->have_real_transparency = TRUE;
196 self->have_real_transparency = FALSE;
199 /* Center the given TildaWindow in the horizontal axis */
201 tilda_window_center_horizontally (TildaWindow *self)
204 debug_assert (TILDA_IS_WINDOW(self));
206 const gint screen_center = gdk_screen_width() / 2;
207 const gint tilda_center = self->width / 2;
208 const gint center_coord = screen_center - tilda_center;
210 g_object_set (G_OBJECT(self), "x-position", center_coord, NULL);
213 /* Center the given TildaWindow in the vertical axis */
215 tilda_window_center_vertically (TildaWindow *self)
218 debug_assert (TILDA_IS_WINDOW(self));
220 const gint screen_center = gdk_screen_height() / 2;
221 const gint tilda_center = self->height / 2;
222 const gint center_coord = screen_center - tilda_center;
224 g_object_set (G_OBJECT(self), "y-position", center_coord, NULL);
228 tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
231 debug_assert (TILDA_IS_WINDOW(data));
233 TildaWindow *self = TILDA_WINDOW(data);
236 /* This call sets the X11 window property _NET_WM_USER_TIME, which GTK+ normally
237 * sets for us. However, because this callback is activated via a global keybinding,
238 * we see the event before GDK / GTK+ does. Therefore, to get the focus, we must
239 * set the property ourselves. */
240 gdk_x11_window_set_user_time (GTK_WIDGET(self->window)->window,
241 tomboy_keybinder_get_current_event_time());
245 case WINDOW_UP: /* Pull the window up */
247 /* Bugfix: having this here keeps the tilda window from being
248 * hidden if you turn off "stick", pull it down on workspace 1,
249 * switch to workspace 2, then pull it up and back down. Without
250 * this, something in metacity (at least) hides the window. Stupid. */
251 gtk_window_deiconify (GTK_WINDOW(self->window));
253 /* Re-set the window properties that do not linger after hiding the
254 * window. I know this looks stupid, but it keeps all of the state-
255 * changing code in the place it belongs: the property-setting code. */
256 g_object_set (G_OBJECT(self),
257 "keep-above", self->keep_above,
258 "stick", self->stick,
260 gtk_widget_show (GTK_WIDGET(self->window));
262 /* Focusing the term here works perfectly, near as I can tell */
263 tt = tilda_window_find_current_terminal (self);
264 gtk_widget_grab_focus (GTK_WIDGET(tt->vte_term));
266 self->state = WINDOW_DOWN;
269 case WINDOW_DOWN: /* Pull the window up */
271 gtk_widget_hide (GTK_WIDGET(self->window));
273 self->state = WINDOW_UP;
277 debug_printf ("ERROR: Window is in a bad state!\n");
279 /* Pretend we're down, for good measure.... */
280 self->state = WINDOW_DOWN;
286 * Attempt to bind the new_key to show this window.
288 * Return: TRUE if successful, FALSE otherwise.
291 tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key)
294 debug_assert (TILDA_IS_WINDOW(self));
296 gboolean ret = FALSE;
298 /* Make sure the new key is not null in any way */
299 if (new_key == NULL || g_ascii_strcasecmp("", new_key) == 0)
302 /* Check that no other windows are using the key */
303 // FIXME: there should be a hidden option to disable this. Maybe some people want
304 // to have logs in two Tildas, and just show them with one key. Crazy...
305 if (tilda_controller_global_key_in_use(TILDA_CONTROLLER(self->controller), new_key))
308 /* Unbind if we were set */
310 tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb);
312 ret = tomboy_keybinder_bind (new_key, tilda_window_keybinding_cb, self);
314 /* If it was successful, update the self->key variable and be done with it */
318 self->key = g_strdup (new_key);
322 g_printerr (_("Bind key '%s' failed. Reverting to original keybinding\n"), self->key);
324 /* Not successful, so rebind the old key, and return FALSE */
325 if (self->key != NULL && g_ascii_strcasecmp("",self->key) != 0)
327 ret = tomboy_keybinder_bind (self->key, tilda_window_keybinding_cb, self);
329 /* Check that it went ok */
331 g_printerr (_("Unable to re-bind original key '%s'. Oh shit...\n"), self->key);
334 g_printerr (_("No original key to revert to!\n"));
340 tilda_window_dbus_register_object (TildaWindow *self)
343 debug_assert (TILDA_IS_WINDOW(self));
347 // Register this object with DBus
348 object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d", self->number);
349 dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(self));
350 g_free (object_path);
353 /*******************************************************************************
354 * All configuration subsystem code is below
355 ******************************************************************************/
358 * Lookup a setting in the config file for this TildaWindow.
360 * The returned string MUST be g_strdup()'d if you want to actually use
361 * it as a value. It is owned by the config system. You MUST NOT g_free() it.
364 tilda_window_lookup_from_config (TildaWindow *self, const gchar key[])
367 debug_assert (TILDA_IS_WINDOW(self));
368 debug_assert (key != NULL);
370 GError *error = NULL;
374 /* Do the bottom-most lookup */
375 group_name = g_strdup_printf ("Window%d", self->number);
376 value = g_key_file_get_string (config_userprefs, group_name, key, &error);
382 g_clear_error (&error);
384 /* Do the global lookup */
385 value = g_key_file_get_string (config_userprefs, "Global", key, &error);
390 g_clear_error (&error);
392 /* Look in the defaults */
393 if (!g_hash_table_lookup_extended (config_defaults, key, NULL, &value))
395 /* If this happened, the developers forgot to set the default for
396 * a key they added. Please email them. */
397 g_critical ("Error: unable to find the default for key=%s\n", key);
401 /* Return the default key */
406 * Set one of TildaWindow's integer properties from the config file or defaults.
409 tilda_window_config_int_property (TildaWindow *self, const gchar *property)
412 debug_assert (TILDA_IS_WINDOW(self));
413 debug_assert (property != NULL);
416 gchar *config_value_raw;
418 config_value_raw = tilda_window_lookup_from_config (self, property);
419 config_value = atoi (config_value_raw);
420 g_object_set (G_OBJECT(self), property, config_value, NULL);
424 tilda_window_config_enum_property (TildaWindow *self, const gchar *property)
427 debug_assert (TILDA_IS_WINDOW(self));
428 debug_assert (property != NULL);
431 gchar *config_value_raw;
433 /* Copy, then strip spaces off of the string from the config */
434 config_value_raw = g_strstrip (g_strdup (tilda_window_lookup_from_config (self, property)));
438 /* Just try all of the possible enums */
439 if (g_ascii_strcasecmp (config_value_raw, "LEFT") == 0)
440 config_value = GTK_POS_LEFT;
441 else if (g_ascii_strcasecmp (config_value_raw, "RIGHT") == 0)
442 config_value = GTK_POS_RIGHT;
443 else if (g_ascii_strcasecmp (config_value_raw, "TOP") == 0)
444 config_value = GTK_POS_TOP;
445 else if (g_ascii_strcasecmp (config_value_raw, "BOTTOM") == 0)
446 config_value = GTK_POS_BOTTOM;
449 g_critical ("Unable to parse: '%s' as an enum\n", config_value_raw);
451 /* Use the default -- which I sure hope is valid (famous last words) */
452 config_value_raw = g_hash_table_lookup (config_defaults, property);
456 /* Free the value from the config system */
457 g_free (config_value_raw);
459 g_object_set (G_OBJECT(self), property, config_value, NULL);
463 tilda_window_config_string_property (TildaWindow *self, const gchar *property)
466 debug_assert (TILDA_IS_WINDOW(self));
467 debug_assert (property != NULL);
469 gchar *config_value_raw;
471 config_value_raw = tilda_window_lookup_from_config (self, property);
473 /* The property system g_strdup()s strings for us! */
474 g_object_set (G_OBJECT(self), property, config_value_raw, NULL);
478 tilda_window_config_boolean_property (TildaWindow *self, const gchar *property)
481 debug_assert (TILDA_IS_WINDOW(self));
482 debug_assert (property != NULL);
484 gboolean config_value;
485 gchar *config_value_raw;
487 config_value_raw = tilda_window_lookup_from_config (self, property);
491 if (g_ascii_strcasecmp (config_value_raw, "true") == 0)
493 else if (g_ascii_strcasecmp (config_value_raw, "false") == 0)
494 config_value = FALSE;
497 g_critical ("Unable to parse: '%s' as a boolean\n", config_value_raw);
499 /* Use the default -- which I sure hope is valid (famous last words) */
500 config_value_raw = g_hash_table_lookup (config_defaults, property);
504 g_object_set (G_OBJECT(self), property, config_value, NULL);
509 /*******************************************************************************
510 * ALL GOBJECT STUFF BELOW PLEASE
511 ******************************************************************************/
513 static GObjectClass *parent_class = NULL;
515 enum tilda_window_properties {
516 TILDA_WINDOW_NUMBER = 1,
517 TILDA_WINDOW_CONTROLLER,
523 TILDA_WINDOW_X_POSITION,
524 TILDA_WINDOW_Y_POSITION,
526 TILDA_WINDOW_TAB_POSITION,
527 TILDA_WINDOW_ANIMATION_ORIENTATION,
528 TILDA_WINDOW_ANIMATION_DELAY,
530 TILDA_WINDOW_KEEP_ABOVE,
531 TILDA_WINDOW_SKIP_TASKBAR_HINT,
533 TILDA_WINDOW_HIDDEN_AT_START,
534 TILDA_WINDOW_CENTERED_HORIZONTALLY,
535 TILDA_WINDOW_CENTERED_VERTICALLY,
537 TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
541 tilda_window_instance_init (GTypeInstance *instance,
546 TildaWindow *self = (TildaWindow *) instance;
547 self->dispose_has_run = FALSE;
549 /* Initialize all properties */
550 self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
551 self->notebook = gtk_notebook_new ();
552 self->terms = g_ptr_array_new ();
554 /* Somewhat of a "poison" value, incase we don't set this */
555 self->number = 0xdeadbeef;
556 self->controller = NULL;
558 self->state = WINDOW_UP;
562 tilda_window_set_property (GObject *object,
567 TildaWindow *self = (TildaWindow *) object;
569 switch (property_id) {
571 case TILDA_WINDOW_NUMBER:
572 self->number = g_value_get_int (value);
573 debug_printf ("window number: %d\n", self->number);
576 case TILDA_WINDOW_CONTROLLER:
577 self->controller = g_value_get_pointer (value);
578 debug_printf ("window controller: 0x%x\n", self->controller);
581 case TILDA_WINDOW_KEY:
582 tilda_window_try_to_bind_key (self, g_value_get_string (value));
583 debug_printf ("window key %s\n", self->key);
586 case TILDA_WINDOW_HEIGHT:
587 self->height = g_value_get_int (value);
588 gtk_widget_set_size_request (self->window, self->width, self->height);
589 gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
590 debug_printf ("window height: %d\n", self->height);
593 case TILDA_WINDOW_WIDTH:
594 self->width = g_value_get_int (value);
595 gtk_widget_set_size_request (self->window, self->width, self->height);
596 gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
597 debug_printf ("window width: %d\n", self->width);
600 case TILDA_WINDOW_X_POSITION:
601 self->x_position = g_value_get_int (value);
602 gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
603 debug_printf ("window x position: %d\n", self->x_position);
606 case TILDA_WINDOW_Y_POSITION:
607 self->y_position = g_value_get_int (value);
608 gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
609 debug_printf ("window y position: %d\n", self->y_position);
612 case TILDA_WINDOW_TAB_POSITION:
613 self->tab_position = g_value_get_int (value);
614 gtk_notebook_set_tab_pos (GTK_NOTEBOOK(self->notebook), self->tab_position);
615 debug_printf ("window tab position: %d\n", self->tab_position);
618 case TILDA_WINDOW_ANIMATION_ORIENTATION:
619 self->animation_orientation = g_value_get_int (value);
620 debug_printf ("window animation orientation: %d\n", self->animation_orientation);
623 case TILDA_WINDOW_ANIMATION_DELAY:
624 self->animation_delay = g_value_get_int (value);
625 debug_printf ("window animation delay: %d\n", self->animation_delay);
628 case TILDA_WINDOW_KEEP_ABOVE:
629 self->keep_above = g_value_get_boolean (value);
630 gtk_window_set_keep_above (GTK_WINDOW(self->window), self->keep_above);
631 debug_printf ("window keep above: %d\n", self->keep_above);
634 case TILDA_WINDOW_SKIP_TASKBAR_HINT:
635 self->skip_taskbar_hint = g_value_get_boolean (value);
636 gtk_window_set_skip_taskbar_hint (GTK_WINDOW(self->window), self->skip_taskbar_hint);
637 debug_printf ("window skip taskbar hint: %d\n", self->skip_taskbar_hint);
640 case TILDA_WINDOW_STICK:
641 self->stick = g_value_get_boolean (value);
643 /* This is moderately ugly, but GTK+ does it this way... */
644 self->stick ? gtk_window_stick (GTK_WINDOW(self->window))
645 : gtk_window_unstick (GTK_WINDOW(self->window));
646 debug_printf ("window stick: %d\n", self->stick);
649 case TILDA_WINDOW_HIDDEN_AT_START:
650 self->hidden_at_start = g_value_get_boolean (value);
651 debug_printf ("window hidden at start: %d\n", self->hidden_at_start);
654 case TILDA_WINDOW_CENTERED_HORIZONTALLY:
655 self->centered_horizontally = g_value_get_boolean (value);
656 if (self->centered_horizontally)
657 tilda_window_center_horizontally (self);
658 debug_printf ("window centered horizontally: %d\n", self->centered_horizontally);
661 case TILDA_WINDOW_CENTERED_VERTICALLY:
662 self->centered_vertically = g_value_get_boolean (value);
663 if (self->centered_vertically)
664 tilda_window_center_vertically (self);
665 debug_printf ("window centered vertically: %d\n", self->centered_vertically);
668 case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
669 self->have_real_transparency = g_value_get_boolean (value);
670 debug_printf ("window have real transp: %d\n", self->have_real_transparency);
674 /* We don't have this property */
675 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
681 tilda_window_get_property (GObject *object,
686 TildaWindow *self = (TildaWindow *) object;
688 switch (property_id) {
690 case TILDA_WINDOW_NUMBER:
691 g_value_set_int (value, self->number);
694 case TILDA_WINDOW_CONTROLLER:
695 g_value_set_pointer (value, self->controller);
698 case TILDA_WINDOW_KEY:
699 g_value_set_string (value, self->key);
702 case TILDA_WINDOW_HEIGHT:
703 g_value_set_int (value, self->height);
706 case TILDA_WINDOW_WIDTH:
707 g_value_set_int (value, self->width);
710 case TILDA_WINDOW_X_POSITION:
711 g_value_set_int (value, self->x_position);
714 case TILDA_WINDOW_Y_POSITION:
715 g_value_set_int (value, self->y_position);
718 case TILDA_WINDOW_TAB_POSITION:
719 g_value_set_int (value, self->tab_position);
722 case TILDA_WINDOW_ANIMATION_ORIENTATION:
723 g_value_set_int (value, self->animation_orientation);
726 case TILDA_WINDOW_ANIMATION_DELAY:
727 g_value_set_int (value, self->animation_delay);
730 case TILDA_WINDOW_KEEP_ABOVE:
731 g_value_set_boolean (value, self->keep_above);
734 case TILDA_WINDOW_SKIP_TASKBAR_HINT:
735 g_value_set_boolean (value, self->skip_taskbar_hint);
738 case TILDA_WINDOW_STICK:
739 g_value_set_boolean (value, self->stick);
742 case TILDA_WINDOW_HIDDEN_AT_START:
743 g_value_set_boolean (value, self->hidden_at_start);
746 case TILDA_WINDOW_CENTERED_HORIZONTALLY:
747 g_value_set_boolean (value, self->centered_horizontally);
750 case TILDA_WINDOW_CENTERED_VERTICALLY:
751 g_value_set_boolean (value, self->centered_vertically);
754 case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
755 g_value_set_boolean (value, self->have_real_transparency);
759 /* We don't have this property */
760 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
766 tilda_window_constructor (GType type,
767 guint n_construct_properties,
768 GObjectConstructParam *construct_properties)
775 /* Invoke parent constructor */
776 TildaWindowClass *klass;
777 klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
778 obj = parent_class->constructor (type,
779 n_construct_properties,
780 construct_properties);
782 /* Do other stuff here. The object is ready to go now, and all
783 * ctor properties have been set.
785 self = TILDA_WINDOW(obj);
787 /* Try to set up real transparency */
788 tilda_window_setup_real_transparency (self);
790 gtk_container_add (GTK_CONTAINER(self->window), self->notebook);
791 g_object_set (G_OBJECT(self->notebook), "can-focus", FALSE, NULL);
792 gtk_widget_show (self->notebook);
794 /* Tilda is never decorated */
795 gtk_window_set_decorated (GTK_WINDOW(self->window), FALSE);
797 /* Set all of the properties out of the config file */
798 tilda_window_config_string_property (self, "key");
800 // FIXME: hack -- start the wizard in this case :)
803 gchar *key = g_strdup_printf ("F%d", self->number+3);
804 g_object_set (G_OBJECT(self), "key", key, NULL);
807 g_critical ("HACK: start the wizard here\n");
810 tilda_window_config_int_property (self, "height");
811 tilda_window_config_int_property (self, "width");
812 tilda_window_config_int_property (self, "x-position");
813 tilda_window_config_int_property (self, "y-position");
814 tilda_window_config_int_property (self, "animation-delay");
816 tilda_window_config_enum_property (self, "tab-position");
817 tilda_window_config_enum_property (self, "animation-orientation");
819 tilda_window_config_boolean_property (self, "keep-above");
820 tilda_window_config_boolean_property (self, "skip-taskbar-hint");
821 tilda_window_config_boolean_property (self, "stick");
822 tilda_window_config_boolean_property (self, "hidden-at-start");
823 tilda_window_config_boolean_property (self, "centered-horizontally");
824 tilda_window_config_boolean_property (self, "centered-vertically");
826 // FIXME: It should be configurable how many terms we add at startup
827 tilda_window_add_terminal (self);
828 tilda_window_add_terminal (self);
830 /* Show us if we're ready. If not, just remain hidden. All sub-widgets must
831 * be gtk_widget_show()n by this point. */
832 if (!self->hidden_at_start)
834 gtk_widget_show (self->window);
835 self->state = WINDOW_DOWN;
838 self->state = WINDOW_UP;
840 /* Register this object with DBus */
841 tilda_window_dbus_register_object (self);
847 tilda_window_dispose (GObject *obj)
851 TildaWindow *self = (TildaWindow *) obj;
853 /* We don't want to run dispose twice, so just return immediately */
854 if (self->dispose_has_run)
858 * In dispose, you are supposed to free all types referenced from this
859 * object which might themselves hold a reference to self. Generally,
860 * the most simple solution is to unref all members on which you own a
863 * NOTE: See the following for how to deal with GtkObject-derived things:
864 * http://library.gnome.org/devel/gtk/unstable/GtkObject.html
866 g_ptr_array_foreach (self->terms, g_object_unref, NULL);
867 gtk_widget_destroy (self->window);
869 /* Unbind if we were set */
871 tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb);
873 /* Chain up to the parent class */
874 G_OBJECT_CLASS (parent_class)->dispose (obj);
878 tilda_window_finalize (GObject *obj)
882 TildaWindow *self = (TildaWindow *) obj;
885 * Here, complete the object's destruction.
886 * You might not need to do much...
888 // TODO: g_free() any primitives here
889 g_ptr_array_free (self->terms, TRUE);
892 /* Chain up to the parent class */
893 G_OBJECT_CLASS (parent_class)->finalize (obj);
897 tilda_window_class_init (gpointer g_class,
898 gpointer g_class_data)
902 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
903 TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
906 /* Hook our functions to this type */
907 gobject_class->set_property = tilda_window_set_property;
908 gobject_class->get_property = tilda_window_get_property;
909 gobject_class->dispose = tilda_window_dispose;
910 gobject_class->finalize = tilda_window_finalize;
911 gobject_class->constructor = tilda_window_constructor;
913 parent_class = g_type_class_peek_parent (klass);
915 /* Install all of the properties */
916 pspec = g_param_spec_int ("number",
920 INT_MAX, // max value
922 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
924 g_object_class_install_property (gobject_class,
928 pspec = g_param_spec_pointer ("controller",
929 _("Pointer to window's controlling TildaController"),
931 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
933 g_object_class_install_property (gobject_class,
934 TILDA_WINDOW_CONTROLLER,
937 pspec = g_param_spec_string ("key",
938 _("Window's drop-down keybinding"),
943 g_object_class_install_property (gobject_class,
947 pspec = g_param_spec_int ("height",
948 _("Window's height"),
955 g_object_class_install_property (gobject_class,
959 pspec = g_param_spec_int ("width",
967 g_object_class_install_property (gobject_class,
971 pspec = g_param_spec_int ("x-position",
972 _("Window's x position"),
979 g_object_class_install_property (gobject_class,
980 TILDA_WINDOW_X_POSITION,
983 pspec = g_param_spec_int ("y-position",
984 _("Window's y position"),
991 g_object_class_install_property (gobject_class,
992 TILDA_WINDOW_Y_POSITION,
995 pspec = g_param_spec_int ("tab-position",
996 _("Position of window's tab bar"),
1003 g_object_class_install_property (gobject_class,
1004 TILDA_WINDOW_TAB_POSITION,
1007 pspec = g_param_spec_int ("animation-orientation",
1008 _("Window's animation orientation"),
1015 g_object_class_install_property (gobject_class,
1016 TILDA_WINDOW_ANIMATION_ORIENTATION,
1019 pspec = g_param_spec_int ("animation-delay",
1020 _("Amount of time in milliseconds between animation intervals"),
1027 g_object_class_install_property (gobject_class,
1028 TILDA_WINDOW_ANIMATION_DELAY,
1031 pspec = g_param_spec_boolean ("keep-above",
1032 _("Keep this window above all others"),
1037 g_object_class_install_property (gobject_class,
1038 TILDA_WINDOW_KEEP_ABOVE,
1041 pspec = g_param_spec_boolean ("skip-taskbar-hint",
1042 _("Hide this window in the taskbar if TRUE"),
1047 g_object_class_install_property (gobject_class,
1048 TILDA_WINDOW_SKIP_TASKBAR_HINT,
1051 pspec = g_param_spec_boolean ("stick",
1052 _("Display this window on all workspaces"),
1057 g_object_class_install_property (gobject_class,
1061 pspec = g_param_spec_boolean ("hidden-at-start",
1062 _("Hide the window when it is first created"),
1067 g_object_class_install_property (gobject_class,
1068 TILDA_WINDOW_HIDDEN_AT_START,
1071 pspec = g_param_spec_boolean ("centered-horizontally",
1072 _("Center the window horizontally"),
1077 g_object_class_install_property (gobject_class,
1078 TILDA_WINDOW_CENTERED_HORIZONTALLY,
1081 pspec = g_param_spec_boolean ("centered-vertically",
1082 _("Center the window vertically"),
1087 g_object_class_install_property (gobject_class,
1088 TILDA_WINDOW_CENTERED_VERTICALLY,
1091 pspec = g_param_spec_boolean ("have-real-transparency",
1092 NULL, NULL, FALSE, G_PARAM_READABLE);
1094 g_object_class_install_property (gobject_class,
1095 TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
1098 /* Hook the TildaWindow type into DBus */
1099 dbus_g_object_type_install_info (tilda_window_get_type(), &dbus_glib_tilda_window_object_info);
1103 tilda_window_get_type (void)
1105 static GType type = 0;
1109 static const GTypeInfo info = {
1110 sizeof (TildaWindowClass),
1111 NULL, /* base_init */
1112 NULL, /* base_finalize */
1113 tilda_window_class_init, /* class_init */
1114 NULL, /* class_finalize */
1115 NULL, /* class_data */
1116 sizeof (TildaWindow),
1117 0, /* n_preallocs */
1118 tilda_window_instance_init, /* instance_init */
1121 type = g_type_register_static (G_TYPE_OBJECT,
1130 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */