~kris/suckless

slock

ref: 35fd53f6f2f5c911532572e889333c4b43927afa slock/patch/keypress_feedback.c -rw-r--r-- 870 bytes
35fd53f6 — bakkeby Adding secret password patch 5 years ago
                                                                                
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
static void
draw_key_feedback(Display *dpy, struct lock **locks, int screen)
{
	XGCValues gr_values;

	Window win = locks[screen]->win;
	Window root_win;

	gr_values.foreground = locks[screen]->colors[BLOCKS];
	GC gc = XCreateGC(dpy, win, GCForeground, &gr_values);

	int width = blocks_width, height = blocks_height;
	if (blocks_height == 0 || blocks_width == 0) {
		int _x, _y;
		unsigned int screen_width, screen_height, _b, _d;
		XGetGeometry(dpy, win, &root_win, &_x, &_y, &screen_width, &screen_height, &_b, &_d);
		width = blocks_width ? blocks_width : screen_width;
		height = blocks_height ? blocks_height : screen_height;
	}

	unsigned int block_width = width / blocks_count;
	unsigned int position = rand() % blocks_count;

	XClearWindow(dpy, win);
	XFillRectangle(dpy, win, gc, blocks_x + position*block_width, blocks_y, width, height);

	XFreeGC(dpy, gc);
}