Skip to content

Commit

Permalink
Support mouse wheel w/multiplier
Browse files Browse the repository at this point in the history
Default multiplier is 3. Available in options dialog.
Can also be set via /wheelmultiplier cmd line arg.
  • Loading branch information
jlopez committed Apr 22, 2010
1 parent 767c7ea commit 8459fd1
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 141 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.idc
*.ncb
*.aps
Debug/
Release/
enc_temp_folder/
132 changes: 79 additions & 53 deletions ClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,64 +792,36 @@ LRESULT CALLBACK ClientConnection::WndProc(HWND hwnd, UINT iMsg,
}
}

int ClientConnection::RealWndProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{

case WM_CREATE:
return 0;

case WM_TIMER:
if (wParam == m_emulate3ButtonsTimer)
{
SubProcessPointerEvent(m_emulateButtonPressedX,
m_emulateButtonPressedY,
m_emulateKeyFlags);
KillTimer(m_hwnd, m_emulate3ButtonsTimer);
m_waitingOnEmulateTimer = false;
}
return 0;


case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MOUSEMOVE:
{
int ClientConnection::OnMouseEvent(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
#ifndef USE_SNOOPDLL
POINT pt;
if (GetFocus() != hwnd) return 0;
if (!m_running) return 0;
POINT pt;
if (GetFocus() != hwnd) return 0;
if (!m_running) return 0;

pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);

ClientToScreen(hwnd, &pt);
int x=pt.x;
int y=pt.y;
ClientToScreen(hwnd, &pt);
int x=pt.x;
int y=pt.y;

if(x<0 || x>32768) x=0;
if(y<0 || y>32768) y=0;
if(x>=m_screenwidth) x=m_screenwidth-1;
if(y>=m_screenheight) y=m_screenheight-1;
if(x<0 || x>32768) x=0;
if(y<0 || y>32768) y=0;
if(x>=m_screenwidth) x=m_screenwidth-1;
if(y>=m_screenheight) y=m_screenheight-1;

if(m_onedge)
{
if(m_onedge)
{
if(hwnd == m_edgewindow)
{
log.Print(4,"Activated by action: %d\n",iMsg);
Activate(x,y);
}
return 0;
}
}

if(hwnd == m_hwnd)
{
if(hwnd == m_hwnd)
{
int back=0;
switch(m_opts.m_edge)
{
Expand All @@ -864,13 +836,54 @@ int ClientConnection::RealWndProc(HWND hwnd, UINT iMsg,
Deactivate(x,y);
return 0;
}
}
}

ProcessPointerEvent(x,y, wParam, iMsg);
ProcessPointerEvent(x,y, wParam, iMsg);
#endif
return 0;
}

#define MK_WHEELUP 0x4000
#define MK_WHEELDOWN 0x8000

int ClientConnection::RealWndProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{

case WM_CREATE:
return 0;

case WM_TIMER:
if (wParam == m_emulate3ButtonsTimer)
{
SubProcessPointerEvent(m_emulateButtonPressedX,
m_emulateButtonPressedY,
m_emulateKeyFlags);
KillTimer(m_hwnd, m_emulate3ButtonsTimer);
m_waitingOnEmulateTimer = false;
}
return 0;


case 0x20A:
{
log.Print(0, "Wheel: %08X %08X\n", wParam, lParam);
int delta = ((short)HIWORD(wParam));
wParam |= delta < 0 ? MK_WHEELDOWN : MK_WHEELUP;
return OnMouseEvent(hwnd, iMsg, wParam, lParam);
}

case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MOUSEMOVE:
return OnMouseEvent(hwnd, iMsg, wParam, lParam);

#ifdef USE_SNOOPDLL
case SNOOPDLL_MOUSE_UPDATE:
{
Expand Down Expand Up @@ -1209,16 +1222,29 @@ ClientConnection::SubProcessPointerEvent(int x, int y, DWORD keyflags)
if (m_opts.m_SwapMouse) {
mask = ( ((keyflags & MK_LBUTTON) ? rfbButton1Mask : 0) |
((keyflags & MK_MBUTTON) ? rfbButton3Mask : 0) |
((keyflags & MK_RBUTTON) ? rfbButton2Mask : 0) );
((keyflags & MK_RBUTTON) ? rfbButton2Mask : 0) |
((keyflags & MK_WHEELUP) ? rfbButtonWheelUpMask : 0) |
((keyflags & MK_WHEELDOWN) ? rfbButtonWheelDownMask : 0) );
} else {
mask = ( ((keyflags & MK_LBUTTON) ? rfbButton1Mask : 0) |
((keyflags & MK_MBUTTON) ? rfbButton2Mask : 0) |
((keyflags & MK_RBUTTON) ? rfbButton3Mask : 0) );
((keyflags & MK_RBUTTON) ? rfbButton3Mask : 0) |
((keyflags & MK_WHEELUP) ? rfbButtonWheelUpMask : 0) |
((keyflags & MK_WHEELDOWN) ? rfbButtonWheelDownMask : 0) );
}


int count = 1;
if (keyflags & (MK_WHEELUP | MK_WHEELDOWN)) {
float delta = ((short)HIWORD(keyflags));
delta = delta < 0 ? -delta : delta;
count = max(delta * m_opts.m_wheelMultiplier / 120, 1);
}

try {
SendPointerEvent((x),
(y), mask);
for (int i = 0; i < count; ++i) {
SendPointerEvent((x),
(y), mask);
}
} catch (Exception &e) {
e.Report();
PostMessage(m_hwnd, WM_CLOSE, 0, 0);
Expand Down
1 change: 1 addition & 0 deletions ClientConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ClientConnection : public omni_thread
void Deactivate(int,int);

int RealWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
int OnMouseEvent(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);

void Init(VNCviewerApp *pApp);
void Exit();
Expand Down
24 changes: 24 additions & 0 deletions VNCOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ VNCOptions::VNCOptions()
m_Emul3Fuzz = 4; // pixels away before emulation is cancelled
m_Shared = false;
m_DisableClipboard = false;
m_wheelMultiplier = 3;

m_host[0] = '\0';
m_port = -1;
Expand Down Expand Up @@ -73,6 +74,7 @@ VNCOptions& VNCOptions::operator=(VNCOptions& s)
m_Emul3Fuzz = s.m_Emul3Fuzz; // pixels away before emulation is cancelled
m_Shared = s.m_Shared;
m_DisableClipboard = s.m_DisableClipboard;
m_wheelMultiplier = s.m_wheelMultiplier;

strcpy(m_host, s.m_host);
m_port = s.m_port;
Expand Down Expand Up @@ -216,6 +218,16 @@ void VNCOptions::SetFromCommandLine(LPTSTR szCmdLine)
continue;
}

} else if ( SwitchMatch(args[j], _T("wheelmultiplier") )) {
if (++j == i) {
ArgError(_T("No wheelmultiplier specified"));
continue;
}
if (_stscanf(args[j], _T("%d"), &m_wheelMultiplier) != 1) {
ArgError(_T("Invalid wheelmultiplier specified"));
continue;
}

} else if ( SwitchMatch(args[j], _T("loglevel") )) {
if (++j == i) {
ArgError(_T("No loglevel specified"));
Expand Down Expand Up @@ -301,6 +313,7 @@ void VNCOptions::Save(char *fname)
saveInt("emulate3timeout", m_Emul3Timeout, fname);
saveInt("emulate3fuzz", m_Emul3Fuzz, fname);
saveInt("disableclipboard", m_DisableClipboard, fname);
saveInt("wheelmultiplier", m_wheelMultiplier, fname);
saveInt("edge", m_edge, fname);
}

Expand All @@ -319,6 +332,7 @@ void VNCOptions::Load(char *fname)
m_Emul3Timeout = readInt("emulate3timeout",m_Emul3Timeout, fname);
m_Emul3Fuzz = readInt("emulate3fuzz", m_Emul3Fuzz, fname);
m_DisableClipboard = readInt("disableclipboard", m_DisableClipboard, fname) != 0;
m_wheelMultiplier = readInt("wheelmultiplier", m_wheelMultiplier, fname);
m_edge = readInt("edge", m_edge, fname);
}

Expand Down Expand Up @@ -470,6 +484,11 @@ int CALLBACK VNCOptions::RealOptDlgProc( HWND hwnd,
HWND hS = GetDlgItem(hwnd, IDC_EDGE_SOUTH);
SendMessage(hW, BM_SETCHECK, m_edge == M_EDGE_SOUTH, 0);

char buffer[20];
_snprintf(buffer, sizeof(buffer), "%d", m_wheelMultiplier);
HWND hWM = GetDlgItem(hwnd, IDC_WHEEL_MULTIPLIER);
SetWindowText(hWM, buffer);

CentreWindow(hwnd);

return TRUE;
Expand Down Expand Up @@ -527,6 +546,11 @@ int CALLBACK VNCOptions::RealOptDlgProc( HWND hwnd,
if(SendMessage(hW, BM_GETCHECK, 0, 0) == BST_CHECKED)
m_edge = M_EDGE_WEST;

HWND hWM = GetDlgItem(hwnd, IDC_WHEEL_MULTIPLIER);
char buffer[20];
GetWindowText(hWM, buffer, 20);
m_wheelMultiplier = atoi(buffer);

EndDialog(hwnd, TRUE);

return TRUE;
Expand Down
1 change: 1 addition & 0 deletions VNCOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class VNCOptions
int m_Emul3Fuzz;
bool m_Shared;
bool m_DisableClipboard;
int m_wheelMultiplier;

#define M_EDGE_NORTH 0
#define M_EDGE_SOUTH 1
Expand Down
Binary file modified WIN2VNC.suo
Binary file not shown.
5 changes: 3 additions & 2 deletions res/resource.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Microsoft Visual C++ generated include file.
// Used by vncviewer.rc
//
#define IDR_TRAY 101
Expand Down Expand Up @@ -51,6 +51,7 @@
#define IDC_EDGE_WEST 1035
#define IDC_EDGE_NORTH 1036
#define IDC_EDGE_SOUTH 1037
#define IDC_WHEEL_MULTIPLIER 1039
#define ID_SESSION_SET_CRECT 32777
#define ID_SESSION_SWAPMOUSE 32785
#define ID_CLOSEDAEMON 40001
Expand All @@ -64,7 +65,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 154
#define _APS_NEXT_COMMAND_VALUE 40010
#define _APS_NEXT_CONTROL_VALUE 1039
#define _APS_NEXT_CONTROL_VALUE 1040
#define _APS_NEXT_SYMED_VALUE 154
#endif
#endif
Loading

0 comments on commit 8459fd1

Please sign in to comment.