git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit510998cec90456c80f21a5951f36f2f2fb9f5a79
parent7658e77d74
authorIsaac Freund <[email protected]>
date2020-04-08 17:43
Add keybind to close views

 src/command.zig | 7 +++++++
 src/config.zig  | 2 ++
 src/view.zig    | 7 +++++++
 3 files changed, 16 insertions(+)

diff --git a/src/command.zig b/src/command.zig
index add31ea..7aac7f6 100644
--- a/src/command.zig
+++ b/src/command.zig
@@ -111,3 +111,10 @@ pub fn spawn(server: *Server, arg: Arg) void {
     const child = std.ChildProcess.init(&argv, std.heap.c_allocator) 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();
+    }
+}
diff --git a/src/config.zig b/src/config.zig
index 7e70778..1434f07 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -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 | 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 = {} } });
     }
 };
diff --git a/src/view.zig b/src/view.zig
index 17a0621..71a00f2 100644
--- a/src/view.zig
+++ b/src/view.zig
@@ -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 {
         // Called when the surface is mapped, or ready to display on-screen.
         const view = @fieldParentPtr(View, "listen_map", listener.?);