mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
clipboard-mac: add macOS clipboard backend
This commit is contained in:
59
player/clipboard/clipboard-mac.m
Normal file
59
player/clipboard/clipboard-mac.m
Normal 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,
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user