Skip to content
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

Change focus when only screen changes #11

Open
yavuzkoca opened this issue Nov 20, 2020 · 57 comments
Open

Change focus when only screen changes #11

yavuzkoca opened this issue Nov 20, 2020 · 57 comments

Comments

@yavuzkoca
Copy link

I have two monitors and I only want to change the focus when mouse switches between the screens, not the apps. Is there any feature for this purpose?

@sbmpost
Copy link
Owner

sbmpost commented Nov 24, 2020

Interesting idea. This is not currently a feature, so I would have to think how difficult this is. For example I am not sure if Apple its APIs allow you to query on which screen the mouse is currently hovering. On the code level, Apple abstracts over multiple screens by adding all screen dimensions together, combining them into one large screen. But there may be other ways to figure out on which screen the mouse is.

@sbmpost
Copy link
Owner

sbmpost commented Jan 28, 2021

I thought some more about your idea. It seems iterating over the screens field in NSScreen to figure out which screen frame the mouse is currently in might do the trick. I am quite busy ATM however, so it might take a while before I can look into this further.

@R4dix
Copy link

R4dix commented Jun 17, 2021

Have you implemented this feature yet?

@sbmpost
Copy link
Owner

sbmpost commented Jun 17, 2021

@R4dix
With the limited time I have, my focus so far has been mainly on bug fixing. This feature is absolutely on my radar and hopefully I can find the time to implement it. Unfortunately I can't tell you exactly when that is.

@sbmpost
Copy link
Owner

sbmpost commented Jun 21, 2021

@yavuzkoca @R4dix
I found some time and created a new branch which can be downloaded here

To try this out, unzip the downloaded branch, and run:

make clean && make && ./AutoRaise -delay 1

Be sure to first stop any previous instances or they will interfere with this one.

If you are curious what changed, you can take a look here
Note this is a proof of concept, so may need some polishing still.
If this works well, the next step could be to make this a command line option.

@R4dix
Copy link

R4dix commented Jun 22, 2021

Thanks mate i will check it out immediately 👍

@sbmpost
Copy link
Owner

sbmpost commented Jun 23, 2021

@R4dix
Just curious if this is working like it should ;-)
And also: is it useful? :-)

@sbmpost
Copy link
Owner

sbmpost commented Jul 3, 2021

@R4dix hi there!
Do you have an update on this? I would like to know if this feature is something to consider for the master branch, or still needs polishing. Or perhaps it is not as useful as thought?

@R4dix
Copy link

R4dix commented Jul 5, 2021

My main purpose for this was using the inspector of Google Chrome without a second click and for this yes it works.
Thank you for that mate!

@sbmpost
Copy link
Owner

sbmpost commented Jul 7, 2021

@R4dix thanks! this is very helpful to know. I will see then if this can still be improved and at some point this might make it to the master branch

@AngryKiller
Copy link

It seems to be working fine, sometimes it does not recognizes that the cursor changes screen but that's rare and seems to only happen when the cursor is moved fast or when it hovers a notification banner before hovering a window.

@sbmpost
Copy link
Owner

sbmpost commented Jul 10, 2021

@AngryKiller thanks also for this feedback :)

@hasantahir
Copy link

Thanks @sbmpost for pointing me to the same feature request. I have tested the test branch linked here, and this is what I observed:

The desired functionality works only when the app is maximised to the whole screen. Behaviour below (On the same screen, Autoraise still works on smaller size windows.

autoraise_low

@sbmpost
Copy link
Owner

sbmpost commented Sep 17, 2021

@hasantahir

Thanks for this capture. Which osx version are you running? And are you sure that while testing, you were not running 2 AutoRaise instances at the same time? Can be checked with:

ps -aux | grep -v "AutoRaise"

It should return at most 1 running instance.

@hasantahir
Copy link

Thanks for pointing this out. The earlier process was indeed running.

@sbmpost
Copy link
Owner

sbmpost commented Sep 21, 2021

@hasantahir
No problem :)

@hasantahir
Copy link

I have been trying to make this work and would appreciate some suggestions on how to properly use this tool.

Let's say I have two windows open of a web browser, one on each of the monitors in the maximised mode. If I open other apps say a terminal, then are they supposed to be minimised when I hover to the other screen with the second window of the web browser? Behaviour in the GIF below:
Kapture 2021-10-06 at 14 47 57

Is it possible to keep the order/contents of one screen independent of the app? Or are there any bad habits that I need to let go? Thanks.

@sbmpost
Copy link
Owner

sbmpost commented Oct 6, 2021

