gardesk/ers / 197f054

Browse files

add --active-only flag to hide borders on unfocused windows

Authored by espadonne
SHA
197f054c3b817e61b81a7b83109965c63158524e
Parents
6599bc6
Tree
62474ab

1 changed file

StatusFile+-
M src/main.rs 23 1
src/main.rsmodified
@@ -24,6 +24,7 @@ struct BorderMap {
2424
     focused_wid: u32,
2525
     active_color: (f64, f64, f64, f64),
2626
     inactive_color: (f64, f64, f64, f64),
27
+    active_only: bool,
2728
 }
2829
 
2930
 impl BorderMap {
@@ -36,6 +37,7 @@ impl BorderMap {
3637
             focused_wid: 0,
3738
             active_color: (0.32, 0.58, 0.89, 1.0),   // #5294e2
3839
             inactive_color: (0.35, 0.35, 0.35, 0.8),  // dim gray
40
+            active_only: false,
3941
         }
4042
     }
4143
 
@@ -200,7 +202,10 @@ impl BorderMap {
200202
         self.focused_wid = front;
201203
         eprintln!("[focus] {} -> {}", old, front);
202204
 
203
-        // Redraw in-place with new color — no destroy/recreate needed
205
+        if self.active_only {
206
+            self.hide(old);
207
+            self.unhide(front);
208
+        }
204209
         self.redraw(old);
205210
         self.redraw(front);
206211
     }
@@ -271,6 +276,8 @@ fn main() {
271276
         .and_then(|i| args.get(i + 1)?.parse().ok())
272277
         .unwrap_or(4.0);
273278
 
279
+    let active_only = args.iter().any(|s| s == "--active-only");
280
+
274281
     let cid = unsafe { SLSMainConnectionID() };
275282
     let own_pid = unsafe {
276283
         let mut pid: i32 = 0;
@@ -286,6 +293,7 @@ fn main() {
286293
 
287294
     // Discover and create borders
288295
     let mut borders = BorderMap::new(cid, own_pid, border_width);
296
+    borders.active_only = active_only;
289297
 
290298
     if let Some(target) = args.get(1).and_then(|s| s.parse::<u32>().ok()) {
291299
         borders.add_batch(target);
@@ -302,6 +310,17 @@ fn main() {
302310
 
303311
     borders.update_focus();
304312
 
313
+    if borders.active_only {
314
+        let focused = borders.focused_wid;
315
+        let to_hide: Vec<u32> = borders.overlays.keys()
316
+            .filter(|&&wid| wid != focused)
317
+            .copied()
318
+            .collect();
319
+        for wid in to_hide {
320
+            borders.hide(wid);
321
+        }
322
+    }
323
+
305324
     eprintln!("{} overlays tracked", borders.overlays.len());
306325
 
307326
     // Process events on background thread with coalescing
@@ -411,6 +430,9 @@ fn main() {
411430
                 pending.remove(&wid);
412431
                 if !skip.contains(&wid) {
413432
                     borders.add_fresh(wid);
433
+                    if borders.active_only && wid != borders.focused_wid {
434
+                        borders.hide(wid);
435
+                    }
414436
                     needs_resubscribe = true;
415437
                 }
416438
             }