all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Improved patch to fix frame positioning bug on Windows
@ 2005-01-13 17:41 Francis Litterio
  2005-01-13 17:59 ` Francis Litterio
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Francis Litterio @ 2005-01-13 17:41 UTC (permalink / raw)
  Cc: help-emacs-windows

On Windows, evaluating (make-frame '((left . -1))) creates a frame that
is positioned several pixels off the right edge of the display.
Similarly, (make-frame '((top . -1))) creates a frame that is positioned
off the bottom edge of the display.

The below patch fixes this bug and does not regress the fix to Drew
Adams' bug reported at:

  http://lists.gnu.org/archive/html/emacs-pretest-bug/2004-11/msg00519.html

(modulo the mistaken assumption about frame width in step #2 of Drew's
bug report).

This patch changes function x_calc_absolute_position() in w32term.c so
that it properly accounts for the width and height of the Windows-drawn
borders around the frame when converting a negative 'left or 'top
parameter into its equivalent non-negative value.  This code works
correctly even if the user has configured the Windows-drawn borders to
have a different width or height from the default.

After applying this patch, you can test it by evaluating these forms and
seeing the described behavior:

  ;; Create a frame flush against the right edge of the display.
  (make-frame '((left . -1)))

  ;; Create a frame flush against the bottom edge of the display.
  (make-frame '((top . -1)))

  ;; Create a frame flush against the bottom/right edge of the display.
  (make-frame '((top . -1) (left . -1)))

  ;; Move the current frame flush against the right edge of the display.
  (modify-frame-parameters nil '((left . -1)))

  ;; Move the current frame flush against the bottom edge of the display.
  (modify-frame-parameters nil '((top . -1)))

  ;; Test that setting the current frame's 'left parameter to a negative
  ;; value that is equivalent to its current positive value does not
  ;; move the frame.  The value of border-width in this test _MUST_ be
  ;; set to the width of your left (or right) Windows border in pixels.
  ;; Values shown here are typical but may not be correct for your
  ;; system.
  (let* ((border-width 4)
         (negative-left (- (+ 1 (- (display-pixel-width)
                                 (+ (* 2 border-width)
                                    (frame-pixel-width nil)
                                    (frame-parameter nil 'left)))))))
    (modify-frame-parameters nil `((left . ,negative-left))))

  ;; Test that setting the current frame's 'top parameter to a negative
  ;; value that is equivalent to its current positive value does not
  ;; move the frame.  The value of border-height-top in this test _MUST_
  ;; be set to the height of your top Windows border in pixels.  The
  ;; value of border-height-bottom in this test _MUST_ be set to the
  ;; height of your bottom Windows border in pixels.  Values shown here
  ;; are typical but may not be correct for your system.
  (let* ((border-height-top 29)
	 (border-height-bottom 4)
         (negative-top (- (+ 1 (- (display-pixel-height)
                                (+ border-height-top
                                   border-height-bottom
                                   (frame-pixel-height nil)
                                   (frame-parameter nil 'top)))))))
    (modify-frame-parameters nil `((top . ,negative-top))))

I hope this helps.
--
Francis Litterio
franl <at> world . std . com


--- src/ChangeLog	10 Jan 2005 08:29:50 -0500	1.4147
+++ src/ChangeLog	13 Jan 2005 12:39:35 -0500	
@@ -1,3 +1,10 @@
+2005-01-13  Francis Litterio  <franl@world.std.com>
+
+	* w32term.c (x_calc_absolute_position): Changed function
+	x_calc_absolute_position() to account for the Windows-drawn
+	borders around a frame when converting a negative 'top or 'left
+	parameter into the equivalent positive value.
+
 2005-01-10  Kim F. Storm  <storm@cua.dk>
 
 	* dispextern.h (merge_faces): Rename from merge_into_realized_face.


--- src/w32term.c	03 Jan 2005 17:52:51 -0500	1.221
+++ src/w32term.c	13 Jan 2005 12:17:05 -0500	
@@ -1461,7 +1461,7 @@
     {
       real_x = max (real_x, s->gc->clip_rectangle.left);
       real_y = max (real_y, s->gc->clip_rectangle.top);
-      real_w = min (real_w, s->gc->clip_rectangle.right
+      real_w = min (real_w, s->gc->clip_rectangle.r ght
                     - s->gc->clip_rectangle.left);
       real_h = min (real_h, s->gc->clip_rectangle.bottom
                     - s->gc->clip_rectangle.top);
@@ -5376,17 +5376,58 @@
 {
   int flags = f->size_hint_flags;
 
-  /* Treat negative positions as relative to the leftmost bottommost
+  /* left_right_borders_width holds the sum of the widths of the frame's left
+     and right borders (in pixels) drawn by Windows. */
+
+  unsigned int left_right_borders_width = 8;   /* A sensible default value. */
+
+  /* top_bottom_borders_height holds the sum of the heights of the frame's top and
+     bottom borders (in pixels) drawn by Windows. */
+
+  unsigned int top_bottom_borders_height = 32;  /* A sensible default value. */
+
+  /* Now obtain the actual values of the above two variables.  If we fail to
+     obtain the actual values, we will use the defaults assigned above.  We compute
+     the border width (height) by subtracting the width (height) of the frame's
+     client area from the width (height) of the frame's entire window.
+  */
+
+  WINDOWPLACEMENT wp = { 0 };
+
+  BOOL status = GetWindowPlacement (FRAME_W32_WINDOW (f), &wp);
+
+  if (status != FALSE)
+  {
+      RECT client_rect = { 0 };
+
+      status = GetClientRect (FRAME_W32_WINDOW (f), &client_rect);
+
+      if (status != FALSE)
+      {
+	  left_right_borders_width =
+	      (wp.rcNormalPosition.right - wp.rcNormalPosition.left) -
+	      (client_rect.right - client_rect.left);
+
+	  top_bottom_borders_height =
+	      (wp.rcNormalPosition.bottom - wp.rcNormalPosition.top) -
+	      (client_rect.bottom - client_rect.top);
+      }
+  }
+
+  /* Treat negative positions as relative to the rightmost bottommost
      position that fits on the screen.  */
   if (flags & XNegative)
     f->left_pos = (FRAME_W32_DISPLAY_INFO (f)->width
 		   - FRAME_PIXEL_WIDTH (f)
-		   + f->left_pos);
+		   + f->left_pos
+		   - (left_right_borders_width - 1));
 
   if (flags & YNegative)
     f->top_pos = (FRAME_W32_DISPLAY_INFO (f)->height
 		  - FRAME_PIXEL_HEIGHT (f)
-		  + f->top_pos);
+		  + f->top_pos
+                  - (top_bottom_borders_height - 1));
+
   /* The left_pos and top_pos
      are now relative to the top and left screen edges,
      so the flags should correspond.  */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Improved patch to fix frame positioning bug on Windows
  2005-01-13 17:41 Improved patch to fix frame positioning bug on Windows Francis Litterio
@ 2005-01-13 17:59 ` Francis Litterio
  2005-01-14 20:57 ` Drew Adams
  2005-01-15  0:11 ` Richard Stallman
  2 siblings, 0 replies; 4+ messages in thread
From: Francis Litterio @ 2005-01-13 17:59 UTC (permalink / raw)
  Cc: help-emacs-windows

Francis Litterio wrote:

> -      real_w = min (real_w, s->gc->clip_rectangle.right
> +      real_w = min (real_w, s->gc->clip_rectangle.r ght

Ugh.  How did _that_ get in there?  Here's a correct version of the
patch.  Sorry for the confusion.
--
Francis Litterio
franl <at> world . std . com


--- src/ChangeLog	10 Jan 2005 08:29:50 -0500	1.4147
+++ src/ChangeLog	13 Jan 2005 12:39:35 -0500	
@@ -1,3 +1,10 @@
+2005-01-13  Francis Litterio  <franl@world.std.com>
+
+	* w32term.c (x_calc_absolute_position): Changed function
+	x_calc_absolute_position() to account for the Windows-drawn
+	borders around a frame when converting a negative 'top or 'left
+	parameter into the equivalent positive value.
+
 2005-01-10  Kim F. Storm  <storm@cua.dk>
 
 	* dispextern.h (merge_faces): Rename from merge_into_realized_face.


--- src/w32term.c	03 Jan 2005 17:52:51 -0500	1.221
+++ src/w32term.c	13 Jan 2005 12:55:19 -0500	
@@ -5376,17 +5376,58 @@
 {
   int flags = f->size_hint_flags;
 
-  /* Treat negative positions as relative to the leftmost bottommost
+  /* left_right_borders_width holds the sum of the widths of the frame's left
+     and right borders (in pixels) drawn by Windows. */
+
+  unsigned int left_right_borders_width = 8;   /* A sensible default value. */
+
+  /* top_bottom_borders_height holds the sum of the heights of the frame's top and
+     bottom borders (in pixels) drawn by Windows. */
+
+  unsigned int top_bottom_borders_height = 32;  /* A sensible default value. */
+
+  /* Now obtain the actual values of the above two variables.  If we fail to
+     obtain the actual values, we will use the defaults assigned above.  We compute
+     the border width (height) by subtracting the width (height) of the frame's
+     client area from the width (height) of the frame's entire window.
+  */
+
+  WINDOWPLACEMENT wp = { 0 };
+
+  BOOL status = GetWindowPlacement (FRAME_W32_WINDOW (f), &wp);
+
+  if (status != FALSE)
+  {
+      RECT client_rect = { 0 };
+
+      status = GetClientRect (FRAME_W32_WINDOW (f), &client_rect);
+
+      if (status != FALSE)
+      {
+	  left_right_borders_width =
+	      (wp.rcNormalPosition.right - wp.rcNormalPosition.left) -
+	      (client_rect.right - client_rect.left);
+
+	  top_bottom_borders_height =
+	      (wp.rcNormalPosition.bottom - wp.rcNormalPosition.top) -
+	      (client_rect.bottom - client_rect.top);
+      }
+  }
+
+  /* Treat negative positions as relative to the rightmost bottommost
      position that fits on the screen.  */
   if (flags & XNegative)
     f->left_pos = (FRAME_W32_DISPLAY_INFO (f)->width
 		   - FRAME_PIXEL_WIDTH (f)
-		   + f->left_pos);
+		   + f->left_pos
+		   - (left_right_borders_width - 1));
 
   if (flags & YNegative)
     f->top_pos = (FRAME_W32_DISPLAY_INFO (f)->height
 		  - FRAME_PIXEL_HEIGHT (f)
-		  + f->top_pos);
+		  + f->top_pos
+                  - (top_bottom_borders_height - 1));
+
   /* The left_pos and top_pos
      are now relative to the top and left screen edges,
      so the flags should correspond.  */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Improved patch to fix frame positioning bug on Windows
  2005-01-13 17:41 Improved patch to fix frame positioning bug on Windows Francis Litterio
  2005-01-13 17:59 ` Francis Litterio
@ 2005-01-14 20:57 ` Drew Adams
  2005-01-15  0:11 ` Richard Stallman
  2 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2005-01-14 20:57 UTC (permalink / raw)
  Cc: help-emacs-windows

    The below patch fixes this bug and does not regress the fix to Drew
    Adams' bug reported at:
http://lists.gnu.org/archive/html/emacs-pretest-bug/2004-11/msg00519.html

    (modulo the mistaken assumption about frame width in step #2 of Drew's
    bug report).

Just to clarify:
 1) The bug isn't mine; I just reported it :-).
 2) There was no mistaken assumption of frame width in the bug description.
    I used 600 as an _example_ ("getting, for example, 600"). In following
    the instructions, each person will no doubt get a different frame size.

More importantly, thanks for the fix! I can't test it, but if it works,
that's great.

 - Drew

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Improved patch to fix frame positioning bug on Windows
  2005-01-13 17:41 Improved patch to fix frame positioning bug on Windows Francis Litterio
  2005-01-13 17:59 ` Francis Litterio
  2005-01-14 20:57 ` Drew Adams
@ 2005-01-15  0:11 ` Richard Stallman
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Stallman @ 2005-01-15  0:11 UTC (permalink / raw)
  Cc: emacs-devel

Your change is too large to install without legal papers.
The papers you have signed so far cover only GNUS.
If you sign papers covering all of Emacs, we could
conceivably install this change.  I will send you another
message about that.

(I will leave it up to people who work on Windows support
to decide whether the change is technically desirable.)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-01-15  0:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-13 17:41 Improved patch to fix frame positioning bug on Windows Francis Litterio
2005-01-13 17:59 ` Francis Litterio
2005-01-14 20:57 ` Drew Adams
2005-01-15  0:11 ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.