From 08045d7843f38a8b6a29ca65655a18f122cd7104 Mon Sep 17 00:00:00 2001 From: Ph42oN Date: Sat, 30 Dec 2023 17:35:41 +0200 Subject: [PATCH] config: add adaptive sync fullscreen option --- include/config/rcxml.h | 8 +++++++- include/labwc.h | 1 + src/config/rcxml.c | 17 ++++++++++++++++- src/output.c | 33 +++++++++++++++++++++++---------- src/view.c | 16 ++++++++++++++++ 5 files changed, 63 insertions(+), 12 deletions(-) diff --git a/include/config/rcxml.h b/include/config/rcxml.h index acb34260..2fa7463a 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -28,6 +28,12 @@ enum view_placement_policy { LAB_PLACE_AUTOMATIC }; +enum adaptive_sync_mode { + LAB_ADAPTIVE_SYNC_DISABLED, + LAB_ADAPTIVE_SYNC_ENABLED, + LAB_ADAPTIVE_SYNC_FULLSCREEN, +}; + struct usable_area_override { struct border margin; char *output; @@ -46,7 +52,7 @@ struct rcxml { /* core */ bool xdg_shell_server_side_deco; int gap; - bool adaptive_sync; + enum adaptive_sync_mode adaptive_sync; bool reuse_output_mode; enum view_placement_policy placement_policy; diff --git a/include/labwc.h b/include/labwc.h index da922422..88dfbec5 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -477,6 +477,7 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener, void *data); void output_add_virtual(struct server *server, const char *output_name); void output_remove_virtual(struct server *server, const char *output_name); +void output_enable_adaptive_sync(struct wlr_output *output, bool enabled); void server_init(struct server *server); void server_start(struct server *server); diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 4f3f5a54..f1a9c110 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -610,6 +610,21 @@ enum_font_place(const char *place) return FONT_PLACE_UNKNOWN; } +static void +set_adaptive_sync_mode(const char *str, enum adaptive_sync_mode *variable) +{ + if (!strcasecmp(str, "fullscreen")) { + *variable = LAB_ADAPTIVE_SYNC_FULLSCREEN; + } else { + int ret = parse_bool(str, -1); + if (ret == 1) { + *variable = LAB_ADAPTIVE_SYNC_ENABLED; + } else { + *variable = LAB_ADAPTIVE_SYNC_DISABLED; + } + } +} + static void entry(xmlNode *node, char *nodename, char *content) { @@ -711,7 +726,7 @@ entry(xmlNode *node, char *nodename, char *content) } else if (!strcmp(nodename, "gap.core")) { rc.gap = atoi(content); } else if (!strcasecmp(nodename, "adaptiveSync.core")) { - set_bool(content, &rc.adaptive_sync); + set_adaptive_sync_mode(content, &rc.adaptive_sync); } else if (!strcasecmp(nodename, "reuseOutputMode.core")) { set_bool(content, &rc.reuse_output_mode); } else if (!strcmp(nodename, "policy.placement")) { diff --git a/src/output.c b/src/output.c index 36d23128..7f2f5520 100644 --- a/src/output.c +++ b/src/output.c @@ -249,15 +249,8 @@ new_output_notify(struct wl_listener *listener, void *data) } } - if (rc.adaptive_sync) { - wlr_output_enable_adaptive_sync(wlr_output, true); - if (!wlr_output_test(wlr_output)) { - wlr_output_enable_adaptive_sync(wlr_output, false); - wlr_log(WLR_DEBUG, - "failed to enable adaptive sync for output %s", wlr_output->name); - } else { - wlr_log(WLR_INFO, "adaptive sync enabled for output %s", wlr_output->name); - } + if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_ENABLED) { + output_enable_adaptive_sync(wlr_output, true); } wlr_output_commit(wlr_output); @@ -415,7 +408,10 @@ output_config_apply(struct server *server, } wlr_output_set_scale(o, head->state.scale); wlr_output_set_transform(o, head->state.transform); - wlr_output_enable_adaptive_sync(o, head->state.adaptive_sync_enabled); + if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_ENABLED) { + output_enable_adaptive_sync(o, + head->state.adaptive_sync_enabled); + } } if (!wlr_output_commit(o)) { wlr_log(WLR_ERROR, "Output config commit failed"); @@ -810,3 +806,20 @@ output_remove_virtual(struct server *server, const char *output_name) } } } + +void +output_enable_adaptive_sync(struct wlr_output *output, bool enabled) +{ + if (output->pending.adaptive_sync_enabled == enabled) { + return; + } + wlr_output_enable_adaptive_sync(output, enabled); + if (!wlr_output_test(output)) { + wlr_output_enable_adaptive_sync(output, false); + wlr_log(WLR_DEBUG, + "failed to enable adaptive sync for output %s", output->name); + } else { + wlr_log(WLR_INFO, "adaptive sync %sabled for output %s", + enabled ? "en" : "dis", output->name); + } +} diff --git a/src/view.c b/src/view.c index d2b3bb50..f0562f9f 100644 --- a/src/view.c +++ b/src/view.c @@ -262,6 +262,17 @@ view_discover_output(struct view *view) view->current.y + view->current.height / 2); } +static void +set_adaptive_sync_fullscreen(struct view *view) +{ + if (rc.adaptive_sync != LAB_ADAPTIVE_SYNC_FULLSCREEN) { + return; + } + /* Enable adaptive sync if view is fullscreen */ + output_enable_adaptive_sync(view->output->wlr_output, view->fullscreen); + wlr_output_commit(view->output->wlr_output); +} + void view_set_activated(struct view *view, bool activated) { @@ -285,6 +296,7 @@ view_set_activated(struct view *view, bool activated) keyboard_update_layout(&view->server->seat, view->keyboard_layout); } } + set_adaptive_sync_fullscreen(view); } void @@ -1186,6 +1198,7 @@ view_set_fullscreen(struct view *view, bool fullscreen) } else { view_apply_special_geometry(view); } + set_adaptive_sync_fullscreen(view); } void @@ -1853,6 +1866,9 @@ view_destroy(struct view *view) if (view->fullscreen && view->output) { view->fullscreen = false; desktop_update_top_layer_visiblity(server); + if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_FULLSCREEN) { + wlr_output_enable_adaptive_sync(view->output->wlr_output, false); + } } /* If we spawned a window menu, close it */ -- 2.52.0