SF.net SVN: geany-plugins:[1775] trunk/geany-plugins/webhelper/src
colombanw at users.sourceforge.net
colombanw at xxxxx
Sun Dec 19 13:23:11 UTC 2010
Revision: 1775
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1775&view=rev
Author: colombanw
Date: 2010-12-19 13:23:10 +0000 (Sun, 19 Dec 2010)
Log Message:
-----------
WebHelper: moved window geometry get/set helpers to utils and improved them
Now they are named gwh_{get,set}_window_geometry(), and
gwh_set_window_geometry() hints the WM that the position/size is
user-specified, hopefully making them answer the request.
Note that not all WM needs this to honor moves or resizes (Metacity, ...).
Modified Paths:
--------------
trunk/geany-plugins/webhelper/src/gwh-browser.c
trunk/geany-plugins/webhelper/src/gwh-utils.c
trunk/geany-plugins/webhelper/src/gwh-utils.h
Modified: trunk/geany-plugins/webhelper/src/gwh-browser.c
===================================================================
--- trunk/geany-plugins/webhelper/src/gwh-browser.c 2010-12-18 23:47:11 UTC (rev 1774)
+++ trunk/geany-plugins/webhelper/src/gwh-browser.c 2010-12-19 13:23:10 UTC (rev 1775)
@@ -125,55 +125,18 @@
static gchar *
get_web_inspector_window_geometry (GwhBrowser *self)
{
- gint width;
- gint height;
- gint x;
- gint y;
- GtkWindow *window;
-
- window = GTK_WINDOW (self->priv->inspector_window);
- gtk_window_get_size (window, &width, &height);
- if (gtk_widget_get_visible (GTK_WIDGET (window))) {
- gtk_window_get_position (window, &x, &y);
- } else {
- x = self->priv->inspector_window_x;
- y = self->priv->inspector_window_y;
- }
-
- return g_strdup_printf ("%dx%d%+d%+d", width, height, x, y);
+ return gwh_get_window_geometry (GTK_WINDOW (self->priv->inspector_window),
+ self->priv->inspector_window_x,
+ self->priv->inspector_window_y);
}
static void
set_web_inspector_window_geometry (GwhBrowser *self,
const gchar *geometry)
{
- gint width;
- gint height;
- gint x;
- gint y;
- gchar dummy;
- GtkWindow *window;
-
- g_return_if_fail (geometry != NULL);
-
- window = GTK_WINDOW (self->priv->inspector_window);
- gtk_window_get_size (window, &width, &height);
- gtk_window_get_position (window, &x, &y);
- switch (sscanf (geometry, "%dx%d%d%d%c", &width, &height, &x, &y, &dummy)) {
- case 4:
- case 3:
- self->priv->inspector_window_x = x;
- self->priv->inspector_window_y = y;
- gtk_window_move (window, x, y);
- /* fallthrough */
- case 2:
- case 1:
- gtk_window_resize (window, width, height);
- break;
-
- default:
- g_warning ("Invalid window geometry \"%s\"", geometry);
- }
+ gwh_set_window_geometry (GTK_WINDOW (self->priv->inspector_window),
+ geometry, &self->priv->inspector_window_x,
+ &self->priv->inspector_window_y);
}
/* settings change notifications */
Modified: trunk/geany-plugins/webhelper/src/gwh-utils.c
===================================================================
--- trunk/geany-plugins/webhelper/src/gwh-utils.c 2010-12-18 23:47:11 UTC (rev 1774)
+++ trunk/geany-plugins/webhelper/src/gwh-utils.c 2010-12-19 13:23:10 UTC (rev 1775)
@@ -72,3 +72,80 @@
return pixbuf;
}
+
+/**
+ * gwh_get_window_geometry:
+ * @window: A #GtkWindow
+ * @default_x: Default position on X if not computable
+ * @default_y: Default position on Y if not computable
+ *
+ * Gets the XWindow-style geometry of a #GtkWindow
+ *
+ * Returns: A newly-allocated string representing the window geometry.
+ */
+gchar *
+gwh_get_window_geometry (GtkWindow *window,
+ gint default_x,
+ gint default_y)
+{
+ gint width;
+ gint height;
+ gint x;
+ gint y;
+
+ gtk_window_get_size (window, &width, &height);
+ if (gtk_widget_get_visible (GTK_WIDGET (window))) {
+ gtk_window_get_position (window, &x, &y);
+ } else {
+ x = default_x;
+ y = default_y;
+ }
+
+ return g_strdup_printf ("%dx%d%+d%+d", width, height, x, y);
+}
+
+/**
+ * gwh_set_window_geometry:
+ * @window: A #GtkWindow
+ * @geometry: a XWindow-style geometry
+ * @x_: (out): return location for the window's X coordinate
+ * @y_: (out): return location for the window's Y coordinate
+ *
+ * Sets the geometry of a window from a XWindow-style geometry.
+ */
+void
+gwh_set_window_geometry (GtkWindow *window,
+ const gchar *geometry,
+ gint *x_,
+ gint *y_)
+{
+ gint width;
+ gint height;
+ gint x;
+ gint y;
+ gchar dummy;
+ GdkWindowHints hints_mask = 0;
+
+ g_return_if_fail (geometry != NULL);
+
+ gtk_window_get_size (window, &width, &height);
+ gtk_window_get_position (window, &x, &y);
+ switch (sscanf (geometry, "%dx%d%d%d%c", &width, &height, &x, &y, &dummy)) {
+ case 4:
+ case 3:
+ if (x_) *x_ = x;
+ if (y_) *y_ = y;
+ gtk_window_move (window, x, y);
+ hints_mask |= GDK_HINT_USER_POS;
+ /* fallthrough */
+ case 2:
+ case 1:
+ gtk_window_resize (window, width, height);
+ hints_mask |= GDK_HINT_USER_SIZE;
+ break;
+
+ default:
+ g_warning ("Invalid window geometry \"%s\"", geometry);
+ }
+ gtk_window_set_geometry_hints (window, NULL, NULL, hints_mask);
+}
Modified: trunk/geany-plugins/webhelper/src/gwh-utils.h
===================================================================
--- trunk/geany-plugins/webhelper/src/gwh-utils.h 2010-12-18 23:47:11 UTC (rev 1774)
+++ trunk/geany-plugins/webhelper/src/gwh-utils.h 2010-12-19 13:23:10 UTC (rev 1775)
@@ -22,6 +22,7 @@
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtk/gtk.h>
G_BEGIN_DECLS
@@ -29,6 +30,15 @@
G_GNUC_INTERNAL
GdkPixbuf *gwh_pixbuf_new_from_uri (const gchar *uri,
GError **error);
+G_GNUC_INTERNAL
+gchar *gwh_get_window_geometry (GtkWindow *window,
+ gint default_x,
+ gint default_y);
+G_GNUC_INTERNAL
+void gwh_set_window_geometry (GtkWindow *window,
+ const gchar *geometry,
+ gint *x_,
+ gint *y_);
G_END_DECLS
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Plugins-Commits
mailing list