1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2017 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "screen_interface.h"
22 #include "screen_list.h"
32 /** welcome message time [s] */
33 static const GTime SCREEN_WELCOME_TIME
= 10;
36 /* minimum window size */
37 static const unsigned SCREEN_MIN_COLS
= 14;
38 static const unsigned SCREEN_MIN_ROWS
= 5;
43 if (screen
.current_page
->close
!= NULL
)
44 screen
.current_page
->close();
48 string_list_free(screen
.find_history
);
50 g_free(screen
.findbuf
);
52 title_bar_deinit(&screen
.title_bar
);
53 delwin(screen
.main_window
.w
);
54 progress_bar_deinit(&screen
.progress_bar
);
55 status_bar_deinit(&screen
.status_bar
);
58 if (screen
.welcome_source_id
!= 0)
59 g_source_remove(screen
.welcome_source_id
);
64 screen_resize(struct mpdclient
*c
)
66 const unsigned cols
= COLS
, rows
= LINES
;
67 if (cols
< SCREEN_MIN_COLS
|| rows
< SCREEN_MIN_ROWS
) {
69 fprintf(stderr
, "%s\n", _("Error: Screen too small"));
74 resize_term(rows
, cols
);
76 resizeterm(rows
, cols
);
79 title_bar_resize(&screen
.title_bar
, cols
);
82 screen
.main_window
.cols
= cols
;
83 screen
.main_window
.rows
= rows
- 4;
84 wresize(screen
.main_window
.w
, screen
.main_window
.rows
, cols
);
87 progress_bar_resize(&screen
.progress_bar
, cols
, rows
- 2, 0);
90 status_bar_resize(&screen
.status_bar
, cols
, rows
- 1, 0);
92 screen
.buf_size
= cols
;
94 screen
.buf
= g_malloc(cols
);
96 /* resize all screens */
97 screen_list_resize(screen
.main_window
.cols
, screen
.main_window
.rows
);
99 /* ? - without this the cursor becomes visible with aterm & Eterm */
103 screen_paint(c
, true);
108 welcome_timer_callback(gpointer data
)
110 struct mpdclient
*c
= data
;
112 screen
.welcome_source_id
= 0;
122 screen_init(struct mpdclient
*c
)
124 const unsigned cols
= COLS
, rows
= LINES
;
125 if (cols
< SCREEN_MIN_COLS
|| rows
< SCREEN_MIN_ROWS
) {
126 fprintf(stderr
, "%s\n", _("Error: Screen too small"));
130 screen
.buf
= g_malloc(cols
);
131 screen
.buf_size
= cols
;
132 screen
.findbuf
= NULL
;
135 if (options
.welcome_screen_list
)
136 screen
.welcome_source_id
=
137 g_timeout_add_seconds(SCREEN_WELCOME_TIME
,
138 welcome_timer_callback
, c
);
141 /* create top window */
142 title_bar_init(&screen
.title_bar
, cols
, 0, 0);
144 /* create main window */
145 window_init(&screen
.main_window
, rows
- 4, cols
, 2, 0);
147 if (!options
.hardware_cursor
)
148 leaveok(screen
.main_window
.w
, TRUE
);
150 keypad(screen
.main_window
.w
, TRUE
);
152 /* create progress window */
153 progress_bar_init(&screen
.progress_bar
, cols
, rows
- 2, 0);
155 /* create status window */
156 status_bar_init(&screen
.status_bar
, cols
, rows
- 1, 0);
159 if (options
.enable_colors
) {
160 /* set background attributes */
161 wbkgd(stdscr
, COLOR_PAIR(COLOR_LIST
));
162 wbkgd(screen
.main_window
.w
, COLOR_PAIR(COLOR_LIST
));
163 wbkgd(screen
.title_bar
.window
.w
, COLOR_PAIR(COLOR_TITLE
));
164 wbkgd(screen
.progress_bar
.window
.w
,
165 COLOR_PAIR(COLOR_PROGRESSBAR
));
166 wbkgd(screen
.status_bar
.window
.w
, COLOR_PAIR(COLOR_STATUS
));
167 colors_use(screen
.progress_bar
.window
.w
, COLOR_PROGRESSBAR
);
171 /* initialize screens */
172 screen_list_init(screen
.main_window
.w
,
173 screen
.main_window
.cols
, screen
.main_window
.rows
);
175 if (screen
.current_page
->open
!= NULL
)
176 screen
.current_page
->open(c
);