mach/libs/gamemode/gamemode.zig
Stephen Gutekanst 0645429df9 all: move standalone libraries to libs/ subdirectory
The root dir of our repository has grown quite a lot the past few months.

I'd like to make it more clear where the bulk of the engine lives (`src/`) and
also make it more clear which Mach libraries are consumable as standalone projects.

As for the name of this directory, `libs` was my first choice but there's a bit of
a convention of that being external libraries in Zig projects _today_, while these
are libraries maintained as part of Mach in this repository - not external ones.

We will name this directory `libs`, and if we have a need for external libraries
we will use `external` or `deps` for that directory name. I considered other names
such as `components`, `systems`, `modules` (which are bad as they overlap with
major ECS / engine concepts), and it seems likely the official Zig package manager
will break the convention of using a `libs` dir anyway.

Performed via:

```sh
mkdir libs/
git mv freetype libs/
git mv basisu libs/
git mv gamemode libs/
git mv glfw libs/
git mv gpu libs/
git mv gpu-dawn libs/
git mv sysaudio libs/
git mv sysjs libs/
git mv ecs libs/
```

git-subtree-dir: glfw
git-subtree-mainline: 0d5b853443
git-subtree-split: 572d1144f11b353abdb64fff828b25a4f0fbb7ca

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>

git mv ecs libs/

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-08-26 15:12:04 -07:00

76 lines
2.1 KiB
Zig

//! Note: All the above requests can be blocking - dbus requests can and will block while the daemon
//! handles the request. It is not recommended to make these calls in performance critical code
pub const c = @import("gamemode_client.zig");
pub const GamemodeError = error{
RequestFailed,
RequestRejected,
QueryFailed,
};
pub const GamemodeStatus = enum(c_int) {
Inactive = 0,
Active = 1,
/// Gamemode is active and the client is registered
ActiveAndRegistered = 2,
};
/// Request gamemode starts
pub fn requestStart() GamemodeError!void {
if (c.gamemode_request_start() == -1)
return GamemodeError.RequestFailed;
}
/// Request gamemode ends
pub fn requestEnd() GamemodeError!void {
if (c.gamemode_request_end() == -1)
return GamemodeError.RequestFailed;
}
/// Query the current status of gamemode
pub fn queryStatus() GamemodeError!GamemodeStatus {
const status = c.gamemode_query_status();
if (status == -1)
return GamemodeError.QueryFailed;
return @intToEnum(GamemodeStatus, status);
}
/// Request gamemode starts for another process
pub fn requestStartFor(pid: c.pid_t) GamemodeError!void {
const res = c.gamemode_request_start_for(pid);
if (res == 0) {
return;
} else if (res == -1) {
return GamemodeError.RequestFailed;
} else if (res == -2) {
return GamemodeError.RequestRejected;
}
}
/// Request gamemode ends for another process
pub fn requestEndFor(pid: c.pid_t) GamemodeError!void {
const res = c.gamemode_request_end_for(pid);
if (res == 0) {
return;
} else if (res == -1) {
return GamemodeError.RequestFailed;
} else if (res == -2) {
return GamemodeError.RequestRejected;
}
}
/// Query the current status of gamemode for another process
pub fn queryStatusFor(pid: c.pid_t) GamemodeError!GamemodeStatus {
const status = c.gamemode_query_status_for(pid);
if (status == -1)
return GamemodeError.QueryFailed;
return @intToEnum(GamemodeStatus, status);
}
/// Get an error string
pub fn errorString() []const u8 {
return @import("std").mem.sliceTo(c.gamemode_error_string(), 0);
}