Merge lp:~andrew-bugs-launchpad-net/nspluginwrapper/flashsaver into lp:nspluginwrapper

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

This proposal supersedes a proposal from 2009-06-13.

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

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".

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
=== modified file 'Makefile'
--- Makefile 2009-01-02 10:07:27 +0000
+++ Makefile 2009-06-13 09:20:20 +0000
@@ -143,6 +143,15 @@
143npviewer_LDFLAGS += $(libsocket_LDFLAGS)143npviewer_LDFLAGS += $(libsocket_LDFLAGS)
144endif144endif
145145
146npsaver_PROGRAM = npsaver.bin
147npsaver_RAWSRCS = npw-screensaver.c inhibit-screensaver.c
148npsaver_SOURCES = $(npsaver_RAWSRCS:%.c=$(SRC_PATH)/src/%.c)
149npsaver_OBJECTS = $(npsaver_RAWSRCS:%.c=npsaver-%.o)
150npsaver_CFLAGS = $(DBUS_CFLAGS) -DNDEBUG
151npsaver_LDFLAGS = $(DBUS_LDFLAGS)
152npsaver_LDFLAGS += $(X_LDFLAGS)
153npsaver_LDFLAGS += $(libdl_LDFLAGS) $(libpthread_LDFLAGS) -lgthread-2.0
154
146npplayer_PROGRAM = npplayer155npplayer_PROGRAM = npplayer
147npplayer_SOURCES = npw-player.c debug.c rpc.c utils.c glibcurl.c gtk2xtbin.c $(tidy_SOURCES)156npplayer_SOURCES = npw-player.c debug.c rpc.c utils.c glibcurl.c gtk2xtbin.c $(tidy_SOURCES)
148npplayer_OBJECTS = $(npplayer_SOURCES:%.c=npplayer-%.o)157npplayer_OBJECTS = $(npplayer_SOURCES:%.c=npplayer-%.o)
@@ -208,6 +217,7 @@
208TARGETS += $(npwrapper_LIBRARY)217TARGETS += $(npwrapper_LIBRARY)
209ifeq ($(build_viewer),yes)218ifeq ($(build_viewer),yes)
210TARGETS += $(npviewer_PROGRAM)219TARGETS += $(npviewer_PROGRAM)
220TARGETS += $(npsaver_PROGRAM)
211TARGETS += $(libxpcom_LIBRARY)221TARGETS += $(libxpcom_LIBRARY)
212TARGETS += $(libnoxshm_LIBRARY)222TARGETS += $(libnoxshm_LIBRARY)
213endif223endif
@@ -253,7 +263,7 @@
253distclean: clean263distclean: clean
254 rm -f config-host.* config.*264 rm -f config-host.* config.*
255265
256uninstall: uninstall.player uninstall.wrapper uninstall.viewer uninstall.libxpcom uninstall.libnoxshm uninstall.loader uninstall.config uninstall.dirs266uninstall: uninstall.player uninstall.wrapper uninstall.viewer uninstall.saver uninstall.libxpcom uninstall.libnoxshm uninstall.loader uninstall.config uninstall.dirs
257uninstall.dirs:267uninstall.dirs:
258 rmdir $(DESTDIR)$(pkglibdir)/noarch268 rmdir $(DESTDIR)$(pkglibdir)/noarch
259 rmdir $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)269 rmdir $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)
@@ -269,6 +279,9 @@
269uninstall.viewer:279uninstall.viewer:
270 rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM)280 rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM)
271 rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM:%.bin=%)281 rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM:%.bin=%)
282uninstall.saver:
283 rm -f $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)/$(npsaver_PROGRAM)
284 rm -f $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)/$(npsaver_PROGRAM:%.bin=%)
272uninstall.libxpcom:285uninstall.libxpcom:
273 rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(libxpcom_LIBRARY)286 rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(libxpcom_LIBRARY)
274uninstall.libnoxshm:287uninstall.libnoxshm:
@@ -281,7 +294,7 @@
281uninstall.mkruntime:294uninstall.mkruntime:
282 rm -f $(DESTDIR)$(pkglibdir)/noarch/mkruntime295 rm -f $(DESTDIR)$(pkglibdir)/noarch/mkruntime
283296
284install: install.dirs install.player install.wrapper install.viewer install.libxpcom install.libnoxshm install.loader install.config297install: install.dirs install.player install.wrapper install.viewer install.saver install.libxpcom install.libnoxshm install.loader install.config
285install.dirs:298install.dirs:
286 mkdir -p $(DESTDIR)$(pkglibdir)/noarch299 mkdir -p $(DESTDIR)$(pkglibdir)/noarch
287 mkdir -p $(DESTDIR)$(pkglibdir)/$(ARCH)300 mkdir -p $(DESTDIR)$(pkglibdir)/$(ARCH)
@@ -302,6 +315,8 @@
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)
303ifeq ($(build_viewer),yes)316ifeq ($(build_viewer),yes)
304install.viewer: install.viewer.bin install.viewer.glue317install.viewer: install.viewer.bin install.viewer.glue
318install.saver: $(npsaver_PROGRAM)
319 $(INSTALL) -m 755 $(STRIP_OPT) $(npsaver_PROGRAM) $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)/$(npsaver_PROGRAM)
305install.libxpcom: do.install.libxpcom320install.libxpcom: do.install.libxpcom
306install.libnoxshm: do.install.libnoxshm321install.libnoxshm: do.install.libnoxshm
307else322else
@@ -386,6 +401,15 @@
386npviewer-%.o: $(SRC_PATH)/src/%.cpp401npviewer-%.o: $(SRC_PATH)/src/%.cpp
387 $(CXX) $(CFLAGS_32) -o $@ -c $< $(CPPFLAGS) $(npviewer_CFLAGS) -DBUILD_VIEWER402 $(CXX) $(CFLAGS_32) -o $@ -c $< $(CPPFLAGS) $(npviewer_CFLAGS) -DBUILD_VIEWER
388403
404$(npsaver_PROGRAM): $(npsaver_OBJECTS) $(LSB_OBJ_DIR) $(LSB_LIBS)
405 $(CC) $(LDFLAGS) -o $@ $(npsaver_OBJECTS) $(npsaver_LDFLAGS)
406
407npsaver-%.o: $(SRC_PATH)/src/%.c
408 $(CC) $(CFLAGS) -o $@ -c $< $(CPPFLAGS) $(npsaver_CFLAGS) -DBUILD_VIEWER
409
410npsaver-%.o: $(SRC_PATH)/src/%.cpp
411 $(CXX) $(CFLAGS) -o $@ -c $< $(CPPFLAGS) $(npsaver_CFLAGS) -DBUILD_VIEWER
412
389$(npplayer_PROGRAM): $(npplayer_OBJECTS) $(npplayer_MAPFILE) $(LSB_OBJ_DIR) $(LSB_LIBS)413$(npplayer_PROGRAM): $(npplayer_OBJECTS) $(npplayer_MAPFILE) $(LSB_OBJ_DIR) $(LSB_LIBS)
390 $(CC) $(LDFLAGS) -o $@ $(npplayer_OBJECTS) $(npplayer_LDFLAGS)414 $(CC) $(LDFLAGS) -o $@ $(npplayer_OBJECTS) $(npplayer_LDFLAGS)
391415
392416
=== modified file 'configure'
--- configure 2009-01-02 10:07:27 +0000
+++ configure 2009-06-13 09:20:20 +0000
@@ -436,6 +436,32 @@
436 rm -f $TMPC $TMPE436 rm -f $TMPC $TMPE
437fi437fi
438438
439# check for DBUS-1 compile CFLAGS
440if test "$build_viewer" = "yes" -o "$build_player" = "yes"; then
441 if $pkgconfig --exists dbus-1; then
442 DBUS_CFLAGS=`$pkgconfig --cflags dbus-1`
443 DBUS_LDFLAGS=`$pkgconfig --libs dbus-1`
444 DBUS_VERSION=`$pkgconfig --modversion dbus-1`
445 else
446 echo "DBUS not found"
447 exit 1
448 fi
449 cat > $TMPC << EOF
450#include <dbus/dbus.h>
451int main(void) {
452 DBusError err;
453 dbus_error_init(&err);
454 return 0;
455}
456EOF
457 if ! $cc $CFLAGS $DBUS_CFLAGS $DBUS_LDFLAGS $TMPC -o $TMPE > /dev/null 2>&1; then
458 echo "DBUS not usable"
459 rm -f $TMPC
460 exit 1
461 fi
462 rm -f $TMPC $TMPE
463fi
464
439# check for cURL compile CFLAGS465# check for cURL compile CFLAGS
440if test "$build_player" = "yes"; then466if test "$build_player" = "yes"; then
441 if $pkgconfig --exists libcurl; then467 if $pkgconfig --exists libcurl; then
@@ -689,6 +715,8 @@
689echo "GLIB_LDFLAGS=$GLIB_LDFLAGS" >> $config_mak715echo "GLIB_LDFLAGS=$GLIB_LDFLAGS" >> $config_mak
690echo "GTK_CFLAGS=$GTK_CFLAGS" >> $config_mak716echo "GTK_CFLAGS=$GTK_CFLAGS" >> $config_mak
691echo "GTK_LDFLAGS=$GTK_LDFLAGS" >> $config_mak717echo "GTK_LDFLAGS=$GTK_LDFLAGS" >> $config_mak
718echo "DBUS_CFLAGS=$DBUS_CFLAGS" >> $config_mak
719echo "DBUS_LDFLAGS=$DBUS_LDFLAGS" >> $config_mak
692echo "CURL_CFLAGS=$CURL_CFLAGS" >> $config_mak720echo "CURL_CFLAGS=$CURL_CFLAGS" >> $config_mak
693echo "CURL_LDFLAGS=$CURL_LDFLAGS" >> $config_mak721echo "CURL_LDFLAGS=$CURL_LDFLAGS" >> $config_mak
694if test "$biarch" = "yes"; then722if test "$biarch" = "yes"; then
695723
=== modified file 'debian/control'
--- debian/control 2008-08-27 17:19:36 +0000
+++ debian/control 2009-06-13 16:56:18 +0000
@@ -3,7 +3,7 @@
3Priority: optional3Priority: optional
4Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>4Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
5XSBC-Original-Maintainer: Rob Andrews <rob@choralone.org>5XSBC-Original-Maintainer: Rob Andrews <rob@choralone.org>
6Build-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-dev6Build-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
7Standards-Version: 3.8.07Standards-Version: 3.8.0
8Xs-Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-dev/nspluginwrapper/ubuntu8Xs-Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-dev/nspluginwrapper/ubuntu
99
1010
=== added file 'src/inhibit-screensaver.c'
--- src/inhibit-screensaver.c 1970-01-01 00:00:00 +0000
+++ src/inhibit-screensaver.c 2009-06-23 12:32:38 +0000
@@ -0,0 +1,195 @@
1/*
2 * inhibit-screensaver.c - screensaver (dis)inhibition functions
3 *
4 * nspluginwrapper (C) 2005-2009 Gwenole Beauchesne
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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <dbus/dbus.h>
22#include <stdio.h>
23#include <stdlib.h>
24
25#define DBUS_MESSAGE(O, M) dbus_message_new_method_call("org."O".ScreenSaver", "/org/"O"/ScreenSaver", "org."O".ScreenSaver", M)
26
27// GNOME and KDE use the compatible interfaces with different names
28static DBusMessage *freedesktop_inhibit;
29static DBusMessage *gnome_inhibit;
30
31static DBusConnection *connection;
32
33static char const*const name = "npviewer.bin";
34static char const*const reason = "Fullscreen Flash application running";
35
36static enum { UNINITIALISED, UNINHIBITED, INHIBITED } state = UNINITIALISED;
37
38static unsigned int freedesktop_cookie;
39static unsigned int gnome_cookie;
40
41void screensaver_terminate() {
42#ifndef NDEBUG
43 printf("Freeing screensaver data\n");
44#endif
45 if (freedesktop_inhibit)
46 dbus_message_unref(freedesktop_inhibit);
47 freedesktop_inhibit = 0;
48 if (gnome_inhibit)
49 dbus_message_unref(gnome_inhibit);
50 gnome_inhibit = 0;
51 if (connection)
52 dbus_connection_unref(connection);
53 connection = 0;
54};
55
56void initialise() {
57
58 if (UNINITIALISED != state) return;
59
60 DBusError err;
61
62 dbus_error_init(&err);
63
64 connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
65 if (dbus_error_is_set(&err)) {
66 fprintf(stderr, "Connection Error (%s)\n", err.message);
67 dbus_error_free(&err);
68 }
69 if (NULL == connection) {
70 exit(1);
71 }
72
73 freedesktop_inhibit = DBUS_MESSAGE("freedesktop", "Inhibit");
74 gnome_inhibit = DBUS_MESSAGE("gnome" , "Inhibit");
75
76 dbus_message_append_args(freedesktop_inhibit,
77 DBUS_TYPE_STRING, &name,
78 DBUS_TYPE_STRING, &reason,
79 DBUS_TYPE_INVALID);
80
81 dbus_message_append_args(gnome_inhibit,
82 DBUS_TYPE_STRING, &name,
83 DBUS_TYPE_STRING, &reason,
84 DBUS_TYPE_INVALID);
85
86 state = UNINHIBITED;
87
88 atexit(screensaver_terminate);
89
90}
91
92// Send either gnome_inhibit or freedesktop_inhibit, and get the reply
93int inhibit_one(DBusMessage* inhibit) {
94 DBusPendingCall* pending;
95 DBusMessageIter args;
96 dbus_uint32_t ret;
97
98 if (!dbus_connection_send_with_reply(connection, inhibit, &pending, -1)) {
99 fprintf(stderr, "Out Of Memory!\n");
100 exit(1);
101 }
102 if (NULL == pending) {
103 fprintf(stderr, "Pending Call Null\n");
104 exit(1);
105 }
106
107 dbus_connection_flush(connection);
108
109 dbus_pending_call_block(pending);
110
111 // get the reply message
112 DBusMessage* msg = dbus_pending_call_steal_reply(pending);
113 if (NULL == msg) {
114 fprintf(stderr, "Reply Null\n");
115 exit(1);
116 }
117 // free the pending message handle
118 dbus_pending_call_unref(pending);
119
120 // read the parameters
121 if (!dbus_message_iter_init(msg, &args))
122 fprintf(stderr, "Message has no arguments!\n");
123 else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args))
124 ret = 0; // Failed
125 else
126 dbus_message_iter_get_basic(&args, &ret);
127
128 // free reply and close connection
129 dbus_message_unref(msg);
130
131 return ret;
132}
133
134void screensaver_inhibit() {
135 initialise();
136 if (UNINHIBITED != state) return;
137
138#ifndef NDEBUG
139 printf("Inhibiting screensaver\n");
140#endif
141
142 freedesktop_cookie = inhibit_one(freedesktop_inhibit);
143 gnome_cookie = inhibit_one(gnome_inhibit);
144
145 state = INHIBITED;
146}
147
148void screensaver_uninhibit() {
149 if (INHIBITED != state) return;
150
151#ifndef NDEBUG
152 printf("Uninhibiting screensaver\n");
153#endif
154
155 if (freedesktop_cookie) {
156 DBusMessage *uninhibit = DBUS_MESSAGE("freedesktop", "UnInhibit");
157 dbus_message_append_args(uninhibit,
158 DBUS_TYPE_UINT32, &freedesktop_cookie,
159 DBUS_TYPE_INVALID);
160
161 if (!dbus_connection_send(connection, uninhibit, NULL)) {
162 fprintf(stderr, "Out Of Memory!\n");
163 exit(1);
164 };
165
166 // free reply and close connection
167 dbus_message_unref(uninhibit);
168 };
169
170
171 if ( gnome_cookie) {
172 DBusMessage *uninhibit = DBUS_MESSAGE("gnome", "UnInhibit");
173 dbus_message_append_args(uninhibit,
174 DBUS_TYPE_UINT32, & gnome_cookie,
175 DBUS_TYPE_INVALID);
176
177 if (!dbus_connection_send(connection, uninhibit, NULL)) {
178 fprintf(stderr, "Out Of Memory!\n");
179 exit(1);
180 };
181
182 // free reply and close connection
183 dbus_message_unref(uninhibit);
184 };
185
186 state = UNINHIBITED;
187
188}
189
190void screensaver_flip() {
191 if (INHIBITED==state)
192 screensaver_uninhibit();
193 else
194 screensaver_inhibit();
195}
0196
=== added file 'src/inhibit-screensaver.h'
--- src/inhibit-screensaver.h 1970-01-01 00:00:00 +0000
+++ src/inhibit-screensaver.h 2009-06-23 12:32:38 +0000
@@ -0,0 +1,13 @@
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.
2
3// Inhibit the screensaver
4void screensaver_inhibit();
5
6// Uninhibit the screensaver
7void screensaver_uninhibit();
8
9// If the screensaver is inhibited, uninhibit the screensaver. Else inhibit the screensaver
10void screensaver_flip();
11
12// Free data when the program terminates (automatically called during normal process termination)
13void screensaver_terminate();
014
=== added file 'src/npw-screensaver.c'
--- src/npw-screensaver.c 1970-01-01 00:00:00 +0000
+++ src/npw-screensaver.c 2009-06-23 12:32:38 +0000
@@ -0,0 +1,211 @@
1/*
2 * npw-screensaver.c - control the screensaver based on Flash
3 *
4 * nspluginwrapper (C) 2005-2009 Gwenole Beauchesne
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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <time.h>
22#include <X11/Xlib.h>
23#include <X11/Xatom.h>
24#include <stdlib.h>
25#include "inhibit-screensaver.h"
26#include <string.h>
27#ifndef NDEBUG
28#include <stdio.h>
29#endif
30#include <unistd.h>
31
32// Run for at least VALGRIND seconds, with no waiting. Useful for testing with valgrind
33//#define VALGRIND 10
34
35// Minimum number of seconds between (dis)inhibiting the screensaver
36#define MIN_TIME 30
37
38// WM_NAME
39Atom name;
40// _NET_WM_STATE
41Atom state;
42// _NET_WM_STATE_FULLSCREEN
43Atom fullscreen;
44// _NET_CLIENT_LIST_STACKING
45Atom stacking;
46
47// Temporary variables used in many places
48
49Atom type;
50int format;
51unsigned long nItems;
52unsigned long bytesAfter;
53unsigned char *property;
54
55// Current display
56Display *display;
57// Root window of the current display
58Atom root_window;
59
60// Is this window a fullscreen npviewer window?
61int is_fullscreen_flash(Window* w)
62{
63 if (property)
64 XFree(property);
65 property = 0;
66
67 // Is this window called npviewer.bin?
68 if (Success != XGetWindowProperty(display, *w, name, 0, 3, False, XA_STRING,
69 &type, &format, &nItems, &bytesAfter, &property)
70 || !property
71 || strcmp((char*)property, "npviewer.bin")) {
72 if (property)
73 XFree(property);
74 property = 0;
75 return 0;
76 };
77 if (property)
78 XFree(property);
79 property = 0;
80
81 // Get the number of state atoms for this window
82 if (Success != XGetWindowProperty(display, *w, state, 0, 0, False, XA_ATOM,
83 &type, &format, &nItems, &bytesAfter, &property)
84 || !property
85 || !bytesAfter) {
86 if (property)
87 XFree(property);
88 property = 0;
89 return 0;
90 };
91 if (property)
92 XFree(property);
93 property = 0;
94
95 // Get the state atoms for this window
96 property = 0;
97 if (Success != XGetWindowProperty(display, *w, state, 0, (bytesAfter / 4), False, XA_ATOM,
98 &type, &format, &nItems, &bytesAfter, &property)
99 || !property) {
100 if (property)
101 XFree(property);
102 property = 0;
103 return 0;
104 };
105
106 // Check whether any of the state atoms are _NET_WM_STATE_FULLSCREEN
107 if (property) {
108 Atom* states = (Atom*)property;
109 while (nItems--) {
110 if (*states++ == fullscreen) {
111 XFree(property);
112 property = 0;
113 return 1;
114 };
115 };
116
117 XFree(property);
118 property = 0;
119 };
120
121 // Fail
122 return 0;
123}
124
125// Inhibit or uninhibit the screensaver, depending on the current state of npviewer
126void inhibit(Atom* old_window)
127{
128 if(Success == XGetWindowProperty(display, root_window, stacking, 0, 0, False, XA_WINDOW,
129 &type, &format, &nItems, &bytesAfter, &property)) {
130
131 if (property)
132 XFree(property);
133 property = 0;
134
135 if(Success == XGetWindowProperty(display, root_window, stacking, (bytesAfter / 4) - 1, sizeof(Atom), False, XA_WINDOW,
136 &type, &format, &nItems, &bytesAfter, &property)
137 && property && *old_window != *((Atom*)property)) {
138 *old_window = *((Atom*)property);
139
140 if (is_fullscreen_flash(old_window)) {
141 screensaver_inhibit();
142 } else {
143 screensaver_uninhibit();
144 };
145 }
146
147 if (property) {
148 XFree(property);
149 };
150 property = 0;
151 }
152}
153
154// Get the value for an atom
155void get_atom(char const*const name, Atom* a)
156{
157 *a = XInternAtom(display, name, True);
158 if(*a == None) {
159#ifndef NDEBUG
160 printf("No such atom: %s\n", name);
161#endif
162 exit(1);
163 }
164}
165
166int main()
167{
168 // Start with the root window.
169 display = XOpenDisplay(0);
170
171 get_atom("WM_NAME", &name);
172 get_atom("_NET_WM_STATE", &state);
173 get_atom("_NET_WM_STATE_FULLSCREEN", &fullscreen);
174 get_atom("_NET_CLIENT_LIST_STACKING", &stacking);
175
176 root_window = XDefaultRootWindow(display);
177
178 Atom old_window = root_window;
179
180 XSelectInput(display, root_window, PropertyChangeMask);
181
182 XEvent event;
183
184 time_t prev_time = 0;
185
186#ifdef VALGRIND
187 time_t start_time = time(0);
188 while (time(0) - start_time < VALGRIND) {
189#else
190 for (;;) {
191#endif
192 XNextEvent(display, &event);
193 if (event.xproperty.atom != stacking) continue; // Window stacking has changed
194
195#ifndef VALGRIND
196 time_t time_elapsed = time(0) - prev_time;
197 if (time_elapsed < MIN_TIME) // Update at most once every 30 seconds
198 sleep(MIN_TIME - time_elapsed);
199#endif
200
201 inhibit(&old_window);
202 prev_time = time(0);
203 };
204
205#ifndef NDEBUG
206 printf("Freeing global variables\n");
207#endif
208 XCloseDisplay(display);
209 if (property)
210 XFree(property);
211}
0212
=== modified file 'src/npw-viewer.sh'
--- src/npw-viewer.sh 2008-12-27 02:10:20 +0000
+++ src/npw-viewer.sh 2009-06-13 09:20:20 +0000
@@ -3,6 +3,7 @@
3# nsplugin viewer wrapper script (C) 2005-2006 Gwenole Beauchesne3# nsplugin viewer wrapper script (C) 2005-2006 Gwenole Beauchesne
4#4#
5OS="`uname -s`"5OS="`uname -s`"
6OS_LOWER="`uname -s | tr '[A-Z]' '[a-z]'`"
6ARCH="`uname -m`"7ARCH="`uname -m`"
7NPW_LIBDIR="%NPW_LIBDIR%"8NPW_LIBDIR="%NPW_LIBDIR%"
89
@@ -143,4 +144,9 @@
143 fi144 fi
144fi145fi
145146
146exec $LOADER $NPW_VIEWER_DIR/npviewer.bin ${1+"$@"}147$NPW_LIBDIR/$ARCH/$OS_LOWER/npsaver.bin &
148NPSAVER=$!
149
150$LOADER $NPW_VIEWER_DIR/npviewer.bin ${1+"$@"}
151
152kill $NPSAVER

Subscribers

People subscribed via source and target branches

to all changes: