Example #1
0
void QWaylandInputDevice::inputHandleKeyboardFocus(void *data,
						   struct wl_input_device *input_device,
						   uint32_t time,
						   struct wl_surface *surface,
						   struct wl_array *keys)
{
#ifndef QT_NO_WAYLAND_XKB
    Q_UNUSED(input_device);
    Q_UNUSED(time);
    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
    QWaylandWindow *window;
    uint32_t *k, *end;
    uint32_t code;

    end = (uint32_t *) ((char *) keys->data + keys->size);
    inputDevice->mModifiers = 0;
    for (k = (uint32_t *) keys->data; k < end; k++) {
	code = *k + inputDevice->mXkb->min_key_code;
	inputDevice->mModifiers |=
	    translateModifiers(inputDevice->mXkb->map->modmap[code]);
    }

    if (surface) {
	window = (QWaylandWindow *) wl_surface_get_user_data(surface);
	inputDevice->mKeyboardFocus = window;
	QWindowSystemInterface::handleWindowActivated(window->widget());
    } else {
	inputDevice->mKeyboardFocus = NULL;
	QWindowSystemInterface::handleWindowActivated(0);
    }
#endif
}
Example #2
0
void QtKeySequenceEdit::handleKeyEvent(QKeyEvent *e)
{
    int nextKey = e->key();
    if (nextKey == Qt::Key_Control || nextKey == Qt::Key_Shift ||
            nextKey == Qt::Key_Meta || nextKey == Qt::Key_Alt ||
            nextKey == Qt::Key_Super_L || nextKey == Qt::Key_AltGr)
        return;

    nextKey |= translateModifiers(e->modifiers(), e->text());
    int k0 = m_keySequence[0];
    int k1 = m_keySequence[1];
    int k2 = m_keySequence[2];
    int k3 = m_keySequence[3];
    switch (m_num) {
        case 0: k0 = nextKey; k1 = 0; k2 = 0; k3 = 0; break;
        case 1: k1 = nextKey; k2 = 0; k3 = 0; break;
        case 2: k2 = nextKey; k3 = 0; break;
        case 3: k3 = nextKey; break;
        default: break;
    }
    ++m_num;
    if (m_num > 3)
        m_num = 0;
    m_keySequence = QKeySequence(k0, k1, k2, k3);
    m_lineEdit->setText(m_keySequence.toString(QKeySequence::NativeText));
    e->accept();
    emit keySequenceChanged(m_keySequence);
}
Example #3
0
bool ShortcutEdit::event(QEvent *event)
{
    switch (event->type()) {
    case QEvent::KeyPress: {
        QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
        switch (keyEvent->key()) {
        case Qt::Key_Alt:
        case Qt::Key_Control:
        case Qt::Key_Meta:
        case Qt::Key_Shift:
            return true;
        default:
            m_key = keyEvent->key();
            m_key |= translateModifiers(keyEvent->modifiers(), keyEvent->text());
            setText(keySequence().toString(QKeySequence::NativeText));
        }
    }
    case QEvent::ShortcutOverride:
        event->accept();
    case QEvent::KeyRelease:
    case QEvent::Shortcut:
        return true;
    default:
        return QLineEdit::event(event);
    }
}
void LLPluginClassMedia::scrollEvent(int x, int y, MASK modifiers)
{
	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "scroll_event");

	message.setValueS32("x", x);
	message.setValueS32("y", y);
	message.setValue("modifiers", translateModifiers(modifiers));
	
	sendMessage(message);
}
bool LLPluginClassMedia::textInput(const std::string &text, MASK modifiers)
{
	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "text_event");

	message.setValue("text", text);
	message.setValue("modifiers", translateModifiers(modifiers));
	
	sendMessage(message);
	
	return true;
}
Example #6
0
/*
    \internal
    Matches the current intermediate key sequence + the latest
    keyevent, with and AccelItem. Returns Identical,
    PartialMatch or NoMatch, and fills \a temp with the
    resulting key sequence.
*/
Qt::SequenceMatch QAccelManager::match( QKeyEvent *e, QAccelItem* item, QKeySequence& temp )
{
    SequenceMatch result = Qt::NoMatch;
    int index = intermediate.count();
    temp = intermediate;

    int modifier = translateModifiers( e->state() );

    if ( e->key() && e->key() != Key_unknown) {
	int key = e->key()  | modifier;
	if ( e->key() == Key_BackTab ) {
	    /*
	    In QApplication, we map shift+tab to shift+backtab.
	    This code here reverts the mapping in a way that keeps
	    backtab and shift+tab accelerators working, in that
	    order, meaning backtab has priority.*/
	    key &= ~SHIFT;

	    temp.setKey( key, index );
	    if ( Qt::NoMatch != (result = temp.matches( item->key )) )
		return result;
	    if ( e->state() & ShiftButton )
		key |= SHIFT;
	    key = Key_Tab | ( key & MODIFIER_MASK );
	    temp.setKey( key, index );
	    if ( Qt::NoMatch != (result = temp.matches( item->key )) )
		return result;
	} else {
	    temp.setKey( key, index );
	    if ( Qt::NoMatch != (result = temp.matches( item->key )) )
		return result;
	}

	if ( key == Key_BackTab ) {
	    if ( e->state() & ShiftButton )
		key |= SHIFT;
	    temp.setKey( key, index );
	    if ( Qt::NoMatch != (result = temp.matches( item->key )) )
		return result;
	}
    }
    if ( !e->text().isEmpty() ) {
        QChar c = e->text()[0];
        // be in accordance with accoQAccel::shortcutKey()
        if ( modifier != 0 && c.isPrint() )
            c = c.upper();
	temp.setKey( (int)c.unicode() | UNICODE_ACCEL | modifier, index );
	result = temp.matches( item->key );
    }
    return result;
}
Example #7
0
void QWaylandInputDevice::inputHandleKey(void *data,
					 struct wl_input_device *input_device,
					 uint32_t time, uint32_t key, uint32_t state)
{
#ifndef QT_NO_WAYLAND_XKB
    Q_UNUSED(input_device);
    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
    QWaylandWindow *window = inputDevice->mKeyboardFocus;
    uint32_t code, sym, level;
    Qt::KeyboardModifiers modifiers;
    QEvent::Type type;
    char s[2];

    if (window == NULL) {
	/* We destroyed the keyboard focus surface, but the server
	 * didn't get the message yet. */
	return;
    }

    code = key + inputDevice->mXkb->min_key_code;

    level = 0;
    if (inputDevice->mModifiers & Qt::ShiftModifier &&
	XkbKeyGroupWidth(inputDevice->mXkb, code, 0) > 1)
	level = 1;

    sym = XkbKeySymEntry(inputDevice->mXkb, code, level, 0);

    modifiers = translateModifiers(inputDevice->mXkb->map->modmap[code]);

    if (state) {
	inputDevice->mModifiers |= modifiers;
	type = QEvent::KeyPress;
    } else {
	inputDevice->mModifiers &= ~modifiers;
	type = QEvent::KeyRelease;
    }

    sym = translateKey(sym, s, sizeof s);

    if (window) {
        QWindowSystemInterface::handleKeyEvent(window->widget(),
                                               time, type, sym,
                                               inputDevice->mModifiers,
                                               QString::fromLatin1(s));
    }
#endif
}
void LLPluginClassMedia::mouseEvent(EMouseEventType type, int button, int x, int y, MASK modifiers)
{
	if(type == MOUSE_EVENT_MOVE)
	{
		if(!mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked())
		{
			// Don't queue up mouse move events that can't be delivered.
			return;
		}

		if((x == mLastMouseX) && (y == mLastMouseY))
		{
			// Don't spam unnecessary mouse move events.
			return;
		}
		
		mLastMouseX = x;
		mLastMouseY = y;
	}
	
	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "mouse_event");
	std::string temp;
	switch(type)
	{
		case MOUSE_EVENT_DOWN:			temp = "down";			break;
		case MOUSE_EVENT_UP:			temp = "up";			break;
		case MOUSE_EVENT_MOVE:			temp = "move";			break;
		case MOUSE_EVENT_DOUBLE_CLICK:	temp = "double_click";	break;
	}
	message.setValue("event", temp);

	message.setValueS32("button", button);

	message.setValueS32("x", x);
	
	// Incoming coordinates are OpenGL-style ((0,0) = lower left), so flip them here if the plugin has requested it.
	if(!mRequestedTextureCoordsOpenGL)
	{
		// TODO: Should I use mMediaHeight or mRequestedMediaHeight here?
		y = mMediaHeight - y;
	}
	message.setValueS32("y", y);

	message.setValue("modifiers", translateModifiers(modifiers));
	
	sendMessage(message);
}
Example #9
0
	Key::Enum handleKeyEvent(const EmscriptenKeyboardEvent* event, uint8_t* specialKeys, uint8_t* _pressedChar)
	{
		*_pressedChar = (uint8_t)event->keyCode;

		int keyCode = (int)event->keyCode;
		*specialKeys = translateModifiers(event);

		if (event->charCode == 0)
		{
			switch (keyCode)
			{
				case 112:  return Key::F1;
				case 113:  return Key::F2;
				case 114:  return Key::F3;
				case 115:  return Key::F4;
				case 116:  return Key::F5;
				case 117:  return Key::F6;
				case 118:  return Key::F7;
				case 119:  return Key::F8;
				case 120:  return Key::F9;
				case 121:  return Key::F10;
				case 122:  return Key::F11;
				case 123:  return Key::F12;

				case 37:   return Key::Left;
				case 39:   return Key::Right;
				case 38:   return Key::Up;
				case 40:   return Key::Down;
			}
		}

		// if this is a unhandled key just return None
		if (keyCode < 256)
		{
			return (Key::Enum)s_translateKey[keyCode];
		}

		return Key::None;
	}
