-
-
Notifications
You must be signed in to change notification settings - Fork 200
Description
I tried to create a borderless window using pygame.Window
module, but found that the Window.maximize
function was not working. I suspect that this function uses the system's window controller, which is disabled by the borderless parameter.
So I tried manually achieving maximization by directly setting the Window.size
and Window.position
properties. This requires obtaining the screen resolution, but window maximization is different from full-screen mode, it should not include areas where components like the taskbar or Dock are located. I tested the pygame.display.get_desktop_sizes()
function, which returns the entire screen size, but that's not what I wanted.
In fact, SDL provides a function called SDL_GetDisplayUsableBounds()
, which retrieves the working area without including the taskbar or Dock. However, pygame does not seem to provide an encapsulation for this function.
I tried using ctypes
to directly call this function from SDL2
and successfully obtained the desired rectangular area:
import ctypes
SDL = ctypes.CDLL('SDL2')
SDL.SDL_GetDisplayUsableBounds.argtypes = [ctypes.c_int, ctypes.c_void_p]
SDL.SDL_GetDisplayUsableBounds.restype = ctypes.c_int
class SDL_Rect(ctypes.Structure):
_fields_ = [("x", ctypes.c_int),
("y", ctypes.c_int),
("w", ctypes.c_int),
("h", ctypes.c_int)]
r = SDL_Rect()
SDL.SDL_GetDisplayUsableBounds(0, ctypes.byref(r))
print("work-area:", r.x, r.y, r.w, r.h)
The SDL2 module is provided directly by pygame. The result is:
work-area: 0 0 2560 1528
My screen size is 2560×1600, running on Windows 11. This result does not include the taskbar area.
I don't think adding this new API will cause any disruptive changes. This is just a piece of code that I used temporarily, and it may not be universally applicable. If necessary, I can also conduct testing on the MacOS system.