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

229
maomao.c
View file

@ -3761,138 +3761,125 @@ 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
/* This event is forwarded by the cursor when a pointer emits an _absolute_ motionabsolute(struct wl_listener *listener, void *data)
* 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 /* This event is forwarded by the cursor when a pointer emits an _absolute_
* move the mouse over the window. You could enter the window from any edge, * motion event, from 0..1 on each axis. This happens, for example, when
* so we have to warp the mouse there. There is also some hardware which * wlroots is running under a Wayland window rather than KMS+DRM, and you
* emits these events. */ * move the mouse over the window. You could enter the window from any edge,
struct wlr_pointer_motion_absolute_event *event = data; * so we have to warp the mouse there. There is also some hardware which
double lx, ly, dx, dy; * emits these events. */
struct wlr_pointer_motion_absolute_event *event = data;
double lx, ly, dx, dy;
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; {
Client *c = NULL, *w = NULL; double sx = 0, sy = 0, sx_confined, sy_confined;
LayerSurface *l = NULL; Client *c = NULL, *w = NULL;
struct wlr_surface *surface = NULL; LayerSurface *l = NULL;
struct wlr_pointer_constraint_v1 *constraint; struct wlr_surface *surface = NULL;
struct wlr_pointer_constraint_v1 *constraint;
/* 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->scene->node.x : w->geom.x);
sx = cursor->x - (l ? l->geom.x : w->geom.x); sy = cursor->y - (l ? l->scene->node.y : w->geom.y);
sy = cursor->y - (l ? l->geom.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 && active_constraint->surface == seat->pointer_state.focused_surface) {
if (c && sx = cursor->x - c->geom.x - c->bw;
active_constraint->surface == seat->pointer_state.focused_surface) { sy = cursor->y - c->geom.y - c->bw;
sx = cursor->x - c->geom.x - c->bw; if (wlr_region_confine(&active_constraint->region, sx, sy,
sy = cursor->y - c->geom.y - c->bw; sx + dx, sy + dy, &sx_confined, &sy_confined)) {
if (wlr_region_confine(&active_constraint->region, sx, sy, sx + dx, dx = sx_confined - sx;
sy + dy, &sx_confined, &sy_confined)) { dy = sy_confined - sy;
dx = sx_confined - sx; }
dy = sy_confined - sy;
}
if (active_constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) if (active_constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED)
return; return;
} }
} }
wlr_cursor_move(cursor, device, dx, dy); wlr_cursor_move(cursor, device, dx, dy);
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
/* Update selmon (even while dragging a window) */ /* Update selmon (even while dragging a window) */
if (sloppyfocus) if (sloppyfocus)
selmon = xytomon(cursor->x, cursor->y); selmon = xytomon(cursor->x, cursor->y);
} }
/* 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);
return; return;
} 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;
} }
/* If there's no client surface under the cursor, set the cursor image to a /* If there's no client surface under the cursor, set the cursor image to a
* 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_ {
* pointer motion event (i.e. a delta) */ /* This event is forwarded by the cursor when a pointer emits a _relative_
struct wlr_pointer_motion_event *event = data; * pointer motion event (i.e. a delta) */
/* The cursor doesn't move unless we tell it to. The cursor automatically struct wlr_pointer_motion_event *event = data;
* handles constraining the motion to the output layout, as well as any /* The cursor doesn't move unless we tell it to. The cursor automatically
* special configuration applied for the specific input device which * handles constraining the motion to the output layout, as well as any
* generated the event. You can pass NULL for the device if you want to move * special configuration applied for the specific input device which
* the cursor around without any input. */ * generated the event. You can pass NULL for the device if you want to move
* the cursor around without any input. */
// //处理一些事件,比如窗口聚焦,图层聚焦通知到客户端 motionnotify(event->time_msec, &event->pointer->base, event->delta_x, event->delta_y,
// motionnotify(event->time_msec); event->unaccel_dx, event->unaccel_dy);
// //扩展事件通知,没有这个鼠标移动的时候滑轮将无法使用
// 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,14 +4131,16 @@ 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,
wlr_seat_start_pointer_drag(seat, event->drag, event->serial); event->serial))
else wlr_seat_start_pointer_drag(seat, event->drag, event->serial);
wlr_data_source_destroy(event->drag->source); else
wlr_data_source_destroy(event->drag->source);
} }
void setborder_color(Client *c) { void setborder_color(Client *c) {
@ -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;

53
util.c
View file

@ -3,30 +3,49 @@
#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
va_list ap; die(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
va_end(ap); va_end(ap);
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
fputc(' ', stderr); fputc(' ', stderr);
perror(NULL); perror(NULL);
} else { } else {
fputc('\n', stderr); fputc('\n', stderr);
} }
exit(1); exit(1);
} }
void *ecalloc(size_t nmemb, size_t size) { void *
void *p; ecalloc(size_t nmemb, size_t size)
{
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);