2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
13 #include <prefs/prefhdr.h>
14 #include <prefs/input.h>
15 #include <devices/input.h>
16 #include <devices/keymap.h>
21 #include <aros/debug.h>
23 /*********************************************************************************************/
28 UBYTE ip_PointerTicks
[2];
29 UBYTE ip_DoubleClick_secs
[4];
30 UBYTE ip_DoubleClick_micro
[4];
31 UBYTE ip_KeyRptDelay_secs
[4];
32 UBYTE ip_KeyRptDelay_micro
[4];
33 UBYTE ip_KeyRptSpeed_secs
[4];
34 UBYTE ip_KeyRptSpeed_micro
[4];
35 UBYTE ip_MouseAccel
[2];
36 UBYTE ip_ClassicKeyboard
[4];
37 char ip_KeymapName
[64];
38 UBYTE ip_SwitchMouseButtons
[4];
41 /*********************************************************************************************/
43 static LONG stopchunks
[] =
49 /*********************************************************************************************/
51 static void SetInputPrefs(struct FileInputPrefs
*prefs
)
53 struct KeyMapNode
*kmn
;
55 struct IOStdReq ioreq
;
57 char *keymap
= prefs
->ip_KeymapName
;
60 keymap
= prefs
->ip_Keymap
;
61 D(bug("[InputPrefs] Keymap name: %s\n", keymap
));
63 kmn
= OpenKeymap(keymap
);
65 SetKeyMapDefault(&kmn
->kn_KeyMap
);
67 GetPrefs(&p
, sizeof(p
));
69 #define GETLONG(x) ((x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3])
70 #define GETWORD(x) ((x[0] << 8) | x[1])
72 p
.PointerTicks
= GETWORD(prefs
->ip_PointerTicks
);
73 p
.DoubleClick
.tv_secs
= GETLONG(prefs
->ip_DoubleClick_secs
);
74 p
.DoubleClick
.tv_micro
= GETLONG(prefs
->ip_DoubleClick_micro
);
75 p
.KeyRptDelay
.tv_secs
= GETLONG(prefs
->ip_KeyRptDelay_secs
);
76 p
.KeyRptDelay
.tv_micro
= GETLONG(prefs
->ip_KeyRptDelay_micro
);
77 p
.KeyRptSpeed
.tv_secs
= GETLONG(prefs
->ip_KeyRptSpeed_secs
);
78 p
.KeyRptSpeed
.tv_micro
= GETLONG(prefs
->ip_KeyRptSpeed_micro
);
79 if (GETWORD(prefs
->ip_MouseAccel
))
81 p
.EnableCLI
|= MOUSE_ACCEL
;
85 p
.EnableCLI
&= ~MOUSE_ACCEL
;
88 SetPrefs(&p
, sizeof(p
), FALSE
);
90 memset(&ioreq
, 0, sizeof(ioreq
));
91 ioreq
.io_Message
.mn_Length
= sizeof(ioreq
);
93 if (!OpenDevice("input.device", 0, (struct IORequest
*)&ioreq
, 0))
95 struct InputDevice
*InputBase
= (struct InputDevice
*)ioreq
.io_Device
;
97 D(bug("[InputPrefs] Opened input.device v%d.%d\n", InputBase
->id_Device
.dd_Library
.lib_Version
,
98 InputBase
->id_Device
.dd_Library
.lib_Revision
));
99 /* AROS input.device support this since v41.3 */
100 if ((InputBase
->id_Device
.dd_Library
.lib_Version
>= 41) &&
101 (InputBase
->id_Device
.dd_Library
.lib_Revision
>= 3))
103 InputBase
->id_Flags
= prefs
->ip_SwitchMouseButtons
[3] ? IDF_SWAP_BUTTONS
: 0;
104 D(bug("[InputPrefs] Flags set to 0x%08lX\n", InputBase
->id_Flags
));
107 CloseDevice((struct IORequest
*)&ioreq
);
111 /*********************************************************************************************/
113 void InputPrefs_Handler(STRPTR filename
)
115 struct IFFHandle
*iff
;
117 D(bug("In IPrefs:InputPrefs_Handler\n"));
119 if ((iff
= CreateIFF(filename
, stopchunks
, 2)))
122 * Disable keymap switcher.
123 * It will stay disabled if the file does not contain KMSW chunk.
124 * This is done for backwards compatibility.
126 KMSBase
->kms_SwitchQual
= KMS_QUAL_DISABLE
;
128 while(ParseIFF(iff
, IFFPARSE_SCAN
) == 0)
130 struct ContextNode
*cn
;
131 struct FileInputPrefs
*inputprefs
;
132 struct KMSPrefs
*kmsprefs
;
134 D(bug("InputPrefs_Handler: ParseIFF okay\n"));
135 cn
= CurrentChunk(iff
);
140 D(bug("InputPrefs_Handler: INPT chunk\n"));
142 inputprefs
= LoadChunk(iff
, sizeof(struct FileInputPrefs
), MEMF_ANY
);
145 SetInputPrefs(inputprefs
);
151 D(bug("InputPrefs_Handler: KMSW chunk\n"));
153 kmsprefs
= LoadChunk(iff
, sizeof(struct KMSPrefs
), MEMF_ANY
);
156 D(bug("KMS Chunk @ 0x%p\n", kmsprefs
));
157 if (kmsprefs
->kms_Enabled
)
159 struct KeyMapNode
*alt_km
;
161 D(bug("KMS Enabled\n"));
163 D(bug("Attempting to use AltKeymap name @ 0x%p\n", kmsprefs
->kms_AltKeymap
));
164 D(bug("AltKeymap name '%s'\n", kmsprefs
->kms_AltKeymap
));
166 alt_km
= OpenKeymap(kmsprefs
->kms_AltKeymap
);
168 D(bug("Keymap @ 0x%p\n", alt_km
));
172 KMSBase
->kms_SwitchQual
= AROS_BE2WORD(kmsprefs
->kms_SwitchQual
);
173 KMSBase
->kms_SwitchCode
= AROS_BE2WORD(kmsprefs
->kms_SwitchCode
);
174 KMSBase
->kms_AltKeymap
= &alt_km
->kn_KeyMap
;
182 } /* while(ParseIFF(iff, IFFPARSE_SCAN) == 0) */
186 } /* if ((iff = CreateIFF(filename))) */
189 D(bug("In IPrefs:InputPrefs_Handler. Done.\n", filename
));
192 /*********************************************************************************************/