Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a5077a7
more feature bits
nichcode Nov 1, 2025
f4323a7
fix minimize bug x11
nichcode Nov 1, 2025
08cfc58
window test
nichcode Nov 1, 2025
800a044
native test
nichcode Nov 5, 2025
0a71db1
native integration test walyand
nichcode Nov 5, 2025
70f4ed3
wayaland events
nichcode Nov 5, 2025
7bb2db0
window close event
nichcode Nov 5, 2025
dede09b
add features64
nichcode Nov 8, 2025
4ab1653
cursor test wayland
nichcode Nov 8, 2025
153ae5e
mouse events
nichcode Nov 9, 2025
4f2a1c8
key events
nichcode Nov 9, 2025
6b82ec7
key repeats
nichcode Nov 11, 2025
1e70ac8
system cursor
nichcode Nov 11, 2025
64d4f0c
character events
nichcode Nov 11, 2025
821c0c2
start wayland gl
nichcode Nov 12, 2025
9430570
opengl context wayland
nichcode Nov 13, 2025
996b264
wayland opengl
nichcode Nov 13, 2025
52991f9
x11 opengl
nichcode Nov 13, 2025
05329b0
native instance test x11
nichcode Nov 13, 2025
e9cd496
start monitor hotpluggin
nichcode Nov 13, 2025
d5a7260
optimize monitor query
nichcode Nov 13, 2025
82b3932
x11 hotpluggin
nichcode Nov 13, 2025
484e4c0
hotpluggin wayland
nichcode Nov 13, 2025
5dbea2d
update changelog
nichcode Nov 14, 2025
2a3eabb
fix wayland keychar
nichcode Nov 14, 2025
b0f9db6
update win32
Nov 14, 2025
5d3f0d0
format includes
Nov 14, 2025
22c2892
format source
Nov 14, 2025
1eddff0
format tests
Nov 14, 2025
64cef1a
testing
nichcode Nov 14, 2025
e679b18
add focus event wayland
nichcode Nov 16, 2025
42e23f7
update mouse button event
nichcode Nov 16, 2025
6eef350
custom decoration
nichcode Nov 17, 2025
a8cbb56
responsive decorations
nichcode Nov 17, 2025
3c2b155
fix monitor queries
nichcode Nov 17, 2025
41135eb
update changelog
nichcode Nov 18, 2025
7f89561
add dpi event wayland
nichcode Nov 18, 2025
b9a711a
add dynamic platform error linux
nichcode Nov 18, 2025
4135c9d
win32 mouse button fix
Nov 18, 2025
8bf6f23
win32 test done
Nov 18, 2025
3aa8fab
update platform error handling win32
Nov 18, 2025
63e8a73
update platform error handling linux
Nov 18, 2025
573968a
surface enter and leave wayland
nichcode Nov 18, 2025
1bbfcfe
code of conduct
nichcode Nov 18, 2025
ff645d4
security.md
nichcode Nov 18, 2025
751aa65
contributing.md
nichcode Nov 18, 2025
2f35fb2
add wayland backend
nichcode Nov 18, 2025
02f4786
update native api test
nichcode Nov 19, 2025
1ebb974
update github templates
nichcode Nov 20, 2025
95ca278
format code
nichcode Nov 20, 2025
55d6033
format github issues template
nichcode Nov 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contributing to PAL

Everyone is welcome to contribute to PAL by submitting bug reports,
bug fixes, improving documentation, adding tests examples, telling others about PAL,
giving PAL a star, adding a new backend, etc.

### Reporting Bugs

