From 7850aa458ec41a1d0462b0a592a04988c1024c0b Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Mon, 18 Feb 2019 20:53:32 +0100 Subject: Re-introduce inactivity-reset without relying on X11 (#263) Fixes: #262 --- core/app.vala | 14 ++++++++++++++ core/browser.vala | 9 ++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/app.vala b/core/app.vala index 7c3e8bd4..4c33b962 100644 --- a/core/app.vala +++ b/core/app.vala @@ -22,12 +22,14 @@ namespace Midori { [CCode (array_length = false, array_null_terminated = true)] static string[]? execute = null; static bool help_execute = false; + static int inactivity_reset = 0; static bool incognito = false; static bool version = false; const OptionEntry[] options = { { "app", 'a', 0, OptionArg.STRING, ref app, N_("Run ADDRESS as a web application"), N_("ADDRESS") }, { "execute", 'e', 0, OptionArg.STRING_ARRAY, ref execute, N_("Execute the specified command"), null }, { "help-execute", 0, 0, OptionArg.NONE, ref help_execute, N_("List available commands to execute with -e/ --execute"), null }, + { "inactivity-reset", 'i', 0, OptionArg.INT, ref inactivity_reset, N_("Reset Midori after SECONDS seconds of inactivity"), N_("SECONDS") }, { "private", 'p', 0, OptionArg.NONE, ref incognito, N_("Private browsing, no changes are saved"), null }, { "version", 'V', 0, OptionArg.NONE, ref version, N_("Display version number"), null }, { null } @@ -409,6 +411,7 @@ namespace Midori { options.insert_value ("app", app ?? ""); options.insert_value ("execute", execute); options.insert_value ("help-execute", help_execute); + options.insert_value ("inactivity-reset", inactivity_reset); options.insert_value ("private", incognito); return -1; } @@ -421,6 +424,7 @@ namespace Midori { app = options.lookup_value ("app", VariantType.STRING).get_string (); execute = options.lookup_value ("execute", VariantType.STRING_ARRAY).dup_strv (); help_execute = options.lookup_value ("help-execute", VariantType.BOOLEAN).get_boolean (); + inactivity_reset = options.lookup_value ("inactivity-reset", VariantType.INT32).get_int32 (); incognito = options.lookup_value ("private", VariantType.BOOLEAN).get_boolean (); debug ("Processing remote command line %s/ %s\n", string.joinv (", ", command_line.get_arguments ()), options.end ().print (true)); @@ -441,6 +445,16 @@ namespace Midori { tab.pinned = true; browser.add (tab); browser.show (); + if (inactivity_reset > 0) { + Timeout.add_seconds (inactivity_reset, () => { + if (browser.idle) { + tab.load_uri (app); + } else { + browser.idle = true; + } + return Source.CONTINUE; + }, Priority.LOW); + } } uint argc = command_line.get_arguments ().length; diff --git a/core/browser.vala b/core/browser.vala index 4af350d2..03ec9ed1 100644 --- a/core/browser.vala +++ b/core/browser.vala @@ -19,6 +19,7 @@ namespace Midori { [GtkTemplate (ui = "/ui/browser.ui")] public class Browser : Gtk.ApplicationWindow { public WebKit.WebContext web_context { get; construct set; } + internal bool idle { get; protected set; default = false; } public bool is_loading { get; protected set; default = false; } public string? uri { get; protected set; } public Tab? tab { get; protected set; } @@ -78,7 +79,7 @@ namespace Midori { uint focus_timeout = 0; construct { - overlay.add_events (Gdk.EventMask.ENTER_NOTIFY_MASK); + overlay.add_events (Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.POINTER_MOTION_MASK); overlay.enter_notify_event.connect ((event) => { if (is_fullscreen && !tab.pinned) { navigationbar.show (); @@ -92,6 +93,10 @@ namespace Midori { } return false; }); + overlay.motion_notify_event.connect ((event) => { + idle = false; + return false; + }); navigationbar.urlbar.focus_out_event.connect ((event) => { if (is_fullscreen) { navigationbar.hide (); @@ -216,6 +221,7 @@ namespace Midori { stop.activate.connect (tab_stop_loading_activated); add_action (stop); notify["is-loading"].connect (() => { + idle = false; reload.set_enabled (!is_loading); stop.set_enabled (is_loading); }); @@ -386,6 +392,7 @@ namespace Midori { } public override bool key_press_event (Gdk.EventKey event) { + idle = false; // No keyboard shortcuts in locked state if (is_locked) { return propagate_key_event (event); -- cgit v1.2.1