From 1711a426f84b59f6f0507401f857d2faf09ff622 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 20 Nov 2012 01:53:30 +0000 Subject: [PATCH 1/6] Added basic mouse wheel handling --- src/input_win.c | 2 +- src/windows.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/input_win.c b/src/input_win.c index 7d5a7485..fa61e1e3 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -367,7 +367,7 @@ static int _printable(const int ch) { return (ch != ERR && ch != '\n' && - ch != KEY_PPAGE && ch != KEY_NPAGE && + ch != KEY_PPAGE && ch != KEY_NPAGE && ch != KEY_MOUSE && ch != KEY_F(1) && ch != KEY_F(2) && ch != KEY_F(3) && ch != KEY_F(4) && ch != KEY_F(5) && ch != KEY_F(6) && ch != KEY_F(7) && ch != KEY_F(8) && ch != KEY_F(9) && diff --git a/src/windows.c b/src/windows.c index 1881f23a..e4718b5e 100644 --- a/src/windows.c +++ b/src/windows.c @@ -107,6 +107,8 @@ gui_init(void) initscr(); cbreak(); keypad(stdscr, TRUE); + mousemask(ALL_MOUSE_EVENTS, NULL); + mouseinterval(5); if (has_colors()) { use_default_colors(); @@ -1761,8 +1763,37 @@ _win_handle_page(const int * const ch) int page_space = rows - 4; int *page_start = &_wins[_curr_prof_win].y_pos; + MEVENT mouse_event; + + if (*ch == KEY_MOUSE) { + if (getmouse(&mouse_event) == OK) { + if (mouse_event.bstate & BUTTON2_PRESSED) { // mouse wheel down + (*page_start)++; + + // only got half a screen, show full screen + if ((y - (*page_start)) < page_space) + *page_start = y - page_space; + + // went past end, show full screen + else if (*page_start >= y) + *page_start = y - page_space; + + _wins[_curr_prof_win].paged = 1; + dirty = TRUE; + } else if (mouse_event.bstate & BUTTON4_PRESSED) { // mouse wheel up + (*page_start)--; + + // went past beginning, show first page + if (*page_start < 0) + *page_start = 0; + + _wins[_curr_prof_win].paged = 1; + dirty = TRUE; + } + } + // page up - if (*ch == KEY_PPAGE) { + } else if (*ch == KEY_PPAGE) { *page_start -= page_space; // went past beginning, show first page From dda57fcd8eb393369cee1665e725bbefd68e7ea6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 20 Nov 2012 02:01:55 +0000 Subject: [PATCH 2/6] Wheel jumps four lines --- src/windows.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/windows.c b/src/windows.c index e4718b5e..8cf3adc7 100644 --- a/src/windows.c +++ b/src/windows.c @@ -1768,7 +1768,7 @@ _win_handle_page(const int * const ch) if (*ch == KEY_MOUSE) { if (getmouse(&mouse_event) == OK) { if (mouse_event.bstate & BUTTON2_PRESSED) { // mouse wheel down - (*page_start)++; + *page_start += 4; // only got half a screen, show full screen if ((y - (*page_start)) < page_space) @@ -1781,7 +1781,7 @@ _win_handle_page(const int * const ch) _wins[_curr_prof_win].paged = 1; dirty = TRUE; } else if (mouse_event.bstate & BUTTON4_PRESSED) { // mouse wheel up - (*page_start)--; + *page_start -= 4; // went past beginning, show first page if (*page_start < 0) From a3da391bfe17a4efac7d2f7dc23b844d1a9d652f Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 20 Nov 2012 21:03:59 +0000 Subject: [PATCH 3/6] Listen only for mouse events we're interested in --- src/windows.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows.c b/src/windows.c index 8cf3adc7..8913c963 100644 --- a/src/windows.c +++ b/src/windows.c @@ -107,7 +107,7 @@ gui_init(void) initscr(); cbreak(); keypad(stdscr, TRUE); - mousemask(ALL_MOUSE_EVENTS, NULL); + mousemask(BUTTON2_PRESSED | BUTTON4_PRESSED, NULL); mouseinterval(5); if (has_colors()) { From a27ed4cf442c74f4d0655e6ac7a5afc2444b0538 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 25 Nov 2012 02:29:01 +0000 Subject: [PATCH 4/6] Fixed compile after merging master --- src/windows.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/windows.c b/src/windows.c index df3f6b2c..4dd0f9ad 100644 --- a/src/windows.c +++ b/src/windows.c @@ -1828,7 +1828,7 @@ _win_handle_page(const int * const ch) else if (*page_start >= y) *page_start = y - page_space; - _wins[_curr_prof_win].paged = 1; + current->paged = 1; dirty = TRUE; } else if (mouse_event.bstate & BUTTON4_PRESSED) { // mouse wheel up *page_start -= 4; @@ -1837,7 +1837,7 @@ _win_handle_page(const int * const ch) if (*page_start < 0) *page_start = 0; - _wins[_curr_prof_win].paged = 1; + current->paged = 1; dirty = TRUE; } } From f6ca1ba15eca8cb904864947195f47dea1994215 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 25 Nov 2012 04:25:22 +0000 Subject: [PATCH 5/6] Added cygwin check to configure.ac --- configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index b7774c13..f6ff55ad 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,12 @@ AM_INIT_AUTOMAKE([foreign subdir-objects]) # Checks for programs. AC_PROG_CC +# get canonical host +AC_CANONICAL_HOST +if test "$host_os" == "cygwin"; then + AC_DEFINE([PLATFORM_CYGWIN], [1], [Cygwin]) +fi + # Options AC_ARG_WITH([libxml2], [AS_HELP_STRING([--with-libxml2], [link with libxml2 instead of expat])]) From a42ff49dab2d2b1c3ce8f74b4e490927df202185 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 25 Nov 2012 17:37:04 +0000 Subject: [PATCH 6/6] Added Cywin mouse wheel handling --- src/windows.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/windows.c b/src/windows.c index 4dd0f9ad..b6b5311e 100644 --- a/src/windows.c +++ b/src/windows.c @@ -107,7 +107,12 @@ gui_init(void) initscr(); raw(); keypad(stdscr, TRUE); + +#ifdef PLATFORM_CYGWIN + mousemask(BUTTON5_PRESSED | BUTTON4_PRESSED, NULL); +#else mousemask(BUTTON2_PRESSED | BUTTON4_PRESSED, NULL); +#endif mouseinterval(5); win_load_colours(); @@ -1817,7 +1822,12 @@ _win_handle_page(const int * const ch) if (*ch == KEY_MOUSE) { if (getmouse(&mouse_event) == OK) { + +#ifdef PLATFORM_CYGWIN + if (mouse_event.bstate & BUTTON5_PRESSED) { // mouse wheel down +#else if (mouse_event.bstate & BUTTON2_PRESSED) { // mouse wheel down +#endif *page_start += 4; // only got half a screen, show full screen