Skip to content

Commit

Permalink
event: add generic IntEvent that can be generated with `send_int_ev…
Browse files Browse the repository at this point in the history
…ent/2`
  • Loading branch information
larpon committed May 5, 2024
1 parent 85f2879 commit ed93c32
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/event.b.v
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ fn (mut e Events) send_record_event() {
}) or { panic('${@STRUCT}.${@FN}: send failed: ${err}') }
}

// send_int_event sends an IntEvent
pub fn (mut e Events) send_int_event(id int, value int) {
e.send(IntEvent{
timestamp: e.shy.ticks()
window_id: e.shy.wm().active_window_id()
id: id
value: value
}) or { panic('${@STRUCT}.${@FN}: send failed: ${err}') }
}

// import sdl
// import manymouse as mm

Expand Down
22 changes: 21 additions & 1 deletion lib/event.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub type Event = DropBeginEvent
| GamepadSensorUpdateEvent
| GamepadTouchpadButtonEvent
| GamepadTouchpadMotionEvent
| IntEvent
| KeyEvent
| MouseButtonEvent
| MouseMotionEvent
Expand All @@ -37,7 +38,7 @@ fn (e Event) serialize_as_playback_string() string {
return match e {
DropBeginEvent, DropEndEvent, DropTextEvent, GamepadAddedEvent, GamepadAxisMotionEvent,
GamepadButtonEvent, GamepadRemappedEvent, GamepadRemovedEvent, GamepadSensorUpdateEvent,
GamepadTouchpadButtonEvent, GamepadTouchpadMotionEvent, DropFileEvent, KeyEvent,
GamepadTouchpadButtonEvent, GamepadTouchpadMotionEvent, DropFileEvent, IntEvent, KeyEvent,
MouseButtonEvent, MouseMotionEvent, MouseWheelEvent, QuitEvent, RecordEvent, UnkownEvent,
WindowEvent, WindowMinimizedEvent, WindowMaximizedEvent, WindowFocusEvent, WindowMoveEvent,
WindowCloseEvent, WindowResizeEvent, WindowShownEvent, WindowHiddenEvent {
Expand Down Expand Up @@ -133,6 +134,14 @@ fn (ip Input) deserialize_event_from_string(serialized_string string, format Eve
path: split[offset]
}
}
'IntEvent' {
IntEvent{
timestamp: timestamp
window_id: window_id
id: split[offset].int()
value: split[offset + 1].int()
}
}
'KeyEvent' {
KeyEvent{
timestamp: timestamp
Expand Down Expand Up @@ -249,6 +258,17 @@ fn (e UnkownEvent) serialize_as_playback_string() string {
return ''
}

pub struct IntEvent {
ShyEvent
pub:
id int
value int
}

fn (e IntEvent) serialize_as_playback_string() string {
return '${e.id},${e.value}'
}

pub struct KeyEvent {
ShyEvent
pub:
Expand Down

0 comments on commit ed93c32

Please sign in to comment.