Code

screen_interface: add method mouse(), replacing CMD_MOUSE_EVENT
[ncmpc.git] / src / screen.h
index c725bb13c64258ce4abdb7b12b4bfc32d696dbe5..3d7bc3922f0e8ac2d45565d65f5eceb3bb933fa1 100644 (file)
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
 #ifndef SCREEN_H
 #define SCREEN_H
-#include <ncurses.h>
-#include "list_window.h"
 
-/* minumum window size */
-#define SCREEN_MIN_COLS 14
-#define SCREEN_MIN_ROWS  5
+#include "config.h"
+#include "command.h"
+#include "window.h"
+#include "title_bar.h"
+#include "progress_bar.h"
+#include "status_bar.h"
+#include "ncmpc_curses.h"
 
-#define IS_PLAYING(s) (s==MPD_STATUS_STATE_PLAY)
-#define IS_PAUSED(s) (s==MPD_STATUS_STATE_PAUSE)
-#define IS_STOPPED(s) (!(IS_PLAYING(s) | IS_PAUSED(s)))
+#include <mpd/client.h>
 
+#include <glib.h>
 
-typedef enum
-{
-  SCREEN_PLAY_WINDOW = 0,
-  SCREEN_FILE_WINDOW,
-  SCREEN_HELP_WINDOW,
-  SCREEN_KEYDEF_WINDOW,
-  SCREEN_CLOCK_WINDOW,
-  SCREEN_SEARCH_WINDOW
+#include <stdbool.h>
 
-} screen_mode_t;
+struct mpdclient;
+struct screen_functions;
 
-typedef struct
-{
-  WINDOW *w;
-  int rows, cols;
+struct screen {
+       struct title_bar title_bar;
+       struct window main_window;
+       struct progress_bar progress_bar;
+       struct status_bar status_bar;
 
-} window_t;
+       const struct screen_functions *current_page;
 
+       char *buf;
+       size_t buf_size;
 
+       char *findbuf;
+       GList *find_history;
 
-typedef struct
-{
-  window_t top_window;
-  window_t main_window;
-  window_t progress_window;
-  window_t status_window;
-
-  GList *screen_list;
-
-  /* GTime is equivalent to time_t */
-  GTime start_timestamp;
-  GTime status_timestamp;
-  GTime input_timestamp;
-  GTime last_cmd;
-
-  int cols, rows;
+#ifndef NCMPC_MINI
+       /**
+        * Non-zero when the welcome message is currently being
+        * displayed.  The associated timer will disable it.
+        */
+       guint welcome_source_id;
+#endif
+};
 
-  screen_mode_t mode;
+extern struct screen screen;
 
-  char *buf;
-  size_t buf_size;
+void screen_init(struct mpdclient *c);
+void screen_exit(void);
+void screen_resize(struct mpdclient *c);
 
-  char *findbuf;
-  GList *find_history;
+void
+paint_top_window(const struct mpdclient *c);
 
-  int painted;
+void
+screen_paint(struct mpdclient *c, bool main_dirty);
 
-} screen_t;
+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
 
-typedef void (*screen_init_fn_t)   (WINDOW *w, int cols, int rows);
-typedef void (*screen_exit_fn_t)   (void);
-typedef void (*screen_open_fn_t)   (screen_t *screen, mpdclient_t *c);
-typedef void (*screen_close_fn_t)  (void);
-typedef void (*screen_resize_fn_t)   (int cols, int rows);
-typedef void (*screen_paint_fn_t)  (screen_t *screen, mpdclient_t *c);
-typedef void (*screen_update_fn_t) (screen_t *screen, mpdclient_t *c);
-typedef int (*screen_cmd_fn_t) (screen_t *scr, mpdclient_t *c, command_t cmd);
-typedef char * (*screen_title_fn_t) (char *s, size_t size);
-typedef list_window_t * (*screen_get_lw_fn_t) (void);
+void
+screen_switch(const struct screen_functions *sf, struct mpdclient *c);
+void 
+screen_swap(struct mpdclient *c, const struct mpd_song *song);
 
-typedef struct
+static inline bool
+screen_is_visible(const struct screen_functions *sf)
 {
-  screen_init_fn_t   init;
-  screen_exit_fn_t   exit;
-  screen_open_fn_t   open;
-  screen_close_fn_t  close;
-  screen_resize_fn_t resize;
-  screen_paint_fn_t  paint;
-  screen_update_fn_t update;
-  screen_cmd_fn_t    cmd;
-  screen_title_fn_t  get_title;
-  screen_get_lw_fn_t get_lw;
-
-} screen_functions_t;
-
-
-int screen_init(mpdclient_t *c);
-int screen_exit(void);
-void screen_resize(void);
-void screen_status_message(char *msg);
-void screen_status_printf(char *format, ...);
-char *screen_error(void);
-void screen_paint(mpdclient_t *c);
-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);
+       return sf == screen.current_page;
+}
 
 #endif