Merge branch 'wlroots' into feature/input

master
Tony Crisci 7 years ago
commit 9fa70ce426

@ -102,8 +102,11 @@ struct output_config {
char *name; char *name;
int enabled; int enabled;
int width, height; int width, height;
float refresh_rate;
int x, y; int x, y;
int scale; int scale;
int32_t transform;
char *background; char *background;
char *background_option; char *background_option;
}; };
@ -391,9 +394,8 @@ struct seat_attachment_config *seat_config_get_attachment(
struct seat_config *seat_config, char *identifier); struct seat_config *seat_config, char *identifier);
int output_name_cmp(const void *item, const void *data); int output_name_cmp(const void *item, const void *data);
struct output_config *new_output_config();
void merge_output_config(struct output_config *dst, struct output_config *src); void merge_output_config(struct output_config *dst, struct output_config *src);
/** Sets up a WLC output handle based on a given output_config.
*/
void apply_output_config(struct output_config *oc, swayc_t *output); void apply_output_config(struct output_config *oc, swayc_t *output);
void free_output_config(struct output_config *oc); void free_output_config(struct output_config *oc);

@ -58,9 +58,9 @@ enum swayc_border_types {
B_NORMAL, /**< Normal border with title bar */ B_NORMAL, /**< Normal border with title bar */
}; };
struct sway_root;
struct sway_output; struct sway_output;
struct sway_view; struct sway_view;
struct wlr_output_layout;
/** /**
* Stores information about a container. * Stores information about a container.
@ -70,7 +70,7 @@ struct wlr_output_layout;
struct sway_container { struct sway_container {
union { union {
// TODO: Encapsulate state for other node types as well like C_CONTAINER // TODO: Encapsulate state for other node types as well like C_CONTAINER
struct wlr_output_layout *output_layout; // C_ROOT struct sway_root *sway_root; // C_ROOT
struct sway_output *sway_output; // C_OUTPUT struct sway_output *sway_output; // C_OUTPUT
struct sway_view *sway_view; // C_VIEW struct sway_view *sway_view; // C_VIEW
}; };
@ -137,6 +137,7 @@ swayc_t *new_output(struct sway_output *sway_output);
swayc_t *new_workspace(swayc_t *output, const char *name); swayc_t *new_workspace(swayc_t *output, const char *name);
swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view); swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view);
swayc_t *destroy_output(swayc_t *output);
swayc_t *destroy_view(swayc_t *view); swayc_t *destroy_view(swayc_t *view);
swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type); swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type);

@ -1,8 +1,16 @@
#ifndef _SWAY_LAYOUT_H #ifndef _SWAY_LAYOUT_H
#define _SWAY_LAYOUT_H #define _SWAY_LAYOUT_H
#include <wlr/types/wlr_output_layout.h>
struct sway_container; struct sway_container;
struct sway_root {
struct wlr_output_layout *output_layout;
struct wl_listener output_layout_change;
};
void init_layout(void); void init_layout(void);
void add_child(struct sway_container *parent, struct sway_container *child); void add_child(struct sway_container *parent, struct sway_container *child);
struct sway_container *remove_child(struct sway_container *child); struct sway_container *remove_child(struct sway_container *child);

@ -12,8 +12,8 @@ struct sway_output {
struct sway_container *swayc; struct sway_container *swayc;
struct sway_server *server; struct sway_server *server;
struct timespec last_frame; struct timespec last_frame;
struct wl_listener frame; struct wl_listener frame;
struct wl_listener resolution;
}; };
#endif #endif

@ -132,6 +132,7 @@ static struct cmd_handler handlers[] = {
{ "exit", cmd_exit }, { "exit", cmd_exit },
{ "include", cmd_include }, { "include", cmd_include },
{ "input", cmd_input }, { "input", cmd_input },
{ "output", cmd_output },
{ "seat", cmd_seat }, { "seat", cmd_seat },
}; };

@ -0,0 +1,311 @@
#define _XOPEN_SOURCE 500
#include <ctype.h>
#include <libgen.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <wordexp.h>
#include "sway/commands.h"
#include "sway/config.h"
#include "list.h"
#include "log.h"
#include "stringop.h"
static char *bg_options[] = {
"stretch",
"center",
"fill",
"fit",
"tile",
};
struct cmd_results *cmd_output(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) {
return error;
}
const char *name = argv[0];
struct output_config *output = new_output_config();
if (!output) {
sway_log(L_ERROR, "Failed to allocate output config");
return NULL;
}
output->name = strdup(name);
int i;
for (i = 1; i < argc; ++i) {
const char *command = argv[i];
if (strcasecmp(command, "disable") == 0) {
output->enabled = 0;
} else if (strcasecmp(command, "mode") == 0 ||
strcasecmp(command, "resolution") == 0 ||
strcasecmp(command, "res") == 0) {
if (++i >= argc) {
error = cmd_results_new(CMD_INVALID, "output",
"Missing mode argument.");
goto fail;
}
int width = -1, height = -1;
float refresh_rate = -1;
char *end;
width = strtol(argv[i], &end, 10);
if (*end) {
// Format is 1234x4321
if (*end != 'x') {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid mode width.");
goto fail;
}
++end;
height = strtol(end, &end, 10);
if (*end) {
if (*end != '@') {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid mode height.");
goto fail;
}
++end;
refresh_rate = strtof(end, &end);
if (strcasecmp("Hz", end) != 0) {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid mode refresh rate.");
goto fail;
}
}
} else {
// Format is 1234 4321
if (++i >= argc) {
error = cmd_results_new(CMD_INVALID, "output",
"Missing mode argument (height).");
goto fail;
}
height = strtol(argv[i], &end, 10);
if (*end) {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid mode height.");
goto fail;
}
}
output->width = width;
output->height = height;
output->refresh_rate = refresh_rate;
} else if (strcasecmp(command, "position") == 0 ||
strcasecmp(command, "pos") == 0) {
if (++i >= argc) {
error = cmd_results_new(CMD_INVALID, "output",
"Missing position argument.");
goto fail;
}
int x = -1, y = -1;
char *end;
x = strtol(argv[i], &end, 10);
if (*end) {
// Format is 1234,4321
if (*end != ',') {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid position x.");
goto fail;
}
++end;
y = strtol(end, &end, 10);
if (*end) {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid position y.");
goto fail;
}
} else {
// Format is 1234 4321 (legacy)
if (++i >= argc) {
error = cmd_results_new(CMD_INVALID, "output",
"Missing position argument (y).");
goto fail;
}
y = strtol(argv[i], &end, 10);
if (*end) {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid position y.");
goto fail;
}
}
output->x = x;
output->y = y;
} else if (strcasecmp(command, "scale") == 0) {
if (++i >= argc) {
error = cmd_results_new(CMD_INVALID, "output",
"Missing scale parameter.");
goto fail;
}
char *end;
output->scale = strtol(argv[i], &end, 10);
if (*end) {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid scale.");
goto fail;
}
} else if (strcasecmp(command, "transform") == 0) {
if (++i >= argc) {
error = cmd_results_new(CMD_INVALID, "output",
"Missing transform parameter.");
goto fail;
}
char *value = argv[i];
if (strcmp(value, "normal") == 0) {
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
} else if (strcmp(value, "90") == 0) {
output->transform = WL_OUTPUT_TRANSFORM_90;
} else if (strcmp(value, "180") == 0) {
output->transform = WL_OUTPUT_TRANSFORM_180;
} else if (strcmp(value, "270") == 0) {
output->transform = WL_OUTPUT_TRANSFORM_270;
} else if (strcmp(value, "flipped") == 0) {
output->transform = WL_OUTPUT_TRANSFORM_FLIPPED;
} else if (strcmp(value, "flipped-90") == 0) {
output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_90;
} else if (strcmp(value, "flipped-180") == 0) {
output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_180;
} else if (strcmp(value, "flipped-270") == 0) {
output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_270;
} else {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid output transform.");
goto fail;
}
} else if (strcasecmp(command, "background") == 0 ||
strcasecmp(command, "bg") == 0) {
wordexp_t p;
if (++i >= argc) {
error = cmd_results_new(CMD_INVALID, "output",
"Missing background file or color specification.");
goto fail;
}
if (i + 1 >= argc) {
error = cmd_results_new(CMD_INVALID, "output",
"Missing background scaling mode or `solid_color`.");
goto fail;
}
if (strcasecmp(argv[i + 1], "solid_color") == 0) {
output->background = strdup(argv[argc - 2]);
output->background_option = strdup("solid_color");
} else {
// argv[i+j]=bg_option
bool valid = false;
char *mode;
size_t j;
for (j = 0; j < (size_t) (argc - i); ++j) {
mode = argv[i + j];
size_t n = sizeof(bg_options) / sizeof(char *);
for (size_t k = 0; k < n; ++k) {
if (strcasecmp(mode, bg_options[k]) == 0) {
valid = true;
break;
}
}
if (valid) {
break;
}
}
if (!valid) {
error = cmd_results_new(CMD_INVALID, "output",
"Missing background scaling mode.");
goto fail;
}
char *src = join_args(argv + i, j);
if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid syntax (%s).", src);
goto fail;
}
free(src);
src = p.we_wordv[0];
if (config->reading && *src != '/') {
char *conf = strdup(config->current_config);
if (conf) {
char *conf_path = dirname(conf);
src = malloc(strlen(conf_path) + strlen(src) + 2);
if (src) {
sprintf(src, "%s/%s", conf_path, p.we_wordv[0]);
} else {
sway_log(L_ERROR,
"Unable to allocate background source");
}
free(conf);
} else {
sway_log(L_ERROR,
"Unable to allocate background source");
}
}
if (!src || access(src, F_OK) == -1) {
error = cmd_results_new(CMD_INVALID, "output",
"Background file unreadable (%s).", src);
wordfree(&p);
goto fail;
}
output->background = strdup(src);
output->background_option = strdup(mode);
if (src != p.we_wordv[0]) {
free(src);
}
wordfree(&p);
i += j;
}
} else {
error = cmd_results_new(CMD_INVALID, "output",
"Invalid output subcommand: %s.", command);
goto fail;
}
}
i = list_seq_find(config->output_configs, output_name_cmp, name);
if (i >= 0) {
// merge existing config
struct output_config *oc = config->output_configs->items[i];
merge_output_config(oc, output);
free_output_config(output);
output = oc;
} else {
list_add(config->output_configs, output);
}
sway_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
"position %d,%d scale %d transform %d) (bg %s %s)",
output->name, output->enabled, output->width, output->height,
output->refresh_rate, output->x, output->y, output->scale,
output->transform, output->background, output->background_option);
if (output->name) {
// 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.
swayc_t *cont = NULL;
for (int i = 0; i < root_container.children->length; ++i) {
cont = root_container.children->items[i];
if (cont->name && ((strcmp(cont->name, output->name) == 0) ||
(strcmp(output->name, "*") == 0))) {
apply_output_config(output, cont);
if (strcmp(output->name, "*") != 0) {
// Stop looking if the output config isn't applicable to all
// outputs
break;
}
}
}
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
fail:
free_output_config(output);
return error;
}

@ -0,0 +1,185 @@
#define _XOPEN_SOURCE 700
#include <string.h>
#include <assert.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include "sway/config.h"
#include "sway/output.h"
#include "log.h"
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);
}
struct output_config *new_output_config() {
struct output_config *oc = calloc(1, sizeof(struct output_config));
if (oc == NULL) {
return NULL;
}
oc->enabled = -1;
oc->width = oc->height = -1;
oc->refresh_rate = -1;
oc->x = oc->y = -1;
oc->scale = -1;
oc->transform = -1;
return oc;
}
void merge_output_config(struct output_config *dst, struct output_config *src) {
if (src->name) {
free(dst->name);
dst->name = strdup(src->name);
}
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;
}
if (src->refresh_rate != -1) {
dst->refresh_rate = src->refresh_rate;
}
if (src->transform != -1) {
dst->transform = src->transform;
}
if (src->background) {
free(dst->background);
dst->background = strdup(src->background);
}
if (src->background_option) {
free(dst->background_option);
dst->background_option = strdup(src->background_option);
}
}
static void set_mode(struct wlr_output *output, int width, int height,
float refresh_rate) {
int mhz = (int)(refresh_rate * 1000);
if (wl_list_empty(&output->modes)) {
sway_log(L_DEBUG, "Assigning custom mode to %s", output->name);
wlr_output_set_custom_mode(output, width, height, mhz);
return;
}
struct wlr_output_mode *mode, *best = NULL;
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) {
sway_log(L_ERROR, "Configured mode for %s not available", output->name);
} else {
sway_log(L_DEBUG, "Assigning configured mode to %s", output->name);
wlr_output_set_mode(output, best);
}
}
void apply_output_config(struct output_config *oc, swayc_t *output) {
assert(output->type == C_OUTPUT);
struct wlr_output *wlr_output = output->sway_output->wlr_output;
if (oc && oc->enabled == 0) {
wlr_output_layout_remove(root_container.sway_root->output_layout,
wlr_output);
destroy_output(output);
return;
}
if (oc && oc->width > 0 && oc->height > 0) {
sway_log(L_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width,
oc->height, oc->refresh_rate);
set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate);
}
if (oc && oc->scale > 0) {
sway_log(L_DEBUG, "Set %s scale to %d", oc->name, oc->scale);
wlr_output_set_scale(wlr_output, oc->scale);
}
if (oc && oc->transform >= 0) {
sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
wlr_output_set_transform(wlr_output, oc->transform);
}
// Find position for it
if (oc && (oc->x != -1 || oc->y != -1)) {
sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
wlr_output_layout_add(root_container.sway_root->output_layout,
wlr_output, oc->x, oc->y);
} else {
wlr_output_layout_add_auto(root_container.sway_root->output_layout,
wlr_output);
}
if (!oc || !oc->background) {
// Look for a * config for background
int i = list_seq_find(config->output_configs, output_name_cmp, "*");
if (i >= 0) {
oc = config->output_configs->items[i];
} else {
oc = NULL;
}
}
int output_i;
for (output_i = 0; output_i < root_container.children->length; ++output_i) {
if (root_container.children->items[output_i] == output) {
break;
}
}
if (oc && oc->background) {
// TODO swaybg
/*if (output->bg_pid != 0) {
terminate_swaybg(output->bg_pid);
}
sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background);
size_t bufsize = 12;
char output_id[bufsize];
snprintf(output_id, bufsize, "%d", output_i);
output_id[bufsize-1] = 0;
char *const cmd[] = {
"swaybg",
output_id,
oc->background,
oc->background_option,
NULL,
};
output->bg_pid = fork();
if (output->bg_pid == 0) {
execvp(cmd[0], cmd);
}*/
}
}
void free_output_config(struct output_config *oc) {
if (!oc) {
return;
}
free(oc->name);
free(oc->background);
free(oc->background_option);
free(oc);
}

