Skip to content

Commit

Permalink
lookup adid directly from active display uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Jan 15, 2024
1 parent 6ff8ffa commit d2299c8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/bar_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
25 changes: 23 additions & 2 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d2299c8

Please sign in to comment.