mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-08 20:57:32 -04:00
Merge branch 'bouncing' into dev
This commit is contained in:
commit
d4a0abe762
11 changed files with 270 additions and 123 deletions
|
|
@ -3,6 +3,10 @@ const LuaUtils = @This();
|
|||
const std = @import("std");
|
||||
const zlua = @import("zlua");
|
||||
|
||||
const View = @import("../View.zig");
|
||||
|
||||
const server = &@import("../main.zig").server;
|
||||
|
||||
pub fn coerceNumber(comptime x: type, number: zlua.Number) error{InvalidNumber}!x {
|
||||
if (number < std.math.minInt(x) or number > std.math.maxInt(x) or std.math.isNan(number)) {
|
||||
return error.InvalidNumber;
|
||||
|
|
@ -43,3 +47,14 @@ pub fn toStringEx(L: *zlua.Lua) [:0]const u8 {
|
|||
L.protectedCall(.{ .args = 1, .results = 1 }) catch return errstr;
|
||||
return L.toString(-1) catch errstr;
|
||||
}
|
||||
|
||||
pub fn viewById(view_id: u64) ?*View {
|
||||
if (view_id == 0) {
|
||||
if(server.seat.focused_surface) |fs| {
|
||||
if(fs == .view) return fs.view;
|
||||
}
|
||||
} else {
|
||||
return server.root.viewById(view_id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,9 +68,11 @@ pub fn check(L: *zlua.Lua) i32 {
|
|||
// ---Get the id for the focused view
|
||||
// ---@return view_id?
|
||||
pub fn get_focused_id(L: *zlua.Lua) i32 {
|
||||
if(server.seat.focused_view) |view| {
|
||||
L.pushInteger(@intCast(view.id));
|
||||
return 1;
|
||||
if(server.seat.focused_surface) |fs| {
|
||||
if(fs == .view) {
|
||||
L.pushInteger(@intCast(fs.view.id));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
L.pushNil();
|
||||
|
|
@ -82,8 +84,7 @@ pub fn get_focused_id(L: *zlua.Lua) i32 {
|
|||
pub fn close(L: *zlua.Lua) i32 {
|
||||
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||
|
||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||
if(view) |v| {
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
v.close();
|
||||
}
|
||||
|
||||
|
|
@ -100,8 +101,7 @@ pub fn set_position(L: *zlua.Lua) i32 {
|
|||
const x = LuaUtils.coerceNumber(i32, L.checkNumber(2)) catch L.raiseErrorStr("The x must be > -inf and < inf", .{});
|
||||
const y = LuaUtils.coerceNumber(i32, L.checkNumber(3)) catch L.raiseErrorStr("The y must be > -inf and < inf", .{});
|
||||
|
||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||
if(view) |v| {
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
v.setPosition(x, y);
|
||||
}
|
||||
|
||||
|
|
@ -109,10 +109,33 @@ pub fn set_position(L: *zlua.Lua) i32 {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// ---Resize the view by it's top left corner
|
||||
// ---Get the position of the view
|
||||
// ---@param view_id view_id 0 maps to focused view
|
||||
// ---@param width number width for view
|
||||
// ---@param height number height for view
|
||||
// ---@return { x: integer, y: integer }? Position of the view
|
||||
pub fn get_position(L: *zlua.Lua) i32 {
|
||||
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||
if (LuaUtils.viewById(view_id)) |v| {
|
||||
L.newTable();
|
||||
|
||||
_ = L.pushString("x");
|
||||
L.pushInteger(@intCast(v.xdg_toplevel.base.geometry.x));
|
||||
L.setTable(-3);
|
||||
|
||||
_ = L.pushString("y");
|
||||
L.pushInteger(@intCast(v.xdg_toplevel.base.geometry.y));
|
||||
L.setTable(-3);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
L.pushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ---Set the size of the spesified view. Will be resized relative to
|
||||
// the view's top left corner.
|
||||
// ---@param view_id view_id 0 maps to focused view
|
||||
// ---@return
|
||||
pub fn set_size(L: *zlua.Lua) i32 {
|
||||
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||
// We use u32s here to enforce a minimum size of zero. The call to resize a
|
||||
|
|
@ -122,8 +145,7 @@ pub fn set_size(L: *zlua.Lua) i32 {
|
|||
const width = LuaUtils.coerceNumber(u32, L.checkNumber(2)) catch L.raiseErrorStr("The width must be >= 0 and < inf", .{});
|
||||
const height = LuaUtils.coerceNumber(u32, L.checkNumber(3)) catch L.raiseErrorStr("The height must be >= 0 and < inf", .{});
|
||||
|
||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||
if(view) |v| {
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
v.setSize(@intCast(width), @intCast(height));
|
||||
}
|
||||
|
||||
|
|
@ -131,10 +153,12 @@ pub fn set_size(L: *zlua.Lua) i32 {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// ---Get the size of the view
|
||||
// ---@param view_id view_id 0 maps to focused view
|
||||
// ---@return { width: integer, height: integer }? Size of the view
|
||||
pub fn get_size(L: *zlua.Lua) i32 {
|
||||
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||
if (view) |v| {
|
||||
if (LuaUtils.viewById(view_id)) |v| {
|
||||
L.newTable();
|
||||
|
||||
_ = L.pushString("width");
|
||||
|
|
@ -158,23 +182,9 @@ pub fn set_focused(L: *zlua.Lua) i32 {
|
|||
const view_id: ?c_longlong = L.optInteger(1);
|
||||
|
||||
if(view_id == null) {
|
||||
if(server.seat.focused_view != null) {
|
||||
server.seat.focused_view.?.focused = false;
|
||||
server.seat.focused_view = null;
|
||||
}
|
||||
L.pushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (view_id == null) {
|
||||
L.pushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(server.root.viewById(@intCast(view_id.?))) |view| {
|
||||
view.setFocused();
|
||||
L.pushNil();
|
||||
return 1;
|
||||
server.seat.focusSurface(null);
|
||||
} else if(server.root.viewById(@intCast(view_id.?))) |view| {
|
||||
server.seat.focusSurface(.{ .view = view });
|
||||
}
|
||||
|
||||
L.pushNil();
|
||||
|
|
@ -186,14 +196,10 @@ pub fn set_focused(L: *zlua.Lua) i32 {
|
|||
pub fn toggle_fullscreen(L: *zlua.Lua) i32 {
|
||||
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||
|
||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||
if(view) |v| {
|
||||
std.log.debug("fullscreen view {d}", .{view_id});
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
std.log.debug("toggling fullscreen", .{});
|
||||
if(v.fullscreen) {
|
||||
v.toContent();
|
||||
} else {
|
||||
v.toFullscreen();
|
||||
}
|
||||
v.toggleFullscreen();
|
||||
}
|
||||
|
||||
L.pushNil();
|
||||
|
|
@ -206,8 +212,7 @@ pub fn toggle_fullscreen(L: *zlua.Lua) i32 {
|
|||
pub fn get_title(L: *zlua.Lua) i32 {
|
||||
const view_id: u64 = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||
|
||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||
if(view) |v| {
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
if(v.xdg_toplevel.title == null) {
|
||||
L.pushNil();
|
||||
return 1;
|
||||
|
|
@ -227,8 +232,7 @@ pub fn get_title(L: *zlua.Lua) i32 {
|
|||
pub fn get_app_id(L: *zlua.Lua) i32 {
|
||||
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||
|
||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||
if(view) |v| {
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
if(v.xdg_toplevel.app_id == null) {
|
||||
L.pushNil();
|
||||
return 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue