Add option to center image
Patch status: rejected
Patch by Romuald Brunet
Long description:
Added an optional -x|--center to center the i3lock image on each screen, instead of being drawn on the upper left corner.
To apply this patch, use:
curl http://cr.i3wm.org/patch/658/raw.patch | git am
b/i3lock.1
| 17 |
@@ -99,6 +99,10 @@ If an image is specified (via \-i) it will display the image tiled all over the |
| 18 |
(if it is a multi-monitor setup, the image is visible on all screens). |
| 19 |
|
| 20 |
.TP |
| 21 |
+.B \-x, \-\-center |
| 22 |
+If an image is specified (via \-i) it will display the image centered inside each screen |
| 23 |
+ |
| 24 |
+.TP |
| 25 |
.BI \-p\ win|default \fR,\ \fB\-\-pointer= win|default |
| 26 |
If you specify "default", |
| 27 |
.B i3lock |
b/i3lock.c
| 32 |
@@ -75,6 +75,7 @@ static uint8_t xkb_base_error; |
| 33 |
|
| 34 |
cairo_surface_t *img = NULL; |
| 35 |
bool tile = false; |
| 36 |
+bool center = false; |
| 37 |
bool ignore_empty_password = false; |
| 38 |
bool skip_repeated_empty_password = false; |
| 39 |
|
| 40 |
@@ -677,6 +678,7 @@ int main(int argc, char *argv[]) {
|
| 41 |
{"help", no_argument, NULL, 'h'},
|
| 42 |
{"no-unlock-indicator", no_argument, NULL, 'u'},
|
| 43 |
{"image", required_argument, NULL, 'i'},
|
| 44 |
+ {"center-image", no_argument, NULL, 'x'},
|
| 45 |
{"tiling", no_argument, NULL, 't'},
|
| 46 |
{"ignore-empty-password", no_argument, NULL, 'e'},
|
| 47 |
{"inactivity-timeout", required_argument, NULL, 'I'},
|
| 48 |
@@ -687,7 +689,7 @@ int main(int argc, char *argv[]) {
|
| 49 |
if ((username = getenv("USER")) == NULL)
|
| 50 |
errx(EXIT_FAILURE, "USER environment variable not set, please set it.\n"); |
| 51 |
|
| 52 |
- char *optstring = "hvnbdc:p:ui:teI:f"; |
| 53 |
+ char *optstring = "hvnbdc:p:ui:teI:fx"; |
| 54 |
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
|
| 55 |
switch (o) {
|
| 56 |
case 'v': |
| 57 |
@@ -726,6 +728,9 @@ int main(int argc, char *argv[]) {
|
| 58 |
case 'i': |
| 59 |
image_path = strdup(optarg); |
| 60 |
break; |
| 61 |
+ case 'x': |
| 62 |
+ center = true; |
| 63 |
+ break; |
| 64 |
case 't': |
| 65 |
tile = true; |
| 66 |
break; |
| 67 |
@@ -750,7 +755,7 @@ int main(int argc, char *argv[]) {
|
| 68 |
break; |
| 69 |
default: |
| 70 |
errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]" |
| 71 |
- " [-i image.png] [-t] [-e] [-I] [-f]" |
| 72 |
+ " [-i image.png] [-t] [-e] [-I] [-f] [-x]" |
| 73 |
); |
| 74 |
} |
| 75 |
} |
b/unlock_indicator.c
| 80 |
@@ -49,6 +49,9 @@ extern cairo_surface_t *img; |
| 81 |
|
| 82 |
/* Whether the image should be tiled. */ |
| 83 |
extern bool tile; |
| 84 |
+/* Whether the image should be centered. */ |
| 85 |
+extern bool center; |
| 86 |
+ |
| 87 |
/* The background color to use (in hex). */ |
| 88 |
extern char color[7]; |
| 89 |
|
| 90 |
@@ -112,8 +115,28 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
|
| 91 |
|
| 92 |
if (img) {
|
| 93 |
if (!tile) {
|
| 94 |
- cairo_set_source_surface(xcb_ctx, img, 0, 0); |
| 95 |
- cairo_paint(xcb_ctx); |
| 96 |
+ double x = 0; |
| 97 |
+ double y = 0; |
| 98 |
+ |
| 99 |
+ int width = cairo_image_surface_get_width(img); |
| 100 |
+ int height = cairo_image_surface_get_height(img); |
| 101 |
+ |
| 102 |
+ if (center && xr_screens > 0) {
|
| 103 |
+ for (int screen = 0; screen < xr_screens; screen++) {
|
| 104 |
+ x = xr_resolutions[screen].x + ((xr_resolutions[screen].width / 2) - (width / 2)); |
| 105 |
+ y = xr_resolutions[screen].y + ((xr_resolutions[screen].height / 2) - (height / 2)); |
| 106 |
+ |
| 107 |
+ cairo_set_source_surface(xcb_ctx, img, x, y); |
| 108 |
+ cairo_paint(xcb_ctx); |
| 109 |
+ } |
| 110 |
+ } else {
|
| 111 |
+ if (center) {
|
| 112 |
+ x = resolution[0] / 2 - width / 2; |
| 113 |
+ y = resolution[1] / 2 - height / 2; |
| 114 |
+ } |
| 115 |
+ cairo_set_source_surface(xcb_ctx, img, x, y); |
| 116 |
+ cairo_paint(xcb_ctx); |
| 117 |
+ } |
| 118 |
} else {
|
| 119 |
/* create a pattern and fill a rectangle as big as the screen */ |
| 120 |
cairo_pattern_t *pattern; |