Zakero's C++ Header Libraries
A collection of reusable C++ libraries
|
A wrapper class for Wayland. More...
Classes | |
struct | CursorConfig |
Cursor configuration. More... | |
struct | Key |
Key event information. More... | |
struct | KeyModifier |
A collection modifier flags. More... | |
struct | Output |
Information about a output device. More... | |
struct | PointerAxis |
Information about an Axis event. More... | |
struct | PointerButton |
Information about a pointer button event. More... | |
struct | PointMm |
A location that uses millimeters. More... | |
struct | PointPercent |
A location that uses percentages. More... | |
struct | PointPixel |
A location that uses pixels. More... | |
struct | SizeMm |
Size measured in millimeters. More... | |
struct | SizePercent |
Size measured as a percentage of the Output (Monitor) resolution. More... | |
struct | SizePixel |
Size measured in pixels. More... | |
class | Window |
A Window. More... | |
Public Types | |
enum | KeyState |
Keyboard key state More... | |
enum | PointerAxisSource { PointerAxisSource::Unknown } |
Where the axis information came from. More... | |
enum | PointerAxisType { PointerAxisType::Unknown } |
The direction of the axis movement. More... | |
enum | PointerButtonState { PointerButtonState::Released } |
Mouse button state. More... | |
enum | WindowDecorations { WindowDecorations::Client_Side } |
Who is responsible for rendering the decorations. More... | |
enum | WindowMode { WindowMode::Normal } |
Public Member Functions | |
virtual ZAKERO_YETANI__ERROR_DATA | ~Yetani () noexcept |
Destructor. More... | |
std::error_code | cursorCreate (const std::string &, const Yetani::CursorConfig &) noexcept |
Create a cursor. More... | |
std::error_code | cursorDestroy (const std::string &) noexcept |
Destroy a cursor. More... | |
int32_t | keyRepeatDelay () const noexcept |
The key repeat delay. More... | |
int32_t | keyRepeatRate () const noexcept |
The key repeat rate. More... | |
Yetani::Output | output (const Yetani::OutputId) const noexcept |
Get a copy of the Output information. More... | |
Yetani::PointMm | outputConvertToMm (const Yetani::OutputId, const Yetani::PointPixel &) const noexcept |
Convert Pixel to Millimeter. More... | |
Yetani::SizeMm | outputConvertToMm (const Yetani::OutputId, const Yetani::SizePixel &) const noexcept |
Convert Pixel to Millimeter. More... | |
Yetani::PointPercent | outputConvertToPercent (const Yetani::OutputId, const Yetani::PointPixel &) const noexcept |
Convert Pixel to a Percentage. More... | |
Yetani::SizePercent | outputConvertToPercent (const Yetani::OutputId, const Yetani::SizePixel &) const noexcept |
Convert Pixel to a Percentage. More... | |
Yetani::PointPixel | outputConvertToPixel (const Yetani::OutputId, const Yetani::PointMm &) const noexcept |
Convert Millimeter to Pixel. More... | |
Yetani::PointPixel | outputConvertToPixel (const Yetani::OutputId, const Yetani::PointPercent &) const noexcept |
Convert Percentage to Pixel. More... | |
Yetani::SizePixel | outputConvertToPixel (const Yetani::OutputId, const Yetani::SizeMm &) const noexcept |
Convert Millimeter to Pixel. More... | |
Yetani::SizePixel | outputConvertToPixel (const Yetani::OutputId, const Yetani::SizePercent &) const noexcept |
Convert Percentage to Pixel. More... | |
void | outputOnAdd (Yetani::LambdaOutputId) noexcept |
Notification of adding an Output device. More... | |
void | outputOnChange (Yetani::LambdaOutputId) noexcept |
Notification that an Output device has changed. More... | |
void | outputOnRemove (Yetani::LambdaOutputId) noexcept |
Notification of removing an Output device. More... | |
Yetani::VectorOutputId | outputVector () const noexcept |
Get a list of the Output Id's. More... | |
const Yetani::VectorShmFormat & | shmFormatAvailable () const noexcept |
Get all the support color formats. More... | |
Yetani::Window * | windowCreate (const Yetani::SizeMm &, const wl_shm_format, std::error_code &) noexcept |
Create a window. More... | |
Yetani::Window * | windowCreate (const Yetani::SizeMm &, const wl_shm_format=SHM_FORMAT_DEFAULT) noexcept |
Create a window. More... | |
Yetani::Window * | windowCreate (const Yetani::SizeMm &, std::error_code &) noexcept |
Create a window. More... | |
Yetani::Window * | windowCreate (const Yetani::SizePercent &, const wl_shm_format, std::error_code &) noexcept |
Create a window. More... | |
Yetani::Window * | windowCreate (const Yetani::SizePercent &, const wl_shm_format=SHM_FORMAT_DEFAULT) noexcept |
Create a window. More... | |
Yetani::Window * | windowCreate (const Yetani::SizePercent &, std::error_code &) noexcept |
Create a window. More... | |
Yetani::Window * | windowCreate (const Yetani::SizePixel &, const wl_shm_format, std::error_code &) noexcept |
Create a window. More... | |
Yetani::Window * | windowCreate (const Yetani::SizePixel &, const wl_shm_format=SHM_FORMAT_DEFAULT) noexcept |
Create a window. More... | |
Yetani::Window * | windowCreate (const Yetani::SizePixel &, std::error_code &) noexcept |
Create a window. More... | |
Static Public Member Functions | |
static Yetani * | connect () noexcept |
Establish a connection with the Wayland Compositor. More... | |
static Yetani * | connect (const std::string &) noexcept |
Establish a connection with the Wayland Compositor. More... | |
static Yetani * | connect (const std::string &, std::error_code &) noexcept |
Establish a connection with the Wayland Compositor. More... | |
static Yetani * | connect (std::error_code &) noexcept |
Establish a connection with the Wayland Compositor. More... | |
static std::string | outputSubpixelName (int32_t) noexcept |
Get a human readable string. More... | |
static std::string | outputTransformName (int32_t) noexcept |
Get a human readable string. More... | |
static uint8_t | shmFormatBytesPerPixel (const wl_shm_format) noexcept |
Determine bytes-per-pixel. More... | |
static std::string | shmFormatDescription (const wl_shm_format) noexcept |
Get a description of the format. More... | |
static std::string | shmFormatName (const wl_shm_format) noexcept |
Get the name of the format. More... | |
Static Public Attributes | |
static constexpr uint32_t | KeyModifier_Alt |
Key Modifier flag. | |
static constexpr uint32_t | KeyModifier_CapsLock |
Key Modifier flag. | |
static constexpr uint32_t | KeyModifier_Control |
Key Modifier flag. | |
static constexpr uint32_t | KeyModifier_Meta |
Key Modifier flag. | |
static constexpr uint32_t | KeyModifier_Shift |
Key Modifier flag. | |
static constexpr wl_shm_format | SHM_FORMAT_DEFAULT |
The default pixel format. | |
Lambdas | |
using | Lambda = std::function< void()> |
A Lambda that has no parameters. | |
using | LambdaKey = std::function< void(const Yetani::Key &, const Yetani::KeyModifier &)> |
A Lambda that has parameters: Key and KeyModifier. | |
using | LambdaAxis = std::function< void(const Yetani::PointerAxis &, const Yetani::KeyModifier &)> |
A Lambda that has parameters: PointerAxis and KeyModifier. | |
using | LambdaButtonMm = std::function< void(const Yetani::PointerButton &, const Yetani::PointMm &, const Yetani::KeyModifier &)> |
A Lambda that has parameters: PointerButton, PointMm and KeyModifier. | |
using | LambdaButtonPercent = std::function< void(const Yetani::PointerButton &, const Yetani::PointPercent &, const Yetani::KeyModifier &)> |
A Lambda that has parameters: PointerButton, PointPercent and KeyModifier. | |
using | LambdaButtonPixel = std::function< void(const Yetani::PointerButton &, const Yetani::PointPixel &, const Yetani::KeyModifier &)> |
A Lambda that has parameters: PointerButton, PointPixel and KeyModifier. | |
using | LambdaPointMm = std::function< void(const Yetani::PointMm &, const Yetani::KeyModifier &)> |
A Lambda that has parameters: PointMm and KeyModifier. | |
using | LambdaPointPercent = std::function< void(const Yetani::PointPercent &, const Yetani::KeyModifier &)> |
A Lambda that has parameters: PointPercent and KeyModifier. | |
using | LambdaPointPixel = std::function< void(const Yetani::PointPixel &, const Yetani::KeyModifier &)> |
A Lambda that has parameters: PointPixel and KeyModifier. | |
using | LambdaBool = std::function< void(bool)> |
A Lambda that has a parameter: bool. | |
using | LambdaWindowDecorations = std::function< void(Yetani::WindowDecorations)> |
A Lambda that has a parameter: WindowDecorations. | |
using | LambdaWindowMode = std::function< void(Yetani::WindowMode)> |
A Lambda that has a parameter: WindowMode. | |
using | LambdaSizeMm = std::function< void(const Yetani::SizeMm &)> |
A Lambda that has a parameter: SizeMm. | |
using | LambdaSizePercent = std::function< void(const Yetani::SizePercent &)> |
A Lambda that has a parameter: SizePercent. | |
using | LambdaSizePixel = std::function< void(const Yetani::SizePixel &)> |
A Lambda that has a parameter: SizePixel. | |
Refer to Zakero_Yetani.h to learn how to include this library.
The intent of this class is to make creating programs that interface directly with Wayland easier. While there are toolkits out there that do this (GTK, Qt, SDL, etc.), they also come with a lot of overhead. This class will abstract much of Wayland and provide a simple event driven interface.
As soon as a connection to the Wayland server has been established, a thread will be created to move all the communications to the background. This means that there is no "main loop" in the Yetani object to hook into. The benefit to this is that Window contents/graphics will not block event handling.
Refer to How To Use It? for a simple example.
Using Yetani to connect to a Wayland Compositor is just the first step. The next step is to create a Window that can display something. This is done using one of the windowCreate() methods. There are 3 sets of methods:
Why three? The traditional pixels for size has many problems in today's display technology. A resolution of 1024x768 may sound consistent in that you know exactly how many pixels will be used on every display. However, 1024x768 may be OK on some displays, it may be too small on 4k laptop screens. And what about the 8k displays?
The easy answer is to find the maximum resolution and use all of it, or just half for a windowed app. Instead of doing that work, why not just use percentages like 1.00x1.00 or 0.50x0.50 that will work on all display resolutions? That is why Yetani has the SizePercent object.
What about millimeters? Using millimeters gives the developer more confidence that size of an area will be physically consistent across devices. To illustrate this consider defining a 300x150 button. This button may be easily clickable on most monitors but may be too small on a 4k display. Defining a button to be 20mm x 10mm, it will be the same physical size on all monitors.
What's wrong with DPI? DPI has become a mess in the computer world and is resolution, not a size.
The main Wayland event loop runs in a dedicated thread. Because of this, there are race-conditions where execution uses the same data. The most likely thread conflict is the resizing of a surface:
While the above is mostly protected via mutexs' there is still a chance.
There are other potential problems such as the User Thread deleting a window while the Wayland Thread is resizing the same window. To resolve this issue will require a complete evaluation of data and thread activities.
Or take the easy way out and rewrite Yetani to be single-threaded...
struct zakero::Yetani::CursorConfig |
Class Members | ||
---|---|---|
wl_shm_format | format | The pixel format. |
int32_t | hotspot_x | The X location of the hotspot. |
int32_t | hotspot_y | The Y location of the hotspot. |
const vector< void * > & | image_data | A collection of image data. |
SizePixel | size | The size of the cursor. |
milliseconds | time_per_frame | How long to display each frame of animation. |
struct zakero::Yetani::Key |
Time is based on the "steady clock" and not system time.
Class Members | ||
---|---|---|
uint32_t | code | The key code of the event. |
KeyState | state | The state of the key. |
uint32_t | time | When the key event happened. |
struct zakero::Yetani::KeyModifier |
The meaning of the modifiers are:
struct zakero::Yetani::Output |
All the Wayland information about an output device in a single structure.
struct zakero::Yetani::PointerAxis |
Class Members | ||
---|---|---|
float | distance | The distance traveled. |
PointerAxisSource | source | The source of the event. |
int32_t | steps | The number of rotation steps. |
uint32_t | time | When the event occurred. |
PointerAxisType | type | The type of Axis. |
struct zakero::Yetani::PointerButton |
Class Members | ||
---|---|---|
uint32_t | code | The event code. |
PointerButtonState | state | The button state. |
|
strong |
When using a keyboard, a key will emit one of these states.
|
strong |
|
strong |
|
strong |
|
strong |
|
strong |
|
virtualnoexcept |
|
staticnoexcept |
Establish a connection with the Wayland Compositor. The following values will be used to determine which Wayland Compositor to connect to:
If a connection was successful, then a pointer to a new Yetani instance will be returned. This pointer will need to be delete
d by the caller. If there was an error connecting to the Wayland Compositor, nullptr
will be returned.
nullptr
.
|
staticnoexcept |
Establish a connection with the Wayland Compositor. The following values will be used to determine which Wayland Compositor to connect to:
display
If a connection was successful, then a pointer to a new Yetani instance will be returned. This pointer will need to be delete
d by the caller. If there was an error connecting to the Wayland Compositor, nullptr
will be returned.
nullptr
. display | The Display Name or ID |
|
staticnoexcept |
Establish a connection with the Wayland Compositor. The following values will be used to determine which Wayland Compositor to connect to:
display
If a connection was successful, then a pointer to a new Yetani instance will be returned. This pointer will need to be delete
d by the caller. If there was an error connecting to the Wayland Compositor, nullptr
will be returned.
The provided error
will be set to Yetani::Error_None or the reason for the connection failure. An error code of Yetani::Error_Connection_Failed
or Yetani::Error_Invalid_Display_Name
may indicate that there is no Wayland Compositor available.
nullptr
. display | ! The Display Name or ID |
error | ! The error status |
|
staticnoexcept |
Establish a connection with the Wayland Compositor. The following values will be used to determine which Wayland Compositor to connect to:
If a connection was successful, then a pointer to a new Yetani instance will be returned. This pointer will need to be delete
d by the caller. If there was an error connecting to the Wayland Compositor, nullptr
will be returned.
The provided error
will be set to Yetani::Error_None or the reason for the connection failure. An error code of Yetani::Error_Connection_Failed
or Yetani::Error_Invalid_Display_Name
may indicate that there is no Wayland Compositor available.
nullptr
. error | The error code |
|
noexcept |
A cursor with the given name
will be created. The config
data will be used to determine how the cursor will be configured.
The CursorConfig::image_data holds the graphic image data for each frame of the cursor. If the cursor is not animated, then only one frame needs to be provided.
Each frame of the cursor (including non-animated cursors, i.e.: a single frame) must have the dimension specified by CursorConfig::size. And the data in each frame must conform to the value of CursorConfig::format. The required amount of data for each frame is: size_in_bytes = size.width * size.height * shmFormatBytesPerPixel(format)
If more than one frame is provided in CursorConfig::image_data, then the amount of time to display each frame must be placed in CursorConfig::time_per_frame.
Once the last frame of the cursor has been displayed, the first frame will be displayed next creating a continuous looping animation.
Every cursor needs to have a spot that is used to determine where the pointer is located called a hotspot. The location of the hotspot is relative to the top-left corner (0x0) and should be assigned to CursorConfig::hotspot_x and CursorConfig::hotspot_y.
If the configuration was valid and the cursor was successfully created, then Yetani::Error_None
will be returned. Otherwise, another error will be returned to indicate the encountered problem.
name | The name of the cursor |
config | The cursor configuration |
|
noexcept |
The cursor with the specified name
will be destroyed. If any windows are using the cursor, they will report an error.
name | The name of the cursor |
|
noexcept |
The key repeat delay is the amount of time in milliseconds that must elapse from a key press event to change into a key repeat event.
|
noexcept |
The key repeat rate is the number of key repeat events that will be emitted per second.
|
noexcept |
All the available information about a Wayland output device will be provided. It is possible that an output device is removed after the data has been retrieved, so consider the provided data as a "snapshot in time".
If the provided output_id
is not valid, then the returned data will be empty.
output_id | The Output Id |
|
noexcept |
Convert a pixel-based point
location to millimeters using the provided output_id
.
output_id | The output device for the conversion |
point | The point to convert |
|
noexcept |
Convert a pixel-based size
to millimeters using the provided output_id
.
output_id | The output device for the conversion |
size | The size to convert |
|
noexcept |
Convert a pixel-based point
location to a percentage using the provided output_id
.
output_id | The output device for the conversion |
point | The point to convert |
|
noexcept |
Convert a pixel-based size
to a percentage using the provided output_id
.
output_id | The output device for the conversion |
size | The size to convert |
|
noexcept |
Convert a millimeter-based point
location to pixel using the provided output_id
.
output_id | The output device for the conversion |
point | The point to convert |
|
noexcept |
Convert a percentage-based point
location to pixel using the provided output_id
.
output_id | The output device for the conversion |
point | The point to convert |
|
noexcept |
Convert a millimeter-based size
to pixel using the provided output_id
.
output_id | The output device for the conversion |
size | The size to convert |
|
noexcept |
Convert a percentage-based size
to pixel using the provided output_id
.
output_id | The output device for the conversion |
size | The size to convert |
|
noexcept |
When a Wayland output device has been added, the lambda
that was provided to this method will be called. To disable these notifications, pass nullptr
as the value of lambda
.
lambda | The lambda to call |
|
noexcept |
When a Wayland output device's configuration has been changed, the lambda
that was provided to this method will be called. To disable these notifications, pass nullptr
as the value of lambda
.
lambda | The lambda to call |
|
noexcept |
When a Wayland output device has been removed, the lambda
that was provided to this method will be called. To disable these notifications, pass nullptr
as the value of lambda
.
lambda | The lambda to call |
|
staticnoexcept |
The Yetani::Output::subpixel
is a Wayland enum value and this method will convert that value into a descriptive name string. If an invalid value is passed, then an empty string will be returned.
subpixel_format | The Subpixel format |
|
staticnoexcept |
The Yetani::Output::transform
is a Wayland enum value and this method will convert that value into a descriptive name string. If an invalid value is passed, then an empty string will be returned.
transform | The transform value |
|
noexcept |
|
noexcept |
All of the supported wl_shm_format values, color formats, are provided in the returned container.
|
staticnoexcept |
When allocating buffers in Wayland, the number of bytes required per pixel is important so that the correct amount of memory is known. This method will determine the bytes-per-pixel based on the provided shm_format
.
shm_format | The format |
|
staticnoexcept |
In the documented code of Wayland, there are descriptions for each of the supported color formats. By providing the shm_format
, the description of the format will be returned.
shm_format | The format |
|
staticnoexcept |
Converts the enum name of the shm_format
to a string.
shm_format | The format |
|
noexcept |
Create a new Window of the specified size
. A pointer to the Window will be returned. If there was a problem, a nullptr
will returned.
The shared memory used by the Window will use the pixel format
.
The error
parameter will be set to Yetani::Error_None on success or to an appropriate error if there was a problem.
0
.nullptr
on error. size | The window size |
format | The pixel format |
error | The error state |
|
noexcept |
Create a new Window of the specified size
. A pointer to the Window will be returned. If there was a problem, a nullptr
will returned.
The shared memory used by the Window will use the pixel format
.
0
.nullptr
on error. size | The window size |
format | The pixel format |
|
noexcept |
Create a new Window of the specified size
. A pointer to the Window will be returned. If there was a problem, a nullptr
will returned.
The error
parameter will be set to Yetani::Error_None on success or to an appropriate error if there was a problem.
0
.nullptr
on error. size | The window size |
error | The error state |
|
noexcept |
Create a new Window of the specified size
. A pointer to the Window will be returned. If there was a problem, a nullptr
will returned.
The shared memory used by the Window will use the pixel format
.
The error
parameter will be set to Yetani::Error_None on success or to an appropriate error if there was a problem.
0
.nullptr
on error. size | The window size |
format | The pixel format |
error | The error state |
|
noexcept |
Create a new Window of the specified size
. A pointer to the Window will be returned. If there was a problem, a nullptr
will returned.
The shared memory used by the Window will use the pixel format
.
0
.nullptr
on error. size | The window size |
format | The pixel format |
|
noexcept |
Create a new Window of the specified size
. A pointer to the Window will be returned. If there was a problem, a nullptr
will returned.
The error
parameter will be set to Yetani::Error_None on success or to an appropriate error if there was a problem.
0
.nullptr
on error. size | The window size |
error | The error state |
|
noexcept |
Create a new Window of the specified size
. A pointer to the Window will be returned. If there was a problem, a nullptr
will returned.
The shared memory used by the Window will use the pixel format
.
The error
parameter will be set to Yetani::Error_None on success or to an appropriate error if there was a problem.
0
.nullptr
on error. size | The window size |
format | The pixel format |
error | The error state |
|
noexcept |
Create a new Window of the specified size
. A pointer to the Window will be returned. If there was a problem, a nullptr
will returned.
The shared memory used by the Window will use the pixel format
.
0
.nullptr
on error. size | The window size |
format | The pixel format |
|
noexcept |
Create a new Window of the specified size
. A pointer to the Window will be returned. If there was a problem, a nullptr
will returned.
The error
parameter will be set to Yetani::Error_None on success or to an appropriate error if there was a problem.
0
.nullptr
on error. size | The window size |
error | The error state |