libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.98k stars 1.84k forks source link

[X11] SDL_SetWindowPosition can not move window outside of desktop bounds #3813

Closed SDLBugzilla closed 3 weeks ago

SDLBugzilla commented 3 years ago

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.13 Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2020-08-31 12:09:01 +0000, Rokas Kupstys wrote:

Created attachment 4456 Screen configuration

We are using SDL windows without decorations + SDL_SetWindowPosition() to move them. On X11 such windows can not move outside of desktop bounds. This behavior does not manifest on other platforms. This behavior is a consequence of xattr.override_redirect being set to false for normal windows. This flag is set to true only for tooltips and popups. Maybe it would also make sense to set it for borderless windows? A quick test overhere seems to work, though i do not know all implications of toggling this flag.

Steps to reproduce:

  1. git clone --single-branch --branch docking https://github.com/ocornut/imgui.git
  2. cd imgui/examples/example_sdl_opengl3
  3. make
  4. ./example_sdl_opengl3
  5. Drag either of Dear ImGui windows ("Hello, world!" or "Dear ImGui Demo") outside of main viewport and try to move window outside of desktop bounds.

Result: Window edge will get stuck at desktop edge. Note that this also confuses Dear ImGui and mouse inputs get registered in wrong locations, this is nothing to be concerned about. In case of multi-monitor setups please use screen at the edge of global X11 display canvas (made up terminology, hope it makes sense). I have two monitors and i can drag these windows to stick outside of smaller screen. For clarity i attached a screenshot with market green area where window can stick out.

Expected result: Dear ImGui window should be able to stick outside of desktop bounds, just like we can drag any other window by it's decorations to stick out of bounds.

icculus commented 3 weeks ago

(Just so the bug report is all in the same place, this was the attachment image from Bugzilla...)

image

icculus commented 3 weeks ago

Okay, so, this still happens with the latest Dear Imgui, if you use the newer imgui/examples/example_sdl3_opengl3 and drag the Hello World window out of the main window and try to drag it off the screen (or even just write a test app that calls SDL_SetWindowPosition() to move to a negative X coordinate). And, yes, it's the lack of the override_redirect flag that prevents this.

BUT: turning on that flag can only be done at window creation time, so we can't do it for borderless windows unless we're willing to recreate them during a SDL_SetWindowBordered() call.

But also: this works because override_redirect=True basically removes Window Manager control from the window. This means it won't respect keyboard focus, z-ordering, it won't show up in the task bar, etc.

If you want to see why this is a bad idea, run that Dear Imgui example with the environment variable SDL_X11_FORCE_OVERRIDE_REDIRECT=1. Just be prepared to reboot your machine or ssh in to kill the process, since it will basically hang the desktop.

I've only tried this on Gnome (with...Metacity? Is that the current Gnome window manager?), but I can see that you can drag windows outside the desktop from a standard title bar but not programmatically position them. I would argue this is a window manager bug and should be addressed by them.

We should close this one.

icculus commented 3 weeks ago

BUT: turning on that flag can only be done at window creation time, so we can't do it for borderless windows unless we're willing to recreate them during a SDL_SetWindowBordered() call.

Wait, that's not true; XChangeWindowAttributes() can change this flag on an existing window.

I'm guessing it would cause problems to just change this flag right before moving the window and then change it back, especially over and over while dragging the window, so I still think we should close this.

slouken commented 3 weeks ago

I'm guessing it would cause problems to just change this flag right before moving the window and then change it back, especially over and over while dragging the window, so I still think we should close this.

Agreed. Positioning the window is just a request, and if the window manager policy is not to programmatically move windows outside the desktop area, that's fine.

icculus commented 3 weeks ago

Okay, closing. I would definitely recommend someone take this up with the Metacity (or whatever is the current thing) developers, though, since it seems like an incorrect thing to be doing at the window manager level.