seerge / g-helper

Lightweight Armoury Crate alternative for Asus laptops and ROG Ally. Control tool for ROG Zephyrus G14, G15, G16, M16, Flow X13, Flow X16, TUF, Strix, Scar and other models
https://g-helper.com
GNU General Public License v3.0
7.61k stars 266 forks source link

Active window loses focus when screen is turned off and then on again #2339

Closed pan2357 closed 7 months ago

pan2357 commented 7 months ago

Rules

What's wrong?

On new versions of g-helper, when the display is turned off then on again, the active window will lose focus. The last known version to not have this issue is 0.141, which I am currently using.

I have set the Fn+F11 (sleep) button to "Turn off the display" in Control Panel. I also sometimes use an AutoHotkey script SendMessage 0x112, 0xF170, 2,, "Program Manager" to turn off the display. All these does is turn off the display. The display can be turned on again by pressing any key on the keyboard or moving the mouse pointer.

Please see the example in the attached videos.

How to reproduce the bug?

Set the sleep key to turn off the display for ease of testing

  1. Go to "Control Panel"
  2. Go to "System and Security"
  3. Go to "Power Options"
  4. Go to "Choose what the power buttons do" on the upper left corner
  5. Change "When I press the sleep button" to "Turn off the display"

Actual testing

  1. Go to any window
  2. Click anywhere inside the window
  3. Press tab a few times until you see some text being highlighted
  4. Press your sleep button, e.g. Fn+F11 on my 2020 model
  5. The screen will turn off
  6. Wait a few seconds
  7. Move your mouse pointer
  8. The screen will turn on
  9. The highlighted text in step 3. is not highlighted anymore
  10. Press tab a few times, there will not be any changes on the active window (as in no text will be highlighted like before we turn off the screen in step 3.)

Logs

log.txt

I have turned the screen off then on at

Device and Model

Asus Zephyrus G14 GA401IH

Additional information.

Normal behavior

https://github.com/seerge/g-helper/assets/70005659/d8e1ab9d-b72e-4d8b-bf4e-6583a4aaf481

Has issue

https://github.com/seerge/g-helper/assets/70005659/3cf2c971-20c5-4c94-bb78-e923320382f4

Note

Sorry for the poor quality of the video as I cannot find a way to directly record the screen and show that it is off.

Armoury Crate

Never installed

Asus Services

0

Version

0.164

OS

Windows 11 23H2

seerge commented 7 months ago

@pan2357 hello, I don't really think it's something connected with G-Helper honestly :)

Hotkey Fn-F11 just emits an asus own sleep command. That's it. Nothing else.

2024-03-30 20:38:58: Key: 108
2024-03-30 20:38:58: Sleep = 108 : 0

And it's same in 0.141 as now (more over it didn't really change since was added) https://github.com/seerge/g-helper/blob/f94d76aab984ba86a6cdc493202e5878ceb49d97/app/Input/InputDispatcher.cs#L505 https://github.com/seerge/g-helper/blob/f94d76aab984ba86a6cdc493202e5878ceb49d97/app/Input/InputDispatcher.cs#L659

Can you just quit g-helper and put your device to sleep and see if that window focus changes or not ? Can you run older version (0.141 as you say) of the app now and see if it's same ?

seerge commented 7 months ago

@pan2357 on a side note I don't have "turn off display" option for sleep button in control panel settings Screenshot 2024-03-30 150206

And I have tried it on my device, active window stays active even after waking up ...

pan2357 commented 7 months ago

Strange. I have these image

seerge commented 7 months ago

@pan2357 but anyway I can't reproduce it

I have even tried SendMessage 0x112, 0xF170, 2,, "Program Manager" method (under Extra you can bind macro keys to "Toggle Screen" and under the hood it does exactly that).

My windows always stay in focus :) And it's actually logical. G-Helper doesn't really touch focus from other windows anyhow ...

P.S. What window does get focus instead ?

pan2357 commented 7 months ago

@seerge I have tried to put the device to sleep, by pressing the power button, then turn it back on. The results are

However, if I try the same thing with Fn+F11

Looks like Fn+F11 will not register any command if g-helper is not running.

P.S. I am not sure which window does get focused either. On the taskbar, the current window is still highlighted. However, the title bar's color is a bit lighter than normal, which suggests that it is not focused.

seerge commented 7 months ago

@pan2357

However, if I try the same thing with Fn+F11 No g-helper is running => nothing happen g-helper 0.141 => focus does not change g-helper 0.164 => focus does not change

So both versions work correct ?

FN+F11 won't work without G-Helper or Asus Services running

pan2357 commented 7 months ago

@seerge

So both versions work correct ?

Yes, that is if you use it to put the computer to sleep.

P.S. What window does get focus instead ?

I have tried again. After the screen is turned on, it is g-helper that get focused. I always run it minimized in the taskbar, so I did not see this.

seerge commented 7 months ago

@pan2357 ok, can you find first version (i.e. 0.142 ?) where this behavior changes ? Then I will be able to compare changes and at least try to guess a reasons for you.

As currently gap between 0.141 and 0.164 is huge :)

pan2357 commented 7 months ago

@pan2357 ok, can you find first version (i.e. 0.142 ?) where this behavior changes ? Then I will be able to compare changes and at least try to guess a reasons for you.

As currently gap between 0.141 and 0.164 is huge :)

You mean run the test (turn off the screen then on) and upload the log file here?

seerge commented 7 months ago

@pan2357 you say that it works OK in 0.141. So try to find first build (after 0.141) that doesn't work as you want.

pan2357 commented 7 months ago

@seerge Found it, 0.143 is the first one that does not work.

seerge commented 7 months ago

@pan2357 ok, it was a lot of changes in the app to support blind people and narrator support.

Nothing related to sleep / screen off

It could be that something related to narrator triggers windows to set focus to g-helper window instead

Try this build

GHelper.zip

pan2357 commented 7 months ago

@seerge

Try this build

GHelper.zip

This build works (focus does not change to g-helper).

seerge commented 7 months ago

@pan2357 ok, that was fast . I was expecting to test more things ....

Github has closed it automatically when I pushed tweak :) but i guess that's ok