Skip to content

Commit fda2a6e

Browse files
committed
CLI: add --with-cursor argument
1 parent 6723c09 commit fda2a6e

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ History:
1010
- Linux: added mouse support (related to #55)
1111
- Linux: refactored how internal handles are stored to fix issues with multiple X servers (fixes #210)
1212
- Linux: removed side effects when leaving the context manager, resources are all freed (fixes #210)
13+
- CLI: added --with-cursor argument
1314
- tests: added PyPy 3.9, removed tox, and improved GNU/Linux coverage
1415

1516
7.0.1 2022/10/27

docs/source/usage.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ You can use ``mss`` via the CLI::
7272

7373
Or via direct call from Python::
7474

75-
python -m mss --help
75+
$ python -m mss --help
76+
usage: __main__.py [-h] [-c COORDINATES] [-l {0,1,2,3,4,5,6,7,8,9}]
77+
[-m MONITOR] [-o OUTPUT] [-q] [-v] [--with-cursor]
78+
79+
options:
80+
-h, --help show this help message and exit
81+
-c COORDINATES, --coordinates COORDINATES
82+
the part of the screen to capture: top, left, width, height
83+
-l {0,1,2,3,4,5,6,7,8,9}, --level {0,1,2,3,4,5,6,7,8,9}
84+
the PNG compression level
85+
-m MONITOR, --monitor MONITOR
86+
the monitor to screen shot
87+
-o OUTPUT, --output OUTPUT
88+
the output file name
89+
--with-cursor include the cursor
90+
-q, --quiet do not print created files
91+
-v, --version show program's version number and exit
7692

7793
.. versionadded:: 3.1.1
94+
95+
.. versionadded:: 8.0.0
96+
``--with-cursor`` to include the cursor in screenshots.

mss/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def main(args: List[str], /) -> int:
3333
)
3434
cli_args.add_argument("-m", "--monitor", default=0, type=int, help="the monitor to screen shot")
3535
cli_args.add_argument("-o", "--output", default="monitor-{mon}.png", help="the output file name")
36+
cli_args.add_argument("--with-cursor", default=False, action="store_true", help="include the cursor")
3637
cli_args.add_argument(
3738
"-q",
3839
"--quiet",
@@ -61,7 +62,7 @@ def main(args: List[str], /) -> int:
6162
kwargs["output"] = "sct-{top}x{left}_{width}x{height}.png"
6263

6364
try:
64-
with mss() as sct:
65+
with mss(with_cursor=options.with_cursor) as sct:
6566
if options.coordinates:
6667
output = kwargs["output"].format(**kwargs["mon"])
6768
sct_img = sct.grab(kwargs["mon"])

mss/linux.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,20 +454,20 @@ def _cursor_impl(self) -> ScreenShot:
454454
raise ScreenShotError("Cannot read XFixesGetCursorImage()")
455455

456456
cursor_img: XFixesCursorImage = ximage.contents
457-
monitor = {
457+
region = {
458458
"left": cursor_img.x - cursor_img.xhot,
459459
"top": cursor_img.y - cursor_img.yhot,
460460
"width": cursor_img.width,
461461
"height": cursor_img.height,
462462
}
463463

464-
raw_data = cast(cursor_img.pixels, POINTER(c_ulong * monitor["height"] * monitor["width"]))
464+
raw_data = cast(cursor_img.pixels, POINTER(c_ulong * region["height"] * region["width"]))
465465
raw = bytearray(raw_data.contents)
466466

467-
data = bytearray(monitor["height"] * monitor["width"] * 4)
467+
data = bytearray(region["height"] * region["width"] * 4)
468468
data[3::4] = raw[3::8]
469469
data[2::4] = raw[2::8]
470470
data[1::4] = raw[1::8]
471471
data[::4] = raw[::8]
472472

473-
return self.cls_image(data, monitor)
473+
return self.cls_image(data, region)

0 commit comments

Comments
 (0)