2 Copyright 1995-2011, 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 /************************************************************************/
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"
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
;
86 X11Base
= (struct X11Base
*)OpenLibrary(X11_LIBNAME
, X11_VERSION
);
88 D(bug("[X11] No X11 driver in the system\n"));
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
;
106 CloseLibrary(&X11Base
->library
);
112 /* This function uses library open count as displays count */
113 static ULONG
AddDisplays(ULONG num
, ULONG old
)
115 struct X11Base
*X11Base
;
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
);
128 D(bug("[X11] Failed to open X11 library!\n"));
132 err
= AddDisplayDriverA(X11Base
->gfxclass
, NULL
, NULL
);
134 /* If driver setup failed, decrement counter back and abort */
137 D(bug("[X11] Failed to add display object\n"));
139 CloseLibrary(X11Base
);
152 struct DiskObject
*icon
;
153 struct RDArgs
*rdargs
= NULL
;
164 olddir
= CurrentDir(WBenchMsg
->sm_ArgList
[0].wa_Lock
);
165 myname
= WBenchMsg
->sm_ArgList
[0].wa_Name
;
169 struct Process
*me
= (struct Process
*)FindTask(NULL
);
173 struct CommandLineInterface
*cli
= BADDR(me
->pr_CLI
);
175 myname
= AROS_BSTR_ADDR(cli
->cli_CommandName
);
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
));
188 str
= FindToolType(icon
->do_ToolTypes
, "DISPLAYS");
190 args
.displays
= atoi(str
);
192 str
= FindToolType(icon
->do_ToolTypes
, "KEYMAP");
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
220 AddDisplays(args
.displays
, old_displays
);
222 (void)old_displays
; /* unused */
228 FreeDiskObject(icon
);