From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ryan Prior Newsgroups: gmane.emacs.bugs Subject: bug#21469: bug#21348: 25.0.50; Screen scaling factor >=2 causes menus, tooltips to display in the wrong place Date: Mon, 12 Oct 2015 16:10:52 -0500 Message-ID: <86twpvhjxf.fsf@gmail.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1444684284 14105 80.91.229.3 (12 Oct 2015 21:11:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 12 Oct 2015 21:11:24 +0000 (UTC) Cc: 20619@debbugs.gnu.org, 21469@debbugs.gnu.org, 18429@debbugs.gnu.org To: 21348@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 12 23:11:13 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZlkNF-0005aF-Ei for geb-bug-gnu-emacs@m.gmane.org; Mon, 12 Oct 2015 23:11:13 +0200 Original-Received: from localhost ([::1]:58799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlkNE-0001NI-Px for geb-bug-gnu-emacs@m.gmane.org; Mon, 12 Oct 2015 17:11:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlkN8-0001Mx-K1 for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2015 17:11:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlkN6-0005SS-MK for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2015 17:11:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:48594) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlkN6-0005SO-J0 for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2015 17:11:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZlkN6-00074q-5s for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2015 17:11:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ryan Prior Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Oct 2015 21:11:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21469 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 21469-submit@debbugs.gnu.org id=B21469.144468425927152 (code B ref 21469); Mon, 12 Oct 2015 21:11:04 +0000 Original-Received: (at 21469) by debbugs.gnu.org; 12 Oct 2015 21:10:59 +0000 Original-Received: from localhost ([127.0.0.1]:37558 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZlkN0-00073l-4o for submit@debbugs.gnu.org; Mon, 12 Oct 2015 17:10:58 -0400 Original-Received: from mail-io0-f170.google.com ([209.85.223.170]:34007) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZlkMx-00073R-84; Mon, 12 Oct 2015 17:10:55 -0400 Original-Received: by iow1 with SMTP id 1so1394851iow.1; Mon, 12 Oct 2015 14:10:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; bh=/aPe9rmSDBXVRJR/74k5aFwqTd2UEqSAG0Y3Db3mmH8=; b=fhoGXgpjmmbD77BLLd7WiMBj1qmu4JuxJL4MDmK3a9nY/5Pa+mpG3NxMUIsywT3x17 HEfn5X52k3VL68YLqbP/H5BVUjYLpUbHmgC/j/Jt1Voa7b1gN6BkTD0d34LjE2D6l+Zv Z4u/AwufRhr/Nc9rSQ++DjXQh0BGrD4MyLKGVKoKGc9iox+LXpsy8IBO99QWpnJKrzgR c+CvGUTdH6+L2E9GocePR5ZX704xw/iyBxumNKJrj9PznkM32ZORE1iJrNJgEpXtIYk8 CTUAeOHEiAh2wys5GY+lQY9PGqA7pNx4CwKcrSSXbyHRhfQ4+JmZpmWKbYa8hy6W+aQ8 K5ww== X-Received: by 10.107.148.72 with SMTP id w69mr35411639iod.82.1444684254816; Mon, 12 Oct 2015 14:10:54 -0700 (PDT) Original-Received: from ryan-XPS-13-9343 ([137.28.231.82]) by smtp.gmail.com with ESMTPSA id t7sm107640igz.10.2015.10.12.14.10.53 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 12 Oct 2015 14:10:53 -0700 (PDT) In-Reply-To: (Ryan Prior's message of "Tue, 25 Aug 2015 17:51:28 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:107550 Archived-At: --=-=-= Content-Type: text/plain I wrote a patch to fix the issues from bugs #20619 and #21348 for GTK users. When the functions to display a tooltip or menu are called, Emacs scales coordinates using a factor from GTK. In my testing, non-GTK tooltips and menus weren't broken, so the problem is specific to GTK and the patch has no effect on non-GTK builds. Michael Droettboom, will you apply this patch and verify that the menus are now placed correctly on your system? There's something else entirely going on with the scroll bars in bug #21469, this patch doesn't address that at all. I had never noticed that hidpi bug because I dont use scroll bars, but I can confirm that turning on scroll bars causes strange behavior. It might be possible that a similar scaling strategy for scroll bar placement could provide a fix, so I CC'd that bug. I will investigate that more as time allows. The final hidpi bug I looked at, #18429, I am unable to reproduce. Perhaps it is not applicable to my platform - I'm on Ubuntu Trusty, while the reporter is on Utopic. Anders Kaseorg, can you still reproduce the bug? Finally, there's the open question of why the coordinates these functions are getting are doubled in the first place. Given my limited familiarity with Emacs internals, I have not made any progress on that question. Perhaps there are few enough places where these sometimes-inflated coordinates are passed into GTK that we can just scale them everywhere and call it good enough. Or perhaps there's a more robust solution somewhere else - if anybody can help explain this to me, I would be appreciative. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Adjust-overlay-position-on-hidpi-screens.patch Content-Description: patch to fix bugs #21348, #20619 >From 3addec3d592b9fc81e2a1503a37ccb078f03118c Mon Sep 17 00:00:00 2001 From: Ryan Prior Date: Fri, 2 Oct 2015 19:22:28 -0500 Subject: [PATCH] Adjust overlay position on hidpi screens Scale the display positions of tooltips and menus according to the window scaling factor provided by GTK3, if it is available (Bug#21348). * src/gtkutil.h (xg_scale_x_y_with_widget): * src/gtkutil.c (xg_scale_x_y_with_widget): Fuction finds scaling factor and performs scaling. (xg_show_tooltip): Divide position of tooltip by scaling factor. * src/xmenu.c (create_and_show_popup_menu) [HAVE_GTK3]: Divide position of native GTK3 menus by scaling factor. --- src/gtkutil.c | 14 ++++++++++++++ src/gtkutil.h | 4 ++++ src/xmenu.c | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/src/gtkutil.c b/src/gtkutil.c index 34e81b5..db80b2e 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -748,6 +748,7 @@ xg_show_tooltip (struct frame *f, int root_x, int root_y) if (x->ttip_window) { block_input (); + xg_scale_x_y_with_widget(GTK_WIDGET(x->ttip_window), &root_x, &root_y); gtk_window_move (x->ttip_window, root_x, root_y); gtk_widget_show_all (GTK_WIDGET (x->ttip_window)); unblock_input (); @@ -3223,6 +3224,19 @@ xg_update_submenu (GtkWidget *submenu, return newsub; } +/* Scale X and Y. + WIDGET the gtk widget from which to get the scaling factor */ +void +xg_scale_x_y_with_widget (GtkWidget *widget, + int *x, + int *y) +{ + gint scale_factor = gtk_widget_get_scale_factor(widget); + if(x) *x /= scale_factor; + if(y) *y /= scale_factor; +} + + /* Update the MENUBAR. F is the frame the menu bar belongs to. VAL describes the contents of the menu bar. diff --git a/src/gtkutil.h b/src/gtkutil.h index 34338db..8db063a 100644 --- a/src/gtkutil.h +++ b/src/gtkutil.h @@ -96,6 +96,10 @@ extern GtkWidget *xg_create_widget (const char *type, GCallback deactivate_cb, GCallback highlight_cb); +extern void xg_scale_x_y_with_widget (GtkWidget *widget, + int *x, + int *y); + extern void xg_modify_menubar_widgets (GtkWidget *menubar, struct frame *f, struct _widget_value *val, diff --git a/src/xmenu.c b/src/xmenu.c index 192ed89..1b7bbb5 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -1229,6 +1229,12 @@ create_and_show_popup_menu (struct frame *f, widget_value *first_wv, /* Child of win. */ &dummy_window); +#ifdef HAVE_GTK3 + /* Use window scaling factor to adjust position for hidpi screens. */ + xg_scale_x_y_with_widget(GTK_WIDGET(f->output_data.x->ttip_window), + &x, + &y); +#endif unblock_input (); popup_x_y.x = x; popup_x_y.y = y; -- 2.6.1 --=-=-=--