~ruther/dwl

c5333e44d94f9d3cf439ac7e257d64f3f3014cfb — Rutherther a month ago 2daeeb4 v0.8/patched-keycodes
Allow applying custom logic applycustomrules

I will use this for custom rules for opening programs just the first
time or putting them to a specific tag when opened second time and so on.
2 files changed, 31 insertions(+), 13 deletions(-)

M config.def.h
M dwl.c
M config.def.h => config.def.h +6 -0
@@ 217,3 217,9 @@ static const Button buttons[] = {
	{ MODKEY, BTN_MIDDLE, togglefloating, {0} },
	{ MODKEY, BTN_RIGHT,  moveresize,     {.ui = CurResize} },
};

bool applycustomrules(const char *appid, const char *title, Rule *r)
{
  // TODO: apply any rules you wish
  return false;
}

M dwl.c => dwl.c +25 -13
@@ 261,7 261,7 @@ typedef struct {
	int noswallow;
	int allow_activation;
	int monitor;
	const char scratchkey;
	char scratchkey;
} Rule;

typedef struct {


@@ 585,7 585,7 @@ applyrules(Client *c)
	const char *appid, *title;
	uint32_t newtags = 0;
	int i;
	const Rule *r;
	Rule *r;
	Monitor *mon = selmon, *m;

	c->scratchkey = 0;


@@ 594,23 594,35 @@ applyrules(Client *c)

	c->pid = client_get_pid(c);

  void
  applyrule(const Rule *r)
  {
    c->isfloating = r->isfloating;
    c->isterm     = r->isterm;
    c->noswallow  = r->noswallow;
    c->scratchkey = r->scratchkey;
    c->allow_activation = r->allow_activation;
    newtags |= r->tags;
    i = 0;
    wl_list_for_each(m, &mons, link) {
      if (r->monitor == i++)
        mon = m;
    }
  }

	for (r = rules; r < END(rules); r++) {
		if ((!r->title || strstr(title, r->title))
				&& (!r->id || strstr(appid, r->id))) {
			c->isfloating = r->isfloating;
			c->isterm     = r->isterm;
			c->noswallow  = r->noswallow;
			c->scratchkey = r->scratchkey;
			c->allow_activation = r->allow_activation;
			newtags |= r->tags;
			i = 0;
			wl_list_for_each(m, &mons, link) {
				if (r->monitor == i++)
					mon = m;
			}
      applyrule(r);
		}
	}

  // Reset the rule.
  Rule rule = (Rule) { NULL, NULL, 0, 0, 0, 0, -1, 0 };
  if (applycustomrules(appid, title, &rule)) {
    applyrule(&rule);
  }

	wl_list_for_each(m, &mons, link) {
		// tag with different monitor selected by rules
		if (m->tagset[m->seltags] & newtags) {