i3lock-color

The world's most popular non-default computer lockscreen.
Index Commits Files Refs README LICENSE
commit baedc431fa642dce312185a3c69c268deafef387
parent c758871bc138fbc54310f840009478f38c374f37
Author: Chris Guillott <chris@techfo.xyz>
Date:   Wed,  2 Aug 2017 18:48:00 -0400

Merge pull request #33 from rantingpirate/indicator-pos

Implements positioning of the unlock indicator
Diffstat:
MREADME.md | 5+++--
Mi3lock.1 | 31+++++++++++++++++++++----------
Mi3lock.c | 14++++++++++++++
Munlock_indicator.c | 44+++++++++++++++++++++++++++++++++++---------
4 files changed, 73 insertions(+), 21 deletions(-)
diff --git a/README.md b/README.md
@@ -41,13 +41,14 @@ Many little improvements have been made to i3lock over time:
      - `-B=sigma, --blur` -- enables Gaussian blur. Sigma is the blur radius.
           - Note: You can still composite images over the blur (but still under the indicator) with -i.
                 - Eventually there might be an `imagepos` arg, similar to `time` and `datepos`. 
+     - `--indpos="x+(w/2):y+(h/2)"` -- position of the unlock indicator. Expressions using the variables x (current screen's x value), y (current screen's y value), w (screen width), h (screen height), and r (indicator radius) can be used.
      - `--timestr="%H:%M:%S"` -- allows custom overriding of the time format string. Accepts `strftime` formatting. Default is `"%H:%M:%S"`.
-     - `--timepos="ix:iy-20"` -- position of the time. Expressions using the variables x (current screen's x value), y (current screen's y value), w (screen width), h (screen height), ix (indicator x position), iy (indicator y position) cw (clock width), and ch (clock height) can be used..
+     - `--timepos="ix:iy-20"` -- position of the time. All the variables in `indpos` can be used here, as well as the additional values ix (indicator x position), iy (indicator y position), cw (clock width), and ch (clock height).
      - `--timecolor=rrggbbaa` -- color of the time string
      - `--timefont="sans-serif"` -- font used for the time display
      - `--timesize=32` -- font size for the time display
      - `--datestr="%A, %m %Y"` -- allows custom overriding of the date format string. Accepts `strftime` formatting. Default is `"%A, %m %Y"`.
-     - `--datepos="ix:iy-20"` -- position of the date. All the variables in `timepos` can be used here, as well as the additional values tx (time x) and ty (time y).
+     - `--datepos="ix:iy-20"` -- position of the date. All the variables in `indpos` and `timepos` can be used here, as well as the additional values tx (time x) and ty (time y).
      - `--datecolor=rrggbbaa` -- color of the date string
      - `--datefont="sans-serif"` -- font used for the date display
      - `--datesize=14` -- font size for the date display
diff --git a/i3lock.1 b/i3lock.1
@@ -182,6 +182,25 @@ Sets the color of the 'separtor', which is at both ends of the ring highlights.
 Sets the color of the status text ("verifying...", "wrong!", etc).
 
 .TP
+.B \-\-indpos="x position:y position"
+Sets the position for the unlock indicator. Valid variables include:
+
+.RS
+.RS
+x - x position of the current display. Corresponds to the leftmost row of pixels on that display.
+
+y - y position of the current display. Corresponds to the topmost row of pixels on that display.
+
+w - width of the current display.
+
+h - height of the current display.
+
+r - the unlock indicator radius.
+
+.RE
+.RE
+
+.TP
 .B \-\-timecolor=rrggbbaa
 Sets the color of the time in the clock.
 
@@ -199,18 +218,10 @@ Sets the font size for rendering the time string. Defaults to 32.
 
 .TP
 .B \-\-timepos="x position:y position"
-Sets the position for the time string. Valid variables include:
+Sets the position for the time string. All the variables from \-\-indpos may be used, in addition to:
 
 .RS
 .RS
-x - x position of the current display. Corresponds to the leftmost row of pixels on that display.
-
-y - y position of the current display. Corresponds to the topmost row of pixels on that display.
-
-w - width of the current display.
-
-h - height of the current display.
-
 ix - the x value of the indicator on the current display.
 
 iy - the y value of the indicator on the current display.
@@ -239,7 +250,7 @@ Sets the font size for rendering the date string. Defaults to 14.
 
 .TP
 .B \-\-datepos="x position:y position"
-Sets the position for the date string. All the variables from \-\-timepos may be used, in addition to:
+Sets the position for the date string. All the variables from \-\-indpos and \-\-timepos may be used, in addition to:
 
 .RS
 .RS
diff --git a/i3lock.c b/i3lock.c
@@ -92,6 +92,8 @@ char time_format[32] = "%H:%M:%S\0";
 char date_format[32] = "%A, %m %Y\0";
 char time_font[32] = "sans-serif\0";
 char date_font[32] = "sans-serif\0";
+char ind_x_expr[32] = "x + (w / 2)\0";
+char ind_y_expr[32] = "y + (h / 2)\0";
 char time_x_expr[32] = "ix - (cw / 2)\0";
 char time_y_expr[32] = "iy - (ch / 2)\0";
 char date_x_expr[32] = "tx\0";
@@ -938,6 +940,7 @@ int main(int argc, char *argv[]) {
         {"datesize", required_argument, NULL, 0},
         {"timepos", required_argument, NULL, 0},
         {"datepos", required_argument, NULL, 0},
+        {"indpos", required_argument, NULL, 0},
 
         {"veriftext", required_argument, NULL, 0},
         {"wrongtext", required_argument, NULL, 0},
@@ -1208,6 +1211,17 @@ int main(int argc, char *argv[]) {
                     if (date_size < 1)
                         errx(1, "datesize must be larger than 0\n");
                 }
+                else if (strcmp(longopts[optind].name, "indpos") == 0) {
+                    //read in to ind_x_expr and ind_y_expr
+                    if (strlen(optarg) > 31) {
+                        // this is overly restrictive since both the x and y string buffers have size 32, but it's easier to check.
+                        errx(1, "indicator position string can be at most 31 characters\n");
+                    }
+                    char* arg = optarg;
+                    if (sscanf(arg, "%30[^:]:%30[^:]", ind_x_expr, ind_y_expr) != 2) {
+                        errx(1, "indpos must be of the form x:y\n");
+                    }
+                }
                 else if (strcmp(longopts[optind].name, "timepos") == 0) {
                     //read in to time_x_expr and time_y_expr
                     if (strlen(optarg) > 31) {
diff --git a/unlock_indicator.c b/unlock_indicator.c
@@ -89,6 +89,8 @@ extern char time_format[32];
 extern char date_format[32];
 extern char time_font[32];
 extern char date_font[32];
+extern char ind_x_expr[32];
+extern char ind_y_expr[32];
 extern char time_x_expr[32];
 extern char time_y_expr[32];
 extern char date_x_expr[32];
@@ -558,6 +560,8 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
     double clock_width = CLOCK_WIDTH;
     double clock_height = CLOCK_HEIGHT;
 
+    double radius = BUTTON_RADIUS;
+
     int te_x_err;
     int te_y_err;
     // variable mapping for evaluating the clock position expression
@@ -566,13 +570,16 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
         {"x", &screen_x}, {"y", &screen_y},
         {"ix", &ix}, {"iy", &iy},
         {"tx", &tx}, {"ty", &ty},
-        {"cw", &clock_width}, {"ch", &clock_height} // pretty sure this is fine.
+        {"cw", &clock_width}, {"ch", &clock_height}, // pretty sure this is fine.
+        {"r", &radius}
     };
 
-    te_expr *te_time_x_expr = te_compile(time_x_expr, vars, 10, &te_x_err);
-    te_expr *te_time_y_expr = te_compile(time_y_expr, vars, 10, &te_y_err);
-    te_expr *te_date_x_expr = te_compile(date_x_expr, vars, 10, &te_x_err);
-    te_expr *te_date_y_expr = te_compile(date_y_expr, vars, 10, &te_y_err);
+    te_expr *te_ind_x_expr = te_compile(ind_x_expr, vars, 11, &te_x_err);
+    te_expr *te_ind_y_expr = te_compile(ind_y_expr, vars, 11, &te_y_err);
+    te_expr *te_time_x_expr = te_compile(time_x_expr, vars, 11, &te_x_err);
+    te_expr *te_time_y_expr = te_compile(time_y_expr, vars, 11, &te_y_err);
+    te_expr *te_date_x_expr = te_compile(date_x_expr, vars, 11, &te_x_err);
+    te_expr *te_date_y_expr = te_compile(date_y_expr, vars, 11, &te_y_err);
 
     if (xr_screens > 0) {
         /* Composite the unlock indicator in the middle of each screen. */
@@ -582,8 +589,18 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
             h = xr_resolutions[screen_number].height;
             screen_x = xr_resolutions[screen_number].x;
             screen_y = xr_resolutions[screen_number].y;
-            ix = xr_resolutions[screen_number].x + (xr_resolutions[screen_number].width / 2);
-            iy = xr_resolutions[screen_number].y + (xr_resolutions[screen_number].height / 2);
+            if (te_ind_x_expr && te_ind_y_expr) {
+                ix = 0;
+                iy = 0;
+                ix = te_eval(te_ind_x_expr);
+                iy = te_eval(te_ind_y_expr);
+                DEBUG("\tscreen x: %d screen y: %d screen w: %f screen h: %f ix: %f iy: %f\n", xr_resolutions[screen_number].x, xr_resolutions[screen_number].y, w, h, ix, iy);
+            }
+            else {
+                ix = xr_resolutions[screen_number].x + (xr_resolutions[screen_number].width / 2);
+                iy = xr_resolutions[screen_number].y + (xr_resolutions[screen_number].height / 2);
+            }
+
             x = ix - (button_diameter_physical / 2);
             y = iy - (button_diameter_physical / 2);
             cairo_set_source_surface(xcb_ctx, output, x, y);
@@ -615,8 +632,17 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
                 h = xr_resolutions[screen].height;
                 screen_x = xr_resolutions[screen].x;
                 screen_y = xr_resolutions[screen].y;
-                ix = xr_resolutions[screen].x + (xr_resolutions[screen].width / 2);
-                iy = xr_resolutions[screen].y + (xr_resolutions[screen].height / 2);
+                if (te_ind_x_expr && te_ind_y_expr) {
+                    ix = 0;
+                    iy = 0;
+                    ix = te_eval(te_ind_x_expr);
+                    iy = te_eval(te_ind_y_expr);
+                    DEBUG("\tscreen x: %d screen y: %d screen w: %f screen h: %f ix: %f iy: %f\n", xr_resolutions[screen].x, xr_resolutions[screen].y, w, h, ix, iy);
+                }
+                else {
+                    ix = xr_resolutions[screen].x + (xr_resolutions[screen].width / 2);
+                    iy = xr_resolutions[screen].y + (xr_resolutions[screen].height / 2);
+                }
                 x = ix - (button_diameter_physical / 2);
                 y = iy - (button_diameter_physical / 2);
                 cairo_set_source_surface(xcb_ctx, output, x, y);