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