noc icon indicating copy to clipboard operation
noc copied to clipboard

noc_file_dialog: Specify timestamp to focus dialog for GTK

Open mborgerson opened this issue 5 years ago • 5 comments

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:

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

mborgerson avatar Mar 25 '20 10:03 mborgerson

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.

thp avatar Nov 29 '20 10:11 thp

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.

guillaumechereau avatar Nov 30 '20 04:11 guillaumechereau

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?

mborgerson avatar Dec 01 '20 19:12 mborgerson

You are right. I was checking with some local changes I think. Let me check again...

guillaumechereau avatar Dec 02 '20 06:12 guillaumechereau

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.

guillaumechereau avatar Dec 02 '20 06:12 guillaumechereau