experimenting with space capturing

This commit is contained in:
Felix Kratz 2022-07-19 15:18:02 +02:00
parent 87584b8a02
commit e9e6ace57a
2 changed files with 25 additions and 3 deletions

View file

@ -34,8 +34,17 @@ bool image_load(struct image* image, char* path, FILE* rsp) {
free(app);
return false;
}
}
else if (file_exists(res_path)) {
} else if (app_kv.key && app_kv.value && strcmp(app_kv.key, "space") == 0) {
uint32_t sid = atoi(app_kv.value);
CGImageRef space_img = space_capture(sid);
if (space_img) new_image_ref = space_img;
else {
respond(rsp, "[!] Image: Invalid Space ID: '%s'\n", app_kv.value);
free(res_path);
free(app);
return false;
}
} else if (file_exists(res_path)) {
CGDataProviderRef data_provider = CGDataProviderCreateWithFilename(res_path);
if (strlen(res_path) > 3 && string_equals(&res_path[strlen(res_path) - 4], ".png"))
new_image_ref = CGImageCreateWithPNGDataProvider(data_provider,
@ -173,4 +182,3 @@ bool image_parse_sub_domain(struct image* image, FILE* rsp, struct token propert
}
return false;
}

View file

@ -17,6 +17,7 @@
extern CFArrayRef SLSCopyManagedDisplaySpaces(int cid);
extern uint32_t SLSGetActiveSpace(int cid);
extern CFStringRef SLSCopyManagedDisplayForSpace(int cid, uint64_t sid);
extern CFArrayRef SLSHWCaptureSpace(int64_t cid, int64_t sid, int64_t flags);
extern int g_connection;
struct signal_args {
@ -440,6 +441,19 @@ out:
return result;
}
static inline CGImageRef space_capture(uint32_t sid) {
uint64_t dsid = dsid_from_sid(sid);
CGImageRef image = NULL;
if (dsid) {
CFArrayRef result = SLSHWCaptureSpace(g_connection, dsid, 0);
uint32_t count = CFArrayGetCount(result);
if (count > 0) {
image = (CGImageRef)CFArrayGetValueAtIndex(result, 0);
}
}
return image;
}
static inline uint32_t display_id_for_space(uint32_t sid) {
uint64_t dsid = dsid_from_sid(sid);
if (!dsid) return 0;