slock

Kris's build of slock (slock-flexipatch)
git clone git clone https://git.krisyotam.com/krisyotam/slock.git
Log | Files | Refs | README | LICENSE

background_image.c (1640B)


      1 #include <Imlib2.h>
      2 
      3 Imlib_Image image;
      4 
      5 void
      6 render_lock_image(Display *dpy, struct lock *lock, Imlib_Image image)
      7 {
      8 	if (image) {
      9 		lock->bgmap = XCreatePixmap(dpy, lock->root, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), DefaultDepth(dpy, lock->screen));
     10 		imlib_context_set_display(dpy);
     11 		imlib_context_set_visual(DefaultVisual(dpy, lock->screen));
     12 		imlib_context_set_colormap(DefaultColormap(dpy, lock->screen));
     13 		imlib_context_set_drawable(lock->bgmap);
     14 		imlib_render_image_on_drawable(0, 0);
     15 		imlib_free_image();
     16 	}
     17 }
     18 
     19 void
     20 create_lock_image(Display *dpy)
     21 {
     22 	/* Load picture */
     23 	Imlib_Image buffer = imlib_load_image(background_image);
     24 
     25 	if (!buffer) {
     26 		fprintf(stderr, "Failed to load background image: %s\n", background_image);
     27 		return;
     28 	}
     29 
     30 	imlib_context_set_image(buffer);
     31 	int background_image_width = imlib_image_get_width();
     32 	int background_image_height = imlib_image_get_height();
     33 
     34 	/* Create an image to be rendered */
     35 	Screen *scr = ScreenOfDisplay(dpy, DefaultScreen(dpy));
     36 	image = imlib_create_image(scr->width, scr->height);
     37 	imlib_context_set_image(image);
     38 
     39 	/* Fill the image for every X monitor */
     40 	XRRMonitorInfo	*monitors;
     41 	int number_of_monitors;
     42 	monitors = XRRGetMonitors(dpy, RootWindow(dpy, XScreenNumberOfScreen(scr)), True, &number_of_monitors);
     43 
     44 	int i;
     45 	for (i = 0; i < number_of_monitors; i++) {
     46 	    imlib_blend_image_onto_image(buffer, 0, 0, 0, background_image_width, background_image_height, monitors[i].x, monitors[i].y, monitors[i].width, monitors[i].height);
     47 	}
     48 
     49 	/* Clean up */
     50 	imlib_context_set_image(buffer);
     51 	imlib_free_image();
     52 	imlib_context_set_image(image);
     53 }