mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-05-03 06:46:38 -04:00
fix: correct size of init float window
This commit is contained in:
parent
7ba7331fd8
commit
8a24c74bf8
3 changed files with 146 additions and 137 deletions
229
maomao.c
229
maomao.c
|
|
@ -3761,138 +3761,125 @@ monocle(Monitor *m, unsigned int gappo, unsigned int gappi) {
|
|||
wlr_scene_node_raise_to_top(&c->scene->node);
|
||||
}
|
||||
|
||||
void motionabsolute(struct wl_listener *listener, void *data) {
|
||||
/* 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
|
||||
* wlroots is running under a Wayland window rather than KMS+DRM, and you
|
||||
* move the mouse over the window. You could enter the window from any edge,
|
||||
* so we have to warp the mouse there. There is also some hardware which
|
||||
* emits these events. */
|
||||
struct wlr_pointer_motion_absolute_event *event = data;
|
||||
double lx, ly, dx, dy;
|
||||
void
|
||||
motionabsolute(struct wl_listener *listener, void *data)
|
||||
{
|
||||
/* 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
|
||||
* wlroots is running under a Wayland window rather than KMS+DRM, and you
|
||||
* move the mouse over the window. You could enter the window from any edge,
|
||||
* so we have to warp the mouse there. There is also some hardware which
|
||||
* 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 */
|
||||
wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y);
|
||||
if (!event->time_msec) /* this is 0 with virtual pointers */
|
||||
wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y);
|
||||
|
||||
wlr_cursor_absolute_to_layout_coords(cursor, &event->pointer->base, event->x,
|
||||
event->y, &lx, &ly);
|
||||
dx = lx - cursor->x;
|
||||
dy = ly - cursor->y;
|
||||
motionnotify(event->time_msec, &event->pointer->base, dx, dy, dx, dy);
|
||||
wlr_cursor_absolute_to_layout_coords(cursor, &event->pointer->base, event->x, event->y, &lx, &ly);
|
||||
dx = lx - cursor->x;
|
||||
dy = ly - cursor->y;
|
||||
motionnotify(event->time_msec, &event->pointer->base, dx, dy, dx, dy);
|
||||
}
|
||||
|
||||
void // fix for 0.5
|
||||
motionnotify(uint32_t time, struct wlr_input_device *device, double dx,
|
||||
double dy, double dx_unaccel, double dy_unaccel) {
|
||||
double sx = 0, sy = 0, sx_confined, sy_confined;
|
||||
Client *c = NULL, *w = NULL;
|
||||
LayerSurface *l = NULL;
|
||||
struct wlr_surface *surface = NULL;
|
||||
struct wlr_pointer_constraint_v1 *constraint;
|
||||
void
|
||||
motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
|
||||
double dx_unaccel, double dy_unaccel)
|
||||
{
|
||||
double sx = 0, sy = 0, sx_confined, sy_confined;
|
||||
Client *c = NULL, *w = NULL;
|
||||
LayerSurface *l = NULL;
|
||||
struct wlr_surface *surface = NULL;
|
||||
struct wlr_pointer_constraint_v1 *constraint;
|
||||
|
||||
/* Find the client under the pointer and send the event along. */
|
||||
xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy);
|
||||
/* Find the client under the pointer and send the event along. */
|
||||
xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy);
|
||||
|
||||
if (cursor_mode == CurPressed && !seat->drag &&
|
||||
surface != seat->pointer_state.focused_surface &&
|
||||
toplevel_from_wlr_surface(seat->pointer_state.focused_surface, &w, &l) >=
|
||||
0) {
|
||||
c = w;
|
||||
surface = seat->pointer_state.focused_surface;
|
||||
sx = cursor->x - (l ? l->geom.x : w->geom.x);
|
||||
sy = cursor->y - (l ? l->geom.y : w->geom.y);
|
||||
}
|
||||
if (cursor_mode == CurPressed && !seat->drag
|
||||
&& surface != seat->pointer_state.focused_surface
|
||||
&& toplevel_from_wlr_surface(seat->pointer_state.focused_surface, &w, &l) >= 0) {
|
||||
c = w;
|
||||
surface = seat->pointer_state.focused_surface;
|
||||
sx = cursor->x - (l ? l->scene->node.x : w->geom.x);
|
||||
sy = cursor->y - (l ? l->scene->node.y : w->geom.y);
|
||||
}
|
||||
|
||||
/* time is 0 in internal calls meant to restore pointer focus. */
|
||||
if (time) {
|
||||
wlr_relative_pointer_manager_v1_send_relative_motion(
|
||||
relative_pointer_mgr, seat, (uint64_t)time * 1000, dx, dy, dx_unaccel,
|
||||
dy_unaccel);
|
||||
/* time is 0 in internal calls meant to restore pointer focus. */
|
||||
if (time) {
|
||||
wlr_relative_pointer_manager_v1_send_relative_motion(
|
||||
relative_pointer_mgr, seat, (uint64_t)time * 1000,
|
||||
dx, dy, dx_unaccel, dy_unaccel);
|
||||
|
||||
wl_list_for_each(constraint, &pointer_constraints->constraints, link)
|
||||
cursorconstrain(constraint);
|
||||
wl_list_for_each(constraint, &pointer_constraints->constraints, link)
|
||||
cursorconstrain(constraint);
|
||||
|
||||
if (active_constraint && cursor_mode != CurResize &&
|
||||
cursor_mode != CurMove) {
|
||||
toplevel_from_wlr_surface(active_constraint->surface, &c, NULL);
|
||||
if (c &&
|
||||
active_constraint->surface == seat->pointer_state.focused_surface) {
|
||||
sx = cursor->x - c->geom.x - c->bw;
|
||||
sy = cursor->y - c->geom.y - c->bw;
|
||||
if (wlr_region_confine(&active_constraint->region, sx, sy, sx + dx,
|
||||
sy + dy, &sx_confined, &sy_confined)) {
|
||||
dx = sx_confined - sx;
|
||||
dy = sy_confined - sy;
|
||||
}
|
||||
if (active_constraint && cursor_mode != CurResize && cursor_mode != CurMove) {
|
||||
toplevel_from_wlr_surface(active_constraint->surface, &c, NULL);
|
||||
if (c && active_constraint->surface == seat->pointer_state.focused_surface) {
|
||||
sx = cursor->x - c->geom.x - c->bw;
|
||||
sy = cursor->y - c->geom.y - c->bw;
|
||||
if (wlr_region_confine(&active_constraint->region, sx, sy,
|
||||
sx + dx, sy + dy, &sx_confined, &sy_confined)) {
|
||||
dx = sx_confined - sx;
|
||||
dy = sy_confined - sy;
|
||||
}
|
||||
|
||||
if (active_constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (active_constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
wlr_cursor_move(cursor, device, dx, dy);
|
||||
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
|
||||
wlr_cursor_move(cursor, device, dx, dy);
|
||||
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
|
||||
|
||||
/* Update selmon (even while dragging a window) */
|
||||
if (sloppyfocus)
|
||||
selmon = xytomon(cursor->x, cursor->y);
|
||||
}
|
||||
/* Update selmon (even while dragging a window) */
|
||||
if (sloppyfocus)
|
||||
selmon = xytomon(cursor->x, cursor->y);
|
||||
}
|
||||
|
||||
/* Update drag icon's position */
|
||||
wlr_scene_node_set_position(&drag_icon->node, cursor->x, cursor->y);
|
||||
/* Update drag icon's position */
|
||||
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 (cursor_mode == CurMove) {
|
||||
/* Move the grabbed client to the new position. */
|
||||
grabc->oldgeom = (struct wlr_box){.x = cursor->x - grabcx,
|
||||
.y = cursor->y - grabcy,
|
||||
/* If we are currently grabbing the mouse, handle and return */
|
||||
if (cursor_mode == CurMove) {
|
||||
/* Move the grabbed client to the new position. */
|
||||
grabc->oldgeom = (struct wlr_box){.x = (int)round(cursor->x) - grabcx,
|
||||
.y = (int)round(cursor->y) - grabcy,
|
||||
.width = grabc->geom.width,
|
||||
.height = grabc->geom.height};
|
||||
resize(grabc, grabc->oldgeom, 1);
|
||||
return;
|
||||
} else if (cursor_mode == CurResize) {
|
||||
resize(grabc, grabc->oldgeom, 1);
|
||||
return;
|
||||
} else if (cursor_mode == CurResize) {
|
||||
grabc->oldgeom = (struct wlr_box){.x = grabc->geom.x,
|
||||
.y = grabc->geom.y,
|
||||
.width = cursor->x - grabc->geom.x,
|
||||
.height = cursor->y - grabc->geom.y};
|
||||
resize(grabc, grabc->oldgeom, 1);
|
||||
return;
|
||||
}
|
||||
.width = (int)round(cursor->x) - grabc->geom.x,
|
||||
.height = (int)round(cursor->y) - grabc->geom.y};
|
||||
resize(grabc, grabc->oldgeom, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 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
|
||||
* off of a client or over its border. */
|
||||
if (!surface && !seat->drag)
|
||||
wlr_cursor_set_xcursor(cursor, cursor_mgr, "left_ptr");
|
||||
/* 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
|
||||
* off of a client or over its border. */
|
||||
if (!surface && !seat->drag)
|
||||
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 光标相对位置移动事件处理
|
||||
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) */
|
||||
struct wlr_pointer_motion_event *event = data;
|
||||
/* The cursor doesn't move unless we tell it to. The cursor automatically
|
||||
* handles constraining the motion to the output layout, as well as any
|
||||
* special configuration applied for the specific input device which
|
||||
* 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);
|
||||
// //扩展事件通知,没有这个鼠标移动的时候滑轮将无法使用
|
||||
// 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);
|
||||
// 鼠标左下热区判断是否触发
|
||||
void
|
||||
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) */
|
||||
struct wlr_pointer_motion_event *event = data;
|
||||
/* The cursor doesn't move unless we tell it to. The cursor automatically
|
||||
* handles constraining the motion to the output layout, as well as any
|
||||
* special configuration applied for the specific input device which
|
||||
* 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,
|
||||
event->unaccel_dx, event->unaccel_dy);
|
||||
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);
|
||||
}
|
||||
|
||||
void // 17
|
||||
requeststartdrag(struct wl_listener *listener, void *data) {
|
||||
struct wlr_seat_request_start_drag_event *event = data;
|
||||
void
|
||||
requeststartdrag(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct wlr_seat_request_start_drag_event *event = data;
|
||||
|
||||
if (wlr_seat_validate_pointer_grab_serial(seat, event->origin, event->serial))
|
||||
wlr_seat_start_pointer_drag(seat, event->drag, event->serial);
|
||||
else
|
||||
wlr_data_source_destroy(event->drag->source);
|
||||
if (wlr_seat_validate_pointer_grab_serial(seat, event->origin,
|
||||
event->serial))
|
||||
wlr_seat_start_pointer_drag(seat, event->drag, event->serial);
|
||||
else
|
||||
wlr_data_source_destroy(event->drag->source);
|
||||
}
|
||||
|
||||
void setborder_color(Client *c) {
|
||||
|
|
@ -4513,8 +4502,8 @@ setfloating(Client *c, int floating) {
|
|||
|
||||
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.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) {
|
||||
// 如果无法打开日志文件,则不处理
|
||||
return;
|
||||
|
|
|
|||
53
util.c
53
util.c
|
|
@ -3,30 +3,49 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
void die(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
void
|
||||
die(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *ecalloc(size_t nmemb, size_t size) {
|
||||
void *p;
|
||||
void *
|
||||
ecalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = calloc(nmemb, size)))
|
||||
die("calloc:");
|
||||
return p;
|
||||
if (!(p = calloc(nmemb, size)))
|
||||
die("calloc:");
|
||||
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
1
util.h
|
|
@ -2,3 +2,4 @@
|
|||
|
||||
void die(const char *fmt, ...);
|
||||
void *ecalloc(size_t nmemb, size_t size);
|
||||
int fd_set_nonblock(int fd);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue