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

commit8102524e97f8b4ba31d87c2c8b0f890c7ce19c2f
parent6ebdc38635
authorIsaac Freund <[email protected]>
date2020-04-27 16:25
Float child and fixed-size toplevels by default

Closes https://github.com/ifreund/river/issues/14

 src/server.zig       |  6 ++++--
 src/xdg_toplevel.zig | 26 +++++++++++++++++---------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/server.zig b/src/server.zig
index 3795f07..8e14fd8 100644
--- a/src/server.zig
+++ b/src/server.zig
@@ -145,11 +145,13 @@ pub const Server = struct {
         const self = @fieldParentPtr(Self, "listen_new_xdg_surface", listener.?);
         const wlr_xdg_surface = @ptrCast(*c.wlr_xdg_surface, @alignCast(@alignOf(*c.wlr_xdg_surface), data));
 
-        if (wlr_xdg_surface.role != .WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
-            // TODO: log
+        if (wlr_xdg_surface.role == .WLR_XDG_SURFACE_ROLE_POPUP) {
+            Log.Debug.log("New xdg_popup", .{});
             return;
         }
 
+        Log.Debug.log("New xdg_toplevel", .{});
+
         self.input_manager.default_seat.focused_output.addView(wlr_xdg_surface);
     }
 
diff --git a/src/xdg_toplevel.zig b/src/xdg_toplevel.zig
index 0bdfa7d..7abcd6e 100644
--- a/src/xdg_toplevel.zig
+++ b/src/xdg_toplevel.zig
@@ -69,6 +69,7 @@ pub fn forEachSurface(
 ) void {
     c.wlr_xdg_surface_for_each_surface(self.wlr_xdg_surface, iterator, user_data);
 }
+
 /// Called when the xdg surface is destroyed
 fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
     const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
@@ -109,17 +110,24 @@ fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
         view.natural_height = @intCast(u32, self.wlr_xdg_surface.surface.*.current.height);
     }
 
-    const app_id: ?[*:0]const u8 = self.wlr_xdg_surface.unnamed_166.toplevel.*.app_id;
-    Log.Debug.log("View with app_id '{}' mapped", .{if (app_id) |id| id else "NULL"});
+    const wlr_xdg_toplevel: *c.wlr_xdg_toplevel = self.wlr_xdg_surface.unnamed_166.toplevel;
+    const state = &wlr_xdg_toplevel.current;
+    const app_id: [*:0]const u8 = if (wlr_xdg_toplevel.app_id) |id| id else "NULL";
+
+    Log.Debug.log("View with app_id '{}' mapped", .{app_id});
 
-    // Make views with app_ids listed in the float filter float
-    if (app_id) |id| {
-        for (root.server.config.float_filter.items) |filter_app_id| {
-            if (std.mem.eql(u8, std.mem.span(id), std.mem.span(filter_app_id))) {
-                view.setFloating(true);
-                break;
-            }
+    for (root.server.config.float_filter.items) |filter_app_id| {
+        // Make views with app_ids listed in the float filter float
+        if (std.mem.eql(u8, std.mem.span(app_id), std.mem.span(filter_app_id))) {
+            view.setFloating(true);
+            break;
         }
+    } else if ((wlr_xdg_toplevel.parent != null) or
+        (state.min_width != 0 and state.min_height != 0 and
+        (state.min_width == state.max_width or state.min_height == state.max_height)))
+    {
+        // If the toplevel has a parent or is of fixed size make it float
+        view.setFloating(true);
     }
 
     // Focus the newly mapped view. Note: if a seat is focusing a different output