Compare commits

...
Sign in to create a new pull request.

8 commits

Author SHA1 Message Date
Smit Barmase
dbed047caa
more dbg 2025-07-16 23:31:11 +05:30
Smit Barmase
d7d12b2510
more dbg 2025-07-14 21:22:14 +05:30
Smit Barmase
960395760b
better dbg 2025-07-14 20:56:05 +05:30
Smit Barmase
cda2119ab5
dbg next frame focus 2025-07-14 19:46:13 +05:30
Smit Barmase
7d175936f6
clear focus 2025-07-14 16:34:08 +05:30
Smit Barmase
85119263c5
dbg focus 2025-07-14 16:13:41 +05:30
Smit Barmase
2eedfc62d8
dbg setting focus id 2025-07-14 10:59:06 +05:30
Smit Barmase
281ef340db
dbg! 2025-07-14 10:16:29 +05:30
6 changed files with 38 additions and 4 deletions

View file

@ -949,10 +949,12 @@ impl App {
.write()
.retain(|handle_id, count| {
if count.load(SeqCst) == 0 {
println!("Dropping {handle_id}");
for window_handle in self.windows() {
window_handle
.update(self, |_, window, _| {
if window.focus == Some(handle_id) {
println!("released focus handle blur");
window.blur();
}
})

View file

@ -570,6 +570,7 @@ impl DispatchTree {
}
pub fn focus_path(&self, focus_id: FocusId) -> SmallVec<[FocusId; 8]> {
println!("focus path requested for focus id: {:?}", focus_id);
let mut focus_path: SmallVec<[FocusId; 8]> = SmallVec::new();
let mut current_node_id = self.focusable_node_ids.get(&focus_id).copied();
while let Some(node_id) = current_node_id {

View file

@ -227,7 +227,7 @@ pub(crate) type FocusMap = RwLock<SlotMap<FocusId, AtomicUsize>>;
impl FocusId {
/// Obtains whether the element associated with this handle is currently focused.
pub fn is_focused(&self, window: &Window) -> bool {
window.focus == Some(*self)
dbg!(window.focus) == Some(*self)
}
/// Obtains whether the element associated with this handle contains the focused
@ -705,6 +705,7 @@ impl Frame {
self.window_control_hitboxes.clear();
self.deferred_draws.clear();
self.focus = None;
println!("clearing focus 1");
#[cfg(any(feature = "inspector", debug_assertions))]
{
@ -751,6 +752,8 @@ impl Frame {
}
pub(crate) fn focus_path(&self) -> SmallVec<[FocusId; 8]> {
dbg!("focus path");
dbg!(self.focus.is_some());
self.focus
.map(|focus_id| self.dispatch_tree.focus_path(focus_id))
.unwrap_or_default()
@ -1264,10 +1267,16 @@ impl Window {
/// Move focus to the element associated with the given [`FocusHandle`].
pub fn focus(&mut self, handle: &FocusHandle) {
println!(
"Setting focus to {:?} on platform {:?}",
handle.id,
std::env::consts::OS
);
if !self.focus_enabled || self.focus == Some(handle.id) {
return;
}
println!("actually setting focus");
self.focus = Some(handle.id);
self.clear_pending_keystrokes();
self.refresh();
@ -1280,11 +1289,13 @@ impl Window {
}
self.focus = None;
println!("clearing focus 2");
self.refresh();
}
/// Blur the window and don't allow anything in it to be focused again.
pub fn disable_focus(&mut self) {
println!("disable_focus");
self.blur();
self.focus_enabled = false;
}
@ -1333,12 +1344,13 @@ impl Window {
/// Dispatch the given action on the currently focused element.
pub fn dispatch_action(&mut self, action: Box<dyn Action>, cx: &mut App) {
let focus_id = self.focused(cx).map(|handle| handle.id);
dbg!(&focus_id);
let window = self.handle;
cx.defer(move |cx| {
window
.update(cx, |_, window, cx| {
let node_id = window.focus_node_id_in_rendered_frame(focus_id);
dbg!(&node_id);
window.dispatch_action_on_node(node_id, action.as_ref(), cx);
})
.log_err();
@ -1797,8 +1809,16 @@ impl Window {
self.invalidator.set_phase(DrawPhase::Focus);
let previous_focus_path = self.rendered_frame.focus_path();
let previous_window_active = self.rendered_frame.window_active;
println!(
"dbg! Window::draw - pre-swap: rendered_frame.focus = {:?}, next_frame.focus = {:?}",
self.rendered_frame.focus, self.next_frame.focus
);
mem::swap(&mut self.rendered_frame, &mut self.next_frame);
self.next_frame.clear();
println!(
"dbg! Window::draw - post-swap: rendered_frame.focus = {:?}, next_frame.focus = {:?}",
self.rendered_frame.focus, self.next_frame.focus
);
let current_focus_path = self.rendered_frame.focus_path();
let current_window_active = self.rendered_frame.window_active;
@ -2115,6 +2135,7 @@ impl Window {
);
if reused_subtree.contains_focus() {
println!("setting focus for next frame");
self.next_frame.focus = self.focus;
}
@ -3113,7 +3134,9 @@ impl Window {
/// This method should only be called as part of the prepaint phase of element drawing.
pub fn set_focus_handle(&mut self, focus_handle: &FocusHandle, _: &App) {
self.invalidator.debug_assert_prepaint();
println!("set_focus_handle called");
if focus_handle.is_focused(self) {
println!("setting focus for next frame");
self.next_frame.focus = Some(focus_handle.id);
}
self.next_frame.dispatch_tree.set_focus_id(focus_handle.id);
@ -3757,7 +3780,10 @@ impl Window {
.dispatch_tree
.focusable_node_id(focus_id)
})
.unwrap_or_else(|| self.rendered_frame.dispatch_tree.root_node_id())
.unwrap_or_else(|| {
println!("root node id");
self.rendered_frame.dispatch_tree.root_node_id()
})
}
fn dispatch_action_on_node(

View file

@ -288,6 +288,7 @@ pub fn init(cx: &mut App) {
cx.observe_new(|workspace: &mut Workspace, _, _| {
workspace.register_action(|workspace, _: &ToggleFocus, window, cx| {
println!("this must run");
workspace.toggle_panel_focus::<ProjectPanel>(window, cx);
});

View file

@ -909,6 +909,7 @@ impl Render for PanelButtons {
.on_click({
let action = action.boxed_clone();
move |_, window, cx| {
println!("panel button click");
window.dispatch_action(action.boxed_clone(), cx)
}
})

View file

@ -1219,6 +1219,7 @@ impl Workspace {
.detach();
cx.on_focus_lost(window, |this, window, cx| {
println!("workspace on_focus_lost");
let focus_handle = this.focus_handle(cx);
window.focus(&focus_handle);
})
@ -1245,6 +1246,8 @@ impl Workspace {
window.focus(&center_pane.focus_handle(cx));
// center_pane.focus_handle(cx).is_focused(window);
cx.emit(Event::PaneAdded(center_pane.clone()));
let window_handle = window.window_handle().downcast::<Workspace>().unwrap();