summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 52abee9)
raw | patch | inline | side by side (parent: 52abee9)
author | Max Kellermann <max.kellermann@gmail.com> | |
Wed, 2 Aug 2017 07:51:31 +0000 (09:51 +0200) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Wed, 2 Aug 2017 07:51:31 +0000 (09:51 +0200) |
13 files changed:
diff --git a/src/command.h b/src/command.h
index 1d6b6babcf8721b02ed1f97a0017d368bab2ba18..aa794c64cded5415e9c5cd521cb5c3eaddf6b00d 100644 (file)
--- a/src/command.h
+++ b/src/command.h
CMD_LIST_SCROLL_DOWN_LINE,
CMD_LIST_SCROLL_UP_HALF,
CMD_LIST_SCROLL_DOWN_HALF,
- CMD_MOUSE_EVENT,
CMD_SCREEN_UPDATE,
CMD_SCREEN_PREVIOUS,
CMD_SCREEN_NEXT,
diff --git a/src/keyboard.c b/src/keyboard.c
index e2234f3cee8a7e2373cce1d9af6da82b385f1164..86f2afe1fe84616dd0828b1ea3c6a747e9e1de10 100644 (file)
--- a/src/keyboard.c
+++ b/src/keyboard.c
static command_t
translate_key(int key)
{
-#ifdef HAVE_GETMOUSE
- if (key == KEY_MOUSE)
- return CMD_MOUSE_EVENT;
-#endif
-
return get_key_command(key);
}
if (ignore_key(key))
return true;
+#ifdef HAVE_GETMOUSE
+ if (key == KEY_MOUSE) {
+ MEVENT event;
+
+ /* retrieve the mouse event from curses */
+#ifdef PDCURSES
+ nc_getmouse(&event);
+#else
+ getmouse(&event);
+#endif
+
+ begin_input_event();
+ do_mouse_event(event.x, event.y, event.bstate);
+ end_input_event();
+
+ return true;
+ }
+#endif
+
command_t cmd = translate_key(key);
if (cmd == CMD_NONE)
return true;
diff --git a/src/main.c b/src/main.c
index 11e46e4a698bef6c81717468ed20ea72cc446e44..eccb5a004c8a114f98966270447278dcbdbf439d 100644 (file)
--- a/src/main.c
+++ b/src/main.c
return true;
}
+#ifdef HAVE_GETMOUSE
+
+void
+do_mouse_event(int x, int y, mmask_t bstate)
+{
+ screen_mouse(mpd, x, y, bstate);
+}
+
+#endif
+
#ifndef NCMPC_MINI
/**
* Check the configured key bindings for errors, and display a status
diff --git a/src/ncmpc.h b/src/ncmpc.h
index 2ca79ad55b2f1e07f024743aeae312a4c20c4e4b..2cc778f416890ccd0778e0167ab30d7954a87feb 100644 (file)
--- a/src/ncmpc.h
+++ b/src/ncmpc.h
#include "command.h"
+#ifdef HAVE_GETMOUSE
+#include "ncmpc_curses.h"
+#endif
+
#include <stdbool.h>
void begin_input_event(void);
bool
do_input_event(command_t cmd);
+#ifdef HAVE_GETMOUSE
+void
+do_mouse_event(int x, int y, mmask_t bstate);
+#endif
+
#endif /* NCMPC_H */
diff --git a/src/screen.c b/src/screen.c
index 6d2610ad1770e461bd72a503ada7a016407bec3e..abd241d16e14e84981ed686fe7e12d3a99442627 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
screen_paint(c, false);
}
-#ifdef HAVE_GETMOUSE
-int
-screen_get_mouse_event(struct mpdclient *c, unsigned long *bstate, int *row)
-{
- MEVENT event;
-
- /* retrieve the mouse event from curses */
-#ifdef PDCURSES
- nc_getmouse(&event);
-#else
- getmouse(&event);
-#endif
- /* calculate the selected row in the list window */
- *row = event.y - screen.title_bar.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;
- }
-
- return 0;
-}
-#endif
-
void
screen_cmd(struct mpdclient *c, command_t cmd)
{
break;
}
}
+
+#ifdef HAVE_GETMOUSE
+
+static bool
+screen_current_page_mouse(struct mpdclient *c, int x, int y, mmask_t bstate)
+{
+ if (screen.current_page->mouse == NULL)
+ return false;
+
+ y -= screen.title_bar.window.rows;
+ return screen.current_page->mouse(c, x, y, bstate);
+}
+
+bool
+screen_mouse(struct mpdclient *c, int x, int y, mmask_t bstate)
+{
+ if (screen_current_page_mouse(c, x, y, bstate))
+ return true;
+
+ /* if button 2 was pressed switch screen */
+ if (bstate & BUTTON2_CLICKED) {
+ screen_cmd(c, CMD_SCREEN_NEXT);
+ return true;
+ }
+
+ return false;
+}
+
+#endif
diff --git a/src/screen.h b/src/screen.h
index 8a91d46279254a7205a16af18d899196de787d2e..3d7bc3922f0e8ac2d45565d65f5eceb3bb933fa1 100644 (file)
--- a/src/screen.h
+++ b/src/screen.h
void screen_update(struct mpdclient *c);
void screen_cmd(struct mpdclient *c, command_t cmd);
+#ifdef HAVE_GETMOUSE
+bool
+screen_mouse(struct mpdclient *c, int x, int y, mmask_t bstate);
+#endif
+
void
screen_switch(const struct screen_functions *sf, struct mpdclient *c);
void
return sf == screen.current_page;
}
-int
-screen_get_mouse_event(struct mpdclient *c, unsigned long *bstate, int *row);
-
#endif
diff --git a/src/screen_artist.c b/src/screen_artist.c
index 2190cbbff54a7f3b4aed0068a47f9cb7d4c52df0..672c93f33c366f0b35f206d86e369911bf07dd19 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
return false;
}
+#ifdef HAVE_GETMOUSE
+static bool
+screen_artist_mouse(struct mpdclient *c, int x, int y, mmask_t bstate)
+{
+ if (browser_mouse(&browser, c, x, y, bstate)) {
+ if (screen_is_visible(&screen_artist))
+ screen_artist_paint();
+
+ return true;
+ }
+
+ return false;
+}
+#endif
+
const struct screen_functions screen_artist = {
.init = screen_artist_init,
.exit = screen_artist_quit,
.paint = screen_artist_paint,
.update = screen_artist_update,
.cmd = screen_artist_cmd,
+#ifdef HAVE_GETMOUSE
+ .mouse = screen_artist_mouse,
+#endif
.get_title = screen_artist_get_title,
};
diff --git a/src/screen_browser.c b/src/screen_browser.c
index c38ae9ea81490f539723a4e7e6dd2e8da0fc76d8..e0c37cbc2e0a48a04e1a66ee3be030b6aad6786a 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
@@ -351,16 +351,15 @@ browser_handle_select_all(struct screen_browser *browser, struct mpdclient *c)
}
#ifdef HAVE_GETMOUSE
-static int
-browser_handle_mouse_event(struct screen_browser *browser, struct mpdclient *c)
+
+bool
+browser_mouse(struct screen_browser *browser,
+ struct mpdclient *c, gcc_unused int x, int row, mmask_t bstate)
{
- int row;
unsigned prev_selected = browser->lw->selected;
- unsigned long bstate;
- if (screen_get_mouse_event(c, &bstate, &row) ||
- list_window_mouse(browser->lw, bstate, row))
- return 1;
+ if (list_window_mouse(browser->lw, bstate, row))
+ return true;
list_window_set_cursor(browser->lw, browser->lw->start + row);
browser_handle_select(browser, c);
}
- return 1;
+ return true;
}
+
#endif
static void
screen_browser_paint_callback, browser);
return true;
-#ifdef HAVE_GETMOUSE
- case CMD_MOUSE_EVENT:
- browser_handle_mouse_event(browser, c);
- return true;
-#endif
-
#ifdef ENABLE_SONG_SCREEN
case CMD_SCREEN_SONG:
song = browser_get_selected_song(browser);
diff --git a/src/screen_browser.h b/src/screen_browser.h
index e972bd5855d64ee9f4aa8e03167dbbf621009406..82d6ffa4afe78bc9ade37321790e4d1eada094a5 100644 (file)
--- a/src/screen_browser.h
+++ b/src/screen_browser.h
void
screen_browser_paint(const struct screen_browser *browser);
-struct filelist_entry *
-browser_get_selected_entry(const struct screen_browser *browser);
+#ifdef HAVE_GETMOUSE
+bool
+browser_mouse(struct screen_browser *browser,
+ struct mpdclient *c, int x, int y, mmask_t bstate);
+#endif
bool
browser_cmd(struct screen_browser *browser,
struct mpdclient *c, command_t cmd);
+struct filelist_entry *
+browser_get_selected_entry(const struct screen_browser *browser);
+
#endif
diff --git a/src/screen_file.c b/src/screen_file.c
index b23a1c84a1363126d3a55aeb2d119997407500da..d55684c3d06cd86d6641e236a9026350516af0d1 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
return false;
}
+#ifdef HAVE_GETMOUSE
+static bool
+screen_file_mouse(struct mpdclient *c, int x, int y, mmask_t bstate)
+{
+ if (browser_mouse(&browser, c, x, y, bstate)) {
+ if (screen_is_visible(&screen_browse))
+ screen_file_paint();
+ return true;
+ }
+
+ return false;
+}
+#endif
+
const struct screen_functions screen_browse = {
.init = screen_file_init,
.exit = screen_file_exit,
.paint = screen_file_paint,
.update = screen_file_update,
.cmd = screen_file_cmd,
+#ifdef HAVE_GETMOUSE
+ .mouse = screen_file_mouse,
+#endif
.get_title = screen_file_get_title,
};
diff --git a/src/screen_interface.h b/src/screen_interface.h
index 82962420f8c064ce11a90ae3e14e6e7b2910d31d..e11813a10f88ca1395ae773d63d9164faf2758da 100644 (file)
--- a/src/screen_interface.h
+++ b/src/screen_interface.h
*/
bool (*cmd)(struct mpdclient *c, command_t cmd);
+#ifdef HAVE_GETMOUSE
+ /**
+ * Handle a mouse event.
+ *
+ * @return true if the event was handled (and should not be
+ * handled by the ncmpc core)
+ */
+ bool (*mouse)(struct mpdclient *c, int x, int y, mmask_t bstate);
+#endif
+
const char *(*get_title)(char *s, size_t size);
};
diff --git a/src/screen_queue.c b/src/screen_queue.c
index dd27df04cce48fd6c1fd5a6ea9dc581aed72021c..5e43b03a490767f4fe5d16ff9ed32d3aaf25410e 100644 (file)
--- a/src/screen_queue.c
+++ b/src/screen_queue.c
#ifdef HAVE_GETMOUSE
static bool
-handle_mouse_event(struct mpdclient *c)
+screen_queue_mouse(struct mpdclient *c, gcc_unused int x, int row,
+ mmask_t bstate)
{
- unsigned long bstate;
- int row;
- if (screen_get_mouse_event(c, &bstate, &row) ||
- list_window_mouse(lw, bstate, row)) {
+ if (list_window_mouse(lw, bstate, row)) {
screen_queue_paint();
return true;
}
screen_queue_paint();
return true;
-#ifdef HAVE_GETMOUSE
- case CMD_MOUSE_EVENT:
- return handle_mouse_event(c);
-#endif
-
#ifdef ENABLE_SONG_SCREEN
case CMD_SCREEN_SONG:
if (screen_queue_selected_song() != NULL) {
.paint = screen_queue_paint,
.update = screen_queue_update,
.cmd = screen_queue_cmd,
+#ifdef HAVE_GETMOUSE
+ .mouse = screen_queue_mouse,
+#endif
.get_title = screen_queue_title,
};
diff --git a/src/screen_search.c b/src/screen_search.c
index 30be533baf66d63875173637ce0f0a5858e8035a..4ba3c826b9ad52669f5b8e4515d92354b73a3c9a 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
return false;
}
+#ifdef HAVE_GETMOUSE
+static bool
+screen_search_mouse(struct mpdclient *c, int x, int y, mmask_t bstate)
+{
+ if (browser_mouse(&browser, c, x, y, bstate)) {
+ if (screen_is_visible(&screen_search))
+ screen_search_paint();
+
+ return true;
+ }
+
+ return false;
+}
+#endif
+
const struct screen_functions screen_search = {
.init = screen_search_init,
.exit = screen_search_quit,
.paint = screen_search_paint,
.update = screen_search_update,
.cmd = screen_search_cmd,
+#ifdef HAVE_GETMOUSE
+ .mouse = screen_search_mouse,
+#endif
.get_title = screen_search_get_title,
};