2 * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * Except as contained in this notice, the name of Conectiva Linux shall
23 * not be used in advertising or otherwise to promote the sale, use or other
24 * dealings in this Software without prior written authorization from
27 * Author: Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
34 #if defined(__SCO__) || defined(__UNIXWARE__) || \
35 (defined(sun) && defined(__SVR4)) || defined(__NetBSD__)
42 #include <X11/extensions/XKBstr.h>
43 #include <X11/extensions/XKBrules.h>
46 #include "xf86config.h"
49 #define IS_KBDDRIV(X) ((strcmp((X),"kbd") == 0))
52 #define PROJECT_ROOT "/usr"
56 #define XKB_RULES_DIR PROJECT_ROOT "/share/X11/xkb/rules"
64 #define MIN(a, b) ((a) < (b) ? (a) : (b))
65 #define MAX(a, b) ((a) > (b) ? (a) : (b))
69 static void ClearScreen(void);
70 static void PaintWindow(WINDOW
*, char*, int, int, int, int);
71 static void PaintBox(WINDOW
*, int, int, int, int);
72 static void PaintButton(WINDOW
*, char*, int, int, int);
73 static void PrintWrap(WINDOW
*, char*, int, int, int);
74 static int Dialog(char*, char*, int, int, char*, char*, int);
75 static void PaintItem(WINDOW
*, char*, int, int);
76 static int DialogMenu(char*, char*, int, int, int, int, char**, char*, char*, int);
77 static void PaintCheckItem(WINDOW
*, char*, int, int, int);
78 static int DialogCheckBox(char*, char*, int, int, int, int, char**, char*, char*, char*);
79 static char *DialogInput(char*, char*, int, int, char*, char*, char*, int);
80 static void PaintScroller(WINDOW
*, int, int, int);
82 static int MouseConfig(void);
83 static int KeyboardConfig(void);
84 static int MonitorConfig(void);
85 static int CardConfig(void);
86 static int ScreenConfig(void);
87 static int LayoutConfig(void);
88 static int WriteXF86Config(void);
90 static XF86ConfLayoutPtr
CopyLayout(XF86ConfLayoutPtr
);
91 static XF86ConfAdjacencyPtr
CopyAdjacency(XF86ConfAdjacencyPtr
);
92 static XF86ConfInputrefPtr
CopyInputref(XF86ConfInputrefPtr
);
93 static XF86ConfInactivePtr
CopyInactive(XF86ConfInactivePtr
);
94 static void FreeLayout(XF86ConfLayoutPtr
);
96 extern int string_to_parser_range(char*, parser_range
*, int);
97 #define PARSER_RANGE_SIZE 256
98 /* string must have at least 256 bytes */
99 extern int parser_range_to_string(char*, parser_range
*, int);
101 static Bool newconfig
;
103 static chtype screen_attr
= A_NORMAL
;
104 static chtype dialog_attr
= A_REVERSE
;
105 static chtype highlight_border_attr
= A_REVERSE
;
106 static chtype shadow_border_attr
= A_REVERSE
;
107 static chtype title_attr
= A_NORMAL
;
108 static chtype button_active_attr
= A_NORMAL
;
109 static chtype button_inactive_attr
= A_NORMAL
;
110 static int menu_width
, item_x
;
111 static char Edit
[] = "Edit ";
113 static char *main_menu
[] = {
116 #define CONF_KEYBOARD 1
117 "Configure keyboard",
118 #define CONF_MONITOR 2
122 #define CONF_SCREEN 4
124 #define CONF_LAYOUT 5
126 #define CONF_FINISH 6
127 "Write "__XCONFIGFILE__
" and quit",
135 static int first
= 1;
136 int i
, choice
= CONF_MOUSE
;
140 LoaderInitializeOptions();
145 keypad(stdscr
, TRUE
);
148 const char *filename
;
154 init_pair(1, COLOR_BLACK
, COLOR_BLACK
);
155 screen_attr
= A_BOLD
| COLOR_PAIR(1);
157 init_pair(2, COLOR_BLACK
, COLOR_WHITE
);
158 dialog_attr
= COLOR_PAIR(2);
160 init_pair(3, COLOR_BLACK
, COLOR_WHITE
);
161 shadow_border_attr
= A_BOLD
| COLOR_PAIR(3);
163 init_pair(4, COLOR_WHITE
, COLOR_WHITE
);
164 highlight_border_attr
= A_BOLD
| COLOR_PAIR(4);
166 init_pair(5, COLOR_WHITE
, COLOR_BLUE
);
167 title_attr
= A_BOLD
| COLOR_PAIR(5);
168 button_active_attr
= title_attr
;
170 init_pair(6, COLOR_WHITE
, COLOR_BLACK
);
171 button_inactive_attr
= A_BOLD
| COLOR_PAIR(6);
174 if ((filename
= xf86openConfigFile(getuid() == 0 ?
175 CONFPATH
: USER_CONFPATH
,
176 XF86Config_path
, NULL
)) != NULL
) {
177 XF86Config_path
= (char *)filename
;
178 if ((XF86Config
= xf86readConfigFile()) == NULL
) {
181 Dialog("Configuration error",
182 "Error parsing configuration file.",
183 7, 50, " Ok ", NULL
, 0);
186 if (XF86Config
== NULL
) {
187 XF86Config
= (XF86ConfigPtr
)XtCalloc(1, sizeof(XF86ConfigRec
));
203 if (Dialog( __XSERVERNAME__
" Configuration",
204 "This program will create the "__XCONFIGFILE__
" file, based on "
205 "menu selections you make.\n"
207 #if defined(__SCO__) || defined(__UNIXWARE__)
208 "The "__XCONFIGFILE__
" file usually resides in /etc. A "
209 "sample "__XCONFIGFILE__
" file is supplied with "
211 "The "__XCONFIGFILE__
" file usually resides in " PROJECT_ROOT
"/etc/X11 "
212 "or /etc/X11. A sample "__XCONFIGFILE__
" file is supplied with "
214 __XSERVERNAME__
"; it is configured for a standard VGA card and "
215 "monitor with 640x480 resolution. This program will ask for "
216 "a pathname when it is ready to write the file.\n"
218 "You can either take the sample "__XCONFIGFILE__
" as a base and "
219 "edit it for your configuration, or let this program "
220 "produce a base "__XCONFIGFILE__
" file for your configuration and "
222 20, 60, " Ok ", " Cancel ", 0) != 0)
228 switch (DialogMenu("Main menu",
229 "Choose one of the options:",
230 17, 60, 8, sizeof(main_menu
) /
231 sizeof(main_menu
[0]), main_menu
,
232 " Ok ", " Cancel ", choice
)) {
235 if (i
> 0 && choice
== CONF_MOUSE
)
236 choice
= CONF_KEYBOARD
;
241 i
= KeyboardConfig();
242 if (i
> 0 && choice
<= CONF_KEYBOARD
)
243 choice
= CONF_MONITOR
;
245 choice
= CONF_KEYBOARD
;
249 if (i
> 0 && choice
<= CONF_MONITOR
)
252 choice
= CONF_MONITOR
;
256 if (i
> 0 && choice
<= CONF_CARD
)
257 choice
= CONF_SCREEN
;
263 if (i
> 0 && choice
<= CONF_SCREEN
)
264 choice
= CONF_LAYOUT
;
266 choice
= CONF_SCREEN
;
270 if (i
> 0 && choice
<= CONF_LAYOUT
)
271 choice
= CONF_FINISH
;
273 choice
= CONF_LAYOUT
;
276 if (WriteXF86Config() < 0)
293 WriteXF86Config(void)
299 xf86config
= DialogInput("Write "__XCONFIGFILE__
, "Write configuration to file:",
300 10, 60, XF86Config_path
? XF86Config_path
:
301 "/etc/X11/"__XCONFIGFILE__
, " Ok ", " Cancel ", 0);
303 if (xf86config
== NULL
)
307 if (XF86Config
->conf_modules
== NULL
) {
308 static char *modules
[] = {"extmod", "glx", "dri", "dbe",
309 "record", "xtrap", "type1"};
313 XF86Config
->conf_modules
= (XF86ConfModulePtr
)
314 XtCalloc(1, sizeof(XF86ConfModuleRec
));
316 XF86Config
->conf_modules
->mod_comment
=
317 XtNewString("\tLoad \"freetype\"\n"
318 "\t# Load \"xtt\"\n");
320 for (i
= 0; i
< sizeof(modules
) / sizeof(modules
[0]); i
++) {
321 load
= (XF86LoadPtr
)XtCalloc(1, sizeof(XF86LoadRec
));
322 load
->load_name
= XtNewString(modules
[i
]);
323 XF86Config
->conf_modules
->mod_load_lst
=
324 xf86addModule(XF86Config
->conf_modules
->mod_load_lst
, load
);
329 if (!xf86writeConfigFile(xf86config
, XF86Config
)) {
332 XmuSnprintf(msg
, sizeof(msg
), "Failed to write configuration file %s.",
336 (void)Dialog("Write failed!", msg
, 8, 60, " Ok ", NULL
, 0);
345 static char *protocols
[] = {
349 #ifdef WSCONS_SUPPORT
380 int i
, nlist
, def
, proto
, emul
;
381 char **list
= NULL
, *device
, *str
;
382 XF86ConfInputPtr
*inputs
= NULL
;
383 XF86ConfInputPtr input
= XF86Config
->conf_input_lst
;
384 XF86OptionPtr option
;
388 if (strcmp(input
->inp_driver
, "mouse") == 0) {
389 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
390 list
[nlist
] = XtMalloc(sizeof(Edit
) +
391 strlen(input
->inp_identifier
) + 1);
392 sprintf(list
[nlist
], "%s%s", Edit
, input
->inp_identifier
);
393 inputs
= (XF86ConfInputPtr
*)XtRealloc((XtPointer
)inputs
, (nlist
+ 1) *
394 sizeof(XF86ConfInputPtr
));
395 inputs
[nlist
] = input
;
398 input
= (XF86ConfInputPtr
)(input
->list
.next
);
404 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 2) * sizeof(char*));
405 list
[nlist
++] = XtNewString("Add new mouse");
407 i
= strlen("Remove ") + strlen(inputs
[0]->inp_identifier
) + 1;
408 list
[nlist
] = XtMalloc(i
);
409 XmuSnprintf(list
[nlist
], i
, "Remove %s", inputs
[0]->inp_identifier
);
413 list
[nlist
++] = XtNewString("Remove mouse");
416 i
= DialogMenu("Mouse configuration",
417 "You can edit or remove a previously configured mouse, "
418 "or add a new one.", 14, 60, 4, nlist
, list
,
419 " Ok ", " Cancel ", 0);
421 for (i
= 0; i
< nlist
; i
++)
423 XtFree((XtPointer
)list
);
424 XtFree((XtPointer
)inputs
);
427 if (nlist
> 2 && i
== nlist
- 1) {
429 for (i
= 0; i
< nlist
- 2; i
++) {
430 /* XXX Remove the "Edit " from list entries */
431 memmove(list
[i
], list
[i
] + sizeof(Edit
) - 1,
432 strlen(list
[i
]) - sizeof(Edit
) + 2);
436 i
= DialogMenu("Remove mouse",
437 "Select which mouse to remove",
438 13, 60, 4, nlist
- 2, list
,
439 " Remove ", " Cancel ", 0);
441 for (i
= 0; i
< nlist
; i
++)
443 XtFree((XtPointer
)list
);
444 XtFree((XtPointer
)inputs
);
451 for (i
= 0; i
< nlist
; i
++)
453 XtFree((XtPointer
)list
);
454 XtFree((XtPointer
)inputs
);
455 xf86removeInput(XF86Config
, input
);
461 for (i
= 0; i
< nlist
; i
++)
463 XtFree((XtPointer
)list
);
464 XtFree((XtPointer
)inputs
);
469 input
= (XF86ConfInputPtr
)XtCalloc(1, sizeof(XF86ConfInputRec
));
470 XmuSnprintf(label
, sizeof(label
), "Mouse%d", nlist
? nlist
- 2 : 0);
473 input
->inp_identifier
=
474 DialogInput("Mouse identifier",
475 "Enter an identifier for your mouse definition:",
477 " Next >>", " Cancel ", 0);
478 if (input
->inp_identifier
== NULL
) {
479 XtFree((XtPointer
)input
);
485 option
= xf86findOption(input
->inp_option_lst
, "Protocol");
487 for (i
= 0; i
< sizeof(protocols
)/sizeof(protocols
[0]); i
++)
488 if (strcasecmp(option
->opt_val
, protocols
[i
]) == 0) {
495 i
= DialogMenu("Select mouse protocol",
496 "If you have a serial mouse, it probably will work with "
497 "the \"Auto\" protocol. But, if it is an old serial "
498 "mouse probably it is not PNP; in that case, most serial "
499 "mouses understand the \"Microsoft\" protocol.",
500 19, 60, 7, sizeof(protocols
) /
501 sizeof(protocols
[0]), protocols
, " Next >>", " Cancel ", def
);
503 if (input
->inp_driver
== NULL
) {
504 XtFree(input
->inp_driver
);
505 XtFree((XtPointer
)input
);
512 if (input
->inp_driver
) {
513 option
= xf86findOption(input
->inp_option_lst
, "Emulate3Buttons");
514 def
= option
? 0 : 1;
518 i
= Dialog("Mouse 3 buttons emulation",
519 "If your mouse has only two buttons, it is recommended that "
520 "you enable Emulate3Buttons.\n"
522 "Do you want to enable Emulate3Buttons?",
523 10, 60, " Yes ", " No ", def
);
529 option
= xf86findOption(input
->inp_option_lst
, "Device");
531 str
= option
->opt_val
;
533 #ifdef WSCONS_SUPPORT
534 str
= "/dev/wsmouse";
535 #elif defined(__FreeBSD__) || defined(__DragonFly__)
536 str
= "/dev/sysmouse";
537 #elif defined(__linux__)
538 str
= "/dev/input/mice";
545 device
= DialogInput("Select mouse device",
546 "Enter mouse device:", 10, 40, str
,
547 " Finish ", " Cancel ", 0);
548 if (device
== NULL
) {
549 if (input
->inp_driver
== NULL
) {
550 XtFree(input
->inp_driver
);
551 XtFree((XtPointer
)input
);
556 /* Finish mouse configuration */
557 option
= xf86findOption(input
->inp_option_lst
, "Protocol");
559 XtFree((XtPointer
)option
->opt_val
);
560 option
->opt_val
= XtNewString(protocols
[proto
]);
563 input
->inp_option_lst
= xf86addNewOption(input
->inp_option_lst
,
564 XtNewString("Protocol"), XtNewString(protocols
[proto
]));
566 option
= xf86findOption(input
->inp_option_lst
, "Emulate3Buttons");
567 if (option
&& !emul
) {
568 xf86removeOption(&input
->inp_option_lst
, "Emulate3Buttons");
570 else if (option
== NULL
&& emul
)
571 input
->inp_option_lst
= xf86addNewOption(input
->inp_option_lst
,
572 XtNewString("Emulate3Buttons"), NULL
);
574 option
= xf86findOption(input
->inp_option_lst
, "Device");
576 XtFree((XtPointer
)option
->opt_val
);
577 option
->opt_val
= device
;
580 input
->inp_option_lst
= xf86addNewOption(input
->inp_option_lst
,
581 XtNewString("Device"), device
);
583 if (input
->inp_driver
== NULL
) {
584 input
->inp_driver
= XtNewString("mouse");
585 XF86Config
->conf_input_lst
=
586 xf86addInput(XF86Config
->conf_input_lst
, input
);
597 static int first
= 1;
598 static XkbRF_RulesPtr rules
;
599 static char **models
, **layouts
;
600 XF86ConfInputPtr
*inputs
= NULL
, input
= XF86Config
->conf_input_lst
;
601 char **list
= NULL
, *model
, *layout
;
603 XF86OptionPtr option
;
607 if (IS_KBDDRIV(input
->inp_driver
)) {
608 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
609 list
[nlist
] = XtMalloc(sizeof(Edit
) +
610 strlen(input
->inp_identifier
) + 1);
611 sprintf(list
[nlist
], "%s%s", Edit
, input
->inp_identifier
);
612 inputs
= (XF86ConfInputPtr
*)XtRealloc((XtPointer
)inputs
, (nlist
+ 1) *
613 sizeof(XF86ConfInputPtr
));
614 inputs
[nlist
] = input
;
617 input
= (XF86ConfInputPtr
)(input
->list
.next
);
623 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 2) * sizeof(char*));
624 list
[nlist
++] = XtNewString("Add new keyboard");
626 i
= strlen("Remove ") + strlen(inputs
[0]->inp_identifier
) + 1;
627 list
[nlist
] = XtMalloc(i
);
628 XmuSnprintf(list
[nlist
], i
, "Remove %s", inputs
[0]->inp_identifier
);
632 list
[nlist
++] = XtNewString("Remove keyboard");
635 i
= DialogMenu("Keyboard configuration",
636 "You can edit or remove a previously configured "
637 "keyboard, or add a new one.", 14, 60, 4, nlist
, list
,
638 " Ok ", " Cancel ", 0);
640 for (i
= 0; i
< nlist
; i
++)
642 XtFree((XtPointer
)list
);
643 XtFree((XtPointer
)inputs
);
646 if (nlist
> 2 && i
== nlist
- 1) {
648 for (i
= 0; i
< nlist
- 2; i
++) {
649 /* XXX Remove the "Edit " from list entries */
650 memmove(list
[i
], list
[i
] + sizeof(Edit
) - 1,
651 strlen(list
[i
]) - sizeof(Edit
) + 2);
655 i
= DialogMenu("Remove keyboard",
656 "Select which keyboard to remove",
657 13, 60, 4, nlist
- 2, list
,
658 " Remove ", " Cancel ", 0);
660 for (i
= 0; i
< nlist
; i
++)
662 XtFree((XtPointer
)list
);
663 XtFree((XtPointer
)inputs
);
670 for (i
= 0; i
< nlist
; i
++)
672 XtFree((XtPointer
)list
);
673 XtFree((XtPointer
)inputs
);
674 xf86removeInput(XF86Config
, input
);
680 for (i
= 0; i
< nlist
; i
++)
682 XtFree((XtPointer
)list
);
683 XtFree((XtPointer
)inputs
);
688 input
= (XF86ConfInputPtr
)XtCalloc(1, sizeof(XF86ConfInputRec
));
689 XmuSnprintf(label
, sizeof(label
), "Keyboard%d", nlist
? nlist
- 2 : 0);
692 input
->inp_identifier
=
693 DialogInput("Keyboard identifier",
694 "Enter an identifier for your keyboard definition:",
696 " Next >>", " Cancel ", 0);
697 if (input
->inp_identifier
== NULL
) {
698 XtFree((XtPointer
)input
);
706 rulesfile
= XKB_RULES_DIR
"/xfree98";
708 rulesfile
= XKB_RULES_DIR
"/"__XKBDEFRULES__
;
710 rules
= XkbRF_Load(rulesfile
, "", True
, False
);
714 Dialog("Configuration error",
715 "XKB rules file not found.\n"
717 "Keyboard XKB options will be set to default values.",
718 10, 50, " Ok ", NULL
, 0);
719 if (input
->inp_driver
== NULL
) {
720 input
->inp_option_lst
=
721 xf86addNewOption(input
->inp_option_lst
,
722 XtNewString("XkbModel"), XtNewString("pc101"));
723 input
->inp_option_lst
=
724 xf86addNewOption(input
->inp_option_lst
,
725 XtNewString("XkbLayout"), XtNewString("us"));
726 input
->inp_driver
= XtNewString("kbd");
727 XF86Config
->conf_input_lst
=
728 xf86addInput(XF86Config
, input
);
732 models
= (char**)XtMalloc(sizeof(char*) * rules
->models
.num_desc
);
733 for (i
= 0; i
< rules
->models
.num_desc
; i
++)
734 models
[i
] = XtNewString(rules
->models
.desc
[i
].desc
);
735 layouts
= (char**)XtMalloc(sizeof(char*) * rules
->layouts
.num_desc
);
736 for (i
= 0; i
< rules
->layouts
.num_desc
; i
++)
737 layouts
[i
] = XtNewString(rules
->layouts
.desc
[i
].desc
);
739 else if (rules
== NULL
)
743 option
= xf86findOption(input
->inp_option_lst
, "XkbModel");
745 for (i
= 0; i
< rules
->models
.num_desc
; i
++)
746 if (strcasecmp(option
->opt_val
, rules
->models
.desc
[i
].name
) == 0) {
753 i
= DialogMenu("Keyboard model",
754 "Please select one of the following keyboard types that is "
755 "the better description of your keyboard. If nothing really "
756 "matches, choose \"Generic 101-key PC\".\n",
757 20, 60, 9, rules
->models
.num_desc
,
758 models
, " Next >>", " Cancel ", def
);
761 model
= rules
->models
.desc
[i
].name
;
764 option
= xf86findOption(input
->inp_option_lst
, "XkbLayout");
766 for (i
= 0; i
< rules
->layouts
.num_desc
; i
++)
767 if (strcasecmp(option
->opt_val
, rules
->layouts
.desc
[i
].name
) == 0) {
774 i
= DialogMenu("Keyboard layout",
775 "Select keyboard layout:",
776 20, 60, 11, rules
->layouts
.num_desc
,
777 layouts
, " Finish ", " Cancel ", def
);
780 layout
= rules
->layouts
.desc
[i
].name
;
782 /* Finish keyboard configuration */
783 option
= xf86findOption(input
->inp_option_lst
, "XkbModel");
785 XtFree((XtPointer
)option
->opt_val
);
786 option
->opt_val
= XtNewString(model
);
789 input
->inp_option_lst
= xf86addNewOption(input
->inp_option_lst
,
790 XtNewString("XkbModel"), XtNewString(model
));
792 option
= xf86findOption(input
->inp_option_lst
, "XkbLayout");
794 XtFree((XtPointer
)option
->opt_val
);
795 option
->opt_val
= XtNewString(layout
);
798 input
->inp_option_lst
= xf86addNewOption(input
->inp_option_lst
,
799 XtNewString("XkbLayout"), XtNewString(layout
));
801 if (input
->inp_driver
== NULL
) {
802 input
->inp_driver
= XtNewString("kbd");
803 XF86Config
->conf_input_lst
=
804 xf86addInput(XF86Config
->conf_input_lst
, input
);
810 static char *hsync
[] = {
811 #define CONF_MONITOR_HSYNC 0
812 "Enter your own horizontal sync range",
813 "31.5; Standard VGA, 640x480 @ 60 Hz",
814 "31.5 - 35.1; Super VGA, 800x600 @ 56 Hz",
815 "31.5, 35.5; 8514 Compatible, 1024x768 @ 87 Hz interlaced (no 800x600)",
816 "31.5, 35.15, 35.5; Super VGA, 1024x768 @ 87 Hz int., 800x600 @ 56 Hz",
817 "31.5 - 37.9; Extended Super VGA, 800x600 @ 60 Hz, 640x480 @ 72 Hz",
818 "31.5 - 48.5; Non-Interlaced SVGA, 1024x768 @ 60 Hz, 800x600 @ 72 Hz",
819 "31.5 - 57.0; High Frequency SVGA, 1024x768 @ 70 Hz",
820 "31.5 - 64.3; Monitor that can do 1280x1024 @ 60 Hz",
821 "31.5 - 79.0; Monitor that can do 1280x1024 @ 74 Hz",
822 "31.5 - 82.0; Monitor that can do 1280x1024 @ 76 Hz",
823 "31.5 - 92.0; Monitor that can do 1280x1024 @ 85 Hz",
824 "31.5 - 108.0; Monitor that can do 1600x1200 @ 85 Hz",
825 "31.5 - 128.5; Monitor that can do 1920x1440 @ 85 Hz",
826 "31.5 - 137.0; Monitor that can do 2048x1536 @ 85 Hz"
829 static char *vrefresh
[] = {
830 #define CONF_MONITOR_VREFRESH 0
831 "Enter your own vertical sync range",
842 XF86ConfMonitorPtr
*monitors
= NULL
, monitor
= XF86Config
->conf_monitor_lst
;
843 char **list
= NULL
, *identifier
= NULL
, *tmp
;
845 char hsync_str
[256], vrefresh_str
[256];
847 hsync_str
[0] = vrefresh_str
[0] = '\0';
850 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
851 list
[nlist
] = XtMalloc(sizeof(Edit
) +
852 strlen(monitor
->mon_identifier
) + 1);
853 sprintf(list
[nlist
], "%s%s", Edit
, monitor
->mon_identifier
);
854 monitors
= (XF86ConfMonitorPtr
*)XtRealloc((XtPointer
)monitors
, (nlist
+ 1) *
855 sizeof(XF86ConfMonitorPtr
));
856 monitors
[nlist
] = monitor
;
858 monitor
= (XF86ConfMonitorPtr
)(monitor
->list
.next
);
864 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 2) * sizeof(char*));
865 list
[nlist
++] = XtNewString("Add new monitor");
867 i
= strlen("Remove ") + strlen(monitors
[0]->mon_identifier
) + 1;
868 list
[nlist
] = XtMalloc(i
);
869 XmuSnprintf(list
[nlist
], i
, "Remove %s", monitors
[0]->mon_identifier
);
873 list
[nlist
++] = XtNewString("Remove monitor");
876 i
= DialogMenu("Monitor configuration",
877 "You can edit or remove a previously configured "
878 "monitor, or add a new one.", 14, 60, 4, nlist
, list
,
879 " Ok ", " Cancel ", 0);
881 for (i
= 0; i
< nlist
; i
++)
883 XtFree((XtPointer
)list
);
884 XtFree((XtPointer
)monitors
);
887 if (nlist
> 2 && i
== nlist
- 1) {
889 for (i
= 0; i
< nlist
- 2; i
++) {
890 /* XXX Remove the "Edit " from list entries */
891 memmove(list
[i
], list
[i
] + sizeof(Edit
) - 1,
892 strlen(list
[i
]) - sizeof(Edit
) + 2);
896 i
= DialogMenu("Remove monitor",
897 "Select which monitor to remove",
898 13, 60, 4, nlist
- 2, list
,
899 " Remove ", " Cancel ", 0);
901 for (i
= 0; i
< nlist
; i
++)
903 XtFree((XtPointer
)list
);
904 XtFree((XtPointer
)monitors
);
907 monitor
= monitors
[i
];
910 monitor
= monitors
[0];
911 for (i
= 0; i
< nlist
; i
++)
913 XtFree((XtPointer
)list
);
914 XtFree((XtPointer
)monitors
);
915 xf86removeMonitor(XF86Config
, monitor
);
919 monitor
= monitors
[i
];
921 for (i
= 0; i
< nlist
; i
++)
923 XtFree((XtPointer
)list
);
924 XtFree((XtPointer
)monitors
);
926 if (monitor
== NULL
) {
929 monitor
= (XF86ConfMonitorPtr
)XtCalloc(1, sizeof(XF86ConfMonitorRec
));
930 XmuSnprintf(label
, sizeof(label
), "Monitor%d", nlist
? nlist
- 2 : 0);
934 DialogInput("Monitor identifier",
935 "Enter an identifier for your monitor definition:",
937 " Next >>", " Cancel ", 0);
938 if (identifier
== NULL
) {
939 XtFree((XtPointer
)monitor
);
944 if (monitor
->mon_identifier
== NULL
) {
947 i
= Dialog("Monitor configuration",
948 "Now we want to set the specifications of the monitor. The "
949 "two critical parameters are the vertical refresh rate, which "
950 "is the rate at which the whole screen is refreshed, and most "
951 "importantly the horizontal sync rate, which is the rate at "
952 "which scanlines are displayed.\n"
954 "The valid range for horizontal sync and vertical sync should "
955 "be documented in the manual of your monitor.",
956 15, 60, " Next >>", " Cancel ", 0);
959 XtFree((XtPointer
)monitor
);
965 if (monitor
->mon_identifier
) {
968 parser_range_to_string(hsync_str
, &(monitor
->mon_hsync
[0]),
969 monitor
->mon_n_hsync
);
970 len
= strlen(hsync_str
);
971 for (i
= 1; i
< sizeof(hsync
) / sizeof(hsync
[0]); i
++) {
972 tmp
= strchr(hsync
[i
], ';');
973 if (strncmp(hsync_str
, hsync
[i
], len
) == 0) {
979 if (hsync_str
[0] == '\0')
980 strcpy(hsync_str
, "31.5");
984 i
= DialogMenu("Monitor HorizSync",
985 "You must indicate the horizontal sync range of your "
986 "monitor. You can either select one of the predefined "
987 "ranges below that correspond to industry-standard monitor "
988 "types, or give a specific range.",
989 22, 78, 11, sizeof(hsync
) /
990 sizeof(hsync
[0]), hsync
, " Next >>", " Cancel ", def
);
992 if (monitor
->mon_identifier
== NULL
) {
994 XtFree((XtPointer
)monitor
);
998 if (i
== CONF_MONITOR_HSYNC
) {
1001 tmp
= DialogInput("Monitor HorizSync",
1002 "Please enter the horizontal sync range of your "
1003 "monitor, in the format used in the table of monitor "
1004 "types above. You can either specify one or more "
1005 "continuous ranges (e.g. 15-25, 30-50), or one or more "
1006 "fixed sync frequencies.\n"
1008 "Horizontal sync range:", 16, 62, hsync_str
,
1009 " Ok ", " Cancel ", def
);
1011 if (monitor
->mon_identifier
== NULL
) {
1013 XtFree((XtPointer
)monitor
);
1017 XmuSnprintf(hsync_str
, sizeof(hsync_str
), "%s", tmp
);
1021 tmp
= strchr(hsync
[i
], ';');
1022 strncpy(hsync_str
, hsync
[i
], tmp
- hsync
[i
]);
1023 hsync_str
[tmp
- hsync
[i
]] = '\0';
1027 if (monitor
->mon_identifier
) {
1028 parser_range_to_string(vrefresh_str
, &(monitor
->mon_vrefresh
[0]),
1029 monitor
->mon_n_vrefresh
);
1030 for (i
= 1; i
< sizeof(vrefresh
) / sizeof(vrefresh
[0]); i
++) {
1031 if (strcmp(vrefresh_str
, vrefresh
[i
]) == 0) {
1037 if (vrefresh_str
[0] == '\0')
1038 strcpy(vrefresh_str
, "50 - 70");
1041 i
= DialogMenu("Monitor VertRefresh",
1042 "You must indicate the vertical sync range of your monitor. "
1043 "You can either select one of the predefined ranges below "
1044 "that correspond to industry-standard monitor types, or "
1045 "give a specific range. For interlaced modes, the number "
1046 "that counts is the high one (e.g. 87 Hz rather than 43 Hz).",
1047 19, 60, 5, sizeof(vrefresh
) /
1048 sizeof(vrefresh
[0]), vrefresh
, " Finish ", " Cancel ", def
);
1050 if (monitor
->mon_identifier
== NULL
) {
1052 XtFree((XtPointer
)monitor
);
1056 if (i
== CONF_MONITOR_VREFRESH
) {
1059 tmp
= DialogInput("Monitor VertRefresh",
1060 "Vertical sync range:", 10, 50, vrefresh_str
,
1061 " Done ", " Cancel ", 0);
1063 if (monitor
->mon_identifier
== NULL
) {
1065 XtFree((XtPointer
)monitor
);
1069 XmuSnprintf(vrefresh_str
, sizeof(vrefresh_str
), "%s", tmp
);
1073 strcpy(vrefresh_str
, vrefresh
[i
]);
1075 /* Finish monitor configuration */
1076 monitor
->mon_n_hsync
= string_to_parser_range(hsync_str
,
1077 &(monitor
->mon_hsync
[0]), CONF_MAX_HSYNC
);
1078 monitor
->mon_n_vrefresh
= string_to_parser_range(vrefresh_str
,
1079 &(monitor
->mon_vrefresh
[0]), CONF_MAX_VREFRESH
);
1080 if (monitor
->mon_identifier
== NULL
) {
1081 monitor
->mon_identifier
= identifier
;
1082 XF86Config
->conf_monitor_lst
=
1083 xf86addMonitor(XF86Config
->conf_monitor_lst
, monitor
);
1093 XF86ConfDevicePtr
*devices
= NULL
, device
= XF86Config
->conf_device_lst
;
1094 char **list
= NULL
, *identifier
= NULL
, *driver
, *busid
, *tmp
;
1096 CardsEntry
*entry
= NULL
;
1097 static char **drivers
;
1098 static int ndrivers
;
1099 static char *xdrivers
[] = {
1135 xf86cfgModuleOptions
*opts
= module_options
;
1140 if (opts
->type
== VideoModule
) {
1142 drivers
= (char**)XtRealloc((XtPointer
)drivers
,
1143 ndrivers
* sizeof(char*));
1144 /* XXX no private copy */
1145 drivers
[ndrivers
- 1] = opts
->name
;
1153 ndrivers
= sizeof(xdrivers
) / sizeof(xdrivers
[0]);
1159 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
1160 list
[nlist
] = XtMalloc(sizeof(Edit
) +
1161 strlen(device
->dev_identifier
) + 1);
1162 sprintf(list
[nlist
], "%s%s", Edit
, device
->dev_identifier
);
1163 devices
= (XF86ConfDevicePtr
*)XtRealloc((XtPointer
)devices
, (nlist
+ 1) *
1164 sizeof(XF86ConfDevicePtr
));
1165 devices
[nlist
] = device
;
1167 device
= (XF86ConfDevicePtr
)(device
->list
.next
);
1173 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 2) * sizeof(char*));
1174 list
[nlist
++] = XtNewString("Add new card");
1176 i
= strlen("Remove ") + strlen(devices
[0]->dev_identifier
) + 1;
1177 list
[nlist
] = XtMalloc(i
);
1178 XmuSnprintf(list
[nlist
], i
, "Remove %s", devices
[0]->dev_identifier
);
1182 list
[nlist
++] = XtNewString("Remove device");
1185 i
= DialogMenu("Card configuration",
1186 "You can edit or remove a previously configured "
1187 "card, or add a new one.", 14, 60, 4, nlist
, list
,
1188 " Ok ", " Cancel ", 0);
1190 for (i
= 0; i
< nlist
; i
++)
1192 XtFree((XtPointer
)list
);
1193 XtFree((XtPointer
)devices
);
1196 if (nlist
> 2 && i
== nlist
- 1) {
1198 for (i
= 0; i
< nlist
- 2; i
++) {
1199 /* XXX Remove the "Edit " from list entries */
1200 memmove(list
[i
], list
[i
] + sizeof(Edit
) - 1,
1201 strlen(list
[i
]) - sizeof(Edit
) + 2);
1205 i
= DialogMenu("Remove card",
1206 "Select which card to remove",
1207 13, 60, 4, nlist
- 2, list
,
1208 " Remove ", " Cancel ", 0);
1210 for (i
= 0; i
< nlist
; i
++)
1212 XtFree((XtPointer
)list
);
1213 XtFree((XtPointer
)devices
);
1216 device
= devices
[i
];
1219 device
= devices
[0];
1220 for (i
= 0; i
< nlist
; i
++)
1222 XtFree((XtPointer
)list
);
1223 XtFree((XtPointer
)devices
);
1224 xf86removeDevice(XF86Config
, device
);
1228 device
= devices
[i
];
1230 for (i
= 0; i
< nlist
; i
++)
1232 XtFree((XtPointer
)list
);
1233 XtFree((XtPointer
)devices
);
1235 if (device
== NULL
) {
1238 device
= (XF86ConfDevicePtr
)XtCalloc(1, sizeof(XF86ConfDeviceRec
));
1239 device
->dev_chipid
= device
->dev_chiprev
= device
->dev_irq
= -1;
1240 XmuSnprintf(label
, sizeof(label
), "Card%d", nlist
? nlist
- 2 : 0);
1244 DialogInput("Card identifier",
1245 "Enter an identifier for your card definition:",
1247 " Next >>", " Cancel ", 0);
1248 if (identifier
== NULL
) {
1249 XtFree((XtPointer
)device
);
1256 if (Dialog("Card configuration",
1257 "Now we must configure video card specific settings. At this "
1258 "point you can choose to make a selection out of a database of "
1259 "video card definitions.\n"
1261 "The database entries include information about the chipset, "
1262 "what driver to run, the Ramdac and ClockChip, and comments "
1263 "that will be included in the Device section. However, a lot "
1264 "of definitions only hint about what driver to run (based on "
1265 "the chipset the card uses) and are untested.\n"
1267 "Do you want to look at the card database?",
1268 18, 60, " Yes ", " No ", device
->dev_identifier
!= NULL
) == 0) {
1269 static char **cards
;
1272 if (cards
== NULL
) {
1273 ReadCardsDatabase();
1274 cards
= GetCardNames(&ncards
);
1275 cards
= (char**)XtRealloc((XtPointer
)cards
,
1276 (ncards
+ 1) * sizeof(char*));
1277 for (i
= ncards
; i
> 0; i
--)
1278 cards
[i
] = cards
[i
- 1];
1279 cards
[0] = "** Unlisted card **";
1282 if (device
->dev_card
)
1283 entry
= LookupCard(device
->dev_card
);
1286 for (i
= 0; i
< NumCardsEntry
; i
++)
1287 if (strcasecmp(CardsDB
[i
]->name
, entry
->name
) == 0) {
1291 /* make sure entry is set to null again */
1295 i
= DialogMenu("Card database",
1296 "Select name that better matches your card:",
1297 20, 70, 11, ncards
, cards
, "Next >>", " Cancel ", def
);
1299 entry
= LookupCard(cards
[i
]);
1303 tmp
= device
->dev_driver
? device
->dev_driver
: entry
&& entry
->driver
?
1304 entry
->driver
: "vga";
1305 for (i
= 0; i
< ndrivers
; i
++)
1306 if (strcmp(drivers
[i
], tmp
) == 0) {
1313 i
= DialogMenu("Card driver",
1314 "You can select the driver for your card here, or just press "
1315 "Enter to use the default/current:", 20, 50, 9,
1316 ndrivers
, drivers
, " Ok ", " Cancel ", def
);
1318 if (device
->dev_identifier
== NULL
) {
1320 XtFree((XtPointer
)device
);
1324 driver
= ndrivers
? drivers
[i
] : "vga";
1328 tmp
= device
->dev_busid
? device
->dev_busid
: "";
1329 busid
= DialogInput("Card BusID",
1330 "You normally does not need to fill this field "
1331 "if you have only one video card:", 11, 50, tmp
,
1332 " Finish ", " Cancel ", 0);
1334 /* Finish card configuration */
1336 XtFree(device
->dev_card
);
1337 device
->dev_card
= XtNewString(entry
->name
);
1338 if (entry
->chipset
) {
1339 XtFree(device
->dev_chipset
);
1340 device
->dev_chipset
= XtNewString(entry
->chipset
);
1342 if (entry
->ramdac
) {
1343 XtFree(device
->dev_ramdac
);
1344 device
->dev_ramdac
= XtNewString(entry
->ramdac
);
1346 if (entry
->clockchip
) {
1347 XtFree(entry
->clockchip
);
1348 device
->dev_clockchip
= XtNewString(entry
->clockchip
);
1352 XtFree(device
->dev_busid
);
1354 device
->dev_busid
= busid
;
1356 device
->dev_busid
= NULL
;
1360 XtFree(device
->dev_driver
);
1361 device
->dev_driver
= XtNewString(driver
);
1362 if (device
->dev_identifier
== NULL
) {
1363 device
->dev_identifier
= identifier
;
1364 XF86Config
->conf_device_lst
=
1365 xf86addDevice(XF86Config
->conf_device_lst
, device
);
1371 static char *depths
[] = {
1372 "1 bit, monochrome",
1374 "8 bit, 256 colors",
1375 "15 bits, 32Kb colors",
1376 "16 bits, 65Kb colors",
1377 "24 bits, 16Mb colors",
1380 static char *modes
[] = {
1402 int i
, disp_allocated
;
1403 XF86ConfScreenPtr
*screens
= NULL
, screen
= XF86Config
->conf_screen_lst
;
1404 char **list
= NULL
, *identifier
= NULL
;
1406 XF86ConfDevicePtr device
= NULL
;
1407 XF86ConfMonitorPtr monitor
= NULL
;
1408 XF86ConfDisplayPtr display
;
1409 XF86ModePtr mode
, ptr
= NULL
;
1414 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
1415 list
[nlist
] = XtMalloc(sizeof(Edit
) +
1416 strlen(screen
->scrn_identifier
) + 1);
1417 sprintf(list
[nlist
], "%s%s", Edit
, screen
->scrn_identifier
);
1418 screens
= (XF86ConfScreenPtr
*)XtRealloc((XtPointer
)screens
, (nlist
+ 1) *
1419 sizeof(XF86ConfScreenPtr
));
1420 screens
[nlist
] = screen
;
1422 screen
= (XF86ConfScreenPtr
)(screen
->list
.next
);
1428 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 2) * sizeof(char*));
1429 list
[nlist
++] = XtNewString("Add new screen");
1431 i
= strlen("Remove ") + strlen(screens
[0]->scrn_identifier
) + 1;
1432 list
[nlist
] = XtMalloc(i
);
1433 XmuSnprintf(list
[nlist
], i
, "Remove %s", screens
[0]->scrn_identifier
);
1437 list
[nlist
++] = XtNewString("Remove screen");
1440 i
= DialogMenu("Screen configuration",
1441 "You can edit or remove a previously configured "
1442 "screen, or add a new one.", 14, 60, 4, nlist
, list
,
1443 " Ok ", " Cancel ", 0);
1445 for (i
= 0; i
< nlist
; i
++)
1447 XtFree((XtPointer
)list
);
1448 XtFree((XtPointer
)screens
);
1451 if (nlist
> 2 && i
== nlist
- 1) {
1453 for (i
= 0; i
< nlist
- 2; i
++) {
1454 /* XXX Remove the "Edit " from list entries */
1455 memmove(list
[i
], list
[i
] + sizeof(Edit
) - 1,
1456 strlen(list
[i
]) - sizeof(Edit
) + 2);
1460 i
= DialogMenu("Remove screen",
1461 "Select which screen to remove",
1462 13, 60, 4, nlist
- 2, list
,
1463 " Remove ", " Cancel ", 0);
1465 for (i
= 0; i
< nlist
; i
++)
1467 XtFree((XtPointer
)list
);
1468 XtFree((XtPointer
)screens
);
1471 screen
= screens
[i
];
1474 screen
= screens
[0];
1475 for (i
= 0; i
< nlist
; i
++)
1477 XtFree((XtPointer
)list
);
1478 XtFree((XtPointer
)screens
);
1479 xf86removeScreen(XF86Config
, screen
);
1483 screen
= screens
[i
];
1485 for (i
= 0; i
< nlist
; i
++)
1487 XtFree((XtPointer
)list
);
1488 XtFree((XtPointer
)screens
);
1490 if (screen
== NULL
) {
1492 XF86ConfDevicePtr
*devices
= NULL
;
1493 XF86ConfMonitorPtr
*monitors
= NULL
;
1495 device
= XF86Config
->conf_device_lst
;
1496 monitor
= XF86Config
->conf_monitor_lst
;
1498 if (device
== NULL
|| monitor
== NULL
) {
1501 Dialog("Configuration error",
1502 "You need to configure (at least) one card and one "
1503 "monitor before creating a screen definition.",
1504 9, 50, " Ok ", NULL
, 0);
1509 XmuSnprintf(label
, sizeof(label
), "Screen%d", nlist
? nlist
- 2 : 0);
1513 DialogInput("Screen identifier",
1514 "Enter an identifier for your screen definition:",
1516 " Next >>", " Cancel ", 0);
1517 if (identifier
== NULL
)
1523 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
1524 list
[nlist
] = XtNewString(device
->dev_identifier
);
1525 devices
= (XF86ConfDevicePtr
*)XtRealloc((XtPointer
)devices
, (nlist
+ 1) *
1526 sizeof(XF86ConfDevicePtr
));
1527 devices
[nlist
] = device
;
1529 device
= (XF86ConfDevicePtr
)(device
->list
.next
);
1533 i
= DialogMenu("Screen card", "Please select a video card:",
1534 13, 60, 4, nlist
, list
, " Next >>", " Cancel ", 0);
1535 for (def
= 0; def
< nlist
; def
++)
1537 XtFree((XtPointer
)list
);
1540 XtFree((XtPointer
)devices
);
1543 device
= devices
[i
];
1544 XtFree((XtPointer
)devices
);
1549 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
1550 list
[nlist
] = XtNewString(monitor
->mon_identifier
);
1551 monitors
= (XF86ConfMonitorPtr
*)XtRealloc((XtPointer
)monitors
, (nlist
+ 1) *
1552 sizeof(XF86ConfMonitorPtr
));
1553 monitors
[nlist
] = monitor
;
1555 monitor
= (XF86ConfMonitorPtr
)(monitor
->list
.next
);
1557 XmuSnprintf(label
, sizeof(label
),
1558 "Select the monitor connected to \"%s\":",
1559 device
->dev_identifier
);
1562 i
= DialogMenu("Screen monitor", label
,
1563 13, 60, 4, nlist
, list
, " Next >>", " Cancel ", 0);
1564 for (def
= 0; def
< nlist
; def
++)
1566 XtFree((XtPointer
)list
);
1569 XtFree((XtPointer
)monitors
);
1572 monitor
= monitors
[i
];
1573 XtFree((XtPointer
)monitors
);
1575 screen
= (XF86ConfScreenPtr
)XtCalloc(1, sizeof(XF86ConfScreenRec
));
1576 screen
->scrn_device
= device
;
1577 screen
->scrn_monitor
= monitor
;
1580 if (screen
->scrn_defaultdepth
== 1)
1582 else if (screen
->scrn_defaultdepth
== 4)
1584 else if (screen
->scrn_defaultdepth
== 8)
1586 else if (screen
->scrn_defaultdepth
== 15)
1588 else if (screen
->scrn_defaultdepth
== 16)
1590 else if (screen
->scrn_defaultdepth
== 24)
1593 if (screen
->scrn_device
&& screen
->scrn_device
->dev_driver
&&
1594 strcmp(screen
->scrn_device
->dev_driver
, "vga") == 0)
1601 i
= DialogMenu("Screen depth",
1602 "Please specify which color depth you want to use by default:",
1603 15, 60, 6, sizeof(depths
) / sizeof(depths
[0]), depths
,
1604 " Next >>", " Cancel ", def
);
1606 if (screen
->scrn_identifier
== NULL
) {
1608 XtFree((XtPointer
)screen
);
1613 /* XXX depths must begin with the depth number */
1614 screen
->scrn_defaultdepth
= atoi(depths
[i
]);
1616 def
= 0; /* use def to count how many modes are selected*/
1619 checks
= XtMalloc(sizeof(modes
) / sizeof(modes
[0]));
1620 /* XXX list fields in the code below are not allocated */
1622 display
= screen
->scrn_display_lst
;
1623 while (display
&& display
->disp_depth
!= screen
->scrn_defaultdepth
)
1624 display
= (XF86ConfDisplayPtr
)(display
->list
.next
);
1625 if (display
== NULL
) {
1626 display
= (XF86ConfDisplayPtr
)XtCalloc(1, sizeof(XF86ConfDisplayRec
));
1627 display
->disp_white
.red
= display
->disp_black
.red
= -1;
1628 display
->disp_depth
= screen
->scrn_defaultdepth
;
1632 mode
= display
->disp_mode_lst
;
1634 for (i
= 0; i
< sizeof(modes
) / sizeof(modes
[0]); i
++)
1635 if (strcmp(modes
[i
], mode
->mode_name
) == 0) {
1639 if (i
== sizeof(modes
) / sizeof(modes
[0])) {
1640 list
= (char**)XtRealloc((XtPointer
)list
,
1641 (nlist
+ 1) * sizeof(char*));
1642 list
[nlist
] = mode
->mode_name
;
1643 checks
= XtRealloc(checks
, sizeof(modes
) / sizeof(modes
[0]) +
1650 mode
= (XF86ModePtr
)(mode
->list
.next
);
1654 for (i
= 0; i
< sizeof(modes
) / sizeof(modes
[0]); i
++)
1655 checks
[i
+ nlist
] = 0;
1657 mode
= display
->disp_mode_lst
;
1659 for (i
= 0; i
< sizeof(modes
) / sizeof(modes
[0]); i
++)
1660 if (strcmp(modes
[i
], mode
->mode_name
) == 0) {
1662 checks
[i
+ nlist
] = 1;
1665 mode
= (XF86ModePtr
)(mode
->list
.next
);
1668 if (nlist
== 0 && def
== 0)
1669 checks
[7] = 1; /* 640x480 */
1670 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ sizeof(modes
) /
1671 sizeof(modes
[0])) * sizeof(char*));
1672 for (i
= 0; i
< sizeof(modes
) / sizeof(modes
[0]); i
++)
1673 list
[i
+ nlist
] = modes
[i
];
1674 nlist
+= sizeof(modes
) / sizeof(modes
[0]);
1678 i
= DialogCheckBox("Screen modes",
1679 "Select the video modes for this screen:",
1680 17, 60, 8, sizeof(modes
) / sizeof(modes
[0]), modes
,
1681 " Finish ", " Cancel ", checks
);
1683 if (screen
->scrn_identifier
== NULL
) {
1685 XtFree((XtPointer
)screen
);
1686 XtFree((XtPointer
)list
);
1688 XtFree((XtPointer
)display
);
1693 mode
= display
->disp_mode_lst
;
1695 ptr
= (XF86ModePtr
)(mode
->list
.next
);
1696 XtFree(mode
->mode_name
);
1697 XtFree((XtPointer
)mode
);
1700 display
->disp_mode_lst
= NULL
;
1702 for (i
= 0; i
< nlist
; i
++) {
1704 mode
= (XF86ModePtr
)XtCalloc(1, sizeof(XF86ModeRec
));
1705 mode
->mode_name
= XtNewString(list
[i
]);
1706 if (display
->disp_mode_lst
== NULL
)
1707 display
->disp_mode_lst
= ptr
= mode
;
1709 ptr
->list
.next
= mode
;
1714 XtFree((XtPointer
)list
);
1716 if (disp_allocated
) {
1717 display
->list
.next
= NULL
;
1718 if (screen
->scrn_display_lst
== NULL
)
1719 screen
->scrn_display_lst
= display
;
1721 screen
->scrn_display_lst
->list
.next
= display
;
1724 if (screen
->scrn_identifier
== NULL
) {
1725 screen
->scrn_identifier
= identifier
;
1726 screen
->scrn_monitor_str
= XtNewString(monitor
->mon_identifier
);
1727 screen
->scrn_device_str
= XtNewString(device
->dev_identifier
);
1728 XF86Config
->conf_screen_lst
=
1729 xf86addScreen(XF86Config
->conf_screen_lst
, screen
);
1735 static XF86ConfAdjacencyPtr
1736 CopyAdjacency(XF86ConfAdjacencyPtr ptr
)
1738 XF86ConfAdjacencyPtr adj
= (XF86ConfAdjacencyPtr
)
1739 XtCalloc(1, sizeof(XF86ConfAdjacencyRec
));
1741 adj
->adj_scrnum
= ptr
->adj_scrnum
;
1742 adj
->adj_screen
= ptr
->adj_screen
;
1743 adj
->adj_screen_str
= XtNewString(ptr
->adj_screen_str
);
1744 adj
->adj_top
= ptr
->adj_top
;
1745 if (ptr
->adj_top_str
)
1746 adj
->adj_top_str
= XtNewString(ptr
->adj_top_str
);
1747 adj
->adj_bottom
= ptr
->adj_bottom
;
1748 if (ptr
->adj_bottom_str
)
1749 adj
->adj_bottom_str
= XtNewString(ptr
->adj_bottom_str
);
1750 adj
->adj_left
= ptr
->adj_left
;
1751 if (ptr
->adj_left_str
)
1752 adj
->adj_left_str
= XtNewString(ptr
->adj_left_str
);
1753 adj
->adj_right
= ptr
->adj_right
;
1754 if (ptr
->adj_right_str
)
1755 adj
->adj_right_str
= XtNewString(ptr
->adj_right_str
);
1756 adj
->adj_where
= ptr
->adj_where
;
1757 adj
->adj_x
= ptr
->adj_x
;
1758 adj
->adj_y
= ptr
->adj_y
;
1759 if (ptr
->adj_refscreen
)
1760 adj
->adj_refscreen
= XtNewString(ptr
->adj_refscreen
);
1765 static XF86ConfInactivePtr
1766 CopyInactive(XF86ConfInactivePtr ptr
)
1768 XF86ConfInactivePtr inac
= (XF86ConfInactivePtr
)
1769 XtCalloc(1, sizeof(XF86ConfInactiveRec
));
1771 inac
->inactive_device
= ptr
->inactive_device
;
1772 if (ptr
->inactive_device_str
)
1773 inac
->inactive_device_str
= XtNewString(ptr
->inactive_device_str
);
1778 static XF86ConfInputrefPtr
1779 CopyInputref(XF86ConfInputrefPtr ptr
)
1781 XF86ConfInputrefPtr iref
= (XF86ConfInputrefPtr
)
1782 XtCalloc(1, sizeof(XF86ConfInputrefRec
));
1783 XF86OptionPtr opt
= ptr
->iref_option_lst
;
1785 iref
->iref_inputdev
= ptr
->iref_inputdev
;
1786 if (ptr
->iref_inputdev_str
)
1787 iref
->iref_inputdev_str
= XtNewString(ptr
->iref_inputdev_str
);
1789 iref
->iref_option_lst
= xf86addNewOption(iref
->iref_option_lst
,
1790 XtNewString(opt
->opt_name
),
1791 opt
->opt_val
? XtNewString(opt
->opt_val
) : NULL
);
1792 opt
= (XF86OptionPtr
)(opt
->list
.next
);
1798 static XF86ConfLayoutPtr
1799 CopyLayout(XF86ConfLayoutPtr ptr
)
1801 XF86ConfLayoutPtr lay
= (XF86ConfLayoutPtr
)
1802 XtCalloc(1, sizeof(XF86ConfLayoutRec
));
1803 XF86ConfAdjacencyPtr adj
= ptr
->lay_adjacency_lst
, padj
;
1804 XF86ConfInactivePtr inac
= ptr
->lay_inactive_lst
, pinac
;
1805 XF86ConfInputrefPtr iref
= ptr
->lay_input_lst
, piref
;
1806 XF86OptionPtr opt
= ptr
->lay_option_lst
;
1808 if (ptr
->lay_identifier
)
1809 lay
->lay_identifier
= XtNewString(ptr
->lay_identifier
);
1811 padj
= lay
->lay_adjacency_lst
= CopyAdjacency(adj
);
1812 adj
= (XF86ConfAdjacencyPtr
)(adj
->list
.next
);
1814 padj
->list
.next
= CopyAdjacency(adj
);
1815 padj
= (XF86ConfAdjacencyPtr
)(padj
->list
.next
);
1816 adj
= (XF86ConfAdjacencyPtr
)(adj
->list
.next
);
1820 pinac
= lay
->lay_inactive_lst
= CopyInactive(inac
);
1821 inac
= (XF86ConfInactivePtr
)(inac
->list
.next
);
1823 pinac
->list
.next
= CopyInactive(inac
);
1824 pinac
= (XF86ConfInactivePtr
)(pinac
->list
.next
);
1825 inac
= (XF86ConfInactivePtr
)(inac
->list
.next
);
1829 piref
= lay
->lay_input_lst
= CopyInputref(iref
);
1830 iref
= (XF86ConfInputrefPtr
)(iref
->list
.next
);
1832 piref
->list
.next
= CopyInputref(iref
);
1833 piref
= (XF86ConfInputrefPtr
)(piref
->list
.next
);
1834 iref
= (XF86ConfInputrefPtr
)(iref
->list
.next
);
1839 lay
->lay_option_lst
= xf86addNewOption(lay
->lay_option_lst
,
1840 XtNewString(opt
->opt_name
),
1841 opt
->opt_val
? XtNewString(opt
->opt_val
) : NULL
);
1842 opt
= (XF86OptionPtr
)(opt
->list
.next
);
1849 FreeLayout(XF86ConfLayoutPtr lay
)
1851 static XF86ConfigRec xf86config
;
1853 xf86config
.conf_layout_lst
= lay
;
1854 xf86removeLayout(&xf86config
, lay
);
1861 XF86ConfLayoutPtr
*layouts
= NULL
, rlayout
= NULL
,
1862 layout
= XF86Config
->conf_layout_lst
;
1863 XF86ConfInputPtr input
= XF86Config
->conf_input_lst
;
1864 char **list
= NULL
, *identifier
= NULL
;
1865 XF86ConfInputPtr
*mouses
= NULL
, *keyboards
= NULL
, mouse
, keyboard
;
1866 XF86ConfInputrefPtr iref
, piref
, mref
, kref
;
1867 XF86ConfAdjacencyPtr adj
, padj
;
1868 int nmouses
, nkeyboards
;
1870 XF86OptionPtr option
;
1871 XF86ConfScreenPtr screen
, *screens
;
1873 nmouses
= nkeyboards
= 0;
1875 if (strcmp(input
->inp_driver
, "mouse") == 0) {
1876 mouses
= (XF86ConfInputPtr
*)XtRealloc((XtPointer
)mouses
,
1877 (nmouses
+ 1) * sizeof(XF86ConfInputPtr
));
1878 mouses
[nmouses
] = input
;
1881 else if (IS_KBDDRIV(input
->inp_driver
)) {
1882 keyboards
= (XF86ConfInputPtr
*)XtRealloc((XtPointer
)keyboards
,
1883 (nkeyboards
+ 1) * sizeof(XF86ConfInputPtr
));
1884 keyboards
[nkeyboards
] = input
;
1887 input
= (XF86ConfInputPtr
)(input
->list
.next
);
1889 if (XF86Config
->conf_screen_lst
== NULL
||
1890 nmouses
== 0 || nkeyboards
== 0) {
1891 XtFree((XtPointer
)mouses
);
1892 XtFree((XtPointer
)keyboards
);
1895 Dialog("Configuration error",
1896 "You need to configure (at least) one screen, mouse "
1897 "and keyboard before creating a layout definition.",
1898 9, 50, " Ok ", NULL
, 0);
1904 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
1905 list
[nlist
] = XtMalloc(sizeof(Edit
) +
1906 strlen(layout
->lay_identifier
) + 1);
1907 sprintf(list
[nlist
], "%s%s", Edit
, layout
->lay_identifier
);
1908 layouts
= (XF86ConfLayoutPtr
*)XtRealloc((XtPointer
)layouts
, (nlist
+ 1) *
1909 sizeof(XF86ConfLayoutPtr
));
1910 layouts
[nlist
] = layout
;
1912 layout
= (XF86ConfLayoutPtr
)(layout
->list
.next
);
1918 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 2) * sizeof(char*));
1919 list
[nlist
++] = XtNewString("Add new layout");
1921 i
= strlen("Remove ") + strlen(layouts
[0]->lay_identifier
) + 1;
1922 list
[nlist
] = XtMalloc(i
);
1923 XmuSnprintf(list
[nlist
], i
, "Remove %s", layouts
[0]->lay_identifier
);
1927 list
[nlist
++] = XtNewString("Remove layout");
1930 i
= DialogMenu("Layout configuration",
1931 "You can edit or remove a previously configured "
1932 "layout, or add a new one.", 14, 60, 4, nlist
, list
,
1933 " Ok ", " Cancel ", 0);
1935 for (i
= 0; i
< nlist
; i
++)
1937 XtFree((XtPointer
)list
);
1938 XtFree((XtPointer
)layouts
);
1939 XtFree((XtPointer
)mouses
);
1940 XtFree((XtPointer
)keyboards
);
1943 if (nlist
> 2 && i
== nlist
- 1) {
1945 for (i
= 0; i
< nlist
- 2; i
++) {
1946 /* XXX Remove the "Edit " from list entries */
1947 memmove(list
[i
], list
[i
] + sizeof(Edit
) - 1,
1948 strlen(list
[i
]) - sizeof(Edit
) + 2);
1952 i
= DialogMenu("Remove layout",
1953 "Select which layout to remove",
1954 13, 60, 4, nlist
- 2, list
,
1955 " Remove ", " Cancel ", 0);
1957 for (i
= 0; i
< nlist
; i
++)
1959 XtFree((XtPointer
)list
);
1960 XtFree((XtPointer
)layouts
);
1961 XtFree((XtPointer
)mouses
);
1962 XtFree((XtPointer
)keyboards
);
1965 layout
= layouts
[i
];
1968 layout
= layouts
[0];
1969 for (i
= 0; i
< nlist
; i
++)
1971 XtFree((XtPointer
)list
);
1972 XtFree((XtPointer
)layouts
);
1973 XtFree((XtPointer
)mouses
);
1974 XtFree((XtPointer
)keyboards
);
1975 xf86removeLayout(XF86Config
, layout
);
1979 layout
= layouts
[i
];
1981 for (i
= 0; i
< nlist
; i
++)
1983 XtFree((XtPointer
)list
);
1984 XtFree((XtPointer
)layouts
);
1986 if (layout
== NULL
) {
1989 layout
= (XF86ConfLayoutPtr
)XtCalloc(1, sizeof(XF86ConfLayoutRec
));
1990 XmuSnprintf(label
, sizeof(label
), "Layout%d", nlist
? nlist
- 2 : 0);
1994 DialogInput("Layout identifier",
1995 "Enter an identifier for your layout definition:",
1997 " Next >>", " Cancel ", 0);
1998 if (identifier
== NULL
) {
1999 XtFree((XtPointer
)layout
);
2000 XtFree((XtPointer
)mouses
);
2001 XtFree((XtPointer
)keyboards
);
2006 /* So that we can safely change it */
2008 layout
= CopyLayout(rlayout
);
2012 mouse
= keyboard
= NULL
;
2016 iref
= layout
->lay_input_lst
;
2018 if (strcmp(iref
->iref_inputdev
->inp_driver
, "mouse") == 0) {
2021 if (xf86findOption(iref
->iref_option_lst
, "CorePointer")) {
2022 mouse
= iref
->iref_inputdev
;
2027 iref
= (XF86ConfInputrefPtr
)(iref
->list
.next
);
2029 if (mouse
== NULL
) {
2032 mouse
= piref
->iref_inputdev
;
2033 piref
->iref_option_lst
=
2034 xf86addNewOption(piref
->iref_option_lst
,
2035 XtNewString("CorePointer"), NULL
);
2039 mref
= iref
= (XF86ConfInputrefPtr
)XtCalloc(1, sizeof(XF86ConfInputrefRec
));
2040 iref
->iref_inputdev_str
= XtNewString(mouse
->inp_identifier
);
2041 iref
->iref_inputdev
= mouse
;
2042 iref
->iref_option_lst
=
2043 xf86addNewOption(iref
->iref_option_lst
,
2044 XtNewString("CorePointer"), NULL
);
2045 iref
->list
.next
= layout
->lay_input_lst
;
2046 if (layout
->lay_input_lst
== NULL
)
2047 layout
->lay_input_lst
= iref
;
2049 iref
->list
.next
= layout
->lay_input_lst
;
2050 layout
->lay_input_lst
= iref
;
2057 /* XXX list fields are not allocated */
2060 list
= (char**)XtMalloc(sizeof(char*));
2061 list
[nlist
++] = mouse
->inp_identifier
;
2062 input
= XF86Config
->conf_input_lst
;
2064 if (input
!= mouse
&& strcmp(input
->inp_driver
, "mouse") == 0) {
2065 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
2066 list
[nlist
++] = input
->inp_identifier
;
2068 input
= (XF86ConfInputPtr
)(input
->list
.next
);
2072 i
= DialogMenu("Select Core Pointer",
2073 "Select the mouse connected to you computer",
2074 12, 60, 4, nlist
, list
, " Ok ", " Cancel ", 0);
2076 XtFree((XtPointer
)mouses
);
2077 XtFree((XtPointer
)keyboards
);
2078 XtFree((XtPointer
)list
);
2079 if (layout
->lay_identifier
== NULL
)
2085 /* Did not select the default one */
2086 iref
= layout
->lay_input_lst
;
2088 if (strcasecmp(iref
->iref_inputdev_str
, list
[i
]) == 0) {
2089 if ((option
= xf86findOption(iref
->iref_option_lst
,
2090 "SendCoreEvents")) != NULL
) {
2091 XtFree(option
->opt_name
);
2092 option
->opt_name
= XtNewString("CorePointer");
2095 iref
->iref_option_lst
=
2096 xf86addNewOption(iref
->iref_option_lst
,
2097 XtNewString("CorePointer"), NULL
);
2098 option
= xf86findOption(mref
->iref_option_lst
,
2100 XtFree(option
->opt_name
);
2101 option
->opt_name
= XtNewString("SendCoreEvents");
2104 iref
= (XF86ConfInputrefPtr
)(iref
->list
.next
);
2108 /* XXX Write code to add/remove more mouses here */
2114 iref
= layout
->lay_input_lst
;
2116 if (IS_KBDDRIV(iref
->iref_inputdev
->inp_driver
)) {
2117 if (keyboard
== NULL
)
2119 if (xf86findOption(iref
->iref_option_lst
, "CoreKeyboard")) {
2120 keyboard
= iref
->iref_inputdev
;
2125 iref
= (XF86ConfInputrefPtr
)(iref
->list
.next
);
2127 if (keyboard
== NULL
) {
2130 keyboard
= piref
->iref_inputdev
;
2131 piref
->iref_option_lst
=
2132 xf86addNewOption(piref
->iref_option_lst
,
2133 XtNewString("CoreKeyboard"), NULL
);
2136 keyboard
= keyboards
[0];
2137 kref
= iref
= (XF86ConfInputrefPtr
)XtCalloc(1, sizeof(XF86ConfInputrefRec
));
2138 iref
->iref_inputdev_str
= XtNewString(keyboard
->inp_identifier
);
2139 iref
->iref_inputdev
= keyboard
;
2140 iref
->iref_option_lst
=
2141 xf86addNewOption(iref
->iref_option_lst
,
2142 XtNewString("CoreKeyboard"), NULL
);
2143 iref
->list
.next
= layout
->lay_input_lst
;
2144 if (layout
->lay_input_lst
== NULL
)
2145 layout
->lay_input_lst
= iref
;
2147 iref
->list
.next
= layout
->lay_input_lst
;
2148 layout
->lay_input_lst
= iref
;
2155 /* XXX list fields are not allocated */
2156 if (nkeyboards
> 1) {
2158 list
= (char**)XtMalloc(sizeof(char*));
2159 list
[nlist
++] = keyboard
->inp_identifier
;
2160 input
= XF86Config
->conf_input_lst
;
2162 if (input
!= keyboard
&& IS_KBDDRIV(input
->inp_driver
)) {
2163 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
2164 list
[nlist
++] = input
->inp_identifier
;
2166 input
= (XF86ConfInputPtr
)(input
->list
.next
);
2170 i
= DialogMenu("Select Core Keyboard",
2171 "Select the keyboard connected to you computer",
2172 12, 60, 4, nlist
, list
, " Ok ", " Cancel ", 0);
2174 XtFree((XtPointer
)mouses
);
2175 XtFree((XtPointer
)keyboards
);
2176 XtFree((XtPointer
)list
);
2177 if (layout
->lay_identifier
== NULL
)
2183 /* Did not select the default one */
2184 iref
= layout
->lay_input_lst
;
2186 if (strcasecmp(iref
->iref_inputdev_str
, list
[i
]) == 0) {
2187 if ((option
= xf86findOption(iref
->iref_option_lst
,
2188 "SendCoreEvents")) != NULL
) {
2189 XtFree(option
->opt_name
);
2190 option
->opt_name
= XtNewString("CoreKeyboard");
2193 iref
->iref_option_lst
=
2194 xf86addNewOption(iref
->iref_option_lst
,
2195 XtNewString("CoreKeyboard"), NULL
);
2196 option
= xf86findOption(kref
->iref_option_lst
,
2198 XtFree(option
->opt_name
);
2199 option
->opt_name
= XtNewString("SendCoreEvents");
2202 iref
= (XF86ConfInputrefPtr
)(iref
->list
.next
);
2206 /* XXX Write code to add/remove more keyboards here */
2209 XtFree((XtPointer
)mouses
);
2210 XtFree((XtPointer
)keyboards
);
2212 /* Just one screen */
2213 if (XF86Config
->conf_screen_lst
->list
.next
== NULL
) {
2216 Dialog("Layout configuration",
2217 (nmouses
> 1 || nkeyboards
> 1) ?
2218 "As you have only one screen configured, I can now finish "
2219 "creating this Layout configuration."
2221 "As you have only one screen, mouse and keyboard configured, "
2222 "I can now finish creating this Layout configuration.",
2223 12, 60, " Finish ", NULL
, 0);
2229 /* The code below just adds a screen to the right of the last
2230 * one, or allows removing a screen.
2231 * Needs some review, and adding more options.
2236 static char *screen_opts
[] = {
2237 "Add a new screen to layout",
2238 "Remove screen from layout",
2239 "Finish layout configuration",
2244 i
= DialogMenu("Layout configuration", "Please choose one option:",
2245 12, 60, 3, sizeof(screen_opts
) / sizeof(screen_opts
[0]),
2246 screen_opts
, " Done ", " Cancel all changes ", 2);
2255 /* add new screen */
2260 screen
= XF86Config
->conf_screen_lst
;
2262 adj
= layout
->lay_adjacency_lst
;
2264 if (adj
->adj_screen
== screen
)
2266 adj
= (XF86ConfAdjacencyPtr
)(adj
->list
.next
);
2269 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
2270 screens
= (XF86ConfScreenPtr
*)XtRealloc((XtPointer
)screens
,
2271 (nlist
+ 1) * sizeof(XF86ConfScreenPtr
));
2272 /* NOT duplicated */
2273 list
[nlist
] = screen
->scrn_identifier
;
2274 screens
[nlist
] = screen
;
2277 screen
= (XF86ConfScreenPtr
)(screen
->list
.next
);
2285 i
= DialogMenu("Layout add screen", "Choose screen to add:",
2286 12, 60, 3, nlist
, list
,
2287 " Add ", " Cancel ", 0);
2289 padj
= layout
->lay_adjacency_lst
;
2290 adj
= (XF86ConfAdjacencyPtr
)
2291 XtCalloc(1, sizeof(XF86ConfAdjacencyRec
));
2292 adj
->adj_screen
= screens
[i
];
2294 adj
->adj_where
= CONF_ADJ_ABSOLUTE
;
2295 layout
->lay_adjacency_lst
= adj
;
2298 while (padj
->list
.next
)
2299 padj
= (XF86ConfAdjacencyPtr
)(padj
->list
.next
);
2300 padj
->list
.next
= adj
;
2301 adj
->adj_where
= CONF_ADJ_RIGHTOF
;
2302 adj
->adj_refscreen
=
2303 XtNewString(padj
->adj_screen
->scrn_identifier
);
2306 XtFree((XtPointer
)list
);
2307 XtFree((XtPointer
)screens
);
2310 /* remove a screen */
2315 adj
= layout
->lay_adjacency_lst
;
2318 list
= (char**)XtRealloc((XtPointer
)list
, (nlist
+ 1) * sizeof(char*));
2319 screens
= (XF86ConfScreenPtr
*)XtRealloc((XtPointer
)screens
,
2320 (nlist
+ 1) * sizeof(XF86ConfScreenPtr
));
2321 list
[nlist
] = adj
->adj_screen
->scrn_identifier
;
2322 screens
[nlist
] = adj
->adj_screen
;
2324 adj
= (XF86ConfAdjacencyPtr
)(adj
->list
.next
);
2332 i
= DialogMenu("Layout remove screen", "Choose screen to remove:",
2333 12, 60, 3, nlist
, list
,
2334 " Remove ", " Cancel ", 0);
2336 adj
= padj
= layout
->lay_adjacency_lst
;
2338 if (adj
->adj_screen
== screens
[i
]) {
2339 padj
= (XF86ConfAdjacencyPtr
)(padj
->list
.next
);
2340 if (padj
&& adj
->adj_where
== CONF_ADJ_RIGHTOF
&&
2341 padj
->adj_where
== CONF_ADJ_RIGHTOF
) {
2342 XtFree(padj
->adj_refscreen
);
2343 padj
->adj_refscreen
= XtNewString(adj
->adj_refscreen
);
2345 xf86removeAdjacency(layout
, adj
);
2349 adj
= (XF86ConfAdjacencyPtr
)(padj
->list
.next
);
2351 XtFree((XtPointer
)list
);
2352 XtFree((XtPointer
)screens
);
2355 /* finish screen configuration */
2361 if (layout
->lay_adjacency_lst
== NULL
) {
2362 adj
= (XF86ConfAdjacencyPtr
)XtCalloc(1, sizeof(XF86ConfAdjacencyRec
));
2363 adj
->adj_screen
= XF86Config
->conf_screen_lst
;
2364 adj
->adj_screen_str
= XtNewString(XF86Config
->conf_screen_lst
->scrn_identifier
);
2365 adj
->adj_where
= CONF_ADJ_ABSOLUTE
;
2366 layout
->lay_adjacency_lst
= adj
;
2369 /* just edited this layout */
2370 if (nmouses
> 1 || nkeyboards
> 1) {
2371 XF86ConfAdjacencyPtr tadj
= rlayout
->lay_adjacency_lst
;
2372 XF86ConfInactivePtr tinac
= rlayout
->lay_inactive_lst
;
2373 XF86ConfInputrefPtr tinp
= rlayout
->lay_input_lst
;
2375 rlayout
->lay_adjacency_lst
= layout
->lay_adjacency_lst
;
2376 rlayout
->lay_inactive_lst
= layout
->lay_inactive_lst
;
2377 rlayout
->lay_input_lst
= layout
->lay_input_lst
;
2379 layout
->lay_adjacency_lst
= tadj
;
2380 layout
->lay_inactive_lst
= tinac
;
2381 layout
->lay_input_lst
= tinp
;
2387 layout
->lay_identifier
= identifier
;
2388 XF86Config
->conf_layout_lst
=
2389 xf86addLayout(XF86Config
->conf_layout_lst
, layout
);
2400 wattrset(stdscr
, screen_attr
);
2401 for (i
= 0; i
< LINES
; i
++) {
2402 wmove(stdscr
, i
, 0);
2403 for (j
= 0; j
< COLS
; j
++)
2404 waddch(stdscr
, ACS_PLUS
);
2410 Dialog(char *title
, char * prompt
, int height
, int width
,
2411 char *label1
, char *label2
, int button
)
2413 int x
, x1
, x2
, y
, key
, l1len
, l2len
;
2416 x
= (COLS
- width
) / 2;
2417 y
= (LINES
- height
) / 2;
2419 dialog
= newwin(height
, width
, y
, x
);
2420 keypad(dialog
, TRUE
);
2422 PaintWindow(dialog
, title
, 0, 0, height
, width
);
2423 wattrset(dialog
, dialog_attr
);
2424 PrintWrap(dialog
, prompt
, width
- 3, 2, 3);
2426 l1len
= strlen(label1
);
2428 l2len
= strlen(label2
);
2433 x1
= (width
- (l1len
+ l2len
)) / (label2
? 3 : 2);
2434 x2
= x1
+ x1
+ l1len
;
2438 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
2439 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
2442 PaintButton(dialog
, label1
, y
, x1
, FALSE
);
2444 PaintButton(dialog
, label2
, y
, x2
, TRUE
);
2450 key
= wgetch(dialog
);
2457 PaintButton(dialog
, label1
, y
, x1
, FALSE
);
2458 PaintButton(dialog
, label2
, y
, x2
, TRUE
);
2465 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
2466 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
2482 PaintWindow(WINDOW
*win
, char *title_str
, int y
, int x
, int height
, int width
)
2486 if (title_str
!= NULL
) {
2487 j
= (width
- strlen(title_str
)) / 2 - 1;
2489 wattrset(win
, title_attr
);
2491 for (i
= 0; i
< j
; i
++)
2493 waddstr(win
, title_str
);
2494 for (; i
< width
; i
++)
2500 for (i
= 1; i
< height
; i
++) {
2501 wmove(win
, y
+ i
, x
);
2502 for (j
= 0; j
< width
; j
++)
2503 if (i
== height
- 1 && !j
)
2504 waddch(win
, highlight_border_attr
| ACS_LLCORNER
);
2505 else if (i
== height
- 1 && j
== width
- 1)
2506 waddch(win
, shadow_border_attr
| ACS_LRCORNER
);
2507 else if (i
== height
- 1)
2508 waddch(win
, shadow_border_attr
| ACS_HLINE
);
2510 waddch(win
, highlight_border_attr
| ACS_VLINE
);
2511 else if (j
== width
- 1)
2512 waddch(win
, shadow_border_attr
| ACS_VLINE
);
2514 waddch(win
, dialog_attr
| ' ');
2520 PaintBox(WINDOW
*win
, int y
, int x
, int height
, int width
)
2526 for (i
= 0; i
< height
; i
++) {
2527 wmove(win
, y
+ i
, x
);
2528 for (j
= 0; j
< width
; j
++)
2530 waddch(win
, shadow_border_attr
| ACS_ULCORNER
);
2531 else if (i
== height
- 1 && !j
)
2532 waddch(win
, shadow_border_attr
| ACS_LLCORNER
);
2533 else if (!i
&& j
== width
-1)
2534 waddch(win
, highlight_border_attr
| ACS_URCORNER
);
2535 else if (i
== height
- 1 && j
== width
- 1)
2536 waddch(win
, highlight_border_attr
| ACS_LRCORNER
);
2538 waddch(win
, shadow_border_attr
| ACS_HLINE
);
2539 else if (i
== height
- 1)
2540 waddch(win
, highlight_border_attr
| ACS_HLINE
);
2542 waddch(win
, shadow_border_attr
| ACS_VLINE
);
2543 else if (j
== width
- 1)
2544 waddch(win
, highlight_border_attr
| ACS_VLINE
);
2546 waddch(win
, dialog_attr
| ' ');
2552 PaintButton(WINDOW
*win
, char *label
, int y
, int x
, int selected
)
2557 wattrset(win
, selected
? button_active_attr
: button_inactive_attr
);
2558 waddstr(win
, selected
? "[" : " ");
2559 temp
= strspn(label
, " ");
2561 wattrset(win
, selected
? button_active_attr
: button_inactive_attr
);
2562 for (i
= 0; i
< temp
; i
++)
2564 wattrset(win
, selected
? button_active_attr
: button_inactive_attr
);
2565 waddch(win
, label
[0]);
2566 wattrset(win
, selected
? button_active_attr
: button_inactive_attr
);
2567 waddstr(win
, label
+ 1);
2568 wattrset(win
, selected
? button_active_attr
: button_inactive_attr
);
2569 waddstr(win
, selected
? "]" : " ");
2570 wmove(win
, y
, x
+ temp
+ 1);
2574 PrintWrap(WINDOW
*win
, char *prompt
, int width
, int y
, int x
)
2576 int cur_x
, cur_y
, len
, yinc
;
2577 char *word
, *tempstr
= XtMalloc(strlen(prompt
) + 1);
2582 while (*prompt
== '\n') {
2587 strcpy(tempstr
, prompt
);
2589 for (word
= strtok(tempstr
, " \n"); word
!= NULL
; word
= strtok(NULL
, " \n")) {
2592 while (prompt
[word
- tempstr
+ len
+ yinc
] == '\n')
2594 if (cur_x
+ strlen(word
) > width
) {
2598 wmove(win
, cur_y
, cur_x
);
2600 getyx(win
, cur_y
, cur_x
);
2613 DialogMenu(char *title
, char *prompt
, int height
, int width
, int menu_height
,
2614 int item_no
, char **items
, char *label1
, char *label2
, int choice
)
2616 int i
, x
, y
, cur_x
, cur_y
, box_x
, box_y
, key
= 0, button
= 0,
2617 scrlx
= 0, max_choice
, nscroll
, max_scroll
, x1
, x2
, l1len
, l2len
;
2618 WINDOW
*dialog
, *menu
;
2620 max_choice
= MIN(menu_height
, item_no
);
2621 max_scroll
= MAX(0, item_no
- max_choice
);
2623 x
= (COLS
- width
) / 2;
2624 y
= (LINES
- height
) / 2;
2626 dialog
= newwin(height
, width
, y
, x
);
2627 keypad(dialog
, TRUE
);
2629 PaintWindow(dialog
, title
, 0, 0, height
, width
);
2631 wattrset(dialog
, dialog_attr
);
2632 PrintWrap(dialog
, prompt
, width
- 3, 2, 3);
2634 l1len
= strlen(label1
);
2635 l2len
= strlen(label2
);
2637 x1
= (width
- (l1len
+ l2len
)) / 3;
2638 x2
= x1
+ x1
+ l1len
;
2640 menu_width
= width
- 6;
2641 getyx(dialog
, cur_y
, cur_x
);
2643 box_x
= (width
- menu_width
) / 2 - 1;
2645 menu
= subwin(dialog
, menu_height
, menu_width
, y
+ box_y
+ 1, x
+ box_x
+ 1);
2648 /* draw a box around the menu items */
2649 PaintBox(dialog
, box_y
, box_x
, menu_height
+ 2, menu_width
+ 2);
2653 if (choice
> menu_height
) {
2654 scrlx
= MIN(max_scroll
, choice
);
2658 for (i
= 0; i
< max_choice
; i
++)
2659 PaintItem(menu
, items
[i
+ scrlx
], i
, i
== choice
);
2660 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2665 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
2666 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
2672 key
= wgetch(dialog
);
2674 if (menu_height
> 1 && key
== KEY_PPAGE
) {
2677 /* Scroll menu down */
2678 getyx(dialog
, cur_y
, cur_x
);
2680 nscroll
= max_choice
> scrlx
? -scrlx
: -max_choice
;
2681 scrollok(menu
, TRUE
);
2682 wscrl(menu
, nscroll
);
2683 scrollok(menu
, FALSE
);
2685 PaintItem(menu
, items
[i
= scrlx
+ nscroll
], 0, TRUE
);
2686 for (++i
; i
<= scrlx
; i
++)
2687 PaintItem(menu
, items
[i
], i
- (scrlx
+ nscroll
), FALSE
);
2689 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2697 else if (menu_height
> 1 && key
== KEY_NPAGE
) {
2698 if (choice
== max_choice
- 1) {
2699 if (scrlx
< max_scroll
) {
2700 /* Scroll menu up */
2701 getyx(dialog
, cur_y
, cur_x
);
2703 nscroll
= (scrlx
+ max_choice
> max_scroll
?
2704 max_scroll
: scrlx
+ max_choice
) - scrlx
;
2705 scrollok(menu
, TRUE
);
2706 wscrl(menu
, nscroll
);
2707 scrollok(menu
, FALSE
);
2710 for (i
= 0; i
< max_choice
- 1; i
++)
2711 PaintItem(menu
, items
[i
+ scrlx
], i
, FALSE
);
2712 PaintItem(menu
, items
[i
+ scrlx
], max_choice
- 1, TRUE
);
2713 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2721 else if (key
== KEY_UP
) {
2724 /* Scroll menu down */
2725 getyx(dialog
, cur_y
, cur_x
);
2726 if (menu_height
> 1) {
2727 PaintItem(menu
, items
[scrlx
], 0, FALSE
);
2728 scrollok(menu
, TRUE
);
2730 scrollok(menu
, FALSE
);
2733 PaintItem(menu
, items
[scrlx
], 0, TRUE
);
2734 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2743 else if (key
== KEY_DOWN
) {
2744 if (choice
== max_choice
- 1) {
2745 if (scrlx
+ choice
< item_no
- 1) {
2746 /* Scroll menu up */
2747 getyx(dialog
, cur_y
, cur_x
);
2748 if (menu_height
> 1) {
2749 PaintItem(menu
, items
[scrlx
+ max_choice
- 1], max_choice
- 1, FALSE
);
2750 scrollok(menu
, TRUE
);
2752 scrollok(menu
, FALSE
);
2755 PaintItem(menu
, items
[scrlx
+ max_choice
- 1], max_choice
- 1, TRUE
);
2756 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2763 i
= MIN(choice
+ 1, item_no
- 1);
2767 getyx(dialog
, cur_y
, cur_x
);
2768 PaintItem(menu
, items
[scrlx
+ choice
], choice
, FALSE
);
2771 PaintItem(menu
, items
[scrlx
+ choice
], choice
, TRUE
);
2772 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2774 wmove(dialog
, cur_y
, cur_x
);
2785 PaintButton(dialog
, label1
, y
, x1
, FALSE
);
2786 PaintButton(dialog
, label2
, y
, x2
, TRUE
);
2790 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
2791 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
2799 return (!button
? scrlx
+ choice
: -1);
2801 for (i
= scrlx
+ choice
+ 1; i
< item_no
; i
++)
2802 if (toupper(items
[i
][0]) == toupper(key
))
2805 for (i
= 0; i
< scrlx
+ choice
; i
++)
2806 if (toupper(items
[i
][0]) == toupper(key
))
2809 getyx(dialog
, cur_y
, cur_x
);
2810 if (i
< item_no
&& i
!= scrlx
+ choice
) {
2811 if (i
>= scrlx
&& i
< scrlx
+ max_choice
) {
2812 /* it is already visible */
2813 PaintItem(menu
, items
[scrlx
+ choice
], choice
, FALSE
);
2817 scrlx
= MIN(i
, max_scroll
);
2819 for (i
= 0; i
< max_choice
; i
++)
2821 PaintItem(menu
, items
[scrlx
+ i
], i
, FALSE
);
2823 PaintItem(menu
, items
[scrlx
+ choice
], choice
, TRUE
);
2824 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2826 wmove(dialog
, cur_y
, cur_x
);
2836 PaintItem(WINDOW
*win
, char *item
, int choice
, int selected
)
2840 wattrset(win
, selected
? title_attr
: dialog_attr
);
2841 wmove(win
, choice
, 1);
2842 for (i
= 1; i
< menu_width
; i
++)
2844 wmove(win
, choice
, item_x
);
2845 wattrset(win
, selected
? title_attr
: dialog_attr
);
2850 PaintScroller(WINDOW
*win
, int offset
, int lenght
, int visible
)
2854 if (lenght
> visible
)
2855 pos
= (visible
/ (double)lenght
) * offset
;
2858 wattrset(win
, shadow_border_attr
);
2859 for (i
= 0; i
< visible
; i
++) {
2861 waddch(win
, i
== pos
? ACS_BLOCK
: ACS_VLINE
);
2866 DialogCheckBox(char *title
, char *prompt
, int height
, int width
, int menu_height
,
2867 int item_no
, char **items
, char *label1
, char *label2
, char *checks
)
2869 int i
, x
, y
, cur_x
, cur_y
, box_x
, box_y
, key
= 0, button
= 0, choice
= 0,
2870 scrlx
= 0, max_choice
, nscroll
, max_scroll
, x1
, x2
, l1len
, l2len
;
2871 WINDOW
*dialog
, *menu
;
2873 max_choice
= MIN(menu_height
, item_no
);
2874 max_scroll
= MAX(0, item_no
- max_choice
);
2876 x
= (COLS
- width
) / 2;
2877 y
= (LINES
- height
) / 2;
2879 dialog
= newwin(height
, width
, y
, x
);
2880 keypad(dialog
, TRUE
);
2882 PaintWindow(dialog
, title
, 0, 0, height
, width
);
2884 wattrset(dialog
, dialog_attr
);
2885 PrintWrap(dialog
, prompt
, width
- 3, 2, 3);
2887 l1len
= strlen(label1
);
2888 l2len
= strlen(label2
);
2890 x1
= (width
- (l1len
+ l2len
)) / 3;
2891 x2
= x1
+ x1
+ l1len
;
2893 menu_width
= width
- 6;
2894 getyx(dialog
, cur_y
, cur_x
);
2896 box_x
= (width
- menu_width
) / 2 - 1;
2898 menu
= subwin(dialog
, menu_height
, menu_width
, y
+ box_y
+ 1, x
+ box_x
+ 1);
2901 /* draw a box around the menu items */
2902 PaintBox(dialog
, box_y
, box_x
, menu_height
+ 2, menu_width
+ 2);
2906 for (i
= 0; i
< max_choice
; i
++)
2907 PaintCheckItem(menu
, items
[i
+ scrlx
], i
, i
== 0, checks
[i
+ scrlx
]);
2908 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2913 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
2914 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
2920 key
= wgetch(dialog
);
2922 if (menu_height
> 1 && key
== KEY_PPAGE
) {
2925 /* Scroll menu down */
2926 getyx(dialog
, cur_y
, cur_x
);
2928 nscroll
= max_choice
> scrlx
? -scrlx
: -max_choice
;
2929 scrollok(menu
, TRUE
);
2930 wscrl(menu
, nscroll
);
2931 scrollok(menu
, FALSE
);
2933 i
= scrlx
+ nscroll
;
2934 PaintCheckItem(menu
, items
[i
], 0, TRUE
, checks
[i
]);
2935 for (++i
; i
<= scrlx
; i
++)
2936 PaintCheckItem(menu
, items
[i
], i
- (scrlx
+ nscroll
), FALSE
, checks
[i
]);
2938 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2946 else if (menu_height
> 1 && key
== KEY_NPAGE
) {
2947 if (choice
== max_choice
- 1) {
2948 if (scrlx
< max_scroll
) {
2949 /* Scroll menu up */
2950 getyx(dialog
, cur_y
, cur_x
);
2952 nscroll
= (scrlx
+ max_choice
> max_scroll
?
2953 max_scroll
: scrlx
+ max_choice
) - scrlx
;
2954 scrollok(menu
, TRUE
);
2955 wscrl(menu
, nscroll
);
2956 scrollok(menu
, FALSE
);
2959 for (i
= 0; i
< max_choice
- 1; i
++)
2960 PaintCheckItem(menu
, items
[i
+ scrlx
], i
, FALSE
, checks
[i
+ scrlx
]);
2961 PaintCheckItem(menu
, items
[i
+ scrlx
], max_choice
- 1, TRUE
, checks
[i
+ scrlx
]);
2962 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2970 else if (key
== KEY_UP
) {
2973 /* Scroll menu down */
2974 getyx(dialog
, cur_y
, cur_x
);
2975 if (menu_height
> 1) {
2976 PaintCheckItem(menu
, items
[scrlx
], 0, FALSE
, checks
[scrlx
]);
2977 scrollok(menu
, TRUE
);
2979 scrollok(menu
, FALSE
);
2982 PaintCheckItem(menu
, items
[scrlx
], 0, TRUE
, checks
[scrlx
]);
2983 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
2992 else if (key
== KEY_DOWN
) {
2993 if (choice
== max_choice
- 1) {
2994 if (scrlx
+ choice
< item_no
- 1) {
2995 /* Scroll menu up */
2996 getyx(dialog
, cur_y
, cur_x
);
2997 if (menu_height
> 1) {
2998 PaintCheckItem(menu
, items
[scrlx
+ max_choice
- 1], max_choice
- 1, FALSE
, checks
[scrlx
+ max_choice
- 1]);
2999 scrollok(menu
, TRUE
);
3001 scrollok(menu
, FALSE
);
3004 PaintCheckItem(menu
, items
[scrlx
+ max_choice
- 1], max_choice
- 1, TRUE
, checks
[scrlx
+ max_choice
- 1]);
3005 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
3012 i
= MIN(choice
+ 1, item_no
- 1);
3016 getyx(dialog
, cur_y
, cur_x
);
3017 PaintCheckItem(menu
, items
[scrlx
+ choice
], choice
, FALSE
, checks
[scrlx
+ choice
]);
3020 PaintCheckItem(menu
, items
[scrlx
+ choice
], choice
, TRUE
, checks
[scrlx
+ choice
]);
3021 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
3023 wmove(dialog
, cur_y
, cur_x
);
3034 PaintButton(dialog
, label1
, y
, x1
, FALSE
);
3035 PaintButton(dialog
, label2
, y
, x2
, TRUE
);
3039 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
3040 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
3045 getyx(dialog
, cur_y
, cur_x
);
3046 checks
[scrlx
+ choice
] = !checks
[scrlx
+ choice
];
3047 PaintCheckItem(menu
, items
[scrlx
+ choice
], choice
, TRUE
, checks
[scrlx
+ choice
]);
3048 wmove(dialog
, cur_y
, cur_x
);
3055 return (!button
? 0 : -1);
3057 for (i
= scrlx
+ choice
+ 1; i
< item_no
; i
++)
3058 if (toupper(items
[i
][0]) == toupper(key
))
3061 for (i
= 0; i
< scrlx
+ choice
; i
++)
3062 if (toupper(items
[i
][0]) == toupper(key
))
3065 getyx(dialog
, cur_y
, cur_x
);
3066 if (i
< item_no
&& i
!= scrlx
+ choice
) {
3067 if (i
>= scrlx
&& i
< scrlx
+ max_choice
) {
3068 /* it is already visible */
3069 PaintCheckItem(menu
, items
[scrlx
+ choice
], choice
, FALSE
, checks
[scrlx
+ choice
]);
3073 scrlx
= MIN(i
, max_scroll
);
3075 for (i
= 0; i
< max_choice
; i
++)
3077 PaintCheckItem(menu
, items
[scrlx
+ i
], i
, FALSE
, checks
[scrlx
+ i
]);
3079 PaintCheckItem(menu
, items
[scrlx
+ choice
], choice
, TRUE
, checks
[scrlx
+ choice
]);
3080 PaintScroller(menu
, scrlx
+ choice
, item_no
, menu_height
);
3082 wmove(dialog
, cur_y
, cur_x
);
3092 PaintCheckItem(WINDOW
*win
, char *item
, int choice
, int selected
, int checked
)
3096 wattrset(win
, selected
? title_attr
: dialog_attr
);
3097 wmove(win
, choice
, 1);
3098 for (i
= 1; i
< menu_width
; i
++)
3100 wmove(win
, choice
, item_x
);
3101 wattrset(win
, selected
? title_attr
: dialog_attr
);
3102 wprintw(win
, "[%c] ", checked
? 'X' : ' ');
3107 DialogInput(char *title
, char *prompt
, int height
, int width
, char *init
,
3108 char *label1
, char *label2
, int def_button
)
3110 int i
, x
, y
, box_y
, box_x
, box_width
, len
,
3111 input_x
= 0, scrlx
= 0, key
= 0, button
= -1, x1
, x2
, l1len
, l2len
;
3112 char instr
[1024 + 1];
3115 x
= (COLS
- width
) / 2;
3116 y
= (LINES
- height
) / 2;
3118 dialog
= newwin(height
, width
, y
, x
);
3119 keypad(dialog
, TRUE
);
3121 PaintWindow(dialog
, title
, 0, 0, height
, width
);
3123 wattrset(dialog
, dialog_attr
);
3124 PrintWrap(dialog
, prompt
, width
- 3, 2, 3);
3126 l1len
= strlen(label1
);
3127 l2len
= strlen(label2
);
3129 x1
= (width
- (l1len
+ l2len
)) / 3;
3130 x2
= x1
+ x1
+ l1len
;
3132 box_width
= width
- 6;
3133 getyx(dialog
, y
, x
);
3135 box_x
= (width
- box_width
) / 2;
3136 PaintBox(dialog
, y
+ 1, box_x
- 1, 3, box_width
+ 2);
3140 PaintButton(dialog
, label2
, y
, x2
, def_button
== 1);
3141 PaintButton(dialog
, label1
, y
, x1
, def_button
== 0);
3143 memset(instr
, '\0', sizeof(instr
));
3144 wmove(dialog
, box_y
, box_x
);
3145 wattrset(dialog
, dialog_attr
);
3147 strncpy(instr
, init
, sizeof(instr
) - 2);
3149 input_x
= len
= strlen(instr
);
3150 if (input_x
>= box_width
) {
3151 scrlx
= input_x
- box_width
+ 1;
3152 input_x
= box_width
- 1;
3153 for (i
= 0; i
< box_width
- 1; i
++)
3154 waddch(dialog
, instr
[scrlx
+ i
]);
3157 waddstr(dialog
, instr
);
3159 wmove(dialog
, box_y
, box_x
+ input_x
);
3164 key
= wgetch(dialog
);
3165 if (button
== -1) { /* Input box selected */
3172 if (scrlx
&& !input_x
) {
3174 wmove(dialog
, box_y
, box_x
);
3175 for (i
= 0; i
< box_width
; i
++)
3176 waddch(dialog
, instr
[scrlx
+ input_x
+ i
] ? instr
[scrlx
+ input_x
+ i
] : ' ');
3177 wmove(dialog
, box_y
, input_x
+ box_x
);
3181 wmove(dialog
, box_y
, --input_x
+ box_x
);
3186 if (input_x
+ scrlx
< len
) {
3187 if (input_x
== box_width
- 1) {
3189 wmove(dialog
, box_y
, box_x
);
3190 for (i
= scrlx
; i
< scrlx
+ box_width
; i
++)
3191 waddch(dialog
, instr
[i
] ? instr
[i
] : ' ');
3192 wmove(dialog
, box_y
, input_x
+ box_x
);
3196 wmove(dialog
, box_y
, ++input_x
+ box_x
);
3203 #if defined(__SCO__) || defined(__UNIXWARE__)
3206 if (input_x
|| scrlx
) {
3207 wattrset(dialog
, dialog_attr
);
3209 if (scrlx
+ input_x
< len
)
3210 memmove(instr
+ scrlx
+ input_x
- 1,
3211 instr
+ scrlx
+ input_x
,
3212 len
- (scrlx
+ input_x
));
3213 instr
[--len
] = '\0';
3216 scrlx
= scrlx
< box_width
- 1 ? 0 : scrlx
- (box_width
- 1);
3217 wmove(dialog
, box_y
, box_x
);
3218 for (i
= 0; i
< box_width
; i
++)
3219 waddch(dialog
, instr
[scrlx
+ input_x
+ i
] ? instr
[scrlx
+ input_x
+ i
] : ' ');
3220 input_x
= len
- scrlx
;
3223 wmove(dialog
, box_y
, --input_x
+ box_x
);
3224 for (i
= scrlx
+ input_x
; i
< len
&&
3225 i
< scrlx
+ box_width
; i
++)
3226 waddch(dialog
, instr
[i
]);
3227 if (i
< scrlx
+ box_width
)
3228 waddch(dialog
, ' ');
3230 wmove(dialog
, box_y
, input_x
+ box_x
);
3236 wmove(dialog
, box_y
, box_x
);
3239 for (i
= 0; i
< box_width
; i
++)
3240 waddch(dialog
, instr
[i
] ? instr
[i
] : ' ');
3243 wmove(dialog
, box_y
, box_x
);
3247 if (input_x
+ scrlx
< len
) {
3248 memmove(instr
+ scrlx
+ input_x
,
3249 instr
+ scrlx
+ input_x
+ 1,
3250 len
- (scrlx
+ input_x
));
3251 instr
[--len
] = '\0';
3252 for (i
= scrlx
+ input_x
; i
< len
&&
3253 i
< scrlx
+ box_width
; i
++)
3254 waddch(dialog
, instr
[i
]);
3255 if (i
< scrlx
+ box_width
)
3256 waddch(dialog
, ' ');
3257 wmove(dialog
, box_y
, input_x
+ box_x
);
3263 if (box_width
+ scrlx
< len
) {
3264 input_x
= box_width
- 1;
3265 scrlx
= len
- box_width
+ 1;
3266 wmove(dialog
, box_y
, box_x
);
3267 for (i
= scrlx
; i
< scrlx
+ box_width
; i
++)
3268 waddch(dialog
, instr
[i
] ? instr
[i
] : ' ');
3269 wmove(dialog
, box_y
, input_x
+ box_x
);
3273 input_x
= len
- scrlx
;
3274 wmove(dialog
, box_y
, input_x
+ box_x
);
3280 for (i
= input_x
; i
< box_width
; i
++)
3281 waddch(dialog
, ' ');
3282 for (i
= scrlx
+ input_x
; i
< len
; i
++)
3284 len
= scrlx
+ input_x
;
3285 wmove(dialog
, box_y
, box_x
+ input_x
);
3290 if (key
< 0x100 && isprint(key
)) {
3291 if (scrlx
+ input_x
< sizeof(instr
) - 1) {
3292 wattrset(dialog
, dialog_attr
);
3293 if (scrlx
+ input_x
< len
) {
3294 memmove(instr
+ scrlx
+ input_x
+ 1,
3295 instr
+ scrlx
+ input_x
,
3296 len
- (scrlx
+ input_x
));
3298 instr
[scrlx
+ input_x
] = key
;
3299 instr
[++len
] = '\0';
3300 if (input_x
== box_width
- 1) {
3302 wmove(dialog
, box_y
, box_x
);
3303 for (i
= 0; i
< box_width
- 1; i
++)
3304 waddch(dialog
, instr
[scrlx
+ i
]);
3307 wmove(dialog
, box_y
, input_x
++ + box_x
);
3308 for (i
= scrlx
+ input_x
- 1; i
< len
&&
3309 i
< scrlx
+ box_width
; i
++)
3310 waddch(dialog
, instr
[i
]);
3311 wmove(dialog
, box_y
, input_x
+ box_x
);
3316 flash(); /* Alarm user about overflow */
3327 button
= 1; /* Indicates "Cancel" button is selected */
3328 PaintButton(dialog
, label1
, y
, x1
, FALSE
);
3329 PaintButton(dialog
, label2
, y
, x2
, TRUE
);
3333 button
= -1; /* Indicates input box is selected */
3334 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
3335 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
3336 wmove(dialog
, box_y
, box_x
+ input_x
);
3340 button
= 0; /* Indicates "OK" button is selected */
3341 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
3342 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
3352 button
= 0; /* Indicates "OK" button is selected */
3353 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
3354 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
3358 button
= 1; /* Indicates "Cancel" button is selected */
3359 PaintButton(dialog
, label1
, y
, x1
, FALSE
);
3360 PaintButton(dialog
, label2
, y
, x2
, TRUE
);
3364 button
= -1; /* Indicates input box is selected */
3365 PaintButton(dialog
, label2
, y
, x2
, FALSE
);
3366 PaintButton(dialog
, label1
, y
, x1
, TRUE
);
3367 wmove(dialog
, box_y
, box_x
+ input_x
);
3376 return (button
!= 1 ? XtNewString(instr
) : NULL
);