define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / rom / intuition / setprefs.c
blobac7c6765f58a90e9d9726a42fb762e0ce0ebdbc9
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <proto/exec.h>
8 #include <proto/graphics.h>
9 #include "intuition_intern.h"
10 #include <intuition/preferences.h>
11 #include <devices/input.h>
12 #include <devices/inputevent.h>
13 #include <stddef.h>
15 /*****************************************************************************
17 NAME */
18 #include <proto/intuition.h>
20 AROS_LH3(struct Preferences *, SetPrefs,
22 /* SYNOPSIS */
23 AROS_LHA(struct Preferences * , prefbuffer, A0),
24 AROS_LHA(LONG , size, D0),
25 AROS_LHA(BOOL , inform, D1),
27 /* LOCATION */
28 struct IntuitionBase *, IntuitionBase, 54, Intuition)
30 /* FUNCTION
31 Sets the current Preferences structure.
33 INPUTS
34 prefbuffer - The buffer which contains your settings for the
35 preferences.
36 size - The number of bytes of the buffer you want to be copied.
37 inform - If TRUE, all windows with IDCMP_NEWPREFS IDCMPFlags set
38 get an IDCMP_NEWPREFS message.
40 RESULT
41 Returns your parameter buffer.
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
50 GetDefPrefs(), GetPrefs()
52 INTERNALS
54 HISTORY
56 *****************************************************************************/
58 AROS_LIBFUNC_INIT
60 DEBUG_SETPREFS(dprintf("SetPrefs: Buffer 0x%lx Size 0x%lx Inform %d\n",
61 (ULONG) prefbuffer, size, inform));
62 if (size > 0 && NULL != prefbuffer)
64 ULONG lock = LockIBase(0);
65 BOOL changepointer = FALSE;
67 if (size > offsetof(struct Preferences, PointerMatrix))
69 if (memcmp(&prefbuffer->PointerMatrix,&GetPrivIBase(IntuitionBase)->ActivePreferences->PointerMatrix,POINTERSIZE) != 0)
70 changepointer = TRUE;
73 CopyMem(prefbuffer,
74 GetPrivIBase(IntuitionBase)->ActivePreferences,
75 size <= sizeof(struct Preferences) ? size : sizeof(struct Preferences));
77 UnlockIBase(lock);
79 DEBUG_SETPREFS(dprintf("SetPrefs: DoubleClick %ld.%ld\n",
80 GetPrivIBase(IntuitionBase)->ActivePreferences->DoubleClick.tv_secs,
81 GetPrivIBase(IntuitionBase)->ActivePreferences->DoubleClick.tv_micro));
83 if (GetPrivIBase(IntuitionBase)->InputIO)
85 struct timerequest req =
87 {{{0}, 0}, 0},
88 {{0}}
91 if (size > offsetof(struct Preferences, KeyRptDelay))
93 #ifdef __MORPHOS__
94 /* No need to setup a reply port, this command is guaranteed to support
95 * quick I/O.
97 #else
98 struct MsgPort *port = CreateMsgPort();
100 if (port)
102 req.tr_node.io_Message.mn_ReplyPort = port;
104 #endif
105 DEBUG_SETPREFS(dprintf("SetPrefs: KeyRptDelay %ld secs micros %ld\n",
106 GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptDelay.tv_secs,
107 GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptDelay.tv_micro));
108 req.tr_node.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
109 req.tr_node.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
110 req.tr_node.io_Command = IND_SETTHRESH;
111 req.tr_time = GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptDelay;
112 DoIO(&req.tr_node);
114 #ifndef __MORPHOS__
115 DeleteMsgPort(port);
117 #endif
120 if (size > offsetof(struct Preferences, KeyRptSpeed))
122 #ifdef __MORPHOS__
123 /* No need to setup a reply port, this command is guaranteed to support
124 * quick I/O.
126 #else
127 struct MsgPort *port = CreateMsgPort();
129 if (port)
131 req.tr_node.io_Message.mn_ReplyPort = port;
132 #endif
134 DEBUG_SETPREFS(dprintf("SetPrefs: KeyRptSpeed secs %ld micros %ld\n",
135 GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptSpeed.tv_secs,
136 GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptSpeed.tv_micro));
138 req.tr_node.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
139 req.tr_node.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
140 req.tr_node.io_Command = IND_SETPERIOD;
141 req.tr_time = GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptSpeed;
142 DoIO(&req.tr_node);
144 #ifndef __MORPHOS__
145 DeleteMsgPort(port);
147 #endif
150 else
152 DEBUG_SETPREFS(dprintf("SetPrefs: no InputIO..don't set Key prefs\n"));
155 //#ifndef __MORPHOS__
156 if (size > offsetof(struct Preferences, PointerMatrix) && changepointer)
158 Object *pointer = MakePointerFromPrefs(IntuitionBase, GetPrivIBase(IntuitionBase)->ActivePreferences);
159 if (pointer)
161 InstallPointer(IntuitionBase, &GetPrivIBase(IntuitionBase)->DefaultPointer, pointer);
164 //#endif
167 ** If inform == TRUE then notify all windows that want to know about
168 ** an update on the preferences.
169 ** Do that by creating an inputevent, that will be handled by our
170 ** handler and converted to idcmp messages, as well as by all other
171 ** input handlers (not sure it should be that way, but that shouldn't
172 ** do any harm).
175 if (inform)
177 struct MsgPort *port = CreateMsgPort();
179 DEBUG_SETPREFS(dprintf("SetPrefs: Send NEWPREFS event\n"));
181 if (port)
183 struct InputEvent ie;
184 struct IOStdReq req;
186 ie.ie_NextEvent = NULL;
187 ie.ie_Class = IECLASS_NEWPREFS;
188 ie.ie_SubClass = 0;
189 ie.ie_Code = 0;
190 ie.ie_Qualifier = 0;
191 ie.ie_EventAddress = NULL;
193 req.io_Message.mn_ReplyPort = port;
194 req.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
195 req.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
196 req.io_Command = IND_WRITEEVENT;
197 req.io_Length = sizeof(ie);
198 req.io_Data = &ie;
200 DoIO((struct IORequest *)&req);
202 DeleteMsgPort(port);
207 #warning Is there any further immediate action to be taken when the prefences are updated?
209 return (struct Preferences *) prefbuffer;
211 AROS_LIBFUNC_EXIT
212 } /* SetPrefs() */