code: create voidCast() util function
This commit is contained in:
parent
ce18f24129
commit
fb8d855ec9
18 changed files with 80 additions and 79 deletions
|
@ -21,6 +21,7 @@ const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
const command = @import("command.zig");
|
const command = @import("command.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Seat = @import("Seat.zig");
|
const Seat = @import("Seat.zig");
|
||||||
|
@ -65,7 +66,7 @@ fn handleDisplayDestroy(wl_listener: ?*c.wl_listener, data: ?*c_void) callconv(.
|
||||||
|
|
||||||
/// Called when a client binds our global
|
/// Called when a client binds our global
|
||||||
fn bind(wl_client: ?*c.wl_client, data: ?*c_void, version: u32, id: u32) callconv(.C) void {
|
fn bind(wl_client: ?*c.wl_client, data: ?*c_void, version: u32, id: u32) callconv(.C) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), data));
|
const self = util.voidCast(Self, data.?);
|
||||||
const wl_resource = c.wl_resource_create(
|
const wl_resource = c.wl_resource_create(
|
||||||
wl_client,
|
wl_client,
|
||||||
&c.zriver_control_v1_interface,
|
&c.zriver_control_v1_interface,
|
||||||
|
@ -85,7 +86,7 @@ fn bind(wl_client: ?*c.wl_client, data: ?*c_void, version: u32, id: u32) callcon
|
||||||
|
|
||||||
/// Remove the resource from the hash map and free all stored args
|
/// Remove the resource from the hash map and free all stored args
|
||||||
fn handleResourceDestroy(wl_resource: ?*c.wl_resource) callconv(.C) void {
|
fn handleResourceDestroy(wl_resource: ?*c.wl_resource) callconv(.C) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), c.wl_resource_get_user_data(wl_resource)));
|
const self = util.voidCast(Self, c.wl_resource_get_user_data(wl_resource).?);
|
||||||
const id = c.wl_resource_get_id(wl_resource);
|
const id = c.wl_resource_get_id(wl_resource);
|
||||||
const list = self.args_map.remove(id).?.value;
|
const list = self.args_map.remove(id).?.value;
|
||||||
for (list.items) |arg| list.allocator.free(arg);
|
for (list.items) |arg| list.allocator.free(arg);
|
||||||
|
@ -97,7 +98,7 @@ fn destroy(wl_client: ?*c.wl_client, wl_resource: ?*c.wl_resource) callconv(.C)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn addArgument(wl_client: ?*c.wl_client, wl_resource: ?*c.wl_resource, arg: ?[*:0]const u8) callconv(.C) void {
|
fn addArgument(wl_client: ?*c.wl_client, wl_resource: ?*c.wl_resource, arg: ?[*:0]const u8) callconv(.C) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), c.wl_resource_get_user_data(wl_resource)));
|
const self = util.voidCast(Self, c.wl_resource_get_user_data(wl_resource).?);
|
||||||
const id = c.wl_resource_get_id(wl_resource);
|
const id = c.wl_resource_get_id(wl_resource);
|
||||||
const allocator = self.server.allocator;
|
const allocator = self.server.allocator;
|
||||||
|
|
||||||
|
@ -119,10 +120,10 @@ fn runCommand(
|
||||||
seat_wl_resource: ?*c.wl_resource,
|
seat_wl_resource: ?*c.wl_resource,
|
||||||
callback_id: u32,
|
callback_id: u32,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), c.wl_resource_get_user_data(wl_resource)));
|
const self = util.voidCast(Self, c.wl_resource_get_user_data(wl_resource).?);
|
||||||
// This can be null if the seat is inert, in which case we ignore the request
|
// This can be null if the seat is inert, in which case we ignore the request
|
||||||
const wlr_seat_client = c.wlr_seat_client_from_resource(seat_wl_resource) orelse return;
|
const wlr_seat_client = c.wlr_seat_client_from_resource(seat_wl_resource) orelse return;
|
||||||
const seat = @ptrCast(*Seat, @alignCast(@alignOf(*Seat), wlr_seat_client.*.seat.*.data));
|
const seat = util.voidCast(Seat, wlr_seat_client.*.seat.*.data.?);
|
||||||
const allocator = self.server.allocator;
|
const allocator = self.server.allocator;
|
||||||
|
|
||||||
const callback_resource = c.wl_resource_create(
|
const callback_resource = c.wl_resource_create(
|
||||||
|
|
|
@ -21,6 +21,7 @@ const build_options = @import("build_options");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const LayerSurface = @import("LayerSurface.zig");
|
const LayerSurface = @import("LayerSurface.zig");
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
|
@ -133,10 +134,7 @@ 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(Self, "listen_axis", listener.?);
|
const cursor = @fieldParentPtr(Self, "listen_axis", listener.?);
|
||||||
const event = @ptrCast(
|
const event = util.voidCast(c.wlr_event_pointer_axis, data.?);
|
||||||
*c.wlr_event_pointer_axis,
|
|
||||||
@alignCast(@alignOf(*c.wlr_event_pointer_axis), data),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Notify the client with pointer focus of the axis event.
|
// Notify the client with pointer focus of the axis event.
|
||||||
c.wlr_seat_pointer_notify_axis(
|
c.wlr_seat_pointer_notify_axis(
|
||||||
|
@ -153,10 +151,7 @@ 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 self = @fieldParentPtr(Self, "listen_button", listener.?);
|
const self = @fieldParentPtr(Self, "listen_button", listener.?);
|
||||||
const event = @ptrCast(
|
const event = util.voidCast(c.wlr_event_pointer_button, data.?);
|
||||||
*c.wlr_event_pointer_button,
|
|
||||||
@alignCast(@alignOf(*c.wlr_event_pointer_button), data),
|
|
||||||
);
|
|
||||||
var sx: f64 = undefined;
|
var sx: f64 = undefined;
|
||||||
var sy: f64 = undefined;
|
var sy: f64 = undefined;
|
||||||
|
|
||||||
|
@ -166,10 +161,7 @@ fn handleButton(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
if (c.wlr_surface_is_layer_surface(wlr_surface)) {
|
if (c.wlr_surface_is_layer_surface(wlr_surface)) {
|
||||||
const wlr_layer_surface = c.wlr_layer_surface_v1_from_wlr_surface(wlr_surface);
|
const wlr_layer_surface = c.wlr_layer_surface_v1_from_wlr_surface(wlr_surface);
|
||||||
if (wlr_layer_surface.*.current.keyboard_interactive) {
|
if (wlr_layer_surface.*.current.keyboard_interactive) {
|
||||||
const layer_surface = @ptrCast(
|
const layer_surface = util.voidCast(LayerSurface, wlr_layer_surface.*.data.?);
|
||||||
*LayerSurface,
|
|
||||||
@alignCast(@alignOf(*LayerSurface), wlr_layer_surface.*.data),
|
|
||||||
);
|
|
||||||
self.seat.setFocusRaw(.{ .layer = layer_surface });
|
self.seat.setFocusRaw(.{ .layer = layer_surface });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,7 +171,7 @@ fn handleButton(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
if (c.wlr_surface_is_xdg_surface(wlr_surface)) {
|
if (c.wlr_surface_is_xdg_surface(wlr_surface)) {
|
||||||
const wlr_xdg_surface = c.wlr_xdg_surface_from_wlr_surface(wlr_surface);
|
const wlr_xdg_surface = c.wlr_xdg_surface_from_wlr_surface(wlr_surface);
|
||||||
if (wlr_xdg_surface.*.role == .WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
if (wlr_xdg_surface.*.role == .WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
|
||||||
const view = @ptrCast(*View, @alignCast(@alignOf(*View), wlr_xdg_surface.*.data));
|
const view = util.voidCast(View, wlr_xdg_surface.*.data.?);
|
||||||
self.seat.focus(view);
|
self.seat.focus(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,10 +203,7 @@ fn handleMotionAbsolute(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C)
|
||||||
// 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 self = @fieldParentPtr(Self, "listen_motion_absolute", listener.?);
|
const self = @fieldParentPtr(Self, "listen_motion_absolute", listener.?);
|
||||||
const event = @ptrCast(
|
const event = util.voidCast(c.wlr_event_pointer_motion_absolute, data.?);
|
||||||
*c.wlr_event_pointer_motion_absolute,
|
|
||||||
@alignCast(@alignOf(*c.wlr_event_pointer_motion_absolute), data),
|
|
||||||
);
|
|
||||||
c.wlr_cursor_warp_absolute(self.wlr_cursor, event.device, event.x, event.y);
|
c.wlr_cursor_warp_absolute(self.wlr_cursor, event.device, event.x, event.y);
|
||||||
self.processMotion(event.time_msec);
|
self.processMotion(event.time_msec);
|
||||||
}
|
}
|
||||||
|
@ -223,10 +212,7 @@ 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 self = @fieldParentPtr(Self, "listen_motion", listener.?);
|
const self = @fieldParentPtr(Self, "listen_motion", listener.?);
|
||||||
const event = @ptrCast(
|
const event = util.voidCast(c.wlr_event_pointer_motion, data.?);
|
||||||
*c.wlr_event_pointer_motion,
|
|
||||||
@alignCast(@alignOf(*c.wlr_event_pointer_motion), data),
|
|
||||||
);
|
|
||||||
// The cursor doesn't move unless we tell it to. The cursor automatically
|
// The cursor doesn't move unless we tell it to. The cursor automatically
|
||||||
// handles constraining the motion to the output layout, as well as any
|
// handles constraining the motion to the output layout, as well as any
|
||||||
// special configuration applied for the specific input device which
|
// special configuration applied for the specific input device which
|
||||||
|
@ -239,10 +225,7 @@ fn handleMotion(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
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 self = @fieldParentPtr(Self, "listen_request_set_cursor", listener.?);
|
const self = @fieldParentPtr(Self, "listen_request_set_cursor", listener.?);
|
||||||
const event = @ptrCast(
|
const event = util.voidCast(c.wlr_seat_pointer_request_set_cursor_event, data.?);
|
||||||
*c.wlr_seat_pointer_request_set_cursor_event,
|
|
||||||
@alignCast(@alignOf(*c.wlr_seat_pointer_request_set_cursor_event), data),
|
|
||||||
);
|
|
||||||
const focused_client = self.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
|
||||||
|
@ -307,10 +290,7 @@ fn surfaceAt(self: Self, lx: f64, ly: f64, sx: *f64, sy: *f64) ?*c.wlr_surface {
|
||||||
const root = self.seat.input_manager.server.root;
|
const root = self.seat.input_manager.server.root;
|
||||||
const wlr_output = c.wlr_output_layout_output_at(root.wlr_output_layout, lx, ly) orelse
|
const wlr_output = c.wlr_output_layout_output_at(root.wlr_output_layout, lx, ly) orelse
|
||||||
return null;
|
return null;
|
||||||
const output = @ptrCast(
|
const output = util.voidCast(Output, wlr_output.*.data orelse return null);
|
||||||
*Output,
|
|
||||||
@alignCast(@alignOf(*Output), wlr_output.*.data orelse return null),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get output-local coords from the layout coords
|
// Get output-local coords from the layout coords
|
||||||
var ox = lx;
|
var ox = lx;
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Decoration = @import("Decoration.zig");
|
const Decoration = @import("Decoration.zig");
|
||||||
const Server = @import("Server.zig");
|
const Server = @import("Server.zig");
|
||||||
|
@ -46,10 +47,7 @@ pub fn init(self: *Self, server: *Server) !void {
|
||||||
|
|
||||||
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 self = @fieldParentPtr(Self, "listen_new_toplevel_decoration", listener.?);
|
const self = @fieldParentPtr(Self, "listen_new_toplevel_decoration", listener.?);
|
||||||
const wlr_xdg_toplevel_decoration = @ptrCast(
|
const wlr_xdg_toplevel_decoration = util.voidCast(c.wlr_xdg_toplevel_decoration_v1, data.?);
|
||||||
*c.wlr_xdg_toplevel_decoration_v1,
|
|
||||||
@alignCast(@alignOf(*c.wlr_xdg_toplevel_decoration_v1), data),
|
|
||||||
);
|
|
||||||
|
|
||||||
const node = self.decorations.allocateNode(self.server.allocator) catch unreachable;
|
const node = self.decorations.allocateNode(self.server.allocator) catch unreachable;
|
||||||
node.data.init(self, wlr_xdg_toplevel_decoration);
|
node.data.init(self, wlr_xdg_toplevel_decoration);
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Seat = @import("Seat.zig");
|
const Seat = @import("Seat.zig");
|
||||||
|
@ -137,7 +138,7 @@ fn handleInhibitDeactivate(listener: ?*c.wl_listener, data: ?*c_void) callconv(.
|
||||||
/// 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 self = @fieldParentPtr(Self, "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 = util.voidCast(c.wlr_input_device, data.?);
|
||||||
|
|
||||||
// TODO: suport multiple seats
|
// TODO: suport multiple seats
|
||||||
if (self.seats.first) |seat_node| {
|
if (self.seats.first) |seat_node| {
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Seat = @import("Seat.zig");
|
const Seat = @import("Seat.zig");
|
||||||
|
@ -72,10 +73,7 @@ pub fn init(self: *Self, seat: *Seat, wlr_input_device: *c.wlr_input_device) !vo
|
||||||
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 self = @fieldParentPtr(Self, "listen_key", listener.?);
|
const self = @fieldParentPtr(Self, "listen_key", listener.?);
|
||||||
const event = @ptrCast(
|
const event = util.voidCast(c.wlr_event_keyboard_key, data.?);
|
||||||
*c.wlr_event_keyboard_key,
|
|
||||||
@alignCast(@alignOf(*c.wlr_event_keyboard_key), data),
|
|
||||||
);
|
|
||||||
|
|
||||||
const wlr_keyboard = self.wlr_keyboard;
|
const wlr_keyboard = self.wlr_keyboard;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Box = @import("Box.zig");
|
const Box = @import("Box.zig");
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
|
@ -187,7 +188,7 @@ fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
|
|
||||||
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 self = @fieldParentPtr(Self, "listen_new_popup", listener.?);
|
const self = @fieldParentPtr(Self, "listen_new_popup", listener.?);
|
||||||
const wlr_xdg_popup = @ptrCast(*c.wlr_xdg_popup, @alignCast(@alignOf(*c.wlr_xdg_popup), data));
|
const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
|
||||||
const allocator = self.output.root.server.allocator;
|
const allocator = self.output.root.server.allocator;
|
||||||
|
|
||||||
// This will free itself on destroy
|
// This will free itself on destroy
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Output = @import("Output.zig");
|
const Output = @import("Output.zig");
|
||||||
|
@ -45,7 +46,7 @@ pub fn init(self: *Self, output: *Output, wl_resource: *c.wl_resource) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleResourceDestroy(wl_resource: ?*c.wl_resource) callconv(.C) void {
|
fn handleResourceDestroy(wl_resource: ?*c.wl_resource) callconv(.C) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), c.wl_resource_get_user_data(wl_resource)));
|
const self = util.voidCast(Self, @ptrCast(*c_void, c.wl_resource_get_user_data(wl_resource)));
|
||||||
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
|
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
|
||||||
self.output.status_trackers.remove(node);
|
self.output.status_trackers.remove(node);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +66,7 @@ pub fn sendViewTags(self: Self) void {
|
||||||
Log.Error.log("out of memory", .{});
|
Log.Error.log("out of memory", .{});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
const ptr_u32 = @ptrCast(*u32, @alignCast(@alignOf(u32), ptr));
|
const ptr_u32 = util.voidCast(u32, ptr);
|
||||||
ptr_u32.* = node.view.current_tags;
|
ptr_u32.* = node.view.current_tags;
|
||||||
}
|
}
|
||||||
c.zriver_output_status_v1_send_view_tags(self.wl_resource, &view_tags);
|
c.zriver_output_status_v1_send_view_tags(self.wl_resource, &view_tags);
|
||||||
|
|
|
@ -21,6 +21,7 @@ const std = @import("std");
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Output = @import("Output.zig");
|
const Output = @import("Output.zig");
|
||||||
|
@ -175,7 +176,7 @@ fn startTransaction(self: *Self) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleTimeout(data: ?*c_void) callconv(.C) c_int {
|
fn handleTimeout(data: ?*c_void) callconv(.C) c_int {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), data));
|
const self = util.voidCast(Self, 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.", .{});
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
const command = @import("command.zig");
|
const command = @import("command.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Cursor = @import("Cursor.zig");
|
const Cursor = @import("Cursor.zig");
|
||||||
const InputManager = @import("InputManager.zig");
|
const InputManager = @import("InputManager.zig");
|
||||||
|
@ -328,9 +329,6 @@ fn addPointer(self: Self, device: *c.struct_wlr_input_device) void {
|
||||||
|
|
||||||
fn handleRequestSetSelection(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleRequestSetSelection(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const self = @fieldParentPtr(Self, "listen_request_set_selection", listener.?);
|
const self = @fieldParentPtr(Self, "listen_request_set_selection", listener.?);
|
||||||
const event = @ptrCast(
|
const event = util.voidCast(c.wlr_seat_request_set_selection_event, data.?);
|
||||||
*c.wlr_seat_request_set_selection_event,
|
|
||||||
@alignCast(@alignOf(*c.wlr_seat_request_set_selection_event), data),
|
|
||||||
);
|
|
||||||
c.wlr_seat_set_selection(self.wlr_seat, event.source, event.serial);
|
c.wlr_seat_set_selection(self.wlr_seat, event.source, event.serial);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Seat = @import("Seat.zig");
|
const Seat = @import("Seat.zig");
|
||||||
|
@ -50,7 +51,7 @@ pub fn init(self: *Self, seat: *Seat, wl_resource: *c.wl_resource) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleResourceDestroy(wl_resource: ?*c.wl_resource) callconv(.C) void {
|
fn handleResourceDestroy(wl_resource: ?*c.wl_resource) callconv(.C) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), c.wl_resource_get_user_data(wl_resource)));
|
const self = util.voidCast(Self, c.wl_resource_get_user_data(wl_resource).?);
|
||||||
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
|
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
|
||||||
self.seat.status_trackers.remove(node);
|
self.seat.status_trackers.remove(node);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ const build_options = @import("build_options");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Config = @import("Config.zig");
|
const Config = @import("Config.zig");
|
||||||
const Control = @import("Control.zig");
|
const Control = @import("Control.zig");
|
||||||
|
@ -183,7 +184,7 @@ pub fn run(self: Self) void {
|
||||||
|
|
||||||
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 self = @fieldParentPtr(Self, "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 = util.voidCast(c.wlr_output, data.?);
|
||||||
Log.Debug.log("New output {}", .{wlr_output.name});
|
Log.Debug.log("New output {}", .{wlr_output.name});
|
||||||
self.root.addOutput(wlr_output);
|
self.root.addOutput(wlr_output);
|
||||||
}
|
}
|
||||||
|
@ -192,7 +193,7 @@ fn handleNewXdgSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) v
|
||||||
// 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 self = @fieldParentPtr(Self, "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 = util.voidCast(c.wlr_xdg_surface, data.?);
|
||||||
|
|
||||||
if (wlr_xdg_surface.role == .WLR_XDG_SURFACE_ROLE_POPUP) {
|
if (wlr_xdg_surface.role == .WLR_XDG_SURFACE_ROLE_POPUP) {
|
||||||
Log.Debug.log("New xdg_popup", .{});
|
Log.Debug.log("New xdg_popup", .{});
|
||||||
|
@ -210,10 +211,7 @@ fn handleNewXdgSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) v
|
||||||
/// 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 self = @fieldParentPtr(Self, "listen_new_layer_surface", listener.?);
|
const self = @fieldParentPtr(Self, "listen_new_layer_surface", listener.?);
|
||||||
const wlr_layer_surface = @ptrCast(
|
const wlr_layer_surface = util.voidCast(c.wlr_layer_surface_v1, data.?);
|
||||||
*c.wlr_layer_surface_v1,
|
|
||||||
@alignCast(@alignOf(*c.wlr_layer_surface_v1), data),
|
|
||||||
);
|
|
||||||
|
|
||||||
Log.Debug.log(
|
Log.Debug.log(
|
||||||
"New layer surface: namespace {}, layer {}, anchor {}, size {}x{}, margin ({},{},{},{}), exclusive_zone {}",
|
"New layer surface: namespace {}, layer {}, anchor {}, size {}x{}, margin ({},{},{},{}), exclusive_zone {}",
|
||||||
|
@ -252,17 +250,14 @@ fn handleNewLayerSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The layer surface will add itself to the proper list of the output on map
|
// The layer surface will add itself to the proper list of the output on map
|
||||||
const output = @ptrCast(*Output, @alignCast(@alignOf(*Output), wlr_layer_surface.output.*.data));
|
const output = util.voidCast(Output, wlr_layer_surface.output.*.data.?);
|
||||||
const node = self.allocator.create(std.TailQueue(LayerSurface).Node) catch unreachable;
|
const node = self.allocator.create(std.TailQueue(LayerSurface).Node) catch unreachable;
|
||||||
node.data.init(output, wlr_layer_surface);
|
node.data.init(output, wlr_layer_surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleNewXwaylandSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleNewXwaylandSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const self = @fieldParentPtr(Self, "listen_new_xwayland_surface", listener.?);
|
const self = @fieldParentPtr(Self, "listen_new_xwayland_surface", listener.?);
|
||||||
const wlr_xwayland_surface = @ptrCast(
|
const wlr_xwayland_surface = util.voidCast(c.wlr_xwayland_surface, data.?);
|
||||||
*c.wlr_xwayland_surface,
|
|
||||||
@alignCast(@alignOf(*c.wlr_xwayland_surface), data),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (wlr_xwayland_surface.override_redirect) {
|
if (wlr_xwayland_surface.override_redirect) {
|
||||||
Log.Debug.log("New unmanaged xwayland surface", .{});
|
Log.Debug.log("New unmanaged xwayland surface", .{});
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
const Output = @import("Output.zig");
|
const Output = @import("Output.zig");
|
||||||
|
@ -63,7 +64,7 @@ fn handleDisplayDestroy(wl_listener: ?*c.wl_listener, data: ?*c_void) callconv(.
|
||||||
|
|
||||||
/// Called when a client binds our global
|
/// Called when a client binds our global
|
||||||
fn bind(wl_client: ?*c.wl_client, data: ?*c_void, version: u32, id: u32) callconv(.C) void {
|
fn bind(wl_client: ?*c.wl_client, data: ?*c_void, version: u32, id: u32) callconv(.C) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), data));
|
const self = util.voidCast(Self, data.?);
|
||||||
const wl_resource = c.wl_resource_create(
|
const wl_resource = c.wl_resource_create(
|
||||||
wl_client,
|
wl_client,
|
||||||
&c.zriver_status_manager_v1_interface,
|
&c.zriver_status_manager_v1_interface,
|
||||||
|
@ -87,10 +88,10 @@ fn getRiverOutputStatus(
|
||||||
new_id: u32,
|
new_id: u32,
|
||||||
output_wl_resource: ?*c.wl_resource,
|
output_wl_resource: ?*c.wl_resource,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), c.wl_resource_get_user_data(wl_resource)));
|
const self = util.voidCast(Self, c.wl_resource_get_user_data(wl_resource).?);
|
||||||
// This can be null if the output is inert, in which case we ignore the request
|
// This can be null if the output is inert, in which case we ignore the request
|
||||||
const wlr_output = c.wlr_output_from_resource(output_wl_resource) orelse return;
|
const wlr_output = c.wlr_output_from_resource(output_wl_resource) orelse return;
|
||||||
const output = @ptrCast(*Output, @alignCast(@alignOf(*Output), wlr_output.*.data));
|
const output = util.voidCast(Output, wlr_output.*.data.?);
|
||||||
const allocator = self.server.allocator;
|
const allocator = self.server.allocator;
|
||||||
|
|
||||||
const node = allocator.create(std.SinglyLinkedList(OutputStatus).Node) catch {
|
const node = allocator.create(std.SinglyLinkedList(OutputStatus).Node) catch {
|
||||||
|
@ -120,10 +121,10 @@ fn getRiverSeatStatus(
|
||||||
new_id: u32,
|
new_id: u32,
|
||||||
seat_wl_resource: ?*c.wl_resource,
|
seat_wl_resource: ?*c.wl_resource,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const self = @ptrCast(*Self, @alignCast(@alignOf(*Self), c.wl_resource_get_user_data(wl_resource)));
|
const self = util.voidCast(Self, c.wl_resource_get_user_data(wl_resource).?);
|
||||||
// This can be null if the seat is inert, in which case we ignore the request
|
// This can be null if the seat is inert, in which case we ignore the request
|
||||||
const wlr_seat_client = c.wlr_seat_client_from_resource(seat_wl_resource) orelse return;
|
const wlr_seat_client = c.wlr_seat_client_from_resource(seat_wl_resource) orelse return;
|
||||||
const seat = @ptrCast(*Seat, @alignCast(@alignOf(*Seat), wlr_seat_client.*.seat.*.data));
|
const seat = util.voidCast(Seat, wlr_seat_client.*.seat.*.data.?);
|
||||||
const allocator = self.server.allocator;
|
const allocator = self.server.allocator;
|
||||||
|
|
||||||
const node = allocator.create(std.SinglyLinkedList(SeatStatus).Node) catch {
|
const node = allocator.create(std.SinglyLinkedList(SeatStatus).Node) catch {
|
||||||
|
|
|
@ -21,6 +21,7 @@ const build_options = @import("build_options");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Box = @import("Box.zig");
|
const Box = @import("Box.zig");
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
|
@ -173,10 +174,7 @@ fn saveBuffersIterator(
|
||||||
surface_y: c_int,
|
surface_y: c_int,
|
||||||
data: ?*c_void,
|
data: ?*c_void,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const saved_buffers = @ptrCast(
|
const saved_buffers = util.voidCast(std.ArrayList(SavedBuffer), data.?);
|
||||||
*std.ArrayList(SavedBuffer),
|
|
||||||
@alignCast(@alignOf(*std.ArrayList(SavedBuffer)), data),
|
|
||||||
);
|
|
||||||
if (wlr_surface) |surface| {
|
if (wlr_surface) |surface| {
|
||||||
if (c.wlr_surface_has_buffer(surface)) {
|
if (c.wlr_surface_has_buffer(surface)) {
|
||||||
saved_buffers.append(.{
|
saved_buffers.append(.{
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Box = @import("Box.zig");
|
const Box = @import("Box.zig");
|
||||||
const Output = @import("Output.zig");
|
const Output = @import("Output.zig");
|
||||||
|
@ -73,7 +74,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
/// Called when a new xdg popup is requested by the client
|
/// Called when a new xdg popup is requested by the client
|
||||||
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 self = @fieldParentPtr(Self, "listen_new_popup", listener.?);
|
const self = @fieldParentPtr(Self, "listen_new_popup", listener.?);
|
||||||
const wlr_xdg_popup = @ptrCast(*c.wlr_xdg_popup, @alignCast(@alignOf(*c.wlr_xdg_popup), data));
|
const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
|
||||||
const allocator = self.output.root.server.allocator;
|
const allocator = self.output.root.server.allocator;
|
||||||
|
|
||||||
// This will free itself on destroy
|
// This will free itself on destroy
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Box = @import("Box.zig");
|
const Box = @import("Box.zig");
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
|
@ -242,7 +243,7 @@ fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
/// Called when a new xdg popup is requested by the client
|
/// Called when a new xdg popup is requested by the client
|
||||||
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 self = @fieldParentPtr(Self, "listen_new_popup", listener.?);
|
const self = @fieldParentPtr(Self, "listen_new_popup", listener.?);
|
||||||
const wlr_xdg_popup = @ptrCast(*c.wlr_xdg_popup, @alignCast(@alignOf(*c.wlr_xdg_popup), data));
|
const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
|
||||||
const allocator = self.view.output.root.server.allocator;
|
const allocator = self.view.output.root.server.allocator;
|
||||||
|
|
||||||
// This will free itself on destroy
|
// This will free itself on destroy
|
||||||
|
|
|
@ -20,6 +20,7 @@ const Self = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Box = @import("Box.zig");
|
const Box = @import("Box.zig");
|
||||||
const Log = @import("log.zig").Log;
|
const Log = @import("log.zig").Log;
|
||||||
|
@ -71,10 +72,7 @@ pub fn surfaceAt(self: Self, ox: f64, oy: f64, sx: *f64, sy: *f64) ?*c.wlr_surfa
|
||||||
|
|
||||||
fn handleRequestConfigure(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
fn handleRequestConfigure(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||||
const self = @fieldParentPtr(Self, "liseten_request_configure", listener.?);
|
const self = @fieldParentPtr(Self, "liseten_request_configure", listener.?);
|
||||||
const wlr_xwayland_surface_configure_event = @ptrCast(
|
const wlr_xwayland_surface_configure_event = util.voidCast(c.wlr_xwayland_surface_configure_event, data.?);
|
||||||
*c.wlr_xwayland_surface_configure_event,
|
|
||||||
@alignCast(@alignOf(*c.wlr_xwayland_surface_configure_event), data),
|
|
||||||
);
|
|
||||||
c.wlr_xwayland_surface_configure(
|
c.wlr_xwayland_surface_configure(
|
||||||
self.wlr_xwayland_surface,
|
self.wlr_xwayland_surface,
|
||||||
wlr_xwayland_surface_configure_event.x,
|
wlr_xwayland_surface_configure_event.x,
|
||||||
|
|
|
@ -19,6 +19,7 @@ const build_options = @import("build_options");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const util = @import("util.zig");
|
||||||
|
|
||||||
const Box = @import("Box.zig");
|
const Box = @import("Box.zig");
|
||||||
const LayerSurface = @import("LayerSurface.zig");
|
const LayerSurface = @import("LayerSurface.zig");
|
||||||
|
@ -193,7 +194,7 @@ fn renderSurfaceIterator(
|
||||||
surface_y: c_int,
|
surface_y: c_int,
|
||||||
data: ?*c_void,
|
data: ?*c_void,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const rdata = @ptrCast(*SurfaceRenderData, @alignCast(@alignOf(SurfaceRenderData), data));
|
const rdata = util.voidCast(SurfaceRenderData, data.?);
|
||||||
|
|
||||||
renderTexture(
|
renderTexture(
|
||||||
rdata.output.*,
|
rdata.output.*,
|
||||||
|
|
26
river/util.zig
Normal file
26
river/util.zig
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// This file is part of river, a dynamic tiling wayland compositor.
|
||||||
|
//
|
||||||
|
// Copyright 2020 Isaac Freund
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/// Take a pointer to c_void and cast it to a pointer to T. This function
|
||||||
|
/// exists to avoid having the verbosity of the required alignment casts all
|
||||||
|
/// over the code.
|
||||||
|
pub fn voidCast(comptime T: type, ptr: var) *T {
|
||||||
|
// See https://github.com/ziglang/zig/issues/5618
|
||||||
|
if (@TypeOf(ptr) != *c_void)
|
||||||
|
@compileError("voidCast takes *c_void but " ++ @typeName(@TypeOf(ptr)) ++ " was provided");
|
||||||
|
return @ptrCast(*T, @alignCast(@alignOf(*T), ptr));
|
||||||
|
}
|
Loading…
Reference in a new issue