wmname: Remove trivial functions
This commit is contained in:
parent
25dc019886
commit
bc191b798d
|
|
@ -37,11 +37,6 @@ def _load_library(name: str) -> ctypes.CDLL:
|
||||||
raise Error(f"Failed to load {name} library: {e}")
|
raise Error(f"Failed to load {name} library: {e}")
|
||||||
|
|
||||||
|
|
||||||
def _load_libwayland_client() -> ctypes.CDLL:
|
|
||||||
"""Load the Wayland client library."""
|
|
||||||
return _load_library("wayland-client")
|
|
||||||
|
|
||||||
|
|
||||||
def _pid_from_fd(fd: int) -> int:
|
def _pid_from_fd(fd: int) -> int:
|
||||||
"""Get the process ID from a file descriptor using SO_PEERCRED.
|
"""Get the process ID from a file descriptor using SO_PEERCRED.
|
||||||
|
|
||||||
|
|
@ -121,7 +116,7 @@ def wayland_compositor_name() -> str:
|
||||||
Approach based on:
|
Approach based on:
|
||||||
https://stackoverflow.com/questions/69302630/wayland-client-get-compositor-name
|
https://stackoverflow.com/questions/69302630/wayland-client-get-compositor-name
|
||||||
"""
|
"""
|
||||||
wayland_client = _load_libwayland_client()
|
wayland_client = _load_library("wayland-client")
|
||||||
with _wayland_display(wayland_client) as display:
|
with _wayland_display(wayland_client) as display:
|
||||||
fd = _wayland_get_fd(wayland_client, display)
|
fd = _wayland_get_fd(wayland_client, display)
|
||||||
pid = _pid_from_fd(fd)
|
pid = _pid_from_fd(fd)
|
||||||
|
|
@ -144,11 +139,6 @@ _X11Display = NewType("_X11Display", "ctypes._Pointer[_X11DisplayStruct]")
|
||||||
_X11Window = NewType("_X11Window", int)
|
_X11Window = NewType("_X11Window", int)
|
||||||
|
|
||||||
|
|
||||||
def _x11_load_lib() -> ctypes.CDLL:
|
|
||||||
"""Load the X11 library."""
|
|
||||||
return _load_library("X11")
|
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def _x11_open_display(xlib: ctypes.CDLL) -> Iterator[_X11Display]:
|
def _x11_open_display(xlib: ctypes.CDLL) -> Iterator[_X11Display]:
|
||||||
"""Open a connection to the X11 display."""
|
"""Open a connection to the X11 display."""
|
||||||
|
|
@ -308,7 +298,7 @@ def _x11_get_wm_name(
|
||||||
|
|
||||||
def x11_wm_name() -> str:
|
def x11_wm_name() -> str:
|
||||||
"""Get the name of the running X11 window manager."""
|
"""Get the name of the running X11 window manager."""
|
||||||
xlib = _x11_load_lib()
|
xlib = _load_library("X11")
|
||||||
with _x11_open_display(xlib) as display:
|
with _x11_open_display(xlib) as display:
|
||||||
atoms = _X11Atoms(
|
atoms = _X11Atoms(
|
||||||
NET_SUPPORTING_WM_CHECK=_x11_intern_atom(
|
NET_SUPPORTING_WM_CHECK=_x11_intern_atom(
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ from qutebrowser.misc import wmname
|
||||||
def test_load_libwayland_client():
|
def test_load_libwayland_client():
|
||||||
"""Test loading the Wayland client library, which might or might not exist."""
|
"""Test loading the Wayland client library, which might or might not exist."""
|
||||||
try:
|
try:
|
||||||
wmname._load_libwayland_client()
|
wmname._load_library("wayland-client")
|
||||||
except wmname.Error:
|
except wmname.Error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ def test_load_libwayland_client_error(mocker: pytest_mock.MockerFixture):
|
||||||
mocker.patch("ctypes.CDLL", side_effect=OSError("Library not found"))
|
mocker.patch("ctypes.CDLL", side_effect=OSError("Library not found"))
|
||||||
|
|
||||||
with pytest.raises(wmname.Error, match="Failed to load wayland-client"):
|
with pytest.raises(wmname.Error, match="Failed to load wayland-client"):
|
||||||
wmname._load_libwayland_client()
|
wmname._load_library("wayland-client")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
@ -178,7 +178,7 @@ def test_wayland_real():
|
||||||
def test_load_xlib():
|
def test_load_xlib():
|
||||||
"""Test loading Xlib, which might or might not exist."""
|
"""Test loading Xlib, which might or might not exist."""
|
||||||
try:
|
try:
|
||||||
wmname._x11_load_lib()
|
wmname._load_library("X11")
|
||||||
except wmname.Error:
|
except wmname.Error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -188,7 +188,7 @@ def test_load_xlib_not_found(monkeypatch: pytest.MonkeyPatch):
|
||||||
monkeypatch.setattr(ctypes.util, "find_library", lambda x: None)
|
monkeypatch.setattr(ctypes.util, "find_library", lambda x: None)
|
||||||
|
|
||||||
with pytest.raises(wmname.Error, match="X11 library not found"):
|
with pytest.raises(wmname.Error, match="X11 library not found"):
|
||||||
wmname._x11_load_lib()
|
wmname._load_library("X11")
|
||||||
|
|
||||||
|
|
||||||
def test_load_xlib_error(mocker: pytest_mock.MockerFixture):
|
def test_load_xlib_error(mocker: pytest_mock.MockerFixture):
|
||||||
|
|
@ -199,7 +199,7 @@ def test_load_xlib_error(mocker: pytest_mock.MockerFixture):
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
wmname.Error, match="Failed to load X11 library: Failed to load library"
|
wmname.Error, match="Failed to load X11 library: Failed to load library"
|
||||||
):
|
):
|
||||||
wmname._x11_load_lib()
|
wmname._load_library("X11")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
@ -290,7 +290,7 @@ def test_x11_get_wm_name(
|
||||||
qtbot.add_widget(w)
|
qtbot.add_widget(w)
|
||||||
w.setWindowTitle("Test Window")
|
w.setWindowTitle("Test Window")
|
||||||
|
|
||||||
xlib = wmname._x11_load_lib()
|
xlib = wmname._load_library("X11")
|
||||||
with wmname._x11_open_display(xlib) as display:
|
with wmname._x11_open_display(xlib) as display:
|
||||||
atoms = wmname._X11Atoms(
|
atoms = wmname._X11Atoms(
|
||||||
NET_SUPPORTING_WM_CHECK=-1,
|
NET_SUPPORTING_WM_CHECK=-1,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue