Skip to content

Instantly share code, notes, and snippets.

@7415963987456321
Last active January 4, 2019 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7415963987456321/00a2a5152165714372ddd81f5e7338c8 to your computer and use it in GitHub Desktop.
Save 7415963987456321/00a2a5152165714372ddd81f5e7338c8 to your computer and use it in GitHub Desktop.
void apply_output_config(struct output_config *oc, struct sway_output *output) {
struct wlr_output *wlr_output = output->wlr_output;
if (!oc) {
if (!output->enabled) {
if (oc->dpms_state != DPMS_OFF) {
wlr_output_enable(wlr_output, true);
}
output_enable(output, oc);
return;
}
}
if (oc) {
switch (oc->dpms_state) {
case DPMS_ON:
wlr_log(WLR_DEBUG, "Turning on screen");
wlr_output_enable(wlr_output, true);
break;
case DPMS_OFF:
wlr_log(WLR_DEBUG, "Turning off screen");
wlr_output_enable(wlr_output, false);
break;
case DPMS_IGNORE:
break;
}
if (oc->enabled == 0) {
if (output->enabled) {
if (output->bg_pid != 0) {
terminate_swaybg(output->bg_pid);
output->bg_pid = 0;
}
output_disable(output);
wlr_output_layout_remove(root->output_layout, wlr_output);
}
wlr_output_enable(wlr_output, false);
return;
}
if (oc->width > 0 && oc->height > 0) {
wlr_log(WLR_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width,
oc->height, oc->refresh_rate);
set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate);
//TODO: Fix modesetting!
} else if (wlr_output->current_mode == NULL && !wl_list_empty(&wlr_output->modes)) {
struct wlr_output_mode *mode =
wl_container_of(wlr_output->modes.prev, mode, link);
wlr_output_set_mode(wlr_output, mode);
}
if (oc->scale > 0) {
wlr_log(WLR_DEBUG, "Set %s scale to %f", oc->name, oc->scale);
wlr_output_set_scale(wlr_output, oc->scale);
}
if (oc->transform >= 0) {
wlr_log(WLR_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
wlr_output_set_transform(wlr_output, oc->transform);
}
// Find position for it
if (oc->x != -1 || oc->y != -1) {
wlr_log(WLR_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
wlr_output_layout_add(root->output_layout, wlr_output, oc->x, oc->y);
} else {
wlr_output_layout_add_auto(root->output_layout, wlr_output);
}
int output_i;
for (output_i = 0; output_i < root->outputs->length; ++output_i) {
if (root->outputs->items[output_i] == output) {
break;
}
}
if (output->bg_pid != 0) {
terminate_swaybg(output->bg_pid);
}
if (oc->background && config->swaybg_command) {
wlr_log(WLR_DEBUG, "Setting background for output %d to %s",
output_i, oc->background);
size_t len = snprintf(NULL, 0, "%s %d \"%s\" %s %s",
config->swaybg_command, output_i, oc->background,
oc->background_option,
oc->background_fallback ? oc->background_fallback : "");
char *command = malloc(len + 1);
if (!command) {
wlr_log(WLR_DEBUG, "Unable to allocate swaybg command");
return;
}
snprintf(command, len + 1, "%s %d \"%s\" %s %s",
config->swaybg_command, output_i, oc->background,
oc->background_option,
oc->background_fallback ? oc->background_fallback : "");
wlr_log(WLR_DEBUG, "-> %s", command);
char *const cmd[] = { "sh", "-c", command, NULL };
output->bg_pid = fork();
if (output->bg_pid == 0) {
execvp(cmd[0], cmd);
} else {
free(command);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment