From f894e8be62946aa47bc2f93ba2b6fcf148cb21dc Mon Sep 17 00:00:00 2001 From: Jeremy Borgman Date: Fri, 7 Oct 2022 14:56:37 -0500 Subject: [PATCH] shot: Add ability to edit in PixelPaint --- Base/usr/share/man/man1/shot.md | 3 ++- Userland/Utilities/shot.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Base/usr/share/man/man1/shot.md b/Base/usr/share/man/man1/shot.md index 638e5e386e..e2e0f22e5e 100644 --- a/Base/usr/share/man/man1/shot.md +++ b/Base/usr/share/man/man1/shot.md @@ -5,7 +5,7 @@ shot ## Synopsis ```sh -$ shot [--clipboard] [--delay seconds] [--screen index] [--region] [output] +$ shot [--clipboard] [--delay seconds] [--screen index] [--region] [--edit] [output] ``` ## Options: @@ -14,6 +14,7 @@ $ shot [--clipboard] [--delay seconds] [--screen index] [--region] [output] * `-d seconds`, `--delay seconds`: Seconds to wait before taking a screenshot * `-s index`, `--screen index`: The index of the screen (default: -1 for all screens) * `-r`, `--region`: Select a region to capture +* `-e`, `--edit`: Open in PixelPaint ## Arguments: diff --git a/Userland/Utilities/shot.cpp b/Userland/Utilities/shot.cpp index e6ab398fe6..f3a7596340 100644 --- a/Userland/Utilities/shot.cpp +++ b/Userland/Utilities/shot.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,7 @@ ErrorOr serenity_main(Main::Arguments arguments) bool output_to_clipboard = false; unsigned delay = 0; bool select_region = false; + bool edit_image = false; int screen = -1; args_parser.add_positional_argument(output_path, "Output filename", "output", Core::ArgsParser::Required::No); @@ -102,6 +104,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(delay, "Seconds to wait before taking a screenshot", "delay", 'd', "seconds"); args_parser.add_option(screen, "The index of the screen (default: -1 for all screens)", "screen", 's', "index"); args_parser.add_option(select_region, "Select a region to capture", "region", 'r'); + args_parser.add_option(edit_image, "Open in PixelPaint", "edit", 'e'); args_parser.parse(arguments); @@ -152,6 +155,8 @@ ErrorOr serenity_main(Main::Arguments arguments) warnln("Failed to encode PNG"); return 1; } + if (edit_image) + output_path = Core::DateTime::now().to_string("/tmp/screenshot-%Y-%m-%d-%H-%M-%S.png"sv); auto file_or_error = Core::File::open(output_path, Core::OpenMode::ReadWrite); if (file_or_error.is_error()) { @@ -165,6 +170,9 @@ ErrorOr serenity_main(Main::Arguments arguments) return 1; } + if (edit_image) + TRY(Core::Process::spawn("/bin/PixelPaint"sv, Array { output_path })); + bool printed_hyperlink = false; if (isatty(STDOUT_FILENO)) { auto full_path = Core::File::real_path_for(output_path);