xref: /haiku/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.h (revision c90684742e7361651849be4116d0e5de3a817194)
1 /*
2  * Copyright 2004-2008, Jérôme Duval. All rights reserved.
3  * Copyright 2005-2010, Axel Dörfler, axeld@pinc-software.de.
4  * Copyright 2008, Stephan Aßmus, superstippi@gmx.de.
5  *
6  * Distributed under the terms of the MIT License.
7  */
8 #ifndef KEYBOARD_INPUT_DEVICE_H
9 #define KEYBOARD_INPUT_DEVICE_H
10 
11 
12 #include <Handler.h>
13 #include <InputServerDevice.h>
14 #include <Locker.h>
15 
16 #include <InputServerTypes.h>
17 #include <ObjectList.h>
18 
19 #include "Keymap.h"
20 #include "TeamMonitorWindow.h"
21 #include "kb_mouse_settings.h"
22 
23 
24 class KeyboardInputDevice;
25 
26 class KeyboardDevice : public BHandler {
27 public:
28 								KeyboardDevice(KeyboardInputDevice* owner,
29 									const char* path);
30 	virtual						~KeyboardDevice();
31 
32 	virtual	void				MessageReceived(BMessage* message);
33 			status_t			Start();
34 			void				Stop();
35 
36 			status_t			UpdateSettings(uint32 opcode = 0);
37 
38 			const char*			Path() const { return fPath; }
39 			input_device_ref*	DeviceRef() { return &fDeviceRef; }
40 
41 private:
42 	static	int32				_ControlThreadEntry(void* arg);
43 			int32				_ControlThread();
44 			void				_ControlThreadCleanup();
45 			void				_UpdateSettings(uint32 opcode);
46 			void				_UpdateLEDs();
47 			status_t			_EnqueueInlineInputMethod(int32 opcode,
48 									const char* string = NULL,
49 									bool confirmed = false,
50 									BMessage* keyDown = NULL);
51 
52 private:
53 			KeyboardInputDevice* fOwner;
54 			input_device_ref	fDeviceRef;
55 			char				fPath[B_PATH_NAME_LENGTH];
56 			int					fFD;
57 			thread_id			fThread;
58 			kb_settings			fSettings;
59 	volatile bool				fActive;
60 	volatile bool				fInputMethodStarted;
61 			uint32				fModifiers;
62 			uint32				fCommandKey;
63 			uint32				fControlKey;
64 
65 	volatile bool				fUpdateSettings;
66 	volatile uint32				fSettingsCommand;
67 
68 			Keymap				fKeymap;
69 			BLocker				fKeymapLock;
70 };
71 
72 
73 class KeyboardInputDevice : public BInputServerDevice {
74 public:
75 								KeyboardInputDevice();
76 	virtual						~KeyboardInputDevice();
77 
78 	virtual	status_t			InitCheck();
79 
80 	virtual	status_t			Start(const char* name, void* cookie);
81 	virtual status_t			Stop(const char* name, void* cookie);
82 
83 	virtual status_t			Control(const char* name, void* cookie,
84 									uint32 command, BMessage* message);
85 
86 	virtual status_t			SystemShuttingDown();
87 
88 private:
89 	friend struct KeyboardDevice;
90 	// TODO: needed by the control thread to remove a dead device
91 	// find a better way...
92 
93 			status_t			_HandleMonitor(BMessage* message);
94 			void				_RecursiveScan(const char* directory);
95 
96 			KeyboardDevice*		_FindDevice(const char* path) const;
97 			status_t			_AddDevice(const char* path);
98 			status_t			_RemoveDevice(const char* path);
99 
100 			BObjectList<KeyboardDevice> fDevices;
101 			BLocker				fDeviceListLock;
102 			TeamMonitorWindow*	fTeamMonitorWindow;
103 };
104 
105 extern "C" BInputServerDevice* instantiate_input_device();
106 
107 #endif	// KEYBOARD_INPUT_DEVICE_H
108