added black window
This commit is contained in:
		
							parent
							
								
									763e52878d
								
							
						
					
					
						commit
						50bc1a788e
					
				
							
								
								
									
										20
									
								
								slock.c
								
								
								
								
							
							
						
						
									
										20
									
								
								slock.c
								
								
								
								
							| 
						 | 
					@ -15,13 +15,15 @@
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
main(int argc, char **argv) {
 | 
					main(int argc, char **argv) {
 | 
				
			||||||
	char buf[32], passwd[256];
 | 
						char buf[32], passwd[256];
 | 
				
			||||||
	int num, prev_nitem;
 | 
						int num, prev_nitem, screen;
 | 
				
			||||||
	struct spwd *sp;
 | 
						struct spwd *sp;
 | 
				
			||||||
	unsigned int i, len;
 | 
						unsigned int i, len;
 | 
				
			||||||
	Bool running = True;
 | 
						Bool running = True;
 | 
				
			||||||
	KeySym ksym;
 | 
						KeySym ksym;
 | 
				
			||||||
	Display *dpy;
 | 
						Display *dpy;
 | 
				
			||||||
 | 
						Window w;
 | 
				
			||||||
	XEvent ev;
 | 
						XEvent ev;
 | 
				
			||||||
 | 
						XSetWindowAttributes wa;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
 | 
						if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
 | 
				
			||||||
		fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
 | 
							fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
 | 
				
			||||||
| 
						 | 
					@ -36,13 +38,23 @@ main(int argc, char **argv) {
 | 
				
			||||||
		fputs("slock: cannot open display\n", stderr);
 | 
							fputs("slock: cannot open display\n", stderr);
 | 
				
			||||||
		exit(EXIT_FAILURE);
 | 
							exit(EXIT_FAILURE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						screen = DefaultScreen(dpy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* init */
 | 
						/* init */
 | 
				
			||||||
	passwd[0] = 0;
 | 
						passwd[0] = 0;
 | 
				
			||||||
	while(XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync,
 | 
						while(XGrabKeyboard(dpy, RootWindow(dpy, screen), True, GrabModeAsync,
 | 
				
			||||||
			 GrabModeAsync, CurrentTime) != GrabSuccess)
 | 
								 GrabModeAsync, CurrentTime) != GrabSuccess)
 | 
				
			||||||
		usleep(1000);
 | 
							usleep(1000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wa.override_redirect = 1;
 | 
				
			||||||
 | 
						wa.background_pixel = BlackPixel(dpy, screen);
 | 
				
			||||||
 | 
						w = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0,
 | 
				
			||||||
 | 
								DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
 | 
				
			||||||
 | 
								0, DefaultDepth(dpy, screen), CopyFromParent,
 | 
				
			||||||
 | 
								DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa);
 | 
				
			||||||
 | 
						XMapRaised(dpy, w);
 | 
				
			||||||
 | 
						XSync(dpy, False);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* main event loop */
 | 
						/* main event loop */
 | 
				
			||||||
	while(running && !XNextEvent(dpy, &ev))
 | 
						while(running && !XNextEvent(dpy, &ev))
 | 
				
			||||||
		if(ev.type == KeyPress) {
 | 
							if(ev.type == KeyPress) {
 | 
				
			||||||
| 
						 | 
					@ -66,7 +78,8 @@ main(int argc, char **argv) {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			switch(ksym) {
 | 
								switch(ksym) {
 | 
				
			||||||
			case XK_Return:
 | 
								case XK_Return:
 | 
				
			||||||
				running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd));
 | 
									if((running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd))))
 | 
				
			||||||
 | 
										XBell(dpy, 100);
 | 
				
			||||||
				passwd[0] = 0;
 | 
									passwd[0] = 0;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case XK_Escape:
 | 
								case XK_Escape:
 | 
				
			||||||
| 
						 | 
					@ -87,6 +100,7 @@ main(int argc, char **argv) {
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						XDestroyWindow(dpy, w);
 | 
				
			||||||
	XCloseDisplay(dpy);
 | 
						XCloseDisplay(dpy);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue