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