storename.c (937B)
1 /* 2 * Copyright 2021 Jacob R. Edwards 3 * License: GPLv3 4 * Compile: 5 * cc -o storename -L/usr/X11R6/lib -I/usr/X11R6/include storename.c -lX11 6 * 7 * The storename utility stores each line of input as the default 8 * root window's name until EOF is encountered. 9 */ 10 11 #include <X11/Xlib.h> 12 13 #include <stdio.h> 14 #include <stdlib.h> 15 #include <string.h> 16 #ifdef __OpenBSD__ 17 #include <unistd.h> 18 #endif 19 20 void 21 die(char *s) 22 { 23 perror(s); 24 exit(1); 25 } 26 27 int 28 main(void) 29 { 30 Display *display; 31 char *buf; 32 size_t size; 33 ssize_t len; 34 35 display = XOpenDisplay(NULL); 36 if (display == NULL) 37 die("unable to open display"); 38 39 #ifdef __OpenBSD__ 40 if (pledge("stdio", NULL) == -1) 41 die("pledge"); 42 #endif 43 44 while ((len = getline(&buf, &size, stdin)) != -1) { 45 if (buf[len - 1] == '\n') 46 buf[len - 1] = 0; 47 XStoreName(display, DefaultRootWindow(display), buf); 48 XFlush(display); 49 } 50 51 XCloseDisplay(display); 52 if (ferror(stdin)) 53 die("stdin"); 54 return 0; 55 }