This commit is contained in:
FelixKratz 2021-09-03 12:18:09 +02:00
parent aae17c908a
commit 5c500af5e9
10 changed files with 122 additions and 172 deletions

View file

@ -241,8 +241,8 @@ void bar_create_frame(struct bar *bar, CFTypeRef *frame_region) {
if (0 == strcmp(g_bar_manager.position, BAR_POSITION_BOTTOM)) {
origin.y = CGRectGetMaxY(bounds) - g_bar_manager.height - 2*g_bar_manager.y_offset;
} else if (display_manager_menu_bar_visible()) {
CGRect menu = display_manager_menu_bar_rect(bar->did);
} else if (display_menu_bar_visible()) {
CGRect menu = display_menu_bar_rect(bar->did);
origin.y += menu.size.height;
}

View file

@ -143,18 +143,18 @@ void bar_manager_script_update(struct bar_manager* bar_manager, bool forced) {
void bar_manager_begin(struct bar_manager *bar_manager) {
if (strcmp(bar_manager->display, BAR_DISPLAY_MAIN_ONLY) == 0) {
uint32_t did = display_manager_main_display_id();
uint32_t did = display_main_display_id();
bar_manager->bar_count = 1;
bar_manager->bars = (struct bar **) malloc(sizeof(struct bar *) * bar_manager->bar_count);
memset(bar_manager->bars,0, sizeof(struct bar*) * bar_manager->bar_count);
bar_manager->bars[0] = bar_create(did);
}
else if (strcmp(bar_manager->display, BAR_DISPLAY_ALL) == 0) {
bar_manager->bar_count = display_manager_active_display_count();
bar_manager->bar_count = display_active_display_count();
bar_manager->bars = (struct bar **) malloc(sizeof(struct bar *) * bar_manager->bar_count);
memset(bar_manager->bars,0, sizeof(struct bar*) * bar_manager->bar_count);
for (uint32_t index=1; index <= bar_manager->bar_count; index++) {
uint32_t did = display_manager_arrangement_display_id(index);
uint32_t did = display_arrangement_display_id(index);
bar_manager->bars[index - 1] = bar_create(did);
}
}

View file

@ -1,9 +1,9 @@
#include "display.h"
extern struct event_loop g_event_loop;
extern struct bar g_bar;
extern int g_connection;
static DISPLAY_EVENT_HANDLER(display_handler) {
if (flags & kCGDisplayAddFlag) {
struct event *event = event_create(&g_event_loop, DISPLAY_ADDED, (void *)(intptr_t) did);
@ -96,3 +96,88 @@ int display_arrangement(uint32_t did) {
CFRelease(uuid);
return result;
}
uint32_t display_main_display_id(void) {
return CGMainDisplayID();
}
CFStringRef display_active_display_uuid(void) {
return SLSCopyActiveMenuBarDisplayIdentifier(g_connection);
}
uint32_t display_active_display_id(void) {
uint32_t result = 0;
CFStringRef uuid = display_active_display_uuid();
CFUUIDRef uuid_ref = CFUUIDCreateFromString(NULL, uuid);
result = CGDisplayGetDisplayIDFromUUID(uuid_ref);
CFRelease(uuid_ref);
CFRelease(uuid);
return result;
}
CFStringRef display_arrangement_display_uuid(int arrangement) {
CFStringRef result = NULL;
CFArrayRef displays = SLSCopyManagedDisplays(g_connection);
int displays_count = CFArrayGetCount(displays);
for (int i = 0; i < displays_count; ++i) {
if ((i+1) != arrangement) continue;
result = CFRetain(CFArrayGetValueAtIndex(displays, i));
break;
}
CFRelease(displays);
return result;
}
uint32_t display_arrangement_display_id(int arrangement) {
uint32_t result = 0;
CFArrayRef displays = SLSCopyManagedDisplays(g_connection);
int displays_count = CFArrayGetCount(displays);
for (int i = 0; i < displays_count; ++i) {
if ((i+1) != arrangement) continue;
CFUUIDRef uuid_ref = CFUUIDCreateFromString(NULL, CFArrayGetValueAtIndex(displays, i));
result = CGDisplayGetDisplayIDFromUUID(uuid_ref);
CFRelease(uuid_ref);
break;
}
CFRelease(displays);
return result;
}
bool display_menu_bar_visible(void) {
int status = 0;
SLSGetMenuBarAutohideEnabled(g_connection, &status);
return !status;
}
CGRect display_menu_bar_rect(uint32_t did) {
CGRect bounds = {};
SLSGetRevealedMenuBarBounds(&bounds, g_connection, display_space_id(did));
return bounds;
}
uint32_t display_active_display_count(void) {
uint32_t count;
CGGetActiveDisplayList(0, NULL, &count);
return count;
}
uint32_t *display_active_display_list(uint32_t *count) {
int display_count = display_active_display_count();
uint32_t *result = malloc(sizeof(uint32_t) * display_count);
CGGetActiveDisplayList(display_count, result, count);
return result;
}
bool display_begin() {
return CGDisplayRegisterReconfigurationCallback(display_handler, NULL) == kCGErrorSuccess;
}
bool display_end() {
return CGDisplayRemoveReconfigurationCallback(display_handler, NULL) == kCGErrorSuccess;
}

View file

@ -8,6 +8,22 @@ extern CFUUIDRef CGDisplayCreateUUIDFromDisplayID(uint32_t did);
extern CFArrayRef SLSCopyManagedDisplays(int cid);
extern uint64_t SLSManagedDisplayGetCurrentSpace(int cid, CFStringRef uuid);
extern CFStringRef SLSCopyBestManagedDisplayForRect(int cid, CGRect rect);
extern CGError SLSGetCurrentCursorLocation(int cid, CGPoint *point);
extern CFStringRef SLSCopyActiveMenuBarDisplayIdentifier(int cid);
extern CGError SLSGetMenuBarAutohideEnabled(int cid, int *enabled);
extern CGError SLSGetRevealedMenuBarBounds(CGRect *rect, int cid, uint64_t sid);
extern CFStringRef SLSCopyBestManagedDisplayForPoint(int cid, CGPoint point);
uint32_t display_main_display_id(void);
uint32_t display_active_display_id(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);
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);

View file

@ -1,19 +1,18 @@
#include "display_manager.h"
extern struct window_manager g_window_manager;
extern int g_connection;
uint32_t display_manager_main_display_id(void) {
uint32_t display_main_display_id(void) {
return CGMainDisplayID();
}
CFStringRef display_manager_active_display_uuid(void) {
CFStringRef display_active_display_uuid(void) {
return SLSCopyActiveMenuBarDisplayIdentifier(g_connection);
}
uint32_t display_manager_active_display_id(void) {
uint32_t display_active_display_id(void) {
uint32_t result = 0;
CFStringRef uuid = display_manager_active_display_uuid();
CFStringRef uuid = display_active_display_uuid();
CFUUIDRef uuid_ref = CFUUIDCreateFromString(NULL, uuid);
result = CGDisplayGetDisplayIDFromUUID(uuid_ref);
CFRelease(uuid_ref);
@ -21,40 +20,7 @@ uint32_t display_manager_active_display_id(void) {
return result;
}
CFStringRef display_manager_dock_display_uuid(void) {
CGRect dock = display_manager_dock_rect();
return SLSCopyBestManagedDisplayForRect(g_connection, dock);
}
uint32_t display_manager_dock_display_id(void) {
CFStringRef uuid = display_manager_dock_display_uuid();
if (!uuid) return 0;
CFUUIDRef uuid_ref = CFUUIDCreateFromString(NULL, uuid);
uint32_t result = CGDisplayGetDisplayIDFromUUID(uuid_ref);
CFRelease(uuid_ref);
CFRelease(uuid);
return result;
}
CFStringRef display_manager_cursor_display_uuid(void) {
CGPoint cursor;
SLSGetCurrentCursorLocation(g_connection, &cursor);
return SLSCopyBestManagedDisplayForPoint(g_connection, cursor);
}
uint32_t display_manager_cursor_display_id(void) {
CFStringRef uuid = display_manager_cursor_display_uuid();
if (!uuid) return 0;
CFUUIDRef uuid_ref = CFUUIDCreateFromString(NULL, uuid);
uint32_t result = CGDisplayGetDisplayIDFromUUID(uuid_ref);
CFRelease(uuid_ref);
CFRelease(uuid);
return result;
}
CFStringRef display_manager_arrangement_display_uuid(int arrangement) {
CFStringRef display_arrangement_display_uuid(int arrangement) {
CFStringRef result = NULL;
CFArrayRef displays = SLSCopyManagedDisplays(g_connection);
@ -69,7 +35,7 @@ CFStringRef display_manager_arrangement_display_uuid(int arrangement) {
return result;
}
uint32_t display_manager_arrangement_display_id(int arrangement) {
uint32_t display_arrangement_display_id(int arrangement) {
uint32_t result = 0;
CFArrayRef displays = SLSCopyManagedDisplays(g_connection);
@ -86,80 +52,35 @@ uint32_t display_manager_arrangement_display_id(int arrangement) {
return result;
}
uint32_t display_manager_first_display_id(void) {
return display_manager_arrangement_display_id(1);
}
uint32_t display_manager_last_display_id(void) {
int arrangement = display_manager_active_display_count();
return display_manager_arrangement_display_id(arrangement);
}
bool display_manager_menu_bar_visible(void) {
bool display_menu_bar_visible(void) {
int status = 0;
SLSGetMenuBarAutohideEnabled(g_connection, &status);
return !status;
}
CGRect display_manager_menu_bar_rect(uint32_t did) {
CGRect display_menu_bar_rect(uint32_t did) {
CGRect bounds = {};
SLSGetRevealedMenuBarBounds(&bounds, g_connection, display_space_id(did));
return bounds;
}
bool display_manager_dock_hidden(void) {
return CoreDockGetAutoHideEnabled();
}
int display_manager_dock_orientation(void) {
int pinning = 0;
int orientation = 0;
CoreDockGetOrientationAndPinning(&orientation, &pinning);
return orientation;
}
CGRect display_manager_dock_rect(void) {
int reason = 0;
CGRect bounds = {};
SLSGetDockRectWithReason(g_connection, &bounds, &reason);
return bounds;
}
bool display_manager_active_display_is_animating(void) {
CFStringRef uuid = display_manager_active_display_uuid();
bool result = SLSManagedDisplayIsAnimating(g_connection, uuid);
CFRelease(uuid);
return result;
}
bool display_manager_display_is_animating(uint32_t did) {
CFStringRef uuid = display_uuid(did);
if (!uuid) return false;
bool result = SLSManagedDisplayIsAnimating(g_connection, uuid);
CFRelease(uuid);
return result;
}
uint32_t display_manager_active_display_count(void) {
uint32_t display_active_display_count(void) {
uint32_t count;
CGGetActiveDisplayList(0, NULL, &count);
return count;
}
uint32_t *display_manager_active_display_list(uint32_t *count) {
int display_count = display_manager_active_display_count();
uint32_t *display_active_display_list(uint32_t *count) {
int display_count = display_active_display_count();
uint32_t *result = malloc(sizeof(uint32_t) * display_count);
CGGetActiveDisplayList(display_count, result, count);
return result;
}
bool display_manager_begin(struct display_manager *dm) {
dm->current_display_id = display_manager_active_display_id();
dm->last_display_id = dm->current_display_id;
bool display_begin() {
return CGDisplayRegisterReconfigurationCallback(display_handler, NULL) == kCGErrorSuccess;
}
bool display_manager_end(void) {
bool display_end() {
return CGDisplayRemoveReconfigurationCallback(display_handler, NULL) == kCGErrorSuccess;
}

View file

@ -1,50 +0,0 @@
#ifndef DISPLAY_MANAGER_H
#define DISPLAY_MANAGER_H
extern CFStringRef SLSCopyBestManagedDisplayForRect(int cid, CGRect rect);
extern CGError SLSGetCurrentCursorLocation(int cid, CGPoint *point);
extern CFStringRef SLSCopyActiveMenuBarDisplayIdentifier(int cid);
extern CFStringRef SLSCopyBestManagedDisplayForPoint(int cid, CGPoint point);
extern bool SLSManagedDisplayIsAnimating(int cid, CFStringRef uuid);
extern CGError SLSGetMenuBarAutohideEnabled(int cid, int *enabled);
extern CGError SLSGetRevealedMenuBarBounds(CGRect *rect, int cid, uint64_t sid);
extern CGError SLSGetDockRectWithReason(int cid, CGRect *rect, int *reason);
extern Boolean CoreDockGetAutoHideEnabled(void);
extern void CoreDockGetOrientationAndPinning(int *orientation, int *pinning);
#define DOCK_ORIENTATION_BOTTOM 2
#define DOCK_ORIENTATION_LEFT 3
#define DOCK_ORIENTATION_RIGHT 4
struct display_manager {
uint32_t current_display_id;
uint32_t last_display_id;
};
uint32_t display_manager_main_display_id(void);
CFStringRef display_manager_active_display_uuid(void);
uint32_t display_manager_active_display_id(void);
CFStringRef display_manager_dock_display_uuid(void);
uint32_t display_manager_dock_display_id(void);
CFStringRef display_manager_cursor_display_uuid(void);
uint32_t display_manager_cursor_display_id(void);
CFStringRef display_manager_arrangement_display_uuid(int arrangement);
uint32_t display_manager_arrangement_display_id(int arrangement);
uint32_t display_manager_prev_display_id(uint32_t did);
uint32_t display_manager_next_display_id(uint32_t did);
uint32_t display_manager_first_display_id(void);
uint32_t display_manager_last_display_id(void);
bool display_manager_menu_bar_visible(void);
CGRect display_manager_menu_bar_rect(uint32_t did);
bool display_manager_dock_hidden(void);
int display_manager_dock_orientation(void);
CGRect display_manager_dock_rect(void);
bool display_manager_active_display_is_animating(void);
bool display_manager_display_is_animating(uint32_t did);
uint32_t display_manager_active_display_count(void);
uint32_t *display_manager_active_display_list(uint32_t *count);
//void display_manager_focus_display(uint32_t did);
bool display_manager_begin(struct display_manager *dm);
bool display_manager_end(void);
#endif

View file

@ -1,10 +1,7 @@
#include "event.h"
extern struct event_loop g_event_loop;
extern struct process_manager g_process_manager;
extern struct display_manager g_display_manager;
extern struct bar_manager g_bar_manager;
extern struct window_manager g_window_manager;
extern int g_connection;
enum event_type event_type_from_string(const char *str) {
@ -52,38 +49,26 @@ static EVENT_CALLBACK(EVENT_HANDLER_SPACE_CHANGED) {
}
static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_CHANGED) {
g_display_manager.last_display_id = g_display_manager.current_display_id;
g_display_manager.current_display_id = display_manager_active_display_id();
debug("%s: %d\n", __FUNCTION__, g_display_manager.current_display_id);
bar_manager_handle_display_change(&g_bar_manager);
bar_manager_refresh(&g_bar_manager);
return EVENT_SUCCESS;
}
static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_ADDED) {
uint32_t did = (uint32_t)(intptr_t) context;
debug("%s: %d\n", __FUNCTION__, did);
bar_manager_display_changed(&g_bar_manager);
return EVENT_SUCCESS;
}
static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_REMOVED) {
uint32_t did = (uint32_t)(intptr_t) context;
debug("%s: %d\n", __FUNCTION__, did);
bar_manager_display_changed(&g_bar_manager);
return EVENT_SUCCESS;
}
static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_MOVED) {
uint32_t did = (uint32_t)(intptr_t) context;
debug("%s: %d\n", __FUNCTION__, did);
bar_manager_display_changed(&g_bar_manager);
return EVENT_SUCCESS;
}
static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_RESIZED) {
uint32_t did = (uint32_t)(intptr_t) context;
debug("%s: %d\n", __FUNCTION__, did);
bar_manager_display_changed(&g_bar_manager);
return EVENT_SUCCESS;
}
@ -133,7 +118,7 @@ out:
static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) {
CGPoint point = CGEventGetLocation(context);
uint32_t sid = mission_control_index(display_space_id(display_manager_active_display_id()));
uint32_t sid = mission_control_index(display_space_id(display_active_display_id()));
debug("EVENT_HANDLER_MOUSE_UP: S#%d (x: %.0f, y: %.0f) -> ", sid, point.x, point.y);
struct bar_item* bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, sid);
debug("item: %s\n", bar_item ? bar_item->name : "NULL");

View file

@ -36,7 +36,6 @@
#include "workspace.h"
#include "message.h"
#include "display.h"
#include "display_manager.h"
#include "bar.h"
#include "graph_data.h"
#include "bar_item.h"
@ -49,7 +48,6 @@
#include "workspace.m"
#include "message.c"
#include "display.c"
#include "display_manager.c"
#include "bar.c"
#include "graph_data.c"
#include "bar_item.c"

View file

@ -3,10 +3,6 @@
#include "bar_manager.h"
extern struct event_loop g_event_loop;
extern struct display_manager g_display_manager;
extern struct space_manager g_space_manager;
extern struct window_manager g_window_manager;
extern struct mouse_state g_mouse_state;
extern struct bar_manager g_bar_manager;
extern bool g_verbose;

View file

@ -23,7 +23,6 @@ typedef CONNECTION_CALLBACK(connection_callback);
struct event_loop g_event_loop;
void *g_workspace_context;
struct display_manager g_display_manager;
struct daemon g_daemon;
struct bar_manager g_bar_manager;
int g_connection;
@ -234,7 +233,7 @@ int main(int argc, char **argv) {
event_loop_begin(&g_event_loop);
mouse_begin();
display_manager_begin(&g_display_manager);
display_begin();
workspace_event_handler_begin(&g_workspace_context);
bar_manager_begin(&g_bar_manager);