[Window] Add support for configuration of tab width
[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         GtkWidget *label;
95         gint notebook_index;
96
97         number = tilda_window_find_next_free_terminal_number (self);
98         tt = g_object_new (TILDA_TYPE_TERMINAL,
99                                            "number", number,
100                                            "parent-window", self,
101                                            NULL);
102         g_ptr_array_add (self->terms, tt);
103
104         label = gtk_label_new ("Tilda");
105         notebook_index = gtk_notebook_prepend_page (GTK_NOTEBOOK(self->notebook), tt->hbox, label);
106         gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(self->notebook), tt->hbox,
107                                                                                 self->full_width_tabs, TRUE, GTK_PACK_START);
108         gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), notebook_index);
109
110         if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) > 1)
111                 gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE);
112
113         /* Focus the VTE Terminal */
114         gtk_widget_grab_focus (tt->vte_term);
115
116         return TRUE;
117 }
118
119 /**
120  * Remove the TildaTerminal with the given number from the given
121  * TildaWindow.
122  *
123  * Return: TRUE on success, FALSE otherwise.
124  */
125 gboolean
126 tilda_window_remove_terminal (TildaWindow *self, gint terminal_number)
127 {
128         debug_enter  ();
129         debug_assert (TILDA_IS_WINDOW(self));
130         debug_assert (terminal_number >= 0);
131
132         gint i;
133
134         for (i=0; i<self->terms->len; ++i)
135         {
136                 TildaTerminal *tt = g_ptr_array_index (self->terms, i);
137
138                 if (tt->number == terminal_number)
139                 {
140                         gint notebook_index = gtk_notebook_page_num (GTK_NOTEBOOK(self->notebook), tt->hbox);
141
142                         /* Make sure the index was valid */
143                         if (notebook_index == -1)
144                         {
145                                 debug_printf ("ERROR: Bad Notebook Tab\n");
146                                 return FALSE;
147                         }
148
149                         /* Actually remove the terminal */
150                         gtk_notebook_remove_page (GTK_NOTEBOOK (self->notebook), notebook_index);
151
152                         /* We should hide the tabs if there is only one tab left */
153                         if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) == 1)
154                                 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (self->notebook), FALSE);
155
156                         /* Remove the term from our lists, then free it */
157                         g_ptr_array_remove_fast (self->terms, tt);
158                         g_object_unref (G_OBJECT(tt));
159
160                         /* With no pages left, it's time to remove this window */
161                         if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) < 1)
162                         {
163                                 debug_printf ("no terminals left, closing window %d\n", self->number);
164                                 tilda_controller_remove_window (TILDA_CONTROLLER(self->controller), self->number);
165                         }
166
167                         /* Leave the loop, we're done */
168                         break;
169                 }
170         }
171
172         return TRUE;
173 }
174
175 /**
176  * This sets up the given TildaWindow for the capability of real
177  * transparency, if the X server is capable of it. */
178 static void
179 tilda_window_setup_real_transparency (TildaWindow *self)
180 {
181         debug_enter  ();
182         debug_assert (TILDA_IS_WINDOW(self));
183
184         GdkScreen *screen;
185         GdkColormap *colormap;
186
187         screen = gtk_widget_get_screen (GTK_WIDGET(self->window));
188         colormap = gdk_screen_get_rgba_colormap (screen);
189
190         /* If possible, set the RGBA colormap so VTE can use real alpha
191          * channels for transparency. */
192         if (colormap != NULL && gdk_screen_is_composited (screen))
193         {
194                 gtk_widget_set_colormap (GTK_WIDGET(self->window), colormap);
195                 self->have_real_transparency = TRUE;
196                 return;
197         }
198
199         self->have_real_transparency = FALSE;
200 }
201
202 /* Center the given TildaWindow in the horizontal axis */
203 static void
204 tilda_window_center_horizontally (TildaWindow *self)
205 {
206         debug_enter  ();
207         debug_assert (TILDA_IS_WINDOW(self));
208
209         const gint screen_center = gdk_screen_width() / 2;
210         const gint tilda_center  = self->width / 2;
211         const gint center_coord  = screen_center - tilda_center;
212
213         g_object_set (G_OBJECT(self), "x-position", center_coord, NULL);
214 }
215
216 /* Center the given TildaWindow in the vertical axis */
217 static void
218 tilda_window_center_vertically (TildaWindow *self)
219 {
220         debug_enter  ();
221         debug_assert (TILDA_IS_WINDOW(self));
222
223         const gint screen_center = gdk_screen_height() / 2;
224         const gint tilda_center  = self->height / 2;
225         const gint center_coord  = screen_center - tilda_center;
226
227         g_object_set (G_OBJECT(self), "y-position", center_coord, NULL);
228 }
229
230 static void
231 tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
232 {
233         debug_enter  ();
234         debug_assert (TILDA_IS_WINDOW(data));
235
236         TildaWindow *self = TILDA_WINDOW(data);
237         TildaTerminal *tt;
238
239         /* This call sets the X11 window property _NET_WM_USER_TIME, which GTK+ normally
240          * sets for us. However, because this callback is activated via a global keybinding,
241          * we see the event before GDK / GTK+ does. Therefore, to get the focus, we must
242          * set the property ourselves. */
243         gdk_x11_window_set_user_time (GTK_WIDGET(self->window)->window,
244                                                                   tomboy_keybinder_get_current_event_time());
245
246         switch (self->state)
247         {
248                 case WINDOW_UP: /* Pull the window up */
249
250                         /* Bugfix: having this here keeps the tilda window from being
251                          * hidden if you turn off "stick", pull it down on workspace 1,
252                          * switch to workspace 2, then pull it up and back down. Without
253                          * this, something in metacity (at least) hides the window. Stupid. */
254                         gtk_window_deiconify (GTK_WINDOW(self->window));
255
256                         /* Re-set the window properties that do not linger after hiding the
257                          * window. I know this looks stupid, but it keeps all of the state-
258                          * changing code in the place it belongs: the property-setting code. */
259                         g_object_set (G_OBJECT(self),
260                                         "keep-above", self->keep_above,
261                                         "stick", self->stick,
262                                         NULL);
263                         gtk_widget_show (GTK_WIDGET(self->window));
264
265                         /* Focusing the term here works perfectly, near as I can tell */
266                         tt = tilda_window_find_current_terminal (self);
267                         gtk_widget_grab_focus (GTK_WIDGET(tt->vte_term));
268
269                         self->state = WINDOW_DOWN;
270                         break;
271
272                 case WINDOW_DOWN: /* Pull the window up */
273
274                         gtk_widget_hide (GTK_WIDGET(self->window));
275
276                         self->state = WINDOW_UP;
277                         break;
278
279                 default:
280                         debug_printf ("ERROR: Window is in a bad state!\n");
281
282                         /* Pretend we're down, for good measure.... */
283                         self->state = WINDOW_DOWN;
284                         break;
285         }
286 }
287
288 /**
289  * Attempt to bind the new_key to show this window.
290  *
291  * Return: TRUE if successful, FALSE otherwise.
292  */
293 static gboolean
294 tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key)
295 {
296         debug_enter  ();
297         debug_assert (TILDA_IS_WINDOW(self));
298
299         gboolean ret = FALSE;
300
301         /* Make sure the new key is not null in any way */
302         if (new_key == NULL || g_ascii_strcasecmp("", new_key) == 0)
303                 return FALSE;
304
305         /* Check that no other windows are using the key */
306         // FIXME: there should be a hidden option to disable this. Maybe some people want
307         // to have logs in two Tildas, and just show them with one key. Crazy...
308         if (tilda_controller_global_key_in_use(TILDA_CONTROLLER(self->controller), new_key))
309                 return FALSE;
310
311         /* Unbind if we were set */
312         if (self->key)
313                 tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb);
314
315         ret = tomboy_keybinder_bind (new_key, tilda_window_keybinding_cb, self);
316
317         /* If it was successful, update the self->key variable and be done with it */
318         if (ret)
319         {
320                 g_free (self->key);
321                 self->key = g_strdup (new_key);
322                 return TRUE;
323         }
324
325         g_printerr (_("Bind key '%s' failed. Reverting to original keybinding\n"), self->key);
326
327         /* Not successful, so rebind the old key, and return FALSE */
328         if (self->key != NULL && g_ascii_strcasecmp("",self->key) != 0)
329         {
330                 ret = tomboy_keybinder_bind (self->key, tilda_window_keybinding_cb, self);
331
332                 /* Check that it went ok */
333                 if (!ret)
334                         g_printerr (_("Unable to re-bind original key '%s'. Oh shit...\n"), self->key);
335         }
336         else
337                 g_printerr (_("No original key to revert to!\n"));
338
339         return FALSE;
340 }
341
342 static void
343 tilda_window_dbus_register_object (TildaWindow *self)
344 {
345         debug_enter  ();
346         debug_assert (TILDA_IS_WINDOW(self));
347
348         gchar *object_path;
349
350         /* If DBus is not running, leave */
351         if (!dbus_connection)
352                 return;
353
354         /* Register this object with DBus */
355         object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d", self->number);
356         dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(self));
357         g_free (object_path);
358 }
359
360 /*******************************************************************************
361  * All accelerator-related stuff below
362  ******************************************************************************/
363
364 typedef gboolean (*TildaWindowAccelCallback) (TildaWindow *self, gpointer data);
365
366 /**
367  * This function updates the accelerator used to call the given function for this
368  * TildaWindow. If accel is NULL, then func will be removed (no accelerator will
369  * cause func to be called).
370  *
371  * Returns: TRUE on success, FALSE on failure
372  */
373 static gboolean
374 tilda_window_update_accelerator (TildaWindow *self,                             /* object */
375                                                                  gchar **accel_to_update,               /* self->??? */
376                                                                  const gchar *accel,                    /* new accel */
377                                                                  const TildaWindowAccelCallback func)
378 {
379         debug_enter  ();
380         debug_assert (TILDA_IS_WINDOW(self));
381         debug_assert (accel_to_update != NULL);
382         debug_assert (func != NULL);
383
384         gboolean ret;
385         guint key;
386         GdkModifierType mod;
387         GClosure *closure;
388
389         /* Remove the old accelerator if there was a previous one set */
390         if (*accel_to_update != NULL)
391         {
392                 /* This should always parse, we've done it before! */
393                 gtk_accelerator_parse (*accel_to_update, &key, &mod);
394                 ret = gtk_accel_group_disconnect_key (self->accel_group, key, mod);
395         }
396
397         /* If we are just removing the old accelerator, we're already done */
398         if (accel == NULL)
399         {
400                 g_free (*accel_to_update);
401                 *accel_to_update = NULL;
402                 return TRUE;
403         }
404
405         /* Create the closure for this function */
406         closure = g_cclosure_new_swap (G_CALLBACK(func), self, NULL);
407
408         /* Try to parse the new accelerator */
409         gtk_accelerator_parse (accel, &key, &mod);
410
411         if (!gtk_accelerator_valid (key, mod))
412         {
413                 g_warning (_("Failed to parse accelerator: %s\n"), accel);
414
415                 /* Re-install the old accelerator */
416                 if (*accel_to_update != NULL)
417                 {
418                         gtk_accelerator_parse (*accel_to_update, &key, &mod);
419                         gtk_accel_group_connect (self->accel_group, key, mod, GTK_ACCEL_VISIBLE, closure);
420                 }
421                 return FALSE;
422         }
423
424         /* All good, g_free() the old accelerator, g_strdup() the new one */
425         g_free (*accel_to_update);
426         *accel_to_update = g_strdup(accel);
427
428         /* Add the new accelerator */
429         gtk_accel_group_connect (self->accel_group, key, mod, GTK_ACCEL_VISIBLE, closure);
430
431         return TRUE;
432 }
433
434 static gboolean
435 tilda_window_accel_quit_cb (TildaWindow *self, gpointer data)
436 {
437         debug_enter  ();
438         debug_assert (TILDA_IS_WINDOW(self));
439
440         tilda_window_close (self);
441
442         /* Do not keep propagating */
443         return TRUE;
444 }
445
446 static gboolean
447 tilda_window_accel_next_tab_cb (TildaWindow *self, gpointer data)
448 {
449         debug_enter  ();
450         debug_assert (TILDA_IS_WINDOW(self));
451
452         gint num_pages;
453         gint current_page;
454
455         num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook));
456         current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(self->notebook));
457
458         /* Go to next page (with wrapping) */
459         if (num_pages != (current_page + num_pages))
460                 gtk_notebook_next_page (GTK_NOTEBOOK(self->notebook));
461         else
462                 gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), num_pages-1);
463
464         /* Do not keep propagating */
465         return TRUE;
466 }
467
468 static gboolean
469 tilda_window_accel_prev_tab_cb (TildaWindow *self, gpointer data)
470 {
471         debug_enter  ();
472         debug_assert (TILDA_IS_WINDOW(self));
473
474         gint num_pages;
475         gint current_page;
476
477         num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook));
478         current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(self->notebook));
479
480         if ((num_pages-1) != current_page)
481                 gtk_notebook_prev_page (GTK_NOTEBOOK(self->notebook));
482         else
483                 gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), 0);
484
485         /* Do not keep propagating */
486         return TRUE;
487 }
488
489 static gboolean
490 tilda_window_accel_add_term_cb (TildaWindow *self, gpointer data)
491 {
492         debug_enter  ();
493         debug_assert (TILDA_IS_WINDOW(self));
494
495         tilda_window_add_terminal (self);
496
497         /* Do not keep propagating */
498         return TRUE;
499 }
500
501 static gboolean
502 tilda_window_accel_remove_term_cb (TildaWindow *self, gpointer data)
503 {
504         debug_enter  ();
505         debug_assert (TILDA_IS_WINDOW(self));
506
507         TildaTerminal *tt = tilda_window_find_current_terminal (self);
508
509         tilda_window_remove_terminal (self, tt->number);
510
511         /* Do not keep propagating */
512         return TRUE;
513 }
514
515 static gboolean
516 tilda_window_accel_copy_cb (TildaWindow *self, gpointer data)
517 {
518         debug_enter  ();
519         debug_assert (TILDA_IS_WINDOW(self));
520
521         TildaTerminal *tt = tilda_window_find_current_terminal (self);
522
523         vte_terminal_copy_clipboard (VTE_TERMINAL(tt->vte_term));
524
525         /* Do not keep propagating */
526         return TRUE;
527 }
528
529 static gboolean
530 tilda_window_accel_paste_cb (TildaWindow *self, gpointer data)
531 {
532         debug_enter  ();
533         debug_assert (TILDA_IS_WINDOW(self));
534
535         TildaTerminal *tt = tilda_window_find_current_terminal (self);
536
537         vte_terminal_paste_clipboard (VTE_TERMINAL(tt->vte_term));
538
539         /* Do not keep propagating */
540         return TRUE;
541 }
542
543 static gboolean
544 tilda_window_accel_goto_generic (TildaWindow *self, guint number)
545 {
546         debug_enter  ();
547         debug_assert (TILDA_IS_WINDOW(self));
548
549         if (self->terms->len > (number - 1))
550         {
551                 gint temp = self->terms->len - number;
552                 gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), temp);
553         }
554
555         /* Do not keep propagating */
556         return TRUE;
557 }
558
559 static gboolean
560 tilda_window_accel_goto_1_cb (TildaWindow *self, gpointer data)
561 {
562         debug_enter  ();
563         debug_assert (TILDA_IS_WINDOW(self));
564
565         return tilda_window_accel_goto_generic (self, 1);
566 }
567
568 static gboolean
569 tilda_window_accel_goto_2_cb (TildaWindow *self, gpointer data)
570 {
571         debug_enter  ();
572         debug_assert (TILDA_IS_WINDOW(self));
573
574         return tilda_window_accel_goto_generic (self, 2);
575 }
576
577 static gboolean
578 tilda_window_accel_goto_3_cb (TildaWindow *self, gpointer data)
579 {
580         debug_enter  ();
581         debug_assert (TILDA_IS_WINDOW(self));
582
583         return tilda_window_accel_goto_generic (self, 3);
584 }
585
586 static gboolean
587 tilda_window_accel_goto_4_cb (TildaWindow *self, gpointer data)
588 {
589         debug_enter  ();
590         debug_assert (TILDA_IS_WINDOW(self));
591
592         return tilda_window_accel_goto_generic (self, 4);
593 }
594
595 static gboolean
596 tilda_window_accel_goto_5_cb (TildaWindow *self, gpointer data)
597 {
598         debug_enter  ();
599         debug_assert (TILDA_IS_WINDOW(self));
600
601         return tilda_window_accel_goto_generic (self, 5);
602 }
603
604 static gboolean
605 tilda_window_accel_goto_6_cb (TildaWindow *self, gpointer data)
606 {
607         debug_enter  ();
608         debug_assert (TILDA_IS_WINDOW(self));
609
610         return tilda_window_accel_goto_generic (self, 6);
611 }
612
613 static gboolean
614 tilda_window_accel_goto_7_cb (TildaWindow *self, gpointer data)
615 {
616         debug_enter  ();
617         debug_assert (TILDA_IS_WINDOW(self));
618
619         return tilda_window_accel_goto_generic (self, 7);
620 }
621
622 static gboolean
623 tilda_window_accel_goto_8_cb (TildaWindow *self, gpointer data)
624 {
625         debug_enter  ();
626         debug_assert (TILDA_IS_WINDOW(self));
627
628         return tilda_window_accel_goto_generic (self, 8);
629 }
630
631 static gboolean
632 tilda_window_accel_goto_9_cb (TildaWindow *self, gpointer data)
633 {
634         debug_enter  ();
635         debug_assert (TILDA_IS_WINDOW(self));
636
637         return tilda_window_accel_goto_generic (self, 9);
638 }
639
640 static gboolean
641 tilda_window_accel_goto_10_cb (TildaWindow *self, gpointer data)
642 {
643         debug_enter  ();
644         debug_assert (TILDA_IS_WINDOW(self));
645
646         return tilda_window_accel_goto_generic (self, 10);
647 }
648
649 /*******************************************************************************
650  * ALL GOBJECT STUFF BELOW PLEASE
651  ******************************************************************************/
652
653 static GObjectClass *parent_class = NULL;
654
655 enum tilda_window_properties {
656         TILDA_WINDOW_NUMBER = 1,
657         TILDA_WINDOW_CONTROLLER,
658
659         TILDA_WINDOW_ACCEL_QUIT,
660         TILDA_WINDOW_ACCEL_NEXT_TAB,
661         TILDA_WINDOW_ACCEL_PREV_TAB,
662         TILDA_WINDOW_ACCEL_ADD_TERM,
663         TILDA_WINDOW_ACCEL_REMOVE_TERM,
664         TILDA_WINDOW_ACCEL_COPY,
665         TILDA_WINDOW_ACCEL_PASTE,
666         TILDA_WINDOW_ACCEL_GOTO_1,
667         TILDA_WINDOW_ACCEL_GOTO_2,
668         TILDA_WINDOW_ACCEL_GOTO_3,
669         TILDA_WINDOW_ACCEL_GOTO_4,
670         TILDA_WINDOW_ACCEL_GOTO_5,
671         TILDA_WINDOW_ACCEL_GOTO_6,
672         TILDA_WINDOW_ACCEL_GOTO_7,
673         TILDA_WINDOW_ACCEL_GOTO_8,
674         TILDA_WINDOW_ACCEL_GOTO_9,
675         TILDA_WINDOW_ACCEL_GOTO_10,
676
677         TILDA_WINDOW_KEY,
678
679         TILDA_WINDOW_HEIGHT,
680         TILDA_WINDOW_WIDTH,
681         TILDA_WINDOW_X_POSITION,
682         TILDA_WINDOW_Y_POSITION,
683         TILDA_WINDOW_INITIAL_TERMINALS,
684
685         TILDA_WINDOW_TAB_POSITION,
686         TILDA_WINDOW_ANIMATION_ORIENTATION,
687         TILDA_WINDOW_ANIMATION_DELAY,
688
689         TILDA_WINDOW_KEEP_ABOVE,
690         TILDA_WINDOW_SKIP_TASKBAR_HINT,
691         TILDA_WINDOW_STICK,
692         TILDA_WINDOW_HIDDEN_AT_START,
693         TILDA_WINDOW_CENTERED_HORIZONTALLY,
694         TILDA_WINDOW_CENTERED_VERTICALLY,
695         TILDA_WINDOW_FULL_WIDTH_TABS,
696
697         TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
698 };
699
700 static void
701 tilda_window_instance_init (GTypeInstance *instance,
702                                                         gpointer       g_class)
703 {
704         debug_enter ();
705
706         TildaWindow *self = (TildaWindow *) instance;
707         self->dispose_has_run = FALSE;
708
709         /* Initialize all properties */
710         self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
711         self->notebook = gtk_notebook_new ();
712         self->terms = g_ptr_array_new ();
713
714         /* Accelerators */
715         self->accel_group = gtk_accel_group_new ();
716         gtk_window_add_accel_group (GTK_WINDOW(self->window), self->accel_group);
717
718         /* Somewhat of a "poison" value, incase we don't set this */
719         self->number = 0xdeadbeef;
720         self->controller = NULL;
721
722         self->state = WINDOW_UP;
723 }
724
725 static void
726 tilda_window_set_property (GObject      *object,
727                                                    guint         property_id,
728                                                    const GValue *value,
729                                                    GParamSpec   *pspec)
730 {
731         TildaWindow *self = (TildaWindow *) object;
732         gint i;
733
734         switch (property_id) {
735
736                 case TILDA_WINDOW_NUMBER:
737                         self->number = g_value_get_int (value);
738                         debug_printf ("window number: %d\n", self->number);
739                         break;
740
741                 case TILDA_WINDOW_CONTROLLER:
742                         self->controller = g_value_get_pointer (value);
743                         debug_printf ("window controller: 0x%x\n", self->controller);
744                         break;
745
746                 case TILDA_WINDOW_ACCEL_QUIT:
747                         tilda_window_update_accelerator (self,
748                                                                                          &self->accel_quit,
749                                                                                          g_value_get_string (value),
750                                                                                          tilda_window_accel_quit_cb);
751                         debug_printf ("window accel quit: %s\n", self->accel_quit);
752                         break;
753
754                 case TILDA_WINDOW_ACCEL_NEXT_TAB:
755                         tilda_window_update_accelerator (self,
756                                                                                          &self->accel_next_tab,
757                                                                                          g_value_get_string (value),
758                                                                                          tilda_window_accel_next_tab_cb);
759                         debug_printf ("window accel next tab: %s\n", self->accel_next_tab);
760                         break;
761
762                 case TILDA_WINDOW_ACCEL_PREV_TAB:
763                         tilda_window_update_accelerator (self,
764                                                                                          &self->accel_prev_tab,
765                                                                                          g_value_get_string (value),
766                                                                                          tilda_window_accel_prev_tab_cb);
767                         debug_printf ("window accel prev tab: %s\n", self->accel_prev_tab);
768                         break;
769
770                 case TILDA_WINDOW_ACCEL_ADD_TERM:
771                         tilda_window_update_accelerator (self,
772                                                                                          &self->accel_add_term,
773                                                                                          g_value_get_string (value),
774                                                                                          tilda_window_accel_add_term_cb);
775                         debug_printf ("window accel add term: %s\n", self->accel_add_term);
776                         break;
777
778                 case TILDA_WINDOW_ACCEL_REMOVE_TERM:
779                         tilda_window_update_accelerator (self,
780                                                                                          &self->accel_remove_term,
781                                                                                          g_value_get_string (value),
782                                                                                          tilda_window_accel_remove_term_cb);
783                         debug_printf ("window accel remove term: %s\n", self->accel_remove_term);
784                         break;
785
786                 case TILDA_WINDOW_ACCEL_COPY:
787                         tilda_window_update_accelerator (self,
788                                                                                          &self->accel_copy,
789                                                                                          g_value_get_string (value),
790                                                                                          tilda_window_accel_copy_cb);
791                         debug_printf ("window accel copy: %s\n", self->accel_copy);
792                         break;
793
794                 case TILDA_WINDOW_ACCEL_PASTE:
795                         tilda_window_update_accelerator (self,
796                                                                                          &self->accel_paste,
797                                                                                          g_value_get_string (value),
798                                                                                          tilda_window_accel_paste_cb);
799                         debug_printf ("window accel paste: %s\n", self->accel_paste);
800                         break;
801
802                 case TILDA_WINDOW_ACCEL_GOTO_1:
803                         tilda_window_update_accelerator (self,
804                                                                                          &self->accel_goto_1,
805                                                                                          g_value_get_string (value),
806                                                                                          tilda_window_accel_goto_1_cb);
807                         debug_printf ("window accel goto 1: %s\n", self->accel_goto_1);
808                         break;
809
810                 case TILDA_WINDOW_ACCEL_GOTO_2:
811                         tilda_window_update_accelerator (self,
812                                                                                          &self->accel_goto_2,
813                                                                                          g_value_get_string (value),
814                                                                                          tilda_window_accel_goto_2_cb);
815                         debug_printf ("window accel goto 2: %s\n", self->accel_goto_2);
816                         break;
817
818                 case TILDA_WINDOW_ACCEL_GOTO_3:
819                         tilda_window_update_accelerator (self,
820                                                                                          &self->accel_goto_3,
821                                                                                          g_value_get_string (value),
822                                                                                          tilda_window_accel_goto_3_cb);
823                         debug_printf ("window accel goto 3: %s\n", self->accel_goto_3);
824                         break;
825
826                 case TILDA_WINDOW_ACCEL_GOTO_4:
827                         tilda_window_update_accelerator (self,
828                                                                                          &self->accel_goto_4,
829                                                                                          g_value_get_string (value),
830                                                                                          tilda_window_accel_goto_4_cb);
831                         debug_printf ("window accel goto 4: %s\n", self->accel_goto_4);
832                         break;
833
834                 case TILDA_WINDOW_ACCEL_GOTO_5:
835                         tilda_window_update_accelerator (self,
836                                                                                          &self->accel_goto_5,
837                                                                                          g_value_get_string (value),
838                                                                                          tilda_window_accel_goto_5_cb);
839                         debug_printf ("window accel goto 5: %s\n", self->accel_goto_5);
840                         break;
841
842                 case TILDA_WINDOW_ACCEL_GOTO_6:
843                         tilda_window_update_accelerator (self,
844                                                                                          &self->accel_goto_6,
845                                                                                          g_value_get_string (value),
846                                                                                          tilda_window_accel_goto_6_cb);
847                         debug_printf ("window accel goto 6: %s\n", self->accel_goto_6);
848                         break;
849
850                 case TILDA_WINDOW_ACCEL_GOTO_7:
851                         tilda_window_update_accelerator (self,
852                                                                                          &self->accel_goto_7,
853                                                                                          g_value_get_string (value),
854                                                                                          tilda_window_accel_goto_7_cb);
855                         debug_printf ("window accel goto 7: %s\n", self->accel_goto_7);
856                         break;
857
858                 case TILDA_WINDOW_ACCEL_GOTO_8:
859                         tilda_window_update_accelerator (self,
860                                                                                          &self->accel_goto_8,
861                                                                                          g_value_get_string (value),
862                                                                                          tilda_window_accel_goto_8_cb);
863                         debug_printf ("window accel goto 8: %s\n", self->accel_goto_8);
864                         break;
865
866                 case TILDA_WINDOW_ACCEL_GOTO_9:
867                         tilda_window_update_accelerator (self,
868                                                                                          &self->accel_goto_9,
869                                                                                          g_value_get_string (value),
870                                                                                          tilda_window_accel_goto_9_cb);
871                         debug_printf ("window accel goto 9: %s\n", self->accel_goto_9);
872                         break;
873
874                 case TILDA_WINDOW_ACCEL_GOTO_10:
875                         tilda_window_update_accelerator (self,
876                                                                                          &self->accel_goto_10,
877                                                                                          g_value_get_string (value),
878                                                                                          tilda_window_accel_goto_10_cb);
879                         debug_printf ("window accel goto 10: %s\n", self->accel_goto_10);
880                         break;
881
882                 case TILDA_WINDOW_KEY:
883                         tilda_window_try_to_bind_key (self, g_value_get_string (value));
884                         debug_printf ("window key %s\n", self->key);
885                         break;
886
887                 case TILDA_WINDOW_HEIGHT:
888                         self->height = g_value_get_int (value);
889                         gtk_widget_set_size_request (self->window, self->width, self->height);
890                         gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
891                         debug_printf ("window height: %d\n", self->height);
892                         break;
893
894                 case TILDA_WINDOW_WIDTH:
895                         self->width = g_value_get_int (value);
896                         gtk_widget_set_size_request (self->window, self->width, self->height);
897                         gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
898                         debug_printf ("window width: %d\n", self->width);
899                         break;
900
901                 case TILDA_WINDOW_X_POSITION:
902                         self->x_position = g_value_get_int (value);
903                         gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
904                         debug_printf ("window x position: %d\n", self->x_position);
905                         break;
906
907                 case TILDA_WINDOW_Y_POSITION:
908                         self->y_position = g_value_get_int (value);
909                         gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
910                         debug_printf ("window y position: %d\n", self->y_position);
911                         break;
912
913                 case TILDA_WINDOW_INITIAL_TERMINALS:
914                         self->initial_terminals = g_value_get_int (value);
915                         debug_printf ("window initial terminals: %d\n", self->initial_terminals);
916                         break;
917
918                 case TILDA_WINDOW_TAB_POSITION:
919                         self->tab_position = g_value_get_enum (value);
920                         gtk_notebook_set_tab_pos (GTK_NOTEBOOK(self->notebook), self->tab_position);
921                         debug_printf ("window tab position: %d\n", self->tab_position);
922                         break;
923
924                 case TILDA_WINDOW_ANIMATION_ORIENTATION:
925                         self->animation_orientation = g_value_get_enum (value);
926                         debug_printf ("window animation orientation: %d\n", self->animation_orientation);
927                         break;
928
929                 case TILDA_WINDOW_ANIMATION_DELAY:
930                         self->animation_delay = g_value_get_int (value);
931                         debug_printf ("window animation delay: %d\n", self->animation_delay);
932                         break;
933
934                 case TILDA_WINDOW_KEEP_ABOVE:
935                         self->keep_above = g_value_get_boolean (value);
936                         gtk_window_set_keep_above (GTK_WINDOW(self->window), self->keep_above);
937                         debug_printf ("window keep above: %d\n", self->keep_above);
938                         break;
939
940                 case TILDA_WINDOW_SKIP_TASKBAR_HINT:
941                         self->skip_taskbar_hint = g_value_get_boolean (value);
942                         gtk_window_set_skip_taskbar_hint (GTK_WINDOW(self->window), self->skip_taskbar_hint);
943                         debug_printf ("window skip taskbar hint: %d\n", self->skip_taskbar_hint);
944                         break;
945
946                 case TILDA_WINDOW_STICK:
947                         self->stick = g_value_get_boolean (value);
948
949                         /* This is moderately ugly, but GTK+ does it this way... */
950                         self->stick ? gtk_window_stick (GTK_WINDOW(self->window))
951                                                 : gtk_window_unstick (GTK_WINDOW(self->window));
952                         debug_printf ("window stick: %d\n", self->stick);
953                         break;
954
955                 case TILDA_WINDOW_HIDDEN_AT_START:
956                         self->hidden_at_start = g_value_get_boolean (value);
957                         debug_printf ("window hidden at start: %d\n", self->hidden_at_start);
958                         break;
959
960                 case TILDA_WINDOW_CENTERED_HORIZONTALLY:
961                         self->centered_horizontally = g_value_get_boolean (value);
962                         if (self->centered_horizontally)
963                                 tilda_window_center_horizontally (self);
964                         debug_printf ("window centered horizontally: %d\n", self->centered_horizontally);
965                         break;
966
967                 case TILDA_WINDOW_CENTERED_VERTICALLY:
968                         self->centered_vertically = g_value_get_boolean (value);
969                         if (self->centered_vertically)
970                                 tilda_window_center_vertically (self);
971                         debug_printf ("window centered vertically: %d\n", self->centered_vertically);
972                         break;
973
974                 case TILDA_WINDOW_FULL_WIDTH_TABS:
975                         self->full_width_tabs = g_value_get_boolean (value);
976                         for (i=0; i<self->terms->len; ++i)
977                                 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(self->notebook),
978                                                                                                         TILDA_TERMINAL(g_ptr_array_index(self->terms, i))->hbox,
979                                                                                                         self->full_width_tabs,
980                                                                                                         TRUE,
981                                                                                                         GTK_PACK_START);
982                         debug_printf ("window full width tabs: %d\n", self->full_width_tabs);
983                         break;
984
985                 case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
986                         self->have_real_transparency = g_value_get_boolean (value);
987                         debug_printf ("window have real transp: %d\n", self->have_real_transparency);
988                         break;
989
990                 default:
991                         /* We don't have this property */
992                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
993                         break;
994         }
995 }
996
997 static void
998 tilda_window_get_property (GObject    *object,
999                                                    guint       property_id,
1000                                                    GValue     *value,
1001                                                    GParamSpec *pspec)
1002 {
1003         TildaWindow *self = (TildaWindow *) object;
1004
1005         switch (property_id) {
1006
1007                 case TILDA_WINDOW_NUMBER:
1008                         g_value_set_int (value, self->number);
1009                         break;
1010
1011                 case TILDA_WINDOW_CONTROLLER:
1012                         g_value_set_pointer (value, self->controller);
1013                         break;
1014
1015                 case TILDA_WINDOW_ACCEL_QUIT:
1016                         g_value_set_string (value, self->accel_quit);
1017                         break;
1018
1019                 case TILDA_WINDOW_ACCEL_NEXT_TAB:
1020                         g_value_set_string (value, self->accel_next_tab);
1021                         break;
1022
1023                 case TILDA_WINDOW_ACCEL_PREV_TAB:
1024                         g_value_set_string (value, self->accel_prev_tab);
1025                         break;
1026
1027                 case TILDA_WINDOW_ACCEL_ADD_TERM:
1028                         g_value_set_string (value, self->accel_prev_tab);
1029                         break;
1030
1031                 case TILDA_WINDOW_ACCEL_REMOVE_TERM:
1032                         g_value_set_string (value, self->accel_remove_term);
1033                         break;
1034
1035                 case TILDA_WINDOW_ACCEL_COPY:
1036                         g_value_set_string (value, self->accel_copy);
1037                         break;
1038
1039                 case TILDA_WINDOW_ACCEL_PASTE:
1040                         g_value_set_string (value, self->accel_paste);
1041                         break;
1042
1043                 case TILDA_WINDOW_ACCEL_GOTO_1:
1044                         g_value_set_string (value, self->accel_goto_1);
1045                         break;
1046
1047                 case TILDA_WINDOW_ACCEL_GOTO_2:
1048                         g_value_set_string (value, self->accel_goto_2);
1049                         break;
1050
1051                 case TILDA_WINDOW_ACCEL_GOTO_3:
1052                         g_value_set_string (value, self->accel_goto_3);
1053                         break;
1054
1055                 case TILDA_WINDOW_ACCEL_GOTO_4:
1056                         g_value_set_string (value, self->accel_goto_4);
1057                         break;
1058
1059                 case TILDA_WINDOW_ACCEL_GOTO_5:
1060                         g_value_set_string (value, self->accel_goto_5);
1061                         break;
1062
1063                 case TILDA_WINDOW_ACCEL_GOTO_6:
1064                         g_value_set_string (value, self->accel_goto_6);
1065                         break;
1066
1067                 case TILDA_WINDOW_ACCEL_GOTO_7:
1068                         g_value_set_string (value, self->accel_goto_7);
1069                         break;
1070
1071                 case TILDA_WINDOW_ACCEL_GOTO_8:
1072                         g_value_set_string (value, self->accel_goto_8);
1073                         break;
1074
1075                 case TILDA_WINDOW_ACCEL_GOTO_9:
1076                         g_value_set_string (value, self->accel_goto_9);
1077                         break;
1078
1079                 case TILDA_WINDOW_ACCEL_GOTO_10:
1080                         g_value_set_string (value, self->accel_goto_10);
1081                         break;
1082
1083                 case TILDA_WINDOW_KEY:
1084                         g_value_set_string (value, self->key);
1085                         break;
1086
1087                 case TILDA_WINDOW_HEIGHT:
1088                         g_value_set_int (value, self->height);
1089                         break;
1090
1091                 case TILDA_WINDOW_WIDTH:
1092                         g_value_set_int (value, self->width);
1093                         break;
1094
1095                 case TILDA_WINDOW_X_POSITION:
1096                         g_value_set_int (value, self->x_position);
1097                         break;
1098
1099                 case TILDA_WINDOW_Y_POSITION:
1100                         g_value_set_int (value, self->y_position);
1101                         break;
1102
1103                 case TILDA_WINDOW_INITIAL_TERMINALS:
1104                         g_value_set_int (value, self->initial_terminals);
1105                         break;
1106
1107                 case TILDA_WINDOW_TAB_POSITION:
1108                         g_value_set_enum (value, self->tab_position);
1109                         break;
1110
1111                 case TILDA_WINDOW_ANIMATION_ORIENTATION:
1112                         g_value_set_enum (value, self->animation_orientation);
1113                         break;
1114
1115                 case TILDA_WINDOW_ANIMATION_DELAY:
1116                         g_value_set_int (value, self->animation_delay);
1117                         break;
1118
1119                 case TILDA_WINDOW_KEEP_ABOVE:
1120                         g_value_set_boolean (value, self->keep_above);
1121                         break;
1122
1123                 case TILDA_WINDOW_SKIP_TASKBAR_HINT:
1124                         g_value_set_boolean (value, self->skip_taskbar_hint);
1125                         break;
1126
1127                 case TILDA_WINDOW_STICK:
1128                         g_value_set_boolean (value, self->stick);
1129                         break;
1130
1131                 case TILDA_WINDOW_HIDDEN_AT_START:
1132                         g_value_set_boolean (value, self->hidden_at_start);
1133                         break;
1134
1135                 case TILDA_WINDOW_CENTERED_HORIZONTALLY:
1136                         g_value_set_boolean (value, self->centered_horizontally);
1137                         break;
1138
1139                 case TILDA_WINDOW_CENTERED_VERTICALLY:
1140                         g_value_set_boolean (value, self->centered_vertically);
1141                         break;
1142
1143                 case TILDA_WINDOW_FULL_WIDTH_TABS:
1144                         g_value_set_boolean (value, self->full_width_tabs);
1145                         break;
1146
1147                 case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
1148                         g_value_set_boolean (value, self->have_real_transparency);
1149                         break;
1150
1151                 default:
1152                         /* We don't have this property */
1153                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1154                         break;
1155         }
1156 }
1157
1158 static GObject *
1159 tilda_window_constructor (GType                  type,
1160                                                   guint                  n_construct_properties,
1161                                                   GObjectConstructParam *construct_properties)
1162 {
1163         debug_enter ();
1164
1165         GObject *obj;
1166         TildaWindow *self;
1167         gint i;
1168
1169         /* Invoke parent constructor */
1170         TildaWindowClass *klass;
1171         klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
1172         obj = parent_class->constructor (type,
1173                                                                          n_construct_properties,
1174                                                                          construct_properties);
1175
1176         /* Do other stuff here. The object is ready to go now, and all
1177          * ctor properties have been set.
1178          */
1179         self = TILDA_WINDOW(obj);
1180
1181         /* Try to set up real transparency */
1182         tilda_window_setup_real_transparency (self);
1183
1184         gtk_container_add (GTK_CONTAINER(self->window), self->notebook);
1185         g_object_set (G_OBJECT(self->notebook), "can-focus", FALSE, NULL);
1186         gtk_widget_show (self->notebook);
1187
1188         /* Tilda is never decorated */
1189         gtk_window_set_decorated (GTK_WINDOW(self->window), FALSE);
1190
1191         /* Set all of the properties out of the config file */
1192         tilda_window_set_property_from_config (self, "key");
1193
1194         // FIXME: hack -- start the wizard in this case :)
1195         if (!self->key)
1196         {
1197                 gchar *key = g_strdup_printf ("F%d", self->number+3);
1198                 g_object_set (G_OBJECT(self), "key", key, NULL);
1199                 g_free (key);
1200
1201                 g_critical ("HACK: start the wizard here\n");
1202         }
1203
1204         tilda_window_set_property_from_config (self, "accelerator-quit");
1205         tilda_window_set_property_from_config (self, "accelerator-next-tab");
1206         tilda_window_set_property_from_config (self, "accelerator-previous-tab");
1207         tilda_window_set_property_from_config (self, "accelerator-add-terminal");
1208         tilda_window_set_property_from_config (self, "accelerator-remove-terminal");
1209         tilda_window_set_property_from_config (self, "accelerator-copy");
1210         tilda_window_set_property_from_config (self, "accelerator-paste");
1211         tilda_window_set_property_from_config (self, "accelerator-goto-1");
1212         tilda_window_set_property_from_config (self, "accelerator-goto-2");
1213         tilda_window_set_property_from_config (self, "accelerator-goto-3");
1214         tilda_window_set_property_from_config (self, "accelerator-goto-4");
1215         tilda_window_set_property_from_config (self, "accelerator-goto-5");
1216         tilda_window_set_property_from_config (self, "accelerator-goto-6");
1217         tilda_window_set_property_from_config (self, "accelerator-goto-7");
1218         tilda_window_set_property_from_config (self, "accelerator-goto-8");
1219         tilda_window_set_property_from_config (self, "accelerator-goto-9");
1220         tilda_window_set_property_from_config (self, "accelerator-goto-10");
1221
1222         tilda_window_set_property_from_config (self, "height");
1223         tilda_window_set_property_from_config (self, "width");
1224         tilda_window_set_property_from_config (self, "x-position");
1225         tilda_window_set_property_from_config (self, "y-position");
1226         tilda_window_set_property_from_config (self, "initial-terminals");
1227         tilda_window_set_property_from_config (self, "animation-delay");
1228
1229         tilda_window_set_property_from_config (self, "tab-position");
1230         tilda_window_set_property_from_config (self, "animation-orientation");
1231
1232         tilda_window_set_property_from_config (self, "keep-above");
1233         tilda_window_set_property_from_config (self, "skip-taskbar-hint");
1234         tilda_window_set_property_from_config (self, "stick");
1235         tilda_window_set_property_from_config (self, "hidden-at-start");
1236         tilda_window_set_property_from_config (self, "centered-horizontally");
1237         tilda_window_set_property_from_config (self, "centered-vertically");
1238         tilda_window_set_property_from_config (self, "full-width-tabs");
1239
1240         /* Add the initial terminal(s) */
1241         for (i=0; i<self->initial_terminals; ++i)
1242                 tilda_window_add_terminal (self);
1243
1244         /* Show us if we're ready. If not, just remain hidden. All sub-widgets must
1245          * be gtk_widget_show()n by this point. */
1246         if (!self->hidden_at_start)
1247         {
1248                 gtk_widget_show (self->window);
1249                 self->state = WINDOW_DOWN;
1250         }
1251         else
1252                 self->state = WINDOW_UP;
1253
1254         /* Register this object with DBus */
1255         tilda_window_dbus_register_object (self);
1256
1257         return obj;
1258 }
1259
1260 static void
1261 tilda_window_dispose (GObject *obj)
1262 {
1263         debug_enter ();
1264
1265         TildaWindow *self = (TildaWindow *) obj;
1266
1267         /* We don't want to run dispose twice, so just return immediately */
1268         if (self->dispose_has_run)
1269                 return;
1270
1271         /*
1272          * In dispose, you are supposed to free all types referenced from this
1273          * object which might themselves hold a reference to self. Generally,
1274          * the most simple solution is to unref all members on which you own a
1275          * reference.
1276          *
1277          * NOTE: See the following for how to deal with GtkObject-derived things:
1278          * http://library.gnome.org/devel/gtk/unstable/GtkObject.html
1279          */
1280         g_object_unref (G_OBJECT(self->accel_group));
1281         g_ptr_array_foreach (self->terms, g_object_unref, NULL);
1282         gtk_widget_destroy (self->window);
1283
1284         /* Unbind if we were set */
1285         if (self->key)
1286                 tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb);
1287
1288         /* Chain up to the parent class */
1289         G_OBJECT_CLASS (parent_class)->dispose (obj);
1290 }
1291
1292 static void
1293 tilda_window_finalize (GObject *obj)
1294 {
1295         debug_enter ();
1296
1297         TildaWindow *self = (TildaWindow *) obj;
1298
1299         /*
1300          * Here, complete the object's destruction.
1301          * You might not need to do much...
1302          */
1303         // TODO: g_free() any primitives here
1304         g_ptr_array_free (self->terms, TRUE);
1305
1306
1307         /* Chain up to the parent class */
1308         G_OBJECT_CLASS (parent_class)->finalize (obj);
1309 }
1310
1311 static void
1312 tilda_window_class_init (gpointer g_class,
1313                                                  gpointer g_class_data)
1314 {
1315         debug_enter ();
1316
1317         GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
1318         TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
1319         GParamSpec *pspec;
1320
1321         /* Hook our functions to this type */
1322         gobject_class->set_property = tilda_window_set_property;
1323         gobject_class->get_property = tilda_window_get_property;
1324         gobject_class->dispose = tilda_window_dispose;
1325         gobject_class->finalize = tilda_window_finalize;
1326         gobject_class->constructor = tilda_window_constructor;
1327
1328         parent_class = g_type_class_peek_parent (klass);
1329
1330         /* Install all of the properties */
1331         pspec = g_param_spec_int ("number",
1332                                                           _("Window number"),
1333                                                           NULL,
1334                                                           0,            // min value
1335                                                           INT_MAX,      // max value
1336                                                           0,            // def value
1337                                                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
1338
1339         g_object_class_install_property (gobject_class,
1340                                                                          TILDA_WINDOW_NUMBER,
1341                                                                          pspec);
1342
1343         pspec = g_param_spec_pointer ("controller",
1344                                                                   _("Pointer to window's controlling TildaController"),
1345                                                                   NULL,
1346                                                                   G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
1347
1348         g_object_class_install_property (gobject_class,
1349                                                                          TILDA_WINDOW_CONTROLLER,
1350                                                                          pspec);
1351
1352         pspec = g_param_spec_string ("accelerator-quit",
1353                                                                  _("Accelerator to quit this window"),
1354                                                                  NULL,
1355                                                                  NULL,
1356                                                                  G_PARAM_READWRITE);
1357
1358         g_object_class_install_property (gobject_class,
1359                                                                          TILDA_WINDOW_ACCEL_QUIT,
1360                                                                          pspec);
1361
1362         pspec = g_param_spec_string ("accelerator-next-tab",
1363                                                                  _("Accelerator to go to the next tab"),
1364                                                                  NULL,
1365                                                                  NULL,
1366                                                                  G_PARAM_READWRITE);
1367
1368         g_object_class_install_property (gobject_class,
1369                                                                          TILDA_WINDOW_ACCEL_NEXT_TAB,
1370                                                                          pspec);
1371
1372         pspec = g_param_spec_string ("accelerator-previous-tab",
1373                                                                  _("Accelerator to go to the previous tab"),
1374                                                                  NULL,
1375                                                                  NULL,
1376                                                                  G_PARAM_READWRITE);
1377
1378         g_object_class_install_property (gobject_class,
1379                                                                          TILDA_WINDOW_ACCEL_PREV_TAB,
1380                                                                          pspec);
1381
1382         pspec = g_param_spec_string ("accelerator-add-terminal",
1383                                                                  _("Accelerator to add a terminal"),
1384                                                                  NULL,
1385                                                                  NULL,
1386                                                                  G_PARAM_READWRITE);
1387
1388         g_object_class_install_property (gobject_class,
1389                                                                          TILDA_WINDOW_ACCEL_ADD_TERM,
1390                                                                          pspec);
1391
1392         pspec = g_param_spec_string ("accelerator-remove-terminal",
1393                                                                  _("Accelerator to remove a terminal"),
1394                                                                  NULL,
1395                                                                  NULL,
1396                                                                  G_PARAM_READWRITE);
1397
1398         g_object_class_install_property (gobject_class,
1399                                                                          TILDA_WINDOW_ACCEL_REMOVE_TERM,
1400                                                                          pspec);
1401
1402         pspec = g_param_spec_string ("accelerator-copy",
1403                                                                  _("Accelerator to copy to the clipboard"),
1404                                                                  NULL,
1405                                                                  NULL,
1406                                                                  G_PARAM_READWRITE);
1407
1408         g_object_class_install_property (gobject_class,
1409                                                                          TILDA_WINDOW_ACCEL_COPY,
1410                                                                          pspec);
1411
1412         pspec = g_param_spec_string ("accelerator-paste",
1413                                                                  _("Accelerator to paste from the clipboard"),
1414                                                                  NULL,
1415                                                                  NULL,
1416                                                                  G_PARAM_READWRITE);
1417
1418         g_object_class_install_property (gobject_class,
1419                                                                          TILDA_WINDOW_ACCEL_PASTE,
1420                                                                          pspec);
1421
1422         pspec = g_param_spec_string ("accelerator-goto-1",
1423                                                                  _("Accelerator to go to tab 1"),
1424                                                                  NULL,
1425                                                                  NULL,
1426                                                                  G_PARAM_READWRITE);
1427
1428         g_object_class_install_property (gobject_class,
1429                                                                          TILDA_WINDOW_ACCEL_GOTO_1,
1430                                                                          pspec);
1431
1432         pspec = g_param_spec_string ("accelerator-goto-2",
1433                                                                  _("Accelerator to go to tab 2"),
1434                                                                  NULL,
1435                                                                  NULL,
1436                                                                  G_PARAM_READWRITE);
1437
1438         g_object_class_install_property (gobject_class,
1439                                                                          TILDA_WINDOW_ACCEL_GOTO_2,
1440                                                                          pspec);
1441
1442         pspec = g_param_spec_string ("accelerator-goto-3",
1443                                                                  _("Accelerator to go to tab 3"),
1444                                                                  NULL,
1445                                                                  NULL,
1446                                                                  G_PARAM_READWRITE);
1447
1448         g_object_class_install_property (gobject_class,
1449                                                                          TILDA_WINDOW_ACCEL_GOTO_3,
1450                                                                          pspec);
1451
1452         pspec = g_param_spec_string ("accelerator-goto-4",
1453                                                                  _("Accelerator to go to tab 4"),
1454                                                                  NULL,
1455                                                                  NULL,
1456                                                                  G_PARAM_READWRITE);
1457
1458         g_object_class_install_property (gobject_class,
1459                                                                          TILDA_WINDOW_ACCEL_GOTO_4,
1460                                                                          pspec);
1461
1462         pspec = g_param_spec_string ("accelerator-goto-5",
1463                                                                  _("Accelerator to go to tab 5"),
1464                                                                  NULL,
1465                                                                  NULL,
1466                                                                  G_PARAM_READWRITE);
1467
1468         g_object_class_install_property (gobject_class,
1469                                                                          TILDA_WINDOW_ACCEL_GOTO_5,
1470                                                                          pspec);
1471
1472         pspec = g_param_spec_string ("accelerator-goto-6",
1473                                                                  _("Accelerator to go to tab 6"),
1474                                                                  NULL,
1475                                                                  NULL,
1476                                                                  G_PARAM_READWRITE);
1477
1478         g_object_class_install_property (gobject_class,
1479                                                                          TILDA_WINDOW_ACCEL_GOTO_6,
1480                                                                          pspec);
1481
1482         pspec = g_param_spec_string ("accelerator-goto-7",
1483                                                                  _("Accelerator to go to tab 7"),
1484                                                                  NULL,
1485                                                                  NULL,
1486                                                                  G_PARAM_READWRITE);
1487
1488         g_object_class_install_property (gobject_class,
1489                                                                          TILDA_WINDOW_ACCEL_GOTO_7,
1490                                                                          pspec);
1491
1492         pspec = g_param_spec_string ("accelerator-goto-8",
1493                                                                  _("Accelerator to go to tab 8"),
1494                                                                  NULL,
1495                                                                  NULL,
1496                                                                  G_PARAM_READWRITE);
1497
1498         g_object_class_install_property (gobject_class,
1499                                                                          TILDA_WINDOW_ACCEL_GOTO_8,
1500                                                                          pspec);
1501
1502         pspec = g_param_spec_string ("accelerator-goto-9",
1503                                                                  _("Accelerator to go to tab 9"),
1504                                                                  NULL,
1505                                                                  NULL,
1506                                                                  G_PARAM_READWRITE);
1507
1508         g_object_class_install_property (gobject_class,
1509                                                                          TILDA_WINDOW_ACCEL_GOTO_9,
1510                                                                          pspec);
1511
1512         pspec = g_param_spec_string ("accelerator-goto-10",
1513                                                                  _("Accelerator to go to tab 10"),
1514                                                                  NULL,
1515                                                                  NULL,
1516                                                                  G_PARAM_READWRITE);
1517
1518         g_object_class_install_property (gobject_class,
1519                                                                          TILDA_WINDOW_ACCEL_GOTO_10,
1520                                                                          pspec);
1521
1522         pspec = g_param_spec_string ("key",
1523                                                                  _("Window's drop-down keybinding"),
1524                                                                  NULL,
1525                                                                  NULL,
1526                                                                  G_PARAM_READWRITE);
1527
1528         g_object_class_install_property (gobject_class,
1529                                                                          TILDA_WINDOW_KEY,
1530                                                                          pspec);
1531
1532         pspec = g_param_spec_int ("height",
1533                                                           _("Window's height"),
1534                                                           NULL,
1535                                                           0,
1536                                                           INT_MAX,
1537                                                           0,
1538                                                           G_PARAM_READWRITE);
1539
1540         g_object_class_install_property (gobject_class,
1541                                                                          TILDA_WINDOW_HEIGHT,
1542                                                                          pspec);
1543
1544         pspec = g_param_spec_int ("width",
1545                                                           _("Window's width"),
1546                                                           NULL,
1547                                                           0,
1548                                                           INT_MAX,
1549                                                           0,
1550                                                           G_PARAM_READWRITE);
1551
1552         g_object_class_install_property (gobject_class,
1553                                                                          TILDA_WINDOW_WIDTH,
1554                                                                          pspec);
1555
1556         pspec = g_param_spec_int ("x-position",
1557                                                           _("Window's x position"),
1558                                                           NULL,
1559                                                           0,
1560                                                           INT_MAX,
1561                                                           0,
1562                                                           G_PARAM_READWRITE);
1563
1564         g_object_class_install_property (gobject_class,
1565                                                                          TILDA_WINDOW_X_POSITION,
1566                                                                          pspec);
1567
1568         pspec = g_param_spec_int ("y-position",
1569                                                           _("Window's y position"),
1570                                                           NULL,
1571                                                           0,
1572                                                           INT_MAX,
1573                                                           0,
1574                                                           G_PARAM_READWRITE);
1575
1576         g_object_class_install_property (gobject_class,
1577                                                                          TILDA_WINDOW_Y_POSITION,
1578                                                                          pspec);
1579
1580         pspec = g_param_spec_int ("initial-terminals",
1581                                                           _("Window's inital number of terminals"),
1582                                                           NULL,
1583                                                           1,
1584                                                           INT_MAX,
1585                                                           1,
1586                                                           G_PARAM_READWRITE);
1587
1588         g_object_class_install_property (gobject_class,
1589                                                                          TILDA_WINDOW_INITIAL_TERMINALS,
1590                                                                          pspec);
1591
1592         pspec = g_param_spec_enum ("tab-position",
1593                                                            _("Position of window's tab bar"),
1594                                                            NULL,
1595                                                            gtk_position_type_get_type(),
1596                                                            GTK_POS_TOP,
1597                                                            G_PARAM_READWRITE);
1598
1599         g_object_class_install_property (gobject_class,
1600                                                                          TILDA_WINDOW_TAB_POSITION,
1601                                                                          pspec);
1602
1603         pspec = g_param_spec_enum ("animation-orientation",
1604                                                            _("Window's animation orientation"),
1605                                                            NULL,
1606                                                            gtk_position_type_get_type(),
1607                                                            GTK_POS_TOP,
1608                                                            G_PARAM_READWRITE);
1609
1610         g_object_class_install_property (gobject_class,
1611                                                                          TILDA_WINDOW_ANIMATION_ORIENTATION,
1612                                                                          pspec);
1613
1614         pspec = g_param_spec_int ("animation-delay",
1615                                                           _("Amount of time in milliseconds between animation intervals"),
1616                                                           NULL,
1617                                                           0,
1618                                                           INT_MAX,
1619                                                           0,
1620                                                           G_PARAM_READWRITE);
1621
1622         g_object_class_install_property (gobject_class,
1623                                                                          TILDA_WINDOW_ANIMATION_DELAY,
1624                                                                          pspec);
1625
1626         pspec = g_param_spec_boolean ("keep-above",
1627                                                                   _("Keep this window above all others"),
1628                                                                   NULL,
1629                                                                   FALSE,
1630                                                                   G_PARAM_READWRITE);
1631
1632         g_object_class_install_property (gobject_class,
1633                                                                          TILDA_WINDOW_KEEP_ABOVE,
1634                                                                          pspec);
1635
1636         pspec = g_param_spec_boolean ("skip-taskbar-hint",
1637                                                                   _("Hide this window in the taskbar if TRUE"),
1638                                                                   NULL,
1639                                                                   FALSE,
1640                                                                   G_PARAM_READWRITE);
1641
1642         g_object_class_install_property (gobject_class,
1643                                                                          TILDA_WINDOW_SKIP_TASKBAR_HINT,
1644                                                                          pspec);
1645
1646         pspec = g_param_spec_boolean ("stick",
1647                                                                   _("Display this window on all workspaces"),
1648                                                                   NULL,
1649                                                                   FALSE,
1650                                                                   G_PARAM_READWRITE);
1651
1652         g_object_class_install_property (gobject_class,
1653                                                                          TILDA_WINDOW_STICK,
1654                                                                          pspec);
1655
1656         pspec = g_param_spec_boolean ("hidden-at-start",
1657                                                                   _("Hide the window when it is first created"),
1658                                                                   NULL,
1659                                                                   FALSE,
1660                                                                   G_PARAM_READWRITE);
1661
1662         g_object_class_install_property (gobject_class,
1663                                                                          TILDA_WINDOW_HIDDEN_AT_START,
1664                                                                          pspec);
1665
1666         pspec = g_param_spec_boolean ("centered-horizontally",
1667                                                                   _("Center the window horizontally"),
1668                                                                   NULL,
1669                                                                   FALSE,
1670                                                                   G_PARAM_READWRITE);
1671
1672         g_object_class_install_property (gobject_class,
1673                                                                          TILDA_WINDOW_CENTERED_HORIZONTALLY,
1674                                                                          pspec);
1675
1676         pspec = g_param_spec_boolean ("centered-vertically",
1677                                                                   _("Center the window vertically"),
1678                                                                   NULL,
1679                                                                   FALSE,
1680                                                                   G_PARAM_READWRITE);
1681
1682         g_object_class_install_property (gobject_class,
1683                                                                          TILDA_WINDOW_CENTERED_VERTICALLY,
1684                                                                          pspec);
1685
1686         pspec = g_param_spec_boolean ("full-width-tabs",
1687                                                                   _("Tabs should have full width of window"),
1688                                                                   NULL,
1689                                                                   TRUE,
1690                                                                   G_PARAM_READWRITE);
1691
1692         g_object_class_install_property (gobject_class,
1693                                                                          TILDA_WINDOW_FULL_WIDTH_TABS,
1694                                                                          pspec);
1695
1696         pspec = g_param_spec_boolean ("have-real-transparency",
1697                                                                   NULL, NULL, FALSE, G_PARAM_READABLE);
1698
1699         g_object_class_install_property (gobject_class,
1700                                                                          TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
1701                                                                          pspec);
1702
1703         /* Hook the TildaWindow type into DBus */
1704         dbus_g_object_type_install_info (tilda_window_get_type(), &dbus_glib_tilda_window_object_info);
1705 }
1706
1707 GType
1708 tilda_window_get_type (void)
1709 {
1710         static GType type = 0;
1711
1712         if (type == 0)
1713         {
1714                 static const GTypeInfo info = {
1715                         sizeof (TildaWindowClass),
1716                         NULL,   /* base_init */
1717                         NULL,   /* base_finalize */
1718                         tilda_window_class_init,        /* class_init */
1719                         NULL,   /* class_finalize */
1720                         NULL,   /* class_data */
1721                         sizeof (TildaWindow),
1722                         0,              /* n_preallocs */
1723                         tilda_window_instance_init,     /* instance_init */
1724                 };
1725
1726                 type = g_type_register_static (G_TYPE_OBJECT,
1727                                                                            "TildaWindowType",
1728                                                                            &info,
1729                                                                            0);
1730         }
1731
1732         return type;
1733 }
1734
1735 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */