X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffake_outputs.c;h=39cbd7bbc6e98fead58a72f94074b45f2826a933;hb=HEAD;hp=3df0e246a28661a0d0a0d29504928442bbeff3ef;hpb=14a4e0c6f8500b981ed36b3e772c65c3ca35749d;p=i3%2Fi3 diff --git a/src/fake_outputs.c b/src/fake_outputs.c index 3df0e246..39cbd7bb 100644 --- a/src/fake_outputs.c +++ b/src/fake_outputs.c @@ -1,5 +1,3 @@ -#undef I3__FILE__ -#define I3__FILE__ "fake_outputs.c" /* * vim:ts=4:sw=4:expandtab * @@ -30,17 +28,27 @@ static Output *get_screen_at(unsigned int x, unsigned int y) { /* * Creates outputs according to the given specification. * The specification must be in the format wxh+x+y, for example 1024x768+0+0, + * optionally followed by 'P' to indicate a primary output, * with multiple outputs separated by commas: - * 1900x1200+0+0,1280x1024+1900+0 + * 1900x1200+0+0P,1280x1024+1900+0 * */ void fake_outputs_init(const char *output_spec) { - char useless_buffer[1024]; const char *walk = output_spec; unsigned int x, y, width, height; - while (sscanf(walk, "%ux%u+%u+%u", &width, &height, &x, &y) == 4) { - DLOG("Parsed output as width = %u, height = %u at (%u, %u)\n", - width, height, x, y); + int chars_consumed; + while (sscanf(walk, "%ux%u+%u+%u%n", &width, &height, &x, &y, &chars_consumed) == 4) { + walk += chars_consumed; + bool primary = false; + if (*walk == 'P') { + primary = true; + walk++; + } + if (*walk == ',') + walk++; /* Skip delimiter */ + DLOG("Parsed output as width = %u, height = %u at (%u, %u)%s\n", + width, height, x, y, primary ? " (primary)" : ""); + Output *new_output = get_screen_at(x, y); if (new_output != NULL) { DLOG("Re-used old output %p\n", new_output); @@ -49,9 +57,12 @@ void fake_outputs_init(const char *output_spec) { new_output->rect.width = min(new_output->rect.width, width); new_output->rect.height = min(new_output->rect.height, height); } else { + struct output_name *output_name = scalloc(1, sizeof(struct output_name)); new_output = scalloc(1, sizeof(Output)); - sasprintf(&(new_output->name), "fake-%d", num_screens); - DLOG("Created new fake output %s (%p)\n", new_output->name, new_output); + sasprintf(&(output_name->name), "fake-%d", num_screens); + SLIST_INIT(&(new_output->names_head)); + SLIST_INSERT_HEAD(&(new_output->names_head), output_name, names); + DLOG("Created new fake output %s (%p)\n", output_primary_name(new_output), new_output); new_output->active = true; new_output->rect.x = x; new_output->rect.y = y; @@ -66,9 +77,7 @@ void fake_outputs_init(const char *output_spec) { init_ws_for_output(new_output, output_get_content(new_output->con)); num_screens++; } - - /* Figure out how long the input was to skip it */ - walk += sprintf(useless_buffer, "%ux%u+%u+%u", width, height, x, y) + 1; + new_output->primary = primary; } if (num_screens == 0) {