@hasantahir
I think what you are trying to say is that when the browser window on the second screen gets raised, for some reason the terminal window on the first screen is pushed behind the browser window on the first screen, correct? The gif only shows a single screen so it is a bit hard to tell what is going on. Also you mentioned one of the browser windows is maximized. I assume it is not in "full screen" mode?

@hasantahir
Copy link

Yes exactly. I couldn't record the second screen simultaneously but raising the browser window causes apps to lose focus on the first screen. Also correct, neither of the browser windows are operating in the full screen mode, just maximised.

@sbmpost
Copy link
Owner

sbmpost commented Oct 7, 2021

@hasantahir

So you may see the effect that the application is activated as a whole and therefore on both screens at once as it is the same application. I am not sure if this can be changed. It might... Will have to investigate this.

@sbmpost
Copy link
Owner

sbmpost commented Oct 8, 2021

@hasantahir

If you are on OSX 11.6 or higher, you should change the "activate" code to this:

void activate(pid_t pid) {
    if (verbose) { NSLog(@"Activate"); }
    [[NSRunningApplication runningApplicationWithProcessIdentifier: pid]
      activateWithOptions: NSApplicationActivateIgnoringOtherApps];
} 

As far as I know, activating the application as a whole is the only way to set the keyboard focus to a certain window.
From AppKit.framework/Versions/C/Headers/NSRunningApplication.h:

NSApplicationActivateIgnoringOtherApps = 1 << 1
// You ALMOST NEVER want to pass this flag, because stealing key focus produces a very bad user experience.

This however is exactly what this tool is doing :-). From then on, it is up to the activated application to decide what happens. For instance it seems that both Chrome and Safari raise all of their windows if they are on different screens whereas Firefox and TextEdit do not. Being application specific, there is not much this tool can do about it unfortunately.

@hasantahir
Copy link

hasantahir commented Oct 14, 2021

@sbmpost thanks for kindly digging into this. I'll try to change my habits :-). Have also noticed that the Cmd + Tab combo for switching the apps produces the same behaviour.

@hasantahir
Copy link

Just wondering if there is a way to exploit Mission control for the per-window (item) type focusing on multiple screens.

@sbmpost
Copy link
Owner

sbmpost commented Mar 1, 2023

@hasantahir
A little late to mention this, but the focus only option (without raising) should kind of solve the issue that an app raises all its windows on activation.

@yavuzkoca @R4dix @AngryKiller
So far limiting the window raise to a screen change has been in a separate branch. But maybe this branch is now less relevant with aforementioned focus only option which has been in master for a while. Would you agree?

@sbmpost sbmpost closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2023
@hasantahir
Copy link

Fully agree. Thoroughly enjoying v3.7 with the stayFocusedBundledIds option.

Thanks, @sbmpost!

@umtiagopereira
Copy link

@sbmpost Hi! Just found your app yesterday, and I'm loving it, thanks for building this.

The "change focus only screen changes" option is still very important for me. I've download the app because of this.

I tried to use this alternative branch, but the bug that @hasantahir said is happening to me (all the windows unraise when the screen changes).

I tried to modify the code you proposed, but still, it wasn't working.

I also tried to activate the focus option on this branch and unable the raise option, but this didn't workout (even building the app with the flag).

Do you have any idea how could I achieve this? For me, either a option for focus only when changing screen or raise only when changing screen would work fine.

Thanks!

@sbmpost
Copy link
Owner

sbmpost commented Oct 13, 2023

@umtiagopereira @yavuzkoca @hasantahir @R4dix @AngryKiller
I have created another experimental branch implementing "focus only on change screen". The problem that a window on the first screen hides below the browser when moving the mouse to the second screen where another browser window resides, can be mitigated by disabling "raise" and rely on "focus only". In summary, I would suggest the following:

  1. checkout branch focus-only-on-change-screen
  2. stop previous AutoRaise instances (use Activitity Monitor to check)
  3. compile and run: make clean && make CXXFLAGS="-DOLD_ACTIVATION_METHOD -DEXPERIMENTAL_FOCUS_FIRST" && ./AutoRaise -focusDelay 1

@sbmpost
Copy link
Owner

sbmpost commented Oct 13, 2023

Maybe a bug that I found is that sometimes my mouse makes the scale and reposition effect when I change focus between windows, even that my settings are saying to disable it

To disable, simply omit/remove the warpX and warpY settings.

@umtiagopereira
Copy link

Maybe a bug that I found is that sometimes my mouse makes the scale and reposition effect when I change focus between windows, even that my settings are saying to disable it

To disable, simply omit the warpX and warpY settings.

Fixed! Thanks

@shijialee
Copy link

Hi, I have an extra screen besides my laptop and would like the mouse pointer focused on the app in different screen I switch to it by using alt-tab. Otherwise, I have to move the mouse to the focused app across screen which is a pain.

Is the focus-only-on-change-screen branch I need?

@umtiagopereira
Copy link

@shijialee, what do you want is that when you change to a window in another screen using alt-tab, the mouse pointer automatically moves to this new screen?

If so, I don't think you can do this right now. Maybe you could try the warp settings, but the problem is that your mouse would move every time you changed to a new window, even on the same screen.

For something like this to be possible, we would need a feature like "warp only on change screen."

@shijialee
Copy link

@umtiagopereira Yes. You understood me correctly. I got a HD cured screen which make moving mouse more pain.

tried warpX warpY setting and the mouse pointer is not moving.

@sbmpost
Copy link
Owner

sbmpost commented Oct 23, 2023

@shijialee

Assuming you only want to focus/raise on change of display, then for this branch, the cmd-tab key combination should still warp the mouse correctly if warpX and warpY settings are enabled. If this doesn't happen, then there might be a bug. I will check and report back to see if this is the case.

@shijialee
Copy link

shijialee commented Oct 26, 2023

@sbmpost

I didn't try the branch before. Now I did. The branch works beautifully with ./AutoRaise -focusDelay 1 -warpX 0.5 -warpY 0.5 Thank you!

@ishaanrathodd
Copy link

@yavuzkoca @R4dix I found some time and created a new branch which can be downloaded here

To try this out, unzip the downloaded branch, and run:

make clean && make && ./AutoRaise -delay 1

Be sure to first stop any previous instances or they will interfere with this one.

If you are curious what changed, you can take a look here Note this is a proof of concept, so may need some polishing still. If this works well, the next step could be to make this a command line option.

Can You include this in app version? This is EXACTLY what i need

@sbmpost
Copy link
Owner

sbmpost commented Feb 2, 2024

@ishaanrathodd

I can but I don't know when because I am very much occupied at the moment. Thanks however for this feedback so I know it is worth including indeed ;-)

@ishaanrathodd
Copy link

ishaanrathodd commented Feb 3, 2024 via email

@ishaanrathodd
Copy link

@ishaanrathodd

I can but I don't know when because I am very much occupied at the moment. Thanks however for this feedback so I know it is worth including indeed ;-)

For the upper command line version, if it is possible, can you give me a detailed step by step process on how to enable change focus only when changing screens and also only enabling focus change and not raise window? and if anything goes wrong how to delete it. It would be a great help!

@sbmpost
Copy link
Owner

sbmpost commented Feb 3, 2024

@ishaanrathodd

can you do something like add delay while shifting through windows in the same screen but 0 delay and direct focus on the window on another screen as soon as you change your screen(external monitor)?

This is an interesting idea. Then to disable it completely for the same screen the delay could be set to zero. I will consider adding this when time allows me to.

@sbmpost
Copy link
Owner

sbmpost commented Feb 3, 2024

@ishaanrathodd

For the upper command line version, if it is possible, can you give me a detailed step by step process on how to enable change focus only when changing screens and also only enabling focus change and not raise window?

The README should provide you with all the information you need. Please give that a try and if that fails, I am here to help.

@ishaanrathodd
Copy link

@ishaanrathodd

For the upper command line version, if it is possible, can you give me a detailed step by step process on how to enable change focus only when changing screens and also only enabling focus change and not raise window?

The README should provide you with all the information you need. Please give that a try and if that fails, I am here to help.

i did definitely read the readme but as far as the command line version goes, im so lost. I tried using it through command line but im not sure how to do it as it doesnt seem to recognise autoraise. Other than that i have doubts on how to reset to default values or disable ceratin features like warp through command line.

@ishaanrathodd
Copy link

@ishaanrathodd

can you do something like add delay while shifting through windows in the same screen but 0 delay and direct focus on the window on another screen as soon as you change your screen(external monitor)?

This is an interesting idea. Then to disable it completely for the same screen the delay could be set to zero. I will consider adding this when time allows me to.

thank you :)

@sbmpost
Copy link
Owner

sbmpost commented Feb 4, 2024

@ishaanrathodd

i did definitely read the readme but as far as the command line version goes, im so lost

In that case perhaps it is better if I compile a UI version. Will do that sometime coming week

@ishaanrathodd
Copy link

@ishaanrathodd

i did definitely read the readme but as far as the command line version goes, im so lost

In that case perhaps it is better if I compile a UI version. Will do that sometime coming week

