fix aliases...again + bar serialization

This commit is contained in:
FelixKratz 2021-09-26 21:11:31 +02:00
parent 906ec7a1aa
commit 6fd12dbe7e
6 changed files with 57 additions and 17 deletions

View file

@ -5,6 +5,7 @@
extern CFArrayRef SLSHWCaptureWindowList(uint32_t cid, uint32_t* wid, uint32_t count, uint32_t flags);
extern void SLSCaptureWindowsContentsToRectWithOptions(uint32_t cid, uint32_t* wid, bool meh, CGRect bounds, uint32_t flags, CGImageRef* image);
extern int SLSGetScreenRectForWindow(uint32_t cid, uint32_t wid, CGRect* out);
void print_all_menu_items(FILE* rsp) {
CFArrayRef window_list = CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID);
@ -101,16 +102,15 @@ void alias_find_window(struct alias* alias) {
CFRelease(window_list);
}
bool alias_update_image(struct alias* alias) {
if (alias->wid == 0) alias_find_window(alias);
if (alias->wid == 0) {
alias->image_ref = NULL;
return false;
}
// Capture Bar Item with SkyLight private framework
CGImageRef tmp_ref = NULL;
/*CFArrayRef image_refs = SLSHWCaptureWindowList(g_connection, &alias->wid, 1, 1 << 8 | 1 << 11);
if (image_refs && CFArrayGetCount(image_refs) > 0) {
tmp_ref = (CGImageRef) CFArrayGetValueAtIndex(image_refs, 0);
@ -118,21 +118,17 @@ bool alias_update_image(struct alias* alias) {
else {
tmp_ref = NULL;
}*/
SLSGetScreenRectForWindow(g_connection, alias->wid, &alias->bounds);
SLSCaptureWindowsContentsToRectWithOptions(g_connection, &alias->wid, true, CGRectNull, 1 << 8, &tmp_ref);
//CGImageRef tmp_ref = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow,
// alias->wid, kCGWindowImageBestResolution | kCGWindowImageBoundsIgnoreFraming);
// alias->wid, kCGWindowImageBestResolution | kCGWindowImageBoundsIgnoreFraming);
if (!tmp_ref) {
alias->size.x = 0;
alias->size.y = 0;
return false;
}
if (!tmp_ref) { alias->wid = 0; return false;}
CGImageRelease(alias->image_ref);
alias->image_ref = tmp_ref;
alias->size.x = CGImageGetWidth(alias->image_ref);
alias->size.y = CGImageGetHeight(alias->image_ref);
// Bar Item Cropping
/* alias->size.x = CGImageGetWidth(raw_image_ref) - 2*MENU_ITEM_CROP;
alias->size.y = CGImageGetHeight(raw_image_ref);

View file

@ -11,7 +11,6 @@ struct alias {
uint64_t pid;
uint32_t wid;
CGImageRef image_ref;
CGPoint size;
CGRect bounds;
};

View file

@ -201,7 +201,7 @@ void bar_redraw(struct bar* bar) {
bar_left_final_item_x += bar_item->graph_data.graph_width;
}
if (bar_item->has_alias) {
bar_left_final_item_x += bar_item->alias.size.x;
bar_left_final_item_x += bar_item->alias.bounds.size.width;
}
}
else if (bar_item->position == BAR_POSITION_RIGHT) {
@ -217,8 +217,8 @@ void bar_redraw(struct bar* bar) {
bar_right_first_item_x -= bar_item->graph_data.graph_width;
}
if (bar_item->has_alias) {
icon_position.x -= bar_item->alias.size.x;
bar_right_first_item_x -= bar_item->alias.size.x;
icon_position.x -= bar_item->alias.bounds.size.width;
bar_right_first_item_x -= bar_item->alias.bounds.size.width;
}
}
else if (bar_item->position == BAR_POSITION_CENTER) {
@ -233,7 +233,7 @@ void bar_redraw(struct bar* bar) {
bar_center_first_item_x += bar_item->graph_data.graph_width;
}
if (bar_item->has_alias) {
bar_center_first_item_x += bar_item->alias.size.x;
bar_center_first_item_x += bar_item->alias.bounds.size.width;
}
}
bar_item->label_line.bounds.origin = label_position;

View file

@ -339,3 +339,43 @@ void bar_manager_freeze(struct bar_manager *bar_manager) {
void bar_manager_unfreeze(struct bar_manager *bar_manager) {
bar_manager->frozen = false;
}
void bar_manager_serialize(struct bar_manager* bar_manager, FILE* rsp) {
fprintf(rsp, "{\n"
"\t\"geometry\": {\n"
"\t\t\"position\": \"%s\",\n"
"\t\t\"height\": %u,\n"
"\t\t\"margin\": %u,\n"
"\t\t\"y_offset\": %u,\n"
"\t\t\"corner_radius\": %u,\n"
"\t\t\"border_width\": %u,\n"
"\t\t\"padding_left\": %u,\n"
"\t\t\"padding_right\": %u\n"
"\t},\n"
"\t\"style\": {\n"
"\t\t\"background_color\": \"0x%x\",\n"
"\t\t\"border_color\": \"0x%x\",\n"
"\t\t\"blur_radius\": %u\n"
"\t},\n"
"\t\"state\": {\n"
"\t\t\"frozen\": %d,\n"
"\t\t\"topmost\": %d,\n"
"\t\t\"font_smoothing\": %d\n"
"\t}\n"
"}\n",
bar_manager->position,
bar_manager->height,
bar_manager->margin,
bar_manager->y_offset,
bar_manager->corner_radius,
bar_manager->border_width,
bar_manager->padding_left,
bar_manager->padding_right,
hex_from_rgba_color(bar_manager->background_color),
hex_from_rgba_color(bar_manager->border_color),
bar_manager->blur_radius,
bar_manager->frozen,
bar_manager->topmost,
bar_manager->font_smoothing);
}

View file

@ -45,6 +45,8 @@ struct bar_item* bar_manager_create_item(struct bar_manager* bar_manager);
void bar_manager_destroy_item(struct bar_manager* bar_manager, struct bar_item* bar_item);
void bar_manager_handle_notification(struct bar_manager* bar_manager, char* context);
void bar_manager_serialize(struct bar_manager* bar_manager, FILE* rsp);
void bar_manager_update(struct bar_manager* bar_manager, bool forced);
void bar_manager_update_space_components(struct bar_manager* bar_manager, bool forced);
void bar_manager_set_background_blur(struct bar_manager* bar_manager, uint32_t radius);

View file

@ -109,6 +109,7 @@ extern bool g_verbose;
#define DOMAIN_QUERY "query"
#define COMMAND_QUERY_DEFAULT_ITEMS "default_menu_items"
#define COMMAND_QUERY_ITEM "item"
#define COMMAND_QUERY_BAR "bar"
#define ARGUMENT_COMMON_VAL_ON "on"
#define ARGUMENT_COMMON_VAL_TRUE "true"
@ -668,8 +669,7 @@ static void handle_domain_query(FILE* rsp, struct token domain, char* message) {
if (token_equals(token, COMMAND_QUERY_DEFAULT_ITEMS)) {
print_all_menu_items(rsp);
}
if (token_equals(token, COMMAND_QUERY_ITEM)) {
} else if (token_equals(token, COMMAND_QUERY_ITEM)) {
struct token name = get_token(&message);
int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, name.text);
if (item_index_for_name < 0) {
@ -678,7 +678,10 @@ static void handle_domain_query(FILE* rsp, struct token domain, char* message) {
return;
}
bar_item_serialize(g_bar_manager.bar_items[item_index_for_name], rsp);
} else if (token_equals(token, COMMAND_QUERY_BAR)) {
bar_manager_serialize(&g_bar_manager, rsp);
}
}
void handle_message(FILE *rsp, char *message) {