summarylogtreecommitdiffstats
path: root/0002-Add-argument-to-start-initial-instance-in-the-backgr.patch
blob: f5479ce83fc3303efde2d25be45a783770e6198c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From 94e223701269f5c9e60bd69575b62aca91c0f85a Mon Sep 17 00:00:00 2001
From: Adam Plumb <adamplumb@gmail.com>
Date: Fri, 10 Sep 2021 20:14:19 -0400
Subject: [PATCH] Add argument to start initial instance in the background

---
 src/application.vala | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/application.vala b/src/application.vala
index 6c1e39a..864b277 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -21,6 +21,7 @@ namespace Clocks {
 public class Application : Adw.Application {
     const OptionEntry[] OPTION_ENTRIES = {
         { "version", 'v', 0, OptionArg.NONE, null, N_("Print version information and exit"), null },
+        { "background", 'b', 0, OptionArg.NONE, null, N_("Start in the background"), null },
         { (string) null }
     };
 
@@ -37,6 +38,7 @@ public class Application : Adw.Application {
     private uint world_clocks_id = 0;
     private Window? window;
     private List<string> system_notifications;
+    private bool background = false;
 
     private Window ensure_window () ensures (window != null) {
         if (window == null) {
@@ -97,7 +99,15 @@ public class Application : Adw.Application {
         base.activate ();
 
         var win = ensure_window ();
-        win.present ();
+
+        // The first activation will toggle the background flag to false
+        // That way the next activation (of other instances)
+        // will cause the window to display
+        if (background) {
+            background = false;
+        } else {
+            win.present ();
+        }
     }
 
     protected override void startup () {
@@ -117,6 +127,13 @@ public class Application : Adw.Application {
             return 0;
         }
 
+        // This allows the primary instance to start in the background
+        // Any subsequent instances will cause the window to display
+        // Even if they pass in the background argument
+        if (options.contains ("background")) {
+            background = true;
+        }
+
         return -1;
     }
 
-- 
2.35.1