1 /* 2 * Copyright 2019, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 * 5 * Author: 6 * Preetpal Kaur <preetpalok123@gmail.com> 7 */ 8 9 10 #ifndef MOUSE_SETTINGS_H 11 #define MOUSE_SETTINGS_H 12 13 14 #include <map> 15 16 #include <Archivable.h> 17 #include <Input.h> 18 #include <InterfaceDefs.h> 19 #include <Point.h> 20 #include <String.h> 21 #include <SupportDefs.h> 22 23 #include "kb_mouse_settings.h" 24 25 26 class BPath; 27 28 class MouseSettings { 29 public: 30 MouseSettings(BString name); 31 MouseSettings(mouse_settings settings, BString name); 32 ~MouseSettings(); 33 34 void Revert(); 35 bool IsRevertable(); 36 void Defaults(); 37 bool IsDefaultable(); 38 void Dump(); 39 40 int32 MouseType() const { return fSettings.type; } 41 void SetMouseType(int32 type); 42 43 bigtime_t ClickSpeed() const; 44 void SetClickSpeed(bigtime_t click_speed); 45 46 int32 MouseSpeed() const { return fSettings.accel.speed; } 47 void SetMouseSpeed(int32 speed); 48 49 int32 AccelerationFactor() const { return fSettings.accel.accel_factor; } 50 void SetAccelerationFactor(int32 factor); 51 52 uint32 Mapping(int32 index) const; 53 void Mapping(mouse_map &map) const; 54 void SetMapping(int32 index, uint32 button); 55 void SetMapping(mouse_map &map); 56 57 mode_mouse MouseMode() const { return fMode; } 58 void SetMouseMode(mode_mouse mode); 59 60 mode_focus_follows_mouse FocusFollowsMouseMode() const { 61 return fFocusFollowsMouseMode; 62 } 63 void SetFocusFollowsMouseMode(mode_focus_follows_mouse mode); 64 65 bool AcceptFirstClick() const { return fAcceptFirstClick; } 66 void SetAcceptFirstClick(bool accept_first_click); 67 status_t _RetrieveSettings(); 68 status_t _LoadLegacySettings(); 69 70 mouse_settings* GetSettings(); 71 72 private: 73 static status_t _GetSettingsPath(BPath &path); 74 75 private: 76 BString fName; 77 mode_mouse fMode, fOriginalMode; 78 mode_focus_follows_mouse fFocusFollowsMouseMode; 79 mode_focus_follows_mouse fOriginalFocusFollowsMouseMode; 80 bool fAcceptFirstClick; 81 bool fOriginalAcceptFirstClick; 82 83 mouse_settings fSettings, fOriginalSettings; 84 }; 85 86 87 class MultipleMouseSettings: public BArchivable 88 { 89 public: 90 MultipleMouseSettings(); 91 ~MultipleMouseSettings(); 92 93 status_t Archive(BMessage* into, bool deep = false) const; 94 95 void Defaults(); 96 void Dump(); 97 status_t SaveSettings(); 98 99 /** Get or create settings for the given mouse */ 100 MouseSettings* AddMouseSettings(BString mouse_name); 101 /** Get the existing settings, or return NULL */ 102 MouseSettings* GetMouseSettings(BString mouse_name); 103 104 private: 105 static status_t GetSettingsPath(BPath &path); 106 void RetrieveSettings(); 107 108 private: 109 MouseSettings* fDeprecatedMouseSettings; 110 111 typedef std::map<BString, MouseSettings*> mouse_settings_object; 112 mouse_settings_object fMouseSettingsObject; 113 }; 114 115 #endif // MOUSE_SETTINGS_H 116