mirror of
https://github.com/swaywm/sway.git
synced 2025-10-29 05:40:18 -04:00
swaybar: fix i3bar relative coordinates when scaling is used
24e8ba048a did not take scaling into account.
The hotspot size used pixel coordinates, the absolute coordinates were logical,
and the relative coordinates were completely wrong.
This commit makes all coordinates use logical values. If
`"float_event_coords":true` is sent in the handshake message, coordinates are
sent as floating-point values.
The "scale" field is an integer containing the scale value.
This commit is contained in:
parent
fca32b6334
commit
7affe5c1bd
8 changed files with 51 additions and 38 deletions
|
|
@ -138,21 +138,23 @@ static bool check_bindings(struct swaybar *bar, uint32_t button,
|
|||
return false;
|
||||
}
|
||||
|
||||
static void process_hotspots(struct swaybar_output *output,
|
||||
static bool process_hotspots(struct swaybar_output *output,
|
||||
double x, double y, uint32_t button) {
|
||||
x *= output->scale;
|
||||
y *= output->scale;
|
||||
double px = x * output->scale;
|
||||
double py = y * output->scale;
|
||||
struct swaybar_hotspot *hotspot;
|
||||
wl_list_for_each(hotspot, &output->hotspots, link) {
|
||||
if (x >= hotspot->x && y >= hotspot->y
|
||||
&& x < hotspot->x + hotspot->width
|
||||
&& y < hotspot->y + hotspot->height) {
|
||||
if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot,
|
||||
x / output->scale, y / output->scale, button, hotspot->data)) {
|
||||
return;
|
||||
if (px >= hotspot->x && py >= hotspot->y
|
||||
&& px < hotspot->x + hotspot->width
|
||||
&& py < hotspot->y + hotspot->height) {
|
||||
if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, x, y,
|
||||
button, hotspot->data)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
||||
|
|
@ -229,19 +231,8 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
|
|||
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, hotspot,
|
||||
pointer->x, pointer->y, button, hotspot->data)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (process_hotspots(output, pointer->x, pointer->y, button)) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct swaybar_config *config = seat->bar->config;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue