Bikeshed variable names

This commit is contained in:
Isaac Freund 2020-04-21 16:29:17 +02:00
parent 109a744007
commit 94760394b4
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
10 changed files with 125 additions and 129 deletions

View File

@ -94,7 +94,7 @@ pub const Cursor = struct {
fn handleAxis(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is forwarded by the cursor when a pointer emits an axis event,
// for example when you move the scroll wheel.
const cursor = @fieldParentPtr(Cursor, "listen_axis", listener.?);
const cursor = @fieldParentPtr(Self, "listen_axis", listener.?);
const event = @ptrCast(
*c.wlr_event_pointer_axis,
@alignCast(@alignOf(*c.wlr_event_pointer_axis), data),
@ -114,14 +114,14 @@ pub const Cursor = struct {
fn handleButton(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is forwarded by the cursor when a pointer emits a button
// event.
const cursor = @fieldParentPtr(Cursor, "listen_button", listener.?);
const self = @fieldParentPtr(Self, "listen_button", listener.?);
const event = @ptrCast(
*c.wlr_event_pointer_button,
@alignCast(@alignOf(*c.wlr_event_pointer_button), data),
);
// Notify the client with pointer focus that a button press has occurred
_ = c.wlr_seat_pointer_notify_button(
cursor.seat.wlr_seat,
self.seat.wlr_seat,
event.time_msec,
event.button,
event.state,
@ -131,9 +131,9 @@ pub const Cursor = struct {
var sy: f64 = undefined;
var surface: ?*c.wlr_surface = null;
const view = cursor.seat.input_manager.server.root.viewAt(
cursor.wlr_cursor.x,
cursor.wlr_cursor.y,
const view = self.seat.input_manager.server.root.viewAt(
self.wlr_cursor.x,
self.wlr_cursor.y,
&surface,
&sx,
&sy,
@ -141,11 +141,11 @@ pub const Cursor = struct {
if (event.state == c.enum_wlr_button_state.WLR_BUTTON_RELEASED) {
// If you released any buttons, we exit interactive move/resize mode.
cursor.mode = CursorMode.Passthrough;
self.mode = CursorMode.Passthrough;
} else {
// Focus that client if the button was _pressed_
if (view) |v| {
cursor.seat.focus(v);
self.seat.focus(v);
}
}
}
@ -155,9 +155,9 @@ pub const Cursor = struct {
// event. Frame events are sent after regular pointer events to group
// multiple events together. For instance, two axis events may happen at the
// same time, in which case a frame event won't be sent in between.
const cursor = @fieldParentPtr(Cursor, "listen_frame", listener.?);
const self = @fieldParentPtr(Self, "listen_frame", listener.?);
// Notify the client with pointer focus of the frame event.
c.wlr_seat_pointer_notify_frame(cursor.seat.wlr_seat);
c.wlr_seat_pointer_notify_frame(self.seat.wlr_seat);
}
fn processMove(self: Self, time: u32) void {
@ -176,19 +176,19 @@ pub const Cursor = struct {
// move the mouse over the window. You could enter the window from any edge,
// so we have to warp the mouse there. There is also some hardware which
// emits these events.
const cursor = @fieldParentPtr(Cursor, "listen_motion_absolute", listener.?);
const self = @fieldParentPtr(Self, "listen_motion_absolute", listener.?);
const event = @ptrCast(
*c.wlr_event_pointer_motion_absolute,
@alignCast(@alignOf(*c.wlr_event_pointer_motion_absolute), data),
);
c.wlr_cursor_warp_absolute(cursor.wlr_cursor, event.device, event.x, event.y);
cursor.processMotion(event.time_msec);
c.wlr_cursor_warp_absolute(self.wlr_cursor, event.device, event.x, event.y);
self.processMotion(event.time_msec);
}
fn handleMotion(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is forwarded by the cursor when a pointer emits a _relative_
// pointer motion event (i.e. a delta)
const cursor = @fieldParentPtr(Cursor, "listen_motion", listener.?);
const self = @fieldParentPtr(Self, "listen_motion", listener.?);
const event = @ptrCast(
*c.wlr_event_pointer_motion,
@alignCast(@alignOf(*c.wlr_event_pointer_motion), data),
@ -198,18 +198,18 @@ pub const Cursor = struct {
// special configuration applied for the specific input device which
// generated the event. You can pass NULL for the device if you want to move
// the cursor around without any input.
c.wlr_cursor_move(cursor.wlr_cursor, event.device, event.delta_x, event.delta_y);
cursor.processMotion(event.time_msec);
c.wlr_cursor_move(self.wlr_cursor, event.device, event.delta_x, event.delta_y);
self.processMotion(event.time_msec);
}
fn handleRequestSetCursor(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is rasied by the seat when a client provides a cursor image
const cursor = @fieldParentPtr(Cursor, "listen_request_set_cursor", listener.?);
const self = @fieldParentPtr(Self, "listen_request_set_cursor", listener.?);
const event = @ptrCast(
*c.wlr_seat_pointer_request_set_cursor_event,
@alignCast(@alignOf(*c.wlr_seat_pointer_request_set_cursor_event), data),
);
const focused_client = cursor.seat.wlr_seat.pointer_state.focused_client;
const focused_client = self.seat.wlr_seat.pointer_state.focused_client;
// This can be sent by any client, so we check to make sure this one is
// actually has pointer focus first.
@ -219,7 +219,7 @@ pub const Cursor = struct {
// on the output that it's currently on and continue to do so as the
// cursor moves between outputs.
c.wlr_cursor_set_surface(
cursor.wlr_cursor,
self.wlr_cursor,
event.surface,
event.hotspot_x,
event.hotspot_y,

View File

@ -27,10 +27,10 @@ pub const Decoration = struct {
}
fn handleRequestMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const decoration = @fieldParentPtr(Decoration, "listen_request_mode", listener.?);
const self = @fieldParentPtr(Self, "listen_request_mode", listener.?);
// TODO: we might need to take this configure serial and do a transaction
_ = c.wlr_xdg_toplevel_decoration_v1_set_mode(
decoration.wlr_xdg_toplevel_decoration,
self.wlr_xdg_toplevel_decoration,
c.wlr_xdg_toplevel_decoration_v1_mode.WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE,
);
}

View File

@ -28,18 +28,14 @@ pub const DecorationManager = struct {
}
fn handleNewToplevelDecoration(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const decoration_manager = @fieldParentPtr(
DecorationManager,
"listen_new_toplevel_decoration",
listener.?,
);
const self = @fieldParentPtr(Self, "listen_new_toplevel_decoration", listener.?);
const wlr_xdg_toplevel_decoration = @ptrCast(
*c.wlr_xdg_toplevel_decoration_v1,
@alignCast(@alignOf(*c.wlr_xdg_toplevel_decoration_v1), data),
);
const node = decoration_manager.decorations.allocateNode(decoration_manager.server.allocator) catch unreachable;
node.data.init(decoration_manager, wlr_xdg_toplevel_decoration);
decoration_manager.decorations.prepend(node);
const node = self.decorations.allocateNode(self.server.allocator) catch unreachable;
node.data.init(self, wlr_xdg_toplevel_decoration);
self.decorations.prepend(node);
}
};

View File

@ -119,11 +119,11 @@ pub const InputManager = struct {
/// This event is raised by the backend when a new input device becomes available.
fn handleNewInput(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const input_manager = @fieldParentPtr(InputManager, "listen_new_input", listener.?);
const self = @fieldParentPtr(Self, "listen_new_input", listener.?);
const device = @ptrCast(*c.wlr_input_device, @alignCast(@alignOf(*c.wlr_input_device), data));
// TODO: suport multiple seats
if (input_manager.seats.first) |seat_node| {
if (self.seats.first) |seat_node| {
seat_node.data.addDevice(device) catch unreachable;
}
}

View File

@ -54,13 +54,13 @@ pub const Keyboard = struct {
fn handleKey(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is raised when a key is pressed or released.
const keyboard = @fieldParentPtr(Keyboard, "listen_key", listener.?);
const self = @fieldParentPtr(Self, "listen_key", listener.?);
const event = @ptrCast(
*c.wlr_event_keyboard_key,
@alignCast(@alignOf(*c.wlr_event_keyboard_key), data),
);
const wlr_keyboard: *c.wlr_keyboard = keyboard.device.unnamed_133.keyboard;
const wlr_keyboard: *c.wlr_keyboard = self.device.unnamed_133.keyboard;
// Translate libinput keycode -> xkbcommon
const keycode = event.keycode + 8;
@ -91,10 +91,10 @@ pub const Keyboard = struct {
if (event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED) {
var i: usize = 0;
while (i < translated_keysyms_len) : (i += 1) {
if (keyboard.handleBuiltinKeybind(translated_keysyms.?[i])) {
if (self.handleBuiltinKeybind(translated_keysyms.?[i])) {
handled = true;
break;
} else if (keyboard.seat.handleKeybinding(translated_keysyms.?[i], modifiers)) {
} else if (self.seat.handleKeybinding(translated_keysyms.?[i], modifiers)) {
handled = true;
break;
}
@ -102,10 +102,10 @@ pub const Keyboard = struct {
if (!handled) {
i = 0;
while (i < raw_keysyms_len) : (i += 1) {
if (keyboard.handleBuiltinKeybind(raw_keysyms.?[i])) {
if (self.handleBuiltinKeybind(raw_keysyms.?[i])) {
handled = true;
break;
} else if (keyboard.seat.handleKeybinding(raw_keysyms.?[i], modifiers)) {
} else if (self.seat.handleKeybinding(raw_keysyms.?[i], modifiers)) {
handled = true;
break;
}
@ -115,8 +115,8 @@ pub const Keyboard = struct {
if (!handled) {
// Otherwise, we pass it along to the client.
const wlr_seat = keyboard.seat.wlr_seat;
c.wlr_seat_set_keyboard(wlr_seat, keyboard.device);
const wlr_seat = self.seat.wlr_seat;
c.wlr_seat_set_keyboard(wlr_seat, self.device);
c.wlr_seat_keyboard_notify_key(
wlr_seat,
event.time_msec,
@ -129,18 +129,18 @@ pub const Keyboard = struct {
fn handleModifiers(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is raised when a modifier key, such as shift or alt, is
// pressed. We simply communicate this to the client. */
const keyboard = @fieldParentPtr(Keyboard, "listen_modifiers", listener.?);
const self = @fieldParentPtr(Self, "listen_modifiers", listener.?);
// A seat can only have one keyboard, but this is a limitation of the
// Wayland protocol - not wlroots. We assign all connected keyboards to the
// same seat. You can swap out the underlying wlr_keyboard like this and
// wlr_seat handles this transparently.
c.wlr_seat_set_keyboard(keyboard.seat.wlr_seat, keyboard.device);
c.wlr_seat_set_keyboard(self.seat.wlr_seat, self.device);
// Send modifiers to the client.
c.wlr_seat_keyboard_notify_modifiers(
keyboard.seat.wlr_seat,
&keyboard.wlr_keyboard.modifiers,
self.seat.wlr_seat,
&self.wlr_keyboard.modifiers,
);
}

View File

@ -57,61 +57,61 @@ pub const LayerSurface = struct {
}
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const layer_surface = @fieldParentPtr(LayerSurface, "listen_destroy", listener.?);
const output = layer_surface.output;
const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
const output = self.output;
Log.Debug.log("Layer surface '{}' destroyed", .{layer_surface.wlr_layer_surface.namespace});
Log.Debug.log("Layer surface '{}' destroyed", .{self.wlr_layer_surface.namespace});
// Remove listeners active the entire lifetime of the layer surface
c.wl_list_remove(&layer_surface.listen_destroy.link);
c.wl_list_remove(&layer_surface.listen_map.link);
c.wl_list_remove(&layer_surface.listen_unmap.link);
c.wl_list_remove(&self.listen_destroy.link);
c.wl_list_remove(&self.listen_map.link);
c.wl_list_remove(&self.listen_unmap.link);
const node = @fieldParentPtr(std.TailQueue(LayerSurface).Node, "data", layer_surface);
output.layers[@intCast(usize, @enumToInt(layer_surface.layer))].remove(node);
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
output.layers[@intCast(usize, @enumToInt(self.layer))].remove(node);
output.root.server.allocator.destroy(node);
}
fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const layer_surface = @fieldParentPtr(LayerSurface, "listen_map", listener.?);
const wlr_layer_surface = layer_surface.wlr_layer_surface;
const self = @fieldParentPtr(Self, "listen_map", listener.?);
const wlr_layer_surface = self.wlr_layer_surface;
Log.Debug.log("Layer surface '{}' mapped.", .{wlr_layer_surface.namespace});
layer_surface.mapped = true;
self.mapped = true;
// Add listeners that are only active while mapped
layer_surface.listen_commit.notify = handleCommit;
c.wl_signal_add(&wlr_layer_surface.surface.*.events.commit, &layer_surface.listen_commit);
self.listen_commit.notify = handleCommit;
c.wl_signal_add(&wlr_layer_surface.surface.*.events.commit, &self.listen_commit);
layer_surface.listen_new_popup.notify = handleNewPopup;
c.wl_signal_add(&wlr_layer_surface.events.new_popup, &layer_surface.listen_new_popup);
self.listen_new_popup.notify = handleNewPopup;
c.wl_signal_add(&wlr_layer_surface.events.new_popup, &self.listen_new_popup);
c.wlr_surface_send_enter(
wlr_layer_surface.surface,
wlr_layer_surface.output,
);
layer_surface.output.arrangeLayers();
self.output.arrangeLayers();
}
fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const layer_surface = @fieldParentPtr(LayerSurface, "listen_unmap", listener.?);
const self = @fieldParentPtr(Self, "listen_unmap", listener.?);
Log.Debug.log("Layer surface '{}' unmapped.", .{layer_surface.wlr_layer_surface.namespace});
Log.Debug.log("Layer surface '{}' unmapped.", .{self.wlr_layer_surface.namespace});
layer_surface.mapped = false;
self.mapped = false;
// remove listeners only active while the layer surface is mapped
c.wl_list_remove(&layer_surface.listen_commit.link);
c.wl_list_remove(&layer_surface.listen_new_popup.link);
c.wl_list_remove(&self.listen_commit.link);
c.wl_list_remove(&self.listen_new_popup.link);
// If the unmapped surface is focused, clear focus
var it = layer_surface.output.root.server.input_manager.seats.first;
var it = self.output.root.server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const seat = &node.data;
if (seat.focused_layer) |current_focus| {
if (current_focus == layer_surface) {
if (current_focus == self) {
seat.setFocusRaw(.{ .none = {} });
}
}
@ -119,11 +119,11 @@ pub const LayerSurface = struct {
// This gives exclusive focus to a keyboard interactive top or overlay layer
// surface if there is one.
layer_surface.output.arrangeLayers();
self.output.arrangeLayers();
// Ensure that focus is given to the appropriate view if there is no
// other top/overlay layer surface to grab focus.
it = layer_surface.output.root.server.input_manager.seats.first;
it = self.output.root.server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const seat = &node.data;
seat.focus(null);
@ -131,34 +131,34 @@ pub const LayerSurface = struct {
}
fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const layer_surface = @fieldParentPtr(LayerSurface, "listen_commit", listener.?);
const wlr_layer_surface = layer_surface.wlr_layer_surface;
const self = @fieldParentPtr(Self, "listen_commit", listener.?);
const wlr_layer_surface = self.wlr_layer_surface;
if (layer_surface.wlr_layer_surface.output == null) {
if (self.wlr_layer_surface.output == null) {
Log.Error.log("Layer surface committed with null output", .{});
return;
}
// If the layer changed, move the LayerSurface to the proper list
if (layer_surface.layer != layer_surface.wlr_layer_surface.current.layer) {
const node = @fieldParentPtr(std.TailQueue(LayerSurface).Node, "data", layer_surface);
if (self.layer != self.wlr_layer_surface.current.layer) {
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
const old_layer_idx = @intCast(usize, @enumToInt(layer_surface.layer));
layer_surface.output.layers[old_layer_idx].remove(node);
const old_layer_idx = @intCast(usize, @enumToInt(self.layer));
self.output.layers[old_layer_idx].remove(node);
layer_surface.layer = layer_surface.wlr_layer_surface.current.layer;
self.layer = self.wlr_layer_surface.current.layer;
const new_layer_idx = @intCast(usize, @enumToInt(layer_surface.layer));
layer_surface.output.layers[new_layer_idx].append(node);
const new_layer_idx = @intCast(usize, @enumToInt(self.layer));
self.output.layers[new_layer_idx].append(node);
}
// TODO: only reconfigure if things haven't changed
// https://github.com/swaywm/wlroots/issues/1079
layer_surface.output.arrangeLayers();
self.output.arrangeLayers();
}
fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const layer_surface = @fieldParentPtr(LayerSurface, "listen_new_popup", listener.?);
const self = @fieldParentPtr(Self, "listen_new_popup", listener.?);
Log.Debug.log("new layer surface popup.", .{});
// TODO: handle popups
unreachable;

View File

@ -431,28 +431,28 @@ pub const Output = struct {
/// Called when the output is destroyed. Evacuate all views from the output
/// and then remove it from the list of outputs.
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const destroyed_output = @fieldParentPtr(Output, "listen_destroy", listener.?);
const root = destroyed_output.root;
const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
const root = self.root;
Log.Debug.log("Output {} destroyed", .{destroyed_output.wlr_output.name});
Log.Debug.log("Output {} destroyed", .{self.wlr_output.name});
// Use the first output in the list that is not the one being destroyed.
// If there is no other real output, use the noop output.
var output_it = root.outputs.first;
const fallback_output = while (output_it) |output_node| : (output_it = output_node.next) {
if (&output_node.data != destroyed_output) {
if (&output_node.data != self) {
break &output_node.data;
}
} else &root.noop_output;
// Move all views from the destroyed output to the fallback one
while (destroyed_output.views.last) |node| {
while (self.views.last) |node| {
const view = &node.view;
view.sendToOutput(fallback_output);
}
// Close all layer surfaces on the destroyed output
for (destroyed_output.layers) |*layer, layer_idx| {
for (self.layers) |*layer, layer_idx| {
while (layer.pop()) |node| {
const layer_surface = &node.data;
c.wlr_layer_surface_v1_close(layer_surface.wlr_layer_surface);
@ -470,22 +470,22 @@ pub const Output = struct {
var seat_it = root.server.input_manager.seats.first;
while (seat_it) |seat_node| : (seat_it = seat_node.next) {
const seat = &seat_node.data;
if (seat.focused_output == destroyed_output) {
if (seat.focused_output == self) {
seat.focused_output = fallback_output;
seat.focus(null);
}
}
// Remove all listeners
c.wl_list_remove(&destroyed_output.listen_destroy.link);
c.wl_list_remove(&destroyed_output.listen_frame.link);
c.wl_list_remove(&destroyed_output.listen_mode.link);
c.wl_list_remove(&self.listen_destroy.link);
c.wl_list_remove(&self.listen_frame.link);
c.wl_list_remove(&self.listen_mode.link);
// Clean up the wlr_output
destroyed_output.wlr_output.data = null;
self.wlr_output.data = null;
// Remove the destroyed output from the list
const node = @fieldParentPtr(std.TailQueue(Output).Node, "data", destroyed_output);
const node = @fieldParentPtr(std.TailQueue(Output).Node, "data", self);
root.outputs.remove(node);
root.server.allocator.destroy(node);
@ -496,13 +496,13 @@ pub const Output = struct {
fn handleFrame(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This function is called every time an output is ready to display a frame,
// generally at the output's refresh rate (e.g. 60Hz).
const output = @fieldParentPtr(Output, "listen_frame", listener.?);
render.renderOutput(output);
const self = @fieldParentPtr(Self, "listen_frame", listener.?);
render.renderOutput(self);
}
fn handleMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const output = @fieldParentPtr(Output, "listen_mode", listener.?);
output.arrangeLayers();
output.root.arrange();
const self = @fieldParentPtr(Self, "listen_mode", listener.?);
self.arrangeLayers();
self.root.arrange();
}
};

View File

@ -154,7 +154,7 @@ pub const Root = struct {
// TODO: log failure to create timer and commit immediately
self.transaction_timer = c.wl_event_loop_add_timer(
self.server.wl_event_loop,
handle_timeout,
handleTimeout,
self,
);
@ -167,7 +167,7 @@ pub const Root = struct {
}
}
fn handle_timeout(data: ?*c_void) callconv(.C) c_int {
fn handleTimeout(data: ?*c_void) callconv(.C) c_int {
const root = @ptrCast(*Root, @alignCast(@alignOf(*Root), data));
Log.Error.log("Transaction timed out. Some imperfect frames may be shown.", .{});

View File

@ -131,16 +131,16 @@ pub const Server = struct {
}
fn handleNewOutput(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const server = @fieldParentPtr(Server, "listen_new_output", listener.?);
const self = @fieldParentPtr(Self, "listen_new_output", listener.?);
const wlr_output = @ptrCast(*c.wlr_output, @alignCast(@alignOf(*c.wlr_output), data));
Log.Debug.log("New output {}", .{wlr_output.name});
server.root.addOutput(wlr_output);
self.root.addOutput(wlr_output);
}
fn handleNewXdgSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is raised when wlr_xdg_shell receives a new xdg surface from a
// client, either a toplevel (application window) or popup.
const server = @fieldParentPtr(Server, "listen_new_xdg_surface", listener.?);
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 != c.enum_wlr_xdg_surface_role.WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
@ -148,12 +148,12 @@ pub const Server = struct {
return;
}
server.input_manager.default_seat.focused_output.addView(wlr_xdg_surface);
self.input_manager.default_seat.focused_output.addView(wlr_xdg_surface);
}
/// This event is raised when the layer_shell recieves a new surface from a client.
fn handleNewLayerSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const server = @fieldParentPtr(Server, "listen_new_layer_surface", listener.?);
const self = @fieldParentPtr(Self, "listen_new_layer_surface", listener.?);
const wlr_layer_surface = @ptrCast(
*c.wlr_layer_surface_v1,
@alignCast(@alignOf(*c.wlr_layer_surface_v1), data),
@ -178,7 +178,7 @@ pub const Server = struct {
// If the new layer surface does not have an output assigned to it, use the
// first output or close the surface if none are available.
if (wlr_layer_surface.output == null) {
if (server.root.outputs.first) |node| {
if (self.root.outputs.first) |node| {
const output = &node.data;
Log.Debug.log(
"New layer surface had null output, assigning it to output {}",

View File

@ -137,68 +137,68 @@ pub const View = struct {
}
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const view = @fieldParentPtr(View, "listen_destroy", listener.?);
const output = view.output;
const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
const output = self.output;
// Remove listeners that are active for the entire lifetime of the view
c.wl_list_remove(&view.listen_destroy.link);
c.wl_list_remove(&view.listen_map.link);
c.wl_list_remove(&view.listen_unmap.link);
c.wl_list_remove(&self.listen_destroy.link);
c.wl_list_remove(&self.listen_map.link);
c.wl_list_remove(&self.listen_unmap.link);
// Remove the view from the stack
const node = @fieldParentPtr(ViewStack(View).Node, "view", view);
const node = @fieldParentPtr(ViewStack(View).Node, "view", self);
output.views.remove(node);
output.root.server.allocator.destroy(node);
}
/// Called when the surface is mapped, or ready to display on-screen.
fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const view = @fieldParentPtr(View, "listen_map", listener.?);
const root = view.output.root;
const self = @fieldParentPtr(Self, "listen_map", listener.?);
const root = self.output.root;
// Add listeners that are only active while mapped
view.listen_commit.notify = handleCommit;
c.wl_signal_add(&view.wlr_xdg_surface.surface.*.events.commit, &view.listen_commit);
self.listen_commit.notify = handleCommit;
c.wl_signal_add(&self.wlr_xdg_surface.surface.*.events.commit, &self.listen_commit);
view.mapped = true;
self.mapped = true;
// 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;
while (it) |seat_node| : (it = seat_node.next) {
seat_node.data.focus(view);
seat_node.data.focus(self);
}
c.wlr_surface_send_enter(view.wlr_xdg_surface.surface, view.output.wlr_output);
c.wlr_surface_send_enter(self.wlr_xdg_surface.surface, self.output.wlr_output);
view.output.root.arrange();
self.output.root.arrange();
}
/// Called when the surface is unmapped and will no longer be displayed.
fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const view = @fieldParentPtr(View, "listen_unmap", listener.?);
const root = view.output.root;
view.mapped = false;
const self = @fieldParentPtr(Self, "listen_unmap", listener.?);
const root = self.output.root;
self.mapped = false;
// Inform all seats that the view has been unmapped so they can handle focus
var it = root.server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const seat = &node.data;
seat.handleViewUnmap(view);
seat.handleViewUnmap(self);
}
root.arrange();
// Remove listeners that are only active while mapped
c.wl_list_remove(&view.listen_commit.link);
c.wl_list_remove(&self.listen_commit.link);
}
fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const view = @fieldParentPtr(View, "listen_commit", listener.?);
if (view.pending_serial) |s| {
if (s == view.wlr_xdg_surface.configure_serial) {
view.output.root.notifyConfigured();
view.pending_serial = null;
const self = @fieldParentPtr(Self, "listen_commit", listener.?);
if (self.pending_serial) |s| {
if (s == self.wlr_xdg_surface.configure_serial) {
self.output.root.notifyConfigured();
self.pending_serial = null;
}
}
// TODO: check for unexpected change in size and react as needed