setxbg

X11 background image
git clone https://porkepik.fr/setxbg
Log | Files | Refs | README | LICENSE

commit c51b322edd68769a6d83baa0195a143ea88cf370
parent 7d9165d7c7106a3e3bcd6d99f7a56999160edf41
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Thu,  1 Aug 2019 04:10:03 +0200

fix style to be closer to the OpenBSD guide

Diffstat:
Msetxbg.c | 39+++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/setxbg.c b/setxbg.c @@ -47,15 +47,15 @@ static void check_args(int argc, char **argv, struct image *img) { for (int i = 1; i <= argc - 1; i++) { - if (!strcmp(argv[i], "--bg-fill")) + if (strcmp(argv[i], "--bg-fill") == 0) img->bg_mode = BG_FILL; - else if (!strcmp(argv[i], "--bg-max")) + else if (strcmp(argv[i], "--bg-max") == 0) img->bg_mode = BG_MAX; - else if (!strcmp(argv[i], "--bg-center")) + else if (strcmp(argv[i], "--bg-center") == 0) img->bg_mode = BG_CENTER; - else if (!strcmp(argv[i], "--bg-color") && i+1 != argc) + else if (strcmp(argv[i], "--bg-color") == 0 && i+1 != argc) img->bg_color = argv[i+1]; - else if (!strcmp(argv[i], "-h")) + else if (strcmp(argv[i], "-h") == 0) usage(); } } @@ -94,22 +94,28 @@ static void apply_background(Display *disp, struct image img, int screen_w, int screen_h) { XImage *ximg; + Window root; + int depth; + Pixmap pixmap; + Colormap cmap; + XColor color; + XGCValues gcval; + GC gc; + ximg = XCreateImage(disp, DefaultVisual(disp, 0), 24, ZPixmap, 0, (char *)img.data, img.width, img.height, 8, 0); - Window root = DefaultRootWindow(disp); - int depth = DefaultDepth(disp, 0); - Pixmap pixmap = XCreatePixmap(disp, root, screen_w, screen_h, depth); + root = DefaultRootWindow(disp); + depth = DefaultDepth(disp, 0); + pixmap = XCreatePixmap(disp, root, screen_w, screen_h, depth); - XColor color; - Colormap cmap = DefaultColormap(disp, DefaultScreen(disp)); - if (!img.bg_color) + cmap = DefaultColormap(disp, DefaultScreen(disp)); + if (img.bg_color == NULL) XAllocNamedColor(disp, cmap, "black", &color, &color); else XAllocNamedColor(disp, cmap, img.bg_color, &color, &color); - XGCValues gcval; gcval.foreground = color.pixel; - GC gc = XCreateGC(disp, root, GCForeground, &gcval); + gc = XCreateGC(disp, root, GCForeground, &gcval); XFillRectangle(disp, pixmap, gc, 0, 0, screen_w, screen_h); XPutImage(disp, pixmap, DefaultGC(disp, 0), ximg, img.src_x, img.src_y, @@ -162,14 +168,15 @@ set_background(Display *disp, struct image *img) int main(int argc, char **argv) { + Display *disp; struct image img; img.src_x = 0, img.src_y = 0; img.dest_x = 0, img.dest_y = 0; img.bg_mode = BG_MAX; img.bg_color = NULL; - Display *disp = XOpenDisplay(NULL); - if (!disp) + disp = XOpenDisplay(NULL); + if (disp == NULL) errx(1, "Failed opening DISPLAY."); if (argc < 2) @@ -177,7 +184,7 @@ main(int argc, char **argv) check_args(argc, argv, &img); img.data = stbi_load(argv[argc-1], &img.width, &img.height, NULL, RGBA); - if (!img.data) + if (img.data == NULL) errx(1, "Error during image loading."); rgb_to_bgr(img);