Skip to content

On Ubuntu, focus switching fails after closing a window #223

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

Closed
rntz opened this issue Sep 19, 2020 · 7 comments
Closed

On Ubuntu, focus switching fails after closing a window #223

rntz opened this issue Sep 19, 2020 · 7 comments
Milestone

Comments

@rntz
Copy link

rntz commented Sep 19, 2020

On Ubuntu 20.04.1, Talon beta 1532.

Problem: focus SOME_APP doesn't always focus SOME_APP.

To reproduce: Have an app, let's assume firefox, with more than one window open. Focus one of those windows and close it. Make sure that when you do this, none of the apps' other windows come into focus - eg. by focusing some non-firefox window before you focus the firefox window to be closed, or by putting the other firefox windows on a different workspace. Now, say focus firefox. Alternatively, using the Talon repl, grab firefox directly from ui.apps() and call firefox.focus().

Expected behavior: some firefox window gets focused.
Actual behavior: nothing.

I don't think this is because of focus stealing blocking, as I have disabled that using a gnome extension: https://extensions.gnome.org/extension/1005/focus-my-window/. Happy to debug this further if there is more info that would help.

@lunixbochs
Copy link

can you repro or prove this should work with any command line tools?
can you check the window.id vs one of the command line tools that dumps x11 info?

@lunixbochs
Copy link

Bumping, would love someone with native linux to confirm whether this affects other app focusing CLI tools.

@rntz
Copy link
Author

rntz commented Dec 27, 2020

I have a guess what's going on here. Note that I wasn't calling focus on a Window object but on an App object, let's call it firefox (obtained via eg. ui.apps()[0]). This App object has a field firefox.active_window, which seems to be the most recently focused Firefox window. If I close that window and this causes focus to fall to a non-firefox window, then firefox.active_window is unchanged, and now points to a window that no longer exists. This much I have observed in the repl. (Also App.focus() returns a boolean for some reason, and it appears to always be True?)

I'm guessing that when I call firefox.focus() that calls firefox.active_window.focus() which does nothing since that window no longer exists. I've verified that calling firefox.active_window.focus() does nothing (and returns True) even if that window no longer exists, but I'm only guessing what firefox.focus() does.

As for command line tools that do this on linux, wmctrl can focus a window belonging to a particular 'class', which seems to correspond to an application in practice. Eg wmctrl -ax firefox.Firefox will focus some firefox window. However, it won't necessarily focus the most recently visited one if such exists, so it doesn't have exactly the behavior that talon should. But it will focus some window even in the situation that triggers this problem in talon. Also, wmctrl -ia ${ID} (which focuses a window by ID) will fail with an error message if you feed it the id of a closed window, so there seems to be some way to tell whether a window is closed when you try to focus it.

The behavior I personally would prefer talon have is to focus the most recently used window of that application on the current desktop, which is the same behavior that pressing super-<number> has on Ubuntu/Gnome, where <number> corresponds to the position of that application in the task bar. But that would change the way App.focus currently works, which selects the most recent window even if it's on another desktop. I also have no idea how Ubuntu/Gnome is doing this, nor if it could be made to work across distributions. Linux GUI stuff is messy like that :/.

@rexroni
Copy link

rexroni commented Jan 14, 2021

(edit: The issue turned out to be in my window manager, so this comment is safely ignorable)


I'm experiencing something similar after windows are closed:

(copying from this thread in the talon slack):

I'm seeing buggy behavior with ui hooks under X11. I have the following python module:

from talon import ui
def win_focus(window):
    print(f'win_focus: {window.title}')def win_title(window):
    print(f'win_title: {window.title}')ui.register('win_focus', win_focus)
ui.register('win_title', win_title)

When I start up talon, I see all of the window focus events I expect and all of the window title events I expect. If I create a new window, I still get a window title event but not a window focus event. Then if I close a window, and the next window I open is the same type of window (close a shell then open a shell, or close a pavucontrol then open a pavucontrol) that new window will cause win_focus and win_title to not work when switching to or from that new window.I have not reproduced this behavior with new firefox windows, but I suspect that has to do with the fact that new windows from firefox are still owned by a process which is not actually closing or something? I'm not closing my main firefox window. But I'm not sure.

@lunixbochs lunixbochs transferred this issue from talonvoice/beta Jan 27, 2021
@lunixbochs lunixbochs added this to the v0.2.0 milestone Jan 27, 2021
@lunixbochs
Copy link

should be fixed in latest beta, please reopen if you have another reproduction case

@rntz
Copy link
Author

rntz commented Jun 19, 2021

does not appear to be fixed for me? Same reproduction: have an app w/ more than one window open, close the window (arranging things so that another window of the same app does not get focus afterwards), run focus APPNAME. nothing happens.

on -393, ubuntu 20.04, default wm.

@rntz
Copy link
Author

rntz commented Jun 19, 2021

same underlying cause, too: an active_window which does not exist. after reproing, run:

>>> firefox = ui.apps()[WHATEVER]
>>> firefox.active_window in firefox.windows()
False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants