2018-11-25 22:12:48 +11:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-03-29 07:38:11 +11:00
|
|
|
#include <assert.h>
|
2017-12-30 05:04:16 +11:00
|
|
|
#include <stdbool.h>
|
2017-12-06 22:36:06 +11:00
|
|
|
#include <string.h>
|
2019-02-17 09:30:19 +11:00
|
|
|
#include <sys/socket.h>
|
2018-03-29 07:38:11 +11:00
|
|
|
#include <sys/wait.h>
|
2018-03-29 09:10:43 +11:00
|
|
|
#include <unistd.h>
|
2019-08-06 19:33:06 +10:00
|
|
|
#include <wlr/types/wlr_cursor.h>
|
2017-12-06 22:57:13 +11:00
|
|
|
#include <wlr/types/wlr_output_layout.h>
|
2019-02-17 09:30:19 +11:00
|
|
|
#include <wlr/types/wlr_output.h>
|
2017-12-06 22:36:06 +11:00
|
|
|
#include "sway/config.h"
|
2019-08-06 19:33:06 +10:00
|
|
|
#include "sway/input/cursor.h"
|
2017-12-06 22:36:06 +11:00
|
|
|
#include "sway/output.h"
|
2018-08-26 12:05:16 +10:00
|
|
|
#include "sway/tree/root.h"
|
2019-02-11 11:56:57 +11:00
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
2017-12-06 22:36:06 +11:00
|
|
|
|
|
|
|
int output_name_cmp(const void *item, const void *data) {
|
|
|
|
const struct output_config *output = item;
|
|
|
|
const char *name = data;
|
|
|
|
|
|
|
|
return strcmp(output->name, name);
|
|
|
|
}
|
|
|
|
|
2017-12-30 05:04:16 +11:00
|
|
|
void output_get_identifier(char *identifier, size_t len,
|
|
|
|
struct sway_output *output) {
|
|
|
|
struct wlr_output *wlr_output = output->wlr_output;
|
|
|
|
snprintf(identifier, len, "%s %s %s", wlr_output->make, wlr_output->model,
|
|
|
|
wlr_output->serial);
|
|
|
|
}
|
|
|
|
|
2019-11-14 05:23:36 +11:00
|
|
|
const char *sway_output_scale_filter_to_string(enum scale_filter_mode scale_filter) {
|
|
|
|
switch (scale_filter) {
|
|
|
|
case SCALE_FILTER_DEFAULT:
|
|
|
|
return "smart";
|
|
|
|
case SCALE_FILTER_LINEAR:
|
|
|
|
return "linear";
|
|
|
|
case SCALE_FILTER_NEAREST:
|
|
|
|
return "nearest";
|
|
|
|
case SCALE_FILTER_SMART:
|
|
|
|
return "smart";
|
|
|
|
}
|
|
|
|
sway_assert(false, "Unknown value for scale_filter.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-28 07:23:30 +11:00
|
|
|
struct output_config *new_output_config(const char *name) {
|
2017-12-07 05:45:43 +11:00
|
|
|
struct output_config *oc = calloc(1, sizeof(struct output_config));
|
|
|
|
if (oc == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-12-28 07:23:30 +11:00
|
|
|
oc->name = strdup(name);
|
|
|
|
if (oc->name == NULL) {
|
|
|
|
free(oc);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-12-06 22:57:13 +11:00
|
|
|
oc->enabled = -1;
|
2017-12-14 10:45:47 +11:00
|
|
|
oc->width = oc->height = -1;
|
2017-12-06 22:57:13 +11:00
|
|
|
oc->refresh_rate = -1;
|
2019-10-27 07:36:49 +11:00
|
|
|
oc->custom_mode = -1;
|
2017-12-06 22:57:13 +11:00
|
|
|
oc->x = oc->y = -1;
|
|
|
|
oc->scale = -1;
|
2019-11-14 05:23:36 +11:00
|
|
|
oc->scale_filter = SCALE_FILTER_DEFAULT;
|
2017-12-06 22:57:13 +11:00
|
|
|
oc->transform = -1;
|
2019-02-11 11:56:57 +11:00
|
|
|
oc->subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
|
2019-09-25 20:58:27 +10:00
|
|
|
oc->max_render_time = -1;
|
2020-03-03 01:30:50 +11:00
|
|
|
oc->adaptive_sync = -1;
|
2017-12-07 05:45:43 +11:00
|
|
|
return oc;
|
2017-12-06 22:57:13 +11:00
|
|
|
}
|
|
|
|
|
2017-12-06 22:36:06 +11:00
|
|
|
void merge_output_config(struct output_config *dst, struct output_config *src) {
|
|
|
|
if (src->enabled != -1) {
|
|
|
|
dst->enabled = src->enabled;
|
|
|
|
}
|
|
|
|
if (src->width != -1) {
|
|
|
|
dst->width = src->width;
|
|
|
|
}
|
|
|
|
if (src->height != -1) {
|
|
|
|
dst->height = src->height;
|
|
|
|
}
|
|
|
|
if (src->x != -1) {
|
|
|
|
dst->x = src->x;
|
|
|
|
}
|
|
|
|
if (src->y != -1) {
|
|
|
|
dst->y = src->y;
|
|
|
|
}
|
|
|
|
if (src->scale != -1) {
|
|
|
|
dst->scale = src->scale;
|
|
|
|
}
|
2019-11-14 05:23:36 +11:00
|
|
|
if (src->scale_filter != SCALE_FILTER_DEFAULT) {
|
|
|
|
dst->scale_filter = src->scale_filter;
|
|
|
|
}
|
2019-02-11 11:56:57 +11:00
|
|
|
if (src->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN) {
|
|
|
|
dst->subpixel = src->subpixel;
|
|
|
|
}
|
2017-12-06 22:57:13 +11:00
|
|
|
if (src->refresh_rate != -1) {
|
|
|
|
dst->refresh_rate = src->refresh_rate;
|
|
|
|
}
|
2019-10-27 07:36:49 +11:00
|
|
|
if (src->custom_mode != -1) {
|
|
|
|
dst->custom_mode = src->custom_mode;
|
|
|
|
}
|
2017-12-06 22:57:13 +11:00
|
|
|
if (src->transform != -1) {
|
|
|
|
dst->transform = src->transform;
|
|
|
|
}
|
2019-09-25 20:58:27 +10:00
|
|
|
if (src->max_render_time != -1) {
|
|
|
|
dst->max_render_time = src->max_render_time;
|
|
|
|
}
|
2020-03-03 01:30:50 +11:00
|
|
|
if (src->adaptive_sync != -1) {
|
|
|
|
dst->adaptive_sync = src->adaptive_sync;
|
|
|
|
}
|
2017-12-06 22:36:06 +11:00
|
|
|
if (src->background) {
|
2017-12-07 05:16:12 +11:00
|
|
|
free(dst->background);
|
2017-12-06 22:36:06 +11:00
|
|
|
dst->background = strdup(src->background);
|
|
|
|
}
|
|
|
|
if (src->background_option) {
|
2017-12-07 05:16:12 +11:00
|
|
|
free(dst->background_option);
|
2017-12-06 22:36:06 +11:00
|
|
|
dst->background_option = strdup(src->background_option);
|
|
|
|
}
|
2018-08-09 03:46:36 +10:00
|
|
|
if (src->background_fallback) {
|
|
|
|
free(dst->background_fallback);
|
|
|
|
dst->background_fallback = strdup(src->background_fallback);
|
|
|
|
}
|
2018-04-17 17:54:02 +10:00
|
|
|
if (src->dpms_state != 0) {
|
|
|
|
dst->dpms_state = src->dpms_state;
|
|
|
|
}
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
|
|
|
|
2018-07-21 02:32:29 +10:00
|
|
|
static void merge_wildcard_on_all(struct output_config *wildcard) {
|
|
|
|
for (int i = 0; i < config->output_configs->length; i++) {
|
|
|
|
struct output_config *oc = config->output_configs->items[i];
|
|
|
|
if (strcmp(wildcard->name, oc->name) != 0) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Merging output * config on %s", oc->name);
|
2018-07-21 02:32:29 +10:00
|
|
|
merge_output_config(oc, wildcard);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 17:20:07 +11:00
|
|
|
static void merge_id_on_name(struct output_config *oc) {
|
|
|
|
char *id_on_name = NULL;
|
|
|
|
char id[128];
|
|
|
|
char *name = NULL;
|
|
|
|
struct sway_output *output;
|
|
|
|
wl_list_for_each(output, &root->all_outputs, link) {
|
|
|
|
name = output->wlr_output->name;
|
|
|
|
output_get_identifier(id, sizeof(id), output);
|
2019-05-10 06:30:08 +10:00
|
|
|
if (strcmp(name, oc->name) == 0 || strcmp(id, oc->name) == 0) {
|
2019-03-15 17:20:07 +11:00
|
|
|
size_t length = snprintf(NULL, 0, "%s on %s", id, name) + 1;
|
|
|
|
id_on_name = malloc(length);
|
|
|
|
if (!id_on_name) {
|
|
|
|
sway_log(SWAY_ERROR, "Failed to allocate id on name string");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
snprintf(id_on_name, length, "%s on %s", id, name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!id_on_name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name);
|
|
|
|
if (i >= 0) {
|
|
|
|
sway_log(SWAY_DEBUG, "Merging on top of existing id on name config");
|
|
|
|
merge_output_config(config->output_configs->items[i], oc);
|
|
|
|
} else {
|
|
|
|
// If both a name and identifier config, exist generate an id on name
|
|
|
|
int ni = list_seq_find(config->output_configs, output_name_cmp, name);
|
|
|
|
int ii = list_seq_find(config->output_configs, output_name_cmp, id);
|
|
|
|
if ((ni >= 0 && ii >= 0) || (ni >= 0 && strcmp(oc->name, id) == 0)
|
|
|
|
|| (ii >= 0 && strcmp(oc->name, name) == 0)) {
|
|
|
|
struct output_config *ion_oc = new_output_config(id_on_name);
|
|
|
|
if (ni >= 0) {
|
|
|
|
merge_output_config(ion_oc, config->output_configs->items[ni]);
|
|
|
|
}
|
|
|
|
if (ii >= 0) {
|
|
|
|
merge_output_config(ion_oc, config->output_configs->items[ii]);
|
|
|
|
}
|
|
|
|
merge_output_config(ion_oc, 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 "
|
2019-09-25 20:58:27 +10:00
|
|
|
"transform %d) (bg %s %s) (dpms %d) (max render time: %d)",
|
|
|
|
ion_oc->name, ion_oc->enabled, ion_oc->width, ion_oc->height,
|
2019-03-15 17:20:07 +11:00
|
|
|
ion_oc->refresh_rate, ion_oc->x, ion_oc->y, ion_oc->scale,
|
|
|
|
ion_oc->transform, ion_oc->background,
|
2019-09-25 20:58:27 +10:00
|
|
|
ion_oc->background_option, ion_oc->dpms_state,
|
|
|
|
ion_oc->max_render_time);
|
2019-03-15 17:20:07 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(id_on_name);
|
|
|
|
}
|
|
|
|
|
2018-07-21 02:32:29 +10:00
|
|
|
struct output_config *store_output_config(struct output_config *oc) {
|
|
|
|
bool wildcard = strcmp(oc->name, "*") == 0;
|
|
|
|
if (wildcard) {
|
|
|
|
merge_wildcard_on_all(oc);
|
2019-03-15 17:20:07 +11:00
|
|
|
} else {
|
|
|
|
merge_id_on_name(oc);
|
2018-07-21 02:32:29 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int i = list_seq_find(config->output_configs, output_name_cmp, oc->name);
|
|
|
|
if (i >= 0) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Merging on top of existing output config");
|
2018-07-21 02:32:29 +10:00
|
|
|
struct output_config *current = config->output_configs->items[i];
|
|
|
|
merge_output_config(current, oc);
|
|
|
|
free_output_config(oc);
|
|
|
|
oc = current;
|
|
|
|
} else if (!wildcard) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Adding non-wildcard output config");
|
2018-07-21 02:32:29 +10:00
|
|
|
i = list_seq_find(config->output_configs, output_name_cmp, "*");
|
|
|
|
if (i >= 0) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Merging on top of output * config");
|
2018-07-21 02:32:29 +10:00
|
|
|
struct output_config *current = new_output_config(oc->name);
|
|
|
|
merge_output_config(current, config->output_configs->items[i]);
|
|
|
|
merge_output_config(current, oc);
|
|
|
|
free_output_config(oc);
|
|
|
|
oc = current;
|
|
|
|
}
|
|
|
|
list_add(config->output_configs, oc);
|
|
|
|
} else {
|
|
|
|
// New wildcard config. Just add it
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Adding output * config");
|
2018-07-21 02:32:29 +10:00
|
|
|
list_add(config->output_configs, oc);
|
|
|
|
}
|
|
|
|
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
|
2019-09-25 20:58:27 +10:00
|
|
|
"position %d,%d scale %f subpixel %s transform %d) (bg %s %s) (dpms %d) "
|
|
|
|
"(max render time: %d)",
|
2018-07-21 02:32:29 +10:00
|
|
|
oc->name, oc->enabled, oc->width, oc->height, oc->refresh_rate,
|
2019-02-11 11:56:57 +11:00
|
|
|
oc->x, oc->y, oc->scale, sway_wl_output_subpixel_to_string(oc->subpixel),
|
2019-09-25 20:58:27 +10:00
|
|
|
oc->transform, oc->background, oc->background_option, oc->dpms_state,
|
|
|
|
oc->max_render_time);
|
2018-07-21 02:32:29 +10:00
|
|
|
|
|
|
|
return oc;
|
|
|
|
}
|
|
|
|
|
2019-12-27 21:47:51 +11:00
|
|
|
static void set_mode(struct wlr_output *output, int width, int height,
|
2019-10-27 07:36:49 +11:00
|
|
|
float refresh_rate, bool custom) {
|
2021-01-16 07:44:22 +11:00
|
|
|
// Not all floating point integers can be represented exactly
|
|
|
|
// as (int)(1000 * mHz / 1000.f)
|
|
|
|
// round() the result to avoid any error
|
|
|
|
int mhz = (int)round(refresh_rate * 1000);
|
2019-10-27 07:36:49 +11:00
|
|
|
|
|
|
|
if (wl_list_empty(&output->modes) || custom) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
|
2019-12-27 21:47:51 +11:00
|
|
|
wlr_output_set_custom_mode(output, width, height,
|
2019-10-27 07:36:49 +11:00
|
|
|
refresh_rate > 0 ? mhz : 0);
|
2019-12-27 21:47:51 +11:00
|
|
|
return;
|
2017-12-12 07:47:40 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_output_mode *mode, *best = NULL;
|
2017-12-06 22:36:06 +11:00
|
|
|
wl_list_for_each(mode, &output->modes, link) {
|
|
|
|
if (mode->width == width && mode->height == height) {
|
|
|
|
if (mode->refresh == mhz) {
|
|
|
|
best = mode;
|
|
|
|
break;
|
|
|
|
}
|
2019-11-06 04:31:41 +11:00
|
|
|
if (best == NULL || mode->refresh > best->refresh) {
|
|
|
|
best = mode;
|
|
|
|
}
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!best) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_ERROR, "Configured mode for %s not available", output->name);
|
2019-11-05 18:11:13 +11:00
|
|
|
sway_log(SWAY_INFO, "Picking preferred mode instead");
|
|
|
|
best = wlr_output_preferred_mode(output);
|
2017-12-06 22:36:06 +11:00
|
|
|
} else {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name);
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
2019-12-27 21:47:51 +11:00
|
|
|
wlr_output_set_mode(output, best);
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
|
|
|
|
2019-12-11 00:40:21 +11:00
|
|
|
/* Some manufacturers hardcode the aspect-ratio of the output in the physical
|
|
|
|
* size field. */
|
|
|
|
static bool phys_size_is_aspect_ratio(struct wlr_output *output) {
|
|
|
|
return (output->phys_width == 1600 && output->phys_height == 900) ||
|
|
|
|
(output->phys_width == 1600 && output->phys_height == 1000) ||
|
|
|
|
(output->phys_width == 160 && output->phys_height == 90) ||
|
|
|
|
(output->phys_width == 160 && output->phys_height == 100) ||
|
|
|
|
(output->phys_width == 16 && output->phys_height == 9) ||
|
|
|
|
(output->phys_width == 16 && output->phys_height == 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The minimum DPI at which we turn on a scale of 2
|
|
|
|
#define HIDPI_DPI_LIMIT (2 * 96)
|
|
|
|
// The minimum screen height at which we turn on a scale of 2
|
|
|
|
#define HIDPI_MIN_HEIGHT 1200
|
|
|
|
// 1 inch = 25.4 mm
|
|
|
|
#define MM_PER_INCH 25.4
|
|
|
|
|
|
|
|
static int compute_default_scale(struct wlr_output *output) {
|
2020-02-11 04:42:45 +11:00
|
|
|
struct wlr_box box = { .width = output->width, .height = output->height };
|
|
|
|
if (output->pending.committed & WLR_OUTPUT_STATE_MODE) {
|
|
|
|
switch (output->pending.mode_type) {
|
|
|
|
case WLR_OUTPUT_STATE_MODE_FIXED:
|
|
|
|
box.width = output->pending.mode->width;
|
|
|
|
box.height = output->pending.mode->height;
|
|
|
|
break;
|
|
|
|
case WLR_OUTPUT_STATE_MODE_CUSTOM:
|
|
|
|
box.width = output->pending.custom_mode.width;
|
|
|
|
box.height = output->pending.custom_mode.height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enum wl_output_transform transform = output->transform;
|
|
|
|
if (output->pending.committed & WLR_OUTPUT_STATE_TRANSFORM) {
|
|
|
|
transform = output->pending.transform;
|
|
|
|
}
|
|
|
|
wlr_box_transform(&box, &box, transform, box.width, box.height);
|
|
|
|
|
|
|
|
int width = box.width;
|
|
|
|
int height = box.height;
|
|
|
|
|
2019-12-11 00:40:21 +11:00
|
|
|
if (height < HIDPI_MIN_HEIGHT) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output->phys_width == 0 || output->phys_height == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phys_size_is_aspect_ratio(output)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
double dpi_x = (double) width / (output->phys_width / MM_PER_INCH);
|
|
|
|
double dpi_y = (double) height / (output->phys_height / MM_PER_INCH);
|
|
|
|
sway_log(SWAY_DEBUG, "Output DPI: %fx%f", dpi_x, dpi_y);
|
|
|
|
if (dpi_x <= HIDPI_DPI_LIMIT || dpi_y <= HIDPI_DPI_LIMIT) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2020-04-08 19:22:51 +10:00
|
|
|
static void queue_output_config(struct output_config *oc,
|
|
|
|
struct sway_output *output) {
|
2019-01-20 20:05:28 +11:00
|
|
|
if (output == root->noop_output) {
|
2020-04-08 19:22:51 +10:00
|
|
|
return;
|
2019-01-20 20:05:28 +11:00
|
|
|
}
|
|
|
|
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
struct wlr_output *wlr_output = output->wlr_output;
|
2018-04-04 11:06:13 +10:00
|
|
|
|
2020-04-08 19:22:51 +10:00
|
|
|
if (oc && (!oc->enabled || oc->dpms_state == DPMS_OFF)) {
|
|
|
|
sway_log(SWAY_DEBUG, "Turning off output %s", wlr_output->name);
|
2018-09-06 04:00:00 +10:00
|
|
|
wlr_output_enable(wlr_output, false);
|
2020-04-08 19:22:51 +10:00
|
|
|
return;
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
|
|
|
|
2020-04-09 18:01:21 +10:00
|
|
|
sway_log(SWAY_DEBUG, "Turning on output %s", wlr_output->name);
|
|
|
|
wlr_output_enable(wlr_output, true);
|
|
|
|
|
|
|
|
if (oc && oc->width > 0 && oc->height > 0) {
|
|
|
|
sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)",
|
|
|
|
wlr_output->name, oc->width, oc->height, oc->refresh_rate);
|
|
|
|
set_mode(wlr_output, oc->width, oc->height,
|
|
|
|
oc->refresh_rate, oc->custom_mode == 1);
|
|
|
|
} else if (!wl_list_empty(&wlr_output->modes)) {
|
|
|
|
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
|
|
|
|
wlr_output_set_mode(wlr_output, mode);
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
2019-01-18 08:30:24 +11:00
|
|
|
|
2019-02-11 11:56:57 +11:00
|
|
|
if (oc && (oc->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN || config->reloading)) {
|
|
|
|
sway_log(SWAY_DEBUG, "Set %s subpixel to %s", oc->name,
|
|
|
|
sway_wl_output_subpixel_to_string(oc->subpixel));
|
|
|
|
wlr_output_set_subpixel(wlr_output, oc->subpixel);
|
|
|
|
}
|
|
|
|
|
2017-12-06 22:57:13 +11:00
|
|
|
if (oc && oc->transform >= 0) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
|
2017-12-14 01:52:18 +11:00
|
|
|
wlr_output_set_transform(wlr_output, oc->transform);
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
|
|
|
|
2020-02-11 04:42:45 +11:00
|
|
|
// Apply the scale last before the commit, because the scale auto-detection
|
|
|
|
// reads the pending output size
|
|
|
|
float scale;
|
|
|
|
if (oc && oc->scale > 0) {
|
|
|
|
scale = oc->scale;
|
|
|
|
} else {
|
|
|
|
scale = compute_default_scale(wlr_output);
|
|
|
|
sway_log(SWAY_DEBUG, "Auto-detected output scale: %f", scale);
|
|
|
|
}
|
|
|
|
if (scale != wlr_output->scale) {
|
2020-02-13 22:54:48 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Set %s scale to %f", wlr_output->name, scale);
|
2020-02-11 04:42:45 +11:00
|
|
|
wlr_output_set_scale(wlr_output, scale);
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:30:50 +11:00
|
|
|
if (oc && oc->adaptive_sync != -1) {
|
2020-04-08 19:22:51 +10:00
|
|
|
sway_log(SWAY_DEBUG, "Set %s adaptive sync to %d", wlr_output->name,
|
|
|
|
oc->adaptive_sync);
|
2020-03-03 01:30:50 +11:00
|
|
|
wlr_output_enable_adaptive_sync(wlr_output, oc->adaptive_sync == 1);
|
|
|
|
}
|
2020-04-08 19:22:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
|
|
|
if (output == root->noop_output) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_output *wlr_output = output->wlr_output;
|
|
|
|
|
2020-07-11 02:04:45 +10:00
|
|
|
// Flag to prevent the output mode event handler from calling us
|
|
|
|
output->enabling = (!oc || oc->enabled);
|
2020-04-08 19:22:51 +10:00
|
|
|
|
|
|
|
queue_output_config(oc, output);
|
|
|
|
|
|
|
|
if (!oc || oc->dpms_state != DPMS_OFF) {
|
|
|
|
output->current_mode = wlr_output->pending.mode;
|
|
|
|
}
|
2020-03-03 01:30:50 +11:00
|
|
|
|
2019-12-27 21:47:51 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name);
|
|
|
|
if (!wlr_output_commit(wlr_output)) {
|
2020-04-08 19:22:51 +10:00
|
|
|
// Failed to commit output changes, maybe the output is missing a CRTC.
|
|
|
|
// Leave the output disabled for now and try again when the output gets
|
|
|
|
// the mode we asked for.
|
|
|
|
sway_log(SWAY_ERROR, "Failed to commit output %s", wlr_output->name);
|
2020-07-11 02:04:45 +10:00
|
|
|
output->enabling = false;
|
2019-12-27 21:47:51 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-11 02:04:45 +10:00
|
|
|
output->enabling = false;
|
|
|
|
|
2020-04-09 18:18:40 +10:00
|
|
|
if (oc && !oc->enabled) {
|
2020-07-11 02:04:45 +10:00
|
|
|
sway_log(SWAY_DEBUG, "Disabling output %s", oc->name);
|
|
|
|
if (output->enabled) {
|
|
|
|
output_disable(output);
|
|
|
|
wlr_output_layout_remove(root->output_layout, wlr_output);
|
|
|
|
}
|
2020-04-09 18:18:40 +10:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-08 19:22:51 +10:00
|
|
|
if (config->reloading) {
|
|
|
|
output_damage_whole(output);
|
|
|
|
}
|
|
|
|
|
2020-02-12 00:23:29 +11:00
|
|
|
if (oc) {
|
|
|
|
enum scale_filter_mode scale_filter_old = output->scale_filter;
|
|
|
|
switch (oc->scale_filter) {
|
|
|
|
case SCALE_FILTER_DEFAULT:
|
|
|
|
case SCALE_FILTER_SMART:
|
|
|
|
output->scale_filter = ceilf(wlr_output->scale) == wlr_output->scale ?
|
|
|
|
SCALE_FILTER_NEAREST : SCALE_FILTER_LINEAR;
|
|
|
|
break;
|
|
|
|
case SCALE_FILTER_LINEAR:
|
|
|
|
case SCALE_FILTER_NEAREST:
|
|
|
|
output->scale_filter = oc->scale_filter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (scale_filter_old != output->scale_filter) {
|
|
|
|
sway_log(SWAY_DEBUG, "Set %s scale_filter to %s", oc->name,
|
|
|
|
sway_output_scale_filter_to_string(output->scale_filter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 22:36:06 +11:00
|
|
|
// Find position for it
|
2017-12-06 22:57:13 +11:00
|
|
|
if (oc && (oc->x != -1 || oc->y != -1)) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
wlr_output_layout_add(root->output_layout, wlr_output, oc->x, oc->y);
|
2017-12-06 22:36:06 +11:00
|
|
|
} else {
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
wlr_output_layout_add_auto(root->output_layout, wlr_output);
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
|
|
|
|
2019-03-11 21:45:01 +11:00
|
|
|
// Update output->{lx, ly, width, height}
|
|
|
|
struct wlr_box *output_box =
|
|
|
|
wlr_output_layout_get_box(root->output_layout, wlr_output);
|
|
|
|
output->lx = output_box->x;
|
|
|
|
output->ly = output_box->y;
|
2019-07-11 03:53:27 +10:00
|
|
|
output->width = output_box->width;
|
|
|
|
output->height = output_box->height;
|
2018-10-09 00:08:33 +11:00
|
|
|
|
2020-07-11 02:04:45 +10:00
|
|
|
if (!output->enabled) {
|
|
|
|
output_enable(output);
|
2020-02-12 00:17:33 +11:00
|
|
|
}
|
|
|
|
|
2019-09-25 20:58:27 +10:00
|
|
|
if (oc && oc->max_render_time >= 0) {
|
|
|
|
sway_log(SWAY_DEBUG, "Set %s max render time to %d",
|
|
|
|
oc->name, oc->max_render_time);
|
|
|
|
output->max_render_time = oc->max_render_time;
|
|
|
|
}
|
|
|
|
|
2020-04-26 09:06:51 +10:00
|
|
|
// Reconfigure all devices, since input config may have been applied before
|
|
|
|
// this output came online, and some config items (like map_to_output) are
|
|
|
|
// dependent on an output being present.
|
2020-06-19 12:26:27 +10:00
|
|
|
input_manager_configure_all_inputs();
|
2021-02-25 05:50:34 +11:00
|
|
|
// Reconfigure the cursor images, since the scale may have changed.
|
|
|
|
input_manager_configure_xcursor();
|
2019-01-18 08:30:24 +11:00
|
|
|
return true;
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
|
|
|
|
2020-04-08 19:22:51 +10:00
|
|
|
bool test_output_config(struct output_config *oc, struct sway_output *output) {
|
|
|
|
if (output == root->noop_output) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
queue_output_config(oc, output);
|
|
|
|
bool ok = wlr_output_test(output->wlr_output);
|
|
|
|
wlr_output_rollback(output->wlr_output);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2018-12-13 04:13:03 +11:00
|
|
|
static void default_output_config(struct output_config *oc,
|
|
|
|
struct wlr_output *wlr_output) {
|
|
|
|
oc->enabled = 1;
|
2019-11-05 18:11:13 +11:00
|
|
|
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
|
|
|
|
if (mode != NULL) {
|
2019-08-07 16:13:15 +10:00
|
|
|
oc->width = mode->width;
|
|
|
|
oc->height = mode->height;
|
2019-10-21 08:10:39 +11:00
|
|
|
oc->refresh_rate = mode->refresh / 1000.f;
|
2018-12-13 04:13:03 +11:00
|
|
|
}
|
|
|
|
oc->x = oc->y = -1;
|
2019-12-11 00:40:21 +11:00
|
|
|
oc->scale = 0; // auto
|
2019-11-14 05:23:36 +11:00
|
|
|
oc->scale_filter = SCALE_FILTER_DEFAULT;
|
2019-02-11 11:56:57 +11:00
|
|
|
struct sway_output *output = wlr_output->data;
|
|
|
|
oc->subpixel = output->detected_subpixel;
|
2018-12-13 04:13:03 +11:00
|
|
|
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
2019-02-15 19:01:19 +11:00
|
|
|
oc->dpms_state = DPMS_ON;
|
2019-09-25 20:58:27 +10:00
|
|
|
oc->max_render_time = 0;
|
2018-12-13 04:13:03 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct output_config *get_output_config(char *identifier,
|
|
|
|
struct sway_output *sway_output) {
|
|
|
|
const char *name = sway_output->wlr_output->name;
|
2018-07-21 12:17:20 +10:00
|
|
|
|
2019-03-15 17:20:07 +11:00
|
|
|
struct output_config *oc_id_on_name = NULL;
|
|
|
|
struct output_config *oc_name = NULL;
|
2018-12-03 13:49:09 +11:00
|
|
|
struct output_config *oc_id = NULL;
|
2019-03-15 17:20:07 +11:00
|
|
|
|
|
|
|
size_t length = snprintf(NULL, 0, "%s on %s", identifier, name) + 1;
|
|
|
|
char *id_on_name = malloc(length);
|
|
|
|
snprintf(id_on_name, length, "%s on %s", identifier, name);
|
|
|
|
int i = list_seq_find(config->output_configs, output_name_cmp, id_on_name);
|
2018-07-21 12:17:20 +10:00
|
|
|
if (i >= 0) {
|
2019-03-15 17:20:07 +11:00
|
|
|
oc_id_on_name = config->output_configs->items[i];
|
|
|
|
} else {
|
|
|
|
i = list_seq_find(config->output_configs, output_name_cmp, name);
|
|
|
|
if (i >= 0) {
|
|
|
|
oc_name = config->output_configs->items[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
i = list_seq_find(config->output_configs, output_name_cmp, identifier);
|
|
|
|
if (i >= 0) {
|
|
|
|
oc_id = config->output_configs->items[i];
|
|
|
|
}
|
2018-07-21 12:17:20 +10:00
|
|
|
}
|
|
|
|
|
2019-02-27 06:49:42 +11:00
|
|
|
struct output_config *result = new_output_config("temp");
|
2018-12-13 04:13:03 +11:00
|
|
|
if (config->reloading) {
|
|
|
|
default_output_config(result, sway_output->wlr_output);
|
|
|
|
}
|
2019-03-15 17:20:07 +11:00
|
|
|
if (oc_id_on_name) {
|
|
|
|
// Already have an identifier on name config, use that
|
|
|
|
free(result->name);
|
|
|
|
result->name = strdup(id_on_name);
|
|
|
|
merge_output_config(result, oc_id_on_name);
|
|
|
|
} else if (oc_name && oc_id) {
|
2018-12-03 13:49:09 +11:00
|
|
|
// Generate a config named `<identifier> on <name>` which contains a
|
|
|
|
// merged copy of the identifier on name. This will make sure that both
|
|
|
|
// identifier and name configs are respected, with identifier getting
|
|
|
|
// priority
|
2019-03-15 17:20:07 +11:00
|
|
|
struct output_config *temp = new_output_config(id_on_name);
|
|
|
|
merge_output_config(temp, oc_name);
|
|
|
|
merge_output_config(temp, oc_id);
|
|
|
|
list_add(config->output_configs, temp);
|
2018-12-03 13:49:09 +11:00
|
|
|
|
2018-12-13 04:13:03 +11:00
|
|
|
free(result->name);
|
2019-03-15 17:20:07 +11:00
|
|
|
result->name = strdup(id_on_name);
|
|
|
|
merge_output_config(result, temp);
|
2018-12-03 13:49:09 +11:00
|
|
|
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Generated output config \"%s\" (enabled: %d)"
|
2018-12-03 13:49:09 +11:00
|
|
|
" (%dx%d@%fHz position %d,%d scale %f transform %d) (bg %s %s)"
|
2019-09-25 20:58:27 +10:00
|
|
|
" (dpms %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->max_render_time);
|
2018-12-03 13:49:09 +11:00
|
|
|
} else if (oc_name) {
|
|
|
|
// No identifier config, just return a copy of the name config
|
2018-12-13 04:13:03 +11:00
|
|
|
free(result->name);
|
|
|
|
result->name = strdup(name);
|
2018-12-03 13:49:09 +11:00
|
|
|
merge_output_config(result, oc_name);
|
|
|
|
} else if (oc_id) {
|
|
|
|
// No name config, just return a copy of the identifier config
|
2018-12-13 04:13:03 +11:00
|
|
|
free(result->name);
|
|
|
|
result->name = strdup(identifier);
|
2018-12-03 13:49:09 +11:00
|
|
|
merge_output_config(result, oc_id);
|
2019-03-17 13:45:06 +11:00
|
|
|
} else {
|
2018-12-13 04:13:03 +11:00
|
|
|
i = list_seq_find(config->output_configs, output_name_cmp, "*");
|
|
|
|
if (i >= 0) {
|
2019-03-17 13:45:06 +11:00
|
|
|
// No name or identifier config, but there is a wildcard config
|
|
|
|
free(result->name);
|
|
|
|
result->name = strdup("*");
|
2018-12-13 04:13:03 +11:00
|
|
|
merge_output_config(result, config->output_configs->items[i]);
|
2019-03-17 13:45:06 +11:00
|
|
|
} else if (!config->reloading) {
|
|
|
|
// No name, identifier, or wildcard config. Since we are not
|
|
|
|
// reloading with defaults, the output config will be empty, so
|
|
|
|
// just return NULL
|
|
|
|
free_output_config(result);
|
|
|
|
result = NULL;
|
2018-12-13 04:13:03 +11:00
|
|
|
}
|
2018-12-03 13:49:09 +11:00
|
|
|
}
|
|
|
|
|
2019-03-15 17:20:07 +11:00
|
|
|
free(id_on_name);
|
2018-12-03 13:49:09 +11:00
|
|
|
return result;
|
2018-07-21 12:17:20 +10:00
|
|
|
}
|
|
|
|
|
Fix output config retrieval for new outputs
This removes `output_find_config`, which would take the first matching
output config it found. This is fine if only a name output config,
identifier output config, or even just wildcard exist, but if there is
a name output config and identifier output config, they are not merged.
Instead, this introduces find_output_config, which is just a wrapper
for `get_output_config`. This ensures that both the name and identifier
output configs are respected.
This fixes the following case:
- For simplicity in this example, remove all output configs from config
- Run `swaymsg output <name> bg #ff0000 solid_color`
- Run `swaymsg output <identifier> scale 2`
- Disconnect and reconnect output
Without this, the output will have the background, but not the scale.
With this, the output will have both the background and scale
2019-03-16 06:09:55 +11:00
|
|
|
struct output_config *find_output_config(struct sway_output *output) {
|
|
|
|
char id[128];
|
|
|
|
output_get_identifier(id, sizeof(id), output);
|
|
|
|
return get_output_config(id, output);
|
|
|
|
}
|
|
|
|
|
2018-07-21 12:17:20 +10:00
|
|
|
void apply_output_config_to_outputs(struct output_config *oc) {
|
|
|
|
// Try to find the output container and apply configuration now. If
|
|
|
|
// this is during startup then there will be no container and config
|
|
|
|
// will be applied during normal "new output" event from wlroots.
|
|
|
|
bool wildcard = strcmp(oc->name, "*") == 0;
|
|
|
|
char id[128];
|
2020-01-17 13:26:15 +11:00
|
|
|
struct sway_output *sway_output, *tmp;
|
|
|
|
wl_list_for_each_safe(sway_output, tmp, &root->all_outputs, link) {
|
2018-07-21 12:17:20 +10:00
|
|
|
char *name = sway_output->wlr_output->name;
|
|
|
|
output_get_identifier(id, sizeof(id), sway_output);
|
|
|
|
if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) {
|
2019-03-15 17:20:07 +11:00
|
|
|
struct output_config *current = get_output_config(id, sway_output);
|
|
|
|
if (!current) {
|
|
|
|
// No stored output config matched, apply oc directly
|
|
|
|
sway_log(SWAY_DEBUG, "Applying oc directly");
|
|
|
|
current = new_output_config(oc->name);
|
|
|
|
merge_output_config(current, oc);
|
2018-07-21 12:17:20 +10:00
|
|
|
}
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
apply_output_config(current, sway_output);
|
2018-12-03 13:49:09 +11:00
|
|
|
free_output_config(current);
|
2018-07-21 12:17:20 +10:00
|
|
|
|
|
|
|
if (!wildcard) {
|
|
|
|
// Stop looking if the output config isn't applicable to all
|
|
|
|
// outputs
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-06 19:33:06 +10:00
|
|
|
|
|
|
|
struct sway_seat *seat;
|
|
|
|
wl_list_for_each(seat, &server.input->seats, link) {
|
2020-05-21 11:20:19 +10:00
|
|
|
wlr_seat_pointer_notify_clear_focus(seat->wlr_seat);
|
2019-08-06 19:33:06 +10:00
|
|
|
cursor_rebase(seat->cursor);
|
|
|
|
}
|
2018-07-21 12:17:20 +10:00
|
|
|
}
|
|
|
|
|
2019-02-17 08:14:27 +11:00
|
|
|
void reset_outputs(void) {
|
|
|
|
struct output_config *oc = NULL;
|
|
|
|
int i = list_seq_find(config->output_configs, output_name_cmp, "*");
|
|
|
|
if (i >= 0) {
|
|
|
|
oc = config->output_configs->items[i];
|
|
|
|
} else {
|
|
|
|
oc = store_output_config(new_output_config("*"));
|
|
|
|
}
|
|
|
|
apply_output_config_to_outputs(oc);
|
|
|
|
}
|
|
|
|
|
2017-12-06 22:36:06 +11:00
|
|
|
void free_output_config(struct output_config *oc) {
|
|
|
|
if (!oc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(oc->name);
|
|
|
|
free(oc->background);
|
|
|
|
free(oc->background_option);
|
|
|
|
free(oc);
|
|
|
|
}
|
2019-04-04 12:53:43 +11:00
|
|
|
|
|
|
|
static void handle_swaybg_client_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
2019-05-04 13:26:18 +10:00
|
|
|
struct sway_config *sway_config =
|
|
|
|
wl_container_of(listener, sway_config, swaybg_client_destroy);
|
|
|
|
wl_list_remove(&sway_config->swaybg_client_destroy.link);
|
|
|
|
wl_list_init(&sway_config->swaybg_client_destroy.link);
|
|
|
|
sway_config->swaybg_client = NULL;
|
2019-04-04 12:53:43 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool _spawn_swaybg(char **command) {
|
|
|
|
if (config->swaybg_client != NULL) {
|
|
|
|
wl_client_destroy(config->swaybg_client);
|
|
|
|
}
|
|
|
|
int sockets[2];
|
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "socketpair failed");
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-29 16:54:16 +11:00
|
|
|
if (!sway_set_cloexec(sockets[0], true) || !sway_set_cloexec(sockets[1], true)) {
|
2019-04-04 12:53:43 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
config->swaybg_client = wl_client_create(server.wl_display, sockets[0]);
|
|
|
|
if (config->swaybg_client == NULL) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "wl_client_create failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
config->swaybg_client_destroy.notify = handle_swaybg_client_destroy;
|
|
|
|
wl_client_add_destroy_listener(config->swaybg_client,
|
|
|
|
&config->swaybg_client_destroy);
|
|
|
|
|
|
|
|
pid_t pid = fork();
|
|
|
|
if (pid < 0) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "fork failed");
|
|
|
|
return false;
|
|
|
|
} else if (pid == 0) {
|
|
|
|
pid = fork();
|
|
|
|
if (pid < 0) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "fork failed");
|
|
|
|
_exit(EXIT_FAILURE);
|
|
|
|
} else if (pid == 0) {
|
2019-10-29 16:54:16 +11:00
|
|
|
if (!sway_set_cloexec(sockets[1], false)) {
|
2019-04-04 12:53:43 +11:00
|
|
|
_exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
char wayland_socket_str[16];
|
|
|
|
snprintf(wayland_socket_str, sizeof(wayland_socket_str),
|
|
|
|
"%d", sockets[1]);
|
|
|
|
setenv("WAYLAND_SOCKET", wayland_socket_str, true);
|
|
|
|
|
|
|
|
execvp(command[0], command);
|
|
|
|
sway_log_errno(SWAY_ERROR, "execvp failed");
|
|
|
|
_exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
_exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (close(sockets[1]) != 0) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "close failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (waitpid(pid, NULL, 0) < 0) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "waitpid failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool spawn_swaybg(void) {
|
|
|
|
if (!config->swaybg_command) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t length = 2;
|
|
|
|
for (int i = 0; i < config->output_configs->length; i++) {
|
|
|
|
struct output_config *oc = config->output_configs->items[i];
|
|
|
|
if (!oc->background) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(oc->background_option, "solid_color") == 0) {
|
|
|
|
length += 4;
|
|
|
|
} else if (oc->background_fallback) {
|
|
|
|
length += 8;
|
|
|
|
} else {
|
|
|
|
length += 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 02:46:11 +10:00
|
|
|
char **cmd = calloc(length, sizeof(char *));
|
2019-04-04 12:53:43 +11:00
|
|
|
if (!cmd) {
|
|
|
|
sway_log(SWAY_ERROR, "Failed to allocate spawn_swaybg command");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
cmd[i++] = config->swaybg_command;
|
|
|
|
for (int j = 0; j < config->output_configs->length; j++) {
|
|
|
|
struct output_config *oc = config->output_configs->items[j];
|
|
|
|
if (!oc->background) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(oc->background_option, "solid_color") == 0) {
|
|
|
|
cmd[i++] = "-o";
|
|
|
|
cmd[i++] = oc->name;
|
|
|
|
cmd[i++] = "-c";
|
|
|
|
cmd[i++] = oc->background;
|
|
|
|
} else {
|
|
|
|
cmd[i++] = "-o";
|
|
|
|
cmd[i++] = oc->name;
|
|
|
|
cmd[i++] = "-i";
|
|
|
|
cmd[i++] = oc->background;
|
|
|
|
cmd[i++] = "-m";
|
|
|
|
cmd[i++] = oc->background_option;
|
|
|
|
if (oc->background_fallback) {
|
|
|
|
cmd[i++] = "-c";
|
|
|
|
cmd[i++] = oc->background_fallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(i <= length);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t k = 0; k < i; k++) {
|
2019-04-09 05:18:42 +10:00
|
|
|
sway_log(SWAY_DEBUG, "spawn_swaybg cmd[%zd] = %s", k, cmd[k]);
|
2019-04-04 12:53:43 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
bool result = _spawn_swaybg(cmd);
|
|
|
|
free(cmd);
|
|
|
|
return result;
|
|
|
|
}
|