diff options
| -rw-r--r-- | Makefile | 19 | ||||
| -rw-r--r-- | client.h | 12 | ||||
| -rw-r--r-- | config.def.h | 234 | ||||
| -rw-r--r-- | drwl.h | 311 | ||||
| -rw-r--r-- | dwl-ipc-unstable-v2.xml | 181 | ||||
| -rw-r--r-- | dwl.c | 1196 | ||||
| -rw-r--r-- | protocols/dwl-ipc-unstable-v2.xml | 181 |
7 files changed, 1948 insertions, 186 deletions
@@ -11,18 +11,23 @@ DWLDEVCFLAGS = -g -Wpedantic -Wall -Wextra -Wdeclaration-after-statement \ -Werror=implicit -Werror=return-type -Werror=incompatible-pointer-types \ -Wfloat-conversion +LDFLAGS = -flto -march=native +CFLAGS = -flto -march=native + # CFLAGS / LDFLAGS -PKGS = wayland-server xkbcommon libinput $(XLIBS) +PKGS = wayland-server xkbcommon libinput pixman-1 fcft $(XLIBS) DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(WLR_INCS) $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS) LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(WLR_LIBS) -lm $(LIBS) all: dwl -dwl: dwl.o util.o - $(CC) dwl.o util.o $(DWLCFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ +dwl: dwl.o util.o dwl-ipc-unstable-v2-protocol.o + $(CC) dwl.o util.o dwl-ipc-unstable-v2-protocol.o $(DWLCFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ dwl.o: dwl.c client.h config.h config.mk cursor-shape-v1-protocol.h \ pointer-constraints-unstable-v1-protocol.h wlr-layer-shell-unstable-v1-protocol.h \ - wlr-output-power-management-unstable-v1-protocol.h xdg-shell-protocol.h + wlr-output-power-management-unstable-v1-protocol.h xdg-shell-protocol.h \ + dwl-ipc-unstable-v2-protocol.h util.o: util.c util.h +dwl-ipc-unstable-v2-protocol.o: dwl-ipc-unstable-v2-protocol.c dwl-ipc-unstable-v2-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 @@ -45,6 +50,12 @@ wlr-output-power-management-unstable-v1-protocol.h: xdg-shell-protocol.h: $(WAYLAND_SCANNER) server-header \ $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@ +dwl-ipc-unstable-v2-protocol.h: + $(WAYLAND_SCANNER) server-header \ + protocols/dwl-ipc-unstable-v2.xml $@ +dwl-ipc-unstable-v2-protocol.c: + $(WAYLAND_SCANNER) private-code \ + protocols/dwl-ipc-unstable-v2.xml $@ config.h: cp config.def.h $@ @@ -131,6 +131,18 @@ client_get_appid(Client *c) return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id : "broken"; } +static inline int +client_get_pid(Client *c) +{ + pid_t pid; +#ifdef XWAYLAND + if (client_is_x11(c)) + return c->surface.xwayland->pid; +#endif + wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL); + return pid; +} + static inline void client_get_clip(Client *c, struct wlr_box *clip) { diff --git a/config.def.h b/config.def.h index 8a6eda0..d9163f7 100644 --- a/config.def.h +++ b/config.def.h @@ -3,29 +3,68 @@ ((hex >> 16) & 0xFF) / 255.0f, \ ((hex >> 8) & 0xFF) / 255.0f, \ (hex & 0xFF) / 255.0f } + +#define TERMINAL "foot" + /* appearance */ static const int sloppyfocus = 1; /* focus follows mouse */ +static const int mousefollowsfocus = 1; /* mouse follows focus */ 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 = 1; /* border pixel of windows */ -static const float rootcolor[] = COLOR(0x222222ff); -static const float bordercolor[] = COLOR(0x444444ff); -static const float focuscolor[] = COLOR(0x005577ff); -static const float urgentcolor[] = COLOR(0xff0000ff); +static const int smartborders = 1; +static const unsigned int borderpx = 2; /* border pixel of windows */ +static const unsigned int gappx = 5; /* default gap size */ +static const int showbar = 1; /* 0 means no bar */ +static const int topbar = 1; /* 0 means bottom bar */ +static const char *fonts[] = {"monospace:size=10"}; +static const float rootcolor[] = COLOR(0x000000ff); /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You can also use glsl colors */ -/* tagging - TAGCOUNT must be no greater than 31 */ -#define TAGCOUNT (9) +static const uint32_t col_border = 0x4f5b58ff; + +static const uint32_t col_fg = 0xd3c6aaff; +static const uint32_t col_fg_sel = 0xa7c080ff; + +static const uint32_t col_bg = 0x272e33ff; +static const uint32_t col_bg_sel = 0x3c4841ff; + +static const uint32_t col_sel = 0x323437ff; +static const uint32_t col_red = 0xe67e80ff; + +static uint32_t colors[][3] = { + /* fg bg border */ + [SchemeNorm] = { col_fg, col_bg, col_border }, + [SchemeSel] = { col_fg_sel, col_bg_sel, col_fg_sel }, + [SchemeTagSel] = { col_bg, col_fg_sel, col_border }, + [SchemeUrg] = { 0, 0, col_red }, +}; + +static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; /* logging */ static int log_level = WLR_ERROR; +/* Autostart */ +static const char *const autostart[] = { + "swaybg", "-m", "fill", "-i", "pictures/bg/default.png", NULL, + "mako", NULL, + NULL /* terminate */ +}; + + +/* NOTE: ALWAYS keep a rule declared even if you don't use rules (e.g leave at least one example) */ +#define TAG(t) (1 << (t - 1)) static const Rule rules[] = { - /* app_id title tags mask isfloating monitor */ - { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */ - { "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */ - /* default/example rule: can be changed but cannot be eliminated; at least one rule must exist */ + /* app_id title tags mask iscentered isfloating isterm noswallow monitor scratchkey */ + /* examples: */ + { "Gimp", NULL, TAG(9), 0, 1, 0, 0, -1, 0 }, /* Start on currently visible tags floating, not tiled */ + { "firefox", NULL, TAG(2), 0, 0, 0, 0, -1, 0 }, /* Start on ONLY tag "9" */ + { NULL, "rogue", 0, 1, 0, 0, 0, -1, 0 }, /* Start on ONLY tag "9" */ + { TERMINAL, NULL, 0, 0, 0, 1, 1, -1, 0 }, /* Start on ONLY tag "9" */ + { NULL, "scratchpad", 0, 1, 1, 1, 1, -1, 's' }, /* Used for terminal scratchpad */ + { NULL, "spadcalc", 0, 1, 1, 1, 0, -1, 'c' }, /* Used for terminal scratchpad */ }; +#undef TAG /* layout(s) */ static const Layout layouts[] = { @@ -40,11 +79,12 @@ static const Layout layouts[] = { * WARNING: negative values other than (-1, -1) cause problems with Xwayland clients due to * https://gitlab.freedesktop.org/xorg/xserver/-/issues/899 */ static const MonitorRule monrules[] = { - /* name mfact nmaster scale layout rotate/reflect x y - * example of a HiDPI laptop monitor: - { "eDP-1", 0.5f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, */ - { NULL, 0.55f, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, - /* default monitor rule: can be changed but cannot be eliminated; at least one monitor rule must exist */ + /* name mfact nmaster scale layout rotate/reflect x y */ + /* example of a HiDPI laptop monitor: + { "eDP-1", 0.5f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, + */ + /* defaults */ + { NULL, 0.55f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, }; /* keyboard */ @@ -53,15 +93,15 @@ static const struct xkb_rule_names xkb_rules = { /* example: .options = "ctrl:nocaps", */ - .options = NULL, + .options = "compose:ralt,caps:escape", }; -static const int repeat_rate = 25; -static const int repeat_delay = 600; +static const int repeat_rate = 50; +static const int repeat_delay = 190; /* Trackpad */ -static const int tap_to_click = 1; -static const int tap_and_drag = 1; +static const int tap_to_click = 0; +static const int tap_and_drag = 0; static const int drag_lock = 1; static const int natural_scrolling = 0; static const int disable_while_typing = 1; @@ -93,7 +133,7 @@ static const uint32_t send_events_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; 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 enum libinput_config_accel_profile accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; static const double accel_speed = 0.0; /* You can choose between: @@ -103,7 +143,7 @@ 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_ALT +#define MODKEY WLR_MODIFIER_LOGO #define TAGKEYS(KEY,SKEY,TAG) \ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ @@ -112,48 +152,105 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA { 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 } } +#define SHCMD(cmd) { .v = (const char*[]){ "/bin/zsh", "-f", "-c", cmd, NULL } } /* commands */ -static const char *termcmd[] = { "foot", NULL }; -static const char *menucmd[] = { "wmenu-run", NULL }; +static const char *browsercmd[] = {"firefox-developer-edition", NULL}; +static const char *browsercmd_p[] = {"firefox-developer-edition", "-P", NULL}; +static const char *menucmd[] = { "bemenu_run_history", "-p", "$", NULL }; +static const char *termcmd[] = { TERMINAL, "-d", "none", NULL }; + +/* named scratchpads - First arg only serves to match against key in rules*/ +static const char *scratchpadcmd[] = { "s", TERMINAL, "-d", "none", "-T", "scratchpad", "-a", "scratchpad", NULL }; +static const char *scratchpadcalc[] = { "c", TERMINAL, "-d", "none", "-T", "spcalc", "-a", "spcalc", "-e", "bc", "-lq", NULL}; static const Key keys[] = { - /* Note that Shift changes certain key codes: 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, 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.05f} }, - { MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} }, - { 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} }, + /* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */ + /* modifier key function argument */ + { MODKEY, XKB_KEY_d, spawn, {.v = menucmd} }, + { MODKEY, XKB_KEY_Return, spawn, {.v = termcmd} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, togglescratch, {.v = scratchpadcmd} }, + { MODKEY, XKB_KEY_apostrophe, togglescratch, {.v = scratchpadcalc} }, + { MODKEY, XKB_KEY_b, togglebar, {0} }, + { MODKEY, XKB_KEY_j, focusstack, {.i = +1} }, + { MODKEY, XKB_KEY_k, focusstack, {.i = -1} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_J, movestack, {.i = +1} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_K, movestack, {.i = -1} }, + { MODKEY, XKB_KEY_v, focusstack, {.i = 0} }, + { MODKEY, XKB_KEY_b, focusstack, {.i = INT_MAX} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_V, movestack, {.i = 0} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_B, movestack, {.i = INT_MAX} }, + { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_I, incnmaster, {.i = -1} }, + { MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} }, + { MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} }, + { MODKEY, XKB_KEY_Return, zoom, {0} }, + { MODKEY, XKB_KEY_Tab, view, {0} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Q, 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_f, togglefullscreen, {0} }, + { MODKEY, XKB_KEY_s, togglesticky, {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} }, + + + /* Programs */ + { MODKEY, XKB_KEY_x, spawn, SHCMD("swaylock") }, + { 0, XKB_KEY_Print, spawn, SHCMD("grim -g \"$(slurp)\" - | tee screenshot.png | wl-copy -t image/png") }, + { MODKEY, XKB_KEY_Insert, spawn, SHCMD("notify-send \"Clipboard contents\" \"$(wl-paste -n)\"") }, + { MODKEY, XKB_KEY_g, spawn, SHCMD("emoji") }, + + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_E, spawn, SHCMD(TERMINAL " -d none nmtui") }, + { MODKEY, XKB_KEY_e, spawn, SHCMD(TERMINAL " -d none btop") }, + + { MODKEY, XKB_KEY_w, spawn, {.v = browsercmd} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_W, spawn, {.v = browsercmd_p} }, + + { MODKEY, XKB_KEY_z, spawn, SHCMD("zathura") }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Z, spawn, SHCMD(TERMINAL " -d none open_book") }, + { MODKEY, XKB_KEY_m, spawn, SHCMD("open_man") }, + + /* Audio controls */ + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_M, spawn, SHCMD("pamixer -t && status_ctl update vol") }, + { 0, XKB_KEY_XF86AudioMute, spawn, SHCMD("pamixer -t && status_ctl update vol") }, + { 0, XKB_KEY_XF86AudioRaiseVolume, spawn,SHCMD("pamixer --allow-boost -i 5 && status_ctl update vol") }, + { 0, XKB_KEY_XF86AudioLowerVolume, spawn,SHCMD("pamixer --allow-boost -d 5 && status_ctl update vol") }, + { MODKEY, XKB_KEY_bracketright, spawn, SHCMD("pamixer --allow-boost -i 5 && status_ctl update vol") }, + { MODKEY, XKB_KEY_bracketleft, spawn, SHCMD("pamixer --allow-boost -d 5 && status_ctl update vol") }, + + /* Monitor brightness controls */ + { 0, XKB_KEY_XF86MonBrightnessUp, spawn,SHCMD("brightnessctl s 10%+") }, + { 0, XKB_KEY_XF86MonBrightnessDown,spawn,SHCMD("brightnessctl s 10%-") }, + + /* Notification controls */ + { WLR_MODIFIER_CTRL, XKB_KEY_space, spawn, SHCMD("makoctl dismiss")}, + { WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT, XKB_KEY_space, spawn, SHCMD("makoctl dismiss --all")}, + { WLR_MODIFIER_CTRL|MODKEY, XKB_KEY_space, spawn, SHCMD("makoctl restore")}, + + /* Adjust gaps */ + { MODKEY, XKB_KEY_minus, setgaps, {.i = -1} }, + { MODKEY, XKB_KEY_equal, setgaps, {.i = +1} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_plus, setgaps, {.i = 0} }, + { MODKEY, XKB_KEY_a, togglegaps, {0} }, + + 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_BackSpace, 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} }, @@ -163,10 +260,19 @@ static const Key keys[] = { #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), +#undef CHVT }; static const Button buttons[] = { - { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} }, - { MODKEY, BTN_MIDDLE, togglefloating, {0} }, - { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} }, + { ClkLtSymbol, 0, BTN_LEFT, setlayout, {.v = &layouts[0]} }, + { ClkLtSymbol, 0, BTN_RIGHT, setlayout, {.v = &layouts[2]} }, + { ClkTitle, 0, BTN_MIDDLE, zoom, {0} }, + { ClkStatus, 0, BTN_MIDDLE, spawn, {.v = termcmd} }, + { ClkClient, MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} }, + { ClkClient, MODKEY, BTN_MIDDLE, togglefloating, {0} }, + { ClkClient, MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} }, + { ClkTagBar, 0, BTN_LEFT, view, {0} }, + { ClkTagBar, 0, BTN_RIGHT, toggleview, {0} }, + { ClkTagBar, MODKEY, BTN_LEFT, tag, {0} }, + { ClkTagBar, MODKEY, BTN_RIGHT, toggletag, {0} }, }; @@ -0,0 +1,311 @@ +/* + * drwl - https://codeberg.org/sewn/drwl + * + * Copyright (c) 2023-2024 sewn <sewn@disroot.org> + * Copyright (c) 2024 notchoc <notchoc@disroot.org> + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The UTF-8 Decoder included is from Bjoern Hoehrmann: + * Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de> + * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details. + */ +#pragma once + +#include <stdlib.h> +#include <fcft/fcft.h> +#include <pixman-1/pixman.h> + +enum { ColFg, ColBg, ColBorder }; /* colorscheme index */ + +typedef struct fcft_font Fnt; +typedef pixman_image_t Img; + +typedef struct { + Img *image; + Fnt *font; + uint32_t *scheme; +} Drwl; + +#define UTF8_ACCEPT 0 +#define UTF8_REJECT 12 +#define UTF8_INVALID 0xFFFD + +static const uint8_t utf8d[] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8, + + 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12, + 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12, + 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12, + 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12, + 12,36,12,12,12,12,12,12,12,12,12,12, +}; + +static inline uint32_t +utf8decode(uint32_t *state, uint32_t *codep, uint8_t byte) +{ + uint32_t type = utf8d[byte]; + + *codep = (*state != UTF8_ACCEPT) ? + (byte & 0x3fu) | (*codep << 6) : + (0xff >> type) & (byte); + + *state = utf8d[256 + *state + type]; + return *state; +} + +static int +drwl_init(void) +{ + fcft_set_scaling_filter(FCFT_SCALING_FILTER_LANCZOS3); + return fcft_init(FCFT_LOG_COLORIZE_AUTO, 0, FCFT_LOG_CLASS_ERROR); +} + +static Drwl * +drwl_create(void) +{ + Drwl *drwl; + + if (!(drwl = calloc(1, sizeof(Drwl)))) + return NULL; + + return drwl; +} + +static void +drwl_setfont(Drwl *drwl, Fnt *font) +{ + if (drwl) + drwl->font = font; +} + +static void +drwl_setimage(Drwl *drwl, Img *image) +{ + if (drwl) + drwl->image = image; +} + +static Fnt * +drwl_font_create(Drwl *drwl, size_t count, + const char *names[static count], const char *attributes) +{ + Fnt *font = fcft_from_name(count, names, attributes); + if (drwl) + drwl_setfont(drwl, font); + return font; +} + +static void +drwl_font_destroy(Fnt *font) +{ + fcft_destroy(font); +} + +static inline pixman_color_t +convert_color(uint32_t clr) +{ + return (pixman_color_t){ + ((clr >> 24) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF, + ((clr >> 16) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF, + ((clr >> 8) & 0xFF) * 0x101 * (clr & 0xFF) / 0xFF, + (clr & 0xFF) * 0x101 + }; +} + +static void +drwl_setscheme(Drwl *drwl, uint32_t *scm) +{ + if (drwl) + drwl->scheme = scm; +} + +static Img * +drwl_image_create(Drwl *drwl, unsigned int w, unsigned int h, uint32_t *bits) +{ + Img *image; + pixman_region32_t clip; + + image = pixman_image_create_bits_no_clear( + PIXMAN_a8r8g8b8, w, h, bits, w * 4); + if (!image) + return NULL; + pixman_region32_init_rect(&clip, 0, 0, w, h); + pixman_image_set_clip_region32(image, &clip); + pixman_region32_fini(&clip); + + if (drwl) + drwl_setimage(drwl, image); + return image; +} + +static void +drwl_rect(Drwl *drwl, + int x, int y, unsigned int w, unsigned int h, + int filled, int invert) +{ + pixman_color_t clr; + if (!drwl || !drwl->scheme || !drwl->image) + return; + + clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]); + if (filled) + pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 1, + &(pixman_rectangle16_t){x, y, w, h}); + else + pixman_image_fill_rectangles(PIXMAN_OP_SRC, drwl->image, &clr, 4, + (pixman_rectangle16_t[4]){ + { x, y, w, 1 }, + { x, y + h - 1, w, 1 }, + { x, y, 1, h }, + { x + w - 1, y, 1, h }}); +} + +static int +drwl_text(Drwl *drwl, + int x, int y, unsigned int w, unsigned int h, + unsigned int lpad, const char *text, int invert) +{ + int ty; + int render = x || y || w || h; + long x_kern; + uint32_t cp = 0, last_cp = 0, state; + pixman_color_t clr; + pixman_image_t *fg_pix = NULL; + int noellipsis = 0; + const struct fcft_glyph *glyph, *eg = NULL; + int fcft_subpixel_mode = FCFT_SUBPIXEL_DEFAULT; + + if (!drwl || (render && (!drwl->scheme || !w || !drwl->image)) || !text || !drwl->font) + return 0; + + if (!render) { + w = invert ? invert : ~invert; + } else { + clr = convert_color(drwl->scheme[invert ? ColBg : ColFg]); + fg_pix = pixman_image_create_solid_fill(&clr); + + drwl_rect(drwl, x, y, w, h, 1, !invert); + + x += lpad; + w -= lpad; + } + + if (render && (drwl->scheme[ColBg] & 0xFF) != 0xFF) + fcft_subpixel_mode = FCFT_SUBPIXEL_NONE; + + if (render) + eg = fcft_rasterize_char_utf32(drwl->font, 0x2026 /* … */, fcft_subpixel_mode); + + for (const char *p = text, *pp; pp = p, *p; p++) { + for (state = UTF8_ACCEPT; *p && + utf8decode(&state, &cp, *p) > UTF8_REJECT; p++) + ; + if (!*p || state == UTF8_REJECT) { + cp = UTF8_INVALID; + if (p > pp) + p--; + } + + glyph = fcft_rasterize_char_utf32(drwl->font, cp, fcft_subpixel_mode); + if (!glyph) + continue; + + x_kern = 0; + if (last_cp) + fcft_kerning(drwl->font, last_cp, cp, &x_kern, NULL); + last_cp = cp; + + ty = y + (h - drwl->font->height) / 2 + drwl->font->ascent; + + if (render && !noellipsis && x_kern + glyph->advance.x + eg->advance.x > w && + *(p + 1) != '\0') { + /* cannot fit ellipsis after current codepoint */ + if (drwl_text(drwl, 0, 0, 0, 0, 0, pp, 0) + x_kern <= w) { + noellipsis = 1; + } else { + w -= eg->advance.x; + pixman_image_composite32( + PIXMAN_OP_OVER, fg_pix, eg->pix, drwl->image, 0, 0, 0, 0, + x + eg->x, ty - eg->y, eg->width, eg->height); + } + } + + if ((x_kern + glyph->advance.x) > w) + break; + + x += x_kern; + + if (render && pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8) + /* pre-rendered glyphs (eg. emoji) */ + pixman_image_composite32( + PIXMAN_OP_OVER, glyph->pix, NULL, drwl->image, 0, 0, 0, 0, + x + glyph->x, ty - glyph->y, glyph->width, glyph->height); + else if (render) + pixman_image_composite32( + PIXMAN_OP_OVER, fg_pix, glyph->pix, drwl->image, 0, 0, 0, 0, + x + glyph->x, ty - glyph->y, glyph->width, glyph->height); + + x += glyph->advance.x; + w -= glyph->advance.x; + } + + if (render) + pixman_image_unref(fg_pix); + + return x + (render ? w : 0); +} + +static unsigned int +drwl_font_getwidth(Drwl *drwl, const char *text) +{ + if (!drwl || !drwl->font || !text) + return 0; + return drwl_text(drwl, 0, 0, 0, 0, 0, text, 0); +} + +static void +drwl_image_destroy(Img *image) +{ + pixman_image_unref(image); +} + +static void +drwl_destroy(Drwl *drwl) +{ + if (drwl->font) + drwl_font_destroy(drwl->font); + if (drwl->image) + drwl_image_destroy(drwl->image); + free(drwl); +} + +static void +drwl_fini(void) +{ + fcft_fini(); +} diff --git a/dwl-ipc-unstable-v2.xml b/dwl-ipc-unstable-v2.xml new file mode 100644 index 0000000..0a6e7e5 --- /dev/null +++ b/dwl-ipc-unstable-v2.xml @@ -0,0 +1,181 @@ +<?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_ipc_unstable_v2"> + <description summary="inter-proccess-communication about dwl's state"> + This protocol allows clients to update and get updates from dwl. + + 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_ipc_manager_v2" 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_ipc_output. + After binding the client will recieve the dwl_ipc_manager.tags and dwl_ipc_manager.layout events. + The dwl_ipc_manager.tags and dwl_ipc_manager.layout events expose tags and layouts to the client. + </description> + + <request name="release" type="destructor"> + <description summary="release dwl_ipc_manager"> + Indicates that the client will not the dwl_ipc_manager object anymore. + Objects created through this instance are not affected. + </description> + </request> + + <request name="get_output"> + <description summary="get a dwl_ipc_outout for a wl_output"> + Get a dwl_ipc_outout for the specified wl_output. + </description> + <arg name="id" type="new_id" interface="zdwl_ipc_output_v2"/> + <arg name="output" type="object" interface="wl_output"/> + </request> + + <event name="tags"> + <description summary="Announces tag amount"> + This event is sent after binding. + A roundtrip after binding guarantees the client recieved all tags. + </description> + <arg name="amount" type="uint"/> + </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_ipc_output_v2" 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_ipc_output.frame 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_ipc_outout"> + Indicates to that the client no longer needs this dwl_ipc_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="1"> + <description summary="Update the appid."> + Indicates the appid has changed. + </description> + <arg name="appid" type="string" summary="The new appid."/> + </event> + + <event name="layout_symbol" since="1"> + <description summary="Update the current layout symbol"> + Indicates the layout has changed. Since layout symbols are dynamic. + As opposed to the zdwl_ipc_manager.layout event, this should take precendence when displaying. + You can ignore the zdwl_ipc_output.layout event. + </description> + <arg name="layout" type="string" summary="The new layout"/> + </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_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> + + <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_ipc_manager.layout"/> + </request> + + <!-- Version 2 --> + <event name="fullscreen" since="2"> + <description summary="Update fullscreen status"> + Indicates if the selected client on this output is fullscreen. + </description> + <arg name="is_fullscreen" type="uint" summary="If the selected client is fullscreen. Nonzero is valid, zero invalid"/> + </event> + + <event name="floating" since="2"> + <description summary="Update the floating status"> + Indicates if the selected client on this output is floating. + </description> + <arg name="is_floating" type="uint" summary="If the selected client is floating. Nonzero is valid, zero invalid"/> + </event> + </interface> +</protocol> @@ -3,11 +3,14 @@ */ #include <getopt.h> #include <libinput.h> +#include <limits.h> #include <linux/input-event-codes.h> #include <math.h> +#include <libdrm/drm_fourcc.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <sys/types.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> @@ -60,6 +63,7 @@ #include <wlr/types/wlr_xdg_decoration_v1.h> #include <wlr/types/wlr_xdg_output_v1.h> #include <wlr/types/wlr_xdg_shell.h> +#include <wlr/interfaces/wlr_buffer.h> #include <wlr/util/log.h> #include <wlr/util/region.h> #include <xkbcommon/xkbcommon.h> @@ -69,23 +73,28 @@ #include <xcb/xcb_icccm.h> #endif +#include "dwl-ipc-unstable-v2-protocol.h" #include "util.h" +#include "drwl.h" /* macros */ #define MAX(A, B) ((A) > (B) ? (A) : (B)) #define MIN(A, B) ((A) < (B) ? (A) : (B)) #define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS) -#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags])) +#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && (((C)->tags & (M)->tagset[(M)->seltags]) || C->issticky)) #define LENGTH(X) (sizeof X / sizeof X[0]) #define END(A) ((A) + LENGTH(A)) -#define TAGMASK ((1u << TAGCOUNT) - 1) +#define TAGMASK ((1u << LENGTH(tags)) - 1) #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L))) #define LISTEN_STATIC(E, H) do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0) +#define TEXTW(mon, text) (drwl_font_getwidth(mon->drw, text) + mon->lrpad) /* enums */ +enum { SchemeNorm, SchemeSel, SchemeTagSel, SchemeUrg }; /* color schemes */ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ enum { XDGShell, LayerShell, X11 }; /* client types */ enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */ +enum { ClkTagBar, ClkLtSymbol, ClkStatus, ClkTitle, ClkClient, ClkRoot }; /* clicks */ typedef union { int i; @@ -95,6 +104,7 @@ typedef union { } Arg; typedef struct { + unsigned int click; unsigned int mod; unsigned int button; void (*func)(const Arg *); @@ -102,7 +112,8 @@ typedef struct { } Button; typedef struct Monitor Monitor; -typedef struct { +typedef struct Client Client; +struct Client { /* Must keep this field first */ unsigned int type; /* XDGShell or X11* */ @@ -138,9 +149,18 @@ typedef struct { #endif unsigned int bw; uint32_t tags; - int isfloating, isurgent, isfullscreen; + int iscentered, isfloating, isurgent, isfullscreen, issticky, isterm, noswallow; + char scratchkey; uint32_t resize; /* configure serial of a pending resize */ -} Client; + pid_t pid; + Client *swallowing, *swallowedby; +}; + +typedef struct { + struct wl_list link; + struct wl_resource *resource; + Monitor *mon; +} DwlIpcOutput; typedef struct { uint32_t mod; @@ -184,10 +204,20 @@ typedef struct { void (*arrange)(Monitor *); } Layout; +typedef struct { + struct wlr_buffer base; + struct wl_listener release; + bool busy; + Img *image; + uint32_t data[]; +} Buffer; + struct Monitor { struct wl_list link; + struct wl_list dwl_ipc_outputs; struct wlr_output *wlr_output; struct wlr_scene_output *scene_output; + struct wlr_scene_buffer *scene_buffer; /* bar buffer */ struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */ struct wl_listener frame; struct wl_listener destroy; @@ -195,17 +225,26 @@ struct Monitor { struct wl_listener destroy_lock_surface; struct wlr_session_lock_surface_v1 *lock_surface; struct wlr_box m; /* monitor area, layout-relative */ + struct { + int width, height; + int real_width, real_height; /* non-scaled */ + float scale; + } b; /* bar area */ struct wlr_box w; /* window area, layout-relative */ struct wl_list layers[4]; /* LayerSurface.link */ const Layout *lt[2]; unsigned int seltags; unsigned int sellt; uint32_t tagset[2]; + int gappx; float mfact; int gamma_lut_changed; int nmaster; char ltsymbol[16]; int asleep; + Drwl *drw; + Buffer *pool[2]; + int lrpad; }; typedef struct { @@ -227,8 +266,12 @@ typedef struct { const char *id; const char *title; uint32_t tags; + int iscentered; int isfloating; + int isterm; + int noswallow; int monitor; + const char scratchkey; } Rule; typedef struct { @@ -247,7 +290,15 @@ static void arrange(Monitor *m); static void arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int exclusive); static void arrangelayers(Monitor *m); +static void autostartexec(void); static void axisnotify(struct wl_listener *listener, void *data); +static bool baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy); +static void bufdestroy(struct wlr_buffer *buffer); +static bool bufdatabegin(struct wlr_buffer *buffer, uint32_t flags, + void **data, uint32_t *format, size_t *stride); +static void bufdataend(struct wlr_buffer *buffer); +static Buffer *bufmon(Monitor *m); +static void bufrelease(struct wl_listener *listener, void *data); static void buttonpress(struct wl_listener *listener, void *data); static void chvt(const Arg *arg); static void checkidleinhibitor(struct wlr_surface *exclude); @@ -283,8 +334,23 @@ static void destroypointerconstraint(struct wl_listener *listener, void *data); static void destroysessionlock(struct wl_listener *listener, void *data); static void destroykeyboardgroup(struct wl_listener *listener, void *data); static Monitor *dirtomon(enum wlr_direction dir); +static void drawbar(Monitor *m); +static void drawbars(void); +static void dwl_ipc_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id); +static void dwl_ipc_manager_destroy(struct wl_resource *resource); +static void dwl_ipc_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output); +static void dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource); +static void dwl_ipc_output_destroy(struct wl_resource *resource); +static void dwl_ipc_output_printstatus(Monitor *monitor); +static void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output); +static void dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags); +static void dwl_ipc_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index); +static void dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset); +static void dwl_ipc_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 focusortogglematchingscratch(const Arg *arg); +static void focusortogglescratch(const Arg *arg); static void focusstack(const Arg *arg); static Client *focustop(Monitor *m); static void fullscreennotify(struct wl_listener *listener, void *data); @@ -301,6 +367,7 @@ static void locksession(struct wl_listener *listener, void *data); static void mapnotify(struct wl_listener *listener, void *data); static void maximizenotify(struct wl_listener *listener, void *data); static void monocle(Monitor *m); +static void movestack(const Arg *arg); static void motionabsolute(struct wl_listener *listener, void *data); static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx, double sy, double sx_unaccel, double sy_unaccel); @@ -311,47 +378,60 @@ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int static void outputmgrtest(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); static void powermgrsetmode(struct wl_listener *listener, void *data); static void quit(const Arg *arg); static void rendermon(struct wl_listener *listener, void *data); static void requestdecorationmode(struct wl_listener *listener, void *data); static void requeststartdrag(struct wl_listener *listener, void *data); static void requestmonstate(struct wl_listener *listener, void *data); -static void resize(Client *c, struct wlr_box geo, int interact); -static void run(char *startup_cmd); +static void resize(Client *c, struct wlr_box geo, int interact, int draw_borders); +static void run(char *startup_cmd, uid_t uid); static void setcursor(struct wl_listener *listener, void *data); static void setcursorshape(struct wl_listener *listener, void *data); static void setfloating(Client *c, int floating); static void setfullscreen(Client *c, int fullscreen); +static void setgaps(const Arg *arg); static void setlayout(const Arg *arg); static void setmfact(const Arg *arg); static void setmon(Client *c, Monitor *m, uint32_t newtags); static void setpsel(struct wl_listener *listener, void *data); static void setsel(struct wl_listener *listener, void *data); +static void setsticky(Client *c, int sticky); static void setup(void); static void spawn(const Arg *arg); +static void spawnscratch(const Arg *arg); static void startdrag(struct wl_listener *listener, void *data); +static int statusin(int fd, unsigned int mask, void *data); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *m); +static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); +static void togglesticky(const Arg *arg); static void togglefullscreen(const Arg *arg); +static void togglegaps(const Arg *arg); +static void togglescratch(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(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); static void updatemons(struct wl_listener *listener, void *data); +static void updatebar(Monitor *m); static void updatetitle(struct wl_listener *listener, void *data); static void urgent(struct wl_listener *listener, void *data); static void view(const Arg *arg); static void virtualkeyboard(struct wl_listener *listener, void *data); static void virtualpointer(struct wl_listener *listener, void *data); +static void warpcursortoclient(Client *c); static Monitor *xytomon(double x, double y); static void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc, LayerSurface **pl, double *nx, double *ny); static void zoom(const Arg *arg); +static pid_t getparentprocess(pid_t p); +static int isdescprocess(pid_t p, pid_t c); +static Client *termforwin(Client *w); +static void swallow(Client *c, Client *w); /* variables */ static pid_t child_pid = -1; @@ -407,6 +487,18 @@ static struct wlr_box sgeom; static struct wl_list mons; static Monitor *selmon; +static struct zdwl_ipc_manager_v2_interface dwl_manager_implementation = {.release = dwl_ipc_manager_release, .get_output = dwl_ipc_manager_get_output}; +static struct zdwl_ipc_output_v2_interface dwl_output_implementation = {.release = dwl_ipc_output_release, .set_tags = dwl_ipc_output_set_tags, .set_layout = dwl_ipc_output_set_layout, .set_client_tags = dwl_ipc_output_set_client_tags}; + +static char stext[256]; +static struct wl_event_source *status_event_source; + +static const struct wlr_buffer_impl buffer_impl = { + .destroy = bufdestroy, + .begin_data_ptr_access = bufdatabegin, + .end_data_ptr_access = bufdataend, +}; + /* global event handlers */ static struct wl_listener cursor_axis = {.notify = axisnotify}; static struct wl_listener cursor_button = {.notify = buttonpress}; @@ -456,6 +548,9 @@ static struct wlr_xwayland *xwayland; /* attempt to encapsulate suck into one file */ #include "client.h" +static pid_t *autostart_pids; +static size_t autostart_len; + /* function implementations */ void applybounds(Client *c, struct wlr_box *bbox) @@ -484,13 +579,21 @@ applyrules(Client *c) const Rule *r; Monitor *mon = selmon, *m; + c->isfloating = client_is_float_type(c); + c->scratchkey = 0; appid = client_get_appid(c); title = client_get_title(c); + c->pid = client_get_pid(c); + for (r = rules; r < END(rules); r++) { if ((!r->title || strstr(title, r->title)) && (!r->id || strstr(appid, r->id))) { + c->iscentered = r->iscentered; c->isfloating = r->isfloating; + c->scratchkey = r->scratchkey; + c->isterm = r->isterm; + c->noswallow = r->noswallow; newtags |= r->tags; i = 0; wl_list_for_each(m, &mons, link) { @@ -499,8 +602,27 @@ applyrules(Client *c) } } } + if (!c->noswallow && !client_is_float_type(c) + && !c->surface.xdg->initial_commit) { + Client *p = termforwin(c); + if (p) { + c->swallowedby = p; + p->swallowing = c; + wl_list_remove(&c->link); + wl_list_remove(&c->flink); + swallow(c, p); + wl_list_remove(&p->link); + wl_list_remove(&p->flink); + mon = p->mon; + newtags = p->tags; + } + } + + if (c->iscentered) { + c->geom.x = (mon->w.width - c->geom.width) / 2 + mon->m.x; + c->geom.y = (mon->w.height - c->geom.height) / 2 + mon->m.y; + } - c->isfloating |= client_is_float_type(c); setmon(c, mon, newtags); } @@ -541,6 +663,8 @@ arrange(Monitor *m) if (m->lt[m->sellt]->arrange) m->lt[m->sellt]->arrange(m); motionnotify(0, NULL, 0, 0, 0, 0); + + if (c && mousefollowsfocus) warpcursortoclient(c); checkidleinhibitor(NULL); } @@ -577,6 +701,11 @@ arrangelayers(Monitor *m) if (!m->wlr_output->enabled) return; + if (m->scene_buffer->node.enabled) { + usable_area.height -= m->b.real_height; + usable_area.y += topbar ? m->b.real_height : 0; + } + /* Arrange exclusive surfaces from top->bottom */ for (i = 3; i >= 0; i--) arrangelayer(m, &m->layers[i], &usable_area, 1); @@ -605,6 +734,27 @@ arrangelayers(Monitor *m) } void +autostartexec(void) { + const char *const *p; + size_t i = 0; + + /* count entries */ + for (p = autostart; *p; autostart_len++, p++) + while (*++p); + + autostart_pids = calloc(autostart_len, sizeof(pid_t)); + for (p = autostart; *p; i++, p++) { + if ((autostart_pids[i] = fork()) == 0) { + setsid(); + execvp(*p, (char *const *)p); + die("dwl: execvp %s:", *p); + } + /* skip arguments */ + while (*++p); + } +} + +void axisnotify(struct wl_listener *listener, void *data) { /* This event is forwarded by the cursor when a pointer emits an axis event, @@ -619,17 +769,103 @@ axisnotify(struct wl_listener *listener, void *data) event->delta_discrete, event->source, event->relative_direction); } +bool +baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy) +{ + return true; +} + +void +bufdestroy(struct wlr_buffer *wlr_buffer) +{ + Buffer *buf = wl_container_of(wlr_buffer, buf, base); + if (buf->busy) + wl_list_remove(&buf->release.link); + drwl_image_destroy(buf->image); + free(buf); +} + +bool +bufdatabegin(struct wlr_buffer *wlr_buffer, uint32_t flags, + void **data, uint32_t *format, size_t *stride) +{ + Buffer *buf = wl_container_of(wlr_buffer, buf, base); + + if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) return false; + + *data = buf->data; + *stride = wlr_buffer->width * 4; + *format = DRM_FORMAT_ARGB8888; + + return true; +} + +void +bufdataend(struct wlr_buffer *wlr_buffer) +{ +} + +Buffer * +bufmon(Monitor *m) +{ + size_t i; + Buffer *buf = NULL; + + for (i = 0; i < LENGTH(m->pool); i++) { + if (m->pool[i]) { + if (m->pool[i]->busy) + continue; + buf = m->pool[i]; + break; + } + + buf = ecalloc(1, sizeof(Buffer) + (m->b.width * 4 * m->b.height)); + buf->image = drwl_image_create(NULL, m->b.width, m->b.height, buf->data); + wlr_buffer_init(&buf->base, &buffer_impl, m->b.width, m->b.height); + m->pool[i] = buf; + break; + } + if (!buf) + return NULL; + + buf->busy = true; + LISTEN(&buf->base.events.release, &buf->release, bufrelease); + wlr_buffer_lock(&buf->base); + drwl_setimage(m->drw, buf->image); + return buf; +} + +void +bufrelease(struct wl_listener *listener, void *data) +{ + Buffer *buf = wl_container_of(listener, buf, release); + buf->busy = false; + wl_list_remove(&buf->release.link); +} + void buttonpress(struct wl_listener *listener, void *data) { + unsigned int i = 0, x = 0; + double cx; + unsigned int click; struct wlr_pointer_button_event *event = data; struct wlr_keyboard *keyboard; + struct wlr_scene_node *node; + struct wlr_scene_buffer *buffer; uint32_t mods; + Arg arg = {0}; Client *c; const Button *b; + uint32_t occ = 0; wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); + click = ClkRoot; + xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL); + if (c) + click = ClkClient; + switch (event->state) { case WL_POINTER_BUTTON_STATE_PRESSED: cursor_mode = CurPressed; @@ -637,17 +873,47 @@ buttonpress(struct wl_listener *listener, void *data) if (locked) break; + if (!c && !exclusive_focus && + (node = wlr_scene_node_at(&layers[LyrBottom]->node, cursor->x, cursor->y, NULL, NULL)) && + (buffer = wlr_scene_buffer_from_node(node)) && buffer == selmon->scene_buffer) { + cx = (cursor->x - selmon->m.x) * selmon->wlr_output->scale; + + // Get shown tags + wl_list_for_each(c, &clients, link) { + if (c->mon != selmon) + continue; + occ |= c->tags == TAGMASK ? 0 : c->tags; + } + + + do { + // Check if the tag is shown + if (!((occ & 1 << i) || selmon->tagset[selmon->seltags] & 1 << i)) + continue; + + x += TEXTW(selmon, tags[i]); + } while (cx >= x && ++i < LENGTH(tags)); + if (i < LENGTH(tags)) { + click = ClkTagBar; + arg.ui = 1 << i; + } else if (cx < x + TEXTW(selmon, selmon->ltsymbol)) + click = ClkLtSymbol; + else if (cx > selmon->b.width - (TEXTW(selmon, stext) - selmon->lrpad + 2)) { + click = ClkStatus; + } else + click = ClkTitle; + } + /* Change focus if the button was _pressed_ over a client */ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL); - if (c && (!client_is_unmanaged(c) || client_wants_focus(c))) + if (click == ClkClient && (!client_is_unmanaged(c) || client_wants_focus(c))) focusclient(c, 1); keyboard = wlr_seat_get_keyboard(seat); mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; for (b = buttons; b < END(buttons); b++) { - if (CLEANMASK(mods) == CLEANMASK(b->mod) && - event->button == b->button && b->func) { - b->func(&b->arg); + if (CLEANMASK(mods) == CLEANMASK(b->mod) && event->button == b->button && click == b->click && b->func) { + b->func(click == ClkTagBar && b->arg.i == 0 ? &arg : &b->arg); return; } } @@ -700,12 +966,22 @@ checkidleinhibitor(struct wlr_surface *exclude) void cleanup(void) { + size_t i; cleanuplisteners(); #ifdef XWAYLAND wlr_xwayland_destroy(xwayland); xwayland = NULL; #endif wl_display_destroy_clients(dpy); + + /* kill child processes */ + for (i = 0; i < autostart_len; i++) { + if (0 < autostart_pids[i]) { + kill(autostart_pids[i], SIGTERM); + waitpid(autostart_pids[i], NULL, 0); + } + } + if (child_pid > 0) { kill(-child_pid, SIGTERM); waitpid(child_pid, NULL, 0); @@ -722,6 +998,8 @@ cleanup(void) /* Destroy after the wayland display (when the monitors are already destroyed) to avoid destroying them with an invalid scene output. */ wlr_scene_node_destroy(&scene->tree.node); + + drwl_fini(); } void @@ -731,12 +1009,22 @@ cleanupmon(struct wl_listener *listener, void *data) LayerSurface *l, *tmp; size_t i; + DwlIpcOutput *ipc_output, *ipc_output_tmp; + wl_list_for_each_safe(ipc_output, ipc_output_tmp, &m->dwl_ipc_outputs, link) + wl_resource_destroy(ipc_output->resource); + /* m->layers[i] are intentionally not unlinked */ for (i = 0; i < LENGTH(m->layers); i++) { wl_list_for_each_safe(l, tmp, &m->layers[i], link) wlr_layer_surface_v1_destroy(l->layer_surface); } + for (i = 0; i < LENGTH(m->pool); i++) + wlr_buffer_drop(&m->pool[i]->base); + + drwl_setimage(m->drw, NULL); + drwl_destroy(m->drw); + wl_list_remove(&m->destroy.link); wl_list_remove(&m->frame.link); wl_list_remove(&m->link); @@ -749,6 +1037,7 @@ cleanupmon(struct wl_listener *listener, void *data) closemon(m); wlr_scene_node_destroy(&m->fullscreen_bg->node); + wlr_scene_node_destroy(&m->scene_buffer->node); free(m); } @@ -810,12 +1099,12 @@ closemon(Monitor *m) wl_list_for_each(c, &clients, link) { if (c->isfloating && c->geom.x > m->m.width) resize(c, (struct wlr_box){.x = c->geom.x - m->w.width, .y = c->geom.y, - .width = c->geom.width, .height = c->geom.height}, 0); + .width = c->geom.width, .height = c->geom.height}, 0, 1); if (c->mon == m) setmon(c, selmon, c->tags); } focusclient(focustop(selmon), 1); - printstatus(); + drawbars(); } void @@ -879,7 +1168,11 @@ commitnotify(struct wl_listener *listener, void *data) return; } - resize(c, c->geom, (c->isfloating && !c->isfullscreen)); + if (client_surface(c)->mapped && c->mon && c->mon->lt[c->mon->sellt]->arrange + && !c->isfullscreen && !c->isfloating) + c->mon->lt[c->mon->sellt]->arrange(c->mon); + else + resize(c, c->geom, (c->isfloating && !c->isfullscreen), (c->isfloating && !c->isfullscreen)); /* mark a pending resize as completed */ if (c->resize && c->resize <= c->surface.xdg->current.configure_serial) @@ -1053,6 +1346,8 @@ createmon(struct wl_listener *listener, void *data) m = wlr_output->data = ecalloc(1, sizeof(*m)); m->wlr_output = wlr_output; + wl_list_init(&m->dwl_ipc_outputs); + for (i = 0; i < LENGTH(m->layers); i++) wl_list_init(&m->layers[i]); @@ -1065,6 +1360,7 @@ createmon(struct wl_listener *listener, void *data) m->m.y = r->y; m->mfact = r->mfact; m->nmaster = r->nmaster; + m->gappx = gappx; m->lt[0] = r->lt; m->lt[1] = &layouts[LENGTH(layouts) > 1 && r->lt != &layouts[1]]; strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol)); @@ -1089,8 +1385,15 @@ createmon(struct wl_listener *listener, void *data) wlr_output_commit_state(wlr_output, &state); wlr_output_state_finish(&state); + if (!(m->drw = drwl_create())) + die("failed to create drwl context"); + + m->scene_buffer = wlr_scene_buffer_create(layers[LyrBottom], NULL); + m->scene_buffer->point_accepts_input = baracceptsinput; + updatebar(m); + wl_list_insert(&mons, &m->link); - printstatus(); + drawbars(); /* The xdg-protocol specifies: * @@ -1401,6 +1704,264 @@ dirtomon(enum wlr_direction dir) } void +dwl_ipc_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) +{ + struct wl_resource *manager_resource = wl_resource_create(client, &zdwl_ipc_manager_v2_interface, version, id); + if (!manager_resource) { + wl_client_post_no_memory(client); + return; + } + wl_resource_set_implementation(manager_resource, &dwl_manager_implementation, NULL, dwl_ipc_manager_destroy); + + zdwl_ipc_manager_v2_send_tags(manager_resource, LENGTH(tags)); + + for (unsigned int i = 0; i < LENGTH(layouts); i++) + zdwl_ipc_manager_v2_send_layout(manager_resource, layouts[i].symbol); +} + +void +dwl_ipc_manager_destroy(struct wl_resource *resource) +{ + /* No state to destroy */ +} + +void +dwl_ipc_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output) +{ + DwlIpcOutput *ipc_output; + Monitor *monitor = wlr_output_from_resource(output)->data; + struct wl_resource *output_resource = wl_resource_create(client, &zdwl_ipc_output_v2_interface, wl_resource_get_version(resource), id); + if (!output_resource) + return; + + ipc_output = ecalloc(1, sizeof(*ipc_output)); + ipc_output->resource = output_resource; + ipc_output->mon = monitor; + wl_resource_set_implementation(output_resource, &dwl_output_implementation, ipc_output, dwl_ipc_output_destroy); + wl_list_insert(&monitor->dwl_ipc_outputs, &ipc_output->link); + dwl_ipc_output_printstatus_to(ipc_output); +} + +void +dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +static void +dwl_ipc_output_destroy(struct wl_resource *resource) +{ + DwlIpcOutput *ipc_output = wl_resource_get_user_data(resource); + wl_list_remove(&ipc_output->link); + free(ipc_output); +} + +void +dwl_ipc_output_printstatus(Monitor *monitor) +{ + DwlIpcOutput *ipc_output; + wl_list_for_each(ipc_output, &monitor->dwl_ipc_outputs, link) + dwl_ipc_output_printstatus_to(ipc_output); +} + +void +dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) +{ + Monitor *monitor = ipc_output->mon; + Client *c, *focused; + int tagmask, state, numclients, focused_client, tag; + const char *title, *appid; + focused = focustop(monitor); + zdwl_ipc_output_v2_send_active(ipc_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_IPC_OUTPUT_V2_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_IPC_OUTPUT_V2_TAG_STATE_URGENT; + + numclients++; + } + zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients, focused_client); + } + title = focused ? client_get_title(focused) : ""; + appid = focused ? client_get_appid(focused) : ""; + + zdwl_ipc_output_v2_send_layout(ipc_output->resource, monitor->lt[monitor->sellt] - layouts); + zdwl_ipc_output_v2_send_title(ipc_output->resource, title); + zdwl_ipc_output_v2_send_appid(ipc_output->resource, appid); + zdwl_ipc_output_v2_send_layout_symbol(ipc_output->resource, monitor->ltsymbol); + if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FULLSCREEN_SINCE_VERSION) { + zdwl_ipc_output_v2_send_fullscreen(ipc_output->resource, focused ? focused->isfullscreen : 0); + } + if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { + zdwl_ipc_output_v2_send_floating(ipc_output->resource, focused ? focused->isfloating : 0); + } + zdwl_ipc_output_v2_send_frame(ipc_output->resource); +} + +void +dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags) +{ + DwlIpcOutput *ipc_output; + Monitor *monitor; + Client *selected_client; + unsigned int newtags = 0; + + ipc_output = wl_resource_get_user_data(resource); + if (!ipc_output) + return; + + monitor = ipc_output->mon; + selected_client = focustop(monitor); + if (!selected_client) + return; + + newtags = (selected_client->tags & and_tags) ^ xor_tags; + if (!newtags) + return; + + selected_client->tags = newtags; + if (selmon == monitor) + focusclient(focustop(monitor), 1); + arrange(selmon); + //printstatus(); +} + +void +dwl_ipc_output_set_layout(struct wl_client *client, struct wl_resource *resource, uint32_t index) +{ + DwlIpcOutput *ipc_output; + Monitor *monitor; + + ipc_output = wl_resource_get_user_data(resource); + if (!ipc_output) + return; + + monitor = ipc_output->mon; + if (index >= LENGTH(layouts)) + return; + if (index != monitor->lt[monitor->sellt] - layouts) + monitor->sellt ^= 1; + + monitor->lt[monitor->sellt] = &layouts[index]; + arrange(monitor); + //printstatus(); +} + +void +dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset) +{ + DwlIpcOutput *ipc_output; + Monitor *monitor; + unsigned int newtags = tagmask & TAGMASK; + + ipc_output = wl_resource_get_user_data(resource); + if (!ipc_output) + return; + monitor = ipc_output->mon; + + if (!newtags || newtags == monitor->tagset[monitor->seltags]) + return; + if (toggle_tagset) + monitor->seltags ^= 1; + + monitor->tagset[monitor->seltags] = newtags; + if (selmon == monitor) + focusclient(focustop(monitor), 1); + arrange(monitor); + //printstatus(); +} + +void +dwl_ipc_output_release(struct wl_client *client, struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +void +drawbar(Monitor *m) +{ + int x, w, tw = 0; + int boxs = m->drw->font->height / 9; + int boxw = m->drw->font->height / 6 + 2; + uint32_t i, occ = 0, urg = 0; + Client *c; + Buffer *buf; + + if (!m->scene_buffer->node.enabled) + return; + if (!(buf = bufmon(m))) + return; + + /* draw status first so it can be overdrawn by tags later */ + if (m == selmon) { /* status is only drawn on selected monitor */ + drwl_setscheme(m->drw, colors[SchemeNorm]); + tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */ + drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0); + } + + wl_list_for_each(c, &clients, link) { + if (c->mon != m) + continue; + occ |= c->tags == TAGMASK ? 0 : c->tags; + if (c->isurgent) + urg |= c->tags; + } + x = 0; + c = focustop(m); + for (i = 0; i < LENGTH(tags); i++) { + // Skip drawing this tag, if not in focus, or empty + if (!((occ & 1 << i) || m->tagset[m->seltags] & 1 << i)) continue; + w = TEXTW(m, tags[i]); + drwl_setscheme(m->drw, colors[m->tagset[m->seltags] & 1 << i ? SchemeTagSel : SchemeNorm]); + drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, tags[i], urg & 1 << i); + x += w; + } + w = TEXTW(m, m->ltsymbol); + drwl_setscheme(m->drw, colors[SchemeNorm]); + x = drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0); + + if ((w = m->b.width - tw - x) > m->b.height) { + if (c) { + drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]); + drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, client_get_title(c), 0); + if (c && c->isfloating) + drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0); + } else { + drwl_setscheme(m->drw, colors[SchemeNorm]); + drwl_rect(m->drw, x, 0, w, m->b.height, 1, 1); + } + } + + wlr_scene_buffer_set_dest_size(m->scene_buffer, + m->b.real_width, m->b.real_height); + wlr_scene_node_set_position(&m->scene_buffer->node, m->m.x, + m->m.y + (topbar ? 0 : m->m.height - m->b.real_height)); + wlr_scene_buffer_set_buffer(m->scene_buffer, &buf->base); + wlr_buffer_unlock(&buf->base); +} + +void +drawbars(void) +{ + Monitor *m = NULL; + + wl_list_for_each(m, &mons, link) + drawbar(m); +} + +void focusclient(Client *c, int lift) { struct wlr_surface *old = seat->keyboard_state.focused_surface; @@ -1434,13 +1995,13 @@ focusclient(Client *c, int lift) /* Don't change border color if there is an exclusive focus or we are * handling a drag operation */ if (!exclusive_focus && !seat->drag) - client_set_border_color(c, focuscolor); + client_set_border_color(c, (float[])COLOR(colors[SchemeSel][ColBorder])); } /* Deactivate old client if focus is changing */ if (old && (!c || client_surface(c) != old)) { /* If an overlay is focused, don't focus or activate the client, - * but only update its position in fstack to render its border with focuscolor + * but only update its position in fstack to render its border with its color * and focus it after the overlay is closed. */ if (old_client_type == LayerShell && wlr_scene_node_coords( &old_l->scene->node, &unused_lx, &unused_ly) @@ -1451,12 +2012,11 @@ focusclient(Client *c, int lift) /* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg * and probably other clients */ } else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) { - client_set_border_color(old_c, bordercolor); - + client_set_border_color(old_c, (float[])COLOR(colors[SchemeNorm][ColBorder])); client_activate_surface(old, 0); } } - printstatus(); + drawbars(); if (!c) { /* With no client, all we have left is to clear focus */ @@ -1478,12 +2038,102 @@ void focusmon(const Arg *arg) { int i = 0, nmons = wl_list_length(&mons); + Client *c = NULL; if (nmons) { do /* don't switch to disabled mons */ selmon = dirtomon(arg->i); while (!selmon->wlr_output->enabled && i++ < nmons); } - focusclient(focustop(selmon), 1); + + c = focustop(selmon); + focusclient(c, 1); + + if (mousefollowsfocus) warpcursortoclient(c); +} + +void +focusortogglematchingscratch(const Arg *arg) +{ + Client *c; + unsigned int found = 0; + unsigned int hide = 0; + + wl_list_for_each(c, &clients, link) { + if (c->scratchkey == 0) { + continue; + } + if (c->scratchkey == ((char**)arg->v)[0][0]) { + if (VISIBLEON(c, selmon)) { + if (found == 1) { + if (hide == 1) { + c->tags = 0; + focusclient(focustop(selmon), 1); + } + continue; + } + if (focustop(selmon) == c) { + // hide + c->tags = 0; + focusclient(focustop(selmon), 1); + hide = 1; + } else { + // focus + focusclient(c, 1); + } + } else { + // show + c->tags = selmon->tagset[selmon->seltags]; + // focus + focusclient(c, 1); + } + found = 1; + continue; + } + if (VISIBLEON(c, selmon)) { + // hide + c->tags = 0; + } + } + + if (found) { + arrange(selmon); + } else { + spawnscratch(arg); + } +} + +void +focusortogglescratch(const Arg *arg) +{ + Client *c; + unsigned int found = 0; + + /* search for first window that matches the scratchkey */ + wl_list_for_each(c, &clients, link) + if (c->scratchkey == ((char**)arg->v)[0][0]) { + found = 1; + break; + } + + if (found) { + if (VISIBLEON(c, selmon)) { + if (focustop(selmon) == c) { + // hide + c->tags = 0; + focusclient(focustop(selmon), 1); + } else { + // focus + focusclient(c, 1); + } + } else { + // show + c->tags = selmon->tagset[selmon->seltags]; + focusclient(c, 1); + } + arrange(selmon); + } else{ + spawnscratch(arg); + } } void @@ -1493,7 +2143,21 @@ focusstack(const Arg *arg) Client *c, *sel = focustop(selmon); if (!sel || (sel->isfullscreen && !client_has_children(sel))) return; - if (arg->i > 0) { + /* If i == 0 select the first client */ + if (arg->i == 0) { + wl_list_for_each(c, &clients, link) { + if (!VISIBLEON(c, selmon) || c->isfloating || c->isfullscreen) + continue; + break; + } + /* If i == INT_MAX select the last client */ + } else if (arg->i == INT_MAX) { + wl_list_for_each_reverse(c, &clients, link) { + if (!VISIBLEON(c, selmon) || c->isfloating || c->isfullscreen) + continue; + break; + } + } else if (arg->i > 0) { wl_list_for_each(c, &sel->link, link) { if (&c->link == &clients) continue; /* wrap past the sentinel node */ @@ -1510,6 +2174,7 @@ focusstack(const Arg *arg) } /* If only one client is visible on selmon, then c == sel */ focusclient(c, 1); + if (mousefollowsfocus) warpcursortoclient(c); } /* We probably should change the name of this: it sounds like it @@ -1562,9 +2227,89 @@ void handlesig(int signo) { if (signo == SIGCHLD) - while (waitpid(-1, NULL, WNOHANG) > 0); - else if (signo == SIGINT || signo == SIGTERM) + { + siginfo_t in; + /* wlroots expects to reap the XWayland process itself, so we + * use WNOWAIT to keep the child waitable until we know it's not + * XWayland. + */ + while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid + ) { + pid_t *p, *lim; + waitpid(in.si_pid, NULL, 0); + if (in.si_pid == child_pid) + child_pid = -1; + if (!(p = autostart_pids)) + continue; + lim = &p[autostart_len]; + + for (; p < lim; p++) { + if (*p == in.si_pid) { + *p = -1; + break; + } + } + } + } else if (signo == SIGINT || signo == SIGTERM) { quit(NULL); + } +} + +pid_t +getparentprocess(pid_t p) +{ + unsigned int v = 0; + + FILE *f; + char buf[256]; + snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p); + + if (!(f = fopen(buf, "r"))) + return 0; + + fscanf(f, "%*u %*s %*c %u", &v); + fclose(f); + + return (pid_t)v; +} + +int +isdescprocess(pid_t p, pid_t c) +{ + while (p != c && c != 0) + c = getparentprocess(c); + + return (int)c; +} + +Client * +termforwin(Client *w) +{ + Client *c; + + if (!w->pid || w->isterm || w->noswallow) + return NULL; + + wl_list_for_each(c, &fstack, flink) + if (c->isterm && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid)) + return c; + + return NULL; +} + +void +swallow(Client *c, Client *w) +{ + c->bw = w->bw; + c->isfloating = w->isfloating; + c->isurgent = w->isurgent; + c->isfullscreen = w->isfullscreen; + c->tags = w->tags; + c->geom = w->geom; + wl_list_insert(&w->link, &c->link); + wl_list_insert(&w->flink, &c->flink); + wlr_scene_node_set_enabled(&w->scene->node, 0); + wlr_scene_node_set_enabled(&c->scene->node, 1); } void @@ -1770,7 +2515,7 @@ mapnotify(struct wl_listener *listener, void *data) for (i = 0; i < 4; i++) { c->border[i] = wlr_scene_rect_create(c->scene, 0, 0, - c->isurgent ? urgentcolor : bordercolor); + (float[])COLOR(colors[c->isurgent ? SchemeUrg : SchemeNorm][ColBorder])); c->border[i]->node.data = c; } @@ -1793,7 +2538,7 @@ mapnotify(struct wl_listener *listener, void *data) } else { applyrules(c); } - printstatus(); + drawbars(); unset_fullscreen: m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y); @@ -1830,7 +2575,7 @@ monocle(Monitor *m) wl_list_for_each(c, &clients, link) { if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) continue; - resize(c, m->w, 0); + resize(c, m->w, 0, !smartborders); n++; } if (n) @@ -1840,6 +2585,49 @@ monocle(Monitor *m) } void +movestack(const Arg *arg) +{ + Client *c, *sel = focustop(selmon); + + if (wl_list_length(&clients) <= 1) { + return; + } + + if (arg->i == 0) { + /* Put the selected client on top */ + wl_list_remove(&sel->link); + wl_list_insert(&clients, &sel->link); + arrange(selmon); + return; + } else if (arg->i == INT_MAX) { + /* Get the last element */ + wl_list_for_each_reverse(c, &clients, link) { + if (!VISIBLEON(c, selmon) || c->isfloating || c->isfullscreen) + continue; + break; + } + } else if (arg->i > 0) { + wl_list_for_each(c, &sel->link, link) { + if (VISIBLEON(c, selmon) || &c->link == &clients) { + break; /* found it */ + } + } + } else { + wl_list_for_each_reverse(c, &sel->link, link) { + if (VISIBLEON(c, selmon) || &c->link == &clients) { + break; /* found it */ + } + } + /* backup one client */ + c = wl_container_of(c->link.prev, c, link); + } + + wl_list_remove(&sel->link); + wl_list_insert(&c->link, &sel->link); + arrange(selmon); +} + +void motionabsolute(struct wl_listener *listener, void *data) { /* This event is forwarded by the cursor when a pointer emits an _absolute_ @@ -1921,11 +2709,11 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d if (cursor_mode == CurMove) { /* Move the grabbed client to the new position. */ resize(grabc, (struct wlr_box){.x = (int)round(cursor->x) - grabcx, .y = (int)round(cursor->y) - grabcy, - .width = grabc->geom.width, .height = grabc->geom.height}, 1); + .width = grabc->geom.width, .height = grabc->geom.height}, 1, 1); return; } else if (cursor_mode == CurResize) { resize(grabc, (struct wlr_box){.x = grabc->geom.x, .y = grabc->geom.y, - .width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}, 1); + .width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}, 1, 1); return; } @@ -2090,38 +2878,9 @@ void printstatus(void) { Monitor *m = NULL; - Client *c; - uint32_t occ, urg, sel; - - wl_list_for_each(m, &mons, link) { - occ = urg = 0; - wl_list_for_each(c, &clients, link) { - if (c->mon != m) - continue; - occ |= c->tags; - if (c->isurgent) - urg |= c->tags; - } - if ((c = focustop(m))) { - printf("%s title %s\n", m->wlr_output->name, client_get_title(c)); - printf("%s appid %s\n", m->wlr_output->name, client_get_appid(c)); - printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen); - printf("%s floating %d\n", m->wlr_output->name, c->isfloating); - sel = c->tags; - } else { - printf("%s title \n", m->wlr_output->name); - printf("%s appid \n", m->wlr_output->name); - printf("%s fullscreen \n", m->wlr_output->name); - printf("%s floating \n", m->wlr_output->name); - sel = 0; - } - printf("%s selmon %u\n", m->wlr_output->name, m == selmon); - printf("%s tags %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"\n", - m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg); - printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol); - } - fflush(stdout); + wl_list_for_each(m, &mons, link) + dwl_ipc_output_printstatus(m); } void @@ -2204,7 +2963,7 @@ requestmonstate(struct wl_listener *listener, void *data) } void -resize(Client *c, struct wlr_box geo, int interact) +resize(Client *c, struct wlr_box geo, int interact, int draw_borders) { struct wlr_box *bbox; struct wlr_box clip; @@ -2216,6 +2975,7 @@ resize(Client *c, struct wlr_box geo, int interact) client_set_bounds(c, geo.width, geo.height); c->geom = geo; + c->bw = draw_borders ? borderpx : 0; applybounds(c, bbox); /* Update scene-graph, including borders */ @@ -2237,7 +2997,7 @@ resize(Client *c, struct wlr_box geo, int interact) } void -run(char *startup_cmd) +run(char *startup_cmd, uid_t uid) { /* Add a Unix socket to the Wayland display. */ const char *socket = wl_display_add_socket_auto(dpy); @@ -2250,34 +3010,25 @@ run(char *startup_cmd) if (!wlr_backend_start(backend)) die("startup: backend_start"); + /* In case the option is passed, drop priviledges to desired uid */ + if (uid > 0) + setuid(uid); + + /* Now that the socket exists and the backend is started, run the startup command */ + autostartexec(); if (startup_cmd) { - int piperw[2]; - if (pipe(piperw) < 0) - die("startup: pipe:"); if ((child_pid = fork()) < 0) die("startup: fork:"); if (child_pid == 0) { + close(STDIN_FILENO); setsid(); - dup2(piperw[0], STDIN_FILENO); - close(piperw[0]); - close(piperw[1]); execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL); die("startup: execl:"); } - dup2(piperw[1], STDOUT_FILENO); - close(piperw[1]); - close(piperw[0]); } - /* Mark stdout as non-blocking to avoid the startup script - * causing dwl to freeze when a user neither closes stdin - * nor consumes standard input in his startup script */ - - if (fd_set_nonblock(STDOUT_FILENO) < 0) - close(STDOUT_FILENO); - - printstatus(); + drawbars(); /* At this point the outputs are initialized, choose initial selmon based on * cursor position, and set default cursor image */ @@ -2342,8 +3093,10 @@ setfloating(Client *c, int floating) wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen || (p && p->isfullscreen) ? LyrFS : c->isfloating ? LyrFloat : LyrTile]); + if (c->isfloating && !c->bw) + resize(c, c->mon->m, 0, 1); arrange(c->mon); - printstatus(); + drawbars(); } void @@ -2359,14 +3112,36 @@ setfullscreen(Client *c, int fullscreen) if (fullscreen) { c->prev = c->geom; - resize(c, c->mon->m, 0); + resize(c, c->mon->m, 0, 0); } else { /* restore previous size instead of arrange for floating windows since * client positions are set by the user and cannot be recalculated */ - resize(c, c->prev, 0); + resize(c, c->prev, 0, 1); } arrange(c->mon); - printstatus(); + drawbars(); +} + +void +setgaps(const Arg *arg) { + if ((arg->i == 0) || (selmon->gappx + arg->i < 0)) + selmon->gappx = gappx; + else if (selmon->gappx + arg->i < 0) + selmon->gappx = 0; + else + selmon->gappx += arg->i; + arrange(selmon); +} + +void +setsticky(Client *c, int sticky) +{ + if(sticky && !c->issticky) { + c->issticky = 1; + } else if(!sticky && c->issticky) { + c->issticky = 0; + arrange(c->mon); + } } void @@ -2379,8 +3154,14 @@ setlayout(const Arg *arg) if (arg && arg->v) selmon->lt[selmon->sellt] = (Layout *)arg->v; strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol)); + if (!selmon->lt[selmon->sellt]->arrange) { + /* floating layout, draw borders around all clients */ + Client *c; + wl_list_for_each(c, &clients, link) + resize(c, c->mon->m, 0, 1); + } arrange(selmon); - printstatus(); + drawbar(selmon); } /* arg > 1.0 will set mfact absolutely */ @@ -2413,7 +3194,7 @@ setmon(Client *c, Monitor *m, uint32_t newtags) arrange(oldmon); if (m) { /* Make sure window actually overlaps with the monitor */ - resize(c, c->geom, 0); + resize(c, c->geom, 0, 1); c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */ setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */ setfloating(c, c->isfloating); @@ -2453,6 +3234,7 @@ setup(void) for (i = 0; i < (int)LENGTH(sig); i++) sigaction(sig[i], &sa, NULL); + wlr_log_init(log_level, NULL); /* The Wayland display is managed by libwayland. It handles accepting @@ -2648,6 +3430,13 @@ setup(void) wl_signal_add(&output_mgr->events.apply, &output_mgr_apply); wl_signal_add(&output_mgr->events.test, &output_mgr_test); + wl_global_create(dpy, &zdwl_ipc_manager_v2_interface, 2, NULL, dwl_ipc_manager_bind); + + drwl_init(); + + status_event_source = wl_event_loop_add_fd(wl_display_get_event_loop(dpy), + STDIN_FILENO, WL_EVENT_READABLE, statusin, NULL); + /* Make sure XWayland clients don't connect to the parent X server, * e.g when running in the x11 backend or the wayland backend and the * compositor has Xwayland support */ @@ -2672,6 +3461,7 @@ void spawn(const Arg *arg) { if (fork() == 0) { + close(STDIN_FILENO); dup2(STDERR_FILENO, STDOUT_FILENO); setsid(); execvp(((char **)arg->v)[0], (char **)arg->v); @@ -2679,6 +3469,16 @@ spawn(const Arg *arg) } } +void spawnscratch(const Arg *arg) +{ + if (fork() == 0) { + dup2(STDERR_FILENO, STDOUT_FILENO); + setsid(); + execvp(((char **)arg->v)[1], ((char **)arg->v)+1); + die("dwl: execvp %s failed:", ((char **)arg->v)[1]); + } +} + void startdrag(struct wl_listener *listener, void *data) { @@ -2690,6 +3490,30 @@ startdrag(struct wl_listener *listener, void *data) LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon); } +int +statusin(int fd, unsigned int mask, void *data) +{ + char status[1024]; + ssize_t n; + + if (mask & WL_EVENT_ERROR) + die("status in event error"); + if (mask & WL_EVENT_HANGUP) + wl_event_source_remove(status_event_source); + + n = read(fd, status, sizeof(status) - 1); + if (n < 0 && errno != EWOULDBLOCK) + die("read:"); + + status[n] = '\0'; + status[strcspn(status, "\n")] = '\0'; + + strncpy(stext, status, sizeof(stext)); + drawbars(); + + return 0; +} + void tag(const Arg *arg) { @@ -2700,7 +3524,7 @@ tag(const Arg *arg) sel->tags = arg->ui & TAGMASK; focusclient(focustop(selmon), 1); arrange(selmon); - printstatus(); + drawbars(); } void @@ -2714,8 +3538,8 @@ tagmon(const Arg *arg) void tile(Monitor *m) { - unsigned int mw, my, ty; - int i, n = 0; + unsigned int mw, my, ty, draw_borders = 1; + int i, n = 0, gap = 0; Client *c; wl_list_for_each(c, &clients, link) @@ -2724,27 +3548,48 @@ tile(Monitor *m) if (n == 0) return; + if (n > 1) + gap = m->gappx; + + if (n == 1 && smartborders) + draw_borders = 0; + if (n > m->nmaster) mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0; else - mw = m->w.width; - i = my = ty = 0; + mw = m->w.width - gap; + i = 0; my = ty = gap; wl_list_for_each(c, &clients, link) { if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) continue; if (i < m->nmaster) { - resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw, - .height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0); - my += c->geom.height; + resize(c, (struct wlr_box){.x = m->w.x + gap, .y = m->w.y + my, + .width = mw - gap, .height = (m->w.height - my - gap) / (MIN(n, m->nmaster) - i)}, 0, draw_borders); + my += c->geom.height + gap; } else { - resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty, - .width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0); - ty += c->geom.height; + resize(c, (struct wlr_box){.x = m->w.x + mw + gap, .y = m->w.y + ty, + .width = m->w.width - mw - 2 * gap, .height = (m->w.height - ty) / (n - i) - gap}, 0, draw_borders); + ty += c->geom.height + gap; } i++; } } +//void +//togglebar(const Arg *arg) { +// DwlIpcOutput *ipc_output; +// wl_list_for_each(ipc_output, &selmon->dwl_ipc_outputs, link) +// zdwl_ipc_output_v2_send_toggle_visibility(ipc_output->resource); +//} + +void +togglebar(const Arg *arg) +{ + wlr_scene_node_set_enabled(&selmon->scene_buffer->node, + !selmon->scene_buffer->node.enabled); + arrangelayers(selmon); +} + void togglefloating(const Arg *arg) { @@ -2762,6 +3607,47 @@ togglefullscreen(const Arg *arg) setfullscreen(sel, !sel->isfullscreen); } +void togglegaps(const Arg *arg) { + if (selmon->gappx == 0) + selmon->gappx = gappx; + else + selmon->gappx = 0; + arrange(selmon); +} + +void +togglescratch(const Arg *arg) +{ + Client *c; + unsigned int found = 0; + + /* search for first window that matches the scratchkey */ + wl_list_for_each(c, &clients, link) + if (c->scratchkey == ((char**)arg->v)[0][0]) { + found = 1; + break; + } + + if (found) { + c->tags = VISIBLEON(c, selmon) ? 0 : selmon->tagset[selmon->seltags]; + + focusclient(c->tags == 0 ? focustop(selmon) : c, 1); + arrange(selmon); + } else{ + spawnscratch(arg); + } +} + +void +togglesticky(const Arg *arg) +{ + Client *c = focustop(selmon); + if(!c) + return; + + setsticky(c, !c->issticky); +} + void toggletag(const Arg *arg) { @@ -2773,7 +3659,7 @@ toggletag(const Arg *arg) sel->tags = newtags; focusclient(focustop(selmon), 1); arrange(selmon); - printstatus(); + drawbars(); } void @@ -2786,7 +3672,7 @@ toggleview(const Arg *arg) selmon->tagset[selmon->seltags] = newtagset; focusclient(focustop(selmon), 1); arrange(selmon); - printstatus(); + drawbars(); } void @@ -2822,19 +3708,36 @@ unmapnotify(struct wl_listener *listener, void *data) grabc = NULL; } + if (c->swallowedby) + swallow(c->swallowedby, c); + if (client_is_unmanaged(c)) { if (c == exclusive_focus) { exclusive_focus = NULL; focusclient(focustop(selmon), 1); } } else { - wl_list_remove(&c->link); + if (!c->swallowing) + wl_list_remove(&c->link); setmon(c, NULL, 0); - wl_list_remove(&c->flink); + if (!c->swallowing) + wl_list_remove(&c->flink); + } + + if (c->swallowedby) { + c->swallowedby->prev = c->geom; + setfullscreen(c->swallowedby, c->isfullscreen); + c->swallowedby->swallowing = NULL; + c->swallowedby = NULL; + } + + if (c->swallowing) { + c->swallowing->swallowedby = NULL; + c->swallowing = NULL; } wlr_scene_node_destroy(&c->scene->node); - printstatus(); + drawbars(); motionnotify(0, NULL, 0, 0, 0, 0); } @@ -2907,7 +3810,7 @@ updatemons(struct wl_listener *listener, void *data) arrange(m); /* make sure fullscreen clients have the right size */ if ((c = focustop(m)) && c->isfullscreen) - resize(c, m->m, 0); + resize(c, m->m, 0, 0); /* Try to re-set the gamma LUT when updating monitors, * it's only really needed when enabling a disabled output, but meh. */ @@ -2934,6 +3837,13 @@ updatemons(struct wl_listener *listener, void *data) } } + if (stext[0] == '\0') + strncpy(stext, "dwl-"VERSION, sizeof(stext)); + wl_list_for_each(m, &mons, link) { + updatebar(m); + drawbar(m); + } + /* FIXME: figure out why the cursor image is at 0,0 after turning all * the monitors on. * Move the cursor image where it used to be. It does not generate a @@ -2945,11 +3855,44 @@ updatemons(struct wl_listener *listener, void *data) } void +updatebar(Monitor *m) +{ + size_t i; + int rw, rh; + char fontattrs[12]; + + wlr_output_transformed_resolution(m->wlr_output, &rw, &rh); + m->b.width = rw; + m->b.real_width = (int)((float)m->b.width / m->wlr_output->scale); + + wlr_scene_node_set_enabled(&m->scene_buffer->node, m->wlr_output->enabled ? showbar : 0); + + for (i = 0; i < LENGTH(m->pool); i++) + if (m->pool[i]) { + wlr_buffer_drop(&m->pool[i]->base); + m->pool[i] = NULL; + } + + if (m->b.scale == m->wlr_output->scale && m->drw) + return; + + drwl_font_destroy(m->drw->font); + snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * m->wlr_output->scale); + if (!(drwl_font_create(m->drw, LENGTH(fonts), fonts, fontattrs))) + die("Could not load font"); + + m->b.scale = m->wlr_output->scale; + m->lrpad = m->drw->font->height; + m->b.height = m->drw->font->height + 2; + m->b.real_height = (int)((float)m->b.height / m->wlr_output->scale); +} + +void updatetitle(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, set_title); if (c == focustop(c->mon)) - printstatus(); + drawbars(); } void @@ -2962,10 +3905,10 @@ urgent(struct wl_listener *listener, void *data) return; c->isurgent = 1; - printstatus(); + drawbars(); if (client_surface(c)->mapped) - client_set_border_color(c, urgentcolor); + client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder])); } void @@ -2978,7 +3921,7 @@ view(const Arg *arg) selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; focusclient(focustop(selmon), 1); arrange(selmon); - printstatus(); + drawbars(); } void @@ -3006,6 +3949,16 @@ virtualpointer(struct wl_listener *listener, void *data) wlr_cursor_map_input_to_output(cursor, device, event->suggested_output); } +void +warpcursortoclient(Client *c) { + struct wlr_box mg = c->mon->m; + struct wlr_box cg = c->geom; + if (!VISIBLEON(c, selmon)) return; + wlr_cursor_warp_absolute(cursor, NULL, + ((double)cg.x + (double)cg.width / 2.0) / (double)mg.width, + ((double)cg.y + (double)cg.height / 2.0) / (double)mg.height); +} + Monitor * xytomon(double x, double y) { @@ -3019,6 +3972,7 @@ xytonode(double x, double y, struct wlr_surface **psurface, { struct wlr_scene_node *node, *pnode; struct wlr_surface *surface = NULL; + struct wlr_scene_surface *scene_surface = NULL; Client *c = NULL; LayerSurface *l = NULL; int layer; @@ -3027,9 +3981,12 @@ xytonode(double x, double y, struct wlr_surface **psurface, if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny))) continue; - if (node->type == WLR_SCENE_NODE_BUFFER) - surface = wlr_scene_surface_try_from_buffer( - wlr_scene_buffer_from_node(node))->surface; + if (node->type == WLR_SCENE_NODE_BUFFER) { + scene_surface = wlr_scene_surface_try_from_buffer( + wlr_scene_buffer_from_node(node)); + if (!scene_surface) continue; + surface = scene_surface->surface; + } /* Walk the tree to find a node that knows the client */ for (pnode = node; pnode && !c; pnode = &pnode->parent->node) c = pnode->data; @@ -3116,7 +4073,7 @@ configurex11(struct wl_listener *listener, void *data) if ((c->isfloating && c != grabc) || !c->mon->lt[c->mon->sellt]->arrange) { resize(c, (struct wlr_box){.x = event->x - c->bw, .y = event->y - c->bw, .width = event->width + c->bw * 2, - .height = event->height + c->bw * 2}, 0); + .height = event->height + c->bw * 2}, 0, 1); } else { arrange(c->mon); } @@ -3162,10 +4119,10 @@ sethints(struct wl_listener *listener, void *data) return; c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints); - printstatus(); + drawbars(); if (c->isurgent && surface && surface->mapped) - client_set_border_color(c, urgentcolor); + client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder])); } void @@ -3189,10 +4146,13 @@ int main(int argc, char *argv[]) { char *startup_cmd = NULL; + uid_t uid = 0; int c; - while ((c = getopt(argc, argv, "s:hdv")) != -1) { - if (c == 's') + while ((c = getopt(argc, argv, "u:s:hdv")) != -1) { + if (c == 'u') + uid = atoi(optarg); + else if (c == 's') startup_cmd = optarg; else if (c == 'd') log_level = WLR_DEBUG; @@ -3208,10 +4168,10 @@ main(int argc, char *argv[]) if (!getenv("XDG_RUNTIME_DIR")) die("XDG_RUNTIME_DIR must be set"); setup(); - run(startup_cmd); + run(startup_cmd, uid); cleanup(); return EXIT_SUCCESS; usage: - die("Usage: %s [-v] [-d] [-s startup command]", argv[0]); + die("Usage: %s [-v] [-u uid] [-d] [-s startup command]", argv[0]); } diff --git a/protocols/dwl-ipc-unstable-v2.xml b/protocols/dwl-ipc-unstable-v2.xml new file mode 100644 index 0000000..0a6e7e5 --- /dev/null +++ b/protocols/dwl-ipc-unstable-v2.xml @@ -0,0 +1,181 @@ +<?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_ipc_unstable_v2"> + <description summary="inter-proccess-communication about dwl's state"> + This protocol allows clients to update and get updates from dwl. + + 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_ipc_manager_v2" 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_ipc_output. + After binding the client will recieve the dwl_ipc_manager.tags and dwl_ipc_manager.layout events. + The dwl_ipc_manager.tags and dwl_ipc_manager.layout events expose tags and layouts to the client. + </description> + + <request name="release" type="destructor"> + <description summary="release dwl_ipc_manager"> + Indicates that the client will not the dwl_ipc_manager object anymore. + Objects created through this instance are not affected. + </description> + </request> + + <request name="get_output"> + <description summary="get a dwl_ipc_outout for a wl_output"> + Get a dwl_ipc_outout for the specified wl_output. + </description> + <arg name="id" type="new_id" interface="zdwl_ipc_output_v2"/> + <arg name="output" type="object" interface="wl_output"/> + </request> + + <event name="tags"> + <description summary="Announces tag amount"> + This event is sent after binding. + A roundtrip after binding guarantees the client recieved all tags. + </description> + <arg name="amount" type="uint"/> + </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_ipc_output_v2" 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_ipc_output.frame 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_ipc_outout"> + Indicates to that the client no longer needs this dwl_ipc_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="1"> + <description summary="Update the appid."> + Indicates the appid has changed. + </description> + <arg name="appid" type="string" summary="The new appid."/> + </event> + + <event name="layout_symbol" since="1"> + <description summary="Update the current layout symbol"> + Indicates the layout has changed. Since layout symbols are dynamic. + As opposed to the zdwl_ipc_manager.layout event, this should take precendence when displaying. + You can ignore the zdwl_ipc_output.layout event. + </description> + <arg name="layout" type="string" summary="The new layout"/> + </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_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> + + <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_ipc_manager.layout"/> + </request> + + <!-- Version 2 --> + <event name="fullscreen" since="2"> + <description summary="Update fullscreen status"> + Indicates if the selected client on this output is fullscreen. + </description> + <arg name="is_fullscreen" type="uint" summary="If the selected client is fullscreen. Nonzero is valid, zero invalid"/> + </event> + + <event name="floating" since="2"> + <description summary="Update the floating status"> + Indicates if the selected client on this output is floating. + </description> + <arg name="is_floating" type="uint" summary="If the selected client is floating. Nonzero is valid, zero invalid"/> + </event> + </interface> +</protocol> |
