GChristensen / enso-portable

Portable Enso Launcher community edition
Other
164 stars 46 forks source link

getDesktopOffset does not get Windows work area #15

Closed robertcollier4 closed 5 years ago

robertcollier4 commented 5 years ago

getDesktopOffset() is currently returned as (0,0) without checking Windows for the work area. This is a problem for users that have their taskbar at the top of the screen. The following is a working code snippet which allows all the necessary calculations to be gotten.

from ctypes import windll
from ctypes import wintypes, byref
SPI_GETWORKAREA = 48
SystemParametersInfo = windll.user32.SystemParametersInfoA
rectWorkarea = wintypes.RECT()
SystemParametersInfo(SPI_GETWORKAREA, 0, byref(rectWorkarea), 0)
workareaLeft = rectWorkarea.left
workareaRight = rectWorkarea.right
workareaTop = rectWorkarea.top
workareaBottom = rectWorkarea.bottom
workareaWidth = workareaRight - workareaLeft
workareaHeight = workareaBottom - workareaTop

The suggested change affects the following files https://github.com/GChristensen/enso-portable/blob/d0eb024cb2448673f5aafc51fe64e5d2d944d61a/enso/enso/platform/win32/graphics/__init__.py#L48 Currently getDesktopSize and getDesktopOffset are not being used anywhere in Win32 because they are calling the function with 0 arguments and getting a void return value. The functions in TransparentWindow.cxx write the information to the pointer addresses of the variables passed into them and return void. So neither getDesktopSize or getDesktopOffset are working as of now. The Win32 calls require passing in a pointer to an int structure as seen in: https://github.com/GChristensen/enso-portable/blob/4fb927ca6c4ae4c66fa0fbbc33c088397f40b9ce/platform/win32/Graphics/TransparentWindow/TransparentWindow.cxx#L622 width also needs to be right minus left (in case of taskbar on left or right side). height needs to be bottom minus top

Rather than dealing with dynamically allocated python variable pointers (which who knows what is going on with them) passed to the C code, best to do it all in python in enso/platform/win32/graphics/init.py with ctypes with the above code snippet.

GChristensen commented 5 years ago

Hi, thanks for participation.

Can you, please, describe exactly in what use cases there are problems?

Currently getDesktopOffset is used in the two following places:

https://github.com/GChristensen/enso-portable/blob/64f5ea097875cde3807c0c48b12fb2e82c4ddf08/enso/enso/messages/primarywindow.py#L211

https://github.com/GChristensen/enso-portable/blob/64f5ea097875cde3807c0c48b12fb2e82c4ddf08/enso/enso/quasimode/linewindows.py#L73

And the top coordinate is not used anyway.

getDesktopSize returns non conventional value with taskbar at top, but these dimensions are currently affect only message window positioning (which is adequate even with such implementation).

GChristensen commented 5 years ago

BTW, I've fixed getDesktopSzie (it needs to be fixed, the pointers are packed to a Python list by a swig-generated c++ wrapper).

robertcollier4 commented 5 years ago

The use case in which there are problems is if you have taskbar docked to top or left of screen. Then enso window comes on top of the taskbar. To still be able to see your open applications while using enso, enso should not come on top of the taskbar. Left and Top should be used in L76 https://github.com/GChristensen/enso-portable/blob/64f5ea097875cde3807c0c48b12fb2e82c4ddf08/enso/enso/quasimode/linewindows.py#L76 TransparentWindow(xPos + left, yPos + top, width, height ) which I will add to the pull request. (before the yPos + top component was missing also).

GChristensen commented 5 years ago

I think this is a too radical change from the default behavior and it should be optional (I think that Enso window was purposefully designed to appear at (0,0) coordinates). I'll add a custom initialization option to position Enso main window off the taskbar latter.