Changeset 2755 for trunk/synergy/lib/platform/CPMScreen.cpp
- Timestamp:
- Jul 31, 2006, 5:21:38 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/synergy/lib/platform/CPMScreen.cpp
r2754 r2755 34 34 #include "CPMUtil.h" 35 35 #include <string.h> 36 #include <unistd.h> 36 37 37 38 // … … 44 45 m_isPrimary(isPrimary), 45 46 m_isOnScreen(m_isPrimary), 46 m_class(0),47 47 m_x(0), m_y(0), 48 48 m_cx(0), m_cy(0), … … 53 53 m_mark(0), 54 54 m_markReceived(0), 55 m_fixTimer(NULL),56 55 m_screensaver(NULL), 57 56 m_screensaverNotify(false), … … 73 72 74 73 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 75 84 try { 76 if (m_isPrimary) {85 if (m_isPrimary) 77 86 m_hmodHook = openHookLibrary("synrgyhk"); 78 }79 87 m_screensaver = new CPMScreenSaver(); 80 88 m_keyState = new CPMKeyState(getEventTarget()); 81 89 updateScreenShape(); 82 m_class = createWindowClass(); 83 m_window = createWindow(m_class, "Synergy"); 90 m_window = createWindow("Synergy"); 84 91 forceShowCursor(); 85 92 LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_cx, m_cy, m_multimon ? "(multi-monitor)" : "")); 86 93 LOG((CLOG_DEBUG "window is 0x%08x", m_window)); 87 } 88 catch (...) { 94 } catch (...) { 89 95 delete m_keyState; 90 96 delete m_screensaver; 91 97 destroyWindow(m_window); 92 destroyClass(m_class);93 98 closeHookLibrary(m_hmodHook); 94 99 s_screen = NULL; … … 98 103 // install event handlers 99 104 EVENTQUEUE->adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(), 100 new TMethodEventJob<CPMScreen>(this, 101 &CPMScreen::handleSystemEvent)); 105 new TMethodEventJob<CPMScreen>(this, &CPMScreen::handleSystemEvent)); 102 106 103 107 // install the platform event queue … … 115 119 delete m_screensaver; 116 120 destroyWindow(m_window); 117 destroyClass(m_class);118 121 closeHookLibrary(m_hmodHook); 119 122 s_screen = NULL; … … 124 127 { 125 128 assert(m_isOnScreen == m_isPrimary); 126 127 // we need to poll some things to fix them128 m_fixTimer = EVENTQUEUE->newTimer(1.0, NULL);129 EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,130 new TMethodEventJob<CPMScreen>(this, &CPMScreen::handleFixes));131 129 132 130 // install our clipboard snooper … … 135 133 WinSetClipbrdViewer(hab, m_window); 136 134 137 /// @todo start here!138 // track the active desk and (re)install the hooks139 m_desks->enable();140 141 135 if (m_isPrimary) { 142 136 // set jump zones … … 151 145 CPMScreen::disable() 152 146 { 153 // stop tracking the active desk154 m_desks->disable();155 156 147 if (m_isPrimary) { 157 148 // disable hooks … … 166 157 m_nextClipboardWindow = NULL; 167 158 168 // uninstall fix timer169 if (m_fixTimer != NULL) {170 EVENTQUEUE->removeHandler(CEvent::kTimer, m_fixTimer);171 EVENTQUEUE->deleteTimer(m_fixTimer);172 m_fixTimer = NULL;173 }174 175 159 m_isOnScreen = m_isPrimary; 176 160 forceShowCursor(); … … 180 164 CPMScreen::enter() 181 165 { 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 183 172 if (m_isPrimary) { 184 173 // watch jump zones … … 197 186 CPMScreen::leave() 198 187 { 188 /// @todo save focus window. 189 199 190 if (m_isPrimary) { 200 191 // warp to center … … 252 243 { 253 244 m_screensaverNotify = notify; 254 if (!m_screensaverNotify) {245 if (!m_screensaverNotify) 255 246 m_screensaver->disable(); 256 }257 247 } 258 248 … … 260 250 CPMScreen::closeScreensaver() 261 251 { 262 if (!m_screensaverNotify) {252 if (!m_screensaverNotify) 263 253 m_screensaver->enable(); 264 }265 254 } 266 255 … … 268 257 CPMScreen::screensaver(bool activate) 269 258 { 270 if (activate) {259 if (activate) 271 260 m_screensaver->activate(); 272 } 273 else { 261 else 274 262 m_screensaver->deactivate(); 275 }276 263 } 277 264 … … 321 308 CPMScreen::getShape(SInt32& x, SInt32& y, SInt32& cx, SInt32& cy) const 322 309 { 323 assert(m_class != 0);324 325 310 x = m_x; 326 311 y = m_y; … … 356 341 // remove all input events before and including warp 357 342 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)) { 359 344 // do nothing 360 345 } … … 483 468 m_keyState->useSavedModifiers(true); 484 469 } 485 m_desks->fakeInputBegin();470 //m_desks->fakeInputBegin(); 486 471 } 487 472 … … 491 476 assert(m_isPrimary); 492 477 493 m_desks->fakeInputEnd();478 //m_desks->fakeInputEnd(); 494 479 if (!m_isOnScreen) { 495 480 m_keyState->useSavedModifiers(false); … … 535 520 CPMScreen::fakeMouseButton(ButtonID id, bool press) const 536 521 { 537 m_desks->fakeMouseButton(id, press);522 //m_desks->fakeMouseButton(id, press); 538 523 } 539 524 … … 541 526 CPMScreen::fakeMouseMove(SInt32 x, SInt32 y) const 542 527 { 543 m_desks->fakeMouseMove(x, y);528 //m_desks->fakeMouseMove(x, y); 544 529 } 545 530 … … 547 532 CPMScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const 548 533 { 549 m_desks->fakeMouseRelativeMove(dx, dy);534 //m_desks->fakeMouseRelativeMove(dx, dy); 550 535 } 551 536 … … 553 538 CPMScreen::fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const 554 539 { 555 m_desks->fakeMouseWheel(xDelta, yDelta);540 //m_desks->fakeMouseWheel(xDelta, yDelta); 556 541 } 557 542 … … 559 544 CPMScreen::updateKeys() 560 545 { 561 m_desks->updateKeys();546 //m_desks->updateKeys(); 562 547 } 563 548 … … 592 577 } 593 578 594 H INSTANCE579 HMODULE 595 580 CPMScreen::openHookLibrary(const char* name) 596 581 { 597 582 // 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)); 601 587 throw XScreenOpenFailure(); 602 588 } 603 589 604 590 // 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); 616 598 throw XScreenOpenFailure(); 617 599 } 618 600 619 601 // 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); 622 605 throw XScreenOpenFailure(); 623 606 } 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 610 void 611 CPMScreen::closeHookLibrary(HMODULE hmod) const 612 { 613 if (hmod != NULL) { 614 m_cleanup(m_hab); 615 DosFreeModule(hmod); 661 616 } 662 617 } 663 618 664 619 HWND 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, 620 CPMScreen::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_?, 673 627 0, 0, 1, 1, 674 NULL, NULL, 675 s_instance, 628 HWND_DESKTOP, 629 NULLHANDLE, 630 0, 631 this, 676 632 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))); 679 635 throw XScreenOpenFailure(); 680 636 } 681 return window;637 return hwnd; 682 638 } 683 639 … … 686 642 { 687 643 if (hwnd != NULL) { 688 DestroyWindow(hwnd);644 WinDestroyWindow(hwnd); 689 645 } 690 646 } … … 708 664 CPMScreen::handleSystemEvent(const CEvent& event, void*) 709 665 { 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)) 714 669 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); 721 671 } 722 672 … … 724 674 CPMScreen::updateButtons() 725 675 { 726 int numButtons = GetSystemMetrics(SM_CMOUSEBUTTONS);727 676 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; 735 682 } 736 683 … … 742 689 743 690 bool 744 CPMScreen::onPreDispatch(HWND hwnd, 745 UINT message, WPARAM wParam, LPARAM lParam) 691 CPMScreen::onPreDispatch(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 746 692 { 747 693 // 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)); 754 697 return true; 755 698 } 756 699 757 700 if (m_isPrimary) { 758 return onPreDispatchPrimary(hwnd, m essage, wParam, lParam);701 return onPreDispatchPrimary(hwnd, msg, mp1, mp2); 759 702 } 760 703 … … 763 706 764 707 bool 765 CPMScreen::onPreDispatchPrimary(HWND, 766 UINT message, WPARAM wParam, LPARAM lParam) 708 CPMScreen::onPreDispatchPrimary(HWND, ULONG msg, MPARAM mp1, MPARAM mp2) 767 709 { 768 710 // 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: 788 725 { 789 // save position to compute delta of next motion790 m_xCursor = static_cast<SInt32>(wParam);791 m_yCursor = static_cast<SInt32>(lParam);792 793 // we warped the mouse. discard events until we find the794 // matching post warp event. see warpCursorNoFlush() for795 // where the events are sent. we discard the matching726 // 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 796 733 // post warp event and can be sure we've skipped the warp 797 734 // 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 */; 803 739 } 804 740 return true; 805 741 806 case SYNERGY_ MSG_POST_WARP:742 case SYNERGY_PM_MSG_POST_WARP: 807 743 LOG((CLOG_WARN "unmatched post warp")); 808 744 return true; 809 810 case WM_HOTKEY:811 // we discard these messages. we'll catch the hot key in the812 // regular key event handling, where we can detect both key813 // press and release. we only register the hot key so no other814 // app will act on the key combination.815 break;816 745 } 817 746 … … 820 749 821 750 bool 822 CPMScreen::onEvent(HWND, UINT msg, 823 WPARAM wParam, LPARAM lParam, LRESULT* result) 751 CPMScreen::onEvent(HWND, ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT *result) 824 752 { 825 753 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 842 754 case WM_DRAWCLIPBOARD: 843 // first pass on the message844 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 //} 847 759 848 760 // now handle the message 849 761 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;882 762 } 883 763 … … 893 773 894 774 bool 895 CPMScreen::onKey( WPARAM wParam, LPARAM lParam)896 { 897 static const KeyModifierMask s_ctrlAlt = 898 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));775 CPMScreen::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)); 901 781 902 782 // 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); 905 785 bool wasDown = isKeyDown(button); 906 786 KeyModifierMask oldState = pollActiveModifiers(); 907 787 908 788 // 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; 911 791 } 912 792 … … 916 796 // alternatively, we could just throw these events out. 917 797 if (button == 0) { 918 button = m_keyState->virtualKeyToButton( wParam& 0xffu);798 button = m_keyState->virtualKeyToButton(mp1 & 0xffu); 919 799 if (button == 0) { 920 800 return true; … … 950 830 if (oldState != state) { 951 831 // modifier key was pressed/released 952 if (onHotKey(0, lParam)) {832 if (onHotKey(0, mp2)) { 953 833 return true; 954 834 } … … 956 836 else { 957 837 // non-modifier was pressed/released 958 if (onHotKey( wParam, lParam)) {838 if (onHotKey(mp1, mp2)) { 959 839 return true; 960 840 } … … 965 845 // check for ctrl+alt+del. we do not want to pass that to the 966 846 // client. the user can use ctrl+alt+pause to emulate it. 967 UINT virtKey = ( wParam& 0xffu);847 UINT virtKey = (mp1 & 0xffu); 968 848 if (virtKey == VK_DELETE && (state & s_ctrlAlt) == s_ctrlAlt) { 969 849 LOG((CLOG_DEBUG "discard ctrl+alt+del")); … … 975 855 (state & s_ctrlAlt) == s_ctrlAlt) { 976 856 LOG((CLOG_DEBUG "emulate ctrl+alt+del")); 977 // switch wParam and lParamto be as if VK_DELETE was857 // switch mp1 and mp2 to be as if VK_DELETE was 978 858 // pressed or released. when mapping the key we require that 979 // we not use AltGr (the 0x10000 flag in wParam) and we not980 // 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; 985 865 } 986 866 987 867 // process key 988 868 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); 991 871 if (key != kKeyNone) { 992 872 // fix key up. if the key isn't down according to … … 1023 903 // do it 1024 904 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); 1028 908 } 1029 909 else { … … 1031 911 } 1032 912 } 1033 913 #endif 1034 914 return true; 1035 915 } 1036 916 1037 917 bool 1038 CPMScreen::onHotKey(WPARAM wParam, LPARAM lParam) 1039 { 918 CPMScreen::onHotKey(MPARAM mp1, MPARAM mp2) 919 { 920 #if 0 1040 921 // get the key info 1041 922 KeyModifierMask state = getActiveModifiers(); 1042 UINT virtKey = ( wParam& 0xffu);923 UINT virtKey = (mp1 & 0xffu); 1043 924 UINT modifiers = 0; 1044 925 if ((state & KeyModifierShift) != 0) { … … 1064 945 // find what kind of event 1065 946 CEvent::Type type; 1066 if (( lParam& 0x80000000u) == 0u) {1067 if (( lParam& 0x40000000u) != 0u) {947 if ((mp2 & 0x80000000u) == 0u) { 948 if ((mp2 & 0x40000000u) != 0u) { 1068 949 // ignore key repeats but it counts as a hot key 1069 950 return true; … … 1079 960 CHotKeyInfo::alloc(i->second))); 1080 961 962 #endif 1081 963 return true; 1082 964 } 1083 965 1084 966 bool 1085 CPMScreen::onMouseButton( WPARAM wParam, LPARAM lParam)967 CPMScreen::onMouseButton(ULONG msg, SInt32 ax, SInt32 ay) 1086 968 { 1087 969 // 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); 1090 972 1091 973 // keep our shadow key state up to date … … 1122 1004 1123 1005 bool 1124 CPMScreen::onMouseMove( SInt32 mx, SInt32 my)1006 CPMScreen::onMouseMove(ULONG msg, SInt32 ax, SInt32 ay) 1125 1007 { 1126 1008 // compute motion delta (relative to the last known 1127 1009 // 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; 1130 1012 1131 1013 // ignore if the mouse didn't move or if message posted prior … … 1136 1018 1137 1019 // save position to compute delta of next motion 1138 m_xCursor = mx;1139 m_yCursor = my;1020 m_xCursor = ax; 1021 m_yCursor = ay; 1140 1022 1141 1023 if (m_isOnScreen) { 1142 1024 // motion on primary screen 1143 sendEvent(getMotionOnPrimaryEvent(), 1144 CMotionInfo::alloc(m_xCursor, m_yCursor)); 1025 sendEvent(getMotionOnPrimaryEvent(), CMotionInfo::alloc(m_xCursor, m_yCursor)); 1145 1026 } 1146 1027 else { … … 1171 1052 1172 1053 bool 1173 CPMScreen::onMouseWheel(SInt32 xDelta, SInt32 yDelta)1174 {1175 // ignore message if posted prior to last mark change1176 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 bool1184 CPMScreen::onScreensaver(bool activated)1185 {1186 // ignore this message if there are any other screen saver1187 // messages already in the queue. this is important because1188 // our checkStarted() function has a deliberate delay, so it1189 // can't respond to events at full CPU speed and will fall1190 // behind if a lot of screen saver events are generated.1191 // that can easily happen because windows will continually1192 // send SC_SCREENSAVE until the screen saver starts, even if1193 // 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 down1207 CArchMiscWindows::removeBusyState(CArchMiscWindows::kDISPLAY);1208 }1209 }1210 else {1211 if (m_screensaverActive) {1212 m_screensaverActive = false;1213 sendEvent(getScreensaverDeactivatedEvent());1214 1215 // disable display power down1216 CArchMiscWindows::addBusyState(CArchMiscWindows::kDISPLAY);1217 }1218 }1219 1220 return true;1221 }1222 1223 bool1224 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 shape1230 updateScreenShape();1231 1232 // do nothing if resolution hasn't changed1233 if (xOld != m_x || yOld != m_y || wOld != m_cx || hOld != m_cy) {1234 if (m_isPrimary) {1235 // warp mouse to center if off screen1236 if (!m_isOnScreen) {1237 warpCursor(m_xCenter, m_yCenter);1238 }1239 1240 // tell hook about resize if on screen1241 else {1242 m_setZone(m_x, m_y, m_cx, m_cy, getJumpZoneSize());1243 }1244 }1245 1246 // send new screen info1247 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 bool1256 1054 CPMScreen::onClipboardChange() 1257 1055 { … … 1278 1076 { 1279 1077 // 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); 1281 1079 1282 1080 // warp mouse. hopefully this inserts a mouse motion event … … 1303 1101 1304 1102 // 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); 1306 1104 } 1307 1105 … … 1313 1111 1314 1112 // 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); 1316 1114 } 1317 1115 … … 1339 1137 } 1340 1138 1341 void1342 CPMScreen::handleFixes(const CEvent&, void*)1343 {1344 // update keys if keyboard layouts have changed1345 if (m_keyState->didGroupsChange()) {1346 updateKeys();1347 }1348 }1349 1350 1139 ButtonID 1351 CPMScreen::mapButtonFromEvent(ULONG msg , MPARAM button) const1140 CPMScreen::mapButtonFromEvent(ULONG msg) const 1352 1141 { 1353 1142 /** @todo query which is left and which is right. */ … … 1377 1166 1378 1167 bool 1379 CPMScreen::mapPressFromEvent(ULONG msg , LPARAM) const1168 CPMScreen::mapPressFromEvent(ULONG msg) const 1380 1169 { 1381 1170 switch (msg) { … … 1411 1200 } 1412 1201 1413 // update layouts if necessary1414 if (m_keyState->didGroupsChange()) {1415 CPlatformScreen::updateKeyMap();1416 }1417 1418 1202 // now update the keyboard state 1419 1203 CPlatformScreen::updateKeyState(); … … 1454 1238 } 1455 1239 1456 HRESULT EXPENTRY1457 CPMScreen::wndProc(HWND hwnd, U INTmsg, MPARAM mp1, MPARAM mp2)1240 MRESULT EXPENTRY 1241 CPMScreen::wndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 1458 1242 { 1459 1243 assert(s_screen != NULL); 1460 1244 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)) { 1463 1247 mr = WinDefWindowProc(hwnd, msg, mp1, mp2); 1464 1248 } … … 1472 1256 // 1473 1257 1474 CPMScreen::CHotKeyItem::CHotKeyItem(U INT keycode, UINTmask) :1258 CPMScreen::CHotKeyItem::CHotKeyItem(ULONG keycode, ULONG mask) : 1475 1259 m_keycode(keycode), 1476 1260 m_mask(mask) … … 1479 1263 } 1480 1264 1481 U INT1265 ULONG 1482 1266 CPMScreen::CHotKeyItem::getVirtualKey() const 1483 1267 {
Note:
See TracChangeset
for help on using the changeset viewer.