コード例 #1
0
ファイル: xinput_helper.cpp プロジェクト: KDE/kde-workspace
bool XInputEventNotifier::processOtherEvents(XEvent* event)
{
	int newDeviceType = getNewDeviceEventType(event);
	if( newDeviceType == DEVICE_KEYBOARD ) {
		emit(newKeyboardDevice());
	}
	else if( newDeviceType == DEVICE_POINTER ) {
		emit(newPointerDevice());
		emit(newKeyboardDevice());	// arghhh, looks like X resets xkb map even when only pointer device is connected
	}
	return true;
}
コード例 #2
0
ファイル: udev_helper.cpp プロジェクト: cmacq2/plasma-desktop
void UdevDeviceNotifier::socketActivated()
{
    static const char *keyboardDevice[] = {
        "ID_INPUT_KEYBOARD",
        "ID_INPUT_KEY"
    };

    static const char *pointerDevice[] = {
        "ID_INPUT_MOUSE",
        "ID_INPUT_TOUCHPAD",
        "ID_INPUT_TABLET"
    };

    struct udev_device *dev = udev_monitor_receive_device(m_monitor);
    if (!dev) {
        return;
    }

    const char *action = udev_device_get_action(dev);
    if (!action || qstrcmp(action, "add") != 0) {
        udev_device_unref(dev);
        return;
    }

    // Skip devices with empty name
    if (!udev_device_get_property_value(dev, "NAME")) {
        udev_device_unref(dev);
        return;
    }

    for (unsigned i = 0; i < sizeof(keyboardDevice) / sizeof(keyboardDevice[0]); ++i) {
        if (qstrcmp(udev_device_get_property_value(dev, keyboardDevice[i]), "1") == 0) {
            Q_EMIT newKeyboardDevice();
            break;
        }
    }

    for (unsigned i = 0; i < sizeof(pointerDevice) / sizeof(pointerDevice[0]); ++i) {
        if (qstrcmp(udev_device_get_property_value(dev, pointerDevice[i]), "1") == 0) {
            Q_EMIT newPointerDevice();
            break;
        }
    }

    udev_device_unref(dev);
}