set SIGWINCH handler before initializing ncurses to avoid races
[ncmpcpp.git] / src / outputs.cpp
blobf420238c8f55a9829d62649d0c0f74eefe690459
1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
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. *
9 * *
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. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "outputs.h"
23 #ifdef ENABLE_OUTPUTS
25 #include "charset.h"
26 #include "display.h"
27 #include "global.h"
28 #include "settings.h"
29 #include "status.h"
30 #include "statusbar.h"
31 #include "title.h"
32 #include "screen_switcher.h"
34 using Global::MainHeight;
35 using Global::MainStartY;
36 using Global::myScreen;
38 Outputs *myOutputs;
40 Outputs::Outputs()
41 : Screen(NC::Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border::None))
43 w.cyclicScrolling(Config.use_cyclic_scrolling);
44 w.centeredCursor(Config.centered_cursor);
45 w.setHighlightColor(Config.main_highlight_color);
46 w.setItemDisplayer([](NC::Menu<MPD::Output> &menu) {
47 menu << Charset::utf8ToLocale(menu.drawn()->value().name());
48 });
51 void Outputs::switchTo()
53 SwitchTo::execute(this);
54 drawHeader();
57 void Outputs::resize()
59 size_t x_offset, width;
60 getWindowResizeParams(x_offset, width);
61 w.resize(width, MainHeight);
62 w.moveTo(x_offset, MainStartY);
63 hasToBeResized = 0;
66 std::wstring Outputs::title()
68 return L"Outputs";
71 void Outputs::enterPressed()
73 if (w.current().value().isEnabled())
75 Mpd.DisableOutput(w.choice());
76 Statusbar::printf("Output \"%s\" disabled", w.current().value().name());
78 else
80 Mpd.EnableOutput(w.choice());
81 Statusbar::printf("Output \"%s\" enabled", w.current().value().name());
85 void Outputs::mouseButtonPressed(MEVENT me)
87 if (w.empty() || !w.hasCoords(me.x, me.y) || size_t(me.y) >= w.size())
88 return;
89 if (me.bstate & BUTTON1_PRESSED || me.bstate & BUTTON3_PRESSED)
91 w.Goto(me.y);
92 if (me.bstate & BUTTON3_PRESSED)
93 enterPressed();
95 else
96 Screen<WindowType>::mouseButtonPressed(me);
99 void Outputs::FetchList()
101 w.clear();
102 Mpd.GetOutputs([this](MPD::Output output) {
103 w.addItem(output, output.isEnabled());
105 if (myScreen == this)
106 w.refresh();
109 #endif // ENABLE_OUTPUTS