Skip to content

Commit

Permalink
only create and commit SLSTransaction on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Feb 4, 2023
1 parent c0ff05f commit 7835f67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ static void *event_loop_run(void *context) {
while (event_loop->is_running) {
struct event *event = queue_pop(queue);
if (event) {
windows_freeze();
uint32_t result = event_handler[event->type](event->context);
windows_unfreeze();
if (event->info) *event->info = (result << 0x1) | EVENT_PROCESSED;
Expand Down
16 changes: 12 additions & 4 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,19 @@ void window_clear(struct window* window) {
}

void windows_freeze() {
if (g_transaction) return;

SLSDisableUpdate(g_connection);
g_transaction = SLSTransactionCreate(g_connection);
}

void windows_unfreeze() {
SLSTransactionCommit(g_transaction, 0);
CFRelease(g_transaction);
g_transaction = NULL;
SLSReenableUpdate(g_connection);
if (g_transaction) {
SLSTransactionCommit(g_transaction, 0);
CFRelease(g_transaction);
g_transaction = NULL;
SLSReenableUpdate(g_connection);
}
}

void window_set_frame(struct window* window, CGRect frame) {
Expand All @@ -109,6 +113,7 @@ void window_move(struct window* window, CGPoint point) {

if (__builtin_available(macOS 12.0, *)) {
// Monterey and later
windows_freeze();
SLSTransactionMoveWindowWithGroup(g_transaction, window->id, point);
} else {
// Big Sur and Previous
Expand All @@ -126,6 +131,7 @@ void window_move(struct window* window, CGPoint point) {
}

bool window_apply_frame(struct window* window) {
windows_freeze();
if (window->needs_resize) {
CFTypeRef frame_region = window_create_region(window, window->frame);

Expand Down Expand Up @@ -185,10 +191,12 @@ void window_close(struct window* window) {
}

void window_set_level(struct window* window, uint32_t level) {
windows_freeze();
SLSTransactionSetWindowLevel(g_transaction, window->id, level);
}

void window_order(struct window* window, struct window* parent, int mode) {
windows_freeze();
if (parent) {
window->parent = parent;
if (mode != W_OUT) window->order_mode = mode;
Expand Down

0 comments on commit 7835f67

Please sign in to comment.