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

commit6350fa30a47cff65ea11e7e6e0d6c997d035c8a8
parent9f45b6db1c
authorIsaac Freund <[email protected]>
date2020-04-22 23:35
Add a filter to start views in floating mode

 src/config.zig |  6 ++++++
 src/view.zig   | 12 ++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/src/config.zig b/src/config.zig
index caa6cd6..29f3792 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -26,12 +26,16 @@ pub const Config = struct {
     /// All user-defined keybindings
     keybinds: std.ArrayList(Keybind),
 
+    /// List of app_ids which will be started floating
+    float_filter: std.ArrayList([*:0]const u8),
+
     pub fn init(self: *Self, allocator: *std.mem.Allocator) !void {
         self.border_width = 2;
         self.view_padding = 8;
         self.outer_padding = 8;
 
         self.keybinds = std.ArrayList(Keybind).init(allocator);
+        self.float_filter = std.ArrayList([*:0]const u8).init(allocator);
 
         const mod = c.WLR_MODIFIER_LOGO;
 
@@ -197,5 +201,7 @@ pub const Config = struct {
             .command = command.toggleFloat,
             .arg = .{ .none = {} },
         });
+
+        try self.float_filter.append("float");
     }
 };
diff --git a/src/view.zig b/src/view.zig
index 3890013..875293f 100644
--- a/src/view.zig
+++ b/src/view.zig
@@ -2,6 +2,7 @@ const std = @import("std");
 const c = @import("c.zig");
 
 const Box = @import("box.zig").Box;
+const Log = @import("log.zig").Log;
 const Output = @import("output.zig").Output;
 const Root = @import("root.zig").Root;
 const ViewStack = @import("view_stack.zig").ViewStack;
@@ -194,6 +195,17 @@ pub const View = struct {
             self.natural_height = @intCast(u32, self.wlr_xdg_surface.surface.*.current.height);
         }
 
+        const app_id: [*:0]const u8 = self.wlr_xdg_surface.unnamed_164.toplevel.*.app_id;
+        Log.Debug.log("View with app_id '{}' mapped", .{app_id});
+
+        // Make views with app_ids listed in the float filter float
+        for (self.output.root.server.config.float_filter.items) |filter_app_id| {
+            if (std.mem.eql(u8, std.mem.span(app_id), std.mem.span(filter_app_id))) {
+                self.setFloating(true);
+                break;
+            }
+        }
+
         // Focus the newly mapped view. Note: if a seat is focusing a different output
         // it will continue to do so.
         var it = root.server.input_manager.seats.first;