diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-07-23 20:27:56 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-07-23 20:31:11 -0400 |
commit | f4b882475eee7a81c206c7825616cc4656b2f60b (patch) | |
tree | 38e6ebf81b235424f105dcbcbb194e5e9eac70c0 /swaybar | |
parent | acd79e1505c06089e4fb9fb6c0c6e1d351ba9176 (diff) | |
parent | 224ade138208e9aa525423cbfbd643aa9d9b63c3 (diff) |
Merge branch 'master' into pid-workspaces
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/bar.c | 25 | ||||
-rw-r--r-- | swaybar/i3bar.c | 41 | ||||
-rw-r--r-- | swaybar/ipc.c | 16 | ||||
-rw-r--r-- | swaybar/main.c | 8 | ||||
-rw-r--r-- | swaybar/render.c | 24 | ||||
-rw-r--r-- | swaybar/status_line.c | 6 |
6 files changed, 95 insertions, 25 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 5b8028e5..62a7727e 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -46,7 +46,7 @@ static void swaybar_output_free(struct swaybar_output *output) { if (!output) { return; } - wlr_log(L_DEBUG, "Removing output %s", output->name); + wlr_log(WLR_DEBUG, "Removing output %s", output->name); zwlr_layer_surface_v1_destroy(output->layer_surface); wl_surface_destroy(output->surface); wl_output_destroy(output->output); @@ -146,8 +146,10 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, && y >= hotspot->y && x < hotspot->x + hotspot->width && y < hotspot->y + hotspot->height) { - hotspot->callback(output, pointer->x, pointer->y, - button, hotspot->data); + if (HOTSPOT_IGNORE == hotspot->callback(output, pointer->x, pointer->y, + wl_button_to_x11_button(button), hotspot->data)) { + return; + } } } } @@ -155,11 +157,28 @@ 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) { + if (HOTSPOT_IGNORE == 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 141612a6..ae37eeb9 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> @@ -31,7 +32,7 @@ static bool i3bar_parse_json(struct status_line *status, const char *text) { status_error(status, "[failed to parse i3bar json]"); return false; } - wlr_log(L_DEBUG, "Got i3bar json: '%s'", text); + wlr_log(WLR_DEBUG, "Got i3bar json: '%s'", text); for (size_t i = 0; i < json_object_array_length(results); ++i) { json_object *full_text, *short_text, *color, *min_width, *align, *urgent; json_object *name, *instance, *separator, *separator_block_width; @@ -191,11 +192,11 @@ bool i3bar_handle_readable(struct status_line *status) { return redraw; } -void i3bar_block_send_click(struct status_line *status, - struct i3bar_block *block, int x, int y, uint32_t button) { - wlr_log(L_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); +enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, + 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; + return HOTSPOT_PROCESS; } struct json_object *event_json = json_object_new_object(); @@ -214,4 +215,34 @@ void i3bar_block_send_click(struct status_line *status, status_error(status, "[failed to write click event]"); } json_object_put(event_json); + return HOTSPOT_IGNORE; +} + +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/ipc.c b/swaybar/ipc.c index 959fa095..c2d05920 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -115,6 +115,18 @@ static void ipc_parse_colors( config->colors.inactive_workspace.text = parse_color( json_object_get_string(inactive_workspace_text)); } + if (urgent_workspace_border) { + config->colors.urgent_workspace.border = parse_color( + json_object_get_string(urgent_workspace_border)); + } + if (urgent_workspace_bg) { + config->colors.urgent_workspace.background = parse_color( + json_object_get_string(urgent_workspace_bg)); + } + if (urgent_workspace_text) { + config->colors.urgent_workspace.text = parse_color( + json_object_get_string(urgent_workspace_text)); + } if (binding_mode_border) { config->colors.binding_mode.border = parse_color( json_object_get_string(binding_mode_border)); @@ -327,7 +339,7 @@ bool handle_ipc_readable(struct swaybar *bar) { json_object *result = json_tokener_parse(resp->payload); if (!result) { free_ipc_response(resp); - wlr_log(L_ERROR, "failed to parse payload as json"); + wlr_log(WLR_ERROR, "failed to parse payload as json"); return false; } json_object *json_change, *json_pango_markup; @@ -340,7 +352,7 @@ bool handle_ipc_readable(struct swaybar *bar) { bar->config->mode = strdup(change); } } else { - wlr_log(L_ERROR, "failed to parse response"); + wlr_log(WLR_ERROR, "failed to parse response"); json_object_put(result); free_ipc_response(resp); return false; diff --git a/swaybar/main.c b/swaybar/main.c index c897e1c9..60e4b37c 100644 --- a/swaybar/main.c +++ b/swaybar/main.c @@ -75,13 +75,13 @@ int main(int argc, char **argv) { } if (debug) { - wlr_log_init(L_DEBUG, NULL); + wlr_log_init(WLR_DEBUG, NULL); } else { - wlr_log_init(L_ERROR, NULL); + wlr_log_init(WLR_ERROR, NULL); } if (!bar_id) { - wlr_log(L_ERROR, "No bar_id passed. " + wlr_log(WLR_ERROR, "No bar_id passed. " "Provide --bar_id or let sway start swaybar"); return 1; } @@ -89,7 +89,7 @@ int main(int argc, char **argv) { if (!socket_path) { socket_path = get_socketpath(); if (!socket_path) { - wlr_log(L_ERROR, "Unable to retrieve socket path"); + wlr_log(WLR_ERROR, "Unable to retrieve socket path"); return 1; } } diff --git a/swaybar/render.c b/swaybar/render.c index 327a6f5f..6f370077 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -108,11 +108,11 @@ 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) { +static enum hotspot_event_handling block_hotspot_callback(struct swaybar_output *output, + 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); + return i3bar_block_send_click(status, block, x, y, button); } static uint32_t render_status_block(cairo_t *cairo, @@ -298,7 +298,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, int text_width, text_height; get_text_size(cairo, config->font, &text_width, &text_height, - output->scale, config->pango_markup, "%s", mode); + output->scale, config->mode_pango_markup, + "%s", mode); int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale; @@ -329,7 +330,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, double text_y = height / 2.0 - text_height / 2.0; cairo_set_source_u32(cairo, config->colors.binding_mode.text); cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); - pango_printf(cairo, config->font, output->scale, config->pango_markup, + pango_printf(cairo, config->font, output->scale, config->mode_pango_markup, "%s", mode); return surface_height; } @@ -347,9 +348,13 @@ static const char *strip_workspace_number(const char *ws_name) { return ws_name; } -static void workspace_hotspot_callback(struct swaybar_output *output, - int x, int y, uint32_t button, void *data) { +static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output, + int x, int y, enum x11_button button, void *data) { + if (button != LEFT) { + return HOTSPOT_PROCESS; + } ipc_send_workspace_command(output->bar, (const char *)data); + return HOTSPOT_IGNORE; } static uint32_t render_workspace_button(cairo_t *cairo, @@ -496,12 +501,15 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) { // different height than what we asked for wl_surface_commit(output->surface); wl_display_roundtrip(bar->display); - } else { + } else if (height > 0) { // Replay recording into shm and send it off output->current_buffer = get_next_buffer(bar->shm, output->buffers, output->width * output->scale, output->height * output->scale); + if (!output->current_buffer) { + return; + } cairo_t *shm = output->current_buffer->cairo; cairo_save(shm); diff --git a/swaybar/status_line.c b/swaybar/status_line.c index e0e7414a..bc47580b 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c @@ -49,14 +49,14 @@ bool status_handle_readable(struct status_line *status) { json_object *version; if (json_object_object_get_ex(proto, "version", &version) && json_object_get_int(version) == 1) { - wlr_log(L_DEBUG, "Switched to i3bar protocol."); + wlr_log(WLR_DEBUG, "Switched to i3bar protocol."); status->protocol = PROTOCOL_I3BAR; } json_object *click_events; if (json_object_object_get_ex( proto, "click_events", &click_events) && json_object_get_boolean(click_events)) { - wlr_log(L_DEBUG, "Enabled click events."); + wlr_log(WLR_DEBUG, "Enabled click events."); status->i3bar_state.click_events = true; const char *events_array = "[\n"; ssize_t len = strlen(events_array); @@ -91,7 +91,7 @@ struct status_line *status_line_init(char *cmd) { int pipe_read_fd[2]; int pipe_write_fd[2]; if (pipe(pipe_read_fd) != 0 || pipe(pipe_write_fd) != 0) { - wlr_log(L_ERROR, "Unable to create pipes for status_command fork"); + wlr_log(WLR_ERROR, "Unable to create pipes for status_command fork"); exit(1); } |