sara icon indicating copy to clipboard operation
sara copied to clipboard

MoveFocusAbs Patch

Open TakeYourFreedom opened this issue 5 years ago • 1 comments

And another patch. This one adds a function to focus a window directly: for example sarasock 'movefocusabs 0' focuses the master window, sarasock 'movefocusabs 2' the third window on the current desktop. I will just send you all my changes as patches so you can decide if you want to incorporate them into the base or keep them as patches.

TakeYourFreedom avatar May 04 '20 19:05 TakeYourFreedom

void
movefocusabs(const Arg arg){
	int i = 0;
	client* c = NULL;

	if (!curmon->current || curmon->current->isfull)
		return;

	parser[WantInt](arg.s, &parg);

        if (parg.i < 0)
                return;

	for EACHCLIENT(curmon->head){
		if (ISVISIBLE(ic)){
			if (i == parg.i){
				c = ic;
                                break;
                        }

			i++;
		}
	}

	if (c && c != curmon->current){
		changecurrent(c, curmon, curmon->curdesk, 0);
		restack(curmon);
	}
}

I changed the if so that it properly checks for client presence. If a client is tagged to more than one desktop (i.e. ic->desks is not of the form 00001000) then the old test would fail. ISVISIBLE(ic) implies that ic is on curmon->curdesk, because curdesk should always coincide with ic->mon->seldesks. Also added a break to stop looping when we've found the proper client.

I also changed the parg.i >= 0 check so that the code is less indented. If you wanted to implement it in the opposite direction as well (i.e. movefocusabs -1 focuses the last client in the list, movefocusabs -2 focuses the second to last), obviously you could change this back.

I wouldn't directly copy-paste the code - I edited it in this comment and had trouble with spaces vs tabs, so there's currently a mixture...

gitluin avatar May 06 '20 14:05 gitluin