~ft/riow

737ffa63cece7382369c4b8eaaa2906ba3bae259 — Sigrid Solveig Haflínudóttir 2 years ago b6b91c9
Kmod4+h/j/k/l - focus left/down/up/right; re-read label to keep sticky status up to date
3 files changed, 73 insertions(+), 12 deletions(-)

M README.md
M riow.c
M riow.man
M README.md => README.md +2 -1
@@ 13,7 13,8 @@ work with drawterm.*
 * virtual desktops from 1 to 0
 * switch between desktops
 * move windows between desktops
 * toggle fullscreen on the current window
 * switch focus between windows
 * toggle fullscreen mode on the current window
 * start a new window
 * "sticky" programs, by default `stats`, `kbmap` etc are shown on every desktop
 * toggle "sticky" mode for current window

M riow.c => riow.c +68 -11
@@ 112,17 112,20 @@ wsupdate(void)
		if(!seen){
			/* not seen previously - set the new state for it */
			w->vd = vd;
			snprint(s, sizeof(s), "/dev/wsys/%d/label", w->id);
			if((f = open(s, OREAD)) >= 0){
				n = read(f, s, sizeof(s)-1);
				close(f);
				if(n > 0){
					s[n] = 0;
					for(k = 0; k < nelem(sticky) && sticky[k] != nil; k++){
						if(strcmp(sticky[k], s) == 0){
							w->flags |= Fsticky;
							break;
						}
		}

		/* because a different program can run in any window we have to re-read */
		snprint(s, sizeof(s), "/dev/wsys/%d/label", w->id);
		w->flags &= ~Fsticky;
		if((f = open(s, OREAD)) >= 0){
			n = read(f, s, sizeof(s)-1);
			close(f);
			if(n > 0){
				s[n] = 0;
				for(k = 0; k < nelem(sticky) && sticky[k] != nil; k++){
					if(strcmp(sticky[k], s) == 0){
						w->flags |= Fsticky;
						break;
					}
				}
			}


@@ 235,6 238,52 @@ arrowaction(int x, int y)
	close(f);
}

static struct {
	int x, y;
}cyclectx;

static int
cyclecmp(void *a_, void *b_)
{
	W *a = a_, *b = b_;

	return cyclectx.x*(a->r.min.x - b->r.min.x) + cyclectx.y*(a->r.min.y - b->r.min.y);
}

static void
cycleaction(int x, int y)
{
	int wcurid, i, f;
	W *w, *w₀;

	wcurid = wcur == nil ? -1 : wcur->id;
	cyclectx.x = x;
	cyclectx.y = y;
	qsort(ws, wsn, sizeof(*ws), cyclecmp);
	w₀ = nil;
	wcur = nil;
	for(i = 0, w = ws; i < wsn; i++, w++){
		if(w->id == wcurid){
			wcur = w;
			continue;
		}
		if((w->flags & Fsticky) != 0 || w->vd != vd)
			continue;
		if(w₀ == nil)
			w₀ = w;
		if(wcur != nil)
			break;
	}
	if(i >= wsn)
		w = w₀;
	if(w == nil || (f = wwctl(w->id, OWRITE)) < 0)
		return;
	fprint(f, "top");
	fprint(f, "current");
	close(f);
	wcur = w;
}

static void
keyevent(Rune r)
{


@@ 256,6 305,14 @@ keyevent(Rune r)
		arrowaction(-1, 0);
	else if(r == Kright)
		arrowaction(1, 0);
	else if(r == 'h')
		cycleaction(-1, 0);
	else if(r == 'l')
		cycleaction(1, 0);
	else if(r == 'j')
		cycleaction(0, 1);
	else if(r == 'k')
		cycleaction(0, -1);
}

static void

M riow.man => riow.man +3 -0
@@ 58,6 58,9 @@ option.
Spawn a new
.IR window(1) .
.TP
.B Kmod4+h/j/k/l
Focus left/down/up/right.
.TP
.B Kmod4+arrows
Move the current window in the specified direction.
.TP