From: Max Kellermann Date: Mon, 22 Sep 2008 08:04:46 +0000 (+0200) Subject: screen: moved list_window mouse code to list_window.c X-Git-Tag: v0.12_alpha1~192 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;ds=sidebyside;h=e6d6231b4de336f60bc5b07331e2f1f01096c66c;p=ncmpc.git screen: moved list_window mouse code to list_window.c Move the portion of screen_get_mouse_event() which handles list_window clicks to list_window.c. The code contained a NULL pointer dereference, which is now fixed. --- diff --git a/src/list_window.c b/src/list_window.c index 5ab8f9c..215a531 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -25,6 +25,7 @@ #include "command.h" #include "colors.h" +#include #include #include #include @@ -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 ca93971..7859394 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 @@ -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 92ce29e..a76438b 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 ca0dd2a..6f98d1e 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 4c8bc2e..bbf69c5 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 cd43982..11d4754 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) {