config: add allowTearing option

This commit is contained in:
Ph42oN 2024-01-01 13:47:02 +02:00
parent 7f357a388b
commit 2f0a9ef158
5 changed files with 56 additions and 1 deletions

View file

@ -34,6 +34,12 @@ enum adaptive_sync_mode {
LAB_ADAPTIVE_SYNC_FULLSCREEN, LAB_ADAPTIVE_SYNC_FULLSCREEN,
}; };
enum tearing_mode {
LAB_TEARING_DISABLED,
LAB_TEARING_ENABLED,
LAB_TEARING_FULLSCREEN,
};
struct usable_area_override { struct usable_area_override {
struct border margin; struct border margin;
char *output; char *output;
@ -53,6 +59,7 @@ struct rcxml {
bool xdg_shell_server_side_deco; bool xdg_shell_server_side_deco;
int gap; int gap;
enum adaptive_sync_mode adaptive_sync; enum adaptive_sync_mode adaptive_sync;
enum tearing_mode allow_tearing;
bool reuse_output_mode; bool reuse_output_mode;
enum view_placement_policy placement_policy; enum view_placement_policy placement_policy;

View file

@ -357,6 +357,7 @@ struct output {
bool leased; bool leased;
bool gamma_lut_changed; bool gamma_lut_changed;
bool tearing;
}; };
#undef LAB_NR_LAYERS #undef LAB_NR_LAYERS

View file

@ -625,6 +625,26 @@ set_adaptive_sync_mode(const char *str, enum adaptive_sync_mode *variable)
} }
} }
static void
set_tearing_mode(const char *str, enum tearing_mode *variable)
{
if (!strcasecmp(str, "fullscreen")) {
*variable = LAB_TEARING_FULLSCREEN;
} else {
int ret = parse_bool(str, -1);
if (ret == 1) {
*variable = LAB_TEARING_ENABLED;
} else {
*variable = LAB_TEARING_DISABLED;
}
}
if (*variable != LAB_TEARING_DISABLED &&
strcmp(getenv("WLR_DRM_NO_ATOMIC"), "1")) {
*variable = LAB_TEARING_DISABLED;
wlr_log(WLR_INFO, "WLR_DRM_NO_ATOMIC is not 1, tearing disabled");
}
}
static void static void
entry(xmlNode *node, char *nodename, char *content) entry(xmlNode *node, char *nodename, char *content)
{ {
@ -727,6 +747,8 @@ entry(xmlNode *node, char *nodename, char *content)
rc.gap = atoi(content); rc.gap = atoi(content);
} else if (!strcasecmp(nodename, "adaptiveSync.core")) { } else if (!strcasecmp(nodename, "adaptiveSync.core")) {
set_adaptive_sync_mode(content, &rc.adaptive_sync); set_adaptive_sync_mode(content, &rc.adaptive_sync);
} else if (!strcasecmp(nodename, "allowTearing.core")) {
set_tearing_mode(content, &rc.allow_tearing);
} else if (!strcasecmp(nodename, "reuseOutputMode.core")) { } else if (!strcasecmp(nodename, "reuseOutputMode.core")) {
set_bool(content, &rc.reuse_output_mode); set_bool(content, &rc.reuse_output_mode);
} else if (!strcmp(nodename, "policy.placement")) { } else if (!strcmp(nodename, "policy.placement")) {

View file

@ -68,7 +68,11 @@ output_frame_notify(struct wl_listener *listener, void *data)
return; return;
} }
wlr_scene_output_commit(output->scene_output, NULL); if (output->tearing) {
output->wlr_output->pending.tearing_page_flip = true;
}
lab_wlr_scene_output_commit(output->scene_output);
struct timespec now = { 0 }; struct timespec now = { 0 };
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
@ -273,6 +277,12 @@ new_output_notify(struct wl_listener *listener, void *data)
wl_list_init(&output->regions); wl_list_init(&output->regions);
if (rc.allow_tearing == LAB_TEARING_ENABLED) {
output->tearing = true;
} else {
output->tearing = false;
}
/* /*
* Create layer-trees (background, bottom, top and overlay) and * Create layer-trees (background, bottom, top and overlay) and
* a layer-popup-tree. * a layer-popup-tree.

View file

@ -273,6 +273,16 @@ set_adaptive_sync_fullscreen(struct view *view)
wlr_output_commit(view->output->wlr_output); wlr_output_commit(view->output->wlr_output);
} }
static void
set_tearing_fullscreen(struct view *view)
{
if (rc.allow_tearing != LAB_TEARING_FULLSCREEN) {
return;
}
/* Enable tearing if view is fullscreen */
view->output->tearing = view->fullscreen;
}
void void
view_set_activated(struct view *view, bool activated) view_set_activated(struct view *view, bool activated)
{ {
@ -297,6 +307,7 @@ view_set_activated(struct view *view, bool activated)
} }
} }
set_adaptive_sync_fullscreen(view); set_adaptive_sync_fullscreen(view);
set_tearing_fullscreen(view);
} }
void void
@ -1199,6 +1210,7 @@ view_set_fullscreen(struct view *view, bool fullscreen)
view_apply_special_geometry(view); view_apply_special_geometry(view);
} }
set_adaptive_sync_fullscreen(view); set_adaptive_sync_fullscreen(view);
set_tearing_fullscreen(view);
} }
void void
@ -1869,6 +1881,9 @@ view_destroy(struct view *view)
if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_FULLSCREEN) { if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_FULLSCREEN) {
wlr_output_enable_adaptive_sync(view->output->wlr_output, false); wlr_output_enable_adaptive_sync(view->output->wlr_output, false);
} }
if (rc.allow_tearing == LAB_TEARING_FULLSCREEN) {
view->output->tearing = false;
}
} }
/* If we spawned a window menu, close it */ /* If we spawned a window menu, close it */