Skip to content

bring_to_front_and_focus implementation on gtk #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 3, 2020
Merged

bring_to_front_and_focus implementation on gtk #1104

merged 2 commits into from
Aug 3, 2020

Conversation

Kartoffelsaft
Copy link
Contributor

This should be a working implementation of the bring_to_front_and_focus function for the WindowHandle mentioned in #295.

Also, I noticed that this focus function has a documentation comment above it but the function below just has a regular comment. I didn't bother to change it as it seemed unrelated to what I was doing, and I didn't know if that was intentional. The documentation seems to have gotten it anyway.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch!

I would trust the GTK docs on this, and use present_with_time instead. From a quick reading it looks like the 'timestamp' is generally something that is associated with an event; it also says that we can pass GDK_CURRENT_TIME to use the current timestamp, so I would try that?

@jneem
Copy link
Collaborator

jneem commented Jul 28, 2020

This gtk API is probably derived from the x11 API, where when you request input focus you're supposed to supply the timestamp of the event that made you want to request input focus. As I recently learned in #1045, you aren't allowed to use the current time; it has something to do with focus stealing prevention. The relevant snippet from ICCCM is

Clients that use a SetInputFocus request must set the time field to the timestamp of the event that caused them to make the attempt. [...] Note that clients must not use CurrentTime in the time field.

The underlying issue here is that the druid-shell API doesn't allow for a meaningful timestamp. But given that constraint, there's actually no difference between present and present_with_time(GDK_CURRENT_TIME). I just checked the gtk source:

void
gtk_window_present (GtkWindow *window)
{
  gtk_window_present_with_time (window, GDK_CURRENT_TIME);
} 

@Kartoffelsaft
Copy link
Contributor Author

Given what @jneem said, I think it should be left at present, as using present_with_time implies that we know what timestamp to use, which we don't. That said, I do think that a // TODO: should be added to indicate that present_with_time should be used if and when the timestamp could be known.

And having looked at the GTK source myself, it does do some conversion so that it doesn't break the X11 side of things:

gtk_window_present_with_time (GtkWindow *window,
			      guint32    timestamp)
{
// ...
      if (timestamp == GDK_CURRENT_TIME)
        {
// #ifdef ...
	      timestamp = gdk_x11_display_get_user_time (display);
// #endif ...
	    timestamp = gtk_get_current_event_time ();
        }

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks for the explanation!

@cmyr cmyr merged commit 7aa9f7c into linebender:master Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants