summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-09-11 04:54:18 +0200
committerLennart Poettering <lennart@poettering.net>2009-09-11 04:54:18 +0200
commit52de76b57ddc497f639c0dd00fdb9c578f329434 (patch)
treee0e4d1d756c8018300003484f8350f242ef5cf48
parenteb17d362304629c08d3d8fccec760fc291db270d (diff)
gtk: generate window position/size properties in ca_gtk_proplist_set_for_widget()
-rw-r--r--src/canberra-gtk.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/canberra-gtk.c b/src/canberra-gtk.c
index 0426dc7..44dc965 100644
--- a/src/canberra-gtk.c
+++ b/src/canberra-gtk.c
@@ -184,6 +184,7 @@ int ca_gtk_proplist_set_for_widget(ca_proplist *p, GtkWidget *widget) {
const char *t, *role;
GdkWindow *dw;
GdkScreen *screen;
+ gint x = 0, y = 0, width = 0, height = 0, screen_width = 0, screen_height = 0;
ca_return_val_if_fail(p, CA_ERROR_INVALID);
ca_return_val_if_fail(widget, CA_ERROR_INVALID);
@@ -233,6 +234,50 @@ int ca_gtk_proplist_set_for_widget(ca_proplist *p, GtkWidget *widget) {
return ret;
}
+ /* FIXME, this might cause a round trip */
+
+ if (dw) {
+ gdk_window_get_origin(dw, &x, &y);
+
+ if (x >= 0)
+ if ((ret = ca_proplist_setf(p, CA_PROP_WINDOW_X, "%i", x)) < 0)
+ return ret;
+ if (y >= 0)
+ if ((ret = ca_proplist_setf(p, CA_PROP_WINDOW_Y, "%i", y)) < 0)
+ return ret;
+ }
+
+ gtk_window_get_size(w, &width, &height);
+
+ if (width > 0)
+ if ((ret = ca_proplist_setf(p, CA_PROP_WINDOW_WIDTH, "%i", width)) < 0)
+ return ret;
+ if (height > 0)
+ if ((ret = ca_proplist_setf(p, CA_PROP_WINDOW_HEIGHT, "%i", height)) < 0)
+ return ret;
+
+ if (x > 0 && width > 0) {
+ x += width/2;
+
+ screen_width = gdk_screen_get_width(gtk_widget_get_screen(GTK_WIDGET(w)));
+
+ /* We use these strange format strings here to avoid that libc
+ * applies locale information on the formatting of floating
+ * numbers. */
+
+ if ((ret = ca_proplist_setf(p, CA_PROP_WINDOW_HPOS, "%i.%03i", (int) (x/screen_width), (int) (1000.0*x/screen_width) % 1000)) < 0)
+ return ret;
+ }
+
+ if (y > 0 && height > 0) {
+ y += height/2;
+
+ screen_height = gdk_screen_get_height(gtk_widget_get_screen(GTK_WIDGET(w)));
+
+ if ((ret = ca_proplist_setf(p, CA_PROP_WINDOW_VPOS, "%i.%03i", (int) (y/screen_height), (int) (1000.0*y/screen_height) % 1000)) < 0)
+ return ret;
+ }
+
return CA_SUCCESS;
}