introduce Output.getEffectiveResolution()
This commit is contained in:
parent
b2f13f5bcc
commit
d4ca5d7a88
@ -128,20 +128,17 @@ const Mode = union(enum) {
|
||||
.move => |view| {
|
||||
const border_width = if (view.draw_borders) config.border_width else 0;
|
||||
|
||||
var output_width: c_int = undefined;
|
||||
var output_height: c_int = undefined;
|
||||
c.wlr_output_effective_resolution(view.output.wlr_output, &output_width, &output_height);
|
||||
|
||||
// Set x/y of cursor and view, clamp to output dimensions
|
||||
const output_resolution = view.output.getEffectiveResolution();
|
||||
view.pending.box.x = std.math.clamp(
|
||||
view.pending.box.x + @floatToInt(i32, delta_x),
|
||||
@intCast(i32, border_width),
|
||||
output_width - @intCast(i32, view.pending.box.width + border_width),
|
||||
@intCast(i32, output_resolution.width - view.pending.box.width - border_width),
|
||||
);
|
||||
view.pending.box.y = std.math.clamp(
|
||||
view.pending.box.y + @floatToInt(i32, delta_y),
|
||||
@intCast(i32, border_width),
|
||||
output_height - @intCast(i32, view.pending.box.height + border_width),
|
||||
@intCast(i32, output_resolution.height - view.pending.box.height - border_width),
|
||||
);
|
||||
|
||||
c.wlr_cursor_move(
|
||||
@ -156,10 +153,6 @@ const Mode = union(enum) {
|
||||
.resize => |data| {
|
||||
const border_width = if (data.view.draw_borders) config.border_width else 0;
|
||||
|
||||
var output_width: c_int = undefined;
|
||||
var output_height: c_int = undefined;
|
||||
c.wlr_output_effective_resolution(data.view.output.wlr_output, &output_width, &output_height);
|
||||
|
||||
// Set width/height of view, clamp to view size constraints and output dimensions
|
||||
const box = &data.view.pending.box;
|
||||
box.width = @intCast(u32, std.math.max(0, @intCast(i32, box.width) + @floatToInt(i32, delta_x)));
|
||||
@ -167,8 +160,9 @@ const Mode = union(enum) {
|
||||
|
||||
data.view.applyConstraints();
|
||||
|
||||
box.width = std.math.min(box.width, @intCast(u32, output_width - box.x - @intCast(i32, border_width)));
|
||||
box.height = std.math.min(box.height, @intCast(u32, output_height - box.y - @intCast(i32, border_width)));
|
||||
const output_resolution = data.view.output.getEffectiveResolution();
|
||||
box.width = std.math.min(box.width, output_resolution.width - border_width - @intCast(u32, box.x));
|
||||
box.height = std.math.min(box.height, output_resolution.height - border_width - @intCast(u32, box.y));
|
||||
|
||||
data.view.applyPending();
|
||||
|
||||
|
@ -135,14 +135,12 @@ pub fn init(self: *Self, root: *Root, wlr_output: *c.wlr_output) !void {
|
||||
log.err(.cursor, "failed to load xcursor theme at scale {}", .{wlr_output.scale});
|
||||
}
|
||||
|
||||
var width: c_int = undefined;
|
||||
var height: c_int = undefined;
|
||||
c.wlr_output_effective_resolution(wlr_output, &width, &height);
|
||||
const effective_resolution = self.getEffectiveResolution();
|
||||
self.usable_box = .{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = @intCast(u32, width),
|
||||
.height = @intCast(u32, height),
|
||||
.width = effective_resolution.width,
|
||||
.height = effective_resolution.height,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -311,16 +309,12 @@ pub fn arrangeViews(self: *Self) void {
|
||||
|
||||
/// Arrange all layer surfaces of this output and adjust the usable area
|
||||
pub fn arrangeLayers(self: *Self) void {
|
||||
const full_box = blk: {
|
||||
var width: c_int = undefined;
|
||||
var height: c_int = undefined;
|
||||
c.wlr_output_effective_resolution(self.wlr_output, &width, &height);
|
||||
break :blk Box{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = @intCast(u32, width),
|
||||
.height = @intCast(u32, height),
|
||||
};
|
||||
const effective_resolution = self.getEffectiveResolution();
|
||||
const full_box: Box = .{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = effective_resolution.width,
|
||||
.height = effective_resolution.height,
|
||||
};
|
||||
|
||||
// This box is modified as exclusive zones are applied
|
||||
@ -615,3 +609,13 @@ fn handleMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||
self.arrangeViews();
|
||||
self.root.startTransaction();
|
||||
}
|
||||
|
||||
pub fn getEffectiveResolution(self: *Self) struct { width: u32, height: u32 } {
|
||||
var width: c_int = undefined;
|
||||
var height: c_int = undefined;
|
||||
c.wlr_output_effective_resolution(self.wlr_output, &width, &height);
|
||||
return .{
|
||||
.width = @intCast(u32, width),
|
||||
.height = @intCast(u32, height),
|
||||
};
|
||||
}
|
||||
|
@ -62,10 +62,9 @@ pub fn snap(
|
||||
const direction = std.meta.stringToEnum(PhysicalDirection, args[1]) orelse
|
||||
return Error.InvalidPhysicalDirection;
|
||||
|
||||
const view = get_view(seat) orelse return;
|
||||
const output_box = get_output_dimensions(view);
|
||||
const view = getView(seat) orelse return;
|
||||
const border_width = @intCast(i32, view.output.root.server.config.border_width);
|
||||
const output_box = view.output.getEffectiveResolution();
|
||||
switch (direction) {
|
||||
.up => view.pending.box.y = border_width,
|
||||
.down => view.pending.box.y =
|
||||
@ -91,10 +90,9 @@ pub fn resize(
|
||||
const orientation = std.meta.stringToEnum(Orientation, args[1]) orelse
|
||||
return Error.InvalidOrientation;
|
||||
|
||||
const view = get_view(seat) orelse return;
|
||||
const output_box = get_output_dimensions(view);
|
||||
const view = getView(seat) orelse return;
|
||||
const border_width = @intCast(i32, view.output.root.server.config.border_width);
|
||||
const output_box = view.output.getEffectiveResolution();
|
||||
switch (orientation) {
|
||||
.horizontal => {
|
||||
var real_delta: i32 = @intCast(i32, view.pending.box.width);
|
||||
@ -158,21 +156,8 @@ fn getView(seat: *Seat) ?*View {
|
||||
return view;
|
||||
}
|
||||
|
||||
fn get_output_dimensions(view: *View) Box {
|
||||
var output_width: c_int = undefined;
|
||||
var output_height: c_int = undefined;
|
||||
c.wlr_output_effective_resolution(view.output.wlr_output, &output_width, &output_height);
|
||||
const box: Box = .{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = @intCast(u32, output_width),
|
||||
.height = @intCast(u32, output_height),
|
||||
};
|
||||
return box;
|
||||
}
|
||||
|
||||
fn moveVertical(view: *View, delta: i32) void {
|
||||
const output_box = view.output.get_output_dimensions(view);
|
||||
const output_box = view.output.getEffectiveResolution();
|
||||
const border_width = @intCast(i32, view.output.root.server.config.border_width);
|
||||
view.pending.box.y = std.math.clamp(
|
||||
view.pending.box.y + delta,
|
||||
@ -182,7 +167,7 @@ fn moveVertical(view: *View, delta: i32) void {
|
||||
}
|
||||
|
||||
fn moveHorizontal(view: *View, delta: i32) void {
|
||||
const output_box = view.output.get_output_dimensions(view);
|
||||
const output_box = view.output.getEffectiveResolution();
|
||||
const border_width = @intCast(i32, view.output.root.server.config.border_width);
|
||||
view.pending.box.x = std.math.clamp(
|
||||
view.pending.box.x + delta,
|
||||
|
Loading…
Reference in New Issue
Block a user