dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

riodraw.c (2084B)


      1 /* drag out an area using slop and resize the selected window to it. */
      2 int
      3 riodraw(Client *c, const char slopstyle[])
      4 {
      5 	int i;
      6 	char str[100];
      7 	char strout[100];
      8 	char tmpstring[30] = {0};
      9 	char slopcmd[100] = "slop -f x%xx%yx%wx%hx ";
     10 	int firstchar = 0;
     11 	int counter = 0;
     12 
     13 	strcat(slopcmd, slopstyle);
     14 	FILE *fp = popen(slopcmd, "r");
     15 
     16 	while (fgets(str, 100, fp) != NULL)
     17 		strcat(strout, str);
     18 
     19 	pclose(fp);
     20 
     21 	if (strlen(strout) < 6)
     22 		return 0;
     23 
     24 	for (i = 0; i < strlen(strout); i++){
     25 		if (!firstchar) {
     26 			if (strout[i] == 'x')
     27 				firstchar = 1;
     28 			continue;
     29 		}
     30 
     31 		if (strout[i] != 'x')
     32 			tmpstring[strlen(tmpstring)] = strout[i];
     33 		else {
     34 			riodimensions[counter] = atoi(tmpstring);
     35 			counter++;
     36 			memset(tmpstring,0,strlen(tmpstring));
     37 		}
     38 	}
     39 
     40 	if (riodimensions[0] <= -40 || riodimensions[1] <= -40 || riodimensions[2] <= 50 || riodimensions[3] <= 50) {
     41 		riodimensions[3] = -1;
     42 		return 0;
     43 	}
     44 
     45 	if (c) {
     46 		rioposition(c, riodimensions[0], riodimensions[1], riodimensions[2], riodimensions[3]);
     47 		return 0;
     48 	}
     49 
     50 	return 1;
     51 }
     52 
     53 void
     54 rioposition(Client *c, int x, int y, int w, int h)
     55 {
     56 	Monitor *m;
     57 	if ((m = recttomon(x, y, w, h)) && m != c->mon) {
     58 		detach(c);
     59 		detachstack(c);
     60 		arrange(c->mon);
     61 		c->mon = m;
     62 		c->tags = m->tagset[m->seltags];
     63 		attach(c);
     64 		attachstack(c);
     65 		selmon = m;
     66 		focus(c);
     67 	}
     68 
     69 	c->isfloating = 1;
     70 	if (riodraw_borders)
     71 		resizeclient(c, x, y, w - (c->bw * 2), h - (c->bw * 2));
     72 	else
     73 		resizeclient(c, x - c->bw, y - c->bw, w, h);
     74 	drawbar(c->mon);
     75 	arrange(c->mon);
     76 
     77 	riodimensions[3] = -1;
     78 	riopid = 0;
     79 }
     80 
     81 /* drag out an area using slop and resize the selected window to it */
     82 void
     83 rioresize(const Arg *arg)
     84 {
     85 	Client *c = (arg && arg->v ? (Client*)arg->v : selmon->sel);
     86 	if (c)
     87 		riodraw(c, slopresizestyle);
     88 }
     89 
     90 /* Spawn a new window and drag out an area using slop to position it while the window is
     91  * initialising in the background. */
     92 void
     93 riospawn(const Arg *arg)
     94 {
     95 	riopid = spawncmd(arg);
     96 	riodraw(NULL, slopspawnstyle);
     97 }
     98 
     99 void
    100 riospawnsync(const Arg *arg)
    101 {
    102 	if (riodraw(NULL, slopspawnstyle))
    103 		riopid = spawncmd(arg);
    104 }
    105