2020-04-11 17:27:19 -05:00
|
|
|
/*
|
|
|
|
|
* See LICENSE file for copyright and license details.
|
|
|
|
|
*/
|
|
|
|
|
#include <getopt.h>
|
2022-04-05 22:07:20 -05:00
|
|
|
#include <libinput.h>
|
2020-05-02 15:24:18 -05:00
|
|
|
#include <linux/input-event-codes.h>
|
2024-06-25 11:38:01 -06:00
|
|
|
#include <math.h>
|
2020-05-02 15:24:18 -05:00
|
|
|
#include <signal.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <stdio.h>
|
2020-05-02 15:24:18 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <sys/wait.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <time.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <wayland-server-core.h>
|
|
|
|
|
#include <wlr/backend.h>
|
2022-04-05 22:07:20 -05:00
|
|
|
#include <wlr/backend/libinput.h>
|
2021-12-16 11:50:11 -06:00
|
|
|
#include <wlr/render/allocator.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <wlr/render/wlr_renderer.h>
|
2024-04-30 12:36:10 -06:00
|
|
|
#include <wlr/types/wlr_alpha_modifier_v1.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2020-05-02 15:24:18 -05:00
|
|
|
#include <wlr/types/wlr_cursor.h>
|
2023-06-27 18:21:58 -06:00
|
|
|
#include <wlr/types/wlr_cursor_shape_v1.h>
|
2020-12-10 12:56:35 +01:00
|
|
|
#include <wlr/types/wlr_data_control_v1.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <wlr/types/wlr_data_device.h>
|
2023-03-07 22:04:32 -06:00
|
|
|
#include <wlr/types/wlr_drm.h>
|
2020-08-03 11:20:12 -05:00
|
|
|
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
2023-02-08 22:25:41 -06:00
|
|
|
#include <wlr/types/wlr_fractional_scale_v1.h>
|
2020-08-22 18:09:38 +02:00
|
|
|
#include <wlr/types/wlr_gamma_control_v1.h>
|
2021-07-12 19:58:55 -05:00
|
|
|
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
2022-10-23 12:32:57 -05:00
|
|
|
#include <wlr/types/wlr_idle_notify_v1.h>
|
2022-04-05 22:07:20 -05:00
|
|
|
#include <wlr/types/wlr_input_device.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <wlr/types/wlr_keyboard.h>
|
2023-12-12 18:04:38 -07:00
|
|
|
#include <wlr/types/wlr_keyboard_group.h>
|
2022-04-05 22:07:20 -05:00
|
|
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
2023-12-01 21:35:50 -06:00
|
|
|
#include <wlr/types/wlr_linux_dmabuf_v1.h>
|
2024-06-11 11:32:50 -06:00
|
|
|
#include <wlr/types/wlr_linux_drm_syncobj_v1.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <wlr/types/wlr_output.h>
|
|
|
|
|
#include <wlr/types/wlr_output_layout.h>
|
2020-10-17 20:11:31 +02:00
|
|
|
#include <wlr/types/wlr_output_management_v1.h>
|
2024-01-17 09:45:03 +01:00
|
|
|
#include <wlr/types/wlr_output_power_management_v1.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <wlr/types/wlr_pointer.h>
|
2024-02-26 16:43:01 -05:00
|
|
|
#include <wlr/types/wlr_pointer_constraints_v1.h>
|
2021-08-02 16:33:38 +02:00
|
|
|
#include <wlr/types/wlr_presentation_time.h>
|
2020-05-09 22:45:22 -05:00
|
|
|
#include <wlr/types/wlr_primary_selection.h>
|
|
|
|
|
#include <wlr/types/wlr_primary_selection_v1.h>
|
2024-02-26 16:43:01 -05:00
|
|
|
#include <wlr/types/wlr_relative_pointer_v1.h>
|
2021-09-05 16:07:28 -05:00
|
|
|
#include <wlr/types/wlr_scene.h>
|
2022-04-05 22:07:20 -05:00
|
|
|
#include <wlr/types/wlr_screencopy_v1.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <wlr/types/wlr_seat.h>
|
2022-04-05 22:07:20 -05:00
|
|
|
#include <wlr/types/wlr_server_decoration.h>
|
2022-02-13 11:56:57 -06:00
|
|
|
#include <wlr/types/wlr_session_lock_v1.h>
|
2022-08-28 21:40:03 -05:00
|
|
|
#include <wlr/types/wlr_single_pixel_buffer_v1.h>
|
2022-01-18 11:33:56 -06:00
|
|
|
#include <wlr/types/wlr_subcompositor.h>
|
2020-08-03 11:20:12 -05:00
|
|
|
#include <wlr/types/wlr_viewporter.h>
|
2020-12-08 12:17:14 +01:00
|
|
|
#include <wlr/types/wlr_virtual_keyboard_v1.h>
|
2024-01-24 22:47:50 +01:00
|
|
|
#include <wlr/types/wlr_virtual_pointer_v1.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <wlr/types/wlr_xcursor_manager.h>
|
2021-05-22 21:18:48 -05:00
|
|
|
#include <wlr/types/wlr_xdg_activation_v1.h>
|
2020-06-04 23:36:04 -05:00
|
|
|
#include <wlr/types/wlr_xdg_decoration_v1.h>
|
2020-05-09 23:01:30 -05:00
|
|
|
#include <wlr/types/wlr_xdg_output_v1.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <wlr/types/wlr_xdg_shell.h>
|
|
|
|
|
#include <wlr/util/log.h>
|
2024-02-26 16:43:01 -05:00
|
|
|
#include <wlr/util/region.h>
|
2020-04-11 17:27:19 -05:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2020-08-10 12:50:56 -05:00
|
|
|
#ifdef XWAYLAND
|
|
|
|
|
#include <wlr/xwayland.h>
|
2023-10-09 21:35:49 -06:00
|
|
|
#include <xcb/xcb.h>
|
2022-05-17 15:31:31 -05:00
|
|
|
#include <xcb/xcb_icccm.h>
|
2020-08-10 12:50:56 -05:00
|
|
|
#endif
|
2020-04-11 17:27:19 -05:00
|
|
|
|
2022-03-15 15:52:26 -06:00
|
|
|
#include "util.h"
|
2025-08-27 17:59:12 +10:00
|
|
|
#include "lib/layers.h"
|
2020-04-11 17:27:19 -05:00
|
|
|
|
2020-04-21 14:08:33 -05:00
|
|
|
/* variables */
|
2022-02-13 11:56:57 -06:00
|
|
|
static int locked;
|
2022-09-02 17:29:41 -05:00
|
|
|
static void *exclusive_focus;
|
2020-04-23 21:16:01 -05:00
|
|
|
static struct wl_display *dpy;
|
2024-01-25 11:11:40 -06:00
|
|
|
static struct wl_event_loop *event_loop;
|
2020-04-21 14:15:19 -05:00
|
|
|
static struct wlr_backend *backend;
|
2021-09-05 16:07:28 -05:00
|
|
|
static struct wlr_scene *scene;
|
2022-06-07 00:31:58 -05:00
|
|
|
static struct wlr_scene_tree *layers[NUM_LAYERS];
|
2023-07-13 16:22:50 -05:00
|
|
|
static struct wlr_scene_tree *drag_icon;
|
2023-06-25 17:44:00 -05:00
|
|
|
/* Map from ZWLR_LAYER_SHELL_* constants to Lyr* enum */
|
2025-08-27 12:50:29 +10:00
|
|
|
static const int layermap[] = {LyrBg, LyrBottom, LyrTop, LyrOverlay};
|
2020-04-23 21:16:01 -05:00
|
|
|
static struct wlr_renderer *drw;
|
2021-12-16 11:50:11 -06:00
|
|
|
static struct wlr_allocator *alloc;
|
2020-07-22 08:35:46 +10:00
|
|
|
static struct wlr_compositor *compositor;
|
2022-11-15 23:04:39 -06:00
|
|
|
static struct wlr_session *session;
|
2020-04-21 14:15:19 -05:00
|
|
|
|
|
|
|
|
static struct wlr_xdg_shell *xdg_shell;
|
2021-05-22 21:18:48 -05:00
|
|
|
static struct wlr_xdg_activation_v1 *activation;
|
2022-12-19 21:43:15 -06:00
|
|
|
static struct wlr_xdg_decoration_manager_v1 *xdg_decoration_mgr;
|
2020-04-22 10:42:40 -05:00
|
|
|
static struct wl_list clients; /* tiling order */
|
|
|
|
|
static struct wl_list fstack; /* focus order */
|
2022-10-23 12:32:57 -05:00
|
|
|
static struct wlr_idle_notifier_v1 *idle_notifier;
|
2021-07-12 19:58:55 -05:00
|
|
|
static struct wlr_idle_inhibit_manager_v1 *idle_inhibit_mgr;
|
2020-08-24 07:04:34 +02:00
|
|
|
static struct wlr_layer_shell_v1 *layer_shell;
|
2020-10-17 20:11:31 +02:00
|
|
|
static struct wlr_output_manager_v1 *output_mgr;
|
2020-12-08 12:17:14 +01:00
|
|
|
static struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr;
|
2024-01-24 22:47:50 +01:00
|
|
|
static struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr;
|
2023-06-27 18:21:58 -06:00
|
|
|
static struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr;
|
2024-01-17 09:45:03 +01:00
|
|
|
static struct wlr_output_power_manager_v1 *power_mgr;
|
2020-04-21 14:15:19 -05:00
|
|
|
|
2024-02-26 16:43:01 -05:00
|
|
|
static struct wlr_pointer_constraints_v1 *pointer_constraints;
|
|
|
|
|
static struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr;
|
|
|
|
|
static struct wlr_pointer_constraint_v1 *active_constraint;
|
|
|
|
|
|
2020-04-21 14:15:19 -05:00
|
|
|
static struct wlr_cursor *cursor;
|
|
|
|
|
static struct wlr_xcursor_manager *cursor_mgr;
|
|
|
|
|
|
2023-12-08 08:22:57 +02:00
|
|
|
static struct wlr_scene_rect *root_bg;
|
2022-02-13 11:56:57 -06:00
|
|
|
static struct wlr_session_lock_manager_v1 *session_lock_mgr;
|
|
|
|
|
static struct wlr_scene_rect *locked_bg;
|
|
|
|
|
static struct wlr_session_lock_v1 *cur_lock;
|
|
|
|
|
|
2020-04-21 14:15:19 -05:00
|
|
|
static struct wlr_seat *seat;
|
2024-01-30 13:16:16 -06:00
|
|
|
static KeyboardGroup *kb_group;
|
2020-04-21 14:15:19 -05:00
|
|
|
static unsigned int cursor_mode;
|
2020-04-22 22:37:11 -05:00
|
|
|
static Client *grabc;
|
2020-04-30 11:33:32 -05:00
|
|
|
static int grabcx, grabcy; /* client-relative */
|
2020-04-21 14:15:19 -05:00
|
|
|
|
|
|
|
|
static struct wlr_output_layout *output_layout;
|
2020-04-26 14:08:47 -05:00
|
|
|
static struct wlr_box sgeom;
|
2020-04-21 14:47:59 -05:00
|
|
|
static struct wl_list mons;
|
2020-04-22 08:25:43 -05:00
|
|
|
static Monitor *selmon;
|
2020-04-21 14:08:33 -05:00
|
|
|
|
2025-01-19 13:43:51 -06:00
|
|
|
/* 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};
|
2025-01-19 17:24:01 -06:00
|
|
|
static struct wl_listener new_idle_inhibitor = {.notify = createidleinhibitor};
|
|
|
|
|
static struct wl_listener new_input_device = {.notify = inputdevice};
|
2025-01-19 13:43:51 -06:00
|
|
|
static struct wl_listener new_virtual_keyboard = {.notify = virtualkeyboard};
|
|
|
|
|
static struct wl_listener new_virtual_pointer = {.notify = virtualpointer};
|
2025-08-27 12:50:29 +10:00
|
|
|
static struct wl_listener new_pointer_constraint = {
|
|
|
|
|
.notify = createpointerconstraint};
|
2025-01-19 13:43:51 -06:00
|
|
|
static struct wl_listener new_output = {.notify = createmon};
|
2025-01-19 17:24:01 -06:00
|
|
|
static struct wl_listener new_xdg_toplevel = {.notify = createnotify};
|
2025-01-19 13:43:51 -06:00
|
|
|
static struct wl_listener new_xdg_popup = {.notify = createpopup};
|
|
|
|
|
static struct wl_listener new_xdg_decoration = {.notify = createdecoration};
|
2025-01-19 17:24:01 -06:00
|
|
|
static struct wl_listener new_layer_surface = {.notify = createlayersurface};
|
2025-01-19 13:43:51 -06:00
|
|
|
static struct wl_listener output_mgr_apply = {.notify = outputmgrapply};
|
|
|
|
|
static struct wl_listener output_mgr_test = {.notify = outputmgrtest};
|
2025-08-27 12:50:29 +10:00
|
|
|
static struct wl_listener output_power_mgr_set_mode = {.notify =
|
|
|
|
|
powermgrsetmode};
|
2025-01-19 13:43:51 -06:00
|
|
|
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};
|
2025-01-19 17:24:01 -06:00
|
|
|
static struct wl_listener request_set_cursor_shape = {.notify = setcursorshape};
|
2025-01-19 13:43:51 -06:00
|
|
|
static struct wl_listener request_start_drag = {.notify = requeststartdrag};
|
|
|
|
|
static struct wl_listener start_drag = {.notify = startdrag};
|
2025-01-19 17:24:01 -06:00
|
|
|
static struct wl_listener new_session_lock = {.notify = locksession};
|
2025-01-19 13:43:51 -06:00
|
|
|
|
2020-04-23 22:20:44 -05:00
|
|
|
/* configuration, allows nested code to access above variables */
|
2020-04-11 17:27:19 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2020-12-25 01:33:55 -05:00
|
|
|
/* attempt to encapsulate suck into one file */
|
|
|
|
|
#include "client.h"
|
|
|
|
|
|
2020-05-03 00:48:12 -05:00
|
|
|
/* function implementations */
|
2025-08-27 12:50:29 +10:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
char *startup_cmd = NULL;
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
while ((c = getopt(argc, argv, "s:hdv")) != -1) {
|
|
|
|
|
if (c == 's')
|
|
|
|
|
startup_cmd = optarg;
|
|
|
|
|
else if (c == 'd')
|
|
|
|
|
log_level = WLR_DEBUG;
|
|
|
|
|
else if (c == 'v')
|
|
|
|
|
die("dwl " VERSION);
|
|
|
|
|
else
|
|
|
|
|
goto usage;
|
|
|
|
|
}
|
|
|
|
|
if (optind < argc)
|
|
|
|
|
goto usage;
|
|
|
|
|
|
|
|
|
|
/* Wayland requires XDG_RUNTIME_DIR for creating its communications socket */
|
|
|
|
|
if (!getenv("XDG_RUNTIME_DIR"))
|
|
|
|
|
die("XDG_RUNTIME_DIR must be set");
|
|
|
|
|
setup();
|
|
|
|
|
run(startup_cmd);
|
|
|
|
|
cleanup();
|
|
|
|
|
return EXIT_SUCCESS;
|
2020-06-03 15:05:12 -05:00
|
|
|
|
|
|
|
|
usage:
|
2025-08-27 12:50:29 +10:00
|
|
|
die("Usage: %s [-v] [-d] [-s startup command]", argv[0]);
|
2020-04-11 17:27:19 -05:00
|
|
|
}
|