3 * Copyright (c) 1997 Metro Link Incorporated
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * Except as contained in this notice, the name of the Metro Link shall not be
24 * used in advertising or otherwise to promote the sale, use or other dealings
25 * in this Software without prior written authorization from Metro Link.
29 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
31 * Permission is hereby granted, free of charge, to any person obtaining a
32 * copy of this software and associated documentation files (the "Software"),
33 * to deal in the Software without restriction, including without limitation
34 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
35 * and/or sell copies of the Software, and to permit persons to whom the
36 * Software is furnished to do so, subject to the following conditions:
38 * The above copyright notice and this permission notice shall be included in
39 * all copies or substantial portions of the Software.
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
44 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
45 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
46 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
47 * OTHER DEALINGS IN THE SOFTWARE.
49 * Except as contained in this notice, the name of the copyright holder(s)
50 * and author(s) shall not be used in advertising or otherwise to promote
51 * the sale, use or other dealings in this Software without prior written
52 * authorization from the copyright holder(s) and author(s).
55 #ifdef HAVE_XORG_CONFIG_H
56 #include <xorg-config.h>
59 #include "xf86Parser.h"
60 #include "xf86tokens.h"
61 #include "Configint.h"
63 #include "optionstr.h"
65 /* Needed for auto server layout */
66 extern int xf86CheckBoolOption(void *optlist
, const char *name
, int deflt
);
70 static xf86ConfigSymTabRec LayoutTab
[] = {
71 {ENDSECTION
, "endsection"},
73 {IDENTIFIER
, "identifier"},
74 {INACTIVE
, "inactive"},
75 {INPUTDEVICE
, "inputdevice"},
80 static xf86ConfigSymTabRec AdjTab
[] = {
85 {RELATIVE
, "relative"},
86 {ABSOLUTE
, "absolute"},
90 #define CLEANUP xf86freeLayoutList
93 xf86parseLayoutSection(void)
95 int has_ident
= FALSE
;
98 parsePrologue(XF86ConfLayoutPtr
, XF86ConfLayoutRec
)
100 while ((token
= xf86getToken(LayoutTab
)) != ENDSECTION
) {
103 ptr
->lay_comment
= xf86addComment(ptr
->lay_comment
, val
.str
);
106 if (xf86getSubToken(&(ptr
->lay_comment
)) != STRING
)
107 Error(QUOTE_MSG
, "Identifier");
108 if (has_ident
== TRUE
)
109 Error(MULTIPLE_MSG
, "Identifier");
110 ptr
->lay_identifier
= val
.str
;
115 XF86ConfInactivePtr iptr
;
117 iptr
= calloc(1, sizeof(XF86ConfInactiveRec
));
118 iptr
->list
.next
= NULL
;
119 if (xf86getSubToken(&(ptr
->lay_comment
)) != STRING
) {
123 iptr
->inactive_device_str
= val
.str
;
124 ptr
->lay_inactive_lst
= (XF86ConfInactivePtr
)
125 xf86addListItem((glp
) ptr
->lay_inactive_lst
, (glp
) iptr
);
130 XF86ConfAdjacencyPtr aptr
;
133 aptr
= calloc(1, sizeof(XF86ConfAdjacencyRec
));
134 aptr
->list
.next
= NULL
;
135 aptr
->adj_scrnum
= -1;
136 aptr
->adj_where
= CONF_ADJ_OBSOLETE
;
139 aptr
->adj_refscreen
= NULL
;
140 if ((token
= xf86getSubToken(&(ptr
->lay_comment
))) == NUMBER
)
141 aptr
->adj_scrnum
= val
.num
;
143 xf86unGetToken(token
);
144 token
= xf86getSubToken(&(ptr
->lay_comment
));
145 if (token
!= STRING
) {
149 aptr
->adj_screen_str
= val
.str
;
151 token
= xf86getSubTokenWithTab(&(ptr
->lay_comment
), AdjTab
);
154 aptr
->adj_where
= CONF_ADJ_RIGHTOF
;
157 aptr
->adj_where
= CONF_ADJ_LEFTOF
;
160 aptr
->adj_where
= CONF_ADJ_ABOVE
;
163 aptr
->adj_where
= CONF_ADJ_BELOW
;
166 aptr
->adj_where
= CONF_ADJ_RELATIVE
;
169 aptr
->adj_where
= CONF_ADJ_ABSOLUTE
;
174 Error(UNEXPECTED_EOF_MSG
);
177 xf86unGetToken(token
);
178 token
= xf86getSubToken(&(ptr
->lay_comment
));
180 aptr
->adj_where
= CONF_ADJ_OBSOLETE
;
182 aptr
->adj_where
= CONF_ADJ_ABSOLUTE
;
184 switch (aptr
->adj_where
) {
185 case CONF_ADJ_ABSOLUTE
:
187 token
= xf86getSubToken(&(ptr
->lay_comment
));
188 if (token
== NUMBER
) {
189 aptr
->adj_x
= val
.num
;
190 token
= xf86getSubToken(&(ptr
->lay_comment
));
191 if (token
!= NUMBER
) {
193 Error(INVALID_SCR_MSG
);
195 aptr
->adj_y
= val
.num
;
200 Error(INVALID_SCR_MSG
);
203 xf86unGetToken(token
);
206 case CONF_ADJ_RIGHTOF
:
207 case CONF_ADJ_LEFTOF
:
210 case CONF_ADJ_RELATIVE
:
211 token
= xf86getSubToken(&(ptr
->lay_comment
));
212 if (token
!= STRING
) {
214 Error(INVALID_SCR_MSG
);
216 aptr
->adj_refscreen
= val
.str
;
217 if (aptr
->adj_where
== CONF_ADJ_RELATIVE
) {
218 token
= xf86getSubToken(&(ptr
->lay_comment
));
219 if (token
!= NUMBER
) {
221 Error(INVALID_SCR_MSG
);
223 aptr
->adj_x
= val
.num
;
224 token
= xf86getSubToken(&(ptr
->lay_comment
));
225 if (token
!= NUMBER
) {
227 Error(INVALID_SCR_MSG
);
229 aptr
->adj_y
= val
.num
;
232 case CONF_ADJ_OBSOLETE
:
234 aptr
->adj_top_str
= val
.str
;
237 if (xf86getSubToken(&(ptr
->lay_comment
)) != STRING
) {
241 aptr
->adj_bottom_str
= val
.str
;
244 if (xf86getSubToken(&(ptr
->lay_comment
)) != STRING
) {
248 aptr
->adj_left_str
= val
.str
;
251 if (xf86getSubToken(&(ptr
->lay_comment
)) != STRING
) {
255 aptr
->adj_right_str
= val
.str
;
258 ptr
->lay_adjacency_lst
= (XF86ConfAdjacencyPtr
)
259 xf86addListItem((glp
) ptr
->lay_adjacency_lst
, (glp
) aptr
);
264 XF86ConfInputrefPtr iptr
;
266 iptr
= calloc(1, sizeof(XF86ConfInputrefRec
));
267 iptr
->list
.next
= NULL
;
268 iptr
->iref_option_lst
= NULL
;
269 if (xf86getSubToken(&(ptr
->lay_comment
)) != STRING
) {
273 iptr
->iref_inputdev_str
= val
.str
;
274 while ((token
= xf86getSubToken(&(ptr
->lay_comment
))) == STRING
) {
275 iptr
->iref_option_lst
=
276 xf86addNewOption(iptr
->iref_option_lst
, val
.str
, NULL
);
278 xf86unGetToken(token
);
279 ptr
->lay_input_lst
= (XF86ConfInputrefPtr
)
280 xf86addListItem((glp
) ptr
->lay_input_lst
, (glp
) iptr
);
284 ptr
->lay_option_lst
= xf86parseOption(ptr
->lay_option_lst
);
287 Error(UNEXPECTED_EOF_MSG
);
290 Error(INVALID_KEYWORD_MSG
, xf86tokenString());
299 printf("Layout section parsed\n");
308 xf86printLayoutSection(FILE * cf
, XF86ConfLayoutPtr ptr
)
310 XF86ConfAdjacencyPtr aptr
;
311 XF86ConfInactivePtr iptr
;
312 XF86ConfInputrefPtr inptr
;
316 fprintf(cf
, "Section \"ServerLayout\"\n");
317 if (ptr
->lay_comment
)
318 fprintf(cf
, "%s", ptr
->lay_comment
);
319 if (ptr
->lay_identifier
)
320 fprintf(cf
, "\tIdentifier \"%s\"\n", ptr
->lay_identifier
);
322 for (aptr
= ptr
->lay_adjacency_lst
; aptr
; aptr
= aptr
->list
.next
) {
323 fprintf(cf
, "\tScreen ");
324 if (aptr
->adj_scrnum
>= 0)
325 fprintf(cf
, "%2d", aptr
->adj_scrnum
);
328 fprintf(cf
, " \"%s\"", aptr
->adj_screen_str
);
329 switch (aptr
->adj_where
) {
330 case CONF_ADJ_OBSOLETE
:
331 fprintf(cf
, " \"%s\"", aptr
->adj_top_str
);
332 fprintf(cf
, " \"%s\"", aptr
->adj_bottom_str
);
333 fprintf(cf
, " \"%s\"", aptr
->adj_right_str
);
334 fprintf(cf
, " \"%s\"\n", aptr
->adj_left_str
);
336 case CONF_ADJ_ABSOLUTE
:
337 if (aptr
->adj_x
!= -1)
338 fprintf(cf
, " %d %d\n", aptr
->adj_x
, aptr
->adj_y
);
342 case CONF_ADJ_RIGHTOF
:
343 fprintf(cf
, " RightOf \"%s\"\n", aptr
->adj_refscreen
);
345 case CONF_ADJ_LEFTOF
:
346 fprintf(cf
, " LeftOf \"%s\"\n", aptr
->adj_refscreen
);
349 fprintf(cf
, " Above \"%s\"\n", aptr
->adj_refscreen
);
352 fprintf(cf
, " Below \"%s\"\n", aptr
->adj_refscreen
);
354 case CONF_ADJ_RELATIVE
:
355 fprintf(cf
, " Relative \"%s\" %d %d\n", aptr
->adj_refscreen
,
356 aptr
->adj_x
, aptr
->adj_y
);
360 for (iptr
= ptr
->lay_inactive_lst
; iptr
; iptr
= iptr
->list
.next
)
361 fprintf(cf
, "\tInactive \"%s\"\n", iptr
->inactive_device_str
);
362 for (inptr
= ptr
->lay_input_lst
; inptr
; inptr
= inptr
->list
.next
) {
363 fprintf(cf
, "\tInputDevice \"%s\"", inptr
->iref_inputdev_str
);
364 for (optr
= inptr
->iref_option_lst
; optr
; optr
= optr
->list
.next
) {
365 fprintf(cf
, " \"%s\"", optr
->opt_name
);
369 xf86printOptionList(cf
, ptr
->lay_option_lst
, 1);
370 fprintf(cf
, "EndSection\n\n");
371 ptr
= ptr
->list
.next
;
376 xf86freeAdjacencyList(XF86ConfAdjacencyPtr ptr
)
378 XF86ConfAdjacencyPtr prev
;
381 TestFree(ptr
->adj_screen_str
);
382 TestFree(ptr
->adj_top_str
);
383 TestFree(ptr
->adj_bottom_str
);
384 TestFree(ptr
->adj_left_str
);
385 TestFree(ptr
->adj_right_str
);
388 ptr
= ptr
->list
.next
;
395 xf86freeInputrefList(XF86ConfInputrefPtr ptr
)
397 XF86ConfInputrefPtr prev
;
400 TestFree(ptr
->iref_inputdev_str
);
401 xf86optionListFree(ptr
->iref_option_lst
);
403 ptr
= ptr
->list
.next
;
410 xf86freeLayoutList(XF86ConfLayoutPtr ptr
)
412 XF86ConfLayoutPtr prev
;
415 TestFree(ptr
->lay_identifier
);
416 TestFree(ptr
->lay_comment
);
417 xf86freeAdjacencyList(ptr
->lay_adjacency_lst
);
418 xf86freeInputrefList(ptr
->lay_input_lst
);
420 ptr
= ptr
->list
.next
;
426 xf86layoutAddInputDevices(XF86ConfigPtr config
, XF86ConfLayoutPtr layout
)
429 XF86ConfInputPtr input
= config
->conf_input_lst
;
430 XF86ConfInputrefPtr inptr
;
432 /* add all AutoServerLayout devices to the server layout */
434 if (xf86CheckBoolOption
435 (input
->inp_option_lst
, "AutoServerLayout", FALSE
)) {
436 XF86ConfInputrefPtr iref
= layout
->lay_input_lst
;
438 /* avoid duplicates if referenced but lists AutoServerLayout too */
440 if (strcmp(iref
->iref_inputdev_str
, input
->inp_identifier
) == 0)
442 iref
= iref
->list
.next
;
446 XF86ConfInputrefPtr iptr
;
448 iptr
= calloc(1, sizeof(XF86ConfInputrefRec
));
449 iptr
->iref_inputdev_str
= input
->inp_identifier
;
450 layout
->lay_input_lst
= (XF86ConfInputrefPtr
)
451 xf86addListItem((glp
) layout
->lay_input_lst
, (glp
) iptr
);
455 input
= input
->list
.next
;
458 inptr
= layout
->lay_input_lst
;
460 input
= xf86findInput(inptr
->iref_inputdev_str
, config
->conf_input_lst
);
462 xf86validationError(UNDEFINED_INPUT_MSG
,
463 inptr
->iref_inputdev_str
,
464 layout
->lay_identifier
);
468 inptr
->iref_inputdev
= input
;
469 inptr
= inptr
->list
.next
;
476 xf86validateLayout(XF86ConfigPtr p
)
478 XF86ConfLayoutPtr layout
= p
->conf_layout_lst
;
479 XF86ConfAdjacencyPtr adj
;
480 XF86ConfInactivePtr iptr
;
481 XF86ConfScreenPtr screen
;
482 XF86ConfDevicePtr device
;
485 adj
= layout
->lay_adjacency_lst
;
487 /* the first one can't be "" but all others can */
488 screen
= xf86findScreen(adj
->adj_screen_str
, p
->conf_screen_lst
);
490 xf86validationError(UNDEFINED_SCREEN_MSG
,
492 layout
->lay_identifier
);
496 adj
->adj_screen
= screen
;
498 adj
= adj
->list
.next
;
500 iptr
= layout
->lay_inactive_lst
;
502 device
= xf86findDevice(iptr
->inactive_device_str
,
505 xf86validationError(UNDEFINED_DEVICE_LAY_MSG
,
506 iptr
->inactive_device_str
,
507 layout
->lay_identifier
);
511 iptr
->inactive_device
= device
;
512 iptr
= iptr
->list
.next
;
515 if (xf86layoutAddInputDevices(p
, layout
) == -1)
518 layout
= layout
->list
.next
;
524 xf86findLayout(const char *name
, XF86ConfLayoutPtr list
)
527 if (xf86nameCompare(list
->lay_identifier
, name
) == 0)
529 list
= list
->list
.next
;