noc
noc copied to clipboard
noc_file_dialog: Specify timestamp to focus dialog for GTK
GNOME has a "focus stealing prevention" feature that will open new windows in the background to prevent the keyboard focus from being stolen from a user, and show an "<Application> is ready" notification.
This feature currently impacts file dialog creation resulting in the dialog being confusingly spawned in the background on every creation after the first with the GTK implementation.
This patch adds a call to gtk_window_present_with_time() with the current time, enforcing that the dialog always makes it to the top of the window stacking order and receives focus.
I believe this is the simplest/best way to handle this for my application of responding to a button click without convenient access to this necessary event token/timestamp, but I welcome someone with more experience with GTK to weigh in here with a better solution. Note that I've not tested with Wayland.
Some information about the issue/feature:
- https://gitlab.gnome.org/GNOME/mutter/issues/673
- https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/358
- An example solution from network-manager-applet
- Another example solution from chromium UI
Tagging other, similar projects I came across while searching for solutions which might be interested in this:
- https://github.com/mlabbe/nativefiledialog/issues/79
- https://github.com/gkngkc/UnityStandaloneFileBrowser/issues/49
If anybody tries to reproduce this issue: This bug seems to happen only on X11, not on Wayland, but the fix presented here indeed fixes the issue for me.
Hello, it seems that this pull requests removed the:
#ifndef NOC_INCLUDE_NOC_FILE_DIALOG_H
Because of that it doesn't compile properly anymore.
Hello, it seems that this pull requests removed the:
#ifndef NOC_INCLUDE_NOC_FILE_DIALOG_H
Because of that it doesn't compile properly anymore.
Looking at the diff I do not see such a change. Have you pulled the code cleanly?
You are right. I was checking with some local changes I think. Let me check again...
I got this error at compilation time:
./noc_file_dialog.h:141:9: error: ‘GDK_IS_X11_DISPLAY’ was not declared in this scope; did you mean ‘GDK_IS_DISPLAY’?
141 | if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
I haven't checked the code for a long time. I also got a few warnings from the original code. I'll try to have a look that that first.