Mercurial > pidgin
annotate finch/plugins/gntclipboard.c @ 16977:563a42d98e3a
Fix ticket #387.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 09 May 2007 21:03:40 +0000 |
parents | 30829e806dae |
children | 87e9d418cbf6 |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gntclipboard.c | |
3 * | |
4 * Copyright (C) 2007 Richard Nelson <wabz@whatsbeef.net> | |
5 * | |
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. | |
10 * | |
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. | |
15 * | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 | |
21 | |
22 #include "internal.h" | |
23 #include <glib.h> | |
24 | |
25 #define PLUGIN_STATIC_NAME "GntClipboard" | |
26 | |
27 #ifdef HAVE_X11 | |
28 #include <X11/Xlib.h> | |
29 #include <X11/Xutil.h> | |
30 #include <X11/Xatom.h> | |
31 #endif | |
32 | |
33 #include <sys/types.h> | |
34 #include <signal.h> | |
35 | |
36 #include <glib.h> | |
37 | |
38 #include <plugin.h> | |
39 #include <version.h> | |
40 #include <debug.h> | |
41 #include <gntwm.h> | |
42 | |
43 #include <gntplugin.h> | |
44 | |
45 static pid_t child = 0; | |
46 | |
47 static gulong sig_handle; | |
48 | |
49 static void | |
50 set_clip(gchar *string) | |
51 { | |
52 #ifdef HAVE_X11 | |
53 Window w; | |
54 XEvent e, respond; | |
55 XSelectionRequestEvent *req; | |
56 const char *ids; | |
57 Display *dpy = XOpenDisplay(NULL); | |
58 | |
59 if (!dpy) | |
60 return; | |
61 ids = getenv("WINDOWID"); | |
62 if (ids == NULL) | |
63 return; | |
64 w = atoi(ids); | |
65 XSetSelectionOwner(dpy, XA_PRIMARY, w, CurrentTime); | |
66 XFlush(dpy); | |
67 XSelectInput(dpy, w, StructureNotifyMask); | |
68 while (TRUE) { | |
69 XNextEvent(dpy, &e); /* this blocks. */ | |
70 req = &e.xselectionrequest; | |
71 if (e.type == SelectionRequest) { | |
72 XChangeProperty(dpy, | |
73 req->requestor, | |
74 req->property, | |
75 XA_STRING, | |
76 8, PropModeReplace, | |
77 (unsigned char *)string, | |
78 strlen(string)); | |
79 respond.xselection.property = req->property; | |
80 respond.xselection.type = SelectionNotify; | |
81 respond.xselection.display = req->display; | |
82 respond.xselection.requestor = req->requestor; | |
83 respond.xselection.selection = req->selection; | |
84 respond.xselection.target= req->target; | |
85 respond.xselection.time = req->time; | |
86 XSendEvent(dpy, req->requestor, 0, 0, &respond); | |
87 XFlush (dpy); | |
88 } else if (e.type == SelectionClear) { | |
89 return; | |
90 } | |
91 } | |
92 #endif | |
93 return; | |
94 } | |
95 | |
96 static void | |
97 clipboard_changed(GntWM *wm, gchar *string) | |
98 { | |
99 #ifdef HAVE_X11 | |
100 if (child) { | |
101 kill(child, SIGTERM); | |
102 } | |
103 if ((child = fork() == 0)) { | |
104 set_clip(string); | |
105 _exit(0); | |
106 } | |
107 #endif | |
108 } | |
109 | |
110 static gboolean | |
15822 | 111 plugin_load(PurplePlugin *plugin) |
15817 | 112 { |
15891
886025ef7daa
Build gntclipboard plugin by default. If we don't want this, at least
Stu Tomlinson <stu@nosnilmot.com>
parents:
15863
diff
changeset
|
113 #ifdef HAVE_X11 |
15817 | 114 if (!XOpenDisplay(NULL)) { |
15822 | 115 purple_debug_warning("gntclipboard", "Couldn't find X display\n"); |
15817 | 116 return FALSE; |
117 } | |
15891
886025ef7daa
Build gntclipboard plugin by default. If we don't want this, at least
Stu Tomlinson <stu@nosnilmot.com>
parents:
15863
diff
changeset
|
118 #endif |
15817 | 119 if (!getenv("WINDOWID")) { |
15822 | 120 purple_debug_warning("gntclipboard", "Couldn't find window\n"); |
15817 | 121 return FALSE; |
122 } | |
123 sig_handle = g_signal_connect(G_OBJECT(gnt_get_clipboard()), "clipboard_changed", G_CALLBACK(clipboard_changed), NULL); | |
124 return TRUE; | |
125 } | |
126 | |
127 static gboolean | |
15822 | 128 plugin_unload(PurplePlugin *plugin) |
15817 | 129 { |
130 if (child) { | |
131 kill(child, SIGTERM); | |
132 child = 0; | |
133 } | |
134 g_signal_handler_disconnect(G_OBJECT(gnt_get_clipboard()), sig_handle); | |
135 return TRUE; | |
136 } | |
137 | |
15822 | 138 static PurplePluginInfo info = |
15817 | 139 { |
15822 | 140 PURPLE_PLUGIN_MAGIC, |
141 PURPLE_MAJOR_VERSION, | |
142 PURPLE_MINOR_VERSION, | |
143 PURPLE_PLUGIN_STANDARD, | |
144 FINCH_PLUGIN_TYPE, | |
15817 | 145 0, |
146 NULL, | |
15822 | 147 PURPLE_PRIORITY_DEFAULT, |
15817 | 148 "gntclipboard", |
149 N_("GntClipboard"), | |
150 VERSION, | |
151 N_("Clipboard plugin"), | |
152 N_("When the gnt clipboard contents change, " | |
153 "the contents are made available to X, if possible."), | |
154 "Richard Nelson <wabz@whatsbeef.net>", | |
15863
4c707efebc0c
Use PURPLE_WEBSITE instead of listing the website directly (which was wrong because of the sed).
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
155 PURPLE_WEBSITE, |
15817 | 156 plugin_load, |
157 plugin_unload, | |
158 NULL, | |
159 NULL, | |
160 NULL, | |
161 NULL, | |
16669
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15891
diff
changeset
|
162 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15891
diff
changeset
|
163 |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15891
diff
changeset
|
164 /* padding */ |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15891
diff
changeset
|
165 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15891
diff
changeset
|
166 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15891
diff
changeset
|
167 NULL, |
15817 | 168 NULL |
169 }; | |
170 | |
171 static void | |
15822 | 172 init_plugin(PurplePlugin *plugin) |
15817 | 173 { |
174 } | |
175 | |
15822 | 176 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |