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
    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
     532
     533
     534
     535
     536
     537
     538
     539
     540
     541
     542
     543
     544
     545
     546
     547
     548
     549
     550
     551
     552
     553
     554
     555
     556
     557
     558
     559
     560
     561
     562
     563
     564
     565
     566
     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
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
    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
    629741        return hmod;
    630742}
     
    633745CPMScreen::closeHookLibrary(HMODULE hmod) const
    634746{
     747
    635748        if (hmod != NULL) {
    636749                m_cleanup(m_hab);
Note: See TracChangeset for help on using the changeset viewer.