very basic window movement bound to alt-left

This commit is contained in:
Harrison DiAmbrosio 2025-10-24 17:24:41 -04:00
parent 17cdbae175
commit 36b89b04d0
4 changed files with 47 additions and 20 deletions

View file

@ -69,6 +69,7 @@ pub fn build(b: *std.Build) void {
mez.linkSystemLibrary("wayland-server"); mez.linkSystemLibrary("wayland-server");
mez.linkSystemLibrary("xkbcommon"); mez.linkSystemLibrary("xkbcommon");
mez.linkSystemLibrary("pixman-1"); mez.linkSystemLibrary("pixman-1");
mez.linkSystemLibrary("libevdev");
const options = b.addOptions(); const options = b.addOptions();
options.addOption([]const u8, "runtime_path_prefix", runtime_path_prefix); options.addOption([]const u8, "runtime_path_prefix", runtime_path_prefix);

View file

@ -11,6 +11,6 @@ mez.path.config = mez.fs.joinpath(env_conf, "mez", "init.lua")
package.path = package.path..";"..mez.fs.joinpath(env_conf, "mez", "lua", "?.lua") package.path = package.path..";"..mez.fs.joinpath(env_conf, "mez", "lua", "?.lua")
-- this is an example -- this is an example
-- mez.api.add_keymap("ctrl", "a", function() mez.api.add_keymap("alt", "a", function()
-- print("hello from my keymap") print("hello from my keymap")
-- end) end)

5
src/c.zig Normal file
View file

@ -0,0 +1,5 @@
pub const c = @cImport({
@cInclude("linux/input-event-codes.h");
@cInclude("libevdev/libevdev.h");
@cInclude("libinput.h");
});

View file

@ -6,11 +6,15 @@ pub const Cursor = @This();
const std = @import("std"); const std = @import("std");
const wl = @import("wayland").server.wl; const wl = @import("wayland").server.wl;
const wlr = @import("wlroots"); const wlr = @import("wlroots");
const xkb = @import("xkbcommon");
const View = @import("view.zig"); const View = @import("view.zig");
const Utils = @import("utils.zig"); const Utils = @import("utils.zig");
const c = @import("c.zig").c;
const server = &@import("main.zig").server; const server = &@import("main.zig").server;
const linux = std.os.linux;
wlr_cursor: *wlr.Cursor, wlr_cursor: *wlr.Cursor,
x_cursor_manager: *wlr.XcursorManager, x_cursor_manager: *wlr.XcursorManager,
@ -59,11 +63,15 @@ pub fn deinit(self: *Cursor) void {
self.frame.link.remove(); self.frame.link.remove();
} }
// pub fn moveView(self: *Cursor, view: *View) void { pub fn moveView(self: *Cursor, view: *View, _: *wlr.Pointer.event.Button) void {
// } self.mode = .move;
self.selected_view = view;
}
// pub fn resizeView(self: *Cursor, view: *View) void { pub fn resizeView(self: *Cursor, view: *View, _: *wlr.Pointer.event.Button) void {
// } self.mode = .resize;
self.selected_view = view;
}
pub fn processCursorMotion(self: *Cursor, time_msec: u32) void { pub fn processCursorMotion(self: *Cursor, time_msec: u32) void {
switch (self.mode) { switch (self.mode) {
@ -77,15 +85,11 @@ pub fn processCursorMotion(self: *Cursor, time_msec: u32) void {
} }
}, },
.move => { .move => {
// REDOING RESIZING AND MOVING TOPLEVELS const view = self.selected_view.?;
// REDOING RESIZING AND MOVING TOPLEVELS view.scene_tree.node.setPosition(
// REDOING RESIZING AND MOVING TOPLEVELS @as(i32, @intFromFloat(self.wlr_cursor.x)),
// REDOING RESIZING AND MOVING TOPLEVELS @as(i32, @intFromFloat(self.wlr_cursor.y))
// const view = self.selected_view.?; );
// view.scene_tree.node.setPosition(
// @as(i32, @intFromFloat(self.wlr_cursor.x - self.grab_x)),
// @as(i32, @intFromFloat(self.wlr_cursor.y - self.grab_y))
// );
}, },
.resize => { .resize => {
// Fix this resize // Fix this resize
@ -153,18 +157,35 @@ fn handleMotionAbsolute(
} }
fn handleButton( fn handleButton(
_: *wl.Listener(*wlr.Pointer.event.Button), listener: *wl.Listener(*wlr.Pointer.event.Button),
event: *wlr.Pointer.event.Button event: *wlr.Pointer.event.Button
) void { ) void {
const cursor: *Cursor = @fieldParentPtr("button", listener);
_ = server.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state); _ = server.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
const view_at_result = server.root.viewAt(cursor.wlr_cursor.x, cursor.wlr_cursor.y);
if (view_at_result) |res| {
server.root.focusView(res.view);
}
std.log.debug("Button pressed {}", .{event.button});
switch (event.state) { switch (event.state) {
.pressed => { .pressed => {
if (server.root.viewAt(server.cursor.wlr_cursor.x, server.cursor.wlr_cursor.y)) |res| { if(server.keyboard.wlr_keyboard.getModifiers().alt) {
server.root.focusView(res.view); // Can be BTN_RIGHT, BTN_LEFT, or BTN_MIDDLE
if(view_at_result) |res| {
if(event.button == c.libevdev_event_code_from_name(c.EV_KEY, "BTN_LEFT")) {
cursor.moveView(res.view, event);
} else if(event.button == c.libevdev_event_code_from_name(c.EV_KEY, "BTN_RIGHT")) {
cursor.resizeView(res.view, event);
}
}
} }
}, },
.released => { .released => {
server.cursor.mode = .passthrough; cursor.mode = .passthrough;
}, },
else => { else => {
std.log.err("Invalid/Unimplemented pointer button event type", .{}); std.log.err("Invalid/Unimplemented pointer button event type", .{});