feat: adaptive_sync

This commit is contained in:
DreamMaoMao 2025-09-18 11:51:19 +08:00
parent 13e90496ef
commit 8533b9e0a0
3 changed files with 34 additions and 6 deletions

View file

@ -302,6 +302,7 @@ typedef struct {
int single_scratchpad; int single_scratchpad;
int xwayland_persistence; int xwayland_persistence;
int syncobj_enable; int syncobj_enable;
int adaptive_syn;
struct xkb_rule_names xkb_rules; struct xkb_rule_names xkb_rules;
} Config; } Config;
@ -1012,6 +1013,8 @@ void parse_config_line(Config *config, const char *line) {
config->xwayland_persistence = atoi(value); config->xwayland_persistence = atoi(value);
} else if (strcmp(key, "syncobj_enable") == 0) { } else if (strcmp(key, "syncobj_enable") == 0) {
config->syncobj_enable = atoi(value); config->syncobj_enable = atoi(value);
} else if (strcmp(key, "adaptive_syn") == 0) {
config->adaptive_syn = atoi(value);
} else if (strcmp(key, "no_border_when_single") == 0) { } else if (strcmp(key, "no_border_when_single") == 0) {
config->no_border_when_single = atoi(value); config->no_border_when_single = atoi(value);
} else if (strcmp(key, "no_radius_when_single") == 0) { } else if (strcmp(key, "no_radius_when_single") == 0) {
@ -2339,6 +2342,7 @@ void override_config(void) {
// 杂项设置 // 杂项设置
xwayland_persistence = CLAMP_INT(config.xwayland_persistence, 0, 1); xwayland_persistence = CLAMP_INT(config.xwayland_persistence, 0, 1);
syncobj_enable = CLAMP_INT(config.syncobj_enable, 0, 1); syncobj_enable = CLAMP_INT(config.syncobj_enable, 0, 1);
adaptive_syn = CLAMP_INT(config.adaptive_syn, 0, 1);
axis_bind_apply_timeout = axis_bind_apply_timeout =
CLAMP_INT(config.axis_bind_apply_timeout, 0, 1000); CLAMP_INT(config.axis_bind_apply_timeout, 0, 1000);
focus_on_activate = CLAMP_INT(config.focus_on_activate, 0, 1); focus_on_activate = CLAMP_INT(config.focus_on_activate, 0, 1);
@ -2501,6 +2505,7 @@ void set_value_default() {
config.single_scratchpad = single_scratchpad; config.single_scratchpad = single_scratchpad;
config.xwayland_persistence = xwayland_persistence; config.xwayland_persistence = xwayland_persistence;
config.syncobj_enable = syncobj_enable; config.syncobj_enable = syncobj_enable;
config.adaptive_syn = adaptive_syn;
config.no_border_when_single = no_border_when_single; config.no_border_when_single = no_border_when_single;
config.no_radius_when_single = no_radius_when_single; config.no_radius_when_single = no_radius_when_single;
config.snap_distance = snap_distance; config.snap_distance = snap_distance;
@ -2755,6 +2760,10 @@ void reapply_monitor_rules(void) {
} }
} }
if (adaptive_syn) {
enable_adaptive_sync(m, &state);
}
wlr_output_commit_state(m->wlr_output, &state); wlr_output_commit_state(m->wlr_output, &state);
wlr_output_state_finish(&state); wlr_output_state_finish(&state);
updatemons(NULL, NULL); updatemons(NULL, NULL);

View file

@ -96,6 +96,7 @@ float fullscreen_bg[] = {0.1, 0.1, 0.1, 1.0};
int warpcursor = 1; /* Warp cursor to focused client */ int warpcursor = 1; /* Warp cursor to focused client */
int xwayland_persistence = 1; /* xwayland persistence */ int xwayland_persistence = 1; /* xwayland persistence */
int syncobj_enable = 0; int syncobj_enable = 0;
int adaptive_syn = 0;
/* keyboard */ /* keyboard */

View file

@ -688,13 +688,15 @@ static struct wlr_scene_tree *
wlr_scene_tree_snapshot(struct wlr_scene_node *node, wlr_scene_tree_snapshot(struct wlr_scene_node *node,
struct wlr_scene_tree *parent); struct wlr_scene_tree *parent);
static bool is_scroller_layout(Monitor *m); static bool is_scroller_layout(Monitor *m);
void create_output(struct wlr_backend *backend, void *data); static void create_output(struct wlr_backend *backend, void *data);
static const char *get_layout_abbr(const char *full_name); static const char *get_layout_abbr(const char *full_name);
void apply_named_scratchpad(Client *target_client); static void apply_named_scratchpad(Client *target_client);
Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title); static Client *get_client_by_id_or_title(const char *arg_id,
bool switch_scratchpad_client_state(Client *c); const char *arg_title);
bool check_trackpad_disabled(struct wlr_pointer *pointer); static bool switch_scratchpad_client_state(Client *c);
unsigned int get_tag_status(unsigned int tag, Monitor *m); static bool check_trackpad_disabled(struct wlr_pointer *pointer);
static unsigned int get_tag_status(unsigned int tag, Monitor *m);
static void enable_adaptive_sync(Monitor *m, struct wlr_output_state *state);
#include "data/static_keymap.h" #include "data/static_keymap.h"
#include "dispatch/bind_declare.h" #include "dispatch/bind_declare.h"
@ -2525,6 +2527,18 @@ struct wlr_output_mode *get_nearest_output_mode(struct wlr_output *output,
return nearest_mode; return nearest_mode;
} }
void enable_adaptive_sync(Monitor *m, struct wlr_output_state *state) {
wlr_output_state_set_adaptive_sync_enabled(state, true);
if (!wlr_output_test_state(m->wlr_output, state)) {
wlr_output_state_set_adaptive_sync_enabled(state, false);
wlr_log(WLR_DEBUG, "failed to enable adaptive sync for output %s",
m->wlr_output->name);
} else {
wlr_log(WLR_INFO, "adaptive sync enabled for output %s",
m->wlr_output->name);
}
}
void createmon(struct wl_listener *listener, void *data) { void createmon(struct wl_listener *listener, void *data) {
/* This event is raised by the backend when a new output (aka a display or /* This event is raised by the backend when a new output (aka a display or
* monitor) becomes available. */ * monitor) becomes available. */
@ -2605,6 +2619,10 @@ void createmon(struct wl_listener *listener, void *data) {
} }
} }
if (adaptive_syn) {
enable_adaptive_sync(m, &state);
}
/* The mode is a tuple of (width, height, refresh rate), and each /* The mode is a tuple of (width, height, refresh rate), and each
* monitor supports only a specific set of modes. We just pick the * monitor supports only a specific set of modes. We just pick the
* monitor's preferred mode; a more sophisticated compositor would let * monitor's preferred mode; a more sophisticated compositor would let