mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 09:21:28 +00:00
Send click events for i3bar blocks
This commit is contained in:
parent
333dbcbe72
commit
0cbd2a4f49
|
@ -67,9 +67,11 @@ struct status_line {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct status_line *status_line_init(char *cmd);
|
struct status_line *status_line_init(char *cmd);
|
||||||
void status_line_free(struct status_line *status);
|
|
||||||
bool status_handle_readable(struct status_line *status);
|
|
||||||
bool i3bar_handle_readable(struct status_line *status);
|
|
||||||
void status_error(struct status_line *status, const char *text);
|
void status_error(struct status_line *status, const char *text);
|
||||||
|
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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -186,3 +186,25 @@ bool i3bar_handle_readable(struct status_line *status) {
|
||||||
state->buffer_index = cur - state->buffer;
|
state->buffer_index = cur - state->buffer;
|
||||||
return redraw;
|
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)");
|
||||||
|
if (!block->name || !status->i3bar_state.click_events) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct json_object *event_json = json_object_new_object();
|
||||||
|
json_object_object_add(event_json, "name",
|
||||||
|
json_object_new_string(block->name));
|
||||||
|
if (block->instance) {
|
||||||
|
json_object_object_add(event_json, "instance",
|
||||||
|
json_object_new_string(block->instance));
|
||||||
|
}
|
||||||
|
|
||||||
|
json_object_object_add(event_json, "button", json_object_new_int(button));
|
||||||
|
json_object_object_add(event_json, "x", json_object_new_int(x));
|
||||||
|
json_object_object_add(event_json, "y", json_object_new_int(y));
|
||||||
|
dprintf(status->write_fd, "%s\n", json_object_to_json_string(event_json));
|
||||||
|
json_object_put(event_json);
|
||||||
|
}
|
||||||
|
|
|
@ -89,9 +89,17 @@ 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) {
|
||||||
|
struct i3bar_block *block = data;
|
||||||
|
struct status_line *status = output->bar->status;
|
||||||
|
i3bar_block_send_click(status, block, x, y, button);
|
||||||
|
}
|
||||||
|
|
||||||
static uint32_t render_status_block(cairo_t *cairo,
|
static uint32_t render_status_block(cairo_t *cairo,
|
||||||
struct swaybar_config *config, struct i3bar_block *block,
|
struct swaybar_config *config, struct swaybar_output *output,
|
||||||
double *x, uint32_t height, bool focused, bool edge) {
|
struct i3bar_block *block, double *x,
|
||||||
|
uint32_t height, bool focused, bool edge) {
|
||||||
static const int margin = 3;
|
static const int margin = 3;
|
||||||
if (!block->full_text || !*block->full_text) {
|
if (!block->full_text || !*block->full_text) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -139,7 +147,15 @@ static uint32_t render_status_block(cairo_t *cairo,
|
||||||
*x -= margin;
|
*x -= margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Create hotspot here
|
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
||||||
|
hotspot->x = *x;
|
||||||
|
hotspot->y = 0;
|
||||||
|
hotspot->width = width;
|
||||||
|
hotspot->height = height;
|
||||||
|
hotspot->callback = block_hotspot_callback;
|
||||||
|
hotspot->destroy = free;
|
||||||
|
hotspot->data = block;
|
||||||
|
wl_list_insert(&output->hotspots, &hotspot->link);
|
||||||
|
|
||||||
double pos = *x;
|
double pos = *x;
|
||||||
if (block->background) {
|
if (block->background) {
|
||||||
|
@ -208,13 +224,14 @@ static uint32_t render_status_block(cairo_t *cairo,
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t render_status_line_i3bar(cairo_t *cairo,
|
static uint32_t render_status_line_i3bar(cairo_t *cairo,
|
||||||
struct swaybar_config *config, struct status_line *status,
|
struct swaybar_config *config, struct swaybar_output *output,
|
||||||
bool focused, double *x, uint32_t width, uint32_t height) {
|
struct status_line *status, bool focused,
|
||||||
|
double *x, uint32_t width, uint32_t height) {
|
||||||
struct i3bar_block *block;
|
struct i3bar_block *block;
|
||||||
uint32_t max_height = 0;
|
uint32_t max_height = 0;
|
||||||
bool edge = true;
|
bool edge = true;
|
||||||
wl_list_for_each_reverse(block, &status->blocks, link) {
|
wl_list_for_each_reverse(block, &status->blocks, link) {
|
||||||
uint32_t h = render_status_block(cairo, config,
|
uint32_t h = render_status_block(cairo, config, output,
|
||||||
block, x, height, focused, edge);
|
block, x, height, focused, edge);
|
||||||
max_height = h > max_height ? h : max_height;
|
max_height = h > max_height ? h : max_height;
|
||||||
edge = false;
|
edge = false;
|
||||||
|
@ -223,8 +240,9 @@ static uint32_t render_status_line_i3bar(cairo_t *cairo,
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t render_status_line(cairo_t *cairo,
|
static uint32_t render_status_line(cairo_t *cairo,
|
||||||
struct swaybar_config *config, struct status_line *status,
|
struct swaybar_config *config, struct swaybar_output *output,
|
||||||
bool focused, double *x, uint32_t width, uint32_t height) {
|
struct status_line *status, bool focused,
|
||||||
|
double *x, uint32_t width, uint32_t height) {
|
||||||
switch (status->protocol) {
|
switch (status->protocol) {
|
||||||
case PROTOCOL_ERROR:
|
case PROTOCOL_ERROR:
|
||||||
return render_status_line_error(cairo,
|
return render_status_line_error(cairo,
|
||||||
|
@ -233,8 +251,8 @@ static uint32_t render_status_line(cairo_t *cairo,
|
||||||
return render_status_line_text(cairo,
|
return render_status_line_text(cairo,
|
||||||
config, status->text, focused, x, width, height);
|
config, status->text, focused, x, width, height);
|
||||||
case PROTOCOL_I3BAR:
|
case PROTOCOL_I3BAR:
|
||||||
return render_status_line_i3bar(cairo,
|
return render_status_line_i3bar(cairo, config, output, status,
|
||||||
config, status, focused, x, width, height);
|
focused, x, width, height);
|
||||||
case PROTOCOL_UNDEF:
|
case PROTOCOL_UNDEF:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -344,8 +362,8 @@ static uint32_t render_workspace_button(cairo_t *cairo,
|
||||||
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
||||||
hotspot->x = *x;
|
hotspot->x = *x;
|
||||||
hotspot->y = 0;
|
hotspot->y = 0;
|
||||||
hotspot->height = height;
|
|
||||||
hotspot->width = width;
|
hotspot->width = width;
|
||||||
|
hotspot->height = height;
|
||||||
hotspot->callback = workspace_hotspot_callback;
|
hotspot->callback = workspace_hotspot_callback;
|
||||||
hotspot->destroy = free;
|
hotspot->destroy = free;
|
||||||
hotspot->data = strdup(name);
|
hotspot->data = strdup(name);
|
||||||
|
@ -391,7 +409,7 @@ static uint32_t render_to_cairo(cairo_t *cairo,
|
||||||
}
|
}
|
||||||
x = output->width;
|
x = output->width;
|
||||||
if (bar->status) {
|
if (bar->status) {
|
||||||
uint32_t h = render_status_line(cairo, config, bar->status,
|
uint32_t h = render_status_line(cairo, config, output, bar->status,
|
||||||
output->focused, &x, output->width, output->height);
|
output->focused, &x, output->width, output->height);
|
||||||
max_height = h > max_height ? h : max_height;
|
max_height = h > max_height ? h : max_height;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue