-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Use a powershell script to manage focus on Windows #5
Conversation
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.
This is fine for me! Thank you for looking into it.
Does the Windows version work now?
It's disappointing (and honestly a bit strange) that bring_to_front
does not bring to front. I'd love to use the native API. Does this thread contain anything useful? sublimehq/sublime_text#444
A comment mentions:
other_window.focus_view(other_window.views()[0])
other_window.bring_to_front()
dd39621
to
9088caf
Compare
if NATIVE_FOCUS_WINDOW: | ||
self.window.bring_to_front() |
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.
By the way I'd probably use feature detection rather than version sniffing. Something like:
if NATIVE_FOCUS_WINDOW: | |
self.window.bring_to_front() | |
if hasattr(self.window, 'bring_to_front'): | |
self.window.bring_to_front() |
In JS I'd just write self.window.bring_to_front?.()
but it doesn't look like Python has that
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.
Yeah, beacuse the (possible) environments in Web development are basically
hostile and complex.
Here in ST land, we would rather tell Package Control a ST3 version of
this plugin, and then go on with ST4 without version sniffing, IMO. Likely
that ST3 version would be final too as the code is stable since years, well
before I came at least.
Fixes GhostText#4 Sublime Text's `bring_to_front` politely asks for the focus which is often not enough when a browser has input focus. But a) if it does it is instant and b) it helps when all windows are minimized. As we cannot check if `bring_to_front` actually did what we want, use the scripts we always had here too, unconditionally. For Windows, replace the used method with a powershell script which works on newer Windows versions without installing the rather idiosyncratic "nircmd". Unfortunately Linux still needs a tool ("xdotool").
9088caf
to
0f624ac
Compare
I did restore the This is because at least the powershell script doesn't work when Sublime only As for
this does not help because the OS prevents stealing the focus when a browser We only do this because we enhance the editing of the textarea element. We're |
I tried that and it doesn't seem to be right (at least in macOS and Safari). I tried:
Note: There's one field on the page, the user does not need to select it |
Anyway it looks good, it can be merged if ready |
For Windows there are several rules https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow#remarks If I click on an icon in the browser that is also a clear interaction with that I just don't know why it sometimes works. From that I get the feeling we just need to call The simple powerscript approach isn't 100% though, and I hate that. If it doen't work often |
I think there are a few ways GhostText could go about this in the future, like setting a The challenge there would be that not every editor can be set up to handle such a protocol, so it would be less flexible (I'm not a fan of that) |
By the way some input would be welcome here if you have any opinions: |
Fixes #4
Revert cd1a2d5 as Sublime Text's
bring_to_front
politely asks for the focus which is usually not enough when a browser has input focus.Since we have a builtin method for MacOs in place just implement a powerscript equivalent for Windows.
Unfortunately Linux then still needs a tool ("xdotool").