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