diff --git a/azul-desktop/src/shell/appkit/mod.rs b/azul-desktop/src/shell/appkit/mod.rs index caab2b09..85402ee3 100644 --- a/azul-desktop/src/shell/appkit/mod.rs +++ b/azul-desktop/src/shell/appkit/mod.rs @@ -915,7 +915,6 @@ fn window_will_close(ptr: Arc>, window_id: WindowId, mtm: MainThr } } - extern "C" fn window_did_resize( ptr: Arc>, window_id: WindowId, @@ -964,7 +963,7 @@ extern "C" fn window_did_resize( ns_window: nswr, }); - crate::shell::event::wm_size( + let r = crate::shell::event::wm_size( window, &mut data.userdata, &guard, @@ -974,9 +973,13 @@ extern "C" fn window_did_resize( WindowFrame::Normal, // Or detect Minimized / Fullscreen if needed ); - Window::finish_gl(guard); + mem::drop(window); + + if let Some(window) = dw.get_mut(&window_id) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + Window::finish_gl(guard); } extern "C" fn window_did_become_key( @@ -1019,11 +1022,24 @@ extern "C" fn window_did_become_key( ns_window: nswr, }); - crate::shell::event::wm_set_focus(window, ud, &guard, &raw); + let r = crate::shell::event::wm_set_focus(window, ud, &guard, &raw); - Window::finish_gl(guard); + mem::drop(window); + + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + window_id, + ud, + &guard, + &raw, + ); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + if let Some(window) = dw.get_mut(&window_id) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } extern "C" fn window_did_resign_key( @@ -1066,11 +1082,24 @@ extern "C" fn window_did_resign_key( ns_window: nswr, }); - crate::shell::event::wm_kill_focus(window, ud, &guard, &raw); + let r = crate::shell::event::wm_kill_focus(window, ud, &guard, &raw); - Window::finish_gl(guard); + mem::drop(window); + + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + window_id, + ud, + &guard, + &raw, + ); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + if let Some(window) = dw.get_mut(&window_id) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } // ADDED: Called when the screen’s backing scale changes => “dpichange” @@ -1114,11 +1143,24 @@ extern "C" fn window_did_change_backing(ptr: Arc>, window_id: Win ns_window: nswr, }); - crate::shell::event::wm_dpichanged(window, ud, &guard, &raw, new_dpi); + let r = crate::shell::event::wm_dpichanged(window, ud, &guard, &raw, new_dpi); - Window::finish_gl(guard); + mem::drop(window); + + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + window_id, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&window_id) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + Window::finish_gl(guard); } // @@ -1130,16 +1172,18 @@ extern "C" fn mouse_down(this: *mut Object, _sel: Sel, event: *mut Object) { let mac_app = &*(*ptr as *const MacApp); let windowid = *(*this).get_ivar::("windowid"); - - // Lock the AppData + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; // Retrieve the Window - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&wid) { Some(s) => s, None => return, }; @@ -1170,12 +1214,24 @@ extern "C" fn mouse_down(this: *mut Object, _sel: Sel, event: *mut Object) { }); // Call your "wm_lbuttondown" event - crate::shell::event::wm_lbuttondown(window, &mut data.userdata, &guard, &raw); + let r = crate::shell::event::wm_lbuttondown(window, ud, &guard, &raw); - Window::finish_gl(guard); + mem::drop(window); - // Restore the NSWindow - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1188,14 +1244,17 @@ extern "C" fn mouse_up(this: *mut Object, _sel: Sel, event: *mut Object) { let mac_app = &*(*ptr as *const MacApp); let windowid = *(*this).get_ivar::("windowid"); - + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&wid) { Some(s) => s, None => return, }; @@ -1221,11 +1280,24 @@ extern "C" fn mouse_up(this: *mut Object, _sel: Sel, event: *mut Object) { ns_window: nswr, }); - crate::shell::event::wm_lbuttonup(window, &mut data.userdata, &guard, &raw, &mut data.active_menus); + let r = crate::shell::event::wm_lbuttonup(window, ud, &guard, &raw, &mut data.active_menus); - Window::finish_gl(guard); + mem::drop(window); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1239,14 +1311,17 @@ extern "C" fn rightMouseDown(this: *mut Object, _sel: Sel, event: *mut Object) { let mac_app = &*(*ptr as *const MacApp); let windowid = *(*this).get_ivar::("windowid"); - + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&wid) { Some(s) => s, None => return, }; @@ -1272,11 +1347,24 @@ extern "C" fn rightMouseDown(this: *mut Object, _sel: Sel, event: *mut Object) { ns_window: nswr, }); - crate::shell::event::wm_rbuttondown(window, &mut data.userdata, &guard, &raw); + let r = crate::shell::event::wm_rbuttondown(window, ud, &guard, &raw); - Window::finish_gl(guard); + mem::drop(window); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1290,14 +1378,17 @@ extern "C" fn rightMouseUp(this: *mut Object, _sel: Sel, event: *mut Object) { let mac_app = &*(*ptr as *const MacApp); let windowid = *(*this).get_ivar::("windowid"); - + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&wid) { Some(s) => s, None => return, }; @@ -1323,11 +1414,24 @@ extern "C" fn rightMouseUp(this: *mut Object, _sel: Sel, event: *mut Object) { ns_window: nswr, }); - crate::shell::event::wm_rbuttonup(window, &mut data.userdata, &guard, &raw, &mut data.active_menus); + let r = crate::shell::event::wm_rbuttonup(window, ud, &guard, &raw, &mut data.active_menus); - Window::finish_gl(guard); + mem::drop(window); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1341,14 +1445,17 @@ extern "C" fn otherMouseDown(this: *mut Object, _sel: Sel, event: *mut Object) { let mac_app = &*(*ptr as *const MacApp); let windowid = *(*this).get_ivar::("windowid"); - + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&wid) { Some(s) => s, None => return, }; @@ -1374,11 +1481,24 @@ extern "C" fn otherMouseDown(this: *mut Object, _sel: Sel, event: *mut Object) { ns_window: nswr, }); - crate::shell::event::wm_mbuttondown(window, &mut data.userdata, &guard, &raw); + let r = crate::shell::event::wm_mbuttondown(window, ud, &guard, &raw); - Window::finish_gl(guard); + mem::drop(window); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1392,14 +1512,17 @@ extern "C" fn otherMouseUp(this: *mut Object, _sel: Sel, event: *mut Object) { let mac_app = &*(*ptr as *const MacApp); let windowid = *(*this).get_ivar::("windowid"); - + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&WindowId { id: windowid }) { Some(s) => s, None => return, }; @@ -1425,11 +1548,24 @@ extern "C" fn otherMouseUp(this: *mut Object, _sel: Sel, event: *mut Object) { ns_window: nswr, }); - crate::shell::event::wm_mbuttonup(window, &mut data.userdata, &guard, &raw); + let r = crate::shell::event::wm_mbuttonup(window, ud, &guard, &raw); - Window::finish_gl(guard); + mem::drop(window); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1447,14 +1583,17 @@ extern "C" fn mouseMoved(this: *mut Object, _sel: Sel, event: *mut Object) { let mac_app = &*(*ptr as *const MacApp); let windowid = *(*this).get_ivar::("windowid"); - + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&WindowId { id: windowid }) { Some(s) => s, None => return, }; @@ -1480,11 +1619,24 @@ extern "C" fn mouseMoved(this: *mut Object, _sel: Sel, event: *mut Object) { ns_window: nswr, }); - crate::shell::event::wm_mousemove(window, &mut data.userdata, &guard, &raw, newpos); + let r = crate::shell::event::wm_mousemove(window, ud, &guard, &raw, newpos); - Window::finish_gl(guard); + mem::drop(window); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1499,14 +1651,17 @@ extern "C" fn scrollWheel(this: *mut Object, _sel: Sel, event: *mut Object) { let mac_app = &*(*ptr as *const MacApp); let windowid = *(*this).get_ivar::("windowid"); - + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&wid) { Some(s) => s, None => return, }; @@ -1534,11 +1689,24 @@ extern "C" fn scrollWheel(this: *mut Object, _sel: Sel, event: *mut Object) { // If you want the scroll amount: let delta_y: f64 = msg_send![event, scrollingDeltaY]; - crate::shell::event::wm_mousewheel(window, &mut data.userdata, &guard, &raw, delta_y as f32); + let r = crate::shell::event::wm_mousewheel(window, ud, &guard, &raw, delta_y as f32); - Window::finish_gl(guard); + mem::drop(window); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1547,6 +1715,7 @@ extern "C" fn scrollWheel(this: *mut Object, _sel: Sel, event: *mut Object) { // #[no_mangle] extern "C" fn keyDown(this: *mut Object, _sel: Sel, event: *mut Object) { + println!("keyDown"); unsafe { let keycode: u16 = msg_send![event, keyCode]; let scancode = keycode as u32; @@ -1556,14 +1725,17 @@ extern "C" fn keyDown(this: *mut Object, _sel: Sel, event: *mut Object) { let mac_app = &*(*ptr as *const MacApp); let windowid = *(*this).get_ivar::("windowid"); - + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&wid) { Some(s) => s, None => return, }; @@ -1590,11 +1762,24 @@ extern "C" fn keyDown(this: *mut Object, _sel: Sel, event: *mut Object) { }); // Possibly parse [event keyCode], etc., then call wm_keydown - crate::shell::event::wm_keydown(window, &mut data.userdata, &guard, &raw, scancode, vk); + let r = crate::shell::event::wm_keydown(window, ud, &guard, &raw, scancode, vk); - Window::finish_gl(guard); + mem::drop(window); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1603,6 +1788,7 @@ extern "C" fn keyDown(this: *mut Object, _sel: Sel, event: *mut Object) { // #[no_mangle] extern "C" fn keyUp(this: *mut Object, _sel: Sel, event: *mut Object) { + println!("keyUp"); unsafe { let keycode: u16 = msg_send![event, keyCode]; @@ -1612,15 +1798,19 @@ extern "C" fn keyUp(this: *mut Object, _sel: Sel, event: *mut Object) { let ptr = (*this).get_ivar::<*const c_void>("app"); let mac_app = &*(*ptr as *const MacApp); - let windowid = *(*this).get_ivar::("windowid"); + let windowid = *(*this).get_ivar::("windowid"); + let wid = WindowId { id: windowid }; let mut data = match mac_app.data.lock().ok() { Some(d) => d, None => return, }; + let data = &mut *data; + let mut dw = &mut data.windows; + let mut ud = &mut data.userdata; - let mut window = match data.windows.get_mut(&WindowId { id: windowid }) { + let mut window = match dw.get_mut(&wid) { Some(s) => s, None => return, }; @@ -1647,11 +1837,24 @@ extern "C" fn keyUp(this: *mut Object, _sel: Sel, event: *mut Object) { }); // Possibly parse [event keyCode], then call wm_keyup - crate::shell::event::wm_keyup(window, &mut data.userdata, &guard, &raw, scancode, vk); + let r = crate::shell::event::wm_keyup(window, ud, &guard, &raw, scancode, vk); - Window::finish_gl(guard); + mem::drop(window); - window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + let _ = crate::shell::event::handle_process_event_result( + r, + dw, + wid, + ud, + &guard, + &raw, + ); + + if let Some(window) = dw.get_mut(&wid) { + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + } + + Window::finish_gl(guard); } } @@ -1662,46 +1865,71 @@ extern "C" fn draw_rect(this: *mut AnyObject, _sel: Sel, dirty_rect: NSRect) { let ptr = (*this).get_ivar::<*const c_void>("app"); let ptr = *ptr as *const MacApp; let mac_app = &*ptr; + let functions = mac_app.functions.clone(); let windowid = *(*this).get_ivar::("windowid"); // Grab the lock to get the Window - if let Ok(mut app_data) = mac_app.data.lock() { - let mut app_data = &mut *app_data; - let w = &mut app_data.windows; - let ud = &mut app_data.userdata; - if let Some(window) = w.get_mut(&WindowId { id: windowid }) { - - let bounds: NSRect = msg_send![this, bounds]; - let bsf: CGFloat = msg_send![this, backingScaleFactor]; - let bdpi = (bsf * 96.0).round() as u32; - let bw = bounds.size.width.round() as u32; - let bh = bounds.size.height.round() as u32; - - let stored_size = window.internal.current_window_state.size.dimensions; - let ssw = stored_size.width.round() as u32; - let ssh = stored_size.height.round() as u32; - let sdpi = window.internal.current_window_state.size.dpi; - - let glc = Window::make_current_gl(msg_send![this, openGLContext]); - - const GL_COLOR_BUFFER_BIT: u32 = 0x00004000; - mac_app.functions.clear_color(1.0, 1.0, 1.0, 1.0); - mac_app.functions.clear(GL_COLOR_BUFFER_BIT); - - /* - if bw != ssw || bh != ssh || sdpi != bdpi { - do_resize(window, ud, bw, bh, bdpi, &glc); - window.internal.current_window_state.size.dimensions.width = bw as f32; - window.internal.current_window_state.size.dimensions.height = bh as f32; - window.internal.current_window_state.size.dpi = bdpi as u32; - } else { - gpu_scroll_render(window, ud, &glc); - } - */ + let mut app_data = match mac_app.data.lock() { + Ok(o) => o, + Err(e) => return, + }; + + let mut app_data = &mut *app_data; + let w = &mut app_data.windows; + let ud = &mut app_data.userdata; + let wid = WindowId { id: windowid }; + let mut window = match w.get_mut(&wid) { + Some(s) => s, + None => return, + }; + + let bounds: NSRect = msg_send![this, bounds]; + let bsf: CGFloat = msg_send![this, backingScaleFactor]; + let bdpi = (bsf * 96.0).round() as u32; + let bw = bounds.size.width.round() as u32; + let bh = bounds.size.height.round() as u32; + + let stored_size = window.internal.current_window_state.size.dimensions; + let ssw = stored_size.width.round() as u32; + let ssh = stored_size.height.round() as u32; + let sdpi = window.internal.current_window_state.size.dpi; + + let glc = Window::make_current_gl(msg_send![this, openGLContext]); - Window::finish_gl(glc); + const GL_COLOR_BUFFER_BIT: u32 = 0x00004000; + mac_app.functions.clear_color(1.0, 1.0, 1.0, 1.0); + mac_app.functions.clear(GL_COLOR_BUFFER_BIT); + + let mut nsw = match window.ns_window.take() { + Some(s) => s, + None => return, + }; + + let mut cv = match nsw.contentView() { + Some(s) => s, + None => { + window.ns_window = Some(nsw); + return; } - } + }; + + let nswr = Retained::::into_raw(nsw) as *mut _; + let raw = RawWindowHandle::MacOS(MacOSHandle { + ns_view: Retained::::into_raw(cv) as *mut _, + ns_window: nswr, + }); + + crate::shell::event::wm_paint( + window, + ud, + &glc, + &raw, + functions, + ); + + window.ns_window = unsafe { Retained::::from_raw(nswr as *mut _) }; + + Window::finish_gl(glc); } } diff --git a/azul-desktop/src/shell/event.rs b/azul-desktop/src/shell/event.rs index 6c27fa84..9d70856e 100644 --- a/azul-desktop/src/shell/event.rs +++ b/azul-desktop/src/shell/event.rs @@ -17,7 +17,12 @@ use crate::app::{self, App}; use azul_core::app_resources::ResourceUpdate; use azul_core::callbacks::LayoutCallbackInfo; use azul_core::window_state::{NodesToCheck, StyleAndLayoutChanges}; -use azul_core::window::{CursorPosition, FullHitTest, LogicalPosition, LogicalSize, MenuCallback, MouseCursorType, OptionMouseCursorType, PhysicalSize, ProcessEventResult, RawWindowHandle, VirtualKeyCode, WindowFrame, WindowId}; +use azul_core::window::{ + CursorPosition, FullHitTest, LogicalPosition, LogicalSize, MenuCallback, + MouseCursorType, OptionMouseCursorType, PhysicalSize, ProcessEventResult, + RawWindowHandle, VirtualKeyCode, WindowFrame, WindowId, + CursorTypeHitTest, +}; use gl_context_loader::GenericGlContext; use webrender::api::units::{DeviceIntRect, DeviceIntSize}; use webrender::Transaction; @@ -36,6 +41,8 @@ use crate::shell::win32::AppData; fn az_regenerate_dom(current_window: &mut Window, userdata: &mut App, _guard: &GlContextGuard) { + println!("az_regenerate_dom"); + let mut ret = ProcessEventResult::DoNothing; // borrow checker :| @@ -168,6 +175,8 @@ fn az_regenerate_dom(current_window: &mut Window, userdata: &mut App, _guard: &G /// ``` fn az_redo_hit_test(current_window: &mut Window, userdata: &mut App, _guard: &GlContextGuard, handle: &RawWindowHandle) -> ProcessEventResult { + println!("az_redo_hit_test"); + let fc_cache = &mut userdata.fc_cache; let image_cache = &mut userdata.image_cache; let config = &userdata.config; @@ -191,6 +200,8 @@ fn az_redo_hit_test(current_window: &mut Window, userdata: &mut App, _guard: &Gl fn az_regenerate_display_list(current_window: &mut Window, userdata: &mut App, _guard: &GlContextGuard) { + println!("az_regenerate_display_list"); + let image_cache = &userdata.image_cache; rebuild_display_list( @@ -213,6 +224,8 @@ fn az_regenerate_display_list(current_window: &mut Window, userdata: &mut App, _ } fn az_gpu_scroll_render(current_window: &mut Window, userdata: &mut App, _guard: &GlContextGuard) { + println!("az_gpu_scroll_render"); + generate_frame( &mut current_window.internal, &mut current_window.render_api, @@ -222,6 +235,7 @@ fn az_gpu_scroll_render(current_window: &mut Window, userdata: &mut App, _guard: // Window has received focus pub(crate) fn wm_set_focus(current_window: &mut Window, userdata: &mut App, guard: &GlContextGuard, handle: &RawWindowHandle) -> ProcessEventResult { + println!("wm_set_focus"); current_window.internal.previous_window_state = Some(current_window.internal.current_window_state.clone()); current_window.internal.current_window_state.flags.has_focus = true; az_redo_hit_test(current_window, userdata, guard, handle) @@ -229,6 +243,7 @@ pub(crate) fn wm_set_focus(current_window: &mut Window, userdata: &mut App, guar // Window has lost focus pub(crate) fn wm_kill_focus(current_window: &mut Window, userdata: &mut App, guard: &GlContextGuard, handle: &RawWindowHandle) -> ProcessEventResult { + println!("wm_kill_focus"); current_window.internal.previous_window_state = Some(current_window.internal.current_window_state.clone()); current_window.internal.current_window_state.flags.has_focus = false; az_redo_hit_test(current_window, userdata, guard, handle) @@ -242,11 +257,7 @@ pub(crate) fn wm_mousemove( newpos: LogicalPosition, ) -> ProcessEventResult { - use azul_core::window::{ - CursorTypeHitTest, LogicalPosition, - CursorPosition, OptionMouseCursorType, - FullHitTest, - }; + println!("wm_mousemove {newpos:?}"); let pos = CursorPosition::InWindow(newpos); @@ -297,6 +308,8 @@ pub(crate) fn wm_keydown( vk: Option, ) -> ProcessEventResult { + println!("wm_keydown {scancode} - {vk:?}"); + current_window.internal.previous_window_state = Some(current_window.internal.current_window_state.clone()); current_window.internal.current_window_state.keyboard_state.current_char = None.into(); current_window.internal.current_window_state.keyboard_state.pressed_scancodes.insert_hm_item(scancode); @@ -318,6 +331,8 @@ pub(crate) fn wm_char( c: char, ) -> ProcessEventResult { + println!("wm_char {c}"); + if c.is_control() { return ProcessEventResult::DoNothing; } @@ -335,6 +350,9 @@ pub(crate) fn wm_keyup( scancode: u32, vk: Option, ) -> ProcessEventResult { + + println!("wm_keyup {scancode} - {vk:?}"); + current_window.internal.previous_window_state = Some(current_window.internal.current_window_state.clone()); current_window.internal.current_window_state.keyboard_state.current_char = None.into(); current_window.internal.current_window_state.keyboard_state.pressed_scancodes.remove_hm_item(&scancode); @@ -352,6 +370,8 @@ pub(crate) fn wm_mouseleave( handle: &RawWindowHandle, ) -> ProcessEventResult { + println!("wm_mouseleave"); + let current_focus = current_window.internal.current_window_state.focused_node; let previous_state = current_window.internal.current_window_state.clone(); current_window.internal.previous_window_state = Some(previous_state); @@ -374,6 +394,7 @@ pub(crate) fn wm_rbuttondown( guard: &GlContextGuard, handle: &RawWindowHandle, ) -> ProcessEventResult { + println!("wm_rbuttondown"); let previous_state = current_window.internal.current_window_state.clone(); current_window.internal.previous_window_state = Some(previous_state); current_window.internal.current_window_state.mouse_state.right_down = true; @@ -387,6 +408,7 @@ pub(crate) fn wm_rbuttonup( handle: &RawWindowHandle, active_menus: &mut BTreeMap, ) -> ProcessEventResult { + println!("wm_rbuttonup"); let previous_state = current_window.internal.current_window_state.clone(); current_window.internal.previous_window_state = Some(previous_state); @@ -405,6 +427,7 @@ pub(crate) fn wm_mbuttondown( guard: &GlContextGuard, handle: &RawWindowHandle, ) -> ProcessEventResult { + println!("wm_mbuttondown"); let previous_state = current_window.internal.current_window_state.clone(); current_window.internal.previous_window_state = Some(previous_state); current_window.internal.current_window_state.mouse_state.middle_down = true; @@ -417,6 +440,7 @@ pub(crate) fn wm_mbuttonup( guard: &GlContextGuard, handle: &RawWindowHandle, ) -> ProcessEventResult { + println!("wm_mbuttonup"); let previous_state = current_window.internal.current_window_state.clone(); current_window.internal.previous_window_state = Some(previous_state); current_window.internal.current_window_state.mouse_state.middle_down = false; @@ -429,6 +453,7 @@ pub(crate) fn wm_lbuttondown( guard: &GlContextGuard, handle: &RawWindowHandle, ) -> ProcessEventResult { + println!("wm_lbuttondown"); let previous_state = current_window.internal.current_window_state.clone(); current_window.internal.previous_window_state = Some(previous_state); current_window.internal.current_window_state.mouse_state.left_down = true; @@ -442,6 +467,7 @@ pub(crate) fn wm_lbuttonup( handle: &RawWindowHandle, active_menus: &mut BTreeMap, ) -> ProcessEventResult { + println!("wm_lbuttonup"); let previous_state = current_window.internal.current_window_state.clone(); current_window.internal.previous_window_state = Some(previous_state); @@ -461,6 +487,7 @@ pub(crate) fn wm_mousewheel( handle: &RawWindowHandle, scroll_amount: f32, ) -> ProcessEventResult { + println!("wm_mousewheel {scroll_amount}"); let previous_state = current_window.internal.current_window_state.clone(); current_window.internal.previous_window_state = Some(previous_state); current_window.internal.current_window_state.mouse_state.scroll_y = Some(scroll_amount).into(); @@ -474,6 +501,7 @@ pub(crate) fn wm_dpichanged( handle: &RawWindowHandle, dpi: u32, ) -> ProcessEventResult { + println!("wm_dpichanged {dpi}"); // TODO! ProcessEventResult::DoNothing } @@ -489,6 +517,8 @@ pub(crate) fn wm_size( frame: WindowFrame, // minimized, maximized, restored ) { + println!("wm_size {dpi} {frame:?} {new_size:?}"); + let mut new_window_state = current_window.internal.current_window_state.clone(); new_window_state.size.dpi = dpi; new_window_state.size.dimensions = new_size.to_logical(new_window_state.size.get_hidpi_factor()); @@ -548,7 +578,7 @@ pub(crate) fn wm_size( pub(crate) fn wm_paint( current_window: &mut Window, userdata: &mut App, - guard: GlContextGuard, + guard: &GlContextGuard, handle: &RawWindowHandle, gl_functions: Rc, ) { @@ -558,6 +588,8 @@ pub(crate) fn wm_paint( // gl context is current (assured by GlContextGuard) + println!("wm_paint"); + let rect_size = current_window.internal.current_window_state.size.dimensions.to_physical( current_window.internal.current_window_state.size.get_hidpi_factor() ); @@ -598,7 +630,6 @@ pub(crate) fn wm_paint( gl.bind_texture(gl_context_loader::gl::TEXTURE_2D, 0); gl.use_program(current_program[0] as u32); - Window::finish_gl(guard); } pub(crate) fn wm_quit( @@ -608,6 +639,7 @@ pub(crate) fn wm_quit( handle: &RawWindowHandle, gl_functions: Rc, ) { + println!("wm_quit"); // TODO: execute quit callback } @@ -618,6 +650,9 @@ pub(crate) fn wm_destroy( handle: &RawWindowHandle, gl_functions: Rc, ) { + + println!("wm_destroy"); + // deallocate objects, etc. current_window.destroy( @@ -626,4 +661,60 @@ pub(crate) fn wm_destroy( handle, gl_functions, ); -} \ No newline at end of file +} + +/// A helper that matches on the `ProcessEventResult`. +/// +/// - `window` (the current window) +/// - `app` (mutable reference to your main app data) +/// - `guard` (the already-current OpenGL context) +/// - `raw` (the `RawWindowHandle`) +/// +pub fn handle_process_event_result( + ret: ProcessEventResult, + all_windows: &mut BTreeMap, + window_id: WindowId, + app: &mut App, + guard: &GlContextGuard, + raw: &RawWindowHandle, +) -> Option<()> { + + match ret { + ProcessEventResult::DoNothing => { }, + ProcessEventResult::ShouldRegenerateDomCurrentWindow => { + // Rebuild the DOM for this one window (OpenGL context is already current) + let cw = all_windows.get_mut(&window_id)?; + az_regenerate_dom(cw, app, guard); + } + ProcessEventResult::ShouldRegenerateDomAllWindows => { + for cw in all_windows.values_mut() { + az_regenerate_dom(cw, app, guard); + } + } + ProcessEventResult::ShouldUpdateDisplayListCurrentWindow => { + // Rebuild the display list, but not the DOM for this single window + let cw = all_windows.get_mut(&window_id)?; + az_regenerate_display_list(cw, app, guard); + } + ProcessEventResult::UpdateHitTesterAndProcessAgain => { + let cw = all_windows.get_mut(&window_id)?; + + // Record old state + cw.internal.previous_window_state = + Some(cw.internal.current_window_state.clone()); + + // 1) Rebuild the display list + az_regenerate_display_list(cw, app, guard); + + // 2) Then re-run the “redo hit test” + // We have the same references, so just call it: + az_redo_hit_test(cw, app, guard, raw); + } + ProcessEventResult::ShouldReRenderCurrentWindow => { + let cw = all_windows.get_mut(&window_id)?; + az_gpu_scroll_render(cw, app, guard); + } + } + + Some(()) +}