Skip to content

Commit f0e8652

Browse files
committed
Warn and ignore for --with-cursor in command line on non-Linux.
1 parent 7e9a697 commit f0e8652

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/mss/__main__.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _backend_cli_choices() -> list[str]:
2929
return ["default"]
3030

3131

32-
def main(*args: str) -> int:
32+
def main(*args: str) -> int: # noqa: PLR0912
3333
"""Main logic."""
3434
backend_choices = _backend_cli_choices()
3535

@@ -51,7 +51,7 @@ def main(*args: str) -> int:
5151
)
5252
cli_args.add_argument("-m", "--monitor", default=0, type=int, help="the monitor to screenshot")
5353
cli_args.add_argument("-o", "--output", default="monitor-{mon}.png", help="the output file name")
54-
cli_args.add_argument("--with-cursor", default=False, action="store_true", help="include the cursor")
54+
cli_args.add_argument("--with-cursor", action="store_true", help="include the cursor")
5555
cli_args.add_argument(
5656
"-q",
5757
"--quiet",
@@ -72,33 +72,42 @@ def main(*args: str) -> int:
7272
cli_args.print_usage(sys.stderr)
7373
print(f"{cli_args.prog}: error: {e}", file=sys.stderr)
7474
return 2
75-
kwargs = {"mon": options.monitor, "output": options.output}
75+
grab_kwargs = {"mon": options.monitor, "output": options.output}
7676
if options.coordinates:
7777
try:
7878
top, left, width, height = options.coordinates.split(",")
7979
except ValueError:
8080
print("Coordinates syntax: top, left, width, height")
8181
return 2
8282

83-
kwargs["mon"] = {
83+
grab_kwargs["mon"] = {
8484
"top": int(top),
8585
"left": int(left),
8686
"width": int(width),
8787
"height": int(height),
8888
}
8989
if options.output == "monitor-{mon}.png":
90-
kwargs["output"] = "sct-{top}x{left}_{width}x{height}.png"
90+
grab_kwargs["output"] = "sct-{top}x{left}_{width}x{height}.png"
91+
92+
if options.with_cursor is not None and platform.system().lower() != "linux":
93+
if not options.quiet:
94+
print("[WARNING] --with-cursor is only supported on Linux; ignoring.")
95+
options.with_cursor = None
96+
97+
mss_kwargs = {"backend": options.backend}
98+
if options.with_cursor is not None:
99+
mss_kwargs["with_cursor"] = options.with_cursor
91100

92101
try:
93-
with MSS(with_cursor=options.with_cursor, backend=options.backend) as sct:
102+
with MSS(**mss_kwargs) as sct:
94103
if options.coordinates:
95-
output = kwargs["output"].format(**kwargs["mon"])
96-
sct_img = sct.grab(kwargs["mon"])
104+
output = grab_kwargs["output"].format(**grab_kwargs["mon"])
105+
sct_img = sct.grab(grab_kwargs["mon"])
97106
to_png(sct_img.rgb, sct_img.size, level=options.level, output=output)
98107
if not options.quiet:
99108
print(os.path.realpath(output))
100109
else:
101-
for file_name in sct.save(**kwargs):
110+
for file_name in sct.save(**grab_kwargs):
102111
if not options.quiet:
103112
print(os.path.realpath(file_name))
104113
return 0

0 commit comments

Comments
 (0)