Skip to content

Commit

Permalink
Implement -i, --inactivity-reset command line option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kalikiana committed Mar 31, 2010
1 parent 632b197 commit 8befee3
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
83 changes: 83 additions & 0 deletions midori/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
#define BOOKMARK_FILE "bookmarks.xbel"
#endif

#ifdef GDK_WINDOWING_X11
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/scrnsaver.h>
#include <gdk/gdkx.h>
#endif

static gchar*
build_config_filename (const gchar* filename)
{
Expand Down Expand Up @@ -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)
Expand All @@ -1434,6 +1506,7 @@ main (int argc,
gboolean execute;
gboolean version;
gchar** uris;
gint inactivity_reset;
MidoriApp* app;
gboolean result;
GError* error;
Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion midori/wscript_build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 8befee3

Please sign in to comment.