diff options
author | James Booth <boothj5@gmail.com> | 2012-11-20 01:53:30 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-11-20 01:53:30 +0000 |
commit | 1711a426f84b59f6f0507401f857d2faf09ff622 (patch) | |
tree | 893d0bc6469c1f554a1cf3ba0bfc66d4554ede40 | |
parent | 306965501ac2cc76454ea71c6ed4f126e02100b2 (diff) | |
download | profani-tty-1711a426f84b59f6f0507401f857d2faf09ff622.tar.gz |
Added basic mouse wheel handling
-rw-r--r-- | src/input_win.c | 2 | ||||
-rw-r--r-- | 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 |