diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index 9332cc9431..5b0614154b 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -1436,49 +1436,6 @@ InputServer::MethodizeEvents(BList *, } -/* - * Method: InputServer::StartStopDevices() - * Descr: - */ -status_t -InputServer::StartStopDevices(const char* deviceName, - input_device_type deviceType, - bool doStart) -{ - CALLED(); - for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--) - { - PRINT(("Device #%d\n", i)); - InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i); - if (NULL == item) - continue; - - BInputServerDevice* isd = item->mIsd; - input_device_ref dev = item->mDev; - - PRINT(("Hey\n")); - - if (NULL != isd) - continue; - - if (deviceType == dev.type) { - if (doStart) { - PRINT((" Starting: %s\n", dev.name)); - isd->Start(dev.name, dev.cookie); - item->mStarted = true; - } else { - PRINT((" Stopping: %s\n", dev.name)); - isd->Stop(dev.name, dev.cookie); - item->mStarted = false; - } - } - } - EXIT(); - - return B_OK; -} - - /* * Method: InputServer::StartStopDevices() * Descr: diff --git a/src/servers/input/InputServer.h b/src/servers/input/InputServer.h index ee228bd4d5..a2f8eaa4be 100644 --- a/src/servers/input/InputServer.h +++ b/src/servers/input/InputServer.h @@ -159,7 +159,6 @@ public: bool SanitizeEvents(BList*); bool MethodizeEvents(BList*, bool); - static status_t StartStopDevices(const char *, input_device_type, bool); static status_t StartStopDevices(BInputServerDevice *isd, bool); status_t ControlDevices(const char *, input_device_type, unsigned long, BMessage*); diff --git a/src/servers/input/InputServerDevice.cpp b/src/servers/input/InputServerDevice.cpp index 4021e2711d..cc95d7ed01 100644 --- a/src/servers/input/InputServerDevice.cpp +++ b/src/servers/input/InputServerDevice.cpp @@ -145,43 +145,33 @@ BInputServerDevice::RegisterDevices(input_device_ref **devices) { CALLED(); - // Lock this section of code so that access to the device list - // is serialized. Be sure to release the lock before exitting. - // BAutolock lock(InputServer::gInputDeviceListLocker); - //bool has_pointing_device = false; - //bool has_keyboard_device = false; - input_device_ref *device = NULL; for (int i = 0; NULL != (device = devices[i]); i++) { - // :TODO: Check to make sure that each device is valid and - // that it is not already registered. - // getDeviceIndex() + if (device->type != B_POINTING_DEVICE + && device->type != B_KEYBOARD_DEVICE + && device->type != B_UNDEFINED_DEVICE) + continue; + + bool found = false; + for (int j = InputServer::gInputDeviceList.CountItems() - 1; j >= 0; j--) { + InputDeviceListItem* item = (InputDeviceListItem*)InputServer::gInputDeviceList.ItemAt(j); + if (!item) + continue; + + if (strcmp(device->name, item->mDev.name) == 0) { + found = true; + break; + } + } - InputServer::gInputDeviceList.AddItem(new InputDeviceListItem(this, *device) ); - - //has_pointing_device = has_pointing_device || (device->type == B_POINTING_DEVICE); - //has_keyboard_device = has_keyboard_device || (device->type == B_KEYBOARD_DEVICE); + if (!found) { + InputServer::gInputDeviceList.AddItem(new InputDeviceListItem(this, *device) ); + Start(device->name, device->cookie); + } } - // If the InputServer event loop is running, signal the InputServer - // to start all devices of the type managed by this InputServerDevice. - // - /*if (InputServer::EventLoopRunning() ) - { - if (has_pointing_device) - { - InputServer::StartStopDevices(NULL, B_POINTING_DEVICE, true); - } - if (has_keyboard_device) - { - InputServer::StartStopDevices(NULL, B_KEYBOARD_DEVICE, true); - } - }*/ - - InputServer::StartStopDevices(this, true); - return B_OK; } @@ -195,14 +185,22 @@ BInputServerDevice::UnregisterDevices(input_device_ref **devices) { CALLED(); - // Lock this section of code so that access to the device list - // is serialized. Be sure to release the lock before exitting. - // - BAutolock lock(InputServer::gInputDeviceListLocker); + BAutolock lock(InputServer::gInputDeviceListLocker); input_device_ref *device = NULL; for (int i = 0; NULL != (device = devices[i]); i++) { - + + for (int j = InputServer::gInputDeviceList.CountItems() - 1; j >= 0; j--) { + InputDeviceListItem* item = (InputDeviceListItem*)InputServer::gInputDeviceList.ItemAt(j); + if (!item) + continue; + + if (strcmp(device->name, item->mDev.name) == 0) { + Stop(item->mDev.name, item->mDev.cookie); + InputServer::gInputDeviceList.RemoveItem(j); + break; + } + } } return B_OK;