Code

screen: moved struct window to window.h
authorMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 22:02:47 +0000 (00:02 +0200)
committerMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 22:02:47 +0000 (00:02 +0200)
Makefile.am
src/screen.c
src/screen.h
src/window.h [new file with mode: 0644]

index 995d01f9bd8a8bb602bc47629e1de3a07373cdaf..e90fb2ef7b3e16ecec774defeefb25e2b4dc80f8 100644 (file)
@@ -21,6 +21,7 @@ ncmpc_headers = \
        src/command.h \
        src/ncu.h \
        src/player_command.h \
+       src/window.h \
        src/screen.h \
        src/screen_list.h \
        src/screen_play.h \
index 13dd1175ad1f92ddc2ed58271bcfa080d09ced7c..a8b2ce56f600585ad587cba5cfd5ae6433c9c303 100644 (file)
@@ -559,41 +559,24 @@ screen_init(struct mpdclient *c)
        screen.start_timestamp = time(NULL);
 
        /* create top window */
-       screen.top_window.rows = 2;
-       screen.top_window.cols = screen.cols;
-       screen.top_window.w = newwin(screen.top_window.rows,
-                                     screen.top_window.cols,
-                                     0, 0);
+       window_init(&screen.top_window, 2, screen.cols, 0, 0);
        leaveok(screen.top_window.w, TRUE);
        keypad(screen.top_window.w, TRUE);
 
        /* create main window */
-       screen.main_window.rows = screen.rows-4;
-       screen.main_window.cols = screen.cols;
-       screen.main_window.w = newwin(screen.main_window.rows,
-                                      screen.main_window.cols,
-                                      2,
-                                      0);
+       window_init(&screen.main_window, screen.rows - 4, screen.cols, 2, 0);
 
        //  leaveok(screen.main_window.w, TRUE); temporary disabled
        keypad(screen.main_window.w, TRUE);
 
        /* create progress window */
-       screen.progress_window.rows = 1;
-       screen.progress_window.cols = screen.cols;
-       screen.progress_window.w = newwin(screen.progress_window.rows,
-                                          screen.progress_window.cols,
-                                          screen.rows-2,
-                                          0);
+       window_init(&screen.progress_window, 1, screen.cols,
+                   screen.rows - 2, 0);
        leaveok(screen.progress_window.w, TRUE);
 
        /* create status window */
-       screen.status_window.rows = 1;
-       screen.status_window.cols = screen.cols;
-       screen.status_window.w = newwin(screen.status_window.rows,
-                                        screen.status_window.cols,
-                                        screen.rows-1,
-                                        0);
+       window_init(&screen.status_window, 1, screen.cols,
+                   screen.rows - 1, 0);
 
        leaveok(screen.status_window.w, FALSE);
        keypad(screen.status_window.w, TRUE);
index 32d57b03c6e644cb6f91f21ad8de98e381b462ac..ebf36748f4a646dafcabd99da58d75e6709a740c 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "config.h"
 #include "command.h"
+#include "window.h"
 
 #include <mpd/client.h>
 
 
 struct mpdclient;
 
-struct window {
-       WINDOW *w;
-       unsigned rows, cols;
-};
-
 struct screen {
        struct window top_window;
        struct window main_window;
diff --git a/src/window.h b/src/window.h
new file mode 100644 (file)
index 0000000..e2edeb2
--- /dev/null
@@ -0,0 +1,43 @@
+/* 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_WINDOW_H
+#define NCMPC_WINDOW_H
+
+#ifdef HAVE_NCURSESW_NCURSES_H
+#include <ncursesw/ncurses.h>
+#else
+#include <ncurses.h>
+#endif
+
+struct window {
+       WINDOW *w;
+       unsigned rows, cols;
+};
+
+static inline void
+window_init(struct window *window, unsigned height, unsigned width,
+           int y, int x)
+{
+       window->w = newwin(height, width, y, x);
+       window->cols = width;
+       window->rows = height;
+}
+
+#endif