gardesk/ers / bf0189e

Browse files

remove dead code, replace debug prints with tracing, fix all warnings

Authored by espadonne
SHA
bf0189e7cb3a14e2ec4868b04c8d92f10e6f9f0f
Parents
2fae700
Tree
d892ce1

1 changed file

StatusFile+-
M src/main.rs 19 44
src/main.rsmodified
@@ -10,6 +10,7 @@ use std::ptr;
1010
 use std::sync::atomic::{AtomicBool, Ordering};
1111
 use std::sync::mpsc;
1212
 use std::sync::Arc;
13
+use tracing::debug;
1314
 
1415
 /// Per-overlay state: the connection it was created on + its wid.
1516
 struct Overlay {
@@ -157,16 +158,6 @@ impl BorderMap {
157158
         }
158159
     }
159160
 
160
-    fn apply_tags_all(&self) {
161
-        unsafe {
162
-            let tags: u64 = 1 << 1;
163
-            for o in self.overlays.values() {
164
-                SLSSetWindowTags(o.cid, o.wid, &tags, 64);
165
-                disable_shadow(o.wid);
166
-            }
167
-        }
168
-    }
169
-
170161
     fn subscribe_target(&self, target_wid: u32) {
171162
         unsafe {
172163
             SLSRequestNotificationsForWindows(self.main_cid, &target_wid, 1);
@@ -200,11 +191,7 @@ impl BorderMap {
200191
                 let ctx = SLWindowContextCreate(overlay.cid, overlay.wid, ptr::null());
201192
                 if ctx.is_null() { return; }
202193
 
203
-                let full = CGRect::new(0.0, 0.0, ow, oh);
204
-                CGContextClearRect(ctx, full);
205
-
206194
                 let color = self.color_for(target_wid);
207
-                let stroke_rect = CGRect::new(bw / 2.0, bw / 2.0, ow - bw, oh - bw);
208195
                 draw_border(ctx, ow, oh, bw, self.radius, color);
209196
                 SLSFlushWindowContentRegion(overlay.cid, overlay.wid, ptr::null());
210197
                 CGContextRelease(ctx);
@@ -219,7 +206,7 @@ impl BorderMap {
219206
 
220207
         let old = self.focused_wid;
221208
         self.focused_wid = front;
222
-        eprintln!("[focus] {} -> {}", old, front);
209
+        debug!("[focus] {} -> {}", old, front);
223210
 
224211
         if self.active_only {
225212
             self.hide(old);
@@ -332,6 +319,11 @@ fn print_help() {
332319
 }
333320
 
334321
 fn main() {
322
+    tracing_subscriber::fmt()
323
+        .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
324
+        .with_writer(std::io::stderr)
325
+        .init();
326
+
335327
     let args: Vec<String> = std::env::args().collect();
336328
 
337329
     if args.iter().any(|s| s == "--help" || s == "-h") {
@@ -386,11 +378,9 @@ fn main() {
386378
         borders.add_batch(target);
387379
     } else {
388380
         let wids = discover_windows(cid, own_pid);
389
-        eprintln!("{} windows discovered", wids.len());
390381
         for &wid in &wids {
391382
             borders.add_batch(wid);
392383
         }
393
-        eprintln!("{} borders created", borders.overlays.len());
394384
     }
395385
 
396386
     borders.subscribe_all();
@@ -408,17 +398,18 @@ fn main() {
408398
         }
409399
     }
410400
 
411
-    eprintln!("{} overlays tracked", borders.overlays.len());
401
+    debug!("{} overlays tracked", borders.overlays.len());
412402
 
413403
     // SIGINT flag — background thread checks this to clean up
414404
     let running = Arc::new(AtomicBool::new(true));
415405
     unsafe {
416406
         libc::signal(libc::SIGINT, {
417407
             unsafe extern "C" fn handler(_: libc::c_int) {
418
-                // Stop CFRunLoop on main thread — this returns control to main()
408
+                unsafe {
419409
                     CFRunLoopStop(CFRunLoopGetMain());
420410
                 }
421
-            handler as libc::sighandler_t
411
+            }
412
+            handler as *const () as libc::sighandler_t
422413
         });
423414
     }
424415
 
@@ -611,7 +602,7 @@ unsafe extern "C" fn drain_events(_: CFMachPortRef, _: *mut std::ffi::c_void, _:
611602
     }
612603
 }
613604
 
614
-fn discover_windows(cid: CGSConnectionID, own_pid: i32) -> Vec<u32> {
605
+fn discover_windows(_cid: CGSConnectionID, own_pid: i32) -> Vec<u32> {
615606
     unsafe {
616607
         let list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
617608
         if list.is_null() { return vec![]; }
@@ -697,11 +688,11 @@ fn create_overlay(
697688
         let mut bounds = CGRect::default();
698689
         let rc = SLSGetWindowBounds(cid, target_wid, &mut bounds);
699690
         if rc != kCGErrorSuccess {
700
-            eprintln!("[create_overlay] SLSGetWindowBounds failed for wid={target_wid} rc={rc}");
691
+            debug!("[create_overlay] SLSGetWindowBounds failed for wid={target_wid} rc={rc}");
701692
             return None;
702693
         }
703694
         if bounds.size.width < 10.0 || bounds.size.height < 10.0 {
704
-            eprintln!("[create_overlay] wid={target_wid} too small: {}x{}", bounds.size.width, bounds.size.height);
695
+            debug!("[create_overlay] wid={target_wid} too small: {}x{}", bounds.size.width, bounds.size.height);
705696
             return None;
706697
         }
707698
 
@@ -715,7 +706,7 @@ fn create_overlay(
715706
         let mut region: CFTypeRef = ptr::null();
716707
         CGSNewRegionWithRect(&frame, &mut region);
717708
         if region.is_null() {
718
-            eprintln!("[create_overlay] CGSNewRegionWithRect failed for wid={target_wid}");
709
+            debug!("[create_overlay] CGSNewRegionWithRect failed for wid={target_wid}");
719710
             return None;
720711
         }
721712
 
@@ -723,11 +714,11 @@ fn create_overlay(
723714
         SLSNewWindow(cid, 2, ox as f32, oy as f32, region, &mut wid);
724715
         CFRelease(region);
725716
         if wid == 0 {
726
-            eprintln!("[create_overlay] SLSNewWindow returned 0 for target={target_wid} cid={cid}");
717
+            debug!("[create_overlay] SLSNewWindow returned 0 for target={target_wid} cid={cid}");
727718
             return None;
728719
         }
729720
 
730
-        eprintln!("[create_overlay] created overlay wid={wid} for target={target_wid} color=({:.2},{:.2},{:.2},{:.2})",
721
+        debug!("[create_overlay] created overlay wid={wid} for target={target_wid} color=({:.2},{:.2},{:.2},{:.2})",
731722
             color.0, color.1, color.2, color.3);
732723
 
733724
         SLSSetWindowResolution(cid, wid, 2.0);
@@ -738,7 +729,7 @@ fn create_overlay(
738729
         // Draw border (point coordinates)
739730
         let ctx = SLWindowContextCreate(cid, wid, ptr::null());
740731
         if ctx.is_null() {
741
-            eprintln!("[create_overlay] SLWindowContextCreate returned null for overlay wid={wid}");
732
+            debug!("[create_overlay] SLWindowContextCreate returned null for overlay wid={wid}");
742733
             SLSReleaseWindow(cid, wid);
743734
             return None;
744735
         }
@@ -787,19 +778,3 @@ fn list_windows() {
787778
     }
788779
 }
789780
 
790
-unsafe fn disable_shadow(wid: u32) {
791
-    let density: i64 = 0;
792
-    let density_cf = CFNumberCreate(ptr::null(), kCFNumberCFIndexType, &density as *const _ as *const _);
793
-    let key = CFStringCreateWithCString(ptr::null(), b"com.apple.WindowShadowDensity\0".as_ptr(), kCFStringEncodingUTF8);
794
-    let keys = [key as CFTypeRef];
795
-    let values = [density_cf as CFTypeRef];
796
-    let dict = CFDictionaryCreate(
797
-        ptr::null(), keys.as_ptr(), values.as_ptr(), 1,
798
-        &kCFTypeDictionaryKeyCallBacks as *const _ as *const _,
799
-        &kCFTypeDictionaryValueCallBacks as *const _ as *const _,
800
-    );
801
-    SLSWindowSetShadowProperties(wid, dict);
802
-    CFRelease(dict);
803
-    CFRelease(density_cf);
804
-    CFRelease(key as CFTypeRef);
805
-}