From 37e221677589811565096683e302f3d65cfe2ad5 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 31 Mar 2010 23:13:58 +0200 Subject: [PATCH] Implement -i, --inactivity-reset command line option The use case is kiosk systems where leaving the application idle for a period of time means that the user left, and the session is reset so the next user starts off clean. The implementation uses libXss and uses XScreenSaverQueryExtension which means it is for now supported on X11 only. Right now reset means closing any opens web pages and opening the original web page. Currently --inactivity-reset is only supported with --app. --- midori/main.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ midori/wscript_build | 2 +- wscript | 1 + 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/midori/main.c b/midori/main.c index d02bb7cb..d0e7e64e 100644 --- a/midori/main.c +++ b/midori/main.c @@ -54,6 +54,13 @@ #define BOOKMARK_FILE "bookmarks.xbel" #endif +#ifdef GDK_WINDOWING_X11 + #include + #include + #include + #include +#endif + static gchar* build_config_filename (const gchar* filename) { @@ -1422,6 +1429,71 @@ signal_handler (int signal_id) } #endif +typedef struct { + MidoriBrowser* browser; + guint timeout; + gchar* uri; +} MidoriInactivityTimeout; + +static gboolean +midori_inactivity_timeout (gpointer data) +{ + #ifdef GDK_WINDOWING_X11 + MidoriInactivityTimeout* mit = data; + static Display* xdisplay = NULL; + static XScreenSaverInfo* mit_info = NULL; + static int has_extension = -1; + int event_base, error_base; + + if (has_extension == -1) + { + GdkDisplay* display = gtk_widget_get_display (GTK_WIDGET (mit->browser)); + xdisplay = GDK_DISPLAY_XDISPLAY (display); + has_extension = XScreenSaverQueryExtension (xdisplay, + &event_base, &error_base); + } + + if (has_extension) + { + if (!mit_info) + mit_info = XScreenSaverAllocInfo (); + + XScreenSaverQueryInfo (xdisplay, RootWindow (xdisplay, 0), mit_info); + if (mit_info->idle / 1000 > mit->timeout) + { + guint i = 0; + GtkWidget* view; + + while ((view = midori_browser_get_nth_tab (mit->browser, i++))) + gtk_widget_destroy (view); + midori_browser_set_current_uri (mit->browser, mit->uri); + /* TODO: Re-run initial commands */ + + } + } + #else + /* TODO: Implement for other windowing systems */ + #endif + + return TRUE; +} + +static void +midori_setup_inactivity_reset (MidoriBrowser* browser, + gint inactivity_reset, + const gchar* uri) +{ + if (inactivity_reset > 0) + { + MidoriInactivityTimeout* mit = g_new (MidoriInactivityTimeout, 1); + mit->browser = browser; + mit->timeout = inactivity_reset; + mit->uri = g_strdup (uri); + g_timeout_add_seconds (inactivity_reset, midori_inactivity_timeout, + mit); + } +} + int main (int argc, char** argv) @@ -1434,6 +1506,7 @@ main (int argc, gboolean execute; gboolean version; gchar** uris; + gint inactivity_reset; MidoriApp* app; gboolean result; GError* error; @@ -1459,6 +1532,10 @@ main (int argc, N_("Display program version"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris, N_("Addresses"), NULL }, + #ifdef GDK_WINDOWING_X11 + { "inactivity-reset", 'i', 0, G_OPTION_ARG_INT, &inactivity_reset, + N_("Reset Midori after SECONDS seconds of inactivity"), N_("SECONDS") }, + #endif { NULL } }; GString* error_messages; @@ -1534,6 +1611,7 @@ main (int argc, execute = FALSE; version = FALSE; uris = NULL; + inactivity_reset = 0; error = NULL; if (!gtk_init_with_args (&argc, &argv, _("[Addresses]"), entries, GETTEXT_PACKAGE, &error)) @@ -1642,11 +1720,16 @@ main (int argc, i++; } } + midori_setup_inactivity_reset (browser, inactivity_reset, webapp); midori_startup_timer ("App created: \t%f"); gtk_main (); return 0; } + /* FIXME: Inactivity reset is only supported for app mode */ + if (inactivity_reset > 0) + g_error ("--inactivity-reset is currently only supported with --app."); + /* Standalone javascript support */ if (run) return midori_run_script (uris ? *uris : NULL); diff --git a/midori/wscript_build b/midori/wscript_build index ca664c65..bb76c6f0 100644 --- a/midori/wscript_build +++ b/midori/wscript_build @@ -6,7 +6,7 @@ import platform progressive = True libs = 'M UNIQUE LIBSOUP GMODULE GTHREAD LIBIDN GIO GTK SQLITE ' \ - 'LIBNOTIFY WEBKIT LIBXML X11 WS2_32 OPENSSL HILDON HILDON_FM' + 'LIBNOTIFY WEBKIT LIBXML X11 XSS WS2_32 OPENSSL HILDON HILDON_FM' if progressive or Options.commands['check']: obj = bld.new_task_gen ('cc', 'staticlib') diff --git a/wscript b/wscript index bb789a0e..e5d682aa 100644 --- a/wscript +++ b/wscript @@ -209,6 +209,7 @@ def configure (conf): args = '--define-variable=target=win32' elif sys.platform != 'darwin': check_pkg ('x11') + conf.check (lib='Xss', mandatory=True) check_pkg ('gtk+-2.0', '2.10.0', var='GTK', args=args) check_pkg ('webkit-1.0', '1.1.1', args=args) check_pkg ('libsoup-2.4', '2.25.2') -- 2.39.5