GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
gp_ev_queue.h File Reference

Event Queue. More...

#include <input/gp_ev_feedback.h>
#include <input/gp_event.h>

Go to the source code of this file.

Data Structures

struct  gp_ev_queue
 An event queue. More...
 

Macros

#define GP_EVENT_QUEUE_SIZE   32
 Maximal number of events the queue can hold.
 

Enumerations

enum  gp_ev_queue_flags { GP_EVENT_QUEUE_LOAD_KEYMAP = 0x01 }
 An event queue init flags. More...
 

Functions

void gp_ev_queue_init (gp_ev_queue *self, unsigned int screen_w, unsigned int screen_h, unsigned int queue_size, enum gp_ev_queue_flags flags)
 Initializes event queue.
 
void gp_ev_queue_set_screen_size (gp_ev_queue *self, unsigned int w, unsigned int h)
 Sets screen (window) size.
 
static void gp_ev_queue_feedback_register (gp_ev_queue *self, gp_ev_feedback *feedback)
 Registers an input device feedback callback.
 
static void gp_ev_queue_feedback_unregister (gp_ev_queue *self, gp_ev_feedback *feedback)
 Unregisters an input device feedback callback.
 
static void gp_ev_queue_feedback_set_all (gp_ev_queue *self, gp_ev_feedback_op *op)
 Calls a all feedback handlers with a specified value.
 
void gp_ev_queue_set_cursor_pos (gp_ev_queue *self, unsigned int x, unsigned int y)
 Sets a cursor postion.
 
unsigned int gp_ev_queue_events (gp_ev_queue *self)
 Returns number of events queued in the queue.
 
static int gp_ev_queue_full (gp_ev_queue *self)
 Returns true if queue is full.
 
gp_eventgp_ev_queue_get (gp_ev_queue *self)
 Remoes and returns pointer to a top event from the queue.
 
gp_eventgp_ev_queue_peek (gp_ev_queue *self)
 Peeks at a top event from the queue.
 
void gp_ev_queue_put (gp_ev_queue *self, gp_event *ev)
 Pushes an event to the event queue.
 
void gp_ev_queue_put_back (gp_ev_queue *self, gp_event *ev)
 Pushes back an event to the event queue.
 
void gp_ev_queue_push_rel (gp_ev_queue *self, int32_t rx, int32_t ry, uint64_t time)
 Pushes a relative event that moves cursor by rx and ry.
 
void gp_ev_queue_push_rel_to (gp_ev_queue *self, uint32_t x, uint32_t y, uint64_t time)
 Pushes a relative event that moves cursor to the point x, y.
 
void gp_ev_queue_push_abs (gp_ev_queue *self, uint32_t x, uint32_t y, uint32_t pressure, uint32_t x_max, uint32_t y_max, uint32_t pressure_max, uint64_t time)
 Pushes an absolute event into the queue.
 
void gp_ev_queue_push_key (gp_ev_queue *self, uint32_t key, uint8_t code, uint64_t time)
 Pushes a key event into the event queue.
 
void gp_ev_queue_push_utf (gp_ev_queue *self, uint32_t utf_ch, uint64_t time)
 Pushes an unicode character typed on keyboard into the queue.
 
void gp_ev_queue_push_resize (gp_ev_queue *self, uint32_t new_w, uint32_t new_h, uint64_t time)
 Pushes a window resize event to the queue.
 
void gp_ev_queue_push (gp_ev_queue *self, uint16_t type, uint32_t code, int32_t value, uint64_t time)
 Push a generic event into the queue.
 
static void gp_ev_queue_push_wheel (gp_ev_queue *self, int32_t val, uint64_t time)
 Pushes a mouse wheel movement into the queue.
 

Detailed Description

Event Queue.

This API is internally used by backends to store input events and is not supposed to be used directly.

Definition in file gp_ev_queue.h.

Enumeration Type Documentation

◆ gp_ev_queue_flags

An event queue init flags.

Enumerator
GP_EVENT_QUEUE_LOAD_KEYMAP 

Load keymap during initialization.

This is used by backends that do not get keystrokes translated to unicode characters, e.g. framebuffer, Linux DRM, e-ink displays, etc.

Definition at line 66 of file gp_ev_queue.h.

Function Documentation

◆ gp_ev_queue_events()

unsigned int gp_ev_queue_events ( gp_ev_queue self)

Returns number of events queued in the queue.

