From 3e14a7d7aeec88adadc579edc9fcdc3d713a6f64 Mon Sep 17 00:00:00 2001 From: micheus Date: Thu, 27 Mar 2025 16:18:00 -0300 Subject: [PATCH 1/2] Fixed dialog placement on a multiple-display setup. A Discord user, Aleks M, reported an issue with his setup, which included two displays (one horizontal and one vertical). When the dialog was invoked with the mouse near the left border of the vertical display, the dialog was cut off. To address this, I updated the code to evaluate which display the mouse was on, and used its geometry to compute the optimal position for showing the dialog. This solution worked well; however, in cases where the display uses scaling (via the OS), the dialog's position can still vary slightly, sometimes ending up farther from the mouse pointer than expected. I also addressed an issue with the option to display centered dialogs. On multiple displays, the dialog could sometimes be positioned across the frame of the displays, resulting in only half of it being visible on each display, which was quite annoying. --- src/wings_dialog.erl | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/wings_dialog.erl b/src/wings_dialog.erl index bace5fa86..a66d932c6 100644 --- a/src/wings_dialog.erl +++ b/src/wings_dialog.erl @@ -919,23 +919,37 @@ set_keyboard_focus(Dialog, Fields) -> end. set_position(mouse, Dialog) -> - {Xm,Ym} = wx_misc:getMousePosition(), + {Xm,Ym} = Pt = wx_misc:getMousePosition(), {Wd, Hd} = wxWindow:getSize(Dialog), Ws = wxSystemSettings:getMetric(?wxSYS_SCREEN_X), Hs = wxSystemSettings:getMetric(?wxSYS_SCREEN_Y), {XWw, YWw} = wxWindow:getScreenPosition(?GET(top_frame)), - if (Xm+Wd) < Ws, (Ym+Hd) < Hs -> - wxWindow:move(Dialog, max(Xm-100, min(0,XWw)), max(Ym-50, min(0,YWw))); - (Xm+Wd) < Ws -> - wxWindow:move(Dialog, max(Xm-100, min(0,XWw)), max(Hs-Hd-50, min(0,YWw))); - (Ym+Hd) < Hs -> - wxWindow:move(Dialog, max(Ws-Wd-100, min(0,XWw)), max(Ym-50, min(0,YWw))); - true -> - io:format("~p ~p~n",[{Xm,Wd,Ws},{Ym,Hd,Hs}]), - ok + + case wxDisplay:getFromPoint(Pt) of + ?wxNOT_FOUND -> + io:format("Not found - getFromPoint: ~p ~n",[Pt]), + ok; + Did -> + Display = wxDisplay:new(Did), + {X,Y,W,H} = wxDisplay:getGeometry(Display), + wxDisplay:destroy(Display), + XMax = X+W, YMax = Y+H, + if (Xm+Wd) < XMax, (Ym+Hd) < YMax -> + wxWindow:move(Dialog, max(Xm-100, max(XWw,X)), max(Ym-50, min(0,Y))); + (Xm+Wd) < XMax -> + wxWindow:move(Dialog, max(Xm-100, max(XWw,X)), max(YMax-Hd-50, min(0,YWw))); + (Ym+Hd) < YMax -> + wxWindow:move(Dialog, max(XMax-Wd-100, max(XWw,X)), max(Ym-50, min(YWw,Y))); + true -> + io:format("~p ~p~n",[{Xm,Wd,Ws},{Ym,Hd,Hs}]), + ok + end end; set_position(center, Dialog) -> - wxTopLevelWindow:centerOnScreen(Dialog); + case wxDisplay:getCount() of + 1 -> wxTopLevelWindow:centerOnScreen(Dialog); + _ -> wxWindow:centerOnParent(Dialog) + end; set_position(_, _Dialog) -> ok. From c8bba19f17d1b0a3e0324956b5764d035aabd6ac Mon Sep 17 00:00:00 2001 From: micheus Date: Tue, 16 Dec 2025 20:21:44 -0300 Subject: [PATCH 2/2] - Worked on Copilot suggestions --- src/wings_dialog.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wings_dialog.erl b/src/wings_dialog.erl index a66d932c6..8b0d0767d 100644 --- a/src/wings_dialog.erl +++ b/src/wings_dialog.erl @@ -927,8 +927,8 @@ set_position(mouse, Dialog) -> case wxDisplay:getFromPoint(Pt) of ?wxNOT_FOUND -> - io:format("Not found - getFromPoint: ~p ~n",[Pt]), - ok; + io:format("Not found - wxDisplay:getFromPoint(~p)~n",[Pt]), + set_position(center, Dialog); Did -> Display = wxDisplay:new(Did), {X,Y,W,H} = wxDisplay:getGeometry(Display),