From 129a5a0d7c2692aaa456acdf16ed762d219b34ba Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Fri, 13 Jun 2025 17:07:34 -0400 Subject: [PATCH] sway/command: add allow_drm_leasing --- include/sway/commands.h | 1 + sway/commands/output.c | 1 + sway/commands/output/allow_drm_leasing.c | 60 ++++++++++++++++++++++++ sway/meson.build | 1 + 4 files changed, 63 insertions(+) create mode 100644 sway/commands/output/allow_drm_leasing.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 389c382e..9c2c9142 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -284,6 +284,7 @@ sway_cmd input_cmd_xkb_switch_layout; sway_cmd input_cmd_xkb_variant; sway_cmd output_cmd_adaptive_sync; +sway_cmd output_cmd_allow_drm_leasing; sway_cmd output_cmd_allow_tearing; sway_cmd output_cmd_background; sway_cmd output_cmd_color_profile; diff --git a/sway/commands/output.c b/sway/commands/output.c index afff23f6..f02e0dd5 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -8,6 +8,7 @@ // must be in order for the bsearch static const struct cmd_handler output_handlers[] = { { "adaptive_sync", output_cmd_adaptive_sync }, + { "allow_drm_leasing", output_cmd_allow_drm_leasing }, { "allow_tearing", output_cmd_allow_tearing }, { "background", output_cmd_background }, { "bg", output_cmd_background }, diff --git a/sway/commands/output/allow_drm_leasing.c b/sway/commands/output/allow_drm_leasing.c new file mode 100644 index 00000000..01269e03 --- /dev/null +++ b/sway/commands/output/allow_drm_leasing.c @@ -0,0 +1,60 @@ +#include "sway/commands.h" +#include "sway/output.h" +#include "sway/server.h" +#include "log.h" +#include "util.h" + +#if WLR_HAS_DRM_BACKEND +#include +#include +#endif + +struct cmd_results *output_cmd_allow_drm_leasing(int argc, char **argv) { + if (!server.drm_lease_manager) { + return cmd_results_new(CMD_FAILURE, + "DRM lease manager interface not available"); + } + + if (!config->handler_context.output_config) { + return cmd_results_new(CMD_FAILURE, "Missing output config"); + } + + if (argc == 0) { + return cmd_results_new(CMD_INVALID, "Missing allow_leasing argument"); + } + + const char *oc_name = config->handler_context.output_config->name; + if (strcmp(oc_name, "*") == 0) { + return cmd_results_new(CMD_INVALID, + "Cannot apply leasing to all outputs"); + } + + struct sway_output *sway_output = all_output_by_name_or_id(oc_name); + + if (parse_boolean(argv[0], + (config->handler_context.output_config->allow_drm_leasing == 1))) { + config->handler_context.output_config->allow_drm_leasing = 1; + +#if WLR_HAS_DRM_BACKEND + if (sway_output) { + sway_log(SWAY_DEBUG, "Offering output %s for leasing", oc_name); + wlr_drm_lease_v1_manager_offer_output(server.drm_lease_manager, + sway_output->wlr_output); + } +#endif + } else { + config->handler_context.output_config->allow_drm_leasing = 0; + +#if WLR_HAS_DRM_BACKEND + if (sway_output) { + sway_log(SWAY_DEBUG, "Withdrawing output %s from leasing", oc_name); + wlr_drm_lease_v1_manager_withdraw_output(server.drm_lease_manager, + sway_output->wlr_output); + } +#endif + } + + config->handler_context.leftovers.argc = argc - 1; + config->handler_context.leftovers.argv = argv + 1; + return NULL; +} diff --git a/sway/meson.build b/sway/meson.build index cb03a4d2..1dc44d32 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -190,6 +190,7 @@ sway_sources = files( 'commands/input/xkb_variant.c', 'commands/output/adaptive_sync.c', + 'commands/output/allow_drm_leasing.c', 'commands/output/allow_tearing.c', 'commands/output/background.c', 'commands/output/disable.c',