Code

screen: moved code to ncu.c
authorMax Kellermann <max@duempel.org>
Mon, 22 Sep 2008 08:04:39 +0000 (10:04 +0200)
committerMax Kellermann <max@duempel.org>
Mon, 22 Sep 2008 08:04:39 +0000 (10:04 +0200)
Moved basic libncurses initialization to ncu.c and ncu.h.  Keep
generic code out of screen.c.

src/Makefile.am
src/main.c
src/ncu.c [new file with mode: 0644]
src/ncu.h [new file with mode: 0644]
src/screen.c
src/screen.h

index a16fef52171ece3f1d1a9609616819519d637563..9a2d5c02263330f6a8c585669cffd1ba7af2a8d7 100644 (file)
@@ -20,6 +20,7 @@ ncmpc_headers = \
   options.h\
   conf.h\
   command.h\
   options.h\
   conf.h\
   command.h\
+       ncu.h \
   screen.h\
   screen_utils.h\
   list_window.h\
   screen.h\
   screen_utils.h\
   list_window.h\
@@ -51,6 +52,7 @@ ncmpc_SOURCES = \
   options.c\
   conf.c\
   command.c\
   options.c\
   conf.c\
   command.c\
+       ncu.c \
   screen.c\
   screen_utils.c\
   screen_play.c\
   screen.c\
   screen_utils.c\
   screen_play.c\
index 5dac8b92bb043d8ce5b84ad917d39b49086d825c..a33643d10e46b0cf44eed16bfdbde186e5183c00 100644 (file)
@@ -26,6 +26,7 @@
 #include "conf.h"
 #include "command.h"
 #include "lyrics.h"
 #include "conf.h"
 #include "command.h"
 #include "lyrics.h"
+#include "ncu.h"
 #include "screen.h"
 #include "screen_utils.h"
 #include "strfsong.h"
 #include "screen.h"
 #include "screen_utils.h"
 #include "strfsong.h"
@@ -417,7 +418,7 @@ main(int argc, const char *argv[])
                exit(EXIT_FAILURE);
        }
 
                exit(EXIT_FAILURE);
        }
 
-       ncurses_init();
+       ncu_init();
 
        lyrics_init();
 
 
        lyrics_init();
 
@@ -452,4 +453,5 @@ main(int argc, const char *argv[])
        g_io_channel_unref(keyboard_channel);
 
        exit_and_cleanup();
        g_io_channel_unref(keyboard_channel);
 
        exit_and_cleanup();
+       ncu_deinit();
 }
 }
diff --git a/src/ncu.c b/src/ncu.c
new file mode 100644 (file)
index 0000000..ed3c227
--- /dev/null
+++ b/src/ncu.c
@@ -0,0 +1,59 @@
+/* ncmpc
+ * (c) 2004 by Kalle Wallin <kaw@linux.se>
+ * Copyright (C) 2008 Max Kellermann <max@duempel.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "ncu.h"
+#include "colors.h"
+
+void
+ncu_init(void)
+{
+       /* initialize the curses library */
+       initscr();
+
+       /* initialize color support */
+       colors_start();
+
+       /* tell curses not to do NL->CR/NL on output */
+       nonl();
+
+       /*  use raw mode (ignore interrupt,quit,suspend, and flow control ) */
+#ifdef ENABLE_RAW_MODE
+       //  raw();
+#endif
+
+       /* don't echo input */
+       noecho();
+
+       /* set cursor invisible */
+       curs_set(0);
+
+       /* enable extra keys */
+       keypad(stdscr, TRUE);
+
+       /* initialize mouse support */
+#ifdef HAVE_GETMOUSE
+       if (options.enable_mouse)
+               mousemask(ALL_MOUSE_EVENTS, NULL);
+#endif
+}
+
+void
+ncu_deinit(void)
+{
+       endwin();
+}
diff --git a/src/ncu.h b/src/ncu.h
new file mode 100644 (file)
index 0000000..0a2ce5e
--- /dev/null
+++ b/src/ncu.h
@@ -0,0 +1,31 @@
+/* ncmpc
+ * Copyright (C) 2008 Max Kellermann <max@duempel.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * Basic libnucrses initialization.
+ */
+
+#ifndef NCU_H
+#define NCU_H
+
+void
+ncu_init(void);
+
+void
+ncu_deinit(void);
+
+#endif
index 2999b598ed0e3ae2403b4125c98161932b88ae25..92ce29e484a786dd91f5c5087522c7bfd3292014 100644 (file)
@@ -429,8 +429,6 @@ screen_exit(void)
 {
        guint i;
 
 {
        guint i;
 
-       endwin();
-
        if (mode_fn->close != NULL)
                mode_fn->close();
 
        if (mode_fn->close != NULL)
                mode_fn->close();
 
@@ -531,30 +529,9 @@ screen_status_printf(const char *format, ...)
 }
 
 void
 }
 
 void
-ncurses_init(void)
+screen_init(mpdclient_t *c)
 {
 {
-
-       /* initialize the curses library */
-       initscr();
-       /* initialize color support */
-       colors_start();
-       /* tell curses not to do NL->CR/NL on output */
-       nonl();
-       /*  use raw mode (ignore interrupt,quit,suspend, and flow control ) */
-#ifdef ENABLE_RAW_MODE
-       //  raw();
-#endif
-       /* don't echo input */
-       noecho();
-       /* set cursor invisible */
-       curs_set(0);
-       /* enable extra keys */
-       keypad(stdscr, TRUE);
-       /* initialize mouse support */
-#ifdef HAVE_GETMOUSE
-       if (options.enable_mouse)
-               mousemask(ALL_MOUSE_EVENTS, NULL);
-#endif
+       guint i;
 
        if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
                fprintf(stderr, _("Error: Screen to small!\n"));
 
        if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
                fprintf(stderr, _("Error: Screen to small!\n"));
@@ -624,12 +601,6 @@ ncurses_init(void)
        }
 
        refresh();
        }
 
        refresh();
-}
-
-void
-screen_init(mpdclient_t *c)
-{
-       guint i;
 
        /* initialize screens */
        for (i = 0; i < NUM_SCREENS; ++i) {
 
        /* initialize screens */
        for (i = 0; i < NUM_SCREENS; ++i) {
index b9087e0ca3091248cd1eec7136b0e4cb533b1be5..ca0dd2a0cdccfefe6e5c941de20a1cb33d9c337e 100644 (file)
@@ -69,9 +69,6 @@ typedef struct screen_functions {
        screen_title_fn_t  get_title;
 } screen_functions_t;
 
        screen_title_fn_t  get_title;
 } screen_functions_t;
 
-void
-ncurses_init(void);
-
 void screen_init(mpdclient_t *c);
 void screen_exit(void);
 void screen_resize(void);
 void screen_init(mpdclient_t *c);
 void screen_exit(void);
 void screen_resize(void);