mirror of
https://github.com/swaywm/sway.git
synced 2025-02-26 03:01:20 +00:00
sway/commands: introduce output leasing command
This commit is contained in:
parent
0a848c0da2
commit
c2aa0a76f8
5 changed files with 74 additions and 0 deletions
|
@ -283,6 +283,7 @@ sway_cmd output_cmd_background;
|
|||
sway_cmd output_cmd_disable;
|
||||
sway_cmd output_cmd_dpms;
|
||||
sway_cmd output_cmd_enable;
|
||||
sway_cmd output_cmd_leasing;
|
||||
sway_cmd output_cmd_max_render_time;
|
||||
sway_cmd output_cmd_mode;
|
||||
sway_cmd output_cmd_modeline;
|
||||
|
|
|
@ -13,6 +13,7 @@ static const struct cmd_handler output_handlers[] = {
|
|||
{ "disable", output_cmd_disable },
|
||||
{ "dpms", output_cmd_dpms },
|
||||
{ "enable", output_cmd_enable },
|
||||
{ "leasing", output_cmd_leasing },
|
||||
{ "max_render_time", output_cmd_max_render_time },
|
||||
{ "mode", output_cmd_mode },
|
||||
{ "modeline", output_cmd_modeline },
|
||||
|
|
66
sway/commands/output/leasing.c
Normal file
66
sway/commands/output/leasing.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "sway/commands.h"
|
||||
#include "sway/output.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
struct cmd_results *output_cmd_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");
|
||||
}
|
||||
|
||||
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 (!sway_output || !sway_output->wlr_output) {
|
||||
return cmd_results_new(CMD_FAILURE,
|
||||
"Cannot apply leasing to unknown output %s", oc_name);
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
return cmd_results_new(CMD_INVALID, "Missing leasing argument");
|
||||
}
|
||||
|
||||
bool status = true;
|
||||
if (parse_boolean(argv[0], status)) {
|
||||
if (sway_output->leasing) {
|
||||
return cmd_results_new(CMD_INVALID,
|
||||
"Output %s is already out for leasing", oc_name);
|
||||
}
|
||||
|
||||
sway_output->leasing = true;
|
||||
output_disable(sway_output);
|
||||
wlr_output_layout_remove(root->output_layout, sway_output->wlr_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);
|
||||
|
||||
config->handler_context.output_config->enabled = 0;
|
||||
|
||||
} else {
|
||||
if (!sway_output->leasing) {
|
||||
return cmd_results_new(CMD_INVALID,
|
||||
"Output %s is already not available for leasing", oc_name);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
sway_output->leasing = false;
|
||||
output_enable(sway_output);
|
||||
|
||||
config->handler_context.output_config->enabled = 1;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -188,6 +188,7 @@ sway_sources = files(
|
|||
'commands/output/disable.c',
|
||||
'commands/output/dpms.c',
|
||||
'commands/output/enable.c',
|
||||
'commands/output/leasing.c',
|
||||
'commands/output/max_render_time.c',
|
||||
'commands/output/mode.c',
|
||||
'commands/output/position.c',
|
||||
|
|
|
@ -180,6 +180,11 @@ must be separated by one space. For example:
|
|||
updated to work with different bit depths. This command is experimental,
|
||||
and may be removed or changed in the future.
|
||||
|
||||
*output* <name> leasing on|off
|
||||
Enables or disables DRM leasing on a given output, the DRM lease
|
||||
interface must be active when calling this command. Outputs offered to
|
||||
leasing will be disabled until taken off from leasing.
|
||||
|
||||
# SEE ALSO
|
||||
|
||||
*sway*(5) *sway-input*(5)
|
||||
|
|
Loading…
Add table
Reference in a new issue