commit 8de94d87c3b3340501adc24fb47424727e565115
parent a6e33348eaea7716507fc72d42116d1b9b208f6c
Author: Rio6 <rio.liu@r26.me>
Date: Tue, 26 Jan 2021 00:54:43 -0500
Error out when both bar-count and bar-width are specified.
and set default bar count to 10
Diffstat:
| M | i3lock.c | | | 32 | ++++++++++++++++++++------------ |
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/i3lock.c b/i3lock.c
@@ -277,7 +277,7 @@ double bar_step = 15;
double bar_base_height = 25;
double bar_periodic_step = 15;
double max_bar_height = 25;
-int bar_count = MIN_BAR_COUNT;
+int bar_count = 0;
int bar_width = 0;
int bar_orientation = BAR_FLAT;
@@ -2288,19 +2288,27 @@ int main(int argc, char *argv[]) {
last_resolution[1] = screen->height_in_pixels;
if (bar_enabled) {
- if (bar_width > 0) {
- fprintf(stderr, "Warning: --bar-width is deprecated, use --bar-count instead\n");
- int tmp = screen->width_in_pixels;
- if (bar_orientation == BAR_VERT) tmp = screen->height_in_pixels;
- bar_count = tmp / bar_width;
- if (tmp % bar_width != 0) {
- ++bar_count;
- }
- if (bar_count < MIN_BAR_COUNT) {
- bar_enabled = false;
+ if (bar_count == 0) {
+ if (bar_width != 0) {
+ fprintf(stderr, "Warning: bar-width is deprecated, use bar-count instead\n");
+ int tmp = screen->width_in_pixels;
+ if (bar_orientation == BAR_VERT) tmp = screen->height_in_pixels;
+ bar_count = tmp / bar_width;
+ if (tmp % bar_width != 0) {
+ ++bar_count;
+ }
+ } else {
+ bar_count = 10;
}
+ } else if (bar_width != 0) {
+ errx(EXIT_FAILURE, "bar-width and bar-count cannot be used at the same time");
+ }
+
+ if (bar_count >= MIN_BAR_COUNT && bar_count <= MAX_BAR_COUNT) {
+ bar_heights = (double*) calloc(bar_count, sizeof(double));
+ } else {
+ bar_enabled = false;
}
- bar_heights = (double*) calloc(bar_count, sizeof(double));
}
xcb_change_window_attributes(conn, screen->root, XCB_CW_EVENT_MASK,