This patch adds a new option to i3lock. If the user specifies the -s option (in conjunction with -i), the image will be scaled to match the screen's resolution. Note that the aspect ratio will not be preserved.
Patch status: rejected
Patch by Martin Ichilevici de Oliveira
To apply this patch, use:
curl http://cr.i3wm.org/patch/258/raw.patch | git am
b/i3lock.1
| 17 |
@@ -24,6 +24,7 @@ i3lock \- improved screen locker |
| 18 |
.RB [\|\-c |
| 19 |
.IR color \|] |
| 20 |
.RB [\|\-t\|] |
| 21 |
+.RB [\|\-s\|] |
| 22 |
.RB [\|\-p |
| 23 |
.IR pointer\|] |
| 24 |
.RB [\|\-u\|] |
| 25 |
@@ -90,6 +91,12 @@ If an image is specified (via \-i) it will display the image tiled all over the |
| 26 |
(if it is a multi-monitor setup, the image is visible on all screens). |
| 27 |
|
| 28 |
.TP |
| 29 |
+.B \-s, \-\-scale |
| 30 |
+If an image is specified (via \-i) it will scale the image to match the resolution of the |
| 31 |
+screen. Note that the aspect ratio will not be preserved. This option has no effect if |
| 32 |
+tiling (via \-t) was used. |
| 33 |
+ |
| 34 |
+.TP |
| 35 |
.BI \-p\ win|default \fR,\ \fB\-\-pointer= win|default |
| 36 |
If you specify "default", |
| 37 |
.B i3lock |
b/i3lock.c
| 42 |
@@ -60,6 +60,7 @@ static struct xkb_context *xkb_context; |
| 43 |
static struct xkb_keymap *xkb_keymap; |
| 44 |
|
| 45 |
cairo_surface_t *img = NULL; |
| 46 |
+bool scale = false; |
| 47 |
bool tile = false; |
| 48 |
bool ignore_empty_password = false; |
| 49 |
|
| 50 |
@@ -584,6 +585,7 @@ int main(int argc, char *argv[]) {
|
| 51 |
{"no-unlock-indicator", no_argument, NULL, 'u'},
|
| 52 |
{"image", required_argument, NULL, 'i'},
|
| 53 |
{"tiling", no_argument, NULL, 't'},
|
| 54 |
+ {"scale", no_argument, NULL, 's'},
|
| 55 |
{"ignore-empty-password", no_argument, NULL, 'e'},
|
| 56 |
{NULL, no_argument, NULL, 0}
|
| 57 |
}; |
| 58 |
@@ -591,7 +593,7 @@ int main(int argc, char *argv[]) {
|
| 59 |
if ((username = getenv("USER")) == NULL)
|
| 60 |
errx(1, "USER environment variable not set, please set it.\n"); |
| 61 |
|
| 62 |
- while ((o = getopt_long(argc, argv, "hvnbdc:p:ui:te", longopts, &optind)) != -1) {
|
| 63 |
+ while ((o = getopt_long(argc, argv, "hvnbdc:p:ui:tes", longopts, &optind)) != -1) {
|
| 64 |
switch (o) {
|
| 65 |
case 'v': |
| 66 |
errx(EXIT_SUCCESS, "version " VERSION " © 2010-2012 Michael Stapelberg"); |
| 67 |
@@ -622,6 +624,9 @@ int main(int argc, char *argv[]) {
|
| 68 |
case 'i': |
| 69 |
image_path = strdup(optarg); |
| 70 |
break; |
| 71 |
+ case 's': |
| 72 |
+ scale = true; |
| 73 |
+ break; |
| 74 |
case 't': |
| 75 |
tile = true; |
| 76 |
break; |
b/unlock_indicator.c
| 81 |
@@ -46,6 +46,8 @@ extern bool unlock_indicator; |
| 82 |
/* A Cairo surface containing the specified image (-i), if any. */ |
| 83 |
extern cairo_surface_t *img; |
| 84 |
|
| 85 |
+/* Whether the image should be scaled to fit the screen */ |
| 86 |
+extern bool scale; |
| 87 |
/* Whether the image should be tiled. */ |
| 88 |
extern bool tile; |
| 89 |
/* The background color to use (in hex). */ |
| 90 |
@@ -87,8 +89,19 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
|
| 91 |
|
| 92 |
if (img) {
|
| 93 |
if (!tile) {
|
| 94 |
+ int w, h; |
| 95 |
+ if (scale) {
|
| 96 |
+ w = cairo_image_surface_get_width(img); |
| 97 |
+ h = cairo_image_surface_get_height(img); |
| 98 |
+ cairo_scale(xcb_ctx, (float) resolution[0]/w, (float) resolution[1]/h); |
| 99 |
+ } |
| 100 |
cairo_set_source_surface(xcb_ctx, img, 0, 0); |
| 101 |
cairo_paint(xcb_ctx); |
| 102 |
+ if (scale) {
|
| 103 |
+ /* Now that the context has been painted, we need to rescale it back to it's original |
| 104 |
+ * size, since other features depend on this */ |
| 105 |
+ cairo_scale(xcb_ctx, (float) w/resolution[0], (float) h/resolution[1]); |
| 106 |
+ } |
| 107 |
} else {
|
| 108 |
/* create a pattern and fill a rectangle as big as the screen */ |
| 109 |
cairo_pattern_t *pattern; |