Skip to content

Commit

Permalink
events: add support for min/max -imize, close events
Browse files Browse the repository at this point in the history
  • Loading branch information
larpon committed Sep 19, 2023
1 parent 6f9d0e8 commit 5174c20
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 13 deletions.
3 changes: 3 additions & 0 deletions embed/embed.v
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ pub fn (mut a EasyApp) event(e shy.Event) {
shy.QuitEvent {
a.shy.shutdown = true
}
shy.WindowCloseEvent {
a.shy.shutdown = true
}
shy.KeyEvent {
if e.state == .up {
return
Expand Down
65 changes: 52 additions & 13 deletions lib/event.v
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ pub type Event = DropBeginEvent
| QuitEvent
| RecordEvent
| UnkownEvent
| WindowCloseEvent
| WindowEvent
| WindowFocusEvent
| WindowHiddenEvent
| WindowMaximizedEvent
| WindowMinimizedEvent
| WindowMoveEvent
| WindowResizeEvent
| WindowShownEvent
Expand All @@ -26,7 +29,8 @@ fn (e Event) serialize_as_playback_string() string {
return match e {
DropBeginEvent, DropEndEvent, DropTextEvent, DropFileEvent, KeyEvent, MouseButtonEvent,
MouseMotionEvent, MouseWheelEvent, QuitEvent, RecordEvent, UnkownEvent, WindowEvent,
WindowFocusEvent, WindowMoveEvent, WindowResizeEvent, WindowShownEvent, WindowHiddenEvent {
WindowMinimizedEvent, WindowMaximizedEvent, WindowFocusEvent, WindowMoveEvent,
WindowCloseEvent, WindowResizeEvent, WindowShownEvent, WindowHiddenEvent {
e.serialize_as_playback_string()
}
}
Expand All @@ -36,9 +40,15 @@ pub enum EventStringSerializeFormat {
playback
}

pub enum WindowFocusEventKind {
pub enum WindowFocusTarget {
keyboard
mouse
}

pub enum WindowFocusKind {
gained
lost
offered
}

[params]
Expand Down Expand Up @@ -173,9 +183,6 @@ fn (ip Input) deserialize_event_from_string(serialized_string string, format Eve
window_id: window_id
}
}
'UnkownEvent' {
empty_event
}
'WindowEvent' {
ip.shy.log.gcritical('${@STRUCT}.${@FN}', 'event ${event_type} not implemented')
empty_event
Expand All @@ -200,6 +207,13 @@ fn (ip Input) deserialize_event_from_string(serialized_string string, format Eve
ip.shy.log.gcritical('${@STRUCT}.${@FN}', 'event ${event_type} not implemented')
empty_event
}
'WindowCloseEvent' {
ip.shy.log.gcritical('${@STRUCT}.${@FN}', 'event ${event_type} not implemented')
empty_event
}
'UnkownEvent' {
empty_event
}
else {
ip.shy.log.gcritical('${@STRUCT}.${@FN}', 'event ${event_type} not implemented')
empty_event
Expand Down Expand Up @@ -256,15 +270,15 @@ pub enum WindowEventKind {
// moved // Window has been moved to data1, data2
// resized // Window has been resized
// size_changed // The window size has changed, either as a result of an API call or through the system or user changing the window size.
minimized // Window has been minimized
maximized // Window has been maximized
// minimized // Window has been minimized
// maximized // Window has been maximized
restored // Window has been restored to normal size and position
enter // Window has gained mouse focus
leave // Window has lost mouse focus
// enter // Window has gained mouse focus
// leave // Window has lost mouse focus
// focus_gained // Window has gained keyboard focus
// focus_lost // Window has lost keyboard focus
close // The window manager requests that the window be closed
take_focus // Window is being offered a focus
// close // The window manager requests that the window be closed
// take_focus // Window is being offered a focus
hit_test // Window had a hit test.
}

Expand All @@ -290,6 +304,14 @@ fn (e WindowMoveEvent) serialize_as_playback_string() string {
return '${e.x},${e.y}'
}

pub struct WindowCloseEvent {
ShyEvent
}

fn (e WindowCloseEvent) serialize_as_playback_string() string {
return ''
}

pub struct WindowShownEvent {
ShyEvent
}
Expand All @@ -309,11 +331,28 @@ fn (e WindowHiddenEvent) serialize_as_playback_string() string {
pub struct WindowFocusEvent {
ShyEvent
pub:
kind WindowFocusEventKind
target WindowFocusTarget
kind WindowFocusKind
}

fn (e WindowFocusEvent) serialize_as_playback_string() string {
return '${e.kind}'
return '${e.target},${e.kind}'
}

pub struct WindowMinimizedEvent {
ShyEvent
}

fn (e WindowMinimizedEvent) serialize_as_playback_string() string {
return ''
}

pub struct WindowMaximizedEvent {
ShyEvent
}

fn (e WindowMaximizedEvent) serialize_as_playback_string() string {
return ''
}

//
Expand Down
44 changes: 44 additions & 0 deletions lib/input.b.v
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,60 @@ fn (ip Input) sdl_to_shy_event(sdl_event sdl.Event) Event {
shy_event = WindowFocusEvent{
timestamp: timestamp
window_id: shy_window_id
target: .keyboard
kind: .gained
}
}
.focus_lost {
shy_event = WindowFocusEvent{
timestamp: timestamp
window_id: shy_window_id
target: .keyboard
kind: .lost
}
}
.enter {
shy_event = WindowFocusEvent{
timestamp: timestamp
window_id: shy_window_id
target: .mouse
kind: .gained
}
}
.leave {
shy_event = WindowFocusEvent{
timestamp: timestamp
window_id: shy_window_id
target: .mouse
kind: .lost
}
}
.take_focus {
shy_event = WindowFocusEvent{
timestamp: timestamp
window_id: shy_window_id
target: .keyboard
kind: .offered
}
}
.minimized {
shy_event = WindowMinimizedEvent{
timestamp: timestamp
window_id: shy_window_id
}
}
.maximized {
shy_event = WindowMaximizedEvent{
timestamp: timestamp
window_id: shy_window_id
}
}
.close {
shy_event = WindowCloseEvent{
timestamp: timestamp
window_id: shy_window_id
}
}
else {
// TODO(lmp) panic('${@STRUCT}.${@FN} TODO implement ${wevid}')
}
Expand Down

0 comments on commit 5174c20

Please sign in to comment.