i3lock-color

The world's most popular non-default computer lockscreen.
Index Commits Files Refs README LICENSE
commit 9fc20b87b5967a83e3df93a41e0102868ef39bdb
parent 208d9714abd3c4dc300885bd84ad5cce1fcfd309
Author: Raymond Li <hi@raymond.li>
Date:   Wed,  2 Jun 2021 22:20:47 -0400

Merge pull request #221 from Rio6/better-tiling

Improve background tiling on multimonitor setup
Diffstat:
Mi3lock.c | 31++++++++-----------------------
Munlock_indicator.c | 26+++++++++++++++++++-------
2 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/i3lock.c b/i3lock.c
@@ -244,6 +244,7 @@ static int randr_base = -1;
 
 cairo_surface_t *img = NULL;
 cairo_surface_t *img_slideshow[256];
+cairo_surface_t *blur_bg_img = NULL;
 int slideshow_image_count = 0;
 int slideshow_interval = 10;
 bool slideshow_random_selection = false;
@@ -2362,29 +2363,20 @@ int main(int argc, char *argv[]) {
 
     free(image_raw_format);
 
-    xcb_pixmap_t* blur_pixmap = NULL;
     if (blur) {
-        blur_pixmap = malloc(sizeof(xcb_pixmap_t));
-        xcb_visualtype_t *vistype = get_root_visual_type(screen);
-        *blur_pixmap = capture_bg_pixmap(conn, screen, last_resolution);
-        cairo_surface_t *xcb_img = cairo_xcb_surface_create(conn, *blur_pixmap, vistype, last_resolution[0], last_resolution[1]);
+        xcb_pixmap_t bg_pixmap = capture_bg_pixmap(conn, screen, last_resolution);
+        cairo_surface_t *xcb_img = cairo_xcb_surface_create(conn, bg_pixmap, get_root_visual_type(screen), last_resolution[0], last_resolution[1]);
+
+        blur_bg_img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, last_resolution[0], last_resolution[1]);
+        cairo_t *ctx = cairo_create(blur_bg_img);
 
-        cairo_surface_t *blur_img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, last_resolution[0], last_resolution[1]);
-        cairo_t *ctx = cairo_create(blur_img);
         cairo_set_source_surface(ctx, xcb_img, 0, 0);
         cairo_paint(ctx);
+        blur_image_surface(blur_bg_img, blur_sigma);
 
-        blur_image_surface(blur_img, blur_sigma);
-        if (img) {
-            // Display image on all outputs.
-            draw_image(last_resolution, img, ctx);
-            cairo_surface_destroy(img);
-        }
         cairo_destroy(ctx);
         cairo_surface_destroy(xcb_img);
-
-        img = blur_img;
-        bg_type = NONE;
+        xcb_free_pixmap(conn, bg_pixmap);
     }
 
     xcb_window_t stolen_focus = find_focused_window(conn, screen->root);
@@ -2395,14 +2387,7 @@ int main(int argc, char *argv[]) {
     xcb_pixmap_t pixmap = create_bg_pixmap(conn, win, last_resolution, color);
     render_lock(last_resolution, pixmap);
     xcb_change_window_attributes(conn, win, XCB_CW_BACK_PIXMAP, (uint32_t[]){pixmap});
-
     xcb_free_pixmap(conn, pixmap);
-    if (blur_pixmap) {
-        xcb_free_pixmap(conn, *blur_pixmap);
-        free(blur_pixmap);
-        blur_pixmap = NULL;
-    }
-
 
     cursor = create_cursor(conn, screen, win, curs_choice);
 
diff --git a/unlock_indicator.c b/unlock_indicator.c
@@ -63,6 +63,7 @@ extern char *modifier_string;
 /* A Cairo surface containing the specified image (-i), if any. */
 extern cairo_surface_t *img;
 extern cairo_surface_t *img_slideshow[256];
+extern cairo_surface_t *blur_bg_img;
 extern int slideshow_image_count;
 extern int slideshow_interval;
 extern bool slideshow_random_selection;
@@ -697,14 +698,19 @@ void render_lock(uint32_t *resolution, xcb_drawable_t drawable) {
         }
     }
 
-    if (img) {
-        draw_image(resolution, img, xcb_ctx);
+    if (blur_bg_img) {
+        cairo_set_source_surface(xcb_ctx, blur_bg_img, 0, 0);
+        cairo_paint(xcb_ctx);
     } else {
         cairo_set_source_rgba(xcb_ctx, background.red, background.green, background.blue, background.alpha);
         cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]);
         cairo_fill(xcb_ctx);
     }
 
+    if (img) {
+        draw_image(resolution, img, xcb_ctx);
+    }
+
     /*
      * gen text
      * calc vars
@@ -1144,13 +1150,19 @@ void draw_image(uint32_t* root_resolution, cairo_surface_t *img, cairo_t* xcb_ct
 
         case TILE:
             {
-                /* create a pattern and fill a rectangle as big as the screen */
-                cairo_pattern_t *pattern;
-                pattern = cairo_pattern_create_for_surface(img);
+                cairo_pattern_t *pattern = cairo_pattern_create_for_surface(img);
                 cairo_set_source(xcb_ctx, pattern);
                 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
-                cairo_rectangle(xcb_ctx, 0, 0, root_resolution[0], root_resolution[1]);
-                cairo_fill(xcb_ctx);
+
+                for (int i = 0; i < xr_screens; i++) {
+                    cairo_matrix_t matrix;
+                    cairo_matrix_init_translate(&matrix, -xr_resolutions[i].x, -xr_resolutions[i].y);
+                    cairo_pattern_set_matrix(pattern, &matrix);
+
+                    cairo_rectangle(xcb_ctx, xr_resolutions[i].x, xr_resolutions[i].y, xr_resolutions[i].width, xr_resolutions[i].height);
+                    cairo_fill(xcb_ctx);
+                }
+
                 cairo_pattern_destroy(pattern);
                 break;
             }