Code

Added basic ncurses mouse support
authorKalle Wallin <kaw@linux.se>
Fri, 2 Jul 2004 21:11:56 +0000 (21:11 +0000)
committerKalle Wallin <kaw@linux.se>
Fri, 2 Jul 2004 21:11:56 +0000 (21:11 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1770 09075e82-0dd4-0310-85a5-a0d7c8717e4f

ChangeLog
configure.ac
src/command.c
src/command.h
src/screen.c
src/screen.h
src/screen_file.c
src/screen_play.c

index 4e196633b8d0a684858b0a19f206ae5c920b7bee..c190378f91a40d2b5ecfceff5e94384f055dbfea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 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
index 4aadbeb0b14d6e3e10b7aa1d52880d86e953a6a5..4782abb6494271ae1ce6e60bac372ace18b5b398 100644 (file)
@@ -56,6 +56,11 @@ AC_CHECK_LIB([ncurses],
             [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
index 50dcdf7d777087d408fd7bedb3b516b00d1a2d99..1d77d0d2d4b9d4a413e387c1e4049ed786cddc7e 100644 (file)
@@ -175,8 +175,6 @@ static command_definition_t cmds[] =
     N_("Clock screen") },
 #endif
 
-
-
   { { -1,  -1,  -1 }, 0, CMD_NONE, NULL, NULL }
 };
 
@@ -396,6 +394,11 @@ get_keyboard_command_with_timeout(int ms)
   if( key==ERR )
     return CMD_NONE;
 
+#ifdef HAVE_GETMOUSE
+  if( key==KEY_MOUSE )
+    return CMD_MOUSE_EVENT;
+#endif
+
   return get_key_command(key);
 }
 
index 593f6993ee30bc4b33ab44d2602076912392cb84..db2c9cee0b861fa1339fc3e2cafc72262ac16cdf 100644 (file)
@@ -40,6 +40,7 @@ typedef enum
   CMD_LIST_RFIND_NEXT,
   CMD_LIST_MOVE_UP,
   CMD_LIST_MOVE_DOWN,
+  CMD_MOUSE_EVENT,
   CMD_SCREEN_UPDATE,
   CMD_SCREEN_PREVIOUS,
   CMD_SCREEN_NEXT,
index ba155a4cff4a88fbe74c80c7526f548bd9ecb976..7b29f1f1e17550844d41f9861c35bd58adb785d8 100644 (file)
@@ -474,7 +474,10 @@ screen_init(mpdclient_t *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 )
     {
@@ -704,6 +707,49 @@ screen_idle(mpdclient_t *c)
   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)
 {
index 262c6bd7edf4457d70b0d7d0546af7840fb269cb..d3cad8cb2ff30aa36c47272b6468a80d6db4d3b6 100644 (file)
@@ -99,4 +99,8 @@ void screen_update(mpdclient_t *c);
 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
index 3fbdf4329678d85aceb26021edd397abf8ed55f4..02dc4c4b3feefb390af21a49c3b4d96da72b468b 100644 (file)
@@ -553,6 +553,37 @@ browse_update(screen_t *screen, mpdclient_t *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)
 {
@@ -601,6 +632,8 @@ 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;
     }
index 20fbe8fe12f9797c9f99e2be89e28b743c445d07..e9cb465e2811804b1b30ae27bfe1802ed90ec884 100644 (file)
@@ -367,6 +367,47 @@ play_update(screen_t *screen, mpdclient_t *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)
 {
@@ -403,6 +444,8 @@ 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;
     }