refactor: move input types to new module and use directly use libvaxis types
This commit is contained in:
		
							parent
							
								
									e08c2aa3ba
								
							
						
					
					
						commit
						18f321bf41
					
				
					 36 changed files with 1224 additions and 1363 deletions
				
			
		| 
						 | 
				
			
			@ -1,265 +1,167 @@
 | 
			
		|||
const Key = @import("vaxis").Key;
 | 
			
		||||
const Mouse = @import("vaxis").Mouse;
 | 
			
		||||
const vaxis = @import("vaxis");
 | 
			
		||||
 | 
			
		||||
pub const key = struct {
 | 
			
		||||
    pub const ENTER: key_type = Key.enter;
 | 
			
		||||
    pub const TAB: key_type = Key.tab;
 | 
			
		||||
    pub const ESC: key_type = Key.escape;
 | 
			
		||||
    pub const SPACE: key_type = Key.space;
 | 
			
		||||
    pub const BACKSPACE: key_type = Key.backspace;
 | 
			
		||||
const utf8Encode = @import("std").unicode.utf8Encode;
 | 
			
		||||
 | 
			
		||||
    pub const INS: key_type = Key.insert;
 | 
			
		||||
    pub const DEL: key_type = Key.delete;
 | 
			
		||||
    pub const LEFT: key_type = Key.left;
 | 
			
		||||
    pub const RIGHT: key_type = Key.right;
 | 
			
		||||
    pub const UP: key_type = Key.up;
 | 
			
		||||
    pub const DOWN: key_type = Key.down;
 | 
			
		||||
    pub const PGDOWN: key_type = Key.page_down;
 | 
			
		||||
    pub const PGUP: key_type = Key.page_up;
 | 
			
		||||
    pub const HOME: key_type = Key.home;
 | 
			
		||||
    pub const END: key_type = Key.end;
 | 
			
		||||
    pub const CAPS_LOCK: key_type = Key.caps_lock;
 | 
			
		||||
    pub const SCROLL_LOCK: key_type = Key.scroll_lock;
 | 
			
		||||
    pub const NUM_LOCK: key_type = Key.num_lock;
 | 
			
		||||
    pub const PRINT_SCREEN: key_type = Key.print_screen;
 | 
			
		||||
    pub const PAUSE: key_type = Key.pause;
 | 
			
		||||
    pub const MENU: key_type = Key.menu;
 | 
			
		||||
    pub const F01: key_type = Key.f1;
 | 
			
		||||
    pub const F02: key_type = Key.f2;
 | 
			
		||||
    pub const F03: key_type = Key.f3;
 | 
			
		||||
    pub const F04: key_type = Key.f4;
 | 
			
		||||
    pub const F05: key_type = Key.f5;
 | 
			
		||||
    pub const F06: key_type = Key.f6;
 | 
			
		||||
    pub const F07: key_type = Key.f7;
 | 
			
		||||
    pub const F08: key_type = Key.f8;
 | 
			
		||||
    pub const F09: key_type = Key.f9;
 | 
			
		||||
    pub const F10: key_type = Key.f10;
 | 
			
		||||
    pub const F11: key_type = Key.f11;
 | 
			
		||||
    pub const F12: key_type = Key.f12;
 | 
			
		||||
    pub const F13: key_type = Key.f13;
 | 
			
		||||
    pub const F14: key_type = Key.f14;
 | 
			
		||||
    pub const F15: key_type = Key.f15;
 | 
			
		||||
    pub const F16: key_type = Key.f16;
 | 
			
		||||
    pub const F17: key_type = Key.f17;
 | 
			
		||||
    pub const F18: key_type = Key.f18;
 | 
			
		||||
    pub const F19: key_type = Key.f19;
 | 
			
		||||
    pub const F20: key_type = Key.f20;
 | 
			
		||||
    pub const F21: key_type = Key.f21;
 | 
			
		||||
    pub const F22: key_type = Key.f22;
 | 
			
		||||
    pub const F23: key_type = Key.f23;
 | 
			
		||||
    pub const F24: key_type = Key.f24;
 | 
			
		||||
    pub const F25: key_type = Key.f25;
 | 
			
		||||
    pub const F26: key_type = Key.f26;
 | 
			
		||||
    pub const F27: key_type = Key.f27;
 | 
			
		||||
    pub const F28: key_type = Key.f28;
 | 
			
		||||
    pub const F29: key_type = Key.f29;
 | 
			
		||||
    pub const F30: key_type = Key.f30;
 | 
			
		||||
    pub const F31: key_type = Key.f31;
 | 
			
		||||
    pub const F32: key_type = Key.f32;
 | 
			
		||||
    pub const F33: key_type = Key.f33;
 | 
			
		||||
    pub const F34: key_type = Key.f34;
 | 
			
		||||
    pub const F35: key_type = Key.f35;
 | 
			
		||||
pub const key = vaxis.Key;
 | 
			
		||||
pub const Key = u21;
 | 
			
		||||
 | 
			
		||||
    pub const F58: key_type = Key.iso_level_5_shift + 1; // FIXME bogus
 | 
			
		||||
pub const Mouse = vaxis.Mouse.Button;
 | 
			
		||||
pub const MouseType = @typeInfo(Mouse).Enum.tag_type;
 | 
			
		||||
 | 
			
		||||
    pub const MEDIA_PLAY: key_type = Key.media_play;
 | 
			
		||||
    pub const MEDIA_PAUSE: key_type = Key.media_pause;
 | 
			
		||||
    pub const MEDIA_PPAUSE: key_type = Key.media_play_pause;
 | 
			
		||||
    pub const MEDIA_REV: key_type = Key.media_reverse;
 | 
			
		||||
    pub const MEDIA_STOP: key_type = Key.media_stop;
 | 
			
		||||
    pub const MEDIA_FF: key_type = Key.media_fast_forward;
 | 
			
		||||
    pub const MEDIA_REWIND: key_type = Key.media_rewind;
 | 
			
		||||
    pub const MEDIA_NEXT: key_type = Key.media_track_next;
 | 
			
		||||
    pub const MEDIA_PREV: key_type = Key.media_track_previous;
 | 
			
		||||
    pub const MEDIA_RECORD: key_type = Key.media_record;
 | 
			
		||||
    pub const MEDIA_LVOL: key_type = Key.lower_volume;
 | 
			
		||||
    pub const MEDIA_RVOL: key_type = Key.raise_volume;
 | 
			
		||||
    pub const MEDIA_MUTE: key_type = Key.mute_volume;
 | 
			
		||||
    pub const LSHIFT: key_type = Key.left_shift;
 | 
			
		||||
    pub const LCTRL: key_type = Key.left_control;
 | 
			
		||||
    pub const LALT: key_type = Key.left_alt;
 | 
			
		||||
    pub const LSUPER: key_type = Key.left_super;
 | 
			
		||||
    pub const LHYPER: key_type = Key.left_hyper;
 | 
			
		||||
    pub const LMETA: key_type = Key.left_meta;
 | 
			
		||||
    pub const RSHIFT: key_type = Key.right_shift;
 | 
			
		||||
    pub const RCTRL: key_type = Key.right_control;
 | 
			
		||||
    pub const RALT: key_type = Key.right_alt;
 | 
			
		||||
    pub const RSUPER: key_type = Key.right_super;
 | 
			
		||||
    pub const RHYPER: key_type = Key.right_hyper;
 | 
			
		||||
    pub const RMETA: key_type = Key.right_meta;
 | 
			
		||||
    pub const L3SHIFT: key_type = Key.iso_level_3_shift;
 | 
			
		||||
    pub const L5SHIFT: key_type = Key.iso_level_5_shift;
 | 
			
		||||
 | 
			
		||||
    pub const MOTION: key_type = @intCast(@intFromEnum(Mouse.Button.none));
 | 
			
		||||
    pub const BUTTON1: key_type = @intCast(@intFromEnum(Mouse.Button.left));
 | 
			
		||||
    pub const BUTTON2: key_type = @intCast(@intFromEnum(Mouse.Button.middle));
 | 
			
		||||
    pub const BUTTON3: key_type = @intCast(@intFromEnum(Mouse.Button.right));
 | 
			
		||||
    pub const BUTTON4: key_type = @intCast(@intFromEnum(Mouse.Button.wheel_up));
 | 
			
		||||
    pub const BUTTON5: key_type = @intCast(@intFromEnum(Mouse.Button.wheel_down));
 | 
			
		||||
    // pub const BUTTON6: key_type = @intCast(@intFromEnum(Mouse.Button.button_6));
 | 
			
		||||
    // pub const BUTTON7: key_type = @intCast(@intFromEnum(Mouse.Button.button_7));
 | 
			
		||||
    pub const BUTTON8: key_type = @intCast(@intFromEnum(Mouse.Button.button_8));
 | 
			
		||||
    pub const BUTTON9: key_type = @intCast(@intFromEnum(Mouse.Button.button_9));
 | 
			
		||||
    pub const BUTTON10: key_type = @intCast(@intFromEnum(Mouse.Button.button_10));
 | 
			
		||||
    pub const BUTTON11: key_type = @intCast(@intFromEnum(Mouse.Button.button_11));
 | 
			
		||||
 | 
			
		||||
    // pub const SIGNAL: key_type = Key.SIGNAL;
 | 
			
		||||
    // pub const EOF: key_type = Key.EOF;
 | 
			
		||||
    // pub const SCROLL_UP: key_type = Key.SCROLL_UP;
 | 
			
		||||
    // pub const SCROLL_DOWN: key_type = Key.SCROLL_DOWN;
 | 
			
		||||
 | 
			
		||||
    /// Is this uint32_t a synthesized event?
 | 
			
		||||
    pub fn synthesized_p(w: u32) bool {
 | 
			
		||||
        return switch (w) {
 | 
			
		||||
            Key.insert...Key.iso_level_5_shift => true,
 | 
			
		||||
            Key.enter => true,
 | 
			
		||||
            Key.tab => true,
 | 
			
		||||
            Key.escape => true,
 | 
			
		||||
            Key.backspace => true,
 | 
			
		||||
            else => false,
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
pub const mouse = struct {
 | 
			
		||||
    pub const MOTION: Mouse = vaxis.Mouse.Button.none;
 | 
			
		||||
    pub const BUTTON1: Mouse = vaxis.Mouse.Button.left;
 | 
			
		||||
    pub const BUTTON2: Mouse = vaxis.Mouse.Button.middle;
 | 
			
		||||
    pub const BUTTON3: Mouse = vaxis.Mouse.Button.right;
 | 
			
		||||
    pub const BUTTON4: Mouse = vaxis.Mouse.Button.wheel_up;
 | 
			
		||||
    pub const BUTTON5: Mouse = vaxis.Mouse.Button.wheel_down;
 | 
			
		||||
    // pub const BUTTON6: Mouse = vaxis.Mouse.Button.button_6;
 | 
			
		||||
    // pub const BUTTON7: Mouse = vaxis.Mouse.Button.button_7;
 | 
			
		||||
    pub const BUTTON8: Mouse = vaxis.Mouse.Button.button_8;
 | 
			
		||||
    pub const BUTTON9: Mouse = vaxis.Mouse.Button.button_9;
 | 
			
		||||
    pub const BUTTON10: Mouse = vaxis.Mouse.Button.button_10;
 | 
			
		||||
    pub const BUTTON11: Mouse = vaxis.Mouse.Button.button_11;
 | 
			
		||||
};
 | 
			
		||||
pub const key_type = u21;
 | 
			
		||||
 | 
			
		||||
pub const modifier = struct {
 | 
			
		||||
    pub const SHIFT: modifier_type = 1;
 | 
			
		||||
    pub const ALT: modifier_type = 2;
 | 
			
		||||
    pub const CTRL: modifier_type = 4;
 | 
			
		||||
    pub const SUPER: modifier_type = 8;
 | 
			
		||||
    pub const HYPER: modifier_type = 16;
 | 
			
		||||
    pub const META: modifier_type = 32;
 | 
			
		||||
    pub const CAPSLOCK: modifier_type = 64;
 | 
			
		||||
    pub const NUMLOCK: modifier_type = 128;
 | 
			
		||||
};
 | 
			
		||||
pub const modifier_type = u32;
 | 
			
		||||
/// Does this key represent input?
 | 
			
		||||
pub fn is_non_input_key(w: Key) bool {
 | 
			
		||||
    return switch (w) {
 | 
			
		||||
        vaxis.Key.insert...vaxis.Key.iso_level_5_shift => true,
 | 
			
		||||
        vaxis.Key.enter => true,
 | 
			
		||||
        vaxis.Key.tab => true,
 | 
			
		||||
        vaxis.Key.escape => true,
 | 
			
		||||
        vaxis.Key.backspace => true,
 | 
			
		||||
        else => false,
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub const event_type = struct {
 | 
			
		||||
    pub const PRESS: usize = 1;
 | 
			
		||||
    pub const REPEAT: usize = 2;
 | 
			
		||||
    pub const RELEASE: usize = 3;
 | 
			
		||||
pub const ModSet = vaxis.Key.Modifiers;
 | 
			
		||||
pub const Mods = u8;
 | 
			
		||||
 | 
			
		||||
pub const mod = struct {
 | 
			
		||||
    pub const shift: u8 = @bitCast(ModSet{ .shift = true });
 | 
			
		||||
    pub const alt: u8 = @bitCast(ModSet{ .alt = true });
 | 
			
		||||
    pub const ctrl: u8 = @bitCast(ModSet{ .ctrl = true });
 | 
			
		||||
    pub const super: u8 = @bitCast(ModSet{ .super = true });
 | 
			
		||||
    pub const caps_lock: u8 = @bitCast(ModSet{ .caps_lock = true });
 | 
			
		||||
    pub const num_lock: u8 = @bitCast(ModSet{ .num_lock = true });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub const Event = u8;
 | 
			
		||||
pub const event = struct {
 | 
			
		||||
    pub const press: Event = 1;
 | 
			
		||||
    pub const repeat: Event = 2;
 | 
			
		||||
    pub const release: Event = 3;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub fn ucs32_to_utf8(ucs32: []const u32, utf8: []u8) !usize {
 | 
			
		||||
    return @intCast(try utf8Encode(@intCast(ucs32[0]), utf8));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub const utils = struct {
 | 
			
		||||
    pub fn isSuper(modifiers: u32) bool {
 | 
			
		||||
        return modifiers & modifier.SUPER != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn isCtrl(modifiers: u32) bool {
 | 
			
		||||
        return modifiers & modifier.CTRL != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn isShift(modifiers: u32) bool {
 | 
			
		||||
        return modifiers & modifier.SHIFT != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn isAlt(modifiers: u32) bool {
 | 
			
		||||
        return modifiers & modifier.ALT != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn key_id_string(k: u32) []const u8 {
 | 
			
		||||
    pub fn key_id_string(k: Key) []const u8 {
 | 
			
		||||
        return switch (k) {
 | 
			
		||||
            key.ENTER => "enter",
 | 
			
		||||
            key.TAB => "tab",
 | 
			
		||||
            key.ESC => "esc",
 | 
			
		||||
            key.SPACE => "space",
 | 
			
		||||
            key.BACKSPACE => "backspace",
 | 
			
		||||
            key.INS => "ins",
 | 
			
		||||
            key.DEL => "del",
 | 
			
		||||
            key.LEFT => "left",
 | 
			
		||||
            key.RIGHT => "right",
 | 
			
		||||
            key.UP => "up",
 | 
			
		||||
            key.DOWN => "down",
 | 
			
		||||
            key.PGDOWN => "pgdown",
 | 
			
		||||
            key.PGUP => "pgup",
 | 
			
		||||
            key.HOME => "home",
 | 
			
		||||
            key.END => "end",
 | 
			
		||||
            key.CAPS_LOCK => "caps_lock",
 | 
			
		||||
            key.SCROLL_LOCK => "scroll_lock",
 | 
			
		||||
            key.NUM_LOCK => "num_lock",
 | 
			
		||||
            key.PRINT_SCREEN => "print_screen",
 | 
			
		||||
            key.PAUSE => "pause",
 | 
			
		||||
            key.MENU => "menu",
 | 
			
		||||
            key.F01 => "f01",
 | 
			
		||||
            key.F02 => "f02",
 | 
			
		||||
            key.F03 => "f03",
 | 
			
		||||
            key.F04 => "f04",
 | 
			
		||||
            key.F05 => "f05",
 | 
			
		||||
            key.F06 => "f06",
 | 
			
		||||
            key.F07 => "f07",
 | 
			
		||||
            key.F08 => "f08",
 | 
			
		||||
            key.F09 => "f09",
 | 
			
		||||
            key.F10 => "f10",
 | 
			
		||||
            key.F11 => "f11",
 | 
			
		||||
            key.F12 => "f12",
 | 
			
		||||
            key.F13 => "f13",
 | 
			
		||||
            key.F14 => "f14",
 | 
			
		||||
            key.F15 => "f15",
 | 
			
		||||
            key.F16 => "f16",
 | 
			
		||||
            key.F17 => "f17",
 | 
			
		||||
            key.F18 => "f18",
 | 
			
		||||
            key.F19 => "f19",
 | 
			
		||||
            key.F20 => "f20",
 | 
			
		||||
            key.F21 => "f21",
 | 
			
		||||
            key.F22 => "f22",
 | 
			
		||||
            key.F23 => "f23",
 | 
			
		||||
            key.F24 => "f24",
 | 
			
		||||
            key.F25 => "f25",
 | 
			
		||||
            key.F26 => "f26",
 | 
			
		||||
            key.F27 => "f27",
 | 
			
		||||
            key.F28 => "f28",
 | 
			
		||||
            key.F29 => "f29",
 | 
			
		||||
            key.F30 => "f30",
 | 
			
		||||
            key.F31 => "f31",
 | 
			
		||||
            key.F32 => "f32",
 | 
			
		||||
            key.F33 => "f33",
 | 
			
		||||
            key.F34 => "f34",
 | 
			
		||||
            key.F35 => "f35",
 | 
			
		||||
            key.MEDIA_PLAY => "media_play",
 | 
			
		||||
            key.MEDIA_PAUSE => "media_pause",
 | 
			
		||||
            key.MEDIA_PPAUSE => "media_ppause",
 | 
			
		||||
            key.MEDIA_REV => "media_rev",
 | 
			
		||||
            key.MEDIA_STOP => "media_stop",
 | 
			
		||||
            key.MEDIA_FF => "media_ff",
 | 
			
		||||
            key.MEDIA_REWIND => "media_rewind",
 | 
			
		||||
            key.MEDIA_NEXT => "media_next",
 | 
			
		||||
            key.MEDIA_PREV => "media_prev",
 | 
			
		||||
            key.MEDIA_RECORD => "media_record",
 | 
			
		||||
            key.MEDIA_LVOL => "media_lvol",
 | 
			
		||||
            key.MEDIA_RVOL => "media_rvol",
 | 
			
		||||
            key.MEDIA_MUTE => "media_mute",
 | 
			
		||||
            key.LSHIFT => "lshift",
 | 
			
		||||
            key.LCTRL => "lctrl",
 | 
			
		||||
            key.LALT => "lalt",
 | 
			
		||||
            key.LSUPER => "lsuper",
 | 
			
		||||
            key.LHYPER => "lhyper",
 | 
			
		||||
            key.LMETA => "lmeta",
 | 
			
		||||
            key.RSHIFT => "rshift",
 | 
			
		||||
            key.RCTRL => "rctrl",
 | 
			
		||||
            key.RALT => "ralt",
 | 
			
		||||
            key.RSUPER => "rsuper",
 | 
			
		||||
            key.RHYPER => "rhyper",
 | 
			
		||||
            key.RMETA => "rmeta",
 | 
			
		||||
            key.L3SHIFT => "l3shift",
 | 
			
		||||
            key.L5SHIFT => "l5shift",
 | 
			
		||||
            vaxis.Key.enter => "enter",
 | 
			
		||||
            vaxis.Key.tab => "tab",
 | 
			
		||||
            vaxis.Key.escape => "escape",
 | 
			
		||||
            vaxis.Key.space => "space",
 | 
			
		||||
            vaxis.Key.backspace => "backspace",
 | 
			
		||||
            vaxis.Key.insert => "insert",
 | 
			
		||||
            vaxis.Key.delete => "delete",
 | 
			
		||||
            vaxis.Key.left => "left",
 | 
			
		||||
            vaxis.Key.right => "right",
 | 
			
		||||
            vaxis.Key.up => "up",
 | 
			
		||||
            vaxis.Key.down => "down",
 | 
			
		||||
            vaxis.Key.page_down => "page_down",
 | 
			
		||||
            vaxis.Key.page_up => "page_up",
 | 
			
		||||
            vaxis.Key.home => "home",
 | 
			
		||||
            vaxis.Key.end => "end",
 | 
			
		||||
            vaxis.Key.caps_lock => "caps_lock",
 | 
			
		||||
            vaxis.Key.scroll_lock => "scroll_lock",
 | 
			
		||||
            vaxis.Key.num_lock => "num_lock",
 | 
			
		||||
            vaxis.Key.print_screen => "print_screen",
 | 
			
		||||
            vaxis.Key.pause => "pause",
 | 
			
		||||
            vaxis.Key.menu => "menu",
 | 
			
		||||
            vaxis.Key.f1 => "f1",
 | 
			
		||||
            vaxis.Key.f2 => "f2",
 | 
			
		||||
            vaxis.Key.f3 => "f3",
 | 
			
		||||
            vaxis.Key.f4 => "f4",
 | 
			
		||||
            vaxis.Key.f5 => "f5",
 | 
			
		||||
            vaxis.Key.f6 => "f6",
 | 
			
		||||
            vaxis.Key.f7 => "f7",
 | 
			
		||||
            vaxis.Key.f8 => "f8",
 | 
			
		||||
            vaxis.Key.f9 => "f9",
 | 
			
		||||
            vaxis.Key.f10 => "f10",
 | 
			
		||||
            vaxis.Key.f11 => "f11",
 | 
			
		||||
            vaxis.Key.f12 => "f12",
 | 
			
		||||
            vaxis.Key.f13 => "f13",
 | 
			
		||||
            vaxis.Key.f14 => "f14",
 | 
			
		||||
            vaxis.Key.f15 => "f15",
 | 
			
		||||
            vaxis.Key.f16 => "f16",
 | 
			
		||||
            vaxis.Key.f17 => "f17",
 | 
			
		||||
            vaxis.Key.f18 => "f18",
 | 
			
		||||
            vaxis.Key.f19 => "f19",
 | 
			
		||||
            vaxis.Key.f20 => "f20",
 | 
			
		||||
            vaxis.Key.f21 => "f21",
 | 
			
		||||
            vaxis.Key.f22 => "f22",
 | 
			
		||||
            vaxis.Key.f23 => "f23",
 | 
			
		||||
            vaxis.Key.f24 => "f24",
 | 
			
		||||
            vaxis.Key.f25 => "f25",
 | 
			
		||||
            vaxis.Key.f26 => "f26",
 | 
			
		||||
            vaxis.Key.f27 => "f27",
 | 
			
		||||
            vaxis.Key.f28 => "f28",
 | 
			
		||||
            vaxis.Key.f29 => "f29",
 | 
			
		||||
            vaxis.Key.f30 => "f30",
 | 
			
		||||
            vaxis.Key.f31 => "f31",
 | 
			
		||||
            vaxis.Key.f32 => "f32",
 | 
			
		||||
            vaxis.Key.f33 => "f33",
 | 
			
		||||
            vaxis.Key.f34 => "f34",
 | 
			
		||||
            vaxis.Key.f35 => "f35",
 | 
			
		||||
            vaxis.Key.media_play => "media_play",
 | 
			
		||||
            vaxis.Key.media_pause => "media_pause",
 | 
			
		||||
            vaxis.Key.media_play_pause => "media_play_pause",
 | 
			
		||||
            vaxis.Key.media_reverse => "media_reverse",
 | 
			
		||||
            vaxis.Key.media_stop => "media_stop",
 | 
			
		||||
            vaxis.Key.media_fast_forward => "media_fast_forward",
 | 
			
		||||
            vaxis.Key.media_rewind => "media_rewind",
 | 
			
		||||
            vaxis.Key.media_track_next => "media_track_next",
 | 
			
		||||
            vaxis.Key.media_track_previous => "media_track_previous",
 | 
			
		||||
            vaxis.Key.media_record => "media_record",
 | 
			
		||||
            vaxis.Key.lower_volume => "lower_volume",
 | 
			
		||||
            vaxis.Key.raise_volume => "raise_volume",
 | 
			
		||||
            vaxis.Key.mute_volume => "mute_volume",
 | 
			
		||||
            vaxis.Key.left_shift => "left_shift",
 | 
			
		||||
            vaxis.Key.left_control => "left_control",
 | 
			
		||||
            vaxis.Key.left_alt => "left_alt",
 | 
			
		||||
            vaxis.Key.left_super => "left_super",
 | 
			
		||||
            vaxis.Key.left_hyper => "left_hyper",
 | 
			
		||||
            vaxis.Key.left_meta => "left_meta",
 | 
			
		||||
            vaxis.Key.right_shift => "right_shift",
 | 
			
		||||
            vaxis.Key.right_control => "right_control",
 | 
			
		||||
            vaxis.Key.right_alt => "right_alt",
 | 
			
		||||
            vaxis.Key.right_super => "right_super",
 | 
			
		||||
            vaxis.Key.right_hyper => "right_hyper",
 | 
			
		||||
            vaxis.Key.right_meta => "right_meta",
 | 
			
		||||
            vaxis.Key.iso_level_3_shift => "iso_level_3_shift",
 | 
			
		||||
            vaxis.Key.iso_level_5_shift => "iso_level_5_shift",
 | 
			
		||||
            else => "",
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn button_id_string(k: u32) []const u8 {
 | 
			
		||||
        return switch (k) {
 | 
			
		||||
            key.MOTION => "motion",
 | 
			
		||||
            key.BUTTON1 => "button1",
 | 
			
		||||
            key.BUTTON2 => "button2",
 | 
			
		||||
            key.BUTTON3 => "button3",
 | 
			
		||||
            key.BUTTON4 => "button4",
 | 
			
		||||
            key.BUTTON5 => "button5",
 | 
			
		||||
            // key.BUTTON6 => "button6",
 | 
			
		||||
            // key.BUTTON7 => "button7",
 | 
			
		||||
            key.BUTTON8 => "button8",
 | 
			
		||||
            key.BUTTON9 => "button9",
 | 
			
		||||
            key.BUTTON10 => "button10",
 | 
			
		||||
            key.BUTTON11 => "button11",
 | 
			
		||||
    pub fn button_id_string(m: Mouse) []const u8 {
 | 
			
		||||
        return switch (m) {
 | 
			
		||||
            mouse.MOTION => "motion",
 | 
			
		||||
            mouse.BUTTON1 => "button1",
 | 
			
		||||
            mouse.BUTTON2 => "button2",
 | 
			
		||||
            mouse.BUTTON3 => "button3",
 | 
			
		||||
            mouse.BUTTON4 => "button4",
 | 
			
		||||
            mouse.BUTTON5 => "button5",
 | 
			
		||||
            // mouse.BUTTON6 => "button6",
 | 
			
		||||
            // mouse.BUTTON7 => "button7",
 | 
			
		||||
            mouse.BUTTON8 => "button8",
 | 
			
		||||
            mouse.BUTTON9 => "button9",
 | 
			
		||||
            mouse.BUTTON10 => "button10",
 | 
			
		||||
            mouse.BUTTON11 => "button11",
 | 
			
		||||
            else => "",
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,19 +4,15 @@ const log = @import("log");
 | 
			
		|||
const Style = @import("theme").Style;
 | 
			
		||||
const Color = @import("theme").Color;
 | 
			
		||||
const vaxis = @import("vaxis");
 | 
			
		||||
const input = @import("input");
 | 
			
		||||
const builtin = @import("builtin");
 | 
			
		||||
 | 
			
		||||
pub const input = @import("input.zig");
 | 
			
		||||
 | 
			
		||||
pub const Plane = @import("Plane.zig");
 | 
			
		||||
pub const Cell = @import("Cell.zig");
 | 
			
		||||
pub const CursorShape = vaxis.Cell.CursorShape;
 | 
			
		||||
 | 
			
		||||
pub const style = @import("style.zig").StyleBits;
 | 
			
		||||
 | 
			
		||||
const key = input.key;
 | 
			
		||||
const event_type = input.event_type;
 | 
			
		||||
 | 
			
		||||
const Self = @This();
 | 
			
		||||
pub const log_name = "vaxis";
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -158,7 +154,7 @@ pub fn process_input_event(self: *Self, input_: []const u8, text: ?[]const u8) !
 | 
			
		|||
            try self.sync_mod_state(key_.codepoint, key_.mods);
 | 
			
		||||
            const cbor_msg = try self.fmtmsg(.{
 | 
			
		||||
                "I",
 | 
			
		||||
                event_type.PRESS,
 | 
			
		||||
                input.event.press,
 | 
			
		||||
                key_.codepoint,
 | 
			
		||||
                key_.shifted_codepoint orelse key_.codepoint,
 | 
			
		||||
                text orelse input.utils.key_id_string(key_.base_layout_codepoint orelse key_.codepoint),
 | 
			
		||||
| 
						 | 
				
			
			@ -172,7 +168,7 @@ pub fn process_input_event(self: *Self, input_: []const u8, text: ?[]const u8) !
 | 
			
		|||
            const key_ = filter_mods(key__);
 | 
			
		||||
            const cbor_msg = try self.fmtmsg(.{
 | 
			
		||||
                "I",
 | 
			
		||||
                event_type.RELEASE,
 | 
			
		||||
                input.event.release,
 | 
			
		||||
                key_.codepoint,
 | 
			
		||||
                key_.shifted_codepoint orelse key_.codepoint,
 | 
			
		||||
                text orelse input.utils.key_id_string(key_.base_layout_codepoint orelse key_.codepoint),
 | 
			
		||||
| 
						 | 
				
			
			@ -193,9 +189,9 @@ pub fn process_input_event(self: *Self, input_: []const u8, text: ?[]const u8) !
 | 
			
		|||
                })),
 | 
			
		||||
                .press => f(self.handler_ctx, @intCast(mouse.row), @intCast(mouse.col), try self.fmtmsg(.{
 | 
			
		||||
                    "B",
 | 
			
		||||
                    event_type.PRESS,
 | 
			
		||||
                    input.event.press,
 | 
			
		||||
                    @intFromEnum(mouse.button),
 | 
			
		||||
                    input.utils.button_id_string(@intFromEnum(mouse.button)),
 | 
			
		||||
                    input.utils.button_id_string(mouse.button),
 | 
			
		||||
                    mouse.col,
 | 
			
		||||
                    mouse.row,
 | 
			
		||||
                    mouse.xoffset,
 | 
			
		||||
| 
						 | 
				
			
			@ -203,9 +199,9 @@ pub fn process_input_event(self: *Self, input_: []const u8, text: ?[]const u8) !
 | 
			
		|||
                })),
 | 
			
		||||
                .release => f(self.handler_ctx, @intCast(mouse.row), @intCast(mouse.col), try self.fmtmsg(.{
 | 
			
		||||
                    "B",
 | 
			
		||||
                    event_type.RELEASE,
 | 
			
		||||
                    input.event.release,
 | 
			
		||||
                    @intFromEnum(mouse.button),
 | 
			
		||||
                    input.utils.button_id_string(@intFromEnum(mouse.button)),
 | 
			
		||||
                    input.utils.button_id_string(mouse.button),
 | 
			
		||||
                    mouse.col,
 | 
			
		||||
                    mouse.row,
 | 
			
		||||
                    mouse.xoffset,
 | 
			
		||||
| 
						 | 
				
			
			@ -214,9 +210,9 @@ pub fn process_input_event(self: *Self, input_: []const u8, text: ?[]const u8) !
 | 
			
		|||
                .drag => if (self.dispatch_mouse_drag) |f_|
 | 
			
		||||
                    f_(self.handler_ctx, @intCast(mouse.row), @intCast(mouse.col), try self.fmtmsg(.{
 | 
			
		||||
                        "D",
 | 
			
		||||
                        event_type.PRESS,
 | 
			
		||||
                        input.event.press,
 | 
			
		||||
                        @intFromEnum(mouse.button),
 | 
			
		||||
                        input.utils.button_id_string(@intFromEnum(mouse.button)),
 | 
			
		||||
                        input.utils.button_id_string(mouse.button),
 | 
			
		||||
                        mouse.col,
 | 
			
		||||
                        mouse.row,
 | 
			
		||||
                        mouse.xoffset,
 | 
			
		||||
| 
						 | 
				
			
			@ -282,19 +278,19 @@ fn fmtmsg(self: *Self, value: anytype) ![]const u8 {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
fn handle_bracketed_paste_input(self: *Self, cbor_msg: []const u8) !bool {
 | 
			
		||||
    var keypress: u32 = undefined;
 | 
			
		||||
    var egc_: u32 = undefined;
 | 
			
		||||
    var keypress: input.Key = undefined;
 | 
			
		||||
    var egc_: input.Key = undefined;
 | 
			
		||||
    if (try cbor.match(cbor_msg, .{ "I", cbor.number, cbor.extract(&keypress), cbor.extract(&egc_), cbor.string, 0 })) {
 | 
			
		||||
        switch (keypress) {
 | 
			
		||||
            key.ENTER => try self.bracketed_paste_buffer.appendSlice("\n"),
 | 
			
		||||
            key.TAB => try self.bracketed_paste_buffer.appendSlice("\t"),
 | 
			
		||||
            else => if (!key.synthesized_p(keypress)) {
 | 
			
		||||
            input.key.enter => try self.bracketed_paste_buffer.appendSlice("\n"),
 | 
			
		||||
            input.key.tab => try self.bracketed_paste_buffer.appendSlice("\t"),
 | 
			
		||||
            else => if (!input.is_non_input_key(keypress)) {
 | 
			
		||||
                var buf: [6]u8 = undefined;
 | 
			
		||||
                const bytes = try ucs32_to_utf8(&[_]u32{egc_}, &buf);
 | 
			
		||||
                const bytes = try input.ucs32_to_utf8(&[_]u32{egc_}, &buf);
 | 
			
		||||
                try self.bracketed_paste_buffer.appendSlice(buf[0..bytes]);
 | 
			
		||||
            } else {
 | 
			
		||||
                var buf: [6]u8 = undefined;
 | 
			
		||||
                const bytes = try ucs32_to_utf8(&[_]u32{egc_}, &buf);
 | 
			
		||||
                const bytes = try input.ucs32_to_utf8(&[_]u32{egc_}, &buf);
 | 
			
		||||
                self.logger.print("unexpected codepoint in paste: {d} {s}", .{ keypress, buf[0..bytes] });
 | 
			
		||||
            },
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -336,7 +332,7 @@ pub fn set_terminal_style(self: *Self, style_: Style) void {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
pub fn set_terminal_cursor_color(self: *Self, color: Color) void {
 | 
			
		||||
        self.vx.setTerminalCursorColor(self.tty.anyWriter(), vaxis.Cell.Color.rgbFromUint(@intCast(color.color)).rgb) catch {};
 | 
			
		||||
    self.vx.setTerminalCursorColor(self.tty.anyWriter(), vaxis.Cell.Color.rgbFromUint(@intCast(color.color)).rgb) catch {};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn set_terminal_working_directory(self: *Self, absolute_path: []const u8) void {
 | 
			
		||||
| 
						 | 
				
			
			@ -376,32 +372,28 @@ pub fn cursor_disable(self: *Self) void {
 | 
			
		|||
    self.vx.screen.cursor_vis = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn ucs32_to_utf8(ucs32: []const u32, utf8: []u8) !usize {
 | 
			
		||||
    return @intCast(try std.unicode.utf8Encode(@intCast(ucs32[0]), utf8));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn sync_mod_state(self: *Self, keypress: u32, modifiers: vaxis.Key.Modifiers) !void {
 | 
			
		||||
    if (modifiers.ctrl and !self.mods.ctrl and !(keypress == key.LCTRL or keypress == key.RCTRL))
 | 
			
		||||
        try self.send_sync_key(event_type.PRESS, key.LCTRL, "lctrl", modifiers);
 | 
			
		||||
    if (!modifiers.ctrl and self.mods.ctrl and !(keypress == key.LCTRL or keypress == key.RCTRL))
 | 
			
		||||
        try self.send_sync_key(event_type.RELEASE, key.LCTRL, "lctrl", modifiers);
 | 
			
		||||
    if (modifiers.alt and !self.mods.alt and !(keypress == key.LALT or keypress == key.RALT))
 | 
			
		||||
        try self.send_sync_key(event_type.PRESS, key.LALT, "lalt", modifiers);
 | 
			
		||||
    if (!modifiers.alt and self.mods.alt and !(keypress == key.LALT or keypress == key.RALT))
 | 
			
		||||
        try self.send_sync_key(event_type.RELEASE, key.LALT, "lalt", modifiers);
 | 
			
		||||
    if (modifiers.shift and !self.mods.shift and !(keypress == key.LSHIFT or keypress == key.RSHIFT))
 | 
			
		||||
        try self.send_sync_key(event_type.PRESS, key.LSHIFT, "lshift", modifiers);
 | 
			
		||||
    if (!modifiers.shift and self.mods.shift and !(keypress == key.LSHIFT or keypress == key.RSHIFT))
 | 
			
		||||
        try self.send_sync_key(event_type.RELEASE, key.LSHIFT, "lshift", modifiers);
 | 
			
		||||
    if (modifiers.ctrl and !self.mods.ctrl and !(keypress == input.key.left_control or keypress == input.key.right_control))
 | 
			
		||||
        try self.send_sync_key(input.event.press, input.key.left_control, "lctrl", modifiers);
 | 
			
		||||
    if (!modifiers.ctrl and self.mods.ctrl and !(keypress == input.key.left_control or keypress == input.key.right_control))
 | 
			
		||||
        try self.send_sync_key(input.event.release, input.key.left_control, "lctrl", modifiers);
 | 
			
		||||
    if (modifiers.alt and !self.mods.alt and !(keypress == input.key.left_alt or keypress == input.key.right_alt))
 | 
			
		||||
        try self.send_sync_key(input.event.press, input.key.left_alt, "lalt", modifiers);
 | 
			
		||||
    if (!modifiers.alt and self.mods.alt and !(keypress == input.key.left_alt or keypress == input.key.right_alt))
 | 
			
		||||
        try self.send_sync_key(input.event.release, input.key.left_alt, "lalt", modifiers);
 | 
			
		||||
    if (modifiers.shift and !self.mods.shift and !(keypress == input.key.left_shift or keypress == input.key.right_shift))
 | 
			
		||||
        try self.send_sync_key(input.event.press, input.key.left_shift, "lshift", modifiers);
 | 
			
		||||
    if (!modifiers.shift and self.mods.shift and !(keypress == input.key.left_shift or keypress == input.key.right_shift))
 | 
			
		||||
        try self.send_sync_key(input.event.release, input.key.left_shift, "lshift", modifiers);
 | 
			
		||||
    self.mods = modifiers;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn send_sync_key(self: *Self, event_type_: usize, keypress: u32, key_string: []const u8, modifiers: vaxis.Key.Modifiers) !void {
 | 
			
		||||
fn send_sync_key(self: *Self, event: input.Event, keypress: u32, key_string: []const u8, modifiers: vaxis.Key.Modifiers) !void {
 | 
			
		||||
    if (self.dispatch_input) |f| f(
 | 
			
		||||
        self.handler_ctx,
 | 
			
		||||
        try self.fmtmsg(.{
 | 
			
		||||
            "I",
 | 
			
		||||
            event_type_,
 | 
			
		||||
            event,
 | 
			
		||||
            keypress,
 | 
			
		||||
            keypress,
 | 
			
		||||
            key_string,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue