sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

shift-tools-scratchpads.c (4274B)


      1 /* Sends a window to the next/prev tag */
      2 void
      3 shifttag(const Arg *arg)
      4 {
      5 	Arg shifted;
      6 	shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
      7 
      8 
      9 	if (arg->i > 0)	/* left circular shift */
     10 		shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i))) & ~SPTAGMASK;
     11 	else		/* right circular shift */
     12 		shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i)) & ~SPTAGMASK;
     13 	tag(&shifted);
     14 }
     15 /* Sends a window to the next/prev tag that has a client, else it moves it to the next/prev one. */
     16 void
     17 shifttagclients(const Arg *arg)
     18 {
     19 
     20 	Arg shifted;
     21 	Client *c;
     22 	unsigned int tagmask = 0;
     23 	shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
     24 
     25 	for (c = selmon->clients; c; c = c->next)
     26 		if (!(c->tags & SPTAGMASK))
     27 			tagmask = tagmask | c->tags;
     28 
     29 
     30 	if (arg->i > 0)	/* left circular shift */
     31 		do {
     32 			shifted.ui = (shifted.ui << arg->i)
     33 			   | (shifted.ui >> (LENGTH(tags) - arg->i));
     34 			shifted.ui &= ~SPTAGMASK;
     35 		} while (tagmask && !(shifted.ui & tagmask));
     36 	else		/* right circular shift */
     37 		do {
     38 			shifted.ui = (shifted.ui >> (- arg->i)
     39 			   | shifted.ui << (LENGTH(tags) + arg->i));
     40 			shifted.ui &= ~SPTAGMASK;
     41 		} while (tagmask && !(shifted.ui & tagmask));
     42 	tag(&shifted);
     43 }
     44 /* Navigate to the next/prev tag */
     45 void
     46 shiftview(const Arg *arg)
     47 {
     48 	Arg shifted;
     49 	shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
     50 
     51 	if (arg->i > 0) {/* left circular shift */
     52 		shifted.ui = (shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i));
     53 		shifted.ui &= ~SPTAGMASK;
     54 	} else {	/* right circular shift */
     55 		shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i));
     56 		shifted.ui &= ~SPTAGMASK;
     57 	}
     58 	view(&shifted);
     59 }
     60 /* Navigate to the next/prev tag that has a client, else moves it to the next/prev tag */
     61 void
     62 shiftviewclients(const Arg *arg)
     63 {
     64 	Arg shifted;
     65 	Client *c;
     66 	unsigned int tagmask = 0;
     67 	shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
     68 
     69 	for (c = selmon->clients; c; c = c->next)
     70 		if (!(c->tags & SPTAGMASK))
     71 			tagmask = tagmask | c->tags;
     72 
     73 
     74 	if (arg->i > 0)	/* left circular shift */
     75 		do {
     76 			shifted.ui = (shifted.ui << arg->i)
     77 			   | (shifted.ui >> (LENGTH(tags) - arg->i));
     78 			shifted.ui &= ~SPTAGMASK;
     79 		} while (tagmask && !(shifted.ui & tagmask));
     80 	else		/* right circular shift */
     81 		do {
     82 			shifted.ui = (shifted.ui >> (- arg->i)
     83 			   | shifted.ui << (LENGTH(tags) + arg->i));
     84 			shifted.ui &= ~SPTAGMASK;
     85 		} while (tagmask && !(shifted.ui & tagmask));
     86 	view(&shifted);
     87 }
     88 /* move the current active window to the next/prev tag and view it. More like following the window */
     89 void
     90 shiftboth(const Arg *arg)
     91 {
     92 	Arg shifted;
     93 	shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
     94 
     95 	if (arg->i > 0)	/* left circular shift */
     96 		shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i))) & ~SPTAGMASK;
     97 	else		/* right circular shift */
     98 		shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i))) & ~SPTAGMASK;
     99 	tag(&shifted);
    100 	view(&shifted);
    101 }
    102 //helper function for shiftswaptags found on:
    103 //https://github.com/moizifty/DWM-Build/blob/65379c62640788881486401a0d8c79333751b02f/config.h#L48
    104 // modified to work with scratchpad
    105 void
    106 swaptags(const Arg *arg)
    107 {
    108 	Client *c;
    109 	unsigned int newtag = arg->ui & TAGMASK;
    110 	unsigned int curtag = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
    111 
    112 	if (newtag == curtag || !curtag || (curtag & (curtag-1)))
    113 		return;
    114 
    115 	for (c = selmon->clients; c != NULL; c = c->next) {
    116 		if ((c->tags & newtag) || (c->tags & curtag))
    117 			c->tags ^= curtag ^ newtag;
    118 
    119 		if (!c->tags)
    120 			c->tags = newtag;
    121 	}
    122 
    123 	//move to the swaped tag
    124 	//selmon->tagset[selmon->seltags] = newtag;
    125 
    126 	focus(NULL);
    127 	arrange(selmon);
    128 }
    129 /* swaps "tags" (all the clients) with the next/prev tag. */
    130 void
    131 shiftswaptags(const Arg *arg)
    132 {
    133 	Arg shifted;
    134 	shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK;
    135 
    136 	if (arg->i > 0)	/* left circular shift */
    137 		shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i))) & ~SPTAGMASK;
    138 	else		/* right circular shift */
    139 		shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i))) & ~SPTAGMASK;
    140 	swaptags(&shifted);
    141 	// uncomment if you also want to "go" (view) the tag where the the clients are going
    142 	//view(&shifted);
    143 }