all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Neil Roberts <bpeeluk@yahoo.co.uk>
To: bug-gnu-emacs@gnu.org
Subject: Broken tooltips with dual-head on MS Windows
Date: Sat, 21 Jul 2007 12:24:51 +0100	[thread overview]
Message-ID: <20070721112451.GA8553@janet> (raw)

[-- Attachment #1: Type: text/plain, Size: 1049 bytes --]

Hi,

I found a few problems with the positioning of tooltips when more than
one monitor is used under Windows. The current code seems to only take
into account the dimensions of the primary display so that for example
if the cursor is to the right of the primary display then it will
always think the tooltip doesn't fit and it will always move it to the
left of the cursor. Also, if there is a display to the left of the
primary display then all of the coordinates on that display are
negative but Emacs won't let the tooltip be positioned at a
co-ordinate less than zero so the tooltip is placed in the wrong
display.

I've made a little patch to the compute_tip_xy function to make it use
the multi-monitor API so that it can correctly position the tooltip
within the display containing the cursor. The API is checked for
dynamically using GetProcAddress so that it can still work under
Windows 95 where it isn't available. I'm not sure if the rest of Emacs
still supports Win95 so it could be tidied up if this isn't necessary.

Regards,
- Neil

[-- Attachment #2: wintooltip.patch --]
[-- Type: text/plain, Size: 4277 bytes --]

Index: src/w32fns.c
===================================================================
RCS file: /sources/emacs/emacs/src/w32fns.c,v
retrieving revision 1.290
diff -c -r1.290 w32fns.c
*** src/w32fns.c	15 Jul 2007 01:50:54 -0000	1.290
--- src/w32fns.c	21 Jul 2007 10:02:15 -0000
***************
*** 7458,7463 ****
--- 7458,7464 ----
       int *root_x, *root_y;
  {
    Lisp_Object left, top;
+   RECT monitor_rect;
  
    /* User-specified position?  */
    left = Fcdr (Fassq (Qleft, parms));
***************
*** 7468,7508 ****
    if (!INTEGERP (left) || !INTEGERP (top))
      {
        POINT pt;
  
        BLOCK_INPUT;
        GetCursorPos (&pt);
        *root_x = pt.x;
        *root_y = pt.y;
        UNBLOCK_INPUT;
      }
  
    if (INTEGERP (top))
      *root_y = XINT (top);
!   else if (*root_y + XINT (dy) <= 0)
!     *root_y = 0; /* Can happen for negative dy */
!   else if (*root_y + XINT (dy) + height <= FRAME_W32_DISPLAY_INFO (f)->height)
      /* It fits below the pointer */
!       *root_y += XINT (dy);
!   else if (height + XINT (dy) <= *root_y)
      /* It fits above the pointer.  */
      *root_y -= height + XINT (dy);
    else
      /* Put it on the top.  */
!     *root_y = 0;
  
    if (INTEGERP (left))
      *root_x = XINT (left);
!   else if (*root_x + XINT (dx) <= 0)
!     *root_x = 0; /* Can happen for negative dx */
!   else if (*root_x + XINT (dx) + width <= FRAME_W32_DISPLAY_INFO (f)->width)
      /* It fits to the right of the pointer.  */
      *root_x += XINT (dx);
!   else if (width + XINT (dx) <= *root_x)
      /* It fits to the left of the pointer.  */
      *root_x -= width + XINT (dx);
    else
      /* Put it left justified on the screen -- it ought to fit that way.  */
!     *root_x = 0;
  }
  
  
--- 7469,7538 ----
    if (!INTEGERP (left) || !INTEGERP (top))
      {
        POINT pt;
+       HMODULE user32;
+       void *(WINAPI * monitor_from_point) (POINT, DWORD);
+       BOOL (WINAPI * get_monitor_info) (void *, void *);
  
        BLOCK_INPUT;
        GetCursorPos (&pt);
        *root_x = pt.x;
        *root_y = pt.y;
+ 
+       /* Try to get the rectangle for the monitor around the point. If
+ 	 the monitor API is not available (eg, on Windows 95) then
+ 	 just assume there is only one monitor */
+       monitor_rect.left = 0;
+       monitor_rect.right = FRAME_W32_DISPLAY_INFO (f)->width;
+       monitor_rect.top = 0;
+       monitor_rect.bottom = FRAME_W32_DISPLAY_INFO (f)->height;
+       if ((user32 = LoadLibrary ("user32")))
+ 	{
+ 	  if ((monitor_from_point = (void *(WINAPI *) (POINT, DWORD))
+ 	       GetProcAddress (user32, "MonitorFromPoint"))
+ 	      && (get_monitor_info = (BOOL (WINAPI *) (void *, void*))
+ 		  GetProcAddress (user32, "GetMonitorInfoA")))
+ 	    {
+ 	      void *monitor;
+ 	      char buf[40 /* sizeof (MONITORINFO) */];
+ 	      *(DWORD *) buf = 40; /* set cbSize */
+ 	      monitor = (* monitor_from_point) (pt, 2 /* MONITOR_DEFAULTTONEAREST */);
+ 	      if ((* get_monitor_info) (monitor, buf))
+ 		monitor_rect = *(RECT *) (buf + sizeof (DWORD));
+ 	    }
+       
+ 	  FreeLibrary (user32);
+ 	}
+ 
        UNBLOCK_INPUT;
      }
  
    if (INTEGERP (top))
      *root_y = XINT (top);
!   else if (*root_y + XINT (dy) <= monitor_rect.top)
!     *root_y = monitor_rect.top; /* Can happen for negative dy */
!   else if (*root_y + XINT (dy) + height <= monitor_rect.bottom)
      /* It fits below the pointer */
!     *root_y += XINT (dy);
!   else if (*root_y - XINT (dy) - height >= monitor_rect.top)
      /* It fits above the pointer.  */
      *root_y -= height + XINT (dy);
    else
      /* Put it on the top.  */
!     *root_y = monitor_rect.top;
  
    if (INTEGERP (left))
      *root_x = XINT (left);
!   else if (*root_x + XINT (dx) <= monitor_rect.left)
!     *root_x = monitor_rect.left; /* Can happen for negative dx */
!   else if (*root_x + XINT (dx) + width <= monitor_rect.right)
      /* It fits to the right of the pointer.  */
      *root_x += XINT (dx);
!   else if (*root_x - width - XINT (dx) >= monitor_rect.left)
      /* It fits to the left of the pointer.  */
      *root_x -= width + XINT (dx);
    else
      /* Put it left justified on the screen -- it ought to fit that way.  */
!     *root_x = monitor_rect.left;
  }
  
  

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
bug-gnu-emacs mailing list
bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs

                 reply	other threads:[~2007-07-21 11:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070721112451.GA8553@janet \
    --to=bpeeluk@yahoo.co.uk \
    --cc=bug-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.