mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-27 12:54:42 +00:00
Minimize window id usage
This commit is contained in:
parent
afd89b256a
commit
8e49d1419a
4 changed files with 38 additions and 37 deletions
|
@ -477,10 +477,10 @@ pub struct AppContext {
|
|||
focus_observations: CallbackCollection<usize, FocusObservationCallback>,
|
||||
release_observations: CallbackCollection<usize, ReleaseObservationCallback>,
|
||||
action_dispatch_observations: CallbackCollection<(), ActionObservationCallback>,
|
||||
window_activation_observations: CallbackCollection<usize, WindowActivationCallback>,
|
||||
window_fullscreen_observations: CallbackCollection<usize, WindowFullscreenCallback>,
|
||||
window_bounds_observations: CallbackCollection<usize, WindowBoundsCallback>,
|
||||
keystroke_observations: CallbackCollection<usize, KeystrokeCallback>,
|
||||
window_activation_observations: CallbackCollection<AnyWindowHandle, WindowActivationCallback>,
|
||||
window_fullscreen_observations: CallbackCollection<AnyWindowHandle, WindowFullscreenCallback>,
|
||||
window_bounds_observations: CallbackCollection<AnyWindowHandle, WindowBoundsCallback>,
|
||||
keystroke_observations: CallbackCollection<AnyWindowHandle, KeystrokeCallback>,
|
||||
active_labeled_task_observations: CallbackCollection<(), ActiveLabeledTasksCallback>,
|
||||
|
||||
foreground: Rc<executor::Foreground>,
|
||||
|
@ -1460,7 +1460,7 @@ impl AppContext {
|
|||
|
||||
let mut refreshing = false;
|
||||
let mut updated_windows = HashSet::default();
|
||||
let mut focus_effects = HashMap::<usize, FocusEffect>::default();
|
||||
let mut focus_effects = HashMap::<AnyWindowHandle, FocusEffect>::default();
|
||||
loop {
|
||||
self.remove_dropped_entities();
|
||||
if let Some(effect) = self.pending_effects.pop_front() {
|
||||
|
@ -1538,13 +1538,13 @@ impl AppContext {
|
|||
|
||||
Effect::Focus(mut effect) => {
|
||||
if focus_effects
|
||||
.get(&effect.window().id())
|
||||
.get(&effect.window())
|
||||
.map_or(false, |prev_effect| prev_effect.is_forced())
|
||||
{
|
||||
effect.force();
|
||||
}
|
||||
|
||||
focus_effects.insert(effect.window().id(), effect);
|
||||
focus_effects.insert(effect.window(), effect);
|
||||
}
|
||||
|
||||
Effect::FocusObservation {
|
||||
|
@ -1577,7 +1577,7 @@ impl AppContext {
|
|||
subscription_id,
|
||||
callback,
|
||||
} => self.window_activation_observations.add_callback(
|
||||
window.id(),
|
||||
window,
|
||||
subscription_id,
|
||||
callback,
|
||||
),
|
||||
|
@ -1586,7 +1586,7 @@ impl AppContext {
|
|||
if self.handle_window_activation_effect(window, is_active) && is_active
|
||||
{
|
||||
focus_effects
|
||||
.entry(window.id())
|
||||
.entry(window)
|
||||
.or_insert_with(|| FocusEffect::View {
|
||||
window,
|
||||
view_id: self
|
||||
|
@ -1603,7 +1603,7 @@ impl AppContext {
|
|||
subscription_id,
|
||||
callback,
|
||||
} => self.window_fullscreen_observations.add_callback(
|
||||
window.id(),
|
||||
window,
|
||||
subscription_id,
|
||||
callback,
|
||||
),
|
||||
|
@ -1618,7 +1618,7 @@ impl AppContext {
|
|||
subscription_id,
|
||||
callback,
|
||||
} => self.window_bounds_observations.add_callback(
|
||||
window.id(),
|
||||
window,
|
||||
subscription_id,
|
||||
callback,
|
||||
),
|
||||
|
@ -1718,10 +1718,10 @@ impl AppContext {
|
|||
let root_view_id = cx.window.root_view().id();
|
||||
if focused_view_id != root_view_id
|
||||
&& !cx.views.contains_key(&(window, focused_view_id))
|
||||
&& !focus_effects.contains_key(&window.id())
|
||||
&& !focus_effects.contains_key(&window)
|
||||
{
|
||||
focus_effects.insert(
|
||||
window.id(),
|
||||
window,
|
||||
FocusEffect::View {
|
||||
window,
|
||||
view_id: Some(root_view_id),
|
||||
|
@ -1860,12 +1860,12 @@ impl AppContext {
|
|||
cx.window.is_fullscreen = is_fullscreen;
|
||||
|
||||
let mut fullscreen_observations = cx.window_fullscreen_observations.clone();
|
||||
fullscreen_observations.emit(window.id(), |callback| callback(is_fullscreen, cx));
|
||||
fullscreen_observations.emit(window, |callback| callback(is_fullscreen, cx));
|
||||
|
||||
if let Some(uuid) = cx.window_display_uuid() {
|
||||
let bounds = cx.window_bounds();
|
||||
let mut bounds_observations = cx.window_bounds_observations.clone();
|
||||
bounds_observations.emit(window.id(), |callback| callback(bounds, uuid, cx));
|
||||
bounds_observations.emit(window, |callback| callback(bounds, uuid, cx));
|
||||
}
|
||||
|
||||
Some(())
|
||||
|
@ -1881,7 +1881,7 @@ impl AppContext {
|
|||
) {
|
||||
self.update_window(window, |cx| {
|
||||
let mut observations = cx.keystroke_observations.clone();
|
||||
observations.emit(window.id(), move |callback| {
|
||||
observations.emit(window, move |callback| {
|
||||
callback(&keystroke, &result, handled_by.as_ref(), cx)
|
||||
});
|
||||
});
|
||||
|
@ -1895,7 +1895,7 @@ impl AppContext {
|
|||
cx.window.is_active = active;
|
||||
|
||||
let mut observations = cx.window_activation_observations.clone();
|
||||
observations.emit(window.id(), |callback| callback(active, cx));
|
||||
observations.emit(window, |callback| callback(active, cx));
|
||||
true
|
||||
})
|
||||
.unwrap_or(false)
|
||||
|
@ -1989,7 +1989,7 @@ impl AppContext {
|
|||
let bounds = cx.window_bounds();
|
||||
cx.window_bounds_observations
|
||||
.clone()
|
||||
.emit(window.id(), move |callback| {
|
||||
.emit(window, move |callback| {
|
||||
callback(bounds, display, cx);
|
||||
true
|
||||
});
|
||||
|
@ -4038,12 +4038,12 @@ impl AnyWindowHandle {
|
|||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn simulate_activation(&self, cx: &mut TestAppContext) {
|
||||
self.update(cx, |cx| {
|
||||
let other_window_ids = cx
|
||||
let other_windows = cx
|
||||
.windows()
|
||||
.filter(|window| *window != *self)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for window in other_window_ids {
|
||||
for window in other_windows {
|
||||
cx.window_changed_active_status(window, false)
|
||||
}
|
||||
|
||||
|
@ -4243,10 +4243,6 @@ impl AnyViewHandle {
|
|||
self.window
|
||||
}
|
||||
|
||||
pub fn window_id(&self) -> usize {
|
||||
self.window.id()
|
||||
}
|
||||
|
||||
pub fn id(&self) -> usize {
|
||||
self.view_id
|
||||
}
|
||||
|
@ -4660,10 +4656,16 @@ pub enum Subscription {
|
|||
GlobalSubscription(callback_collection::Subscription<TypeId, GlobalSubscriptionCallback>),
|
||||
GlobalObservation(callback_collection::Subscription<TypeId, GlobalObservationCallback>),
|
||||
FocusObservation(callback_collection::Subscription<usize, FocusObservationCallback>),
|
||||
WindowActivationObservation(callback_collection::Subscription<usize, WindowActivationCallback>),
|
||||
WindowFullscreenObservation(callback_collection::Subscription<usize, WindowFullscreenCallback>),
|
||||
WindowBoundsObservation(callback_collection::Subscription<usize, WindowBoundsCallback>),
|
||||
KeystrokeObservation(callback_collection::Subscription<usize, KeystrokeCallback>),
|
||||
WindowActivationObservation(
|
||||
callback_collection::Subscription<AnyWindowHandle, WindowActivationCallback>,
|
||||
),
|
||||
WindowFullscreenObservation(
|
||||
callback_collection::Subscription<AnyWindowHandle, WindowFullscreenCallback>,
|
||||
),
|
||||
WindowBoundsObservation(
|
||||
callback_collection::Subscription<AnyWindowHandle, WindowBoundsCallback>,
|
||||
),
|
||||
KeystrokeObservation(callback_collection::Subscription<AnyWindowHandle, KeystrokeCallback>),
|
||||
ReleaseObservation(callback_collection::Subscription<usize, ReleaseObservationCallback>),
|
||||
ActionObservation(callback_collection::Subscription<(), ActionObservationCallback>),
|
||||
ActiveLabeledTasksObservation(
|
||||
|
|
|
@ -326,7 +326,7 @@ impl<'a> WindowContext<'a> {
|
|||
});
|
||||
Subscription::WindowActivationObservation(
|
||||
self.window_activation_observations
|
||||
.subscribe(handle.id(), subscription_id),
|
||||
.subscribe(handle, subscription_id),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -344,7 +344,7 @@ impl<'a> WindowContext<'a> {
|
|||
});
|
||||
Subscription::WindowActivationObservation(
|
||||
self.window_activation_observations
|
||||
.subscribe(window.id(), subscription_id),
|
||||
.subscribe(window, subscription_id),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ impl<'a> WindowContext<'a> {
|
|||
});
|
||||
Subscription::WindowBoundsObservation(
|
||||
self.window_bounds_observations
|
||||
.subscribe(window.id(), subscription_id),
|
||||
.subscribe(window, subscription_id),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -374,10 +374,10 @@ impl<'a> WindowContext<'a> {
|
|||
let window = self.window_handle;
|
||||
let subscription_id = post_inc(&mut self.next_subscription_id);
|
||||
self.keystroke_observations
|
||||
.add_callback(window.id(), subscription_id, Box::new(callback));
|
||||
.add_callback(window, subscription_id, Box::new(callback));
|
||||
Subscription::KeystrokeObservation(
|
||||
self.keystroke_observations
|
||||
.subscribe(window.id(), subscription_id),
|
||||
.subscribe(window, subscription_id),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -882,7 +882,7 @@ impl platform::Window for Window {
|
|||
|
||||
fn is_topmost_for_position(&self, position: Vector2F) -> bool {
|
||||
let self_borrow = self.0.borrow();
|
||||
let self_id = self_borrow.handle;
|
||||
let self_handle = self_borrow.handle;
|
||||
|
||||
unsafe {
|
||||
let app = NSApplication::sharedApplication(nil);
|
||||
|
@ -899,8 +899,8 @@ impl platform::Window for Window {
|
|||
let is_panel: BOOL = msg_send![top_most_window, isKindOfClass: PANEL_CLASS];
|
||||
let is_window: BOOL = msg_send![top_most_window, isKindOfClass: WINDOW_CLASS];
|
||||
if is_panel == YES || is_window == YES {
|
||||
let topmost_window_id = get_window_state(&*top_most_window).borrow().handle;
|
||||
topmost_window_id == self_id
|
||||
let topmost_window = get_window_state(&*top_most_window).borrow().handle;
|
||||
topmost_window == self_handle
|
||||
} else {
|
||||
// Someone else's window is on top
|
||||
false
|
||||
|
|
|
@ -192,7 +192,6 @@ where
|
|||
F: FnOnce(&mut gpui::ViewContext<V>) -> D,
|
||||
{
|
||||
const TITLEBAR_HEIGHT: f32 = 28.;
|
||||
// let active = cx.window_is_active(cx.window_id());
|
||||
|
||||
Flex::column()
|
||||
.with_child(
|
||||
|
|
Loading…
Reference in a new issue