Skip to content

Commit

Permalink
Add default support for scrolling with the mouse wheel.
Browse files Browse the repository at this point in the history
Also changes the scrollback() function so that the amount to scroll
can be configured as a fraction of the screen height.

This fixes martanne#103.
  • Loading branch information
ccrusius authored and cyruseuros committed May 28, 2020
1 parent 02af892 commit 630a4cf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DEBUG_CFLAGS = ${CFLAGS} -UNDEBUG -O0 -g -ggdb -Wall -Wextra -Wno-unused-paramet

all: dvtm dvtm-editor

config.h:
config.h: config.def.h
cp config.def.h config.h

dvtm: config.h config.mk *.c *.h
Expand Down
16 changes: 12 additions & 4 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ static KeyBinding bindings[] = {
{ { MOD, 'E', }, { copymode, { "dvtm-pager" } } },
{ { MOD, '/', }, { copymode, { "dvtm-pager", "/" } } },
{ { MOD, 'p', }, { paste, { NULL } } },
{ { MOD, KEY_PPAGE, }, { scrollback, { "-1" } } },
{ { MOD, KEY_NPAGE, }, { scrollback, { "1" } } },
{ { MOD, KEY_PPAGE, }, { scrollback, { "-2" } } },
{ { MOD, KEY_NPAGE, }, { scrollback, { "2" } } },
{ { MOD, '?', }, { create, { "man dvtm", "dvtm help" } } },
{ { MOD, MOD, }, { send, { (const char []){MOD, 0} } } },
{ { KEY_SPREVIOUS, }, { scrollback, { "-1" } } },
{ { KEY_SNEXT, }, { scrollback, { "1" } } },
{ { KEY_SPREVIOUS, }, { scrollback, { "-2" } } },
{ { KEY_SNEXT, }, { scrollback, { "2" } } },
{ { MOD, '0', }, { view, { NULL } } },
{ { MOD, KEY_F(1), }, { view, { tags[0] } } },
{ { MOD, KEY_F(2), }, { view, { tags[1] } } },
Expand Down Expand Up @@ -177,6 +177,8 @@ static const ColorRule colorrules[] = {

#ifdef NCURSES_MOUSE_VERSION
# define CONFIG_MOUSE /* compile in mouse support if we build against ncurses */
#else
# warning "Compiling without mouse support"
#endif

#define ENABLE_MOUSE true /* whether to enable mouse events by default */
Expand All @@ -187,6 +189,12 @@ static Button buttons[] = {
{ BUTTON1_DOUBLE_CLICKED, { mouse_fullscreen, { "[ ]" } } },
{ BUTTON2_CLICKED, { mouse_zoom, { NULL } } },
{ BUTTON3_CLICKED, { mouse_minimize, { NULL } } },
# if NCURSES_MOUSE_VERSION > 1
{ BUTTON4_PRESSED, { scrollback, { "-4" } } },
{ BUTTON5_PRESSED, { scrollback, { "4" } } },
# else
# warning "Compiling without mouse wheel support"
# endif
};
#endif /* CONFIG_MOUSE */

Expand Down
4 changes: 4 additions & 0 deletions dvtm.1
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ Zoom/cycle current window to/from master area.
.
.It Ic Button3 click
Toggle minimization of current window.
.
.It Ic Button4/Button5 (mouse wheel)
Scroll using the mouse wheel. This is only available if dvtm was compiled
with ncurses version 6 or higher.
.El
.
.
Expand Down
13 changes: 10 additions & 3 deletions dvtm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,13 +1319,19 @@ redraw(const char *args[]) {

static void
scrollback(const char *args[]) {
int div = 0;
if (!is_content_visible(sel))
return;

if (!args[0] || atoi(args[0]) < 0)
vt_scroll(sel->term, -sel->h/2);
if (args[0])
div = atoi(args[0]);
if (!div)
div = -2;

if (div > sel->h)
vt_scroll(sel->term, abs(div)/div);
else
vt_scroll(sel->term, sel->h/2);
vt_scroll(sel->term, sel->h/div);

draw(sel);
curs_set(vt_cursor_visible(sel->term));
Expand Down Expand Up @@ -1635,6 +1641,7 @@ handle_mouse(void) {
#ifdef CONFIG_MOUSE
MEVENT event;
unsigned int i;
debug("mouse\n");
if (getmouse(&event) != OK)
return;
msel = get_client_by_coord(event.x, event.y);
Expand Down

0 comments on commit 630a4cf

Please sign in to comment.