diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2020-04-22 22:50:03 +0200 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2020-04-22 22:51:18 +0200 |
| commit | 1362061c4cefc558470c188d894f75faaa4e9cb2 (patch) | |
| tree | 3e7228007807e02e7f6d372a96ff247800a91a5d /src/view.zig | |
| parent | 94760394b4b57fec09f4fed214dd2bf70993c857 (diff) | |
| download | river-1362061c4cefc558470c188d894f75faaa4e9cb2.tar.gz river-1362061c4cefc558470c188d894f75faaa4e9cb2.tar.xz | |
Implement floating views
Diffstat (limited to 'src/view.zig')
| -rw-r--r-- | src/view.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/view.zig b/src/view.zig index 9bde87d..3890013 100644 --- a/src/view.zig +++ b/src/view.zig @@ -14,9 +14,16 @@ pub const View = struct { mapped: bool, + /// If the view is floating or not + floating: bool, + current_box: Box, pending_box: ?Box, + /// The dimensions the view would have taken if we didn't force it to tile + natural_width: u32, + natural_height: u32, + current_tags: u32, pending_tags: ?u32, @@ -122,6 +129,22 @@ pub const View = struct { } } + /// If true is passsed, make the view float. If false, return it to the tiled + /// layout. + pub fn setFloating(self: *Self, float: bool) void { + if (float and !self.floating) { + self.floating = true; + self.pending_box = Box{ + .x = @intCast(i32, (self.output.usable_box.width - self.natural_width) / 2), + .y = @intCast(i32, (self.output.usable_box.height - self.natural_height) / 2), + .width = self.natural_width, + .height = self.natural_height, + }; + } else if (!float and self.floating) { + self.floating = false; + } + } + /// Move a view from one output to another, sending the required enter/leave /// events. pub fn sendToOutput(self: *Self, destination_output: *Output) void { @@ -161,6 +184,15 @@ pub const View = struct { c.wl_signal_add(&self.wlr_xdg_surface.surface.*.events.commit, &self.listen_commit); self.mapped = true; + self.floating = false; + + self.natural_width = @intCast(u32, self.wlr_xdg_surface.geometry.width); + self.natural_height = @intCast(u32, self.wlr_xdg_surface.geometry.height); + + if (self.natural_width == 0 and self.natural_height == 0) { + self.natural_width = @intCast(u32, self.wlr_xdg_surface.surface.*.current.width); + self.natural_height = @intCast(u32, self.wlr_xdg_surface.surface.*.current.height); + } // Focus the newly mapped view. Note: if a seat is focusing a different output // it will continue to do so. |
