SaifAqqad / AHK_MicMute

Control your microphone using keyboard and mouse hotkeys.
The Unlicense
165 stars 13 forks source link

Upon program start OnscreenOverlay "DisplayID" setting in config.json is replaced with value for only detected monitor even if configured for disconnected monitor #97

Closed successtheman closed 6 months ago

successtheman commented 7 months ago

Essentially if you have set the OnscreenOverlay to show on one monitor then disconnect or disable that monitor temporarily for whatever reason (I regularly use https://sourceforge.net/projects/monitorswitcher/ to manage my monitor layouts and switch between them), MicMute will edit and replace the previously set "DisplayID" in config.json with the currently connected monitor (not sure how it would behave if there were 2 monitors connected and the previously configured value was not able to be found but I assume it would be something similar, I have only tested with enabling just one monitor however). As a result when you reconnect the monitor, it then will be on the new monitor which was put in config.json instead of the one you had previously configured.

Would it be possible to preserve the "DisplayID" for when the monitor is reconnected once again instead of completely changing the "DisplayID" in config.json when the program detects a monitor as disconnected?

Could there be some fallback logic that doesn't edit the config.json and preserves the disconnected monitor positioning but just defaults OnscreenOverlay to the first monitor when the monitor in "DisplayID" in config.json can't be found?

successtheman commented 7 months ago

Might be related to this https://github.com/SaifAqqad/AHK_MicMute/issues/73#issuecomment-1636999519 and I have to change my config.json somehow? If this is the case could you fill me in on how I can make it so I don't lose positioning on disconnected monitors?

If I remove "DisplayID" from config.json it just adds it back when you close MicMute, so using an absolute offset wouldn't work

successtheman commented 7 months ago

So it appears it remembered the other monitor positioning now? I am very confused as I changed nothing 😂 this is an odd one. Nevermind I was mistaken (it is not remembering the original config), it is treating the 3rd monitor as if it is the first monitor I had my 2nd and 3rd monitors disabled when I turned on the PC, then switched using MonitorProfileSwitcher to enable all 3 and somehow, it's now on the far right on my 3rd monitor. I had originally set it to be on the left with the config before I discovered the bug, so yea it's not remembering the original config as I thought initially when I posted this comment. The odd thing is that when it started showing on the far right monitor, it didn't change the "DisplayID" value this time...

Anyways, let me know if you need any more information

SaifAqqad commented 6 months ago

Hey, I just tested the overlay position behavior, and it seems to work as intended, unless I'm misunderstanding the issue here.

When first setting up the overlay on a monitor, a relative position will be added to the config for that exact monitor (with its Id set to the monitor name and serial number)

image

Even if u add other monitors it should not replace a position for one monitor with another, only if you do move the overlay to the other monitor or disconnect the first monitor, in the former case it will immediately add a new entry for the new monitor with the relative positions u set, however in the latter case, the overlay will check if there is an entry in the Position array that matches the new monitor id, if there is, it will use it as is, and if there isn't, it will add a new entry for the new monitor with the same relative position of the first monitor

After adding a second monitor and moving the overlay onto it:

image

Note that the entries in the Position array are ordered based on most recently added (i.e. the first position will be for the last monitor you changed the position on), also you can manually change the order of the positions so that one monitor would be preferred over another when both are present.

also note that there was a bug with the DisplayId where sometimes the serial number would not be retrieved and so the DisplayId would just be the monitor's name followed by an _ this might cause issues if you have multiple monitors with the same name, though it should be fixed now with commit c5f3c3ef59187869deaeb08184ecebfe7cfbb2bc

successtheman commented 6 months ago

I just tested again and it still seems to not remember the disconnected monitor positioning, and upon closing MicMute and opening it again (to simulate rebooting the pc) it then replaced the DisplayID value with one of the monitors that was connected when the program was last closed instead of saving the previous value for a disconnected monitor in the config file and adding a new entry like in your screenshot.

It appears I might have fixed it by adding a secondary entry to the config like in your screenshot, so I will see if it sticks.

Anyway my idea is that it should just add a secondary entry to the list, instead of replacing the DisplayID value like it replaced the value in the config for me when I only had one entry in the list.

SaifAqqad commented 6 months ago

Yep, you're right.

if the second monitor is added after the first monitor is disconnected, it will replace the first monitor's position with a new position for the second monitor.

The code that's causing the issue: https://github.com/SaifAqqad/AHK_MicMute/blob/c5f3c3ef59187869deaeb08184ecebfe7cfbb2bc/src/UI/Overlay.ahk#L89-L106

Will hopefully fix it this weekend

SaifAqqad commented 6 months ago

I pushed a commit (0820feadbaebcb666720b9c06f1169c1f2b5836d) that should fix this issue, the overlay will now insert a new position for the other monitor instead of replacing the original one with it.

If you want, you can test it out in the dev build.
I will probably make a new release tomorrow though.

successtheman commented 6 months ago

Good to know I wasn't crazy, also thanks for this great software, I used to use the original one on sourceforge (which I think inspired this one if I am not mistaken)