Init, merge output config params, use wlr_output_layout

This commit is contained in:
emersion 2017-12-06 12:57:13 +01:00
parent aaae59026f
commit 68ae989cee
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
4 changed files with 33 additions and 25 deletions

View file

@ -84,7 +84,7 @@ struct output_config {
float refresh_rate;
int x, y;
int scale;
enum wl_output_transform transform;
int32_t transform;
char *background;
char *background_option;
@ -364,6 +364,7 @@ void apply_input_config(struct input_config *ic, struct libinput_device *dev);
void free_input_config(struct input_config *ic);
int output_name_cmp(const void *item, const void *data);
void output_config_defaults(struct output_config *oc);
void merge_output_config(struct output_config *dst, struct output_config *src);
/** Sets up a WLC output handle based on a given output_config.
*/

View file

@ -31,10 +31,8 @@ struct cmd_results *cmd_output(int argc, char **argv) {
if (!output) {
return cmd_results_new(CMD_FAILURE, "output", "Unable to allocate output config");
}
output->x = output->y = output->width = output->height = -1;
output_config_defaults(output);
output->name = strdup(name);
output->enabled = -1;
output->scale = 1;
// TODO: atoi doesn't handle invalid numbers

View file

@ -2,6 +2,7 @@
#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"
@ -13,6 +14,15 @@ int output_name_cmp(const void *item, const void *data) {
return strcmp(output->name, name);
}
void output_config_defaults(struct output_config *oc) {
oc->enabled = -1;
oc->width = oc->height -1;
oc->refresh_rate = -1;
oc->x = oc->y = -1;
oc->scale = -1;
oc->transform = -1;
}
void merge_output_config(struct output_config *dst, struct output_config *src) {
if (src->name) {
if (dst->name) {
@ -38,6 +48,12 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
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) {
if (dst->background) {
free(dst->background);
@ -86,29 +102,28 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
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->scale = oc->scale;
}
if (oc && oc->transform != WL_OUTPUT_TRANSFORM_NORMAL) {
if (oc && oc->transform >= 0) {
sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
wlr_output_transform(wlr_output, oc->transform);
}
// Find position for it
if (oc && oc->x != -1 && oc->y != -1) {
if (oc && (oc->x != -1 || oc->y != -1)) {
sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
output->x = oc->x;
output->y = oc->y;
wlr_output_layout_add(root_container.output_layout, wlr_output, oc->x,
oc->y);
} else {
int x = 0;
for (int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
if (c->type == C_OUTPUT) {
if (c->width + c->x > x) {
x = c->width + c->x;
}
}
}
output->x = x;
wlr_output_layout_add_auto(root_container.output_layout, wlr_output);
}
struct wlr_box *output_layout_box =
wlr_output_layout_get_box(root_container.output_layout, wlr_output);
output->x = output_layout_box->x;
output->y = output_layout_box->y;
output->width = output_layout_box->width;
output->height = output_layout_box->height;
if (!oc || !oc->background) {
// Look for a * config for background
@ -128,7 +143,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
}
if (oc && oc->background) {
// TODO: swaybg
// TODO swaybg
/*if (output->bg_pid != 0) {
terminate_swaybg(output->bg_pid);
}

View file

@ -100,12 +100,6 @@ swayc_t *new_output(struct sway_output *sway_output) {
swayc_t *output = new_swayc(C_OUTPUT);
output->sway_output = sway_output;
output->name = name ? strdup(name) : NULL;
output->width = size.width;
output->height = size.width;
// TODO configure output layout position
wlr_output_layout_add_auto(root_container.output_layout,
sway_output->wlr_output);
apply_output_config(oc, output);