slock-feh-background-1.6.diff (3183B)
1 diff --color -up a/config.def.h b/config.def.h 2 --- a/config.def.h 3 +++ b/config.def.h 4 @@ -1,6 +1,6 @@ 5 /* user and group to drop privileges to */ 6 static const char *user = "nobody"; 7 -static const char *group = "nobody"; 8 +static const char *group = "nogroup"; 9 10 static const char *colorname[NUMCOLS] = { 11 [INIT] = "black", /* after initialization */ 12 @@ -13,3 +13,6 @@ static const int failonclear = 1; 13 14 /* Background image path, should be available to the user above */ 15 static const char* background_image = ""; 16 + 17 +/* Path to .fehbg (default: /home/user/.fehbg), should be available to the user above */ 18 +static const char *fehbg_home_path = ""; 19 diff --color -up a/slock.c b/slock.c 20 --- a/slock.c 21 +++ b/slock.c 22 @@ -129,6 +129,40 @@ gethash(void) 23 return hash; 24 } 25 26 +static char * 27 +get_fehbg_path(const char *fehbg_file) 28 +{ 29 + FILE *file = fopen(fehbg_file, "r"); 30 + if (file == NULL) { 31 + return NULL; 32 + } 33 + 34 + char buffer[500]; 35 + char *path = NULL; 36 + 37 + while (fgets(buffer, sizeof(buffer), file) != NULL) { 38 + /* Look for the first single quote */ 39 + char *start = strchr(buffer, '\''); 40 + if (start != NULL) { 41 + /* Look for the closing single quote */ 42 + char *end = strchr(start + 1, '\''); 43 + if (end != NULL) { 44 + size_t len = end - start - 1; 45 + path = (char *)malloc(len + 1); 46 + if (path != NULL) { 47 + strncpy(path, start + 1, len); 48 + path[len] = '\0'; 49 + } 50 + break; 51 + } 52 + } 53 + } 54 + 55 + fclose(file); 56 + return path; 57 +} 58 + 59 + 60 static void 61 readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, 62 const char *hash) 63 @@ -378,6 +412,7 @@ main(int argc, char **argv) { 64 die("slock: setuid: %s\n", strerror(errno)); 65 66 /* Load picture */ 67 + background_image = get_fehbg_path(fehbg_home_path); 68 Imlib_Image buffer = imlib_load_image(background_image); 69 imlib_context_set_image(buffer); 70 int background_image_width = imlib_image_get_width(); 71 @@ -395,7 +430,27 @@ main(int argc, char **argv) { 72 73 int i; 74 for (i = 0; i < number_of_monitors; i++) { 75 - 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); 76 + int m_x = monitors[i].x; 77 + int m_y = monitors[i].y; 78 + int m_w = monitors[i].width; 79 + int m_h = monitors[i].height; 80 + 81 + int s_x = 0; 82 + int s_y = 0; 83 + int s_w = background_image_width; 84 + int s_h = background_image_height; 85 + 86 + /* This implements a stretching behaviour for the given image, 87 + * it should not be hard to modify and achieve different effects */ 88 + if ((double)m_w / m_h > (double)s_w / s_h) { 89 + s_h = (s_w * m_h) / m_w; 90 + s_y = (background_image_height - s_h) / 2; 91 + } else { 92 + s_w = (s_h * m_w) / m_h; 93 + s_x = (background_image_width - s_w) / 2; 94 + } 95 + 96 + imlib_blend_image_onto_image(buffer, 0, s_x, s_y, s_w, s_h, m_x, m_y, m_w, m_h); 97 } 98 99 /* Clean up */