2 Copyright © 1995-2001, 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];
38 /*********************************************************************************************/
40 static LONG stopchunks
[] =
45 /*********************************************************************************************/
47 static struct KeyMapNode
*KeymapAlreadyOpen(struct KeyMapResource
*KeyMapResource
, STRPTR name
)
49 struct KeyMapNode
*kmn
= NULL
;
54 ForeachNode(&KeyMapResource
->kr_List
, node
)
56 if (!stricmp(name
, node
->ln_Name
))
58 kmn
= (struct KeyMapNode
*)node
;
68 /*********************************************************************************************/
70 static void SetInputPrefs(struct FileInputPrefs
*prefs
)
72 struct KeyMapResource
*KeyMapResource
;
73 struct KeyMapNode
*kmn
;
76 if ((KeyMapResource
= OpenResource("keymap.resource")))
78 kmn
= KeymapAlreadyOpen(KeyMapResource
, prefs
->ip_Keymap
);
82 struct KeyMapNode
*kmn_check
;
83 BPTR lock
, olddir
, seg
;
85 lock
= Lock("DEVS:Keymaps", SHARED_LOCK
);
88 olddir
= CurrentDir(lock
);
90 if ((seg
= LoadSeg(prefs
->ip_Keymap
)))
92 kmn
= (struct KeyMapNode
*) (((UBYTE
*)BADDR(seg
)) + sizeof(APTR
));
95 if ((kmn_check
= KeymapAlreadyOpen(KeyMapResource
, prefs
->ip_Keymap
)))
101 AddHead(&KeyMapResource
->kr_List
, &kmn
->kn_Node
);
106 if (seg
) UnLoadSeg(seg
);
117 if (kmn
) SetKeyMapDefault(&kmn
->kn_KeyMap
);
119 } /* if ((KeyMapResource = OpenResource("keymap.resource"))) */
121 GetPrefs(&p
, sizeof(p
));
123 #define GETLONG(x) ((x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3])
124 #define GETWORD(x) ((x[0] << 8) | x[1])
126 p
.PointerTicks
= GETWORD(prefs
->ip_PointerTicks
);
127 p
.DoubleClick
.tv_secs
= GETLONG(prefs
->ip_DoubleClick_secs
);
128 p
.DoubleClick
.tv_micro
= GETLONG(prefs
->ip_DoubleClick_micro
);
129 p
.KeyRptDelay
.tv_secs
= GETLONG(prefs
->ip_KeyRptDelay_secs
);
130 p
.KeyRptDelay
.tv_micro
= GETLONG(prefs
->ip_KeyRptDelay_micro
);
131 p
.KeyRptSpeed
.tv_secs
= GETLONG(prefs
->ip_KeyRptSpeed_secs
);
132 p
.KeyRptSpeed
.tv_micro
= GETLONG(prefs
->ip_KeyRptSpeed_micro
);
133 if (GETWORD(prefs
->ip_MouseAccel
))
135 p
.EnableCLI
|= MOUSE_ACCEL
;
139 p
.EnableCLI
&= ~MOUSE_ACCEL
;
142 SetPrefs(&p
, sizeof(p
), FALSE
);
146 /*********************************************************************************************/
148 void InputPrefs_Handler(STRPTR filename
)
150 struct IFFHandle
*iff
;
152 D(bug("In IPrefs:InputPrefs_Handler\n"));
154 if ((iff
= CreateIFF(filename
, stopchunks
, 1)))
156 while(ParseIFF(iff
, IFFPARSE_SCAN
) == 0)
158 struct ContextNode
*cn
;
159 struct FileInputPrefs inputprefs
;
161 cn
= CurrentChunk(iff
);
163 D(bug("InputPrefs_Handler: ParseIFF okay. Chunk Type = %c%c%c%c ChunkID = %c%c%c%c\n",
173 if ((cn
->cn_ID
== ID_INPT
) && (cn
->cn_Size
== sizeof(inputprefs
)))
175 D(bug("InputPrefs_Handler: ID_INPT chunk with correct size found.\n"));
177 if (ReadChunkBytes(iff
, &inputprefs
, sizeof(inputprefs
)) == sizeof(inputprefs
))
179 SetInputPrefs(&inputprefs
);
181 } /* if (ReadChunkBytes(iff, &inputprefs, sizeof(inputprefs)) == sizeof(inputprefs)) */
183 } /* if ((cn->cn_ID == ID_INPT) && (cn->cn_Size == sizeof(inputprefs))) */
185 } /* while(ParseIFF(iff, IFFPARSE_SCAN) == 0) */
189 } /* if ((iff = CreateIFF(filename))) */
192 D(bug("In IPrefs:InputPrefs_Handler. Done.\n", filename
));
195 /*********************************************************************************************/