Add keybind to close views

This commit is contained in:
Isaac Freund 2020-04-08 17:43:00 +02:00
parent dd480ca567
commit b2fbdf2d87
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
3 changed files with 16 additions and 0 deletions

View file

@ -111,3 +111,10 @@ pub fn spawn(server: *Server, arg: Arg) void {
const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch unreachable; const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch unreachable;
std.ChildProcess.spawn(child) catch unreachable; std.ChildProcess.spawn(child) catch unreachable;
} }
/// Close the focused view, if any.
pub fn close(server: *Server, arg: Arg) void {
if (server.root.focused_view) |view| {
view.close();
}
}

View file

@ -75,5 +75,7 @@ pub const Config = struct {
try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_0, .modifiers = mod, .command = command.focusTags, .arg = .{ .uint = 0xFFFFFFFF } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_0, .modifiers = mod, .command = command.focusTags, .arg = .{ .uint = 0xFFFFFFFF } });
try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_0, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.setFocusedViewTags, .arg = .{ .uint = 0xFFFFFFFF } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_0, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.setFocusedViewTags, .arg = .{ .uint = 0xFFFFFFFF } });
try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_q, .modifiers = mod, .command = command.close, .arg = .{ .none = {} } });
} }
}; };

View file

@ -126,6 +126,13 @@ pub const View = struct {
} }
} }
/// Send a close event to the view's client
pub fn close(self: Self) void {
// Note: we don't call arrange() here as it will be called
// automatically when the view is unmapped.
c.wlr_xdg_toplevel_send_close(self.wlr_xdg_surface);
}
fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// Called when the surface is mapped, or ready to display on-screen. // Called when the surface is mapped, or ready to display on-screen.
const view = @fieldParentPtr(View, "listen_map", listener.?); const view = @fieldParentPtr(View, "listen_map", listener.?);