Changeset 43364 in vbox for trunk/src/VBox/Additions/haiku/VBoxMouse
- Timestamp:
- Sep 20, 2012 12:12:09 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 80828
- Location:
- trunk/src/VBox/Additions/haiku/VBoxMouse
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.cpp
r43363 r43364 63 63 64 64 /* Export as global symbol with C linkage, RTDECL is necessary. */ 65 RTDECL(BInputServerDevice *)65 RTDECL(BInputServerDevice *) 66 66 instantiate_input_device() 67 67 { … … 69 69 } 70 70 71 71 72 VBoxMouse::VBoxMouse() 72 : BInputServerDevice(), 73 fDriverFD(-1), 74 fServiceThreadID(-1), 75 fExiting(false) 76 { 77 } 73 : BInputServerDevice(), 74 fDriverFD(-1), 75 fServiceThreadID(-1), 76 fExiting(false) 77 { 78 } 79 78 80 79 81 VBoxMouse::~VBoxMouse() 80 82 { 81 83 } 84 82 85 83 86 status_t VBoxMouse::InitCheck() … … 85 88 int rc = VbglR3Init(); 86 89 if (!RT_SUCCESS(rc)) 87 88 89 90 return ENXIO; 91 92 //// Start() will *not* Init() again 90 93 //VbglR3Term(); 91 94 92 // return B_DEVICE_NOT_FOUND; 93 94 input_device_ref device = { (char *)"VBoxMouse", 95 B_POINTING_DEVICE, (void*)this }; 96 input_device_ref* deviceList[2] = { &device, NULL }; 97 RegisterDevices(deviceList); 98 99 return B_OK; 100 } 95 // return B_DEVICE_NOT_FOUND; 96 97 input_device_ref device = { (char *)"VBoxMouse", 98 B_POINTING_DEVICE, (void *)this }; 99 input_device_ref *deviceList[2] = { &device, NULL }; 100 RegisterDevices(deviceList); 101 102 return B_OK; 103 } 104 101 105 102 106 status_t VBoxMouse::SystemShuttingDown() … … 104 108 VbglR3Term(); 105 109 106 return B_OK; 107 } 108 109 status_t VBoxMouse::Start(const char* device, void* cookie) 110 { 111 status_t err; 112 int rc; 110 return B_OK; 111 } 112 113 114 status_t VBoxMouse::Start(const char *device, void *cookie) 115 { 116 status_t err; 117 int rc; 113 118 uint32_t fFeatures = 0; 114 119 Log(("VBoxMouse::%s()\n", __FUNCTION__)); … … 116 121 rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL); 117 122 if (RT_SUCCESS(rc)) 118 rc = VbglR3SetMouseStatus( 123 rc = VbglR3SetMouseStatus(fFeatures 119 124 | VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE 120 125 | VMMDEV_MOUSE_NEW_PROTOCOL); 121 if (!RT_SUCCESS(rc)) { 122 LogRel(("VBoxMouse: Error switching guest mouse into absolute mode: %d\n", rc)); 126 if (!RT_SUCCESS(rc)) 127 { 128 LogRel(("VBoxMouse: Error switching guest mouse into absolute mode: %d\n", rc)); 123 129 return B_DEVICE_NOT_FOUND; 124 130 } 125 131 126 err = fServiceThreadID = spawn_thread(_ServiceThreadNub, 127 "VBoxMouse", B_NORMAL_PRIORITY, this); 128 if (err >= B_OK) { 129 resume_thread(fServiceThreadID); 130 return B_OK; 131 } else 132 err = fServiceThreadID = spawn_thread(_ServiceThreadNub, 133 "VBoxMouse", B_NORMAL_PRIORITY, this); 134 if (err >= B_OK) 135 { 136 resume_thread(fServiceThreadID); 137 return B_OK; 138 } 139 else 132 140 LogRel(("VBoxMouse: Error starting service thread: 0x%08lx\n", 133 134 135 141 err)); 142 143 // release the mouse 136 144 rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL); 137 145 if (RT_SUCCESS(rc)) 138 rc = VbglR3SetMouseStatus( 146 rc = VbglR3SetMouseStatus(fFeatures 139 147 & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE 140 148 & ~VMMDEV_MOUSE_NEW_PROTOCOL); 141 149 142 return B_ERROR; 143 } 144 145 status_t VBoxMouse::Stop(const char* device, void* cookie) 146 { 147 status_t status; 148 int rc; 150 return B_ERROR; 151 } 152 153 154 status_t VBoxMouse::Stop(const char *device, void *cookie) 155 { 156 status_t status; 157 int rc; 149 158 uint32_t fFeatures = 0; 150 159 Log(("VBoxMouse::%s()\n", __FUNCTION__)); 151 160 152 161 fExiting = true; 153 162 154 163 155 164 rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL); 156 165 if (RT_SUCCESS(rc)) 157 rc = VbglR3SetMouseStatus( 166 rc = VbglR3SetMouseStatus(fFeatures 158 167 & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE 159 168 & ~VMMDEV_MOUSE_NEW_PROTOCOL); 160 169 161 170 162 163 164 165 166 167 168 169 170 return B_OK; 171 } 172 173 status_t VBoxMouse::Control(const char *device, 174 void *cookie, 175 uint32 code, 176 BMessage *message) 177 { 178 // respond to changes in the system 179 switch (code) { 180 case B_MOUSE_SPEED_CHANGED:181 case B_CLICK_SPEED_CHANGED:182 case B_MOUSE_ACCELERATION_CHANGED:183 default: 184 return BInputServerDevice::Control(device, cookie, code, message); 185 } 186 return B_OK; 187 } 171 close(fDriverFD); 172 fDriverFD = -1; 173 //XXX WTF ? 174 suspend_thread(fServiceThreadID); 175 resume_thread(fServiceThreadID); 176 wait_for_thread(fServiceThreadID, &status); 177 fServiceThreadID = -1; 178 fExiting = false; 179 return B_OK; 180 } 181 182 183 status_t VBoxMouse::Control(const char *device, void *cookie, uint32 code, BMessage *message) 184 { 185 // respond to changes in the system 186 switch (code) 187 { 188 case B_MOUSE_SPEED_CHANGED: 189 case B_CLICK_SPEED_CHANGED: 190 case B_MOUSE_ACCELERATION_CHANGED: 191 default: 192 return BInputServerDevice::Control(device, cookie, code, message); 193 } 194 return B_OK; 195 } 196 188 197 189 198 status_t VBoxMouse::_ServiceThreadNub(void *_this) 190 199 { 191 VBoxMouse *service = (VBoxMouse *)_this; 192 return service->_ServiceThread(); 193 } 200 VBoxMouse *service = (VBoxMouse *)_this; 201 return service->_ServiceThread(); 202 } 203 194 204 195 205 status_t VBoxMouse::_ServiceThread() … … 197 207 Log(("VBoxMouse::%s()\n", __FUNCTION__)); 198 208 199 200 201 209 fDriverFD = open(VBOXGUEST_DEVICE_NAME, O_RDWR); 210 if (fDriverFD < 0) 211 return ENXIO; 202 212 203 213 /* The thread waits for incoming messages from the host. */ 204 214 while (!fExiting) 205 215 { 206 207 208 209 210 211 212 213 214 215 216 217 218 if (rc < 0) { 219 if (errno == EINTR || errno == EAGAIN) 220 continue; 221 break;222 } 223 224 if (RT_SUCCESS(VbglR3GetMouseStatus(&fFeatures, &cx, &cy)) 225 && (fFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE))226 {227 float x = cx * 1.0 / 65535; 228 float y = cy* 1.0 / 65535;229 230 _debugPrintf("VBoxMouse: at %d,%d %f,%f\n", cx, cy, x, y); 231 232 /* send absolute movement */ 233 234 bigtime_t now = system_time(); 235 BMessage* event = new BMessage(B_MOUSE_MOVED);236 event->AddInt64("when", now);237 event->AddFloat("x", x);238 event->AddFloat("y", y);239 event->AddFloat("be:tablet_x", x);240 event->AddFloat("be:tablet_y", y);241 //event->PrintToStream();242 EnqueueMessage(event);243 244 //LogRelFlow(("processed host event rc = %d\n", rc)); 245 }246 }247 return 0; 248 } 249 250 216 uint32_t cx, cy, fFeatures; 217 int rc; 218 219 220 fd_set readSet, writeSet, errorSet; 221 FD_ZERO(&readSet); 222 FD_ZERO(&writeSet); 223 FD_ZERO(&errorSet); 224 FD_SET(fDriverFD, &readSet); 225 if (fDriverFD < 0) 226 break; 227 rc = select(fDriverFD + 1, &readSet, &writeSet, &errorSet, NULL); 228 if (rc < 0) 229 { 230 if (errno == EINTR || errno == EAGAIN) 231 continue; 232 break; 233 } 234 235 if (RT_SUCCESS(VbglR3GetMouseStatus(&fFeatures, &cx, &cy)) 236 && (fFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE)) 237 { 238 float x = cx * 1.0 / 65535; 239 float y = cy * 1.0 / 65535; 240 241 _debugPrintf("VBoxMouse: at %d,%d %f,%f\n", cx, cy, x, y); 242 243 /* send absolute movement */ 244 245 bigtime_t now = system_time(); 246 BMessage *event = new BMessage(B_MOUSE_MOVED); 247 event->AddInt64("when", now); 248 event->AddFloat("x", x); 249 event->AddFloat("y", y); 250 event->AddFloat("be:tablet_x", x); 251 event->AddFloat("be:tablet_y", y); 252 //event->PrintToStream(); 253 EnqueueMessage(event); 254 255 //LogRelFlow(("processed host event rc = %d\n", rc)); 256 } 257 } 258 return 0; 259 } 260 -
trunk/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.h
r43363 r43364 50 50 #include <InputServerDevice.h> 51 51 52 extern "C" _EXPORT BInputServerDevice* instantiate_input_device(); 52 extern "C" 53 _EXPORT BInputServerDevice* instantiate_input_device(); 53 54 54 class VBoxMouse : public BInputServerDevice { 55 public: 56 VBoxMouse(); 57 virtual ~VBoxMouse(); 55 class VBoxMouse : public BInputServerDevice 56 { 57 public: 58 VBoxMouse(); 59 virtual ~VBoxMouse(); 58 60 59 60 61 virtual status_t InitCheck(); 62 virtual status_t SystemShuttingDown(); 61 63 62 virtual status_t Start(const char* device, void*cookie);63 virtual status_t Stop(const char* device, void*cookie);64 65 66 67 64 virtual status_t Start(const char *device, void *cookie); 65 virtual status_t Stop(const char *device, void *cookie); 66 virtual status_t Control(const char *device, 67 void *cookie, 68 uint32 code, 69 BMessage *message); 68 70 69 private:71 private: 70 72 71 static status_t _ServiceThreadNub(void *_this);72 73 static status_t _ServiceThreadNub(void *_this); 74 status_t _ServiceThread(); 73 75 74 75 76 76 int fDriverFD; 77 thread_id fServiceThreadID; 78 bool fExiting; 77 79 78 80 }; … … 80 82 81 83 #endif /* __VBOXMOUSE__H */ 84 -
trunk/src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.cpp
r43363 r43364 64 64 // TODO can this be merged with VBoxMouse? 65 65 66 RTDECL(BInputServerFilter *)66 RTDECL(BInputServerFilter *) 67 67 instantiate_input_filter() 68 68 { 69 69 return new VBoxMouseFilter(); 70 70 } 71 71 72 72 VBoxMouseFilter::VBoxMouseFilter() 73 74 75 76 77 73 : BInputServerFilter(), 74 fDriverFD(-1), 75 fServiceThreadID(-1), 76 fExiting(false), 77 fCurrentButtons(0) 78 78 { 79 79 } … … 83 83 } 84 84 85 filter_result VBoxMouseFilter::Filter(BMessage * message, BList*outList)85 filter_result VBoxMouseFilter::Filter(BMessage *message, BList *outList) 86 86 { 87 switch(message->what) { 88 case B_MOUSE_UP: 89 case B_MOUSE_DOWN: 90 { 91 printf("click|release\n"); 92 message->FindInt32("buttons", &fCurrentButtons); 93 } 94 case B_MOUSE_MOVED: 95 { 96 printf("mouse moved\n"); 97 message->ReplaceInt32("buttons", fCurrentButtons); 98 } 99 } 87 switch (message->what) 88 { 89 case B_MOUSE_UP: 90 case B_MOUSE_DOWN: 91 { 92 printf("click|release\n"); 93 message->FindInt32("buttons", &fCurrentButtons); 94 } 95 case B_MOUSE_MOVED: 96 { 97 printf("mouse moved\n"); 98 message->ReplaceInt32("buttons", fCurrentButtons); 99 } 100 } 100 101 101 102 return B_DISPATCH_MESSAGE; 102 103 }
Note:
See TracChangeset
for help on using the changeset viewer.