2

Well, the title almost says it all : Why should I not move a GUI (e.g. Gtk) window on screen from the code ? In Gtk 3 there was an API for moving windows on screen, but it was removed in Gtk 4, because it is not good to move a window from code; only the user should do so (don't ask me to provide sources for that, I read it somewhere but have forgotten where and cannot find it). But I cannot think of any reason why it shouldn't be good, but of several reasons why it could be good, for example to restore the position of a window between application restarts. Could you please shed some light on this ?

TheEagle
  • 5,808
  • 3
  • 11
  • 39

1 Answers1

3

The major reason why is that it can't possibly work cross-platform, so it is broken API by definition. That’s also why it was removed in GTK4. For example: this is impossible to implement when running on top of a Wayland session, since the protocol doesn't allow getting/setting global coordinates. If you still want to have something similar working, you'll have to call the specific platform API (for example, X11) for those platforms that you want to support.

On the reason why it’s not supported by some display protocols: it’s bad for UX and security. In terms of UX: some compositors can have special behavior because they need to work on a small device, or because they have a kiosk mode in which everything should always run fullscreen, or they provide a tiling experience. Applications positioning their windows themselves then tend to give unexpected behaviour. In terms of security: if you allow this, it’s technically possible for an application to reposition and resize itself so that it covers your screens while making itself transparent, without it being noticeable, which means it has the possibility of scraping all input.

nielsdg
  • 2,318
  • 1
  • 13
  • 22
  • 1
    `"Wayland session, since the protocol doesn't allow getting/setting global coordinates"` - but then how is the Gedit window move on Wayland by dragging it's `HeaderBar` around ? – TheEagle Jul 08 '21 at 16:39
  • Good question! It's better explained [here on wayland-book.com](https://wayland-book.com/xdg-shell-in-depth/interactive.html), but the general gist is: you need a Wayland extension like XDG Desktop, that provides an event which you can trigger as client, where you provide the serial number of the event that kickstarted the dragging operation. After that, the compositor takes over and will make sure the correct stuff happens. – nielsdg Jul 09 '21 at 20:01