Merge lp:~andrew-bugs-launchpad-net/nspluginwrapper/flashsaver into lp:nspluginwrapper
- flashsaver
- Merge into ubuntu
Proposed by
Andrew Sayers
Status: | Needs review |
---|---|
Proposed branch: | lp:~andrew-bugs-launchpad-net/nspluginwrapper/flashsaver |
Merge into: | lp:nspluginwrapper |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~andrew-bugs-launchpad-net/nspluginwrapper/flashsaver |
Related bugs: |
This proposal supersedes a proposal from 2009-06-13.
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Andrew Sayers (andrew-bugs-launchpad-net) wrote : Posted in a previous version of this proposal | # |
Unmerged revisions
- 58. By Andrew Sayers <email address hidden>
-
Ran flashsaver through valgrind, caught a few memory leaks
- 57. By Andrew Sayers <email address hidden>
-
s/dbus-1/libdbus-1/ in debian/control
- 56. By Andrew Sayers <email address hidden>
-
Fixed a daft build-dependency issue
- 55. By Andrew Sayers <email address hidden>
-
Flash screensaver workaround now operational
- 54. By Andrew Sayers <email address hidden>
-
Initial Flash screensaver workaround
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Makefile' | |||
2 | --- Makefile 2009-01-02 10:07:27 +0000 | |||
3 | +++ Makefile 2009-06-13 09:20:20 +0000 | |||
4 | @@ -143,6 +143,15 @@ | |||
5 | 143 | npviewer_LDFLAGS += $(libsocket_LDFLAGS) | 143 | npviewer_LDFLAGS += $(libsocket_LDFLAGS) |
6 | 144 | endif | 144 | endif |
7 | 145 | 145 | ||
8 | 146 | npsaver_PROGRAM = npsaver.bin | ||
9 | 147 | npsaver_RAWSRCS = npw-screensaver.c inhibit-screensaver.c | ||
10 | 148 | npsaver_SOURCES = $(npsaver_RAWSRCS:%.c=$(SRC_PATH)/src/%.c) | ||
11 | 149 | npsaver_OBJECTS = $(npsaver_RAWSRCS:%.c=npsaver-%.o) | ||
12 | 150 | npsaver_CFLAGS = $(DBUS_CFLAGS) -DNDEBUG | ||
13 | 151 | npsaver_LDFLAGS = $(DBUS_LDFLAGS) | ||
14 | 152 | npsaver_LDFLAGS += $(X_LDFLAGS) | ||
15 | 153 | npsaver_LDFLAGS += $(libdl_LDFLAGS) $(libpthread_LDFLAGS) -lgthread-2.0 | ||
16 | 154 | |||
17 | 146 | npplayer_PROGRAM = npplayer | 155 | npplayer_PROGRAM = npplayer |
18 | 147 | npplayer_SOURCES = npw-player.c debug.c rpc.c utils.c glibcurl.c gtk2xtbin.c $(tidy_SOURCES) | 156 | npplayer_SOURCES = npw-player.c debug.c rpc.c utils.c glibcurl.c gtk2xtbin.c $(tidy_SOURCES) |
19 | 148 | npplayer_OBJECTS = $(npplayer_SOURCES:%.c=npplayer-%.o) | 157 | npplayer_OBJECTS = $(npplayer_SOURCES:%.c=npplayer-%.o) |
20 | @@ -208,6 +217,7 @@ | |||
21 | 208 | TARGETS += $(npwrapper_LIBRARY) | 217 | TARGETS += $(npwrapper_LIBRARY) |
22 | 209 | ifeq ($(build_viewer),yes) | 218 | ifeq ($(build_viewer),yes) |
23 | 210 | TARGETS += $(npviewer_PROGRAM) | 219 | TARGETS += $(npviewer_PROGRAM) |
24 | 220 | TARGETS += $(npsaver_PROGRAM) | ||
25 | 211 | TARGETS += $(libxpcom_LIBRARY) | 221 | TARGETS += $(libxpcom_LIBRARY) |
26 | 212 | TARGETS += $(libnoxshm_LIBRARY) | 222 | TARGETS += $(libnoxshm_LIBRARY) |
27 | 213 | endif | 223 | endif |
28 | @@ -253,7 +263,7 @@ | |||
29 | 253 | distclean: clean | 263 | distclean: clean |
30 | 254 | rm -f config-host.* config.* | 264 | rm -f config-host.* config.* |
31 | 255 | 265 | ||
33 | 256 | uninstall: uninstall.player uninstall.wrapper uninstall.viewer uninstall.libxpcom uninstall.libnoxshm uninstall.loader uninstall.config uninstall.dirs | 266 | uninstall: uninstall.player uninstall.wrapper uninstall.viewer uninstall.saver uninstall.libxpcom uninstall.libnoxshm uninstall.loader uninstall.config uninstall.dirs |
34 | 257 | uninstall.dirs: | 267 | uninstall.dirs: |
35 | 258 | rmdir $(DESTDIR)$(pkglibdir)/noarch | 268 | rmdir $(DESTDIR)$(pkglibdir)/noarch |
36 | 259 | rmdir $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS) | 269 | rmdir $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS) |
37 | @@ -269,6 +279,9 @@ | |||
38 | 269 | uninstall.viewer: | 279 | uninstall.viewer: |
39 | 270 | rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM) | 280 | rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM) |
40 | 271 | rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM:%.bin=%) | 281 | rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM:%.bin=%) |
41 | 282 | uninstall.saver: | ||
42 | 283 | rm -f $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)/$(npsaver_PROGRAM) | ||
43 | 284 | rm -f $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)/$(npsaver_PROGRAM:%.bin=%) | ||
44 | 272 | uninstall.libxpcom: | 285 | uninstall.libxpcom: |
45 | 273 | rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(libxpcom_LIBRARY) | 286 | rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(libxpcom_LIBRARY) |
46 | 274 | uninstall.libnoxshm: | 287 | uninstall.libnoxshm: |
47 | @@ -281,7 +294,7 @@ | |||
48 | 281 | uninstall.mkruntime: | 294 | uninstall.mkruntime: |
49 | 282 | rm -f $(DESTDIR)$(pkglibdir)/noarch/mkruntime | 295 | rm -f $(DESTDIR)$(pkglibdir)/noarch/mkruntime |
50 | 283 | 296 | ||
52 | 284 | install: install.dirs install.player install.wrapper install.viewer install.libxpcom install.libnoxshm install.loader install.config | 297 | install: install.dirs install.player install.wrapper install.viewer install.saver install.libxpcom install.libnoxshm install.loader install.config |
53 | 285 | install.dirs: | 298 | install.dirs: |
54 | 286 | mkdir -p $(DESTDIR)$(pkglibdir)/noarch | 299 | mkdir -p $(DESTDIR)$(pkglibdir)/noarch |
55 | 287 | mkdir -p $(DESTDIR)$(pkglibdir)/$(ARCH) | 300 | mkdir -p $(DESTDIR)$(pkglibdir)/$(ARCH) |
56 | @@ -302,6 +315,8 @@ | |||
57 | 302 | $(INSTALL) -m 755 $(STRIP_OPT) $(npwrapper_LIBRARY) $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)/$(npwrapper_LIBRARY) | 315 | $(INSTALL) -m 755 $(STRIP_OPT) $(npwrapper_LIBRARY) $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)/$(npwrapper_LIBRARY) |
58 | 303 | ifeq ($(build_viewer),yes) | 316 | ifeq ($(build_viewer),yes) |
59 | 304 | install.viewer: install.viewer.bin install.viewer.glue | 317 | install.viewer: install.viewer.bin install.viewer.glue |
60 | 318 | install.saver: $(npsaver_PROGRAM) | ||
61 | 319 | $(INSTALL) -m 755 $(STRIP_OPT) $(npsaver_PROGRAM) $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)/$(npsaver_PROGRAM) | ||
62 | 305 | install.libxpcom: do.install.libxpcom | 320 | install.libxpcom: do.install.libxpcom |
63 | 306 | install.libnoxshm: do.install.libnoxshm | 321 | install.libnoxshm: do.install.libnoxshm |
64 | 307 | else | 322 | else |
65 | @@ -386,6 +401,15 @@ | |||
66 | 386 | npviewer-%.o: $(SRC_PATH)/src/%.cpp | 401 | npviewer-%.o: $(SRC_PATH)/src/%.cpp |
67 | 387 | $(CXX) $(CFLAGS_32) -o $@ -c $< $(CPPFLAGS) $(npviewer_CFLAGS) -DBUILD_VIEWER | 402 | $(CXX) $(CFLAGS_32) -o $@ -c $< $(CPPFLAGS) $(npviewer_CFLAGS) -DBUILD_VIEWER |
68 | 388 | 403 | ||
69 | 404 | $(npsaver_PROGRAM): $(npsaver_OBJECTS) $(LSB_OBJ_DIR) $(LSB_LIBS) | ||
70 | 405 | $(CC) $(LDFLAGS) -o $@ $(npsaver_OBJECTS) $(npsaver_LDFLAGS) | ||
71 | 406 | |||
72 | 407 | npsaver-%.o: $(SRC_PATH)/src/%.c | ||
73 | 408 | $(CC) $(CFLAGS) -o $@ -c $< $(CPPFLAGS) $(npsaver_CFLAGS) -DBUILD_VIEWER | ||
74 | 409 | |||
75 | 410 | npsaver-%.o: $(SRC_PATH)/src/%.cpp | ||
76 | 411 | $(CXX) $(CFLAGS) -o $@ -c $< $(CPPFLAGS) $(npsaver_CFLAGS) -DBUILD_VIEWER | ||
77 | 412 | |||
78 | 389 | $(npplayer_PROGRAM): $(npplayer_OBJECTS) $(npplayer_MAPFILE) $(LSB_OBJ_DIR) $(LSB_LIBS) | 413 | $(npplayer_PROGRAM): $(npplayer_OBJECTS) $(npplayer_MAPFILE) $(LSB_OBJ_DIR) $(LSB_LIBS) |
79 | 390 | $(CC) $(LDFLAGS) -o $@ $(npplayer_OBJECTS) $(npplayer_LDFLAGS) | 414 | $(CC) $(LDFLAGS) -o $@ $(npplayer_OBJECTS) $(npplayer_LDFLAGS) |
80 | 391 | 415 | ||
81 | 392 | 416 | ||
82 | === modified file 'configure' | |||
83 | --- configure 2009-01-02 10:07:27 +0000 | |||
84 | +++ configure 2009-06-13 09:20:20 +0000 | |||
85 | @@ -436,6 +436,32 @@ | |||
86 | 436 | rm -f $TMPC $TMPE | 436 | rm -f $TMPC $TMPE |
87 | 437 | fi | 437 | fi |
88 | 438 | 438 | ||
89 | 439 | # check for DBUS-1 compile CFLAGS | ||
90 | 440 | if test "$build_viewer" = "yes" -o "$build_player" = "yes"; then | ||
91 | 441 | if $pkgconfig --exists dbus-1; then | ||
92 | 442 | DBUS_CFLAGS=`$pkgconfig --cflags dbus-1` | ||
93 | 443 | DBUS_LDFLAGS=`$pkgconfig --libs dbus-1` | ||
94 | 444 | DBUS_VERSION=`$pkgconfig --modversion dbus-1` | ||
95 | 445 | else | ||
96 | 446 | echo "DBUS not found" | ||
97 | 447 | exit 1 | ||
98 | 448 | fi | ||
99 | 449 | cat > $TMPC << EOF | ||
100 | 450 | #include <dbus/dbus.h> | ||
101 | 451 | int main(void) { | ||
102 | 452 | DBusError err; | ||
103 | 453 | dbus_error_init(&err); | ||
104 | 454 | return 0; | ||
105 | 455 | } | ||
106 | 456 | EOF | ||
107 | 457 | if ! $cc $CFLAGS $DBUS_CFLAGS $DBUS_LDFLAGS $TMPC -o $TMPE > /dev/null 2>&1; then | ||
108 | 458 | echo "DBUS not usable" | ||
109 | 459 | rm -f $TMPC | ||
110 | 460 | exit 1 | ||
111 | 461 | fi | ||
112 | 462 | rm -f $TMPC $TMPE | ||
113 | 463 | fi | ||
114 | 464 | |||
115 | 439 | # check for cURL compile CFLAGS | 465 | # check for cURL compile CFLAGS |
116 | 440 | if test "$build_player" = "yes"; then | 466 | if test "$build_player" = "yes"; then |
117 | 441 | if $pkgconfig --exists libcurl; then | 467 | if $pkgconfig --exists libcurl; then |
118 | @@ -689,6 +715,8 @@ | |||
119 | 689 | echo "GLIB_LDFLAGS=$GLIB_LDFLAGS" >> $config_mak | 715 | echo "GLIB_LDFLAGS=$GLIB_LDFLAGS" >> $config_mak |
120 | 690 | echo "GTK_CFLAGS=$GTK_CFLAGS" >> $config_mak | 716 | echo "GTK_CFLAGS=$GTK_CFLAGS" >> $config_mak |
121 | 691 | echo "GTK_LDFLAGS=$GTK_LDFLAGS" >> $config_mak | 717 | echo "GTK_LDFLAGS=$GTK_LDFLAGS" >> $config_mak |
122 | 718 | echo "DBUS_CFLAGS=$DBUS_CFLAGS" >> $config_mak | ||
123 | 719 | echo "DBUS_LDFLAGS=$DBUS_LDFLAGS" >> $config_mak | ||
124 | 692 | echo "CURL_CFLAGS=$CURL_CFLAGS" >> $config_mak | 720 | echo "CURL_CFLAGS=$CURL_CFLAGS" >> $config_mak |
125 | 693 | echo "CURL_LDFLAGS=$CURL_LDFLAGS" >> $config_mak | 721 | echo "CURL_LDFLAGS=$CURL_LDFLAGS" >> $config_mak |
126 | 694 | if test "$biarch" = "yes"; then | 722 | if test "$biarch" = "yes"; then |
127 | 695 | 723 | ||
128 | === modified file 'debian/control' | |||
129 | --- debian/control 2008-08-27 17:19:36 +0000 | |||
130 | +++ debian/control 2009-06-13 16:56:18 +0000 | |||
131 | @@ -3,7 +3,7 @@ | |||
132 | 3 | Priority: optional | 3 | Priority: optional |
133 | 4 | Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com> | 4 | Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com> |
134 | 5 | XSBC-Original-Maintainer: Rob Andrews <rob@choralone.org> | 5 | XSBC-Original-Maintainer: Rob Andrews <rob@choralone.org> |
136 | 6 | Build-Depends: debhelper (>= 5), quilt, autotools-dev, libc6-dev-i386 [ amd64 ], libxt-dev, x11proto-core-dev, x11proto-xext-dev, libx11-dev, libatk1.0-dev, libfontconfig1-dev, libgtk2.0-dev, libglib2.0-dev, libpango1.0-dev, ia32-libs [ amd64 ], gcc-multilib [ amd64 ], g++-multilib [ amd64 ], libcurl4-gnutls-dev | 6 | Build-Depends: debhelper (>= 5), quilt, autotools-dev, libc6-dev-i386 [ amd64 ], libxt-dev, x11proto-core-dev, x11proto-xext-dev, libx11-dev, libatk1.0-dev, libfontconfig1-dev, libgtk2.0-dev, libglib2.0-dev, libpango1.0-dev, ia32-libs [ amd64 ], gcc-multilib [ amd64 ], g++-multilib [ amd64 ], libcurl4-gnutls-dev, libdbus-1-dev |
137 | 7 | Standards-Version: 3.8.0 | 7 | Standards-Version: 3.8.0 |
138 | 8 | Xs-Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-dev/nspluginwrapper/ubuntu | 8 | Xs-Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-dev/nspluginwrapper/ubuntu |
139 | 9 | 9 | ||
140 | 10 | 10 | ||
141 | === added file 'src/inhibit-screensaver.c' | |||
142 | --- src/inhibit-screensaver.c 1970-01-01 00:00:00 +0000 | |||
143 | +++ src/inhibit-screensaver.c 2009-06-23 12:32:38 +0000 | |||
144 | @@ -0,0 +1,195 @@ | |||
145 | 1 | /* | ||
146 | 2 | * inhibit-screensaver.c - screensaver (dis)inhibition functions | ||
147 | 3 | * | ||
148 | 4 | * nspluginwrapper (C) 2005-2009 Gwenole Beauchesne | ||
149 | 5 | * | ||
150 | 6 | * This program is free software; you can redistribute it and/or modify | ||
151 | 7 | * it under the terms of the GNU General Public License as published by | ||
152 | 8 | * the Free Software Foundation; either version 2 of the License, or | ||
153 | 9 | * (at your option) any later version. | ||
154 | 10 | * | ||
155 | 11 | * This program is distributed in the hope that it will be useful, | ||
156 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
157 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
158 | 14 | * GNU General Public License for more details. | ||
159 | 15 | * | ||
160 | 16 | * You should have received a copy of the GNU General Public License along | ||
161 | 17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
162 | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
163 | 19 | */ | ||
164 | 20 | |||
165 | 21 | #include <dbus/dbus.h> | ||
166 | 22 | #include <stdio.h> | ||
167 | 23 | #include <stdlib.h> | ||
168 | 24 | |||
169 | 25 | #define DBUS_MESSAGE(O, M) dbus_message_new_method_call("org."O".ScreenSaver", "/org/"O"/ScreenSaver", "org."O".ScreenSaver", M) | ||
170 | 26 | |||
171 | 27 | // GNOME and KDE use the compatible interfaces with different names | ||
172 | 28 | static DBusMessage *freedesktop_inhibit; | ||
173 | 29 | static DBusMessage *gnome_inhibit; | ||
174 | 30 | |||
175 | 31 | static DBusConnection *connection; | ||
176 | 32 | |||
177 | 33 | static char const*const name = "npviewer.bin"; | ||
178 | 34 | static char const*const reason = "Fullscreen Flash application running"; | ||
179 | 35 | |||
180 | 36 | static enum { UNINITIALISED, UNINHIBITED, INHIBITED } state = UNINITIALISED; | ||
181 | 37 | |||
182 | 38 | static unsigned int freedesktop_cookie; | ||
183 | 39 | static unsigned int gnome_cookie; | ||
184 | 40 | |||
185 | 41 | void screensaver_terminate() { | ||
186 | 42 | #ifndef NDEBUG | ||
187 | 43 | printf("Freeing screensaver data\n"); | ||
188 | 44 | #endif | ||
189 | 45 | if (freedesktop_inhibit) | ||
190 | 46 | dbus_message_unref(freedesktop_inhibit); | ||
191 | 47 | freedesktop_inhibit = 0; | ||
192 | 48 | if (gnome_inhibit) | ||
193 | 49 | dbus_message_unref(gnome_inhibit); | ||
194 | 50 | gnome_inhibit = 0; | ||
195 | 51 | if (connection) | ||
196 | 52 | dbus_connection_unref(connection); | ||
197 | 53 | connection = 0; | ||
198 | 54 | }; | ||
199 | 55 | |||
200 | 56 | void initialise() { | ||
201 | 57 | |||
202 | 58 | if (UNINITIALISED != state) return; | ||
203 | 59 | |||
204 | 60 | DBusError err; | ||
205 | 61 | |||
206 | 62 | dbus_error_init(&err); | ||
207 | 63 | |||
208 | 64 | connection = dbus_bus_get(DBUS_BUS_SESSION, &err); | ||
209 | 65 | if (dbus_error_is_set(&err)) { | ||
210 | 66 | fprintf(stderr, "Connection Error (%s)\n", err.message); | ||
211 | 67 | dbus_error_free(&err); | ||
212 | 68 | } | ||
213 | 69 | if (NULL == connection) { | ||
214 | 70 | exit(1); | ||
215 | 71 | } | ||
216 | 72 | |||
217 | 73 | freedesktop_inhibit = DBUS_MESSAGE("freedesktop", "Inhibit"); | ||
218 | 74 | gnome_inhibit = DBUS_MESSAGE("gnome" , "Inhibit"); | ||
219 | 75 | |||
220 | 76 | dbus_message_append_args(freedesktop_inhibit, | ||
221 | 77 | DBUS_TYPE_STRING, &name, | ||
222 | 78 | DBUS_TYPE_STRING, &reason, | ||
223 | 79 | DBUS_TYPE_INVALID); | ||
224 | 80 | |||
225 | 81 | dbus_message_append_args(gnome_inhibit, | ||
226 | 82 | DBUS_TYPE_STRING, &name, | ||
227 | 83 | DBUS_TYPE_STRING, &reason, | ||
228 | 84 | DBUS_TYPE_INVALID); | ||
229 | 85 | |||
230 | 86 | state = UNINHIBITED; | ||
231 | 87 | |||
232 | 88 | atexit(screensaver_terminate); | ||
233 | 89 | |||
234 | 90 | } | ||
235 | 91 | |||
236 | 92 | // Send either gnome_inhibit or freedesktop_inhibit, and get the reply | ||
237 | 93 | int inhibit_one(DBusMessage* inhibit) { | ||
238 | 94 | DBusPendingCall* pending; | ||
239 | 95 | DBusMessageIter args; | ||
240 | 96 | dbus_uint32_t ret; | ||
241 | 97 | |||
242 | 98 | if (!dbus_connection_send_with_reply(connection, inhibit, &pending, -1)) { | ||
243 | 99 | fprintf(stderr, "Out Of Memory!\n"); | ||
244 | 100 | exit(1); | ||
245 | 101 | } | ||
246 | 102 | if (NULL == pending) { | ||
247 | 103 | fprintf(stderr, "Pending Call Null\n"); | ||
248 | 104 | exit(1); | ||
249 | 105 | } | ||
250 | 106 | |||
251 | 107 | dbus_connection_flush(connection); | ||
252 | 108 | |||
253 | 109 | dbus_pending_call_block(pending); | ||
254 | 110 | |||
255 | 111 | // get the reply message | ||
256 | 112 | DBusMessage* msg = dbus_pending_call_steal_reply(pending); | ||
257 | 113 | if (NULL == msg) { | ||
258 | 114 | fprintf(stderr, "Reply Null\n"); | ||
259 | 115 | exit(1); | ||
260 | 116 | } | ||
261 | 117 | // free the pending message handle | ||
262 | 118 | dbus_pending_call_unref(pending); | ||
263 | 119 | |||
264 | 120 | // read the parameters | ||
265 | 121 | if (!dbus_message_iter_init(msg, &args)) | ||
266 | 122 | fprintf(stderr, "Message has no arguments!\n"); | ||
267 | 123 | else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args)) | ||
268 | 124 | ret = 0; // Failed | ||
269 | 125 | else | ||
270 | 126 | dbus_message_iter_get_basic(&args, &ret); | ||
271 | 127 | |||
272 | 128 | // free reply and close connection | ||
273 | 129 | dbus_message_unref(msg); | ||
274 | 130 | |||
275 | 131 | return ret; | ||
276 | 132 | } | ||
277 | 133 | |||
278 | 134 | void screensaver_inhibit() { | ||
279 | 135 | initialise(); | ||
280 | 136 | if (UNINHIBITED != state) return; | ||
281 | 137 | |||
282 | 138 | #ifndef NDEBUG | ||
283 | 139 | printf("Inhibiting screensaver\n"); | ||
284 | 140 | #endif | ||
285 | 141 | |||
286 | 142 | freedesktop_cookie = inhibit_one(freedesktop_inhibit); | ||
287 | 143 | gnome_cookie = inhibit_one(gnome_inhibit); | ||
288 | 144 | |||
289 | 145 | state = INHIBITED; | ||
290 | 146 | } | ||
291 | 147 | |||
292 | 148 | void screensaver_uninhibit() { | ||
293 | 149 | if (INHIBITED != state) return; | ||
294 | 150 | |||
295 | 151 | #ifndef NDEBUG | ||
296 | 152 | printf("Uninhibiting screensaver\n"); | ||
297 | 153 | #endif | ||
298 | 154 | |||
299 | 155 | if (freedesktop_cookie) { | ||
300 | 156 | DBusMessage *uninhibit = DBUS_MESSAGE("freedesktop", "UnInhibit"); | ||
301 | 157 | dbus_message_append_args(uninhibit, | ||
302 | 158 | DBUS_TYPE_UINT32, &freedesktop_cookie, | ||
303 | 159 | DBUS_TYPE_INVALID); | ||
304 | 160 | |||
305 | 161 | if (!dbus_connection_send(connection, uninhibit, NULL)) { | ||
306 | 162 | fprintf(stderr, "Out Of Memory!\n"); | ||
307 | 163 | exit(1); | ||
308 | 164 | }; | ||
309 | 165 | |||
310 | 166 | // free reply and close connection | ||
311 | 167 | dbus_message_unref(uninhibit); | ||
312 | 168 | }; | ||
313 | 169 | |||
314 | 170 | |||
315 | 171 | if ( gnome_cookie) { | ||
316 | 172 | DBusMessage *uninhibit = DBUS_MESSAGE("gnome", "UnInhibit"); | ||
317 | 173 | dbus_message_append_args(uninhibit, | ||
318 | 174 | DBUS_TYPE_UINT32, & gnome_cookie, | ||
319 | 175 | DBUS_TYPE_INVALID); | ||
320 | 176 | |||
321 | 177 | if (!dbus_connection_send(connection, uninhibit, NULL)) { | ||
322 | 178 | fprintf(stderr, "Out Of Memory!\n"); | ||
323 | 179 | exit(1); | ||
324 | 180 | }; | ||
325 | 181 | |||
326 | 182 | // free reply and close connection | ||
327 | 183 | dbus_message_unref(uninhibit); | ||
328 | 184 | }; | ||
329 | 185 | |||
330 | 186 | state = UNINHIBITED; | ||
331 | 187 | |||
332 | 188 | } | ||
333 | 189 | |||
334 | 190 | void screensaver_flip() { | ||
335 | 191 | if (INHIBITED==state) | ||
336 | 192 | screensaver_uninhibit(); | ||
337 | 193 | else | ||
338 | 194 | screensaver_inhibit(); | ||
339 | 195 | } | ||
340 | 0 | 196 | ||
341 | === added file 'src/inhibit-screensaver.h' | |||
342 | --- src/inhibit-screensaver.h 1970-01-01 00:00:00 +0000 | |||
343 | +++ src/inhibit-screensaver.h 2009-06-23 12:32:38 +0000 | |||
344 | @@ -0,0 +1,13 @@ | |||
345 | 1 | // These functions can be safely called at the wrong time (e.g. calling inhibit() several times in a row). The extra calls will do nothing. | ||
346 | 2 | |||
347 | 3 | // Inhibit the screensaver | ||
348 | 4 | void screensaver_inhibit(); | ||
349 | 5 | |||
350 | 6 | // Uninhibit the screensaver | ||
351 | 7 | void screensaver_uninhibit(); | ||
352 | 8 | |||
353 | 9 | // If the screensaver is inhibited, uninhibit the screensaver. Else inhibit the screensaver | ||
354 | 10 | void screensaver_flip(); | ||
355 | 11 | |||
356 | 12 | // Free data when the program terminates (automatically called during normal process termination) | ||
357 | 13 | void screensaver_terminate(); | ||
358 | 0 | 14 | ||
359 | === added file 'src/npw-screensaver.c' | |||
360 | --- src/npw-screensaver.c 1970-01-01 00:00:00 +0000 | |||
361 | +++ src/npw-screensaver.c 2009-06-23 12:32:38 +0000 | |||
362 | @@ -0,0 +1,211 @@ | |||
363 | 1 | /* | ||
364 | 2 | * npw-screensaver.c - control the screensaver based on Flash | ||
365 | 3 | * | ||
366 | 4 | * nspluginwrapper (C) 2005-2009 Gwenole Beauchesne | ||
367 | 5 | * | ||
368 | 6 | * This program is free software; you can redistribute it and/or modify | ||
369 | 7 | * it under the terms of the GNU General Public License as published by | ||
370 | 8 | * the Free Software Foundation; either version 2 of the License, or | ||
371 | 9 | * (at your option) any later version. | ||
372 | 10 | * | ||
373 | 11 | * This program is distributed in the hope that it will be useful, | ||
374 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
375 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
376 | 14 | * GNU General Public License for more details. | ||
377 | 15 | * | ||
378 | 16 | * You should have received a copy of the GNU General Public License along | ||
379 | 17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
380 | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
381 | 19 | */ | ||
382 | 20 | |||
383 | 21 | #include <time.h> | ||
384 | 22 | #include <X11/Xlib.h> | ||
385 | 23 | #include <X11/Xatom.h> | ||
386 | 24 | #include <stdlib.h> | ||
387 | 25 | #include "inhibit-screensaver.h" | ||
388 | 26 | #include <string.h> | ||
389 | 27 | #ifndef NDEBUG | ||
390 | 28 | #include <stdio.h> | ||
391 | 29 | #endif | ||
392 | 30 | #include <unistd.h> | ||
393 | 31 | |||
394 | 32 | // Run for at least VALGRIND seconds, with no waiting. Useful for testing with valgrind | ||
395 | 33 | //#define VALGRIND 10 | ||
396 | 34 | |||
397 | 35 | // Minimum number of seconds between (dis)inhibiting the screensaver | ||
398 | 36 | #define MIN_TIME 30 | ||
399 | 37 | |||
400 | 38 | // WM_NAME | ||
401 | 39 | Atom name; | ||
402 | 40 | // _NET_WM_STATE | ||
403 | 41 | Atom state; | ||
404 | 42 | // _NET_WM_STATE_FULLSCREEN | ||
405 | 43 | Atom fullscreen; | ||
406 | 44 | // _NET_CLIENT_LIST_STACKING | ||
407 | 45 | Atom stacking; | ||
408 | 46 | |||
409 | 47 | // Temporary variables used in many places | ||
410 | 48 | |||
411 | 49 | Atom type; | ||
412 | 50 | int format; | ||
413 | 51 | unsigned long nItems; | ||
414 | 52 | unsigned long bytesAfter; | ||
415 | 53 | unsigned char *property; | ||
416 | 54 | |||
417 | 55 | // Current display | ||
418 | 56 | Display *display; | ||
419 | 57 | // Root window of the current display | ||
420 | 58 | Atom root_window; | ||
421 | 59 | |||
422 | 60 | // Is this window a fullscreen npviewer window? | ||
423 | 61 | int is_fullscreen_flash(Window* w) | ||
424 | 62 | { | ||
425 | 63 | if (property) | ||
426 | 64 | XFree(property); | ||
427 | 65 | property = 0; | ||
428 | 66 | |||
429 | 67 | // Is this window called npviewer.bin? | ||
430 | 68 | if (Success != XGetWindowProperty(display, *w, name, 0, 3, False, XA_STRING, | ||
431 | 69 | &type, &format, &nItems, &bytesAfter, &property) | ||
432 | 70 | || !property | ||
433 | 71 | || strcmp((char*)property, "npviewer.bin")) { | ||
434 | 72 | if (property) | ||
435 | 73 | XFree(property); | ||
436 | 74 | property = 0; | ||
437 | 75 | return 0; | ||
438 | 76 | }; | ||
439 | 77 | if (property) | ||
440 | 78 | XFree(property); | ||
441 | 79 | property = 0; | ||
442 | 80 | |||
443 | 81 | // Get the number of state atoms for this window | ||
444 | 82 | if (Success != XGetWindowProperty(display, *w, state, 0, 0, False, XA_ATOM, | ||
445 | 83 | &type, &format, &nItems, &bytesAfter, &property) | ||
446 | 84 | || !property | ||
447 | 85 | || !bytesAfter) { | ||
448 | 86 | if (property) | ||
449 | 87 | XFree(property); | ||
450 | 88 | property = 0; | ||
451 | 89 | return 0; | ||
452 | 90 | }; | ||
453 | 91 | if (property) | ||
454 | 92 | XFree(property); | ||
455 | 93 | property = 0; | ||
456 | 94 | |||
457 | 95 | // Get the state atoms for this window | ||
458 | 96 | property = 0; | ||
459 | 97 | if (Success != XGetWindowProperty(display, *w, state, 0, (bytesAfter / 4), False, XA_ATOM, | ||
460 | 98 | &type, &format, &nItems, &bytesAfter, &property) | ||
461 | 99 | || !property) { | ||
462 | 100 | if (property) | ||
463 | 101 | XFree(property); | ||
464 | 102 | property = 0; | ||
465 | 103 | return 0; | ||
466 | 104 | }; | ||
467 | 105 | |||
468 | 106 | // Check whether any of the state atoms are _NET_WM_STATE_FULLSCREEN | ||
469 | 107 | if (property) { | ||
470 | 108 | Atom* states = (Atom*)property; | ||
471 | 109 | while (nItems--) { | ||
472 | 110 | if (*states++ == fullscreen) { | ||
473 | 111 | XFree(property); | ||
474 | 112 | property = 0; | ||
475 | 113 | return 1; | ||
476 | 114 | }; | ||
477 | 115 | }; | ||
478 | 116 | |||
479 | 117 | XFree(property); | ||
480 | 118 | property = 0; | ||
481 | 119 | }; | ||
482 | 120 | |||
483 | 121 | // Fail | ||
484 | 122 | return 0; | ||
485 | 123 | } | ||
486 | 124 | |||
487 | 125 | // Inhibit or uninhibit the screensaver, depending on the current state of npviewer | ||
488 | 126 | void inhibit(Atom* old_window) | ||
489 | 127 | { | ||
490 | 128 | if(Success == XGetWindowProperty(display, root_window, stacking, 0, 0, False, XA_WINDOW, | ||
491 | 129 | &type, &format, &nItems, &bytesAfter, &property)) { | ||
492 | 130 | |||
493 | 131 | if (property) | ||
494 | 132 | XFree(property); | ||
495 | 133 | property = 0; | ||
496 | 134 | |||
497 | 135 | if(Success == XGetWindowProperty(display, root_window, stacking, (bytesAfter / 4) - 1, sizeof(Atom), False, XA_WINDOW, | ||
498 | 136 | &type, &format, &nItems, &bytesAfter, &property) | ||
499 | 137 | && property && *old_window != *((Atom*)property)) { | ||
500 | 138 | *old_window = *((Atom*)property); | ||
501 | 139 | |||
502 | 140 | if (is_fullscreen_flash(old_window)) { | ||
503 | 141 | screensaver_inhibit(); | ||
504 | 142 | } else { | ||
505 | 143 | screensaver_uninhibit(); | ||
506 | 144 | }; | ||
507 | 145 | } | ||
508 | 146 | |||
509 | 147 | if (property) { | ||
510 | 148 | XFree(property); | ||
511 | 149 | }; | ||
512 | 150 | property = 0; | ||
513 | 151 | } | ||
514 | 152 | } | ||
515 | 153 | |||
516 | 154 | // Get the value for an atom | ||
517 | 155 | void get_atom(char const*const name, Atom* a) | ||
518 | 156 | { | ||
519 | 157 | *a = XInternAtom(display, name, True); | ||
520 | 158 | if(*a == None) { | ||
521 | 159 | #ifndef NDEBUG | ||
522 | 160 | printf("No such atom: %s\n", name); | ||
523 | 161 | #endif | ||
524 | 162 | exit(1); | ||
525 | 163 | } | ||
526 | 164 | } | ||
527 | 165 | |||
528 | 166 | int main() | ||
529 | 167 | { | ||
530 | 168 | // Start with the root window. | ||
531 | 169 | display = XOpenDisplay(0); | ||
532 | 170 | |||
533 | 171 | get_atom("WM_NAME", &name); | ||
534 | 172 | get_atom("_NET_WM_STATE", &state); | ||
535 | 173 | get_atom("_NET_WM_STATE_FULLSCREEN", &fullscreen); | ||
536 | 174 | get_atom("_NET_CLIENT_LIST_STACKING", &stacking); | ||
537 | 175 | |||
538 | 176 | root_window = XDefaultRootWindow(display); | ||
539 | 177 | |||
540 | 178 | Atom old_window = root_window; | ||
541 | 179 | |||
542 | 180 | XSelectInput(display, root_window, PropertyChangeMask); | ||
543 | 181 | |||
544 | 182 | XEvent event; | ||
545 | 183 | |||
546 | 184 | time_t prev_time = 0; | ||
547 | 185 | |||
548 | 186 | #ifdef VALGRIND | ||
549 | 187 | time_t start_time = time(0); | ||
550 | 188 | while (time(0) - start_time < VALGRIND) { | ||
551 | 189 | #else | ||
552 | 190 | for (;;) { | ||
553 | 191 | #endif | ||
554 | 192 | XNextEvent(display, &event); | ||
555 | 193 | if (event.xproperty.atom != stacking) continue; // Window stacking has changed | ||
556 | 194 | |||
557 | 195 | #ifndef VALGRIND | ||
558 | 196 | time_t time_elapsed = time(0) - prev_time; | ||
559 | 197 | if (time_elapsed < MIN_TIME) // Update at most once every 30 seconds | ||
560 | 198 | sleep(MIN_TIME - time_elapsed); | ||
561 | 199 | #endif | ||
562 | 200 | |||
563 | 201 | inhibit(&old_window); | ||
564 | 202 | prev_time = time(0); | ||
565 | 203 | }; | ||
566 | 204 | |||
567 | 205 | #ifndef NDEBUG | ||
568 | 206 | printf("Freeing global variables\n"); | ||
569 | 207 | #endif | ||
570 | 208 | XCloseDisplay(display); | ||
571 | 209 | if (property) | ||
572 | 210 | XFree(property); | ||
573 | 211 | } | ||
574 | 0 | 212 | ||
575 | === modified file 'src/npw-viewer.sh' | |||
576 | --- src/npw-viewer.sh 2008-12-27 02:10:20 +0000 | |||
577 | +++ src/npw-viewer.sh 2009-06-13 09:20:20 +0000 | |||
578 | @@ -3,6 +3,7 @@ | |||
579 | 3 | # nsplugin viewer wrapper script (C) 2005-2006 Gwenole Beauchesne | 3 | # nsplugin viewer wrapper script (C) 2005-2006 Gwenole Beauchesne |
580 | 4 | # | 4 | # |
581 | 5 | OS="`uname -s`" | 5 | OS="`uname -s`" |
582 | 6 | OS_LOWER="`uname -s | tr '[A-Z]' '[a-z]'`" | ||
583 | 6 | ARCH="`uname -m`" | 7 | ARCH="`uname -m`" |
584 | 7 | NPW_LIBDIR="%NPW_LIBDIR%" | 8 | NPW_LIBDIR="%NPW_LIBDIR%" |
585 | 8 | 9 | ||
586 | @@ -143,4 +144,9 @@ | |||
587 | 143 | fi | 144 | fi |
588 | 144 | fi | 145 | fi |
589 | 145 | 146 | ||
591 | 146 | exec $LOADER $NPW_VIEWER_DIR/npviewer.bin ${1+"$@"} | 147 | $NPW_LIBDIR/$ARCH/$OS_LOWER/npsaver.bin & |
592 | 148 | NPSAVER=$! | ||
593 | 149 | |||
594 | 150 | $LOADER $NPW_VIEWER_DIR/npviewer.bin ${1+"$@"} | ||
595 | 151 | |||
596 | 152 | kill $NPSAVER |
Adobe Flash doesn't currently inhibit the screensaver when playing a video: http:// bugs.adobe. com/jira/ browse/ FP-997? page=com. atlassian. jira.plugin. system. issuetabpanels: all-tabpanel). There's no sign of activity in that bug report, and users are currently working around the bug on their own: http:// ubuntuforums. org/showthread. php?t=1090393
This branch includes an "npsaver.bin" application that monitors X Window events, and inhibits the screensaver when npviewer.bin is fullscreen and on the top of the stack. This gives a very close match to Flash's behaviour in Windows.
This application is being proposed for inclusion in nspluginwrapper for mainly practical reasons: the process should run whenever a Flash window is open, and has to be written in C to avoid depending on packages not currently installed by default.
This branch directly modifies the "configure" script - I think this is normally frowned upon, but I can't find the m4 script that automatically generates "configure".