Alright! Honestly the real use case for this app (my pov) is genuinely just avoiding that extra click when we want visible apps open at the same time on the visible screens and browse between them without that extra click to focus. Doesn't really make sense to enable focus on window change in the SAME display because its very inconvenient, sometimes you want to copy text from a window but if the cursor is out of window you do not notice it and the operation is not completed as some other window is focused by then, etc. There are many loop holes i found in this implementation and to keep it turned off as of now seems the best option for me. Triggering "focus follows cursor" ONLY WHEN CHANGING DISPLAY seems the best use case (i think people just use command tab to shift between windows focus in the SAME display because you really don't have that much space to keep all windows visible at the same time in the same display so "focus follows cursor" doesnt make sense in just 1 display.) This is my point of view, people might still make use out of the available features. Triggering focus follows cursor only when the cursor changes screens and then again turning the "focus follows cursor" feature off until the cursor moves to a different screen is an incredible feature and would really be useful, delay should obviously be 0 for prompt action. Thank you so much for understanding my use case! Would be waiting to try this feature soon!

@sbmpost
Copy link
Owner

sbmpost commented Feb 9, 2024

@ishaanrathodd

I guess it is a matter of taste. Personally I have the focus only feature enabled (without raise) for every window regardless of the display it is in. The loop holes you describe are not so much an issue for me, maybe because I got very used to how it works now.

About the binary version: this is still on my todo list but I got ill these last 2 days with a nasty fever. Fortunately today I feel a lot better already but I will have to postpone the binary until next week.

Thanks for taking the time to explain your use case. It is good to know how AutoRaise is being used so it can be improved upon :-)

@ishaanrathodd
Copy link

week.

sure ofcourse! this was my pov. I would wait until next week no problem! The app is really useful.

@sbmpost
Copy link
Owner

sbmpost commented Feb 14, 2024

@ishaanrathodd

I would wait until next week no problem!

The binary has been updated in this branch.

@ishaanrathodd
Copy link

@ishaanrathodd

I would wait until next week no problem!

The binary has been updated in this branch.

WORKS! Thank you so muchhhh man!

@kjyv
Copy link

kjyv commented Feb 15, 2024

I've tested this a little and it seems I can only use this with window raising, not only focus change. I'm starting with ./AutoRaise -delay 2.
Btw, how to also build the nice little UI that is included in the dmg?

@ishaanrathodd
Copy link

@ishaanrathodd

I would wait until next week no problem!

The binary has been updated in this branch.

WORKS! Thank you so muchhhh man!

There are a few things. If i have one external monitor and i have youtube in fullscreen mode, and i move my cursor from there to main screen of laptop, the focus doesnt shift. I understand this also happens if a popup window from an app (like settings pane) also produces the same problem. Is this a system problem as it doesnt seem like a bug and is very consistent across? Focus only activates if im moving from one window to other without having opened any pop up windows of either apps.

@sbmpost
Copy link
Owner

sbmpost commented Feb 19, 2024

@ishaanrathodd

Those things will have to be looked at. Having AutoRaise only enabled on screen change introduces various side effects. It is for this reason it never became part of the main branch. This branch is more an experimental one. Still there seems to be a demand for this feature so it could be worth adding it. I am very busy however so it may take some time.

@sbmpost
Copy link
Owner

sbmpost commented Feb 19, 2024

@kjyv

I've tested this a little and it seems I can only use this with window raising, not only focus change. I'm starting with ./AutoRaise -delay 2.

Try with: ./AutoRaise -focusDelay 1

Btw, how to also build the nice little UI that is included in the dmg?

With Xcode. In addition it requires an Apple Developer ID to get it signed and notorized. It is quite a hassle. However the UI code can be found in the AutoRaise-UI repository.

@kjyv
Copy link

kjyv commented Feb 19, 2024

This yields the same behaviour, all windows are raised, not just focused. If I use -focusDelay 1 -delay 0, nothing happens at al. focusDelay is not in the usage message btw.

I'll check out the UI, thanks.

@sbmpost
Copy link
Owner

sbmpost commented Feb 19, 2024

@kjyv

focusDelay is not in the usage message btw.

Which tells me that the AutoRaise binary you are running hasn't been compiled with the EXPERIMENTAL_FOCUS_FIRST flag enabled. This is further documented in the README. In short:

make clean && make CXXFLAGS="-DOLD_ACTIVATION_METHOD -DEXPERIMENTAL_FOCUS_FIRST" && ./AutoRaise -focusDelay 1

@kjyv
Copy link

kjyv commented Feb 20, 2024

Ah, sorry for the confusion then - it does work fine now!

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

No branches or pull requests

9 participants