summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8a22ebb)
raw | patch | inline | side by side (parent: 8a22ebb)
author | Kalle Wallin <kaw@linux.se> | |
Fri, 2 Jul 2004 21:11:56 +0000 (21:11 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Fri, 2 Jul 2004 21:11:56 +0000 (21:11 +0000) |
ChangeLog | patch | blob | history | |
configure.ac | patch | blob | history | |
src/command.c | patch | blob | history | |
src/command.h | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/screen.h | patch | blob | history | |
src/screen_file.c | patch | blob | history | |
src/screen_play.c | patch | blob | history |
diff --git a/ChangeLog b/ChangeLog
index 4e196633b8d0a684858b0a19f206ae5c920b7bee..c190378f91a40d2b5ecfceff5e94384f055dbfea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
2004-07-02 Kalle Wallin <kaw@linux.se>
* options.c: improved error handling in the argv parser
+ * screen_play.c: scroll up when moving a item uppwards
+ * mpdclient.c: redesigned the plchanges code (its now based on qball's)
+ * Added ncurses basic mouse support (playlist and browse screens)
2004-07-01 Kalle Wallin <kaw@linux.se>
* support.[c|h]: removed the trim() function
diff --git a/configure.ac b/configure.ac
index 4aadbeb0b14d6e3e10b7aa1d52880d86e953a6a5..4782abb6494271ae1ce6e60bac372ace18b5b398 100644 (file)
--- a/configure.ac
+++ b/configure.ac
[initscr],
[LIBS="$LIBS -lncurses"],
[AC_MSG_ERROR(ncurses library is required)])
+AC_CHECK_LIB([ncurses],
+ [getmouse],
+ [AC_DEFINE([HAVE_GETMOUSE], [1], [ncurses - getmouse()])],
+ [])
+
dnl Check for glib-2.4
diff --git a/src/command.c b/src/command.c
index 50dcdf7d777087d408fd7bedb3b516b00d1a2d99..1d77d0d2d4b9d4a413e387c1e4049ed786cddc7e 100644 (file)
--- a/src/command.c
+++ b/src/command.c
N_("Clock screen") },
#endif
-
-
{ { -1, -1, -1 }, 0, CMD_NONE, NULL, NULL }
};
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 593f6993ee30bc4b33ab44d2602076912392cb84..db2c9cee0b861fa1339fc3e2cafc72262ac16cdf 100644 (file)
--- a/src/command.h
+++ b/src/command.h
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 ba155a4cff4a88fbe74c80c7526f548bd9ecb976..7b29f1f1e17550844d41f9861c35bd58adb785d8 100644 (file)
--- a/src/screen.c
+++ b/src/screen.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 )
{
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 262c6bd7edf4457d70b0d7d0546af7840fb269cb..d3cad8cb2ff30aa36c47272b6468a80d6db4d3b6 100644 (file)
--- a/src/screen.h
+++ b/src/screen.h
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 3fbdf4329678d85aceb26021edd397abf8ed55f4..02dc4c4b3feefb390af21a49c3b4d96da72b468b 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.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)
{
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 20fbe8fe12f9797c9f99e2be89e28b743c445d07..e9cb465e2811804b1b30ae27bfe1802ed90ec884 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.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)
{
return screen_find(screen, c,
lw, c->playlist.length,
cmd, list_callback);
+ case CMD_MOUSE_EVENT:
+ return handle_mouse_event(screen,c);
default:
break;
}