@ -88,8 +88,7 @@ static void output_frame_view(swayc_t *view, void *data) {
} }
static void output_frame_notify(struct wl_listener *listener, void *data) { static void output_frame_notify(struct wl_listener *listener, void *data) {
struct sway_output *soutput = wl_container_of( struct sway_output *soutput = wl_container_of(listener, soutput, frame);
listener, soutput, frame);
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
struct sway_server *server = soutput->server; struct sway_server *server = soutput->server;
@ -108,42 +107,53 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
soutput->last_frame = now; soutput->last_frame = now;
} }
static void output_resolution_notify(struct wl_listener *listener, void *data) {
struct sway_output *soutput = wl_container_of(
listener, soutput, resolution);
arrange_windows(soutput->swayc, -1, -1);
}
void output_add_notify(struct wl_listener *listener, void *data) { void output_add_notify(struct wl_listener *listener, void *data) {
struct sway_server *server = wl_container_of(listener, server, output_add); struct sway_server *server = wl_container_of(listener, server, output_add);
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name);
struct sway_output *output = calloc(1, sizeof(struct sway_output)); struct sway_output *output = calloc(1, sizeof(struct sway_output));
if (!output) {
return;
}
output->wlr_output = wlr_output; output->wlr_output = wlr_output;
output->server = server; output->server = server;
output->swayc = new_output(output);
if (wl_list_length(&wlr_output->modes) > 0) { if (!wl_list_empty(&wlr_output->modes)) {
struct wlr_output_mode *mode = NULL; struct wlr_output_mode *mode =
mode = wl_container_of((&wlr_output->modes)->prev, mode, link); wl_container_of(wlr_output->modes.prev, mode, link);
wlr_output_set_mode(wlr_output, mode); wlr_output_set_mode(wlr_output, mode);
} }
output->frame.notify = output_frame_notify; output->swayc = new_output(output);
wl_signal_add(&wlr_output->events.frame, &output->frame); if (!output->swayc) {
free(output);
output->resolution.notify = output_resolution_notify; return;
wl_signal_add(&wlr_output->events.resolution, &output->resolution); }
sway_input_manager_configure_xcursor(input_manager); sway_input_manager_configure_xcursor(input_manager);
arrange_windows(output->swayc, -1, -1); output->frame.notify = output_frame_notify;
wl_signal_add(&wlr_output->events.frame, &output->frame);
} }
void output_remove_notify(struct wl_listener *listener, void *data) { void output_remove_notify(struct wl_listener *listener, void *data) {
struct sway_server *server = wl_container_of(listener, server, output_remove); struct sway_server *server = wl_container_of(listener, server, output_remove);
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name);
// TODO
swayc_t *output_container = NULL;
for (int i = 0 ; i < root_container.children->length; ++i) {
swayc_t *child = root_container.children->items[i];
if (child->type == C_OUTPUT &&
child->sway_output->wlr_output == wlr_output) {
output_container = child;
break;
}
}
if (!output_container) {
return;
}
destroy_output(output_container);
} }

@ -57,7 +57,7 @@ static void set_position(struct sway_view *view, double ox, double oy) {
if (!sway_assert(root, "output must be within tree to set position")) { if (!sway_assert(root, "output must be within tree to set position")) {
return; return;
} }
struct wlr_output_layout *layout = root->output_layout; struct wlr_output_layout *layout = root->sway_root->output_layout;
struct wlr_output_layout_output *loutput = struct wlr_output_layout_output *loutput =
wlr_output_layout_get(layout, output->sway_output->wlr_output); wlr_output_layout_get(layout, output->sway_output->wlr_output);
if (!sway_assert(loutput, "output must be within layout to set position")) { if (!sway_assert(loutput, "output must be within layout to set position")) {

@ -140,7 +140,8 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
} }
cursor->seat = seat; cursor->seat = seat;
wlr_cursor_attach_output_layout(wlr_cursor, root_container.output_layout); wlr_cursor_attach_output_layout(wlr_cursor,
root_container.sway_root->output_layout);
// input events // input events
wl_signal_add(&wlr_cursor->events.motion, &cursor->motion); wl_signal_add(&wlr_cursor->events.motion, &cursor->motion);

@ -406,6 +406,10 @@ int main(int argc, char **argv) {
security_sanity_check(); security_sanity_check();
// TODO: wait for server to be ready
// TODO: consume config->cmd_queue
config->active = true;
if (!terminate_request) { if (!terminate_request) {
server_run(&server); server_run(&server);
} }

@ -29,7 +29,9 @@ sway_sources = files(
'commands/input/xkb_options.c', 'commands/input/xkb_options.c',
'commands/input/xkb_rules.c', 'commands/input/xkb_rules.c',
'commands/input/xkb_variant.c', 'commands/input/xkb_variant.c',
'commands/output.c',
'config.c', 'config.c',
'config/output.c',
'ipc-json.c', 'ipc-json.c',
'ipc-server.c', 'ipc-server.c',
'desktop/output.c', 'desktop/output.c',

@ -2,11 +2,14 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <strings.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
#include "sway/config.h"
#include "sway/container.h" #include "sway/container.h"
#include "sway/layout.h" #include "sway/layout.h"
#include "sway/output.h" #include "sway/output.h"
#include "sway/server.h"
#include "sway/view.h" #include "sway/view.h"
#include "sway/workspace.h" #include "sway/workspace.h"
#include "log.h" #include "log.h"
@ -48,19 +51,38 @@ static swayc_t *new_swayc(enum swayc_types type) {
swayc_t *new_output(struct sway_output *sway_output) { swayc_t *new_output(struct sway_output *sway_output) {
struct wlr_box size; struct wlr_box size;
wlr_output_effective_resolution( wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
sway_output->wlr_output, &size.width, &size.height); &size.height);
const char *name = sway_output->wlr_output->name; const char *name = sway_output->wlr_output->name;
struct output_config *oc = NULL, *all = NULL;
for (int i = 0; i < config->output_configs->length; ++i) {
struct output_config *cur = config->output_configs->items[i];
if (strcasecmp(name, cur->name) == 0) {
sway_log(L_DEBUG, "Matched output config for %s", name);
oc = cur;
}
if (strcasecmp("*", cur->name) == 0) {
sway_log(L_DEBUG, "Matched wildcard output config for %s", name);
all = cur;
}
if (oc && all) {
break;
}
}
if (!oc) {
oc = all;
}
if (oc && !oc->enabled) {
return NULL;
}
swayc_t *output = new_swayc(C_OUTPUT); swayc_t *output = new_swayc(C_OUTPUT);
output->sway_output = sway_output; output->sway_output = sway_output;
output->name = name ? strdup(name) : NULL; output->name = name ? strdup(name) : NULL;
output->width = size.width;
output->height = size.width;
// TODO configure output layout position apply_output_config(oc, output);
wlr_output_layout_add_auto(root_container.output_layout,
sway_output->wlr_output);
add_child(&root_container, output); add_child(&root_container, output);
@ -146,6 +168,34 @@ static void free_swayc(swayc_t *cont) {
free(cont); free(cont);
} }
swayc_t *destroy_output(swayc_t *output) {
if (!sway_assert(output, "null output passed to destroy_output")) {
return NULL;
}
if (output->children->length > 0) {
// TODO save workspaces when there are no outputs.
// TODO also check if there will ever be no outputs except for exiting
// program
if (root_container.children->length > 1) {
int p = root_container.children->items[0] == output;
// Move workspace from this output to another output
while (output->children->length) {
swayc_t *child = output->children->items[0];
remove_child(child);
add_child(root_container.children->items[p], child);
}
sort_workspaces(root_container.children->items[p]);
arrange_windows(root_container.children->items[p], -1, -1);
}
}
sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
free_swayc(output);
return &root_container;
}
swayc_t *destroy_view(swayc_t *view) { swayc_t *destroy_view(swayc_t *view) {
if (!sway_assert(view, "null view passed to destroy_view")) { if (!sway_assert(view, "null view passed to destroy_view")) {
return NULL; return NULL;
@ -189,7 +239,8 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
struct sway_view *sview = swayc->sway_view; struct sway_view *sview = swayc->sway_view;
swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT);
struct wlr_box *output_box = struct wlr_box *output_box =
wlr_output_layout_get_box(root_container.output_layout, wlr_output_layout_get_box(
root_container.sway_root->output_layout,
soutput->sway_output->wlr_output); soutput->sway_output->wlr_output);
double ox = lx - output_box->x; double ox = lx - output_box->x;
double oy = ly - output_box->y; double oy = ly - output_box->y;

@ -7,6 +7,7 @@
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include "sway/container.h" #include "sway/container.h"
#include "sway/layout.h"
#include "sway/output.h" #include "sway/output.h"
#include "sway/view.h" #include "sway/view.h"
#include "list.h" #include "list.h"
@ -14,13 +15,47 @@
swayc_t root_container; swayc_t root_container;
static void output_layout_change_notify(struct wl_listener *listener, void *data) {
struct wlr_box *layout_box = wlr_output_layout_get_box(
root_container.sway_root->output_layout, NULL);
root_container.width = layout_box->width;
root_container.height = layout_box->height;
for (int i = 0 ; i < root_container.children->length; ++i) {
swayc_t *output_container = root_container.children->items[i];
if (output_container->type != C_OUTPUT) {
continue;
}
struct sway_output *output = output_container->sway_output;
struct wlr_box *output_box = wlr_output_layout_get_box(
root_container.sway_root->output_layout, output->wlr_output);
if (!output_box) {
continue;
}
output_container->x = output_box->x;
output_container->y = output_box->y;
output_container->width = output_box->width;
output_container->height = output_box->height;
}
arrange_windows(&root_container, -1, -1);
}
void init_layout(void) { void init_layout(void) {
root_container.id = 0; // normally assigned in new_swayc() root_container.id = 0; // normally assigned in new_swayc()
root_container.type = C_ROOT; root_container.type = C_ROOT;
root_container.layout = L_NONE; root_container.layout = L_NONE;
root_container.name = strdup("root"); root_container.name = strdup("root");
root_container.children = create_list(); root_container.children = create_list();
root_container.output_layout = wlr_output_layout_create();
root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
root_container.sway_root->output_layout = wlr_output_layout_create();
root_container.sway_root->output_layout_change.notify =
output_layout_change_notify;
wl_signal_add(&root_container.sway_root->output_layout->events.change,
&root_container.sway_root->output_layout_change);
} }
void add_child(swayc_t *parent, swayc_t *child) { void add_child(swayc_t *parent, swayc_t *child) {

Loading…
Cancel
Save