2012-04-09 14:27:33 +02:00
|
|
|
|
/*
|
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
|
*
|
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
2015-04-04 02:17:56 +02:00
|
|
|
|
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
|
2012-04-09 14:27:33 +02:00
|
|
|
|
*
|
|
|
|
|
* Faking outputs is useful in pathological situations (like network X servers
|
|
|
|
|
* which don’t support multi-monitor in a useful way) and for our testsuite.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include "all.h"
|
|
|
|
|
|
|
|
|
|
static int num_screens;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Looks in outputs for the Output whose start coordinates are x, y
|
|
|
|
|
*
|
|
|
|
|
*/
|
2013-12-25 20:01:37 +01:00
|
|
|
|
static Output *get_screen_at(unsigned int x, unsigned int y) {
|
2012-04-09 14:27:33 +02:00
|
|
|
|
Output *output;
|
2020-02-19 11:31:09 +01:00
|
|
|
|
TAILQ_FOREACH (output, &outputs, outputs) {
|
|
|
|
|
if (output->rect.x == x && output->rect.y == y) {
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-09 14:27:33 +02:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Creates outputs according to the given specification.
|
|
|
|
|
* The specification must be in the format wxh+x+y, for example 1024x768+0+0,
|
2017-09-19 16:42:13 +02:00
|
|
|
|
* optionally followed by 'P' to indicate a primary output,
|
2012-04-09 14:27:33 +02:00
|
|
|
|
* with multiple outputs separated by commas:
|
2017-09-19 16:42:13 +02:00
|
|
|
|
* 1900x1200+0+0P,1280x1024+1900+0
|
2012-04-09 14:27:33 +02:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void fake_outputs_init(const char *output_spec) {
|
|
|
|
|
const char *walk = output_spec;
|
|
|
|
|
unsigned int x, y, width, height;
|
2017-09-19 16:33:51 +02:00
|
|
|
|
int chars_consumed;
|
|
|
|
|
while (sscanf(walk, "%ux%u+%u+%u%n", &width, &height, &x, &y, &chars_consumed) == 4) {
|
2017-09-19 16:42:13 +02:00
|
|
|
|
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)" : "");
|
|
|
|
|
|
2012-04-09 14:27:33 +02:00
|
|
|
|
Output *new_output = get_screen_at(x, y);
|
|
|
|
|
if (new_output != NULL) {
|
|
|
|
|
DLOG("Re-used old output %p\n", new_output);
|
|
|
|
|
/* This screen already exists. We use the littlest screen so that the user
|
|
|
|
|
can always see the complete workspace */
|
|
|
|
|
new_output->rect.width = min(new_output->rect.width, width);
|
|
|
|
|
new_output->rect.height = min(new_output->rect.height, height);
|
|
|
|
|
} else {
|
2017-09-09 09:37:37 +02:00
|
|
|
|
struct output_name *output_name = scalloc(1, sizeof(struct output_name));
|
2015-08-03 11:50:13 +02:00
|
|
|
|
new_output = scalloc(1, sizeof(Output));
|
2017-09-09 09:37:37 +02:00
|
|
|
|
sasprintf(&(output_name->name), "fake-%d", num_screens);
|
|
|
|
|
SLIST_INIT(&(new_output->names_head));
|
|
|
|
|
SLIST_INSERT_HEAD(&(new_output->names_head), output_name, names);
|
2017-09-09 09:18:29 +02:00
|
|
|
|
DLOG("Created new fake output %s (%p)\n", output_primary_name(new_output), new_output);
|
2012-04-09 14:27:33 +02:00
|
|
|
|
new_output->active = true;
|
|
|
|
|
new_output->rect.x = x;
|
|
|
|
|
new_output->rect.y = y;
|
|
|
|
|
new_output->rect.width = width;
|
|
|
|
|
new_output->rect.height = height;
|
|
|
|
|
/* We always treat the screen at 0x0 as the primary screen */
|
|
|
|
|
if (new_output->rect.x == 0 && new_output->rect.y == 0)
|
|
|
|
|
TAILQ_INSERT_HEAD(&outputs, new_output, outputs);
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
TAILQ_INSERT_TAIL(&outputs, new_output, outputs);
|
2012-04-09 14:27:33 +02:00
|
|
|
|
output_init_con(new_output);
|
2018-09-12 15:53:20 +02:00
|
|
|
|
init_ws_for_output(new_output);
|
2012-04-09 14:27:33 +02:00
|
|
|
|
num_screens++;
|
|
|
|
|
}
|
2017-09-19 16:42:13 +02:00
|
|
|
|
new_output->primary = primary;
|
2012-04-09 14:27:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (num_screens == 0) {
|
|
|
|
|
ELOG("No screens found. Please fix your setup. i3 will exit now.\n");
|
2020-01-16 09:21:27 +01:00
|
|
|
|
exit(EXIT_FAILURE);
|
2012-04-09 14:27:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|