Added missing properties.
[AROS.git] / arch / all-hosted / hidd / x11 / disk_startup.c
blobe46ccf9e9be4520f181e10889de576288c6aa93a
1 /*
2 Copyright 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Disk-resident part of X11 display driver
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <dos/dosextens.h>
11 #include <oop/oop.h>
12 #include <workbench/startup.h>
13 #include <workbench/workbench.h>
14 #include <proto/dos.h>
15 #include <proto/exec.h>
16 #include <proto/graphics.h>
17 #include <proto/oop.h>
18 #include <proto/icon.h>
20 #include <stdlib.h>
22 #include "x11_class.h"
24 /* Minimum required library version */
25 #define X11_VERSION 42
26 /* Default host keymap file */
27 #define DEF_KEYMAP "DEVS:Keymaps/X11/keycode2rawkey.table"
29 /************************************************************************/
32 * This program is not a driver itself. It is some kind of prefs applicator
33 * whose functions are:
35 * 1. Load host keymap file
36 * 2. Create additional displays (when implemented in the driver)
38 * The driver itself should be placed in kickstart in the form of library.
41 #define ARGS_TEMPLATE "DISPLAYS/N,KEYMAP"
43 struct MyArgs
45 IPTR displays;
46 STRPTR keymap;
49 extern struct WBStartup *WBenchMsg;
51 int __nocommandline = 1;
54 * This code loads a specified X11 keymap table into the driver. Without
55 * this keyboard may work in a wrong way.
57 * The default keymap is created by the build system using this command:
58 * make default-x11keymaptable
60 * A user may also generate his own one:
61 * make change-x11keymaptable
63 * The default keymaptable probably works with most PCs having a 105 key
64 * keyboard if you are using XFree86 as X Server (might also work with
65 * others). So try that one first!
67 * Since the keymap table will be deleted when you do a "make clean" you
68 * might want to make a backup of it. Then you will be able to restore it later:
69 * make backup-x11keymaptable
70 * make restore-x11keymaptable\n"
72 * The keymap table will be backed up in your HOME directory.
74 * Note that the keymaptable only makes sure that your keyboard looks as
75 * much as possible like an Amiga keyboard to AROS. So with the keymaptable
76 * alone the keyboard will behave like an Amiga keyboard with American layout.
77 * For other layouts you must activate the correct keymap in AROS Locale prefs.
80 static ULONG LoadKeyCode2RawKeyTable(STRPTR filename)
82 struct X11Base *X11Base;
83 ULONG displays;
84 BPTR fh;
86 X11Base = (struct X11Base *)OpenLibrary(X11_LIBNAME, X11_VERSION);
87 if (!X11Base) {
88 D(bug("[X11] No X11 driver in the system\n"));
89 return 0;
92 displays = X11Base->library.lib_OpenCnt - 1;
94 if ((fh = Open(filename, MODE_OLDFILE)))
96 D(bug("[X11] X keymap file handle: %p\n", fh));
98 if ((256 == Read(fh, X11Base->keycode2rawkey, 256)))
100 D(bug("LoadKeyCode2RawKeyTable: keycode2rawkey.table successfully loaded!\n"));
101 X11Base->havetable = TRUE;
103 Close(fh);
106 CloseLibrary(&X11Base->library);
108 return displays;
111 #if 0
112 /* This function uses library open count as displays count */
113 static ULONG AddDisplays(ULONG num, ULONG old)
115 struct X11Base *X11Base;
116 ULONG i, err;
118 D(bug("[X11] Making %u displays\n", num));
119 D(bug("[X11] Current displays count: %u\n", old));
121 /* Add displays if needed, open the library once more for every display */
122 for (i = old; i < num; i++)
124 /* This increments counter */
125 X11Base = (struct X11Base *)OpenLibrary(X11_LIBNAME, X11_VERSION);
126 if (!X11Base)
128 D(bug("[X11] Failed to open X11 library!\n"));
129 break;
132 err = AddDisplayDriverA(X11Base->gfxclass, NULL, NULL);
134 /* If driver setup failed, decrement counter back and abort */
135 if (!err)
137 D(bug("[X11] Failed to add display object\n"));
139 CloseLibrary(X11Base);
140 break;
144 return i;
146 #endif
148 int main(void)
150 BPTR olddir = BNULL;
151 STRPTR myname;
152 struct DiskObject *icon;
153 struct RDArgs *rdargs = NULL;
154 ULONG old_displays;
155 int res = RETURN_OK;
156 struct MyArgs args =
159 DEF_KEYMAP
162 if (WBenchMsg)
164 olddir = CurrentDir(WBenchMsg->sm_ArgList[0].wa_Lock);
165 myname = WBenchMsg->sm_ArgList[0].wa_Name;
167 else
169 struct Process *me = (struct Process *)FindTask(NULL);
171 if (me->pr_CLI)
173 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
175 myname = AROS_BSTR_ADDR(cli->cli_CommandName);
176 } else
177 myname = me->pr_Task.tc_Node.ln_Name;
179 D(bug("[X11] Command name: %s\n", myname));
181 icon = GetDiskObject(myname);
182 D(bug("[X11] Icon 0x%p\n", icon));
184 if (icon)
186 STRPTR str;
188 str = FindToolType(icon->do_ToolTypes, "DISPLAYS");
189 if (str)
190 args.displays = atoi(str);
192 str = FindToolType(icon->do_ToolTypes, "KEYMAP");
193 if (str)
194 args.keymap = str;
197 if (!WBenchMsg) {
198 rdargs = ReadArgs(ARGS_TEMPLATE, (IPTR *)&args, NULL);
199 D(bug("[X11] RDArgs 0x%p\n", rdargs));
202 D(bug("[X11] Keymap: %s\n", args.keymap));
204 old_displays = LoadKeyCode2RawKeyTable(args.keymap);
207 * TODO: In order for this to work X11 driver needs to be fixed
208 * in the following way:
209 * - display-specific and window-specific data should be moved from class static data
210 * to driver instance data.
211 * - event task should be able to handle several display windows
212 * - display windows should close when not needed (empty).
213 * - invent what to do with host clipboard handling. The idea is nice but:
214 * a) It should be somehow integrated with clipboard.device
215 * b) Several X11 displays might mean several clipboards (if they run on different
216 * X servers).
218 #if 0
219 if (old_displays)
220 AddDisplays(args.displays, old_displays);
221 #else
222 (void)old_displays; /* unused */
223 #endif
225 if (rdargs)
226 FreeArgs(rdargs);
227 if (icon)
228 FreeDiskObject(icon);
229 if (olddir)
230 CurrentDir(olddir);
232 return res;