~ruther/dwl

cafed0f6f1d8bad7a12d255b8f7c575599644aba — Rutherther 11 months ago bd59573 v0.7/accessnthmonitor
feat: access nth monitor
2 files changed, 49 insertions(+), 1 deletions(-)

M config.def.h
M dwl.c
M config.def.h => config.def.h +3 -1
@@ 113,7 113,9 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA
	{ MODKEY,                    KEY,            view,            {.ui = 1 << TAG} }, \
	{ MODKEY|WLR_MODIFIER_CTRL,  KEY,            toggleview,      {.ui = 1 << TAG} }, \
	{ MODKEY|WLR_MODIFIER_SHIFT, SKEY,           tag,             {.ui = 1 << TAG} }, \
	{ MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,SKEY,toggletag, {.ui = 1 << TAG} }
	{ MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,SKEY,toggletag, {.ui = 1 << TAG} }, \
	{ WLR_MODIFIER_ALT,          KEY,            focusnthmon,     {.ui = TAG} }, \
	{ WLR_MODIFIER_ALT|WLR_MODIFIER_SHIFT, SKEY, tagnthmon,       {.ui = TAG} }

/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }

M dwl.c => dwl.c +46 -0
@@ 12,6 12,7 @@
#include <time.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wayland-util.h>
#include <wlr/backend.h>
#include <wlr/backend/libinput.h>
#include <wlr/render/allocator.h>


@@ 285,8 286,10 @@ static void destroysessionlock(struct wl_listener *listener, void *data);
static void destroysessionmgr(struct wl_listener *listener, void *data);
static void destroykeyboardgroup(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir);
static Monitor *numtomon(int num);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
static void focusnthmon(const Arg *arg);
static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m);
static void fullscreennotify(struct wl_listener *listener, void *data);


@@ 337,6 340,7 @@ static void spawn(const Arg *arg);
static void startdrag(struct wl_listener *listener, void *data);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tagnthmon(const Arg *arg);
static void tile(Monitor *m);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);


@@ 1335,6 1339,25 @@ dirtomon(enum wlr_direction dir)
	return selmon;
}

Monitor *
numtomon(int num)
{
	Monitor *m = NULL;
	int found = 0;
	int i = 0;

	wl_list_for_each(m, &mons, link) {
		if (!m->wlr_output->enabled)
			i--;
		else if (i == num) {
			found = true;
			break;
		}
		i++;
	}
	return found ? m : NULL;
}

void
focusclient(Client *c, int lift)
{


@@ 1423,6 1446,16 @@ focusmon(const Arg *arg)
}

void
focusnthmon(const Arg *arg)
{
	Monitor *m = numtomon(arg->i);
	if (!m || m == selmon)
		return;
	selmon = m;
	focusclient(focustop(selmon), 1);
}

void
focusstack(const Arg *arg)
{
	/* Focus the next or previous client (in tiling order) on selmon */


@@ 2688,6 2721,19 @@ tagmon(const Arg *arg)
}

void
tagnthmon(const Arg *arg)
{
	Client *sel = focustop(selmon);
	Monitor *m = numtomon(arg->i);
	if (!m || !sel)
		return;
	setmon(sel, m, 0);

	arrange(selmon);
	arrange(m);
}

void
tile(Monitor *m)
{
	unsigned int mw, my, ty;

Do not follow this link