Bikeshed variable names
This commit is contained in:
parent
109a744007
commit
94760394b4
@ -94,7 +94,7 @@ pub const Cursor = struct {
|
|||||||
fn handleAxis(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
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,
|
// This event is forwarded by the cursor when a pointer emits an axis event,
|
||||||
// for example when you move the scroll wheel.
|
// 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(
|
const event = @ptrCast(
|
||||||
*c.wlr_event_pointer_axis,
|
*c.wlr_event_pointer_axis,
|
||||||
@alignCast(@alignOf(*c.wlr_event_pointer_axis), data),
|
@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 {
|
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
|
// This event is forwarded by the cursor when a pointer emits a button
|
||||||
// event.
|
// event.
|
||||||
const cursor = @fieldParentPtr(Cursor, "listen_button", listener.?);
|
const self = @fieldParentPtr(Self, "listen_button", listener.?);
|
||||||
const event = @ptrCast(
|
const event = @ptrCast(
|
||||||
*c.wlr_event_pointer_button,
|
*c.wlr_event_pointer_button,
|
||||||
@alignCast(@alignOf(*c.wlr_event_pointer_button), data),
|
@alignCast(@alignOf(*c.wlr_event_pointer_button), data),
|
||||||
);
|
);
|
||||||
// Notify the client with pointer focus that a button press has occurred
|
// Notify the client with pointer focus that a button press has occurred
|
||||||
_ = c.wlr_seat_pointer_notify_button(
|
_ = c.wlr_seat_pointer_notify_button(
|
||||||
cursor.seat.wlr_seat,
|
self.seat.wlr_seat,
|
||||||
event.time_msec,
|
event.time_msec,
|
||||||
event.button,
|
event.button,
|
||||||
event.state,
|
event.state,
|
||||||
@ -131,9 +131,9 @@ pub const Cursor = struct {
|
|||||||
var sy: f64 = undefined;
|
var sy: f64 = undefined;
|
||||||
|
|
||||||
var surface: ?*c.wlr_surface = null;
|
var surface: ?*c.wlr_surface = null;
|
||||||
const view = cursor.seat.input_manager.server.root.viewAt(
|
const view = self.seat.input_manager.server.root.viewAt(
|
||||||
cursor.wlr_cursor.x,
|
self.wlr_cursor.x,
|
||||||
cursor.wlr_cursor.y,
|
self.wlr_cursor.y,
|
||||||
&surface,
|
&surface,
|
||||||
&sx,
|
&sx,
|
||||||
&sy,
|
&sy,
|
||||||
@ -141,11 +141,11 @@ pub const Cursor = struct {
|
|||||||
|
|
||||||
if (event.state == c.enum_wlr_button_state.WLR_BUTTON_RELEASED) {
|
if (event.state == c.enum_wlr_button_state.WLR_BUTTON_RELEASED) {
|
||||||
// If you released any buttons, we exit interactive move/resize mode.
|
// If you released any buttons, we exit interactive move/resize mode.
|
||||||
cursor.mode = CursorMode.Passthrough;
|
self.mode = CursorMode.Passthrough;
|
||||||
} else {
|
} else {
|
||||||
// Focus that client if the button was _pressed_
|
// Focus that client if the button was _pressed_
|
||||||
if (view) |v| {
|
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
|
// event. Frame events are sent after regular pointer events to group
|
||||||
// multiple events together. For instance, two axis events may happen at the
|
// 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.
|
// 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.
|
// 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 {
|
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,
|
// 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
|
// so we have to warp the mouse there. There is also some hardware which
|
||||||
// emits these events.
|
// emits these events.
|
||||||
const cursor = @fieldParentPtr(Cursor, "listen_motion_absolute", listener.?);
|
const self = @fieldParentPtr(Self, "listen_motion_absolute", listener.?);
|
||||||
const event = @ptrCast(
|
const event = @ptrCast(
|
||||||
*c.wlr_event_pointer_motion_absolute,
|
*c.wlr_event_pointer_motion_absolute,
|
||||||
@alignCast(@alignOf(*c.wlr_event_pointer_motion_absolute), data),
|
@alignCast(@alignOf(*c.wlr_event_pointer_motion_absolute), data),
|
||||||
);
|
);
|
||||||
c.wlr_cursor_warp_absolute(cursor.wlr_cursor, event.device, event.x, event.y);
|
c.wlr_cursor_warp_absolute(self.wlr_cursor, event.device, event.x, event.y);
|
||||||
cursor.processMotion(event.time_msec);
|
self.processMotion(event.time_msec);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleMotion(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
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_
|
// This event is forwarded by the cursor when a pointer emits a _relative_
|
||||||
// pointer motion event (i.e. a delta)
|
// pointer motion event (i.e. a delta)
|
||||||
const cursor = @fieldParentPtr(Cursor, "listen_motion", listener.?);
|
const self = @fieldParentPtr(Self, "listen_motion", listener.?);
|
||||||
const event = @ptrCast(
|
const event = @ptrCast(
|
||||||
*c.wlr_event_pointer_motion,
|
*c.wlr_event_pointer_motion,
|
||||||
@alignCast(@alignOf(*c.wlr_event_pointer_motion), data),
|
@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
|
// special configuration applied for the specific input device which
|
||||||
// generated the event. You can pass NULL for the device if you want to move
|
// generated the event. You can pass NULL for the device if you want to move
|
||||||
// the cursor around without any input.
|
// the cursor around without any input.
|
||||||
c.wlr_cursor_move(cursor.wlr_cursor, event.device, event.delta_x, event.delta_y);
|
c.wlr_cursor_move(self.wlr_cursor, event.device, event.delta_x, event.delta_y);
|
||||||
cursor.processMotion(event.time_msec);
|
self.processMotion(event.time_msec);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleRequestSetCursor(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
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
|
// 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(
|
const event = @ptrCast(
|
||||||
*c.wlr_seat_pointer_request_set_cursor_event,
|
*c.wlr_seat_pointer_request_set_cursor_event,
|
||||||
@alignCast(@alignOf(*c.wlr_seat_pointer_request_set_cursor_event), data),
|
@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
|
// This can be sent by any client, so we check to make sure this one is
|
||||||
// actually has pointer focus first.
|
// 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
|
// on the output that it's currently on and continue to do so as the
|
||||||
// cursor moves between outputs.
|
// cursor moves between outputs.
|
||||||
c.wlr_cursor_set_surface(
|
c.wlr_cursor_set_surface(
|
||||||
cursor.wlr_cursor,
|
self.wlr_cursor,
|
||||||
event.surface,
|
event.surface,
|
||||||
event.hotspot_x,
|
event.hotspot_x,
|
||||||
event.hotspot_y,
|
event.hotspot_y,
|
||||||
|
@ -27,10 +27,10 @@ pub const Decoration = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handleRequestMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
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
|
// TODO: we might need to take this configure serial and do a transaction
|
||||||
_ = c.wlr_xdg_toplevel_decoration_v1_set_mode(
|
_ = 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,
|
c.wlr_xdg_toplevel_decoration_v1_mode.WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -28,18 +28,14 @@ pub const DecorationManager = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handleNewToplevelDecoration(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleNewToplevelDecoration(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const decoration_manager = @fieldParentPtr(
|
const self = @fieldParentPtr(Self, "listen_new_toplevel_decoration", listener.?);
|
||||||
DecorationManager,
|
|
||||||
"listen_new_toplevel_decoration",
|
|
||||||
listener.?,
|
|
||||||
);
|
|
||||||
const wlr_xdg_toplevel_decoration = @ptrCast(
|
const wlr_xdg_toplevel_decoration = @ptrCast(
|
||||||
*c.wlr_xdg_toplevel_decoration_v1,
|
*c.wlr_xdg_toplevel_decoration_v1,
|
||||||
@alignCast(@alignOf(*c.wlr_xdg_toplevel_decoration_v1), data),
|
@alignCast(@alignOf(*c.wlr_xdg_toplevel_decoration_v1), data),
|
||||||
);
|
);
|
||||||
|
|
||||||
const node = decoration_manager.decorations.allocateNode(decoration_manager.server.allocator) catch unreachable;
|
const node = self.decorations.allocateNode(self.server.allocator) catch unreachable;
|
||||||
node.data.init(decoration_manager, wlr_xdg_toplevel_decoration);
|
node.data.init(self, wlr_xdg_toplevel_decoration);
|
||||||
decoration_manager.decorations.prepend(node);
|
self.decorations.prepend(node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -119,11 +119,11 @@ pub const InputManager = struct {
|
|||||||
|
|
||||||
/// This event is raised by the backend when a new input device becomes available.
|
/// 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 {
|
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));
|
const device = @ptrCast(*c.wlr_input_device, @alignCast(@alignOf(*c.wlr_input_device), data));
|
||||||
|
|
||||||
// TODO: suport multiple seats
|
// TODO: suport multiple seats
|
||||||
if (input_manager.seats.first) |seat_node| {
|
if (self.seats.first) |seat_node| {
|
||||||
seat_node.data.addDevice(device) catch unreachable;
|
seat_node.data.addDevice(device) catch unreachable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,13 +54,13 @@ pub const Keyboard = struct {
|
|||||||
|
|
||||||
fn handleKey(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleKey(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
// This event is raised when a key is pressed or released.
|
// 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(
|
const event = @ptrCast(
|
||||||
*c.wlr_event_keyboard_key,
|
*c.wlr_event_keyboard_key,
|
||||||
@alignCast(@alignOf(*c.wlr_event_keyboard_key), data),
|
@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
|
// Translate libinput keycode -> xkbcommon
|
||||||
const keycode = event.keycode + 8;
|
const keycode = event.keycode + 8;
|
||||||
@ -91,10 +91,10 @@ pub const Keyboard = struct {
|
|||||||
if (event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED) {
|
if (event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED) {
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (i < translated_keysyms_len) : (i += 1) {
|
while (i < translated_keysyms_len) : (i += 1) {
|
||||||
if (keyboard.handleBuiltinKeybind(translated_keysyms.?[i])) {
|
if (self.handleBuiltinKeybind(translated_keysyms.?[i])) {
|
||||||
handled = true;
|
handled = true;
|
||||||
break;
|
break;
|
||||||
} else if (keyboard.seat.handleKeybinding(translated_keysyms.?[i], modifiers)) {
|
} else if (self.seat.handleKeybinding(translated_keysyms.?[i], modifiers)) {
|
||||||
handled = true;
|
handled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -102,10 +102,10 @@ pub const Keyboard = struct {
|
|||||||
if (!handled) {
|
if (!handled) {
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < raw_keysyms_len) : (i += 1) {
|
while (i < raw_keysyms_len) : (i += 1) {
|
||||||
if (keyboard.handleBuiltinKeybind(raw_keysyms.?[i])) {
|
if (self.handleBuiltinKeybind(raw_keysyms.?[i])) {
|
||||||
handled = true;
|
handled = true;
|
||||||
break;
|
break;
|
||||||
} else if (keyboard.seat.handleKeybinding(raw_keysyms.?[i], modifiers)) {
|
} else if (self.seat.handleKeybinding(raw_keysyms.?[i], modifiers)) {
|
||||||
handled = true;
|
handled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -115,8 +115,8 @@ pub const Keyboard = struct {
|
|||||||
|
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
// Otherwise, we pass it along to the client.
|
// Otherwise, we pass it along to the client.
|
||||||
const wlr_seat = keyboard.seat.wlr_seat;
|
const wlr_seat = self.seat.wlr_seat;
|
||||||
c.wlr_seat_set_keyboard(wlr_seat, keyboard.device);
|
c.wlr_seat_set_keyboard(wlr_seat, self.device);
|
||||||
c.wlr_seat_keyboard_notify_key(
|
c.wlr_seat_keyboard_notify_key(
|
||||||
wlr_seat,
|
wlr_seat,
|
||||||
event.time_msec,
|
event.time_msec,
|
||||||
@ -129,18 +129,18 @@ pub const Keyboard = struct {
|
|||||||
fn handleModifiers(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
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
|
// This event is raised when a modifier key, such as shift or alt, is
|
||||||
// pressed. We simply communicate this to the client. */
|
// 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
|
// 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
|
// Wayland protocol - not wlroots. We assign all connected keyboards to the
|
||||||
// same seat. You can swap out the underlying wlr_keyboard like this and
|
// same seat. You can swap out the underlying wlr_keyboard like this and
|
||||||
// wlr_seat handles this transparently.
|
// 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.
|
// Send modifiers to the client.
|
||||||
c.wlr_seat_keyboard_notify_modifiers(
|
c.wlr_seat_keyboard_notify_modifiers(
|
||||||
keyboard.seat.wlr_seat,
|
self.seat.wlr_seat,
|
||||||
&keyboard.wlr_keyboard.modifiers,
|
&self.wlr_keyboard.modifiers,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,61 +57,61 @@ pub const LayerSurface = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const layer_surface = @fieldParentPtr(LayerSurface, "listen_destroy", listener.?);
|
const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
|
||||||
const output = layer_surface.output;
|
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
|
// Remove listeners active the entire lifetime of the layer surface
|
||||||
c.wl_list_remove(&layer_surface.listen_destroy.link);
|
c.wl_list_remove(&self.listen_destroy.link);
|
||||||
c.wl_list_remove(&layer_surface.listen_map.link);
|
c.wl_list_remove(&self.listen_map.link);
|
||||||
c.wl_list_remove(&layer_surface.listen_unmap.link);
|
c.wl_list_remove(&self.listen_unmap.link);
|
||||||
|
|
||||||
const node = @fieldParentPtr(std.TailQueue(LayerSurface).Node, "data", layer_surface);
|
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
|
||||||
output.layers[@intCast(usize, @enumToInt(layer_surface.layer))].remove(node);
|
output.layers[@intCast(usize, @enumToInt(self.layer))].remove(node);
|
||||||
output.root.server.allocator.destroy(node);
|
output.root.server.allocator.destroy(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const layer_surface = @fieldParentPtr(LayerSurface, "listen_map", listener.?);
|
const self = @fieldParentPtr(Self, "listen_map", listener.?);
|
||||||
const wlr_layer_surface = layer_surface.wlr_layer_surface;
|
const wlr_layer_surface = self.wlr_layer_surface;
|
||||||
|
|
||||||
Log.Debug.log("Layer surface '{}' mapped.", .{wlr_layer_surface.namespace});
|
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
|
// Add listeners that are only active while mapped
|
||||||
layer_surface.listen_commit.notify = handleCommit;
|
self.listen_commit.notify = handleCommit;
|
||||||
c.wl_signal_add(&wlr_layer_surface.surface.*.events.commit, &layer_surface.listen_commit);
|
c.wl_signal_add(&wlr_layer_surface.surface.*.events.commit, &self.listen_commit);
|
||||||
|
|
||||||
layer_surface.listen_new_popup.notify = handleNewPopup;
|
self.listen_new_popup.notify = handleNewPopup;
|
||||||
c.wl_signal_add(&wlr_layer_surface.events.new_popup, &layer_surface.listen_new_popup);
|
c.wl_signal_add(&wlr_layer_surface.events.new_popup, &self.listen_new_popup);
|
||||||
|
|
||||||
c.wlr_surface_send_enter(
|
c.wlr_surface_send_enter(
|
||||||
wlr_layer_surface.surface,
|
wlr_layer_surface.surface,
|
||||||
wlr_layer_surface.output,
|
wlr_layer_surface.output,
|
||||||
);
|
);
|
||||||
|
|
||||||
layer_surface.output.arrangeLayers();
|
self.output.arrangeLayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
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
|
// remove listeners only active while the layer surface is mapped
|
||||||
c.wl_list_remove(&layer_surface.listen_commit.link);
|
c.wl_list_remove(&self.listen_commit.link);
|
||||||
c.wl_list_remove(&layer_surface.listen_new_popup.link);
|
c.wl_list_remove(&self.listen_new_popup.link);
|
||||||
|
|
||||||
// If the unmapped surface is focused, clear focus
|
// 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) {
|
while (it) |node| : (it = node.next) {
|
||||||
const seat = &node.data;
|
const seat = &node.data;
|
||||||
if (seat.focused_layer) |current_focus| {
|
if (seat.focused_layer) |current_focus| {
|
||||||
if (current_focus == layer_surface) {
|
if (current_focus == self) {
|
||||||
seat.setFocusRaw(.{ .none = {} });
|
seat.setFocusRaw(.{ .none = {} });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,11 +119,11 @@ pub const LayerSurface = struct {
|
|||||||
|
|
||||||
// This gives exclusive focus to a keyboard interactive top or overlay layer
|
// This gives exclusive focus to a keyboard interactive top or overlay layer
|
||||||
// surface if there is one.
|
// 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
|
// Ensure that focus is given to the appropriate view if there is no
|
||||||
// other top/overlay layer surface to grab focus.
|
// 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) {
|
while (it) |node| : (it = node.next) {
|
||||||
const seat = &node.data;
|
const seat = &node.data;
|
||||||
seat.focus(null);
|
seat.focus(null);
|
||||||
@ -131,34 +131,34 @@ pub const LayerSurface = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const layer_surface = @fieldParentPtr(LayerSurface, "listen_commit", listener.?);
|
const self = @fieldParentPtr(Self, "listen_commit", listener.?);
|
||||||
const wlr_layer_surface = layer_surface.wlr_layer_surface;
|
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", .{});
|
Log.Error.log("Layer surface committed with null output", .{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the layer changed, move the LayerSurface to the proper list
|
// If the layer changed, move the LayerSurface to the proper list
|
||||||
if (layer_surface.layer != layer_surface.wlr_layer_surface.current.layer) {
|
if (self.layer != self.wlr_layer_surface.current.layer) {
|
||||||
const node = @fieldParentPtr(std.TailQueue(LayerSurface).Node, "data", layer_surface);
|
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
|
||||||
|
|
||||||
const old_layer_idx = @intCast(usize, @enumToInt(layer_surface.layer));
|
const old_layer_idx = @intCast(usize, @enumToInt(self.layer));
|
||||||
layer_surface.output.layers[old_layer_idx].remove(node);
|
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));
|
const new_layer_idx = @intCast(usize, @enumToInt(self.layer));
|
||||||
layer_surface.output.layers[new_layer_idx].append(node);
|
self.output.layers[new_layer_idx].append(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: only reconfigure if things haven't changed
|
// TODO: only reconfigure if things haven't changed
|
||||||
// https://github.com/swaywm/wlroots/issues/1079
|
// 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 {
|
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.", .{});
|
Log.Debug.log("new layer surface popup.", .{});
|
||||||
// TODO: handle popups
|
// TODO: handle popups
|
||||||
unreachable;
|
unreachable;
|
||||||
|
@ -431,28 +431,28 @@ pub const Output = struct {
|
|||||||
/// Called when the output is destroyed. Evacuate all views from the output
|
/// Called when the output is destroyed. Evacuate all views from the output
|
||||||
/// and then remove it from the list of outputs.
|
/// and then remove it from the list of outputs.
|
||||||
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const destroyed_output = @fieldParentPtr(Output, "listen_destroy", listener.?);
|
const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
|
||||||
const root = destroyed_output.root;
|
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.
|
// 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.
|
// If there is no other real output, use the noop output.
|
||||||
var output_it = root.outputs.first;
|
var output_it = root.outputs.first;
|
||||||
const fallback_output = while (output_it) |output_node| : (output_it = output_node.next) {
|
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;
|
break &output_node.data;
|
||||||
}
|
}
|
||||||
} else &root.noop_output;
|
} else &root.noop_output;
|
||||||
|
|
||||||
// Move all views from the destroyed output to the fallback one
|
// 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;
|
const view = &node.view;
|
||||||
view.sendToOutput(fallback_output);
|
view.sendToOutput(fallback_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close all layer surfaces on the destroyed 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| {
|
while (layer.pop()) |node| {
|
||||||
const layer_surface = &node.data;
|
const layer_surface = &node.data;
|
||||||
c.wlr_layer_surface_v1_close(layer_surface.wlr_layer_surface);
|
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;
|
var seat_it = root.server.input_manager.seats.first;
|
||||||
while (seat_it) |seat_node| : (seat_it = seat_node.next) {
|
while (seat_it) |seat_node| : (seat_it = seat_node.next) {
|
||||||
const seat = &seat_node.data;
|
const seat = &seat_node.data;
|
||||||
if (seat.focused_output == destroyed_output) {
|
if (seat.focused_output == self) {
|
||||||
seat.focused_output = fallback_output;
|
seat.focused_output = fallback_output;
|
||||||
seat.focus(null);
|
seat.focus(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all listeners
|
// Remove all listeners
|
||||||
c.wl_list_remove(&destroyed_output.listen_destroy.link);
|
c.wl_list_remove(&self.listen_destroy.link);
|
||||||
c.wl_list_remove(&destroyed_output.listen_frame.link);
|
c.wl_list_remove(&self.listen_frame.link);
|
||||||
c.wl_list_remove(&destroyed_output.listen_mode.link);
|
c.wl_list_remove(&self.listen_mode.link);
|
||||||
|
|
||||||
// Clean up the wlr_output
|
// Clean up the wlr_output
|
||||||
destroyed_output.wlr_output.data = null;
|
self.wlr_output.data = null;
|
||||||
|
|
||||||
// Remove the destroyed output from the list
|
// 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.outputs.remove(node);
|
||||||
root.server.allocator.destroy(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 {
|
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,
|
// This function is called every time an output is ready to display a frame,
|
||||||
// generally at the output's refresh rate (e.g. 60Hz).
|
// generally at the output's refresh rate (e.g. 60Hz).
|
||||||
const output = @fieldParentPtr(Output, "listen_frame", listener.?);
|
const self = @fieldParentPtr(Self, "listen_frame", listener.?);
|
||||||
render.renderOutput(output);
|
render.renderOutput(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const output = @fieldParentPtr(Output, "listen_mode", listener.?);
|
const self = @fieldParentPtr(Self, "listen_mode", listener.?);
|
||||||
output.arrangeLayers();
|
self.arrangeLayers();
|
||||||
output.root.arrange();
|
self.root.arrange();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -154,7 +154,7 @@ pub const Root = struct {
|
|||||||
// TODO: log failure to create timer and commit immediately
|
// TODO: log failure to create timer and commit immediately
|
||||||
self.transaction_timer = c.wl_event_loop_add_timer(
|
self.transaction_timer = c.wl_event_loop_add_timer(
|
||||||
self.server.wl_event_loop,
|
self.server.wl_event_loop,
|
||||||
handle_timeout,
|
handleTimeout,
|
||||||
self,
|
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));
|
const root = @ptrCast(*Root, @alignCast(@alignOf(*Root), data));
|
||||||
|
|
||||||
Log.Error.log("Transaction timed out. Some imperfect frames may be shown.", .{});
|
Log.Error.log("Transaction timed out. Some imperfect frames may be shown.", .{});
|
||||||
|
@ -131,16 +131,16 @@ pub const Server = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handleNewOutput(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
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));
|
const wlr_output = @ptrCast(*c.wlr_output, @alignCast(@alignOf(*c.wlr_output), data));
|
||||||
Log.Debug.log("New output {}", .{wlr_output.name});
|
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 {
|
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
|
// This event is raised when wlr_xdg_shell receives a new xdg surface from a
|
||||||
// client, either a toplevel (application window) or popup.
|
// 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));
|
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) {
|
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;
|
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.
|
/// 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 {
|
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(
|
const wlr_layer_surface = @ptrCast(
|
||||||
*c.wlr_layer_surface_v1,
|
*c.wlr_layer_surface_v1,
|
||||||
@alignCast(@alignOf(*c.wlr_layer_surface_v1), data),
|
@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
|
// 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.
|
// first output or close the surface if none are available.
|
||||||
if (wlr_layer_surface.output == null) {
|
if (wlr_layer_surface.output == null) {
|
||||||
if (server.root.outputs.first) |node| {
|
if (self.root.outputs.first) |node| {
|
||||||
const output = &node.data;
|
const output = &node.data;
|
||||||
Log.Debug.log(
|
Log.Debug.log(
|
||||||
"New layer surface had null output, assigning it to output {}",
|
"New layer surface had null output, assigning it to output {}",
|
||||||
|
48
src/view.zig
48
src/view.zig
@ -137,68 +137,68 @@ pub const View = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const view = @fieldParentPtr(View, "listen_destroy", listener.?);
|
const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
|
||||||
const output = view.output;
|
const output = self.output;
|
||||||
|
|
||||||
// Remove listeners that are active for the entire lifetime of the view
|
// Remove listeners that are active for the entire lifetime of the view
|
||||||
c.wl_list_remove(&view.listen_destroy.link);
|
c.wl_list_remove(&self.listen_destroy.link);
|
||||||
c.wl_list_remove(&view.listen_map.link);
|
c.wl_list_remove(&self.listen_map.link);
|
||||||
c.wl_list_remove(&view.listen_unmap.link);
|
c.wl_list_remove(&self.listen_unmap.link);
|
||||||
|
|
||||||
// Remove the view from the stack
|
// 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.views.remove(node);
|
||||||
output.root.server.allocator.destroy(node);
|
output.root.server.allocator.destroy(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called when the surface is mapped, or ready to display on-screen.
|
/// Called when the surface is mapped, or ready to display on-screen.
|
||||||
fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const view = @fieldParentPtr(View, "listen_map", listener.?);
|
const self = @fieldParentPtr(Self, "listen_map", listener.?);
|
||||||
const root = view.output.root;
|
const root = self.output.root;
|
||||||
|
|
||||||
// Add listeners that are only active while mapped
|
// Add listeners that are only active while mapped
|
||||||
view.listen_commit.notify = handleCommit;
|
self.listen_commit.notify = handleCommit;
|
||||||
c.wl_signal_add(&view.wlr_xdg_surface.surface.*.events.commit, &view.listen_commit);
|
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
|
// Focus the newly mapped view. Note: if a seat is focusing a different output
|
||||||
// it will continue to do so.
|
// it will continue to do so.
|
||||||
var it = root.server.input_manager.seats.first;
|
var it = root.server.input_manager.seats.first;
|
||||||
while (it) |seat_node| : (it = seat_node.next) {
|
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.
|
/// Called when the surface is unmapped and will no longer be displayed.
|
||||||
fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const view = @fieldParentPtr(View, "listen_unmap", listener.?);
|
const self = @fieldParentPtr(Self, "listen_unmap", listener.?);
|
||||||
const root = view.output.root;
|
const root = self.output.root;
|
||||||
view.mapped = false;
|
self.mapped = false;
|
||||||
|
|
||||||
// Inform all seats that the view has been unmapped so they can handle focus
|
// Inform all seats that the view has been unmapped so they can handle focus
|
||||||
var it = root.server.input_manager.seats.first;
|
var it = root.server.input_manager.seats.first;
|
||||||
while (it) |node| : (it = node.next) {
|
while (it) |node| : (it = node.next) {
|
||||||
const seat = &node.data;
|
const seat = &node.data;
|
||||||
seat.handleViewUnmap(view);
|
seat.handleViewUnmap(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
root.arrange();
|
root.arrange();
|
||||||
|
|
||||||
// Remove listeners that are only active while mapped
|
// 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 {
|
fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const view = @fieldParentPtr(View, "listen_commit", listener.?);
|
const self = @fieldParentPtr(Self, "listen_commit", listener.?);
|
||||||
if (view.pending_serial) |s| {
|
if (self.pending_serial) |s| {
|
||||||
if (s == view.wlr_xdg_surface.configure_serial) {
|
if (s == self.wlr_xdg_surface.configure_serial) {
|
||||||
view.output.root.notifyConfigured();
|
self.output.root.notifyConfigured();
|
||||||
view.pending_serial = null;
|
self.pending_serial = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: check for unexpected change in size and react as needed
|
// TODO: check for unexpected change in size and react as needed
|
||||||
|
Loading…
Reference in New Issue
Block a user