From 38a633cd9ff3af515ded78407a3e0f97babb8c5d Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Thu, 4 Mar 2021 10:26:49 -0700 Subject: [PATCH 1/2] Add --single-app command-line option for easier kiosk mode Combined with "--app=URL", "--single-app" will replace the URL of an existing browser window, instead of opening a new one. If no existing browser window is open, "--single-app" is a no-op and a new browser window will open. Example: # Open a browser in full screen, app mode (e.g. a "kiosk") midori -e fullscreen -a https://www.google.com # Replace the webpage shown on the existing browser midori --single-app -a https://www.yahoo.com --- core/app.vala | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/core/app.vala b/core/app.vala index e8c1676a7..0cacca6c2 100644 --- a/core/app.vala +++ b/core/app.vala @@ -24,9 +24,11 @@ namespace Midori { static bool help_execute = false; static int inactivity_reset = 0; static bool incognito = false; + static bool single_app = false; static bool version = false; const OptionEntry[] options = { { "app", 'a', 0, OptionArg.STRING, ref app, N_("Run ADDRESS as a web application"), N_("ADDRESS") }, + { "single-app", 'S', 0, OptionArg.NONE, ref single_app, N_("With --app, prefer currently open browser window (if any)"), null }, { "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") }, @@ -426,6 +428,7 @@ namespace Midori { // Propagate options processed in the primary instance options.insert_value ("app", app ?? ""); options.insert_value ("execute", execute); + options.insert_value ("single-app", single_app); options.insert_value ("help-execute", help_execute); options.insert_value ("inactivity-reset", inactivity_reset); options.insert_value ("private", incognito); @@ -438,6 +441,7 @@ namespace Midori { // Retrieve values for options passed from another process var options = command_line.get_options_dict (); app = options.lookup_value ("app", VariantType.STRING).get_string (); + single_app = options.lookup_value ("single-app", VariantType.BOOLEAN).get_boolean (); 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 (); @@ -456,11 +460,24 @@ namespace Midori { } if (app != "") { - var browser = new Browser (this, true); - var tab = new Tab (null, browser.web_context, app); - tab.pinned = true; - browser.add (tab); + var create_new = !single_app || (active_window == null); + + var browser = (create_new) ? new Browser (this, true) : (active_window as Browser) ; + Tab tab = null ; + + var num_tabs = browser.tabs.get_children().length(); + + if (create_new || (num_tabs==0)) { + tab = new Tab (null, browser.web_context, app); + tab.pinned = true; + browser.add (tab); + } else { + tab = (Tab)browser.tabs.get_children().nth_data(0); + tab.load_uri(app); + } + browser.show (); + if (inactivity_reset > 0) { Timeout.add_seconds (inactivity_reset, () => { if (browser.idle) { From 2f32d9a44e7c824af9c60a232e0d42407f989e4a Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Fri, 5 Mar 2021 00:10:36 -0700 Subject: [PATCH 2/2] new -e/--execute command: 'force-fullscreen' Complementary to '-e fullscreen' which toggles fullscreen mode, this command always turns full-screen mode (or no-op if already in full screen mode). This is useful for kiosk mode, especially with changing the kiosk webpage display from the command line. Example: midory -e force-fullscreen -a https://www.yahoo.com --- core/browser.vala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/browser.vala b/core/browser.vala index 503aa301c..9a3ccb5eb 100644 --- a/core/browser.vala +++ b/core/browser.vala @@ -48,6 +48,7 @@ namespace Midori { { "clear-private-data", clear_private_data_activated }, { "preferences", preferences_activated }, { "about", about_activated }, + { "force-fullscreen", force_fullscreen_activated }, }; [GtkChild] Gtk.HeaderBar panelbar; @@ -605,6 +606,12 @@ namespace Midori { } } + void force_fullscreen_activated () { + if (!is_fullscreen) { + fullscreen_activated (); + } + } + void show_downloads_activated () { downloads.show_downloads (); }