i3
fake_outputs.c
Go to the documentation of this file.
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * Faking outputs is useful in pathological situations (like network X servers
8  * which don’t support multi-monitor in a useful way) and for our testsuite.
9  *
10  */
11 #include "all.h"
12 
13 static int num_screens;
14 
15 /*
16  * Looks in outputs for the Output whose start coordinates are x, y
17  *
18  */
19 static Output *get_screen_at(unsigned int x, unsigned int y) {
20  Output *output;
21  TAILQ_FOREACH(output, &outputs, outputs)
22  if (output->rect.x == x && output->rect.y == y)
23  return output;
24 
25  return NULL;
26 }
27 
28 /*
29  * Creates outputs according to the given specification.
30  * The specification must be in the format wxh+x+y, for example 1024x768+0+0,
31  * with multiple outputs separated by commas:
32  * 1900x1200+0+0,1280x1024+1900+0
33  *
34  */
35 void fake_outputs_init(const char *output_spec) {
36  char useless_buffer[1024];
37  const char *walk = output_spec;
38  unsigned int x, y, width, height;
39  while (sscanf(walk, "%ux%u+%u+%u", &width, &height, &x, &y) == 4) {
40  DLOG("Parsed output as width = %u, height = %u at (%u, %u)\n",
41  width, height, x, y);
42  Output *new_output = get_screen_at(x, y);
43  if (new_output != NULL) {
44  DLOG("Re-used old output %p\n", new_output);
45  /* This screen already exists. We use the littlest screen so that the user
46  can always see the complete workspace */
47  new_output->rect.width = min(new_output->rect.width, width);
48  new_output->rect.height = min(new_output->rect.height, height);
49  } else {
50  new_output = scalloc(1, sizeof(Output));
51  sasprintf(&(new_output->name), "fake-%d", num_screens);
52  DLOG("Created new fake output %s (%p)\n", new_output->name, new_output);
53  new_output->active = true;
54  new_output->rect.x = x;
55  new_output->rect.y = y;
56  new_output->rect.width = width;
57  new_output->rect.height = height;
58  /* We always treat the screen at 0x0 as the primary screen */
59  if (new_output->rect.x == 0 && new_output->rect.y == 0)
60  TAILQ_INSERT_HEAD(&outputs, new_output, outputs);
61  else
62  TAILQ_INSERT_TAIL(&outputs, new_output, outputs);
63  output_init_con(new_output);
64  init_ws_for_output(new_output, output_get_content(new_output->con));
65  num_screens++;
66  }
67 
68  /* Figure out how long the input was to skip it */
69  walk += sprintf(useless_buffer, "%ux%u+%u+%u", width, height, x, y) + 1;
70  }
71 
72  if (num_screens == 0) {
73  ELOG("No screens found. Please fix your setup. i3 will exit now.\n");
74  exit(0);
75  }
76 }
#define ELOG(fmt,...)
Definition: libi3.h:89
struct outputs_head outputs
Definition: randr.c:26
uint32_t y
Definition: data.h:150
void init_ws_for_output(Output *output, Con *content)
Initializes at least one workspace for this output, trying the following steps until there is at leas...
Definition: randr.c:383
uint32_t height
Definition: data.h:152
uint32_t x
Definition: data.h:149
int min(int a, int b)
Definition: util.c:27
An Output is a physical output on your graphics driver.
Definition: data.h:344
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition: output.c:16
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:376
uint32_t width
Definition: data.h:129
Rect rect
x, y, width, height
Definition: data.h:365
static Output * get_screen_at(unsigned int x, unsigned int y)
Definition: fake_outputs.c:19
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:347
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
Definition: data.h:350
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
void output_init_con(Output *output)
Initializes a CT_OUTPUT Con (searches existing ones from inplace restart before) to use for the given...
Definition: randr.c:279
Con * con
Pointer to the Con which represents this output.
Definition: data.h:362
uint32_t height
Definition: data.h:130
uint32_t width
Definition: data.h:151
#define DLOG(fmt,...)
Definition: libi3.h:94
void fake_outputs_init(const char *output_spec)
Creates outputs according to the given specification.
Definition: fake_outputs.c:35
char * name
Name of the output.
Definition: data.h:359
uint32_t y
Definition: data.h:128
static int num_screens
Definition: fake_outputs.c:13
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:366
uint32_t x
Definition: data.h:127