Fix crash on non-toplevel views

This commit is contained in:
Isaac Freund 2020-04-23 17:27:18 +02:00
parent 0452f9ec23
commit 56400a5955
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
4 changed files with 28 additions and 16 deletions

View file

@ -17,7 +17,7 @@ pub const Keyboard = struct {
pub fn init(self: *Self, seat: *Seat, device: *c.wlr_input_device) !void {
self.seat = seat;
self.device = device;
self.wlr_keyboard = device.unnamed_133.keyboard;
self.wlr_keyboard = device.unnamed_134.keyboard;
// We need to prepare an XKB keymap and assign it to the keyboard. This
// assumes the defaults (e.g. layout = "us").
@ -60,7 +60,7 @@ pub const Keyboard = struct {
@alignCast(@alignOf(*c.wlr_event_keyboard_key), data),
);
const wlr_keyboard: *c.wlr_keyboard = self.device.unnamed_133.keyboard;
const wlr_keyboard: *c.wlr_keyboard = self.device.unnamed_134.keyboard;
// Translate libinput keycode -> xkbcommon
const keycode = event.keycode + 8;

View file

@ -262,7 +262,7 @@ fn renderSurface(_surface: ?*c.wlr_surface, sx: c_int, sy: c_int, data: ?*c_void
fn renderBorders(output: Output, view: *View, now: *c.timespec) void {
var border: c.wlr_box = undefined;
const color = if (view.wlr_xdg_surface.unnamed_164.toplevel.*.current.activated)
const color = if (view.focused)
[_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 } // Solarized base1
else
[_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }; // Solarized base01

View file

@ -159,7 +159,7 @@ pub const Seat = struct {
// First clear the current focus
if (self.focused_view) |current_focus| {
std.debug.assert(self.focused_layer == null);
current_focus.setActivated(false);
current_focus.setFocused(false);
self.focused_view = null;
}
if (self.focused_layer) |current_focus| {
@ -172,7 +172,7 @@ pub const Seat = struct {
switch (focus_target) {
.view => |target_view| {
std.debug.assert(self.focused_output == target_view.output);
target_view.setActivated(true);
target_view.setFocused(true);
self.focused_view = target_view;
},
.layer => |target_layer| blk: {

View file

@ -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,16 +212,18 @@ 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
if (app_id) |id| {
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))) {
if (std.mem.eql(u8, std.mem.span(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.
@ -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