xref: /haiku/src/servers/input/InputServer.h (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 /*****************************************************************************/
2 // OpenBeOS input_server Backend Application
3 //
4 // This is the primary application class for the OpenBeOS input_server.
5 //
6 //
7 // Copyright (c) 2001 OpenBeOS Project
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a
10 // copy of this software and associated documentation files (the "Software"),
11 // to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 // and/or sell copies of the Software, and to permit persons to whom the
14 // Software is furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included
17 // in all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
26 /*****************************************************************************/
27 
28 
29 #ifndef INPUTSERVERAPP_H
30 #define INPUTSERVERAPP_H
31 
32 // BeAPI Headers
33 #include <Application.h>
34 #include "InputServerDevice.h"
35 #include "InputServerFilter.h"
36 #include "InputServerMethod.h"
37 
38 #include <stdlib.h>
39 #include <string.h>
40 #include <unistd.h>
41 #include <Locker.h>
42 
43 #include <Debug.h>
44 #include <FindDirectory.h>
45 #include <InterfaceDefs.h>
46 #include <Message.h>
47 #include <OS.h>
48 #include <SupportDefs.h>
49 
50 class PortLink;
51 
52 // Constants
53 #define SET_METHOD					'stmd'
54 #define GET_MOUSE_TYPE				'gtmt'
55 #define SET_MOUSE_TYPE 				'stmt'
56 #define GET_MOUSE_ACCELERATION 		'gtma'
57 #define SET_MOUSE_ACCELERATION 		'stma'
58 #define GET_KEY_REPEAT_DELAY 		'gkrd'
59 #define SET_KEY_REPEAT_DELAY 		'skrd'
60 #define GET_KEY_INFO 				'ktki'
61 #define GET_MODIFIERS 				'gtmf'
62 #define SET_MODIFIER_KEY 			'smky'
63 #define SET_KEYBOARD_LOCKS 			'skbl'
64 #define GET_MOUSE_SPEED 			'gtms'
65 #define SET_MOUSE_SPEED 			'stms'
66 #define SET_MOUSE_POSITION 			'stmp'
67 #define GET_MOUSE_MAP 				'gtmm'
68 #define SET_MOUSE_MAP 				'stmm'
69 #define GET_KEYBOARD_ID 			'gkbi'
70 #define GET_CLICK_SPEED 			'gtcs'
71 #define SET_CLICK_SPEED 			'stcs'
72 #define GET_KEY_REPEAT_RATE 		'gkrr'
73 #define SET_KEY_REPEAT_RATE 		'skrr'
74 #define GET_KEY_MAP 				'gtkm'
75 #define SET_KEY_MAP 				'stkm'
76 #define FOCUS_IM_AWARE_VIEW 		'fiav'
77 #define UNFOCUS_IM_AWARE_VIEW 		'uiav'
78 
79 class InputDeviceListItem
80 {
81 	public:
82 	BInputServerDevice* mIsd;
83 	input_device_ref*   mDev;
84 
85 	InputDeviceListItem(BInputServerDevice* isd, input_device_ref* dev):
86 		mIsd(isd), mDev(dev) {};
87 };
88 
89 /*****************************************************************************/
90 // InputServer
91 //
92 // Application class for input_server.
93 /*****************************************************************************/
94 
95 class InputServer : public BApplication
96 {
97 	typedef BApplication Inherited;
98 public:
99 	InputServer(void);
100 	virtual ~InputServer(void);
101 
102 	virtual void ArgvReceived(long, char**);
103 
104 	void InitKeyboardMouseStates(void);
105 
106 	void InitDevices(void);
107 	void InitFilters(void);
108 	void InitMethods(void);
109 
110 	virtual bool QuitRequested(void);
111 	virtual void ReadyToRun(void);
112 	//thread_id Run(void);
113 	virtual void MessageReceived(BMessage*);
114 
115 	void HandleSetMethod(BMessage*);
116 	void HandleGetMouseType(BMessage*, BMessage*);
117 	void HandleSetMouseType(BMessage*, BMessage*);
118 	void HandleGetMouseAcceleration(BMessage*, BMessage*);
119 	void HandleSetMouseAcceleration(BMessage*, BMessage*);
120 	void HandleGetKeyRepeatDelay(BMessage*, BMessage*);
121 	void HandleSetKeyRepeatDelay(BMessage*, BMessage*);
122 	void HandleGetKeyInfo(BMessage*, BMessage*);
123 	void HandleGetModifiers(BMessage*, BMessage*);
124 	void HandleSetModifierKey(BMessage*, BMessage*);
125 	void HandleSetKeyboardLocks(BMessage*, BMessage*);
126 	void HandleGetMouseSpeed(BMessage*, BMessage*);
127 	void HandleSetMouseSpeed(BMessage*, BMessage*);
128 	void HandleSetMousePosition(BMessage*, BMessage*);
129 	void HandleGetMouseMap(BMessage*, BMessage*);
130 	void HandleSetMouseMap(BMessage*, BMessage*);
131 	void HandleGetKeyboardID(BMessage*, BMessage*);
132 	void HandleGetClickSpeed(BMessage*, BMessage*);
133 	void HandleSetClickSpeed(BMessage*, BMessage*);
134 	void HandleGetKeyRepeatRate(BMessage*, BMessage*);
135 	void HandleSetKeyRepeatRate(BMessage*, BMessage*);
136 	void HandleGetSetKeyMap(BMessage*, BMessage*);
137 	void HandleFocusUnfocusIMAwareView(BMessage*, BMessage*);
138 
139 	status_t EnqueueDeviceMessage(BMessage*);
140 	status_t EnqueueMethodMessage(BMessage*);
141 	status_t UnlockMethodQueue(void);
142 	status_t LockMethodQueue(void);
143 	status_t SetNextMethod(bool);
144 	//SetActiveMethod(_BMethodAddOn_*);
145 	const BMessenger* MethodReplicant(void);
146 
147 	status_t EventLoop(void*);
148 	static bool     EventLoopRunning(void);
149 
150 	bool DispatchEvents(BList*);
151 	int DispatchEvent(BMessage*);
152 	bool CacheEvents(BList*);
153 	const BList* GetNextEvents(BList*);
154 	bool FilterEvents(BList*);
155 	bool SanitizeEvents(BList*);
156 	bool MethodizeEvents(BList*, bool);
157 
158 	static status_t StartStopDevices(const char *, input_device_type, bool);
159 	status_t ControlDevices(const char *, input_device_type, unsigned long, BMessage*);
160 
161 	bool DoMouseAcceleration(long*, long*);
162 	bool SetMousePos(long*, long*, long, long);
163 	bool SetMousePos(long*, long*, BPoint);
164 	bool SetMousePos(long*, long*, float, float);
165 
166 	bool SafeMode(void);
167 
168 	static BList   gInputDeviceList;
169 	static BLocker gInputDeviceListLocker;
170 
171 private:
172 	void InitTestDevice();
173 
174 	status_t AddInputServerDevice(const char* path);
175 	status_t AddInputServerFilter(const char* path);
176 	status_t AddInputServerMethod(const char* path);
177 
178 	bool 			sEventLoopRunning;
179 	bool 			sSafeMode;
180 	port_id 		sEventPort;
181 	BPoint			sMousePos;
182 	int32			sMouseType;
183 	int32			sMouseSpeed;
184 	int32			sMouseAcceleration;
185 	bigtime_t		sMouseClickSpeed;
186 	int32			sKeyRepeatRate;
187 	bigtime_t       sKeyRepeatDelay;
188 	mouse_map		sMouseMap;
189 
190 	port_id			ISPort;
191 	port_id      	EventLooperPort;
192 	thread_id    	ISPortThread;
193 	static int32 	ISPortWatcher(void *arg);
194 	void WatchPort();
195 
196 	static bool doStartStopDevice(void*, void*);
197 
198 	static BList mInputServerDeviceList;
199 	static BList mInputServerFilterList;
200 	static BList mInputServerMethodList;
201 
202 	// added this to communicate via portlink
203 
204 	PortLink *serverlink;
205 
206 	//fMouseState;
207 };
208 
209 
210 #endif
211