AutoRaise icon indicating copy to clipboard operation
AutoRaise copied to clipboard

Change focus when only screen changes

Open yavuzkoca opened this issue 4 years ago • 58 comments

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?

yavuzkoca avatar Nov 20 '20 09:11 yavuzkoca

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 avatar Nov 24 '20 14:11 sbmpost

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.

sbmpost avatar Jan 28 '21 12:01 sbmpost

Have you implemented this feature yet?

R4dix avatar Jun 17 '21 07:06 R4dix

@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 avatar Jun 17 '21 19:06 sbmpost

@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.

sbmpost avatar Jun 21 '21 17:06 sbmpost

Thanks mate i will check it out immediately 👍

R4dix avatar Jun 22 '21 06:06 R4dix

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

sbmpost avatar Jun 23 '21 14:06 sbmpost

@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?

sbmpost avatar Jul 03 '21 08:07 sbmpost

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!

R4dix avatar Jul 05 '21 06:07 R4dix

@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

sbmpost avatar Jul 07 '21 08:07 sbmpost

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.

AngryKiller avatar Jul 07 '21 12:07 AngryKiller

@AngryKiller thanks also for this feedback :)

sbmpost avatar Jul 10 '21 10:07 sbmpost

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

hasantahir avatar Sep 15 '21 16:09 hasantahir

@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.

sbmpost avatar Sep 17 '21 11:09 sbmpost

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

hasantahir avatar Sep 20 '21 08:09 hasantahir

@hasantahir No problem :)

sbmpost avatar Sep 21 '21 17:09 sbmpost

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.

hasantahir avatar Oct 06 '21 13:10 hasantahir

@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?

sbmpost avatar Oct 06 '21 19:10 sbmpost

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.

hasantahir avatar Oct 06 '21 20:10 hasantahir

@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 avatar Oct 07 '21 06:10 sbmpost

@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.

sbmpost avatar Oct 08 '21 14:10 sbmpost

@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 avatar Oct 14 '21 09:10 hasantahir

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

hasantahir avatar Oct 21 '21 13:10 hasantahir

@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 avatar Mar 01 '23 20:03 sbmpost

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

Thanks, @sbmpost!

hasantahir avatar Mar 17 '23 11:03 hasantahir

@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!

umtiagopereira avatar Oct 12 '23 15:10 umtiagopereira

@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 avatar Oct 13 '23 11:10 sbmpost

@sbmpost You are amazing! After creating a config file it's working nicely. Thanks!

umtiagopereira avatar Oct 13 '23 14:10 umtiagopereira

@sbmpost

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:

CleanShot 2023-10-13 at 11 24 07

Ah, just a feature suggestion for the future. Having a option to "focus only when shortcut is pressed" would be awesome. Like the inverse of the disable shortcut. Like for situations where I want to copy a text below the active windows but don't want to raise the window.

https://github.com/sbmpost/AutoRaise/assets/145727709/04507764-555d-479b-8d80-397bcfaafe9e

umtiagopereira avatar Oct 13 '23 14:10 umtiagopereira

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.

sbmpost avatar Oct 13 '23 18:10 sbmpost