From 8b7e953a25cfb9446e924a2061c864c5b5f6f8eb Mon Sep 17 00:00:00 2001 From: Ph42oN <59069994+Ph42oN@users.noreply.github.com> Date: Thu, 4 Jan 2024 03:52:58 +0200 Subject: [PATCH] Zonai master (#1) * simplify tearing implementation --------- Co-authored-by: Andrew J. Hesford --- docs/labwc-config.5.scd | 6 +++--- include/config/rcxml.h | 2 +- include/labwc.h | 2 -- src/output.c | 44 +++++++++++++++++++++++++++++++++-------- src/tearing.c | 30 ---------------------------- src/view.c | 2 -- 6 files changed, 40 insertions(+), 46 deletions(-) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index 81c2784f..d1e052f6 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -133,10 +133,10 @@ this is for compatibility with Openbox. Allow tearing to reduce input lag. Default is no. This open requires setting the environment variable WLR_DRM_NO_ATOMIC=1. - *yes* allow tearing if an open window requests it. + *yes* allow tearing if the active window requests it. - *fullscreen* allow tearing if an open window requests it, or if any - window is in fullscreen mode. + *fullscreen* allow tearing if the active window requests it or is in + fullscreen mode. *always* allow tearing regardless of window status. diff --git a/include/config/rcxml.h b/include/config/rcxml.h index bb82609e..f3578c17 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -35,7 +35,7 @@ enum adaptive_sync_mode { }; enum tearing_mode { - LAB_TEARING_DISABLED, + LAB_TEARING_DISABLED = 0, LAB_TEARING_ENABLED, LAB_TEARING_FULLSCREEN, LAB_TEARING_ALWAYS, diff --git a/include/labwc.h b/include/labwc.h index 1e387905..b2d51057 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -361,7 +361,6 @@ struct output { bool leased; bool gamma_lut_changed; - bool tearing; }; #undef LAB_NR_LAYERS @@ -484,7 +483,6 @@ 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 new_tearing_hint(struct wl_listener *listener, void *data); -void set_tearing(struct output *output); void server_init(struct server *server); void server_start(struct server *server); diff --git a/src/output.c b/src/output.c index 4319c847..0f0bb10b 100644 --- a/src/output.c +++ b/src/output.c @@ -27,6 +27,40 @@ #include "view.h" #include "xwayland.h" +static bool +get_tearing_preference(struct output *output) +{ + struct server *server = output->server; + + /* Never allow tearing when disabled */ + if (rc.allow_tearing == LAB_TEARING_DISABLED) { + return false; + } + + /* Allows allow tearing when forced */ + if (rc.allow_tearing == LAB_TEARING_ALWAYS) { + return true; + } + + /* Tearing is only allowed for the output with the active view */ + if (!server->active_view || server->active_view->output != output) { + return false; + } + + /* If the active view requests tearing, allow it */ + if (server->active_view->tearing_hint) { + return true; + } + + /* If the active view is fullscreen, allow tearing if configured */ + if (rc.allow_tearing == LAB_TEARING_FULLSCREEN && + server->active_view->fullscreen) { + return true; + } + + return false; +} + static void output_frame_notify(struct wl_listener *listener, void *data) { @@ -68,8 +102,8 @@ output_frame_notify(struct wl_listener *listener, void *data) return; } - output->wlr_output->pending.tearing_page_flip = output->tearing; - + output->wlr_output->pending.tearing_page_flip = + get_tearing_preference(output); lab_wlr_scene_output_commit(output->scene_output); struct timespec now = { 0 }; @@ -275,12 +309,6 @@ new_output_notify(struct wl_listener *listener, void *data) wl_list_init(&output->regions); - if (rc.allow_tearing == LAB_TEARING_ALWAYS) { - output->tearing = true; - } else { - output->tearing = false; - } - /* * Create layer-trees (background, bottom, top and overlay) and * a layer-popup-tree. diff --git a/src/tearing.c b/src/tearing.c index 351994d6..443149bc 100644 --- a/src/tearing.c +++ b/src/tearing.c @@ -48,33 +48,3 @@ new_tearing_hint(struct wl_listener *listener, void *data) controller->destroy.notify = tearing_controller_destroy; wl_signal_add(&tearing_control->events.destroy, &controller->destroy); } - -void -set_tearing(struct output *output) -{ - if (rc.allow_tearing == LAB_TEARING_DISABLED) { - output->tearing = false; - return; - } - - if (rc.allow_tearing == LAB_TEARING_ALWAYS) { - output->tearing = true; - return; - } - - struct server *server = output->server; - struct view *view; - bool on_fullscreen = rc.allow_tearing == LAB_TEARING_FULLSCREEN; - - wl_list_for_each(view, &server->views, link) { - if (view->output != output) { - continue; - } - - if (view->tearing_hint || (on_fullscreen && view->fullscreen)) { - output->tearing = true; - return; - } - } - output->tearing = false; -} diff --git a/src/view.c b/src/view.c index 09499faa..f0562f9f 100644 --- a/src/view.c +++ b/src/view.c @@ -297,7 +297,6 @@ view_set_activated(struct view *view, bool activated) } } set_adaptive_sync_fullscreen(view); - set_tearing(view->output); } void @@ -1200,7 +1199,6 @@ view_set_fullscreen(struct view *view, bool fullscreen) view_apply_special_geometry(view); } set_adaptive_sync_fullscreen(view); - set_tearing(view->output); } void