commit 73f02eea6e5f55e5ca85cdffbd6feced50f85e99
parent 79a049365d80157dfdaa572b5d737c79af50cd7d
Author: James Wescott <james@wescottdesign.com>
Date: Sat, 8 Jul 2017 12:01:22 -0700
Initial implementation of indicator positioning
Diffstat:
2 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/i3lock.c b/i3lock.c
@@ -91,6 +91,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";
@@ -937,6 +939,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},
@@ -1205,6 +1208,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);