aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile22
-rw-r--r--colorscheme36
-rw-r--r--config.def.h1
-rw-r--r--config.h175
-rw-r--r--config.mk4
-rw-r--r--dwl.c512
-rw-r--r--patches/dwl_ipcv2.patch766
-rw-r--r--patches/pointer-constraints.patch563
-rw-r--r--protocols/dwl-bar-ipc-unstable-v1.xml157
10 files changed, 2199 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
index 0dde90e..5c28541 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,3 @@ dwl
*-protocol.c
*-protocol.h
.ccls-cache
-config.h
diff --git a/Makefile b/Makefile
index ccca079..c65f7cf 100644
--- a/Makefile
+++ b/Makefile
@@ -9,15 +9,16 @@ DWLDEVCFLAGS = -pedantic -Wall -Wextra -Wdeclaration-after-statement -Wno-unused
-Werror=strict-prototypes -Werror=implicit -Werror=return-type -Werror=incompatible-pointer-types
# CFLAGS / LDFLAGS
-PKGS = wlroots wayland-server xkbcommon libinput $(XLIBS)
+PKGS = wlroots wayland-server xkbcommon libinput pixman-1 $(XLIBS)
DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS)
-LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(LIBS)
+LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` -lm $(LIBS)
all: dwl
-dwl: dwl.o util.o
- $(CC) dwl.o util.o $(LDLIBS) $(LDFLAGS) $(DWLCFLAGS) -o $@
-dwl.o: dwl.c config.mk config.h client.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h
+dwl: dwl.o util.o dwl-bar-ipc-unstable-v1-protocol.o
+ $(CC) dwl.o util.o dwl-bar-ipc-unstable-v1-protocol.o $(LDLIBS) $(LDFLAGS) $(DWLCFLAGS) -o $@
+dwl.o: dwl.c config.mk config.h client.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h dwl-bar-ipc-unstable-v1-protocol.h pointer-constraints-unstable-v1-protocol.h
util.o: util.c util.h
+dwl-bar-ipc-unstable-v1-protocol.o: dwl-bar-ipc-unstable-v1-protocol.c dwl-bar-ipc-unstable-v1-protocol.h
# wayland-scanner is a tool which generates C headers and rigging for Wayland
# protocols, which are specified in XML. wlroots requires you to rig these up
@@ -31,11 +32,20 @@ xdg-shell-protocol.h:
wlr-layer-shell-unstable-v1-protocol.h:
$(WAYLAND_SCANNER) server-header \
protocols/wlr-layer-shell-unstable-v1.xml $@
+pointer-constraints-unstable-v1-protocol.h:
+ $(WAYLAND_SCANNER) server-header \
+ $(WAYLAND_PROTOCOLS)/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml $@
+dwl-bar-ipc-unstable-v1-protocol.h:
+ $(WAYLAND_SCANNER) server-header \
+ protocols/dwl-bar-ipc-unstable-v1.xml $@
+dwl-bar-ipc-unstable-v1-protocol.c:
+ $(WAYLAND_SCANNER) private-code \
+ protocols/dwl-bar-ipc-unstable-v1.xml $@
config.h:
cp config.def.h $@
clean:
- rm -f dwl *.o *-protocol.h
+ rm -f dwl *.o *-protocol.*
dist: clean
mkdir -p dwl-$(VERSION)
diff --git a/colorscheme b/colorscheme
new file mode 100644
index 0000000..8774ed6
--- /dev/null
+++ b/colorscheme
@@ -0,0 +1,36 @@
+--- Default ---
+bg #282828
+red #cc241d
+green #98971a
+blue #458588
+purple #b16286
+aqua #689d6a
+gray #a89984
+orange #d65d0e
+fg #ebdbb2
+
+--- Light -----
+gray #928374
+red #fb4934
+green #b8bb26
+yellow #fabd2f
+blue #83a598
+purple #d3869b
+aqua #8ec07c
+orange #fe8019
+
+--- BG --------
+0 #1d2021
+1 #282828
+2 #3c3836
+3 #504945
+4 #665c54
+5 #7c6f64
+6 #928374
+
+--- FG --------
+1 #a89984
+2 #bdae93
+3 #d5c4a1
+4 #ebdbb2
+5 #fbf1c1
diff --git a/config.def.h b/config.def.h
index c6a4950..5a80e21 100644
--- a/config.def.h
+++ b/config.def.h
@@ -111,6 +111,7 @@ static const Key keys[] = {
/* modifier key function argument */
{ MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
+ { MODKEY, XKB_KEY_b, toggle_visibility, {0}},
{ MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
{ MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
{ MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..757fd3c
--- /dev/null
+++ b/config.h
@@ -0,0 +1,175 @@
+/* appearance */
+static const int sloppyfocus = 1; /* focus follows mouse */
+static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
+static const unsigned int borderpx = 2; /* border pixel of windows */
+static const float rootcolor[] = {0.11, 0.13, 0.13, 1.0};
+static const float bordercolor[] = {0.11, 0.13, 0.13, 1.0};
+static const float focuscolor[] = {0.69, 0.38, 0.53, 1.0};
+/* To conform the xdg-protocol, set the alpha to zero to restore the old behavior */
+static const float fullscreen_bg[] = {0.1, 0.1, 0.1, 1.0};
+
+/* tagging */
+static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+
+static const Rule rules[] = {
+ /* app_id title tags mask isfloating monitor */
+ /* examples:
+ { "Gimp", NULL, 0, 1, -1 },
+ */
+ { "Gimp", NULL, 0, 0, -1 },
+};
+
+/* layout(s) */
+static const Layout layouts[] = {
+ /* symbol arrange function */
+ { "[]=", tile },
+ { "><>", NULL }, /* no layout function means floating behavior */
+ { "[M]", monocle },
+};
+
+/* monitors */
+static const MonitorRule monrules[] = {
+ /* name mfact nmaster scale layout rotate/reflect x y */
+ /* example of a HiDPI laptop monitor:
+ { "eDP-1", 0.5, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 },
+ */
+ /* defaults */
+ { "DP-2", 0.55, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, 0, 0 },
+ { "DP-3", 0.55, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, 1920, 0 },
+ { "HDMI-A-1", 0.55, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, 3840, 0 },
+ { NULL, 0.55, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 },
+};
+
+/* keyboard */
+static const struct xkb_rule_names xkb_rules = {
+ /* can specify fields: rules, model, layout, variant, options */
+ /* example:
+ .options = "ctrl:nocaps",
+ */
+ .options = "caps:escape",
+};
+
+static const int repeat_rate = 25;
+static const int repeat_delay = 600;
+
+/* Trackpad */
+static const int tap_to_click = 1;
+static const int tap_and_drag = 1;
+static const int drag_lock = 1;
+static const int natural_scrolling = 0;
+static const int disable_while_typing = 1;
+static const int left_handed = 0;
+static const int middle_button_emulation = 0;
+/* You can choose between:
+LIBINPUT_CONFIG_SCROLL_NO_SCROLL
+LIBINPUT_CONFIG_SCROLL_2FG
+LIBINPUT_CONFIG_SCROLL_EDGE
+LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN
+*/
+static const enum libinput_config_scroll_method scroll_method = LIBINPUT_CONFIG_SCROLL_2FG;
+
+/* You can choose between:
+LIBINPUT_CONFIG_CLICK_METHOD_NONE
+LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS
+LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER
+*/
+static const enum libinput_config_click_method click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
+
+/* You can choose between:
+LIBINPUT_CONFIG_SEND_EVENTS_ENABLED
+LIBINPUT_CONFIG_SEND_EVENTS_DISABLED
+LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE
+*/
+static const uint32_t send_events_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
+
+/* You can choose between:
+LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT
+LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE
+*/
+static const enum libinput_config_accel_profile accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
+static const double accel_speed = 0.0;
+/* You can choose between:
+LIBINPUT_CONFIG_TAP_MAP_LRM -- 1/2/3 finger tap maps to left/right/middle
+LIBINPUT_CONFIG_TAP_MAP_LMR -- 1/2/3 finger tap maps to left/middle/right
+*/
+static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TAP_MAP_LRM;
+
+/* If you want to use the windows key for MODKEY, use WLR_MODIFIER_LOGO */
+#define MODKEY WLR_MODIFIER_LOGO
+
+#define TAGKEYS(KEY,SKEY,TAG) \
+ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
+ { MODKEY|WLR_MODIFIER_CTRL, KEY, toggleview, {.ui = 1 << TAG} }, \
+ { MODKEY|WLR_MODIFIER_SHIFT, SKEY, tag, {.ui = 1 << TAG} }, \
+ { MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,SKEY,toggletag, {.ui = 1 << TAG} }
+
+/* helper for spawning shell commands in the pre dwm-5.0 fashion */
+#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
+
+/* commands */
+static const char *termcmd[] = { "swt", NULL };
+static const char *menucmd[] = { "dmenu-wl_run", "-p", "Run", NULL };
+
+static const Key keys[] = {
+ /* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */
+ /* modifier key function argument */
+ { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_B, spawn, SHCMD("$BROWSER") },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_L, spawn, SHCMD("wlock") },
+ { 0, XKB_KEY_Scroll_Lock, spawn, SHCMD("wlock") },
+ { 0, XKB_KEY_SunPrint_Screen, spawn, SHCMD("grimshot copy area") },
+ { MODKEY, XKB_KEY_SunPrint_Screen, spawn, SHCMD("grimshot save area") },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_P, spawn, SHCMD("passmenu --type") },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_E, spawn, SHCMD("swt -e neomutt") },
+ { MODKEY, XKB_KEY_F12, spawn, SHCMD("keyusbctl -t && status -u")},
+ { 0, XKB_KEY_XF86AudioLowerVolume, spawn, SHCMD("pactl set-sink-volume 0 -3% && status -u")},
+ { 0, XKB_KEY_XF86AudioRaiseVolume, spawn, SHCMD("pactl set-sink-volume 0 +3% && status -u")},
+ { 0, XKB_KEY_XF86AudioMute, spawn, SHCMD("pactl set-sink-mute 0 toggle && status -u")},
+ { 0, XKB_KEY_XF86AudioPlay, spawn, SHCMD("playerctl play-pause && status -u")},
+ { 0, XKB_KEY_XF86AudioNext, spawn, SHCMD("playerctl next && status -u")},
+ { 0, XKB_KEY_XF86AudioPrev, spawn, SHCMD("playerctl previous && status -u")},
+ { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
+ { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
+ { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
+ { MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
+ { MODKEY, XKB_KEY_h, setmfact, {.f = -0.05} },
+ { MODKEY, XKB_KEY_l, setmfact, {.f = +0.05} },
+ { MODKEY, XKB_KEY_Return, zoom, {0} },
+ { MODKEY, XKB_KEY_Tab, view, {0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_C, killclient, {0} },
+ { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
+ { MODKEY, XKB_KEY_space, setlayout, {0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
+ { MODKEY, XKB_KEY_e, togglefullscreen, {0} },
+ { MODKEY, XKB_KEY_0, view, {.ui = ~0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} },
+ { MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} },
+ { MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} },
+ TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0),
+ TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
+ TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
+ TAGKEYS( XKB_KEY_4, XKB_KEY_dollar, 3),
+ TAGKEYS( XKB_KEY_5, XKB_KEY_percent, 4),
+ TAGKEYS( XKB_KEY_6, XKB_KEY_asciicircum, 5),
+ TAGKEYS( XKB_KEY_7, XKB_KEY_ampersand, 6),
+ TAGKEYS( XKB_KEY_8, XKB_KEY_asterisk, 7),
+ TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8),
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Q, quit, {0} },
+
+ /* Ctrl-Alt-Backspace and Ctrl-Alt-Fx used to be handled by X server */
+ { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_Terminate_Server, quit, {0} },
+#define CHVT(n) { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_XF86Switch_VT_##n, chvt, {.ui = (n)} }
+ CHVT(1), CHVT(2), CHVT(3), CHVT(4), CHVT(5), CHVT(6),
+ CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12),
+};
+
+static const Button buttons[] = {
+ { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} },
+ { MODKEY, BTN_MIDDLE, togglefloating, {0} },
+ { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} },
+};
diff --git a/config.mk b/config.mk
index f50156f..a20a8f0 100644
--- a/config.mk
+++ b/config.mk
@@ -10,5 +10,5 @@ MANDIR = $(PREFIX)/share/man
XWAYLAND =
XLIBS =
# Uncomment to build XWayland support
-#XWAYLAND = -DXWAYLAND
-#XLIBS = xcb xcb-icccm
+XWAYLAND = -DXWAYLAND
+XLIBS = xcb xcb-icccm
diff --git a/dwl.c b/dwl.c
index b7436bb..57024ca 100644
--- a/dwl.c
+++ b/dwl.c
@@ -5,6 +5,7 @@
#include <libinput.h>
#include <limits.h>
#include <linux/input-event-codes.h>
+#include <pixman-1/pixman.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -12,6 +13,7 @@
#include <time.h>
#include <unistd.h>
#include <wayland-server-core.h>
+#include <wayland-util.h>
#include <wlr/backend.h>
#include <wlr/backend/libinput.h>
#include <wlr/render/allocator.h>
@@ -33,9 +35,11 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_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>
@@ -51,7 +55,9 @@
#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>
+#include "dwl-bar-ipc-unstable-v1-protocol.h"
#ifdef XWAYLAND
#include <wlr/xwayland.h>
#include <X11/Xlib.h>
@@ -172,9 +178,16 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
+typedef struct {
+ struct wl_list link;
+ struct wl_resource* resource;
+ Monitor *monitor;
+} DwlOutput;
+
struct Monitor {
struct wl_list link;
struct wlr_output *wlr_output;
+ struct wl_list dwl_outputs;
struct wlr_scene_output *scene_output;
struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
struct wl_listener frame;
@@ -204,6 +217,14 @@ typedef struct {
} MonitorRule;
typedef struct {
+ struct wlr_pointer_constraint_v1 *constraint;
+ Client *focused;
+
+ struct wl_listener set_region;
+ struct wl_listener destroy;
+} PointerConstraint;
+
+typedef struct {
const char *id;
const char *title;
uint32_t tags;
@@ -229,6 +250,7 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
static void arrangelayers(Monitor *m);
static void axisnotify(struct wl_listener *listener, void *data);
static void buttonpress(struct wl_listener *listener, void *data);
+static void checkconstraintregion(void);
static void chvt(const Arg *arg);
static void checkidleinhibitor(struct wlr_surface *exclude);
static void cleanup(void);
@@ -238,6 +260,7 @@ static void closemon(Monitor *m);
static void commitlayersurfacenotify(struct wl_listener *listener, void *data);
static void commitnotify(struct wl_listener *listener, void *data);
static void createdecoration(struct wl_listener *listener, void *data);
+static void commitpointerconstraint(struct wl_listener *listener, void *data);
static void createidleinhibitor(struct wl_listener *listener, void *data);
static void createkeyboard(struct wlr_keyboard *keyboard);
static void createlayersurface(struct wl_listener *listener, void *data);
@@ -245,16 +268,31 @@ static void createlocksurface(struct wl_listener *listener, void *data);
static void createmon(struct wl_listener *listener, void *data);
static void createnotify(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_pointer *pointer);
+static void createpointerconstraint(struct wl_listener *listener, void *data);
+static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void cursorframe(struct wl_listener *listener, void *data);
+static void cursorwarptoconstrainthint(void);
static void destroydragicon(struct wl_listener *listener, void *data);
static void destroyidleinhibitor(struct wl_listener *listener, void *data);
static void destroylayersurfacenotify(struct wl_listener *listener, void *data);
static void destroylock(SessionLock *lock, int unlocked);
static void destroylocksurface(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 destroysessionlock(struct wl_listener *listener, void *data);
static void destroysessionmgr(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir);
+static void dwl_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id);
+static void dwl_manager_destroy(struct wl_resource* resource);
+static void dwl_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output);
+static void dwl_manager_release(struct wl_client *client, struct wl_resource *resource);
+static void dwl_output_destroy(struct wl_resource *resource);
+static void dwl_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags);
+static void dwl_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index);
+static void dwl_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset);
+static void dwl_output_printstatus(Monitor* monitor);
+static void dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output);
+static void dwl_output_release(struct wl_client *client, struct wl_resource *resource);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
@@ -273,12 +311,14 @@ static void mapnotify(struct wl_listener *listener, void *data);
static void maximizenotify(struct wl_listener *listener, void *data);
static void monocle(Monitor *m);
static void motionabsolute(struct wl_listener *listener, void *data);
-static void motionnotify(uint32_t time);
+static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx,
+ double sy, double sx_unaccel, double sy_unaccel);
static void motionrelative(struct wl_listener *listener, void *data);
static void moveresize(const Arg *arg);
static void outputmgrapply(struct wl_listener *listener, void *data);
static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test);
static void outputmgrtest(struct wl_listener *listener, void *data);
+static void pointerconstraintsetregion(struct wl_listener *listener, void *data);
static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time);
static void printstatus(void);
@@ -306,6 +346,7 @@ static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
+static void toggle_visibility(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
static void unmapnotify(struct wl_listener *listener, void *data);
@@ -346,6 +387,13 @@ 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_relative_pointer_manager_v1 *relative_pointer_mgr;
+static struct wlr_pointer_constraints_v1 *pointer_constraints;
+static struct wl_listener pointer_constraint_commit;
+static PointerConstraint *active_constraint;
+static pixman_region32_t active_confine;
+static int active_confine_requires_warp;
+
static struct wlr_cursor *cursor;
static struct wlr_xcursor_manager *cursor_mgr;
@@ -371,12 +419,15 @@ 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 drag_icon_destroy = {.notify = destroydragicon};
+static struct zdwl_manager_v1_interface dwl_manager_implementation = {.get_output = dwl_manager_get_output, .release = dwl_manager_release};
+static struct zdwl_output_v1_interface dwl_output_implementation = {.release = dwl_output_release, .set_client_tags = dwl_output_set_client_tags, .set_tags = dwl_output_set_tags, .set_layout = dwl_output_set_layout};
static struct wl_listener idle_inhibitor_create = {.notify = createidleinhibitor};
static struct wl_listener idle_inhibitor_destroy = {.notify = destroyidleinhibitor};
static struct wl_listener layout_change = {.notify = updatemons};
static struct wl_listener new_input = {.notify = inputdevice};
static struct wl_listener new_virtual_keyboard = {.notify = virtualkeyboard};
static struct wl_listener new_output = {.notify = createmon};
+static struct wl_listener new_pointer_constraint = {.notify = createpointerconstraint};
static struct wl_listener new_xdg_surface = {.notify = createnotify};
static struct wl_listener new_xdg_decoration = {.notify = createdecoration};
static struct wl_listener new_layer_shell_surface = {.notify = createlayersurface};
@@ -484,8 +535,7 @@ arrange(Monitor *m)
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
- motionnotify(0);
- checkidleinhibitor(NULL);
+ motionnotify(0, NULL, 0, 0, 0, 0);
}
void
@@ -606,7 +656,7 @@ buttonpress(struct wl_listener *listener, void *data)
* we will send an enter event after which the client will provide us
* a cursor surface */
wlr_seat_pointer_clear_focus(seat);
- motionnotify(0);
+ motionnotify(0, NULL, 0, 0, 0, 0);
/* Drop the window off on its new monitor */
selmon = xytomon(cursor->x, cursor->y);
setmon(grabc, selmon, 0);
@@ -623,6 +673,42 @@ buttonpress(struct wl_listener *listener, void *data)
}
void
+checkconstraintregion(void)
+{
+ struct wlr_pointer_constraint_v1 *constraint = active_constraint->constraint;
+ pixman_region32_t *region = &constraint->region;
+ Client *c = NULL;
+ double sx, sy;
+ toplevel_from_wlr_surface(constraint->surface, &c, NULL);
+ if (active_confine_requires_warp && c) {
+ active_confine_requires_warp = 0;
+
+ sx = cursor->x + c->geom.x;
+ sy = cursor->y + c->geom.y;
+
+ if (!pixman_region32_contains_point(region,
+ floor(sx), floor(sy), NULL)) {
+ int nboxes;
+ pixman_box32_t *boxes = pixman_region32_rectangles(region, &nboxes);
+ if (nboxes > 0) {
+ sx = (boxes[0].x1 + boxes[0].x2) / 2.;
+ sy = (boxes[0].y1 + boxes[0].y2) / 2.;
+
+ wlr_cursor_warp_closest(cursor, NULL,
+ sx - c->geom.x, sy - c->geom.y);
+ }
+ }
+ }
+
+ /* A locked pointer will result in an empty region, thus disallowing all movement. */
+ if (constraint->type == WLR_POINTER_CONSTRAINT_V1_CONFINED) {
+ pixman_region32_copy(&active_confine, region);
+ } else {
+ pixman_region32_clear(&active_confine);
+ }
+}
+
+void
chvt(const Arg *arg)
{
wlr_session_change_vt(wlr_backend_get_session(backend), arg->ui);
@@ -684,6 +770,7 @@ cleanupkeyboard(struct wl_listener *listener, void *data)
void
cleanupmon(struct wl_listener *listener, void *data)
{
+ DwlOutput *output, *output_tmp;
Monitor *m = wl_container_of(listener, m, destroy);
LayerSurface *l, *tmp;
int i;
@@ -700,6 +787,11 @@ cleanupmon(struct wl_listener *listener, void *data)
wlr_scene_output_destroy(m->scene_output);
wlr_scene_node_destroy(&m->fullscreen_bg->node);
+ wl_list_for_each_safe(output, output_tmp, &m->dwl_outputs, link) {
+ wl_resource_set_user_data(output->resource, NULL);
+ free(output);
+ }
+
closemon(m);
free(m);
}
@@ -786,6 +878,12 @@ createdecoration(struct wl_listener *listener, void *data)
}
void
+commitpointerconstraint(struct wl_listener *listener, void *data)
+{
+ checkconstraintregion();
+}
+
+void
createidleinhibitor(struct wl_listener *listener, void *data)
{
struct wlr_idle_inhibitor_v1 *idle_inhibitor = data;
@@ -905,6 +1003,7 @@ createmon(struct wl_listener *listener, void *data)
Monitor *m = wlr_output->data = ecalloc(1, sizeof(*m));
m->wlr_output = wlr_output;
+ wl_list_init(&m->dwl_outputs);
wlr_output_init_render(wlr_output, alloc, drw);
/* Initialize monitor state using configured rules */
@@ -1062,6 +1161,74 @@ createpointer(struct wlr_pointer *pointer)
}
void
+createpointerconstraint(struct wl_listener *listener, void *data)
+{
+ struct wlr_pointer_constraint_v1 *wlr_constraint = data;
+ PointerConstraint *constraint = ecalloc(1, sizeof(*constraint));
+ Client *c = NULL, *sel = focustop(selmon);
+ toplevel_from_wlr_surface(wlr_constraint->surface, &c, NULL);
+ constraint->constraint = wlr_constraint;
+ wlr_constraint->data = constraint;
+
+ LISTEN(&wlr_constraint->events.set_region, &constraint->set_region,
+ pointerconstraintsetregion);
+ LISTEN(&wlr_constraint->events.destroy, &constraint->destroy,
+ destroypointerconstraint);
+
+ if (c == sel)
+ cursorconstrain(wlr_constraint);
+}
+
+void
+cursorconstrain(struct wlr_pointer_constraint_v1 *wlr_constraint)
+{
+ PointerConstraint *constraint = wlr_constraint->data;
+
+ if (active_constraint == constraint)
+ return;
+
+ wl_list_remove(&pointer_constraint_commit.link);
+ if (active_constraint) {
+ if (!wlr_constraint)
+ cursorwarptoconstrainthint();
+
+ wlr_pointer_constraint_v1_send_deactivated(active_constraint->constraint);
+ }
+
+ active_constraint = constraint;
+
+ if (!wlr_constraint) {
+ wl_list_init(&pointer_constraint_commit.link);
+ return;
+ }
+
+ active_confine_requires_warp = 1;
+
+ /* Stolen from sway/input/cursor.c:1435
+ *
+ * FIXME: Big hack, stolen from wlr_pointer_constraints_v1.c:121.
+ * This is necessary because the focus may be set before the surface
+ * has finished committing, which means that warping won't work properly,
+ * since this code will be run *after* the focus has been set.
+ * That is why we duplicate the code here.
+ */
+ if (pixman_region32_not_empty(&wlr_constraint->current.region)) {
+ pixman_region32_intersect(&wlr_constraint->region,
+ &wlr_constraint->surface->input_region, &wlr_constraint->current.region);
+ } else {
+ pixman_region32_copy(&wlr_constraint->region,
+ &wlr_constraint->surface->input_region);
+ }
+
+ checkconstraintregion();
+
+ wlr_pointer_constraint_v1_send_activated(wlr_constraint);
+
+ LISTEN(&wlr_constraint->surface->events.commit, &pointer_constraint_commit,
+ commitpointerconstraint);
+}
+
+void
cursorframe(struct wl_listener *listener, void *data)
{
/* This event is forwarded by the cursor when a pointer emits an frame
@@ -1073,13 +1240,39 @@ cursorframe(struct wl_listener *listener, void *data)
}
void
+cursorwarptoconstrainthint(void)
+{
+ struct wlr_pointer_constraint_v1 *constraint = active_constraint->constraint;
+
+ if (constraint->current.committed &
+ WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) {
+ double lx, ly;
+ double sx = lx = constraint->current.cursor_hint.x;
+ double sy = ly = constraint->current.cursor_hint.y;
+
+ Client *c = NULL;
+ toplevel_from_wlr_surface(constraint->surface, &c, NULL);
+ if (c) {
+ lx -= c->geom.x;
+ ly -= c->geom.y;
+ }
+
+ wlr_cursor_warp(cursor, NULL, lx, ly);
+
+ /* Warp the pointer as well, so that on the next pointer rebase we don't
+ * send an unexpected synthetic motion event to clients. */
+ wlr_seat_pointer_warp(seat, sx, sy);
+ }
+}
+
+void
destroydragicon(struct wl_listener *listener, void *data)
{
struct wlr_drag_icon *icon = data;
wlr_scene_node_destroy(icon->data);
/* Focus enter isn't sent during drag, so refocus the focused node. */
focusclient(focustop(selmon), 1);
- motionnotify(0);
+ motionnotify(0, NULL, 0, 0, 0, 0);
}
void
@@ -1114,7 +1307,7 @@ destroylock(SessionLock *lock, int unlock)
wlr_scene_node_set_enabled(&locked_bg->node, 0);
focusclient(focustop(selmon), 0);
- motionnotify(0);
+ motionnotify(0, NULL, 0, 0, 0, 0);
destroy:
wl_list_remove(&lock->new_surface.link);
@@ -1168,6 +1361,26 @@ destroynotify(struct wl_listener *listener, void *data)
}
void
+destroypointerconstraint(struct wl_listener *listener, void *data)
+{
+ PointerConstraint *constraint = wl_container_of(listener, constraint, destroy);
+ wl_list_remove(&constraint->set_region.link);
+ wl_list_remove(&constraint->destroy.link);
+
+ if (active_constraint == constraint) {
+ cursorwarptoconstrainthint();
+
+ if (pointer_constraint_commit.link.next)
+ wl_list_remove(&pointer_constraint_commit.link);
+
+ wl_list_init(&pointer_constraint_commit.link);
+ active_constraint = NULL;
+ }
+
+ free(constraint);
+}
+
+void
destroysessionlock(struct wl_listener *listener, void *data)
{
SessionLock *lock = wl_container_of(listener, lock, destroy);
@@ -1198,6 +1411,196 @@ dirtomon(enum wlr_direction dir)
}
void
+dwl_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
+{
+ int i;
+ struct wl_resource* resource = wl_resource_create(client, &zdwl_manager_v1_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ wl_resource_set_implementation(resource, &dwl_manager_implementation, NULL, dwl_manager_destroy);
+
+ for (i = 0; i < LENGTH(tags); i++) {
+ zdwl_manager_v1_send_tag(resource, tags[i]);
+ }
+
+ for (i = 0; i < LENGTH(layouts); i++) {
+ zdwl_manager_v1_send_layout(resource, layouts[i].symbol);
+ }
+}
+
+void dwl_manager_destroy(struct wl_resource* resource) {/* No state to destroy */}
+
+void
+dwl_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output)
+{
+ DwlOutput* dwl_output;
+ Monitor* monitor = wlr_output_from_resource(output)->data;
+ struct wl_resource* dwl_output_resource = wl_resource_create(client, &zdwl_output_v1_interface, wl_resource_get_version(resource), id);
+ if (!dwl_output_resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ dwl_output = ecalloc(1, sizeof(*dwl_output));
+ dwl_output->resource = dwl_output_resource;
+ dwl_output->monitor = monitor;
+
+ wl_resource_set_implementation(dwl_output_resource, &dwl_output_implementation, dwl_output, dwl_output_destroy);
+ wl_list_insert(&monitor->dwl_outputs, &dwl_output->link);
+
+ dwl_output_printstatus_to(monitor, dwl_output);
+}
+
+void
+dwl_manager_release(struct wl_client *client, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+void
+dwl_output_destroy(struct wl_resource *resource)
+{
+ DwlOutput *output = wl_resource_get_user_data(resource);
+ if (output) {
+ wl_list_remove(&output->link);
+ free(output);
+ }
+}
+
+void
+dwl_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags)
+{
+ DwlOutput *output;
+ Client *selected_client;
+ unsigned int newtags;
+
+ output = wl_resource_get_user_data(resource);
+ if (!output)
+ return;
+
+ selected_client = focustop(output->monitor);
+ if (!selected_client)
+ return;
+
+ newtags = (selected_client->tags & and_tags) ^ xor_tags;
+ if (!newtags)
+ return;
+
+ selected_client->tags = newtags;
+ focusclient(focustop(selmon), 1);
+ arrange(selmon);
+}
+
+void
+dwl_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index)
+{
+ DwlOutput *output;
+ Monitor *monitor;
+
+ if (index >= LENGTH(layouts))
+ return;
+
+ output = wl_resource_get_user_data(resource);
+ if (!output)
+ return;
+
+ monitor = output->monitor;
+ if (!monitor)
+ return;
+
+ if (index != monitor->lt[monitor->sellt] - layouts)
+ monitor->sellt ^= 1;
+
+ monitor->lt[monitor->sellt] = &layouts[index];
+ arrange(monitor);
+ printstatus();
+}
+
+void
+dwl_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset)
+{
+ DwlOutput *output;
+ Monitor *monitor;
+
+ output = wl_resource_get_user_data(resource);
+ if (!output)
+ return;
+
+ monitor = output->monitor;
+ if (!monitor)
+ return;
+
+ if ((tagmask & TAGMASK) == monitor->tagset[monitor->seltags])
+ return;
+ if (toggle_tagset)
+ monitor->seltags ^= 1;
+ if (tagmask & TAGMASK)
+ monitor->tagset[monitor->seltags] = tagmask & TAGMASK;
+
+ focusclient(focustop(monitor), 1);
+ arrange(monitor);
+ printstatus();
+}
+
+void
+dwl_output_printstatus(Monitor* monitor)
+{
+ DwlOutput *output;
+ wl_list_for_each(output, &monitor->dwl_outputs, link) {
+ dwl_output_printstatus_to(monitor, output);
+ }
+}
+
+void
+dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output)
+{
+ Client *c, *focused;
+ int tagmask, state, numclients, focused_client, tag;
+ const char *title, *appid;
+ focused = focustop(monitor);
+ zdwl_output_v1_send_active(output->resource, monitor == selmon);
+
+ for ( tag = 0 ; tag < LENGTH(tags); tag++) {
+ numclients = state = focused_client = 0;
+ tagmask = 1 << tag;
+ if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
+ state |= ZDWL_OUTPUT_V1_TAG_STATE_ACTIVE;
+
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon != monitor)
+ continue;
+ if (!(c->tags & tagmask))
+ continue;
+ if (c == focused)
+ focused_client = 1;
+ if (c->isurgent)
+ state |= ZDWL_OUTPUT_V1_TAG_STATE_URGENT;
+
+ numclients++;
+ }
+ zdwl_output_v1_send_tag(output->resource, tag, state, numclients, focused_client);
+ }
+ title = focused ? client_get_title(focused) : "";
+
+ zdwl_output_v1_send_layout(output->resource, monitor->lt[monitor->sellt] - layouts);
+ zdwl_output_v1_send_title(output->resource, title ? title : broken);
+ if (wl_resource_get_version(output->resource) >= ZDWL_OUTPUT_V1_APPID_SINCE_VERSION) { /* Don't break clients using version 1 */
+ appid = focused ? client_get_appid(focused) : "";
+ zdwl_output_v1_send_appid(output->resource, appid ? appid : broken);
+ }
+ zdwl_output_v1_send_frame(output->resource);
+}
+
+void
+dwl_output_release(struct wl_client *client, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+void
focusclient(Client *c, int lift)
{
struct wlr_surface *old = seat->keyboard_state.focused_surface;
@@ -1259,7 +1662,7 @@ focusclient(Client *c, int lift)
}
/* Change cursor surface */
- motionnotify(0);
+ motionnotify(0, NULL, 0, 0, 0, 0);
/* Have a client, so focus its top-level wlr_surface */
client_notify_enter(client_surface(c), wlr_seat_get_keyboard(seat));
@@ -1502,7 +1905,7 @@ maplayersurfacenotify(struct wl_listener *listener, void *data)
{
LayerSurface *l = wl_container_of(listener, l, map);
wlr_surface_send_enter(l->layer_surface->surface, l->mon->wlr_output);
- motionnotify(0);
+ motionnotify(0, NULL, 0, 0, 0, 0);
}
void
@@ -1617,22 +2020,62 @@ motionabsolute(struct wl_listener *listener, void *data)
* 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;
- wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y);
- motionnotify(event->time_msec);
+ double lx, ly, 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
-motionnotify(uint32_t time)
+motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
+ double dx_unaccel, double dy_unaccel)
{
double sx = 0, sy = 0;
+ double sx_confined, sy_confined;
Client *c = NULL, *w = NULL;
LayerSurface *l = NULL;
int type;
struct wlr_surface *surface = NULL;
struct wlr_drag_icon *icon;
+ struct wlr_pointer_constraint_v1 *constraint = NULL;
+
+ /* 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) {
+ if ((type = toplevel_from_wlr_surface(
+ seat->pointer_state.focused_surface, &w, &l)) >= 0) {
+ c = w;
+ surface = seat->pointer_state.focused_surface;
+ sx = cursor->x - (type == LayerShell ? l->geom.x : w->geom.x);
+ sy = cursor->y - (type == LayerShell ? l->geom.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);
+
+ wl_list_for_each(constraint, &pointer_constraints->constraints, link)
+ cursorconstrain(constraint);
+
+ if (active_constraint) {
+ constraint = active_constraint->constraint;
+ if (constraint->surface == surface
+ && wlr_region_confine(&active_confine, sx, sy, sx + dx,
+ sy + dy, &sx_confined, &sy_confined)) {
+ dx = sx_confined - sx;
+ dy = sy_confined - sy;
+ } else {
+ return;
+ }
+ }
+ wlr_cursor_move(cursor, device, dx, dy);
+
IDLE_NOTIFY_ACTIVITY;
/* Update selmon (even while dragging a window) */
@@ -1656,19 +2099,6 @@ motionnotify(uint32_t time)
return;
}
- /* 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) {
- if ((type = toplevel_from_wlr_surface(
- seat->pointer_state.focused_surface, &w, &l)) >= 0) {
- c = w;
- surface = seat->pointer_state.focused_surface;
- sx = cursor->x - (type == LayerShell ? l->geom.x : w->geom.x);
- sy = cursor->y - (type == LayerShell ? l->geom.y : w->geom.y);
- }
- }
-
/* 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. */
@@ -1689,8 +2119,8 @@ motionrelative(struct wl_listener *listener, void *data)
* 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. */
- wlr_cursor_move(cursor, &event->pointer->base, event->delta_x, event->delta_y);
- motionnotify(event->time_msec);
+ motionnotify(event->time_msec, &event->pointer->base, event->delta_x, event->delta_y,
+ event->unaccel_dx, event->unaccel_dy);
}
void
@@ -1793,6 +2223,14 @@ outputmgrtest(struct wl_listener *listener, void *data)
}
void
+pointerconstraintsetregion(struct wl_listener *listener, void *data)
+{
+ PointerConstraint *constraint = wl_container_of(listener, constraint, set_region);
+ active_confine_requires_warp = 1;
+ constraint->constraint->surface->data = NULL;
+}
+
+void
pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
uint32_t time)
{
@@ -1857,6 +2295,7 @@ printstatus(void)
printf("%s tags %u %u %u %u\n", m->wlr_output->name, occ, m->tagset[m->seltags],
sel, urg);
printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
+ dwl_output_printstatus(m);
}
fflush(stdout);
}
@@ -2293,7 +2732,13 @@ setup(void)
wl_signal_add(&output_mgr->events.apply, &output_mgr_apply);
wl_signal_add(&output_mgr->events.test, &output_mgr_test);
+ relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy);
+ pointer_constraints = wlr_pointer_constraints_v1_create(dpy);
+ wl_signal_add(&pointer_constraints->events.new_constraint, &new_pointer_constraint);
+ wl_list_init(&pointer_constraint_commit.link);
+
wlr_scene_set_presentation(scene, wlr_presentation_create(dpy, backend));
+ wl_global_create(dpy, &zdwl_manager_v1_interface, 2, NULL, dwl_manager_bind);
#ifdef XWAYLAND
/*
@@ -2332,7 +2777,7 @@ startdrag(struct wl_listener *listener, void *data)
return;
drag->icon->data = wlr_scene_subsurface_tree_create(layers[LyrDragIcon], drag->icon->surface);
- motionnotify(0);
+ motionnotify(0, NULL, 0, 0, 0, 0);
wl_signal_add(&drag->icon->events.destroy, &drag_icon_destroy);
}
@@ -2436,6 +2881,15 @@ toggleview(const Arg *arg)
}
void
+toggle_visibility(const Arg* arg)
+{
+ DwlOutput* output;
+ wl_list_for_each(output, &selmon->dwl_outputs, link) {
+ zdwl_output_v1_send_toggle_visibility(output->resource);
+ }
+}
+
+void
unlocksession(struct wl_listener *listener, void *data)
{
SessionLock *lock = wl_container_of(listener, lock, unlock);
@@ -2457,7 +2911,7 @@ unmaplayersurfacenotify(struct wl_listener *listener, void *data)
if (layersurface->layer_surface->surface ==
seat->keyboard_state.focused_surface)
focusclient(focustop(selmon), 1);
- motionnotify(0);
+ motionnotify(0, NULL, 0, 0, 0, 0);
}
void
@@ -2484,7 +2938,7 @@ unmapnotify(struct wl_listener *listener, void *data)
wl_list_remove(&c->commit.link);
wlr_scene_node_destroy(&c->scene->node);
printstatus();
- motionnotify(0);
+ motionnotify(0, NULL, 0, 0, 0, 0);
}
void
diff --git a/patches/dwl_ipcv2.patch b/patches/dwl_ipcv2.patch
new file mode 100644
index 0000000..a1e2f57
--- /dev/null
+++ b/patches/dwl_ipcv2.patch
@@ -0,0 +1,766 @@
+From ec00ae9cc1ef363fef13e029932e789ae41ef974 Mon Sep 17 00:00:00 2001
+From: MadcowOG <N/A>
+Date: Thu, 23 Feb 2023 00:28:20 -0800
+Subject: [PATCH 1/6] added ipc functionality
+
+---
+ Makefile | 15 +-
+ config.def.h | 1 +
+ dwl.c | 225 ++++++++++++++++++++++++++
+ protocols/dwl-bar-ipc-unstable-v1.xml | 141 ++++++++++++++++
+ 4 files changed, 378 insertions(+), 4 deletions(-)
+ create mode 100644 protocols/dwl-bar-ipc-unstable-v1.xml
+
+diff --git a/Makefile b/Makefile
+index ccca0794..a027522b 100644
+--- a/Makefile
++++ b/Makefile
+@@ -14,10 +14,11 @@ DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CF
+ LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(LIBS)
+
+ all: dwl
+-dwl: dwl.o util.o
+- $(CC) dwl.o util.o $(LDLIBS) $(LDFLAGS) $(DWLCFLAGS) -o $@
+-dwl.o: dwl.c config.mk config.h client.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h
++dwl: dwl.o util.o dwl-bar-ipc-unstable-v1-protocol.o
++ $(CC) dwl.o util.o dwl-bar-ipc-unstable-v1-protocol.o $(LDLIBS) $(LDFLAGS) $(DWLCFLAGS) -o $@
++dwl.o: dwl.c config.mk config.h client.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h dwl-bar-ipc-unstable-v1-protocol.h
+ util.o: util.c util.h
++dwl-bar-ipc-unstable-v1-protocol.o: dwl-bar-ipc-unstable-v1-protocol.c dwl-bar-ipc-unstable-v1-protocol.h
+
+ # wayland-scanner is a tool which generates C headers and rigging for Wayland
+ # protocols, which are specified in XML. wlroots requires you to rig these up
+@@ -31,11 +32,17 @@ xdg-shell-protocol.h:
+ wlr-layer-shell-unstable-v1-protocol.h:
+ $(WAYLAND_SCANNER) server-header \
+ protocols/wlr-layer-shell-unstable-v1.xml $@
++dwl-bar-ipc-unstable-v1-protocol.h:
++ $(WAYLAND_SCANNER) server-header \
++ protocols/dwl-bar-ipc-unstable-v1.xml $@
++dwl-bar-ipc-unstable-v1-protocol.c:
++ $(WAYLAND_SCANNER) private-code \
++ protocols/dwl-bar-ipc-unstable-v1.xml $@
+
+ config.h:
+ cp config.def.h $@
+ clean:
+- rm -f dwl *.o *-protocol.h
++ rm -f dwl *.o *-protocol.*
+
+ dist: clean
+ mkdir -p dwl-$(VERSION)
+diff --git a/config.def.h b/config.def.h
+index 419e6ef4..c3960d26 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -112,6 +112,7 @@ static const Key keys[] = {
+ /* modifier key function argument */
+ { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
++ { MODKEY, XKB_KEY_b, toggle_visibility, {0}},
+ { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
+ { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
+ { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
+diff --git a/dwl.c b/dwl.c
+index 8043bf98..58b6f008 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -12,6 +12,7 @@
+ #include <time.h>
+ #include <unistd.h>
+ #include <wayland-server-core.h>
++#include <wayland-util.h>
+ #include <wlr/backend.h>
+ #include <wlr/backend/libinput.h>
+ #include <wlr/render/allocator.h>
+@@ -52,6 +53,7 @@
+ #include <wlr/types/wlr_xdg_shell.h>
+ #include <wlr/util/log.h>
+ #include <xkbcommon/xkbcommon.h>
++#include "dwl-bar-ipc-unstable-v1-protocol.h"
+ #ifdef XWAYLAND
+ #include <wlr/xwayland.h>
+ #include <X11/Xlib.h>
+@@ -172,9 +174,16 @@ typedef struct {
+ void (*arrange)(Monitor *);
+ } Layout;
+
++typedef struct {
++ struct wl_list link;
++ struct wl_resource* resource;
++ Monitor *monitor;
++} DwlOutput;
++
+ struct Monitor {
+ struct wl_list link;
+ struct wlr_output *wlr_output;
++ struct wl_list dwl_outputs;
+ struct wlr_scene_output *scene_output;
+ struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
+ struct wl_listener frame;
+@@ -254,6 +263,17 @@ static void destroynotify(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 Monitor *dirtomon(enum wlr_direction dir);
++static void dwl_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id);
++static void dwl_manager_destroy(struct wl_resource* resource);
++static void dwl_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output);
++static void dwl_manager_release(struct wl_client *client, struct wl_resource *resource);
++static void dwl_output_destroy(struct wl_resource *resource);
++static void dwl_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags);
++static void dwl_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index);
++static void dwl_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset);
++static void dwl_output_printstatus(Monitor* monitor);
++static void dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output);
++static void dwl_output_release(struct wl_client *client, struct wl_resource *resource);
+ static void focusclient(Client *c, int lift);
+ static void focusmon(const Arg *arg);
+ static void focusstack(const Arg *arg);
+@@ -305,6 +325,7 @@ static void togglefloating(const Arg *arg);
+ static void togglefullscreen(const Arg *arg);
+ static void toggletag(const Arg *arg);
+ static void toggleview(const Arg *arg);
++static void toggle_visibility(const Arg *arg);
+ static void unlocksession(struct wl_listener *listener, void *data);
+ static void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
+ static void unmapnotify(struct wl_listener *listener, void *data);
+@@ -370,6 +391,8 @@ 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 drag_icon_destroy = {.notify = destroydragicon};
++static struct zdwl_manager_v1_interface dwl_manager_implementation = {.get_output = dwl_manager_get_output, .release = dwl_manager_release};
++static struct zdwl_output_v1_interface dwl_output_implementation = {.release = dwl_output_release, .set_client_tags = dwl_output_set_client_tags, .set_tags = dwl_output_set_tags, .set_layout = dwl_output_set_layout};
+ static struct wl_listener idle_inhibitor_create = {.notify = createidleinhibitor};
+ static struct wl_listener idle_inhibitor_destroy = {.notify = destroyidleinhibitor};
+ static struct wl_listener layout_change = {.notify = updatemons};
+@@ -684,6 +707,7 @@ cleanupkeyboard(struct wl_listener *listener, void *data)
+ void
+ cleanupmon(struct wl_listener *listener, void *data)
+ {
++ DwlOutput *output, *output_tmp;
+ Monitor *m = wl_container_of(listener, m, destroy);
+ LayerSurface *l, *tmp;
+ int i;
+@@ -700,6 +724,11 @@ cleanupmon(struct wl_listener *listener, void *data)
+ wlr_scene_output_destroy(m->scene_output);
+ wlr_scene_node_destroy(&m->fullscreen_bg->node);
+
++ wl_list_for_each_safe(output, output_tmp, &m->dwl_outputs, link) {
++ wl_resource_set_user_data(output->resource, NULL);
++ free(output);
++ }
++
+ closemon(m);
+ free(m);
+ }
+@@ -905,6 +934,7 @@ createmon(struct wl_listener *listener, void *data)
+ Monitor *m = wlr_output->data = ecalloc(1, sizeof(*m));
+ m->wlr_output = wlr_output;
+
++ wl_list_init(&m->dwl_outputs);
+ wlr_output_init_render(wlr_output, alloc, drw);
+
+ /* Initialize monitor state using configured rules */
+@@ -1196,6 +1226,190 @@ dirtomon(enum wlr_direction dir)
+ return selmon;
+ }
+
++void
++dwl_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
++{
++ int i;
++ struct wl_resource* resource = wl_resource_create(client, &zdwl_manager_v1_interface, version, id);
++ if (!resource) {
++ wl_client_post_no_memory(client);
++ return;
++ }
++
++ wl_resource_set_implementation(resource, &dwl_manager_implementation, NULL, dwl_manager_destroy);
++
++ for (i = 0; i < LENGTH(tags); i++) {
++ zdwl_manager_v1_send_tag(resource, tags[i]);
++ }
++
++ for (i = 0; i < LENGTH(layouts); i++) {
++ zdwl_manager_v1_send_layout(resource, layouts[i].symbol);
++ }
++}
++
++void dwl_manager_destroy(struct wl_resource* resource) {/* No state to destroy */}
++
++void
++dwl_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output)
++{
++ DwlOutput* dwl_output;
++ Monitor* monitor = wlr_output_from_resource(output)->data;
++ struct wl_resource* dwl_output_resource = wl_resource_create(client, &zdwl_output_v1_interface, wl_resource_get_version(resource), id);
++ if (!dwl_output_resource) {
++ wl_client_post_no_memory(client);
++ return;
++ }
++
++ dwl_output = ecalloc(1, sizeof(*dwl_output));
++ dwl_output->resource = dwl_output_resource;
++ dwl_output->monitor = monitor;
++
++ wl_resource_set_implementation(dwl_output_resource, &dwl_output_implementation, dwl_output, dwl_output_destroy);
++ wl_list_insert(&monitor->dwl_outputs, &dwl_output->link);
++
++ dwl_output_printstatus_to(monitor, dwl_output);
++}
++
++void
++dwl_manager_release(struct wl_client *client, struct wl_resource *resource)
++{
++ wl_resource_destroy(resource);
++}
++
++void
++dwl_output_destroy(struct wl_resource *resource)
++{
++ DwlOutput *output = wl_resource_get_user_data(resource);
++ if (output) {
++ wl_list_remove(&output->link);
++ free(output);
++ }
++}
++
++void
++dwl_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags)
++{
++ DwlOutput *output;
++ Client *selected_client;
++ unsigned int newtags;
++
++ output = wl_resource_get_user_data(resource);
++ if (!output)
++ return;
++
++ selected_client = focustop(output->monitor);
++ if (!selected_client)
++ return;
++
++ newtags = (selected_client->tags & and_tags) ^ xor_tags;
++ if (!newtags)
++ return;
++
++ selected_client->tags = newtags;
++ focusclient(focustop(selmon), 1);
++ arrange(selmon);
++}
++
++void
++dwl_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index)
++{
++ DwlOutput *output;
++ Monitor *monitor;
++
++ if (index >= LENGTH(layouts))
++ return;
++
++ output = wl_resource_get_user_data(resource);
++ if (!output)
++ return;
++
++ monitor = output->monitor;
++ if (!monitor)
++ return;
++
++ if (index != monitor->lt[monitor->sellt] - layouts)
++ monitor->sellt ^= 1;
++
++ monitor->lt[monitor->sellt] = &layouts[index];
++ arrange(monitor);
++ printstatus();
++}
++
++void
++dwl_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset)
++{
++ DwlOutput *output;
++ Monitor *monitor;
++
++ output = wl_resource_get_user_data(resource);
++ if (!output)
++ return;
++
++ monitor = output->monitor;
++ if (!monitor)
++ return;
++
++ if ((tagmask & TAGMASK) == monitor->tagset[monitor->seltags])
++ return;
++ if (toggle_tagset)
++ monitor->seltags ^= 1;
++ if (tagmask & TAGMASK)
++ monitor->tagset[monitor->seltags] = tagmask & TAGMASK;
++
++ focusclient(focustop(monitor), 1);
++ arrange(monitor);
++ printstatus();
++}
++
++void
++dwl_output_printstatus(Monitor* monitor)
++{
++ DwlOutput *output;
++ wl_list_for_each(output, &monitor->dwl_outputs, link) {
++ dwl_output_printstatus_to(monitor, output);
++ }
++}
++
++void
++dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output)
++{
++ Client *c, *focused;
++ int tagmask, state, numclients, focused_client, tag;
++ focused = focustop(monitor);
++ zdwl_output_v1_send_active(output->resource, monitor == selmon);
++
++ for ( tag = 0 ; tag < LENGTH(tags); tag++) {
++ numclients = state = 0;
++ focused_client = -1;
++ tagmask = 1 << tag;
++ if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
++ state |= ZDWL_OUTPUT_V1_TAG_STATE_ACTIVE;
++
++ wl_list_for_each(c, &clients, link) {
++ if (c->mon != monitor)
++ continue;
++ if (!(c->tags & tagmask))
++ continue;
++ if (c == focused)
++ focused_client = numclients;
++ if (c->isurgent)
++ state |= ZDWL_OUTPUT_V1_TAG_STATE_URGENT;
++
++ numclients++;
++ }
++ zdwl_output_v1_send_tag(output->resource, tag, state, numclients, focused_client);
++ }
++ zdwl_output_v1_send_layout(output->resource, monitor->lt[monitor->sellt] - layouts);
++ zdwl_output_v1_send_title(output->resource, focused ? client_get_title(focused) : "");
++ zdwl_output_v1_send_frame(output->resource);
++}
++
++void
++dwl_output_release(struct wl_client *client, struct wl_resource *resource)
++{
++ wl_resource_destroy(resource);
++}
++
+ void
+ focusclient(Client *c, int lift)
+ {
+@@ -1852,6 +2066,7 @@ printstatus(void)
+ printf("%s tags %u %u %u %u\n", m->wlr_output->name, occ, m->tagset[m->seltags],
+ sel, urg);
+ printf("%s layout %s\n", m->wlr_output->name, m->lt[m->sellt]->symbol);
++ dwl_output_printstatus(m);
+ }
+ fflush(stdout);
+ }
+@@ -2289,6 +2504,7 @@ setup(void)
+ wl_signal_add(&output_mgr->events.test, &output_mgr_test);
+
+ wlr_scene_set_presentation(scene, wlr_presentation_create(dpy, backend));
++ wl_global_create(dpy, &zdwl_manager_v1_interface, 1, NULL, dwl_manager_bind);
+
+ #ifdef XWAYLAND
+ /*
+@@ -2430,6 +2646,15 @@ toggleview(const Arg *arg)
+ printstatus();
+ }
+
++void
++toggle_visibility(const Arg* arg)
++{
++ DwlOutput* output;
++ wl_list_for_each(output, &selmon->dwl_outputs, link) {
++ zdwl_output_v1_send_toggle_visibility(output->resource);
++ }
++}
++
+ void
+ unlocksession(struct wl_listener *listener, void *data)
+ {
+diff --git a/protocols/dwl-bar-ipc-unstable-v1.xml b/protocols/dwl-bar-ipc-unstable-v1.xml
+new file mode 100644
+index 00000000..c2d0674f
+--- /dev/null
++++ b/protocols/dwl-bar-ipc-unstable-v1.xml
+@@ -0,0 +1,141 @@
++<?xml version="1.0" encoding="utf-8"?>
++<!--
++This is largely ripped from somebar's ipc patchset; just with some personal modifications.
++I would probably just submit raphi's patchset but I don't think that would be polite.
++-->
++<protocol name="dwl_bar_ipc_unstable_v1">
++ <description summary="inter-proccess-communication about dwl's state">
++ This protocol allows clients to get updates from dwl and vice versa.
++
++ Warning! This protocol is experimental and may make backward incompatible changes.
++ </description>
++
++ <interface name="zdwl_manager_v1" version="1">
++ <description summary="manage dwl state">
++ This interface is exposed as a global in wl_registry.
++
++ Clients can use this interface to get a dwl_output.
++ After binding the client will revieve dwl_manager.tag and dwl_manager.layout events.
++ The dwl_manager.tag and dwl_manager.layout events expose tags and layouts to the client.
++ </description>
++
++ <request name="release" type="destructor">
++ <description summary="release dwl_manager">
++ Indicates that the client will not the dwl_manager object anymore.
++ Objects created through this instance are not affected.
++ </description>
++ </request>
++
++ <request name="get_output">
++ <description summary="get a dwl_output for a wl_output">
++ Get a dwl_output for the specified wl_output.
++ </description>
++ <arg name="id" type="new_id" interface="zdwl_output_v1"/>
++ <arg name="output" type="object" interface="wl_output"/>
++ </request>
++
++ <event name="tag">
++ <description summary="Announces a tag">
++ This event is sent after binding.
++ A roundtrip after binding guarantees the client recieved all tags.
++ </description>
++ <arg name="name" type="string"/>
++ </event>
++
++ <event name="layout">
++ <description summary="Announces a layout">
++ This event is sent after binding.
++ A roundtrip after binding guarantees the client recieved all layouts.
++ </description>
++ <arg name="name" type="string"/>
++ </event>
++ </interface>
++
++ <interface name="zdwl_output_v1" version="1">
++ <description summary="control dwl output">
++ Observe and control a dwl output.
++
++ Events are double-buffered:
++ Clients should cache events and redraw when a dwl_output.done event is sent.
++
++ Request are not double-buffered:
++ The compositor will update immediately upon request.
++ </description>
++
++ <enum name="tag_state">
++ <entry name="none" value="0" summary="no state"/>
++ <entry name="active" value="1" summary="tag is active"/>
++ <entry name="urgent" value="2" summary="tag has at least one urgent client"/>
++ </enum>
++
++ <request name="release" type="destructor">
++ <description summary="release dwl_output">
++ Indicates to that the client no longer needs this dwl_output.
++ </description>
++ </request>
++
++ <event name="toggle_visibility">
++ <description summary="Toggle client visibilty">
++ Indicates the client should hide or show themselves.
++ If the client is visible then hide, if hidden then show.
++ </description>
++ </event>
++
++ <event name="active">
++ <description summary="Update the selected output.">
++ Indicates if the output is active. Zero is invalid, nonzero is valid.
++ </description>
++ <arg name="active" type="uint"/>
++ </event>
++
++ <event name="tag">
++ <description summary="Update the state of a tag.">
++ Indicates that a tag has been updated.
++ </description>
++ <arg name="tag" type="uint" summary="Index of the tag"/>
++ <arg name="state" type="uint" enum="tag_state" summary="The state of the tag."/>
++ <arg name="clients" type="uint" summary="The number of clients in the tag."/>
++ <arg name="focused" type="uint" summary="If there is a focused client. Nonzero being valid, zero being invalid."/>
++ </event>
++
++ <event name="layout">
++ <description summary="Update the layout.">
++ Indicates a new layout is selected.
++ </description>
++ <arg name="layout" type="uint" summary="Index of the layout."/>
++ </event>
++
++ <event name="title">
++ <description summary="Update the title.">
++ Indicates the title has changed.
++ </description>
++ <arg name="title" type="string" summary="The new title name."/>
++ </event>
++
++ <event name="frame">
++ <description summary="The update sequence is done.">
++ Indicates that a sequence of status updates have finished and the client should redraw.
++ </description>
++ </event>
++
++ <request name="set_layout">
++ <description summary="Set the layout of this output"/>
++ <arg name="index" type="uint" summary="index of a layout recieved by dwl_manager.layout"/>
++ </request>
++
++ <request name="set_tags">
++ <description summary="Set the active tags of this output"/>
++ <arg name="tagmask" type="uint" summary="bitmask of the tags that should be set."/>
++ <arg name="toggle_tagset" type="uint" summary="toggle the selected tagset, zero for invalid, nonzero for valid."/>
++ </request>
++
++ <request name="set_client_tags">
++ <description summary="Set the tags of the focused client.">
++ The tags are updated as follows:
++ new_tags = (current_tags AND and_tags) XOR xor_tags
++ </description>
++ <arg name="and_tags" type="uint"/>
++ <arg name="xor_tags" type="uint"/>
++ </request>
++ </interface>
++</protocol>
+
+From d20aa3b667af6ed073e88f1c1eb617bec1d4c300 Mon Sep 17 00:00:00 2001
+From: MadcowOG <N/A>
+Date: Sun, 26 Feb 2023 13:18:09 -0800
+Subject: [PATCH 2/6] focused_client should be 0 then 1 not -1 then not -1.
+
+---
+ dwl.c | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/dwl.c b/dwl.c
+index 58b6f008..f0f5f68d 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -1379,8 +1379,7 @@ dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output)
+ zdwl_output_v1_send_active(output->resource, monitor == selmon);
+
+ for ( tag = 0 ; tag < LENGTH(tags); tag++) {
+- numclients = state = 0;
+- focused_client = -1;
++ numclients = state = focused_client = 0;
+ tagmask = 1 << tag;
+ if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
+ state |= ZDWL_OUTPUT_V1_TAG_STATE_ACTIVE;
+@@ -1391,7 +1390,7 @@ dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output)
+ if (!(c->tags & tagmask))
+ continue;
+ if (c == focused)
+- focused_client = numclients;
++ focused_client = 1;
+ if (c->isurgent)
+ state |= ZDWL_OUTPUT_V1_TAG_STATE_URGENT;
+
+
+From e736f44db576d6ab99aab19aa2e2175c1e6f17f8 Mon Sep 17 00:00:00 2001
+From: MadcowOG <N/A>
+Date: Mon, 27 Feb 2023 13:47:39 -0800
+Subject: [PATCH 3/6] Added version 2 of protocol. Added functionality for
+ appid.
+
+---
+ dwl.c | 11 ++++++++---
+ protocols/dwl-bar-ipc-unstable-v1.xml | 11 +++++++++--
+ 2 files changed, 17 insertions(+), 5 deletions(-)
+
+diff --git a/dwl.c b/dwl.c
+index f0f5f68d..b01d3106 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -1375,6 +1375,7 @@ dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output)
+ {
+ Client *c, *focused;
+ int tagmask, state, numclients, focused_client, tag;
++ const char *title, *appid;
+ focused = focustop(monitor);
+ zdwl_output_v1_send_active(output->resource, monitor == selmon);
+
+@@ -1398,9 +1399,13 @@ dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output)
+ }
+ zdwl_output_v1_send_tag(output->resource, tag, state, numclients, focused_client);
+ }
+- zdwl_output_v1_send_layout(output->resource, monitor->lt[monitor->sellt] - layouts);
+- zdwl_output_v1_send_title(output->resource, focused ? client_get_title(focused) : "");
+- zdwl_output_v1_send_frame(output->resource);
++ title = focused ? client_get_title(focused) : "";
++ appid = focused ? client_get_appid(focused) : "";
++
++ zdwl_output_v1_send_layout(output->resource, monitor->lt[monitor->sellt] - layouts);
++ zdwl_output_v1_send_title(output->resource, title ? title : broken);
++ zdwl_output_v1_send_appid(output->resource, appid ? appid : broken);
++ zdwl_output_v1_send_frame(output->resource);
+ }
+
+ void
+diff --git a/protocols/dwl-bar-ipc-unstable-v1.xml b/protocols/dwl-bar-ipc-unstable-v1.xml
+index c2d0674f..ca7df773 100644
+--- a/protocols/dwl-bar-ipc-unstable-v1.xml
++++ b/protocols/dwl-bar-ipc-unstable-v1.xml
+@@ -10,7 +10,7 @@ I would probably just submit raphi's patchset but I don't think that would be po
+ Warning! This protocol is experimental and may make backward incompatible changes.
+ </description>
+
+- <interface name="zdwl_manager_v1" version="1">
++ <interface name="zdwl_manager_v1" version="2">
+ <description summary="manage dwl state">
+ This interface is exposed as a global in wl_registry.
+
+@@ -51,7 +51,7 @@ I would probably just submit raphi's patchset but I don't think that would be po
+ </event>
+ </interface>
+
+- <interface name="zdwl_output_v1" version="1">
++ <interface name="zdwl_output_v1" version="2">
+ <description summary="control dwl output">
+ Observe and control a dwl output.
+
+@@ -112,6 +112,13 @@ I would probably just submit raphi's patchset but I don't think that would be po
+ <arg name="title" type="string" summary="The new title name."/>
+ </event>
+
++ <event name="appid">
++ <description summary="Update the appid.">
++ Indicates the appid has changed.
++ </description>
++ <arg name="appid" type="string" summary="The new appid."/>
++ </event>
++
+ <event name="frame">
+ <description summary="The update sequence is done.">
+ Indicates that a sequence of status updates have finished and the client should redraw.
+
+From e9cd8e936e939ea8bc7ca8b1c738949d1c7e299a Mon Sep 17 00:00:00 2001
+From: MadcowOG <N/A>
+Date: Mon, 27 Feb 2023 17:02:46 -0800
+Subject: [PATCH 4/6] Fixed version imcompatibility, I don't know how I missed
+ this.
+
+---
+ dwl.c | 6 ++++--
+ protocols/dwl-bar-ipc-unstable-v1.xml | 17 +++++++++++++----
+ 2 files changed, 17 insertions(+), 6 deletions(-)
+
+diff --git a/dwl.c b/dwl.c
+index b01d3106..6911e03e 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -1400,11 +1400,13 @@ dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output)
+ zdwl_output_v1_send_tag(output->resource, tag, state, numclients, focused_client);
+ }
+ title = focused ? client_get_title(focused) : "";
+- appid = focused ? client_get_appid(focused) : "";
+
+ zdwl_output_v1_send_layout(output->resource, monitor->lt[monitor->sellt] - layouts);
+ zdwl_output_v1_send_title(output->resource, title ? title : broken);
+- zdwl_output_v1_send_appid(output->resource, appid ? appid : broken);
++ if (wl_resource_get_version(output->resource) >= ZDWL_OUTPUT_V1_APPID) { /* Don't break clients using version 1 */
++ appid = focused ? client_get_appid(focused) : "";
++ zdwl_output_v1_send_appid(output->resource, appid ? appid : broken);
++ }
+ zdwl_output_v1_send_frame(output->resource);
+ }
+
+diff --git a/protocols/dwl-bar-ipc-unstable-v1.xml b/protocols/dwl-bar-ipc-unstable-v1.xml
+index ca7df773..b7637751 100644
+--- a/protocols/dwl-bar-ipc-unstable-v1.xml
++++ b/protocols/dwl-bar-ipc-unstable-v1.xml
+@@ -5,9 +5,18 @@ I would probably just submit raphi's patchset but I don't think that would be po
+ -->
+ <protocol name="dwl_bar_ipc_unstable_v1">
+ <description summary="inter-proccess-communication about dwl's state">
+- This protocol allows clients to get updates from dwl and vice versa.
+-
+- Warning! This protocol is experimental and may make backward incompatible changes.
++ This protocol allows clients to get updates from dwl and vice versa.
++
++ Warning! The protocol described in this file is experimental and
++ backward incompatible changes may be made. Backward compatible
++ changes may be added together with the corresponding interface
++ version bump.
++ Backward incompatible changes are done by bumping the version
++ number in the protocol and interface names and resetting the
++ interface version. Once the protocol is to be declared stable,
++ the 'z' prefix and the version number in the protocol and
++ interface names are removed and the interface version number is
++ reset.
+ </description>
+
+ <interface name="zdwl_manager_v1" version="2">
+@@ -112,7 +121,7 @@ I would probably just submit raphi's patchset but I don't think that would be po
+ <arg name="title" type="string" summary="The new title name."/>
+ </event>
+
+- <event name="appid">
++ <event name="appid" since="2">
+ <description summary="Update the appid.">
+ Indicates the appid has changed.
+ </description>
+
+From bbca957db16e2c2d24d5f212b0f49aa3af0ace50 Mon Sep 17 00:00:00 2001
+From: MadcowOG <N/A>
+Date: Tue, 28 Feb 2023 03:51:06 -0800
+Subject: [PATCH 5/6] I messed it up again.
+
+---
+ dwl.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/dwl.c b/dwl.c
+index 6911e03e..79218ccf 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -1403,7 +1403,7 @@ dwl_output_printstatus_to(Monitor* monitor, DwlOutput *output)
+
+ zdwl_output_v1_send_layout(output->resource, monitor->lt[monitor->sellt] - layouts);
+ zdwl_output_v1_send_title(output->resource, title ? title : broken);
+- if (wl_resource_get_version(output->resource) >= ZDWL_OUTPUT_V1_APPID) { /* Don't break clients using version 1 */
++ if (wl_resource_get_version(output->resource) >= ZDWL_OUTPUT_V1_APPID_SINCE_VERSION) { /* Don't break clients using version 1 */
+ appid = focused ? client_get_appid(focused) : "";
+ zdwl_output_v1_send_appid(output->resource, appid ? appid : broken);
+ }
+@@ -2510,7 +2510,7 @@ setup(void)
+ wl_signal_add(&output_mgr->events.test, &output_mgr_test);
+
+ wlr_scene_set_presentation(scene, wlr_presentation_create(dpy, backend));
+- wl_global_create(dpy, &zdwl_manager_v1_interface, 1, NULL, dwl_manager_bind);
++ wl_global_create(dpy, &zdwl_manager_v1_interface, 2, NULL, dwl_manager_bind);
+
+ #ifdef XWAYLAND
+ /*
+
+From 9fb7aa6a6b365abf0e68c05d6cc313d8a544de1c Mon Sep 17 00:00:00 2001
+From: MadcowOG <N/A>
+Date: Wed, 1 Mar 2023 07:09:02 -0800
+Subject: [PATCH 6/6] Removed trailing whitespace as to avoid problems with git
+ apply
+
+---
+ protocols/dwl-bar-ipc-unstable-v1.xml | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/protocols/dwl-bar-ipc-unstable-v1.xml b/protocols/dwl-bar-ipc-unstable-v1.xml
+index b7637751..9c152465 100644
+--- a/protocols/dwl-bar-ipc-unstable-v1.xml
++++ b/protocols/dwl-bar-ipc-unstable-v1.xml
+@@ -13,7 +13,7 @@ I would probably just submit raphi's patchset but I don't think that would be po
+ version bump.
+ Backward incompatible changes are done by bumping the version
+ number in the protocol and interface names and resetting the
+- interface version. Once the protocol is to be declared stable,
++ interface version. Once the protocol is to be declared stable,
+ the 'z' prefix and the version number in the protocol and
+ interface names are removed and the interface version number is
+ reset.
diff --git a/patches/pointer-constraints.patch b/patches/pointer-constraints.patch
new file mode 100644
index 0000000..23d1ea1
--- /dev/null
+++ b/patches/pointer-constraints.patch
@@ -0,0 +1,563 @@
+From a18dab86893714b4103d9965ec0e143e53ffbfd8 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?=
+ <leohdz172@protonmail.com>
+Date: Thu, 26 May 2022 01:26:21 -0500
+Subject: [PATCH] implement pointer constraints
+
+mostly copied from sway implementation
+
+Co-authored-by: A Frederick Christenesn <dwl@ivories.org>
+Co-authored-by: pm4rcin <37148802+pm4rcin@users.noreply.github.com>
+---
+ Makefile | 9 +-
+ dwl.c | 281 +++++++++++++++++++++++++++++++++++++++++++++++++------
+ 2 files changed, 258 insertions(+), 32 deletions(-)
+
+diff --git a/Makefile b/Makefile
+index ccca0794..28c57728 100644
+--- a/Makefile
++++ b/Makefile
+@@ -9,14 +9,14 @@ DWLDEVCFLAGS = -pedantic -Wall -Wextra -Wdeclaration-after-statement -Wno-unused
+ -Werror=strict-prototypes -Werror=implicit -Werror=return-type -Werror=incompatible-pointer-types
+
+ # CFLAGS / LDFLAGS
+-PKGS = wlroots wayland-server xkbcommon libinput $(XLIBS)
++PKGS = wlroots wayland-server xkbcommon libinput pixman-1 $(XLIBS)
+ DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS)
+-LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(LIBS)
++LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` -lm $(LIBS)
+
+ all: dwl
+ dwl: dwl.o util.o dwl-bar-ipc-unstable-v1-protocol.o
+ $(CC) dwl.o util.o dwl-bar-ipc-unstable-v1-protocol.o $(LDLIBS) $(LDFLAGS) $(DWLCFLAGS) -o $@
+-dwl.o: dwl.c config.mk config.h client.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h dwl-bar-ipc-unstable-v1-protocol.h
++dwl.o: dwl.c config.mk config.h client.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h dwl-bar-ipc-unstable-v1-protocol.h pointer-constraints-unstable-v1-protocol.h
+ util.o: util.c util.h
+ dwl-bar-ipc-unstable-v1-protocol.o: dwl-bar-ipc-unstable-v1-protocol.c dwl-bar-ipc-unstable-v1-protocol.h
+
+@@ -31,6 +31,9 @@ xdg-shell-protocol.h:
+ wlr-layer-shell-unstable-v1-protocol.h:
+ $(WAYLAND_SCANNER) server-header \
+ protocols/wlr-layer-shell-unstable-v1.xml $@
++pointer-constraints-unstable-v1-protocol.h:
++ $(WAYLAND_SCANNER) server-header \
++ $(WAYLAND_PROTOCOLS)/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml $@
+ dwl-bar-ipc-unstable-v1-protocol.h:
+ $(WAYLAND_SCANNER) server-header \
+ protocols/dwl-bar-ipc-unstable-v1.xml $@
+diff --git a/dwl.c b/dwl.c
+index 8043bf98..5c018f55 100644
+--- a/dwl.c
++++ b/dwl.c
+@@ -5,6 +5,7 @@
+ #include <libinput.h>
+ #include <limits.h>
+ #include <linux/input-event-codes.h>
++#include <pixman-1/pixman.h>
+ #include <signal.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -33,9 +34,11 @@
+ #include <wlr/types/wlr_output_layout.h>
+ #include <wlr/types/wlr_output_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>
+@@ -51,6 +54,7 @@
+ #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>
+ #include "dwl-bar-ipc-unstable-v1-protocol.h"
+ #ifdef XWAYLAND
+@@ -202,6 +206,14 @@ typedef struct {
+ int x, y;
+ } MonitorRule;
+
++typedef struct {
++ struct wlr_pointer_constraint_v1 *constraint;
++ Client *focused;
++
++ struct wl_listener set_region;
++ struct wl_listener destroy;
++} PointerConstraint;
++
+ typedef struct {
+ const char *id;
+ const char *title;
+@@ -228,6 +240,7 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
+ static void arrangelayers(Monitor *m);
+ static void axisnotify(struct wl_listener *listener, void *data);
+ static void buttonpress(struct wl_listener *listener, void *data);
++static void checkconstraintregion(void);
+ static void chvt(const Arg *arg);
+ static void checkidleinhibitor(struct wlr_surface *exclude);
+ static void cleanup(void);
+@@ -237,6 +250,7 @@ static void closemon(Monitor *m);
+ static void commitlayersurfacenotify(struct wl_listener *listener, void *data);
+ static void commitnotify(struct wl_listener *listener, void *data);
+ static void createdecoration(struct wl_listener *listener, void *data);
++static void commitpointerconstraint(struct wl_listener *listener, void *data);
+ static void createidleinhibitor(struct wl_listener *listener, void *data);
+ static void createkeyboard(struct wlr_keyboard *keyboard);
+ static void createlayersurface(struct wl_listener *listener, void *data);
+@@ -244,13 +258,17 @@ static void createlocksurface(struct wl_listener *listener, void *data);
+ static void createmon(struct wl_listener *listener, void *data);
+ static void createnotify(struct wl_listener *listener, void *data);
+ static void createpointer(struct wlr_pointer *pointer);
++static void createpointerconstraint(struct wl_listener *listener, void *data);
++static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
+ static void cursorframe(struct wl_listener *listener, void *data);
++static void cursorwarptoconstrainthint(void);
+ static void destroydragicon(struct wl_listener *listener, void *data);
+ static void destroyidleinhibitor(struct wl_listener *listener, void *data);
+ static void destroylayersurfacenotify(struct wl_listener *listener, void *data);
+ static void destroylock(SessionLock *lock, int unlocked);
+ static void destroylocksurface(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 destroysessionlock(struct wl_listener *listener, void *data);
+ static void destroysessionmgr(struct wl_listener *listener, void *data);
+ static Monitor *dirtomon(enum wlr_direction dir);
+@@ -272,12 +290,14 @@ static void mapnotify(struct wl_listener *listener, void *data);
+ static void maximizenotify(struct wl_listener *listener, void *data);
+ static void monocle(Monitor *m);
+ static void motionabsolute(struct wl_listener *listener, void *data);
+-static void motionnotify(uint32_t time);
++static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx,
++ double sy, double sx_unaccel, double sy_unaccel);
+ static void motionrelative(struct wl_listener *listener, void *data);
+ static void moveresize(const Arg *arg);
+ static void outputmgrapply(struct wl_listener *listener, void *data);
+ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test);
+ static void outputmgrtest(struct wl_listener *listener, void *data);
++static void pointerconstraintsetregion(struct wl_listener *listener, void *data);
+ static void pointerfocus(Client *c, struct wlr_surface *surface,
+ double sx, double sy, uint32_t time);
+ static void printstatus(void);
+@@ -345,6 +365,13 @@ 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_relative_pointer_manager_v1 *relative_pointer_mgr;
++static struct wlr_pointer_constraints_v1 *pointer_constraints;
++static struct wl_listener pointer_constraint_commit;
++static PointerConstraint *active_constraint;
++static pixman_region32_t active_confine;
++static int active_confine_requires_warp;
++
+ static struct wlr_cursor *cursor;
+ static struct wlr_xcursor_manager *cursor_mgr;
+
+@@ -376,6 +403,7 @@ static struct wl_listener layout_change = {.notify = updatemons};
+ static struct wl_listener new_input = {.notify = inputdevice};
+ static struct wl_listener new_virtual_keyboard = {.notify = virtualkeyboard};
+ static struct wl_listener new_output = {.notify = createmon};
++static struct wl_listener new_pointer_constraint = {.notify = createpointerconstraint};
+ static struct wl_listener new_xdg_surface = {.notify = createnotify};
+ static struct wl_listener new_xdg_decoration = {.notify = createdecoration};
+ static struct wl_listener new_layer_shell_surface = {.notify = createlayersurface};
+@@ -484,8 +512,7 @@ arrange(Monitor *m)
+ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
+ if (m && m->lt[m->sellt]->arrange)
+ m->lt[m->sellt]->arrange(m);
+- motionnotify(0);
+- checkidleinhibitor(NULL);
++ motionnotify(0, NULL, 0, 0, 0, 0);
+ }
+
+ void
+@@ -606,7 +633,7 @@ buttonpress(struct wl_listener *listener, void *data)
+ * we will send an enter event after which the client will provide us
+ * a cursor surface */
+ wlr_seat_pointer_clear_focus(seat);
+- motionnotify(0);
++ motionnotify(0, NULL, 0, 0, 0, 0);
+ /* Drop the window off on its new monitor */
+ selmon = xytomon(cursor->x, cursor->y);
+ setmon(grabc, selmon, 0);
+@@ -622,6 +649,42 @@ buttonpress(struct wl_listener *listener, void *data)
+ event->time_msec, event->button, event->state);
+ }
+
++void
++checkconstraintregion(void)
++{
++ struct wlr_pointer_constraint_v1 *constraint = active_constraint->constraint;
++ pixman_region32_t *region = &constraint->region;
++ Client *c = NULL;
++ double sx, sy;
++ toplevel_from_wlr_surface(constraint->surface, &c, NULL);
++ if (active_confine_requires_warp && c) {
++ active_confine_requires_warp = 0;
++
++ sx = cursor->x + c->geom.x;
++ sy = cursor->y + c->geom.y;
++
++ if (!pixman_region32_contains_point(region,
++ floor(sx), floor(sy), NULL)) {
++ int nboxes;
++ pixman_box32_t *boxes = pixman_region32_rectangles(region, &nboxes);
++ if (nboxes > 0) {
++ sx = (boxes[0].x1 + boxes[0].x2) / 2.;
++ sy = (boxes[0].y1 + boxes[0].y2) / 2.;
++
++ wlr_cursor_warp_closest(cursor, NULL,
++ sx - c->geom.x, sy - c->geom.y);
++ }
++ }
++ }
++
++ /* A locked pointer will result in an empty region, thus disallowing all movement. */
++ if (constraint->type == WLR_POINTER_CONSTRAINT_V1_CONFINED) {
++ pixman_region32_copy(&active_confine, region);
++ } else {
++ pixman_region32_clear(&active_confine);
++ }
++}
++
+ void
+ chvt(const Arg *arg)
+ {
+@@ -785,6 +848,12 @@ createdecoration(struct wl_listener *listener, void *data)
+ wlr_xdg_toplevel_decoration_v1_set_mode(dec, WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
+ }
+
++void
++commitpointerconstraint(struct wl_listener *listener, void *data)
++{
++ checkconstraintregion();
++}
++
+ void
+ createidleinhibitor(struct wl_listener *listener, void *data)
+ {
+@@ -1060,6 +1129,74 @@ createpointer(struct wlr_pointer *pointer)
+ wlr_cursor_attach_input_device(cursor, &pointer->base);
+ }
+
++void
++createpointerconstraint(struct wl_listener *listener, void *data)
++{
++ struct wlr_pointer_constraint_v1 *wlr_constraint = data;
++ PointerConstraint *constraint = ecalloc(1, sizeof(*constraint));
++ Client *c = NULL, *sel = focustop(selmon);
++ toplevel_from_wlr_surface(wlr_constraint->surface, &c, NULL);
++ constraint->constraint = wlr_constraint;
++ wlr_constraint->data = constraint;
++
++ LISTEN(&wlr_constraint->events.set_region, &constraint->set_region,
++ pointerconstraintsetregion);
++ LISTEN(&wlr_constraint->events.destroy, &constraint->destroy,
++ destroypointerconstraint);
++
++ if (c == sel)
++ cursorconstrain(wlr_constraint);
++}
++
++void
++cursorconstrain(struct wlr_pointer_constraint_v1 *wlr_constraint)
++{
++ PointerConstraint *constraint = wlr_constraint->data;
++
++ if (active_constraint == constraint)
++ return;
++
++ wl_list_remove(&pointer_constraint_commit.link);
++ if (active_constraint) {
++ if (!wlr_constraint)
++ cursorwarptoconstrainthint();
++
++ wlr_pointer_constraint_v1_send_deactivated(active_constraint->constraint);
++ }
++
++ active_constraint = constraint;
++
++ if (!wlr_constraint) {
++ wl_list_init(&pointer_constraint_commit.link);
++ return;
++ }
++
++ active_confine_requires_warp = 1;
++
++ /* Stolen from sway/input/cursor.c:1435
++ *
++ * FIXME: Big hack, stolen from wlr_pointer_constraints_v1.c:121.
++ * This is necessary because the focus may be set before the surface
++ * has finished committing, which means that warping won't work properly,
++ * since this code will be run *after* the focus has been set.
++ * That is why we duplicate the code here.
++ */
++ if (pixman_region32_not_empty(&wlr_constraint->current.region)) {
++ pixman_region32_intersect(&wlr_constraint->region,
++ &wlr_constraint->surface->input_region, &wlr_constraint->current.region);
++ } else {
++ pixman_region32_copy(&wlr_constraint->region,
++ &wlr_constraint->surface->input_region);
++ }
++
++ checkconstraintregion();
++
++ wlr_pointer_constraint_v1_send_activated(wlr_constraint);
++
++ LISTEN(&wlr_constraint->surface->events.commit, &pointer_constraint_commit,
++ commitpointerconstraint);
++}
++
+ void
+ cursorframe(struct wl_listener *listener, void *data)
+ {
+@@ -1071,6 +1208,32 @@ cursorframe(struct wl_listener *listener, void *data)
+ wlr_seat_pointer_notify_frame(seat);
+ }
+
++void
++cursorwarptoconstrainthint(void)
++{
++ struct wlr_pointer_constraint_v1 *constraint = active_constraint->constraint;
++
++ if (constraint->current.committed &
++ WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) {
++ double lx, ly;
++ double sx = lx = constraint->current.cursor_hint.x;
++ double sy = ly = constraint->current.cursor_hint.y;
++
++ Client *c = NULL;
++ toplevel_from_wlr_surface(constraint->surface, &c, NULL);
++ if (c) {
++ lx -= c->geom.x;
++ ly -= c->geom.y;
++ }
++
++ wlr_cursor_warp(cursor, NULL, lx, ly);
++
++ /* Warp the pointer as well, so that on the next pointer rebase we don't
++ * send an unexpected synthetic motion event to clients. */
++ wlr_seat_pointer_warp(seat, sx, sy);
++ }
++}
++
+ void
+ destroydragicon(struct wl_listener *listener, void *data)
+ {
+@@ -1078,7 +1241,7 @@ destroydragicon(struct wl_listener *listener, void *data)
+ wlr_scene_node_destroy(icon->data);
+ /* Focus enter isn't sent during drag, so refocus the focused node. */
+ focusclient(focustop(selmon), 1);
+- motionnotify(0);
++ motionnotify(0, NULL, 0, 0, 0, 0);
+ }
+
+ void
+@@ -1113,7 +1276,7 @@ destroylock(SessionLock *lock, int unlock)
+ wlr_scene_node_set_enabled(&locked_bg->node, 0);
+
+ focusclient(focustop(selmon), 0);
+- motionnotify(0);
++ motionnotify(0, NULL, 0, 0, 0, 0);
+
+ destroy:
+ wl_list_remove(&lock->new_surface.link);
+@@ -1166,6 +1329,26 @@ destroynotify(struct wl_listener *listener, void *data)
+ free(c);
+ }
+
++void
++destroypointerconstraint(struct wl_listener *listener, void *data)
++{
++ PointerConstraint *constraint = wl_container_of(listener, constraint, destroy);
++ wl_list_remove(&constraint->set_region.link);
++ wl_list_remove(&constraint->destroy.link);
++
++ if (active_constraint == constraint) {
++ cursorwarptoconstrainthint();
++
++ if (pointer_constraint_commit.link.next)
++ wl_list_remove(&pointer_constraint_commit.link);
++
++ wl_list_init(&pointer_constraint_commit.link);
++ active_constraint = NULL;
++ }
++
++ free(constraint);
++}
++
+ void
+ destroysessionlock(struct wl_listener *listener, void *data)
+ {
+@@ -1258,7 +1441,7 @@ focusclient(Client *c, int lift)
+ }
+
+ /* Change cursor surface */
+- motionnotify(0);
++ motionnotify(0, NULL, 0, 0, 0, 0);
+
+ /* Have a client, so focus its top-level wlr_surface */
+ client_notify_enter(client_surface(c), wlr_seat_get_keyboard(seat));
+@@ -1501,7 +1684,7 @@ maplayersurfacenotify(struct wl_listener *listener, void *data)
+ {
+ LayerSurface *l = wl_container_of(listener, l, map);
+ wlr_surface_send_enter(l->layer_surface->surface, l->mon->wlr_output);
+- motionnotify(0);
++ motionnotify(0, NULL, 0, 0, 0, 0);
+ }
+
+ void
+@@ -1612,22 +1795,62 @@ motionabsolute(struct wl_listener *listener, void *data)
+ * 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;
+- wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y);
+- motionnotify(event->time_msec);
++ double lx, ly, 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
+-motionnotify(uint32_t time)
++motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
++ double dx_unaccel, double dy_unaccel)
+ {
+ double sx = 0, sy = 0;
++ double sx_confined, sy_confined;
+ Client *c = NULL, *w = NULL;
+ LayerSurface *l = NULL;
+ int type;
+ struct wlr_surface *surface = NULL;
+ struct wlr_drag_icon *icon;
++ struct wlr_pointer_constraint_v1 *constraint = NULL;
++
++ /* 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) {
++ if ((type = toplevel_from_wlr_surface(
++ seat->pointer_state.focused_surface, &w, &l)) >= 0) {
++ c = w;
++ surface = seat->pointer_state.focused_surface;
++ sx = cursor->x - (type == LayerShell ? l->geom.x : w->geom.x);
++ sy = cursor->y - (type == LayerShell ? l->geom.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);
++
++ wl_list_for_each(constraint, &pointer_constraints->constraints, link)
++ cursorconstrain(constraint);
++
++ if (active_constraint) {
++ constraint = active_constraint->constraint;
++ if (constraint->surface == surface
++ && wlr_region_confine(&active_confine, sx, sy, sx + dx,
++ sy + dy, &sx_confined, &sy_confined)) {
++ dx = sx_confined - sx;
++ dy = sy_confined - sy;
++ } else {
++ return;
++ }
++ }
++ wlr_cursor_move(cursor, device, dx, dy);
++
+ IDLE_NOTIFY_ACTIVITY;
+
+ /* Update selmon (even while dragging a window) */
+@@ -1651,19 +1874,6 @@ motionnotify(uint32_t time)
+ return;
+ }
+
+- /* 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) {
+- if ((type = toplevel_from_wlr_surface(
+- seat->pointer_state.focused_surface, &w, &l)) >= 0) {
+- c = w;
+- surface = seat->pointer_state.focused_surface;
+- sx = cursor->x - (type == LayerShell ? l->geom.x : w->geom.x);
+- sy = cursor->y - (type == LayerShell ? l->geom.y : w->geom.y);
+- }
+- }
+-
+ /* 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. */
+@@ -1684,8 +1894,8 @@ motionrelative(struct wl_listener *listener, void *data)
+ * 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. */
+- wlr_cursor_move(cursor, &event->pointer->base, event->delta_x, event->delta_y);
+- motionnotify(event->time_msec);
++ motionnotify(event->time_msec, &event->pointer->base, event->delta_x, event->delta_y,
++ event->unaccel_dx, event->unaccel_dy);
+ }
+
+ void
+@@ -1787,6 +1997,14 @@ outputmgrtest(struct wl_listener *listener, void *data)
+ outputmgrapplyortest(config, 1);
+ }
+
++void
++pointerconstraintsetregion(struct wl_listener *listener, void *data)
++{
++ PointerConstraint *constraint = wl_container_of(listener, constraint, set_region);
++ active_confine_requires_warp = 1;
++ constraint->constraint->surface->data = NULL;
++}
++
+ void
+ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
+ uint32_t time)
+@@ -2288,6 +2506,11 @@ setup(void)
+ wl_signal_add(&output_mgr->events.apply, &output_mgr_apply);
+ wl_signal_add(&output_mgr->events.test, &output_mgr_test);
+
++ relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy);
++ pointer_constraints = wlr_pointer_constraints_v1_create(dpy);
++ wl_signal_add(&pointer_constraints->events.new_constraint, &new_pointer_constraint);
++ wl_list_init(&pointer_constraint_commit.link);
++
+ wlr_scene_set_presentation(scene, wlr_presentation_create(dpy, backend));
+ wl_global_create(dpy, &zdwl_manager_v1_interface, 2, NULL, dwl_manager_bind);
+
+@@ -2327,7 +2550,7 @@ startdrag(struct wl_listener *listener, void *data)
+ return;
+
+ drag->icon->data = wlr_scene_subsurface_tree_create(layers[LyrDragIcon], drag->icon->surface);
+- motionnotify(0);
++ motionnotify(0, NULL, 0, 0, 0, 0);
+ wl_signal_add(&drag->icon->events.destroy, &drag_icon_destroy);
+ }
+
+@@ -2452,7 +2675,7 @@ unmaplayersurfacenotify(struct wl_listener *listener, void *data)
+ if (layersurface->layer_surface->surface ==
+ seat->keyboard_state.focused_surface)
+ focusclient(focustop(selmon), 1);
+- motionnotify(0);
++ motionnotify(0, NULL, 0, 0, 0, 0);
+ }
+
+ void
+@@ -2479,7 +2702,7 @@ unmapnotify(struct wl_listener *listener, void *data)
+ wl_list_remove(&c->commit.link);
+ wlr_scene_node_destroy(&c->scene->node);
+ printstatus();
+- motionnotify(0);
++ motionnotify(0, NULL, 0, 0, 0, 0);
+ }
+
+ void
diff --git a/protocols/dwl-bar-ipc-unstable-v1.xml b/protocols/dwl-bar-ipc-unstable-v1.xml
new file mode 100644
index 0000000..9c15246
--- /dev/null
+++ b/protocols/dwl-bar-ipc-unstable-v1.xml
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+This is largely ripped from somebar's ipc patchset; just with some personal modifications.
+I would probably just submit raphi's patchset but I don't think that would be polite.
+-->
+<protocol name="dwl_bar_ipc_unstable_v1">
+ <description summary="inter-proccess-communication about dwl's state">
+ This protocol allows clients to get updates from dwl and vice versa.
+
+ Warning! The protocol described in this file is experimental and
+ backward incompatible changes may be made. Backward compatible
+ changes may be added together with the corresponding interface
+ version bump.
+ Backward incompatible changes are done by bumping the version
+ number in the protocol and interface names and resetting the
+ interface version. Once the protocol is to be declared stable,
+ the 'z' prefix and the version number in the protocol and
+ interface names are removed and the interface version number is
+ reset.
+ </description>
+
+ <interface name="zdwl_manager_v1" version="2">
+ <description summary="manage dwl state">
+ This interface is exposed as a global in wl_registry.
+
+ Clients can use this interface to get a dwl_output.
+ After binding the client will revieve dwl_manager.tag and dwl_manager.layout events.
+ The dwl_manager.tag and dwl_manager.layout events expose tags and layouts to the client.
+ </description>
+
+ <request name="release" type="destructor">
+ <description summary="release dwl_manager">
+ Indicates that the client will not the dwl_manager object anymore.
+ Objects created through this instance are not affected.
+ </description>
+ </request>
+
+ <request name="get_output">
+ <description summary="get a dwl_output for a wl_output">
+ Get a dwl_output for the specified wl_output.
+ </description>
+ <arg name="id" type="new_id" interface="zdwl_output_v1"/>
+ <arg name="output" type="object" interface="wl_output"/>
+ </request>
+
+ <event name="tag">
+ <description summary="Announces a tag">
+ This event is sent after binding.
+ A roundtrip after binding guarantees the client recieved all tags.
+ </description>
+ <arg name="name" type="string"/>
+ </event>
+
+ <event name="layout">
+ <description summary="Announces a layout">
+ This event is sent after binding.
+ A roundtrip after binding guarantees the client recieved all layouts.
+ </description>
+ <arg name="name" type="string"/>
+ </event>
+ </interface>
+
+ <interface name="zdwl_output_v1" version="2">
+ <description summary="control dwl output">
+ Observe and control a dwl output.
+
+ Events are double-buffered:
+ Clients should cache events and redraw when a dwl_output.done event is sent.
+
+ Request are not double-buffered:
+ The compositor will update immediately upon request.
+ </description>
+
+ <enum name="tag_state">
+ <entry name="none" value="0" summary="no state"/>
+ <entry name="active" value="1" summary="tag is active"/>
+ <entry name="urgent" value="2" summary="tag has at least one urgent client"/>
+ </enum>
+
+ <request name="release" type="destructor">
+ <description summary="release dwl_output">
+ Indicates to that the client no longer needs this dwl_output.
+ </description>
+ </request>
+
+ <event name="toggle_visibility">
+ <description summary="Toggle client visibilty">
+ Indicates the client should hide or show themselves.
+ If the client is visible then hide, if hidden then show.
+ </description>
+ </event>
+
+ <event name="active">
+ <description summary="Update the selected output.">
+ Indicates if the output is active. Zero is invalid, nonzero is valid.
+ </description>
+ <arg name="active" type="uint"/>
+ </event>
+
+ <event name="tag">
+ <description summary="Update the state of a tag.">
+ Indicates that a tag has been updated.
+ </description>
+ <arg name="tag" type="uint" summary="Index of the tag"/>
+ <arg name="state" type="uint" enum="tag_state" summary="The state of the tag."/>
+ <arg name="clients" type="uint" summary="The number of clients in the tag."/>
+ <arg name="focused" type="uint" summary="If there is a focused client. Nonzero being valid, zero being invalid."/>
+ </event>
+
+ <event name="layout">
+ <description summary="Update the layout.">
+ Indicates a new layout is selected.
+ </description>
+ <arg name="layout" type="uint" summary="Index of the layout."/>
+ </event>
+
+ <event name="title">
+ <description summary="Update the title.">
+ Indicates the title has changed.
+ </description>
+ <arg name="title" type="string" summary="The new title name."/>
+ </event>
+
+ <event name="appid" since="2">
+ <description summary="Update the appid.">
+ Indicates the appid has changed.
+ </description>
+ <arg name="appid" type="string" summary="The new appid."/>
+ </event>
+
+ <event name="frame">
+ <description summary="The update sequence is done.">
+ Indicates that a sequence of status updates have finished and the client should redraw.
+ </description>
+ </event>
+
+ <request name="set_layout">
+ <description summary="Set the layout of this output"/>
+ <arg name="index" type="uint" summary="index of a layout recieved by dwl_manager.layout"/>
+ </request>
+
+ <request name="set_tags">
+ <description summary="Set the active tags of this output"/>
+ <arg name="tagmask" type="uint" summary="bitmask of the tags that should be set."/>
+ <arg name="toggle_tagset" type="uint" summary="toggle the selected tagset, zero for invalid, nonzero for valid."/>
+ </request>
+
+ <request name="set_client_tags">
+ <description summary="Set the tags of the focused client.">
+ The tags are updated as follows:
+ new_tags = (current_tags AND and_tags) XOR xor_tags
+ </description>
+ <arg name="and_tags" type="uint"/>
+ <arg name="xor_tags" type="uint"/>
+ </request>
+ </interface>
+</protocol>