@@ -10,6 +10,7 @@ use std::ptr; |
| 10 | 10 | use std::sync::atomic::{AtomicBool, Ordering}; |
| 11 | 11 | use std::sync::mpsc; |
| 12 | 12 | use std::sync::Arc; |
| 13 | +use tracing::debug; |
| 13 | 14 | |
| 14 | 15 | /// Per-overlay state: the connection it was created on + its wid. |
| 15 | 16 | struct Overlay { |
@@ -157,16 +158,6 @@ impl BorderMap { |
| 157 | 158 | } |
| 158 | 159 | } |
| 159 | 160 | |
| 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 | | - |
| 170 | 161 | fn subscribe_target(&self, target_wid: u32) { |
| 171 | 162 | unsafe { |
| 172 | 163 | SLSRequestNotificationsForWindows(self.main_cid, &target_wid, 1); |
@@ -200,11 +191,7 @@ impl BorderMap { |
| 200 | 191 | let ctx = SLWindowContextCreate(overlay.cid, overlay.wid, ptr::null()); |
| 201 | 192 | if ctx.is_null() { return; } |
| 202 | 193 | |
| 203 | | - let full = CGRect::new(0.0, 0.0, ow, oh); |
| 204 | | - CGContextClearRect(ctx, full); |
| 205 | | - |
| 206 | 194 | let color = self.color_for(target_wid); |
| 207 | | - let stroke_rect = CGRect::new(bw / 2.0, bw / 2.0, ow - bw, oh - bw); |
| 208 | 195 | draw_border(ctx, ow, oh, bw, self.radius, color); |
| 209 | 196 | SLSFlushWindowContentRegion(overlay.cid, overlay.wid, ptr::null()); |
| 210 | 197 | CGContextRelease(ctx); |
@@ -219,7 +206,7 @@ impl BorderMap { |
| 219 | 206 | |
| 220 | 207 | let old = self.focused_wid; |
| 221 | 208 | self.focused_wid = front; |
| 222 | | - eprintln!("[focus] {} -> {}", old, front); |
| 209 | + debug!("[focus] {} -> {}", old, front); |
| 223 | 210 | |
| 224 | 211 | if self.active_only { |
| 225 | 212 | self.hide(old); |
@@ -332,6 +319,11 @@ fn print_help() { |
| 332 | 319 | } |
| 333 | 320 | |
| 334 | 321 | 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 | + |
| 335 | 327 | let args: Vec<String> = std::env::args().collect(); |
| 336 | 328 | |
| 337 | 329 | if args.iter().any(|s| s == "--help" || s == "-h") { |
@@ -386,11 +378,9 @@ fn main() { |
| 386 | 378 | borders.add_batch(target); |
| 387 | 379 | } else { |
| 388 | 380 | let wids = discover_windows(cid, own_pid); |
| 389 | | - eprintln!("{} windows discovered", wids.len()); |
| 390 | 381 | for &wid in &wids { |
| 391 | 382 | borders.add_batch(wid); |
| 392 | 383 | } |
| 393 | | - eprintln!("{} borders created", borders.overlays.len()); |
| 394 | 384 | } |
| 395 | 385 | |
| 396 | 386 | borders.subscribe_all(); |
@@ -408,17 +398,18 @@ fn main() { |
| 408 | 398 | } |
| 409 | 399 | } |
| 410 | 400 | |
| 411 | | - eprintln!("{} overlays tracked", borders.overlays.len()); |
| 401 | + debug!("{} overlays tracked", borders.overlays.len()); |
| 412 | 402 | |
| 413 | 403 | // SIGINT flag — background thread checks this to clean up |
| 414 | 404 | let running = Arc::new(AtomicBool::new(true)); |
| 415 | 405 | unsafe { |
| 416 | 406 | libc::signal(libc::SIGINT, { |
| 417 | 407 | unsafe extern "C" fn handler(_: libc::c_int) { |
| 418 | | - // Stop CFRunLoop on main thread — this returns control to main() |
| 408 | + unsafe { |
| 419 | 409 | CFRunLoopStop(CFRunLoopGetMain()); |
| 420 | 410 | } |
| 421 | | - handler as libc::sighandler_t |
| 411 | + } |
| 412 | + handler as *const () as libc::sighandler_t |
| 422 | 413 | }); |
| 423 | 414 | } |
| 424 | 415 | |
@@ -611,7 +602,7 @@ unsafe extern "C" fn drain_events(_: CFMachPortRef, _: *mut std::ffi::c_void, _: |
| 611 | 602 | } |
| 612 | 603 | } |
| 613 | 604 | |
| 614 | | -fn discover_windows(cid: CGSConnectionID, own_pid: i32) -> Vec<u32> { |
| 605 | +fn discover_windows(_cid: CGSConnectionID, own_pid: i32) -> Vec<u32> { |
| 615 | 606 | unsafe { |
| 616 | 607 | let list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); |
| 617 | 608 | if list.is_null() { return vec![]; } |
@@ -697,11 +688,11 @@ fn create_overlay( |
| 697 | 688 | let mut bounds = CGRect::default(); |
| 698 | 689 | let rc = SLSGetWindowBounds(cid, target_wid, &mut bounds); |
| 699 | 690 | 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}"); |
| 701 | 692 | return None; |
| 702 | 693 | } |
| 703 | 694 | 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); |
| 705 | 696 | return None; |
| 706 | 697 | } |
| 707 | 698 | |
@@ -715,7 +706,7 @@ fn create_overlay( |
| 715 | 706 | let mut region: CFTypeRef = ptr::null(); |
| 716 | 707 | CGSNewRegionWithRect(&frame, &mut region); |
| 717 | 708 | if region.is_null() { |
| 718 | | - eprintln!("[create_overlay] CGSNewRegionWithRect failed for wid={target_wid}"); |
| 709 | + debug!("[create_overlay] CGSNewRegionWithRect failed for wid={target_wid}"); |
| 719 | 710 | return None; |
| 720 | 711 | } |
| 721 | 712 | |
@@ -723,11 +714,11 @@ fn create_overlay( |
| 723 | 714 | SLSNewWindow(cid, 2, ox as f32, oy as f32, region, &mut wid); |
| 724 | 715 | CFRelease(region); |
| 725 | 716 | 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}"); |
| 727 | 718 | return None; |
| 728 | 719 | } |
| 729 | 720 | |
| 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})", |
| 731 | 722 | color.0, color.1, color.2, color.3); |
| 732 | 723 | |
| 733 | 724 | SLSSetWindowResolution(cid, wid, 2.0); |
@@ -738,7 +729,7 @@ fn create_overlay( |
| 738 | 729 | // Draw border (point coordinates) |
| 739 | 730 | let ctx = SLWindowContextCreate(cid, wid, ptr::null()); |
| 740 | 731 | 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}"); |
| 742 | 733 | SLSReleaseWindow(cid, wid); |
| 743 | 734 | return None; |
| 744 | 735 | } |
@@ -787,19 +778,3 @@ fn list_windows() { |
| 787 | 778 | } |
| 788 | 779 | } |
| 789 | 780 | |
| 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 | | -} |