Support for NCurses 6.0 and mouse wheel

This commit is contained in:
Hisham Muhammad 2015-08-19 18:55:24 -03:00
parent 3e93f9b852
commit b003636958
5 changed files with 61 additions and 20 deletions

12
CRT.c
View File

@ -29,6 +29,9 @@ in the source distribution for its full text.
#define Cyan COLOR_CYAN #define Cyan COLOR_CYAN
#define White COLOR_WHITE #define White COLOR_WHITE
#define KEY_WHEELUP KEY_F(20)
#define KEY_WHEELDOWN KEY_F(21)
//#link curses //#link curses
/*{ /*{
@ -515,6 +518,8 @@ int CRT_cursorX = 0;
int CRT_scrollHAmount = 5; int CRT_scrollHAmount = 5;
int CRT_scrollWheelVAmount = 10;
char* CRT_termType; char* CRT_termType;
// TODO move color scheme to Settings, perhaps? // TODO move color scheme to Settings, perhaps?
@ -550,6 +555,7 @@ void CRT_init(int delay, int colorScheme) {
nonl(); nonl();
intrflush(stdscr, false); intrflush(stdscr, false);
keypad(stdscr, true); keypad(stdscr, true);
mouseinterval(0);
curs_set(0); curs_set(0);
if (has_colors()) { if (has_colors()) {
start_color(); start_color();
@ -598,7 +604,11 @@ void CRT_init(int delay, int colorScheme) {
CRT_treeStr = CRT_utf8 ? CRT_treeStrUtf8 : CRT_treeStrAscii; CRT_treeStr = CRT_utf8 ? CRT_treeStrUtf8 : CRT_treeStrAscii;
mousemask(BUTTON1_CLICKED, NULL); #if NCURSES_MOUSE_VERSION > 1
mousemask(BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL);
#else
mousemask(BUTTON1_RELEASED, NULL);
#endif
} }
void CRT_done() { void CRT_done() {

5
CRT.h
View File

@ -20,6 +20,9 @@ in the source distribution for its full text.
#define Cyan COLOR_CYAN #define Cyan COLOR_CYAN
#define White COLOR_WHITE #define White COLOR_WHITE
#define KEY_WHEELUP KEY_F(20)
#define KEY_WHEELDOWN KEY_F(21)
//#link curses //#link curses
#include <stdbool.h> #include <stdbool.h>
@ -130,6 +133,8 @@ extern int CRT_cursorX;
extern int CRT_scrollHAmount; extern int CRT_scrollHAmount;
extern int CRT_scrollWheelVAmount;
char* CRT_termType; char* CRT_termType;
// TODO move color scheme to Settings, perhaps? // TODO move color scheme to Settings, perhaps?

15
Panel.c
View File

@ -412,6 +412,21 @@ bool Panel_onKey(Panel* this, int key) {
this->scrollV += (this->h - 1); this->scrollV += (this->h - 1);
this->needsRedraw = true; this->needsRedraw = true;
break; break;
case KEY_WHEELUP:
this->selected -= CRT_scrollWheelVAmount;
this->scrollV -= CRT_scrollWheelVAmount;
this->needsRedraw = true;
break;
case KEY_WHEELDOWN:
{
this->selected += CRT_scrollWheelVAmount;
this->scrollV += CRT_scrollWheelVAmount;
if (this->scrollV > Vector_size(this->items) - this->h) {
this->scrollV = Vector_size(this->items) - this->h;
}
this->needsRedraw = true;
break;
}
case KEY_HOME: case KEY_HOME:
this->selected = 0; this->selected = 0;
break; break;

View File

@ -9,6 +9,7 @@ in the source distribution for its full text.
#include "ProcessList.h" #include "ProcessList.h"
#include "Object.h" #include "Object.h"
#include "CRT.h"
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
@ -196,26 +197,34 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
MEVENT mevent; MEVENT mevent;
int ok = getmouse(&mevent); int ok = getmouse(&mevent);
if (ok == OK) { if (ok == OK) {
if (mevent.y == LINES - 1) { if (mevent.bstate & BUTTON1_RELEASED) {
ch = FunctionBar_synthesizeEvent(panelFocus->currentBar, mevent.x); if (mevent.y == LINES - 1) {
} else { ch = FunctionBar_synthesizeEvent(panelFocus->currentBar, mevent.x);
for (int i = 0; i < this->panelCount; i++) { } else {
Panel* panel = (Panel*) Vector_get(this->panels, i); for (int i = 0; i < this->panelCount; i++) {
if (mevent.x >= panel->x && mevent.x <= panel->x+panel->w) { Panel* panel = (Panel*) Vector_get(this->panels, i);
if (mevent.y == panel->y) { if (mevent.x >= panel->x && mevent.x <= panel->x+panel->w) {
ch = EVENT_HEADER_CLICK(mevent.x - panel->x); if (mevent.y == panel->y) {
break; ch = EVENT_HEADER_CLICK(mevent.x - panel->x);
} else if (mevent.y > panel->y && mevent.y <= panel->y+panel->h) { break;
if (panel == panelFocus || this->allowFocusChange) { } else if (mevent.y > panel->y && mevent.y <= panel->y+panel->h) {
focus = i; if (panel == panelFocus || this->allowFocusChange) {
panelFocus = setCurrentPanel(panel); focus = i;
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1); panelFocus = setCurrentPanel(panel);
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
}
ch = KEY_MOUSE;
break;
} }
ch = KEY_MOUSE;
break;
} }
} }
} }
#if NCURSES_MOUSE_VERSION > 1
} else if (mevent.bstate & BUTTON4_PRESSED) {
ch = KEY_WHEELUP;
} else if (mevent.bstate & BUTTON5_PRESSED) {
ch = KEY_WHEELDOWN;
#endif
} }
} }
} }

View File

@ -143,9 +143,11 @@ fi
AC_ARG_ENABLE(unicode, [AC_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes") AC_ARG_ENABLE(unicode, [AC_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="yes")
if test "x$enable_unicode" = xyes; then if test "x$enable_unicode" = xyes; then
AC_CHECK_LIB([ncursesw], [refresh], [], [ AC_CHECK_LIB([ncursesw6], [refresh], [], [
missing_libraries="$missing_libraries libncursesw" AC_CHECK_LIB([ncursesw], [refresh], [], [
AC_MSG_ERROR([You may want to use --disable-unicode or install libncursesw.]) missing_libraries="$missing_libraries libncursesw"
AC_MSG_ERROR([You may want to use --disable-unicode or install libncursesw.])
])
]) ])
AC_CHECK_HEADERS([ncursesw/curses.h],[:], AC_CHECK_HEADERS([ncursesw/curses.h],[:],
[AC_CHECK_HEADERS([ncurses/ncurses.h],[:], [AC_CHECK_HEADERS([ncurses/ncurses.h],[:],