GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_ev_queue.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2021 Cyril Hrubis <metan@ucw.cz>
4 */
5
6/*
7
8 Event Queue.
9
10 This API is internally used by backends to store input events and is not
11 supposed to be used directly.
12
13 */
14
15#ifndef INPUT_GP_EV_QUEUE_H
16#define INPUT_GP_EV_QUEUE_H
17
18#include <input/gp_ev_feedback.h>
19#include <input/gp_event.h>
20
21#define GP_EVENT_QUEUE_SIZE 32
22
23struct gp_ev_queue {
24 /* screen size */
25 unsigned int screen_w;
26 unsigned int screen_h;
27
28 /* Cursor position valid for the last event in the queue */
29 uint32_t cursor_x;
30 uint32_t cursor_y;
31
32 /* event queue */
33 unsigned int queue_first;
34 unsigned int queue_last;
35 unsigned int queue_size;
36
37 /* keymap needed only for framebuffer */
38 gp_keymap *keymap;
39
40 /* list of callbacks to turn on/off leds and other feedback */
41 gp_ev_feedback *feedbacks_list;
42
43 /*
44 * Accumulated state, pressed keys, cursor position, etc.
45 *
46 * Valid only for event removed by the last gp_ev_queue_get().
47 */
48 gp_events_state state;
49
50 gp_event events[GP_EVENT_QUEUE_SIZE];
51};
52
53enum gp_ev_queue_flags {
54 GP_EVENT_QUEUE_LOAD_KEYMAP = 0x01,
55};
56
57/*
58 * Initializes event queue passed as a pointer. The events array must be
59 * queue_size long.
60 *
61 * If queue_size is set to zero, default value is expected.
62 */
63void gp_ev_queue_init(gp_ev_queue *self,
64 unsigned int screen_w, unsigned int screen_h,
65 unsigned int queue_size, int flags);
66
67/*
68 * Sets screen (window) size.
69 */
70void gp_ev_queue_set_screen_size(gp_ev_queue *self,
71 unsigned int w, unsigned int h);
72
79static inline void gp_ev_queue_feedback_register(gp_ev_queue *self, gp_ev_feedback *feedback)
80{
81 gp_ev_feedback_register(&self->feedbacks_list, feedback);
82}
83
90static inline void gp_ev_queue_feedback_unregister(gp_ev_queue *self, gp_ev_feedback *feedback)
91{
92 gp_ev_feedback_unregister(&self->feedbacks_list, feedback);
93}
94
101static inline void gp_ev_queue_feedback_set_all(gp_ev_queue *self, gp_ev_feedback_op *op)
102{
103 gp_ev_feedback_set_all(self->feedbacks_list, op);
104}
105
106/*
107 * Sets cursor postion.
108 */
109void gp_ev_queue_set_cursor_pos(gp_ev_queue *self,
110 unsigned int x, unsigned int y);
111
112/*
113 * Returns number of events queued in the queue.
114 */
115unsigned int gp_ev_queue_events(gp_ev_queue *self);
116
123static inline int gp_ev_queue_full(gp_ev_queue *self)
124{
125 unsigned int next = (self->queue_last + 1) % self->queue_size;
126
127 return next == self->queue_first;
128}
129
130/*
131 * In case there are any events queued a pointer to a top event in the queue is
132 * returned. The pointer is valid until next call to gp_ev_queue_get().
133 *
134 * The pointer is also invalidated by a call to gp_ev_queue_put_back().
135 *
136 * If there are no events queued the call returns NULL.
137 */
138gp_event *gp_ev_queue_get(gp_ev_queue *self);
139
140/*
141 * Same as gp_ev_queue_get() but the event is not removed from the queue.
142 * The pointer is valid until a call to gp_ev_queue_get().
143 *
144 * If there are no events queued the calll returns NULL.
145 *
146 * The keyboard state bitmask is _NOT_ modified.
147 */
148gp_event *gp_ev_queue_peek(gp_ev_queue *self);
149
150/*
151 * Puts the event in the queue.
152 *
153 * This is bare call that just copies the event into the queue. Use the calls
154 * below instead.
155 */
156void gp_ev_queue_put(gp_ev_queue *self, gp_event *ev);
157
158/*
159 * Puts event to the top of the queue, i.e. this event is going to be returned
160 * by a next call to gp_ev_queue_get().
161 */
162void gp_ev_queue_put_back(gp_ev_queue *self, gp_event *ev);
163
164struct timeval;
165
166/*
167 * Inject event that moves cursor by rx and ry.
168 *
169 * If timeval is NULL, current time is used.
170 */
171void gp_ev_queue_push_rel(gp_ev_queue *self,
172 int32_t rx, int32_t ry, uint64_t time);
173
174/*
175 * Produces relative event that moves cursor to the point x, y.
176 *
177 * If timeval is NULL, current time is used.
178 */
179void gp_ev_queue_push_rel_to(gp_ev_queue *self,
180 uint32_t x, uint32_t y, uint64_t time);
181
182/*
183 * Inject absolute event.
184 *
185 * If timeval is NULL, current time is used.
186 */
187void gp_ev_queue_push_abs(gp_ev_queue *self,
188 uint32_t x, uint32_t y, uint32_t pressure,
189 uint32_t x_max, uint32_t y_max, uint32_t pressure_max,
190 uint64_t time);
191
192/*
193 * Inject event that changes key state (i.e. press, release, repeat).
194 *
195 * @key Physical key pressed on keyboard
196 * @code Action press/release/repeat
197 * @utf An UTF32 mapping, if available, pass zero if none
198 * @timeval A timestamp; if NULL current time is used
199 */
200void gp_ev_queue_push_key(gp_ev_queue *self,
201 uint32_t key, uint8_t code,
202 uint64_t time);
203
211void gp_ev_queue_push_utf(gp_ev_queue *self, uint32_t utf_ch,
212 uint64_t time);
213
214/*
215 * Inject window resize event
216 */
217void gp_ev_queue_push_resize(gp_ev_queue *self,
218 uint32_t w, uint32_t h, uint64_t time);
219
220/*
221 * Inject common event.
222 */
223void gp_ev_queue_push(gp_ev_queue *self,
224 uint16_t type, uint32_t code, int32_t value,
225 uint64_t time);
226
227/*
228 * Pushes mouse wheel movement.
229 */
230static inline void gp_ev_queue_push_wheel(gp_ev_queue *self,
231 int32_t val, uint64_t time)
232{
233 gp_ev_queue_push(self, GP_EV_REL, GP_EV_REL_WHEEL, val, time);
234}
235
236#endif /* INPUT_GP_EV_QUEUE_H */