summaryrefslogtreecommitdiffhomepage
path: root/patch/riodraw.c
blob: ace3acc2f408d72132fedab5f932a212b0e7bad6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* drag out an area using slop and resize the selected window to it. */
void
riodraw(const Arg *arg)
{
	char str[100];
	int i;
	char strout[100];
	int dimensions[4];
	int width, height, x, y;
	char tmpstring[30] = {0};
	char slopcmd[100] = "slop -f x%xx%yx%wx%hx ";
	int firstchar = 0;
	int counter = 0;
	Monitor *m;
	Client *c;

	if (!selmon->sel)
		return;
	strcat(slopcmd, slopstyle);
	FILE *fp = popen(slopcmd, "r");

	while (fgets(str, 100, fp) != NULL)
		strcat(strout, str);

	pclose(fp);

	if (strlen(strout) < 6)
		return;

	for (i = 0; i < strlen(strout); i++){
		if (!firstchar) {
			if (strout[i] == 'x')
				firstchar = 1;
			continue;
		}

		if (strout[i] != 'x')
			tmpstring[strlen(tmpstring)] = strout[i];
		else {
			dimensions[counter] = atoi(tmpstring);
			counter++;
			memset(tmpstring,0,strlen(tmpstring));
		}
	}

	x = dimensions[0];
	y = dimensions[1];
	width = dimensions[2];
	height = dimensions[3];

	if (!selmon->sel)
		return;

	c = selmon->sel;

	if (width > 50 && height > 50 && x > -40 && y > -40 && width < selmon->mw + 40 && height < selmon->mh + 40 &&
	(abs(c->w - width) > 20 || abs(c->h - height) > 20 || abs(c->x - x) > 20 || abs(c->y - y) > 20)) {
		if ((m = recttomon(x, y, width, height)) != selmon) {
			sendmon(c, m);
			unfocus(selmon->sel, 0, NULL);
			selmon = m;
			focus(NULL);
		}

		if (!c->isfloating)
			togglefloating(NULL);
		resizeclient(c, x, y, width - (c->bw * 2), height - (c->bw * 2));
		arrange(selmon);
	} else
		fprintf(stderr, "error %s", strout);
	memset(tmpstring,0,strlen(tmpstring));
}