clipboard-mac: add macOS clipboard backend

This commit is contained in:
der richter
2024-12-23 14:22:50 +01:00
parent e8ecc7d9d9
commit 026f1fb61d
7 changed files with 146 additions and 4 deletions

View File

@@ -0,0 +1,59 @@
/*
* This file is part of mpv.
*
* mpv is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* mpv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include "clipboard.h"
#include "osdep/mac/swift.h"
struct clipboard_mac_priv {
Clipboard *clipboard;
};
static int init(struct clipboard_ctx *cl, struct clipboard_init_params *params)
{
struct clipboard_mac_priv *p = cl->priv = talloc_zero(cl, struct clipboard_mac_priv);
p->clipboard = [[Clipboard alloc] init];
return CLIPBOARD_SUCCESS;
}
static bool data_changed(struct clipboard_ctx *cl)
{
struct clipboard_mac_priv *p = cl->priv;
return [p->clipboard changed];
}
static int get_data(struct clipboard_ctx *cl, struct clipboard_access_params *params,
struct clipboard_data *out, void *talloc_ctx)
{
struct clipboard_mac_priv *p = cl->priv;
return [p->clipboard getWithParams:params out:out tallocCtx:talloc_ctx];
}
static int set_data(struct clipboard_ctx *cl, struct clipboard_access_params *params,
struct clipboard_data *data)
{
struct clipboard_mac_priv *p = cl->priv;
return [p->clipboard setWithParams:params data:data];
}
const struct clipboard_backend clipboard_backend_mac = {
.name = "mac",
.desc = "macOS clipboard",
.init = init,
.data_changed = data_changed,
.get_data = get_data,
.set_data = set_data,
};

View File

@@ -42,11 +42,15 @@ const struct m_sub_options clipboard_conf = {
// backend list
extern const struct clipboard_backend clipboard_backend_win32;
extern const struct clipboard_backend clipboard_backend_mac;
extern const struct clipboard_backend clipboard_backend_vo;
static const struct clipboard_backend *const clipboard_backend_list[] = {
#if HAVE_WIN32_DESKTOP
&clipboard_backend_win32,
#endif
#if HAVE_COCOA
&clipboard_backend_mac,
#endif
&clipboard_backend_vo,
};