summaryrefslogtreecommitdiff
path: root/platform/x11
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-03-31 17:10:37 +0100
committerRobin Watts <robin.watts@artifex.com>2015-03-31 18:34:22 +0100
commit0a039da57c4ad338ed6e6f818b480d2124223a6d (patch)
tree8e42ceda2141381dbb84855da8ca7c8868c769dd /platform/x11
parentc4e17decdd2e278a44e281a8d3342b94dd833891 (diff)
downloadmupdf-0a039da57c4ad338ed6e6f818b480d2124223a6d.tar.xz
Bug 695457: Improve mouse wheel handling in viewer.
On windows, handle mouse wheel events as mouse events rather than keyboard ones. This means that Ctrl-wheel zooms as expected (consistent with Chrome etc). Also ensure that Shift-wheel changes from vertical to horizontal. Mouse wheel over pages that are larger than fit in the window now scroll around the page. Once they hit the edge of the window, the page flips to the next/previous page as you would expect.
Diffstat (limited to 'platform/x11')
-rw-r--r--platform/x11/pdfapp.c91
-rw-r--r--platform/x11/win_main.c19
2 files changed, 73 insertions, 37 deletions
diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c
index a4c3488d..3eda4c6f 100644
--- a/platform/x11/pdfapp.c
+++ b/platform/x11/pdfapp.c
@@ -1400,6 +1400,66 @@ void pdfapp_onkey(pdfapp_t *app, int c, int modifiers)
}
}
+static void handlescroll(pdfapp_t *app, int modifiers, int dir)
+{
+ app->ispanning = app->iscopying = 0;
+ if (modifiers & (1<<2))
+ {
+ /* zoom in/out if ctrl is pressed */
+ if (dir < 0)
+ app->resolution = zoom_in(app->resolution);
+ else
+ app->resolution = zoom_out(app->resolution);
+ if (app->resolution > MAXRES)
+ app->resolution = MAXRES;
+ if (app->resolution < MINRES)
+ app->resolution = MINRES;
+ pdfapp_showpage(app, 0, 1, 1, 0, 0);
+ }
+ else
+ {
+ /* scroll up/down, or left/right if
+ shift is pressed */
+ int w = fz_pixmap_width(app->ctx, app->image);
+ int h = fz_pixmap_height(app->ctx, app->image);
+ int xstep = 0;
+ int ystep = 0;
+ int pagestep = 0;
+ if (modifiers & (1<<0))
+ {
+ if (dir > 0 && app->panx >= 0)
+ pagestep = -1;
+ else if (dir < 0 && app->panx <= app->winw - w)
+ pagestep = 1;
+ else
+ xstep = 20 * dir;
+ }
+ else
+ {
+ if (dir > 0 && app->pany >= 0)
+ pagestep = -1;
+ else if (dir < 0 && app->pany <= app->winh - h)
+ pagestep = 1;
+ else
+ ystep = 20 * dir;
+ }
+ if (pagestep == 0)
+ pdfapp_panview(app, app->panx + xstep, app->pany + ystep);
+ else if (pagestep > 0 && app->pageno < app->pagecount)
+ {
+ app->pageno++;
+ app->pany = 0;
+ pdfapp_showpage(app, 1, 1, 1, 0, 0);
+ }
+ else if (pagestep < 0 && app->pageno > 1)
+ {
+ app->pageno--;
+ app->pany = INT_MIN;
+ pdfapp_showpage(app, 1, 1, 1, 0, 0);
+ }
+ }
+}
+
void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state)
{
fz_context *ctx = app->ctx;
@@ -1583,39 +1643,12 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta
}
if (btn == 4 || btn == 5) /* scroll wheel */
{
- int dir = btn == 4 ? 1 : -1;
- app->ispanning = app->iscopying = 0;
- if (modifiers & (1<<2))
- {
- /* zoom in/out if ctrl is pressed */
- if (dir > 0)
- app->resolution = zoom_in(app->resolution);
- else
- app->resolution = zoom_out(app->resolution);
- if (app->resolution > MAXRES)
- app->resolution = MAXRES;
- if (app->resolution < MINRES)
- app->resolution = MINRES;
- pdfapp_showpage(app, 0, 1, 1, 0, 0);
- }
- else
- {
- /* scroll up/down, or left/right if
- shift is pressed */
- int isx = (modifiers & (1<<0));
- int xstep = isx ? 20 * dir : 0;
- int ystep = !isx ? 20 * dir : 0;
- pdfapp_panview(app, app->panx + xstep, app->pany + ystep);
- }
+ handlescroll(app, modifiers, btn == 4 ? 1 : -1);
}
if (btn == 6 || btn == 7) /* scroll wheel (horizontal) */
{
/* scroll left/right or up/down if shift is pressed */
- int dir = btn == 6 ? 1 : -1;
- int isx = (modifiers & (1<<0));
- int xstep = !isx ? 20 * dir : 0;
- int ystep = isx ? 20 * dir : 0;
- pdfapp_panview(app, app->panx + xstep, app->pany + ystep);
+ handlescroll(app, modifiers ^ (1<<0), btn == 6 ? 1 : -1);
}
if (app->presentation_mode)
{
diff --git a/platform/x11/win_main.c b/platform/x11/win_main.c
index 532fa76c..32121f5f 100644
--- a/platform/x11/win_main.c
+++ b/platform/x11/win_main.c
@@ -910,8 +910,11 @@ static void killtimer(pdfapp_t *app)
timer_pending = 0;
}
-void handlekey(int c, int modifier)
+void handlekey(int c)
{
+ int modifier = (GetAsyncKeyState(VK_SHIFT) < 0);
+ modifier |= ((GetAsyncKeyState(VK_CONTROL) < 0)<<2);
+
if (timer_pending)
killtimer(&gapp);
@@ -1100,9 +1103,11 @@ viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_MOUSEWHEEL:
if ((signed short)HIWORD(wParam) > 0)
- handlekey(LOWORD(wParam) & MK_SHIFT ? '+' : 'k', 0);
+ handlemouse(oldx, oldy, 4, 1);
+ //handlekey(LOWORD(wParam) & MK_SHIFT ? '+' : 'k');
else
- handlekey(LOWORD(wParam) & MK_SHIFT ? '-' : 'j', 0);
+ handlemouse(oldx, oldy, 5, 1);
+ //handlekey(LOWORD(wParam) & MK_SHIFT ? '-' : 'j');
return 0;
/* Timer */
@@ -1110,7 +1115,7 @@ viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
if (wParam == OUR_TIMER_ID && timer_pending && gapp.presentation_mode)
{
timer_pending = 0;
- handlekey(VK_RIGHT + 256, 0);
+ handlekey(VK_RIGHT + 256);
handlemouse(oldx, oldy, 0, 0); /* update cursor */
return 0;
}
@@ -1130,7 +1135,7 @@ viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case VK_DOWN:
case VK_NEXT:
case VK_ESCAPE:
- handlekey(wParam + 256, 0);
+ handlekey(wParam + 256);
handlemouse(oldx, oldy, 0, 0); /* update cursor */
return 0;
}
@@ -1140,9 +1145,7 @@ viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_CHAR:
if (wParam < 256)
{
- int modifier = (GetAsyncKeyState(VK_SHIFT) < 0);
- modifier |= ((GetAsyncKeyState(VK_CONTROL) < 0)<<2);
- handlekey(wParam, modifier);
+ handlekey(wParam);
handlemouse(oldx, oldy, 0, 0); /* update cursor */
}
return 0;