fix some more scaling problems with app icon images

This commit is contained in:
Felix Kratz 2023-11-06 20:46:32 +01:00
parent 10f6a110c4
commit dc73334f4b
2 changed files with 10 additions and 2 deletions

View file

@ -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);

View file

@ -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]);