Windows: fix initial active status (#9694)

Separate from #9451

On Windows, a new window may already active immediate after creation.

Release Notes:

- N/A

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
白山風露 2024-03-26 03:44:18 +09:00 committed by GitHub
parent 78dc458231
commit 6231df978b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 24 additions and 1 deletions

View File

@ -188,6 +188,7 @@ pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle {
answers: &[&str],
) -> Option<oneshot::Receiver<usize>>;
fn activate(&self);
fn is_active(&self) -> bool;
fn set_title(&mut self, title: &str);
fn set_edited(&mut self, edited: bool);
fn show_character_palette(&self);

View File

@ -346,6 +346,11 @@ impl PlatformWindow for WaylandWindow {
// todo(linux)
}
// todo(linux)
fn is_active(&self) -> bool {
false
}
fn set_title(&mut self, title: &str) {
self.0.toplevel.set_title(title.to_string());
}

View File

@ -406,6 +406,11 @@ impl PlatformWindow for X11Window {
.unwrap();
}
// todo(linux)
fn is_active(&self) -> bool {
false
}
fn set_title(&mut self, title: &str) {
self.0
.xcb_connection

View File

@ -916,6 +916,10 @@ impl PlatformWindow for MacWindow {
.detach();
}
fn is_active(&self) -> bool {
unsafe { self.0.lock().native_window.isKeyWindow() == YES }
}
fn set_title(&mut self, title: &str) {
unsafe {
let app = NSApplication::sharedApplication(nil);

View File

@ -181,6 +181,10 @@ impl PlatformWindow for TestWindow {
.set_active_window(Some(self.clone()))
}
fn is_active(&self) -> bool {
false
}
fn set_title(&mut self, title: &str) {
self.0.lock().title = Some(title.to_owned());
}

View File

@ -1389,6 +1389,10 @@ impl PlatformWindow for WindowsWindow {
unsafe { SetForegroundWindow(self.inner.hwnd) };
}
fn is_active(&self) -> bool {
self.inner.hwnd == unsafe { GetActiveWindow() }
}
// todo(windows)
fn set_title(&mut self, title: &str) {
unsafe { SetWindowTextW(self.inner.hwnd, &HSTRING::from(title)) }

View File

@ -421,7 +421,7 @@ impl Window {
let appearance = platform_window.appearance();
let text_system = Arc::new(WindowTextSystem::new(cx.text_system().clone()));
let dirty = Rc::new(Cell::new(true));
let active = Rc::new(Cell::new(false));
let active = Rc::new(Cell::new(platform_window.is_active()));
let needs_present = Rc::new(Cell::new(false));
let next_frame_callbacks: Rc<RefCell<Vec<FrameCallback>>> = Default::default();
let last_input_timestamp = Rc::new(Cell::new(Instant::now()));