Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / qt / 2009-01

is it possible to call private grabMouseWhileInWindow function?

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Paul Ishenin

Hello, Items specific to the Qt widget set

Qt mouse grab is very heavy. On windows it can grab input so that only ctrl+alt+del can unlock this grab. Qt installs windows hook which is imo a very big hack. LCL uses mouse grabs often and we dont need so heavy grabs since LCL can lock the whole system with them. At the same moment qt guys uses grabMouseWhileInWindow for their tasks. Can we publish this function in the bindings library then I will use it for windows-qt application.

Best regards,
Paul Ishenin.

Den Jean
to Paul Ishenin
Paul Ishenin wrote 7 lines
Qt mouse grab is very heavy. On windows it can grab input so that only ctrl+alt+del can unlock this grab. Qt installs windows hook which is imo a very big hack. LCL uses mouse grabs often and we dont need so heavy grabs since LCL can lock the whole system with them. At the same moment qt guys uses grabMouseWhileInWindow for their tasks. Can we publish this function in the bindings library then I will use it for windows-qt application.

grabMouseWhileInWindow is not only private, but also the implementation of grabMouseWhileInWindow writes in local private variables, that are used by grab/release mouse to check for existing grabs. If we would just write a grabMouseWhileInWindow (i.e. grab w/o hook), we cannot correctly update those local private variables. Other calls to grab/release would not work correctly.

The capture is windows call SetCapture,
the hook is windows call SetWindowsHookExA
the local variables are mouseGrb,mouseGrbCur,journalRec code from Qt:
./gui/kernel/qwidget_win.cpp

... local variables in qwidget_win.cpp

static QWidget *mouseGrb    = 0;
static QCursor *mouseGrbCur = 0;
static QWidget *keyboardGrb = 0;
static HHOOK   journalRec  = 0;

...
void QWidgetPrivate::grabMouseWhileInWindow()
{

    Q_Q(QWidget);
    if (!qt_nograb()) {
        if (mouseGrb)
            mouseGrb->releaseMouse();
        Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
        SetCapture(q->effectiveWinId());
        mouseGrb = q;

#ifndef QT_NO_CURSOR

        mouseGrbCur = new QCursor(mouseGrb->cursor());

#endif
}
}
...
#ifndef Q_OS_WINCE
void QWidget::grabMouse()
{
if (!qt_nograb()) {
if (mouseGrb)

            mouseGrb->releaseMouse();
        journalRec = SetWindowsHookExA(WH_JOURNALRECORD,

(HOOKPROC)qJournalRecordProc, GetModuleHandleA(0), 0);

        Q_ASSERT(testAttribute(Qt::WA_WState_Created));
        SetCapture(effectiveWinId());
        mouseGrb = this;
        mouseGrbCur = new QCursor(mouseGrb->cursor());
    }

}
void QWidget::releaseMouse()
{
if (!qt_nograb() && mouseGrb == this) {

        ReleaseCapture();
        if (journalRec) {
            UnhookWindowsHookEx(journalRec);
            journalRec = 0;
        }
        if (mouseGrbCur) {
            delete mouseGrbCur;
            mouseGrbCur = 0;
        }
        mouseGrb = 0;
    }

}
#endif
....

Den Jean
to Den Jean
Den Jean wrote
> Qt mouse grab is very heavy. On windows it can grab input so that only void QWidgetPrivate::grabMouseWhileInWindow()

...

Show quoted text 11 lines
{ Q_Q(QWidget); if (!qt_nograb()) { if (mouseGrb) mouseGrb->releaseMouse(); Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); SetCapture(q->effectiveWinId()); mouseGrb = q; #ifndef QT_NO_CURSOR mouseGrbCur = new QCursor(mouseGrb->cursor()); #endif

Note how qt_nograb() is used everywhere. Trolltech advise to launch apps with -nograb for debugging. For Lazarus launched LCL/Qt apps we could do this by default ? To ease debugging. Probably need the Qt debug libs.

./gui/kernel/qapplication_win.cpp:
...
#if defined(QT_DEBUG)
static bool appNoGrab = false; // mouse/keyboard grabbing #endif
...
bool qt_nograb() // application no-grab option {
#if defined(QT_DEBUG)

    return appNoGrab;

#else

    return false;

#endif
}
...
#if defined(QT_DEBUG)
if(arg == "-nograb")

                appNoGrab = !appNoGrab;
            else

#endif // QT_DEBUG

Paul Ishenin
to Den Jean
Den Jean wrote
Note how qt_nograb() is used everywhere. Trolltech advise to launch apps with -nograb for debugging. For Lazarus launched LCL/Qt apps we could do this by default ? To ease debugging. Probably need the Qt debug libs

Grab is needed, but windows Hook is not needed. Dont know how to overcome :)

Best regards,
Paul Ishenin.