can draw dimensions of selection
This commit is contained in:
parent
dd35c163d4
commit
dda61ec788
20
box.zig
20
box.zig
|
@ -161,6 +161,26 @@ pub const Box = struct {
|
||||||
return getInner(T, self.position.y);
|
return getInner(T, self.position.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// lowest X-axis value
|
||||||
|
pub fn getLeftMost(self: *const Self, comptime T: anytype) T {
|
||||||
|
return getInner(T, self.position.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// highest X-axis value
|
||||||
|
pub fn getRightMost(self: *const Self, comptime T: anytype) T {
|
||||||
|
return getInner(T, self.position.x + self.getWidth(isize));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// lowest Y-axis value
|
||||||
|
pub fn getTopMost(self: *const Self, comptime T: anytype) T {
|
||||||
|
return getInner(T, self.position.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// highest Y-axis value
|
||||||
|
pub fn getBottomMost(self: *const Self, comptime T: anytype) T {
|
||||||
|
return getInner(T, self.position.y + self.getHeight(isize));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn getWidth(self: *const Self, comptime T: anytype) T {
|
pub fn getWidth(self: *const Self, comptime T: anytype) T {
|
||||||
return getInner(T, self.extents.width);
|
return getInner(T, self.extents.width);
|
||||||
}
|
}
|
||||||
|
|
51
main.zig
51
main.zig
|
@ -246,8 +246,6 @@ const Output = struct {
|
||||||
frame_callback: ?*wl.Callback = null,
|
frame_callback: ?*wl.Callback = null,
|
||||||
|
|
||||||
fn init(self: *Self, state: *State.Init) !void {
|
fn init(self: *Self, state: *State.Init) !void {
|
||||||
std.debug.print("output.init()\n", .{});
|
|
||||||
|
|
||||||
self.state = state;
|
self.state = state;
|
||||||
try self.buffers.init(state);
|
try self.buffers.init(state);
|
||||||
|
|
||||||
|
@ -299,6 +297,30 @@ const Output = struct {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn drawDimensions(self: *Self, c: *Cairo.cairo_t, color: u32, box: *const Box) void {
|
||||||
|
const opts = self.state.getOptions();
|
||||||
|
const font_family = if (opts.@"font-family") |ff| ff.ptr else null;
|
||||||
|
Cairo.cairo_select_font_face(c,
|
||||||
|
font_family,
|
||||||
|
Cairo.CAIRO_FONT_SLANT_NORMAL,
|
||||||
|
Cairo.CAIRO_FONT_WEIGHT_NORMAL,
|
||||||
|
);
|
||||||
|
Cairo.cairo_set_font_size(c, 14);
|
||||||
|
setSourceU32(c, color);
|
||||||
|
var buffer = [_]u8{0} ** 12;
|
||||||
|
const printed = std.fmt.bufPrint(&buffer,
|
||||||
|
"{}x{}",
|
||||||
|
.{box.extents.width, box.extents.height}) catch null;
|
||||||
|
|
||||||
|
if (printed) |str| {
|
||||||
|
Cairo.cairo_move_to(c,
|
||||||
|
box.getRightMost(f64) + 10.0,
|
||||||
|
box.getBottomMost(f64) + 10.0,
|
||||||
|
);
|
||||||
|
Cairo.cairo_show_text(c, @ptrCast([*c]const u8, str.ptr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn render(self: *Self, buffer: *Buffer) void {
|
fn render(self: *Self, buffer: *Buffer) void {
|
||||||
const cairo = &buffer.cairo;
|
const cairo = &buffer.cairo;
|
||||||
const opts = self.state.getOptions();
|
const opts = self.state.getOptions();
|
||||||
|
@ -310,7 +332,6 @@ const Output = struct {
|
||||||
|
|
||||||
// draw in_boxes
|
// draw in_boxes
|
||||||
if (self.state.config.in_boxes) |boxes| {
|
if (self.state.config.in_boxes) |boxes| {
|
||||||
std.debug.print("in_boxes: {}\n", .{boxes});
|
|
||||||
var iter = boxes.iter();
|
var iter = boxes.iter();
|
||||||
while (iter.next()) |box| {
|
while (iter.next()) |box| {
|
||||||
if (box.intersects(&self.logical_geometry)) {
|
if (box.intersects(&self.logical_geometry)) {
|
||||||
|
@ -318,6 +339,10 @@ const Output = struct {
|
||||||
|
|
||||||
drawRect(buffer, corrected_box, opts.choice);
|
drawRect(buffer, corrected_box, opts.choice);
|
||||||
Cairo.cairo_fill(cairo.ctx);
|
Cairo.cairo_fill(cairo.ctx);
|
||||||
|
|
||||||
|
if (opts.@"display-dimensions") {
|
||||||
|
self.drawDimensions(cairo.ctx, opts.border, box);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -343,7 +368,9 @@ const Output = struct {
|
||||||
drawRect(buffer, corrected_box, opts.border);
|
drawRect(buffer, corrected_box, opts.border);
|
||||||
Cairo.cairo_stroke(cairo.ctx);
|
Cairo.cairo_stroke(cairo.ctx);
|
||||||
|
|
||||||
// TODO: draw dimensions
|
if (opts.@"display-dimensions") {
|
||||||
|
self.drawDimensions(cairo.ctx, opts.border, &box);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,8 +438,6 @@ const Output = struct {
|
||||||
if (self.needs_redraw) {
|
if (self.needs_redraw) {
|
||||||
self.commitFrame();
|
self.commitFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
std.debug.print("frame_callback done\n", .{});
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -566,7 +591,6 @@ const Seat = struct {
|
||||||
fn init(self: *Self, state: *State.Init) void {
|
fn init(self: *Self, state: *State.Init) void {
|
||||||
self.state = state;
|
self.state = state;
|
||||||
|
|
||||||
std.debug.print("seat.init()\n", .{});
|
|
||||||
self.seat.setListener(*Self, seatListener, self);
|
self.seat.setListener(*Self, seatListener, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -719,13 +743,6 @@ const Seat = struct {
|
||||||
if (self.keyboard.?.xkb) |xkb_| {
|
if (self.keyboard.?.xkb) |xkb_| {
|
||||||
const keysym = xkb.xkb_state_key_get_one_sym(xkb_.state, key.key + 8);
|
const keysym = xkb.xkb_state_key_get_one_sym(xkb_.state, key.key + 8);
|
||||||
|
|
||||||
// const buf_len = 32;
|
|
||||||
// const buf = self.state.ally.alloc(u8, buf_len) catch null;
|
|
||||||
// if (buf) |buffer| {
|
|
||||||
// _ = xkb.xkb_keysym_get_name(keysym, @ptrCast([*c]u8, buffer), buf_len);
|
|
||||||
// std.debug.print("key: {s} {s}\n", .{buffer, if (key.state == .pressed) "pressed" else "released"});
|
|
||||||
// }
|
|
||||||
|
|
||||||
switch (key.state) {
|
switch (key.state) {
|
||||||
.pressed => {
|
.pressed => {
|
||||||
switch (keysym) {
|
switch (keysym) {
|
||||||
|
@ -1083,7 +1100,6 @@ const State = struct {
|
||||||
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, self: *Self) void {
|
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, self: *Self) void {
|
||||||
_ = registry;
|
_ = registry;
|
||||||
_ = self;
|
_ = self;
|
||||||
std.debug.print("registryListener called after init", .{});
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
.global => {},
|
.global => {},
|
||||||
.global_remove => {},
|
.global_remove => {},
|
||||||
|
@ -1166,7 +1182,7 @@ const Args = struct {
|
||||||
selection: u32 = 0x00000000,
|
selection: u32 = 0x00000000,
|
||||||
choice: u32 = 0xFFFFFF40,
|
choice: u32 = 0xFFFFFF40,
|
||||||
format: ?[]const u8 = null,
|
format: ?[]const u8 = null,
|
||||||
@"font-family": ?[]const u8 = null,
|
@"font-family": ?[]const u8 = "sans-serif",
|
||||||
@"border-weight": u32 = 2,
|
@"border-weight": u32 = 2,
|
||||||
@"single-point": bool = false,
|
@"single-point": bool = false,
|
||||||
@"output-boxes": bool = false,
|
@"output-boxes": bool = false,
|
||||||
|
@ -1251,9 +1267,6 @@ const Input = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn run(ally: std.mem.Allocator) !void {
|
pub fn run(ally: std.mem.Allocator) !void {
|
||||||
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
|
|
||||||
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
|
||||||
|
|
||||||
const state = try State.Uninit.create(ally);
|
const state = try State.Uninit.create(ally);
|
||||||
const init = try state.intoInit();
|
const init = try state.intoInit();
|
||||||
defer init.deinit();
|
defer init.deinit();
|
||||||
|
|
Loading…
Reference in a new issue