lookup adid directly from active display uuid

This commit is contained in:
Felix Kratz 2024-01-15 21:34:33 +01:00
parent 6ff8ffabef
commit d2299c8379
5 changed files with 36 additions and 14 deletions

View file

@ -37,7 +37,7 @@ void bar_manager_init(struct bar_manager* bar_manager) {
bar_manager->topmost = false;
bar_manager->notch_width = 200;
bar_manager->notch_offset = 0;
bar_manager->active_adid = display_arrangement(display_active_display_id());
bar_manager->active_adid = display_active_display_adid();
bar_manager->might_need_clipping = false;
bar_manager->sticky = false;
@ -603,7 +603,7 @@ void bar_manager_begin(struct bar_manager* bar_manager) {
bar_manager->active_displays |= 1 << bar_manager->bars[i]->adid;
}
bar_manager->active_adid = display_arrangement(display_active_display_id());
bar_manager->active_adid = display_active_display_adid();
bar_manager->needs_ordering = true;
}
@ -763,7 +763,7 @@ void bar_manager_display_added(struct bar_manager* bar_manager, uint32_t did) {
}
void bar_manager_display_changed(struct bar_manager* bar_manager) {
bar_manager->active_adid = display_arrangement(display_active_display_id());
bar_manager->active_adid = display_active_display_adid();
bar_manager_freeze(bar_manager);
bar_manager_reset(bar_manager);
@ -978,7 +978,7 @@ void bar_manager_handle_space_change(struct bar_manager* bar_manager, bool force
}
void bar_manager_handle_display_change(struct bar_manager* bar_manager) {
bar_manager->active_adid = display_arrangement(display_active_display_id());
bar_manager->active_adid = display_active_display_adid();
struct env_vars env_vars;
env_vars_init(&env_vars);
char adid_str[3];

View file

@ -135,8 +135,7 @@ uint32_t display_main_display_id(void) {
}
static CFStringRef display_active_display_uuid(void) {
CFStringRef menubar = SLSCopyActiveMenuBarDisplayIdentifier(g_connection);
return menubar;
return SLSCopyActiveMenuBarDisplayIdentifier(g_connection);
}
uint32_t display_active_display_id(void) {
@ -192,6 +191,28 @@ uint32_t display_arrangement_display_id(int arrangement) {
return result;
}
uint32_t display_active_display_adid(void) {
CFStringRef uuid = display_active_display_uuid();
CFArrayRef displays = SLSCopyManagedDisplays(g_connection);
if (!displays) {
CFRelease(uuid);
return 0;
}
int result = 0;
int displays_count = CFArrayGetCount(displays);
for (int i = 0; i < displays_count; ++i) {
if (CFEqual(CFArrayGetValueAtIndex(displays, i), uuid)) {
result = i + 1;
break;
}
}
CFRelease(displays);
CFRelease(uuid);
return result;
}
bool display_menu_bar_visible(void) {
int status = 0;
SLSGetMenuBarAutohideEnabled(g_connection, &status);

View file

@ -30,18 +30,19 @@ extern CGError SLSSetMenuBarAutohideEnabled(int cid, bool enabled);
uint32_t display_main_display_id(void);
uint32_t display_active_display_id(void);
uint32_t display_active_display_adid(void);
uint32_t display_arrangement_display_id(int arrangement);
bool display_menu_bar_visible(void);
CGRect display_menu_bar_rect(uint32_t did);
uint32_t display_active_display_count(void);
uint32_t *display_active_display_list(uint32_t *count);
uint32_t* display_active_display_list(uint32_t* count);
bool display_begin(void);
bool display_end(void);
CFStringRef display_uuid(uint32_t did);
CGRect display_bounds(uint32_t did);
uint64_t display_space_id(uint32_t did);
uint64_t *display_space_list(uint32_t did, int *count);
uint64_t* display_space_list(uint32_t did, int* count);
int display_arrangement(uint32_t did);
void forced_brightness_event();

View file

@ -72,7 +72,7 @@ static void event_mouse_up(void* context) {
CGEventType type = CGEventGetType(context);
uint32_t mouse_button_code = CGEventGetIntegerValueField(context, kCGMouseEventButtonNumber);
uint32_t modifier_keys = CGEventGetFlags(context);
uint32_t adid = display_arrangement(display_active_display_id());
uint32_t adid = display_active_display_adid();
struct bar_item* bar_item = bar_manager_get_item_by_wid(&g_bar_manager,
wid,
@ -109,7 +109,7 @@ static void event_mouse_up(void* context) {
static void event_mouse_dragged(void* context) {
CGPoint point = CGEventGetLocation(context);
uint32_t wid = get_wid_from_cg_event(context);
uint32_t adid = display_arrangement(display_active_display_id());
uint32_t adid = display_active_display_adid();
struct bar_item* bar_item = bar_manager_get_item_by_wid(&g_bar_manager,
wid,
@ -160,7 +160,7 @@ static void event_mouse_entered(void* context) {
return;
}
uint32_t adid = display_arrangement(display_active_display_id());
uint32_t adid = display_active_display_adid();
struct bar_item* bar_item = bar_manager_get_item_by_wid(&g_bar_manager,
wid,
@ -175,7 +175,7 @@ static void event_mouse_entered(void* context) {
}
static void event_mouse_exited(void* context) {
uint32_t adid = display_arrangement(display_active_display_id());
uint32_t adid = display_active_display_adid();
uint32_t wid = get_wid_from_cg_event(context);
struct bar* bar,* bar_target;
@ -245,7 +245,7 @@ static void event_mouse_scrolled(void* context) {
int scroll_delta
= CGEventGetIntegerValueField(context,
kCGScrollWheelEventDeltaAxis1);
uint32_t adid = display_arrangement(display_active_display_id());
uint32_t adid = display_active_display_adid();
uint64_t event_time = clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW_APPROX);
if (g_scroll_info.timestamp + SCROLL_TIMEOUT > event_time) {

View file

@ -359,7 +359,7 @@ static bool handle_domain_bar(FILE *rsp, struct token domain, char *message) {
struct token state = get_token(&message);
uint32_t adid = 0;
if (token_equals(state, "current")) {
adid = display_arrangement(display_active_display_id());
adid = display_active_display_adid();
if (adid > 0 && adid <= g_bar_manager.bar_count)
needs_refresh = bar_manager_set_hidden(&g_bar_manager,