diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2020-04-23 17:27:18 +0200 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2020-04-23 17:27:18 +0200 |
| commit | 56400a5955603b8760a27f49ac4b33bcaa86b73c (patch) | |
| tree | b7059dac75f9a908bf479fe489fbc0d5835328f0 /src/view.zig | |
| parent | 0452f9ec23a847a624ed4f25098bdd94b2e2038c (diff) | |
| download | river-56400a5955603b8760a27f49ac4b33bcaa86b73c.tar.gz river-56400a5955603b8760a27f49ac4b33bcaa86b73c.tar.xz | |
Fix crash on non-toplevel views
Diffstat (limited to 'src/view.zig')
| -rw-r--r-- | src/view.zig | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/view.zig b/src/view.zig index 8e84066..41c7824 100644 --- a/src/view.zig +++ b/src/view.zig @@ -18,6 +18,9 @@ pub const View = struct { /// If the view is floating or not floating: bool, + /// True if the view is currentlt focused by at lease one seat + focused: bool, + current_box: Box, pending_box: ?Box, @@ -52,6 +55,8 @@ pub const View = struct { self.mapped = false; + self.focused = false; + self.current_box = Box{ .x = 0, .y = 0, @@ -130,6 +135,16 @@ pub const View = struct { } } + /// Set the focued bool and the active state of the view if it is a toplevel + pub fn setFocused(self: *Self, focused: bool) void { + self.focused = focused; + if (self.wlr_xdg_surface.role == + c.enum_wlr_xdg_surface_role.WLR_XDG_SURFACE_ROLE_TOPLEVEL) + { + _ = c.wlr_xdg_toplevel_set_activated(self.wlr_xdg_surface, focused); + } + } + /// If true is passsed, make the view float. If false, return it to the tiled /// layout. pub fn setFloating(self: *Self, float: bool) void { @@ -197,14 +212,16 @@ 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}); + const app_id: ?[*:0]const u8 = self.wlr_xdg_surface.unnamed_165.toplevel.*.app_id; + Log.Debug.log("View with app_id '{}' mapped", .{if (app_id) |id| id else "NULL"}); // 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; + if (app_id) |id| { + for (self.output.root.server.config.float_filter.items) |filter_app_id| { + if (std.mem.eql(u8, std.mem.span(id), std.mem.span(filter_app_id))) { + self.setFloating(true); + break; + } } } @@ -250,11 +267,6 @@ pub const View = struct { // TODO: check for unexpected change in size and react as needed } - /// Set the active state of the view to the passed bool - pub fn setActivated(self: Self, activated: bool) void { - _ = c.wlr_xdg_toplevel_set_activated(self.wlr_xdg_surface, activated); - } - fn isAt(self: Self, lx: f64, ly: f64, surface: *?*c.wlr_surface, sx: *f64, sy: *f64) bool { // XDG toplevels may have nested surfaces, such as popup windows for context // menus or tooltips. This function tests if any of those are underneath the |
