~ubuntu-branches/ubuntu/trusty/fcitx/trusty-proposed

« back to all changes in this revision

Viewing changes to src/module/clipboard/clipboard-x11.c

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-02-10 17:03:56 UTC
  • mfrom: (1.3.18) (33.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20130210170356-2yuv6xy3ed378kn0
Tags: 1:4.2.7-1
* New upstream release.
* New binary packages:
  - fcitx-libs-gclient: D-Bus client library for Glib
  - fcitx-libs-qt: D-Bus client library for Qt
  - fcitx-module-quickphrase-editor: Quick Phrase editor module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2012~2012 by Yichao Yu                                  *
 
3
 *   yyc1992@gmail.com                                                     *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
 
19
 ***************************************************************************/
 
20
 
 
21
#include "fcitx/fcitx.h"
 
22
#include "config.h"
 
23
#include "clipboard-internal.h"
 
24
#include "fcitx/module.h"
 
25
#include "module/x11/fcitx-x11.h"
 
26
 
 
27
static void
 
28
_X11ClipboardPrimaryConvertCb(
 
29
    void *owner, const char *sel_str, const char *tgt_str, int format,
 
30
    size_t nitems, const void *buff, void *data)
 
31
{
 
32
    FCITX_UNUSED(sel_str);
 
33
    FCITX_UNUSED(tgt_str);
 
34
    FCITX_UNUSED(data);
 
35
    FcitxClipboard *clipboard = owner;
 
36
    if (format != 8)
 
37
        return;
 
38
    ClipboardSetPrimary(clipboard, nitems, buff);
 
39
}
 
40
 
 
41
static void
 
42
_X11ClipboardPrimaryNotifyCb(void *owner, const char *sel_str,
 
43
                             int subtype, void *data)
 
44
{
 
45
    FCITX_UNUSED(sel_str);
 
46
    FCITX_UNUSED(subtype);
 
47
    FCITX_UNUSED(data);
 
48
    FcitxClipboard *clipboard = owner;
 
49
    FcitxX11RequestConvertSelect(clipboard->owner, "PRIMARY", NULL,
 
50
                                 clipboard, _X11ClipboardPrimaryConvertCb,
 
51
                                 NULL, NULL);
 
52
}
 
53
 
 
54
static void
 
55
_X11ClipboardClipboardConvertCb(
 
56
    void *owner, const char *sel_str, const char *tgt_str, int format,
 
57
    size_t nitems, const void *buff, void *data)
 
58
{
 
59
    FCITX_UNUSED(sel_str);
 
60
    FCITX_UNUSED(tgt_str);
 
61
    FCITX_UNUSED(data);
 
62
    FcitxClipboard *clipboard = owner;
 
63
    if (format != 8)
 
64
        return;
 
65
    ClipboardPushClipboard(clipboard, nitems, buff);
 
66
}
 
67
 
 
68
static void
 
69
_X11ClipboardClipboardNotifyCb(void *owner, const char *sel_str,
 
70
                               int subtype, void *data)
 
71
{
 
72
    FCITX_UNUSED(sel_str);
 
73
    FCITX_UNUSED(subtype);
 
74
    FCITX_UNUSED(data);
 
75
    FcitxClipboard *clipboard = owner;
 
76
    FcitxX11RequestConvertSelect(clipboard->owner, "CLIPBOARD", NULL,
 
77
                                 clipboard, _X11ClipboardClipboardConvertCb,
 
78
                                 NULL, NULL);
 
79
}
 
80
 
 
81
void
 
82
ClipboardInitX11(FcitxClipboard *clipboard)
 
83
{
 
84
    FcitxInstance *instance = clipboard->owner;
 
85
    clipboard->x11 = FcitxX11GetAddon(instance);
 
86
    if (!clipboard->x11)
 
87
        return;
 
88
    clipboard->x11_primary_notify_id = FcitxX11RegSelectNotify(
 
89
        instance, "PRIMARY", clipboard,
 
90
        _X11ClipboardPrimaryNotifyCb, NULL, NULL);
 
91
    clipboard->x11_clipboard_notify_id = FcitxX11RegSelectNotify(
 
92
        instance, "CLIPBOARD", clipboard,
 
93
        _X11ClipboardClipboardNotifyCb, NULL, NULL);
 
94
    FcitxX11RequestConvertSelect(clipboard->owner, "PRIMARY", NULL,
 
95
                                 clipboard, _X11ClipboardPrimaryConvertCb,
 
96
                                 NULL, NULL);
 
97
    FcitxX11RequestConvertSelect(clipboard->owner, "CLIPBOARD", NULL,
 
98
                                 clipboard, _X11ClipboardClipboardConvertCb,
 
99
                                 NULL, NULL);
 
100
}