mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-09-20 14:01:56 +00:00
remove ax api playground for now
This commit is contained in:
parent
0901d4fd0d
commit
e851eebad5
3 changed files with 1 additions and 77 deletions
2
makefile
2
makefile
|
@ -4,7 +4,7 @@ ODIR = bin
|
|||
SRC = src
|
||||
|
||||
_OBJ = alias.o background.o bar_item.o custom_events.o event.o graph.o \
|
||||
image.o mouse.o shadow.o text.o message.o mouse.o ax.o bar.o window.o \
|
||||
image.o mouse.o shadow.o text.o message.o mouse.o bar.o window.o \
|
||||
bar_manager.o display.o event_loop.o group.o mach.o popup.o \
|
||||
animation.o workspace.om
|
||||
OBJ = $(patsubst %, $(ODIR)/%, $(_OBJ))
|
||||
|
|
62
src/ax.c
62
src/ax.c
|
@ -1,62 +0,0 @@
|
|||
#include "ax.h"
|
||||
|
||||
void ax_init(struct ax* ax, bool check_privileges) {
|
||||
ax->elements = NULL;
|
||||
ax->element_count = 0;
|
||||
if (check_privileges) {
|
||||
const void *keys[] = { kAXTrustedCheckOptionPrompt };
|
||||
const void *values[] = { kCFBooleanTrue };
|
||||
|
||||
CFDictionaryRef options;
|
||||
options = CFDictionaryCreate(kCFAllocatorDefault,
|
||||
keys, values, sizeof(keys) / sizeof(*keys),
|
||||
&kCFCopyStringDictionaryKeyCallBacks,
|
||||
&kCFTypeDictionaryValueCallBacks );
|
||||
|
||||
ax->is_privileged = AXIsProcessTrustedWithOptions(options);
|
||||
CFRelease(options);
|
||||
} else ax->is_privileged = g_ax.is_privileged;
|
||||
|
||||
}
|
||||
|
||||
void ax_perform_click(AXUIElementRef element) {
|
||||
if (!element) return;
|
||||
|
||||
AXUIElementPerformAction(element, kAXPressAction);
|
||||
}
|
||||
|
||||
AXUIElementRef ax_get_extra_menu_item(struct ax* ax, pid_t pid, char* name) {
|
||||
AXUIElementRef extra_menus_ref = NULL;
|
||||
AXUIElementRef extra_menu = NULL;
|
||||
CFArrayRef children_ref = NULL;
|
||||
|
||||
AXUIElementRef app = AXUIElementCreateApplication(pid);
|
||||
AXError error = AXUIElementCopyAttributeValue(app,
|
||||
kAXExtrasMenuBarAttribute,
|
||||
(CFTypeRef*)&extra_menus_ref);
|
||||
if (app) CFRelease(app);
|
||||
|
||||
if (error == kAXErrorSuccess) {
|
||||
error = AXUIElementCopyAttributeValue(extra_menus_ref,
|
||||
kAXVisibleChildrenAttribute,
|
||||
(CFTypeRef*)&children_ref);
|
||||
|
||||
uint32_t count = CFArrayGetCount(children_ref);
|
||||
|
||||
if (count == 1 || (count > 0 && !name)) {
|
||||
extra_menu = CFRetain(CFArrayGetValueAtIndex(children_ref, 0));
|
||||
} else {
|
||||
// Loop through array and find correct item via name...
|
||||
}
|
||||
CFRelease(extra_menus_ref);
|
||||
CFRelease(children_ref);
|
||||
}
|
||||
return extra_menu;
|
||||
}
|
||||
|
||||
void ax_clear(struct ax* ax) {
|
||||
for (int i = 0; i < ax->element_count; i++) {
|
||||
if (ax->elements[i]) CFRelease(ax->elements[i]);
|
||||
}
|
||||
if (ax->elements) free(ax->elements);
|
||||
}
|
14
src/ax.h
14
src/ax.h
|
@ -1,14 +0,0 @@
|
|||
#pragma once
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
struct ax {
|
||||
bool is_privileged;
|
||||
|
||||
uint32_t element_count;
|
||||
AXUIElementRef* elements;
|
||||
};
|
||||
|
||||
struct ax g_ax;
|
||||
void ax_init(struct ax* ax, bool check_privileges);
|
||||
void ax_clear(struct ax* ax);
|
||||
void ax_get_menu_item(struct ax* ax, pid_t pid, char* name);
|
Loading…
Reference in a new issue