Skip to content

Commit 44bf176

Browse files
committed
Change the default backend on Linux to xshmgetimage
Also, fix a minor error in the docs formatting.
1 parent 9eaf3fc commit 44bf176

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

docs/source/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ Factory function to return the appropriate backend implementation.
4747
Factory returning a proper MSS class instance for GNU/Linux.
4848
The backend parameter selects the implementation:
4949

50-
- "default" or "xlib": Traditional Xlib-based backend (default)
50+
- "default" or "xshmgetimage": XCB-based backend using XShmGetImage (default, with automatic fallback to XGetImage)
5151
- "xgetimage": XCB-based backend using XGetImage
52-
- "xshmgetimage": XCB-based backend using XShmGetImage (falls back to XGetImage if unavailable)
52+
- "xlib": Traditional Xlib-based backend retained for environments without working XCB libraries
5353

5454
.. function:: MSS(*args, **kwargs)
5555

@@ -61,7 +61,7 @@ Xlib Backend
6161

6262
.. module:: mss.linux.xlib
6363

64-
Traditional Xlib-based backend (default).
64+
Legacy Xlib-based backend, kept as a fallback when XCB is unavailable.
6565

6666
.. attribute:: CFUNCTIONS
6767

docs/source/usage.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ GNU/Linux
7979
Display
8080
^^^^^^^
8181

82-
On GNU/Linux, the default display is taken from the :envvar:`DISPLAY` environment variable. You can instead specify which display to use (useful for distant screenshots via SSH) using the :keyword:`display` keyword::
82+
On GNU/Linux, the default display is taken from the :envvar:`DISPLAY` environment variable. You can instead specify which display to use (useful for distant screenshots via SSH) using the ``display`` keyword::
8383

8484
.. literalinclude:: examples/linux_display_keyword.py
85-
:lines: 9-
85+
:lines: 7-
86+
8687

8788
Backends
8889
^^^^^^^^
@@ -91,14 +92,18 @@ The GNU/Linux implementation has multiple backends (see :ref:`backends`), or way
9192

9293
There are three available backends.
9394

94-
:py:mod:`xlib` (default)
95-
The legacy backend, based on :c:func:`XGetImage`. This backend is not being improved anymore. It is only provided in case the newer backends don't work for some reason.
95+
:py:mod:`xshmgetimage` (default)
96+
The fastest backend, based on :c:func:`xcb_shm_get_image`. It is roughly three times faster than :py:mod:`xgetimage`
97+
and is used automatically. When the MIT-SHM extension is unavailable (for example on remote SSH displays), it
98+
transparently falls back to :py:mod:`xgetimage` so you can always request it safely.
9699

97100
:py:mod:`xgetimage`
98-
A highly-compatible, but slow, backend, based on :c:func:`xcb_get_image`. This backend is the slowest of the new backends, but works in all situations. You can use this if you know that :py:mod:`xshmgetimage` won't work.
101+
A highly-compatible, but slower, backend based on :c:func:`xcb_get_image`. Use this explicitly only when you know
102+
that :py:mod:`xshmgetimage` cannot operate in your environment.
99103

100-
:py:mod:`xshmgetimage`
101-
The fastest backend, based on :c:func:`xcb_shm_get_image`. This backend is the fastest, about three times faster than :py:mod:`xgetimage`. However, it doesn't work for remote screenshots, such as over SSH. If you use it with a remote display, then it will automatically switch to :py:mod:`xgetimage` instead. It's always safe to use this backend.
104+
:py:mod:`xlib`
105+
The legacy backend powered by :c:func:`XGetImage`. It is kept solely for systems where XCB libraries are
106+
unavailable and no new features are being added to it.
102107

103108

104109
Command Line

src/mss/linux/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ class for instantiation.
1515
versions will look at other options as well.
1616
"""
1717
backend = backend.lower()
18-
if backend in {"default", "xlib"}:
18+
if backend == "xlib":
1919
from . import xlib # noqa: PLC0415
2020

2121
return xlib.MSS(**kwargs)
2222
if backend == "xgetimage":
2323
from . import xgetimage # noqa: PLC0415
2424

25-
# Note that the xshmgetimage backend will automatically fall
26-
# back to XGetImage calls if XShmGetImage isn't available. The
27-
# only reason to use the xgetimage backend is if the user
28-
# already knows that XShmGetImage isn't going to be supported.
25+
# Note that the xshmgetimage backend will automatically fall back to XGetImage calls if XShmGetImage isn't
26+
# available. The only reason to use the xgetimage backend is if the user already knows that XShmGetImage
27+
# isn't going to be supported.
2928
return xgetimage.MSS(**kwargs)
30-
if backend == "xshmgetimage":
29+
if backend in {"default", "xshmgetimage"}:
3130
from . import xshmgetimage # noqa: PLC0415
3231

3332
return xshmgetimage.MSS(**kwargs)

0 commit comments

Comments
 (0)