[Controller] Add initial-windows property
[tilda-gobject.git] / tilda-window.c
1 #include <gdk/gdkx.h> /* for gdk_x11_window_set_user_time() */
2 #include <stdlib.h>
3
4 #include "tilda.h"
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"
10
11 /**
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.
15  */
16 static TildaTerminal *
17 tilda_window_find_current_terminal (TildaWindow *self)
18 {
19         debug_enter();
20         debug_assert (TILDA_IS_WINDOW(self));
21
22         gint i;
23         TildaTerminal *ret;
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);
26
27         for (i=0; i<self->terms->len; ++i)
28         {
29                 ret = g_ptr_array_index (self->terms, i);
30
31                 if (ret->hbox == box)
32                         return ret;
33         }
34
35         debug_printf ("ERROR: unable to find current terminal!\n");
36         return NULL;
37 }
38
39 static gint
40 tilda_window_find_next_free_terminal_number (TildaWindow *self)
41 {
42         debug_enter ();
43         debug_assert (TILDA_IS_WINDOW(self));
44
45         gint i, j;
46         gboolean found;
47
48         for (i=0; i<INT_MAX; ++i)
49         {
50                 found = FALSE;
51
52                 for (j=0; j<self->terms->len; ++j)
53                 {
54                         TildaTerminal *tt = g_ptr_array_index (self->terms, j);
55
56                         if (tt->number == i)
57                         {
58                                 found = TRUE;
59                                 break;
60                         }
61                 }
62
63                 if (!found)
64                         return i;
65         }
66
67         return 0;
68 }
69
70 /**
71  * Clean up and remove self completely from the program
72  *
73  * Should only be used by DBus...
74  */
75 gboolean
76 tilda_window_close (TildaWindow *self)
77 {
78         debug_enter  ();
79         debug_assert (TILDA_IS_WINDOW(self));
80
81         tilda_controller_remove_window (TILDA_CONTROLLER(self->controller), self->number);
82
83         return TRUE;
84 }
85
86 gboolean
87 tilda_window_add_terminal (TildaWindow *self)
88 {
89         debug_enter ();
90         debug_assert (TILDA_IS_WINDOW(self));
91
92         gint number;
93         TildaTerminal *tt;
94
95         number = tilda_window_find_next_free_terminal_number (self);
96         tt = g_object_new (TILDA_TYPE_TERMINAL,
97                                            "number", number,
98                                            "parent-window", self,
99                                            NULL);
100         g_ptr_array_add (self->terms, tt);
101
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);
106
107         if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) > 1)
108                 gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE);
109
110         /* Focus the VTE Terminal */
111         gtk_widget_grab_focus (tt->vte_term);
112
113         return TRUE;
114 }
115
116 /**
117  * Remove the TildaTerminal with the given number from the given
118  * TildaWindow.
119  *
120  * Return: TRUE on success, FALSE otherwise.
121  */
122 gboolean
123 tilda_window_remove_terminal (TildaWindow *self, gint terminal_number)
124 {
125         debug_enter  ();
126         debug_assert (TILDA_IS_WINDOW(self));
127         debug_assert (terminal_number >= 0);
128
129         gint i;
130
131         for (i=0; i<self->terms->len; ++i)
132         {
133                 TildaTerminal *tt = g_ptr_array_index (self->terms, i);
134
135                 if (tt->number == terminal_number)
136                 {
137                         gint notebook_index = gtk_notebook_page_num (GTK_NOTEBOOK(self->notebook), tt->hbox);
138
139                         /* Make sure the index was valid */
140                         if (notebook_index == -1)
141                         {
142                                 debug_printf ("ERROR: Bad Notebook Tab\n");
143                                 return FALSE;
144                         }
145
146                         /* Actually remove the terminal */
147                         gtk_notebook_remove_page (GTK_NOTEBOOK (self->notebook), notebook_index);
148
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);
152
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));
156
157                         /* With no pages left, it's time to remove this window */
158                         if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) < 1)
159                         {
160                                 debug_printf ("no terminals left, closing window %d\n", self->number);
161                                 tilda_controller_remove_window (TILDA_CONTROLLER(self->controller), self->number);
162                         }
163
164                         /* Leave the loop, we're done */
165                         break;
166                 }
167         }
168
169         return TRUE;
170 }
171
172 /**
173  * This sets up the given TildaWindow for the capability of real
174  * transparency, if the X server is capable of it. */
175 static void
176 tilda_window_setup_real_transparency (TildaWindow *self)
177 {
178         debug_enter  ();
179         debug_assert (TILDA_IS_WINDOW(self));
180
181         GdkScreen *screen;
182         GdkColormap *colormap;
183
184         screen = gtk_widget_get_screen (GTK_WIDGET(self->window));
185         colormap = gdk_screen_get_rgba_colormap (screen);
186
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))
190         {
191                 gtk_widget_set_colormap (GTK_WIDGET(self->window), colormap);
192                 self->have_real_transparency = TRUE;
193                 return;
194         }
195
196         self->have_real_transparency = FALSE;
197 }
198
199 /* Center the given TildaWindow in the horizontal axis */
200 static void
201 tilda_window_center_horizontally (TildaWindow *self)
202 {
203         debug_enter  ();
204         debug_assert (TILDA_IS_WINDOW(self));
205
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;
209
210         g_object_set (G_OBJECT(self), "x-position", center_coord, NULL);
211 }
212
213 /* Center the given TildaWindow in the vertical axis */
214 static void
215 tilda_window_center_vertically (TildaWindow *self)
216 {
217         debug_enter  ();
218         debug_assert (TILDA_IS_WINDOW(self));
219
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;
223
224         g_object_set (G_OBJECT(self), "y-position", center_coord, NULL);
225 }
226
227 static void
228 tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
229 {
230         debug_enter  ();
231         debug_assert (TILDA_IS_WINDOW(data));
232
233         TildaWindow *self = TILDA_WINDOW(data);
234         TildaTerminal *tt;
235
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());
242
243         switch (self->state)
244         {
245                 case WINDOW_UP: /* Pull the window up */
246
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));
252
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,
259                                         NULL);
260                         gtk_widget_show (GTK_WIDGET(self->window));
261
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));
265
266                         self->state = WINDOW_DOWN;
267                         break;
268
269                 case WINDOW_DOWN: /* Pull the window up */
270
271                         gtk_widget_hide (GTK_WIDGET(self->window));
272
273                         self->state = WINDOW_UP;
274                         break;
275
276                 default:
277                         debug_printf ("ERROR: Window is in a bad state!\n");
278
279                         /* Pretend we're down, for good measure.... */
280                         self->state = WINDOW_DOWN;
281                         break;
282         }
283 }
284
285 /**
286  * Attempt to bind the new_key to show this window.
287  *
288  * Return: TRUE if successful, FALSE otherwise.
289  */
290 static gboolean
291 tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key)
292 {
293         debug_enter  ();
294         debug_assert (TILDA_IS_WINDOW(self));
295
296         gboolean ret = FALSE;
297
298         /* Make sure the new key is not null in any way */
299         if (new_key == NULL || g_ascii_strcasecmp("", new_key) == 0)
300                 return FALSE;
301
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))
306                 return FALSE;
307
308         /* Unbind if we were set */
309         if (self->key)
310                 tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb);
311
312         ret = tomboy_keybinder_bind (new_key, tilda_window_keybinding_cb, self);
313
314         /* If it was successful, update the self->key variable and be done with it */
315         if (ret)
316         {
317                 g_free (self->key);
318                 self->key = g_strdup (new_key);
319                 return TRUE;
320         }
321
322         g_printerr (_("Bind key '%s' failed. Reverting to original keybinding\n"), self->key);
323
324         /* Not successful, so rebind the old key, and return FALSE */
325         if (self->key != NULL && g_ascii_strcasecmp("",self->key) != 0)
326         {
327                 ret = tomboy_keybinder_bind (self->key, tilda_window_keybinding_cb, self);
328
329                 /* Check that it went ok */
330                 if (!ret)
331                         g_printerr (_("Unable to re-bind original key '%s'. Oh shit...\n"), self->key);
332         }
333         else
334                 g_printerr (_("No original key to revert to!\n"));
335
336         return FALSE;
337 }
338
339 static void
340 tilda_window_dbus_register_object (TildaWindow *self)
341 {
342         debug_enter  ();
343         debug_assert (TILDA_IS_WINDOW(self));
344
345         gchar *object_path;
346
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);
351 }
352
353 /*******************************************************************************
354  * ALL GOBJECT STUFF BELOW PLEASE
355  ******************************************************************************/
356
357 static GObjectClass *parent_class = NULL;
358
359 enum tilda_window_properties {
360         TILDA_WINDOW_NUMBER = 1,
361         TILDA_WINDOW_CONTROLLER,
362
363         TILDA_WINDOW_KEY,
364
365         TILDA_WINDOW_HEIGHT,
366         TILDA_WINDOW_WIDTH,
367         TILDA_WINDOW_X_POSITION,
368         TILDA_WINDOW_Y_POSITION,
369         TILDA_WINDOW_INITIAL_TERMINALS,
370
371         TILDA_WINDOW_TAB_POSITION,
372         TILDA_WINDOW_ANIMATION_ORIENTATION,
373         TILDA_WINDOW_ANIMATION_DELAY,
374
375         TILDA_WINDOW_KEEP_ABOVE,
376         TILDA_WINDOW_SKIP_TASKBAR_HINT,
377         TILDA_WINDOW_STICK,
378         TILDA_WINDOW_HIDDEN_AT_START,
379         TILDA_WINDOW_CENTERED_HORIZONTALLY,
380         TILDA_WINDOW_CENTERED_VERTICALLY,
381
382         TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
383 };
384
385 static void
386 tilda_window_instance_init (GTypeInstance *instance,
387                                                         gpointer       g_class)
388 {
389         debug_enter ();
390
391         TildaWindow *self = (TildaWindow *) instance;
392         self->dispose_has_run = FALSE;
393
394         /* Initialize all properties */
395         self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
396         self->notebook = gtk_notebook_new ();
397         self->terms = g_ptr_array_new ();
398
399         /* Somewhat of a "poison" value, incase we don't set this */
400         self->number = 0xdeadbeef;
401         self->controller = NULL;
402
403         self->state = WINDOW_UP;
404 }
405
406 static void
407 tilda_window_set_property (GObject      *object,
408                                                    guint         property_id,
409                                                    const GValue *value,
410                                                    GParamSpec   *pspec)
411 {
412         TildaWindow *self = (TildaWindow *) object;
413
414         switch (property_id) {
415
416                 case TILDA_WINDOW_NUMBER:
417                         self->number = g_value_get_int (value);
418                         debug_printf ("window number: %d\n", self->number);
419                         break;
420
421                 case TILDA_WINDOW_CONTROLLER:
422                         self->controller = g_value_get_pointer (value);
423                         debug_printf ("window controller: 0x%x\n", self->controller);
424                         break;
425
426                 case TILDA_WINDOW_KEY:
427                         tilda_window_try_to_bind_key (self, g_value_get_string (value));
428                         debug_printf ("window key %s\n", self->key);
429                         break;
430
431                 case TILDA_WINDOW_HEIGHT:
432                         self->height = g_value_get_int (value);
433                         gtk_widget_set_size_request (self->window, self->width, self->height);
434                         gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
435                         debug_printf ("window height: %d\n", self->height);
436                         break;
437
438                 case TILDA_WINDOW_WIDTH:
439                         self->width = g_value_get_int (value);
440                         gtk_widget_set_size_request (self->window, self->width, self->height);
441                         gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
442                         debug_printf ("window width: %d\n", self->width);
443                         break;
444
445                 case TILDA_WINDOW_X_POSITION:
446                         self->x_position = g_value_get_int (value);
447                         gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
448                         debug_printf ("window x position: %d\n", self->x_position);
449                         break;
450
451                 case TILDA_WINDOW_Y_POSITION:
452                         self->y_position = g_value_get_int (value);
453                         gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
454                         debug_printf ("window y position: %d\n", self->y_position);
455                         break;
456
457                 case TILDA_WINDOW_INITIAL_TERMINALS:
458                         self->initial_terminals = g_value_get_int (value);
459                         debug_printf ("window initial terminals: %d\n", self->initial_terminals);
460                         break;
461
462                 case TILDA_WINDOW_TAB_POSITION:
463                         self->tab_position = g_value_get_enum (value);
464                         gtk_notebook_set_tab_pos (GTK_NOTEBOOK(self->notebook), self->tab_position);
465                         debug_printf ("window tab position: %d\n", self->tab_position);
466                         break;
467
468                 case TILDA_WINDOW_ANIMATION_ORIENTATION:
469                         self->animation_orientation = g_value_get_enum (value);
470                         debug_printf ("window animation orientation: %d\n", self->animation_orientation);
471                         break;
472
473                 case TILDA_WINDOW_ANIMATION_DELAY:
474                         self->animation_delay = g_value_get_int (value);
475                         debug_printf ("window animation delay: %d\n", self->animation_delay);
476                         break;
477
478                 case TILDA_WINDOW_KEEP_ABOVE:
479                         self->keep_above = g_value_get_boolean (value);
480                         gtk_window_set_keep_above (GTK_WINDOW(self->window), self->keep_above);
481                         debug_printf ("window keep above: %d\n", self->keep_above);
482                         break;
483
484                 case TILDA_WINDOW_SKIP_TASKBAR_HINT:
485                         self->skip_taskbar_hint = g_value_get_boolean (value);
486                         gtk_window_set_skip_taskbar_hint (GTK_WINDOW(self->window), self->skip_taskbar_hint);
487                         debug_printf ("window skip taskbar hint: %d\n", self->skip_taskbar_hint);
488                         break;
489
490                 case TILDA_WINDOW_STICK:
491                         self->stick = g_value_get_boolean (value);
492
493                         /* This is moderately ugly, but GTK+ does it this way... */
494                         self->stick ? gtk_window_stick (GTK_WINDOW(self->window))
495                                                 : gtk_window_unstick (GTK_WINDOW(self->window));
496                         debug_printf ("window stick: %d\n", self->stick);
497                         break;
498
499                 case TILDA_WINDOW_HIDDEN_AT_START:
500                         self->hidden_at_start = g_value_get_boolean (value);
501                         debug_printf ("window hidden at start: %d\n", self->hidden_at_start);
502                         break;
503
504                 case TILDA_WINDOW_CENTERED_HORIZONTALLY:
505                         self->centered_horizontally = g_value_get_boolean (value);
506                         if (self->centered_horizontally)
507                                 tilda_window_center_horizontally (self);
508                         debug_printf ("window centered horizontally: %d\n", self->centered_horizontally);
509                         break;
510
511                 case TILDA_WINDOW_CENTERED_VERTICALLY:
512                         self->centered_vertically = g_value_get_boolean (value);
513                         if (self->centered_vertically)
514                                 tilda_window_center_vertically (self);
515                         debug_printf ("window centered vertically: %d\n", self->centered_vertically);
516                         break;
517
518                 case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
519                         self->have_real_transparency = g_value_get_boolean (value);
520                         debug_printf ("window have real transp: %d\n", self->have_real_transparency);
521                         break;
522
523                 default:
524                         /* We don't have this property */
525                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
526                         break;
527         }
528 }
529
530 static void
531 tilda_window_get_property (GObject    *object,
532                                                    guint       property_id,
533                                                    GValue     *value,
534                                                    GParamSpec *pspec)
535 {
536         TildaWindow *self = (TildaWindow *) object;
537
538         switch (property_id) {
539
540                 case TILDA_WINDOW_NUMBER:
541                         g_value_set_int (value, self->number);
542                         break;
543
544                 case TILDA_WINDOW_CONTROLLER:
545                         g_value_set_pointer (value, self->controller);
546                         break;
547
548                 case TILDA_WINDOW_KEY:
549                         g_value_set_string (value, self->key);
550                         break;
551
552                 case TILDA_WINDOW_HEIGHT:
553                         g_value_set_int (value, self->height);
554                         break;
555
556                 case TILDA_WINDOW_WIDTH:
557                         g_value_set_int (value, self->width);
558                         break;
559
560                 case TILDA_WINDOW_X_POSITION:
561                         g_value_set_int (value, self->x_position);
562                         break;
563
564                 case TILDA_WINDOW_Y_POSITION:
565                         g_value_set_int (value, self->y_position);
566                         break;
567
568                 case TILDA_WINDOW_INITIAL_TERMINALS:
569                         g_value_set_int (value, self->initial_terminals);
570                         break;
571
572                 case TILDA_WINDOW_TAB_POSITION:
573                         g_value_set_enum (value, self->tab_position);
574                         break;
575
576                 case TILDA_WINDOW_ANIMATION_ORIENTATION:
577                         g_value_set_enum (value, self->animation_orientation);
578                         break;
579
580                 case TILDA_WINDOW_ANIMATION_DELAY:
581                         g_value_set_int (value, self->animation_delay);
582                         break;
583
584                 case TILDA_WINDOW_KEEP_ABOVE:
585                         g_value_set_boolean (value, self->keep_above);
586                         break;
587
588                 case TILDA_WINDOW_SKIP_TASKBAR_HINT:
589                         g_value_set_boolean (value, self->skip_taskbar_hint);
590                         break;
591
592                 case TILDA_WINDOW_STICK:
593                         g_value_set_boolean (value, self->stick);
594                         break;
595
596                 case TILDA_WINDOW_HIDDEN_AT_START:
597                         g_value_set_boolean (value, self->hidden_at_start);
598                         break;
599
600                 case TILDA_WINDOW_CENTERED_HORIZONTALLY:
601                         g_value_set_boolean (value, self->centered_horizontally);
602                         break;
603
604                 case TILDA_WINDOW_CENTERED_VERTICALLY:
605                         g_value_set_boolean (value, self->centered_vertically);
606                         break;
607
608                 case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
609                         g_value_set_boolean (value, self->have_real_transparency);
610                         break;
611
612                 default:
613                         /* We don't have this property */
614                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
615                         break;
616         }
617 }
618
619 static GObject *
620 tilda_window_constructor (GType                  type,
621                                                   guint                  n_construct_properties,
622                                                   GObjectConstructParam *construct_properties)
623 {
624         debug_enter ();
625
626         GObject *obj;
627         TildaWindow *self;
628         gint i;
629
630         /* Invoke parent constructor */
631         TildaWindowClass *klass;
632         klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
633         obj = parent_class->constructor (type,
634                                                                          n_construct_properties,
635                                                                          construct_properties);
636
637         /* Do other stuff here. The object is ready to go now, and all
638          * ctor properties have been set.
639          */
640         self = TILDA_WINDOW(obj);
641
642         /* Try to set up real transparency */
643         tilda_window_setup_real_transparency (self);
644
645         gtk_container_add (GTK_CONTAINER(self->window), self->notebook);
646         g_object_set (G_OBJECT(self->notebook), "can-focus", FALSE, NULL);
647         gtk_widget_show (self->notebook);
648
649         /* Tilda is never decorated */
650         gtk_window_set_decorated (GTK_WINDOW(self->window), FALSE);
651
652         /* Set all of the properties out of the config file */
653         tilda_window_set_property_from_config (self, "key");
654
655         // FIXME: hack -- start the wizard in this case :)
656         if (!self->key)
657         {
658                 gchar *key = g_strdup_printf ("F%d", self->number+3);
659                 g_object_set (G_OBJECT(self), "key", key, NULL);
660                 g_free (key);
661
662                 g_critical ("HACK: start the wizard here\n");
663         }
664
665         tilda_window_set_property_from_config (self, "height");
666         tilda_window_set_property_from_config (self, "width");
667         tilda_window_set_property_from_config (self, "x-position");
668         tilda_window_set_property_from_config (self, "y-position");
669         tilda_window_set_property_from_config (self, "initial-terminals");
670         tilda_window_set_property_from_config (self, "animation-delay");
671
672         tilda_window_set_property_from_config (self, "tab-position");
673         tilda_window_set_property_from_config (self, "animation-orientation");
674
675         tilda_window_set_property_from_config (self, "keep-above");
676         tilda_window_set_property_from_config (self, "skip-taskbar-hint");
677         tilda_window_set_property_from_config (self, "stick");
678         tilda_window_set_property_from_config (self, "hidden-at-start");
679         tilda_window_set_property_from_config (self, "centered-horizontally");
680         tilda_window_set_property_from_config (self, "centered-vertically");
681
682         /* Add the initial terminal(s) */
683         for (i=0; i<self->initial_terminals; ++i)
684                 tilda_window_add_terminal (self);
685
686         /* Show us if we're ready. If not, just remain hidden. All sub-widgets must
687          * be gtk_widget_show()n by this point. */
688         if (!self->hidden_at_start)
689         {
690                 gtk_widget_show (self->window);
691                 self->state = WINDOW_DOWN;
692         }
693         else
694                 self->state = WINDOW_UP;
695
696         /* Register this object with DBus */
697         tilda_window_dbus_register_object (self);
698
699         return obj;
700 }
701
702 static void
703 tilda_window_dispose (GObject *obj)
704 {
705         debug_enter ();
706
707         TildaWindow *self = (TildaWindow *) obj;
708
709         /* We don't want to run dispose twice, so just return immediately */
710         if (self->dispose_has_run)
711                 return;
712
713         /*
714          * In dispose, you are supposed to free all types referenced from this
715          * object which might themselves hold a reference to self. Generally,
716          * the most simple solution is to unref all members on which you own a
717          * reference.
718          *
719          * NOTE: See the following for how to deal with GtkObject-derived things:
720          * http://library.gnome.org/devel/gtk/unstable/GtkObject.html
721          */
722         g_ptr_array_foreach (self->terms, g_object_unref, NULL);
723         gtk_widget_destroy (self->window);
724
725         /* Unbind if we were set */
726         if (self->key)
727                 tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb);
728
729         /* Chain up to the parent class */
730         G_OBJECT_CLASS (parent_class)->dispose (obj);
731 }
732
733 static void
734 tilda_window_finalize (GObject *obj)
735 {
736         debug_enter ();
737
738         TildaWindow *self = (TildaWindow *) obj;
739
740         /*
741          * Here, complete the object's destruction.
742          * You might not need to do much...
743          */
744         // TODO: g_free() any primitives here
745         g_ptr_array_free (self->terms, TRUE);
746
747
748         /* Chain up to the parent class */
749         G_OBJECT_CLASS (parent_class)->finalize (obj);
750 }
751
752 static void
753 tilda_window_class_init (gpointer g_class,
754                                                  gpointer g_class_data)
755 {
756         debug_enter ();
757
758         GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
759         TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
760         GParamSpec *pspec;
761
762         /* Hook our functions to this type */
763         gobject_class->set_property = tilda_window_set_property;
764         gobject_class->get_property = tilda_window_get_property;
765         gobject_class->dispose = tilda_window_dispose;
766         gobject_class->finalize = tilda_window_finalize;
767         gobject_class->constructor = tilda_window_constructor;
768
769         parent_class = g_type_class_peek_parent (klass);
770
771         /* Install all of the properties */
772         pspec = g_param_spec_int ("number",
773                                                           _("Window number"),
774                                                           NULL,
775                                                           0,            // min value
776                                                           INT_MAX,      // max value
777                                                           0,            // def value
778                                                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
779
780         g_object_class_install_property (gobject_class,
781                                                                          TILDA_WINDOW_NUMBER,
782                                                                          pspec);
783
784         pspec = g_param_spec_pointer ("controller",
785                                                                   _("Pointer to window's controlling TildaController"),
786                                                                   NULL,
787                                                                   G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
788
789         g_object_class_install_property (gobject_class,
790                                                                          TILDA_WINDOW_CONTROLLER,
791                                                                          pspec);
792
793         pspec = g_param_spec_string ("key",
794                                                                  _("Window's drop-down keybinding"),
795                                                                  NULL,
796                                                                  NULL,
797                                                                  G_PARAM_READWRITE);
798
799         g_object_class_install_property (gobject_class,
800                                                                          TILDA_WINDOW_KEY,
801                                                                          pspec);
802
803         pspec = g_param_spec_int ("height",
804                                                           _("Window's height"),
805                                                           NULL,
806                                                           0,
807                                                           INT_MAX,
808                                                           0,
809                                                           G_PARAM_READWRITE);
810
811         g_object_class_install_property (gobject_class,
812                                                                          TILDA_WINDOW_HEIGHT,
813                                                                          pspec);
814
815         pspec = g_param_spec_int ("width",
816                                                           _("Window's width"),
817                                                           NULL,
818                                                           0,
819                                                           INT_MAX,
820                                                           0,
821                                                           G_PARAM_READWRITE);
822
823         g_object_class_install_property (gobject_class,
824                                                                          TILDA_WINDOW_WIDTH,
825                                                                          pspec);
826
827         pspec = g_param_spec_int ("x-position",
828                                                           _("Window's x position"),
829                                                           NULL,
830                                                           0,
831                                                           INT_MAX,
832                                                           0,
833                                                           G_PARAM_READWRITE);
834
835         g_object_class_install_property (gobject_class,
836                                                                          TILDA_WINDOW_X_POSITION,
837                                                                          pspec);
838
839         pspec = g_param_spec_int ("y-position",
840                                                           _("Window's y position"),
841                                                           NULL,
842                                                           0,
843                                                           INT_MAX,
844                                                           0,
845                                                           G_PARAM_READWRITE);
846
847         g_object_class_install_property (gobject_class,
848                                                                          TILDA_WINDOW_Y_POSITION,
849                                                                          pspec);
850
851         pspec = g_param_spec_int ("initial-terminals",
852                                                           _("Window's inital number of terminals"),
853                                                           NULL,
854                                                           1,
855                                                           INT_MAX,
856                                                           1,
857                                                           G_PARAM_READWRITE);
858
859         g_object_class_install_property (gobject_class,
860                                                                          TILDA_WINDOW_INITIAL_TERMINALS,
861                                                                          pspec);
862
863         pspec = g_param_spec_enum ("tab-position",
864                                                            _("Position of window's tab bar"),
865                                                            NULL,
866                                                            gtk_position_type_get_type(),
867                                                            GTK_POS_TOP,
868                                                            G_PARAM_READWRITE);
869
870         g_object_class_install_property (gobject_class,
871                                                                          TILDA_WINDOW_TAB_POSITION,
872                                                                          pspec);
873
874         pspec = g_param_spec_enum ("animation-orientation",
875                                                            _("Window's animation orientation"),
876                                                            NULL,
877                                                            gtk_position_type_get_type(),
878                                                            GTK_POS_TOP,
879                                                            G_PARAM_READWRITE);
880
881         g_object_class_install_property (gobject_class,
882                                                                          TILDA_WINDOW_ANIMATION_ORIENTATION,
883                                                                          pspec);
884
885         pspec = g_param_spec_int ("animation-delay",
886                                                           _("Amount of time in milliseconds between animation intervals"),
887                                                           NULL,
888                                                           0,
889                                                           INT_MAX,
890                                                           0,
891                                                           G_PARAM_READWRITE);
892
893         g_object_class_install_property (gobject_class,
894                                                                          TILDA_WINDOW_ANIMATION_DELAY,
895                                                                          pspec);
896
897         pspec = g_param_spec_boolean ("keep-above",
898                                                                   _("Keep this window above all others"),
899                                                                   NULL,
900                                                                   FALSE,
901                                                                   G_PARAM_READWRITE);
902
903         g_object_class_install_property (gobject_class,
904                                                                          TILDA_WINDOW_KEEP_ABOVE,
905                                                                          pspec);
906
907         pspec = g_param_spec_boolean ("skip-taskbar-hint",
908                                                                   _("Hide this window in the taskbar if TRUE"),
909                                                                   NULL,
910                                                                   FALSE,
911                                                                   G_PARAM_READWRITE);
912
913         g_object_class_install_property (gobject_class,
914                                                                          TILDA_WINDOW_SKIP_TASKBAR_HINT,
915                                                                          pspec);
916
917         pspec = g_param_spec_boolean ("stick",
918                                                                   _("Display this window on all workspaces"),
919                                                                   NULL,
920                                                                   FALSE,
921                                                                   G_PARAM_READWRITE);
922
923         g_object_class_install_property (gobject_class,
924                                                                          TILDA_WINDOW_STICK,
925                                                                          pspec);
926
927         pspec = g_param_spec_boolean ("hidden-at-start",
928                                                                   _("Hide the window when it is first created"),
929                                                                   NULL,
930                                                                   FALSE,
931                                                                   G_PARAM_READWRITE);
932
933         g_object_class_install_property (gobject_class,
934                                                                          TILDA_WINDOW_HIDDEN_AT_START,
935                                                                          pspec);
936
937         pspec = g_param_spec_boolean ("centered-horizontally",
938                                                                   _("Center the window horizontally"),
939                                                                   NULL,
940                                                                   FALSE,
941                                                                   G_PARAM_READWRITE);
942
943         g_object_class_install_property (gobject_class,
944                                                                          TILDA_WINDOW_CENTERED_HORIZONTALLY,
945                                                                          pspec);
946
947         pspec = g_param_spec_boolean ("centered-vertically",
948                                                                   _("Center the window vertically"),
949                                                                   NULL,
950                                                                   FALSE,
951                                                                   G_PARAM_READWRITE);
952
953         g_object_class_install_property (gobject_class,
954                                                                          TILDA_WINDOW_CENTERED_VERTICALLY,
955                                                                          pspec);
956
957         pspec = g_param_spec_boolean ("have-real-transparency",
958                                                                   NULL, NULL, FALSE, G_PARAM_READABLE);
959
960         g_object_class_install_property (gobject_class,
961                                                                          TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
962                                                                          pspec);
963
964         /* Hook the TildaWindow type into DBus */
965         dbus_g_object_type_install_info (tilda_window_get_type(), &dbus_glib_tilda_window_object_info);
966 }
967
968 GType
969 tilda_window_get_type (void)
970 {
971         static GType type = 0;
972
973         if (type == 0)
974         {
975                 static const GTypeInfo info = {
976                         sizeof (TildaWindowClass),
977                         NULL,   /* base_init */
978                         NULL,   /* base_finalize */
979                         tilda_window_class_init,        /* class_init */
980                         NULL,   /* class_finalize */
981                         NULL,   /* class_data */
982                         sizeof (TildaWindow),
983                         0,              /* n_preallocs */
984                         tilda_window_instance_init,     /* instance_init */
985                 };
986
987                 type = g_type_register_static (G_TYPE_OBJECT,
988                                                                            "TildaWindowType",
989                                                                            &info,
990                                                                            0);
991         }
992
993         return type;
994 }
995
996 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */