Skip to content

Commit

Permalink
Remove internal references to DPMS
Browse files Browse the repository at this point in the history
While at it, use an int for the config field, just like we do for
all other fields.
  • Loading branch information
emersion committed Jun 23, 2022
1 parent 6150e12 commit c59f944
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
8 changes: 1 addition & 7 deletions include/sway/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,6 @@ struct seat_config {
} xcursor_theme;
};

enum config_dpms {
DPMS_IGNORE,
DPMS_ON,
DPMS_OFF,
};

enum scale_filter_mode {
SCALE_FILTER_DEFAULT, // the default is currently smart
SCALE_FILTER_LINEAR,
Expand All @@ -273,6 +267,7 @@ enum render_bit_depth {
struct output_config {
char *name;
int enabled;
int power;
int width, height;
float refresh_rate;
int custom_mode;
Expand All @@ -289,7 +284,6 @@ struct output_config {
char *background;
char *background_option;
char *background_fallback;
enum config_dpms dpms_state;
};

/**
Expand Down
10 changes: 5 additions & 5 deletions sway/commands/output/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct cmd_results *output_cmd_power(int argc, char **argv) {
return cmd_results_new(CMD_INVALID, "Missing power argument");
}

enum config_dpms current_dpms = DPMS_ON;
bool current = true;
if (strcasecmp(argv[0], "toggle") == 0) {
const char *oc_name = config->handler_context.output_config->name;
if (strcmp(oc_name, "*") == 0) {
Expand All @@ -27,14 +27,14 @@ struct cmd_results *output_cmd_power(int argc, char **argv) {
}

if (sway_output->enabled && !sway_output->wlr_output->enabled) {
current_dpms = DPMS_OFF;
current = false;
}
}

if (parse_boolean(argv[0], current_dpms == DPMS_ON)) {
config->handler_context.output_config->dpms_state = DPMS_ON;
if (parse_boolean(argv[0], current)) {
config->handler_context.output_config->power = 1;
} else {
config->handler_context.output_config->dpms_state = DPMS_OFF;
config->handler_context.output_config->power = 0;
}

config->handler_context.leftovers.argc = argc - 1;
Expand Down
23 changes: 12 additions & 11 deletions sway/config/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct output_config *new_output_config(const char *name) {
oc->max_render_time = -1;
oc->adaptive_sync = -1;
oc->render_bit_depth = RENDER_BIT_DEPTH_DEFAULT;
oc->power = -1;
return oc;
}

Expand Down Expand Up @@ -132,8 +133,8 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
free(dst->background_fallback);
dst->background_fallback = strdup(src->background_fallback);
}
if (src->dpms_state != 0) {
dst->dpms_state = src->dpms_state;
if (src->power != -1) {
dst->power = src->power;
}
}

Expand Down Expand Up @@ -192,11 +193,11 @@ static void merge_id_on_name(struct output_config *oc) {
list_add(config->output_configs, ion_oc);
sway_log(SWAY_DEBUG, "Generated id on name output config \"%s\""
" (enabled: %d) (%dx%d@%fHz position %d,%d scale %f "
"transform %d) (bg %s %s) (dpms %d) (max render time: %d)",
"transform %d) (bg %s %s) (power %d) (max render time: %d)",
ion_oc->name, ion_oc->enabled, ion_oc->width, ion_oc->height,
ion_oc->refresh_rate, ion_oc->x, ion_oc->y, ion_oc->scale,
ion_oc->transform, ion_oc->background,
ion_oc->background_option, ion_oc->dpms_state,
ion_oc->background_option, ion_oc->power,
ion_oc->max_render_time);
}
}
Expand Down Expand Up @@ -237,11 +238,11 @@ struct output_config *store_output_config(struct output_config *oc) {
}

sway_log(SWAY_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
"position %d,%d scale %f subpixel %s transform %d) (bg %s %s) (dpms %d) "
"position %d,%d scale %f subpixel %s transform %d) (bg %s %s) (power %d) "
"(max render time: %d)",
oc->name, oc->enabled, oc->width, oc->height, oc->refresh_rate,
oc->x, oc->y, oc->scale, sway_wl_output_subpixel_to_string(oc->subpixel),
oc->transform, oc->background, oc->background_option, oc->dpms_state,
oc->transform, oc->background, oc->background_option, oc->power,
oc->max_render_time);

return oc;
Expand Down Expand Up @@ -385,7 +386,7 @@ static void queue_output_config(struct output_config *oc,

struct wlr_output *wlr_output = output->wlr_output;

if (oc && (!oc->enabled || oc->dpms_state == DPMS_OFF)) {
if (oc && (!oc->enabled || oc->power == 0)) {
sway_log(SWAY_DEBUG, "Turning off output %s", wlr_output->name);
wlr_output_state_set_enabled(pending, false);
return;
Expand Down Expand Up @@ -494,7 +495,7 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
struct wlr_output_state pending = {0};
queue_output_config(oc, output, &pending);

if (!oc || oc->dpms_state != DPMS_OFF) {
if (!oc || oc->power != 0) {
output->current_mode = pending.mode;
}

Expand Down Expand Up @@ -590,6 +591,7 @@ bool test_output_config(struct output_config *oc, struct sway_output *output) {
static void default_output_config(struct output_config *oc,
struct wlr_output *wlr_output) {
oc->enabled = 1;
oc->power = 1;
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
if (mode != NULL) {
oc->width = mode->width;
Expand All @@ -602,7 +604,6 @@ static void default_output_config(struct output_config *oc,
struct sway_output *output = wlr_output->data;
oc->subpixel = output->detected_subpixel;
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
oc->dpms_state = DPMS_ON;
oc->max_render_time = 0;
}

Expand Down Expand Up @@ -657,10 +658,10 @@ static struct output_config *get_output_config(char *identifier,

sway_log(SWAY_DEBUG, "Generated output config \"%s\" (enabled: %d)"
" (%dx%d@%fHz position %d,%d scale %f transform %d) (bg %s %s)"
" (dpms %d) (max render time: %d)", result->name, result->enabled,
" (power %d) (max render time: %d)", result->name, result->enabled,
result->width, result->height, result->refresh_rate,
result->x, result->y, result->scale, result->transform,
result->background, result->background_option, result->dpms_state,
result->background, result->background_option, result->power,
result->max_render_time);
} else if (oc_name) {
// No identifier config, just return a copy of the name config
Expand Down
4 changes: 2 additions & 2 deletions sway/desktop/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,10 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
struct output_config *oc = new_output_config(output->wlr_output->name);
switch (event->mode) {
case ZWLR_OUTPUT_POWER_V1_MODE_OFF:
oc->dpms_state = DPMS_OFF;
oc->power = 0;
break;
case ZWLR_OUTPUT_POWER_V1_MODE_ON:
oc->dpms_state = DPMS_ON;
oc->power = 1;
break;
}
oc = store_output_config(oc);
Expand Down

0 comments on commit c59f944

Please sign in to comment.