summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: eb14b27)
raw | patch | inline | side by side (parent: eb14b27)
author | Max Kellermann <max@duempel.org> | |
Wed, 30 Sep 2009 06:22:08 +0000 (08:22 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Wed, 30 Sep 2009 06:22:08 +0000 (08:22 +0200) |
Makefile.am | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/screen.h | patch | blob | history | |
src/title_bar.c | [new file with mode: 0644] | patch | blob |
src/title_bar.h | [new file with mode: 0644] | patch | blob |
diff --git a/Makefile.am b/Makefile.am
index 5111564769fbac6d99fc52f8a1393614e8a60c37..0a12f3ae49bc5a4c876ea376777eb55e4e3a3074 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
src/ncu.h \
src/player_command.h \
src/window.h \
+ src/title_bar.h \
src/progress_bar.h \
src/screen.h \
src/screen_list.h \
src/command.c \
src/ncu.c \
src/player_command.c \
+ src/title_bar.c \
src/progress_bar.c \
src/screen.c \
src/screen_list.c \
diff --git a/src/screen.c b/src/screen.c
index a4f0a89eb26bc730d45fec68c22c1cc527b1a512..9001c71ffeb73ed3a22301df965674d11b5a0259 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
screen_switch(sf, c);
}
-#ifndef NCMPC_MINI
-static void
-print_hotkey(WINDOW *w, command_t cmd, const char *label)
-{
- colors_use(w, COLOR_TITLE_BOLD);
- waddstr(w, get_key_names(cmd, FALSE));
- colors_use(w, COLOR_TITLE);
- waddch(w, ':');
- waddstr(w, label);
- waddch(w, ' ');
- waddch(w, ' ');
-}
-#endif
-
-static inline int
-get_volume(const struct mpd_status *status)
-{
- return status != NULL
- ? mpd_status_get_volume(status)
- : -1;
-}
-
-static void
-paint_top_window2(const char *header, struct mpdclient *c)
-{
- int volume;
- char flags[5];
- WINDOW *w = screen.top_window.w;
- char buf[32];
-
- if (header[0]) {
- colors_use(w, COLOR_TITLE_BOLD);
- mvwaddstr(w, 0, 0, header);
-#ifndef NCMPC_MINI
- } else {
-#ifdef ENABLE_HELP_SCREEN
- print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
-#endif
- print_hotkey(w, CMD_SCREEN_PLAY, _("Playlist"));
- print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
-#ifdef ENABLE_ARTIST_SCREEN
- print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
-#endif
-#ifdef ENABLE_SEARCH_SCREEN
- print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
-#endif
-#ifdef ENABLE_LYRICS_SCREEN
- print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
-#endif
-#ifdef ENABLE_OUTPUTS_SCREEN
- print_hotkey(w, CMD_SCREEN_OUTPUTS, _("Outputs"));
-#endif
-#endif
- }
-
- volume = get_volume(c->status);
- if (volume < 0)
- g_snprintf(buf, 32, _("Volume n/a"));
- else
- g_snprintf(buf, 32, _("Volume %d%%"), volume);
-
- colors_use(w, COLOR_TITLE);
- mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
-
- flags[0] = 0;
- if (c->status != NULL) {
- if (mpd_status_get_repeat(c->status))
- g_strlcat(flags, "r", sizeof(flags));
- if (mpd_status_get_random(c->status))
- g_strlcat(flags, "z", sizeof(flags));
- if (mpd_status_get_single(c->status))
- g_strlcat(flags, "s", sizeof(flags));
- if (mpd_status_get_consume(c->status))
- g_strlcat(flags, "c", sizeof(flags));
- if (mpd_status_get_crossfade(c->status))
- g_strlcat(flags, "x", sizeof(flags));
- if (mpd_status_get_update_id(c->status) != 0)
- g_strlcat(flags, "U", sizeof(flags));
- }
-
- colors_use(w, COLOR_LINE);
- mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
- if (flags[0]) {
- wmove(w,1,screen.top_window.cols-strlen(flags)-3);
- waddch(w, '[');
- colors_use(w, COLOR_LINE_BOLD);
- waddstr(w, flags);
- colors_use(w, COLOR_LINE);
- waddch(w, ']');
- }
- wnoutrefresh(w);
-}
-
static inline int
volume_length(int volume)
{
}
static void
-paint_top_window(const char *header, struct mpdclient *c, int full_repaint)
+paint_top_window(const char *header, const struct mpdclient *c)
{
- static int prev_volume = -1;
- static unsigned prev_header_len = -1;
- WINDOW *w = screen.top_window.w;
-
- if (prev_header_len != utf8_width(header)) {
- prev_header_len = utf8_width(header);
- full_repaint = 1;
- }
-
- if (c->status &&
- volume_length(prev_volume) !=
- volume_length(mpd_status_get_volume(c->status)))
- full_repaint = 1;
-
- if (full_repaint) {
- wmove(w, 0, 0);
- wclrtoeol(w);
- }
-
- if ((c->status != NULL &&
- prev_volume != mpd_status_get_volume(c->status)) ||
- full_repaint)
- paint_top_window2(header, c);
+ title_bar_paint(&screen.title_bar, header, c->status);
}
static void
g_free(screen.buf);
g_free(screen.findbuf);
- delwin(screen.top_window.w);
+ title_bar_deinit(&screen.title_bar);
delwin(screen.main_window.w);
progress_bar_deinit(&screen.progress_bar);
delwin(screen.status_window.w);
screen.cols = COLS;
screen.rows = LINES;
- /* top window */
- screen.top_window.cols = screen.cols;
- wresize(screen.top_window.w, 2, screen.cols);
+ title_bar_resize(&screen.title_bar, screen.cols);
/* main window */
screen.main_window.cols = screen.cols;
screen.start_timestamp = time(NULL);
/* create top window */
- window_init(&screen.top_window, 2, screen.cols, 0, 0);
- leaveok(screen.top_window.w, TRUE);
- keypad(screen.top_window.w, TRUE);
+ title_bar_init(&screen.title_bar, screen.cols, 0, 0);
/* create main window */
window_init(&screen.main_window, screen.rows - 4, screen.cols, 2, 0);
/* set background attributes */
wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
- wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE));
+ wbkgd(screen.title_bar.window.w, COLOR_PAIR(COLOR_TITLE));
wbkgd(screen.progress_bar.window.w,
COLOR_PAIR(COLOR_PROGRESSBAR));
wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS));
/* paint the title/header window */
if( title )
- paint_top_window(title, c, 1);
+ paint_top_window(title, c);
else
- paint_top_window("", c, 1);
+ paint_top_window("", c);
/* paint the bottom window */
/* update title/header window */
if (welcome && options.welcome_screen_list &&
time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
- paint_top_window("", c, 0);
+ paint_top_window("", c);
else
#endif
if (mode_fn->get_title != NULL) {
- paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
+ paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c);
#ifndef NCMPC_MINI
welcome = FALSE;
#endif
} else
- paint_top_window("", c, 0);
+ paint_top_window("", c);
/* update progress window */
paint_progress_window(c);
/* retrieve the mouse event from ncurses */
getmouse(&event);
/* calculate the selected row in the list window */
- *row = event.y - screen.top_window.rows;
+ *row = event.y - screen.title_bar.window.rows;
/* copy button state bits */
*bstate = event.bstate;
/* if button 2 was pressed switch screen */
diff --git a/src/screen.h b/src/screen.h
index 6b7d1a99b01f1a1bddd8383fb0097b93537dffff..57214c507435bef87a821d3659f137405c0051d1 100644 (file)
--- a/src/screen.h
+++ b/src/screen.h
#include "config.h"
#include "command.h"
#include "window.h"
+#include "title_bar.h"
#include "progress_bar.h"
#include <mpd/client.h>
struct mpdclient;
struct screen {
- struct window top_window;
+ struct title_bar title_bar;
struct window main_window;
struct progress_bar progress_bar;
struct window status_window;
diff --git a/src/title_bar.c b/src/title_bar.c
--- /dev/null
+++ b/src/title_bar.c
@@ -0,0 +1,140 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 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.
+ */
+
+#include "title_bar.h"
+#include "colors.h"
+#include "command.h"
+#include "i18n.h"
+#include "charset.h"
+
+#include <mpd/client.h>
+
+#include <glib.h>
+
+#include <assert.h>
+#include <string.h>
+
+#ifndef NCMPC_MINI
+static void
+print_hotkey(WINDOW *w, command_t cmd, const char *label)
+{
+ colors_use(w, COLOR_TITLE_BOLD);
+ waddstr(w, get_key_names(cmd, FALSE));
+ colors_use(w, COLOR_TITLE);
+ waddch(w, ':');
+ waddstr(w, label);
+ waddch(w, ' ');
+ waddch(w, ' ');
+}
+#endif
+
+static inline int
+get_volume(const struct mpd_status *status)
+{
+ return status != NULL
+ ? mpd_status_get_volume(status)
+ : -1;
+}
+
+void
+title_bar_paint(const struct title_bar *p, const char *title,
+ const struct mpd_status *status)
+{
+ WINDOW *w = p->window.w;
+ int volume;
+ char flags[5];
+ char buf[32];
+
+ assert(p != NULL);
+
+ wmove(w, 0, 0);
+ wclrtoeol(w);
+
+ if (title[0]) {
+ colors_use(w, COLOR_TITLE_BOLD);
+ mvwaddstr(w, 0, 0, title);
+#ifndef NCMPC_MINI
+ } else {
+#ifdef ENABLE_HELP_SCREEN
+ print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
+#endif
+ print_hotkey(w, CMD_SCREEN_PLAY, _("Playlist"));
+ print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
+#ifdef ENABLE_ARTIST_SCREEN
+ print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
+#endif
+#ifdef ENABLE_SEARCH_SCREEN
+ print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
+#endif
+#ifdef ENABLE_LYRICS_SCREEN
+ print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
+#endif
+#ifdef ENABLE_OUTPUTS_SCREEN
+ print_hotkey(w, CMD_SCREEN_OUTPUTS, _("Outputs"));
+#endif
+#endif
+ }
+
+ volume = get_volume(status);
+ if (volume < 0)
+ g_snprintf(buf, 32, _("Volume n/a"));
+ else
+ g_snprintf(buf, 32, _("Volume %d%%"), volume);
+
+ colors_use(w, COLOR_TITLE);
+ mvwaddstr(w, 0, p->window.cols - utf8_width(buf), buf);
+
+ flags[0] = 0;
+ if (status != NULL) {
+ if (mpd_status_get_repeat(status))
+ g_strlcat(flags, "r", sizeof(flags));
+ if (mpd_status_get_random(status))
+ g_strlcat(flags, "z", sizeof(flags));
+ if (mpd_status_get_single(status))
+ g_strlcat(flags, "s", sizeof(flags));
+ if (mpd_status_get_consume(status))
+ g_strlcat(flags, "c", sizeof(flags));
+ if (mpd_status_get_crossfade(status))
+ g_strlcat(flags, "x", sizeof(flags));
+ if (mpd_status_get_update_id(status) != 0)
+ g_strlcat(flags, "U", sizeof(flags));
+ }
+
+ colors_use(w, COLOR_LINE);
+ mvwhline(w, 1, 0, ACS_HLINE, p->window.cols);
+ if (flags[0]) {
+ wmove(w, 1, p->window.cols - strlen(flags) - 3);
+ waddch(w, '[');
+ colors_use(w, COLOR_LINE_BOLD);
+ waddstr(w, flags);
+ colors_use(w, COLOR_LINE);
+ waddch(w, ']');
+ }
+
+ wnoutrefresh(w);
+}
+
+void
+title_bar_resize(struct title_bar *p, unsigned width)
+{
+ assert(p != NULL);
+
+ p->window.cols = width;
+ wresize(p->window.w, 2, width);
+}
diff --git a/src/title_bar.h b/src/title_bar.h
--- /dev/null
+++ b/src/title_bar.h
@@ -0,0 +1,55 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 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 NCMPC_TITLE_BAR_H
+#define NCMPC_TITLE_BAR_H
+
+#include "window.h"
+
+#include <stdbool.h>
+
+struct mpd_status;
+
+struct title_bar {
+ struct window window;
+};
+
+static inline void
+title_bar_init(struct title_bar *p, unsigned width, int y, int x)
+{
+ window_init(&p->window, 2, width, y, x);
+
+ leaveok(p->window.w, true);
+ keypad(p->window.w, true);
+}
+
+static inline void
+title_bar_deinit(struct title_bar *p)
+{
+ delwin(p->window.w);
+}
+
+void
+title_bar_paint(const struct title_bar *p, const char *title,
+ const struct mpd_status *status);
+
+void
+title_bar_resize(struct title_bar *p, unsigned width);
+
+#endif