mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
chore(repo): prune dead code and duplicate abstractions (#3413)
This commit is contained in:
1 parent
c17091768c
commit
c9fdf8fead
2937 files changed
+42233
-176793
No files matched your search
@@ -0,0 +1,585 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct KeyMapU16 {
|
||||
pub code: u16,
|
||||
pub name: &'static str,
|
||||
}
|
||||
|
||||
pub mod windows {
|
||||
use super::KeyMapU16;
|
||||
|
||||
pub const VK_TABLE: &[KeyMapU16] = &[
|
||||
KeyMapU16 {
|
||||
code: 0x1b,
|
||||
name: "Escape",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x70,
|
||||
name: "F1",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x71,
|
||||
name: "F2",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x72,
|
||||
name: "F3",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x73,
|
||||
name: "F4",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x74,
|
||||
name: "F5",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x75,
|
||||
name: "F6",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x76,
|
||||
name: "F7",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x77,
|
||||
name: "F8",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x78,
|
||||
name: "F9",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x79,
|
||||
name: "F10",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x7a,
|
||||
name: "F11",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x7b,
|
||||
name: "F12",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x7c,
|
||||
name: "F13",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x7d,
|
||||
name: "F14",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x7e,
|
||||
name: "F15",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x7f,
|
||||
name: "F16",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x80,
|
||||
name: "F17",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x81,
|
||||
name: "F18",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x82,
|
||||
name: "F19",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x83,
|
||||
name: "F20",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x84,
|
||||
name: "F21",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x85,
|
||||
name: "F22",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x86,
|
||||
name: "F23",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x87,
|
||||
name: "F24",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x13,
|
||||
name: "Pause",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x2c,
|
||||
name: "PrintScreen",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x91,
|
||||
name: "ScrollLock",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x90,
|
||||
name: "NumLock",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x5d,
|
||||
name: "ContextMenu",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xc0,
|
||||
name: "Backquote",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x31,
|
||||
name: "1",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x32,
|
||||
name: "2",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x33,
|
||||
name: "3",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x34,
|
||||
name: "4",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x35,
|
||||
name: "5",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x36,
|
||||
name: "6",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x37,
|
||||
name: "7",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x38,
|
||||
name: "8",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x39,
|
||||
name: "9",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x30,
|
||||
name: "0",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xbd,
|
||||
name: "Minus",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xbb,
|
||||
name: "Equal",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x08,
|
||||
name: "Backspace",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x09,
|
||||
name: "Tab",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x51,
|
||||
name: "Q",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x57,
|
||||
name: "W",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x45,
|
||||
name: "E",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x52,
|
||||
name: "R",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x54,
|
||||
name: "T",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x59,
|
||||
name: "Y",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x55,
|
||||
name: "U",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x49,
|
||||
name: "I",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x4f,
|
||||
name: "O",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x50,
|
||||
name: "P",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xdb,
|
||||
name: "BracketLeft",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xdd,
|
||||
name: "BracketRight",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xdc,
|
||||
name: "Backslash",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x14,
|
||||
name: "CapsLock",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x41,
|
||||
name: "A",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x53,
|
||||
name: "S",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x44,
|
||||
name: "D",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x46,
|
||||
name: "F",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x47,
|
||||
name: "G",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x48,
|
||||
name: "H",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x4a,
|
||||
name: "J",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x4b,
|
||||
name: "K",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x4c,
|
||||
name: "L",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xba,
|
||||
name: "Semicolon",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xde,
|
||||
name: "Quote",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x0d,
|
||||
name: "Enter",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa0,
|
||||
name: "ShiftLeft",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x5a,
|
||||
name: "Z",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x58,
|
||||
name: "X",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x43,
|
||||
name: "C",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x56,
|
||||
name: "V",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x42,
|
||||
name: "B",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x4e,
|
||||
name: "N",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x4d,
|
||||
name: "M",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xbc,
|
||||
name: "Comma",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xbe,
|
||||
name: "Period",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xbf,
|
||||
name: "Slash",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa1,
|
||||
name: "ShiftRight",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa2,
|
||||
name: "ControlLeft",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x5b,
|
||||
name: "MetaLeft",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa4,
|
||||
name: "AltLeft",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x20,
|
||||
name: "Space",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa5,
|
||||
name: "AltRight",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x5c,
|
||||
name: "MetaRight",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa3,
|
||||
name: "ControlRight",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x60,
|
||||
name: "Numpad0",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x61,
|
||||
name: "Numpad1",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x62,
|
||||
name: "Numpad2",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x63,
|
||||
name: "Numpad3",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x64,
|
||||
name: "Numpad4",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x65,
|
||||
name: "Numpad5",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x66,
|
||||
name: "Numpad6",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x67,
|
||||
name: "Numpad7",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x68,
|
||||
name: "Numpad8",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x69,
|
||||
name: "Numpad9",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x6a,
|
||||
name: "NumpadMultiply",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x6b,
|
||||
name: "NumpadAdd",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x6c,
|
||||
name: "NumpadComma",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x6d,
|
||||
name: "NumpadSubtract",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x6e,
|
||||
name: "NumpadDecimal",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x6f,
|
||||
name: "NumpadDivide",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x92,
|
||||
name: "NumpadEqual",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x0c,
|
||||
name: "Numpad5",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x25,
|
||||
name: "ArrowLeft",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x26,
|
||||
name: "ArrowUp",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x27,
|
||||
name: "ArrowRight",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x28,
|
||||
name: "ArrowDown",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x2d,
|
||||
name: "Insert",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x2e,
|
||||
name: "Delete",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x24,
|
||||
name: "Home",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x23,
|
||||
name: "End",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x21,
|
||||
name: "PageUp",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x22,
|
||||
name: "PageDown",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xad,
|
||||
name: "AudioVolumeMute",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xae,
|
||||
name: "AudioVolumeDown",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xaf,
|
||||
name: "AudioVolumeUp",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xb0,
|
||||
name: "MediaTrackNext",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xb1,
|
||||
name: "MediaTrackPrevious",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xb2,
|
||||
name: "MediaStop",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xb3,
|
||||
name: "MediaPlayPause",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa6,
|
||||
name: "BrowserBack",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa7,
|
||||
name: "BrowserForward",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa8,
|
||||
name: "BrowserRefresh",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xa9,
|
||||
name: "BrowserStop",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xaa,
|
||||
name: "BrowserSearch",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xab,
|
||||
name: "BrowserFavorites",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xac,
|
||||
name: "BrowserHome",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xb4,
|
||||
name: "LaunchMail",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xb5,
|
||||
name: "LaunchMediaPlayer",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xb6,
|
||||
name: "LaunchApp1",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0xb7,
|
||||
name: "LaunchApp2",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x1c,
|
||||
name: "Convert",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x1d,
|
||||
name: "NonConvert",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x15,
|
||||
name: "KanaMode",
|
||||
},
|
||||
KeyMapU16 {
|
||||
code: 0x5f,
|
||||
name: "Sleep",
|
||||
},
|
||||
];
|
||||
|
||||
pub fn vk_to_name(vk: u16) -> Option<&'static str> {
|
||||
VK_TABLE
|
||||
.iter()
|
||||
.find(|entry| entry.code == vk)
|
||||
.map(|entry| entry.name)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fallback_name(prefix_value: impl std::fmt::Display) -> String {
|
||||
format!("Key{prefix_value}")
|
||||
}
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
mod keymap;
|
||||
#[cfg(target_os = "windows")]
|
||||
mod modifiers;
|
||||
#[cfg(target_os = "windows")]
|
||||
mod windows_mouse;
|
||||
|
||||
use napi::{
|
||||
Env,
|
||||
bindgen_prelude::{Function, Object, Result, ToNapiValue},
|
||||
@@ -139,7 +145,7 @@ fn scan_aware_key_name(vk: u16, flags: u32) -> Option<&'static str> {
|
||||
}
|
||||
|
||||
pub fn write_key_name(buf: &mut [u8; KEY_NAME_BUF], len_out: &mut u8, vk: u16) {
|
||||
use fluxer_desktop_native::input::keymap::{fallback_name, windows::vk_to_name};
|
||||
use crate::keymap::{fallback_name, windows::vk_to_name};
|
||||
if let Some(name) = vk_to_name(vk) {
|
||||
write_ascii_key_name(buf, len_out, name);
|
||||
} else {
|
||||
@@ -208,7 +214,7 @@ mod platform {
|
||||
EventKind, EventThreadsafeFunction, HeldInputs, QueuedEvent, VK_PACKET,
|
||||
write_key_name_from_hook, write_packet_key_name,
|
||||
};
|
||||
use fluxer_desktop_native::input::modifiers::{
|
||||
use crate::modifiers::{
|
||||
Modifiers,
|
||||
windows::{from_sampled, with_pressed_key},
|
||||
};
|
||||
@@ -395,7 +401,7 @@ mod platform {
|
||||
}
|
||||
|
||||
unsafe extern "system" fn mouse_proc(code: i32, wparam: WPARAM, lparam: LPARAM) -> LRESULT {
|
||||
use fluxer_desktop_native::input::windows_mouse::{Action, classify};
|
||||
use crate::windows_mouse::{Action, classify};
|
||||
if code >= 0
|
||||
&& let Some(handle) = current_handle()
|
||||
{
|
||||
@@ -771,23 +777,6 @@ pub fn is_available() -> bool {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use fluxer_desktop_native::input::ring::Ring;
|
||||
|
||||
#[test]
|
||||
fn write_key_name_known_vk() {
|
||||
let mut buf = [0u8; KEY_NAME_BUF];
|
||||
let mut len = 0u8;
|
||||
write_key_name(&mut buf, &mut len, 0x41);
|
||||
assert_eq!(&buf[..len as usize], b"A");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_key_name_function_keys() {
|
||||
let mut buf = [0u8; KEY_NAME_BUF];
|
||||
let mut len = 0u8;
|
||||
write_key_name(&mut buf, &mut len, 0x7b);
|
||||
assert_eq!(&buf[..len as usize], b"F12");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_key_name_from_hook_distinguishes_keypad_navigation() {
|
||||
@@ -808,14 +797,6 @@ mod tests {
|
||||
assert_eq!(&buf[..len as usize], b"NumpadEnter");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_key_name_fallback() {
|
||||
let mut buf = [0u8; KEY_NAME_BUF];
|
||||
let mut len = 0u8;
|
||||
write_key_name(&mut buf, &mut len, 0x0fff);
|
||||
assert_eq!(&buf[..len as usize], b"Key4095");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_packet_key_name_uses_the_injected_character() {
|
||||
let name = |unit: u32| {
|
||||
@@ -887,21 +868,4 @@ mod tests {
|
||||
);
|
||||
assert!(held.take_releases().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ring_holds_queued_events() {
|
||||
let ring: Ring<QueuedEvent, 4> = Ring::new();
|
||||
let idx = ring.claim().expect("claim slot") as usize;
|
||||
|
||||
unsafe {
|
||||
let slots = ring.slots.as_ptr() as *mut QueuedEvent;
|
||||
(*slots.add(idx)).kind = EventKind::MouseUp;
|
||||
(*slots.add(idx)).button = 4;
|
||||
}
|
||||
let pop_idx = ring.pop().expect("pop slot") as usize;
|
||||
assert_eq!(ring.slots[pop_idx].kind, EventKind::MouseUp);
|
||||
assert_eq!(ring.slots[pop_idx].button, 4);
|
||||
ring.release();
|
||||
assert!(ring.pop().is_none());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub struct Modifiers {
|
||||
pub ctrl: bool,
|
||||
pub alt: bool,
|
||||
pub shift: bool,
|
||||
pub meta: bool,
|
||||
}
|
||||
|
||||
pub mod windows {
|
||||
use super::Modifiers;
|
||||
|
||||
pub const HIGH_BIT: u16 = 0x8000;
|
||||
|
||||
pub fn from_sampled(
|
||||
shift_state: u16,
|
||||
ctrl_state: u16,
|
||||
alt_state: u16,
|
||||
lwin_state: u16,
|
||||
rwin_state: u16,
|
||||
) -> Modifiers {
|
||||
Modifiers {
|
||||
shift: (shift_state & HIGH_BIT) != 0,
|
||||
ctrl: (ctrl_state & HIGH_BIT) != 0,
|
||||
alt: (alt_state & HIGH_BIT) != 0,
|
||||
meta: ((lwin_state | rwin_state) & HIGH_BIT) != 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_pressed_key(modifiers: Modifiers, vk: u16) -> Modifiers {
|
||||
match vk {
|
||||
0x10 | 0xa0 | 0xa1 => Modifiers {
|
||||
shift: true,
|
||||
..modifiers
|
||||
},
|
||||
0x11 | 0xa2 | 0xa3 => Modifiers {
|
||||
ctrl: true,
|
||||
..modifiers
|
||||
},
|
||||
0x12 | 0xa4 | 0xa5 => Modifiers {
|
||||
alt: true,
|
||||
..modifiers
|
||||
},
|
||||
0x5b | 0x5c => Modifiers {
|
||||
meta: true,
|
||||
..modifiers
|
||||
},
|
||||
_ => modifiers,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
pub const WM_MOUSEMOVE: u32 = 0x0200;
|
||||
pub const WM_LBUTTONDOWN: u32 = 0x0201;
|
||||
pub const WM_LBUTTONUP: u32 = 0x0202;
|
||||
pub const WM_RBUTTONDOWN: u32 = 0x0204;
|
||||
pub const WM_RBUTTONUP: u32 = 0x0205;
|
||||
pub const WM_MBUTTONDOWN: u32 = 0x0207;
|
||||
pub const WM_MBUTTONUP: u32 = 0x0208;
|
||||
pub const WM_MOUSEWHEEL: u32 = 0x020a;
|
||||
pub const WM_XBUTTONDOWN: u32 = 0x020b;
|
||||
pub const WM_XBUTTONUP: u32 = 0x020c;
|
||||
pub const WM_MOUSEHWHEEL: u32 = 0x020e;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Action {
|
||||
Button { down: bool, button: u8 },
|
||||
Activity,
|
||||
Ignored,
|
||||
}
|
||||
|
||||
pub fn classify(msg: u32, xbutton: u16) -> Action {
|
||||
match msg {
|
||||
WM_MOUSEMOVE | WM_MOUSEWHEEL | WM_MOUSEHWHEEL => Action::Activity,
|
||||
WM_LBUTTONDOWN => Action::Button {
|
||||
down: true,
|
||||
button: 0,
|
||||
},
|
||||
WM_LBUTTONUP => Action::Button {
|
||||
down: false,
|
||||
button: 0,
|
||||
},
|
||||
WM_RBUTTONDOWN => Action::Button {
|
||||
down: true,
|
||||
button: 2,
|
||||
},
|
||||
WM_RBUTTONUP => Action::Button {
|
||||
down: false,
|
||||
button: 2,
|
||||
},
|
||||
WM_MBUTTONDOWN => Action::Button {
|
||||
down: true,
|
||||
button: 1,
|
||||
},
|
||||
WM_MBUTTONUP => Action::Button {
|
||||
down: false,
|
||||
button: 1,
|
||||
},
|
||||
WM_XBUTTONDOWN => match xbutton {
|
||||
1 => Action::Button {
|
||||
down: true,
|
||||
button: 3,
|
||||
},
|
||||
2 => Action::Button {
|
||||
down: true,
|
||||
button: 4,
|
||||
},
|
||||
_ => Action::Ignored,
|
||||
},
|
||||
WM_XBUTTONUP => match xbutton {
|
||||
1 => Action::Button {
|
||||
down: false,
|
||||
button: 3,
|
||||
},
|
||||
2 => Action::Button {
|
||||
down: false,
|
||||
button: 4,
|
||||
},
|
||||
_ => Action::Ignored,
|
||||
},
|
||||
_ => Action::Ignored,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user