Subject: bug#5968: Problems with 'geometry' [GTK,Cygwin,trunk]

From: Angelo Graziosi <[email-masked]>
Date: Sun, 18 Apr 2010 11:52:31 +0200

I have in .Xdefaults:

Emacs.geometry:         80x40-0+0

which has always started Emacs with the top-right corner (TRC) over the 
same corner of Desktop.

But now, the revisions 99918, 99920, 99922... of trunk (GTK build on 
Cygwin) starts Emacs with TRC *out* the Desktop! See the attached figure 
in [*]! :(

I suspect this is related:

src/ChangeLog:
==================================================
[...]
2010-04-13  Jan DjÃrv  <...>

* gtkutil.c (xg_set_geometry): Set geometry for PPosition also.
(x_wm_set_size_hint): Dont set position flags, gtk_window_parse_geometry
does that.
[...]
==================================================

Rev. 99880 works just fine... Indeed, reverting *only* the changes to 
'gtkutil.c' (applying 'gtkutil.c.revert_to_880.diff') and building rev. 
99922, Emacs starts as expected!! :-)

Perhaps these changes are the cause of the problems:

====================
[...]
-  if (user_position)
-    {
-      hint_flags &= ~GDK_HINT_POS;
-      hint_flags |= GDK_HINT_USER_POS;
-    }
[...]
====================

It seems that this problem is Cygwin specific, I can't reproduce it on 
GNU/Linux Kubuntu 9.10.

On Cygwin, it can be reproduced simply with:

$ emacs -Q --geometry 80x40-0+0 &

or

$ emacs -Q --geometry -0+0 &

Thanks,
Angelo.

---
[*] http://lists.gnu.org/archive/html/emacs-devel/2010-04/msg00772.html
--- /tmp/emacs/src/gtkutil.c	2010-04-13 18:33:36.000000000 +0200
+++ emacs24/src/gtkutil.c	2010-02-24 23:46:20.000000000 +0100
@@ -529,7 +529,7 @@
 xg_set_geometry (f)
      FRAME_PTR f;
 {
-  if (f->size_hint_flags & (USPosition | PPosition))
+  if (f->size_hint_flags & USPosition)
     {
       int left = f->left_pos;
       int xneg = f->size_hint_flags & XNegative;
@@ -542,7 +542,9 @@
       if (yneg)
         top = -top;
 
-      sprintf (geom_str, "%c%d%c%d",
+      sprintf (geom_str, "=%dx%d%c%d%c%d",
+               FRAME_PIXEL_WIDTH (f),
+               FRAME_TOTAL_PIXEL_HEIGHT (f),
                (xneg ? '-' : '+'), left,
                (yneg ? '-' : '+'), top);
 
@@ -550,6 +552,9 @@
                                       geom_str))
         fprintf (stderr, "Failed to parse: '%s'\n", geom_str);
     }
+  else if (f->size_hint_flags & PPosition)
+    gtk_window_move (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
+                     f->left_pos, f->top_pos);
 }
 
 /* Clear under internal border if any.  As we use a mix of Gtk+ and X calls
@@ -951,6 +956,16 @@
   else if (win_gravity == StaticGravity)
     size_hints.win_gravity = GDK_GRAVITY_STATIC;
 
+  if (flags & PPosition) hint_flags |= GDK_HINT_POS;
+  if (flags & USPosition) hint_flags |= GDK_HINT_USER_POS;
+  if (flags & USSize) hint_flags |= GDK_HINT_USER_SIZE;
+
+  if (user_position)
+    {
+      hint_flags &= ~GDK_HINT_POS;
+      hint_flags |= GDK_HINT_USER_POS;
+    }
+
   if (hint_flags != f->output_data.x->hint_flags
       || memcmp (&size_hints,
 		 &f->output_data.x->size_hints,