use original window bounds to draw image

This commit is contained in:
FelixKratz 2021-09-24 18:55:01 +02:00
parent 6170ff34f7
commit 53ea4c913c
3 changed files with 6 additions and 2 deletions

View file

@ -87,6 +87,9 @@ void alias_find_window(struct alias* alias) {
CFNumberRef window_id_ref = CFDictionaryGetValue(dictionary, kCGWindowNumber);
if (!window_id_ref) continue;
CFDictionaryRef bounds = CFDictionaryGetValue(dictionary, kCGWindowBounds);
if (!bounds) continue;
CGRectMakeWithDictionaryRepresentation(bounds, &alias->bounds);
CFNumberGetValue(window_id_ref, CFNumberGetType(window_id_ref), &alias->wid);
CFRelease(window_list);
@ -113,7 +116,7 @@ bool alias_update_image(struct alias* alias) {
else {
tmp_ref = NULL;
}*/
SLSCaptureWindowsContentsToRectWithOptions(g_connection, &alias->wid, true, CGRectNull, 1 << 9 | 1 << 11, &tmp_ref);
SLSCaptureWindowsContentsToRectWithOptions(g_connection, &alias->wid, true, CGRectNull, 1 << 8, &tmp_ref);
//CGImageRef tmp_ref = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow,
// alias->wid, kCGWindowImageBestResolution | kCGWindowImageBoundsIgnoreFraming);

View file

@ -12,6 +12,7 @@ struct alias {
uint32_t wid;
CGImageRef image_ref;
CGPoint size;
CGRect bounds;
};
void print_all_menu_items();

View file

@ -158,7 +158,7 @@ void bar_draw_item_background(struct bar* bar, struct bar_item* bar_item, uint32
void bar_draw_alias(struct bar* bar, struct bar_item* bar_item, uint32_t x) {
if (!bar_item->has_alias || !bar_item->alias.image_ref) return;
CGRect bounds = {{x, (bar->frame.size.height - bar_item->alias.size.y) / 2},{bar_item->alias.size.x, bar_item->alias.size.y}};
CGRect bounds = {{x, (bar->frame.size.height - bar_item->alias.bounds.size.height) / 2},{bar_item->alias.bounds.size.width, bar_item->alias.bounds.size.height}};
CGContextDrawImage(bar->context, bounds, bar_item->alias.image_ref);
}