Init, merge output config params, use wlr_output_layout

master
emersion 7 years ago
parent aaae59026f
commit 68ae989cee
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

@ -84,7 +84,7 @@ struct output_config {
float refresh_rate; float refresh_rate;
int x, y; int x, y;
int scale; int scale;
enum wl_output_transform transform; int32_t transform;
char *background; char *background;
char *background_option; 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); void free_input_config(struct input_config *ic);
int output_name_cmp(const void *item, const void *data); 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); void merge_output_config(struct output_config *dst, struct output_config *src);
/** Sets up a WLC output handle based on a given output_config. /** Sets up a WLC output handle based on a given output_config.
*/ */

@ -31,10 +31,8 @@ struct cmd_results *cmd_output(int argc, char **argv) {
if (!output) { if (!output) {
return cmd_results_new(CMD_FAILURE, "output", "Unable to allocate output config"); 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->name = strdup(name);
output->enabled = -1;
output->scale = 1;
// TODO: atoi doesn't handle invalid numbers // TODO: atoi doesn't handle invalid numbers

@ -2,6 +2,7 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include "sway/config.h" #include "sway/config.h"
#include "sway/output.h" #include "sway/output.h"
#include "log.h" #include "log.h"
@ -13,6 +14,15 @@ int output_name_cmp(const void *item, const void *data) {
return strcmp(output->name, name); 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) { void merge_output_config(struct output_config *dst, struct output_config *src) {
if (src->name) { if (src->name) {
if (dst->name) { if (dst->name) {
@ -38,6 +48,12 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
if (src->scale != -1) { if (src->scale != -1) {
dst->scale = src->scale; 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 (src->background) {
if (dst->background) { if (dst->background) {
free(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); set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate);
} }
if (oc && oc->scale > 0) { if (oc && oc->scale > 0) {
sway_log(L_DEBUG, "Set %s scale to %d", oc->name, oc->scale);
wlr_output->scale = 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); wlr_output_transform(wlr_output, oc->transform);
} }
// Find position for it // 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); sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
output->x = oc->x; wlr_output_layout_add(root_container.output_layout, wlr_output, oc->x,
output->y = oc->y; oc->y);
} else { } else {
int x = 0; wlr_output_layout_add_auto(root_container.output_layout, wlr_output);
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;
} }
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) { if (!oc || !oc->background) {
// Look for a * config for 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) { if (oc && oc->background) {
// TODO: swaybg // TODO swaybg
/*if (output->bg_pid != 0) { /*if (output->bg_pid != 0) {
terminate_swaybg(output->bg_pid); terminate_swaybg(output->bg_pid);
} }

@ -100,12 +100,6 @@ swayc_t *new_output(struct sway_output *sway_output) {
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
wlr_output_layout_add_auto(root_container.output_layout,
sway_output->wlr_output);
apply_output_config(oc, output); apply_output_config(oc, output);

Loading…
Cancel
Save