Skip to content

Commit

Permalink
remove proxy lookup table due to new proxy book keeping design (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Mar 2, 2024
1 parent a7b4ff7 commit fb4f55d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 76 deletions.
13 changes: 7 additions & 6 deletions src/border.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void border_create_window(struct border* border, int cid, CGRect frame) {
border->wid = window_create(cid,
frame,
g_settings.hidpi,
border->unmanaged);
border->is_proxy);

border->frame = frame;
border->needs_redraw = true;
Expand Down Expand Up @@ -41,7 +41,7 @@ static bool border_check_too_small(struct border* border, CGRect window_frame) {

static bool border_calculate_bounds(struct border* border, int cid, CGRect* frame) {
CGRect window_frame;
if (border->unmanaged) window_frame = border->target_bounds;
if (border->is_proxy) window_frame = border->target_bounds;
else SLSGetWindowBounds(cid, border->target_wid, &window_frame);
border->target_bounds = window_frame;

Expand Down Expand Up @@ -208,11 +208,12 @@ static void border_draw(struct border* border, CGRect frame) {

void border_destroy(struct border* border) {
border_destroy_window(border);
if (border->proxy) border_destroy(border->proxy);
free(border);
}

void border_move(struct border* border) {
if (border->disable_update) return;
if (border->proxy_wid) return;
int cid = SLSMainConnectionID();

CGRect window_frame;
Expand All @@ -231,7 +232,7 @@ void border_move(struct border* border) {
}

void border_update(struct border* border) {
if (border->disable_update) return;
if (border->proxy_wid) return;

int cid = SLSMainConnectionID();
uint64_t tags = window_tags(cid, border->target_wid);
Expand All @@ -241,7 +242,7 @@ void border_update(struct border* border) {

bool shown = false;
SLSWindowIsOrderedIn(cid, border->target_wid, &shown);
if (!shown) {
if (!shown && !border->is_proxy) {
border_hide(border);
return;
}
Expand Down Expand Up @@ -302,7 +303,7 @@ void border_hide(struct border* border) {
void border_unhide(struct border* border) {
int cid = SLSMainConnectionID();
if (border->too_small
|| border->disable_update
|| border->proxy_wid
|| (!border->sticky && !is_space_visible(cid, border->sid))) {
return;
}
Expand Down
6 changes: 4 additions & 2 deletions src/border.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ struct border {
bool focused;
bool needs_redraw;
bool too_small;
bool disable_update;
bool sticky;
bool unmanaged;

uint64_t sid;
uint32_t wid;
Expand All @@ -64,6 +62,10 @@ struct border {
CGRect target_bounds;
CGRect drawing_bounds;
CGContextRef context;

bool is_proxy;
uint32_t proxy_wid;
struct border* proxy;
};

void border_init(struct border* border);
Expand Down
8 changes: 4 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
pid_t g_pid;
mach_port_t g_server_port;
struct table g_windows;
struct table g_animation_proxies;
struct mach_server g_mach_server;
struct settings g_settings = { .active_window = { .stype = COLOR_STYLE_SOLID,
.color = 0xffe1e3e4 },
Expand Down Expand Up @@ -119,12 +118,14 @@ static void event_callback(CFMachPortRef port, void* message, CFIndex size, void
payload = *(struct payload*)data->descriptor.address;
if (payload.event == 1325) {
yabai_proxy_begin(&g_windows,
&g_animation_proxies,
SLSMainConnectionID(),
payload.proxy_wid,
payload.real_wid );
} else if (payload.event == 1326) {
yabai_proxy_end(&g_windows, &g_animation_proxies, payload.proxy_wid);
yabai_proxy_end(&g_windows,
SLSMainConnectionID(),
payload.proxy_wid,
payload.real_wid );
}
}
}
Expand Down Expand Up @@ -169,7 +170,6 @@ int main(int argc, char** argv) {

pid_for_task(mach_task_self(), &g_pid);
table_init(&g_windows, 1024, hash_windows, cmp_windows);
table_init(&g_animation_proxies, 1024, hash_windows, cmp_windows);

g_server_port = create_connection_server_port();

Expand Down
2 changes: 2 additions & 0 deletions src/misc/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extern CGError SLSGetWindowOwner(int cid, uint32_t wid, int* out_cid);
extern CGError SLSConnectionGetPID(int cid, pid_t *pid);
extern CGError SLSRequestNotificationsForWindows(int cid, uint32_t *window_list, int window_count);

extern CGError SLSNewConnection(int zero, int *cid);
extern CGError SLSReleaseConnection(int cid);
extern CGError SLSWindowIsOrderedIn(int cid, uint32_t wid, bool* shown);
extern CGError SLSGetWindowBounds(int cid, uint32_t wid, CGRect *frame);
extern CGError CGSNewRegionWithRect(CGRect *rect, CFTypeRef *outRegion);
Expand Down
107 changes: 44 additions & 63 deletions src/misc/yabai.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static CVReturn frame_callback(CVDisplayLinkRef display_link, const CVTimeStamp*
CVDisplayLinkStop(display_link);
CVDisplayLinkRelease(display_link);
free(payload);
SLSReleaseConnection(payload->cid);
return kCVReturnSuccess;
}

Expand All @@ -48,87 +49,67 @@ static inline void border_track_transform(struct track_transform_payload* payloa
}


static inline bool yabai_proxy_exists(struct table* proxies, uint32_t wid) {
return table_find(proxies, &wid);
}

static inline void yabai_proxy_begin(struct table* windows, struct table* proxies, int cid, uint32_t wid, uint32_t real_wid) {
static inline void yabai_proxy_begin(struct table* windows, int cid, uint32_t wid, uint32_t real_wid) {
if (!real_wid) return;

uint32_t current_proxy_wid = (intptr_t)table_find(proxies, &real_wid);
table_remove(proxies, &real_wid);
table_add(proxies, &real_wid, (void*)(intptr_t)wid);

struct border* border = table_find(windows, &real_wid);
struct border* proxy = table_find(proxies, &current_proxy_wid);
table_remove(proxies, &current_proxy_wid);

if (border) {
border->disable_update = true;
if (!proxy) {
proxy = malloc(sizeof(struct border));
border_init(proxy);
proxy->target_bounds = border->target_bounds;
proxy->focused = border->focused;
proxy->target_wid = real_wid;
proxy->sid = border->sid;
proxy->unmanaged = true;
border_update(proxy);
proxy->disable_update = true;
border->proxy_wid = wid;
if (!border->proxy) {
border->proxy = malloc(sizeof(struct border));
border_init(border->proxy);
border->proxy->is_proxy = true;
border->proxy->target_bounds = border->target_bounds;
border->proxy->focused = border->focused;
border->proxy->target_wid = border->target_wid;
border->proxy->sid = border->sid;

border_update(border->proxy);

CFTypeRef transaction = SLSTransactionCreate(cid);
SLSTransactionSetWindowAlpha(transaction, border->wid, 0.f);
SLSTransactionSetWindowAlpha(transaction, border->proxy->wid, 1.f);
SLSTransactionCommit(transaction, 1);
CFRelease(transaction);
}
table_add(proxies, &wid, (void*)proxy);

CFTypeRef transaction = SLSTransactionCreate(cid);
SLSTransactionSetWindowAlpha(transaction, border->wid, 0.f);
SLSTransactionSetWindowAlpha(transaction, proxy->wid, 1.f);
SLSTransactionCommit(transaction, 1);
CFRelease(transaction);

struct track_transform_payload* payload
= malloc(sizeof(struct track_transform_payload));

CGRect proxy_frame;
SLSGetWindowBounds(cid, wid, &proxy_frame);

payload->border_wid = proxy->wid;
payload->target_wid = wid;
payload->cid = cid;
payload->border_wid = border->proxy->wid;
payload->target_wid = border->proxy_wid;
SLSNewConnection(0, &payload->cid);

payload->initial_transform = CGAffineTransformIdentity;
payload->initial_transform.a = border->target_bounds.size.width
/ proxy_frame.size.width;
payload->initial_transform.d = border->target_bounds.size.height
/ proxy_frame.size.height;
payload->initial_transform.tx = 0.5*(border->frame.size.width
- border->target_bounds.size.width);
payload->initial_transform.ty = 0.5*(border->frame.size.height
- border->target_bounds.size.height);
payload->initial_transform.a = border->proxy->target_bounds.size.width
/ proxy_frame.size.width;
payload->initial_transform.d = border->proxy->target_bounds.size.height
/ proxy_frame.size.height;
payload->initial_transform.tx = 0.5*(border->proxy->frame.size.width
- border->proxy->target_bounds.size.width);
payload->initial_transform.ty = 0.5*(border->proxy->frame.size.height
- border->proxy->target_bounds.size.height);

border_track_transform(payload);
} else if (proxy) border_destroy(proxy);
}
}

static inline void yabai_proxy_end(struct table* windows, struct table* proxies, uint32_t wid) {
struct border* proxy = (struct border*)table_find(proxies, &wid);
if (proxy) {
uint32_t real_wid = proxy->target_wid;
table_remove(proxies, &wid);

uint32_t current_proxy_wid = (intptr_t)table_find(proxies, &real_wid);
if (wid == current_proxy_wid) {
table_remove(proxies, &real_wid);
struct border* border = table_find(windows, &real_wid);
if (border) {
border->disable_update = false;
border_update(border);
int cid = SLSMainConnectionID();
CFTypeRef transaction = SLSTransactionCreate(cid);
SLSTransactionSetWindowAlpha(transaction, proxy->wid, 0.f);
SLSTransactionSetWindowAlpha(transaction, border->wid, 1.f);
SLSTransactionCommit(transaction, 1);
CFRelease(transaction);
}
}
static inline void yabai_proxy_end(struct table* windows, int cid, uint32_t wid, uint32_t real_wid) {
struct border* border = (struct border*)table_find(windows, &real_wid);
if (border && border->proxy && border->proxy_wid == wid) {
struct border* proxy = border->proxy;
border->proxy_wid = 0;
border->proxy = NULL;
border_update(border);

CFTypeRef transaction = SLSTransactionCreate(cid);
SLSTransactionSetWindowAlpha(transaction, proxy->wid, 0.f);
SLSTransactionSetWindowAlpha(transaction, border->wid, 1.f);
SLSTransactionCommit(transaction, 1);
CFRelease(transaction);
border_destroy(proxy);
}
}
1 change: 0 additions & 1 deletion src/windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <libproc.h>

extern pid_t g_pid;
extern struct table g_animation_proxies;
extern struct settings g_settings;

static bool window_in_list(struct table* list, char* app_name) {
Expand Down

0 comments on commit fb4f55d

Please # to comment.