mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
gpui: Fix hide
, activate
method on Windows to hide/show application (#18164)
Release Notes: - N/A Continue #18161 to fix `cx.hide`, `cx.activate` method on Windows to hide/show application. ## After https://github.com/user-attachments/assets/fe0070f9-7844-4c2a-b859-3e22ee4b8d22 --------- Co-authored-by: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
parent
8d795ff882
commit
72be8c5d14
2 changed files with 32 additions and 4 deletions
|
@ -150,6 +150,18 @@ impl Render for WindowDemo {
|
|||
)
|
||||
.unwrap();
|
||||
}))
|
||||
.child(button("Hide Application", |cx| {
|
||||
cx.hide();
|
||||
|
||||
// Restore the application after 3 seconds
|
||||
cx.spawn(|mut cx| async move {
|
||||
Timer::after(std::time::Duration::from_secs(3)).await;
|
||||
cx.update(|cx| {
|
||||
cx.activate(false);
|
||||
})
|
||||
})
|
||||
.detach();
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ use crate::*;
|
|||
pub(crate) struct WindowsPlatform {
|
||||
state: RefCell<WindowsPlatformState>,
|
||||
raw_window_handles: RwLock<SmallVec<[HWND; 4]>>,
|
||||
// The window handles that are hided by `hide` method.
|
||||
hidden_windows: RwLock<SmallVec<[HWND; 4]>>,
|
||||
// The below members will never change throughout the entire lifecycle of the app.
|
||||
icon: HICON,
|
||||
main_receiver: flume::Receiver<Runnable>,
|
||||
|
@ -100,6 +102,7 @@ impl WindowsPlatform {
|
|||
Self {
|
||||
state,
|
||||
raw_window_handles,
|
||||
hidden_windows: RwLock::new(SmallVec::new()),
|
||||
icon,
|
||||
main_receiver,
|
||||
dispatch_event,
|
||||
|
@ -295,12 +298,25 @@ impl Platform for WindowsPlatform {
|
|||
}
|
||||
}
|
||||
|
||||
// todo(windows)
|
||||
fn activate(&self, _ignoring_other_apps: bool) {}
|
||||
fn activate(&self, _ignoring_other_apps: bool) {
|
||||
let mut state = self.hidden_windows.write();
|
||||
state.iter().for_each(|handle| unsafe {
|
||||
ShowWindow(*handle, SW_SHOW).ok().log_err();
|
||||
});
|
||||
state.clear();
|
||||
}
|
||||
|
||||
// todo(windows)
|
||||
fn hide(&self) {
|
||||
unimplemented!()
|
||||
let mut state = self.hidden_windows.write();
|
||||
self.raw_window_handles
|
||||
.read()
|
||||
.iter()
|
||||
.for_each(|handle| unsafe {
|
||||
if IsWindowVisible(*handle).as_bool() {
|
||||
state.push(*handle);
|
||||
ShowWindow(*handle, SW_HIDE).ok().log_err();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// todo(windows)
|
||||
|
|
Loading…
Reference in a new issue