add --force-clock option; remove old debug output that _shouldn't_ be necessary now

This commit is contained in:
Chris Guillott 2017-11-19 15:49:20 -05:00
parent b5099e3cd3
commit 807ff5c2b1
3 changed files with 27 additions and 15 deletions

View File

@ -127,7 +127,7 @@ Forces the indicator to always be visible, instead of only showing on activity.
.TP
.B \-\-keylayout mode
Displays the keylayout. Modes are as follows:
Displays the keylayout. Positionable similar to date, time, and indicator. Modes are as follows:
.RS
.RS
@ -140,6 +140,10 @@ Displays the keylayout. Modes are as follows:
.RE
.RE
.TP
.B \-k, \-\-clock, \-\-force\-clock
Displays the clock. \-\-force\-clock also displays the clock when there's indicator text (useful for when the clock is not positioned with the indicator).
.TP
.B \-\-composite
Some compositors have problems with i3lock trying to render over them, so this argument is disabled by default. However, some will work properly with it, so it's been left enabled.

View File

@ -83,6 +83,7 @@ int screen_number = -1;
int internal_line_source = 0;
/* bool for showing the clock; why am I commenting this? */
bool show_clock = false;
bool always_show_clock = false;
bool show_indicator = false;
float refresh_rate = 1.0;
@ -1014,6 +1015,7 @@ int main(int argc, char *argv[]) {
{"screen", required_argument, NULL, 'S'},
{"blur", required_argument, NULL, 'B'},
{"clock", no_argument, NULL, 'k'},
{"force-clock", no_argument, NULL, 0},
{"indicator", no_argument, NULL, 0},
{"refresh-rate", required_argument, NULL, 0},
{"composite", no_argument, NULL, 0},
@ -1436,6 +1438,10 @@ int main(int argc, char *argv[]) {
ring_width = new_width;
}
}
else if (strcmp(longopts[longoptind].name, "force-clock") == 0) {
show_clock = true;
always_show_clock = true;
}
break;
case 'f':

View File

@ -87,6 +87,7 @@ extern int screen_number;
extern float refresh_rate;
extern bool show_clock;
extern bool always_show_clock;
extern bool show_indicator;
extern char time_format[32];
extern char date_format[32];
@ -494,7 +495,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
}
}
if (show_clock && !unlock_indic_text) {
if (show_clock && (!unlock_indic_text || always_show_clock)) {
char *text = NULL;
char *date = NULL;
char time_text[40] = {0};
@ -601,7 +602,6 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
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);
@ -628,9 +628,6 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
double layout_x = te_eval(te_layout_x_expr);
double layout_y = te_eval(te_layout_y_expr);
DEBUG("tx: %f ty: %f ix: %f, iy: %f\n", tx, ty, ix, iy);
DEBUG("\ttime_x: %f time_y: %f date_x: %f date_y: %f layout_x: %f layout_y: %f screen_number: %d\n", time_x, time_y, date_x, date_y, layout_x, layout_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);
cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT);
cairo_fill(xcb_ctx);
@ -652,7 +649,6 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
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);
@ -676,9 +672,6 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
double date_y = dy;
double layout_x = te_eval(te_layout_x_expr);
double layout_y = te_eval(te_layout_y_expr);
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 layout_x: %f layout_y: %f screen_number: %d\n", time_x, time_y, date_x, date_y, layout_x, layout_y, screen_number);
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);
@ -710,10 +703,14 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
if (te_time_x_expr && te_time_y_expr) {
tx = te_eval(te_time_x_expr);
ty = te_eval(te_time_y_expr);
double time_x = tx - CLOCK_WIDTH / 2;
double time_y = tx - CLOCK_HEIGHT / 2;
double date_x = te_eval(te_date_x_expr) - CLOCK_WIDTH / 2;
double date_y = te_eval(te_date_y_expr) - CLOCK_HEIGHT / 2;
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);
DEBUG("Placing time at %f, %f\n", time_x, time_y);
cairo_set_source_surface(xcb_ctx, time_output, time_x, time_y);
cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT);
@ -721,16 +718,21 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
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);
}
}
cairo_surface_destroy(xcb_output);
cairo_surface_destroy(time_output);
cairo_surface_destroy(date_output);
cairo_surface_destroy(layout_output);
cairo_surface_destroy(output);
cairo_destroy(ctx);
cairo_destroy(time_ctx);
cairo_destroy(date_ctx);
cairo_destroy(layout_ctx);
cairo_destroy(xcb_ctx);
return bg_pixmap;
}
@ -740,7 +742,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
*
*/
void redraw_screen(void) {
DEBUG("redraw_screen(unlock_state = %d, auth_state = %d)\n", unlock_state, auth_state);
DEBUG("redraw_screen(unlock_state = %d, auth_state = %d) @ [%lu]\n", unlock_state, auth_state, (unsigned long)time(NULL));
xcb_pixmap_t bg_pixmap = draw_image(last_resolution);
xcb_change_window_attributes(conn, win, XCB_CW_BACK_PIXMAP, (uint32_t[1]){bg_pixmap});
/* XXX: Possible optimization: Only update the area in the middle of the