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