2 Copyright 1995-2016, The AROS Development Team. All rights reserved.
5 Desc: Disk-resident part of X11 display driver
9 #include <aros/debug.h>
10 #include <dos/dosextens.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>
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"
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
;
88 X11Base
= (struct X11Base
*)OpenLibrary(X11_LIBNAME
, X11_VERSION
);
90 D(bug("[X11] No X11 driver in the system\n"));
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
;
108 CloseLibrary(&X11Base
->library
);
114 /* This function uses library open count as displays count */
115 static ULONG
AddDisplays(ULONG num
, ULONG old
)
117 struct X11Base
*X11Base
;
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
);
130 D(bug("[X11] Failed to open X11 library!\n"));
134 err
= AddDisplayDriverA(X11Base
->gfxclass
, NULL
, NULL
);
136 /* If driver setup failed, decrement counter back and abort */
139 D(bug("[X11] Failed to add display object\n"));
141 CloseLibrary(X11Base
);
154 struct DiskObject
*icon
;
155 struct RDArgs
*rdargs
= NULL
;
163 struct StackSwapStruct sss
;
164 struct StackSwapArgs ssa
;
167 stack
= AllocMem(STACK_SIZE
, MEMF_ANY
);
173 olddir
= CurrentDir(WBenchMsg
->sm_ArgList
[0].wa_Lock
);
174 myname
= WBenchMsg
->sm_ArgList
[0].wa_Name
;
178 struct Process
*me
= (struct Process
*)FindTask(NULL
);
182 struct CommandLineInterface
*cli
= BADDR(me
->pr_CLI
);
184 myname
= AROS_BSTR_ADDR(cli
->cli_CommandName
);
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
));
197 str
= FindToolType(icon
->do_ToolTypes
, "DISPLAYS");
199 args
.displays
= atoi(str
);
201 str
= FindToolType(icon
->do_ToolTypes
, "KEYMAP");
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
237 AddDisplays(args
.displays
, old_displays
);
239 (void)old_displays
; /* unused */
245 FreeDiskObject(icon
);
248 FreeMem(stack
, STACK_SIZE
);