]> git.mdlowis.com Git - proto/labwc.git/commitdiff
config: add adaptive sync fullscreen option
authorPh42oN <julle.ys.57@gmail.com>
Sat, 30 Dec 2023 15:35:41 +0000 (17:35 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 30 Dec 2023 15:46:35 +0000 (15:46 +0000)
include/config/rcxml.h
include/labwc.h
src/config/rcxml.c
src/output.c
src/view.c

index acb34260104697bde31e9f84be1abde82a4413f8..2fa7463ac8bb7cccd62a957b8e6c63b89db3b5d0 100644 (file)
@@ -28,6 +28,12 @@ enum view_placement_policy {
        LAB_PLACE_AUTOMATIC
 };
 
+enum adaptive_sync_mode {
+       LAB_ADAPTIVE_SYNC_DISABLED,
+       LAB_ADAPTIVE_SYNC_ENABLED,
+       LAB_ADAPTIVE_SYNC_FULLSCREEN,
+};
+
 struct usable_area_override {
        struct border margin;
        char *output;
@@ -46,7 +52,7 @@ struct rcxml {
        /* core */
        bool xdg_shell_server_side_deco;
        int gap;
-       bool adaptive_sync;
+       enum adaptive_sync_mode adaptive_sync;
        bool reuse_output_mode;
        enum view_placement_policy placement_policy;
 
index da92242202c4f17fc86f445488d6bcbaf1934539..88dfbec52aeff2a60796a7ff01fe195f65cd8e56 100644 (file)
@@ -477,6 +477,7 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
        void *data);
 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 server_init(struct server *server);
 void server_start(struct server *server);
index 4f3f5a547031570161f96754cd94be0bc81d1d8f..f1a9c1100a854d2ba6ad2c94a044ed86357d6478 100644 (file)
@@ -610,6 +610,21 @@ enum_font_place(const char *place)
        return FONT_PLACE_UNKNOWN;
 }
 
+static void
+set_adaptive_sync_mode(const char *str, enum adaptive_sync_mode *variable)
+{
+       if (!strcasecmp(str, "fullscreen")) {
+               *variable = LAB_ADAPTIVE_SYNC_FULLSCREEN;
+       } else {
+               int ret = parse_bool(str, -1);
+               if (ret == 1) {
+                       *variable = LAB_ADAPTIVE_SYNC_ENABLED;
+               } else {
+                       *variable = LAB_ADAPTIVE_SYNC_DISABLED;
+               }
+       }
+}
+
 static void
 entry(xmlNode *node, char *nodename, char *content)
 {
@@ -711,7 +726,7 @@ entry(xmlNode *node, char *nodename, char *content)
        } else if (!strcmp(nodename, "gap.core")) {
                rc.gap = atoi(content);
        } else if (!strcasecmp(nodename, "adaptiveSync.core")) {
-               set_bool(content, &rc.adaptive_sync);
+               set_adaptive_sync_mode(content, &rc.adaptive_sync);
        } else if (!strcasecmp(nodename, "reuseOutputMode.core")) {
                set_bool(content, &rc.reuse_output_mode);
        } else if (!strcmp(nodename, "policy.placement")) {
index 36d23128a7e4efbb4d5c9c1ad17e3d32e6f53ec8..7f2f5520949a51c93bd2a99d079b337907425add 100644 (file)
@@ -249,15 +249,8 @@ new_output_notify(struct wl_listener *listener, void *data)
                }
        }
 
-       if (rc.adaptive_sync) {
-               wlr_output_enable_adaptive_sync(wlr_output, true);
-               if (!wlr_output_test(wlr_output)) {
-                       wlr_output_enable_adaptive_sync(wlr_output, false);
-                       wlr_log(WLR_DEBUG,
-                               "failed to enable adaptive sync for output %s", wlr_output->name);
-               } else {
-                       wlr_log(WLR_INFO, "adaptive sync enabled for output %s", wlr_output->name);
-               }
+       if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_ENABLED) {
+               output_enable_adaptive_sync(wlr_output, true);
        }
 
        wlr_output_commit(wlr_output);
@@ -415,7 +408,10 @@ output_config_apply(struct server *server,
                        }
                        wlr_output_set_scale(o, head->state.scale);
                        wlr_output_set_transform(o, head->state.transform);
-                       wlr_output_enable_adaptive_sync(o, head->state.adaptive_sync_enabled);
+                       if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_ENABLED) {
+                               output_enable_adaptive_sync(o,
+                                       head->state.adaptive_sync_enabled);
+                       }
                }
                if (!wlr_output_commit(o)) {
                        wlr_log(WLR_ERROR, "Output config commit failed");
@@ -810,3 +806,20 @@ output_remove_virtual(struct server *server, const char *output_name)
                }
        }
 }
+
+void
+output_enable_adaptive_sync(struct wlr_output *output, bool enabled)
+{
+       if (output->pending.adaptive_sync_enabled == enabled) {
+               return;
+       }
+       wlr_output_enable_adaptive_sync(output, enabled);
+       if (!wlr_output_test(output)) {
+               wlr_output_enable_adaptive_sync(output, false);
+               wlr_log(WLR_DEBUG,
+                               "failed to enable adaptive sync for output %s", output->name);
+       } else {
+               wlr_log(WLR_INFO, "adaptive sync %sabled for output %s",
+                       enabled ? "en" : "dis", output->name);
+       }
+}
index d2b3bb50043328a7496909150be03ebd55817ede..f0562f9f1d6fb86cc0095f0c30571fd9a7c82eea 100644 (file)
@@ -262,6 +262,17 @@ view_discover_output(struct view *view)
                view->current.y + view->current.height / 2);
 }
 
+static void
+set_adaptive_sync_fullscreen(struct view *view)
+{
+       if (rc.adaptive_sync != LAB_ADAPTIVE_SYNC_FULLSCREEN) {
+               return;
+       }
+       /* Enable adaptive sync if view is fullscreen */
+       output_enable_adaptive_sync(view->output->wlr_output, view->fullscreen);
+       wlr_output_commit(view->output->wlr_output);
+}
+
 void
 view_set_activated(struct view *view, bool activated)
 {
@@ -285,6 +296,7 @@ view_set_activated(struct view *view, bool activated)
                        keyboard_update_layout(&view->server->seat, view->keyboard_layout);
                }
        }
+       set_adaptive_sync_fullscreen(view);
 }
 
 void
@@ -1186,6 +1198,7 @@ view_set_fullscreen(struct view *view, bool fullscreen)
        } else {
                view_apply_special_geometry(view);
        }
+       set_adaptive_sync_fullscreen(view);
 }
 
 void
@@ -1853,6 +1866,9 @@ view_destroy(struct view *view)
        if (view->fullscreen && view->output) {
                view->fullscreen = false;
                desktop_update_top_layer_visiblity(server);
+               if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_FULLSCREEN) {
+                       wlr_output_enable_adaptive_sync(view->output->wlr_output, false);
+               }
        }
 
        /* If we spawned a window menu, close it */