Mercurial > pidgin.yaz
annotate finch/plugins/gntclipboard.c @ 18058:4ca97b26a8fb
Mark the return type const for the following functions. I noticed this
while fixing some DBus stuff which I'll commit shortly.
* purple_accounts_get_all
* purple_connections_get_all
* purple_connections_get_connecting
* purple_conv_chat_get_ignored
* purple_conv_chat_get_users
* purple_get_chats
* purple_get_conversations
* purple_get_ims
* purple_notify_user_info_get_entries
References #1344
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 07 Jun 2007 04:22:42 +0000 |
parents | 30829e806dae |
children | 87e9d418cbf6 |
rev | line source |
---|---|
15818 | 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 | |
15823 | 111 plugin_load(PurplePlugin *plugin) |
15818 | 112 { |
15893
886025ef7daa
Build gntclipboard plugin by default. If we don't want this, at least
Stu Tomlinson <stu@nosnilmot.com>
parents:
15864
diff
changeset
|
113 #ifdef HAVE_X11 |
15818 | 114 if (!XOpenDisplay(NULL)) { |
15823 | 115 purple_debug_warning("gntclipboard", "Couldn't find X display\n"); |
15818 | 116 return FALSE; |
117 } | |
15893
886025ef7daa
Build gntclipboard plugin by default. If we don't want this, at least
Stu Tomlinson <stu@nosnilmot.com>
parents:
15864
diff
changeset
|
118 #endif |
15818 | 119 if (!getenv("WINDOWID")) { |
15823 | 120 purple_debug_warning("gntclipboard", "Couldn't find window\n"); |
15818 | 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 | |
15823 | 128 plugin_unload(PurplePlugin *plugin) |
15818 | 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 | |
15823 | 138 static PurplePluginInfo info = |
15818 | 139 { |
15823 | 140 PURPLE_PLUGIN_MAGIC, |
141 PURPLE_MAJOR_VERSION, | |
142 PURPLE_MINOR_VERSION, | |
143 PURPLE_PLUGIN_STANDARD, | |
144 FINCH_PLUGIN_TYPE, | |
15818 | 145 0, |
146 NULL, | |
15823 | 147 PURPLE_PRIORITY_DEFAULT, |
15818 | 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>", | |
15864
4c707efebc0c
Use PURPLE_WEBSITE instead of listing the website directly (which was wrong because of the sed).
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
155 PURPLE_WEBSITE, |
15818 | 156 plugin_load, |
157 plugin_unload, | |
158 NULL, | |
159 NULL, | |
160 NULL, | |
161 NULL, | |
16677
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15893
diff
changeset
|
162 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15893
diff
changeset
|
163 |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15893
diff
changeset
|
164 /* padding */ |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15893
diff
changeset
|
165 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15893
diff
changeset
|
166 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
15893
diff
changeset
|
167 NULL, |
15818 | 168 NULL |
169 }; | |
170 | |
171 static void | |
15823 | 172 init_plugin(PurplePlugin *plugin) |
15818 | 173 { |
174 } | |
175 | |
15823 | 176 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |