Invert slint:🪟:WindowInner and PlatformWindow ownership

Previously: Window is an Rc<WindowInner>, which has an Rc<dyn
PLatformWindow> - and weak references the other way around.

Now: Rc<dyn PlatformWindow> is the root of window ownership. The impl
PlatformWindow has a slint::api::Window, which just holds a WindowInner.

This change is incomplete on a few levels, mainly that neither of the
code generators nor the interpreter is ported.
This commit is contained in:
Simon Hausmann 2022-08-18 11:38:30 +02:00 committed by Simon Hausmann
parent f88b688fbf
commit af86f36157
32 changed files with 494 additions and 533 deletions

View file

@ -135,7 +135,7 @@ fn gen_corelib(
config.export.include = [
"ComponentVTable",
"Slice",
"WindowRcOpaque",
"PlatformWindowRcOpaque",
"PropertyAnimation",
"EasingCurve",
"TextHorizontalAlignment",

View file

@ -86,7 +86,9 @@ inline void assert_main_thread()
class WindowRc
{
public:
explicit WindowRc(cbindgen_private::WindowRcOpaque adopted_inner) : inner(adopted_inner) { }
explicit WindowRc(cbindgen_private::PlatformWindowRcOpaque adopted_inner) : inner(adopted_inner)
{
}
WindowRc() { cbindgen_private::slint_windowrc_init(&inner); }
~WindowRc() { cbindgen_private::slint_windowrc_drop(&inner); }
WindowRc(const WindowRc &other)
@ -223,7 +225,7 @@ public:
}
private:
cbindgen_private::WindowRcOpaque inner;
cbindgen_private::PlatformWindowRcOpaque inner;
};
constexpr inline ItemTreeNode make_item_node(uint32_t child_count, uint32_t child_index,

View file

@ -564,7 +564,7 @@ public:
/// such as the position on the screen.
const slint::Window &window()
{
const cbindgen_private::WindowRcOpaque *win_ptr = nullptr;
const cbindgen_private::PlatformWindowRcOpaque *win_ptr = nullptr;
cbindgen_private::slint_interpreter_component_instance_window(inner(), &win_ptr);
return *reinterpret_cast<const slint::Window *>(win_ptr);
}
@ -582,7 +582,7 @@ public:
/// it may return nullptr if the Qt backend is not used at runtime.
QWidget *qwidget() const
{
const cbindgen_private::WindowRcOpaque *win_ptr = nullptr;
const cbindgen_private::PlatformWindowRcOpaque *win_ptr = nullptr;
cbindgen_private::slint_interpreter_component_instance_window(inner(), &win_ptr);
auto wid = reinterpret_cast<QWidget *>(cbindgen_private::slint_qt_get_widget(
reinterpret_cast<const cbindgen_private::WindowRc *>(win_ptr)));
@ -1010,7 +1010,7 @@ inline void send_keyboard_string_sequence(const slint::interpreter::ComponentIns
const slint::SharedString &str,
KeyboardModifiers modifiers = {})
{
const cbindgen_private::WindowRcOpaque *win_ptr = nullptr;
const cbindgen_private::PlatformWindowRcOpaque *win_ptr = nullptr;
cbindgen_private::slint_interpreter_component_instance_window(
reinterpret_cast<const cbindgen_private::ErasedComponentBox *>(component), &win_ptr);
cbindgen_private::send_keyboard_string_sequence(

View file

@ -5,8 +5,7 @@
use core::ffi::c_void;
use i_slint_backend_selector::backend;
use i_slint_core::api::Window;
use i_slint_core::window::{ffi::WindowRcOpaque, WindowRc};
use i_slint_core::window::{ffi::PlatformWindowRcOpaque, PlatformWindowRc};
#[doc(hidden)]
#[cold]
@ -18,9 +17,12 @@ pub fn use_modules() -> usize {
}
#[no_mangle]
pub unsafe extern "C" fn slint_windowrc_init(out: *mut WindowRcOpaque) {
assert_eq!(core::mem::size_of::<Window>(), core::mem::size_of::<WindowRcOpaque>());
core::ptr::write(out as *mut Window, crate::backend().create_window());
pub unsafe extern "C" fn slint_windowrc_init(out: *mut PlatformWindowRcOpaque) {
assert_eq!(
core::mem::size_of::<PlatformWindowRc>(),
core::mem::size_of::<PlatformWindowRcOpaque>()
);
core::ptr::write(out as *mut PlatformWindowRc, crate::backend().create_window());
}
#[no_mangle]
@ -63,14 +65,17 @@ pub unsafe extern "C" fn slint_quit_event_loop() {
#[no_mangle]
pub unsafe extern "C" fn slint_register_font_from_path(
win: *const WindowRcOpaque,
win: *const PlatformWindowRcOpaque,
path: &i_slint_core::SharedString,
error_str: *mut i_slint_core::SharedString,
) {
let window = &*(win as *const WindowRc);
let platform_window = &*(win as *const PlatformWindowRc);
core::ptr::write(
error_str,
match window.renderer().register_font_from_path(std::path::Path::new(path.as_str())) {
match platform_window
.renderer()
.register_font_from_path(std::path::Path::new(path.as_str()))
{
Ok(()) => Default::default(),
Err(err) => err.to_string().into(),
},
@ -79,14 +84,14 @@ pub unsafe extern "C" fn slint_register_font_from_path(
#[no_mangle]
pub unsafe extern "C" fn slint_register_font_from_data(
win: *const WindowRcOpaque,
win: *const PlatformWindowRcOpaque,
data: i_slint_core::slice::Slice<'static, u8>,
error_str: *mut i_slint_core::SharedString,
) {
let window = &*(win as *const WindowRc);
let platform_window = &*(win as *const PlatformWindowRc);
core::ptr::write(
error_str,
match window.renderer().register_font_from_memory(data.as_slice()) {
match platform_window.renderer().register_font_from_memory(data.as_slice()) {
Ok(()) => Default::default(),
Err(err) => err.to_string().into(),
},