diff --git a/qutebrowser/misc/wmname.py b/qutebrowser/misc/wmname.py index d59375bdb..e27cca394 100644 --- a/qutebrowser/misc/wmname.py +++ b/qutebrowser/misc/wmname.py @@ -37,11 +37,6 @@ def _load_library(name: str) -> ctypes.CDLL: 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: """Get the process ID from a file descriptor using SO_PEERCRED. @@ -121,7 +116,7 @@ def wayland_compositor_name() -> str: Approach based on: 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: fd = _wayland_get_fd(wayland_client, display) pid = _pid_from_fd(fd) @@ -144,11 +139,6 @@ _X11Display = NewType("_X11Display", "ctypes._Pointer[_X11DisplayStruct]") _X11Window = NewType("_X11Window", int) -def _x11_load_lib() -> ctypes.CDLL: - """Load the X11 library.""" - return _load_library("X11") - - @contextlib.contextmanager def _x11_open_display(xlib: ctypes.CDLL) -> Iterator[_X11Display]: """Open a connection to the X11 display.""" @@ -308,7 +298,7 @@ def _x11_get_wm_name( def x11_wm_name() -> str: """Get the name of the running X11 window manager.""" - xlib = _x11_load_lib() + xlib = _load_library("X11") with _x11_open_display(xlib) as display: atoms = _X11Atoms( NET_SUPPORTING_WM_CHECK=_x11_intern_atom( diff --git a/tests/unit/misc/test_wmname.py b/tests/unit/misc/test_wmname.py index 03c465d3b..bc0e1daea 100644 --- a/tests/unit/misc/test_wmname.py +++ b/tests/unit/misc/test_wmname.py @@ -21,7 +21,7 @@ from qutebrowser.misc import wmname def test_load_libwayland_client(): """Test loading the Wayland client library, which might or might not exist.""" try: - wmname._load_libwayland_client() + wmname._load_library("wayland-client") except wmname.Error: 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")) with pytest.raises(wmname.Error, match="Failed to load wayland-client"): - wmname._load_libwayland_client() + wmname._load_library("wayland-client") @pytest.fixture @@ -178,7 +178,7 @@ def test_wayland_real(): def test_load_xlib(): """Test loading Xlib, which might or might not exist.""" try: - wmname._x11_load_lib() + wmname._load_library("X11") except wmname.Error: pass @@ -188,7 +188,7 @@ def test_load_xlib_not_found(monkeypatch: pytest.MonkeyPatch): monkeypatch.setattr(ctypes.util, "find_library", lambda x: None) 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): @@ -199,7 +199,7 @@ def test_load_xlib_error(mocker: pytest_mock.MockerFixture): with pytest.raises( wmname.Error, match="Failed to load X11 library: Failed to load library" ): - wmname._x11_load_lib() + wmname._load_library("X11") @pytest.fixture @@ -290,7 +290,7 @@ def test_x11_get_wm_name( qtbot.add_widget(w) w.setWindowTitle("Test Window") - xlib = wmname._x11_load_lib() + xlib = wmname._load_library("X11") with wmname._x11_open_display(xlib) as display: atoms = wmname._X11Atoms( NET_SUPPORTING_WM_CHECK=-1,