Ignore:
Timestamp:
Jul 31, 2006, 5:21:38 AM (19 years ago)
Author:
bird
Message:

bedtime

File:
1 edited

Legend:

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

    r2754 r2755  
    3434#include "CPMUtil.h"
    3535#include <string.h>
     36#include <unistd.h>
    3637
    3738//
     
    4445        m_isPrimary(isPrimary),
    4546        m_isOnScreen(m_isPrimary),
    46         m_class(0),
    4747        m_x(0), m_y(0),
    4848        m_cx(0), m_cy(0),
     
    5353        m_mark(0),
    5454        m_markReceived(0),
    55         m_fixTimer(NULL),
    5655        m_screensaver(NULL),
    5756        m_screensaverNotify(false),
     
    7372
    7473        s_screen = this;
     74
     75        // query curren thread bits.
     76        m_threadID = _gettid();
     77        m_hab = WinQueryAnchorBlock(HWND_DESKTOP);
     78        m_hmq = WinQueueFromID(m_hab, getpid(), _gettid());
     79        if (m_hab == NULLHANDLE || m_hmq == NULLHANDLE) {
     80                LOG((CLOG_CRIT "couldn't get the hab/hmq of the current thread!\n"));
     81                throw XScreenOpenFailure();
     82        }
     83
    7584        try {
    76                 if (m_isPrimary) {
     85                if (m_isPrimary)
    7786                        m_hmodHook = openHookLibrary("synrgyhk");
    78                 }
    7987                m_screensaver = new CPMScreenSaver();
    8088                m_keyState    = new CPMKeyState(getEventTarget());
    8189                updateScreenShape();
    82                 m_class       = createWindowClass();
    83                 m_window      = createWindow(m_class, "Synergy");
     90                m_window      = createWindow("Synergy");
    8491                forceShowCursor();
    8592                LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_cx, m_cy, m_multimon ? "(multi-monitor)" : ""));
    8693                LOG((CLOG_DEBUG "window is 0x%08x", m_window));
    87         }
    88         catch (...) {
     94        } catch (...) {
    8995                delete m_keyState;
    9096                delete m_screensaver;
    9197                destroyWindow(m_window);
    92                 destroyClass(m_class);
    9398                closeHookLibrary(m_hmodHook);
    9499                s_screen = NULL;
     
    98103        // install event handlers
    99104        EVENTQUEUE->adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(),
    100                                                         new TMethodEventJob<CPMScreen>(this,
    101                                                                 &CPMScreen::handleSystemEvent));
     105                                                        new TMethodEventJob<CPMScreen>(this, &CPMScreen::handleSystemEvent));
    102106
    103107        // install the platform event queue
     
    115119        delete m_screensaver;
    116120        destroyWindow(m_window);
    117         destroyClass(m_class);
    118121        closeHookLibrary(m_hmodHook);
    119122        s_screen = NULL;
     
    124127{
    125128        assert(m_isOnScreen == m_isPrimary);
    126 
    127         // we need to poll some things to fix them
    128         m_fixTimer = EVENTQUEUE->newTimer(1.0, NULL);
    129         EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
    130                                                          new TMethodEventJob<CPMScreen>(this, &CPMScreen::handleFixes));
    131129
    132130        // install our clipboard snooper
     
    135133    WinSetClipbrdViewer(hab, m_window);
    136134
    137 /// @todo start here!
    138         // track the active desk and (re)install the hooks
    139         m_desks->enable();
    140 
    141135        if (m_isPrimary) {
    142136                // set jump zones
     
    151145CPMScreen::disable()
    152146{
    153         // stop tracking the active desk
    154         m_desks->disable();
    155 
    156147        if (m_isPrimary) {
    157148                // disable hooks
     
    166157        m_nextClipboardWindow = NULL;
    167158
    168         // uninstall fix timer
    169         if (m_fixTimer != NULL) {
    170                 EVENTQUEUE->removeHandler(CEvent::kTimer, m_fixTimer);
    171                 EVENTQUEUE->deleteTimer(m_fixTimer);
    172                 m_fixTimer = NULL;
    173         }
    174 
    175159        m_isOnScreen = m_isPrimary;
    176160        forceShowCursor();
     
    180164CPMScreen::enter()
    181165{
    182         m_desks->enter();
     166        // show the pointer (?), hide the synergy window and restore focus.
     167        WinShowPointer(HWND_DESKTOP, TRUE);
     168        WinSetWindowPos(m_window, HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDE);
     169        //?? WinSetFocus(
     170        //?? WinEnableWindow
     171
    183172        if (m_isPrimary) {
    184173                // watch jump zones
     
    197186CPMScreen::leave()
    198187{
     188        /// @todo save focus window.
     189
    199190        if (m_isPrimary) {
    200191                // warp to center
     
    252243{
    253244        m_screensaverNotify = notify;
    254         if (!m_screensaverNotify) {
     245        if (!m_screensaverNotify)
    255246                m_screensaver->disable();
    256         }
    257247}
    258248
     
    260250CPMScreen::closeScreensaver()
    261251{
    262         if (!m_screensaverNotify) {
     252        if (!m_screensaverNotify)
    263253                m_screensaver->enable();
    264         }
    265254}
    266255
     
    268257CPMScreen::screensaver(bool activate)
    269258{
    270     if (activate) {
     259    if (activate)
    271260        m_screensaver->activate();
    272     }
    273     else {
     261    else
    274262        m_screensaver->deactivate();
    275     }
    276263}
    277264
     
    321308CPMScreen::getShape(SInt32& x, SInt32& y, SInt32& cx, SInt32& cy) const
    322309{
    323         assert(m_class != 0);
    324 
    325310        x = m_x;
    326311        y = m_y;
     
    356341        // remove all input events before and including warp
    357342        QMSG qmsg;
    358         while (WinPeekMsg(m_hab, &qmsg, NULLHANDLE, SYNERGY_MSG_INPUT_FIRST, SYNERGY_MSG_INPUT_LAST, PM_REMOVE)) {
     343        while (WinPeekMsg(m_hab, &qmsg, NULLHANDLE, SYNERGY_PM_MSG_INPUT_FIRST, SYNERGY_PM_MSG_INPUT_LAST, PM_REMOVE)) {
    359344                // do nothing
    360345        }
     
    483468                m_keyState->useSavedModifiers(true);
    484469        }
    485         m_desks->fakeInputBegin();
     470        //m_desks->fakeInputBegin();
    486471}
    487472
     
    491476        assert(m_isPrimary);
    492477
    493         m_desks->fakeInputEnd();
     478        //m_desks->fakeInputEnd();
    494479        if (!m_isOnScreen) {
    495480                m_keyState->useSavedModifiers(false);
     
    535520CPMScreen::fakeMouseButton(ButtonID id, bool press) const
    536521{
    537         m_desks->fakeMouseButton(id, press);
     522        //m_desks->fakeMouseButton(id, press);
    538523}
    539524
     
    541526CPMScreen::fakeMouseMove(SInt32 x, SInt32 y) const
    542527{
    543         m_desks->fakeMouseMove(x, y);
     528        //m_desks->fakeMouseMove(x, y);
    544529}
    545530
     
    547532CPMScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
    548533{
    549         m_desks->fakeMouseRelativeMove(dx, dy);
     534        //m_desks->fakeMouseRelativeMove(dx, dy);
    550535}
    551536
     
    553538CPMScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const
    554539{
    555         m_desks->fakeMouseWheel(xDelta, yDelta);
     540        //m_desks->fakeMouseWheel(xDelta, yDelta);
    556541}
    557542
     
    559544CPMScreen::updateKeys()
    560545{
    561         m_desks->updateKeys();
     546        //m_desks->updateKeys();
    562547}
    563548
     
    592577}
    593578
    594 HINSTANCE
     579HMODULE
    595580CPMScreen::openHookLibrary(const char* name)
    596581{
    597582        // load the hook library
    598         HINSTANCE hookLibrary = LoadLibrary(name);
    599         if (hookLibrary == NULL) {
    600                 LOG((CLOG_ERR "Failed to load hook library;  %s.dll is missing", name));
     583        HMODULE hmod;
     584        APIRET rc = DosLoadModule(NULL, 0, (PCSZ)name, &hmod);
     585        if (rc != NO_ERROR) {
     586                LOG((CLOG_ERR "Failed to load hook library (%s), rc=%d ", name, rc));
    601587                throw XScreenOpenFailure();
    602588        }
    603589
    604590        // look up functions
    605         m_setSides  = (SetSidesFunc)GetProcAddress(hookLibrary, "setSides");
    606         m_setZone   = (SetZoneFunc)GetProcAddress(hookLibrary, "setZone");
    607         m_setMode   = (SetModeFunc)GetProcAddress(hookLibrary, "setMode");
    608         m_init      = (InitFunc)GetProcAddress(hookLibrary, "init");
    609         m_cleanup   = (CleanupFunc)GetProcAddress(hookLibrary, "cleanup");
    610         if (m_setSides             == NULL ||
    611                 m_setZone              == NULL ||
    612                 m_setMode              == NULL ||
    613                 m_init                 == NULL ||
    614                 m_cleanup              == NULL) {
    615                 LOG((CLOG_ERR "Invalid hook library;  use a newer %s.dll", name));
     591        if (    (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_setSides",      (PPFN)&m_setSides)) != NO_ERROR
     592                ||      (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_setZone",       (PPFN)&m_setZone )) != NO_ERROR
     593                ||      (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_setMode",       (PPFN)&m_setMode )) != NO_ERROR
     594                ||      (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_init",          (PPFN)&m_init    )) != NO_ERROR
     595                ||      (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_cleanup",       (PPFN)&m_cleanup )) != NO_ERROR) {
     596                LOG((CLOG_ERR "Invalid hook library;  use a newer %s.dll (rc=%d)", name, rc));
     597                DosFreeModule(hmod);
    616598                throw XScreenOpenFailure();
    617599        }
    618600
    619601        // initialize hook library
    620         if (m_init(GetCurrentThreadId()) == 0) {
    621                 LOG((CLOG_ERR "Cannot initialize hook library;  is synergy already running?"));
     602        if (m_init(m_hmq, _gettid(), getpid()) == 0) {
     603                LOG((CLOG_ERR "Cannot initialize hook library; is synergy already running?"));
     604                DosFreeModule(hmod);
    622605                throw XScreenOpenFailure();
    623606        }
    624 
    625         return hookLibrary;
    626 }
    627 
    628 void
    629 CPMScreen::closeHookLibrary(HINSTANCE hookLibrary) const
    630 {
    631         if (hookLibrary != NULL) {
    632                 m_cleanup();
    633                 FreeLibrary(hookLibrary);
    634         }
    635 }
    636 
    637 ATOM
    638 CPMScreen::createWindowClass() const
    639 {
    640         WNDCLASSEX classInfo;
    641         classInfo.cbSize        = sizeof(classInfo);
    642         classInfo.style         = CS_DBLCLKS | CS_NOCLOSE;
    643         classInfo.lpfnWndProc   = &CPMScreen::wndProc;
    644         classInfo.cbClsExtra    = 0;
    645         classInfo.cbWndExtra    = 0;
    646         classInfo.hInstance     = s_instance;
    647         classInfo.hIcon         = NULL;
    648         classInfo.hCursor       = NULL;
    649         classInfo.hbrBackground = NULL;
    650         classInfo.lpszMenuName  = NULL;
    651         classInfo.lpszClassName = "Synergy";
    652         classInfo.hIconSm       = NULL;
    653         return RegisterClassEx(&classInfo);
    654 }
    655 
    656 void
    657 CPMScreen::destroyClass(ATOM windowClass) const
    658 {
    659         if (windowClass != 0) {
    660                 UnregisterClass(reinterpret_cast<LPCTSTR>(windowClass), s_instance);
     607        return hmod;
     608}
     609
     610void
     611CPMScreen::closeHookLibrary(HMODULE hmod) const
     612{
     613        if (hmod != NULL) {
     614                m_cleanup(m_hab);
     615                DosFreeModule(hmod);
    661616        }
    662617}
    663618
    664619HWND
    665 CPMScreen::createWindow(ATOM windowClass, const char* name) const
    666 {
    667         HWND window = CreateWindowEx(WS_EX_TOPMOST |
    668                                                                         WS_EX_TRANSPARENT |
    669                                                                         WS_EX_TOOLWINDOW,
    670                                                                 reinterpret_cast<LPCTSTR>(windowClass),
    671                                                                 name,
    672                                                                 WS_POPUP,
     620CPMScreen::createWindow(const char* name)
     621{
     622        WinRegisterClass(m_hab, (PCSZ)"Synergy", CPMScreen::wndProc, CS_MOVENOTIFY, sizeof(uintptr_t));
     623        HWND hwnd = WinCreateWindow(HWND_DESKTOP,
     624                                                                (PCSZ)"Synergy",
     625                                                                NULL,
     626                                                                0, //WS_?,
    673627                                                                0, 0, 1, 1,
    674                                                                 NULL, NULL,
    675                                                                 s_instance,
     628                                                                HWND_DESKTOP,
     629                                                                NULLHANDLE,
     630                                                                0,
     631                                                                this,
    676632                                                                NULL);
    677         if (window == NULL) {
    678                 LOG((CLOG_ERR "failed to create window: %d", GetLastError()));
     633        if (hwnd == NULLHANDLE) {
     634                LOG((CLOG_ERR "failed to create window: %ld", WinGetLastError(m_hab)));
    679635                throw XScreenOpenFailure();
    680636        }
    681         return window;
     637        return hwnd;
    682638}
    683639
     
    686642{
    687643        if (hwnd != NULL) {
    688                 DestroyWindow(hwnd);
     644                WinDestroyWindow(hwnd);
    689645        }
    690646}
     
    708664CPMScreen::handleSystemEvent(const CEvent& event, void*)
    709665{
    710         MSG* msg = reinterpret_cast<MSG*>(event.getData());
    711         assert(msg != NULL);
    712 
    713         if (CArchMiscWindows::processDialog(msg)) {
     666        PQMSG pqmsg = (PQMSG)event.getData();
     667        assert(pqmsg != NULL);
     668        if (onPreDispatch(pqmsg->hwnd, pqmsg->msg, pqmsg->mp1, pqmsg->mp2))
    714669                return;
    715         }
    716         if (onPreDispatch(msg->hwnd, msg->message, msg->wParam, msg->lParam)) {
    717                 return;
    718         }
    719         TranslateMessage(msg);
    720         DispatchMessage(msg);
     670        WinDispatchMsg(CPMUtil::getHAB(), pqmsg);
    721671}
    722672
     
    724674CPMScreen::updateButtons()
    725675{
    726         int numButtons               = GetSystemMetrics(SM_CMOUSEBUTTONS);
    727676        m_buttons[kButtonNone]       = false;
    728         m_buttons[kButtonLeft]       = (GetKeyState(VK_LBUTTON)  < 0);
    729         m_buttons[kButtonRight]      = (GetKeyState(VK_RBUTTON)  < 0);
    730         m_buttons[kButtonMiddle]     = (GetKeyState(VK_MBUTTON)  < 0);
    731         m_buttons[kButtonExtra0 + 0] = (numButtons >= 4) &&
    732                                                                    (GetKeyState(VK_XBUTTON1) < 0);
    733         m_buttons[kButtonExtra0 + 1] = (numButtons >= 5) &&
    734                                                                    (GetKeyState(VK_XBUTTON2) < 0);
     677        m_buttons[kButtonLeft]       = (WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000) != 0;
     678        m_buttons[kButtonRight]      = (WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000) != 0;
     679        m_buttons[kButtonMiddle]     = (WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000) != 0;
     680        m_buttons[kButtonExtra0 + 0] = false;
     681        m_buttons[kButtonExtra0 + 1] = false;
    735682}
    736683
     
    742689
    743690bool
    744 CPMScreen::onPreDispatch(HWND hwnd,
    745                                 UINT message, WPARAM wParam, LPARAM lParam)
     691CPMScreen::onPreDispatch(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
    746692{
    747693        // handle event
    748         switch (message) {
    749         case SYNERGY_MSG_SCREEN_SAVER:
    750                 return onScreensaver(wParam != 0);
    751 
    752         case SYNERGY_MSG_DEBUG:
    753                 LOG((CLOG_DEBUG1 "hook: 0x%08x 0x%08x", wParam, lParam));
     694        switch (msg) {
     695        case SYNERGY_PM_MSG_DEBUG:
     696                LOG((CLOG_DEBUG1 "hook: 0x%08x 0x%08x", mp1, mp2));
    754697                return true;
    755698        }
    756699
    757700        if (m_isPrimary) {
    758                 return onPreDispatchPrimary(hwnd, message, wParam, lParam);
     701                return onPreDispatchPrimary(hwnd, msg, mp1, mp2);
    759702        }
    760703
     
    763706
    764707bool
    765 CPMScreen::onPreDispatchPrimary(HWND,
    766                                 UINT message, WPARAM wParam, LPARAM lParam)
     708CPMScreen::onPreDispatchPrimary(HWND, ULONG msg, MPARAM mp1, MPARAM mp2)
    767709{
    768710        // handle event
    769         switch (message) {
    770         case SYNERGY_MSG_MARK:
    771                 return onMark(static_cast<UInt32>(wParam));
    772 
    773         case SYNERGY_MSG_KEY:
    774                 return onKey(wParam, lParam);
    775 
    776         case SYNERGY_MSG_MOUSE_BUTTON:
    777                 return onMouseButton(wParam, lParam);
    778 
    779         case SYNERGY_MSG_MOUSE_MOVE:
    780                 return onMouseMove(static_cast<SInt32>(wParam),
    781                                                         static_cast<SInt32>(lParam));
    782 
    783         case SYNERGY_MSG_MOUSE_WHEEL:
    784                 // XXX -- support x-axis scrolling
    785                 return onMouseWheel(0, static_cast<SInt32>(wParam));
    786 
    787         case SYNERGY_MSG_PRE_WARP:
     711        switch (msg) {
     712        case SYNERGY_PM_MSG_MARK:
     713                return onMark((uintptr_t)mp1);
     714
     715        case SYNERGY_PM_MSG_KEY:
     716                return onKey(SHORT1FROMMP(mp1), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
     717
     718        case SYNERGY_PM_MSG_MOUSE_BUTTON:
     719                return onMouseButton(SHORT1FROMMP(mp1), (SHORT)SHORT1FROMMP(mp2), m_cy - (SHORT)SHORT2FROMMP(mp2));
     720
     721        case SYNERGY_PM_MSG_MOUSE_MOVE:
     722                return onMouseMove(SHORT1FROMMP(mp1), (SHORT)SHORT1FROMMP(mp2), m_cy - (SHORT)SHORT2FROMMP(mp2));
     723
     724        case SYNERGY_PM_MSG_PRE_WARP:
    788725                {
    789                         // save position to compute delta of next motion
    790                         m_xCursor = static_cast<SInt32>(wParam);
    791                         m_yCursor = static_cast<SInt32>(lParam);
    792 
    793                         // we warped the mouse.  discard events until we find the
    794                         // matching post warp event.  see warpCursorNoFlush() for
    795                         // where the events are sent.  we discard the matching
     726                        // Save position to compute delta of next motion
     727                        m_xCursor = (SInt32)mp1;
     728                        m_yCursor = (SInt32)mp2;
     729
     730                        // We warped the mouse. Discard events until we find the
     731                        // matching post warp event. See warpCursorNoFlush() for
     732                        // where the events are sent. We discard the matching
    796733                        // post warp event and can be sure we've skipped the warp
    797734                        // event.
    798                         MSG msg;
    799                         do {
    800                                 GetMessage(&msg, NULL, SYNERGY_MSG_MOUSE_MOVE,
    801                                                                                 SYNERGY_MSG_POST_WARP);
    802                         } while (msg.message != SYNERGY_MSG_POST_WARP);
     735                        QMSG qmsg;
     736                        while (   WinGetMsg(m_hab, &qmsg, NULLHANDLE, SYNERGY_PM_MSG_MOUSE_MOVE, SYNERGY_PM_MSG_POST_WARP)
     737                                   && qmsg.msg != SYNERGY_PM_MSG_POST_WARP)
     738                                /* nothing */;
    803739                }
    804740                return true;
    805741
    806         case SYNERGY_MSG_POST_WARP:
     742        case SYNERGY_PM_MSG_POST_WARP:
    807743                LOG((CLOG_WARN "unmatched post warp"));
    808744                return true;
    809 
    810         case WM_HOTKEY:
    811                 // we discard these messages.  we'll catch the hot key in the
    812                 // regular key event handling, where we can detect both key
    813                 // press and release.  we only register the hot key so no other
    814                 // app will act on the key combination.
    815                 break;
    816745        }
    817746
     
    820749
    821750bool
    822 CPMScreen::onEvent(HWND, UINT msg,
    823                                 WPARAM wParam, LPARAM lParam, LRESULT* result)
     751CPMScreen::onEvent(HWND, ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT *result)
    824752{
    825753        switch (msg) {
    826         case WM_QUERYENDSESSION:
    827                 if (m_is95Family) {
    828                         *result = TRUE;
    829                         return true;
    830                 }
    831                 break;
    832 
    833         case WM_ENDSESSION:
    834                 if (m_is95Family) {
    835                         if (wParam == TRUE && lParam == 0) {
    836                                 EVENTQUEUE->addEvent(CEvent(CEvent::kQuit));
    837                         }
    838                         return true;
    839                 }
    840                 break;
    841 
    842754        case WM_DRAWCLIPBOARD:
    843                 // first pass on the message
    844                 if (m_nextClipboardWindow != NULL) {
    845                         SendMessage(m_nextClipboardWindow, msg, wParam, lParam);
    846                 }
     755                //// first pass on the message
     756                //if (m_nextClipboardWindow != NULL) {
     757                //      WinSendMessage(m_nextClipboardWindow, msg, mp1, mp2);
     758                //}
    847759
    848760                // now handle the message
    849761                return onClipboardChange();
    850 
    851         case WM_CHANGECBCHAIN:
    852                 if (m_nextClipboardWindow == (HWND)wParam) {
    853                         m_nextClipboardWindow = (HWND)lParam;
    854                         LOG((CLOG_DEBUG "clipboard chain: new next: 0x%08x", m_nextClipboardWindow));
    855                 }
    856                 else if (m_nextClipboardWindow != NULL) {
    857                         SendMessage(m_nextClipboardWindow, msg, wParam, lParam);
    858                 }
    859                 return true;
    860 
    861         case WM_DISPLAYCHANGE:
    862                 return onDisplayChange();
    863 
    864         case WM_POWERBROADCAST:
    865                 switch (wParam) {
    866                 case PBT_APMRESUMEAUTOMATIC:
    867                 case PBT_APMRESUMECRITICAL:
    868                 case PBT_APMRESUMESUSPEND:
    869                         EVENTQUEUE->addEvent(CEvent(IScreen::getResumeEvent(),
    870                                                         getEventTarget(), NULL,
    871                                                         CEvent::kDeliverImmediately));
    872                         break;
    873 
    874                 case PBT_APMSUSPEND:
    875                         EVENTQUEUE->addEvent(CEvent(IScreen::getSuspendEvent(),
    876                                                         getEventTarget(), NULL,
    877                                                         CEvent::kDeliverImmediately));
    878                         break;
    879                 }
    880                 *result = TRUE;
    881                 return true;
    882762        }
    883763
     
    893773
    894774bool
    895 CPMScreen::onKey(WPARAM wParam, LPARAM lParam)
    896 {
    897         static const KeyModifierMask s_ctrlAlt =
    898                 KeyModifierControl | KeyModifierAlt;
    899 
    900         LOG((CLOG_DEBUG1 "event: Key char=%d, vk=0x%02x, nagr=%d, lParam=0x%08x", (wParam & 0xff00u) >> 8, wParam & 0xffu, (wParam & 0x10000u) ? 1 : 0, lParam));
     775CPMScreen::onKey(USHORT fsFlags, UCHAR ucRepeat, UCHAR ucScanCode, USHORT usch, USHORT usvk)
     776{
     777#if 0
     778        static const KeyModifierMask s_ctrlAlt = KeyModifierControl | KeyModifierAlt;
     779
     780        LOG((CLOG_DEBUG1 "event: Key char=%d, vk=0x%02x, nagr=%d, mp2=0x%08x", (mp1 & 0xff00u) >> 8, mp1 & 0xffu, (mp1 & 0x10000u) ? 1 : 0, mp2));
    901781
    902782        // get event info
    903         KeyButton button         = (KeyButton)((lParam & 0x01ff0000) >> 16);
    904         bool down                = ((lParam & 0x80000000u) == 0x00000000u);
     783        KeyButton button         = (KeyButton)((mp2 & 0x01ff0000) >> 16);
     784        bool down                = ((mp2 & 0x80000000u) == 0x00000000u);
    905785        bool wasDown             = isKeyDown(button);
    906786        KeyModifierMask oldState = pollActiveModifiers();
    907787
    908788        // check for autorepeat
    909         if (m_keyState->testAutoRepeat(down, (lParam & 0x40000000u) == 1, button)) {
    910                 lParam |= 0x40000000u;
     789        if (m_keyState->testAutoRepeat(down, (mp2 & 0x40000000u) == 1, button)) {
     790                mp2 |= 0x40000000u;
    911791        }
    912792
     
    916796        // alternatively, we could just throw these events out.
    917797        if (button == 0) {
    918                 button = m_keyState->virtualKeyToButton(wParam & 0xffu);
     798                button = m_keyState->virtualKeyToButton(mp1 & 0xffu);
    919799                if (button == 0) {
    920800                        return true;
     
    950830        if (oldState != state) {
    951831                // modifier key was pressed/released
    952                 if (onHotKey(0, lParam)) {
     832                if (onHotKey(0, mp2)) {
    953833                        return true;
    954834                }
     
    956836        else {
    957837                // non-modifier was pressed/released
    958                 if (onHotKey(wParam, lParam)) {
     838                if (onHotKey(mp1, mp2)) {
    959839                        return true;
    960840                }
     
    965845                // check for ctrl+alt+del.  we do not want to pass that to the
    966846                // client.  the user can use ctrl+alt+pause to emulate it.
    967                 UINT virtKey = (wParam & 0xffu);
     847                UINT virtKey = (mp1 & 0xffu);
    968848                if (virtKey == VK_DELETE && (state & s_ctrlAlt) == s_ctrlAlt) {
    969849                        LOG((CLOG_DEBUG "discard ctrl+alt+del"));
     
    975855                        (state & s_ctrlAlt) == s_ctrlAlt) {
    976856                        LOG((CLOG_DEBUG "emulate ctrl+alt+del"));
    977                         // switch wParam and lParam to be as if VK_DELETE was
     857                        // switch mp1 and mp2 to be as if VK_DELETE was
    978858                        // pressed or released.  when mapping the key we require that
    979                         // we not use AltGr (the 0x10000 flag in wParam) and we not
    980                         // use the keypad delete key (the 0x01000000 flag in lParam).
    981                         wParam  = VK_DELETE | 0x00010000u;
    982                         lParam &= 0xfe000000;
    983                         lParam |= m_keyState->virtualKeyToButton(wParam & 0xffu) << 16;
    984                         lParam |= 0x01000001;
     859                        // we not use AltGr (the 0x10000 flag in mp1) and we not
     860                        // use the keypad delete key (the 0x01000000 flag in mp2).
     861                        mp1  = VK_DELETE | 0x00010000u;
     862                        mp2 &= 0xfe000000;
     863                        mp2 |= m_keyState->virtualKeyToButton(mp1 & 0xffu) << 16;
     864                        mp2 |= 0x01000001;
    985865                }
    986866
    987867                // process key
    988868                KeyModifierMask mask;
    989                 KeyID key = m_keyState->mapKeyFromEvent(wParam, lParam, &mask);
    990                 button    = static_cast<KeyButton>((lParam & 0x01ff0000u) >> 16);
     869                KeyID key = m_keyState->mapKeyFromEvent((ULONG)mp1, (ULONG)mp2, &mask);
     870                button    = static_cast<KeyButton>((mp2 & 0x01ff0000u) >> 16);
    991871                if (key != kKeyNone) {
    992872                        // fix key up.  if the key isn't down according to
     
    1023903                        // do it
    1024904                        m_keyState->sendKeyEvent(getEventTarget(),
    1025                                                         ((lParam & 0x80000000u) == 0),
    1026                                                         ((lParam & 0x40000000u) != 0),
    1027                                                         key, mask, (SInt32)(lParam & 0xffff), button);
     905                                                        ((mp2 & 0x80000000u) == 0),
     906                                                        ((mp2 & 0x40000000u) != 0),
     907                                                        key, mask, (SInt32)(mp2 & 0xffff), button);
    1028908                }
    1029909                else {
     
    1031911                }
    1032912        }
    1033 
     913#endif
    1034914        return true;
    1035915}
    1036916
    1037917bool
    1038 CPMScreen::onHotKey(WPARAM wParam, LPARAM lParam)
    1039 {
     918CPMScreen::onHotKey(MPARAM mp1, MPARAM mp2)
     919{
     920#if 0
    1040921        // get the key info
    1041922        KeyModifierMask state = getActiveModifiers();
    1042         UINT virtKey   = (wParam & 0xffu);
     923        UINT virtKey   = (mp1 & 0xffu);
    1043924        UINT modifiers = 0;
    1044925        if ((state & KeyModifierShift) != 0) {
     
    1064945        // find what kind of event
    1065946        CEvent::Type type;
    1066         if ((lParam & 0x80000000u) == 0u) {
    1067                 if ((lParam & 0x40000000u) != 0u) {
     947        if ((mp2 & 0x80000000u) == 0u) {
     948                if ((mp2 & 0x40000000u) != 0u) {
    1068949                        // ignore key repeats but it counts as a hot key
    1069950                        return true;
     
    1079960                                                        CHotKeyInfo::alloc(i->second)));
    1080961
     962#endif
    1081963        return true;
    1082964}
    1083965
    1084966bool
    1085 CPMScreen::onMouseButton(WPARAM wParam, LPARAM lParam)
     967CPMScreen::onMouseButton(ULONG msg, SInt32 ax, SInt32 ay)
    1086968{
    1087969        // get which button
    1088         bool pressed    = mapPressFromEvent((ULONG)wParam, lParam);
    1089         ButtonID button = mapButtonFromEvent((ULONG)wParam, lParam);
     970        bool pressed    = mapPressFromEvent(msg);
     971        ButtonID button = mapButtonFromEvent(msg);
    1090972
    1091973        // keep our shadow key state up to date
     
    11221004
    11231005bool
    1124 CPMScreen::onMouseMove(SInt32 mx, SInt32 my)
     1006CPMScreen::onMouseMove(ULONG msg, SInt32 ax, SInt32 ay)
    11251007{
    11261008        // compute motion delta (relative to the last known
    11271009        // mouse position)
    1128         SInt32 x = mx - m_xCursor;
    1129         SInt32 y = my - m_yCursor;
     1010        SInt32 x = ax - m_xCursor;
     1011        SInt32 y = ay - m_yCursor;
    11301012
    11311013        // ignore if the mouse didn't move or if message posted prior
     
    11361018
    11371019        // save position to compute delta of next motion
    1138         m_xCursor = mx;
    1139         m_yCursor = my;
     1020        m_xCursor = ax;
     1021        m_yCursor = ay;
    11401022
    11411023        if (m_isOnScreen) {
    11421024                // motion on primary screen
    1143                 sendEvent(getMotionOnPrimaryEvent(),
    1144                                                         CMotionInfo::alloc(m_xCursor, m_yCursor));
     1025                sendEvent(getMotionOnPrimaryEvent(), CMotionInfo::alloc(m_xCursor, m_yCursor));
    11451026        }
    11461027        else {
     
    11711052
    11721053bool
    1173 CPMScreen::onMouseWheel(SInt32 xDelta, SInt32 yDelta)
    1174 {
    1175         // ignore message if posted prior to last mark change
    1176         if (!ignore()) {
    1177                 LOG((CLOG_DEBUG1 "event: button wheel delta=%+d,%+d", xDelta, yDelta));
    1178                 sendEvent(getWheelEvent(), CWheelInfo::alloc(xDelta, yDelta));
    1179         }
    1180         return true;
    1181 }
    1182 
    1183 bool
    1184 CPMScreen::onScreensaver(bool activated)
    1185 {
    1186         // ignore this message if there are any other screen saver
    1187         // messages already in the queue.  this is important because
    1188         // our checkStarted() function has a deliberate delay, so it
    1189         // can't respond to events at full CPU speed and will fall
    1190         // behind if a lot of screen saver events are generated.
    1191         // that can easily happen because windows will continually
    1192         // send SC_SCREENSAVE until the screen saver starts, even if
    1193         // the screen saver is disabled!
    1194         MSG msg;
    1195         if (PeekMessage(&msg, NULL, SYNERGY_MSG_SCREEN_SAVER,
    1196                                                 SYNERGY_MSG_SCREEN_SAVER, PM_NOREMOVE)) {
    1197                 return true;
    1198         }
    1199 
    1200         if (activated) {
    1201                 if (!m_screensaverActive &&
    1202                         m_screensaver->checkStarted(SYNERGY_MSG_SCREEN_SAVER, FALSE, 0)) {
    1203                         m_screensaverActive = true;
    1204                         sendEvent(getScreensaverActivatedEvent());
    1205 
    1206                         // enable display power down
    1207                         CArchMiscWindows::removeBusyState(CArchMiscWindows::kDISPLAY);
    1208                 }
    1209         }
    1210         else {
    1211                 if (m_screensaverActive) {
    1212                         m_screensaverActive = false;
    1213                         sendEvent(getScreensaverDeactivatedEvent());
    1214 
    1215                         // disable display power down
    1216                         CArchMiscWindows::addBusyState(CArchMiscWindows::kDISPLAY);
    1217                 }
    1218         }
    1219 
    1220         return true;
    1221 }
    1222 
    1223 bool
    1224 CPMScreen::onDisplayChange()
    1225 {
    1226         // screen resolution may have changed.  save old shape.
    1227         SInt32 xOld = m_x, yOld = m_y, wOld = m_cx, hOld = m_cy;
    1228 
    1229         // update shape
    1230         updateScreenShape();
    1231 
    1232         // do nothing if resolution hasn't changed
    1233         if (xOld != m_x || yOld != m_y || wOld != m_cx || hOld != m_cy) {
    1234                 if (m_isPrimary) {
    1235                         // warp mouse to center if off screen
    1236                         if (!m_isOnScreen) {
    1237                                 warpCursor(m_xCenter, m_yCenter);
    1238                         }
    1239 
    1240                         // tell hook about resize if on screen
    1241                         else {
    1242                                 m_setZone(m_x, m_y, m_cx, m_cy, getJumpZoneSize());
    1243                         }
    1244                 }
    1245 
    1246                 // send new screen info
    1247                 sendEvent(getShapeChangedEvent());
    1248 
    1249                 LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_cx, m_cy, m_multimon ? "(multi-monitor)" : ""));
    1250         }
    1251 
    1252         return true;
    1253 }
    1254 
    1255 bool
    12561054CPMScreen::onClipboardChange()
    12571055{
     
    12781076{
    12791077        // send an event that we can recognize before the mouse warp
    1280     WinPostQueueMsg(m_hmq, SYNERGY_MSG_PRE_WARP, (MPARAM)x, (MPARAM)y);
     1078    WinPostQueueMsg(m_hmq, SYNERGY_PM_MSG_PRE_WARP, (MPARAM)x, (MPARAM)y);
    12811079
    12821080        // warp mouse.  hopefully this inserts a mouse motion event
     
    13031101
    13041102        // send an event that we can recognize after the mouse warp
    1305     WinPostQueueMsg(m_hmq, SYNERGY_MSG_POST_WARP, 0, 0);
     1103    WinPostQueueMsg(m_hmq, SYNERGY_PM_MSG_POST_WARP, 0, 0);
    13061104}
    13071105
     
    13131111
    13141112        // mark point in message queue where the mark was changed
    1315     WinPostQueueMsg(m_hmq, SYNERGY_MSG_MARK, (MPARAM)m_mark, 0);
     1113    WinPostQueueMsg(m_hmq, SYNERGY_PM_MSG_MARK, (MPARAM)m_mark, 0);
    13161114}
    13171115
     
    13391137}
    13401138
    1341 void
    1342 CPMScreen::handleFixes(const CEvent&, void*)
    1343 {
    1344         // update keys if keyboard layouts have changed
    1345         if (m_keyState->didGroupsChange()) {
    1346                 updateKeys();
    1347         }
    1348 }
    1349 
    13501139ButtonID
    1351 CPMScreen::mapButtonFromEvent(ULONG msg, MPARAM button) const
     1140CPMScreen::mapButtonFromEvent(ULONG msg) const
    13521141{
    13531142    /** @todo query which is left and which is right. */
     
    13771166
    13781167bool
    1379 CPMScreen::mapPressFromEvent(ULONG msg, LPARAM) const
     1168CPMScreen::mapPressFromEvent(ULONG msg) const
    13801169{
    13811170        switch (msg) {
     
    14111200        }
    14121201
    1413         // update layouts if necessary
    1414         if (m_keyState->didGroupsChange()) {
    1415                 CPlatformScreen::updateKeyMap();
    1416         }
    1417 
    14181202        // now update the keyboard state
    14191203        CPlatformScreen::updateKeyState();
     
    14541238}
    14551239
    1456 HRESULT EXPENTRY
    1457 CPMScreen::wndProc(HWND hwnd, UINT msg, MPARAM mp1, MPARAM mp2)
     1240MRESULT EXPENTRY
     1241CPMScreen::wndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
    14581242{
    14591243        assert(s_screen != NULL);
    14601244
    1461         HRESULT mr = 0;
    1462         if (!s_screen->onEvent(hwnd, msg, mp1, mp2, &result)) {
     1245        MRESULT mr = 0;
     1246        if (!s_screen->onEvent(hwnd, msg, mp1, mp2, &mr)) {
    14631247                mr = WinDefWindowProc(hwnd, msg, mp1, mp2);
    14641248        }
     
    14721256//
    14731257
    1474 CPMScreen::CHotKeyItem::CHotKeyItem(UINT keycode, UINT mask) :
     1258CPMScreen::CHotKeyItem::CHotKeyItem(ULONG keycode, ULONG mask) :
    14751259        m_keycode(keycode),
    14761260        m_mask(mask)
     
    14791263}
    14801264
    1481 UINT
     1265ULONG
    14821266CPMScreen::CHotKeyItem::getVirtualKey() const
    14831267{
Note: See TracChangeset for help on using the changeset viewer.