2 * Copyright 2004-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
7 * Andrew McCall (mccall@digitalparadise.co.uk)
8 * Axel Dörfler, axeld@pinc-software.de
12 #include "MouseSettings.h"
16 #include <FindDirectory.h>
22 static const bigtime_t kDefaultClickSpeed
= 500000;
23 static const int32 kDefaultMouseSpeed
= 65536;
24 static const int32 kDefaultMouseType
= 3; // 3 button mouse
25 static const int32 kDefaultAccelerationFactor
= 65536;
26 static const bool kDefaultAcceptFirstClick
= false;
30 MouseSettings::MouseSettings()
39 fOriginalSettings
= fSettings
;
40 fOriginalMode
= fMode
;
41 fOriginalFocusFollowsMouseMode
= fFocusFollowsMouseMode
;
42 fOriginalAcceptFirstClick
= fAcceptFirstClick
;
46 MouseSettings::~MouseSettings()
53 MouseSettings::GetSettingsPath(BPath
&path
)
55 status_t status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
59 path
.Append(mouse_settings_file
);
65 MouseSettings::RetrieveSettings()
67 // retrieve current values
70 fAcceptFirstClick
= accept_first_click();
73 // also try to load the window position from disk
76 if (GetSettingsPath(path
) < B_OK
)
79 BFile
file(path
.Path(), B_READ_ONLY
);
80 if (file
.InitCheck() < B_OK
)
83 if (file
.ReadAt(0, &fSettings
, sizeof(mouse_settings
))
84 != sizeof(mouse_settings
)) {
88 if ((fSettings
.click_speed
== 0)
89 || (fSettings
.type
== 0)) {
96 MouseSettings::SaveSettings()
103 status_t status
= GetSettingsPath(path
);
107 BFile
file(path
.Path(), B_READ_WRITE
| B_CREATE_FILE
);
108 status
= file
.InitCheck();
112 file
.Write(&fSettings
, sizeof(fSettings
));
114 // who is responsible for saving the mouse mode and accept_first_click?
122 MouseSettings::Dump()
124 printf("type:\t\t%ld button mouse\n", fSettings
.type
);
125 printf("map:\t\tleft = %lu : middle = %lu : right = %lu\n",
126 fSettings
.map
.button
[0], fSettings
.map
.button
[2],
127 fSettings
.map
.button
[1]);
128 printf("click speed:\t%Ld\n", fSettings
.click_speed
);
129 printf("accel:\t\t%s\n", fSettings
.accel
.enabled
130 ? "enabled" : "disabled");
131 printf("accel factor:\t%ld\n", fSettings
.accel
.accel_factor
);
132 printf("speed:\t\t%ld\n", fSettings
.accel
.speed
);
134 char *mode
= "unknown";
139 case B_CLICK_TO_FOCUS_MOUSE
:
142 case B_FOCUS_FOLLOWS_MOUSE
:
146 printf("mouse mode:\t%s\n", mode
);
148 char *focus_follows_mouse_mode
= "unknown";
149 switch (fFocusFollowsMouseMode
) {
150 case B_NORMAL_FOCUS_FOLLOWS_MOUSE
:
151 focus_follows_mouse_mode
= "normal";
153 case B_WARP_FOCUS_FOLLOWS_MOUSE
:
154 focus_follows_mouse_mode
= "warp";
156 case B_INSTANT_WARP_FOCUS_FOLLOWS_MOUSE
:
157 focus_follows_mouse_mode
= "instant warp";
160 printf("focus follows mouse mode:\t%s\n", focus_follows_mouse_mode
);
161 printf("accept first click:\t%s\n", fAcceptFirstClick
162 ? "enabled" : "disabled");
167 /** Resets the settings to the system defaults
171 MouseSettings::Defaults()
173 SetClickSpeed(kDefaultClickSpeed
);
174 SetMouseSpeed(kDefaultMouseSpeed
);
175 SetMouseType(kDefaultMouseType
);
176 SetAccelerationFactor(kDefaultAccelerationFactor
);
177 SetMouseMode(B_NORMAL_MOUSE
);
178 SetFocusFollowsMouseMode(B_NORMAL_FOCUS_FOLLOWS_MOUSE
);
179 SetAcceptFirstClick(kDefaultAcceptFirstClick
);
181 fSettings
.map
.button
[0] = B_PRIMARY_MOUSE_BUTTON
;
182 fSettings
.map
.button
[1] = B_SECONDARY_MOUSE_BUTTON
;
183 fSettings
.map
.button
[2] = B_TERTIARY_MOUSE_BUTTON
;
189 MouseSettings::SetMouseType(int32 type
)
191 fSettings
.type
= type
;
196 MouseSettings::ClickSpeed() const
198 return fSettings
.click_speed
;
203 MouseSettings::SetClickSpeed(bigtime_t clickSpeed
)
205 fSettings
.click_speed
= clickSpeed
;
210 MouseSettings::SetMouseSpeed(int32 speed
)
212 fSettings
.accel
.speed
= speed
;
217 MouseSettings::SetAccelerationFactor(int32 factor
)
219 fSettings
.accel
.accel_factor
= factor
;
224 MouseSettings::Mapping(int32 index
) const
226 return fSettings
.map
.button
[index
];
231 MouseSettings::Mapping(mouse_map
&map
) const
238 MouseSettings::SetMapping(int32 index
, uint32 button
)
240 fSettings
.map
.button
[index
] = button
;
245 MouseSettings::SetMapping(mouse_map
&map
)
252 MouseSettings::SetMouseMode(mode_mouse mode
)
259 MouseSettings::SetFocusFollowsMouseMode(mode_focus_follows_mouse mode
)
261 fFocusFollowsMouseMode
= mode
;
266 MouseSettings::SetAcceptFirstClick(bool acceptFirstClick
)
268 fAcceptFirstClick
= acceptFirstClick
;