2 * Copyright 2008-2010, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
6 * Clemens Zeidler (haiku@Clemens-Zeidler.de)
10 #include "TouchpadPref.h"
13 #include <FindDirectory.h>
17 #include <keyboard_mouse_driver.h>
20 TouchpadPref::TouchpadPref()
23 // default center position
24 fWindowPosition
.x
= -1;
25 fWindowPosition
.y
= -1;
29 if (LoadSettings() != B_OK
)
32 fStartSettings
= fSettings
;
36 TouchpadPref::~TouchpadPref()
46 TouchpadPref::Revert()
48 fSettings
= fStartSettings
;
53 TouchpadPref::UpdateSettings()
58 LOG("UpdateSettings of device %s\n", fTouchPad
->Name());
61 msg
.AddBool("scroll_twofinger", fSettings
.scroll_twofinger
);
62 msg
.AddBool("scroll_twofinger_horizontal",
63 fSettings
.scroll_twofinger_horizontal
);
64 msg
.AddFloat("scroll_rightrange", fSettings
.scroll_rightrange
);
65 msg
.AddFloat("scroll_bottomrange", fSettings
.scroll_bottomrange
);
66 msg
.AddInt16("scroll_xstepsize", fSettings
.scroll_xstepsize
);
67 msg
.AddInt16("scroll_ystepsize", fSettings
.scroll_ystepsize
);
68 msg
.AddInt8("scroll_acceleration", fSettings
.scroll_acceleration
);
69 msg
.AddInt8("tapgesture_sensibility", fSettings
.tapgesture_sensibility
);
71 return fTouchPad
->Control(MS_SET_TOUCHPAD_SETTINGS
, &msg
);
76 TouchpadPref::Defaults()
78 fSettings
= kDefaultTouchpadSettings
;
83 TouchpadPref::GetSettingsPath(BPath
&path
)
85 status_t status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
89 return path
.Append(TOUCHPAD_SETTINGS_FILE
);
94 TouchpadPref::LoadSettings()
97 status_t status
= GetSettingsPath(path
);
101 BFile
settingsFile(path
.Path(), B_READ_ONLY
);
102 status
= settingsFile
.InitCheck();
106 if (settingsFile
.Read(&fSettings
, sizeof(touchpad_settings
))
107 != sizeof(touchpad_settings
)) {
108 LOG("failed to load settings\n");
112 if (settingsFile
.Read(&fWindowPosition
, sizeof(BPoint
))
114 LOG("failed to load settings\n");
123 TouchpadPref::SaveSettings()
126 status_t status
= GetSettingsPath(path
);
130 BFile
settingsFile(path
.Path(), B_READ_WRITE
| B_CREATE_FILE
);
131 status
= settingsFile
.InitCheck();
135 if (settingsFile
.Write(&fSettings
, sizeof(touchpad_settings
))
136 != sizeof(touchpad_settings
)) {
137 LOG("can't save settings\n");
141 if (settingsFile
.Write(&fWindowPosition
, sizeof(BPoint
))
143 LOG("can't save window position\n");
152 TouchpadPref::ConnectToTouchPad()
155 status_t status
= get_input_devices(&devList
);
161 BInputDevice
* dev
= (BInputDevice
*)devList
.ItemAt(i
);
166 LOG("input device %s\n", dev
->Name());
168 BString name
= dev
->Name();
170 if (name
.FindFirst("Touchpad") >= 0
171 && dev
->Type() == B_POINTING_DEVICE
175 // Don't bail out here, since we need to delete the other devices
184 LOG("touchpad input device NOT found\n");
185 return B_ENTRY_NOT_FOUND
;