change window timeout more transparently
This commit is contained in:
@@ -141,6 +141,7 @@ int main(int argc, char **argv)
|
||||
myPlaylist->switchTo();
|
||||
|
||||
// local variables
|
||||
int nc_wtimeout;
|
||||
Key input(0, Key::Standard);
|
||||
auto past = boost::posix_time::from_time_t(0);
|
||||
|
||||
@@ -244,17 +245,15 @@ int main(int argc, char **argv)
|
||||
Statusbar::printf("Unexpected error: %1%", e.what());
|
||||
}
|
||||
|
||||
// set appropriate window timeout
|
||||
nc_wtimeout = std::numeric_limits<int>::max();
|
||||
applyToVisibleWindows([&nc_wtimeout](BaseScreen *s) {
|
||||
nc_wtimeout = std::min(nc_wtimeout, s->windowTimeout());
|
||||
});
|
||||
wFooter->setTimeout(nc_wtimeout);
|
||||
|
||||
if (myScreen == myPlaylist)
|
||||
myPlaylist->EnableHighlighting();
|
||||
|
||||
# ifdef ENABLE_VISUALIZER
|
||||
// visualizer sets timeout to 40ms, but since only it needs such small
|
||||
// value, we should restore default one after switching to another screen.
|
||||
if (wFooter->getTimeout() < 500
|
||||
&& !(myScreen == myVisualizer || myLockedScreen == myVisualizer || myInactiveScreen == myVisualizer)
|
||||
)
|
||||
wFooter->setTimeout(500);
|
||||
# endif // ENABLE_VISUALIZER
|
||||
}
|
||||
catch (MPD::ClientError &e)
|
||||
{
|
||||
|
||||
@@ -125,19 +125,19 @@ void BaseScreen::unlock()
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void applyToVisibleWindows(void (BaseScreen::*f)())
|
||||
void applyToVisibleWindows(std::function<void(BaseScreen *)> f)
|
||||
{
|
||||
if (myLockedScreen && myScreen->isMergable())
|
||||
{
|
||||
if (myScreen == myLockedScreen)
|
||||
{
|
||||
if (myInactiveScreen)
|
||||
(myInactiveScreen->*f)();
|
||||
f(myInactiveScreen);
|
||||
}
|
||||
else
|
||||
(myLockedScreen->*f)();
|
||||
f(myLockedScreen);
|
||||
}
|
||||
(myScreen->*f)();
|
||||
f(myScreen);
|
||||
}
|
||||
|
||||
void updateInactiveScreen(BaseScreen *screen_to_be_set)
|
||||
|
||||
11
src/screen.h
11
src/screen.h
@@ -58,6 +58,9 @@ struct BaseScreen
|
||||
/// if requested by hasToBeResized
|
||||
virtual void resize() = 0;
|
||||
|
||||
/// @return ncurses timeout parameter for the screen
|
||||
virtual int windowTimeout() = 0;
|
||||
|
||||
/// @return title of the screen
|
||||
virtual std::wstring title() = 0;
|
||||
|
||||
@@ -107,7 +110,7 @@ protected:
|
||||
void getWindowResizeParams(size_t &x_offset, size_t &width, bool adjust_locked_screen = true);
|
||||
};
|
||||
|
||||
void applyToVisibleWindows(void (BaseScreen::*f)());
|
||||
void applyToVisibleWindows(std::function<void(BaseScreen *)> f);
|
||||
void updateInactiveScreen(BaseScreen *screen_to_be_set);
|
||||
bool isVisible(BaseScreen *screen);
|
||||
|
||||
@@ -172,6 +175,12 @@ public:
|
||||
Accessor::apply(w).scroll(where);
|
||||
}
|
||||
|
||||
/// @return timeout parameter used for the screen (in ms)
|
||||
/// @default 500
|
||||
virtual int windowTimeout() OVERRIDE {
|
||||
return 500;
|
||||
}
|
||||
|
||||
/// Invoked after there was one of mouse buttons pressed
|
||||
/// @param me struct that contains coords of where the click
|
||||
/// had its place and button actions
|
||||
|
||||
@@ -352,11 +352,6 @@ void Status::Changes::playerState()
|
||||
break;
|
||||
}
|
||||
|
||||
# ifdef ENABLE_VISUALIZER
|
||||
if (myScreen == myVisualizer)
|
||||
wFooter->setTimeout(State::player() == MPD::psPlay ? Visualizer::WindowTimeout : 500);
|
||||
# endif // ENABLE_VISUALIZER
|
||||
|
||||
std::string state = playerStateToString(State::player());
|
||||
if (Config.design == Design::Alternative)
|
||||
{
|
||||
|
||||
@@ -35,14 +35,13 @@
|
||||
#include "statusbar.h"
|
||||
#include "title.h"
|
||||
#include "screen_switcher.h"
|
||||
#include "status.h"
|
||||
|
||||
using Global::MainStartY;
|
||||
using Global::MainHeight;
|
||||
|
||||
Visualizer *myVisualizer;
|
||||
|
||||
const int Visualizer::WindowTimeout = 1000/25; /* 25 fps */
|
||||
|
||||
Visualizer::Visualizer()
|
||||
: Screen(NC::Window(0, MainStartY, COLS, MainHeight, "", Config.visualizer_color, NC::Border::None))
|
||||
{
|
||||
@@ -62,8 +61,6 @@ void Visualizer::switchTo()
|
||||
SwitchTo::execute(this);
|
||||
w.clear();
|
||||
SetFD();
|
||||
if (m_fifo >= 0)
|
||||
Global::wFooter->setTimeout(WindowTimeout);
|
||||
drawHeader();
|
||||
}
|
||||
|
||||
@@ -127,6 +124,14 @@ void Visualizer::update()
|
||||
w.refresh();
|
||||
}
|
||||
|
||||
int Visualizer::windowTimeout()
|
||||
{
|
||||
if (m_fifo >= 0 && Status::State::player() == MPD::psPlay)
|
||||
return 1000/25; // 25 fps
|
||||
else
|
||||
return Screen<WindowType>::windowTimeout();
|
||||
}
|
||||
|
||||
void Visualizer::spacePressed()
|
||||
{
|
||||
# ifdef HAVE_FFTW3_H
|
||||
|
||||
@@ -47,6 +47,8 @@ struct Visualizer: Screen<NC::Window>, Tabbable
|
||||
virtual void update() OVERRIDE;
|
||||
virtual void scroll(NC::Scroll) OVERRIDE { }
|
||||
|
||||
virtual int windowTimeout() OVERRIDE;
|
||||
|
||||
virtual void enterPressed() OVERRIDE { }
|
||||
virtual void spacePressed() OVERRIDE;
|
||||
virtual void mouseButtonPressed(MEVENT) OVERRIDE { }
|
||||
@@ -58,8 +60,6 @@ struct Visualizer: Screen<NC::Window>, Tabbable
|
||||
void ResetFD();
|
||||
void FindOutputID();
|
||||
|
||||
static const int WindowTimeout;
|
||||
|
||||
protected:
|
||||
virtual bool isLockable() OVERRIDE { return true; }
|
||||
|
||||
|
||||
@@ -706,10 +706,13 @@ void Window::altCharset(bool altcharset_state) const
|
||||
}
|
||||
|
||||
void Window::setTimeout(int timeout)
|
||||
{
|
||||
if (timeout != m_window_timeout)
|
||||
{
|
||||
m_window_timeout = timeout;
|
||||
wtimeout(m_window, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::addFDCallback(int fd, void (*callback)())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user