mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge pull request #3252 from hvenev/swaybar-rel
Add relative coordinates in JSON for i3bar click events
This commit is contained in:
		
						commit
						6ccc836ebf
					
				
					 5 changed files with 20 additions and 10 deletions
				
			
		| 
						 | 
					@ -27,6 +27,7 @@ struct i3bar_block {
 | 
				
			||||||
void i3bar_block_unref(struct i3bar_block *block);
 | 
					void i3bar_block_unref(struct i3bar_block *block);
 | 
				
			||||||
bool i3bar_handle_readable(struct status_line *status);
 | 
					bool i3bar_handle_readable(struct status_line *status);
 | 
				
			||||||
enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
 | 
					enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
 | 
				
			||||||
		struct i3bar_block *block, int x, int y, enum x11_button button);
 | 
							struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h,
 | 
				
			||||||
 | 
							enum x11_button button);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,8 @@ struct swaybar_hotspot {
 | 
				
			||||||
	struct wl_list link; // swaybar_output::hotspots
 | 
						struct wl_list link; // swaybar_output::hotspots
 | 
				
			||||||
	int x, y, width, height;
 | 
						int x, y, width, height;
 | 
				
			||||||
	enum hotspot_event_handling (*callback)(struct swaybar_output *output,
 | 
						enum hotspot_event_handling (*callback)(struct swaybar_output *output,
 | 
				
			||||||
			int x, int y, enum x11_button button, void *data);
 | 
							struct swaybar_hotspot *hotspot, int x, int y,
 | 
				
			||||||
 | 
							enum x11_button button, void *data);
 | 
				
			||||||
	void (*destroy)(void *data);
 | 
						void (*destroy)(void *data);
 | 
				
			||||||
	void *data;
 | 
						void *data;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -260,7 +260,8 @@ bool i3bar_handle_readable(struct status_line *status) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
 | 
					enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
 | 
				
			||||||
		struct i3bar_block *block, int x, int y, enum x11_button button) {
 | 
							struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h,
 | 
				
			||||||
 | 
							enum x11_button button) {
 | 
				
			||||||
	wlr_log(WLR_DEBUG, "block %s clicked", block->name);
 | 
						wlr_log(WLR_DEBUG, "block %s clicked", block->name);
 | 
				
			||||||
	if (!block->name || !status->click_events) {
 | 
						if (!block->name || !status->click_events) {
 | 
				
			||||||
		return HOTSPOT_PROCESS;
 | 
							return HOTSPOT_PROCESS;
 | 
				
			||||||
| 
						 | 
					@ -277,6 +278,10 @@ enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
 | 
				
			||||||
	json_object_object_add(event_json, "button", json_object_new_int(button));
 | 
						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, "x", json_object_new_int(x));
 | 
				
			||||||
	json_object_object_add(event_json, "y", json_object_new_int(y));
 | 
						json_object_object_add(event_json, "y", json_object_new_int(y));
 | 
				
			||||||
 | 
						json_object_object_add(event_json, "relative_x", json_object_new_int(rx));
 | 
				
			||||||
 | 
						json_object_object_add(event_json, "relative_y", json_object_new_int(ry));
 | 
				
			||||||
 | 
						json_object_object_add(event_json, "width", json_object_new_int(w));
 | 
				
			||||||
 | 
						json_object_object_add(event_json, "height", json_object_new_int(h));
 | 
				
			||||||
	if (dprintf(status->write_fd, "%s%s\n", status->clicked ? "," : "",
 | 
						if (dprintf(status->write_fd, "%s%s\n", status->clicked ? "," : "",
 | 
				
			||||||
				json_object_to_json_string(event_json)) < 0) {
 | 
									json_object_to_json_string(event_json)) < 0) {
 | 
				
			||||||
		status_error(status, "[failed to write click event]");
 | 
							status_error(status, "[failed to write click event]");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -133,8 +133,8 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
 | 
				
			||||||
				&& y >= hotspot->y
 | 
									&& y >= hotspot->y
 | 
				
			||||||
				&& x < hotspot->x + hotspot->width
 | 
									&& x < hotspot->x + hotspot->width
 | 
				
			||||||
				&& y < hotspot->y + hotspot->height) {
 | 
									&& y < hotspot->y + hotspot->height) {
 | 
				
			||||||
			if (HOTSPOT_IGNORE == hotspot->callback(output, pointer->x, pointer->y,
 | 
								if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot,
 | 
				
			||||||
					wl_button_to_x11_button(button), hotspot->data)) {
 | 
										pointer->x, pointer->y, wl_button_to_x11_button(button), hotspot->data)) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -166,8 +166,8 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
 | 
				
			||||||
				&& y >= hotspot->y
 | 
									&& y >= hotspot->y
 | 
				
			||||||
				&& x < hotspot->x + hotspot->width
 | 
									&& x < hotspot->x + hotspot->width
 | 
				
			||||||
				&& y < hotspot->y + hotspot->height) {
 | 
									&& y < hotspot->y + hotspot->height) {
 | 
				
			||||||
			if (HOTSPOT_IGNORE == hotspot->callback(
 | 
								if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot,
 | 
				
			||||||
					output, pointer->x, pointer->y, button, hotspot->data)) {
 | 
										pointer->x, pointer->y, button, hotspot->data)) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -112,10 +112,12 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static enum hotspot_event_handling block_hotspot_callback(struct swaybar_output *output,
 | 
					static enum hotspot_event_handling block_hotspot_callback(struct swaybar_output *output,
 | 
				
			||||||
 | 
							struct swaybar_hotspot *hotspot,
 | 
				
			||||||
		int x, int y, enum x11_button button, void *data) {
 | 
							int x, int y, enum x11_button button, void *data) {
 | 
				
			||||||
	struct i3bar_block *block = data;
 | 
						struct i3bar_block *block = data;
 | 
				
			||||||
	struct status_line *status = output->bar->status;
 | 
						struct status_line *status = output->bar->status;
 | 
				
			||||||
	return i3bar_block_send_click(status, block, x, y, button);
 | 
						return i3bar_block_send_click(status, block, x, y, x - hotspot->x, y - hotspot->y,
 | 
				
			||||||
 | 
								hotspot->width, hotspot->height, button);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void i3bar_block_unref_callback(void *data) {
 | 
					static void i3bar_block_unref_callback(void *data) {
 | 
				
			||||||
| 
						 | 
					@ -343,6 +345,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output,
 | 
					static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output,
 | 
				
			||||||
 | 
							struct swaybar_hotspot *hotspot,
 | 
				
			||||||
		int x, int y, enum x11_button button, void *data) {
 | 
							int x, int y, enum x11_button button, void *data) {
 | 
				
			||||||
	if (button != LEFT) {
 | 
						if (button != LEFT) {
 | 
				
			||||||
		return HOTSPOT_PROCESS;
 | 
							return HOTSPOT_PROCESS;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue