Browse Source

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

master
Pandora 7 years ago
parent
commit
8f7ae46752
No known key found for this signature in database GPG Key ID: 55DB77C2A03E1EF5
  1. 35
      i3lock.c
  2. 93
      unlock_indicator.c

35
i3lock.c

@ -188,20 +188,24 @@ bool redraw_thread = false;
#define BAR_VERT 0 #define BAR_VERT 0
#define BAR_FLAT 1 #define BAR_FLAT 1
#define BAR_DEFAULT 0
#define BAR_REVERSED 1
#define BAR_BIDIRECTIONAL 2
// experimental bar stuff // experimental bar stuff
bool bar_enabled = false; bool bar_enabled = false;
double *bar_heights = NULL; double *bar_heights = NULL;
double bar_step = 15; double bar_step = 15;
double bar_base_height = 15; double bar_base_height = 25;
double bar_periodic_step = 1; double bar_periodic_step = 15;
double max_bar_height = 50; double max_bar_height = 25;
int num_bars = 0; int num_bars = 0;
int bar_width = 15; int bar_width = 150;
int bar_orientation = BAR_FLAT; int bar_orientation = BAR_FLAT;
char bar_base_color[9] = "000000ff"; char bar_base_color[9] = "000000ff";
char bar_expr[32] = "0\0"; char bar_expr[32] = "0\0";
bool bar_bidirectional = false; bool bar_bidirectional = false;
bool bar_reversed = false;
/* isutf, u8_dec © 2005 Jeff Bezanson, public domain */ /* isutf, u8_dec © 2005 Jeff Bezanson, public domain */
#define isutf(c) (((c)&0xC0) != 0x80) #define isutf(c) (((c)&0xC0) != 0x80)
@ -1090,7 +1094,7 @@ int main(int argc, char *argv[]) {
{"ring-width", required_argument, NULL, 0}, {"ring-width", required_argument, NULL, 0},
{"bar-indicator", no_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-width", required_argument, NULL, 0},
{"bar-orientation", required_argument, NULL, 0}, {"bar-orientation", required_argument, NULL, 0},
{"bar-step", 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) { else if (strcmp(longopts[longoptind].name, "bar-indicator") == 0) {
bar_enabled = true; bar_enabled = true;
} }
else if (strcmp(longopts[longoptind].name, "bar-bidirectional") == 0) { else if (strcmp(longopts[longoptind].name, "bar-direction") == 0) {
bar_bidirectional = true; 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) { else if (strcmp(longopts[longoptind].name, "bar-width") == 0) {
bar_width = atoi(optarg); 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 // num_bars and bar_heights* initialized later when we grab display info
} }
else if (strcmp(longopts[longoptind].name, "bar-orientation") == 0) { 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) { else if (strcmp(longopts[longoptind].name, "bar-max-height") == 0) {
max_bar_height = atoi(optarg); 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) { else if (strcmp(longopts[longoptind].name, "bar-base-width") == 0) {
bar_base_height = atoi(optarg); 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) { else if (strcmp(longopts[longoptind].name, "bar-color") == 0) {
char *arg = optarg; char *arg = optarg;

93
unlock_indicator.c

@ -182,6 +182,7 @@ extern int bar_orientation;
extern char bar_base_color[9]; extern char bar_base_color[9];
extern char bar_expr[32]; extern char bar_expr[32];
extern bool bar_bidirectional; extern bool bar_bidirectional;
extern bool bar_reversed;
/* /*
* Initialize all the color arrays once. * 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_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical);
cairo_fill(xcb_ctx); cairo_fill(xcb_ctx);
if (te_time_x_expr && te_time_y_expr) { tx = 0;
tx = 0; ty = 0;
ty = 0; tx = te_eval(te_time_x_expr);
tx = te_eval(te_time_x_expr); ty = te_eval(te_time_y_expr);
ty = te_eval(te_time_y_expr); double time_x = tx;
double time_x = tx; double time_y = ty;
double time_y = ty; dx = te_eval(te_date_x_expr);
dx = te_eval(te_date_x_expr); dy = te_eval(te_date_y_expr);
dy = te_eval(te_date_y_expr); double date_x = dx;
double date_x = dx; double date_y = dy;
double date_y = dy; double layout_x = te_eval(te_layout_x_expr);
double layout_x = te_eval(te_layout_x_expr); double layout_y = te_eval(te_layout_y_expr);
double layout_y = te_eval(te_layout_y_expr); cairo_set_source_surface(xcb_ctx, time_output, 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);
cairo_rectangle(xcb_ctx, time_x, time_y, CLOCK_WIDTH, CLOCK_HEIGHT); cairo_fill(xcb_ctx);
cairo_fill(xcb_ctx); cairo_set_source_surface(xcb_ctx, date_output, date_x, date_y);
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_rectangle(xcb_ctx, date_x, date_y, CLOCK_WIDTH, CLOCK_HEIGHT); cairo_fill(xcb_ctx);
cairo_fill(xcb_ctx); cairo_set_source_surface(xcb_ctx, layout_output, layout_x, layout_y);
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_rectangle(xcb_ctx, layout_x, layout_y, CLOCK_WIDTH, CLOCK_HEIGHT); cairo_fill(xcb_ctx);
cairo_fill(xcb_ctx);
}
} else { } else {
for (int screen = 0; screen < xr_screens; screen++) { for (int screen = 0; screen < xr_screens; screen++) {
w = xr_resolutions[screen].width; w = xr_resolutions[screen].width;
@ -812,6 +811,13 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
// oh boy, here we go! // oh boy, here we go!
// TODO: get this to play nicely with multiple monitors // TODO: get this to play nicely with multiple monitors
// ideally it'd intelligently span both 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 bar_offset = te_eval(te_bar_expr);
double x, y, width, height; double x, y, width, height;
double back_x = 0, back_y = 0, back_x2 = 0, back_y2 = 0, back_width = 0, back_height = 0; 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; height = bar_width;
x = bar_offset; x = bar_offset;
y = i * bar_width; 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; width = (cur_bar_height <= 0 ? bar_base_height : cur_bar_height) * 2;
x = bar_offset - (width / 2) + (bar_base_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); height = (cur_bar_height <= 0 ? bar_base_height : cur_bar_height);
x = i * bar_width; x = i * bar_width;
y = bar_offset; 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; height = (cur_bar_height <= 0 ? bar_base_height : cur_bar_height) * 2;
y = bar_offset - (height / 2) + (bar_base_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_y = y;
back_width = bar_base_height - cur_bar_height; back_width = bar_base_height - cur_bar_height;
back_height = 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_x = bar_offset;
back_y2 = y; back_y2 = y;
back_width = (bar_base_height - (cur_bar_height * 2)) / 2; 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_y = bar_offset + cur_bar_height;
back_width = width; back_width = width;
back_height = bar_base_height - cur_bar_height; 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_x2 = x;
back_y = bar_offset; back_y = bar_offset;
back_height = (bar_base_height - (cur_bar_height * 2)) / 2; 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) if (bar_heights[i] > 0)
bar_heights[i] -= bar_periodic_step; 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); te_free(te_ind_x_expr);

Loading…
Cancel
Save