Compare commits

..

No commits in common. "d1c2f434983562bd7d2ace15ab0c05155be603bc" and "0925fe956aeddb983875f0fd892e9049e2d8cb76" have entirely different histories.

151
dwl.c
View File

@ -252,7 +252,6 @@ static void chvt(const Arg *arg);
static void checkidleinhibitor(struct wlr_surface *exclude); static void checkidleinhibitor(struct wlr_surface *exclude);
static void cleanup(void); static void cleanup(void);
static void cleanupmon(struct wl_listener *listener, void *data); static void cleanupmon(struct wl_listener *listener, void *data);
static void cleanuplisteners(void);
static void closemon(Monitor *m); static void closemon(Monitor *m);
static void commitlayersurfacenotify(struct wl_listener *listener, void *data); static void commitlayersurfacenotify(struct wl_listener *listener, void *data);
static void commitnotify(struct wl_listener *listener, void *data); static void commitnotify(struct wl_listener *listener, void *data);
@ -280,6 +279,7 @@ static void destroylocksurface(struct wl_listener *listener, void *data);
static void destroynotify(struct wl_listener *listener, void *data); static void destroynotify(struct wl_listener *listener, void *data);
static void destroypointerconstraint(struct wl_listener *listener, void *data); static void destroypointerconstraint(struct wl_listener *listener, void *data);
static void destroysessionlock(struct wl_listener *listener, void *data); static void destroysessionlock(struct wl_listener *listener, void *data);
static void destroysessionmgr(struct wl_listener *listener, void *data);
static void destroykeyboardgroup(struct wl_listener *listener, void *data); static void destroykeyboardgroup(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir); static Monitor *dirtomon(enum wlr_direction dir);
static void focusclient(Client *c, int lift); static void focusclient(Client *c, int lift);
@ -394,6 +394,7 @@ static struct wlr_scene_rect *root_bg;
static struct wlr_session_lock_manager_v1 *session_lock_mgr; static struct wlr_session_lock_manager_v1 *session_lock_mgr;
static struct wlr_scene_rect *locked_bg; static struct wlr_scene_rect *locked_bg;
static struct wlr_session_lock_v1 *cur_lock; static struct wlr_session_lock_v1 *cur_lock;
static struct wl_listener lock_listener = {.notify = locksession};
static struct wlr_seat *seat; static struct wlr_seat *seat;
static KeyboardGroup *kb_group; static KeyboardGroup *kb_group;
@ -406,36 +407,6 @@ static struct wlr_box sgeom;
static struct wl_list mons; static struct wl_list mons;
static Monitor *selmon; static Monitor *selmon;
/* global event handlers */
static struct wl_listener cursor_axis = {.notify = axisnotify};
static struct wl_listener cursor_button = {.notify = buttonpress};
static struct wl_listener cursor_frame = {.notify = cursorframe};
static struct wl_listener cursor_motion = {.notify = motionrelative};
static struct wl_listener cursor_motion_absolute = {.notify = motionabsolute};
static struct wl_listener gpu_reset = {.notify = gpureset};
static struct wl_listener layout_change = {.notify = updatemons};
static struct wl_listener new_idle_inhibitor = {.notify = createidleinhibitor};
static struct wl_listener new_input_device = {.notify = inputdevice};
static struct wl_listener new_virtual_keyboard = {.notify = virtualkeyboard};
static struct wl_listener new_virtual_pointer = {.notify = virtualpointer};
static struct wl_listener new_pointer_constraint = {.notify = createpointerconstraint};
static struct wl_listener new_output = {.notify = createmon};
static struct wl_listener new_xdg_toplevel = {.notify = createnotify};
static struct wl_listener new_xdg_popup = {.notify = createpopup};
static struct wl_listener new_xdg_decoration = {.notify = createdecoration};
static struct wl_listener new_layer_surface = {.notify = createlayersurface};
static struct wl_listener output_mgr_apply = {.notify = outputmgrapply};
static struct wl_listener output_mgr_test = {.notify = outputmgrtest};
static struct wl_listener output_power_mgr_set_mode = {.notify = powermgrsetmode};
static struct wl_listener request_activate = {.notify = urgent};
static struct wl_listener request_cursor = {.notify = setcursor};
static struct wl_listener request_set_psel = {.notify = setpsel};
static struct wl_listener request_set_sel = {.notify = setsel};
static struct wl_listener request_set_cursor_shape = {.notify = setcursorshape};
static struct wl_listener request_start_drag = {.notify = requeststartdrag};
static struct wl_listener start_drag = {.notify = startdrag};
static struct wl_listener new_session_lock = {.notify = locksession};
#ifdef XWAYLAND #ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data); static void activatex11(struct wl_listener *listener, void *data);
static void associatex11(struct wl_listener *listener, void *data); static void associatex11(struct wl_listener *listener, void *data);
@ -444,8 +415,6 @@ static void createnotifyx11(struct wl_listener *listener, void *data);
static void dissociatex11(struct wl_listener *listener, void *data); static void dissociatex11(struct wl_listener *listener, void *data);
static void sethints(struct wl_listener *listener, void *data); static void sethints(struct wl_listener *listener, void *data);
static void xwaylandready(struct wl_listener *listener, void *data); static void xwaylandready(struct wl_listener *listener, void *data);
static struct wl_listener new_xwayland_surface = {.notify = createnotifyx11};
static struct wl_listener xwayland_ready = {.notify = xwaylandready};
static struct wlr_xwayland *xwayland; static struct wlr_xwayland *xwayland;
#endif #endif
@ -695,7 +664,6 @@ checkidleinhibitor(struct wlr_surface *exclude)
void void
cleanup(void) cleanup(void)
{ {
cleanuplisteners();
#ifdef XWAYLAND #ifdef XWAYLAND
wlr_xwayland_destroy(xwayland); wlr_xwayland_destroy(xwayland);
xwayland = NULL; xwayland = NULL;
@ -745,43 +713,6 @@ cleanupmon(struct wl_listener *listener, void *data)
free(m); free(m);
} }
void
cleanuplisteners(void)
{
wl_list_remove(&cursor_axis.link);
wl_list_remove(&cursor_button.link);
wl_list_remove(&cursor_frame.link);
wl_list_remove(&cursor_motion.link);
wl_list_remove(&cursor_motion_absolute.link);
wl_list_remove(&gpu_reset.link);
wl_list_remove(&new_idle_inhibitor.link);
wl_list_remove(&layout_change.link);
wl_list_remove(&new_input_device.link);
wl_list_remove(&new_virtual_keyboard.link);
wl_list_remove(&new_virtual_pointer.link);
wl_list_remove(&new_pointer_constraint.link);
wl_list_remove(&new_output.link);
wl_list_remove(&new_xdg_toplevel.link);
wl_list_remove(&new_xdg_decoration.link);
wl_list_remove(&new_xdg_popup.link);
wl_list_remove(&new_layer_surface.link);
wl_list_remove(&output_mgr_apply.link);
wl_list_remove(&output_mgr_test.link);
wl_list_remove(&output_power_mgr_set_mode.link);
wl_list_remove(&request_activate.link);
wl_list_remove(&request_cursor.link);
wl_list_remove(&request_set_psel.link);
wl_list_remove(&request_set_sel.link);
wl_list_remove(&request_set_cursor_shape.link);
wl_list_remove(&request_start_drag.link);
wl_list_remove(&start_drag.link);
wl_list_remove(&new_session_lock.link);
#ifdef XWAYLAND
wl_list_remove(&new_xwayland_surface.link);
wl_list_remove(&xwayland_ready.link);
#endif
}
void void
closemon(Monitor *m) closemon(Monitor *m)
{ {
@ -1362,15 +1293,22 @@ destroysessionlock(struct wl_listener *listener, void *data)
destroylock(lock, 0); destroylock(lock, 0);
} }
void
destroysessionmgr(struct wl_listener *listener, void *data)
{
wl_list_remove(&lock_listener.link);
wl_list_remove(&listener->link);
}
void void
destroykeyboardgroup(struct wl_listener *listener, void *data) destroykeyboardgroup(struct wl_listener *listener, void *data)
{ {
KeyboardGroup *group = wl_container_of(listener, group, destroy); KeyboardGroup *group = wl_container_of(listener, group, destroy);
wl_event_source_remove(group->key_repeat_source); wl_event_source_remove(group->key_repeat_source);
wlr_keyboard_group_destroy(group->wlr_group);
wl_list_remove(&group->key.link); wl_list_remove(&group->key.link);
wl_list_remove(&group->modifiers.link); wl_list_remove(&group->modifiers.link);
wl_list_remove(&group->destroy.link); wl_list_remove(&group->destroy.link);
wlr_keyboard_group_destroy(group->wlr_group);
free(group); free(group);
} }
@ -1535,8 +1473,7 @@ gpureset(struct wl_listener *listener, void *data)
if (!(alloc = wlr_allocator_autocreate(backend, drw))) if (!(alloc = wlr_allocator_autocreate(backend, drw)))
die("couldn't recreate allocator"); die("couldn't recreate allocator");
wl_list_remove(&gpu_reset.link); LISTEN_STATIC(&drw->events.lost, gpureset);
wl_signal_add(&drw->events.lost, &gpu_reset);
wlr_compositor_set_renderer(compositor, drw); wlr_compositor_set_renderer(compositor, drw);
@ -2469,7 +2406,7 @@ setup(void)
* supports for shared memory, this configures that for clients. */ * supports for shared memory, this configures that for clients. */
if (!(drw = wlr_renderer_autocreate(backend))) if (!(drw = wlr_renderer_autocreate(backend)))
die("couldn't create renderer"); die("couldn't create renderer");
wl_signal_add(&drw->events.lost, &gpu_reset); LISTEN_STATIC(&drw->events.lost, gpureset);
/* Create shm, drm and linux_dmabuf interfaces by ourselves. /* Create shm, drm and linux_dmabuf interfaces by ourselves.
* The simplest way is call: * The simplest way is call:
@ -2516,24 +2453,23 @@ setup(void)
/* Initializes the interface used to implement urgency hints */ /* Initializes the interface used to implement urgency hints */
activation = wlr_xdg_activation_v1_create(dpy); activation = wlr_xdg_activation_v1_create(dpy);
wl_signal_add(&activation->events.request_activate, &request_activate); LISTEN_STATIC(&activation->events.request_activate, urgent);
wlr_scene_set_gamma_control_manager_v1(scene, wlr_gamma_control_manager_v1_create(dpy)); wlr_scene_set_gamma_control_manager_v1(scene, wlr_gamma_control_manager_v1_create(dpy));
power_mgr = wlr_output_power_manager_v1_create(dpy); power_mgr = wlr_output_power_manager_v1_create(dpy);
wl_signal_add(&power_mgr->events.set_mode, &output_power_mgr_set_mode); LISTEN_STATIC(&power_mgr->events.set_mode, powermgrsetmode);
/* Creates an output layout, which a wlroots utility for working with an /* Creates an output layout, which a wlroots utility for working with an
* arrangement of screens in a physical layout. */ * arrangement of screens in a physical layout. */
output_layout = wlr_output_layout_create(dpy); output_layout = wlr_output_layout_create(dpy);
wl_signal_add(&output_layout->events.change, &layout_change); LISTEN_STATIC(&output_layout->events.change, updatemons);
wlr_xdg_output_manager_v1_create(dpy, output_layout);
wlr_xdg_output_manager_v1_create(dpy, output_layout);
/* Configure a listener to be notified when new outputs are available on the /* Configure a listener to be notified when new outputs are available on the
* backend. */ * backend. */
wl_list_init(&mons); wl_list_init(&mons);
wl_signal_add(&backend->events.new_output, &new_output); LISTEN_STATIC(&backend->events.new_output, createmon);
/* Set up our client lists, the xdg-shell and the layer-shell. The xdg-shell is a /* Set up our client lists, the xdg-shell and the layer-shell. The xdg-shell is a
* Wayland protocol which is used for application windows. For more * Wayland protocol which is used for application windows. For more
@ -2545,19 +2481,20 @@ setup(void)
wl_list_init(&fstack); wl_list_init(&fstack);
xdg_shell = wlr_xdg_shell_create(dpy, 6); xdg_shell = wlr_xdg_shell_create(dpy, 6);
wl_signal_add(&xdg_shell->events.new_toplevel, &new_xdg_toplevel); LISTEN_STATIC(&xdg_shell->events.new_toplevel, createnotify);
wl_signal_add(&xdg_shell->events.new_popup, &new_xdg_popup); LISTEN_STATIC(&xdg_shell->events.new_popup, createpopup);
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); LISTEN_STATIC(&layer_shell->events.new_surface, createlayersurface);
idle_notifier = wlr_idle_notifier_v1_create(dpy); idle_notifier = wlr_idle_notifier_v1_create(dpy);
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); LISTEN_STATIC(&idle_inhibit_mgr->events.new_inhibitor, createidleinhibitor);
session_lock_mgr = wlr_session_lock_manager_v1_create(dpy); session_lock_mgr = wlr_session_lock_manager_v1_create(dpy);
wl_signal_add(&session_lock_mgr->events.new_lock, &new_session_lock); wl_signal_add(&session_lock_mgr->events.new_lock, &lock_listener);
LISTEN_STATIC(&session_lock_mgr->events.destroy, destroysessionmgr);
locked_bg = wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height, locked_bg = wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height,
(float [4]){0.1f, 0.1f, 0.1f, 1.0f}); (float [4]){0.1f, 0.1f, 0.1f, 1.0f});
wlr_scene_node_set_enabled(&locked_bg->node, 0); wlr_scene_node_set_enabled(&locked_bg->node, 0);
@ -2567,10 +2504,10 @@ 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); LISTEN_STATIC(&xdg_decoration_mgr->events.new_toplevel_decoration, createdecoration);
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); LISTEN_STATIC(&pointer_constraints->events.new_constraint, createpointerconstraint);
relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy); relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy);
@ -2598,14 +2535,14 @@ setup(void)
* *
* And more comments are sprinkled throughout the notify functions above. * And more comments are sprinkled throughout the notify functions above.
*/ */
wl_signal_add(&cursor->events.motion, &cursor_motion); LISTEN_STATIC(&cursor->events.motion, motionrelative);
wl_signal_add(&cursor->events.motion_absolute, &cursor_motion_absolute); LISTEN_STATIC(&cursor->events.motion_absolute, motionabsolute);
wl_signal_add(&cursor->events.button, &cursor_button); LISTEN_STATIC(&cursor->events.button, buttonpress);
wl_signal_add(&cursor->events.axis, &cursor_axis); LISTEN_STATIC(&cursor->events.axis, axisnotify);
wl_signal_add(&cursor->events.frame, &cursor_frame); LISTEN_STATIC(&cursor->events.frame, cursorframe);
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); LISTEN_STATIC(&cursor_shape_mgr->events.request_set_shape, setcursorshape);
/* /*
* 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
@ -2613,27 +2550,25 @@ setup(void)
* pointer, touch, and drawing tablet device. We also rig up a listener to * pointer, touch, and drawing tablet device. We also rig up a listener to
* let us know when new input devices are available on the backend. * let us know when new input devices are available on the backend.
*/ */
wl_signal_add(&backend->events.new_input, &new_input_device); LISTEN_STATIC(&backend->events.new_input, inputdevice);
virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy); virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy);
wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard, LISTEN_STATIC(&virtual_keyboard_mgr->events.new_virtual_keyboard, virtualkeyboard);
&new_virtual_keyboard);
virtual_pointer_mgr = wlr_virtual_pointer_manager_v1_create(dpy); virtual_pointer_mgr = wlr_virtual_pointer_manager_v1_create(dpy);
wl_signal_add(&virtual_pointer_mgr->events.new_virtual_pointer, LISTEN_STATIC(&virtual_pointer_mgr->events.new_virtual_pointer, virtualpointer);
&new_virtual_pointer);
seat = wlr_seat_create(dpy, "seat0"); seat = wlr_seat_create(dpy, "seat0");
wl_signal_add(&seat->events.request_set_cursor, &request_cursor); LISTEN_STATIC(&seat->events.request_set_cursor, setcursor);
wl_signal_add(&seat->events.request_set_selection, &request_set_sel); LISTEN_STATIC(&seat->events.request_set_selection, setsel);
wl_signal_add(&seat->events.request_set_primary_selection, &request_set_psel); LISTEN_STATIC(&seat->events.request_set_primary_selection, setpsel);
wl_signal_add(&seat->events.request_start_drag, &request_start_drag); LISTEN_STATIC(&seat->events.request_start_drag, requeststartdrag);
wl_signal_add(&seat->events.start_drag, &start_drag); LISTEN_STATIC(&seat->events.start_drag, startdrag);
kb_group = createkeyboardgroup(); kb_group = createkeyboardgroup();
wl_list_init(&kb_group->destroy.link); wl_list_init(&kb_group->destroy.link);
output_mgr = wlr_output_manager_v1_create(dpy); output_mgr = wlr_output_manager_v1_create(dpy);
wl_signal_add(&output_mgr->events.apply, &output_mgr_apply); LISTEN_STATIC(&output_mgr->events.apply, outputmgrapply);
wl_signal_add(&output_mgr->events.test, &output_mgr_test); LISTEN_STATIC(&output_mgr->events.test, outputmgrtest);
/* Make sure XWayland clients don't connect to the parent X server, /* Make sure XWayland clients don't connect to the parent X server,
* e.g when running in the x11 backend or the wayland backend and the * e.g when running in the x11 backend or the wayland backend and the
@ -2645,8 +2580,8 @@ setup(void)
* It will be started when the first X client is started. * It will be started when the first X client is started.
*/ */
if ((xwayland = wlr_xwayland_create(dpy, compositor, 1))) { if ((xwayland = wlr_xwayland_create(dpy, compositor, 1))) {
wl_signal_add(&xwayland->events.ready, &xwayland_ready); LISTEN_STATIC(&xwayland->events.ready, xwaylandready);
wl_signal_add(&xwayland->events.new_surface, &new_xwayland_surface); LISTEN_STATIC(&xwayland->events.new_surface, createnotifyx11);
setenv("DISPLAY", xwayland->display_name, 1); setenv("DISPLAY", xwayland->display_name, 1);
} else { } else {