mirror of
https://github.com/swaywm/sway.git
synced 2025-10-29 05:40:18 -04:00
swaybar: fix cursor scale
This fixes a few issues with swaybar's cursor scaling: 1. The cursor scale is now changed when the output scale changes 2. The cursor scale is no longer bound by the max output scale when swaybar is launched 3. Related to the previous item, the cursor is no longer tiny on low scale outputs after the max output scale has changed This also bumps up `wl_compositor` to version 4 to allow usage of `wl_surface_damage_buffer`.
This commit is contained in:
parent
cd714cc12a
commit
35a82a8693
3 changed files with 33 additions and 31 deletions
|
|
@ -55,11 +55,34 @@ static enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value) {
|
|||
}
|
||||
}
|
||||
|
||||
void update_cursor(struct swaybar *bar) {
|
||||
struct swaybar_pointer *pointer = &bar->pointer;
|
||||
if (pointer->cursor_theme) {
|
||||
wl_cursor_theme_destroy(pointer->cursor_theme);
|
||||
}
|
||||
int scale = pointer->current ? pointer->current->scale : 1;
|
||||
pointer->cursor_theme = wl_cursor_theme_load(NULL, 24 * scale, bar->shm);
|
||||
struct wl_cursor *cursor;
|
||||
cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr");
|
||||
pointer->cursor_image = cursor->images[0];
|
||||
wl_surface_set_buffer_scale(pointer->cursor_surface, scale);
|
||||
wl_surface_attach(pointer->cursor_surface,
|
||||
wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
|
||||
wl_pointer_set_cursor(pointer->pointer, pointer->serial,
|
||||
pointer->cursor_surface,
|
||||
pointer->cursor_image->hotspot_x / scale,
|
||||
pointer->cursor_image->hotspot_y / scale);
|
||||
wl_surface_damage_buffer(pointer->cursor_surface, 0, 0,
|
||||
INT32_MAX, INT32_MAX);
|
||||
wl_surface_commit(pointer->cursor_surface);
|
||||
}
|
||||
|
||||
static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
|
||||
uint32_t serial, struct wl_surface *surface,
|
||||
wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
||||
struct swaybar *bar = data;
|
||||
struct swaybar_pointer *pointer = &bar->pointer;
|
||||
pointer->serial = serial;
|
||||
struct swaybar_output *output;
|
||||
wl_list_for_each(output, &bar->outputs, link) {
|
||||
if (output->surface == surface) {
|
||||
|
|
@ -67,20 +90,7 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
|
|||
break;
|
||||
}
|
||||
}
|
||||
int max_scale = 1;
|
||||
struct swaybar_output *_output;
|
||||
wl_list_for_each(_output, &bar->outputs, link) {
|
||||
if (_output->scale > max_scale) {
|
||||
max_scale = _output->scale;
|
||||
}
|
||||
}
|
||||
wl_surface_set_buffer_scale(pointer->cursor_surface, max_scale);
|
||||
wl_surface_attach(pointer->cursor_surface,
|
||||
wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
|
||||
wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface,
|
||||
pointer->cursor_image->hotspot_x / max_scale,
|
||||
pointer->cursor_image->hotspot_y / max_scale);
|
||||
wl_surface_commit(pointer->cursor_surface);
|
||||
update_cursor(bar);
|
||||
}
|
||||
|
||||
static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue