aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/swaybar/bar.h15
-rw-r--r--include/swaybar/status_line.h4
-rw-r--r--sway/tree/container.c17
-rw-r--r--swaybar/bar.c17
-rw-r--r--swaybar/i3bar.c32
-rw-r--r--swaybar/render.c4
-rw-r--r--swaylock/main.c187
7 files changed, 201 insertions, 75 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index af478f33..f1ff25b2 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -16,11 +16,24 @@ struct swaybar_pointer {
int x, y;
};
+enum x11_button {
+ NONE,
+ LEFT,
+ MIDDLE,
+ RIGHT,
+ SCROLL_UP,
+ SCROLL_DOWN,
+ SCROLL_LEFT,
+ SCROLL_RIGHT,
+ BACK,
+ FORWARD,
+};
+
struct swaybar_hotspot {
struct wl_list link;
int x, y, width, height;
void (*callback)(struct swaybar_output *output,
- int x, int y, uint32_t button, void *data);
+ int x, int y, enum x11_button button, void *data);
void (*destroy)(void *data);
void *data;
};
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h
index bf12a842..2eaf8140 100644
--- a/include/swaybar/status_line.h
+++ b/include/swaybar/status_line.h
@@ -72,7 +72,9 @@ bool status_handle_readable(struct status_line *status);
void status_line_free(struct status_line *status);
bool i3bar_handle_readable(struct status_line *status);
void i3bar_block_send_click(struct status_line *status,
- struct i3bar_block *block, int x, int y, uint32_t button);
+ struct i3bar_block *block, int x, int y, enum x11_button button);
void i3bar_block_free(struct i3bar_block *block);
+enum x11_button wl_button_to_x11_button(uint32_t button);
+enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value);
#endif
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 3f9d701a..02384199 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -199,16 +199,23 @@ static struct sway_container *container_workspace_destroy(
return NULL;
}
- // Do not destroy this if it's the last workspace on this output
struct sway_container *output = container_parent(workspace, C_OUTPUT);
- if (output && output->children->length == 1) {
+
+ // If we're destroying the output, it will be NULL here. Return the root so
+ // that it doesn't appear that the workspace has refused to be destoyed,
+ // which would leave it in a broken state with no parent.
+ if (output == NULL) {
+ return &root_container;
+ }
+
+ // Do not destroy this if it's the last workspace on this output
+ if (output->children->length == 1) {
return NULL;
}
wlr_log(WLR_DEBUG, "destroying workspace '%s'", workspace->name);
- struct sway_container *parent = workspace->parent;
- if (!workspace_is_empty(workspace) && output) {
+ if (!workspace_is_empty(workspace)) {
// Move children to a different workspace on this output
struct sway_container *new_workspace = NULL;
for (int i = 0; i < output->children->length; i++) {
@@ -230,7 +237,7 @@ static struct sway_container *container_workspace_destroy(
}
}
- return parent;
+ return output;
}
static struct sway_container *container_output_destroy(
diff --git a/swaybar/bar.c b/swaybar/bar.c
index f03c5aea..94bc48bc 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -147,7 +147,7 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
&& x < hotspot->x + hotspot->width
&& y < hotspot->y + hotspot->height) {
hotspot->callback(output, pointer->x, pointer->y,
- button, hotspot->data);
+ wl_button_to_x11_button(button), hotspot->data);
}
}
}
@@ -155,11 +155,26 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value) {
struct swaybar *bar = data;
+ struct swaybar_pointer *pointer = &bar->pointer;
struct swaybar_output *output = bar->pointer.current;
if (!sway_assert(output, "axis with no active output")) {
return;
}
+ struct swaybar_hotspot *hotspot;
+ wl_list_for_each(hotspot, &output->hotspots, link) {
+ double x = pointer->x * output->scale;
+ double y = pointer->y * output->scale;
+ if (x >= hotspot->x
+ && y >= hotspot->y
+ && x < hotspot->x + hotspot->width
+ && y < hotspot->y + hotspot->height) {
+ hotspot->callback(output, pointer->x, pointer->y,
+ wl_axis_to_x11_button(axis, value), hotspot->data);
+ return;
+ }
+ }
+
double amt = wl_fixed_to_double(value);
if (amt == 0.0) {
return;
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c
index 26f073c8..78b183ad 100644
--- a/swaybar/i3bar.c
+++ b/swaybar/i3bar.c
@@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include <json-c/json.h>
+#include <linux/input-event-codes.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -192,7 +193,7 @@ bool i3bar_handle_readable(struct status_line *status) {
}
void i3bar_block_send_click(struct status_line *status,
- struct i3bar_block *block, int x, int y, uint32_t button) {
+ struct i3bar_block *block, int x, int y, enum x11_button button) {
wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)");
if (!block->name || !status->i3bar_state.click_events) {
return;
@@ -215,3 +216,32 @@ void i3bar_block_send_click(struct status_line *status,
}
json_object_put(event_json);
}
+
+enum x11_button wl_button_to_x11_button(uint32_t button) {
+ switch (button) {
+ case BTN_LEFT:
+ return LEFT;
+ case BTN_MIDDLE:
+ return MIDDLE;
+ case BTN_RIGHT:
+ return RIGHT;
+ case BTN_SIDE:
+ return BACK;
+ case BTN_EXTRA:
+ return FORWARD;
+ default:
+ return NONE;
+ }
+}
+
+enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value) {
+ switch (axis) {
+ case WL_POINTER_AXIS_VERTICAL_SCROLL:
+ return wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN;
+ case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
+ return wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT;
+ default:
+ wlr_log(WLR_DEBUG, "Unexpected axis value on mouse scroll");
+ return NONE;
+ }
+}
diff --git a/swaybar/render.c b/swaybar/render.c
index 909b56f4..d210e25a 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -109,7 +109,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,
}
static void block_hotspot_callback(struct swaybar_output *output,
- int x, int y, uint32_t button, void *data) {
+ int x, int y, enum x11_button button, void *data) {
struct i3bar_block *block = data;
struct status_line *status = output->bar->status;
i3bar_block_send_click(status, block, x, y, button);
@@ -349,7 +349,7 @@ static const char *strip_workspace_number(const char *ws_name) {
}
static void workspace_hotspot_callback(struct swaybar_output *output,
- int x, int y, uint32_t button, void *data) {
+ int x, int y, enum x11_button button, void *data) {
ipc_send_workspace_command(output->bar, (const char *)data);
}
diff --git a/swaylock/main.c b/swaylock/main.c
index ae5b86b9..668a8742 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -345,22 +345,25 @@ static void load_image(char *arg, struct swaylock_state *state) {
image->path = strdup(arg);
}
- bool exists = false;
- struct swaylock_image *iter_image;
- wl_list_for_each(iter_image, &state->images, link) {
+ struct swaylock_image *iter_image, *temp;
+ wl_list_for_each_safe(iter_image, temp, &state->images, link) {
if (lenient_strcmp(iter_image->output_name, image->output_name) == 0) {
- exists = true;
+ if (image->output_name) {
+ wlr_log(WLR_DEBUG,
+ "Replacing image defined for output %s with %s",
+ image->output_name, image->path);
+ } else {
+ wlr_log(WLR_DEBUG, "Replacing default image with %s",
+ image->path);
+ }
+ wl_list_remove(&iter_image->link);
+ free(iter_image->cairo_surface);
+ free(iter_image->output_name);
+ free(iter_image->path);
+ free(iter_image);
break;
}
}
- if (exists) {
- if (image->output_name) {
- wlr_log(WLR_ERROR, "Multiple images defined for output %s",
- image->output_name);
- } else {
- wlr_log(WLR_ERROR, "Multiple default images defined");
- }
- }
// Bash doesn't replace the ~ with $HOME if the output name is supplied
wordexp_t p;
@@ -420,7 +423,7 @@ enum line_mode {
};
static int parse_options(int argc, char **argv, struct swaylock_state *state,
- enum line_mode *line_mode) {
+ enum line_mode *line_mode, char **config_path) {
enum long_option_codes {
LO_BS_HL_COLOR = 256,
LO_FONT,
@@ -572,38 +575,58 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
}
switch (c) {
case 'C':
- // Config file. This will have already been handled so just ignore.
+ if (config_path) {
+ *config_path = strdup(optarg);
+ }
break;
case 'c':
- state->args.colors.background = parse_color(optarg);
- state->args.mode = BACKGROUND_MODE_SOLID_COLOR;
+ if (state) {
+ state->args.colors.background = parse_color(optarg);
+ state->args.mode = BACKGROUND_MODE_SOLID_COLOR;
+ }
break;
case 'e':
- state->args.ignore_empty = true;
+ if (state) {
+ state->args.ignore_empty = true;
+ }
break;
case 'f':
- state->args.daemonize = true;
+ if (state) {
+ state->args.daemonize = true;
+ }
break;
case 'i':
- load_image(optarg, state);
+ if (state) {
+ load_image(optarg, state);
+ }
break;
case 'n':
- *line_mode = LM_INSIDE;
+ if (line_mode) {
+ *line_mode = LM_INSIDE;
+ }
break;
case 'r':
- *line_mode = LM_RING;
+ if (line_mode) {
+ *line_mode = LM_RING;
+ }
break;
case 's':
- state->args.mode = parse_background_mode(optarg);
- if (state->args.mode == BACKGROUND_MODE_INVALID) {
- return 1;
+ if (state) {
+ state->args.mode = parse_background_mode(optarg);
+ if (state->args.mode == BACKGROUND_MODE_INVALID) {
+ return 1;
+ }
}
break;
case 't':
- state->args.mode = BACKGROUND_MODE_TILE;
+ if (state) {
+ state->args.mode = BACKGROUND_MODE_TILE;
+ }
break;
case 'u':
- state->args.show_indicator = false;
+ if (state) {
+ state->args.show_indicator = false;
+ }
break;
case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
@@ -612,73 +635,117 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
#else
fprintf(stdout, "version unknown\n");
#endif
- return 0;
+ return 1;
case LO_BS_HL_COLOR:
- state->args.colors.bs_highlight = parse_color(optarg);
+ if (state) {
+ state->args.colors.bs_highlight = parse_color(optarg);
+ }
break;
case LO_FONT:
- free(state->args.font);
- state->args.font = strdup(optarg);
+ if (state) {
+ free(state->args.font);
+ state->args.font = strdup(optarg);
+ }
break;
case LO_IND_RADIUS:
- state->args.radius = strtol(optarg, NULL, 0);
+ if (state) {
+ state->args.radius = strtol(optarg, NULL, 0);
+ }
break;
case LO_IND_THICKNESS:
- state->args.thickness = strtol(optarg, NULL, 0);
+ if (state) {
+ state->args.thickness = strtol(optarg, NULL, 0);
+ }
break;
case LO_INSIDE_COLOR:
- state->args.colors.inside.input = parse_color(optarg);
+ if (state) {
+ state->args.colors.inside.input = parse_color(optarg);
+ }
break;
case LO_INSIDE_CLEAR_COLOR:
- state->args.colors.inside.cleared = parse_color(optarg);
+ if (state) {
+ state->args.colors.inside.cleared = parse_color(optarg);
+ }
break;
case LO_INSIDE_VER_COLOR:
- state->args.colors.inside.verifying = parse_color(optarg);
+ if (state) {
+ state->args.colors.inside.verifying = parse_color(optarg);
+ }
break;
case LO_INSIDE_WRONG_COLOR:
- state->args.colors.inside.wrong = parse_color(optarg);
+ if (state) {
+ state->args.colors.inside.wrong = parse_color(optarg);
+ }
break;
case LO_KEY_HL_COLOR:
- state->args.colors.key_highlight = parse_color(optarg);
+ if (state) {
+ state->args.colors.key_highlight = parse_color(optarg);
+ }
break;
case LO_LINE_COLOR:
- state->args.colors.line.input = parse_color(optarg);
+ if (state) {
+ state->args.colors.line.input = parse_color(optarg);
+ }
break;
case LO_LINE_CLEAR_COLOR:
- state->args.colors.line.cleared = parse_color(optarg);
+ if (state) {
+ state->args.colors.line.cleared = parse_color(optarg);
+ }
break;
case LO_LINE_VER_COLOR:
- state->args.colors.line.verifying = parse_color(optarg);
+ if (state) {
+ state->args.colors.line.verifying = parse_color(optarg);
+ }
break;
case LO_LINE_WRONG_COLOR:
- state->args.colors.line.wrong = parse_color(optarg);
+ if (state) {
+ state->args.colors.line.wrong = parse_color(optarg);
+ }
break;
case LO_RING_COLOR:
- state->args.colors.ring.input = parse_color(optarg);
+ if (state) {
+ state->args.colors.ring.input = parse_color(optarg);
+ }
break;
case LO_RING_CLEAR_COLOR:
- state->args.colors.ring.cleared = parse_color(optarg);
+ if (state) {
+ state->args.colors.ring.cleared = parse_color(optarg);
+ }
break;
case LO_RING_VER_COLOR:
- state->args.colors.ring.verifying = parse_color(optarg);
+ if (state) {
+ state->args.colors.ring.verifying = parse_color(optarg);
+ }
break;
case LO_RING_WRONG_COLOR:
- state->args.colors.ring.wrong = parse_color(optarg);
+ if (state) {
+ state->args.colors.ring.wrong = parse_color(optarg);
+ }
break;
case LO_SEP_COLOR:
- state->args.colors.separator = parse_color(optarg);
+ if (state) {
+ state->args.colors.separator = parse_color(optarg);
+ }
break;
case LO_TEXT_COLOR:
- state->args.colors.text.input = parse_color(optarg);
+ if (state) {
+ state->args.colors.text.input = parse_color(optarg);
+ }
break;
case LO_TEXT_CLEAR_COLOR:
- state->args.colors.text.cleared = parse_color(optarg);
+ if (state) {
+ state->args.colors.text.cleared = parse_color(optarg);
+ }
break;
case LO_TEXT_VER_COLOR:
- state->args.colors.text.verifying = parse_color(optarg);
+ if (state) {
+ state->args.colors.text.verifying = parse_color(optarg);
+ }
break;
case LO_TEXT_WRONG_COLOR:
- state->args.colors.text.wrong = parse_color(optarg);
+ if (state) {
+ state->args.colors.text.wrong = parse_color(optarg);
+ }
break;
default:
fprintf(stderr, "%s", usage);
@@ -759,7 +826,7 @@ static int load_config(char *path, struct swaylock_state *state,
char flag[strlen(line) + 3];
sprintf(flag, "--%s", line);
char *argv[] = {"swaylock", flag};
- int result = parse_options(2, argv, state, line_mode);
+ int result = parse_options(2, argv, state, line_mode, NULL);
if (result != 0) {
free(line);
fclose(config);
@@ -789,18 +856,10 @@ int main(int argc, char **argv) {
wlr_log_init(WLR_DEBUG, NULL);
char *config_path = NULL;
- static struct option long_options[] = {
- {"config", required_argument, NULL, 'C'},
- {0, 0, 0, 0},
- };
- while (1) {
- int c = getopt_long(argc, argv, "C:", long_options, NULL);
- if (c == -1) {
- break;
- } else if (c == 'C') {
- config_path = strdup(optarg);
- break;
- }
+ int result = parse_options(argc, argv, NULL, NULL, &config_path);
+ if (result != 0) {
+ free(config_path);
+ return result;
}
if (!config_path) {
config_path = get_config_path();
@@ -817,7 +876,7 @@ int main(int argc, char **argv) {
if (argc > 1) {
wlr_log(WLR_DEBUG, "Parsing CLI Args");
- int result = parse_options(argc, argv, &state, &line_mode);
+ int result = parse_options(argc, argv, &state, &line_mode, NULL);
if (result != 0) {
return result;
}