diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 7 | ||||
-rw-r--r-- | src/command.h | 1 | ||||
-rw-r--r-- | src/screen.c | 48 | ||||
-rw-r--r-- | src/screen.h | 4 | ||||
-rw-r--r-- | src/screen_file.c | 33 | ||||
-rw-r--r-- | src/screen_play.c | 43 |
6 files changed, 133 insertions, 3 deletions
diff --git a/src/command.c b/src/command.c index 50dcdf7d7..1d77d0d2d 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 593f6993e..db2c9cee0 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 ba155a4cf..7b29f1f1e 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( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS ) { @@ -704,6 +707,49 @@ screen_idle(mpdclient_t *c) seek_id = -1; } +#ifdef HAVE_GETMOUSE +int +screen_get_mouse_event(mpdclient_t *c, + list_window_t *lw, int lw_length, + unsigned long *bstate, int *row) +{ + MEVENT event; + + /* retreive the mouse event from ncurses */ + getmouse(&event); + D("mouse: id=%d y=%d,x=%d,z=%d\n",event.id,event.y,event.x,event.z); + /* calculate the selected row in the list window */ + *row = event.y - screen->top_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 262c6bd7e..d3cad8cb2 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 3fbdf4329..02dc4c4b3 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 20fbe8fe1..e9cb465e2 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; } |