aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Crisci <tony@dubstepdish.com>2017-08-16 15:00:15 -0400
committerDrew DeVault <sir@cmpwn.com>2017-08-17 21:05:13 -0400
commit2e9e237f9d5485f65afbf3d8b49c740ed0653e5b (patch)
treecce6db9b905d9aa89fce25c8a6fc78c1e931adb2
parent44181b57aceb2a49846d15e9cea11a704cba9786 (diff)
layout-output example: handle empty config
-rw-r--r--examples/output-layout.c31
-rw-r--r--include/wlr/types/wlr_output_layout.h3
-rw-r--r--types/wlr_output_layout.c2
3 files changed, 33 insertions, 3 deletions
diff --git a/examples/output-layout.c b/examples/output-layout.c
index f0e2d2d4..81a7251b 100644
--- a/examples/output-layout.c
+++ b/examples/output-layout.c
@@ -31,6 +31,7 @@ struct sample_state {
float x_offs, y_offs;
float x_vel, y_vel;
struct wlr_output *main_output;
+ struct wl_list outputs;
};
struct output_config {
@@ -109,6 +110,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
static void handle_output_add(struct output_state *output) {
struct sample_state *sample = output->compositor->data;
+ bool found = false;
struct output_config *conf;
wl_list_for_each(conf, &sample->config, link) {
if (strcmp(conf->name, output->output->name) == 0) {
@@ -120,13 +122,35 @@ static void handle_output_add(struct output_state *output) {
sample->main_output = output->output;
sample->x_offs = conf->x + 20;
sample->y_offs = conf->y + 20;
- sample->x_vel = 500;
- sample->y_vel = 500;
}
wlr_log(L_DEBUG, "Adding output to layout: %s", output->output->name);
+ found = true;
+ break;
+ }
+ }
+
+ // if it's not in the config, just place it next to the rightmost output
+ if (!found) {
+ int x = 0;
+ struct output_state *_output;
+ wl_list_for_each(_output, &sample->outputs, link) {
+ struct wlr_output_layout_output *layout_output =
+ wlr_output_layout_get(sample->layout, _output->output);
+ if (layout_output && layout_output->output) {
+ x += layout_output->x + _output->output->width;
+ }
}
+ wlr_output_layout_add(sample->layout, output->output, x, 0);
+
+ if (wl_list_empty(&sample->config) && !sample->main_output) {
+ sample->main_output = output->output;
+ sample->x_offs = x + 20;
+ sample->y_offs = 20;
+ }
}
+
+ wl_list_insert(&sample->outputs, &output->link);
}
static void update_velocities(struct compositor_state *state,
@@ -245,9 +269,12 @@ static void parse_args(int argc, char *argv[], struct wl_list *config) {
int main(int argc, char *argv[]) {
struct sample_state state = {0};
+ state.x_vel = 500;
+ state.y_vel = 500;
state.layout = wlr_output_layout_init();
wl_list_init(&state.config);
+ wl_list_init(&state.outputs);
parse_args(argc, argv, &state.config);
struct compositor_state compositor = { 0 };
diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h
index cd36482a..7c904838 100644
--- a/include/wlr/types/wlr_output_layout.h
+++ b/include/wlr/types/wlr_output_layout.h
@@ -18,6 +18,9 @@ struct wlr_output_layout *wlr_output_layout_init();
void wlr_output_layout_destroy(struct wlr_output_layout *layout);
+struct wlr_output_layout_output *wlr_output_layout_get(
+ struct wlr_output_layout *layout, struct wlr_output *reference);
+
struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout,
double x, double y);
diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c
index 8b4256f9..dd31aef8 100644
--- a/types/wlr_output_layout.c
+++ b/types/wlr_output_layout.c
@@ -33,7 +33,7 @@ void wlr_output_layout_add(struct wlr_output_layout *layout,
wl_list_insert(&layout->outputs, &layout_output->link);
}
-static struct wlr_output_layout_output *wlr_output_layout_get(
+struct wlr_output_layout_output *wlr_output_layout_get(
struct wlr_output_layout *layout, struct wlr_output *reference) {
struct wlr_output_layout_output *ret = NULL;
struct wlr_output_layout_output *_output;