193 lines
7.3 KiB
C
193 lines
7.3 KiB
C
/*
|
|
* See LICENSE file for copyright and license details.
|
|
*/
|
|
#include <getopt.h>
|
|
#include <libinput.h>
|
|
#include <linux/input-event-codes.h>
|
|
#include <math.h>
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/wait.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
#include <wayland-server-core.h>
|
|
#include <wlr/backend.h>
|
|
#include <wlr/backend/libinput.h>
|
|
#include <wlr/render/allocator.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_cursor.h>
|
|
#include <wlr/types/wlr_cursor_shape_v1.h>
|
|
#include <wlr/types/wlr_data_control_v1.h>
|
|
#include <wlr/types/wlr_data_device.h>
|
|
#include <wlr/types/wlr_drm.h>
|
|
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
|
#include <wlr/types/wlr_fractional_scale_v1.h>
|
|
#include <wlr/types/wlr_gamma_control_v1.h>
|
|
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
|
#include <wlr/types/wlr_idle_notify_v1.h>
|
|
#include <wlr/types/wlr_input_device.h>
|
|
#include <wlr/types/wlr_keyboard.h>
|
|
#include <wlr/types/wlr_keyboard_group.h>
|
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
|
#include <wlr/types/wlr_linux_dmabuf_v1.h>
|
|
#include <wlr/types/wlr_linux_drm_syncobj_v1.h>
|
|
#include <wlr/types/wlr_output.h>
|
|
#include <wlr/types/wlr_output_layout.h>
|
|
#include <wlr/types/wlr_output_management_v1.h>
|
|
#include <wlr/types/wlr_output_power_management_v1.h>
|
|
#include <wlr/types/wlr_pointer.h>
|
|
#include <wlr/types/wlr_pointer_constraints_v1.h>
|
|
#include <wlr/types/wlr_presentation_time.h>
|
|
#include <wlr/types/wlr_primary_selection.h>
|
|
#include <wlr/types/wlr_primary_selection_v1.h>
|
|
#include <wlr/types/wlr_relative_pointer_v1.h>
|
|
#include <wlr/types/wlr_scene.h>
|
|
#include <wlr/types/wlr_screencopy_v1.h>
|
|
#include <wlr/types/wlr_seat.h>
|
|
#include <wlr/types/wlr_server_decoration.h>
|
|
#include <wlr/types/wlr_session_lock_v1.h>
|
|
#include <wlr/types/wlr_single_pixel_buffer_v1.h>
|
|
#include <wlr/types/wlr_subcompositor.h>
|
|
#include <wlr/types/wlr_viewporter.h>
|
|
#include <wlr/types/wlr_virtual_keyboard_v1.h>
|
|
#include <wlr/types/wlr_virtual_pointer_v1.h>
|
|
#include <wlr/types/wlr_xcursor_manager.h>
|
|
#include <wlr/types/wlr_xdg_activation_v1.h>
|
|
#include <wlr/types/wlr_xdg_decoration_v1.h>
|
|
#include <wlr/types/wlr_xdg_output_v1.h>
|
|
#include <wlr/types/wlr_xdg_shell.h>
|
|
#include <wlr/util/log.h>
|
|
#include <wlr/util/region.h>
|
|
#include <xkbcommon/xkbcommon.h>
|
|
#ifdef XWAYLAND
|
|
#include <wlr/xwayland.h>
|
|
#include <xcb/xcb.h>
|
|
#include <xcb/xcb_icccm.h>
|
|
#endif
|
|
|
|
#include "util.h"
|
|
#include "lib/layers.h"
|
|
|
|
/* variables */
|
|
static int locked;
|
|
static void *exclusive_focus;
|
|
static struct wl_display *dpy;
|
|
static struct wl_event_loop *event_loop;
|
|
static struct wlr_backend *backend;
|
|
static struct wlr_scene *scene;
|
|
static struct wlr_scene_tree *layers[NUM_LAYERS];
|
|
static struct wlr_scene_tree *drag_icon;
|
|
/* Map from ZWLR_LAYER_SHELL_* constants to Lyr* enum */
|
|
static const int layermap[] = {LyrBg, LyrBottom, LyrTop, LyrOverlay};
|
|
static struct wlr_renderer *drw;
|
|
static struct wlr_allocator *alloc;
|
|
static struct wlr_compositor *compositor;
|
|
static struct wlr_session *session;
|
|
|
|
static struct wlr_xdg_shell *xdg_shell;
|
|
static struct wlr_xdg_activation_v1 *activation;
|
|
static struct wlr_xdg_decoration_manager_v1 *xdg_decoration_mgr;
|
|
static struct wl_list clients; /* tiling order */
|
|
static struct wl_list fstack; /* focus order */
|
|
static struct wlr_idle_notifier_v1 *idle_notifier;
|
|
static struct wlr_idle_inhibit_manager_v1 *idle_inhibit_mgr;
|
|
static struct wlr_layer_shell_v1 *layer_shell;
|
|
static struct wlr_output_manager_v1 *output_mgr;
|
|
static struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr;
|
|
static struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr;
|
|
static struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr;
|
|
static struct wlr_output_power_manager_v1 *power_mgr;
|
|
|
|
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;
|
|
|
|
static struct wlr_cursor *cursor;
|
|
static struct wlr_xcursor_manager *cursor_mgr;
|
|
|
|
static struct wlr_scene_rect *root_bg;
|
|
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;
|
|
|
|
static struct wlr_seat *seat;
|
|
static KeyboardGroup *kb_group;
|
|
static unsigned int cursor_mode;
|
|
static Client *grabc;
|
|
static int grabcx, grabcy; /* client-relative */
|
|
|
|
static struct wlr_output_layout *output_layout;
|
|
static struct wlr_box sgeom;
|
|
static struct wl_list mons;
|
|
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};
|
|
|
|
/* configuration, allows nested code to access above variables */
|
|
#include "config.h"
|
|
|
|
/* attempt to encapsulate suck into one file */
|
|
#include "client.h"
|
|
|
|
/* function implementations */
|
|
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;
|
|
|
|
usage:
|
|
die("Usage: %s [-v] [-d] [-s startup command]", argv[0]);
|
|
}
|