From: Kalle Wallin Date: Fri, 2 Jul 2004 21:11:56 +0000 (+0000) Subject: Added basic ncurses mouse support X-Git-Tag: v0.12_alpha1~480 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b268b9992faa303d6283c5a88ba460b5fd73cef6;p=ncmpc.git Added basic ncurses mouse support git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1770 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- diff --git a/ChangeLog b/ChangeLog index 4e19663..c190378 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2004-07-02 Kalle Wallin * options.c: improved error handling in the argv parser + * screen_play.c: scroll up when moving a item uppwards + * mpdclient.c: redesigned the plchanges code (its now based on qball's) + * Added ncurses basic mouse support (playlist and browse screens) 2004-07-01 Kalle Wallin * support.[c|h]: removed the trim() function diff --git a/configure.ac b/configure.ac index 4aadbeb..4782abb 100644 --- a/configure.ac +++ b/configure.ac @@ -56,6 +56,11 @@ AC_CHECK_LIB([ncurses], [initscr], [LIBS="$LIBS -lncurses"], [AC_MSG_ERROR(ncurses library is required)]) +AC_CHECK_LIB([ncurses], + [getmouse], + [AC_DEFINE([HAVE_GETMOUSE], [1], [ncurses - getmouse()])], + []) + dnl Check for glib-2.4 diff --git a/src/command.c b/src/command.c index 50dcdf7..1d77d0d 100644 --- a/src/command.c +++ b/src/command.c @@ -175,8 +175,6 @@ static command_definition_t cmds[] = N_("Clock screen") }, #endif - - { { -1, -1, -1 }, 0, CMD_NONE, NULL, NULL } }; @@ -396,6 +394,11 @@ get_keyboard_command_with_timeout(int ms) if( key==ERR ) return CMD_NONE; +#ifdef HAVE_GETMOUSE + if( key==KEY_MOUSE ) + return CMD_MOUSE_EVENT; +#endif + return get_key_command(key); } diff --git a/src/command.h b/src/command.h index 593f699..db2c9ce 100644 --- a/src/command.h +++ b/src/command.h @@ -40,6 +40,7 @@ typedef enum CMD_LIST_RFIND_NEXT, CMD_LIST_MOVE_UP, CMD_LIST_MOVE_DOWN, + CMD_MOUSE_EVENT, CMD_SCREEN_UPDATE, CMD_SCREEN_PREVIOUS, CMD_SCREEN_NEXT, diff --git a/src/screen.c b/src/screen.c index ba155a4..7b29f1f 100644 --- a/src/screen.c +++ b/src/screen.c @@ -474,7 +474,10 @@ screen_init(mpdclient_t *c) keypad(stdscr, TRUE); /* return from getch() without blocking */ timeout(SCREEN_TIMEOUT); - + /* initialize mouse support */ +#ifdef HAVE_GETMOUSE + mousemask(ALL_MOUSE_EVENTS, NULL); +#endif if( COLStop_window.rows; + /* copy button state bits */ + *bstate = event.bstate; + /* if button 2 was pressed switch screen */ + if( event.bstate & BUTTON2_CLICKED ) + { + screen_cmd(c, CMD_SCREEN_NEXT); + return 1; + } + /* if the even occured above the list window move up */ + if( *row<0 && lw ) + { + if( event.bstate & BUTTON3_CLICKED ) + list_window_first(lw); + else + list_window_previous_page(lw); + return 1; + } + /* if the even occured below the list window move down */ + if( *row>=lw->rows && lw ) + { + if( event.bstate & BUTTON3_CLICKED ) + list_window_last(lw, lw_length); + else + list_window_next_page(lw, lw_length); + return 1; + } + return 0; +} +#endif + void screen_cmd(mpdclient_t *c, command_t cmd) { diff --git a/src/screen.h b/src/screen.h index 262c6bd..d3cad8c 100644 --- a/src/screen.h +++ b/src/screen.h @@ -99,4 +99,8 @@ void screen_update(mpdclient_t *c); void screen_idle(mpdclient_t *c); void screen_cmd(mpdclient_t *c, command_t cmd); +int screen_get_mouse_event(mpdclient_t *c, + list_window_t *lw, int lw_length, + unsigned long *bstate, int *row); + #endif diff --git a/src/screen_file.c b/src/screen_file.c index 3fbdf43..02dc4c4 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -553,6 +553,37 @@ browse_update(screen_t *screen, mpdclient_t *c) } +#ifdef HAVE_GETMOUSE +static int +handle_mouse_event(screen_t *screen, mpdclient_t *c) +{ + int row; + int prev_selected = lw->selected; + unsigned long bstate; + + if( screen_get_mouse_event(c, lw, filelist->length, &bstate, &row) ) + return 1; + + lw->selected = lw->start+row; + list_window_check_selected(lw, filelist->length); + + if( bstate & BUTTON1_CLICKED ) + { + if( prev_selected == lw->selected ) + handle_enter(screen, c); + } + else if( bstate & BUTTON3_CLICKED ) + { + if( prev_selected == lw->selected ) + handle_select(screen, c); + } + + return 1; +} +#else +#define handle_mouse_event(s,c) (0) +#endif + static int browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) { @@ -601,6 +632,8 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) return screen_find(screen, c, lw, filelist->length, cmd, list_callback); + case CMD_MOUSE_EVENT: + return handle_mouse_event(screen,c); default: break; } diff --git a/src/screen_play.c b/src/screen_play.c index 20fbe8f..e9cb465 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -367,6 +367,47 @@ play_update(screen_t *screen, mpdclient_t *c) } } +#ifdef HAVE_GETMOUSE +static int +handle_mouse_event(screen_t *screen, mpdclient_t *c) +{ + int row; + int selected; + unsigned long bstate; + + if( screen_get_mouse_event(c, lw, c->playlist.length, &bstate, &row) ) + return 1; + + if( bstate & BUTTON1_DOUBLE_CLICKED ) + { + /* stop */ + screen_cmd(c, CMD_STOP); + return 1; + } + + selected = lw->start+row; + + if( bstate & BUTTON1_CLICKED ) + { + /* play */ + if( lw->start+row < c->playlist.length ) + mpdclient_cmd_play(c, lw->start+row); + } + else if( bstate & BUTTON3_CLICKED ) + { + /* delete */ + if( selected == lw->selected ) + mpdclient_cmd_delete(c, lw->selected); + } + lw->selected = selected; + list_window_check_selected(lw, c->playlist.length); + + return 1; +} +#else +#define handle_mouse_event(s,c) (0) +#endif + static int play_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) { @@ -403,6 +444,8 @@ play_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) return screen_find(screen, c, lw, c->playlist.length, cmd, list_callback); + case CMD_MOUSE_EVENT: + return handle_mouse_event(screen,c); default: break; }