Parameters
selfAn event queue.
Returns
A number of events in the queue.

◆ gp_ev_queue_feedback_register()

static void gp_ev_queue_feedback_register ( gp_ev_queue self,
gp_ev_feedback *  feedback 
)
inlinestatic

Registers an input device feedback callback.

Parameters
selfAn event queue.
feedbackAn input device feedback callback.

Definition at line 114 of file gp_ev_queue.h.

References gp_ev_queue::feedbacks_list, and gp_ev_feedback_register().

◆ gp_ev_queue_feedback_set_all()

static void gp_ev_queue_feedback_set_all ( gp_ev_queue self,
gp_ev_feedback_op *  op 
)
inlinestatic

Calls a all feedback handlers with a specified value.

Parameters
selfAn event queue.
opAn operation to be done, e.g. turn on caps lock led.

Definition at line 136 of file gp_ev_queue.h.

References gp_ev_queue::feedbacks_list, and gp_ev_feedback_set_all().

◆ gp_ev_queue_feedback_unregister()

static void gp_ev_queue_feedback_unregister ( gp_ev_queue self,
gp_ev_feedback *  feedback 
)
inlinestatic

Unregisters an input device feedback callback.

Parameters
selfAn event queue.
feedbackAn input device feedback callback.

Definition at line 125 of file gp_ev_queue.h.

References gp_ev_queue::feedbacks_list, and gp_ev_feedback_unregister().

◆ gp_ev_queue_full()

static int gp_ev_queue_full ( gp_ev_queue self)
inlinestatic

Returns true if queue is full.

Parameters
selfAn event queue.
Returns
Non-zero if queue is full zero otherwise.

Definition at line 165 of file gp_ev_queue.h.

◆ gp_ev_queue_get()

gp_event * gp_ev_queue_get ( gp_ev_queue self)

Remoes and returns pointer to a top event from the queue.

In case there are any events queued a pointer to a top event in the queue is returned. The pointer is valid until next call to gp_ev_queue_get().

The pointer is also invalidated by a call to gp_ev_queue_put_back().

If there are no events queued the call returns NULL.

Parameters
selfAn event queue.
Returns
A pointer to the top event in the queue or NULL if queue is empty.

◆ gp_ev_queue_init()

void gp_ev_queue_init ( gp_ev_queue self,
unsigned int  screen_w,
unsigned int  screen_h,
unsigned int  queue_size,
enum gp_ev_queue_flags  flags 
)

Initializes event queue.

The queue has to be allocatedpassed as a pointer. The events array must be queue_size long.

If queue_size is set to zero, default value is expected.

Parameters
selfA pointer to newly allocated event queue structure.
screen_wA width of the display/window.
screen_hA height of the display/window.
queue_sizeA size of the circular buffer for the queue, pass 0 for default.
flagsA bitwise combination of enum gp_ev_queue_flags.

◆ gp_ev_queue_peek()

gp_event * gp_ev_queue_peek ( gp_ev_queue self)

Peeks at a top event from the queue.

Same as gp_ev_queue_get() but the event is not removed from the queue. The pointer is valid until a call to gp_ev_queue_get().

If there are no events queued the calll returns NULL.

Parameters
selfAn event queue.
Returns
A pointer to the top event in the queue or NULL if queue is empty.

◆ gp_ev_queue_push()

void gp_ev_queue_push ( gp_ev_queue self,
uint16_t  type,
uint32_t  code,
int32_t  value,
uint64_t  time 
)

Push a generic event into the queue.

Parameters
selfAn input queue.
typeAn event type enum gp_ev_type.
codeBased on type one of the enum gp_ev_key_code, enum gp_ev_rel_code, enum gp_ev_abs_code, enum gp_ev_sys_code.
valueAn event value, e.g. which key was pressed.
timeA timestamp, if NULL current time is used.

Referenced by gp_backend_clipboard_ready(), and gp_ev_queue_push_wheel().

◆ gp_ev_queue_push_abs()

void gp_ev_queue_push_abs ( gp_ev_queue self,
uint32_t  x,
uint32_t  y,
uint32_t  pressure,
uint32_t  x_max,
uint32_t  y_max,
uint32_t  pressure_max,
uint64_t  time 
)

Pushes an absolute event into the queue.

The values are scaled between 0 and max value.

