Skip to content

Commit

Permalink
screenshot: add screenshot-to-clipboard command
Browse files Browse the repository at this point in the history
  • Loading branch information
rcombs committed Dec 25, 2024
1 parent 44878b6 commit 3d5afcb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ Property Manipulation
Playlist Manipulation
~~~~~~~~~~~~~~~~~~~~~

``screenshot-to-clipboard [<flags>]``
Take a screenshot and save it to the system clipboard.

The ``flags`` argument is like the first argument to ``screenshot`` and
supports ``subtitles``, ``video``, ``window``.

``playlist-next <flags>``
Go to the next entry on the playlist.

Expand Down
10 changes: 10 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -7169,6 +7169,16 @@ const struct mp_cmd_def mp_cmds[] = {
},
.spawn_thread = true,
},
{ "screenshot-to-clipboard", cmd_screenshot_to_clipboard,
{
{"flags", OPT_CHOICE(v.i,
{"video", 0},
{"window", 1},
{"subtitles", 2}),
OPTDEF_INT(2)},
},
.spawn_thread = true,
},
{ "screenshot-raw", cmd_screenshot_raw,
{
{"flags", OPT_CHOICE(v.i,
Expand Down
29 changes: 29 additions & 0 deletions player/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "misc/dispatch.h"
#include "misc/node.h"
#include "misc/thread_tools.h"
#include "clipboard/clipboard.h"
#include "common/msg.h"
#include "options/path.h"
#include "video/mp_image.h"
Expand Down Expand Up @@ -500,6 +501,34 @@ void cmd_screenshot_to_file(void *p)
talloc_free(image);
}

void cmd_screenshot_to_clipboard(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
int mode = cmd->args[0].v.i;
struct image_writer_opts opts = *mpctx->opts->screenshot_image_opts;
bool high_depth = image_writer_high_depth(&opts);
struct mp_image *image = screenshot_get(mpctx, mode, high_depth);
if (!image) {
mp_cmd_msg(cmd, MSGL_ERR, "Taking screenshot failed.");
cmd->success = false;
return;
}

struct clipboard_access_params params = {
.type = CLIPBOARD_DATA_IMAGE,
.target = CLIPBOARD_TARGET_CLIPBOARD,
};

struct clipboard_data item = {
.type = CLIPBOARD_DATA_IMAGE,
.u.image = image,
};

cmd->success = mp_clipboard_set_data(mpctx->clipboard, &params, &item) == CLIPBOARD_SUCCESS;
talloc_free(image);
}

void cmd_screenshot(void *p)
{
struct mp_cmd_ctx *cmd = p;
Expand Down
1 change: 1 addition & 0 deletions player/screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct mp_image *convert_image(struct mp_image *image, int destfmt,
// Handlers for the user-facing commands.
void cmd_screenshot(void *p);
void cmd_screenshot_to_file(void *p);
void cmd_screenshot_to_clipboard(void *p);
void cmd_screenshot_raw(void *p);

#endif /* MPLAYER_SCREENSHOT_H */

0 comments on commit 3d5afcb

Please sign in to comment.