2018-11-25 12:12:48 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-03-28 22:38:11 +02:00
|
|
|
#include <assert.h>
|
2019-02-16 23:30:19 +01:00
|
|
|
#include <fcntl.h>
|
2017-12-29 19:04:16 +01:00
|
|
|
#include <stdbool.h>
|
2017-12-06 12:36:06 +01:00
|
|
|
#include <string.h>
|
2019-02-16 23:30:19 +01:00
|
|
|
#include <sys/socket.h>
|
2018-03-28 22:38:11 +02:00
|
|
|
#include <sys/wait.h>
|
2018-03-29 00:10:43 +02:00
|
|
|
#include <unistd.h>
|
2017-12-06 12:57:13 +01:00
|
|
|
#include <wlr/types/wlr_output_layout.h>
|
2019-02-16 23:30:19 +01:00
|
|
|
#include <wlr/types/wlr_output.h>
|
|
|
|
#include "log.h"
|
2017-12-06 12:36:06 +01:00
|
|
|
#include "sway/config.h"
|
|
|
|
#include "sway/output.h"
|
2018-08-26 04:05:16 +02:00
|
|
|
#include "sway/tree/root.h"
|
2017-12-06 12:36:06 +01: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-29 19:04:16 +01: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);
|
|
|
|
}
|
|
|
|
|
2017-12-27 21:23:30 +01:00
|
|
|
struct output_config *new_output_config(const char *name) {
|
2017-12-06 19:45:43 +01:00
|
|
|
struct output_config *oc = calloc(1, sizeof(struct output_config));
|
|
|
|
if (oc == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-12-27 21:23:30 +01:00
|
|
|
oc->name = strdup(name);
|
|
|
|
if (oc->name == NULL) {
|
|
|
|
free(oc);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-12-06 12:57:13 +01:00
|
|
|
oc->enabled = -1;
|
2017-12-14 00:45:47 +01:00
|
|
|
oc->width = oc->height = -1;
|
2017-12-06 12:57:13 +01:00
|
|
|
oc->refresh_rate = -1;
|
|
|
|
oc->x = oc->y = -1;
|
|
|
|
oc->scale = -1;
|
|
|
|
oc->transform = -1;
|
2017-12-06 19:45:43 +01:00
|
|
|
return oc;
|
2017-12-06 12:57:13 +01:00
|
|
|
}
|
|
|
|
|
2017-12-06 12:36:06 +01: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;
|
|
|
|
}
|
2017-12-06 12:57:13 +01:00
|
|
|
if (src->refresh_rate != -1) {
|
|
|
|
dst->refresh_rate = src->refresh_rate;
|
|
|
|
}
|
|
|
|
if (src->transform != -1) {
|
|
|
|
dst->transform = src->transform;
|
|
|
|
}
|
2017-12-06 12:36:06 +01:00
|
|
|
if (src->background) {
|
2017-12-06 19:16:12 +01:00
|
|
|
free(dst->background);
|
2017-12-06 12:36:06 +01:00
|
|
|
dst->background = strdup(src->background);
|
|
|
|
}
|
|
|
|
if (src->background_option) {
|
2017-12-06 19:16:12 +01:00
|
|
|
free(dst->background_option);
|
2017-12-06 12:36:06 +01:00
|
|
|
dst->background_option = strdup(src->background_option);
|
|
|
|
}
|
2018-08-08 19:46:36 +02:00
|
|
|
if (src->background_fallback) {
|
|
|
|
free(dst->background_fallback);
|
|
|
|
dst->background_fallback = strdup(src->background_fallback);
|
|
|
|
}
|
2018-04-17 09:54:02 +02:00
|
|
|
if (src->dpms_state != 0) {
|
|
|
|
dst->dpms_state = src->dpms_state;
|
|
|
|
}
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
|
|
|
|
2018-07-20 18:32:29 +02: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-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Merging output * config on %s", oc->name);
|
2018-07-20 18:32:29 +02:00
|
|
|
merge_output_config(oc, wildcard);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct output_config *store_output_config(struct output_config *oc) {
|
|
|
|
bool wildcard = strcmp(oc->name, "*") == 0;
|
|
|
|
if (wildcard) {
|
|
|
|
merge_wildcard_on_all(oc);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = list_seq_find(config->output_configs, output_name_cmp, oc->name);
|
|
|
|
if (i >= 0) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Merging on top of existing output config");
|
2018-07-20 18:32:29 +02: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-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Adding non-wildcard output config");
|
2018-07-20 18:32:29 +02:00
|
|
|
i = list_seq_find(config->output_configs, output_name_cmp, "*");
|
|
|
|
if (i >= 0) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Merging on top of output * config");
|
2018-07-20 18:32:29 +02: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-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Adding output * config");
|
2018-07-20 18:32:29 +02:00
|
|
|
list_add(config->output_configs, oc);
|
|
|
|
}
|
|
|
|
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
|
2018-07-20 18:32:29 +02:00
|
|
|
"position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)",
|
|
|
|
oc->name, oc->enabled, oc->width, oc->height, oc->refresh_rate,
|
|
|
|
oc->x, oc->y, oc->scale, oc->transform, oc->background,
|
|
|
|
oc->background_option, oc->dpms_state);
|
|
|
|
|
|
|
|
return oc;
|
|
|
|
}
|
|
|
|
|
2019-01-17 22:30:24 +01:00
|
|
|
static bool set_mode(struct wlr_output *output, int width, int height,
|
2017-12-06 12:36:06 +01:00
|
|
|
float refresh_rate) {
|
|
|
|
int mhz = (int)(refresh_rate * 1000);
|
2017-12-11 21:47:40 +01:00
|
|
|
if (wl_list_empty(&output->modes)) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
|
2019-01-17 22:30:24 +01:00
|
|
|
return wlr_output_set_custom_mode(output, width, height, mhz);
|
2017-12-11 21:47:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_output_mode *mode, *best = NULL;
|
2017-12-06 12:36:06 +01:00
|
|
|
wl_list_for_each(mode, &output->modes, link) {
|
|
|
|
if (mode->width == width && mode->height == height) {
|
|
|
|
if (mode->refresh == mhz) {
|
|
|
|
best = mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
best = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!best) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_ERROR, "Configured mode for %s not available", output->name);
|
|
|
|
sway_log(SWAY_INFO, "Picking default mode instead");
|
2019-01-17 22:30:24 +01:00
|
|
|
best = wl_container_of(output->modes.prev, mode, link);
|
2017-12-06 12:36:06 +01:00
|
|
|
} else {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name);
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
2019-01-17 22:30:24 +01:00
|
|
|
return wlr_output_set_mode(output, best);
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
|
|
|
|
2019-02-16 23:30:19 +01:00
|
|
|
static void handle_swaybg_client_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct sway_output *output =
|
|
|
|
wl_container_of(listener, output, swaybg_client_destroy);
|
|
|
|
wl_list_remove(&output->swaybg_client_destroy.link);
|
|
|
|
wl_list_init(&output->swaybg_client_destroy.link);
|
|
|
|
output->swaybg_client = NULL;
|
|
|
|
}
|
|
|
|
|
2019-02-19 16:18:31 +01:00
|
|
|
static bool set_cloexec(int fd, bool cloexec) {
|
|
|
|
int flags = fcntl(fd, F_GETFD);
|
|
|
|
if (flags == -1) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "fcntl failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (cloexec) {
|
|
|
|
flags = flags | FD_CLOEXEC;
|
|
|
|
} else {
|
|
|
|
flags = flags & ~FD_CLOEXEC;
|
|
|
|
}
|
|
|
|
if (fcntl(fd, F_SETFD, flags) == -1) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "fcntl failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-16 23:30:19 +01:00
|
|
|
static bool spawn_swaybg(struct sway_output *output, char *const cmd[]) {
|
|
|
|
int sockets[2];
|
2019-02-19 16:18:31 +01:00
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0) {
|
2019-02-16 23:30:19 +01:00
|
|
|
sway_log_errno(SWAY_ERROR, "socketpair failed");
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-19 16:18:31 +01:00
|
|
|
if (!set_cloexec(sockets[0], true) || !set_cloexec(sockets[1], true)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-16 23:30:19 +01:00
|
|
|
|
|
|
|
output->swaybg_client = wl_client_create(server.wl_display, sockets[0]);
|
|
|
|
if (output->swaybg_client == NULL) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "wl_client_create failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->swaybg_client_destroy.notify = handle_swaybg_client_destroy;
|
|
|
|
wl_client_add_destroy_listener(output->swaybg_client,
|
|
|
|
&output->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");
|
2019-03-02 22:09:14 +01:00
|
|
|
_exit(EXIT_FAILURE);
|
2019-02-16 23:30:19 +01:00
|
|
|
} else if (pid == 0) {
|
2019-02-19 16:18:31 +01:00
|
|
|
if (!set_cloexec(sockets[1], false)) {
|
2019-03-02 22:09:14 +01:00
|
|
|
_exit(EXIT_FAILURE);
|
2019-02-16 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
char wayland_socket_str[16];
|
|
|
|
snprintf(wayland_socket_str, sizeof(wayland_socket_str),
|
|
|
|
"%d", sockets[1]);
|
|
|
|
setenv("WAYLAND_SOCKET", wayland_socket_str, true);
|
|
|
|
|
|
|
|
execvp(cmd[0], cmd);
|
|
|
|
sway_log_errno(SWAY_ERROR, "execvp failed");
|
2019-03-02 22:09:14 +01:00
|
|
|
_exit(EXIT_FAILURE);
|
2019-02-16 23:30:19 +01:00
|
|
|
}
|
2019-03-02 22:09:14 +01:00
|
|
|
_exit(EXIT_SUCCESS);
|
2018-03-28 22:38:11 +02:00
|
|
|
}
|
2019-02-16 23:30:19 +01:00
|
|
|
|
2019-02-19 16:18:31 +01:00
|
|
|
if (close(sockets[1]) != 0) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "close failed");
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-16 23:30:19 +01:00
|
|
|
if (waitpid(pid, NULL, 0) < 0) {
|
|
|
|
sway_log_errno(SWAY_ERROR, "waitpid failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-03-28 22:38:11 +02:00
|
|
|
}
|
|
|
|
|
2019-01-17 22:30:24 +01:00
|
|
|
bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
2019-01-20 10:05:28 +01:00
|
|
|
if (output == root->noop_output) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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 13:00:10 +02:00
|
|
|
struct wlr_output *wlr_output = output->wlr_output;
|
2018-04-04 03:06:13 +02:00
|
|
|
|
2019-01-17 22:30:24 +01:00
|
|
|
if (oc && !oc->enabled) {
|
|
|
|
// Output is configured to be disabled
|
2018-09-05 20:00:00 +02:00
|
|
|
if (output->enabled) {
|
|
|
|
output_disable(output);
|
|
|
|
wlr_output_layout_remove(root->output_layout, wlr_output);
|
|
|
|
}
|
|
|
|
wlr_output_enable(wlr_output, false);
|
2019-01-17 22:30:24 +01:00
|
|
|
return true;
|
2018-09-05 20:00:00 +02:00
|
|
|
} else if (!output->enabled) {
|
2019-01-17 22:30:24 +01:00
|
|
|
// Output is not enabled. Enable it, output_enable will call us again.
|
2018-09-05 20:00:00 +02:00
|
|
|
if (!oc || oc->dpms_state != DPMS_OFF) {
|
|
|
|
wlr_output_enable(wlr_output, true);
|
2018-05-01 17:38:55 +02:00
|
|
|
}
|
2018-09-05 20:00:00 +02:00
|
|
|
output_enable(output, oc);
|
2019-01-17 22:30:24 +01:00
|
|
|
return true;
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 09:01:19 +01:00
|
|
|
if (oc && oc->dpms_state == DPMS_ON) {
|
|
|
|
sway_log(SWAY_DEBUG, "Turning on screen");
|
|
|
|
wlr_output_enable(wlr_output, true);
|
|
|
|
}
|
|
|
|
|
2019-01-17 22:30:24 +01:00
|
|
|
bool modeset_success;
|
2017-12-06 12:36:06 +01:00
|
|
|
if (oc && oc->width > 0 && oc->height > 0) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width,
|
2017-12-11 21:47:40 +01:00
|
|
|
oc->height, oc->refresh_rate);
|
2019-01-17 22:30:24 +01:00
|
|
|
modeset_success =
|
|
|
|
set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate);
|
2018-09-01 18:56:53 +02:00
|
|
|
} else if (!wl_list_empty(&wlr_output->modes)) {
|
|
|
|
struct wlr_output_mode *mode =
|
|
|
|
wl_container_of(wlr_output->modes.prev, mode, link);
|
2019-01-17 22:30:24 +01:00
|
|
|
modeset_success = wlr_output_set_mode(wlr_output, mode);
|
|
|
|
} else {
|
|
|
|
// Output doesn't support modes
|
|
|
|
modeset_success = true;
|
|
|
|
}
|
|
|
|
if (!modeset_success) {
|
|
|
|
// Failed to modeset, 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.
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_ERROR, "Failed to modeset output %s", wlr_output->name);
|
2019-01-17 22:30:24 +01:00
|
|
|
return false;
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
2019-01-17 22:30:24 +01:00
|
|
|
|
2017-12-06 12:36:06 +01:00
|
|
|
if (oc && oc->scale > 0) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Set %s scale to %f", oc->name, oc->scale);
|
2017-12-06 19:16:12 +01:00
|
|
|
wlr_output_set_scale(wlr_output, oc->scale);
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
2017-12-06 12:57:13 +01:00
|
|
|
if (oc && oc->transform >= 0) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
|
2017-12-13 15:52:18 +01:00
|
|
|
wlr_output_set_transform(wlr_output, oc->transform);
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find position for it
|
2017-12-06 12:57:13 +01:00
|
|
|
if (oc && (oc->x != -1 || oc->y != -1)) {
|
2019-01-20 19:51:12 +01: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 13:00:10 +02:00
|
|
|
wlr_output_layout_add(root->output_layout, wlr_output, oc->x, oc->y);
|
2017-12-06 12:36:06 +01: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 13:00:10 +02:00
|
|
|
wlr_output_layout_add_auto(root->output_layout, wlr_output);
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
|
|
|
|
2019-03-11 11:45:01 +01: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;
|
|
|
|
wlr_output_transformed_resolution(wlr_output,
|
|
|
|
&output->width, &output->height);
|
|
|
|
|
2019-02-16 23:30:19 +01:00
|
|
|
if (output->swaybg_client != NULL) {
|
|
|
|
wl_client_destroy(output->swaybg_client);
|
2018-10-08 15:08:33 +02:00
|
|
|
}
|
|
|
|
if (oc && oc->background && config->swaybg_command) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Setting background for output %s to %s",
|
2019-01-17 11:13:10 +01:00
|
|
|
wlr_output->name, oc->background);
|
2017-12-06 12:36:06 +01:00
|
|
|
|
2019-01-17 11:20:08 +01:00
|
|
|
char *const cmd[] = {
|
|
|
|
config->swaybg_command,
|
|
|
|
wlr_output->name,
|
|
|
|
oc->background,
|
2019-01-17 11:13:10 +01:00
|
|
|
oc->background_option,
|
2019-01-17 11:20:08 +01:00
|
|
|
oc->background_fallback ? oc->background_fallback : NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
2019-02-16 23:30:19 +01:00
|
|
|
if (!spawn_swaybg(output, cmd)) {
|
|
|
|
return false;
|
2018-03-28 22:38:11 +02:00
|
|
|
}
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
2018-10-08 15:08:33 +02:00
|
|
|
|
2019-02-15 09:01:19 +01:00
|
|
|
if (oc && oc->dpms_state == DPMS_OFF) {
|
|
|
|
sway_log(SWAY_DEBUG, "Turning off screen");
|
|
|
|
wlr_output_enable(wlr_output, false);
|
2018-04-17 09:54:02 +02:00
|
|
|
}
|
2019-01-17 22:30:24 +01:00
|
|
|
|
|
|
|
return true;
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 18:13:03 +01:00
|
|
|
static void default_output_config(struct output_config *oc,
|
|
|
|
struct wlr_output *wlr_output) {
|
|
|
|
oc->enabled = 1;
|
|
|
|
if (!wl_list_empty(&wlr_output->modes)) {
|
|
|
|
struct wlr_output_mode *mode =
|
|
|
|
wl_container_of(wlr_output->modes.prev, mode, link);
|
|
|
|
oc->width = mode->width;
|
|
|
|
oc->height = mode->height;
|
|
|
|
oc->refresh_rate = mode->refresh;
|
|
|
|
}
|
|
|
|
oc->x = oc->y = -1;
|
|
|
|
oc->scale = 1;
|
|
|
|
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
2019-02-15 09:01:19 +01:00
|
|
|
oc->dpms_state = DPMS_ON;
|
2018-12-12 18:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct output_config *get_output_config(char *identifier,
|
|
|
|
struct sway_output *sway_output) {
|
|
|
|
const char *name = sway_output->wlr_output->name;
|
2018-12-03 03:49:09 +01:00
|
|
|
struct output_config *oc_name = NULL;
|
2018-07-21 04:17:20 +02:00
|
|
|
int i = list_seq_find(config->output_configs, output_name_cmp, name);
|
|
|
|
if (i >= 0) {
|
2018-12-03 03:49:09 +01:00
|
|
|
oc_name = config->output_configs->items[i];
|
2018-07-21 04:17:20 +02:00
|
|
|
}
|
|
|
|
|
2018-12-03 03:49:09 +01:00
|
|
|
struct output_config *oc_id = NULL;
|
2018-07-21 04:17:20 +02:00
|
|
|
i = list_seq_find(config->output_configs, output_name_cmp, identifier);
|
|
|
|
if (i >= 0) {
|
2018-12-03 03:49:09 +01:00
|
|
|
oc_id = config->output_configs->items[i];
|
2018-07-21 04:17:20 +02:00
|
|
|
}
|
|
|
|
|
2019-02-26 20:49:42 +01:00
|
|
|
struct output_config *result = new_output_config("temp");
|
2018-12-12 18:13:03 +01:00
|
|
|
if (config->reloading) {
|
|
|
|
default_output_config(result, sway_output->wlr_output);
|
|
|
|
}
|
2018-12-03 03:49:09 +01:00
|
|
|
if (oc_name && oc_id) {
|
|
|
|
// 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
|
|
|
|
size_t length = snprintf(NULL, 0, "%s on %s", identifier, name) + 1;
|
|
|
|
char *temp = malloc(length);
|
|
|
|
snprintf(temp, length, "%s on %s", identifier, name);
|
|
|
|
|
2018-12-12 18:13:03 +01:00
|
|
|
free(result->name);
|
|
|
|
result->name = temp;
|
2018-12-03 03:49:09 +01:00
|
|
|
merge_output_config(result, oc_name);
|
|
|
|
merge_output_config(result, oc_id);
|
|
|
|
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Generated output config \"%s\" (enabled: %d)"
|
2018-12-03 03:49:09 +01:00
|
|
|
" (%dx%d@%fHz position %d,%d scale %f transform %d) (bg %s %s)"
|
|
|
|
" (dpms %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);
|
|
|
|
} else if (oc_name) {
|
|
|
|
// No identifier config, just return a copy of the name config
|
2018-12-12 18:13:03 +01:00
|
|
|
free(result->name);
|
|
|
|
result->name = strdup(name);
|
2018-12-03 03:49:09 +01:00
|
|
|
merge_output_config(result, oc_name);
|
|
|
|
} else if (oc_id) {
|
|
|
|
// No name config, just return a copy of the identifier config
|
2018-12-12 18:13:03 +01:00
|
|
|
free(result->name);
|
|
|
|
result->name = strdup(identifier);
|
2018-12-03 03:49:09 +01:00
|
|
|
merge_output_config(result, oc_id);
|
2018-12-12 18:13:03 +01:00
|
|
|
} else if (config->reloading) {
|
|
|
|
// Neither config exists, but we need to reset the output so create a
|
|
|
|
// default config for the output and if a wildcard config exists, merge
|
|
|
|
// that on top
|
|
|
|
free(result->name);
|
|
|
|
result->name = strdup("*");
|
|
|
|
i = list_seq_find(config->output_configs, output_name_cmp, "*");
|
|
|
|
if (i >= 0) {
|
|
|
|
merge_output_config(result, config->output_configs->items[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
free_output_config(result);
|
|
|
|
result = NULL;
|
2018-12-03 03:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2018-07-21 04:17:20 +02: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-15 20:09:55 +01: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 04:17:20 +02: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];
|
|
|
|
struct sway_output *sway_output;
|
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 13:00:10 +02:00
|
|
|
wl_list_for_each(sway_output, &root->all_outputs, link) {
|
2018-07-21 04:17:20 +02: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)) {
|
2018-12-03 03:49:09 +01:00
|
|
|
struct output_config *current = new_output_config(oc->name);
|
|
|
|
merge_output_config(current, oc);
|
2018-07-21 04:17:20 +02:00
|
|
|
if (wildcard) {
|
2018-12-12 18:13:03 +01:00
|
|
|
struct output_config *tmp = get_output_config(id, sway_output);
|
2018-07-21 04:17:20 +02:00
|
|
|
if (tmp) {
|
2018-12-03 03:49:09 +01:00
|
|
|
free_output_config(current);
|
2018-07-21 04:17:20 +02:00
|
|
|
current = tmp;
|
|
|
|
}
|
|
|
|
}
|
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 13:00:10 +02:00
|
|
|
apply_output_config(current, sway_output);
|
2018-12-03 03:49:09 +01:00
|
|
|
free_output_config(current);
|
2018-07-21 04:17:20 +02:00
|
|
|
|
|
|
|
if (!wildcard) {
|
|
|
|
// Stop looking if the output config isn't applicable to all
|
|
|
|
// outputs
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-16 22:14:27 +01: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 12:36:06 +01:00
|
|
|
void free_output_config(struct output_config *oc) {
|
|
|
|
if (!oc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(oc->name);
|
|
|
|
free(oc->background);
|
|
|
|
free(oc->background_option);
|
|
|
|
free(oc);
|
|
|
|
}
|