i3lock-color

The world's most popular non-default computer lockscreen.
Index Commits Files Refs README LICENSE
commit 8f7ae46752ff3d701860f685e9241fcb376a3cd3
parent 59cdccb3e510c5d393cab9656b8a30efd37b45e6
Author: Pandora <pandora@techfo.xyz>
Date:   Fri,  8 Dec 2017 10:24:29 -0500

tweak bar default behaviour; add options, fix clock stuff for bar

Diffstat:
Mi3lock.c | 35+++++++++++++++++++++++++----------
Munlock_indicator.c | 93++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
2 files changed, 91 insertions(+), 37 deletions(-)
diff --git a/i3lock.c b/i3lock.c
@@ -188,20 +188,24 @@ bool redraw_thread = false;
 
 #define BAR_VERT 0
 #define BAR_FLAT 1
+#define BAR_DEFAULT 0
+#define BAR_REVERSED 1
+#define BAR_BIDIRECTIONAL 2
 // experimental bar stuff
 bool bar_enabled = false;
 double *bar_heights = NULL;
 double bar_step = 15;
-double bar_base_height = 15;
-double bar_periodic_step = 1;
-double max_bar_height = 50;
+double bar_base_height = 25;
+double bar_periodic_step = 15;
+double max_bar_height = 25;
 int num_bars = 0;
-int bar_width = 15;
+int bar_width = 150;
 int bar_orientation = BAR_FLAT;
 
 char bar_base_color[9] = "000000ff";
 char bar_expr[32] = "0\0";
 bool bar_bidirectional = false;
+bool bar_reversed = false;
 
 /* isutf, u8_dec © 2005 Jeff Bezanson, public domain */
 #define isutf(c) (((c)&0xC0) != 0x80)
@@ -1090,7 +1094,7 @@ int main(int argc, char *argv[]) {
         {"ring-width", required_argument, NULL, 0},
         
         {"bar-indicator", no_argument, NULL, 0},
-        {"bar-bidirectional", no_argument, NULL, 0},
+        {"bar-direction", required_argument, NULL, 0},
         {"bar-width", required_argument, NULL, 0},
         {"bar-orientation", required_argument, NULL, 0},
         {"bar-step", required_argument, NULL, 0},
@@ -1529,12 +1533,23 @@ int main(int argc, char *argv[]) {
                 else if (strcmp(longopts[longoptind].name, "bar-indicator") == 0) {
                     bar_enabled = true;                    
                 }
-                else if (strcmp(longopts[longoptind].name, "bar-bidirectional") == 0) {
-                    bar_bidirectional = true;                    
+                else if (strcmp(longopts[longoptind].name, "bar-direction") == 0) {
+                    int opt = atoi(optarg);
+                    switch(opt) {
+                        case BAR_REVERSED:
+                            bar_reversed = true;
+                            break;
+                        case BAR_BIDIRECTIONAL:
+                            bar_bidirectional = true;
+                            break;
+                        case BAR_DEFAULT:
+                        default:
+                            break;
+                    }
                 }
                 else if (strcmp(longopts[longoptind].name, "bar-width") == 0) {
                     bar_width = atoi(optarg);
-                    if (bar_width < 1) bar_width = 15;
+                    if (bar_width < 1) bar_width = 150;
                     // num_bars and bar_heights* initialized later when we grab display info
                 }
                 else if (strcmp(longopts[longoptind].name, "bar-orientation") == 0) {
@@ -1552,11 +1567,11 @@ int main(int argc, char *argv[]) {
                 }
                 else if (strcmp(longopts[longoptind].name, "bar-max-height") == 0) {
                     max_bar_height = atoi(optarg);
-                    if (max_bar_height < 1) max_bar_height = 50;
+                    if (max_bar_height < 1) max_bar_height = 25;
                 }
                 else if (strcmp(longopts[longoptind].name, "bar-base-width") == 0) {
                     bar_base_height = atoi(optarg);
-                    if (bar_base_height < 1) bar_base_height = 15;
+                    if (bar_base_height < 1) bar_base_height = 25;
                 }
                 else if (strcmp(longopts[longoptind].name, "bar-color") == 0) {
                     char *arg = optarg;
diff --git a/unlock_indicator.c b/unlock_indicator.c
@@ -182,6 +182,7 @@ extern int bar_orientation;
 extern char bar_base_color[9];
 extern char bar_expr[32];
 extern bool bar_bidirectional;
+extern bool bar_reversed;
 
 /*
  * Initialize all the color arrays once.
@@ -702,29 +703,27 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
             cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical);
             cairo_fill(xcb_ctx);
 
-            if (te_time_x_expr && te_time_y_expr) {
-                tx = 0;
-                ty = 0;
-                tx = te_eval(te_time_x_expr);
-                ty = te_eval(te_time_y_expr);
-                double time_x = tx;
-                double time_y = ty;
-                dx = te_eval(te_date_x_expr);
-                dy = te_eval(te_date_y_expr);
-                double date_x = dx;
-                double date_y = dy;
-                double layout_x = te_eval(te_layout_x_expr);
-                double layout_y = te_eval(te_layout_y_expr);
-                cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y);
-                cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT);
-                cairo_fill(xcb_ctx);
-                cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y);
-                cairo_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT);
-                cairo_fill(xcb_ctx);
-                cairo_set_source_surface(xcb_ctx, layout_output, layout_x, layout_y);
-                cairo_rectangle(xcb_ctx, layout_x, layout_y, CLOCK_WIDTH, CLOCK_HEIGHT);
-                cairo_fill(xcb_ctx);
-            }
+            tx = 0;
+            ty = 0;
+            tx = te_eval(te_time_x_expr);
+            ty = te_eval(te_time_y_expr);
+            double time_x = tx;
+            double time_y = ty;
+            dx = te_eval(te_date_x_expr);
+            dy = te_eval(te_date_y_expr);
+            double date_x = dx;
+            double date_y = dy;
+            double layout_x = te_eval(te_layout_x_expr);
+            double layout_y = te_eval(te_layout_y_expr);
+            cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y);
+            cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT);
+            cairo_fill(xcb_ctx);
+            cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y);
+            cairo_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT);
+            cairo_fill(xcb_ctx);
+            cairo_set_source_surface(xcb_ctx, layout_output, layout_x, layout_y);
+            cairo_rectangle(xcb_ctx, layout_x, layout_y, CLOCK_WIDTH, CLOCK_HEIGHT);
+            cairo_fill(xcb_ctx);
         } else {
             for (int screen = 0; screen < xr_screens; screen++) {
                 w = xr_resolutions[screen].width;
@@ -812,6 +811,13 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
         // oh boy, here we go!
         // TODO: get this to play nicely with multiple monitors
         // ideally it'd intelligently span both monitors
+        if (screen_number != -1 && screen_number < xr_screens) {
+            w = xr_resolutions[screen_number].width;
+            h = xr_resolutions[screen_number].height;
+        } else {
+            w = xr_resolutions[0].width;
+            h = xr_resolutions[0].height;
+        }
         double bar_offset = te_eval(te_bar_expr);
         double x, y, width, height;
         double back_x = 0, back_y = 0, back_x2 = 0, back_y2 = 0, back_width = 0, back_height = 0;
@@ -846,7 +852,10 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
                 height = bar_width;
                 x = bar_offset;
                 y = i * bar_width;
-                if (bar_bidirectional) {
+                if (bar_reversed) {
+                    x -= width;
+                }
+                else if (bar_bidirectional) {
                     width = (cur_bar_height <= 0 ? bar_base_height : cur_bar_height) * 2;
                     x = bar_offset - (width / 2) + (bar_base_height / 2);
                 }
@@ -855,7 +864,10 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
                 height = (cur_bar_height <= 0 ? bar_base_height : cur_bar_height);
                 x = i * bar_width;
                 y = bar_offset;
-                if (bar_bidirectional) {
+                if (bar_reversed) {
+                    y -= height;
+                }
+                else if (bar_bidirectional) {
                     height = (cur_bar_height <= 0 ? bar_base_height : cur_bar_height) * 2;
                     y = bar_offset - (height / 2) + (bar_base_height / 2);
                 }
@@ -867,7 +879,10 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
                     back_y = y;
                     back_width = bar_base_height - cur_bar_height;
                     back_height = height;
-                    if (bar_bidirectional) {
+                    if (bar_reversed) {
+                       back_x = bar_offset - bar_base_height; 
+                    }
+                    else if (bar_bidirectional) {
                         back_x = bar_offset;
                         back_y2 = y;
                         back_width = (bar_base_height - (cur_bar_height * 2)) / 2;
@@ -878,7 +893,10 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
                     back_y = bar_offset + cur_bar_height;
                     back_width = width;
                     back_height = bar_base_height - cur_bar_height;
-                    if (bar_bidirectional) {
+                    if (bar_reversed) {
+                        back_y = bar_offset - bar_base_height;
+                    }
+                    else if (bar_bidirectional) {
                         back_x2 = x;
                         back_y = bar_offset;
                         back_height = (bar_base_height - (cur_bar_height * 2)) / 2;
@@ -917,6 +935,27 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
             if (bar_heights[i] > 0)
                 bar_heights[i] -= bar_periodic_step;
         }
+        tx = 0;
+        ty = 0;
+        tx = te_eval(te_time_x_expr);
+        ty = te_eval(te_time_y_expr);
+        double time_x = tx;
+        double time_y = ty;
+        dx = te_eval(te_date_x_expr);
+        dy = te_eval(te_date_y_expr);
+        double date_x = dx;
+        double date_y = dy;
+        double layout_x = te_eval(te_layout_x_expr);
+        double layout_y = te_eval(te_layout_y_expr);
+        cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y);
+        cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT);
+        cairo_fill(xcb_ctx);
+        cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y);
+        cairo_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT);
+        cairo_fill(xcb_ctx);
+        cairo_set_source_surface(xcb_ctx, layout_output, layout_x, layout_y);
+        cairo_rectangle(xcb_ctx, layout_x, layout_y, CLOCK_WIDTH, CLOCK_HEIGHT);
+        cairo_fill(xcb_ctx);
     }
     
     te_free(te_ind_x_expr);