4 * Copyright (C) 2007 Richard Nelson <wabz@whatsbeef.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25 #define PLUGIN_STATIC_NAME "GntClipboard"
29 #include <X11/Xutil.h>
30 #include <X11/Xatom.h>
33 #include <sys/types.h>
44 #include <gntplugin.h>
47 static pid_t child
= 0;
49 static gulong sig_handle
;
52 set_clip(gchar
*string
)
56 XSelectionRequestEvent
*req
;
58 Display
*dpy
= XOpenDisplay(NULL
);
62 ids
= getenv("WINDOWID");
66 XSetSelectionOwner(dpy
, XA_PRIMARY
, w
, CurrentTime
);
68 XSelectInput(dpy
, w
, StructureNotifyMask
);
70 XNextEvent(dpy
, &e
); /* this blocks. */
71 req
= &e
.xselectionrequest
;
72 if (e
.type
== SelectionRequest
) {
78 (unsigned char *)string
,
80 respond
.xselection
.property
= req
->property
;
81 respond
.xselection
.type
= SelectionNotify
;
82 respond
.xselection
.display
= req
->display
;
83 respond
.xselection
.requestor
= req
->requestor
;
84 respond
.xselection
.selection
= req
->selection
;
85 respond
.xselection
.target
= req
->target
;
86 respond
.xselection
.time
= req
->time
;
87 XSendEvent(dpy
, req
->requestor
, 0, 0, &respond
);
89 } else if (e
.type
== SelectionClear
) {
97 clipboard_changed(GntWM
*wm
, gchar
*string
)
100 kill(child
, SIGTERM
);
102 if ((child
= fork() == 0)) {
110 plugin_load(PurplePlugin
*plugin
)
113 if (!XOpenDisplay(NULL
)) {
114 purple_debug_warning("gntclipboard", "Couldn't find X display\n");
115 purple_notify_error(NULL
, _("Error"), _("Error loading the plugin."),
116 _("Couldn't find X display"));
119 if (!getenv("WINDOWID")) {
120 purple_debug_warning("gntclipboard", "Couldn't find window\n");
121 purple_notify_error(NULL
, _("Error"), _("Error loading the plugin."),
122 _("Couldn't find window"));
125 sig_handle
= g_signal_connect(G_OBJECT(gnt_get_clipboard()), "clipboard_changed", G_CALLBACK(clipboard_changed
), NULL
);
128 purple_notify_error(NULL
, _("Error"), _("Error loading the plugin."),
129 _("This plugin cannot be loaded because it was not built with X11 support."));
135 plugin_unload(PurplePlugin
*plugin
)
139 kill(child
, SIGTERM
);
142 g_signal_handler_disconnect(G_OBJECT(gnt_get_clipboard()), sig_handle
);
147 static PurplePluginInfo info
=
150 PURPLE_MAJOR_VERSION
,
151 PURPLE_MINOR_VERSION
,
152 PURPLE_PLUGIN_STANDARD
,
156 PURPLE_PRIORITY_DEFAULT
,
160 N_("Clipboard plugin"),
161 N_("When the gnt clipboard contents change, "
162 "the contents are made available to X, if possible."),
163 "Richard Nelson <wabz@whatsbeef.net>",
181 init_plugin(PurplePlugin
*plugin
)
185 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME
, init_plugin
, info
)