summaryrefslogtreecommitdiff
path: root/src/unix/sdl/clipboard.c
blob: 53728f70c1fbf2bcfafdc150f09ea3265d66f7ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Copyright (C) 2003-2012 Andrey Nazarov

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "video.h"

#if USE_X11
#include <SDL_syswm.h>
#include <X11/Xutil.h>
#endif

/*
=================
VID_GetClipboardData
=================
*/
char *VID_GetClipboardData(void)
{
#if USE_X11
    SDL_SysWMinfo info;
    Display *dpy;
    Window win, sowner;
    Atom type, property;
    unsigned long len, bytes_left;
    unsigned char *data;
    int format, result;
    char *ret;

    SDL_VERSION(&info.version);
    if (!SDL_GetWMInfo(&info)) {
        return NULL;
    }

    if (info.subsystem != SDL_SYSWM_X11) {
        return NULL;
    }

    dpy = info.info.x11.display;
    win = info.info.x11.window;

    if (!dpy) {
        return NULL;
    }

    sowner = XGetSelectionOwner(dpy, XA_PRIMARY);
    if (sowner == None) {
        return NULL;
    }

    property = XInternAtom(dpy, "GETCLIPBOARDDATA_PROP", False);

    XConvertSelection(dpy, XA_PRIMARY, XA_STRING, property, win, CurrentTime);

    XSync(dpy, False);

    result = XGetWindowProperty(dpy, win, property, 0, 0, False,
                                AnyPropertyType, &type, &format, &len, &bytes_left, &data);

    if (result != Success) {
        return NULL;
    }

    ret = NULL;
    if (bytes_left) {
        result = XGetWindowProperty(dpy, win, property, 0, bytes_left, True,
                                    AnyPropertyType, &type, &format, &len, &bytes_left, &data);
        if (result == Success) {
            ret = Z_CopyString((char *)data);
        }
    }

    XFree(data);

    return ret;
#else
    return NULL;
#endif
}

/*
=================
VID_SetClipboardData
=================
*/
void VID_SetClipboardData(const char *data)
{
}