Browse code

rehelper: exit if it detects another instance is running

Dario Rodriguez authored on 02/01/2024 17:08:33
Showing 1 changed files
... ...
@@ -28,8 +28,25 @@ pack .b -side top -fill both -expand true
28 28
 
29 29
 set curselection ""
30 30
 
31
+set lastseconds 0
32
+set nstolen 0
33
+
31 34
 proc selectionlost {} {
32 35
         global curselection
36
+        global lastseconds nstolen
37
+        # check if there is another instance fighting for the selection
38
+        set newseconds [clock seconds]
39
+        if { $newseconds == $lastseconds } {
40
+                incr nstolen
41
+                if { $nstolen>10 } {
42
+                        puts "There seems to be another instance running, exiting"
43
+                        exit 0
44
+                }
45
+        } else {
46
+                set lastseconds $newseconds
47
+                set nstolen 0
48
+        }
49
+        # process the selection
33 50
         set curselection [selection get -selection PRIMARY]
34 51
         puts $curselection
35 52
         checkselection $curselection