summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0763284)
raw | patch | inline | side by side (parent: 0763284)
author | Max Kellermann <max@duempel.org> | |
Mon, 22 Sep 2008 08:04:46 +0000 (10:04 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 22 Sep 2008 08:04:46 +0000 (10:04 +0200) |
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.
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 5ab8f9c9c125c5ecc628fd050a6de932de327fb8..215a531dd4907a8bcba373c084db1c7706182f55 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
#include "command.h"
#include "colors.h"
+#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
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 ca93971dde2aa5146242a1b1f9c2ed79a96a804e..78593948add8eae7438f33ced05e8278d40c0fdf 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
#ifndef LIST_WINDOW_H
#define LIST_WINDOW_H
+#include "../config.h"
#include "command.h"
#include <ncurses.h>
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 92ce29e484a786dd91f5c5087522c7bfd3292014..a76438b9c6f9b095f016fbaea11d6f364b5cf6c2 100644 (file)
--- a/src/screen.c
+++ b/src/screen.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;
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 ca0dd2a0cdccfefe6e5c941de20a1cb33d9c337e..6f98d1e4d5a238f4b6db32f0a28c2b807a3ae4fe 100644 (file)
--- a/src/screen.h
+++ b/src/screen.h
#define MAX_SONGNAME_LENGTH 512
-struct list_window;
-
struct window {
WINDOW *w;
int rows, cols;
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 4c8bc2ed6cccfd5421a36d51af7aff9be09bdc45..bbf69c5227aa3d3d44bd8033701171f9fd8dbe15 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.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 cd43982c334de9a4252e4b7cba546c3cd7f24dcf..11d4754783d15c855bda56c9e35bdf3f8433eff0 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.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) {