#![allow(non_snake_case)]
use std::cell::RefCell;
use std::rc::Rc;
use bevy_ecs::prelude::Entity;
use windows::Win32::Foundation::*;
use crate::ecs::world::EcsWorld;
type HandlerResult = Option<LRESULT>;
#[inline]
pub(super) fn WM_KEYDOWN(
_world: &Rc<RefCell<EcsWorld>>,
_entity: Entity,
_hwnd: HWND,
wparam: WPARAM,
_lparam: LPARAM,
) -> HandlerResult {
use windows::Win32::UI::Input::KeyboardAndMouse::VK_ESCAPE;
if wparam.0 == VK_ESCAPE.0 as usize {
crate::ecs::drag::cancel_dragging();
tracing::debug!("[WM_KEYDOWN] ESC key pressed, drag cancelled");
}
None }
#[inline]
pub(super) fn WM_CANCELMODE(
_world: &Rc<RefCell<EcsWorld>>,
_entity: Entity,
_hwnd: HWND,
_wparam: WPARAM,
_lparam: LPARAM,
) -> HandlerResult {
crate::ecs::drag::cancel_dragging();
tracing::debug!("[WM_CANCELMODE] System cancel, drag cancelled");
None }
pub(super) fn WM_ACTIVATE(
world: &Rc<RefCell<EcsWorld>>,
entity: Entity,
_hwnd: HWND,
wparam: WPARAM,
_lparam: LPARAM,
) -> HandlerResult {
let activation_state = (wparam.0 & 0xFFFF) as u32;
if activation_state != 0 {
return None;
}
match crate::ecs::drag::cancel_dragging() {
crate::ecs::drag::DragClose::Closed {
entity,
notified: true,
} => {
tracing::info!(
entity = ?entity,
"[WM_ACTIVATE] Window deactivated during drag, cancelling"
);
}
crate::ecs::drag::DragClose::Closed {
notified: false, ..
} => {
tracing::debug!("[WM_ACTIVATE] Window deactivated during drag prepare, resetting");
}
crate::ecs::drag::DragClose::OtherWindow | crate::ecs::drag::DragClose::NotActive => {}
}
if let Ok(mut world_borrow) = world.try_borrow_mut() {
crate::ecs::window::mark_pair_sink_observation(world_borrow.world_mut(), entity);
}
None }
pub(super) fn WM_CAPTURECHANGED(
_world: &Rc<RefCell<EcsWorld>>,
_entity: Entity,
_hwnd: HWND,
_wparam: WPARAM,
_lparam: LPARAM,
) -> HandlerResult {
if let crate::ecs::drag::DragClose::Closed { .. } =
crate::ecs::drag::cancel_dragging_on_capture_lost()
{
tracing::debug!("[WM_CAPTURECHANGED] Capture lost externally, drag cancelled");
}
None }
#[cfg(test)]
#[path = "keyboard_tests.rs"]
mod keyboard_tests;