From dc73334f4b8a8bb44b74b9c9ea6cb39ac3df6d1d Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Mon, 6 Nov 2023 20:46:32 +0100 Subject: [PATCH] fix some more scaling problems with app icon images --- src/image.c | 1 + src/workspace.m | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/image.c b/src/image.c index 73cff39..0331c1c 100644 --- a/src/image.c +++ b/src/image.c @@ -40,6 +40,7 @@ bool image_load(struct image* image, char* path, FILE* rsp) { if (app_kv.key && app_kv.value && strcmp(app_kv.key, "app") == 0) { CGImageRef app_icon = workspace_icon_for_app(app_kv.value); scale = workspace_get_scale(); + scale *= scale; if (app_icon) new_image_ref = app_icon; else { respond(rsp, "[!] Image: Invalid application name: '%s'\n", app_kv.value); diff --git a/src/workspace.m b/src/workspace.m index 45001d4..8c30a40 100644 --- a/src/workspace.m +++ b/src/workspace.m @@ -9,7 +9,14 @@ @end float workspace_get_scale() { - return [[NSScreen mainScreen] backingScaleFactor]; + float scale = 1.f; + NSArray* screens = [NSScreen screens]; + for (int i = 0; i < [screens count]; i++) { + NSScreen* screen = screens[i]; + float screen_scale = [screen backingScaleFactor]; + if (screen_scale > scale) scale = screen_scale; + } + return scale; } void workspace_event_handler_init(void **context) { @@ -74,7 +81,7 @@ CGImageRef workspace_icon_for_app(char* app) { if (!image) return NULL; float scale = workspace_get_scale(); - NSRect rect = NSMakeRect( 0, 0, 16 * scale, 16 * scale); + NSRect rect = NSMakeRect( 0, 0, 32 * scale, 32 * scale); return (CGImageRef)CFRetain([image CGImageForProposedRect: &rect context: NULL hints: NULL]);