diff options
-rw-r--r-- | src/list_window.c | 30 | ||||
-rw-r--r-- | src/list_window.h | 11 | ||||
-rw-r--r-- | src/screen.c | 22 | ||||
-rw-r--r-- | src/screen.h | 6 | ||||
-rw-r--r-- | src/screen_browser.c | 3 | ||||
-rw-r--r-- | src/screen_play.c | 3 |
6 files changed, 47 insertions, 28 deletions
diff --git a/src/list_window.c b/src/list_window.c index 5ab8f9c9c..215a531dd 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -25,6 +25,7 @@ #include "command.h" #include "colors.h" +#include <assert.h> #include <stdlib.h> #include <unistd.h> #include <string.h> @@ -362,6 +363,35 @@ list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd) return 1; } +#ifdef HAVE_GETMOUSE +int +list_window_mouse(struct list_window *lw, unsigned rows, + unsigned long bstate, int y) +{ + assert(lw != NULL); + + /* if the even occured above the list window move up */ + if (y < 0) { + if (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 ((unsigned)y >= rows) { + if (bstate & BUTTON3_CLICKED) + list_window_last(lw, rows); + else + list_window_next_page(lw, rows); + return 1; + } + + return 0; +} +#endif + list_window_state_t * list_window_init_state(void) { diff --git a/src/list_window.h b/src/list_window.h index ca93971dd..78593948a 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -1,6 +1,7 @@ #ifndef LIST_WINDOW_H #define LIST_WINDOW_H +#include "../config.h" #include "command.h" #include <ncurses.h> @@ -56,6 +57,16 @@ int list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd); int list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd); +#ifdef HAVE_GETMOUSE +/** + * The mouse was clicked. Check if the list should be scrolled + * Returns non-zero if the mouse event has been handled. + */ +int +list_window_mouse(struct list_window *lw, unsigned rows, + unsigned long bstate, int y); +#endif + void list_window_center(struct list_window *lw, unsigned rows, unsigned n); diff --git a/src/screen.c b/src/screen.c index 92ce29e48..a76438b9c 100644 --- a/src/screen.c +++ b/src/screen.c @@ -737,9 +737,7 @@ screen_idle(mpdclient_t *c) #ifdef HAVE_GETMOUSE int -screen_get_mouse_event(mpdclient_t *c, - list_window_t *lw, int lw_length, - unsigned long *bstate, int *row) +screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row) { MEVENT event; @@ -756,24 +754,6 @@ screen_get_mouse_event(mpdclient_t *c, 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 ((unsigned)*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 diff --git a/src/screen.h b/src/screen.h index ca0dd2a0c..6f98d1e4d 100644 --- a/src/screen.h +++ b/src/screen.h @@ -13,8 +13,6 @@ #define MAX_SONGNAME_LENGTH 512 -struct list_window; - struct window { WINDOW *w; int rows, cols; @@ -83,8 +81,6 @@ gint screen_get_id(const char *name); gint get_cur_mode_id(void); -int screen_get_mouse_event(mpdclient_t *c, - struct list_window *lw, int lw_length, - unsigned long *bstate, int *row); +int screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row); #endif diff --git a/src/screen_browser.c b/src/screen_browser.c index 4c8bc2ed6..bbf69c522 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -423,7 +423,8 @@ browser_handle_mouse_event(struct screen_browser *browser, mpdclient_t *c) else length = 0; - if( screen_get_mouse_event(c, browser->lw, length, &bstate, &row) ) + if (screen_get_mouse_event(c, &bstate, &row) || + list_window_mouse(browser->lw, length, bstate, row)) return 1; browser->lw->selected = browser->lw->start + row; diff --git a/src/screen_play.c b/src/screen_play.c index cd43982c3..11d475478 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -422,7 +422,8 @@ handle_mouse_event(mpd_unused screen_t *screen, mpdclient_t *c) unsigned selected; unsigned long bstate; - if (screen_get_mouse_event(c, lw, c->playlist.list->len, &bstate, &row)) + if (screen_get_mouse_event(c, &bstate, &row) || + list_window_mouse(lw, c->playlist.list->len, bstate, row)) return 1; if (bstate & BUTTON1_DOUBLE_CLICKED) { |