diff options
author | Mattias Andrée <m@maandree.se> | 2025-02-20 20:24:28 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-02-20 20:24:28 +0100 |
commit | 4c745dab4c6925fa17714c2214ed5941e5cbf64d (patch) | |
tree | 30129b2838d7a27a7a37fd37f5f95d6b355b7203 /libterminput_unmarshal_mouseevent__.c | |
parent | Add state marshalling and unmarshalling functions (diff) | |
download | libterminput-4c745dab4c6925fa17714c2214ed5941e5cbf64d.tar.gz libterminput-4c745dab4c6925fa17714c2214ed5941e5cbf64d.tar.bz2 libterminput-4c745dab4c6925fa17714c2214ed5941e5cbf64d.tar.xz |
Validate unmarshalled state + add man pages for (un)marshal functions
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libterminput_unmarshal_mouseevent__.c')
-rw-r--r-- | libterminput_unmarshal_mouseevent__.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/libterminput_unmarshal_mouseevent__.c b/libterminput_unmarshal_mouseevent__.c index 55f72ea..f91b606 100644 --- a/libterminput_unmarshal_mouseevent__.c +++ b/libterminput_unmarshal_mouseevent__.c @@ -3,7 +3,7 @@ int -libterminput_unmarshal_mouseevent__(struct libterminput_unmarshaller *how, struct libterminput_mouseevent *what) +libterminput_unmarshal_mouseevent__(struct libterminput_unmarshaller *how, struct libterminput_mouseevent *what) /* TODO test */ { what->type = LIBTERMINPUT_MOUSEEVENT; if (how->load(how, &what->event, sizeof(what->event)) || @@ -11,13 +11,20 @@ libterminput_unmarshal_mouseevent__(struct libterminput_unmarshaller *how, struc return -1; what->mods = 0; what->button = LIBTERMINPUT_BUTTON1; - if (what->event == LIBTERMINPUT_HIGHLIGHT_OUTSIDE) { - if (how->load(how, &what->start_x, sizeof(size_t) * 4U)) - return -1; - } else if (what->event != LIBTERMINPUT_HIGHLIGHT_INSIDE) { + switch ((int)what->event) { + case LIBTERMINPUT_PRESS: + case LIBTERMINPUT_RELEASE: + case LIBTERMINPUT_MOTION: if (how->load(how, &what->mods, sizeof(what->mods)) || how->load(how, &what->button, sizeof(what->button))) return -1; + /* fall through */ + case LIBTERMINPUT_HIGHLIGHT_INSIDE: + return 0; + case LIBTERMINPUT_HIGHLIGHT_OUTSIDE: + return how->load(how, &what->start_x, sizeof(size_t) * 4U); + default: + errno = EINVAL; + return -1; } - return 0; } |