SBgl 0.1.0
A graphics framework in C99
Loading...
Searching...
No Matches
linux_internal.h File Reference
#include "sbgl_types.h"
#include "core/sbgl_input.h"
#include <stdint.h>
#include <stdbool.h>
#include <X11/Xlib.h>
Include dependency graph for linux_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sbgl_Window
 Native X11 window state. More...
 

Functions

void x11_internal_process_event (XEvent *event, struct sbgl_Window *window)
 
void linux_internal_update_input_states (struct sbgl_Window *window)
 

Function Documentation

◆ linux_internal_update_input_states()

void linux_internal_update_input_states ( struct sbgl_Window * window)

Definition at line 127 of file input_wayland.c.

127 {
128 sbgl_InputState* input = window->input;
129 if (!input) return;
130
131 if (!window->relative_pointer) {
132 input->mouseDeltaX = input->mouseX - input->_internalMouseX;
133 input->mouseDeltaY = input->mouseY - input->_internalMouseY;
134 }
135 // Note: If relative_pointer is active, mouseDeltaX/Y were accumulated in relative_motion.
136 // We do NOT reset them here, as they should be reset at the start of PollEvents
137 // or we should handle the accumulation window carefully.
138 // For now, assume PollEvents or the next frame will clear them if needed,
139 // but actually sbgl_InputState usually expects deltas to be "since last frame".
140
141 input->_internalMouseX = input->mouseX;
142 input->_internalMouseY = input->mouseY;
143}
Represents the real-time state of physical inputs.
Definition sbgl_input.h:165
sbgl_InputState * input

◆ x11_internal_process_event()

void x11_internal_process_event ( XEvent * event,
struct sbgl_Window * window )

Definition at line 32 of file input_x11.c.

32 {
33 sbgl_InputState* input = window->input;
34 switch (event->type) {
35 case KeyPress: {
36 KeySym keysym = XLookupKeysym(&event->xkey, 0);
38 if (code < SBGL_SCANCODE_MAX) {
39 if (!input->keysDown[code]) input->keysPressed[code] = true;
40 input->keysDown[code] = true;
41 }
42 break;
43 }
44 case KeyRelease: {
45 // X11 Auto-repeat handling
46 if (XEventsQueued(window->display, QueuedAfterReading)) {
47 XEvent next;
48 XPeekEvent(window->display, &next);
49 if (next.type == KeyPress && next.xkey.time == event->xkey.time && next.xkey.keycode == event->xkey.keycode) {
50 XNextEvent(window->display, event); // Consume repeat
51 break;
52 }
53 }
54 KeySym keysym = XLookupKeysym(&event->xkey, 0);
56 if (code < SBGL_SCANCODE_MAX) input->keysDown[code] = false;
57 break;
58 }
59 case MotionNotify: {
60 input->mouseX = event->xmotion.x;
61 input->mouseY = event->xmotion.y;
62 break;
63 }
64 case ButtonPress:
65 case ButtonRelease: {
66 bool down = (event->type == ButtonPress);
67 int btn = -1;
68 if (event->xbutton.button == Button1) btn = SBGL_MOUSE_BUTTON_LEFT;
69 else if (event->xbutton.button == Button3) btn = SBGL_MOUSE_BUTTON_RIGHT;
70 else if (event->xbutton.button == Button2) btn = SBGL_MOUSE_BUTTON_MIDDLE;
71 if (btn != -1 && btn < SBGL_MOUSE_BUTTON_MAX) input->mouseDown[btn] = down;
72 break;
73 }
74 case FocusIn: {
75 window->focused = true;
76 break;
77 }
78 case FocusOut: {
79 window->focused = false;
80 break;
81 }
82 }
83}
SBGL_Scancode
OS-independent physical scancodes.
Definition sbgl_input.h:21
@ SBGL_SCANCODE_MAX
Definition sbgl_input.h:137
@ SBGL_MOUSE_BUTTON_MIDDLE
Definition sbgl_input.h:146
@ SBGL_MOUSE_BUTTON_MAX
Definition sbgl_input.h:147
@ SBGL_MOUSE_BUTTON_LEFT
Definition sbgl_input.h:144
@ SBGL_MOUSE_BUTTON_RIGHT
Definition sbgl_input.h:145
static SBGL_Scancode x11_keysym_to_scancode(KeySym keysym)
Definition input_x11.c:7
bool mouseDown[SBGL_MOUSE_BUTTON_MAX]
Definition sbgl_input.h:168
bool keysPressed[SBGL_SCANCODE_MAX]
Definition sbgl_input.h:167
bool keysDown[SBGL_SCANCODE_MAX]
Definition sbgl_input.h:166
Display * display