FedoraQt / QGnomePlatform

QPlatformTheme for a better Qt application inclusion in GNOME
GNU Lesser General Public License v2.1
262 stars 38 forks source link

Prevent window from losing focus while moving or resizing #128

Closed polter-rnd closed 1 year ago

polter-rnd commented 1 year ago

Experimental fix for nasty bug with losing window focus -- #115 or https://github.com/FedoraQt/adwaita-qt/issues/170

This is really a dirty hack, but it actually works. Only for Wayland.

One can test it using my copr repo

grulja commented 1 year ago

This sounds like a bug in QtWayland, I don't think we should be trying to workaround this on our side.

polter-rnd commented 1 year ago

I agree that this fix is quite suspicious and I'm not sure if it should be merged, but let me share my findings first.

I also thought that it's a bug in qtwayland, but apparently I was incorrect. That's true that window dimming is present since commit e532733 (which you have backported to Fedora's Qt5). But this commit has not introduced a bug, it has fixed the inconsistent behavior instead. That's because of the way Qt handles focus -- it uses keyboard focus to select active or inactive palette to draw. And when we click on the decoration to move or resize the window, application loses keyboard focus, so it has to be drawn inactive. However until e532733 qtwayland relied on Xdg hint for that (so that dimming was not occurring), while xcb backend not, that was inconsistent and was a bug. But the decoration itself should not be drawn inactive in that case, that's why they introduced wayland-specific windowStates() in that commit to check for Xdg hints, which we're using to fix titlebar dimming.

So to be short, the dimming of widgets is not specific to wayland backend, it occurs on xcb as well and looks like it's an intended behavior. I didn't notice that because I use wayland daily, and on xcb+XWayland it does not occur because of XWayland limitation -- I guess that's because Xwayland doesn't pass events happening with the decoration to the app itself.

To summarize:

Why nobody complains about that - I think because they don't use Inactive palette for that purpose, like in Fusion or Breeze style in KDE, window itself never becomes greyed-out even if it's not focused, only titlebar is drawn inactive. But GTK behaves differently and draws the whole app inactive in that case, and adwaita-qt tries to minic it as much as possible and that's great, however it leads to dimming.

How can it be fixed, from my opinion:

  1. Change focus detection logic somewhere in Qt core (very unlikely, I think it's an intended behavior for xcb and wayland platforms and won't be changed);
  2. Don't use Inactive palette in adwaita-qt style -- that will make app never greyed out and worsen GTK look and feel;
  3. Introduce a hack somewhere in adwaita-qt - I tried that, but it's much more tricky, needs access to private Qt API and slows down rendering a lot;
  4. The hack in QGnomePlatform above :)
grulja commented 1 year ago

QGnomePlatform is now unmaintained and not actively developed. For decoration improvements please submit your change to https://github.com/FedoraQt/QAdwaitaDecoration instead.