-
Notifications
You must be signed in to change notification settings - Fork 132
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
app,io/system: [API] add StageInactive when window is not in focus #92
Conversation
Currently, the behavior of "focus" is defined by the OS, which doesn't match very well. On Windows, the "focus" is lost when some children is focused, on MacOS it's not, but there's another event for that case. However, the FocusEvent can be improved once Gio have better support for children windows. |
app/os_x11.go
Outdated
@@ -619,8 +619,10 @@ func (h *x11EventHandler) handleEvents() bool { | |||
redraw = (*C.XExposeEvent)(unsafe.Pointer(xev)).count == 0 | |||
case C.FocusIn: | |||
w.w.Event(key.FocusEvent{Focus: true}) | |||
w.w.Event(system.FocusEvent{Focus: true}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere you send a system.FocusEvent when a key.FocusEvent is also sent. Why is key.FocusEvent not enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key.FocusEvent
is going to be consumed by the foremost key handler, which may be deeply nested within application layout code. Wanting to change a window behavior based on the window focus state is a much higher-level concern. One user asked for this focus detection feature in order to build a dmenu-esque application launcher. If the window loses focus, they want to close the window. Doing that by interrogating the state of every widget to see if any of them are focused doesn't seem like the right design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't use key.FocusEvent because of the reason mentioned by @whereswaldon. Also, the FocusEvent can work differently from key.FocusEvent.
I force-push to make the behavior differently. Now, the FocusEvent is only triggered when the window loses focus, instead of the keyboard focus. The word "focus" could be changed to "active", or something else.
app/os_windows.go
Outdated
case windows.WM_NCACTIVATE: | ||
w.w.Event(system.FocusEvent{Focus: wParam == windows.TRUE}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Windows, the KILLFOCUS
happens when another window have keyboard focus, which might also happens when some child window is in focus. The NCACTIVATE
sounds better, since it report when the window decoration should update.
This difference between macOS and WIndows is fixed by #93, right?
Thanks for explaining. I agree that it would be useful to know the active state of an app.Window, separate from the focus. However, I'm not sure a separate event is necessary. Why not expand |
I initially thought about adding a new However, I'm not sure how the new Stage will work, because we have some checks: Lines 828 to 835 in b67bef3
Currently, the Lines 61 to 67 in b5f12c5
But, in the case of "not in focus" it's both of them, at same time. It's inactive at the perspective of the user, but it's active because it can generate new frames (it still displayed on the screen). I don't think that it makes sense but maybe we can use |
FocusEvent could work if we can't cram the focused/active state into Stage.
This check (and similar) should change to
Stage was designed to be an integer of increasing "liveness" of the window. So for active, inactive:
|
9315868
to
dab39c8
Compare
726f626
to
5109d18
Compare
Now, Gio will send one system.StageEvent with system.StageInactive when the window is not active. That is currently implemented to MacOS and Windows. This change is not fully backward compatible, if your code compares the Stage (`stage < system.StageRunning`), you need to consider the new system.StageInactive. Signed-off-by: Inkeliz <inkeliz@inkeliz.com> Signed-off-by: inkeliz <inkeliz@inkeliz.com>
Sorry for a lot of force pushes, but there's no change between them. That fixed comparison, as you suggest. |
Merged, thanks! |
Now, Gio will notify when window focus changes.
Signed-off-by: Inkeliz inkeliz@inkeliz.com