From 52de76b57ddc497f639c0dd00fdb9c578f329434 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 11 Sep 2009 04:54:18 +0200 Subject: gtk: generate window position/size properties in ca_gtk_proplist_set_for_widget() --- src/canberra-gtk.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) 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; } -- cgit