Parameters
selfAn input queue.
xAn absolute x coordinate.
yAn absolute y coordinate.
pressureA pen pressure.
x_maxAn absolute x coordinate maximum.
y_maxAn absolute y coordinate maximum.
pressure_maxA maximal pen pressure.
timeA timestamp, if NULL current time is used.

◆ gp_ev_queue_push_key()

void gp_ev_queue_push_key ( gp_ev_queue self,
uint32_t  key,
uint8_t  code,
uint64_t  time 
)

Pushes a key event into the event queue.

Pushes a GP_EV_KEY event to the event queue.

If backend uses a keymap key events are processed by the keymap state machine and GP_EV_UTF events are generated accordingly.

Parameters
selfAn input queue.
keyPhysical key pressed on keyboard.
codeAction enum gp_ev_key_code press/release/repeat.
timeA timestamp, if NULL current time is used.

◆ gp_ev_queue_push_rel()

void gp_ev_queue_push_rel ( gp_ev_queue self,
int32_t  rx,
int32_t  ry,
uint64_t  time 
)

Pushes a relative event that moves cursor by rx and ry.

Parameters
selfAn input queue.
rxA relative change in x coordinate.
ryA relative change in y coordinate.
timeA timestamp, if NULL current time is used.

◆ gp_ev_queue_push_rel_to()

void gp_ev_queue_push_rel_to ( gp_ev_queue self,
uint32_t  x,
uint32_t  y,
uint64_t  time 
)

Pushes a relative event that moves cursor to the point x, y.

Parameters
selfAn input queue.
xA x coordinate to move the cursor to.
yA y coordinate to move the cursor to.
timeA timestamp, if NULL current time is used.

◆ gp_ev_queue_push_resize()

void gp_ev_queue_push_resize ( gp_ev_queue self,
uint32_t  new_w,
uint32_t  new_h,
uint64_t  time 
)

Pushes a window resize event to the queue.

Backends start the resize operation by pushing the GP_EV_SYS_RESIZE event to the input queue. When the application processes the event it has to acknowledge the resize by calling gp_backend_resize_ack(), which resizes the pixel buffers and also calls gp_ev_queue_set_screen_size().

Parameters
selfAn input queue.
new_wA new display/window/screen width.
new_hA new display/window/screen height.
timeA timestamp, if NULL current time is used.

◆ gp_ev_queue_push_utf()

void gp_ev_queue_push_utf ( gp_ev_queue self,
uint32_t  utf_ch,
uint64_t  time 
)

Pushes an unicode character typed on keyboard into the queue.

Parameters
selfAn input queue.
utf_chAn unicode character.
timeA timestamp, if NULL current time is used.

◆ gp_ev_queue_push_wheel()

static void gp_ev_queue_push_wheel ( gp_ev_queue self,
int32_t  val,
uint64_t  time 
)
inlinestatic

Pushes a mouse wheel movement into the queue.

Parameters
selfAn input queue.
valA relative change of the mouse wheel position.
timeA timestamp, if NULL current time is used.

Definition at line 328 of file gp_ev_queue.h.

References gp_ev_queue_push(), GP_EV_REL, and GP_EV_REL_WHEEL.

◆ gp_ev_queue_put()

void gp_ev_queue_put ( gp_ev_queue self,
gp_event ev 
)

Pushes an event to the event queue.

This is bare call that just copies the event into the queue. Use the calls below instead.

Parameters
selfAn input queue.
evA pointer to an event.

◆ gp_ev_queue_put_back()

void gp_ev_queue_put_back ( gp_ev_queue self,
gp_event ev 
)

Pushes back an event to the event queue.

Puts event to the top of the queue, i.e. this event is going to be returned by a next call to gp_ev_queue_get().

Parameters
selfAn input queue.
evA pointer to an event.

◆ gp_ev_queue_set_cursor_pos()

void gp_ev_queue_set_cursor_pos ( gp_ev_queue self,
unsigned int  x,
unsigned int  y 
)

Sets a cursor postion.

Parameters
selfAn event queue.
xA new cursor x position.
yA new cursor y position.

◆ gp_ev_queue_set_screen_size()

void gp_ev_queue_set_screen_size ( gp_ev_queue self,
unsigned int  w,
unsigned int  h 
)

Sets screen (window) size.

This is needs to be called when backend is resized in order to update cursor position and limits.

Parameters
selfAn event queue.
wNew display/window/screen width.
hNew display/window/screen height.