Use tag masks for tag commands and clean up

This commit is contained in:
Isaac Freund
2020-06-02 15:19:08 +02:00
parent 0e9ecb6051
commit ea7f5d4064
9 changed files with 143 additions and 282 deletions

View File

@ -1,32 +0,0 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Isaac Freund
//
// 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 Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Set focus to all tags
pub fn focusAllTags(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
seat.focused_output.pending_focused_tags = 0xFFFFFFFF;
seat.input_manager.server.root.arrange();
}

View File

@ -1,37 +0,0 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Isaac Freund
//
// 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 Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Switch focus to the passed tag.
pub fn focusTag(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const tag = try std.fmt.parseInt(u32, args[1], 10);
const tags = @as(u32, 1) << @intCast(u5, tag - 1);
seat.focused_output.pending_focused_tags = tags;
seat.input_manager.server.root.arrange();
}

View File

@ -1,43 +0,0 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Isaac Freund
//
// 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 c = @import("../c.zig");
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Set the tag of the focused view.
pub fn tagView(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const tag = try std.fmt.parseInt(u32, args[1], 10);
const tags = @as(u32, 1) << @intCast(u5, tag - 1);
if (seat.focused_view) |view| {
if (view.current_tags != tags) {
view.pending_tags = tags;
seat.input_manager.server.root.arrange();
}
}
}

View File

@ -1,38 +0,0 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Isaac Freund
//
// 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 c = @import("../c.zig");
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Tag the focused view with all tags.
pub fn tagViewAllTags(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
if (seat.focused_view) |view| {
if (view.current_tags != 0xFFFFFFFF) {
view.pending_tags = 0xFFFFFFFF;
seat.input_manager.server.root.arrange();
}
}
}

102
river/command/tags.zig Normal file
View File

@ -0,0 +1,102 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Isaac Freund
//
// 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 Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Switch focus to the passed tags.
pub fn setFocusedTags(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
const tags = try parseTags(allocator, args, failure_message);
if (seat.focused_output.current_focused_tags != tags) {
seat.focused_output.pending_focused_tags = tags;
seat.input_manager.server.root.arrange();
}
}
/// Set the tags of the focused view.
pub fn setViewTags(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
const tags = try parseTags(allocator, args, failure_message);
if (seat.focused_view) |view| {
if (view.current_tags != tags) {
view.pending_tags = tags;
seat.input_manager.server.root.arrange();
}
}
}
/// Toggle focus of the passsed tags.
pub fn toggleFocusedTags(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
const tags = try parseTags(allocator, args, failure_message);
const output = seat.focused_output;
const new_focused_tags = output.current_focused_tags ^ tags;
if (new_focused_tags != 0) {
output.pending_focused_tags = new_focused_tags;
seat.input_manager.server.root.arrange();
}
}
/// Toggle the passed tags of the focused view
pub fn toggleViewTags(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
const tags = try parseTags(allocator, args, failure_message);
if (seat.focused_view) |view| {
const new_tags = view.current_tags ^ tags;
if (new_tags != 0) {
view.pending_tags = new_tags;
seat.input_manager.server.root.arrange();
}
}
}
fn parseTags(
allocator: *std.mem.Allocator,
args: []const []const u8,
failure_message: *[]const u8,
) Error!u32 {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const tags = try std.fmt.parseInt(u32, args[1], 10);
if (tags == 0) {
failure_message.* = try std.fmt.allocPrint(allocator, "tagmask may not be 0", .{});
return Error.CommandFailed;
}
return tags;
}

View File

@ -1,43 +0,0 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Isaac Freund
//
// 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 c = @import("../c.zig");
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Toggle focus of the passsed tags.
pub fn toggleTagFocus(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const tag = try std.fmt.parseInt(u32, args[1], 10);
const tags = @as(u32, 1) << @intCast(u5, tag - 1);
const output = seat.focused_output;
const new_focused_tags = output.current_focused_tags ^ tags;
if (new_focused_tags != 0) {
output.pending_focused_tags = new_focused_tags;
seat.input_manager.server.root.arrange();
}
}

View File

@ -1,44 +0,0 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Isaac Freund
//
// 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 c = @import("../c.zig");
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Toggle the passed tag of the focused view
pub fn toggleViewTag(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
failure_message: *[]const u8,
) Error!void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const tag = try std.fmt.parseInt(u32, args[1], 10);
const tags = @as(u32, 1) << @intCast(u5, tag - 1);
if (seat.focused_view) |view| {
const new_tags = view.current_tags ^ tags;
if (new_tags != 0) {
view.pending_tags = new_tags;
seat.input_manager.server.root.arrange();
}
}
}