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