Skip to content

Commit ca35070

Browse files
committed
0.7, 2024/03/22 -- LINUX: (Really) Fixed position and size for GNOME (by using GTK_EXTENTS)
1 parent dcf37b3 commit ca35070

File tree

17 files changed

+100
-68
lines changed

17 files changed

+100
-68
lines changed

AUTHORS.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ PyWinBox authors, contributors and maintainers:
22

33
Kalmat https://github.com/Kalmat
44
elraymond (https://github.com/elraymond)
5+
Leonard Bruns https://github.com/roym899
6+
lappely - https://github.com/poipoiPIO
7+

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.7, 2024/03/22 -- LINUX: (Really) Fixed position and size for GNOME (by using GTK_EXTENTS)
2+
0.6, 2023/10/12 -- LINUX: Improved position and size for GNOME (by using GTK_EXTENTS)
3+
WIN32: Fixed GetAwarenessFromDpiAwarenessContext not supported on Windows Server
14
0.5, 2023/09/06 -- MACOS: Tested OK in multi-monitor setup
25
0.4, 2023/08/25 -- Reorganized to avoid IDEs showing external and / or private elements
36
0.3, 2023/08/21 -- Linux: Improved window geometry (thanks to elraymond - https://github.com/elraymond)

dist/PyWinBox-0.7-py3-none-any.whl

51.5 KB
Binary file not shown.

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@
6262
'Programming Language :: Python',
6363
'Programming Language :: Python :: 3',
6464
'Programming Language :: Python :: 3 :: Only',
65-
'Programming Language :: Python :: 3.7',
66-
'Programming Language :: Python :: 3.8',
6765
'Programming Language :: Python :: 3.9',
68-
'Programming Language :: Python :: 3.10'
66+
'Programming Language :: Python :: 3.10',
67+
'Programming Language :: Python :: 3.11'
6968
],
7069
)

src/pywinbox/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version", "PyWinBox", "Box", "Rect", "Point", "Size", "pointInBox"
66
]
77

8-
__version__ = "0.6"
8+
__version__ = "0.7"
99

1010

1111
def version(numberOnly: bool = True) -> str:

src/pywinbox/_pywinbox_linux.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
# -*- coding: utf-8 -*-
33
from __future__ import annotations
44

5+
import os
56
import sys
67
assert sys.platform == "linux"
78

89
from typing import Union, Optional
910

1011
from Xlib.xobject.drawable import Window as XWindow
12+
1113
from ._main import Box
12-
from ewmhlib import EwmhWindow
14+
from .ewmhlib import EwmhWindow
1315

1416

1517
def _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

3252
def _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)

src/pywinbox/_pywinbox_macos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _CGmoveResizeTo(appName: str, title: str, newBox: Box):
134134
proc = subprocess.Popen(['osascript', '-', appName, title,
135135
str(newBox.left), str(newBox.top), str(newBox.width), str(newBox.height)],
136136
stdin=subprocess.PIPE, stdout=subprocess.PIPE, encoding='utf8')
137-
ret, err = proc.communicate(cmd)
137+
_, _ = proc.communicate(cmd)
138138

139139

140140
def _flipTop(window: AppKit.NSWindow, box: Box) -> int:

src/pywinbox/_pywinbox_win.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
from ._main import Box
1515

1616

17+
# Thanks to poipoiPIO (https://github.com/poipoiPIO) for his HELP!!!
1718
try:
1819
dpiAware = ctypes.windll.user32.GetAwarenessFromDpiAwarenessContext(ctypes.windll.user32.GetThreadDpiAwarenessContext())
1920
except AttributeError: # Windows server does not implement GetAwarenessFromDpiAwarenessContext
2021
dpiAware = 0
2122

2223
if dpiAware == 0:
23-
ctypes.windll.shcore.SetProcessDpiAwareness(2)
24+
# It seems that this can't be invoked twice. Setting it to 1 for apps having 0 (unaware) may have less impact
25+
ctypes.windll.shcore.SetProcessDpiAwareness(1)
2426

2527

2628
def _getHandle(handle: Union[int, str]) -> Optional[int]:

0 commit comments

Comments
 (0)