From 1e684db291d46d4e90f35c6009f9b7a294893bba Mon Sep 17 00:00:00 2001 From: Jonathan Ami <126116089+jonathan-ami@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:27:22 -0700 Subject: [PATCH] changed leader + added blacklist --- src/callbacks.rs | 2 +- src/keybinds.rs | 5 ++++- src/main.rs | 1 + src/window_manager.rs | 22 +++++++++++++++------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/callbacks.rs b/src/callbacks.rs index efafa6c..f3a5515 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -37,7 +37,7 @@ pub unsafe extern "system" fn enum_windows_proc(hwnd: HWND, lparam: LPARAM) -> B //SW_HIDE and SW_SHOWMINIMIZED if window.placement.showCmd != 0 && window.placement.showCmd != 2 { if let Some(title) = window.get_title() { - if title != "Windows Input Experience" { + if !window_manager.blacklist.contains(&title) { window_manager.set_window(window); } } diff --git a/src/keybinds.rs b/src/keybinds.rs index fb3fea3..15ea8bb 100644 --- a/src/keybinds.rs +++ b/src/keybinds.rs @@ -28,7 +28,9 @@ const KEY_N: u32 = 0x4E; const KEY_D: u32 = 0x44; const KEY_P: u32 = 0x50; const ESC: u32 = 0x1B; +const SHIFT: u32 = 0x10; const SPACE: u32 = 0x20; +const CAPS: u32 = 0x14; pub fn handle_hotkey( wparam: i32, @@ -36,6 +38,7 @@ pub fn handle_hotkey( leader_pressed: bool, ) -> Result { if !leader_pressed && wparam == LEADER { + println!("leader pressed"); match register_hotkeys() { Ok(_) => return Ok(true), Err(e) => return Err(format!("Error: {}", e)), @@ -103,7 +106,7 @@ pub fn handle_hotkey( } pub fn register_leader() -> Result<(), Error> { unsafe { - if let Err(e) = RegisterHotKey(None, LEADER, HOT_KEY_MODIFIERS(4), SPACE) { + if let Err(e) = RegisterHotKey(None, LEADER, HOT_KEY_MODIFIERS(1), CAPS) { println!("{}", e); } } diff --git a/src/main.rs b/src/main.rs index f7824c9..b85dc36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,6 +105,7 @@ fn main() -> Result<(), Error> { window_manager.set_windows(); let window_manger_listener = thread::spawn(move || window_manager.start()); + unregister_leader(); match register_leader() { Ok(()) => println!("Leader Registered"), Err(e) => println!("Failed to registrer leader: {}", e), diff --git a/src/window_manager.rs b/src/window_manager.rs index 45bb93d..fcca0d5 100644 --- a/src/window_manager.rs +++ b/src/window_manager.rs @@ -1,6 +1,7 @@ use crate::callbacks::enum_windows_proc; use crate::window::Window; +use std::collections::HashSet; use std::sync::mpsc::Receiver; use windows::Win32::Foundation::{HWND, LPARAM}; use windows::Win32::UI::WindowsAndMessaging::{ @@ -26,18 +27,23 @@ pub enum WindowManagerMessage { pub struct WindowManager { pub current: Window, - pub left: Option, - pub right: Option, - pub below: Option, - pub above: Option, + left: Option, + right: Option, + below: Option, + above: Option, next: Option, window_stack: Vec, // keep track of prevous windows stack_bottom: Option, pub count: i32, // corresponds to order in window struct receiver: Receiver, + pub blacklist: HashSet, //window titles that will not be managed } impl WindowManager { pub fn new(receiver: Receiver) -> WindowManager { + let mut names = HashSet::new(); + names.insert("Windows Input Experience".to_string()); + names.insert("Program Manager".to_string()); + names.insert("Settings".to_string()); let current = unsafe { Window::new(GetForegroundWindow(), 0) }; WindowManager { current, @@ -50,6 +56,7 @@ impl WindowManager { stack_bottom: None, count: 0, receiver: receiver, + blacklist: names, } } @@ -75,6 +82,7 @@ impl WindowManager { } pub fn set_window(&mut self, window: Window) { + window.print_title(); if self.left.is_none() && window.rect.right <= self.current.rect.left { self.left = Some(window); } else if self.right.is_none() && window.rect.left >= self.current.rect.right { @@ -108,7 +116,7 @@ impl WindowManager { } } - pub fn close_window(&mut self) { + fn close_window(&mut self) { unsafe { if let Err(e) = CloseWindow(self.current.hwnd) { println!("Failed to close window {}", e); @@ -116,10 +124,8 @@ impl WindowManager { } if let Some(window) = &self.next { self.current = window.to_owned(); - self.clear_windows(); self.set_windows(); } - self.print_windows(); } #[allow(dead_code)] @@ -165,6 +171,7 @@ impl WindowManager { } pub fn set_windows(&mut self) { + println!(""); unsafe { let _ = EnumWindows( Some(enum_windows_proc), @@ -227,6 +234,7 @@ impl WindowManager { } self.current = window; }; + self.set_windows(); } }