opt: chase some thing from dwl 0.8

This commit is contained in:
DreamMaoMao 2025-03-04 13:58:41 +08:00
parent 3bfd64a881
commit 2b2d76af57
2 changed files with 326 additions and 377 deletions

273
maomao.c
View file

@ -17,17 +17,17 @@
#include <wlr/backend/libinput.h> #include <wlr/backend/libinput.h>
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_alpha_modifier_v1.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_data_control_v1.h> #include <wlr/types/wlr_data_control_v1.h>
#include <wlr/types/wlr_alpha_modifier_v1.h>
#include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/types/wlr_linux_drm_syncobj_v1.h>
#include <wlr/types/wlr_data_device.h> #include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_drm.h> #include <wlr/types/wlr_drm.h>
#include <wlr/types/wlr_export_dmabuf_v1.h> #include <wlr/types/wlr_export_dmabuf_v1.h>
#include <wlr/types/wlr_fractional_scale_v1.h> #include <wlr/types/wlr_fractional_scale_v1.h>
#include <wlr/types/wlr_gamma_control_v1.h> #include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/types/wlr_linux_drm_syncobj_v1.h>
#include <wlr/types/wlr_pointer_constraints_v1.h> #include <wlr/types/wlr_pointer_constraints_v1.h>
#include <wlr/types/wlr_relative_pointer_v1.h> #include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/util/region.h> #include <wlr/util/region.h>
@ -90,7 +90,12 @@
#define ISFULLSCREEN(A) \ #define ISFULLSCREEN(A) \
((A)->isfullscreen || (A)->ismaxmizescreen || \ ((A)->isfullscreen || (A)->ismaxmizescreen || \
(A)->overview_ismaxmizescreenbak || (A)->overview_isfullscreenbak) (A)->overview_ismaxmizescreenbak || (A)->overview_isfullscreenbak)
#define LISTEN_STATIC(E, H) do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0) #define LISTEN_STATIC(E, H) \
do { \
struct wl_listener *_l = ecalloc(1, sizeof(*_l)); \
_l->notify = (H); \
wl_signal_add((E), _l); \
} while (0)
/* enums */ /* enums */
/* enums */ /* enums */
@ -454,7 +459,6 @@ static int keybinding(uint32_t mods, xkb_keysym_t sym);
static void keypress(struct wl_listener *listener, void *data); static void keypress(struct wl_listener *listener, void *data);
static void keypressmod(struct wl_listener *listener, void *data); static void keypressmod(struct wl_listener *listener, void *data);
static void locksession(struct wl_listener *listener, void *data); static void locksession(struct wl_listener *listener, void *data);
static void maplayersurfacenotify(struct wl_listener *listener, void *data);
static void mapnotify(struct wl_listener *listener, void *data); static void mapnotify(struct wl_listener *listener, void *data);
static void maximizenotify(struct wl_listener *listener, void *data); static void maximizenotify(struct wl_listener *listener, void *data);
static void minimizenotify(struct wl_listener *listener, void *data); static void minimizenotify(struct wl_listener *listener, void *data);
@ -650,7 +654,8 @@ static struct wl_listener new_idle_inhibitor = {.notify = createidleinhibitor};
static struct wl_listener new_input_device = {.notify = inputdevice}; static struct wl_listener new_input_device = {.notify = inputdevice};
static struct wl_listener new_virtual_keyboard = {.notify = virtualkeyboard}; static struct wl_listener new_virtual_keyboard = {.notify = virtualkeyboard};
static struct wl_listener new_virtual_pointer = {.notify = virtualpointer}; static struct wl_listener new_virtual_pointer = {.notify = virtualpointer};
static struct wl_listener new_pointer_constraint = {.notify = createpointerconstraint}; static struct wl_listener new_pointer_constraint = {
.notify = createpointerconstraint};
static struct wl_listener new_output = {.notify = createmon}; static struct wl_listener new_output = {.notify = createmon};
static struct wl_listener new_xdg_toplevel = {.notify = createnotify}; static struct wl_listener new_xdg_toplevel = {.notify = createnotify};
static struct wl_listener new_xdg_popup = {.notify = createpopup}; static struct wl_listener new_xdg_popup = {.notify = createpopup};
@ -765,8 +770,8 @@ void init_baked_points(void) {
calculate_animation_curve_at((double)i / (BAKED_POINTS_COUNT - 1), TAG); calculate_animation_curve_at((double)i / (BAKED_POINTS_COUNT - 1), TAG);
} }
for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) { for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) {
baked_points_close[i] = baked_points_close[i] = calculate_animation_curve_at(
calculate_animation_curve_at((double)i / (BAKED_POINTS_COUNT - 1), CLOSE); (double)i / (BAKED_POINTS_COUNT - 1), CLOSE);
} }
} }
@ -815,17 +820,22 @@ void apply_opacity_to_rect_nodes(Client *c, struct wlr_scene_node *node,
// 划出的border剪切屏幕之外的这里底部bttome可以了左右的还不不对 // 划出的border剪切屏幕之外的这里底部bttome可以了左右的还不不对
offsetx = c->geom.width - c->animation.current.width; offsetx = c->geom.width - c->animation.current.width;
offsety = c->geom.height - c->animation.current.height; offsety = c->geom.height - c->animation.current.height;
if(node->y > c->geom.y + c->geom.height/2 ){ if (node->y > c->geom.y + c->geom.height / 2) {
wlr_scene_node_set_position(node,c->geom.x,c->geom.y + c->geom.height - offsety); wlr_scene_node_set_position(node, c->geom.x,
c->geom.y + c->geom.height - offsety);
wlr_scene_rect_set_size(rect, c->animation.current.width, c->bw); // down wlr_scene_rect_set_size(rect, c->animation.current.width, c->bw); // down
} else if(node->y < c->geom.y + c->geom.height/2 && rect->width > rect->height) { } else if (node->y < c->geom.y + c->geom.height / 2 &&
wlr_scene_node_set_position(node,c->geom.x,c->geom.y); rect->width > rect->height) {
wlr_scene_node_set_position(node, c->geom.x, c->geom.y);
wlr_scene_rect_set_size(rect, c->animation.current.width, c->bw); // up wlr_scene_rect_set_size(rect, c->animation.current.width, c->bw); // up
} else if(node->x < c->geom.x + c->geom.width/2 && rect->width < rect->height) { } else if (node->x < c->geom.x + c->geom.width / 2 &&
wlr_scene_rect_set_size(rect,c->bw,c->animation.current.height); // left rect->width < rect->height) {
wlr_scene_rect_set_size(rect, c->bw, c->animation.current.height); // left
} else { } else {
wlr_scene_node_set_position(node,c->geom.x + c->geom.width - offsetx,c->geom.y); wlr_scene_node_set_position(node, c->geom.x + c->geom.width - offsetx,
wlr_scene_rect_set_size(rect,c->bw,c->animation.current.height); // right c->geom.y);
wlr_scene_rect_set_size(rect, c->bw,
c->animation.current.height); // right
} }
} }
@ -1114,8 +1124,7 @@ bool client_draw_fadeout_frame(Client *c) {
return true; return true;
} }
void // 0.5 void applybounds(Client *c, struct wlr_box *bbox) {
applybounds(Client *c, struct wlr_box *bbox) {
/* set minimum possible */ /* set minimum possible */
c->geom.width = MAX(1 + 2 * (int)c->bw, c->geom.width); c->geom.width = MAX(1 + 2 * (int)c->bw, c->geom.width);
c->geom.height = MAX(1 + 2 * (int)c->bw, c->geom.height); c->geom.height = MAX(1 + 2 * (int)c->bw, c->geom.height);
@ -1256,9 +1265,7 @@ void toggle_scratchpad(const Arg *arg) {
} }
} }
void void gpureset(struct wl_listener *listener, void *data) {
gpureset(struct wl_listener *listener, void *data)
{
struct wlr_renderer *old_drw = drw; struct wlr_renderer *old_drw = drw;
struct wlr_allocator *old_alloc = alloc; struct wlr_allocator *old_alloc = alloc;
struct Monitor *m; struct Monitor *m;
@ -1281,7 +1288,7 @@ gpureset(struct wl_listener *listener, void *data)
wlr_renderer_destroy(old_drw); wlr_renderer_destroy(old_drw);
} }
void // 0.5 void // 0.5 custom
handlesig(int signo) { handlesig(int signo) {
if (signo == SIGCHLD) { if (signo == SIGCHLD) {
#ifdef XWAYLAND #ifdef XWAYLAND
@ -1357,7 +1364,7 @@ void lognumtofile(float num) {
system(cmd); system(cmd);
} }
int // 0.5 int // 0.5 custom
applyrulesgeom(Client *c) { applyrulesgeom(Client *c) {
/* rule matching */ /* rule matching */
const char *appid, *title; const char *appid, *title;
@ -1432,7 +1439,7 @@ applyrules(Client *c) {
} }
} }
if(!client_surface(c)->mapped) if (!client_surface(c)->mapped)
return; return;
wlr_scene_node_reparent(&c->scene->node, wlr_scene_node_reparent(&c->scene->node,
@ -1540,8 +1547,7 @@ arrange(Monitor *m, bool want_animation) {
checkidleinhibitor(NULL); checkidleinhibitor(NULL);
} }
void // 0.5 void arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area,
arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area,
int exclusive) { int exclusive) {
LayerSurface *l; LayerSurface *l;
struct wlr_box full_area = m->m; struct wlr_box full_area = m->m;
@ -1556,8 +1562,6 @@ arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area,
usable_area); usable_area);
wlr_scene_node_set_position(&l->popups->node, l->scene->node.x, wlr_scene_node_set_position(&l->popups->node, l->scene->node.x,
l->scene->node.y); l->scene->node.y);
l->geom.x = l->scene->node.x;
l->geom.y = l->scene->node.y;
} }
} }
@ -1732,8 +1736,7 @@ void focusdir(const Arg *arg) {
} }
} }
void // 0.5 void arrangelayers(Monitor *m) {
arrangelayers(Monitor *m) {
int i; int i;
struct wlr_box usable_area = m->m; struct wlr_box usable_area = m->m;
LayerSurface *l; LayerSurface *l;
@ -1947,13 +1950,9 @@ buttonpress(struct wl_listener *listener, void *data) {
event->state); event->state);
} }
void // 0.5 void chvt(const Arg *arg) { wlr_session_change_vt(session, arg->ui); }
chvt(const Arg *arg) {
wlr_session_change_vt(session, arg->ui);
}
void // 0.5 void checkidleinhibitor(struct wlr_surface *exclude) {
checkidleinhibitor(struct wlr_surface *exclude) {
int inhibited = 0, unused_lx, unused_ly; int inhibited = 0, unused_lx, unused_ly;
struct wlr_idle_inhibitor_v1 *inhibitor; struct wlr_idle_inhibitor_v1 *inhibitor;
wl_list_for_each(inhibitor, &idle_inhibit_mgr->inhibitors, link) { wl_list_for_each(inhibitor, &idle_inhibit_mgr->inhibitors, link) {
@ -1972,8 +1971,7 @@ checkidleinhibitor(struct wlr_surface *exclude) {
wlr_idle_notifier_v1_set_inhibited(idle_notifier, inhibited); wlr_idle_notifier_v1_set_inhibited(idle_notifier, inhibited);
} }
void // 0.5 void setcursorshape(struct wl_listener *listener, void *data) {
setcursorshape(struct wl_listener *listener, void *data) {
struct wlr_cursor_shape_manager_v1_request_set_shape_event *event = data; struct wlr_cursor_shape_manager_v1_request_set_shape_event *event = data;
if (cursor_mode != CurNormal && cursor_mode != CurPressed) if (cursor_mode != CurNormal && cursor_mode != CurPressed)
return; return;
@ -1985,9 +1983,7 @@ setcursorshape(struct wl_listener *listener, void *data) {
wlr_cursor_shape_v1_name(event->shape)); wlr_cursor_shape_v1_name(event->shape));
} }
void void cleanuplisteners(void) {
cleanuplisteners(void)
{
wl_list_remove(&cursor_axis.link); wl_list_remove(&cursor_axis.link);
wl_list_remove(&cursor_button.link); wl_list_remove(&cursor_button.link);
wl_list_remove(&cursor_frame.link); wl_list_remove(&cursor_frame.link);
@ -2058,7 +2054,7 @@ cleanupkeyboard(struct wl_listener *listener, void *data) {
free(kb); free(kb);
} }
void // 0.5 void // 0.5 custom
cleanupmon(struct wl_listener *listener, void *data) { cleanupmon(struct wl_listener *listener, void *data) {
Monitor *m = wl_container_of(listener, m, destroy); Monitor *m = wl_container_of(listener, m, destroy);
LayerSurface *l, *tmp; LayerSurface *l, *tmp;
@ -2083,7 +2079,7 @@ cleanupmon(struct wl_listener *listener, void *data) {
free(m); free(m);
} }
void closemon(Monitor *m) // 0.5 void closemon(Monitor *m) // 0.5 custom
{ {
/* update selmon if needed and /* update selmon if needed and
* move closed monitor's clients to the focused one */ * move closed monitor's clients to the focused one */
@ -2114,8 +2110,7 @@ void closemon(Monitor *m) // 0.5
printstatus(); printstatus();
} }
void // 0.5 void commitlayersurfacenotify(struct wl_listener *listener, void *data) {
commitlayersurfacenotify(struct wl_listener *listener, void *data) {
LayerSurface *l = wl_container_of(listener, l, surface_commit); LayerSurface *l = wl_container_of(listener, l, surface_commit);
struct wlr_layer_surface_v1 *layer_surface = l->layer_surface; struct wlr_layer_surface_v1 *layer_surface = l->layer_surface;
struct wlr_scene_tree *scene_layer = struct wlr_scene_tree *scene_layer =
@ -2123,6 +2118,8 @@ commitlayersurfacenotify(struct wl_listener *listener, void *data) {
struct wlr_layer_surface_v1_state old_state; struct wlr_layer_surface_v1_state old_state;
if (l->layer_surface->initial_commit) { if (l->layer_surface->initial_commit) {
client_set_scale(layer_surface->surface, l->mon->wlr_output->scale);
/* Temporarily set the layer's current state to pending /* Temporarily set the layer's current state to pending
* so that we can easily arrange it */ * so that we can easily arrange it */
old_state = l->layer_surface->current; old_state = l->layer_surface->current;
@ -2206,7 +2203,8 @@ void commitnotify(struct wl_listener *listener, void *data) {
client_set_scale(client_surface(c), c->mon->wlr_output->scale); client_set_scale(client_surface(c), c->mon->wlr_output->scale);
} }
setmon(c, NULL, 0); /* Make sure to reapply rules in mapnotify() */ setmon(c, NULL, 0); /* Make sure to reapply rules in mapnotify() */
wlr_xdg_toplevel_set_wm_capabilities(c->surface.xdg->toplevel, WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN); wlr_xdg_toplevel_set_wm_capabilities(
c->surface.xdg->toplevel, WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN);
wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, 0, 0); wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, 0, 0);
if (c->decoration) if (c->decoration)
requestdecorationmode(&c->set_decoration_mode, c->decoration); requestdecorationmode(&c->set_decoration_mode, c->decoration);
@ -2227,18 +2225,14 @@ void commitnotify(struct wl_listener *listener, void *data) {
// c->surface.xdg->current.configure_serial) c->configure_serial = 0; // c->surface.xdg->current.configure_serial) c->configure_serial = 0;
} }
void // 0.5 void destroydecoration(struct wl_listener *listener, void *data) {
destroydecoration(struct wl_listener *listener, void *data) {
Client *c = wl_container_of(listener, c, destroy_decoration); Client *c = wl_container_of(listener, c, destroy_decoration);
c->decoration = NULL;
wl_list_remove(&c->destroy_decoration.link); wl_list_remove(&c->destroy_decoration.link);
wl_list_remove(&c->set_decoration_mode.link); wl_list_remove(&c->set_decoration_mode.link);
motionnotify(0, NULL, 0, 0, 0, 0);
} }
void void commitpopup(struct wl_listener *listener, void *data) {
commitpopup(struct wl_listener *listener, void *data)
{
struct wlr_surface *surface = data; struct wlr_surface *surface = data;
struct wlr_xdg_popup *popup = wlr_xdg_popup_try_from_wlr_surface(surface); struct wlr_xdg_popup *popup = wlr_xdg_popup_try_from_wlr_surface(surface);
LayerSurface *l = NULL; LayerSurface *l = NULL;
@ -2252,8 +2246,8 @@ commitpopup(struct wl_listener *listener, void *data)
type = toplevel_from_wlr_surface(popup->base->surface, &c, &l); type = toplevel_from_wlr_surface(popup->base->surface, &c, &l);
if (!popup->parent || type < 0) if (!popup->parent || type < 0)
return; return;
popup->base->surface->data = wlr_scene_xdg_surface_create( popup->base->surface->data =
popup->parent->data, popup->base); wlr_scene_xdg_surface_create(popup->parent->data, popup->base);
if ((l && !l->mon) || (c && !c->mon)) if ((l && !l->mon) || (c && !c->mon))
return; return;
box = type == LayerShell ? l->mon->m : c->mon->w; box = type == LayerShell ? l->mon->m : c->mon->w;
@ -2264,21 +2258,19 @@ commitpopup(struct wl_listener *listener, void *data)
free(listener); free(listener);
} }
void void createdecoration(struct wl_listener *listener, void *data) {
createdecoration(struct wl_listener *listener, void *data)
{
struct wlr_xdg_toplevel_decoration_v1 *deco = data; struct wlr_xdg_toplevel_decoration_v1 *deco = data;
Client *c = deco->toplevel->base->data; Client *c = deco->toplevel->base->data;
c->decoration = deco; c->decoration = deco;
LISTEN(&deco->events.request_mode, &c->set_decoration_mode, requestdecorationmode); LISTEN(&deco->events.request_mode, &c->set_decoration_mode,
requestdecorationmode);
LISTEN(&deco->events.destroy, &c->destroy_decoration, destroydecoration); LISTEN(&deco->events.destroy, &c->destroy_decoration, destroydecoration);
requestdecorationmode(&c->set_decoration_mode, deco); requestdecorationmode(&c->set_decoration_mode, deco);
} }
void // 0.5 void createidleinhibitor(struct wl_listener *listener, void *data) {
createidleinhibitor(struct wl_listener *listener, void *data) {
struct wlr_idle_inhibitor_v1 *idle_inhibitor = data; struct wlr_idle_inhibitor_v1 *idle_inhibitor = data;
LISTEN_STATIC(&idle_inhibitor->events.destroy, destroyidleinhibitor); LISTEN_STATIC(&idle_inhibitor->events.destroy, destroyidleinhibitor);
@ -2331,8 +2323,7 @@ createkeyboard(struct wlr_keyboard *keyboard) {
wl_list_insert(&keyboards, &kb->link); wl_list_insert(&keyboards, &kb->link);
} }
void // 0.5 void createlayersurface(struct wl_listener *listener, void *data) {
createlayersurface(struct wl_listener *listener, void *data) {
struct wlr_layer_surface_v1 *layer_surface = data; struct wlr_layer_surface_v1 *layer_surface = data;
LayerSurface *l; LayerSurface *l;
struct wlr_surface *surface = layer_surface->surface; struct wlr_surface *surface = layer_surface->surface;
@ -2348,7 +2339,6 @@ createlayersurface(struct wl_listener *listener, void *data) {
l = layer_surface->data = ecalloc(1, sizeof(*l)); l = layer_surface->data = ecalloc(1, sizeof(*l));
l->type = LayerShell; l->type = LayerShell;
LISTEN(&surface->events.commit, &l->surface_commit, commitlayersurfacenotify); LISTEN(&surface->events.commit, &l->surface_commit, commitlayersurfacenotify);
LISTEN(&surface->events.map, &l->map, maplayersurfacenotify);
LISTEN(&surface->events.unmap, &l->unmap, unmaplayersurfacenotify); LISTEN(&surface->events.unmap, &l->unmap, unmaplayersurfacenotify);
LISTEN(&layer_surface->events.destroy, &l->destroy, LISTEN(&layer_surface->events.destroy, &l->destroy,
destroylayersurfacenotify); destroylayersurfacenotify);
@ -2366,11 +2356,9 @@ createlayersurface(struct wl_listener *listener, void *data) {
wl_list_insert(&l->mon->layers[layer_surface->pending.layer], &l->link); wl_list_insert(&l->mon->layers[layer_surface->pending.layer], &l->link);
wlr_surface_send_enter(surface, layer_surface->output); wlr_surface_send_enter(surface, layer_surface->output);
} }
void // 0.5 void createlocksurface(struct wl_listener *listener, void *data) {
createlocksurface(struct wl_listener *listener, void *data) {
SessionLock *lock = wl_container_of(listener, lock, new_surface); SessionLock *lock = wl_container_of(listener, lock, new_surface);
struct wlr_session_lock_surface_v1 *lock_surface = data; struct wlr_session_lock_surface_v1 *lock_surface = data;
Monitor *m = lock_surface->output->data; Monitor *m = lock_surface->output->data;
@ -2388,15 +2376,13 @@ createlocksurface(struct wl_listener *listener, void *data) {
client_notify_enter(lock_surface->surface, wlr_seat_get_keyboard(seat)); client_notify_enter(lock_surface->surface, wlr_seat_get_keyboard(seat));
} }
void void createmon(struct wl_listener *listener, void *data) {
createmon(struct wl_listener *listener, void *data)
{
/* This event is raised by the backend when a new output (aka a display or /* This event is raised by the backend when a new output (aka a display or
* monitor) becomes available. */ * monitor) becomes available. */
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
const ConfigMonitorRule *r; const ConfigMonitorRule *r;
size_t i; size_t i;
int ji,jk; int ji, jk;
struct wlr_output_state state; struct wlr_output_state state;
Monitor *m; Monitor *m;
@ -2499,8 +2485,8 @@ createmon(struct wl_listener *listener, void *data)
* *
*/ */
/* updatemons() will resize and set correct position */ /* updatemons() will resize and set correct position */
// m->fullscreen_bg = wlr_scene_rect_create(layers[LyrFS], 0, 0, fullscreen_bg); // m->fullscreen_bg = wlr_scene_rect_create(layers[LyrFS], 0, 0,
// wlr_scene_node_set_enabled(&m->fullscreen_bg->node, 0); // fullscreen_bg); wlr_scene_node_set_enabled(&m->fullscreen_bg->node, 0);
/* Adds this to the output layout in the order it was configured. /* Adds this to the output layout in the order it was configured.
* *
@ -2534,15 +2520,14 @@ createnotify(struct wl_listener *listener, void *data) {
LISTEN(&toplevel->base->surface->events.map, &c->map, mapnotify); LISTEN(&toplevel->base->surface->events.map, &c->map, mapnotify);
LISTEN(&toplevel->base->surface->events.unmap, &c->unmap, unmapnotify); LISTEN(&toplevel->base->surface->events.unmap, &c->unmap, unmapnotify);
LISTEN(&toplevel->events.destroy, &c->destroy, destroynotify); LISTEN(&toplevel->events.destroy, &c->destroy, destroynotify);
LISTEN(&toplevel->events.request_fullscreen, &c->fullscreen, fullscreennotify); LISTEN(&toplevel->events.request_fullscreen, &c->fullscreen,
fullscreennotify);
LISTEN(&toplevel->events.request_maximize, &c->maximize, maximizenotify); LISTEN(&toplevel->events.request_maximize, &c->maximize, maximizenotify);
LISTEN(&toplevel->events.request_maximize, &c->minimize, minimizenotify); LISTEN(&toplevel->events.request_maximize, &c->minimize, minimizenotify);
LISTEN(&toplevel->events.set_title, &c->set_title, updatetitle); LISTEN(&toplevel->events.set_title, &c->set_title, updatetitle);
} }
void // 0.5 void createpointer(struct wlr_pointer *pointer) {
createpointer(struct wlr_pointer *pointer) {
struct libinput_device *device; struct libinput_device *device;
if (wlr_input_device_is_libinput(&pointer->base) && if (wlr_input_device_is_libinput(&pointer->base) &&
(device = wlr_libinput_get_device_handle(&pointer->base))) { (device = wlr_libinput_get_device_handle(&pointer->base))) {
@ -2588,8 +2573,7 @@ createpointer(struct wlr_pointer *pointer) {
wlr_cursor_attach_input_device(cursor, &pointer->base); wlr_cursor_attach_input_device(cursor, &pointer->base);
} }
void // 0.5 void createpointerconstraint(struct wl_listener *listener, void *data) {
createpointerconstraint(struct wl_listener *listener, void *data) {
PointerConstraint *pointer_constraint = PointerConstraint *pointer_constraint =
ecalloc(1, sizeof(*pointer_constraint)); ecalloc(1, sizeof(*pointer_constraint));
pointer_constraint->constraint = data; pointer_constraint->constraint = data;
@ -2597,17 +2581,14 @@ createpointerconstraint(struct wl_listener *listener, void *data) {
&pointer_constraint->destroy, destroypointerconstraint); &pointer_constraint->destroy, destroypointerconstraint);
} }
void void createpopup(struct wl_listener *listener, void *data) {
createpopup(struct wl_listener *listener, void *data)
{
/* This event is raised when a client (either xdg-shell or layer-shell) /* This event is raised when a client (either xdg-shell or layer-shell)
* creates a new popup. */ * creates a new popup. */
struct wlr_xdg_popup *popup = data; struct wlr_xdg_popup *popup = data;
LISTEN_STATIC(&popup->base->surface->events.commit, commitpopup); LISTEN_STATIC(&popup->base->surface->events.commit, commitpopup);
} }
void // 0.5 void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint) {
cursorconstrain(struct wlr_pointer_constraint_v1 *constraint) {
if (active_constraint == constraint) if (active_constraint == constraint)
return; return;
@ -2618,8 +2599,7 @@ cursorconstrain(struct wlr_pointer_constraint_v1 *constraint) {
wlr_pointer_constraint_v1_send_activated(constraint); wlr_pointer_constraint_v1_send_activated(constraint);
} }
void // 0.5 void cursorframe(struct wl_listener *listener, void *data) {
cursorframe(struct wl_listener *listener, void *data) {
/* This event is forwarded by the cursor when a pointer emits an frame /* This event is forwarded by the cursor when a pointer emits an frame
* event. Frame events are sent after regular pointer events to group * event. Frame events are sent after regular pointer events to group
* multiple events together. For instance, two axis events may happen at the * multiple events together. For instance, two axis events may happen at the
@ -2628,17 +2608,13 @@ cursorframe(struct wl_listener *listener, void *data) {
wlr_seat_pointer_notify_frame(seat); wlr_seat_pointer_notify_frame(seat);
} }
void // 0.5 void cursorwarptohint(void) {
cursorwarptohint(void) {
Client *c = NULL; Client *c = NULL;
double sx = active_constraint->current.cursor_hint.x; double sx = active_constraint->current.cursor_hint.x;
double sy = active_constraint->current.cursor_hint.y; double sy = active_constraint->current.cursor_hint.y;
toplevel_from_wlr_surface(active_constraint->surface, &c, NULL); toplevel_from_wlr_surface(active_constraint->surface, &c, NULL);
/* TODO: wlroots 0.18: if (c && active_constraint->current.cursor_hint.enabled) {
* https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4478 */
if (c && (active_constraint->current.committed &
WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT)) {
wlr_cursor_warp(cursor, NULL, sx + c->geom.x + c->bw, wlr_cursor_warp(cursor, NULL, sx + c->geom.x + c->bw,
sy + c->geom.y + c->bw); sy + c->geom.y + c->bw);
wlr_seat_pointer_warp(active_constraint->seat, sx, sy); wlr_seat_pointer_warp(active_constraint->seat, sx, sy);
@ -2647,8 +2623,7 @@ cursorwarptohint(void) {
void defaultgaps(const Arg *arg) { setgaps(gappoh, gappov, gappih, gappiv); } void defaultgaps(const Arg *arg) { setgaps(gappoh, gappov, gappih, gappiv); }
void // 0.5 void destroydragicon(struct wl_listener *listener, void *data) {
destroydragicon(struct wl_listener *listener, void *data) {
/* Focus enter isn't sent during drag, so refocus the focused node. */ /* Focus enter isn't sent during drag, so refocus the focused node. */
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
motionnotify(0, NULL, 0, 0, 0, 0); motionnotify(0, NULL, 0, 0, 0, 0);
@ -2656,9 +2631,7 @@ destroydragicon(struct wl_listener *listener, void *data) {
free(listener); free(listener);
} }
void void destroyidleinhibitor(struct wl_listener *listener, void *data) {
destroyidleinhibitor(struct wl_listener *listener, void *data)
{
/* `data` is the wlr_surface of the idle inhibitor being destroyed, /* `data` is the wlr_surface of the idle inhibitor being destroyed,
* at this point the idle inhibitor is still in the list of the manager */ * at this point the idle inhibitor is still in the list of the manager */
checkidleinhibitor(wlr_surface_get_root_surface(data)); checkidleinhibitor(wlr_surface_get_root_surface(data));
@ -2666,13 +2639,11 @@ destroyidleinhibitor(struct wl_listener *listener, void *data)
free(listener); free(listener);
} }
void // 0.5 void destroylayersurfacenotify(struct wl_listener *listener, void *data) {
destroylayersurfacenotify(struct wl_listener *listener, void *data) {
LayerSurface *l = wl_container_of(listener, l, destroy); LayerSurface *l = wl_container_of(listener, l, destroy);
wl_list_remove(&l->link); wl_list_remove(&l->link);
wl_list_remove(&l->destroy.link); wl_list_remove(&l->destroy.link);
wl_list_remove(&l->map.link);
wl_list_remove(&l->unmap.link); wl_list_remove(&l->unmap.link);
wl_list_remove(&l->surface_commit.link); wl_list_remove(&l->surface_commit.link);
wlr_scene_node_destroy(&l->scene->node); wlr_scene_node_destroy(&l->scene->node);
@ -2680,8 +2651,7 @@ destroylayersurfacenotify(struct wl_listener *listener, void *data) {
free(l); free(l);
} }
void // 0.5 void destroylock(SessionLock *lock, int unlock) {
destroylock(SessionLock *lock, int unlock) {
wlr_seat_keyboard_notify_clear_focus(seat); wlr_seat_keyboard_notify_clear_focus(seat);
if ((locked = !unlock)) if ((locked = !unlock))
goto destroy; goto destroy;
@ -2701,8 +2671,7 @@ destroy:
free(lock); free(lock);
} }
void // 0.5 void destroylocksurface(struct wl_listener *listener, void *data) {
destroylocksurface(struct wl_listener *listener, void *data) {
Monitor *m = wl_container_of(listener, m, destroy_lock_surface); Monitor *m = wl_container_of(listener, m, destroy_lock_surface);
struct wlr_session_lock_surface_v1 *surface, *lock_surface = m->lock_surface; struct wlr_session_lock_surface_v1 *surface, *lock_surface = m->lock_surface;
@ -2722,7 +2691,7 @@ destroylocksurface(struct wl_listener *listener, void *data) {
} }
} }
void // 0.5 void // 0.7 custom
destroynotify(struct wl_listener *listener, void *data) { destroynotify(struct wl_listener *listener, void *data) {
/* Called when the xdg_toplevel is destroyed. */ /* Called when the xdg_toplevel is destroyed. */
Client *c = wl_container_of(listener, c, destroy); Client *c = wl_container_of(listener, c, destroy);
@ -2748,8 +2717,7 @@ destroynotify(struct wl_listener *listener, void *data) {
free(c); free(c);
} }
void // 0.5 void destroypointerconstraint(struct wl_listener *listener, void *data) {
destroypointerconstraint(struct wl_listener *listener, void *data) {
PointerConstraint *pointer_constraint = PointerConstraint *pointer_constraint =
wl_container_of(listener, pointer_constraint, destroy); wl_container_of(listener, pointer_constraint, destroy);
@ -2762,11 +2730,9 @@ destroypointerconstraint(struct wl_listener *listener, void *data) {
free(pointer_constraint); free(pointer_constraint);
} }
void // 0.5 void destroysessionlock(struct wl_listener *listener, void *data) {
destroysessionlock(struct wl_listener *listener, void *data) {
SessionLock *lock = wl_container_of(listener, lock, destroy); SessionLock *lock = wl_container_of(listener, lock, destroy);
destroylock(lock, 0); destroylock(lock, 0);
motionnotify(0, NULL, 0, 0, 0, 0);
} }
void // 17 void // 17
@ -2784,8 +2750,7 @@ dissociatex11(struct wl_listener *listener, void *data) {
wl_list_remove(&c->unmap.link); wl_list_remove(&c->unmap.link);
} }
Monitor * // 0.5 Monitor *dirtomon(enum wlr_direction dir) {
dirtomon(enum wlr_direction dir) {
struct wlr_output *next; struct wlr_output *next;
if (!wlr_output_layout_get(output_layout, selmon->wlr_output)) if (!wlr_output_layout_get(output_layout, selmon->wlr_output))
return selmon; return selmon;
@ -2891,12 +2856,13 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
// numclients++; // numclients++;
// } // }
// zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients, // zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state,
// numclients,
// focused_client); // focused_client);
// } // }
// } // }
for ( tag = 0 ; tag < LENGTH(tags); tag++) { for (tag = 0; tag < LENGTH(tags); tag++) {
numclients = state = focused_client = 0; numclients = state = focused_client = 0;
tagmask = 1 << tag; tagmask = 1 << tag;
if ((tagmask & monitor->tagset[monitor->seltags]) != 0) if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
@ -2912,8 +2878,8 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT; state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT;
numclients++; numclients++;
} }
zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients,
numclients, focused_client); focused_client);
} }
title = focused ? client_get_title(focused) : ""; title = focused ? client_get_title(focused) : "";
@ -3111,17 +3077,13 @@ void focusclient(Client *c, int lift) {
client_activate_surface(client_surface(c), 1); client_activate_surface(client_surface(c), 1);
} }
void // 0.5 void focusmon(const Arg *arg) {
focusmon(const Arg *arg) {
int i = 0, nmons = wl_list_length(&mons); int i = 0, nmons = wl_list_length(&mons);
if (nmons) { if (nmons) {
do /* don't switch to disabled mons */ do /* don't switch to disabled mons */
selmon = dirtomon(arg->i); selmon = dirtomon(arg->i);
while (!selmon->wlr_output->enabled && i++ < nmons); while (!selmon->wlr_output->enabled && i++ < nmons);
if (!selmon->wlr_output->enabled)
selmon = NULL;
} }
warp_cursor_to_selmon(selmon);
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
} }
@ -3504,9 +3466,7 @@ void killclient(const Arg *arg) {
} }
} }
void void locksession(struct wl_listener *listener, void *data) {
locksession(struct wl_listener *listener, void *data)
{
struct wlr_session_lock_v1 *session_lock = data; struct wlr_session_lock_v1 *session_lock = data;
SessionLock *lock; SessionLock *lock;
wlr_scene_node_set_enabled(&locked_bg->node, 1); wlr_scene_node_set_enabled(&locked_bg->node, 1);
@ -3521,18 +3481,14 @@ locksession(struct wl_listener *listener, void *data)
cur_lock = lock->lock = session_lock; cur_lock = lock->lock = session_lock;
locked = 1; locked = 1;
LISTEN(&session_lock->events.new_surface, &lock->new_surface, createlocksurface); LISTEN(&session_lock->events.new_surface, &lock->new_surface,
createlocksurface);
LISTEN(&session_lock->events.destroy, &lock->destroy, destroysessionlock); LISTEN(&session_lock->events.destroy, &lock->destroy, destroysessionlock);
LISTEN(&session_lock->events.unlock, &lock->unlock, unlocksession); LISTEN(&session_lock->events.unlock, &lock->unlock, unlocksession);
wlr_session_lock_v1_send_locked(session_lock); wlr_session_lock_v1_send_locked(session_lock);
} }
void // 0.5
maplayersurfacenotify(struct wl_listener *listener, void *data) {
motionnotify(0, NULL, 0, 0, 0, 0);
}
void // old fix to 0.5 void // old fix to 0.5
mapnotify(struct wl_listener *listener, void *data) { mapnotify(struct wl_listener *listener, void *data) {
/* Called when the surface is mapped, or ready to display on-screen. */ /* Called when the surface is mapped, or ready to display on-screen. */
@ -3650,7 +3606,7 @@ mapnotify(struct wl_listener *listener, void *data) {
printstatus(); printstatus();
} }
void // 0.5 void // 0.5 custom
maximizenotify(struct wl_listener *listener, void *data) { maximizenotify(struct wl_listener *listener, void *data) {
/* This event is raised when a client would like to maximize itself, /* This event is raised when a client would like to maximize itself,
* typically because the user clicked on the maximize button on * typically because the user clicked on the maximize button on
@ -3699,7 +3655,7 @@ void set_minized(Client *c) {
wl_list_insert(clients.prev, &c->link); // 插入尾部 wl_list_insert(clients.prev, &c->link); // 插入尾部
} }
void // 0.5 void // 0.5 custom
minimizenotify(struct wl_listener *listener, void *data) { minimizenotify(struct wl_listener *listener, void *data) {
/* This event is raised when a client would like to maximize itself, /* This event is raised when a client would like to maximize itself,
* typically because the user clicked on the maximize button on * typically because the user clicked on the maximize button on
@ -3738,8 +3694,7 @@ 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 // 0.5 void motionabsolute(struct wl_listener *listener, void *data) {
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
@ -3903,13 +3858,12 @@ moveresize(const Arg *arg) {
} }
} }
void // 0.5 void outputmgrapply(struct wl_listener *listener, void *data) {
outputmgrapply(struct wl_listener *listener, void *data) {
struct wlr_output_configuration_v1 *config = data; struct wlr_output_configuration_v1 *config = data;
outputmgrapplyortest(config, 0); outputmgrapplyortest(config, 0);
} }
void // 0.5 void // 0.7 custom
outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test) { outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test) {
/* /*
* Called when a client such as wlr-randr requests a change in output * Called when a client such as wlr-randr requests a change in output
@ -3964,12 +3918,11 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test) {
wlr_output_configuration_v1_send_failed(config); wlr_output_configuration_v1_send_failed(config);
wlr_output_configuration_v1_destroy(config); wlr_output_configuration_v1_destroy(config);
/* TODO: use a wrapper function? */ /* https://codeberg.org/dwl/dwl/issues/577 */
updatemons(NULL, NULL); updatemons(NULL, NULL);
} }
void // 0.5 void outputmgrtest(struct wl_listener *listener, void *data) {
outputmgrtest(struct wl_listener *listener, void *data) {
struct wlr_output_configuration_v1 *config = data; struct wlr_output_configuration_v1 *config = data;
outputmgrapplyortest(config, 1); outputmgrapplyortest(config, 1);
} }
@ -4019,7 +3972,7 @@ printstatus(void) {
} }
} }
void // 0.5 void // 0.5 custom
quit(const Arg *arg) { quit(const Arg *arg) {
wl_display_terminate(dpy); wl_display_terminate(dpy);
free_config(); free_config();
@ -4117,13 +4070,11 @@ void rendermon(struct wl_listener *listener, void *data) {
} }
} }
void void requestdecorationmode(struct wl_listener *listener, void *data) {
requestdecorationmode(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, set_decoration_mode); Client *c = wl_container_of(listener, c, set_decoration_mode);
if (c->surface.xdg->initialized) if (c->surface.xdg->initialized)
wlr_xdg_toplevel_decoration_v1_set_mode(c->decoration, wlr_xdg_toplevel_decoration_v1_set_mode(
WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); c->decoration, WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
} }
void // 17 void // 17
@ -4470,7 +4421,7 @@ void setcursor(struct wl_listener *listener, void *data) {
} }
} }
void // 0.5 void // 0.5 custom
setfloating(Client *c, int floating) { setfloating(Client *c, int floating) {
Client *fc; Client *fc;
@ -4706,8 +4657,7 @@ void setsmfact(const Arg *arg) {
arrange(selmon, false); arrange(selmon, false);
} }
void // 0.5 void setmon(Client *c, Monitor *m, uint32_t newtags) {
setmon(Client *c, Monitor *m, uint32_t newtags) {
Monitor *oldmon = c->mon; Monitor *oldmon = c->mon;
if (oldmon == m) if (oldmon == m)
@ -4939,8 +4889,8 @@ void setup(void) {
scene, wlr_linux_dmabuf_v1_create_with_renderer(dpy, 5, drw)); scene, wlr_linux_dmabuf_v1_create_with_renderer(dpy, 5, drw));
} }
if ((drm_fd = wlr_renderer_get_drm_fd(drw)) >= 0 && drw->features.timeline if ((drm_fd = wlr_renderer_get_drm_fd(drw)) >= 0 && drw->features.timeline &&
&& backend->features.timeline) backend->features.timeline)
wlr_linux_drm_syncobj_manager_v1_create(dpy, 1, drm_fd); wlr_linux_drm_syncobj_manager_v1_create(dpy, 1, drm_fd);
/* Create a default allocator */ /* Create a default allocator */
@ -4999,7 +4949,6 @@ void setup(void) {
idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy); idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy);
wl_signal_add(&idle_inhibit_mgr->events.new_inhibitor, &new_idle_inhibitor); wl_signal_add(&idle_inhibit_mgr->events.new_inhibitor, &new_idle_inhibitor);
layer_shell = wlr_layer_shell_v1_create(dpy, 3); layer_shell = wlr_layer_shell_v1_create(dpy, 3);
wl_signal_add(&layer_shell->events.new_surface, &new_layer_surface); wl_signal_add(&layer_shell->events.new_surface, &new_layer_surface);
@ -5019,10 +4968,12 @@ void setup(void) {
wlr_server_decoration_manager_create(dpy), wlr_server_decoration_manager_create(dpy),
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
xdg_decoration_mgr = wlr_xdg_decoration_manager_v1_create(dpy); xdg_decoration_mgr = wlr_xdg_decoration_manager_v1_create(dpy);
wl_signal_add(&xdg_decoration_mgr->events.new_toplevel_decoration, &new_xdg_decoration); wl_signal_add(&xdg_decoration_mgr->events.new_toplevel_decoration,
&new_xdg_decoration);
pointer_constraints = wlr_pointer_constraints_v1_create(dpy); pointer_constraints = wlr_pointer_constraints_v1_create(dpy);
wl_signal_add(&pointer_constraints->events.new_constraint, &new_pointer_constraint); wl_signal_add(&pointer_constraints->events.new_constraint,
&new_pointer_constraint);
relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy); relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy);
@ -5061,7 +5012,8 @@ void setup(void) {
// 这两句代码会造成obs窗口里的鼠标光标消失,不知道注释有什么影响 // 这两句代码会造成obs窗口里的鼠标光标消失,不知道注释有什么影响
cursor_shape_mgr = wlr_cursor_shape_manager_v1_create(dpy, 1); cursor_shape_mgr = wlr_cursor_shape_manager_v1_create(dpy, 1);
wl_signal_add(&cursor_shape_mgr->events.request_set_shape, &request_set_cursor_shape); wl_signal_add(&cursor_shape_mgr->events.request_set_shape,
&request_set_cursor_shape);
/* /*
* Configures a seat, which is a single "seat" at which a user sits and * Configures a seat, which is a single "seat" at which a user sits and
@ -5266,8 +5218,7 @@ void fibonacci(Monitor *mon, int s) {
if (i % 2) { if (i % 2) {
if (i == 1) { if (i == 1) {
nh = nh * c->mon->pertag->smfacts[selmon->pertag->curtag]; nh = nh * c->mon->pertag->smfacts[selmon->pertag->curtag];
} } else
else
nh /= 2; nh /= 2;
} else } else
nw /= 2; nw /= 2;
@ -5856,14 +5807,12 @@ void toggleview(const Arg *arg) {
printstatus(); printstatus();
} }
void // 0.5 void unlocksession(struct wl_listener *listener, void *data) {
unlocksession(struct wl_listener *listener, void *data) {
SessionLock *lock = wl_container_of(listener, lock, unlock); SessionLock *lock = wl_container_of(listener, lock, unlock);
destroylock(lock, 1); destroylock(lock, 1);
} }
void // 0.5 void unmaplayersurfacenotify(struct wl_listener *listener, void *data) {
unmaplayersurfacenotify(struct wl_listener *listener, void *data) {
LayerSurface *l = wl_container_of(listener, l, unmap); LayerSurface *l = wl_container_of(listener, l, unmap);
l->mapped = 0; l->mapped = 0;
@ -5991,7 +5940,7 @@ void unmapnotify(struct wl_listener *listener, void *data) {
motionnotify(0, NULL, 0, 0, 0, 0); motionnotify(0, NULL, 0, 0, 0, 0);
} }
void // 0.5 void // 0.5 custom
updatemons(struct wl_listener *listener, void *data) { updatemons(struct wl_listener *listener, void *data) {
/* /*
* Called whenever the output layout changes: adding or removing a * Called whenever the output layout changes: adding or removing a