From 3bc510484be8c7371a90afd09b34437d789d18f8 Mon Sep 17 00:00:00 2001 From: Ray Andrew <4437323+rayandrew@users.noreply.github.com> Date: Thu, 26 Sep 2024 22:50:28 -0500 Subject: [PATCH] change term to foot --- config.def.h | 94 +++++++++----- dwl.c | 361 +++++++++++++++++++++++++++++++++++++++++++++++++-- shiftview.c | 34 +++++ 3 files changed, 448 insertions(+), 41 deletions(-) create mode 100644 shiftview.c diff --git a/config.def.h b/config.def.h index b4f549a..7b932c9 100644 --- a/config.def.h +++ b/config.def.h @@ -6,14 +6,26 @@ /* appearance */ static const int sloppyfocus = 1; /* focus follows mouse */ static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */ +static const int smartgaps = 0; /* 1 means no outer gap when there is only one window */ +static const int monoclegaps = 1; /* 1 means outer gaps in monocle layout */ 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 unsigned int gappih = 10; /* horiz inner gap between windows */ +static const unsigned int gappiv = 10; /* vert inner gap between windows */ +static const unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */ +static const unsigned int gappov = 10; /* vert outer gap between windows and screen edge */ +// static const float rootcolor[] = COLOR(0x222222ff); +static const float rootcolor[] = COLOR(0x1e222aff); +// static const float bordercolor[] = COLOR(0x444444ff); +static const float bordercolor[] = COLOR(0x282b2cff); +// static const float focuscolor[] = COLOR(0x005577ff); +static const float focuscolor[] = COLOR(0xd1b171ff); +// static const float urgentcolor[] = COLOR(0xff0000ff); +static const float urgentcolor[] = COLOR(0xec6b64ff); /* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */ static const float fullscreen_bg[] = {0.1f, 0.1f, 0.1f, 1.0f}; /* You can also use glsl colors */ +static const unsigned int swipe_min_threshold = 0; + /* tagging - TAGCOUNT must be no greater than 31 */ #define TAGCOUNT (10) @@ -24,7 +36,7 @@ static int log_level = WLR_ERROR; static const char *const autostart[] = { "dbus-update-activation-environment", "DISPLAY", "MOZ_DBUS_REMOTE", "WAYLAND_DISPLAY", "XDG_CURRENT_DESKTOP", NULL, "dinit", "-q", NULL, - "pkexec", "swayosd-libinput-backend", NULL, + // "pkexec", "swayosd-libinput-backend", NULL, "swayosd-server", NULL, NULL /* terminate */ }; @@ -61,7 +73,7 @@ static const Layout layouts[] = { 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 }, + { "eDP-1", 0.5f, 1, 1.5f, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, /* defaults */ { NULL, 0.55f, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, }; @@ -82,10 +94,10 @@ static const int repeat_delay = 600; static const int tap_to_click = 1; static const int tap_and_drag = 1; static const int drag_lock = 1; -static const int natural_scrolling = 0; +static const int natural_scrolling = 1; static const int disable_while_typing = 1; static const int left_handed = 0; -static const int middle_button_emulation = 0; +static const int middle_button_emulation = 1; /* You can choose between: LIBINPUT_CONFIG_SCROLL_NO_SCROLL LIBINPUT_CONFIG_SCROLL_2FG @@ -134,11 +146,14 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } /* commands */ -#define TERM_CMD "wezterm", "-e" +// #define TERM_CMD "wezterm", "-e" +#define TERM_CMD "footclient" #define TERM(cmd) { .v = (const char*[]){ TERM_CMD, cmd, NULL } } -static const char *termcmd[] = { "wezterm", "-e", NULL }; -static const char *menucmd[] = { "wofi", "--show=drun", NULL }; -static const char *swaynccmd[] = { "swaync-client", "-t", "-sw", NULL }; +static const char *termcmd[] = { TERM_CMD, NULL }; +// static const char *menucmd[] = { "wofi", "--show=drun", NULL }; +static const char *menucmd[] = { "rofi", "-show", "drun", NULL }; +static const char *calccmd[] = { "rofi", "-show", "calc", "-modi", "calc", "-no-show-match", "-no-sort", "-kb-accept-custom", "Return", "-kb-accept-entry", "Control+Return", "-calc-command", "wl-copy {result}", "-theme", "~/.config/rofi/calc.rasi", NULL}; +static const char *swaynccmd[] = { "swaync-client", "-t", "-sw", NULL }; // volume // static const char *volmicmutecmd[] = { "/usr/bin/pactl", "set-source-mute", "@DEFAULT_SOURCE@", "toggle", NULL }; // static const char *volsoundmutecmd[] = { "/usr/bin/wpctl", "set-mute", "@DEFAULT_AUDIO_SINK@", "toggle", NULL }; @@ -149,9 +164,9 @@ static const char *voldecreasecmd[] = { "swayosd-client", "--output-vol static const char *volincreasecmd[] = { "swayosd-client", "--output-volume=raise", NULL }; // mic -static const char *micmutecmd[] = { "swayosd-client", "--input=volume=mute-toggle", NULL }; -static const char *micdecreasecmd[] = { "swayosd-client", "--input=volume=lower", NULL }; -static const char *micincreasecmd[] = { "swayosd-client", "--input=volume=raise", NULL }; +static const char *micmutecmd[] = { "swayosd-client", "--input=volume=mute-toggle", NULL }; +static const char *micdecreasecmd[] = { "swayosd-client", "--input=volume=lower", NULL }; +static const char *micincreasecmd[] = { "swayosd-client", "--input=volume=raise", NULL }; // brightness static const char *increasebrightnesscmd[] = { "/usr/bin/brightnessctl", "s", "+10%", NULL }; @@ -164,37 +179,42 @@ static const char *mediaplaynextcmd[] = { "/usr/bin/playerctl", "next", N static const char *mediaplayprevcmd[] = { "/usr/bin/playerctl", "previous", NULL }; // screenshot #define SCREENSHOTDIR_CMD SHCMD("grim -g \"$(slurp)\" \"$(xdg-user-dir)/Screenshots/$(date +%Y-%m-%d-%H-%M-%S).png\"") -#define SCREENSHOTCLIPBOARD_CMD SHCMD("grim -g \"$(slurp)]\" -t png - | wl-copy") +#define SCREENSHOTCLIPBOARD_CMD SHCMD("grim -g \"$(slurp)\" -t png - | wl-copy") + +#include "shiftview.c" static const Key keys[] = { /* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */ /* modifier key function argument */ { MODKEY, XKB_KEY_space, spawn, {.v = menucmd} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, spawn, {.v = calccmd} }, + { MODKEY, XKB_KEY_Return, spawn, {.v = termcmd} }, - { MODKEY|WLR_MODIFIER_SHIFT, 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_B, togglebar, {0} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_J, focusstack, {.i = +1} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_K, focusstack, {.i = -1} }, { MODKEY, XKB_KEY_h, focusdir, {.ui = 0} }, { MODKEY, XKB_KEY_l, focusdir, {.ui = 1} }, { MODKEY, XKB_KEY_k, focusdir, {.ui = 2} }, { MODKEY, XKB_KEY_j, focusdir, {.ui = 3} }, { 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|WLR_MODIFIER_SHIFT, XKB_KEY_H, setmfact, {.f = -0.05f} }, + { MODKEY|WLR_MODIFIER_SHIFT, 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_P, setlayout, {.v = &layouts[1]} }, + { MODKEY, XKB_KEY_e, setlayout, {.v = &layouts[0]} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_P, setlayout, {.v = &layouts[1]} }, { MODKEY, XKB_KEY_p, togglefloating, {0} }, { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[2]} }, // { MODKEY, XKB_KEY_p, setlayout, {0} }, { MODKEY, XKB_KEY_f, togglefullscreen, {0} }, - { MODKEY, XKB_KEY_F, togglefakefullscreen, {0} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_F, togglefakefullscreen, {0} }, { MODKEY, XKB_KEY_BackSpace, togglesticky, {0} }, - // { MODKEY, XKB_KEY_grave, view, {.ui = ~0} }, - // { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_grave, tag, {.ui = ~0} }, + { MODKEY, XKB_KEY_grave, view, {.ui = ~0} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_asciitilde, 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} }, @@ -209,7 +229,14 @@ static const Key keys[] = { TAGKEYS( XKB_KEY_8, XKB_KEY_asterisk, 7), TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8), TAGKEYS( XKB_KEY_0, XKB_KEY_parenright, 9), - // { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_R, quit, {0} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_R, spawn, SHCMD("killall dbus-run-session") }, + // { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_R, quit, {0} }, + + // gaps + { MODKEY, XKB_KEY_minus, incgaps, {.i = -1 } }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_underscore, togglegaps, {0} }, + { MODKEY, XKB_KEY_equal, incgaps, {.i = +1 } }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_plus, defaultgaps, {0} }, // volume { 0, XKB_KEY_XF86AudioMute, spawn, {.v = volsoundmutecmd } }, @@ -233,9 +260,9 @@ static const Key keys[] = { { 0, XKB_KEY_XF86MonBrightnessDown, spawn, {.v = decreasebrightnesscmd } }, // screenshot - { MODKEY, XKB_KEY_Print, spawn, SCREENSHOTDIR_CMD }, - { MODKEY, XKB_KEY_o, spawn, SCREENSHOTCLIPBOARD_CMD }, - { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_o, spawn, SCREENSHOTCLIPBOARD_CMD }, + { MODKEY, XKB_KEY_Print, spawn, SCREENSHOTDIR_CMD }, + { MODKEY, XKB_KEY_o, spawn, SCREENSHOTDIR_CMD }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_O, spawn, SCREENSHOTCLIPBOARD_CMD }, // Apps { MODKEY, XKB_KEY_m, spawn, TERM("neomutt") }, @@ -259,3 +286,10 @@ static const Button buttons[] = { { MODKEY, BTN_MIDDLE, togglefloating, {0} }, { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} }, }; + +static const Gesture gestures[] = { + { MODKEY, SWIPE_LEFT, 4, shiftview, { .i = 1 } }, + { MODKEY, SWIPE_RIGHT, 4, shiftview, { .i = -1 } }, + { MODKEY, SWIPE_UP, 3, focusstack, {.i = 1} }, + { MODKEY, SWIPE_DOWN, 3, focusstack, {.i = -1} }, +}; diff --git a/dwl.c b/dwl.c index 7cbb179..60067c8 100644 --- a/dwl.c +++ b/dwl.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,7 @@ #include #ifdef XWAYLAND #include +#include #include #include #endif @@ -91,6 +93,7 @@ enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar, NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */ #endif +enum { SWIPE_LEFT, SWIPE_RIGHT, SWIPE_DOWN, SWIPE_UP }; typedef union { int i; @@ -106,6 +109,14 @@ typedef struct { const Arg arg; } Button; +typedef struct { + unsigned int mod; + unsigned int motion; + unsigned int fingers_count; + void (*func)(const Arg *); + const Arg arg; +} Gesture; + typedef struct Pertag Pertag; typedef struct Monitor Monitor; typedef struct Client Client; @@ -219,6 +230,10 @@ struct Monitor { struct wlr_box w; /* window area, layout-relative */ struct wl_list layers[4]; /* LayerSurface.link */ const Layout *lt[2]; + int gappih; /* horizontal gap between windows */ + int gappiv; /* vertical gap between windows */ + int gappoh; /* horizontal outer gaps */ + int gappov; /* vertical outer gaps */ Pertag *pertag; unsigned int seltags; unsigned int sellt; @@ -274,6 +289,15 @@ static void arrangelayers(Monitor *m); static void autostartexec(void); static void axisnotify(struct wl_listener *listener, void *data); static void buttonpress(struct wl_listener *listener, void *data); +static int ongesture(struct wlr_pointer_swipe_end_event *event); +static void swipe_begin(struct wl_listener *listener, void *data); +static void swipe_update(struct wl_listener *listener, void *data); +static void swipe_end(struct wl_listener *listener, void *data); +static void pinch_begin(struct wl_listener *listener, void *data); +static void pinch_update(struct wl_listener *listener, void *data); +static void pinch_end(struct wl_listener *listener, void *data); +static void hold_begin(struct wl_listener *listener, void *data); +static void hold_end(struct wl_listener *listener, void *data); static void chvt(const Arg *arg); static void checkidleinhibitor(struct wlr_surface *exclude); static void cleanup(void); @@ -296,6 +320,7 @@ static void createpopup(struct wl_listener *listener, void *data); static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint); static void cursorframe(struct wl_listener *listener, void *data); static void cursorwarptohint(void); +static void defaultgaps(const Arg *arg); static void destroydecoration(struct wl_listener *listener, void *data); static void destroydragicon(struct wl_listener *listener, void *data); static void destroyidleinhibitor(struct wl_listener *listener, void *data); @@ -328,6 +353,13 @@ static void fullscreennotify(struct wl_listener *listener, void *data); static void gpureset(struct wl_listener *listener, void *data); static void handlesig(int signo); static void incnmaster(const Arg *arg); +static void incgaps(const Arg *arg); +static void incigaps(const Arg *arg); +static void incihgaps(const Arg *arg); +static void incivgaps(const Arg *arg); +static void incogaps(const Arg *arg); +static void incohgaps(const Arg *arg); +static void incovgaps(const Arg *arg); static void inputdevice(struct wl_listener *listener, void *data); static int keybinding(uint32_t mods, xkb_keysym_t sym); static void keypress(struct wl_listener *listener, void *data); @@ -361,6 +393,7 @@ 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(int oh, int ov, int ih, int iv); static void setsticky(Client *c, int sticky); static void setfakefullscreen(Client *c, int fullscreen); static void setgamma(struct wl_listener *listener, void *data); @@ -379,6 +412,7 @@ 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 togglefakefullscreen(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); @@ -437,6 +471,7 @@ static struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr; static struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr; static struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr; static struct wlr_output_power_manager_v1 *power_mgr; +static struct wlr_pointer_gestures_v1 *pointer_gestures; static struct wlr_pointer_constraints_v1 *pointer_constraints; static struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr; @@ -467,6 +502,12 @@ 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 int enablegaps = 1; /* enables gaps, used by togglegaps */ + +static uint32_t swipe_fingers = 0; +static double swipe_dx = 0; +static double swipe_dy = 0; + #ifdef XWAYLAND static void activatex11(struct wl_listener *listener, void *data); static void associatex11(struct wl_listener *listener, void *data); @@ -497,6 +538,8 @@ struct Pertag { static pid_t *autostart_pids; static size_t autostart_len; +static const unsigned int abzsquare = swipe_min_threshold * swipe_min_threshold; + /* function implementations */ void applybounds(Client *c, struct wlr_box *bbox) @@ -763,6 +806,174 @@ buttonpress(struct wl_listener *listener, void *data) event->time_msec, event->button, event->state); } +void +swipe_begin(struct wl_listener *listener, void *data) +{ + struct wlr_pointer_swipe_begin_event *event = data; + + swipe_fingers = event->fingers; + // Reset swipe distance at the beginning of a swipe + swipe_dx = 0; + swipe_dy = 0; + + // Forward swipe begin event to client + wlr_pointer_gestures_v1_send_swipe_begin( + pointer_gestures, + seat, + event->time_msec, + event->fingers + ); +} + +void +swipe_update(struct wl_listener *listener, void *data) +{ + struct wlr_pointer_swipe_update_event *event = data; + + swipe_fingers = event->fingers; + // Accumulate swipe distance + swipe_dx += event->dx; + swipe_dy += event->dy; + + // Forward swipe update event to client + wlr_pointer_gestures_v1_send_swipe_update( + pointer_gestures, + seat, + event->time_msec, + event->dx, + event->dy + ); +} + +int +ongesture(struct wlr_pointer_swipe_end_event *event) +{ + struct wlr_keyboard *keyboard; + uint32_t mods; + const Gesture *g; + unsigned int motion; + unsigned int adx = (int)round(fabs(swipe_dx)); + unsigned int ady = (int)round(fabs(swipe_dy)); + int handled = 0; + + if (event->cancelled) { + return handled; + } + + // Require absolute distance movement beyond a small thresh-hold + if (adx * adx + ady * ady < abzsquare) { + return handled; + } + + if (adx > ady) { + motion = swipe_dx < 0 ? SWIPE_LEFT : SWIPE_RIGHT; + } else { + motion = swipe_dy < 0 ? SWIPE_UP : SWIPE_DOWN; + } + + keyboard = wlr_seat_get_keyboard(seat); + mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; + for (g = gestures; g < END(gestures); g++) { + if (CLEANMASK(mods) == CLEANMASK(g->mod) && + swipe_fingers == g->fingers_count && + motion == g->motion && g->func) { + g->func(&g->arg); + handled = 1; + } + } + return handled; +} + +void +swipe_end(struct wl_listener *listener, void *data) +{ + struct wlr_pointer_swipe_end_event *event = data; + + // TODO: should we stop here if the event has been handled? + ongesture(event); + + // Forward swipe end event to client + wlr_pointer_gestures_v1_send_swipe_end( + pointer_gestures, + seat, + event->time_msec, + event->cancelled + ); +} + +void +pinch_begin(struct wl_listener *listener, void *data) +{ + struct wlr_pointer_pinch_begin_event *event = data; + + // Forward pinch begin event to client + wlr_pointer_gestures_v1_send_pinch_begin( + pointer_gestures, + seat, + event->time_msec, + event->fingers + ); +} + +void +pinch_update(struct wl_listener *listener, void *data) +{ + struct wlr_pointer_pinch_update_event *event = data; + + // Forward pinch update event to client + wlr_pointer_gestures_v1_send_pinch_update( + pointer_gestures, + seat, + event->time_msec, + event->dx, + event->dy, + event->scale, + event->rotation + ); +} + +void +pinch_end(struct wl_listener *listener, void *data) +{ + struct wlr_pointer_pinch_end_event *event = data; + + // Forward pinch end event to client + wlr_pointer_gestures_v1_send_pinch_end( + pointer_gestures, + seat, + event->time_msec, + event->cancelled + ); +} + +void +hold_begin(struct wl_listener *listener, void *data) +{ + struct wlr_pointer_hold_begin_event *event = data; + + // Forward hold begin event to client + wlr_pointer_gestures_v1_send_hold_begin( + pointer_gestures, + seat, + event->time_msec, + event->fingers + ); +} + +void +hold_end(struct wl_listener *listener, void *data) +{ + struct wlr_pointer_hold_end_event *event = data; + + // Forward hold end event to client + wlr_pointer_gestures_v1_send_hold_end( + pointer_gestures, + seat, + event->time_msec, + event->cancelled + ); +} + void chvt(const Arg *arg) { @@ -1120,6 +1331,11 @@ createmon(struct wl_listener *listener, void *data) for (i = 0; i < LENGTH(m->layers); i++) wl_list_init(&m->layers[i]); + m->gappih = gappih; + m->gappiv = gappiv; + m->gappoh = gappoh; + m->gappov = gappov; + wlr_output_state_init(&state); /* Initialize monitor state using configured rules */ m->tagset[0] = m->tagset[1] = 1; @@ -1313,6 +1529,12 @@ cursorwarptohint(void) } } +void +defaultgaps(const Arg *arg) +{ + setgaps(gappoh, gappov, gappih, gappiv); +} + void destroydecoration(struct wl_listener *listener, void *data) { @@ -1989,6 +2211,83 @@ incnmaster(const Arg *arg) arrange(selmon); } +void +incgaps(const Arg *arg) +{ + setgaps( + selmon->gappoh + arg->i, + selmon->gappov + arg->i, + selmon->gappih + arg->i, + selmon->gappiv + arg->i + ); +} + +void +incigaps(const Arg *arg) +{ + setgaps( + selmon->gappoh, + selmon->gappov, + selmon->gappih + arg->i, + selmon->gappiv + arg->i + ); +} + +void +incihgaps(const Arg *arg) +{ + setgaps( + selmon->gappoh, + selmon->gappov, + selmon->gappih + arg->i, + selmon->gappiv + ); +} + +void +incivgaps(const Arg *arg) +{ + setgaps( + selmon->gappoh, + selmon->gappov, + selmon->gappih, + selmon->gappiv + arg->i + ); +} + +void +incogaps(const Arg *arg) +{ + setgaps( + selmon->gappoh + arg->i, + selmon->gappov + arg->i, + selmon->gappih, + selmon->gappiv + ); +} + +void +incohgaps(const Arg *arg) +{ + setgaps( + selmon->gappoh + arg->i, + selmon->gappov, + selmon->gappih, + selmon->gappiv + ); +} + +void +incovgaps(const Arg *arg) +{ + setgaps( + selmon->gappoh, + selmon->gappov + arg->i, + selmon->gappih, + selmon->gappiv + ); +} + void inputdevice(struct wl_listener *listener, void *data) { @@ -2246,8 +2545,12 @@ monocle(Monitor *m) wl_list_for_each(c, &clients, link) { if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) continue; - resize(c, m->w, 0); n++; + if (!monoclegaps) + resize(c, m->w, 0); + else + resize(c, (struct wlr_box){.x = m->w.x + gappoh, .y = m->w.y + gappov, + .width = m->w.width - 2 * gappoh, .height = m->w.height - 2 * gappov}, 0); } if (n) snprintf(m->ltsymbol, LENGTH(m->ltsymbol), "[%d]", n); @@ -2814,6 +3117,16 @@ setsticky(Client *c, int sticky) } } +void +setgaps(int oh, int ov, int ih, int iv) +{ + selmon->gappoh = MAX(oh, 0); + selmon->gappov = MAX(ov, 0); + selmon->gappih = MAX(ih, 0); + selmon->gappiv = MAX(iv, 0); + arrange(selmon); +} + void setlayout(const Arg *arg) { @@ -3081,6 +3394,16 @@ setup(void) virtual_pointer_mgr = wlr_virtual_pointer_manager_v1_create(dpy); LISTEN_STATIC(&virtual_pointer_mgr->events.new_virtual_pointer, virtualpointer); + pointer_gestures = wlr_pointer_gestures_v1_create(dpy); + LISTEN_STATIC(&cursor->events.swipe_begin, swipe_begin); + LISTEN_STATIC(&cursor->events.swipe_update, swipe_update); + LISTEN_STATIC(&cursor->events.swipe_end, swipe_end); + LISTEN_STATIC(&cursor->events.pinch_begin, pinch_begin); + LISTEN_STATIC(&cursor->events.pinch_update, pinch_update); + LISTEN_STATIC(&cursor->events.pinch_end, pinch_end); + LISTEN_STATIC(&cursor->events.hold_begin, hold_begin); + LISTEN_STATIC(&cursor->events.hold_end, hold_end); + seat = wlr_seat_create(dpy, "seat0"); LISTEN_STATIC(&seat->events.request_set_cursor, setcursor); LISTEN_STATIC(&seat->events.request_set_selection, setsel); @@ -3163,7 +3486,7 @@ tagmon(const Arg *arg) void tile(Monitor *m) { - unsigned int mw, my, ty; + unsigned int mw, my, ty, h, r, oe = enablegaps, ie = enablegaps; int i, n = 0; Client *c; @@ -3173,22 +3496,31 @@ tile(Monitor *m) if (n == 0) return; + if (smartgaps == n) { + oe = 0; // outer gaps disabled + } + if (n > m->nmaster) - mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0; + mw = m->nmaster ? (int)roundf((m->w.width + m->gappiv*ie) * m->mfact) : 0; else - mw = m->w.width; - i = my = ty = 0; + mw = m->w.width - 2*m->gappov*oe + m->gappiv*ie; + i = 0; + my = ty = m->gappoh*oe; 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; + r = MIN(n, m->nmaster) - i; + h = (m->w.height - my - m->gappoh*oe - m->gappih*ie * (r - 1)) / r; + resize(c, (struct wlr_box){.x = m->w.x + m->gappov*oe, .y = m->w.y + my, + .width = mw - m->gappiv*ie, .height = h}, 0); + my += c->geom.height + m->gappih*ie; } 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; + r = n - i; + h = (m->w.height - ty - m->gappoh*oe - m->gappih*ie * (r - 1)) / r; + resize(c, (struct wlr_box){.x = m->w.x + mw + m->gappov*oe, .y = m->w.y + ty, + .width = m->w.width - mw - 2*m->gappov*oe, .height = h}, 0); + ty += c->geom.height + m->gappih*ie; } i++; } @@ -3236,6 +3568,13 @@ togglesticky(const Arg *arg) setsticky(c, !c->issticky); } +void +togglegaps(const Arg *arg) +{ + enablegaps = !enablegaps; + arrange(selmon); +} + void toggletag(const Arg *arg) { diff --git a/shiftview.c b/shiftview.c new file mode 100644 index 0000000..fa53db0 --- /dev/null +++ b/shiftview.c @@ -0,0 +1,34 @@ +// "arg->i" stores the number of tags to shift right (positive value) +// or left (negative value) +void +shiftview(const Arg *arg) +{ + Arg a; + Client *c; + bool visible = false; + int i = arg->i; + int count = 0; + int nextseltags, curseltags = selmon->tagset[selmon->seltags]; + + do { + if (i > 0) // left circular shift + nextseltags = (curseltags << i) | (curseltags >> (TAGCOUNT - i)); + else // right circular shift + nextseltags = curseltags >> (-i) | (curseltags << (TAGCOUNT + i)); + + // Check if the tag is visible + wl_list_for_each(c, &clients, link) { + if (c->mon == selmon && nextseltags & c->tags) { + visible = true; + break; + } + } + + i += arg->i; + } while (!visible && ++count <= TAGCOUNT); + + if (count <= TAGCOUNT) { + a.i = nextseltags; + view(&a); + } +}