klesh / JigsawWM

JigsawWM is a dynamic window manager for Windows10/11 just like the suckless dwm for the X
GNU Lesser General Public License v3.0
140 stars 5 forks source link

error message "invalid monitor handle" when starting example #9

Closed nnako closed 4 months ago

nnako commented 4 months ago

Hi,

starting about two weeks ago, JigsawWM suddenly will not operate correctly when I start my widescreen example.

Normally, I start a batch script which opens the virtual environment and starts the example from the repo:

:: walk into local source folder for files
c:
cd c:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM

:: walk into virtual environment
call _venv\Scripts\activate

:: start tooling
python examples\nnako.pyw

Then the windows which I have placed on my big screen get arranged and I am given the control over the functionality by hotkeys as defined within the example. But now, after arranging the windows, I get error messages within the console. And I can only exit by pressing <CTRL> + <C>.

I did no change to the code for months. Maybe the Windows OS changed its behaviour and the implemented JigsawWM interface is not able to work out these differences? At least, the error essentially shows an "invalid monitor handle".

What could this be? Where should I start looking for the cause within the code?

Here the debug and error outputs from the console (it is essentially the same error code block printed four times, which seems odd to me as well):

arrange None static_bigscreen_8
arrange None static_bigscreen_8
arrange None static_bigscreen_8
Uncaught exception:
   File "c:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\examples\nnako.pyw", line 51, in <module>
    wm = WindowManager(
         ^^^^^^^^^^^^^^
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\manager.py", line 90, in __init__
    self.sync(init=True)
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\manager.py", line 189, in sync
    monitor_state.sync(
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\state.py", line 117, in sync
    self.arrange(theme)
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\state.py", line 126, in arrange
    wr = self.monitor.get_info().rcWork
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\w32\monitor.py", line 156, in get_info
    raise WinError(get_last_error())

OSError: [WinError 1461] Ungültiges Handle für den Monitor.
Traceback (most recent call last):
  File "c:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\examples\nnako.pyw", line 51, in <module>
    wm = WindowManager(
         ^^^^^^^^^^^^^^
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\manager.py", line 90, in __init__
    self.sync(init=True)
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\manager.py", line 189, in sync
    monitor_state.sync(
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\state.py", line 117, in sync
    self.arrange(theme)
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\state.py", line 126, in arrange
    wr = self.monitor.get_info().rcWork
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\w32\monitor.py", line 156, in get_info
    raise WinError(get_last_error())
OSError: [WinError 1461] Ungültiges Handle für den Monitor.
2024-03-16 07:30:13,426 [MainThread  ] [CRITI]  Uncaught exception:
   File "c:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\examples\nnako.pyw", line 51, in <module>
    wm = WindowManager(
         ^^^^^^^^^^^^^^
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\manager.py", line 90, in __init__
    self.sync(init=True)
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\manager.py", line 189, in sync
    monitor_state.sync(
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\state.py", line 117, in sync
    self.arrange(theme)
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\state.py", line 126, in arrange
    wr = self.monitor.get_info().rcWork
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\w32\monitor.py", line 156, in get_info
    raise WinError(get_last_error())

OSError: [WinError 1461] Ungültiges Handle für den Monitor.
Traceback (most recent call last):
  File "c:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\examples\nnako.pyw", line 51, in <module>
    wm = WindowManager(
         ^^^^^^^^^^^^^^
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\manager.py", line 90, in __init__
    self.sync(init=True)
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\manager.py", line 189, in sync
    monitor_state.sync(
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\state.py", line 117, in sync
    self.arrange(theme)
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\wm\state.py", line 126, in arrange
    wr = self.monitor.get_info().rcWork
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\w32\monitor.py", line 156, in get_info
    raise WinError(get_last_error())
OSError: [WinError 1461] Ungültiges Handle für den Monitor.
klesh commented 4 months ago

@nnako Can you print the self._hmon and see if it had valid value?

nnako commented 4 months ago

Hi @klesh

I see the following behaviour:

after setting a breakpoint to

C:\Users\USER\_NEXTCLOUD\_TOOLS\_Python\APP__JigsawWM\src\jigsawwm\w32\monitor.py:155

which points into the function get_info() here:

    def get_info(self) -> MONITORINFOEX:
        """Retrieves monitor information

        :returns: monitor information
        :rtype: MONITORINFOEX
        """
        monitor_info = MONITORINFOEX()
        monitor_info.cbSize = sizeof(monitor_info)
--->    if not user32.GetMonitorInfoA(self._hmon, pointer(monitor_info)):
            raise WinError(get_last_error())
        return monitor_info

then continue until the 1st hit, self._hmon shows a value of 65539. After issuing the next continue, the windows are set up on the big monitor (properly, as intended), but the value of self._hmon now shows 0 in the marked line. Which seems to be responsible for raising the WinError in the next line.

klesh commented 4 months ago

Do you have multiple monitors or using virtual desktops?

nnako commented 4 months ago

Hi @klesh , sorry for the delay...

I use multiple monitors. The main one is the built-in monitor of my laptop and the other one is connected via a HP docking station which in turn is connected to my laptop via USB-C. No virtual desktops. The screen configuration looks like this:

                              x=0
                               |
                               |

     -  +----------------------+
     ^  |                      |
     |  |                      +----------------+ --- y=0
     |  |       55 inch        |     17 inch    |  ^
2160 |  |   secondary screen   |  main screen   |  |  1080
 px  |  |   external monitor   | laptop monitor |  v   px
     |  |                      +----------------+  -
     v  |                      |
     -  +----------------------+

        |<-------------------->|<-------------->|
                 3840 px             1280 px

The odd thing is that this feature worked fine until some weeks ago. I didn't change anything as I was happy to at least be able to realize a static window location configuration (by double-clicking on a desktop icon). As the application now crashes at the described point in code, I can not change the window configuration by keyboard hotkeys. The application is not running properly anymore to evaluate the hotkeys for that.

Any suggestions? Any hints where I could have a look myself?

nnako commented 4 months ago

To test if the effect has anything to do with my local setting, I just re-set my docking station where the secondary screen is connected to. And... the tool works fine again.

Must have been an error within my docking station having caused the effects described here. Closing the issue. Thanks.