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.
This commit is contained in:
parent
832b2e9922
commit
37e2216775
3 changed files with 85 additions and 1 deletions
|
@ -54,6 +54,13 @@
|
||||||
#define BOOKMARK_FILE "bookmarks.xbel"
|
#define BOOKMARK_FILE "bookmarks.xbel"
|
||||||
#endif
|
#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*
|
static gchar*
|
||||||
build_config_filename (const gchar* filename)
|
build_config_filename (const gchar* filename)
|
||||||
{
|
{
|
||||||
|
@ -1422,6 +1429,71 @@ signal_handler (int signal_id)
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char** argv)
|
char** argv)
|
||||||
|
@ -1434,6 +1506,7 @@ main (int argc,
|
||||||
gboolean execute;
|
gboolean execute;
|
||||||
gboolean version;
|
gboolean version;
|
||||||
gchar** uris;
|
gchar** uris;
|
||||||
|
gint inactivity_reset;
|
||||||
MidoriApp* app;
|
MidoriApp* app;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
GError* error;
|
GError* error;
|
||||||
|
@ -1459,6 +1532,10 @@ main (int argc,
|
||||||
N_("Display program version"), NULL },
|
N_("Display program version"), NULL },
|
||||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris,
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris,
|
||||||
N_("Addresses"), NULL },
|
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 }
|
{ NULL }
|
||||||
};
|
};
|
||||||
GString* error_messages;
|
GString* error_messages;
|
||||||
|
@ -1534,6 +1611,7 @@ main (int argc,
|
||||||
execute = FALSE;
|
execute = FALSE;
|
||||||
version = FALSE;
|
version = FALSE;
|
||||||
uris = NULL;
|
uris = NULL;
|
||||||
|
inactivity_reset = 0;
|
||||||
error = NULL;
|
error = NULL;
|
||||||
if (!gtk_init_with_args (&argc, &argv, _("[Addresses]"), entries,
|
if (!gtk_init_with_args (&argc, &argv, _("[Addresses]"), entries,
|
||||||
GETTEXT_PACKAGE, &error))
|
GETTEXT_PACKAGE, &error))
|
||||||
|
@ -1642,11 +1720,16 @@ main (int argc,
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
midori_setup_inactivity_reset (browser, inactivity_reset, webapp);
|
||||||
midori_startup_timer ("App created: \t%f");
|
midori_startup_timer ("App created: \t%f");
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
return 0;
|
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 */
|
/* Standalone javascript support */
|
||||||
if (run)
|
if (run)
|
||||||
return midori_run_script (uris ? *uris : NULL);
|
return midori_run_script (uris ? *uris : NULL);
|
||||||
|
|
|
@ -6,7 +6,7 @@ import platform
|
||||||
|
|
||||||
progressive = True
|
progressive = True
|
||||||
libs = 'M UNIQUE LIBSOUP GMODULE GTHREAD LIBIDN GIO GTK SQLITE ' \
|
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']:
|
if progressive or Options.commands['check']:
|
||||||
obj = bld.new_task_gen ('cc', 'staticlib')
|
obj = bld.new_task_gen ('cc', 'staticlib')
|
||||||
|
|
1
wscript
1
wscript
|
@ -209,6 +209,7 @@ def configure (conf):
|
||||||
args = '--define-variable=target=win32'
|
args = '--define-variable=target=win32'
|
||||||
elif sys.platform != 'darwin':
|
elif sys.platform != 'darwin':
|
||||||
check_pkg ('x11')
|
check_pkg ('x11')
|
||||||
|
conf.check (lib='Xss', mandatory=True)
|
||||||
check_pkg ('gtk+-2.0', '2.10.0', var='GTK', args=args)
|
check_pkg ('gtk+-2.0', '2.10.0', var='GTK', args=args)
|
||||||
check_pkg ('webkit-1.0', '1.1.1', args=args)
|
check_pkg ('webkit-1.0', '1.1.1', args=args)
|
||||||
check_pkg ('libsoup-2.4', '2.25.2')
|
check_pkg ('libsoup-2.4', '2.25.2')
|
||||||
|
|
Loading…
Reference in a new issue