-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hidpi support to swaybar #1722
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,11 +69,19 @@ 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, | ||
pointer->cursor_image->hotspot_y); | ||
pointer->cursor_image->hotspot_x / max_scale, | ||
pointer->cursor_image->hotspot_y / max_scale); | ||
wl_surface_commit(pointer->cursor_surface); | ||
} | ||
|
||
|
@@ -103,10 +111,12 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | |
} | ||
struct swaybar_hotspot *hotspot; | ||
wl_list_for_each(hotspot, &output->hotspots, link) { | ||
if (pointer->x >= hotspot->x | ||
&& pointer->y >= hotspot->y | ||
&& pointer->x < hotspot->x + hotspot->width | ||
&& pointer->y < hotspot->y + hotspot->height) { | ||
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) { | ||
hotspot->callback(output, pointer->x, pointer->y, | ||
button, hotspot->data); | ||
} | ||
|
@@ -197,12 +207,43 @@ const struct wl_seat_listener seat_listener = { | |
.name = seat_handle_name, | ||
}; | ||
|
||
static void output_geometry(void *data, struct wl_output *output, int32_t x, | ||
int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, | ||
const char *make, const char *model, int32_t transform) { | ||
// Who cares | ||
} | ||
|
||
static void output_mode(void *data, struct wl_output *output, uint32_t flags, | ||
int32_t width, int32_t height, int32_t refresh) { | ||
// Who cares | ||
} | ||
|
||
static void output_done(void *data, struct wl_output *output) { | ||
// Who cares | ||
} | ||
|
||
static void output_scale(void *data, struct wl_output *wl_output, | ||
int32_t factor) { | ||
struct swaybar_output *output = data; | ||
output->scale = factor; | ||
if (output->surface) { | ||
render_frame(output->bar, output); | ||
} | ||
} | ||
|
||
struct wl_output_listener output_listener = { | ||
.geometry = output_geometry, | ||
.mode = output_mode, | ||
.done = output_done, | ||
.scale = output_scale, | ||
}; | ||
|
||
static void handle_global(void *data, struct wl_registry *registry, | ||
uint32_t name, const char *interface, uint32_t version) { | ||
struct swaybar *bar = data; | ||
if (strcmp(interface, wl_compositor_interface.name) == 0) { | ||
bar->compositor = wl_registry_bind(registry, name, | ||
&wl_compositor_interface, 1); | ||
&wl_compositor_interface, 3); | ||
} else if (strcmp(interface, wl_seat_interface.name) == 0) { | ||
bar->seat = wl_registry_bind(registry, name, | ||
&wl_seat_interface, 1); | ||
|
@@ -216,7 +257,9 @@ static void handle_global(void *data, struct wl_registry *registry, | |
calloc(1, sizeof(struct swaybar_output)); | ||
output->bar = bar; | ||
output->output = wl_registry_bind(registry, name, | ||
&wl_output_interface, 1); | ||
&wl_output_interface, 3); | ||
wl_output_add_listener(output->output, &output_listener, output); | ||
output->scale = 1; | ||
output->index = index++; | ||
wl_list_init(&output->workspaces); | ||
wl_list_init(&output->hotspots); | ||
|
@@ -262,9 +305,20 @@ void bar_setup(struct swaybar *bar, | |
wl_registry_add_listener(registry, ®istry_listener, bar); | ||
wl_display_roundtrip(bar->display); | ||
assert(bar->compositor && bar->layer_shell && bar->shm); | ||
wl_display_roundtrip(bar->display); | ||
|
||
struct swaybar_pointer *pointer = &bar->pointer; | ||
|
||
assert(pointer->cursor_theme = wl_cursor_theme_load(NULL, 16, bar->shm)); | ||
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; | ||
} | ||
} | ||
|
||
assert(pointer->cursor_theme = wl_cursor_theme_load( | ||
NULL, 16 * (max_scale * 2), bar->shm)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. x cursor themes are weird, I dunno |
||
struct wl_cursor *cursor; | ||
assert(cursor = wl_cursor_theme_get_cursor( | ||
pointer->cursor_theme, "left_ptr")); | ||
|
@@ -273,7 +327,6 @@ void bar_setup(struct swaybar *bar, | |
wl_compositor_create_surface(bar->compositor)); | ||
|
||
// TODO: we might not necessarily be meant to do all of the outputs | ||
struct swaybar_output *output; | ||
wl_list_for_each(output, &bar->outputs, link) { | ||
struct config_output *coutput; | ||
wl_list_for_each(coutput, &bar->config->outputs, link) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't put a side effect in an assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do this all the time, it's all over sway et al. This is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind duh I see why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed fix to this file but will file a follow-up ticket to go fix my fuck-ups elsewhere