ask for permission and less agressive O flag

This commit is contained in:
FelixKratz 2021-09-19 22:41:05 +02:00
parent 86da5be578
commit e6c758b87d
4 changed files with 16 additions and 6 deletions

View file

@ -1,6 +1,6 @@
FRAMEWORK_PATH = -F/System/Library/PrivateFrameworks
FRAMEWORK = -framework Carbon -framework Cocoa -framework SkyLight
BUILD_FLAGS = -std=c99 -Wall -DNDEBUG -Ofast -fvisibility=hidden -mmacosx-version-min=10.13
BUILD_FLAGS = -std=c99 -Wall -DNDEBUG -O0 -fvisibility=hidden -mmacosx-version-min=10.13
BUILD_PATH = ./bin
SKETCHYBAR_SRC = ./src/manifest.m
BINS = $(BUILD_PATH)/sketchybar

View file

@ -2,11 +2,16 @@
#include "misc/helpers.h"
#include <string.h>
void alias_get_permission(struct alias* alias) {
if (@available(macOS 10.15, *)) alias->permission = CGRequestScreenCaptureAccess();
}
void alias_init(struct alias* alias, char* name) {
alias->using_light_colors = true;
alias->name = name;
alias->wid = 0;
alias->image_ref = NULL;
alias_get_permission(alias);
alias_update_image(alias);
}
@ -23,6 +28,7 @@ void alias_find_window(struct alias* alias) {
if (!owner_ref) continue;
CFNumberRef layer_ref = CFDictionaryGetValue(dictionary, kCGWindowLayer);
printf("Moind \n");
if (!layer_ref) continue;
uint64_t layer = 0;
@ -34,13 +40,11 @@ void alias_find_window(struct alias* alias) {
CGWindowID window_id = 0;
CFNumberGetValue(window_id_ref, CFNumberGetType(window_id_ref), &window_id);
char* owner = cfstring_copy(owner_ref);
char* name = cfstring_copy(name_ref);
if (strcmp(alias->name, owner) != 0) { free(owner); free(name); continue; }
if (strcmp(alias->name, owner) != 0) { free(owner); continue; }
alias->wid = window_id;
free(owner);
free(name);
CFRelease(window_list);
return;
}
@ -54,7 +58,12 @@ bool alias_update_image(struct alias* alias) {
if (alias->image_ref) CFRelease(alias->image_ref);
alias->image_ref = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow,
alias->wid, kCGWindowImageBestResolution);
if (!alias->image_ref) return false;
if (!alias->image_ref) {
alias->size.x = 0;
alias->size.y = 0;
return false;
}
alias->size.x = CGImageGetWidth(alias->image_ref);
alias->size.y = CGImageGetHeight(alias->image_ref);
return true;

View file

@ -5,6 +5,7 @@
struct alias {
bool using_light_colors;
bool permission;
char* name;
uint32_t wid;
CGImageRef image_ref;

View file

@ -172,8 +172,8 @@ void bar_manager_set_hidden(struct bar_manager *bar_manager, bool hidden) {
bar_manager->window_level = level;
}
else {
bar_manager_begin(bar_manager);
bar_manager_unfreeze(bar_manager);
bar_manager_begin(bar_manager);
bar_manager_refresh(bar_manager, true);
}
}