Skip to content

Commit a4b4de0

Browse files
nichcodenichcode
andauthored
Add character input eventt and foreign window attach/detach support (#2)
* attach window feature * demo test * update changelog * demo test win32 * detach window * event helpers * fix keyup event lost * key char event win32 * key char event x11 * updated readme * fix window state bug * code format * fix warning --------- Co-authored-by: nichcode <nicholasagbo04@gmail.com>
1 parent f948770 commit a4b4de0

15 files changed

Lines changed: 1811 additions & 297 deletions

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,26 @@
4646
- No API or ABI changes - existing Windows code remains compatible.
4747
- Linux video support currently targets **X11** only: **Wayland** is planned for future releases.
4848
- Safe upgrade from **v1.0.1** - just rebuild your project after updating.
49+
50+
## [1.2.0] - 2025-10-22
51+
52+
### Features
53+
- **Video:** Added **palGetInstance()** to retrieve the native display or instance handle.
54+
- **Video:** Added **palAttachWindow()** for attaching **foreign windows** to PAL.
55+
- **Video:** Added **palDetachWindow()** for detaching **foreign windows** from PAL.
56+
- **Event:** Added **PAL_EVENT_KEYCHAR** to `PalEventType` enum.
57+
- **Event:** Added documentation for event bits(payload) layout.
58+
59+
### Naming Update
60+
- PAL now stands for **Prime Abstraction Layer**,
61+
reflecting its role as the primary explicit foundation for OS and graphics abstraction.
62+
- All API remains unchanged — this is an identity update only.
63+
64+
### Tests
65+
- Added multi-threaded OpenGL example: demonstrating **Multi-Threaded OpenGL Rendering**. see **multi_thread_opengl_test.c**.
66+
- Added attaching and detach foreign windows example. see **attach_window_test.c**
67+
- Added key character example. see **char_event_test.c**
68+
69+
### Notes
70+
- No API or ABI changes - existing code remains compatible.
71+
- Safe upgrade from **v1.1.0** - just rebuild your project after updating.

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PAL (Platform Abstraction Layer)
1+
# PAL (Prime Abstraction Layer)
22

33
![License: Zlib](https://img.shields.io/badge/License-Zlib-blue.svg)
44
![Language: C99](https://img.shields.io/badge/language-C99-green.svg)
@@ -7,6 +7,9 @@
77

88
PAL is a lightweight, low-level, cross-platform abstraction layer in **C**, designed to be **explicit** and as close to the **OS** as possible — similar in philosophy to Vulkan. It gives you precise control without hidden behavior, making it ideal for developers who want performance and predictability.
99

10+
Originally named as **Platform Abstraction Layer**,
11+
PAL has evolved into **Prime Abstraction Layer** — the **first** and most **direct** layer between your engine or software and the operating system.
12+
1013
PAL is transparent. All queries — window size, position, monitor info, and more — reflect the current platform state. Using PAL is like working directly with the OS: it applies no hidden logic, makes no assumptions, and leaves behavior fully in your control.
1114

1215
This approach gives you total control: you handle events, manage resources, and cache state explicitly. PAL provides the building blocks; how you use them — whether for simple applications or advanced frameworks — is entirely up to you.
@@ -22,7 +25,8 @@ palGetWindowSize(window, &w, &h);
2225
2326
## Why PAL?
2427
25-
Other libraries like SDL or GLFW provide high-level abstractions but at the cost of overhead, implicit behavior, and limited control. **PAL is different:**
28+
While libraries like SDL or GLFW focus on simplifying development
29+
through high-level abstractions. **PAL is different:**
2630
2731
- ✅ **Explicit**: You decide how memory, events, and handles are managed.
2832
- ✅ **Low Overhead**: PAL is close to raw OS calls, ensuring performance.

include/pal/pal_event.h

Lines changed: 226 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,243 @@ typedef bool(PAL_CALL* PalPollFn)(
111111
* @ingroup pal_event
112112
*/
113113
typedef enum {
114-
PAL_EVENT_WINDOW_CLOSE, /**< Window close button.*/
114+
/**
115+
* PAL_EVENT_WINDOW_CLOSE
116+
*
117+
* event.data2 : window
118+
*
119+
* Use inline helpers:
120+
* - palUnpackPointer()
121+
*/
122+
PAL_EVENT_WINDOW_CLOSE,
123+
124+
/**
125+
* PAL_EVENT_WINDOW_SIZE
126+
*
127+
* event.data : lower 32 bits = width, upper 32 bits = height
128+
*
129+
* event.data2 : window
130+
*
131+
* Use inline helpers:
132+
* - palUnpackUint32()
133+
* - palUnpackPointer()
134+
*/
115135
PAL_EVENT_WINDOW_SIZE,
136+
137+
/**
138+
* PAL_EVENT_WINDOW_MOVE
139+
*
140+
* event.data : lower 32 bits = x, upper 32 bits = y
141+
*
142+
* event.data2 : window
143+
*
144+
* Use inline helpers:
145+
* - palUnpackInt32()
146+
* - palUnpackPointer()
147+
*/
116148
PAL_EVENT_WINDOW_MOVE,
117-
PAL_EVENT_WINDOW_STATE, /**< (minimized, maximized, restored).*/
118-
PAL_EVENT_WINDOW_FOCUS, /**< True for focus gained.*/
119-
PAL_EVENT_WINDOW_VISIBILITY, /**< True for visible.*/
120-
PAL_EVENT_WINDOW_MODAL_BEGIN, /**< WM_ENTERSIZEMOVE (Windows Only).*/
121-
PAL_EVENT_WINDOW_MODAL_END, /**< WM_EXITSIZEMOVE. (Windows Only).*/
149+
150+
/**
151+
* PAL_EVENT_WINDOW_STATE
152+
*
153+
* event.data : state(minimized, maximized, restored).
154+
*
155+
* event.data2 : window
156+
*
157+
* Use inline helpers:
158+
* - palUnpackPointer()
159+
*/
160+
PAL_EVENT_WINDOW_STATE,
161+
162+
/**
163+
* PAL_EVENT_WINDOW_FOCUS
164+
*
165+
* event.data : `true` for focus gained or `false` for focus lost.
166+
*
167+
* event.data2 : window
168+
*
169+
* Use inline helpers:
170+
* - palUnpackPointer()
171+
*/
172+
PAL_EVENT_WINDOW_FOCUS,
173+
174+
/**
175+
* PAL_EVENT_WINDOW_VISIBILITY
176+
*
177+
* event.data : `true` for visible or `false` for hidden.
178+
*
179+
* event.data2 : window
180+
*
181+
* Use inline helpers:
182+
* - palUnpackPointer()
183+
*/
184+
PAL_EVENT_WINDOW_VISIBILITY,
185+
186+
/**
187+
* @brief WM_ENTERSIZEMOVE (Windows Only).
188+
*
189+
* PAL_EVENT_WINDOW_MODAL_BEGIN
190+
*
191+
* event.data2 : window
192+
*/
193+
PAL_EVENT_WINDOW_MODAL_BEGIN,
194+
195+
/**
196+
* @brief WM_EXITSIZEMOVE (Windows Only).
197+
*
198+
* PAL_EVENT_WINDOW_MODAL_END
199+
*
200+
* event.data2 : window
201+
*/
202+
PAL_EVENT_WINDOW_MODAL_END,
203+
204+
/**
205+
* PAL_EVENT_MONITOR_DPI_CHANGED
206+
*
207+
* event.data2 : window
208+
*/
122209
PAL_EVENT_MONITOR_DPI_CHANGED,
123-
PAL_EVENT_MONITOR_LIST_CHANGED, /**< Monitor list changed.*/
210+
211+
/**
212+
* @brief Monitor list changed
213+
*
214+
* PAL_EVENT_MONITOR_LIST_CHANGED
215+
*
216+
* event.data2 : window
217+
*/
218+
PAL_EVENT_MONITOR_LIST_CHANGED,
219+
220+
/**
221+
* PAL_EVENT_KEYDOWN
222+
*
223+
* event.data : lower 32 bits = keycode, upper 32 bits = scancode
224+
*
225+
* event.data2 : window
226+
*
227+
* Use inline helpers:
228+
* - palUnpackUint32()
229+
* - palUnpackPointer()
230+
*/
124231
PAL_EVENT_KEYDOWN,
232+
233+
/**
234+
* PAL_EVENT_KEYREPEAT
235+
*
236+
* event.data : lower 32 bits = keycode, upper 32 bits = scancode
237+
*
238+
* event.data2 : window
239+
*
240+
* Use inline helpers:
241+
* - palUnpackUint32()
242+
* - palUnpackPointer()
243+
*/
125244
PAL_EVENT_KEYREPEAT,
245+
246+
/**
247+
* PAL_EVENT_KEYUP
248+
*
249+
* event.data : lower 32 bits = keycode, upper 32 bits = scancode
250+
*
251+
* event.data2 : window
252+
*
253+
* Use inline helpers:
254+
* - palUnpackUint32()
255+
* - palUnpackPointer()
256+
*/
126257
PAL_EVENT_KEYUP,
258+
259+
/**
260+
* PAL_EVENT_MOUSE_BUTTONDOWN
261+
*
262+
* event.data : mouse button
263+
*
264+
* event.data2 : window
265+
*
266+
* Use inline helpers:
267+
* - palUnpackPointer()
268+
*/
127269
PAL_EVENT_MOUSE_BUTTONDOWN,
270+
271+
/**
272+
* PAL_EVENT_MOUSE_BUTTONUP
273+
*
274+
* event.data : mouse button
275+
*
276+
* event.data2 : window
277+
*
278+
* Use inline helpers:
279+
* - palUnpackPointer()
280+
*/
128281
PAL_EVENT_MOUSE_BUTTONUP,
282+
283+
/**
284+
* PAL_EVENT_MOUSE_MOVE
285+
*
286+
* event.data : lower 32 bits = x, upper 32 bits = y
287+
*
288+
* event.data2 : window
289+
*
290+
* Use inline helpers:
291+
* - palUnpackInt32()
292+
* - palUnpackPointer()
293+
*/
129294
PAL_EVENT_MOUSE_MOVE,
130-
PAL_EVENT_MOUSE_DELTA, /**< Mouse movement delta.*/
295+
296+
/**
297+
* @brief Mouse movement delta.
298+
*
299+
* PAL_EVENT_MOUSE_DELTA
300+
*
301+
* event.data : lower 32 bits = dx, upper 32 bits = dy
302+
*
303+
* event.data2 : window
304+
*
305+
* Use inline helpers:
306+
* - palUnpackInt32()
307+
* - palUnpackPointer()
308+
*/
309+
PAL_EVENT_MOUSE_DELTA,
310+
311+
/**
312+
* PAL_EVENT_MOUSE_WHEEL
313+
*
314+
* event.data : lower 32 bits = dx, upper 32 bits = dy
315+
*
316+
* event.data2 : window
317+
*
318+
* Use inline helpers:
319+
* - palUnpackInt32()
320+
* - palUnpackPointer()
321+
*/
131322
PAL_EVENT_MOUSE_WHEEL,
323+
324+
/**
325+
* PAL_EVENT_USER
326+
*
327+
* event.userId : User event ID or type.
328+
*
329+
* Use inline helpers:
330+
* - palPackInt32()
331+
* - palPackUint32()
332+
* - palPackPointer()
333+
* - palUnpackInt32()
334+
* - palUnpackUint32()
335+
* - palUnpackPointer()
336+
*/
132337
PAL_EVENT_USER,
338+
339+
/**
340+
* PAL_EVENT_USER
341+
*
342+
* event.data : codepoint
343+
*
344+
* event.data2 : window
345+
*
346+
* Use inline helpers:
347+
* - palUnpackPointer()
348+
*/
349+
PAL_EVENT_KEYCHAR,
350+
133351
PAL_EVENT_MAX
134352
} PalEventType;
135353

0 commit comments

Comments
 (0)