revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-hosted / hidd / x11 / disk_startup.c
blob3b0a0c4df159674efbb95b37204bf0acb4b7565d
1 /*
2 Copyright 1995-2016, 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 #define STACK_SIZE 100000
31 /************************************************************************/
34 * This program is not a driver itself. It is some kind of prefs applicator
35 * whose functions are:
37 * 1. Load host keymap file
38 * 2. Create additional displays (when implemented in the driver)
40 * The driver itself should be placed in kickstart in the form of library.
43 #define ARGS_TEMPLATE "DISPLAYS/N,KEYMAP"
45 struct MyArgs
47 IPTR displays;
48 STRPTR keymap;
51 extern struct WBStartup *WBenchMsg;
53 int __nocommandline = 1;
56 * This code loads a specified X11 keymap table into the driver. Without
57 * this keyboard may work in a wrong way.
59 * The default keymap is created by the build system using this command:
60 * make default-x11keymaptable
62 * A user may also generate his own one:
63 * make change-x11keymaptable
65 * The default keymaptable probably works with most PCs having a 105 key
66 * keyboard if you are using XFree86 as X Server (might also work with
67 * others). So try that one first!
69 * Since the keymap table will be deleted when you do a "make clean" you
70 * might want to make a backup of it. Then you will be able to restore it later:
71 * make backup-x11keymaptable
72 * make restore-x11keymaptable\n"
74 * The keymap table will be backed up in your HOME directory.
76 * Note that the keymaptable only makes sure that your keyboard looks as
77 * much as possible like an Amiga keyboard to AROS. So with the keymaptable
78 * alone the keyboard will behave like an Amiga keyboard with American layout.
79 * For other layouts you must activate the correct keymap in AROS Locale prefs.
82 static ULONG LoadKeyCode2RawKeyTable(STRPTR filename)
84 struct X11Base *X11Base;
85 ULONG displays;
86 BPTR fh;
88 X11Base = (struct X11Base *)OpenLibrary(X11_LIBNAME, X11_VERSION);
89 if (!X11Base) {
90 D(bug("[X11] No X11 driver in the system\n"));
91 return 0;
94 displays = X11Base->library.lib_OpenCnt - 1;
96 if ((fh = Open(filename, MODE_OLDFILE)))
98 D(bug("[X11] X keymap file handle: %p\n", fh));
100 if ((256 == Read(fh, X11Base->keycode2rawkey, 256)))
102 D(bug("LoadKeyCode2RawKeyTable: keycode2rawkey.table successfully loaded!\n"));
103 X11Base->havetable = TRUE;
105 Close(fh);
108 CloseLibrary(&X11Base->library);
110 return displays;
113 #if 0
114 /* This function uses library open count as displays count */
115 static ULONG AddDisplays(ULONG num, ULONG old)
117 struct X11Base *X11Base;
118 ULONG i, err;
120 D(bug("[X11] Making %u displays\n", num));
121 D(bug("[X11] Current displays count: %u\n", old));
123 /* Add displays if needed, open the library once more for every display */
124 for (i = old; i < num; i++)
126 /* This increments counter */
127 X11Base = (struct X11Base *)OpenLibrary(X11_LIBNAME, X11_VERSION);
128 if (!X11Base)
130 D(bug("[X11] Failed to open X11 library!\n"));
131 break;
134 err = AddDisplayDriverA(X11Base->gfxclass, NULL, NULL);
136 /* If driver setup failed, decrement counter back and abort */
137 if (!err)
139 D(bug("[X11] Failed to add display object\n"));
141 CloseLibrary(X11Base);
142 break;
146 return i;
148 #endif
150 int main(void)
152 BPTR olddir = BNULL;
153 STRPTR myname;
154 struct DiskObject *icon;
155 struct RDArgs *rdargs = NULL;
156 ULONG old_displays;
157 int res = RETURN_OK;
158 struct MyArgs args =
161 DEF_KEYMAP
163 struct StackSwapStruct sss;
164 struct StackSwapArgs ssa;
165 UBYTE *stack;
167 stack = AllocMem(STACK_SIZE, MEMF_ANY);
168 if (stack == NULL)
169 return RETURN_FAIL;
171 if (WBenchMsg)
173 olddir = CurrentDir(WBenchMsg->sm_ArgList[0].wa_Lock);
174 myname = WBenchMsg->sm_ArgList[0].wa_Name;
176 else
178 struct Process *me = (struct Process *)FindTask(NULL);
180 if (me->pr_CLI)
182 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
184 myname = AROS_BSTR_ADDR(cli->cli_CommandName);
185 } else
186 myname = me->pr_Task.tc_Node.ln_Name;
188 D(bug("[X11] Command name: %s\n", myname));
190 icon = GetDiskObject(myname);
191 D(bug("[X11] Icon 0x%p\n", icon));
193 if (icon)
195 STRPTR str;
197 str = FindToolType(icon->do_ToolTypes, "DISPLAYS");
198 if (str)
199 args.displays = atoi(str);
201 str = FindToolType(icon->do_ToolTypes, "KEYMAP");
202 if (str)
203 args.keymap = str;
206 if (!WBenchMsg) {
207 rdargs = ReadArgs(ARGS_TEMPLATE, (IPTR *)&args, NULL);
208 D(bug("[X11] RDArgs 0x%p\n", rdargs));
211 D(bug("[X11] Keymap: %s\n", args.keymap));
213 /* Call LoadKeyCode2RawKeyTable() with a new stack: it initialises
214 x11gfx.hidd, and some X servers need a larger than normal stack */
215 sss.stk_Lower = stack;
216 sss.stk_Upper = stack + STACK_SIZE;
217 sss.stk_Pointer = sss.stk_Upper;
219 ssa.Args[0] = (IPTR)args.keymap;
221 old_displays = NewStackSwap(&sss, LoadKeyCode2RawKeyTable, &ssa);
224 * TODO: In order for this to work X11 driver needs to be fixed
225 * in the following way:
226 * - display-specific and window-specific data should be moved from class static data
227 * to driver instance data.
228 * - event task should be able to handle several display windows
229 * - display windows should close when not needed (empty).
230 * - invent what to do with host clipboard handling. The idea is nice but:
231 * a) It should be somehow integrated with clipboard.device
232 * b) Several X11 displays might mean several clipboards (if they run on different
233 * X servers).
235 #if 0
236 if (old_displays)
237 AddDisplays(args.displays, old_displays);
238 #else
239 (void)old_displays; /* unused */
240 #endif
242 if (rdargs)
243 FreeArgs(rdargs);
244 if (icon)
245 FreeDiskObject(icon);
246 if (olddir)
247 CurrentDir(olddir);
248 FreeMem(stack, STACK_SIZE);
250 return res;