22# -*- coding: utf-8 -*-
33from __future__ import annotations
44
5+ import os
56import sys
67assert sys .platform == "linux"
78
89from typing import Union , Optional
910
1011from Xlib .xobject .drawable import Window as XWindow
12+
1113from ._main import Box
12- from ewmhlib import EwmhWindow
14+ from . ewmhlib import EwmhWindow
1315
1416
1517def _getHandle (handle : Union [int , XWindow ]) -> Optional [EwmhWindow ]:
@@ -26,12 +28,44 @@ def _getWindowBox(handle: EwmhWindow) -> Box:
2628 # https://stackoverflow.com/questions/12775136/get-window-position-and-size-in-python-with-xlib
2729 geom = handle .xWindow .get_geometry ()
2830 pos = handle .root .translate_coords (handle .id , 0 , 0 )
29- return Box (pos .x , pos .y , geom .width , geom .height )
31+ x = pos .x
32+ y = pos .y
33+ w = geom .width
34+ h = geom .height
35+ # Thanks to roym899 (https://github.com/roym899) for his HELP!!!!
36+ if os .environ .get ('XDG_SESSION_TYPE' , "" ).lower () == "gnome" :
37+ # Most apps in GNOME do not set _NET_EXTENTS, but _GTK_EXTENTS,
38+ # which is the additional space AROUND the window.
39+ _gtk_extents = handle ._getGtkFrameExtents ()
40+ if _gtk_extents and len (_gtk_extents ) >= 4 :
41+ # this means there is a GTK HeaderBar
42+ x += int (_gtk_extents [0 ])
43+ y += int (_gtk_extents [2 ])
44+ w -= (int (_gtk_extents [0 ]) + int (_gtk_extents [1 ]))
45+ h -= (int (_gtk_extents [2 ]) + int (_gtk_extents [3 ]))
46+ # If not in GNOME: best guess is to trust pos and geom from above
47+ # NOTE: if you have this case and are not getting the expected result,
48+ # please open an issue: https://github.com/Kalmat/PyWinBox/issues/new
49+ return Box (x , y , w , h )
3050
3151
3252def _moveResizeWindow (handle : EwmhWindow , newBox : Box ):
3353 newLeft = max (0 , newBox .left ) # Xlib won't accept negative positions
3454 newTop = max (0 , newBox .top )
35- handle .setMoveResize (x = newLeft , y = newTop , width = newBox .width , height = newBox .height , userAction = True )
36- # handle.configure(x=newLeft, y=newTop, width=newBox.width, height=newBox.height)
37-
55+ newWidth = newBox .width
56+ newHeight = newBox .height
57+ if os .environ .get ('XDG_SESSION_TYPE' , "" ).lower () == "gnome" :
58+ # Most apps in GNOME do not set _NET_EXTENTS, but _GTK_EXTENTS,
59+ # which is the additional space AROUND the window.
60+ _gtk_extents = handle ._getGtkFrameExtents ()
61+ if _gtk_extents and len (_gtk_extents ) >= 4 :
62+ # this means there is a GTK HeaderBar
63+ newLeft -= int (_gtk_extents [0 ])
64+ newTop -= int (_gtk_extents [2 ])
65+ newWidth += (int (_gtk_extents [0 ]) + int (_gtk_extents [1 ]))
66+ newHeight += (int (_gtk_extents [2 ]) + int (_gtk_extents [3 ]))
67+ # If not in GNOME: best guess is to trust pos and geom from above
68+ # NOTE: if you have this case and are not getting the expected result,
69+ # please open an issue: https://github.com/Kalmat/PyWinBox/issues/new
70+ handle .setMoveResize (x = newLeft , y = newTop , width = newWidth , height = newHeight , userAction = True )
71+ # handle.configure(x=newLeft, y=newTop, width=newWidth, height=newHeight)
0 commit comments