mirror of
https://github.com/labwc/labwc.git
synced 2026-02-25 01:40:28 -05:00
Add tearing support (#1390)
Co-authored-by: Andrew J. Hesford <ajh@sideband.org>
This commit is contained in:
parent
72f3ce6b41
commit
bce0c6ce56
13 changed files with 111 additions and 1 deletions
|
|
@ -102,6 +102,7 @@ enum action_type {
|
|||
ACTION_TYPE_VIRTUAL_OUTPUT_ADD,
|
||||
ACTION_TYPE_VIRTUAL_OUTPUT_REMOVE,
|
||||
ACTION_TYPE_AUTO_PLACE,
|
||||
ACTION_TYPE_TOGGLE_TEARING,
|
||||
};
|
||||
|
||||
const char *action_names[] = {
|
||||
|
|
@ -149,6 +150,7 @@ const char *action_names[] = {
|
|||
"VirtualOutputAdd",
|
||||
"VirtualOutputRemove",
|
||||
"AutoPlace",
|
||||
"ToggleTearing",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
@ -951,6 +953,13 @@ actions_run(struct view *activator, struct server *server,
|
|||
}
|
||||
}
|
||||
break;
|
||||
case ACTION_TYPE_TOGGLE_TEARING:
|
||||
if (view) {
|
||||
view->tearing_hint = !view->tearing_hint;
|
||||
wlr_log(WLR_DEBUG, "tearing %sabled",
|
||||
view->tearing_hint ? "en" : "dis");
|
||||
}
|
||||
break;
|
||||
case ACTION_TYPE_INVALID:
|
||||
wlr_log(WLR_ERROR, "Not executing unknown action");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -740,6 +740,12 @@ entry(xmlNode *node, char *nodename, char *content)
|
|||
rc.gap = atoi(content);
|
||||
} else if (!strcasecmp(nodename, "adaptiveSync.core")) {
|
||||
set_adaptive_sync_mode(content, &rc.adaptive_sync);
|
||||
} else if (!strcasecmp(nodename, "allowTearing.core")) {
|
||||
set_bool(content, &rc.allow_tearing);
|
||||
if (rc.allow_tearing && strcmp(getenv("WLR_DRM_NO_ATOMIC"), "1")) {
|
||||
rc.allow_tearing = false;
|
||||
wlr_log(WLR_INFO, "WLR_DRM_NO_ATOMIC is not 1, tearing disabled");
|
||||
}
|
||||
} else if (!strcasecmp(nodename, "reuseOutputMode.core")) {
|
||||
set_bool(content, &rc.reuse_output_mode);
|
||||
} else if (!strcmp(nodename, "policy.placement")) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ labwc_sources = files(
|
|||
'server.c',
|
||||
'session-lock.c',
|
||||
'snap.c',
|
||||
'tearing.c',
|
||||
'theme.c',
|
||||
'view.c',
|
||||
'view-impl-common.c',
|
||||
|
|
|
|||
23
src/output.c
23
src/output.c
|
|
@ -27,6 +27,25 @@
|
|||
#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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 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, or it is toggled on with action, allow it */
|
||||
return server->active_view->tearing_hint;
|
||||
}
|
||||
|
||||
static void
|
||||
output_frame_notify(struct wl_listener *listener, void *data)
|
||||
{
|
||||
|
|
@ -68,7 +87,9 @@ output_frame_notify(struct wl_listener *listener, void *data)
|
|||
return;
|
||||
}
|
||||
|
||||
wlr_scene_output_commit(output->scene_output, NULL);
|
||||
output->wlr_output->pending.tearing_page_flip =
|
||||
get_tearing_preference(output);
|
||||
lab_wlr_scene_output_commit(output->scene_output);
|
||||
|
||||
struct timespec now = { 0 };
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
|
|
|||
|
|
@ -449,6 +449,10 @@ server_init(struct server *server)
|
|||
wl_signal_add(&server->output_power_manager_v1->events.set_mode,
|
||||
&server->output_power_manager_set_mode);
|
||||
|
||||
server->tearing_control = wlr_tearing_control_manager_v1_create(server->wl_display, 1);
|
||||
server->tearing_new_object.notify = new_tearing_hint;
|
||||
wl_signal_add(&server->tearing_control->events.new_object, &server->tearing_new_object);
|
||||
|
||||
layers_init(server);
|
||||
|
||||
#if HAVE_XWAYLAND
|
||||
|
|
|
|||
50
src/tearing.c
Normal file
50
src/tearing.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
#include "labwc.h"
|
||||
#include "view.h"
|
||||
|
||||
struct tearing_controller {
|
||||
struct wlr_tearing_control_v1 *tearing_control;
|
||||
struct wl_listener set_hint;
|
||||
struct wl_listener destroy;
|
||||
};
|
||||
|
||||
static void
|
||||
set_tearing_hint(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct tearing_controller *controller = wl_container_of(listener, controller, set_hint);
|
||||
struct view *view = view_from_wlr_surface(controller->tearing_control->surface);
|
||||
if (view && controller->tearing_control->hint) {
|
||||
view->tearing_hint = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
tearing_controller_destroy(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct tearing_controller *controller = wl_container_of(listener, controller, destroy);
|
||||
free(controller);
|
||||
}
|
||||
|
||||
void
|
||||
new_tearing_hint(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct server *server = wl_container_of(listener, server, tearing_new_object);
|
||||
struct wlr_tearing_control_v1 *tearing_control = data;
|
||||
|
||||
enum wp_tearing_control_v1_presentation_hint hint =
|
||||
wlr_tearing_control_manager_v1_surface_hint_from_surface
|
||||
(server->tearing_control, tearing_control->surface);
|
||||
wlr_log(WLR_DEBUG, "New presentation hint %d received for surface %p",
|
||||
hint, tearing_control->surface);
|
||||
|
||||
struct tearing_controller *controller = calloc(1, sizeof(struct tearing_controller));
|
||||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
controller->tearing_control = tearing_control;
|
||||
controller->set_hint.notify = set_tearing_hint;
|
||||
wl_signal_add(&tearing_control->events.set_hint, &controller->set_hint);
|
||||
controller->destroy.notify = tearing_controller_destroy;
|
||||
wl_signal_add(&tearing_control->events.destroy, &controller->destroy);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue