Fitting persistent window to screen when screen size changes

61 views
Skip to first unread message

Kenneth Porter

unread,
May 3, 2024, 4:38:11 PMMay 3
to wxWidgets Users
I'm experimenting with the persistence feature and realized I'm using
this from Remote Desktop, where my remote display window is a different
size than the one in my lab. I don't want to move the window to a
position that's restored outside the reach of someone using a different
display setup. So is there an easy method to catch that situation and
make sure the position is within the current screen dimensions? And is
there an event that detects a change in screen size that can be
intercepted to move an off-screen window within the current display
boundaries?


Igor Korot

unread,
May 3, 2024, 5:21:03 PMMay 3
to wx-u...@googlegroups.com
Hi,
Are you talking about the DPI change, screen rotation,
changing the size of the screen from 1920xN to 1440XN for
example?

Thank yuo.

>
>
> --
> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
> ---
> You received this message because you are subscribed to the Google Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/a4539447-dbd5-4034-906d-79c5b4ebc464%40sewingwitch.com.

Kenneth Porter

unread,
May 3, 2024, 5:54:32 PMMay 3
to wx-u...@googlegroups.com
On 5/3/2024 2:20 PM, Igor Korot wrote:
Are you talking about the DPI change, screen rotation,
changing the size of the screen from 1920xN to 1440XN for
example?

My Remote Desktop session is set to 1280x1024. I often connect to systems with 1024x768 displays. I might also use a session from my 4k screen. Imagine I move the window on my 4k screen to the right half. Then I release the session to someone using the PC locally. The window is way off the right edge of their screen. The same would happen if I closed the app with the window off to the right and they started the app.

So I need two things: One is to move the window from its persisted location back onto the smaller display, potentially resizing to fit. Second, when a user using a smaller screen takes control, I need to intercept some event and bring the window back onto the now smaller display.

The first part I could do with explicit code, but I'm wondering if there's something in the library that can already do this. For the second part I just need to know if there's an event to intercept when the screen changes between local and remote. Or even someone plugging a different monitor in.


Vadim Zeitlin

unread,
May 4, 2024, 12:43:42 PMMay 4
to wxWidgets Users
On Fri, 3 May 2024 13:35:52 -0700 Kenneth Porter wrote:

KP> I'm experimenting with the persistence feature and realized I'm using
KP> this from Remote Desktop, where my remote display window is a different
KP> size than the one in my lab. I don't want to move the window to a
KP> position that's restored outside the reach of someone using a different
KP> display setup.

This won't happen, the code restoring window geometry checks for this, see

https://github.com/wxWidgets/wxWidgets/blob/e02c65f45f1f6af57e37127ee243fa146f5a8e5e/include/wx/private/tlwgeom.h#L127-L140

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
https://www.tt-solutions.com/

Kenneth Porter

unread,
May 4, 2024, 3:21:54 PMMay 4
to wx-u...@googlegroups.com
On 5/4/2024 9:43 AM, Vadim Zeitlin wrote:
This won't happen, the code restoring window geometry checks for this

Oh good. (Still reviewing that code to see what it does.) That looks like it handles when the window is created, such as on a subsequent run of the app. but what about if the app is already running when the resolution changes? I see an event for DPI changes, but some googling suggests it only works with Win10, and I fear I might have a Win7 box somewhere. All I really need is an event to tell me when the session changed hands. Does something like that exist?


Gunter Königsmann

unread,
May 4, 2024, 3:47:47 PMMay 4
to wx-u...@googlegroups.com
My impression is that the window manager should be able to deal with
that case without every simple application watching it. But on MS
Windows nearly every MS Office application has already ended up behind
the task bar on one occasion or another for me, which I would claim to
be a bug in MS Windows. I am not convinced that it is our task to ship
around these...

Kenneth Porter

unread,
May 5, 2024, 3:16:53 PMMay 5
to wx-u...@googlegroups.com
I think I found the right Windows event to intercept. I don't see the
symbols in the wx source so it looks like I'll need to roll my own support.

Is there anything like this on Mac or Linux? So I can model my support
to be extended if and when I port there.

https://learn.microsoft.com/en-us/windows/win32/termserv/wm-wtssession-change

Note that one must register an HWND to receive these notifications:

https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtsregistersessionnotification

I figure it makes sense to create a mix-in class for wxWindow that
handles the registration in its ctor/dtor, similar to the design for the
persistence classes.


Kenneth Porter

unread,
May 8, 2024, 12:49:10 AMMay 8
to wx-u...@googlegroups.com
I fleshed out a wxEvent subclass that tells me when Remote Desktop
connects and disconnects. I'm not entirely happy with my object names so
I'm open to suggestions. I can use this to dynamically change my window
sizes.

https://github.com/SpareSimian/wxRemoteDesktopEvents

When I disconnect from my RD session and then reconnect, I see this in
the debugger output:

OnSessionChange({type=SESSION_LOCK,id=9})
OnSessionChange({type=REMOTE_DISCONNECT,id=9})
OnSessionChange({type=REMOTE_CONNECT,id=9})
OnSessionChange({type=SESSION_UNLOCK,id=9})


Vadim Zeitlin

unread,
May 8, 2024, 3:52:42 PMMay 8
to wx-u...@googlegroups.com
On Tue, 7 May 2024 21:46:30 -0700 Kenneth Porter wrote:

KP> I fleshed out a wxEvent subclass that tells me when Remote Desktop
KP> connects and disconnects. I'm not entirely happy with my object names so
KP> I'm open to suggestions. I can use this to dynamically change my window
KP> sizes.
KP>
KP> https://github.com/SpareSimian/wxRemoteDesktopEvents
KP>
KP> When I disconnect from my RD session and then reconnect, I see this in
KP> the debugger output:
KP>
KP> OnSessionChange({type=SESSION_LOCK,id=9})
KP> OnSessionChange({type=REMOTE_DISCONNECT,id=9})
KP> OnSessionChange({type=REMOTE_CONNECT,id=9})
KP> OnSessionChange({type=SESSION_UNLOCK,id=9})

Sorry, I'm still not sure why do you need these events in the first place:
don't you get the usual display size/resolution change events?

Kenneth Porter

unread,
May 8, 2024, 5:06:13 PMMay 8
to wx-u...@googlegroups.com
On 5/8/2024 12:52 PM, Vadim Zeitlin wrote:
 Sorry, I'm still not sure why do you need these events in the first place:
don't you get the usual display size/resolution change events?

Which events are those?


Vadim Zeitlin

unread,
May 8, 2024, 7:19:43 PMMay 8
to wx-u...@googlegroups.com
On Wed, 8 May 2024 14:03:54 -0700 Kenneth Porter wrote:

KP> On 5/8/2024 12:52 PM, Vadim Zeitlin wrote:
KP> > Sorry, I'm still not sure why do you need these events in the first place:
KP> > don't you get the usual display size/resolution change events?
KP>
KP> Which events are those?

At Windows level there are WM_SETTINGCHANGE and WM_DISPLAYCHANGE and there
is wxDisplayChangedEvent corresponding to the latter.
Reply all
Reply to author
Forward
0 new messages