Make sure the bug is not an API usage issue and you have the lastest version of PAL.
If the above is not the case, report the bug on our [GitHub Issue Tracker](https://github.com/nichcode/PAL/issues) using the bug report template. Please make sure you write a good bug report.

## Requesting Features

Requesting a feature which does not align with the goals of PAL (explicit, low-level) will likey
not be merge into PAL. This approach keeps project focused and consistent.

Request features on our [GitHub Issue Tracker](https://github.com/nichcode/PAL/issues)
using the feature report template. Please explain into detail why your feature will work and if
possibly usages of it in use.

## Coding Convention

- **C99** for C source.

- Naming convention:
- `lowerCamelCase` for functions and function parameters. (e.g. `palCreateWindow`, `windowHandle`).
- `PascalCase` for public types (e.g. `PalResult`).
- static internal variables uses 's_' prefix. (eg. `s_InternalData`).
- `snakeCase` for public and internal macros. (e.g. `PAL_DEFAULT_ALIGNMENT`).


## Contributing code

**PAL is released under the Zlib License and every
code contributed to PAL must agree to Zlib licensing terms.**

Pull request checklist:

- Ensure it compiles on **all** supported platforms.
- Ensure the PR is focused and changes are relevant to the feature or bug fix.
- Ensure your code is formatted with clang-format using the `clang-format` file in the repo.
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Bug report
about: Create a report to help us improve
labels: bug
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Operating system (please complete the following information)**:
- OS: [e.g. windows]
- Version: [e.g. 11]

**Additional context**
Add any other context about the problem here.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: false
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project
labels: enhancement
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
56 changes: 54 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Changelog
# CHANGELOG

## [1.0.0] - 2025-09-27
- Initial stable release of PAL.
Expand Down Expand Up @@ -68,4 +68,56 @@ reflecting its role as the primary explicit foundation for OS and graphics abstr

### Notes
- No API or ABI changes - existing code remains compatible.
- Safe upgrade from **v1.1.0** - just rebuild your project after updating.
- Safe upgrade from **v1.1.0** - just rebuild your project after updating.

## [1.3.0] - 2025-11-21

### Features
- **Video:** Added Wayland backend support
- **Video:** Added **palGetVideoFeaturesEx()** to check old and extended supported features.
- **Video:** Added **palGetWindowHandleInfoEx()** to get extended window handles.
- **Video:** Added **palGetRawMouseWheelDelta()** to get raw mouse wheel delta.
- **Video:** Added **PAL_CONFIG_BACKEND_GLES** to `PalFBConfigBackend` enum.
- **Video:** Added **palSetPreferredInstance()** to set the native instance or display PAL video should use rather than creating a new one.

- **Core:** Added **palPackFloat()** to combine two floats into a single Int64 integer.
- **Core:** Added **palUnpackFloat()** to retreive two floats from a single Int64 integer.

- **OpenGL:** Added **palGLSetInstance()** to set the native instance or display PAL opengl should use. This must be set before calling **palInitGL()**.
- **OpenGL:** Added **palGLGetBackend()** to get the opengl backend.

- **Event:** Added **PAL_EVENT_WINDOW_DECORATION_MODE** to `PalEventType` enum.
- **Event:** Added **PalDecorationMode** enum.

### Tests
- Added native integration example: demonstrating **Native API Integration with PAL API**. see
**native_integration_test.c**.

- Added native instance example: demonstrating **Native Instance or Display Integration with PAL API**.
see **native_instance_test.c**.

- Added custom decoration example: demonstrating **Custom Window Decoration**.
see **custom_decoration_test.c**.

### Notes
- **No ABI changes** - existing code remains compatible.

- **OpenGL tests may fail** - The opengl system now needs to call **palGLSetInstance()**
to set the instance or display before initializing. Failure to do this fails.
This is a runtime behavior change. The tests are updated in the repo.

- **Pal mouse button event** - The `event.data` now packs both the button and
wayland seat serial (If on wayland). Existing code that reads as a single value
without unpacking will see different values.
This is a runtime behavior change. The **input_window_test.c** has been updated in the repo.

- **palJoinThread()** - ABI remains unchanged but now takes the address
of a pointer variable for the return value of the thread.
PAL internally reinterpreted into a pointer-to-pointer. This is for ABI stability.

Example – Join thread and get the return value
```c
void* retval;
palJoinThread(thread, &retval);
```

2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

zlib License

Copyright (C) 2025 Nicholas Agbo
Copyright (C) 2025 Nicholas Agbo <agbonicholas04@gmail.com>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

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.

Originally named as **Platform Abstraction Layer**,
PAL has evolved into **Prime Abstraction Layer** — the **first** and most **direct** layer between your engine or software and the operating system.

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.

The goal is very simple, write low-level cross-platform code without having per platform files
all over the place. Example: `renderer_vulkan`, `renderer_d3d12`, `window_win32`, etc.
PAL makes it possible to safely mix native API with its API in a very straight forward way. This is one of the main reasons why PAL exists.

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.

Example – Get Window Size
Expand Down Expand Up @@ -93,9 +94,9 @@ For more detailed examples, see the [tests folder](./tests) tests folder, which
## Supported Platforms
- Windows (Vista+)
- Linux (X11)
- Linux (Wayland)

## Planned Platforms
- Linux (Wayland)
- macOS (Cocoa)
- Android
- iOS
Expand Down
75 changes: 74 additions & 1 deletion include/pal/pal_core.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/**

Copyright (C) 2025 Nicholas Agbo
Copyright (C) 2025 Nicholas Agbo <agbonicholas04@gmail.com>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -33,6 +33,7 @@ freely, subject to the following restrictions:
#define _PAL_CORE_H

#include <stdint.h>
#include <string.h>

#ifdef __cplusplus
#define PAL_EXTERN_C extern "C"
Expand Down Expand Up @@ -75,7 +76,14 @@ typedef _Bool bool;
#define PAL_API PAL_EXTERN_C
#endif // _PAL_BUILD_DLL

#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define PAL_BIG_ENDIAN 1
#else
#define PAL_BIG_ENDIAN 0
#endif // __ORDER_BIG_ENDIAN__

#define PAL_BIT(x) 1 << x
#define PAL_BIT64(x) 1ULL << x

/**
* @brief A signed 8-bit integer
Expand Down Expand Up @@ -462,6 +470,33 @@ static inline Int64 PAL_CALL palPackPointer(void* ptr)
return (Int64)(UintPtr)ptr;
}

/**
* @brief Combine two floats into a single 64-bit signed integer.
*
* @return The combined 64-bit signed integer.
*
* Thread safety: This function is thread safe.
*
* @since 1.3
* @ingroup pal_core
* @sa palUnpackFloat
*/
static inline Int64 PAL_CALL palPackFloat(
float low,
float high)
{
Int64 combined = 0;
#if PAL_BIG_ENDIAN
memcpy(&((Uint32*)&combined)[0], &high, sizeof(float));
memcpy(&((Uint32*)&combined)[1], &low, sizeof(float));
#else
memcpy(&((Uint32*)&combined)[0], &low, sizeof(float));
memcpy(&((Uint32*)&combined)[1], &high, sizeof(float));
#endif // PAL_BIG_ENDIAN

return combined;
}

/**
* @brief Retrieve two 32-bit unsigned integers from a 64-bit signed integer.
*
Expand Down Expand Up @@ -531,6 +566,44 @@ static inline void* PAL_CALL palUnpackPointer(Int64 data)
return (void*)(UintPtr)data;
}

/**
* @brief Retrieve two floats from a 64-bit signed integer.
*
* @param[out] outLow Low value of the 64-bit signed integer.
* @param[out] outHigh High value of the 64-bit signed integer.
*
* Thread safety: This function is thread-safe if `outLow` and `outHigh` are
* thread local.
*
* @since 1.3
* @ingroup pal_core
* @sa palPackFloat
*/
static inline void PAL_CALL palUnpackFloat(
Int64 data,
float* low,
float* high)
{
#if PAL_BIG_ENDIAN
if (low) {
memcpy(low, &((Uint32*)&data)[1], sizeof(float));
}

if (high) {
memcpy(high, &((Uint32*)&data)[0], sizeof(float));
}
#else
if (low) {
memcpy(low, &((Uint32*)&data)[0], sizeof(float));
}

if (high) {
memcpy(high, &((Uint32*)&data)[1], sizeof(float));
}

#endif // PAL_BIG_ENDIAN
}

/** @} */ // end of pal_core group

#endif // _PAL_CORE_H
33 changes: 30 additions & 3 deletions include/pal/pal_event.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/**

Copyright (C) 2025 Nicholas Agbo
Copyright (C) 2025 Nicholas Agbo <agbonicholas04@gmail.com>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -100,6 +100,21 @@ typedef bool(PAL_CALL* PalPollFn)(
void* userData,
PalEvent* outEvent);

/**
* @enum PalDecorationMode
* @brief Decoration types. This is not a bitmask enum.
*
* All decoration types follow the format `PAL_DECORATION_MODE_**` for
* consistency and API use.
*
* @since 1.3
* @ingroup pal_event
*/
typedef enum {
PAL_DECORATION_MODE_CLIENT_SIDE,
PAL_DECORATION_MODE_SERVER_SIDE
} PalDecorationMode;

/**
* @enum PalEventType
* @brief Event types. This is not a bitmask enum.
Expand Down Expand Up @@ -259,7 +274,7 @@ typedef enum {
/**
* PAL_EVENT_MOUSE_BUTTONDOWN
*
* event.data : mouse button
* event.data : lower 32 bits = button, upper 32 bits = serial
*
* event.data2 : window
*
Expand All @@ -271,7 +286,7 @@ typedef enum {
/**
* PAL_EVENT_MOUSE_BUTTONUP
*
* event.data : mouse button
* event.data : lower 32 bits = button, upper 32 bits = serial
*
* event.data2 : window
*
Expand Down Expand Up @@ -348,6 +363,18 @@ typedef enum {
*/
PAL_EVENT_KEYCHAR,

/**
* PAL_EVENT_WINDOW_DECORATION_MODE
*
* event.data : negotiated decorations mode
*
* event.data2 : window
*
* Use inline helpers:
* - palUnpackPointer()
*/
PAL_EVENT_WINDOW_DECORATION_MODE,

PAL_EVENT_MAX
} PalEventType;

Expand Down
Loading