only create and commit SLSTransaction on demand

This commit is contained in:
Felix Kratz 2023-02-04 15:15:48 +01:00
parent c0ff05f056
commit 7835f67c31
2 changed files with 12 additions and 5 deletions

View file

@ -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;

View file

@ -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) {
@ -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
@ -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);
@ -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;