From 07632841df4ff1d8fcfac33bd93e06ee43a4498e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 22 Sep 2008 10:04:39 +0200 Subject: [PATCH] screen: moved code to ncu.c Moved basic libncurses initialization to ncu.c and ncu.h. Keep generic code out of screen.c. --- src/Makefile.am | 2 ++ src/main.c | 4 +++- src/ncu.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ src/ncu.h | 31 ++++++++++++++++++++++++++ src/screen.c | 33 ++------------------------- src/screen.h | 3 --- 6 files changed, 97 insertions(+), 35 deletions(-) create mode 100644 src/ncu.c create mode 100644 src/ncu.h diff --git a/src/Makefile.am b/src/Makefile.am index a16fef5..9a2d5c0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ ncmpc_headers = \ options.h\ conf.h\ command.h\ + ncu.h \ screen.h\ screen_utils.h\ list_window.h\ @@ -51,6 +52,7 @@ ncmpc_SOURCES = \ options.c\ conf.c\ command.c\ + ncu.c \ screen.c\ screen_utils.c\ screen_play.c\ diff --git a/src/main.c b/src/main.c index 5dac8b9..a33643d 100644 --- a/src/main.c +++ b/src/main.c @@ -26,6 +26,7 @@ #include "conf.h" #include "command.h" #include "lyrics.h" +#include "ncu.h" #include "screen.h" #include "screen_utils.h" #include "strfsong.h" @@ -417,7 +418,7 @@ main(int argc, const char *argv[]) exit(EXIT_FAILURE); } - ncurses_init(); + ncu_init(); lyrics_init(); @@ -452,4 +453,5 @@ main(int argc, const char *argv[]) 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 index 0000000..ed3c227 --- /dev/null +++ b/src/ncu.c @@ -0,0 +1,59 @@ +/* ncmpc + * (c) 2004 by Kalle Wallin + * Copyright (C) 2008 Max Kellermann + * + * 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 index 0000000..0a2ce5e --- /dev/null +++ b/src/ncu.h @@ -0,0 +1,31 @@ +/* ncmpc + * Copyright (C) 2008 Max Kellermann + * + * 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 diff --git a/src/screen.c b/src/screen.c index 2999b59..92ce29e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -429,8 +429,6 @@ screen_exit(void) { guint i; - endwin(); - if (mode_fn->close != NULL) mode_fn->close(); @@ -531,30 +529,9 @@ screen_status_printf(const char *format, ...) } 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")); @@ -624,12 +601,6 @@ ncurses_init(void) } refresh(); -} - -void -screen_init(mpdclient_t *c) -{ - guint i; /* initialize screens */ for (i = 0; i < NUM_SCREENS; ++i) { diff --git a/src/screen.h b/src/screen.h index b9087e0..ca0dd2a 100644 --- a/src/screen.h +++ b/src/screen.h @@ -69,9 +69,6 @@ typedef struct screen_functions { 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); -- 2.30.2