Skip to content

Commit

Permalink
Re-introduce inactivity-reset without relying on X11 (#263)
Browse files Browse the repository at this point in the history
Fixes: #262
  • Loading branch information
kalikiana committed Feb 18, 2019
1 parent 7b2675a commit 7850aa4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions core/app.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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;
}
Expand All @@ -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));
Expand All @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion core/browser.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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 ();
Expand All @@ -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 ();
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7850aa4

Please sign in to comment.