actions: add action for environment update
This commit is contained in:
1
NEWS
1
NEWS
@@ -22,6 +22,7 @@ ncmpcpp-0.7 (????-??-??)
|
|||||||
* NCurses terminal sequence escaping is no longer used as it's not accurate enough.
|
* NCurses terminal sequence escaping is no longer used as it's not accurate enough.
|
||||||
* Selecting items no longer depends on space mode and is bound by default to Insert key.
|
* Selecting items no longer depends on space mode and is bound by default to Insert key.
|
||||||
* Support for Alt, Ctrl and Shift modifiers as well as Escape key was added.
|
* Support for Alt, Ctrl and Shift modifiers as well as Escape key was added.
|
||||||
|
* Action that updates the environment can now be used in bindings configuration file.
|
||||||
|
|
||||||
ncmpcpp-0.6.4 (2015-05-02)
|
ncmpcpp-0.6.4 (2015-05-02)
|
||||||
|
|
||||||
|
|||||||
@@ -114,6 +114,13 @@
|
|||||||
## could be used. Then ncmpcpp will not wait for confirmation
|
## could be used. Then ncmpcpp will not wait for confirmation
|
||||||
## (enter) and will execute the command the moment it sees it.
|
## (enter) and will execute the command the moment it sees it.
|
||||||
##
|
##
|
||||||
|
## Note: while command chains are executed, internal environment
|
||||||
|
## update (which includes current window refresh and mpd status
|
||||||
|
## update) is not performed for performance reasons. However, it
|
||||||
|
## may be desirable to do so in some situration. Therefore it's
|
||||||
|
## possible to invoke by hand by performing 'update enviroment'
|
||||||
|
## action.
|
||||||
|
##
|
||||||
## Note: There is a difference between:
|
## Note: There is a difference between:
|
||||||
##
|
##
|
||||||
## def_key "key"
|
## def_key "key"
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ void resizeScreen(bool reload_main_window)
|
|||||||
using Global::MainHeight;
|
using Global::MainHeight;
|
||||||
using Global::wHeader;
|
using Global::wHeader;
|
||||||
using Global::wFooter;
|
using Global::wFooter;
|
||||||
|
|
||||||
// update internal screen dimensions
|
// update internal screen dimensions
|
||||||
if (reload_main_window)
|
if (reload_main_window)
|
||||||
{
|
{
|
||||||
@@ -198,29 +198,29 @@ void resizeScreen(bool reload_main_window)
|
|||||||
endwin();
|
endwin();
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainHeight = LINES-(Config.design == Design::Alternative ? 7 : 4);
|
MainHeight = LINES-(Config.design == Design::Alternative ? 7 : 4);
|
||||||
|
|
||||||
validateScreenSize();
|
validateScreenSize();
|
||||||
|
|
||||||
if (!Config.header_visibility)
|
if (!Config.header_visibility)
|
||||||
MainHeight += 2;
|
MainHeight += 2;
|
||||||
if (!Config.statusbar_visibility)
|
if (!Config.statusbar_visibility)
|
||||||
++MainHeight;
|
++MainHeight;
|
||||||
|
|
||||||
setResizeFlags();
|
setResizeFlags();
|
||||||
|
|
||||||
applyToVisibleWindows(&BaseScreen::resize);
|
applyToVisibleWindows(&BaseScreen::resize);
|
||||||
|
|
||||||
if (Config.header_visibility || Config.design == Design::Alternative)
|
if (Config.header_visibility || Config.design == Design::Alternative)
|
||||||
wHeader->resize(COLS, HeaderHeight);
|
wHeader->resize(COLS, HeaderHeight);
|
||||||
|
|
||||||
FooterStartY = LINES-(Config.statusbar_visibility ? 2 : 1);
|
FooterStartY = LINES-(Config.statusbar_visibility ? 2 : 1);
|
||||||
wFooter->moveTo(0, FooterStartY);
|
wFooter->moveTo(0, FooterStartY);
|
||||||
wFooter->resize(COLS, Config.statusbar_visibility ? 2 : 1);
|
wFooter->resize(COLS, Config.statusbar_visibility ? 2 : 1);
|
||||||
|
|
||||||
applyToVisibleWindows(&BaseScreen::refresh);
|
applyToVisibleWindows(&BaseScreen::refresh);
|
||||||
|
|
||||||
Status::Changes::elapsedTime(false);
|
Status::Changes::elapsedTime(false);
|
||||||
Status::Changes::playerState();
|
Status::Changes::playerState();
|
||||||
// Note: routines for drawing separator if alternative user
|
// Note: routines for drawing separator if alternative user
|
||||||
@@ -301,6 +301,36 @@ BaseAction *get(const std::string &name)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateEnvironment::UpdateEnvironment()
|
||||||
|
: BaseAction(Type::UpdateEnvironment, "update_environment")
|
||||||
|
, m_past(boost::posix_time::from_time_t(0))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void UpdateEnvironment::run(bool update_timer, bool refresh_window)
|
||||||
|
{
|
||||||
|
using Global::Timer;
|
||||||
|
|
||||||
|
// update timer, status if necessary etc.
|
||||||
|
Status::trace(update_timer, true);
|
||||||
|
|
||||||
|
// header stuff
|
||||||
|
if ((myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics)
|
||||||
|
&& (Timer - m_past > boost::posix_time::milliseconds(500))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
drawHeader();
|
||||||
|
m_past = Timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (refresh_window)
|
||||||
|
myScreen->refreshWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateEnvironment::run()
|
||||||
|
{
|
||||||
|
run(true, true);
|
||||||
|
}
|
||||||
|
|
||||||
bool MouseEvent::canBeRun()
|
bool MouseEvent::canBeRun()
|
||||||
{
|
{
|
||||||
return Config.mouse_support;
|
return Config.mouse_support;
|
||||||
@@ -2427,6 +2457,7 @@ void populateActions()
|
|||||||
AvailableActions[static_cast<size_t>(a->type())] = a;
|
AvailableActions[static_cast<size_t>(a->type())] = a;
|
||||||
};
|
};
|
||||||
insert_action(new Actions::Dummy());
|
insert_action(new Actions::Dummy());
|
||||||
|
insert_action(new Actions::UpdateEnvironment());
|
||||||
insert_action(new Actions::MouseEvent());
|
insert_action(new Actions::MouseEvent());
|
||||||
insert_action(new Actions::ScrollUp());
|
insert_action(new Actions::ScrollUp());
|
||||||
insert_action(new Actions::ScrollDown());
|
insert_action(new Actions::ScrollDown());
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#ifndef NCMPCPP_ACTIONS_H
|
#ifndef NCMPCPP_ACTIONS_H
|
||||||
#define NCMPCPP_ACTIONS_H
|
#define NCMPCPP_ACTIONS_H
|
||||||
|
|
||||||
|
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -34,7 +35,7 @@ namespace Actions {
|
|||||||
enum class Type
|
enum class Type
|
||||||
{
|
{
|
||||||
MacroUtility = 0,
|
MacroUtility = 0,
|
||||||
Dummy, MouseEvent, ScrollUp, ScrollDown, ScrollUpArtist, ScrollUpAlbum,
|
Dummy, UpdateEnvironment, MouseEvent, ScrollUp, ScrollDown, ScrollUpArtist, ScrollUpAlbum,
|
||||||
ScrollDownArtist, ScrollDownAlbum, PageUp, PageDown, MoveHome, MoveEnd,
|
ScrollDownArtist, ScrollDownAlbum, PageUp, PageDown, MoveHome, MoveEnd,
|
||||||
ToggleInterface, JumpToParentDirectory, PressEnter, PressSpace, PreviousColumn,
|
ToggleInterface, JumpToParentDirectory, PressEnter, PressSpace, PreviousColumn,
|
||||||
NextColumn, MasterScreen, SlaveScreen, VolumeUp, VolumeDown, DeletePlaylistItems,
|
NextColumn, MasterScreen, SlaveScreen, VolumeUp, VolumeDown, DeletePlaylistItems,
|
||||||
@@ -122,6 +123,18 @@ private:
|
|||||||
virtual void run() OVERRIDE { }
|
virtual void run() OVERRIDE { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct UpdateEnvironment: BaseAction
|
||||||
|
{
|
||||||
|
UpdateEnvironment();
|
||||||
|
|
||||||
|
void run(bool update_status, bool refresh_window);
|
||||||
|
|
||||||
|
private:
|
||||||
|
boost::posix_time::ptime m_past;
|
||||||
|
|
||||||
|
virtual void run() OVERRIDE;
|
||||||
|
};
|
||||||
|
|
||||||
struct MouseEvent: BaseAction
|
struct MouseEvent: BaseAction
|
||||||
{
|
{
|
||||||
MouseEvent(): BaseAction(Type::MouseEvent, "mouse_event")
|
MouseEvent(): BaseAction(Type::MouseEvent, "mouse_event")
|
||||||
@@ -134,9 +147,8 @@ private:
|
|||||||
virtual bool canBeRun() OVERRIDE;
|
virtual bool canBeRun() OVERRIDE;
|
||||||
virtual void run() OVERRIDE;
|
virtual void run() OVERRIDE;
|
||||||
|
|
||||||
private:
|
MEVENT m_mouse_event;
|
||||||
MEVENT m_mouse_event;
|
MEVENT m_old_mouse_event;
|
||||||
MEVENT m_old_mouse_event;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ScrollUp: BaseAction
|
struct ScrollUp: BaseAction
|
||||||
|
|||||||
@@ -162,7 +162,9 @@ int main(int argc, char **argv)
|
|||||||
bool key_pressed = false;
|
bool key_pressed = false;
|
||||||
auto input = NC::Key::None;
|
auto input = NC::Key::None;
|
||||||
auto connect_attempt = boost::posix_time::from_time_t(0);
|
auto connect_attempt = boost::posix_time::from_time_t(0);
|
||||||
auto past = boost::posix_time::from_time_t(0);
|
auto update_environment = static_cast<Actions::UpdateEnvironment &>(
|
||||||
|
Actions::get(Actions::Type::UpdateEnvironment)
|
||||||
|
);
|
||||||
|
|
||||||
while (!Actions::ExitMainLoop)
|
while (!Actions::ExitMainLoop)
|
||||||
{
|
{
|
||||||
@@ -189,30 +191,17 @@ int main(int argc, char **argv)
|
|||||||
Status::handleClientError(e);
|
Status::handleClientError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update timer, status if necessary etc.
|
|
||||||
Status::trace(!key_pressed, true);
|
|
||||||
|
|
||||||
if (run_resize_screen)
|
if (run_resize_screen)
|
||||||
{
|
{
|
||||||
Actions::resizeScreen(true);
|
Actions::resizeScreen(true);
|
||||||
run_resize_screen = false;
|
run_resize_screen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// header stuff
|
update_environment.run(!key_pressed, key_pressed);
|
||||||
if ((myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics)
|
|
||||||
&& (Timer - past > boost::posix_time::milliseconds(500))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
drawHeader();
|
|
||||||
past = Timer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key_pressed)
|
|
||||||
myScreen->refreshWindow();
|
|
||||||
input = readKey(*wFooter);
|
input = readKey(*wFooter);
|
||||||
key_pressed = input != NC::Key::None;
|
key_pressed = input != NC::Key::None;
|
||||||
|
|
||||||
if (!key_pressed)
|
if (!key_pressed)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user