Skip to content

Commit

Permalink
cleanup: remove last traces of refcell'ed winit window
Browse files Browse the repository at this point in the history
  • Loading branch information
tronical committed Dec 2, 2022
1 parent b24e403 commit b08d1ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/backends/winit/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub trait WinitWindow: WindowAdapter {
fn currently_pressed_key_code(&self) -> &Cell<Option<winit::event::VirtualKeyCode>>;
/// Returns true if during the drawing request_redraw() was called.
fn draw(&self) -> bool;
fn with_window_handle(&self, callback: &mut dyn FnMut(&winit::window::Window));
fn winit_window(&self) -> Option<&winit::window::Window>;
fn constraints(&self) -> (corelib::layout::LayoutInfo, corelib::layout::LayoutInfo);
fn set_constraints(
&self,
Expand Down
34 changes: 17 additions & 17 deletions internal/backends/winit/glwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,8 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WinitWindow for GLWindow<Rende
self.pending_redraw.get()
}

fn with_window_handle(&self, callback: &mut dyn FnMut(&winit::window::Window)) {
if let Some(mapped_window) = self.borrow_mapped_window() {
callback(mapped_window.canvas.window());
}
fn winit_window(&self) -> Option<&winit::window::Window> {
self.borrow_mapped_window().map(|mapped_window| mapped_window.canvas.window())
}

fn constraints(&self) -> (corelib::layout::LayoutInfo, corelib::layout::LayoutInfo) {
Expand Down Expand Up @@ -238,7 +236,9 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapter for GLWindow<Ren
impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWindow<Renderer> {
fn request_redraw(&self) {
self.pending_redraw.set(true);
self.with_window_handle(&mut |window| window.request_redraw())
if let Some(winit_window) = self.winit_window() {
winit_window.request_redraw();
}
}

fn unregister_component<'a>(
Expand All @@ -264,15 +264,15 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWind

fn request_window_properties_update(&self) {
self.call_with_event_loop(|self_| {
self_.with_window_handle(&mut |window| {
if let Some(window) = self_.winit_window() {
let window_id = window.id();
crate::event_loop::with_window_target(|event_loop| {
event_loop.event_loop_proxy().send_event(
crate::event_loop::CustomEvent::UpdateWindowProperties(window_id),
)
})
.ok();
})
}
});
}

Expand All @@ -287,7 +287,7 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWind

let mut must_resize = false;

self.with_window_handle(&mut |winit_window| {
if let Some(winit_window) = self.winit_window() {
winit_window.set_window_icon(icon_to_winit(window_item.icon()));
winit_window.set_title(&window_item.title());
winit_window
Expand Down Expand Up @@ -320,7 +320,7 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWind
winit_window.set_inner_size(winit::dpi::LogicalSize::new(width, height));
}
}
});
};

if must_resize {
let win = self.window();
Expand All @@ -334,7 +334,7 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWind
constraints_horizontal: corelib::layout::LayoutInfo,
constraints_vertical: corelib::layout::LayoutInfo,
) {
self.with_window_handle(&mut |winit_window| {
if let Some(winit_window) = self.winit_window() {
// If we're in fullscreen state, don't try to resize the window but maintain the surface
// size we've been assigned to from the windowing system. Weston/Wayland don't like it
// when we create a surface that's bigger than the screen due to constraints (#532).
Expand Down Expand Up @@ -385,7 +385,7 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWind
}
}
}
});
};
}

fn show(&self) {
Expand Down Expand Up @@ -566,10 +566,10 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWind
MouseCursor::NeswResize => winit::window::CursorIcon::NeswResize,
MouseCursor::NwseResize => winit::window::CursorIcon::NwseResize,
};
self.with_window_handle(&mut |winit_window| {
if let Some(winit_window) = self.winit_window() {
winit_window.set_cursor_visible(cursor != MouseCursor::None);
winit_window.set_cursor_icon(winit_cursor);
});
};
}

fn renderer(&self) -> &dyn i_slint_core::renderer::Renderer {
Expand All @@ -588,7 +588,7 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWind
h.show();
}
#[cfg(not(target_arch = "wasm32"))]
self.with_window_handle(&mut |winit_window| {
self.winit_window().map(|winit_window| {
winit_window.set_ime_allowed(matches!(_it, corelib::items::InputType::Text))
});
}
Expand All @@ -599,13 +599,13 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWind
h.hide()
}
#[cfg(not(target_arch = "wasm32"))]
self.with_window_handle(&mut |winit_window| winit_window.set_ime_allowed(false));
self.winit_window().map(|winit_window| winit_window.set_ime_allowed(false));
}

fn set_ime_position(&self, ime_pos: LogicalPoint) {
self.with_window_handle(&mut |winit_window| {
if let Some(winit_window) = self.winit_window() {
winit_window.set_ime_position(winit::dpi::LogicalPosition::new(ime_pos.x, ime_pos.y))
})
}
}

fn as_any(&self) -> &dyn std::any::Any {
Expand Down

0 comments on commit b08d1ee

Please sign in to comment.