Ignore:
Timestamp:
Aug 13, 2006, 12:50:25 PM (19 years ago)
Author:
bird
Message:

Grr. HK_MSGINPUT / PM sucks. Got mouse working, but the hook code contains seriously bad hacks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/synergy/lib/platform/CPMScreen.cpp

    r2762 r2763  
    7171        assert(s_screen == NULL);
    7272        s_screen = this;
     73    LOG((CLOG_DEBUG1 "CPMScreen: isPrimary=%d", isPrimary));
    7374   
    7475    // create the event queue buffer first so we know there is a message queue.
     
    9394
    9495        try {
    95                 if (m_isPrimary)
    96                         m_hmodHook = openHookLibrary("synrgyhk");
     96                m_hmodHook = openHookLibrary("synrgyhk");
    9797                m_screensaver = new CPMScreenSaver();
    9898                m_keyState    = new CPMKeyState(getEventTarget());
     
    528528}
    529529
     530/**
     531 * Injects a fake input message.
     532 *
     533 * @param   msg     The message id.
     534 * @param   mp1     Message param 1.
     535 * @param   mp1     Message param 2.
     536 */
     537void
     538CPMScreen::fakeMessage(ULONG msg, MPARAM mp1, MPARAM mp2) const
     539{
     540    QMSG qmsg;
     541    qmsg.hwnd = NULLHANDLE;
     542    qmsg.msg = msg;
     543    qmsg.mp1 = mp1;
     544    qmsg.mp2 = mp2;
     545    qmsg.time = WinGetCurrentTime(m_hab);
     546    qmsg.ptl.x = 0;     ///@todo check the qmsg.ptl.
     547    qmsg.ptl.y = 0;
     548    qmsg.reserved = 0;
     549LOG((CLOG_DEBUG "fakeMessage: msg=%#lx mp1=%#lx mp2=%#lx...", msg, mp1, mp2));
     550    const char *pszError = m_fakeMsg(m_hab, &qmsg);
     551    if (pszError) {
     552        LOG((CLOG_CRIT "fakeMessage: msg=%#lx mp1=%#lx mp2=%#lx failed: %s", msg, mp1, mp2, pszError));
     553    }
     554else LOG((CLOG_DEBUG "fakeMessage: done"));
     555}
     556
     557/**
     558 * Injects a fake input message generating mp2.
     559 * @param   msg     The message id.
     560 * @param   mp1     The mouse coordinates.
     561 */
     562void
     563CPMScreen::fakeMouseMessage(ULONG msg, MPARAM mp1) const
     564{
     565    /* hittest stuff is taken care off.. dunno about KC_*. */
     566    fakeMessage(msg, mp1, 0);
     567}
     568
    530569void
    531570CPMScreen::fakeMouseButton(ButtonID id, bool press) const
    532571{
    533         //m_desks->fakeMouseButton(id, press);
     572    // determin the message.
     573    ULONG msg;
     574    switch (id) {
     575        case kButtonLeft:
     576            msg = press ? WM_BUTTON1DOWN : WM_BUTTON1UP;
     577            break;
     578        case kButtonRight:
     579            msg = press ? WM_BUTTON2DOWN : WM_BUTTON2UP;
     580            break;
     581        case kButtonMiddle:
     582            msg = press ? WM_BUTTON3DOWN : WM_BUTTON3UP;
     583            break;
     584        default:
     585            return;
     586    }
     587
     588    // mp1
     589    POINTL ptl;
     590    if (!WinQueryPointerPos(HWND_DESKTOP, &ptl)) {
     591        LOG((CLOG_CRIT "fakeMouseButton: failed %#lx", WinGetLastError(CPMUtil::getHAB())));
     592        ptl.x = m_xCenter;
     593        ptl.y = m_yCenter;
     594    }
     595
     596    // forge the message.
     597    fakeMouseMessage(msg, MPFROM2SHORT(ptl.x, ptl.y));
    534598}
    535599
     
    539603    LOG((CLOG_DEBUG "fakeMouseMove: %d,%d (y=%d)", x, m_cy - y, y));
    540604    if (WinSetPointerPos(HWND_DESKTOP, x, m_cy - y)) {
     605        // check x limits
     606        if (x > 0x7fff) x = 0x7fff;
     607        else if (x < -0x8000) x = -0x8000;
     608
     609        // wrap y and check the limits.
     610        y = m_cy - y;
     611        if (y > 0x7fff) y = 0x7fff;
     612        else if (y < -0x8000) y = -0x8000;
     613
     614        // forge the message.
     615        fakeMouseMessage(WM_MOUSEMOVE, MPFROM2SHORT(x, y));
    541616        return;
    542617    }
     
    550625    if (WinQueryPointerPos(HWND_DESKTOP, &ptl)) {
    551626        LOG((CLOG_DEBUG "fakeMouseRelativeMove: %d,%d (%d,%d +/- %d,%d)", ptl.x + dx, ptl.y - dy, ptl.y, ptl.x, dx, dy));
    552         if (WinSetPointerPos(HWND_DESKTOP, ptl.x + dx, ptl.y - dy)) {
    553             return;
     627        fakeMouseMove(ptl.x + dx, ptl.y - dy - m_cy);
     628        return;
     629    }
     630    LOG((CLOG_CRIT "fakeMouseRelativeMove: failed %#lx", WinGetLastError(CPMUtil::getHAB())));
     631}
     632
     633void
     634CPMScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const
     635{   
     636#if 0 /** @todo send scroll messages the the window beneath the cursor. */
     637    POINTL ptl;
     638    if (WinQueryPointerPos(HWND_DESKTOP, &ptl)) {
     639    }
     640#else
     641    /* dead simple arrow movement. */
     642    yDelta /= 30;
     643    while (yDelta != 0) {
     644        if (yDelta < 0) {
     645            yDelta++;
     646            fakeMessage(WM_CHAR, MPFROMSH2CH(KC_VIRTUALKEY | KC_SCANCODE, 1, 0x66), MPFROM2SHORT(0x50e0, VK_DOWN));
     647            fakeMessage(WM_CHAR, MPFROMSH2CH(KC_VIRTUALKEY | KC_SCANCODE | KC_KEYUP | KC_LONEKEY | KC_TOGGLE, 1, 0x66), MPFROM2SHORT(0x50e0, VK_DOWN));
     648        } else {
     649            yDelta--;
     650            fakeMessage(WM_CHAR, MPFROMSH2CH(KC_VIRTUALKEY | KC_SCANCODE, 1, 0x61), MPFROM2SHORT(0x48e0, VK_UP));
     651            fakeMessage(WM_CHAR, MPFROMSH2CH(KC_VIRTUALKEY | KC_SCANCODE | KC_KEYUP | KC_LONEKEY | KC_TOGGLE, 1, 0x61), MPFROM2SHORT(0x48e0, VK_UP));
    554652        }
    555653    }
    556     LOG((CLOG_CRIT "fakeMouseRelativeMove: failed %#lx", WinGetLastError(CPMUtil::getHAB())));
    557 }
    558 
    559 void
    560 CPMScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const
    561 {
    562         //m_desks->fakeMouseWheel(xDelta, yDelta);
     654#endif
    563655}
    564656
     
    602694CPMScreen::openHookLibrary(const char* name)
    603695{
    604         // load the hook library
    605         HMODULE hmod;
    606         APIRET rc = DosLoadModule(NULL, 0, (PCSZ)name, &hmod);
     696        // load the hook library - try with qualified name first.
     697        HMODULE hmod = NULLHANDLE;
     698    APIRET rc = ERROR_FILE_NOT_FOUND;
     699    char szFullName[CCHMAXPATH + 10];
     700    if (!_execname(szFullName, CCHMAXPATH)) {
     701        char *psz = strrchr(szFullName, '\\');
     702        if (!psz || strrchr(psz, '/')) {
     703            psz = strrchr(psz, '/');
     704        }
     705        if (psz) {
     706            strcat(strcpy(psz + 1, name), ".DLL");
     707        }
     708            rc = DosLoadModule(NULL, 0, (PCSZ)szFullName, &hmod);
     709    }
     710
     711    // if that failed, try with the bare name.
     712    if (rc != NO_ERROR) {
     713            rc = DosLoadModule(NULL, 0, (PCSZ)name, &hmod);
     714    } else {
     715        name = szFullName;
     716    }
    607717        if (rc != NO_ERROR) {
    608718                LOG((CLOG_ERR "Failed to load hook library (%s), rc=%d ", name, rc));
     
    611721
    612722        // look up functions
    613         if (    (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_setSides",      (PPFN)&m_setSides)) != NO_ERROR
     723        if (    (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_fakeMsg",       (PPFN)&m_fakeMsg )) != NO_ERROR
     724        ||      (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_setSides",      (PPFN)&m_setSides)) != NO_ERROR
    614725                ||      (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_setZone",       (PPFN)&m_setZone )) != NO_ERROR
    615726                ||      (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_setMode",       (PPFN)&m_setMode )) != NO_ERROR
     
    627738                throw XScreenOpenFailure();
    628739        }
     740    LOG((CLOG_DEBUG1 "openHookLibrary: hmod=%#lx '%s'", hmod, name));
    629741        return hmod;
    630742}
     
    633745CPMScreen::closeHookLibrary(HMODULE hmod) const
    634746{
     747    LOG((CLOG_DEBUG1 "closeHookLibrary: hmod=%#lx\n", hmod));
    635748        if (hmod != NULL) {
    636749                m_cleanup(m_hab);
Note: See TracChangeset for help on using the changeset viewer.