Example #10
0
bool RShortcutLineEdit::eventFilter(QObject *obj, QEvent *event) {
    if (event->type() == QEvent::KeyPress) {
        QKeyEvent *keyEvent = static_cast<QKeyEvent *> (event);
        int nextKey = keyEvent->key();
        if (m_keyNum > 3 || nextKey == Qt::Key_Control || nextKey
                == Qt::Key_Shift || nextKey == Qt::Key_Meta || nextKey
                == Qt::Key_Alt)
            return true;

        nextKey |= translateModifiers(keyEvent->modifiers(), keyEvent->text());
        switch (m_keyNum) {
        case 0:
            m_key[0] = nextKey;
            break;
        case 1:
            m_key[1] = nextKey;
            break;
        case 2:
            m_key[2] = nextKey;
            break;
        case 3:
            m_key[3] = nextKey;
            break;
        default:
            break;
        }
        m_keyNum++;
        QKeySequence ks(m_key[0], m_key[1], m_key[2], m_key[3]);
        setText(ks);
        keyEvent->accept();
        return true;
    } else {
        // standard event processing
        return QObject::eventFilter(obj, event);
    }
}
Example #11
0
/*
    \internal
    Checks for possible accelerators, if no widget
    ate the keypres, or we are in the middle of a
    partial key sequence.
*/
bool QAccelManager::dispatchAccelEvent( QWidget* w, QKeyEvent* e )
{
#ifndef QT_NO_STATUSBAR
    // Needs to be declared and used here because of "goto doclash"
    QStatusBar* mainStatusBar = 0;
#endif

    // Modifiers can NOT be accelerators...
    if ( e->key() >= Key_Shift &&
	 e->key() <= Key_Alt )
	 return FALSE;

    SequenceMatch result = Qt::NoMatch;
    QKeySequence tocheck, partial;
    QAccelPrivate* accel = 0;
    QAccelItem* item = 0;
    QAccelPrivate* firstaccel = 0;
    QAccelItem* firstitem = 0;
    QAccelPrivate* lastaccel = 0;
    QAccelItem* lastitem = 0;
    
    QKeyEvent pe = *e;
    int n = -1;
    int hasShift = (e->state()&Qt::ShiftButton)?1:0;
    bool identicalDisabled = FALSE;
    bool matchFound = FALSE;
    do {
	accel = accels.first();
	matchFound = FALSE;
	while ( accel ) {
	    if ( correctSubWindow( w, accel ) ) {
		if ( accel->enabled ) {
		    item = accel->aitems.last();
		    while( item ) {
			if ( Qt::Identical == (result = match( &pe, item, tocheck )) ) {
			    if ( item->enabled ) {
				if ( !firstaccel ) {
				    firstaccel = accel;
				    firstitem = item;
				}
				lastaccel = accel;
				lastitem = item;
				n++;
				matchFound = TRUE;
				if ( n > QMAX(clash,0) )
				    goto doclash;
			    } else {
				identicalDisabled = TRUE;
			    }
			}
			if ( item->enabled && Qt::PartialMatch == result ) {
			    partial = tocheck;
			    matchFound = TRUE;
			}
			item = accel->aitems.prev();
		    }
		} else {
		    item = accel->aitems.last();
		    while( item ) {
			if ( Qt::Identical == match( &pe, item, tocheck ) )
			    identicalDisabled = TRUE;
			item = accel->aitems.prev();
		    }
		}
	    }
	    accel = accels.next();
	}
	pe = QKeyEvent( QEvent::Accel, pe.key(), pe.ascii(), pe.state()&~Qt::ShiftButton, pe.text() );
    } while ( hasShift-- && !matchFound && !identicalDisabled );

#ifndef QT_NO_STATUSBAR
    mainStatusBar = (QStatusBar*) w->topLevelWidget()->child( 0, "QStatusBar" );
#endif
    if ( n < 0 ) { // no match found
	currentState = partial.count() ? PartialMatch : NoMatch;
#ifndef QT_NO_STATUSBAR
	// Only display message if we are, or were, in a partial match
	if ( mainStatusBar && (PartialMatch == currentState || intermediate.count() ) ) {
	    if ( currentState == Qt::PartialMatch ) {
		mainStatusBar->message( (QString)partial + ", ...", 0 );
	    } else if (!identicalDisabled) {
		QString message = QAccel::tr("%1, %2 not defined").
		    arg( (QString)intermediate ).
		    arg( QKeySequence::encodeString( e->key() | translateModifiers(e->state()) ) );
		mainStatusBar->message( message, 2000 );
		// Since we're a NoMatch, reset the clash count
		clash = -1;
	    } else {
	    	mainStatusBar->clear();
	    }
	}
#endif

	bool eatKey = (PartialMatch == currentState || intermediate.count() );
	intermediate = partial;
	if ( eatKey )
	    e->accept();
	return eatKey;
    } else if ( n == 0 ) { // found exactly one match
	clash = -1; // reset
#ifndef QT_NO_STATUSBAR
	if ( currentState == Qt::PartialMatch && mainStatusBar )
		mainStatusBar->clear();
#endif
	currentState = Qt::NoMatch; // Free sequence keylock
	intermediate = QKeySequence();
	lastaccel->activate( lastitem );
	e->accept();
	return TRUE;
    }

 doclash: // found more than one match
#ifndef QT_NO_STATUSBAR
    if ( !mainStatusBar ) // if "goto doclash", we need to get statusbar again.
	mainStatusBar = (QStatusBar*) w->topLevelWidget()->child( 0, "QStatusBar" );
#endif

    QString message = QAccel::tr( "Ambiguous \"%1\" not handled" ).arg( (QString)tocheck );
    if ( clash >= 0 && n > clash ) { // pick next  match
	intermediate = QKeySequence();
	currentState = Qt::NoMatch; // Free sequence keylock
	clash++;
#ifndef QT_NO_STATUSBAR
	if ( mainStatusBar &&
	     !lastitem->signal &&
	     !(lastaccel->parent->receivers( "activatedAmbiguously(int)" )) )
	    mainStatusBar->message( message, 2000 );
#endif
	lastaccel->activateAmbiguously( lastitem );
    } else { // start (or wrap) with the first matching
	intermediate = QKeySequence();
	currentState = Qt::NoMatch; // Free sequence keylock
	clash = 0;
#ifndef QT_NO_STATUSBAR
	if ( mainStatusBar &&
	     !firstitem->signal &&
	     !(firstaccel->parent->receivers( "activatedAmbiguously(int)" )) )
	    mainStatusBar->message( message, 2000 );
#endif
	firstaccel->activateAmbiguously( firstitem );
    }
    e->accept();
    return TRUE;
}
bool LLPluginClassMedia::keyEvent(EKeyEventType type, int key_code, MASK modifiers, LLSD native_key_data)
{
	bool result = true;
	
	// FIXME:
	// HACK: we don't have an easy way to tell if the plugin is going to handle a particular keycode.
	// For now, return false for the ones the webkit plugin won't handle properly.
	
	switch(key_code)
	{
		case KEY_BACKSPACE:		
		case KEY_TAB:			
		case KEY_RETURN:		
		case KEY_PAD_RETURN:	
		case KEY_SHIFT:			
		case KEY_CONTROL:		
		case KEY_ALT:			
		case KEY_CAPSLOCK:		
		case KEY_ESCAPE:		
		case KEY_PAGE_UP:		
		case KEY_PAGE_DOWN:		
		case KEY_END:			
		case KEY_HOME:			
		case KEY_LEFT:			
		case KEY_UP:			
		case KEY_RIGHT:			
		case KEY_DOWN:			
		case KEY_INSERT:		
		case KEY_DELETE:
			// These will be handled		
		break;
		
		default:
			// regular ASCII characters will also be handled
			if(key_code >= KEY_SPECIAL)
			{
				// Other "special" codes will not work properly.
				result = false;
			}
		break;
	}

#if LL_DARWIN	
	if(modifiers & MASK_ALT)
	{
		// Option-key modified characters should be handled by the unicode input path instead of this one.
		result = false;
	}
#endif

	if(result)
	{
		LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "key_event");
		std::string temp;
		switch(type)
		{
			case KEY_EVENT_DOWN:			temp = "down";			break;
			case KEY_EVENT_UP:				temp = "up";			break;
			case KEY_EVENT_REPEAT:			temp = "repeat";		break;
		}
		message.setValue("event", temp);
		
		message.setValueS32("key", key_code);

		message.setValue("modifiers", translateModifiers(modifiers));
		message.setValueLLSD("native_key_data", native_key_data);
		
		sendMessage(message);
	}
		
	return result;
}