From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Roberts Newsgroups: gmane.emacs.bugs Subject: Broken tooltips with dual-head on MS Windows Date: Sat, 21 Jul 2007 12:24:51 +0100 Message-ID: <20070721112451.GA8553@janet> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="zYM0uCDKw75PZbzx" X-Trace: sea.gmane.org 1185028100 9372 80.91.229.12 (21 Jul 2007 14:28:20 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 21 Jul 2007 14:28:20 +0000 (UTC) To: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 21 16:28:19 2007 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1ICFwK-000114-QY for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Jul 2007 16:28:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ICFwK-0006FA-8V for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Jul 2007 10:28:12 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ICD4x-00041y-7L for bug-gnu-emacs@gnu.org; Sat, 21 Jul 2007 07:24:55 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ICD4w-00041m-M4 for bug-gnu-emacs@gnu.org; Sat, 21 Jul 2007 07:24:54 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ICD4w-00041j-Ix for bug-gnu-emacs@gnu.org; Sat, 21 Jul 2007 07:24:54 -0400 Original-Received: from mra05.ch.as12513.net ([82.153.254.73]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1ICD4v-0006PO-Na for bug-gnu-emacs@gnu.org; Sat, 21 Jul 2007 07:24:54 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mra05.ch.as12513.net (Postfix) with ESMTP id 4A20FC45D3 for ; Sat, 21 Jul 2007 12:24:52 +0100 (BST) Original-Received: from mra05.ch.as12513.net ([127.0.0.1]) by localhost (mra05.ch.as12513.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 18907-01-34 for ; Sat, 21 Jul 2007 12:24:51 +0100 (BST) Original-Received: from localhost (unknown [91.84.60.59]) by mra05.ch.as12513.net (Postfix) with ESMTP id 76C27C45B0 for ; Sat, 21 Jul 2007 12:24:51 +0100 (BST) Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: by Eclipse VIRUSshield at eclipse.net.uk X-detected-kernel: Linux 2.4-2.6 X-Mailman-Approved-At: Sat, 21 Jul 2007 10:28:09 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:16191 Archived-At: --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="wintooltip.patch" 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; } --zYM0uCDKw75PZbzx Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ bug-gnu-emacs mailing list bug-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs --zYM0uCDKw75PZbzx--