From 6c42aced3d6bb236a445a33b62d4331974e676dd Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Mon, 23 Jan 2023 07:15:55 +0100 Subject: [PATCH] Support flicker free boot Fixes #724 --- docs/labwc-config.5.scd | 7 +++++++ docs/rc.xml.all | 1 + include/config/rcxml.h | 1 + src/config/rcxml.c | 2 ++ src/output.c | 22 +++++++++++++++++----- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index 070e4c04..8407cc7c 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -70,6 +70,13 @@ The rest of this man page describes configuration options. ** [yes|no] Enable adaptive sync. Default is no. +** [yes|no] + Try to re-use the existing output mode (resolution / refresh rate). + This may prevent unnecessary screenblank delays when starting labwc + (also known as flicker free boot). If the existing output mode can not + be used with labwc the preferred mode of the monitor is used instead. + Default is no. + ** [yes|no] Preview the contents of the selected window when cycling between windows. Default is no. diff --git a/docs/rc.xml.all b/docs/rc.xml.all index 2c86fb7d..d829f2a1 100644 --- a/docs/rc.xml.all +++ b/docs/rc.xml.all @@ -11,6 +11,7 @@ server 0 no + no no yes diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 975e6754..56586b25 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -18,6 +18,7 @@ struct rcxml { bool xdg_shell_server_side_deco; int gap; bool adaptive_sync; + bool reuse_output_mode; /* focus */ bool focus_follow_mouse; diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 068e6d3c..4d3bf6d9 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -400,6 +400,8 @@ entry(xmlNode *node, char *nodename, char *content) rc.gap = atoi(content); } else if (!strcasecmp(nodename, "adaptiveSync.core")) { rc.adaptive_sync = get_bool(content); + } else if (!strcasecmp(nodename, "reuseOutputMode.core")) { + rc.reuse_output_mode = get_bool(content); } else if (!strcmp(nodename, "name.theme")) { rc.theme_name = xstrdup(content); } else if (!strcmp(nodename, "cornerradius.theme")) { diff --git a/src/output.c b/src/output.c index 991a1653..0ae6f684 100644 --- a/src/output.c +++ b/src/output.c @@ -66,6 +66,12 @@ output_destroy_notify(struct wl_listener *listener, void *data) static void do_output_layout_change(struct server *server); +static bool +can_reuse_mode(struct wlr_output *wlr_output) +{ + return wlr_output->current_mode && wlr_output_test(wlr_output); +} + static void new_output_notify(struct wl_listener *listener, void *data) { @@ -109,11 +115,17 @@ new_output_notify(struct wl_listener *listener, void *data) wlr_log(WLR_DEBUG, "enable output"); wlr_output_enable(wlr_output, true); - /* The mode is a tuple of (width, height, refresh rate). */ - wlr_log(WLR_DEBUG, "set preferred mode"); - struct wlr_output_mode *preferred_mode = - wlr_output_preferred_mode(wlr_output); - wlr_output_set_mode(wlr_output, preferred_mode); + /* + * Try to re-use the existing mode if configured to do so. + * Failing that, try to set the preferred mode. + */ + struct wlr_output_mode *preferred_mode = NULL; + if (!rc.reuse_output_mode || !can_reuse_mode(wlr_output)) { + wlr_log(WLR_DEBUG, "set preferred mode"); + /* The mode is a tuple of (width, height, refresh rate). */ + preferred_mode = wlr_output_preferred_mode(wlr_output); + wlr_output_set_mode(wlr_output, preferred_mode); + } /* * Sometimes the preferred mode is not available due to hardware