aboutsummaryrefslogtreecommitdiff
path: root/riverctl/args.zig
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2021-04-26 21:03:04 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2021-04-27 00:10:20 +0200
commit871fc7c8de172365bd18456c799ec8aacea9ee4a (patch)
tree2f3d56534f80daaf1c36fc2157b0d2aa4aad1a41 /riverctl/args.zig
parenta6f908d7ebfd94c20b27b54cf3275d7a078e3cae (diff)
downloadriver-871fc7c8de172365bd18456c799ec8aacea9ee4a.tar.gz
river-871fc7c8de172365bd18456c799ec8aacea9ee4a.tar.xz
river-options: remove protocol
This protocol involves far too much accidental complexity. The original motivating use-case was to provide a convenient way to send arbitrary data to layout clients at runtime in order to avoid layout clients needing to implement their own IPC and do this over a side-channel. Instead of implementing a quite complex but still rigid options protocol and storing this state in the compositor, instead we will simply add events to the layout protocol to support this use case. Consider the status quo event sequence: 1. send get_option_handle request (riverctl) 2. roundtrip waiting for first event (riverctl) 3. send set_foo_value request (riverctl) 4. receive set_foo_value request (river) 5. send foo_value event to all current handles (river) 6. receive foo_value event (rivertile) 7. send parameters_changed request (rivertile) 8. receive parameters_changed request (river) 9. send layout_demand (river) And compare with the event sequence after the proposed change: 1. send set_foo_value request (riverctl) 2. receive set_foo_value request (river) 3. send set_foo_value event (river) 4. send layout_demand (river) This requires *much* less back and forth between the server and clients and is clearly much simpler.
Diffstat (limited to 'riverctl/args.zig')
-rw-r--r--riverctl/args.zig119
1 files changed, 0 insertions, 119 deletions
diff --git a/riverctl/args.zig b/riverctl/args.zig
deleted file mode 100644
index 29ca0f9..0000000
--- a/riverctl/args.zig
+++ /dev/null
@@ -1,119 +0,0 @@
-// This file is part of river, a dynamic tiling wayland compositor.
-//
-// Copyright 2021 The River Developers
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-const std = @import("std");
-const mem = std.mem;
-const cstr = std.cstr;
-
-const root = @import("root");
-
-pub const FlagDef = struct {
- name: [*:0]const u8,
- kind: enum { boolean, arg },
-};
-
-pub fn Args(comptime num_positionals: comptime_int, comptime flag_defs: []const FlagDef) type {
- return struct {
- const Self = @This();
-
- positionals: [num_positionals][*:0]const u8,
- flags: [flag_defs.len]struct {
- name: [*:0]const u8,
- value: union {
- boolean: bool,
- arg: ?[*:0]const u8,
- },
- },
-
- pub fn parse(argv: [][*:0]const u8) Self {
- var ret: Self = undefined;
-
- // Init all flags in the flags array to false/null
- inline for (flag_defs) |flag_def, flag_idx| {
- switch (flag_def.kind) {
- .boolean => ret.flags[flag_idx] = .{
- .name = flag_def.name,
- .value = .{ .boolean = false },
- },
- .arg => ret.flags[flag_idx] = .{
- .name = flag_def.name,
- .value = .{ .arg = null },
- },
- }
- }
-
- // Parse the argv in to the positionals and flags arrays
- var arg_idx: usize = 0;
- var positional_idx: usize = 0;
- outer: while (arg_idx < argv.len) : (arg_idx += 1) {
- var should_continue = false;
- inline for (flag_defs) |flag_def, flag_idx| {
- if (cstr.cmp(flag_def.name, argv[arg_idx]) == 0) {
- switch (flag_def.kind) {
- .boolean => ret.flags[flag_idx].value.boolean = true,
- .arg => {
- arg_idx += 1;
- ret.flags[flag_idx].value.arg = if (arg_idx < argv.len)
- argv[arg_idx]
- else
- root.printErrorExit("flag '" ++ flag_def.name ++
- "' requires an argument but none was provided!", .{});
- },
- }
- // TODO: this variable exists as a workaround for the fact that
- // using continue :outer here crashes the stage1 compiler.
- should_continue = true;
- }
- }
- if (should_continue) continue;
-
- if (positional_idx == num_positionals) {
- root.printErrorExit(
- "{} positional arguments expected but more were provided!",
- .{num_positionals},
- );
- }
-
- ret.positionals[positional_idx] = argv[arg_idx];
- positional_idx += 1;
- }
-
- if (positional_idx < num_positionals) {
- root.printErrorExit(
- "{} positional arguments expected but only {} were provided!",
- .{ num_positionals, positional_idx },
- );
- }
-
- return ret;
- }
-
- pub fn boolFlag(self: Self, flag_name: [*:0]const u8) bool {
- for (self.flags) |flag| {
- if (cstr.cmp(flag.name, flag_name) == 0) return flag.value.boolean;
- }
- unreachable;
- }
-
- pub fn argFlag(self: Self, flag_name: [*:0]const u8) ?[*:0]const u8 {
- for (self.flags) |flag| {
- if (cstr.cmp(flag.name, flag_name) == 0) return flag.value.arg;
- }
- unreachable;
- }
- };
-}