mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-24 17:48:34 +02:00
feat(wm): allow valid attach_thread_input failures
This commit allows the Window.focus() fn to continue execution if AttachThreadInput fails, as there are valid situations in which this might fail, but the focusing of the window may/should still succeed. fix #156
This commit is contained in:
@@ -199,7 +199,19 @@ impl Window {
|
|||||||
// Attach komorebi thread to Window thread
|
// Attach komorebi thread to Window thread
|
||||||
let (_, window_thread_id) = WindowsApi::window_thread_process_id(self.hwnd());
|
let (_, window_thread_id) = WindowsApi::window_thread_process_id(self.hwnd());
|
||||||
let current_thread_id = WindowsApi::current_thread_id();
|
let current_thread_id = WindowsApi::current_thread_id();
|
||||||
WindowsApi::attach_thread_input(current_thread_id, window_thread_id, true)?;
|
|
||||||
|
// This can be allowed to fail if a window doesn't have a message queue or if a journal record
|
||||||
|
// hook has been installed
|
||||||
|
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-attachthreadinput#remarks
|
||||||
|
match WindowsApi::attach_thread_input(current_thread_id, window_thread_id, true) {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(error) => {
|
||||||
|
tracing::error!(
|
||||||
|
"could not attach to window thread input processing mechanism, but continuing execution of focus(): {}",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Raise Window to foreground
|
// Raise Window to foreground
|
||||||
match WindowsApi::set_foreground_window(self.hwnd()) {
|
match WindowsApi::set_foreground_window(self.hwnd()) {
|
||||||
|
|||||||
@@ -28,56 +28,56 @@ pub enum WindowManagerEvent {
|
|||||||
impl Display for WindowManagerEvent {
|
impl Display for WindowManagerEvent {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
WindowManagerEvent::Manage(window) => {
|
Self::Manage(window) => {
|
||||||
write!(f, "Manage (Window: {})", window)
|
write!(f, "Manage (Window: {})", window)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::Unmanage(window) => {
|
Self::Unmanage(window) => {
|
||||||
write!(f, "Unmanage (Window: {})", window)
|
write!(f, "Unmanage (Window: {})", window)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::Destroy(winevent, window) => {
|
Self::Destroy(winevent, window) => {
|
||||||
write!(f, "Destroy (WinEvent: {}, Window: {})", winevent, window)
|
write!(f, "Destroy (WinEvent: {}, Window: {})", winevent, window)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::FocusChange(winevent, window) => {
|
Self::FocusChange(winevent, window) => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"FocusChange (WinEvent: {}, Window: {})",
|
"FocusChange (WinEvent: {}, Window: {})",
|
||||||
winevent, window
|
winevent, window
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::Hide(winevent, window) => {
|
Self::Hide(winevent, window) => {
|
||||||
write!(f, "Hide (WinEvent: {}, Window: {})", winevent, window)
|
write!(f, "Hide (WinEvent: {}, Window: {})", winevent, window)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::Minimize(winevent, window) => {
|
Self::Minimize(winevent, window) => {
|
||||||
write!(f, "Minimize (WinEvent: {}, Window: {})", winevent, window)
|
write!(f, "Minimize (WinEvent: {}, Window: {})", winevent, window)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::Show(winevent, window) => {
|
Self::Show(winevent, window) => {
|
||||||
write!(f, "Show (WinEvent: {}, Window: {})", winevent, window)
|
write!(f, "Show (WinEvent: {}, Window: {})", winevent, window)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::MoveResizeStart(winevent, window) => {
|
Self::MoveResizeStart(winevent, window) => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"MoveResizeStart (WinEvent: {}, Window: {})",
|
"MoveResizeStart (WinEvent: {}, Window: {})",
|
||||||
winevent, window
|
winevent, window
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::MoveResizeEnd(winevent, window) => {
|
Self::MoveResizeEnd(winevent, window) => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"MoveResizeEnd (WinEvent: {}, Window: {})",
|
"MoveResizeEnd (WinEvent: {}, Window: {})",
|
||||||
winevent, window
|
winevent, window
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::MouseCapture(winevent, window) => {
|
Self::MouseCapture(winevent, window) => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"MouseCapture (WinEvent: {}, Window: {})",
|
"MouseCapture (WinEvent: {}, Window: {})",
|
||||||
winevent, window
|
winevent, window
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::Raise(window) => {
|
Self::Raise(window) => {
|
||||||
write!(f, "Raise (Window: {})", window)
|
write!(f, "Raise (Window: {})", window)
|
||||||
}
|
}
|
||||||
WindowManagerEvent::MonitorPoll(winevent, window) => {
|
Self::MonitorPoll(winevent, window) => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"MonitorPoll (WinEvent: {}, Window: {})",
|
"MonitorPoll (WinEvent: {}, Window: {})",
|
||||||
@@ -91,18 +91,18 @@ impl Display for WindowManagerEvent {
|
|||||||
impl WindowManagerEvent {
|
impl WindowManagerEvent {
|
||||||
pub const fn window(self) -> Window {
|
pub const fn window(self) -> Window {
|
||||||
match self {
|
match self {
|
||||||
WindowManagerEvent::Destroy(_, window)
|
Self::Destroy(_, window)
|
||||||
| WindowManagerEvent::FocusChange(_, window)
|
| Self::FocusChange(_, window)
|
||||||
| WindowManagerEvent::Hide(_, window)
|
| Self::Hide(_, window)
|
||||||
| WindowManagerEvent::Minimize(_, window)
|
| Self::Minimize(_, window)
|
||||||
| WindowManagerEvent::Show(_, window)
|
| Self::Show(_, window)
|
||||||
| WindowManagerEvent::MoveResizeStart(_, window)
|
| Self::MoveResizeStart(_, window)
|
||||||
| WindowManagerEvent::MoveResizeEnd(_, window)
|
| Self::MoveResizeEnd(_, window)
|
||||||
| WindowManagerEvent::MouseCapture(_, window)
|
| Self::MouseCapture(_, window)
|
||||||
| WindowManagerEvent::MonitorPoll(_, window)
|
| Self::MonitorPoll(_, window)
|
||||||
| WindowManagerEvent::Raise(window)
|
| Self::Raise(window)
|
||||||
| WindowManagerEvent::Manage(window)
|
| Self::Manage(window)
|
||||||
| WindowManagerEvent::Unmanage(window) => window,
|
| Self::Unmanage(window) => window,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -680,7 +680,7 @@ pub fn send_message(bytes: &[u8]) -> Result<()> {
|
|||||||
let socket = socket.as_path();
|
let socket = socket.as_path();
|
||||||
|
|
||||||
let mut stream = UnixStream::connect(&socket)?;
|
let mut stream = UnixStream::connect(&socket)?;
|
||||||
Ok(stream.write_all(&*bytes)?)
|
Ok(stream.write_all(bytes)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
@@ -720,8 +720,9 @@ fn main() -> Result<()> {
|
|||||||
color_log.push("komorebi.log");
|
color_log.push("komorebi.log");
|
||||||
let file = TailedFile::new(File::open(color_log)?);
|
let file = TailedFile::new(File::open(color_log)?);
|
||||||
let locked = file.lock();
|
let locked = file.lock();
|
||||||
for line in locked.lines() {
|
#[allow(clippy::significant_drop_in_scrutinee)]
|
||||||
println!("{}", line?);
|
for line in locked.lines().flatten() {
|
||||||
|
println!("{}", line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SubCommand::Focus(arg) => {
|
SubCommand::Focus(arg) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user