Added mouse_events_to_lua helper function
Doesn't work correctly yet, due to limitations in what WLC hands us in
the mouse callbacks.
@@ -5,6 +5,18 @@ use rustwlc::*;
const MOD_NAMES: [&str; 8] = ["Shift", "Caps", "Control", "Alt",
"Mod2", "Mod3", "Mod4", "Mod5"];
+const MOUSE_EVENTS: [u32; 6] = [
+ // TODO This only grabs the buttons, not the scroll
+ // This is a WLC limitation, it will be lifted later!
+
+ 272, // button mask 1
+ 273, // button mask 2
+ 274, // button mask 3
+ 275, // button mask 4
+ 276, // button mask 5
+
+ // TODO currently unused
+ 1 << 15 /* mask any */];
/// Convert a modifier to the Lua interpretation
pub fn mods_to_lua(lua: &rlua::Lua, mut mods: KeyMod) -> rlua::Result<Table> {
@@ -20,3 +32,15 @@ pub fn mods_to_lua(lua: &rlua::Lua, mut mods: KeyMod) -> rlua::Result<Table> {
}
lua.create_table_from(mods_list.into_iter().enumerate())
}
+
+/// Convert a mouse event from Wayland to the representation Lua expcets
+pub fn mouse_events_to_lua(_: &rlua::Lua, button: u32,
+ button_state: ButtonState) -> rlua::Result<Vec<bool>> {
+ let mut event_list = Vec::with_capacity(MOUSE_EVENTS.len());
+ for mouse_event in &MOUSE_EVENTS[..5] {
+ let state_pressed = button_state == ButtonState::Pressed;
+ let is_pressed = button == *mouse_event && state_pressed;
+ event_list.push(is_pressed);
+ }
+ Ok(event_list)
+}
