Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default support for scrolling with the mouse wheel. #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad. It will overwrite custom config.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 @@ -1318,13 +1318,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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem right. You compare div, which is essentially compile-time constant with buffer height.

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 @@ -1634,6 +1640,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