Mercurial > pidgin
annotate finch/plugins/gntclipboard.c @ 15863:4c707efebc0c
Use PURPLE_WEBSITE instead of listing the website directly (which was wrong because of the sed).
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 21 Mar 2007 08:41:56 +0000 |
parents | 32c366eeeb99 |
children | 886025ef7daa |
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 { |
113 if (!XOpenDisplay(NULL)) { | |
15822 | 114 purple_debug_warning("gntclipboard", "Couldn't find X display\n"); |
15817 | 115 return FALSE; |
116 } | |
117 if (!getenv("WINDOWID")) { | |
15822 | 118 purple_debug_warning("gntclipboard", "Couldn't find window\n"); |
15817 | 119 return FALSE; |
120 } | |
121 sig_handle = g_signal_connect(G_OBJECT(gnt_get_clipboard()), "clipboard_changed", G_CALLBACK(clipboard_changed), NULL); | |
122 return TRUE; | |
123 } | |
124 | |
125 static gboolean | |
15822 | 126 plugin_unload(PurplePlugin *plugin) |
15817 | 127 { |
128 if (child) { | |
129 kill(child, SIGTERM); | |
130 child = 0; | |
131 } | |
132 g_signal_handler_disconnect(G_OBJECT(gnt_get_clipboard()), sig_handle); | |
133 return TRUE; | |
134 } | |
135 | |
15822 | 136 static PurplePluginInfo info = |
15817 | 137 { |
15822 | 138 PURPLE_PLUGIN_MAGIC, |
139 PURPLE_MAJOR_VERSION, | |
140 PURPLE_MINOR_VERSION, | |
141 PURPLE_PLUGIN_STANDARD, | |
142 FINCH_PLUGIN_TYPE, | |
15817 | 143 0, |
144 NULL, | |
15822 | 145 PURPLE_PRIORITY_DEFAULT, |
15817 | 146 "gntclipboard", |
147 N_("GntClipboard"), | |
148 VERSION, | |
149 N_("Clipboard plugin"), | |
150 N_("When the gnt clipboard contents change, " | |
151 "the contents are made available to X, if possible."), | |
152 "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
|
153 PURPLE_WEBSITE, |
15817 | 154 plugin_load, |
155 plugin_unload, | |
156 NULL, | |
157 NULL, | |
158 NULL, | |
159 NULL, | |
160 NULL | |
161 }; | |
162 | |
163 static void | |
15822 | 164 init_plugin(PurplePlugin *plugin) |
15817 | 165 { |
166 } | |
167 | |
15822 | 168 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |