Browse Source

fix pointer bugs, fix arithmetic bugs, expose more variables for time/date pos

master
Chris Guillott 8 years ago
parent
commit
3637d7ba28
  1. 4
      i3lock.c
  2. 150
      unlock_indicator.c

4
i3lock.c

@ -1197,7 +1197,7 @@ int main(int argc, char *argv[]) {
errx(1, "date position string can be at most 31 characters\n"); errx(1, "date position string can be at most 31 characters\n");
} }
char* arg = optarg; char* arg = optarg;
if (sscanf(arg, "%30[^:]:%30[^:]", &time_x_expr, &time_y_expr) != 2) { if (sscanf(arg, "%30[^:]:%30[^:]", time_x_expr, time_y_expr) != 2) {
errx(1, "timepos must be of the form x:y\n"); errx(1, "timepos must be of the form x:y\n");
} }
} }
@ -1208,7 +1208,7 @@ int main(int argc, char *argv[]) {
errx(1, "date position string can be at most 31 characters\n"); errx(1, "date position string can be at most 31 characters\n");
} }
char* arg = optarg; char* arg = optarg;
if (sscanf(arg, "%30[^:]:%30[^:]", &date_x_expr, &date_y_expr) != 2) { if (sscanf(arg, "%30[^:]:%30[^:]", date_x_expr, date_y_expr) != 2) {
errx(1, "datepos must be of the form x:y\n"); errx(1, "datepos must be of the form x:y\n");
} }
} }

150
unlock_indicator.c

@ -495,9 +495,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
strftime(time_text, 40, time_format, timeinfo); strftime(time_text, 40, time_format, timeinfo);
strftime(date_text, 40, date_format, timeinfo); strftime(date_text, 40, date_format, timeinfo);
if (text == NULL) { text = time_text;
text = time_text;
}
date = date_text; date = date_text;
if (text) { if (text) {
@ -537,81 +535,101 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
double ix, iy; double ix, iy;
double x, y; double x, y;
double screen_x, screen_y;
double w, h; double w, h;
double tx = 0; double tx = 0;
double ty = 0; double ty = 0;
double clock_width = CLOCK_WIDTH;
double clock_height = CLOCK_HEIGHT;
int te_x_err; int te_x_err;
int te_y_err; int te_y_err;
// variable mapping for evaluating the clock position expression // variable mapping for evaluating the clock position expression
te_variable vars[] = {{"ix", &ix}, {"iy", &iy}, {"w", &w}, {"h", &h}, {"tx", &tx}, {"ty", &ty}}; te_variable vars[] = {
{"w", &w}, {"h", &h},
te_expr *te_time_x_expr = te_compile(time_x_expr, vars, 6, &te_x_err); {"x", &screen_x}, {"y", &screen_y},
te_expr *te_time_y_expr = te_compile(time_y_expr, vars, 6, &te_y_err); {"ix", &ix}, {"iy", &iy},
te_expr *te_date_x_expr = te_compile(date_x_expr, vars, 6, &te_x_err); {"tx", &tx}, {"ty", &ty},
te_expr *te_date_y_expr = te_compile(date_y_expr, vars, 6, &te_y_err); {"cw", &clock_width}, {"ch", &clock_height} // pretty sure this is fine.
};
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);
if (xr_screens > 0) { if (xr_screens > 0) {
/* Composite the unlock indicator in the middle of each screen. */ /* Composite the unlock indicator in the middle of each screen. */
// excuse me, just gonna hack something in right here // excuse me, just gonna hack something in right here
if (screen_number != -1 && screen_number < xr_screens) { if (screen_number != -1 && screen_number < xr_screens) {
w = xr_resolutions[screen_number].width; w = xr_resolutions[screen_number].width;
h = xr_resolutions[screen_number].height; h = xr_resolutions[screen_number].height;
ix = xr_resolutions[screen_number].x + (xr_resolutions[screen_number].width / 2); screen_x = xr_resolutions[screen_number].x;
iy = xr_resolutions[screen_number].y + (xr_resolutions[screen_number].height / 2); screen_y = xr_resolutions[screen_number].y;
x = ix - (button_diameter_physical / 2); ix = xr_resolutions[screen_number].x + (xr_resolutions[screen_number].width / 2);
y = iy - (button_diameter_physical / 2); iy = xr_resolutions[screen_number].y + (xr_resolutions[screen_number].height / 2);
cairo_set_source_surface(xcb_ctx, output, x, y); x = ix - (button_diameter_physical / 2);
cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical); y = iy - (button_diameter_physical / 2);
cairo_fill(xcb_ctx); cairo_set_source_surface(xcb_ctx, output, x, y);
cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical);
if (te_time_x_expr && te_time_y_expr) { cairo_fill(xcb_ctx);
tx = te_eval(te_time_x_expr);
ty = te_eval(te_time_y_expr); if (te_time_x_expr && te_time_y_expr) {
double time_x = xr_resolutions[screen_number].x + tx - CLOCK_WIDTH / 2; tx = 0;
double time_y = xr_resolutions[screen_number].y + ty - CLOCK_HEIGHT / 2; ty = 0;
double date_x = xr_resolutions[screen_number].x + te_eval(te_date_x_expr) - CLOCK_WIDTH / 2; tx = te_eval(te_time_x_expr);
double date_y = xr_resolutions[screen_number].y + te_eval(te_date_y_expr) - CLOCK_HEIGHT / 2; ty = te_eval(te_time_y_expr);
cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y); double time_x = tx - CLOCK_WIDTH / 2;
cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT); double time_y = ty - CLOCK_HEIGHT / 2;
cairo_fill(xcb_ctx); double date_x = te_eval(te_date_x_expr) - CLOCK_WIDTH / 2;
cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y); double date_y = te_eval(te_date_y_expr) - CLOCK_HEIGHT / 2;
cairo_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT); DEBUG("tx: %f ty: %f ix: %f, iy: %f\n", tx, ty, ix, iy);
cairo_fill(xcb_ctx); DEBUG("\ttime_x: %f time_y: %f date_x: %f date_y: %f screen_number: %d\n", time_x, time_y, date_x, date_y, screen_number);
} DEBUG("\tscreen x: %d screen y: %d screen w: %f screen h: %f\n", xr_resolutions[screen_number].x, xr_resolutions[screen_number].y, w, h);
} cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y);
else { cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT);
for (int screen = 0; screen < xr_screens; screen++) { cairo_fill(xcb_ctx);
w = xr_resolutions[screen].width; cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y);
h = xr_resolutions[screen].height; cairo_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT);
ix = xr_resolutions[screen].x + (xr_resolutions[screen].width / 2); cairo_fill(xcb_ctx);
iy = xr_resolutions[screen].y + (xr_resolutions[screen].height / 2); }
x = ix - (button_diameter_physical / 2); } else {
y = iy - (button_diameter_physical / 2); for (int screen = 0; screen < xr_screens; screen++) {
cairo_set_source_surface(xcb_ctx, output, x, y); w = xr_resolutions[screen].width;
cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical); h = xr_resolutions[screen].height;
cairo_fill(xcb_ctx); screen_x = xr_resolutions[screen].x;
if (te_time_x_expr && te_time_y_expr) { screen_y = xr_resolutions[screen].y;
tx = te_eval(te_time_x_expr); ix = xr_resolutions[screen].x + (xr_resolutions[screen].width / 2);
ty = te_eval(te_time_y_expr); iy = xr_resolutions[screen].y + (xr_resolutions[screen].height / 2);
double time_x = xr_resolutions[screen].x + tx - CLOCK_WIDTH / 2; x = ix - (button_diameter_physical / 2);
double time_y = xr_resolutions[screen].y + ty - CLOCK_HEIGHT / 2; y = iy - (button_diameter_physical / 2);
double date_x = xr_resolutions[screen].x + te_eval(te_date_x_expr) - CLOCK_WIDTH / 2; cairo_set_source_surface(xcb_ctx, output, x, y);
double date_y = xr_resolutions[screen].y + te_eval(te_date_y_expr) - CLOCK_HEIGHT / 2; cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical);
cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y); cairo_fill(xcb_ctx);
cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT); if (te_time_x_expr && te_time_y_expr) {
cairo_fill(xcb_ctx); tx = 0;
cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y); ty = 0;
cairo_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT); tx = te_eval(te_time_x_expr);
cairo_fill(xcb_ctx); ty = te_eval(te_time_y_expr);
} double time_x = tx - CLOCK_WIDTH / 2;
else { double time_y = ty - CLOCK_HEIGHT / 2;
DEBUG("error codes for exprs are %d, %d\n", te_x_err, te_y_err); double date_x = te_eval(te_date_x_expr) - CLOCK_WIDTH / 2;
DEBUG("exprs: %s, %s\n", time_x_expr, time_y_expr); double date_y = te_eval(te_date_y_expr) - CLOCK_HEIGHT / 2;
} DEBUG("tx: %f ty: %f f ix: %f iy: %f\n", tx, ty, ix, iy);
} DEBUG("\ttime_x: %f time_y: %f date_x: %f date_y: %f screen_number: %d\n", time_x, time_y, date_x, date_y, screen);
DEBUG("\tscreen x: %d screen y: %d screen w: %f screen h: %f\n", xr_resolutions[screen].x, xr_resolutions[screen].y, w, h);
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);
} else {
DEBUG("error codes for exprs are %d, %d\n", te_x_err, te_y_err);
DEBUG("exprs: %s, %s\n", time_x_expr, time_y_expr);
}
}
} }
} else { } else {
/* We have no information about the screen sizes/positions, so we just /* We have no information about the screen sizes/positions, so we just

Loading…
Cancel
Save