fix resize, move and border bugs

This commit is contained in:
2026-04-01 17:42:16 +07:00
parent 32028bae98
commit 698e89685c
7 changed files with 24 additions and 127 deletions
+1 -4
View File
@@ -1,6 +1,3 @@
absinthe
.cache/
result/
result
compile_commands.json
xdg-shell-protocol.h
TAGS
+1 -1
View File
@@ -5,5 +5,5 @@ proto:
compile: proto
gcc -o absinthe src/* \
-I./ -I./include -DWLR_USE_UNSTABLE $(shell pkg-config wlroots-0.19 --libs --cflags) -lwayland-server -lxkbcommon \
-I./ -I./include -DWLR_USE_UNSTABLE $(shell pkg-config wlroots-0.20 --libs --cflags) -lwayland-server -lxkbcommon \
-ggdb
Generated
-27
View File
@@ -1,27 +0,0 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1768773494,
"narHash": "sha256-XsM7GP3jHlephymxhDE+/TKKO1Q16phz/vQiLBGhpF4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "77ef7a29d276c6d8303aece3444d61118ef71ac2",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-25.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
-66
View File
@@ -1,66 +0,0 @@
{
description = "Absinthe wayland compositor";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
};
outputs = { self, nixpkgs, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
in
{
packages.${system}.default = pkgs.stdenv.mkDerivation {
pname = "absinthe";
version = "0.1";
src = ./.;
nativeBuildInputs = with pkgs; [
gcc
gnumake
pkg-config
wayland-scanner
];
buildInputs = with pkgs; [
wayland
wayland-protocols
wlroots_0_19
pixman
libxkbcommon
];
buildPhase = ''
make
'';
installPhase = ''
mkdir -p $out/bin
cp absinthe $out/bin/
'';
};
devShells."${system}".default = pkgs.mkShell {
packages = with pkgs; [
pkg-config
gnumake
gcc
gdb
wayland
wayland-protocols
wayland-scanner
wlroots_0_19
pixman
libxkbcommon
fish
];
shellHook = ''
echo "Absinthe dev shell"
exec fish
'';
};
};
}
+10 -8
View File
@@ -127,6 +127,16 @@ static void process_cursor_resize(struct absinthe_server *server) {
void process_cursor_motion(struct absinthe_server *server, uint32_t time)
{
double sx, sy;
struct wlr_seat *seat = server->seat;
struct wlr_surface *surface = NULL;
struct absinthe_toplevel *toplevel = absinthe_toplevel_at(server, server->cursor->x, server->cursor->y, &surface, &sx, &sy);
if (!toplevel) {
wlr_cursor_set_xcursor(server->cursor, server->cursor_mgr, "default");
return;
}
if (server->cursor_mode == ABSINTHE_CURSOR_MOVE) {
process_cursor_move(server);
return;
@@ -135,14 +145,6 @@ void process_cursor_motion(struct absinthe_server *server, uint32_t time)
return;
}
double sx, sy;
struct wlr_seat *seat = server->seat;
struct wlr_surface *surface = NULL;
struct absinthe_toplevel *toplevel = absinthe_toplevel_at(server, server->cursor->x, server->cursor->y, &surface, &sx, &sy);
if (!toplevel)
wlr_cursor_set_xcursor(server->cursor, server->cursor_mgr, "default");
if (surface) {
wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
+4 -4
View File
@@ -31,7 +31,7 @@ void server_new_output(struct wl_listener *listener, void *data)
wlr_output_commit_state(wlr_output, &state);
wlr_output_state_finish(&state);
struct absinthe_output *output = calloc(1, sizeof(*output));
struct absinthe_output *output = malloc(sizeof(*output));
output->wlr_output = wlr_output;
output->server = server;
@@ -57,7 +57,7 @@ void server_new_xdg_toplevel(struct wl_listener *listener, void *data)
struct absinthe_server *server = wl_container_of(listener, server, new_xdg_toplevel);
struct wlr_xdg_toplevel *xdg_toplevel = data;
struct absinthe_toplevel *toplevel = calloc(1, sizeof(*toplevel));
struct absinthe_toplevel *toplevel = malloc(sizeof(*toplevel));
toplevel->server = server;
toplevel->xdg_toplevel = xdg_toplevel;
toplevel->scene_tree = wlr_scene_tree_create(&toplevel->server->scene->tree);
@@ -90,7 +90,7 @@ void server_new_xdg_popup(struct wl_listener *listener, void *data)
struct absinthe_server *server = wl_container_of(listener, server, new_xdg_popup);
struct wlr_xdg_popup *xdg_popup = data;
struct absinthe_popup *popup = calloc(1, sizeof(*popup));
struct absinthe_popup *popup = malloc(sizeof(*popup));
popup->xdg_popup = xdg_popup;
struct wlr_xdg_surface *parent = wlr_xdg_surface_try_from_wlr_surface(xdg_popup->parent);
@@ -221,7 +221,7 @@ void server_cursor_frame(struct wl_listener *listener, void *data)
static void server_new_keyboard(struct absinthe_server *server, struct wlr_input_device *device)
{
struct wlr_keyboard *wlr_keyboard = wlr_keyboard_from_input_device(device);
struct absinthe_keyboard *keyboard = calloc(1, sizeof(*keyboard));
struct absinthe_keyboard *keyboard = malloc(sizeof(*keyboard));
keyboard->server = server;
keyboard->wlr_keyboard = wlr_keyboard;
+7 -16
View File
@@ -1,4 +1,5 @@
#include <stdlib.h>
#include <assert.h>
#include <wayland-server-core.h>
#include <wlr/util/log.h>
@@ -12,24 +13,17 @@ void xdg_toplevel_commit(struct wl_listener *listener, void *data)
struct absinthe_toplevel *toplevel = wl_container_of(listener, toplevel, commit);
if (toplevel->xdg_toplevel->base->initial_commit) {
// Let client set the preferred size
wlr_xdg_toplevel_set_size(toplevel->xdg_toplevel, 0, 0);
// Forse server side decoration mode
if (toplevel->decoration)
xdg_decoration_request_mode(&toplevel->decoration_request_mode, toplevel->decoration);
// Let toplevel set preferred size
wlr_xdg_toplevel_set_size(toplevel->xdg_toplevel, 0, 0);
} else {
// Check for size because we did't set it on initial commit
if (toplevel->geometry.width == 0 || toplevel->geometry.height == 0) {
int32_t bw = toplevel->border_width;
toplevel->geometry.width = toplevel->xdg_toplevel->base->geometry.width + 2 * bw;
toplevel->geometry.height = toplevel->xdg_toplevel->base->geometry.height + 2 * bw;
int32_t rel_x = toplevel->output->geometry.x + toplevel->output->geometry.width / 2 - toplevel->geometry.width / 2;
int32_t rel_y = toplevel->output->geometry.y + toplevel->output->geometry.height / 2 - toplevel->geometry.height / 2;
toplevel->geometry.x += abs(rel_x);
toplevel->geometry.y += abs(rel_y);
}
int32_t bw = toplevel->border_width;
toplevel->geometry.width = toplevel->xdg_toplevel->base->geometry.width + 2 * bw;
toplevel->geometry.height = toplevel->xdg_toplevel->base->geometry.height + 2 * bw;
absinthe_toplevel_set_position(toplevel, toplevel->geometry.x, toplevel->geometry.y);
absinthe_toplevel_update_borders_geometry(toplevel);
@@ -48,9 +42,6 @@ void xdg_toplevel_map(struct wl_listener *listener, void *data)
toplevel->border_width = ABSINTHE_WINDOW_BORDER_WIDTH;
absinthe_toplevel_set_border_color(toplevel, unfocused_border_color);
absinthe_toplevel_update_borders_geometry(toplevel);
toplevel->output = toplevel->server->focused_output;
toplevel->fullscreen = false;