You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Also, before marking XShmGetImage as unavailable if the first grab()
fails, also test to see if the fallback XGetImage also fails (such as
if the user gave an out-of-bounds rect). In that case, just reraise
the exception and try XShmGetImage again with the next grab().
Copy file name to clipboardExpand all lines: docs/source/usage.rst
+46-3Lines changed: 46 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ Usage
5
5
Import
6
6
======
7
7
8
-
So MSS can be used as simply as::
8
+
MSS can be used as simply as::
9
9
10
10
from mss import mss
11
11
@@ -20,6 +20,11 @@ Or import the good one based on your operating system::
20
20
# Microsoft Windows
21
21
from mss.windows import MSS as mss
22
22
23
+
On GNU/Linux you can also import a specific backend (see :ref:`backends`)
24
+
directly when you need a particular implementation, for example::
25
+
26
+
from mss.linux.xshmgetimage import MSS as mss
27
+
23
28
24
29
Instance
25
30
========
@@ -49,19 +54,57 @@ This is a much better usage, memory efficient::
49
54
Also, it is a good thing to save the MSS instance inside an attribute of your class and calling it when needed.
50
55
51
56
57
+
.. _backends:
58
+
59
+
Backends
60
+
--------
61
+
62
+
Some platforms have multiple ways to take screenshots. In MSS, these are known as *backends*. The :py:func:`mss` functions will normally autodetect which one is appropriate for your situation, but you can override this if you want. For instance, you may know that your specific situation requires a particular backend.
63
+
64
+
If you want to choose a particular backend, you can use the :py::`backend` keyword to :py:func:`mss`:::
65
+
66
+
with mss(backend="xgetimage") as sct:
67
+
...
68
+
69
+
Instead, you can also directly import the backend you want to use:::
70
+
71
+
from mss.linux.xgetimage import MSS as mss
72
+
73
+
Currently, only the GNU/Linux implementation has multiple backends. These are described in their own section below.
74
+
75
+
52
76
GNU/Linux
53
77
---------
54
78
55
-
On GNU/Linux, you can specify which display to use (useful for distant screenshots via SSH)::
79
+
Display
80
+
^^^^^^^
81
+
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::
56
83
57
84
with mss(display=":0.0") as sct:
58
-
# ...
85
+
...
59
86
60
87
A more specific example (only valid on GNU/Linux):
The GNU/Linux implementation has multiple backends (see :ref:`backends`), or ways it can take screenshots. The :py:func:`mss.mss` and :py:func:`mss.linux.mss` functions will normally autodetect which one is appropriate, but you can override this if you want.
96
+
97
+
There are three available backends.
98
+
99
+
:py:mod:`xlib` (default)
100
+
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.
101
+
102
+
:py:mod:`xgetimage`
103
+
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.
104
+
105
+
:py:mod:`xshmgetimage`
106
+
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.
0 commit comments