fix: correct size of init float window

This commit is contained in:
DreamMaoMao 2025-03-09 13:45:20 +08:00
parent 7ba7331fd8
commit 8a24c74bf8
3 changed files with 146 additions and 137 deletions

View file

@ -3761,7 +3761,9 @@ monocle(Monitor *m, unsigned int gappo, unsigned int gappi) {
wlr_scene_node_raise_to_top(&c->scene->node); wlr_scene_node_raise_to_top(&c->scene->node);
} }
void motionabsolute(struct wl_listener *listener, void *data) { void
motionabsolute(struct wl_listener *listener, void *data)
{
/* This event is forwarded by the cursor when a pointer emits an _absolute_ /* This event is forwarded by the cursor when a pointer emits an _absolute_
* motion event, from 0..1 on each axis. This happens, for example, when * motion event, from 0..1 on each axis. This happens, for example, when
* wlroots is running under a Wayland window rather than KMS+DRM, and you * wlroots is running under a Wayland window rather than KMS+DRM, and you
@ -3774,16 +3776,16 @@ void motionabsolute(struct wl_listener *listener, void *data) {
if (!event->time_msec) /* this is 0 with virtual pointers */ if (!event->time_msec) /* this is 0 with virtual pointers */
wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y); wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y);
wlr_cursor_absolute_to_layout_coords(cursor, &event->pointer->base, event->x, wlr_cursor_absolute_to_layout_coords(cursor, &event->pointer->base, event->x, event->y, &lx, &ly);
event->y, &lx, &ly);
dx = lx - cursor->x; dx = lx - cursor->x;
dy = ly - cursor->y; dy = ly - cursor->y;
motionnotify(event->time_msec, &event->pointer->base, dx, dy, dx, dy); motionnotify(event->time_msec, &event->pointer->base, dx, dy, dx, dy);
} }
void // fix for 0.5 void
motionnotify(uint32_t time, struct wlr_input_device *device, double dx, motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
double dy, double dx_unaccel, double dy_unaccel) { double dx_unaccel, double dy_unaccel)
{
double sx = 0, sy = 0, sx_confined, sy_confined; double sx = 0, sy = 0, sx_confined, sy_confined;
Client *c = NULL, *w = NULL; Client *c = NULL, *w = NULL;
LayerSurface *l = NULL; LayerSurface *l = NULL;
@ -3793,34 +3795,31 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx,
/* Find the client under the pointer and send the event along. */ /* Find the client under the pointer and send the event along. */
xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy); xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy);
if (cursor_mode == CurPressed && !seat->drag && if (cursor_mode == CurPressed && !seat->drag
surface != seat->pointer_state.focused_surface && && surface != seat->pointer_state.focused_surface
toplevel_from_wlr_surface(seat->pointer_state.focused_surface, &w, &l) >= && toplevel_from_wlr_surface(seat->pointer_state.focused_surface, &w, &l) >= 0) {
0) {
c = w; c = w;
surface = seat->pointer_state.focused_surface; surface = seat->pointer_state.focused_surface;
sx = cursor->x - (l ? l->geom.x : w->geom.x); sx = cursor->x - (l ? l->scene->node.x : w->geom.x);
sy = cursor->y - (l ? l->geom.y : w->geom.y); sy = cursor->y - (l ? l->scene->node.y : w->geom.y);
} }
/* time is 0 in internal calls meant to restore pointer focus. */ /* time is 0 in internal calls meant to restore pointer focus. */
if (time) { if (time) {
wlr_relative_pointer_manager_v1_send_relative_motion( wlr_relative_pointer_manager_v1_send_relative_motion(
relative_pointer_mgr, seat, (uint64_t)time * 1000, dx, dy, dx_unaccel, relative_pointer_mgr, seat, (uint64_t)time * 1000,
dy_unaccel); dx, dy, dx_unaccel, dy_unaccel);
wl_list_for_each(constraint, &pointer_constraints->constraints, link) wl_list_for_each(constraint, &pointer_constraints->constraints, link)
cursorconstrain(constraint); cursorconstrain(constraint);
if (active_constraint && cursor_mode != CurResize && if (active_constraint && cursor_mode != CurResize && cursor_mode != CurMove) {
cursor_mode != CurMove) {
toplevel_from_wlr_surface(active_constraint->surface, &c, NULL); toplevel_from_wlr_surface(active_constraint->surface, &c, NULL);
if (c && if (c && active_constraint->surface == seat->pointer_state.focused_surface) {
active_constraint->surface == seat->pointer_state.focused_surface) {
sx = cursor->x - c->geom.x - c->bw; sx = cursor->x - c->geom.x - c->bw;
sy = cursor->y - c->geom.y - c->bw; sy = cursor->y - c->geom.y - c->bw;
if (wlr_region_confine(&active_constraint->region, sx, sy, sx + dx, if (wlr_region_confine(&active_constraint->region, sx, sy,
sy + dy, &sx_confined, &sy_confined)) { sx + dx, sy + dy, &sx_confined, &sy_confined)) {
dx = sx_confined - sx; dx = sx_confined - sx;
dy = sy_confined - sy; dy = sy_confined - sy;
} }
@ -3839,13 +3838,13 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx,
} }
/* Update drag icon's position */ /* Update drag icon's position */
wlr_scene_node_set_position(&drag_icon->node, cursor->x, cursor->y); wlr_scene_node_set_position(&drag_icon->node, (int)round(cursor->x), (int)round(cursor->y));
/* If we are currently grabbing the mouse, handle and return */ /* If we are currently grabbing the mouse, handle and return */
if (cursor_mode == CurMove) { if (cursor_mode == CurMove) {
/* Move the grabbed client to the new position. */ /* Move the grabbed client to the new position. */
grabc->oldgeom = (struct wlr_box){.x = cursor->x - grabcx, grabc->oldgeom = (struct wlr_box){.x = (int)round(cursor->x) - grabcx,
.y = cursor->y - grabcy, .y = (int)round(cursor->y) - grabcy,
.width = grabc->geom.width, .width = grabc->geom.width,
.height = grabc->geom.height}; .height = grabc->geom.height};
resize(grabc, grabc->oldgeom, 1); resize(grabc, grabc->oldgeom, 1);
@ -3853,8 +3852,8 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx,
} else if (cursor_mode == CurResize) { } else if (cursor_mode == CurResize) {
grabc->oldgeom = (struct wlr_box){.x = grabc->geom.x, grabc->oldgeom = (struct wlr_box){.x = grabc->geom.x,
.y = grabc->geom.y, .y = grabc->geom.y,
.width = cursor->x - grabc->geom.x, .width = (int)round(cursor->x) - grabc->geom.x,
.height = cursor->y - grabc->geom.y}; .height = (int)round(cursor->y) - grabc->geom.y};
resize(grabc, grabc->oldgeom, 1); resize(grabc, grabc->oldgeom, 1);
return; return;
} }
@ -3863,13 +3862,14 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx,
* default. This is what makes the cursor image appear when you move it * default. This is what makes the cursor image appear when you move it
* off of a client or over its border. */ * off of a client or over its border. */
if (!surface && !seat->drag) if (!surface && !seat->drag)
wlr_cursor_set_xcursor(cursor, cursor_mgr, "left_ptr"); wlr_cursor_set_xcursor(cursor, cursor_mgr, "default");
pointerfocus(c, surface, sx, sy, time); pointerfocus(c, surface, sx, sy, time);
} }
void // fix for 0.5 光标相对位置移动事件处理 void
motionrelative(struct wl_listener *listener, void *data) { motionrelative(struct wl_listener *listener, void *data)
{
/* This event is forwarded by the cursor when a pointer emits a _relative_ /* This event is forwarded by the cursor when a pointer emits a _relative_
* pointer motion event (i.e. a delta) */ * pointer motion event (i.e. a delta) */
struct wlr_pointer_motion_event *event = data; struct wlr_pointer_motion_event *event = data;
@ -3878,21 +3878,8 @@ motionrelative(struct wl_listener *listener, void *data) {
* special configuration applied for the specific input device which * special configuration applied for the specific input device which
* generated the event. You can pass NULL for the device if you want to move * generated the event. You can pass NULL for the device if you want to move
* the cursor around without any input. */ * the cursor around without any input. */
motionnotify(event->time_msec, &event->pointer->base, event->delta_x, event->delta_y,
// //处理一些事件,比如窗口聚焦,图层聚焦通知到客户端 event->unaccel_dx, event->unaccel_dy);
// motionnotify(event->time_msec);
// //扩展事件通知,没有这个鼠标移动的时候滑轮将无法使用
// wlr_relative_pointer_manager_v1_send_relative_motion(
// pointer_manager,
// seat, (uint64_t)(event->time_msec) * 1000,
// event->delta_x, event->delta_y,
// event->unaccel_dx, event->unaccel_dy);
// //通知光标设备移动
// wlr_cursor_move(cursor, &event->pointer->base, event->delta_x,
// event->delta_y);
motionnotify(event->time_msec, &event->pointer->base, event->delta_x,
event->delta_y, event->unaccel_dx, event->unaccel_dy);
// 鼠标左下热区判断是否触发
toggle_hotarea(cursor->x, cursor->y); toggle_hotarea(cursor->x, cursor->y);
} }
@ -4144,11 +4131,13 @@ void requestdecorationmode(struct wl_listener *listener, void *data) {
c->decoration, WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); c->decoration, WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
} }
void // 17 void
requeststartdrag(struct wl_listener *listener, void *data) { requeststartdrag(struct wl_listener *listener, void *data)
{
struct wlr_seat_request_start_drag_event *event = data; struct wlr_seat_request_start_drag_event *event = data;
if (wlr_seat_validate_pointer_grab_serial(seat, event->origin, event->serial)) if (wlr_seat_validate_pointer_grab_serial(seat, event->origin,
event->serial))
wlr_seat_start_pointer_drag(seat, event->drag, event->serial); wlr_seat_start_pointer_drag(seat, event->drag, event->serial);
else else
wlr_data_source_destroy(event->drag->source); wlr_data_source_destroy(event->drag->source);
@ -4513,8 +4502,8 @@ setfloating(Client *c, int floating) {
target_box = c->geom; target_box = c->geom;
if (c->istiled && !c->swallowing) {
if (c->istiled) { if (c->istiled) {
if (!c->swallowing && !c->is_open_animation) {
target_box.height = target_box.height * 0.8; target_box.height = target_box.height * 0.8;
target_box.width = target_box.width * 0.8; target_box.width = target_box.width * 0.8;
} }
@ -4872,7 +4861,7 @@ void signalhandler(int signalnumber) {
} }
// 打开日志文件 // 打开日志文件
FILE *fp = fopen(filename, "a"); FILE *fp = fopen(filename, "w");
if (!fp) { if (!fp) {
// 如果无法打开日志文件,则不处理 // 如果无法打开日志文件,则不处理
return; return;

23
util.c
View file

@ -3,10 +3,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <fcntl.h>
#include "util.h" #include "util.h"
void die(const char *fmt, ...) { void
die(const char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@ -23,10 +25,27 @@ void die(const char *fmt, ...) {
exit(1); exit(1);
} }
void *ecalloc(size_t nmemb, size_t size) { void *
ecalloc(size_t nmemb, size_t size)
{
void *p; void *p;
if (!(p = calloc(nmemb, size))) if (!(p = calloc(nmemb, size)))
die("calloc:"); die("calloc:");
return p; return p;
} }
int
fd_set_nonblock(int fd) {
int flags = fcntl(fd, F_GETFL);
if (flags < 0) {
perror("fcntl(F_GETFL):");
return -1;
}
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
perror("fcntl(F_SETFL):");
return -1;
}
return 0;
}

1
util.h
View file

@ -2,3 +2,4 @@
void die(const char *fmt, ...); void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size); void *ecalloc(size_t nmemb, size_t size);
int fd_set_nonblock(int fd);