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