Skip to content

Commit

Permalink
feat: outputs now lists surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Mar 8, 2024
1 parent 2d3b8d9 commit a03ba54
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
.hash = "1220813b3d22d110b409ec8619fc1da2bc2ba2e71eb37b6a921ad228b485135793be",
},
.xcb = .{
.url = "https://github.com/MidstallSoftware/xcb.zig/archive/f22397e0584cd3359b1aa8ff862a7baca6f122e3.tar.gz",
.hash = "122075e699b270a850f3c39b24cc729156393c0a16656fc261efce246adf1b8a8da1",
.url = "https://github.com/MidstallSoftware/xcb.zig/archive/c73249901914916d197161b1395b737eb7a980e4.tar.gz",
.hash = "12205df2465ca2777bb1bfa60167af0e0bfea4f6292ff27f26bd1a27826dd70d5bbe",
},
},
}
2 changes: 1 addition & 1 deletion src/example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn main() !void {

const output = blk: {
for (outputs.items) |value| {
if ((value.info() catch continue).enable) break :blk value;
if ((try value.info()).enable) break :blk value;
}
@panic("Could not find an output");
};
Expand Down
5 changes: 2 additions & 3 deletions src/phantom/display/backends/xcb/display.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn display(self: *Self) phantom.display.Base {
};
}

fn getXScreen(self: *Self) !*const xcb.xproto.SCREEN {
pub fn getXScreen(self: *Self) !*const xcb.xproto.SCREEN {
var iter = self.setup.rootsIterator();
var i: usize = 0;
while (iter.next()) |screen| : (i += 1) {
Expand All @@ -58,8 +58,7 @@ fn impl_outputs(ctx: *anyopaque) anyerror!std.ArrayList(*phantom.display.Output)

while (monitorsIter.next()) |monitor| {
for (monitor.outputs()) |output| {
std.debug.print("{}\n", .{output});
try outputs.append(&(try Output.new(self, monitor.name)).base);
try outputs.append(&(try Output.new(self, output)).base);
}
}
return outputs;
Expand Down
31 changes: 26 additions & 5 deletions src/phantom/display/backends/xcb/output.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const Self = @This();

base: phantom.display.Output,
display: *Display,
id: xcb.xproto.ATOM,
id: xcb.randr.OUTPUT,
scale: vizops.vector.Float32Vector2,

pub fn new(display: *Display, id: xcb.xproto.ATOM) !*Self {
pub fn new(display: *Display, id: xcb.randr.OUTPUT) !*Self {
const self = try display.allocator.create(Self);
errdefer display.allocator.destroy(self);

Expand All @@ -29,6 +30,7 @@ pub fn new(display: *Display, id: xcb.xproto.ATOM) !*Self {
},
.display = display,
.id = id,
.scale = vizops.vector.Float32Vector2.init([_]f32{ 1.0, 1.0 }),
};
return self;
}
Expand All @@ -38,12 +40,19 @@ fn impl_surfaces(ctx: *anyopaque) anyerror!std.ArrayList(*phantom.display.Surfac
var surfaces = std.ArrayList(*phantom.display.Surface).init(self.display.allocator);
errdefer surfaces.deinit();

// TODO: implement me
const xscreen = try self.display.getXScreen();
const tree = try xcb.xproto.queryTree(self.display.connection, xscreen.root).reply(self.display.connection);
for (tree.children()) |child| {
const surf = try Surface.new(self, child);
errdefer surf.base.deinit();
try surfaces.append(&surf.base);
}
return surfaces;
}

fn impl_create_surface(ctx: *anyopaque, kind: phantom.display.Surface.Kind, info: phantom.display.Surface.Info) anyerror!*phantom.display.Surface {
const self: *Self = @ptrCast(@alignCast(ctx));

_ = self;
_ = kind;
_ = info;
Expand All @@ -52,8 +61,20 @@ fn impl_create_surface(ctx: *anyopaque, kind: phantom.display.Surface.Kind, info

fn impl_info(ctx: *anyopaque) anyerror!phantom.display.Output.Info {
const self: *Self = @ptrCast(@alignCast(ctx));
_ = self;
return error.NotImplemented;

const outputInfo = try xcb.randr.getOutputInfo(self.display.connection, self.id, 0).reply(self.display.connection);
const crtcInfo = try xcb.randr.getCrtcInfo(self.display.connection, outputInfo.crtc, 0).reply(self.display.connection);

return .{
.enable = true,
.size = .{
.phys = .{ .value = .{ @floatFromInt(outputInfo.mm_width), @floatFromInt(outputInfo.mm_height) } },
.res = .{ .value = .{ crtcInfo.width, crtcInfo.height } },
},
.name = outputInfo.name(),
.colorFormat = .{ .rgba = @splat(8) },
.scale = self.scale,
};
}

fn impl_update_info(ctx: *anyopaque, info: phantom.display.Output.Info, fields: []std.meta.FieldEnum(phantom.display.Output.Info)) anyerror!void {
Expand Down
7 changes: 4 additions & 3 deletions src/phantom/display/backends/xcb/surface.zig
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const std = @import("std");
const phantom = @import("phantom");
const Output = @import("output.zig");
const xcb = @import("xcb");
const Self = @This();

base: phantom.display.Surface,
output: *Output,
scene: ?*phantom.scene.Base,
id: xcb.xproto.WINDOW,

pub fn new(output: *Output, info: phantom.display.Surface.Info) !*Self {
pub fn new(output: *Output, id: xcb.xproto.WINDOW) !*Self {
const self = try output.display.allocator.create(Self);
errdefer output.display.allocator.destroy(self);

_ = info;

self.* = .{
.base = .{
.ptr = self,
Expand All @@ -29,6 +29,7 @@ pub fn new(output: *Output, info: phantom.display.Surface.Info) !*Self {
},
.output = output,
.scene = null,
.id = id,
};
return self;
}
Expand Down

0 comments on commit a03ba54

Please sign in to comment.