Ejemplo n.º 1
0
void QWaylandWindow::handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
{
    if (mWindowDecoration->handleMouse(inputDevice,local,global,b,mods))
        return;

    QMargins marg = frameMargins();
    QRect windowRect(0 + marg.left(),
                     0 + marg.top(),
                     geometry().size().width() - marg.right(),
                     geometry().size().height() - marg.bottom());
    if (windowRect.contains(local.toPoint()) || mMousePressedInContentArea != Qt::NoButton) {
        QPointF localTranslated = local;
        QPointF globalTranslated = global;
        localTranslated.setX(localTranslated.x() - marg.left());
        localTranslated.setY(localTranslated.y() - marg.top());
        globalTranslated.setX(globalTranslated.x() - marg.left());
        globalTranslated.setY(globalTranslated.y() - marg.top());
        if (!mMouseEventsInContentArea) {
            restoreMouseCursor(inputDevice);
            QWindowSystemInterface::handleEnterEvent(window());
        }
        QWindowSystemInterface::handleMouseEvent(window(), timestamp, localTranslated, globalTranslated, b, mods);
        mMouseEventsInContentArea = true;
        mMousePressedInContentArea = b;
    } else {
        if (mMouseEventsInContentArea) {
            QWindowSystemInterface::handleLeaveEvent(window());
            mMouseEventsInContentArea = false;
        }
        mWindowDecoration->handleMouse(inputDevice,local,global,b,mods);
    }
}
Ejemplo n.º 2
0
void X11Window::setMouseCursor(const std::string& file, const Point& hotSpot)
{
    std::stringstream fin;
    g_resources.loadFile(file, fin);

    apng_data apng;
    if(load_apng(fin, &apng) != 0) {
        g_logger.traceError(stdext::format("unable to load png file %s", file));
        return;
    }

    if(apng.bpp != 4) {
        g_logger.error("the cursor png must have 4 channels");
        free_apng(&apng);
        return;
    }

    if(apng.width != 32|| apng.height != 32) {
        g_logger.error("the cursor png must have 32x32 dimension");
        free_apng(&apng);
        return;
    }

    if(m_cursor != None)
        restoreMouseCursor();

    int width = apng.width;
    int height = apng.height;
    int numbits = width * height;
    int numbytes = (width * height)/8;

    XColor bg, fg;
    bg.red   = 255 << 8;
    bg.green = 255 << 8;
    bg.blue  = 255 << 8;
    fg.red   = 0;
    fg.green = 0;
    fg.blue  = 0;

    std::vector<uchar> mapBits(numbytes, 0);
    std::vector<uchar> maskBits(numbytes, 0);

    for(int i=0;i<numbits;++i) {
        uint32 rgba = stdext::readLE32(apng.pdata + i*4);
        if(rgba == 0xffffffff) { //white, background
            LSB_BIT_SET(maskBits, i);
        } else if(rgba == 0xff000000) { //black, foreground
            LSB_BIT_SET(mapBits, i);
            LSB_BIT_SET(maskBits, i);
        } //otherwise 0x00000000 => alpha
    }
    free_apng(&apng);

    Pixmap cp = XCreateBitmapFromData(m_display, m_window, (char*)&mapBits[0], width, height);
    Pixmap mp = XCreateBitmapFromData(m_display, m_window, (char*)&maskBits[0], width, height);
    m_cursor = XCreatePixmapCursor(m_display, cp, mp, &fg, &bg, hotSpot.x, hotSpot.y);
    XDefineCursor(m_display, m_window, m_cursor);
    XFreePixmap(m_display, cp);
    XFreePixmap(m_display, mp);
}
Ejemplo n.º 3
0
void QWaylandWindow::handleMouseEnter(QWaylandInputDevice *inputDevice)
{
    if (!mWindowDecoration) {
        QWindowSystemInterface::handleEnterEvent(window());
    }
    restoreMouseCursor(inputDevice);
}
Ejemplo n.º 4
0
void X11Window::setMouseCursor(int cursorId)
{
    if(cursorId >= (int)m_cursors.size() || cursorId < 0)
        return;

    if(m_cursor != None)
        restoreMouseCursor();

    m_cursor = m_cursors[cursorId];
    XDefineCursor(m_display, m_window, m_cursor);
}
Ejemplo n.º 5
0
void QWaylandWindow::handleMouseLeave(QWaylandInputDevice *inputDevice)
{
    if (mWindowDecoration) {
        if (mMouseEventsInContentArea) {
            QWindowSystemInterface::handleLeaveEvent(window());
        }
    } else {
        QWindowSystemInterface::handleLeaveEvent(window());
    }
    restoreMouseCursor(inputDevice);
}
Ejemplo n.º 6
0
void X11Window::hideMouse()
{
    if(m_cursor != None)
        restoreMouseCursor();

    char bm[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    Pixmap pix = XCreateBitmapFromData(m_display, m_window, bm, 8, 8);
    XColor black;
    memset(&black, 0, sizeof(black));
    black.flags = DoRed | DoGreen | DoBlue;
    m_cursor = XCreatePixmapCursor(m_display, pix, pix, &black, &black, 0, 0);
    XFreePixmap(m_display, pix);
    XDefineCursor(m_display, m_window, m_cursor);
}
Ejemplo n.º 7
0
void QWaylandWindow::handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e)
{
    if (mMousePressedInContentArea == Qt::NoButton &&
        mWindowDecoration->handleMouse(inputDevice, e.local, e.global, e.buttons, e.modifiers)) {
        if (mMouseEventsInContentArea)
            QWindowSystemInterface::handleLeaveEvent(window());
        return;
    }

    QMargins marg = frameMargins();
    QRect windowRect(0 + marg.left(),
                     0 + marg.top(),
                     geometry().size().width() - marg.right(),
                     geometry().size().height() - marg.bottom());
    if (windowRect.contains(e.local.toPoint()) || mMousePressedInContentArea != Qt::NoButton) {
        QPointF localTranslated = e.local;
        QPointF globalTranslated = e.global;
        localTranslated.setX(localTranslated.x() - marg.left());
        localTranslated.setY(localTranslated.y() - marg.top());
        globalTranslated.setX(globalTranslated.x() - marg.left());
        globalTranslated.setY(globalTranslated.y() - marg.top());
        if (!mMouseEventsInContentArea) {
            restoreMouseCursor(inputDevice);
            QWindowSystemInterface::handleEnterEvent(window());
        }

        switch (e.type) {
            case QWaylandPointerEvent::Enter:
                QWindowSystemInterface::handleEnterEvent(window(), localTranslated, globalTranslated);
                break;
            case QWaylandPointerEvent::Motion:
                QWindowSystemInterface::handleMouseEvent(window(), e.timestamp, localTranslated, globalTranslated, e.buttons, e.modifiers);
                break;
            case QWaylandPointerEvent::Wheel:
                QWindowSystemInterface::handleWheelEvent(window(), e.timestamp, localTranslated, globalTranslated, e.pixelDelta, e.angleDelta);
                break;
        }

        mMouseEventsInContentArea = true;
        mMousePressedInContentArea = e.buttons;
    } else {
        if (mMouseEventsInContentArea) {
            QWindowSystemInterface::handleLeaveEvent(window());
            mMouseEventsInContentArea = false;
        }
    }
}
Ejemplo n.º 8
0
void QWaylandWindow::handleMouse(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e)
{

    if (mWindowDecoration) {
        handleMouseEventWithDecoration(inputDevice, e);
    } else {
        switch (e.type) {
            case QWaylandPointerEvent::Enter:
                QWindowSystemInterface::handleEnterEvent(window(), e.local, e.global);
                break;
            case QWaylandPointerEvent::Motion:
                QWindowSystemInterface::handleMouseEvent(window(), e.timestamp, e.local, e.global, e.buttons, e.modifiers);
                break;
        }
    }

    if (e.type == QWaylandPointerEvent::Enter)
        restoreMouseCursor(inputDevice);
}
Ejemplo n.º 9
0
void X11Window::showMouse()
{
    restoreMouseCursor();
}