aboutsummaryrefslogtreecommitdiff
path: root/riverctl
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2020-06-15 22:24:54 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2020-06-16 18:27:46 +0200
commitf0c3aa374447684de95f9653830b232d896aee0b (patch)
tree36c883633524fdaea8de80738047c0ce96f7cb35 /riverctl
parente7bf1940da80610ca415793b42694fe9bbaf0724 (diff)
downloadriver-f0c3aa374447684de95f9653830b232d896aee0b.tar.gz
river-f0c3aa374447684de95f9653830b232d896aee0b.tar.xz
river-control: implement protocol changes
Diffstat (limited to 'riverctl')
-rw-r--r--riverctl/main.zig45
1 files changed, 25 insertions, 20 deletions
diff --git a/riverctl/main.zig b/riverctl/main.zig
index 287c1aa..8e02a06 100644
--- a/riverctl/main.zig
+++ b/riverctl/main.zig
@@ -33,6 +33,7 @@ const command_callback_listener = c.zriver_command_callback_v1_listener{
};
var river_control_optional: ?*c.zriver_control_v1 = null;
+var wl_seat_optional: ?*c.wl_seat = null;
pub fn main() !void {
const wl_display = c.wl_display_connect(null) orelse return error.CantConnectToDisplay;
@@ -43,21 +44,14 @@ pub fn main() !void {
if (c.wl_display_roundtrip(wl_display) < 0) return error.RoundtripFailed;
const river_control = river_control_optional orelse return error.RiverControlNotAdvertised;
+ const wl_seat = wl_seat_optional orelse return error.SeatNotAdverstised;
- var command: c.wl_array = undefined;
- c.wl_array_init(&command);
- var it = std.process.args();
- // Skip our name
- _ = it.nextPosix();
- while (it.nextPosix()) |arg| {
- // Add one as we need to copy the null terminators as well
- var ptr = @ptrCast([*]u8, c.wl_array_add(&command, arg.len + 1) orelse
- return error.OutOfMemory);
- for (arg) |ch, i| ptr[i] = ch;
- ptr[arg.len] = 0;
- }
+ // Skip our name, send all other args
+ // This next line is needed cause of https://github.com/ziglang/zig/issues/2622
+ const args = std.os.argv;
+ for (args[1..]) |arg| c.zriver_control_v1_add_argument(river_control, arg);
- const command_callback = c.zriver_control_v1_run_command(river_control, &command);
+ const command_callback = c.zriver_control_v1_run_command(river_control, wl_seat);
if (c.zriver_command_callback_v1_add_listener(
command_callback,
&command_callback_listener,
@@ -76,23 +70,34 @@ fn handleGlobal(
version: u32,
) callconv(.C) void {
// We only care about the river_control global
- if (std.mem.eql(
- u8,
- std.mem.spanZ(interface.?),
- std.mem.spanZ(@ptrCast([*:0]const u8, c.zriver_control_v1_interface.name.?)),
- )) {
+ if (std.cstr.cmp(interface.?, @ptrCast([*:0]const u8, c.zriver_control_v1_interface.name.?)) == 0) {
river_control_optional = @ptrCast(
*c.zriver_control_v1,
c.wl_registry_bind(wl_registry, name, &c.zriver_control_v1_interface, 1),
);
+ } else if (std.cstr.cmp(interface.?, @ptrCast([*:0]const u8, c.wl_seat_interface.name.?)) == 0) {
+ // river does not yet support multi-seat, so just use the first
+ // (and only) seat advertised
+ wl_seat_optional = @ptrCast(
+ *c.wl_seat,
+ c.wl_registry_bind(wl_registry, name, &c.wl_seat_interface, 1),
+ );
}
}
/// Ignore the event
fn handleGlobalRemove(data: ?*c_void, wl_registry: ?*c.wl_registry, name: u32) callconv(.C) void {}
-/// On success we simply exit with a clean exit code
-fn handleSuccess(data: ?*c_void, callback: ?*c.zriver_command_callback_v1) callconv(.C) void {
+/// Print the output of the command if any and exit
+fn handleSuccess(
+ data: ?*c_void,
+ callback: ?*c.zriver_command_callback_v1,
+ output: ?[*:0]const u8,
+) callconv(.C) void {
+ if (std.mem.len(output.?) > 0) {
+ const stdout = std.io.getStdOut().outStream();
+ stdout.print("{}\n", .{output}) catch @panic("failed to write to stdout");
+ }
std.os.exit(0);
}