mirror of
https://git.sr.ht/~leon_plickat/wlopm
synced 2024-11-16 10:28:25 +01:00
Accept * as parameter to operate on all outputs
This commit is contained in:
parent
f968900de8
commit
fec8a5db3d
7
wlopm.1
7
wlopm.1
@ -41,6 +41,13 @@ Toggle the power mode of the output.
|
|||||||
.RE
|
.RE
|
||||||
|
|
||||||
|
|
||||||
|
.SH OUTPUT NAMES
|
||||||
|
Output names are compositor dependand.
|
||||||
|
.P
|
||||||
|
If instead of an output name * is given as parameter to an operation, wlopm will
|
||||||
|
do that operation for all discovered outputs.
|
||||||
|
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Leon Henrik Plickat
|
Leon Henrik Plickat
|
||||||
|
|
||||||
|
100
wlopm.c
100
wlopm.c
@ -173,11 +173,67 @@ static struct Output *output_from_name (const char *str)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void output_set_power_mode (struct Output *output, enum Power_mode mode)
|
||||||
|
{
|
||||||
|
enum zwlr_output_power_v1_mode new_mode;
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case ON:
|
||||||
|
new_mode = ZWLR_OUTPUT_POWER_V1_MODE_ON;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OFF:
|
||||||
|
new_mode = ZWLR_OUTPUT_POWER_V1_MODE_OFF;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TOGGLE:
|
||||||
|
if ( output->mode == ZWLR_OUTPUT_POWER_V1_MODE_ON )
|
||||||
|
new_mode = ZWLR_OUTPUT_POWER_V1_MODE_OFF;
|
||||||
|
else
|
||||||
|
new_mode = ZWLR_OUTPUT_POWER_V1_MODE_ON;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
zwlr_output_power_v1_set_mode(output->wlr_output_power, new_mode);
|
||||||
|
}
|
||||||
|
|
||||||
static char *power_mode_to_string (enum zwlr_output_power_v1_mode mode)
|
static char *power_mode_to_string (enum zwlr_output_power_v1_mode mode)
|
||||||
{
|
{
|
||||||
return mode == ZWLR_OUTPUT_POWER_V1_MODE_ON ? "on" : "off";
|
return mode == ZWLR_OUTPUT_POWER_V1_MODE_ON ? "on" : "off";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void do_operation (struct Operation *operation)
|
||||||
|
{
|
||||||
|
if ( *operation->name == '*' )
|
||||||
|
{
|
||||||
|
struct Output *output;
|
||||||
|
wl_list_for_each(output, &outputs, link)
|
||||||
|
output_set_power_mode(output, operation->power_mode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct Output *output = output_from_name(operation->name);
|
||||||
|
if ( output == NULL )
|
||||||
|
{
|
||||||
|
if (json)
|
||||||
|
{
|
||||||
|
fprintf(stdout,
|
||||||
|
"%s\n {\n"
|
||||||
|
" \"output\": \"%s\",\n"
|
||||||
|
" \"error\": \"output does not exist\"\n"
|
||||||
|
" }",
|
||||||
|
json_prev ? "," : "",
|
||||||
|
operation->name);
|
||||||
|
json_prev = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fprintf(stderr, "ERROR: Output '%s' does not exist.\n",
|
||||||
|
operation->name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
output_set_power_mode(output, operation->power_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void sync_handle_done (void *data, struct wl_callback *wl_callback, uint32_t other_data)
|
static void sync_handle_done (void *data, struct wl_callback *wl_callback, uint32_t other_data)
|
||||||
{
|
{
|
||||||
wl_callback_destroy(wl_callback);
|
wl_callback_destroy(wl_callback);
|
||||||
@ -264,49 +320,7 @@ static void sync_handle_done (void *data, struct wl_callback *wl_callback, uint3
|
|||||||
|
|
||||||
struct Operation *operation;
|
struct Operation *operation;
|
||||||
wl_list_for_each(operation, &operations, link)
|
wl_list_for_each(operation, &operations, link)
|
||||||
{
|
do_operation(operation);
|
||||||
const struct Output *output = output_from_name(operation->name);
|
|
||||||
if ( output == NULL )
|
|
||||||
{
|
|
||||||
if (json)
|
|
||||||
{
|
|
||||||
fprintf(stdout,
|
|
||||||
"%s\n {\n"
|
|
||||||
" \"output\": \"%s\",\n"
|
|
||||||
" \"error\": \"output does not exist\"\n"
|
|
||||||
" }",
|
|
||||||
json_prev ? "," : "",
|
|
||||||
operation->name);
|
|
||||||
json_prev = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fprintf(stderr, "ERROR: Output '%s' does not exist.\n",
|
|
||||||
operation->name);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum zwlr_output_power_v1_mode new_mode;
|
|
||||||
switch (operation->power_mode)
|
|
||||||
{
|
|
||||||
case ON:
|
|
||||||
new_mode = ZWLR_OUTPUT_POWER_V1_MODE_ON;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OFF:
|
|
||||||
new_mode = ZWLR_OUTPUT_POWER_V1_MODE_OFF;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TOGGLE:
|
|
||||||
if ( output->mode == ZWLR_OUTPUT_POWER_V1_MODE_ON )
|
|
||||||
new_mode = ZWLR_OUTPUT_POWER_V1_MODE_OFF;
|
|
||||||
else
|
|
||||||
new_mode = ZWLR_OUTPUT_POWER_V1_MODE_ON;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
zwlr_output_power_v1_set_mode(output->wlr_output_power, new_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* We need to sync yet another time because setting the
|
/* We need to sync yet another time because setting the
|
||||||
* power mode might fail and we want to display those
|
* power mode might fail and we want to display those
|
||||||
|
Loading…
Reference in New Issue
Block a user