Parially refactor commands to take a *Seat
This commit is contained in:
parent
b822084f39
commit
3cb52c4898
164
src/command.zig
164
src/command.zig
@ -2,7 +2,7 @@ const std = @import("std");
|
|||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Server = @import("server.zig").Server;
|
const Seat = @import("seat.zig").Seat;
|
||||||
const View = @import("view.zig").View;
|
const View = @import("view.zig").View;
|
||||||
const ViewStack = @import("view_stack.zig").ViewStack;
|
const ViewStack = @import("view_stack.zig").ViewStack;
|
||||||
|
|
||||||
@ -14,107 +14,162 @@ pub const Arg = union {
|
|||||||
none: void,
|
none: void,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Command = fn (server: *Server, arg: Arg) void;
|
pub const Command = fn (seat: *Seat, arg: Arg) void;
|
||||||
|
|
||||||
/// Exit the compositor, terminating the wayland session.
|
/// Exit the compositor, terminating the wayland session.
|
||||||
pub fn exitCompositor(server: *Server, arg: Arg) void {
|
pub fn exitCompositor(seat: *Seat, arg: Arg) void {
|
||||||
c.wl_display_terminate(server.wl_display);
|
c.wl_display_terminate(seat.input_manager.server.wl_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shift focus to the next visible view, wrapping if needed.
|
/// Focus the next visible view in the stack, wrapping if needed. Does
|
||||||
pub fn focusNextView(server: *Server, arg: Arg) void {
|
/// nothing if there is only one view in the stack.
|
||||||
server.root.focusNextView();
|
pub fn focusNextView(seat: *Seat, arg: Arg) void {
|
||||||
|
// FIXME: this need to be rewritten the next commit adding a focus stack
|
||||||
|
//const output = self.focusedOutput();
|
||||||
|
//if (self.focused_view) |current_focus| {
|
||||||
|
// // If there is a currently focused view, focus the next visible view in the stack.
|
||||||
|
// const current_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
|
||||||
|
// var it = ViewStack(View).iterator(current_node, output.current_focused_tags);
|
||||||
|
// // Skip past the current node
|
||||||
|
// _ = it.next();
|
||||||
|
// // Focus the next visible node if there is one
|
||||||
|
// if (it.next()) |node| {
|
||||||
|
// node.view.focus(node.view.wlr_xdg_surface.surface);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//// There is either no currently focused view or the last visible view in the
|
||||||
|
//// stack is focused and we need to wrap.
|
||||||
|
//var it = ViewStack(View).iterator(output.views.first, output.current_focused_tags);
|
||||||
|
//if (it.next()) |node| {
|
||||||
|
// node.view.focus(node.view.wlr_xdg_surface.surface);
|
||||||
|
//} else {
|
||||||
|
// // Otherwise clear the focus since there are no visible views
|
||||||
|
// self.clearFocus();
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shift focus to the previous visible view, wrapping if needed.
|
/// Focus the previous view in the stack, wrapping if needed. Does nothing
|
||||||
pub fn focusPrevView(server: *Server, arg: Arg) void {
|
/// if there is only one view in the stack.
|
||||||
server.root.focusPrevView();
|
pub fn focusPrevView(seat: *Seat, arg: Arg) void {
|
||||||
|
// FIXME: this need to be rewritten the next commit adding a focus stack
|
||||||
|
//const output = self.focusedOutput();
|
||||||
|
//if (self.focused_view) |current_focus| {
|
||||||
|
// // If there is a currently focused view, focus the previous visible view in the stack.
|
||||||
|
// const current_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
|
||||||
|
// var it = ViewStack(View).reverseIterator(current_node, output.current_focused_tags);
|
||||||
|
// // Skip past the current node
|
||||||
|
// _ = it.next();
|
||||||
|
// // Focus the previous visible node if there is one
|
||||||
|
// if (it.next()) |node| {
|
||||||
|
// node.view.focus(node.view.wlr_xdg_surface.surface);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//// There is either no currently focused view or the first visible view in the
|
||||||
|
//// stack is focused and we need to wrap.
|
||||||
|
//var it = ViewStack(View).reverseIterator(output.views.last, output.current_focused_tags);
|
||||||
|
//if (it.next()) |node| {
|
||||||
|
// node.view.focus(node.view.wlr_xdg_surface.surface);
|
||||||
|
//} else {
|
||||||
|
// // Otherwise clear the focus since there are no visible views
|
||||||
|
// self.clearFocus();
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modify the number of master views
|
/// Modify the number of master views
|
||||||
pub fn modifyMasterCount(server: *Server, arg: Arg) void {
|
pub fn modifyMasterCount(seat: *Seat, arg: Arg) void {
|
||||||
const delta = arg.int;
|
const delta = arg.int;
|
||||||
const output = server.root.focusedOutput();
|
const root = &seat.input_manager.server.root;
|
||||||
|
const output = root.focusedOutput();
|
||||||
output.master_count = @intCast(
|
output.master_count = @intCast(
|
||||||
u32,
|
u32,
|
||||||
std.math.max(0, @intCast(i32, output.master_count) + delta),
|
std.math.max(0, @intCast(i32, output.master_count) + delta),
|
||||||
);
|
);
|
||||||
server.root.arrange();
|
root.arrange();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modify the percent of the width of the screen that the master views occupy.
|
/// Modify the percent of the width of the screen that the master views occupy.
|
||||||
pub fn modifyMasterFactor(server: *Server, arg: Arg) void {
|
pub fn modifyMasterFactor(seat: *Seat, arg: Arg) void {
|
||||||
const delta = arg.float;
|
const delta = arg.float;
|
||||||
const output = server.root.focusedOutput();
|
const root = &seat.input_manager.server.root;
|
||||||
|
const output = root.focusedOutput();
|
||||||
const new_master_factor = std.math.min(
|
const new_master_factor = std.math.min(
|
||||||
std.math.max(output.master_factor + delta, 0.05),
|
std.math.max(output.master_factor + delta, 0.05),
|
||||||
0.95,
|
0.95,
|
||||||
);
|
);
|
||||||
if (new_master_factor != output.master_factor) {
|
if (new_master_factor != output.master_factor) {
|
||||||
output.master_factor = new_master_factor;
|
output.master_factor = new_master_factor;
|
||||||
server.root.arrange();
|
root.arrange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bump the focused view to the top of the stack.
|
/// Bump the focused view to the top of the stack.
|
||||||
/// TODO: if the top of the stack is focused, bump the next visible view.
|
/// TODO: if the top of the stack is focused, bump the next visible view.
|
||||||
pub fn zoom(server: *Server, arg: Arg) void {
|
pub fn zoom(seat: *Seat, arg: Arg) void {
|
||||||
if (server.root.focused_view) |current_focus| {
|
// FIXME rewrite after next commit adding focus stack
|
||||||
const output = server.root.focusedOutput();
|
//if (server.root.focused_view) |current_focus| {
|
||||||
const node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
|
// const output = server.root.focusedOutput();
|
||||||
if (node != output.views.first) {
|
// const node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
|
||||||
output.views.remove(node);
|
// if (node != output.views.first) {
|
||||||
output.views.push(node);
|
// output.views.remove(node);
|
||||||
server.root.arrange();
|
// output.views.push(node);
|
||||||
}
|
// server.root.arrange();
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Switch focus to the passed tags.
|
/// Switch focus to the passed tags.
|
||||||
pub fn focusTags(server: *Server, arg: Arg) void {
|
pub fn focusTags(seat: *Seat, arg: Arg) void {
|
||||||
const tags = arg.uint;
|
const tags = arg.uint;
|
||||||
const output = server.root.focusedOutput();
|
const root = &seat.input_manager.server.root;
|
||||||
|
const output = root.focusedOutput();
|
||||||
output.pending_focused_tags = tags;
|
output.pending_focused_tags = tags;
|
||||||
server.root.arrange();
|
root.arrange();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Toggle focus of the passsed tags.
|
/// Toggle focus of the passsed tags.
|
||||||
pub fn toggleTags(server: *Server, arg: Arg) void {
|
pub fn toggleTags(seat: *Seat, arg: Arg) void {
|
||||||
const tags = arg.uint;
|
const tags = arg.uint;
|
||||||
const output = server.root.focusedOutput();
|
const root = &seat.input_manager.server.root;
|
||||||
|
const output = root.focusedOutput();
|
||||||
const new_focused_tags = output.current_focused_tags ^ tags;
|
const new_focused_tags = output.current_focused_tags ^ tags;
|
||||||
if (new_focused_tags != 0) {
|
if (new_focused_tags != 0) {
|
||||||
output.pending_focused_tags = new_focused_tags;
|
output.pending_focused_tags = new_focused_tags;
|
||||||
server.root.arrange();
|
root.arrange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the tags of the focused view.
|
/// Set the tags of the focused view.
|
||||||
pub fn setFocusedViewTags(server: *Server, arg: Arg) void {
|
pub fn setFocusedViewTags(seat: *Seat, arg: Arg) void {
|
||||||
const tags = arg.uint;
|
// FIXME
|
||||||
if (server.root.focused_view) |view| {
|
//const tags = arg.uint;
|
||||||
if (view.current_tags != tags) {
|
//if (server.root.focused_view) |view| {
|
||||||
view.pending_tags = tags;
|
// if (view.current_tags != tags) {
|
||||||
server.root.arrange();
|
// view.pending_tags = tags;
|
||||||
}
|
// server.root.arrange();
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Toggle the passed tags of the focused view
|
/// Toggle the passed tags of the focused view
|
||||||
pub fn toggleFocusedViewTags(server: *Server, arg: Arg) void {
|
pub fn toggleFocusedViewTags(seat: *Seat, arg: Arg) void {
|
||||||
const tags = arg.uint;
|
// FIXME: rewrite afet next commit adding focus stack
|
||||||
if (server.root.focused_view) |view| {
|
//const tags = arg.uint;
|
||||||
const new_tags = view.current_tags ^ tags;
|
//if (server.root.focused_view) |view| {
|
||||||
if (new_tags != 0) {
|
// const new_tags = view.current_tags ^ tags;
|
||||||
view.pending_tags = new_tags;
|
// if (new_tags != 0) {
|
||||||
server.root.arrange();
|
// view.pending_tags = new_tags;
|
||||||
}
|
// server.root.arrange();
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn a program.
|
/// Spawn a program.
|
||||||
/// TODO: make this take a program as a paramter and spawn that
|
/// TODO: make this take a program as a paramter and spawn that
|
||||||
pub fn spawn(server: *Server, arg: Arg) void {
|
pub fn spawn(seat: *Seat, arg: Arg) void {
|
||||||
const cmd = arg.str;
|
const cmd = arg.str;
|
||||||
|
|
||||||
const argv = [_][]const u8{ "/bin/sh", "-c", cmd };
|
const argv = [_][]const u8{ "/bin/sh", "-c", cmd };
|
||||||
@ -129,8 +184,9 @@ pub fn spawn(server: *Server, arg: Arg) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Close the focused view, if any.
|
/// Close the focused view, if any.
|
||||||
pub fn close(server: *Server, arg: Arg) void {
|
pub fn close(seat: *Seat, arg: Arg) void {
|
||||||
if (server.root.focused_view) |view| {
|
// FIXME: see above
|
||||||
view.close();
|
//if (server.root.focused_view) |view| {
|
||||||
}
|
// view.close();
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
60
src/root.zig
60
src/root.zig
@ -89,62 +89,6 @@ pub const Root = struct {
|
|||||||
self.focused_view = null;
|
self.focused_view = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Focus the next visible view in the stack, wrapping if needed. Does
|
|
||||||
/// nothing if there is only one view in the stack.
|
|
||||||
pub fn focusNextView(self: *Self) void {
|
|
||||||
const output = self.focusedOutput();
|
|
||||||
if (self.focused_view) |current_focus| {
|
|
||||||
// If there is a currently focused view, focus the next visible view in the stack.
|
|
||||||
const current_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
|
|
||||||
var it = ViewStack(View).iterator(current_node, output.current_focused_tags);
|
|
||||||
// Skip past the current node
|
|
||||||
_ = it.next();
|
|
||||||
// Focus the next visible node if there is one
|
|
||||||
if (it.next()) |node| {
|
|
||||||
node.view.focus(node.view.wlr_xdg_surface.surface);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// There is either no currently focused view or the last visible view in the
|
|
||||||
// stack is focused and we need to wrap.
|
|
||||||
var it = ViewStack(View).iterator(output.views.first, output.current_focused_tags);
|
|
||||||
if (it.next()) |node| {
|
|
||||||
node.view.focus(node.view.wlr_xdg_surface.surface);
|
|
||||||
} else {
|
|
||||||
// Otherwise clear the focus since there are no visible views
|
|
||||||
self.clearFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Focus the previous view in the stack, wrapping if needed. Does nothing
|
|
||||||
/// if there is only one view in the stack.
|
|
||||||
pub fn focusPrevView(self: *Self) void {
|
|
||||||
const output = self.focusedOutput();
|
|
||||||
if (self.focused_view) |current_focus| {
|
|
||||||
// If there is a currently focused view, focus the previous visible view in the stack.
|
|
||||||
const current_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
|
|
||||||
var it = ViewStack(View).reverseIterator(current_node, output.current_focused_tags);
|
|
||||||
// Skip past the current node
|
|
||||||
_ = it.next();
|
|
||||||
// Focus the previous visible node if there is one
|
|
||||||
if (it.next()) |node| {
|
|
||||||
node.view.focus(node.view.wlr_xdg_surface.surface);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// There is either no currently focused view or the first visible view in the
|
|
||||||
// stack is focused and we need to wrap.
|
|
||||||
var it = ViewStack(View).reverseIterator(output.views.last, output.current_focused_tags);
|
|
||||||
if (it.next()) |node| {
|
|
||||||
node.view.focus(node.view.wlr_xdg_surface.surface);
|
|
||||||
} else {
|
|
||||||
// Otherwise clear the focus since there are no visible views
|
|
||||||
self.clearFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Arrange all outputs and then a transaction.
|
/// Arrange all outputs and then a transaction.
|
||||||
pub fn arrange(self: *Self) void {
|
pub fn arrange(self: *Self) void {
|
||||||
var it = self.outputs.first;
|
var it = self.outputs.first;
|
||||||
@ -257,7 +201,7 @@ pub const Root = struct {
|
|||||||
output.pending_focused_tags = null;
|
output.pending_focused_tags = null;
|
||||||
|
|
||||||
self.focused_view = null;
|
self.focused_view = null;
|
||||||
self.focusNextView();
|
Log.Error.log("FIXME: this needs to iterate over all seats and focus(null)", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
var view_it = ViewStack(View).iterator(output.views.first, 0xFFFFFFFF);
|
var view_it = ViewStack(View).iterator(output.views.first, 0xFFFFFFFF);
|
||||||
@ -281,7 +225,7 @@ pub const Root = struct {
|
|||||||
if (focus == view and
|
if (focus == view and
|
||||||
view.current_tags & output.current_focused_tags == 0)
|
view.current_tags & output.current_focused_tags == 0)
|
||||||
{
|
{
|
||||||
self.focusNextView();
|
Log.Error.log("FIXME: this needs to iterate over all seats and focus(null)", .{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,11 +36,11 @@ pub const Seat = struct {
|
|||||||
|
|
||||||
/// Handle any user-defined keybinding for the passed keysym and modifiers
|
/// Handle any user-defined keybinding for the passed keysym and modifiers
|
||||||
/// Returns true if the key was handled
|
/// Returns true if the key was handled
|
||||||
pub fn handleKeybinding(self: Self, keysym: c.xkb_keysym_t, modifiers: u32) bool {
|
pub fn handleKeybinding(self: *Self, keysym: c.xkb_keysym_t, modifiers: u32) bool {
|
||||||
for (self.input_manager.server.config.keybinds.items) |keybind| {
|
for (self.input_manager.server.config.keybinds.items) |keybind| {
|
||||||
if (modifiers == keybind.modifiers and keysym == keybind.keysym) {
|
if (modifiers == keybind.modifiers and keysym == keybind.keysym) {
|
||||||
// Execute the bound command
|
// Execute the bound command
|
||||||
keybind.command(self.input_manager.server, keybind.arg);
|
keybind.command(self, keybind.arg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,8 @@ pub const View = struct {
|
|||||||
// If the view being unmapped is focused
|
// If the view being unmapped is focused
|
||||||
if (current_focus == view) {
|
if (current_focus == view) {
|
||||||
// Focus the previous view. This clears the focus if there are no visible views.
|
// Focus the previous view. This clears the focus if there are no visible views.
|
||||||
root.focusPrevView();
|
// FIXME: must be fixed in next commit adding focus stack
|
||||||
|
//root.focusPrevView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user