2020-05-16 15:03:26 -07:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
2020-11-11 11:30:21 -08:00
|
|
|
// Copyright 2020 The River Developers
|
2020-05-16 15:03:26 -07:00
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
|
2020-05-26 13:55:07 -07:00
|
|
|
const Self = @This();
|
|
|
|
|
|
|
|
const std = @import("std");
|
2020-11-03 15:23:21 -08:00
|
|
|
const wlr = @import("wlroots");
|
|
|
|
const xkb = @import("xkbcommon");
|
2020-05-26 13:55:07 -07:00
|
|
|
|
2020-10-25 01:25:29 -07:00
|
|
|
const util = @import("util.zig");
|
2020-05-16 15:03:26 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
keysym: xkb.Keysym,
|
|
|
|
modifiers: wlr.Keyboard.ModifierMask,
|
2020-05-26 13:55:07 -07:00
|
|
|
command_args: []const []const u8,
|
|
|
|
|
2020-09-15 04:46:08 -07:00
|
|
|
/// When set to true the mapping will be executed on key release rather than on press
|
|
|
|
release: bool,
|
|
|
|
|
2020-05-26 13:55:07 -07:00
|
|
|
pub fn init(
|
2020-11-03 15:23:21 -08:00
|
|
|
keysym: xkb.Keysym,
|
|
|
|
modifiers: wlr.Keyboard.ModifierMask,
|
2020-09-15 04:46:08 -07:00
|
|
|
release: bool,
|
2020-05-26 13:55:07 -07:00
|
|
|
command_args: []const []const u8,
|
|
|
|
) !Self {
|
2020-10-25 01:25:29 -07:00
|
|
|
const owned_args = try util.gpa.alloc([]u8, command_args.len);
|
|
|
|
errdefer util.gpa.free(owned_args);
|
2020-08-21 11:06:26 -07:00
|
|
|
for (command_args) |arg, i| {
|
2020-10-25 01:25:29 -07:00
|
|
|
errdefer for (owned_args[0..i]) |a| util.gpa.free(a);
|
|
|
|
owned_args[i] = try std.mem.dupe(util.gpa, u8, arg);
|
2020-08-21 11:06:26 -07:00
|
|
|
}
|
2020-05-26 13:55:07 -07:00
|
|
|
return Self{
|
|
|
|
.keysym = keysym,
|
|
|
|
.modifiers = modifiers,
|
2020-09-15 04:46:08 -07:00
|
|
|
.release = release,
|
2020-05-26 13:55:07 -07:00
|
|
|
.command_args = owned_args,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-25 01:25:29 -07:00
|
|
|
pub fn deinit(self: Self) void {
|
|
|
|
for (self.command_args) |arg| util.gpa.free(arg);
|
|
|
|
util.gpa.free(self.command_args);
|
2020-05-26 13:55:07 -07:00
|
|
|
}
|