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 Apr 12, 2024
1 parent 8464810 commit 4fe4ab7
Show file tree
Hide file tree
Showing 4 changed files with 42 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 @@ -402,6 +402,12 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_).
Like all input command parameters, the filename is subject to property
expansion as described in `Property Expansion`_.

``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
11 changes: 11 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "misc/thread_pool.h"
#include "misc/thread_tools.h"

#include "osdep/clipboard.h"
#include "osdep/io.h"
#include "osdep/subprocess.h"
#include "osdep/terminal.h"
Expand Down Expand Up @@ -6854,6 +6855,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
24 changes: 24 additions & 0 deletions player/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "misc/dispatch.h"
#include "misc/node.h"
#include "misc/thread_tools.h"
#include "osdep/clipboard.h"
#include "common/msg.h"
#include "options/path.h"
#include "video/mp_image.h"
Expand Down Expand Up @@ -501,6 +502,29 @@ 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 m_clipboard_item item = {
.type = CLIPBOARD_IMAGE,
.image = image,
};

cmd->success = m_clipboard_set(mpctx, &item) == CLIPBOARD_OK;
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 4fe4ab7

Please sign in to comment.