screen_switcher between current and last screen

Setting the new config variable "screen_switcher_browser_only" to "no"
will make the "key_screen_switcher" key switch between the current and
the last used screen, sort of like the Alt+Tab window switching
mechanism in many window managers.

This (intendedly) works only for the "main" screens (playlist, browser,
media library, etc.) and not for info/lyrics/server info. Those screens
can be closed with the screen_switcher key, but the will not be
remembered.

indentation correction in config
This commit is contained in:
Frank Blendinger
2009-12-06 22:49:01 +01:00
committed by Andrzej Rybczak
parent 64f64895ac
commit b504b346af
27 changed files with 83 additions and 5 deletions

View File

@@ -263,6 +263,14 @@
# #
#display_screens_numbers_on_start = "yes" #display_screens_numbers_on_start = "yes"
# #
##
## How shall key_screen_switcher work?
##
## - yes - always switch between browser and playlist
## - no - switch between current and last used screen
##
#screen_switcher_browser_only = "yes"
#
#jump_to_now_playing_song_at_start = "yes" #jump_to_now_playing_song_at_start = "yes"
# #
#ask_before_clearing_main_playlist = "no" #ask_before_clearing_main_playlist = "no"

View File

@@ -213,6 +213,9 @@ If set to "playlist", Search engine will perform searching in current MPD playli
.B display_screens_numbers_on_start = yes/no .B display_screens_numbers_on_start = yes/no
If enabled, screens' names and their keybindings will be shown in header window until key is pressed, otherwise they won't be displayed at all. If enabled, screens' names and their keybindings will be shown in header window until key is pressed, otherwise they won't be displayed at all.
.TP .TP
.B screen_switcher_browser_only = yes/no
If enabled, the "screen_switcher" key (<Tab> by default) will only switch between the playlist and browser screens. If disabled, the last active screen will be remembered, and the "screen_switcher" key will jump back.
.TP
.B jump_to_now_playing_song_at_start = yes/no .B jump_to_now_playing_song_at_start = yes/no
If enabled, ncmpcpp will jump at start to now playing song if mpd is playing or paused. If enabled, ncmpcpp will jump at start to now playing song if mpd is playing or paused.
.TP .TP

View File

@@ -87,6 +87,9 @@ void Browser::SwitchTo()
Config.browser_sort_by_mtime = 0; Config.browser_sort_by_mtime = 0;
w->Empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList(); w->Empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
RedrawHeader = 1; RedrawHeader = 1;
} }

View File

@@ -37,6 +37,7 @@ class Browser : public Screen< Menu<MPD::Item> >
virtual void EnterPressed(); virtual void EnterPressed();
virtual void SpacePressed(); virtual void SpacePressed();
virtual void MouseButtonPressed(MEVENT); virtual void MouseButtonPressed(MEVENT);
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong(); virtual MPD::Song *CurrentSong();

View File

@@ -87,6 +87,8 @@ void Clock::SwitchTo()
if (hasToBeResized) if (hasToBeResized)
Resize(); Resize();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
myPlaylist->Items->Hide(); myPlaylist->Items->Hide();
RedrawHeader = 1; RedrawHeader = 1;

View File

@@ -44,6 +44,7 @@ class Clock : public Screen<Window>
virtual void EnterPressed() { } virtual void EnterPressed() { }
virtual void SpacePressed() { } virtual void SpacePressed() { }
virtual void MouseButtonPressed(MEVENT) { } virtual void MouseButtonPressed(MEVENT) { }
virtual bool isTabbable() { return true; }
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }

View File

@@ -28,7 +28,9 @@
namespace Global namespace Global
{ {
extern BasicScreen *myScreen; extern BasicScreen *myScreen;
extern BasicScreen *myOldScreen; extern BasicScreen *myOldScreen; // for info, lyrics, popups
extern BasicScreen *myPrevScreen; // "real" screen switching
// (browser, search, etc.)
extern Window *wHeader; extern Window *wHeader;
extern Window *wFooter; extern Window *wFooter;

View File

@@ -55,6 +55,8 @@ void Help::SwitchTo()
if (hasToBeResized) if (hasToBeResized)
Resize(); Resize();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
RedrawHeader = 1; RedrawHeader = 1;
@@ -133,7 +135,10 @@ void Help::GetKeybindings()
*w << DisplayKeys(Key.Home) << "Home\n"; *w << DisplayKeys(Key.Home) << "Home\n";
*w << DisplayKeys(Key.End) << "End\n"; *w << DisplayKeys(Key.End) << "End\n";
*w << "\n"; *w << "\n";
*w << DisplayKeys(Key.ScreenSwitcher) << "Switch between playlist and browser\n"; if (Config.screen_switcher_browser_only)
*w << DisplayKeys(Key.ScreenSwitcher) << "Switch between playlist and browser\n";
else
*w << DisplayKeys(Key.ScreenSwitcher) << "Switch between current and last screen\n";
*w << DisplayKeys(Key.Help) << "Help screen\n"; *w << DisplayKeys(Key.Help) << "Help screen\n";
*w << DisplayKeys(Key.Playlist) << "Playlist screen\n"; *w << DisplayKeys(Key.Playlist) << "Playlist screen\n";
*w << DisplayKeys(Key.Browser) << "Browse screen\n"; *w << DisplayKeys(Key.Browser) << "Browse screen\n";

View File

@@ -34,6 +34,7 @@ class Help : public Screen<Scrollpad>
virtual void EnterPressed() { } virtual void EnterPressed() { }
virtual void SpacePressed() { } virtual void SpacePressed() { }
virtual bool isTabbable() { return true; }
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }

View File

@@ -145,6 +145,8 @@ void MediaLibrary::SwitchTo()
if (hasToBeResized) if (hasToBeResized)
Resize(); Resize();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
RedrawHeader = 1; RedrawHeader = 1;
Refresh(); Refresh();

View File

@@ -48,6 +48,7 @@ class MediaLibrary : public Screen<Window>
virtual void EnterPressed() { AddToPlaylist(1); } virtual void EnterPressed() { AddToPlaylist(1); }
virtual void SpacePressed(); virtual void SpacePressed();
virtual void MouseButtonPressed(MEVENT); virtual void MouseButtonPressed(MEVENT);
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong(); virtual MPD::Song *CurrentSong();

View File

@@ -73,6 +73,7 @@ using namespace MPD;
BasicScreen *Global::myScreen; BasicScreen *Global::myScreen;
BasicScreen *Global::myOldScreen; BasicScreen *Global::myOldScreen;
BasicScreen *Global::myPrevScreen;
Window *Global::wHeader; Window *Global::wHeader;
Window *Global::wFooter; Window *Global::wFooter;
@@ -276,6 +277,12 @@ int main(int argc, char *argv[])
wFooter->AddFDCallback(Mpd.GetFD(), StatusbarMPDCallback); wFooter->AddFDCallback(Mpd.GetFD(), StatusbarMPDCallback);
wFooter->CreateHistory(); wFooter->CreateHistory();
// initialize screens to browser as default previous screen
myScreen = myBrowser;
myPrevScreen = myBrowser;
myOldScreen = myBrowser;
// go to playlist
myPlaylist->SwitchTo(); myPlaylist->SwitchTo();
myPlaylist->UpdateTimer(); myPlaylist->UpdateTimer();
@@ -1915,10 +1922,20 @@ int main(int argc, char *argv[])
} }
else if (Keypressed(input, Key.ScreenSwitcher)) else if (Keypressed(input, Key.ScreenSwitcher))
{ {
if (myScreen == myPlaylist) if (Config.screen_switcher_browser_only)
myBrowser->SwitchTo(); {
if (myScreen == myPlaylist)
myBrowser->SwitchTo();
else
myPlaylist->SwitchTo();
}
else else
myPlaylist->SwitchTo(); {
if (myScreen->isTabbable())
myPrevScreen->SwitchTo();
else
myOldScreen->SwitchTo();
}
} }
else if (Keypressed(input, Key.Playlist)) else if (Keypressed(input, Key.Playlist))
{ {

View File

@@ -51,6 +51,8 @@ void Outputs::SwitchTo()
if (hasToBeResized) if (hasToBeResized)
Resize(); Resize();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
w->Window::Clear(); w->Window::Clear();

View File

@@ -42,6 +42,7 @@ class Outputs : public Screen< Menu<MPD::Output> >
virtual void EnterPressed(); virtual void EnterPressed();
virtual void SpacePressed() { } virtual void SpacePressed() { }
virtual void MouseButtonPressed(MEVENT); virtual void MouseButtonPressed(MEVENT);
virtual bool isTabbable() { return true; }
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }

View File

@@ -97,6 +97,8 @@ void Playlist::SwitchTo()
if (hasToBeResized) if (hasToBeResized)
Resize(); Resize();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
Items->Window::Clear(); Items->Window::Clear();
EnableHighlighting(); EnableHighlighting();

View File

@@ -41,6 +41,7 @@ class Playlist : public Screen<Window>
virtual void EnterPressed(); virtual void EnterPressed();
virtual void SpacePressed(); virtual void SpacePressed();
virtual void MouseButtonPressed(MEVENT); virtual void MouseButtonPressed(MEVENT);
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong(); virtual MPD::Song *CurrentSong();

View File

@@ -102,6 +102,8 @@ void PlaylistEditor::SwitchTo()
if (hasToBeResized) if (hasToBeResized)
Resize(); Resize();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
RedrawHeader = 1; RedrawHeader = 1;
Refresh(); Refresh();

View File

@@ -37,6 +37,7 @@ class PlaylistEditor : public Screen<Window>
virtual void EnterPressed() { AddToPlaylist(1); } virtual void EnterPressed() { AddToPlaylist(1); }
virtual void SpacePressed(); virtual void SpacePressed();
virtual void MouseButtonPressed(MEVENT); virtual void MouseButtonPressed(MEVENT);
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong(); virtual MPD::Song *CurrentSong();

View File

@@ -118,6 +118,11 @@ class BasicScreen
/// cast to List if available or null pointer otherwise /// cast to List if available or null pointer otherwise
/// ///
virtual List *GetList() = 0; virtual List *GetList() = 0;
/// When this is overwritten with a function returning true, the
/// screen will be used in tab switching.
///
virtual bool isTabbable() { return false; }
/// Should be set to true each time screen needs resize /// Should be set to true each time screen needs resize
/// ///

View File

@@ -89,6 +89,9 @@ void SearchEngine::SwitchTo()
if (w->Empty()) if (w->Empty())
Prepare(); Prepare();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
RedrawHeader = 1; RedrawHeader = 1;

View File

@@ -35,6 +35,7 @@ class SearchEngine : public Screen< Menu< std::pair<Buffer *, MPD::Song *> > >
virtual void EnterPressed(); virtual void EnterPressed();
virtual void SpacePressed(); virtual void SpacePressed();
virtual void MouseButtonPressed(MEVENT); virtual void MouseButtonPressed(MEVENT);
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong(); virtual MPD::Song *CurrentSong();

View File

@@ -294,6 +294,7 @@ void DefaultConfiguration(ncmpcpp_config &conf)
conf.header_text_scrolling = true; conf.header_text_scrolling = true;
conf.statusbar_visibility = true; conf.statusbar_visibility = true;
conf.centered_cursor = false; conf.centered_cursor = false;
conf.screen_switcher_browser_only = true;
conf.autocenter_mode = false; conf.autocenter_mode = false;
conf.wrapped_search = true; conf.wrapped_search = true;
conf.space_selects = false; conf.space_selects = false;
@@ -754,6 +755,10 @@ void ReadConfiguration(ncmpcpp_config &conf)
{ {
conf.statusbar_visibility = v == "yes"; conf.statusbar_visibility = v == "yes";
} }
else if (cl.find("screen_switcher_browser_only") != std::string::npos)
{
conf.screen_switcher_browser_only = v == "yes";
}
else if (cl.find("autocenter_mode") != std::string::npos) else if (cl.find("autocenter_mode") != std::string::npos)
{ {
conf.autocenter_mode = v == "yes"; conf.autocenter_mode = v == "yes";

View File

@@ -187,6 +187,7 @@ struct ncmpcpp_config
bool header_text_scrolling; bool header_text_scrolling;
bool statusbar_visibility; bool statusbar_visibility;
bool centered_cursor; bool centered_cursor;
bool screen_switcher_browser_only;
bool autocenter_mode; bool autocenter_mode;
bool wrapped_search; bool wrapped_search;
bool space_selects; bool space_selects;

View File

@@ -42,6 +42,7 @@ using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
using Global::myOldScreen; using Global::myOldScreen;
using Global::myScreen; using Global::myScreen;
using Global::myPrevScreen;
using Global::wFooter; using Global::wFooter;
TagEditor *myTagEditor = new TagEditor; TagEditor *myTagEditor = new TagEditor;
@@ -197,6 +198,8 @@ void TagEditor::SwitchTo()
if (hasToBeResized) if (hasToBeResized)
Resize(); Resize();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
Global::RedrawHeader = 1; Global::RedrawHeader = 1;
Refresh(); Refresh();

View File

@@ -53,6 +53,7 @@ class TagEditor : public Screen<Window>
virtual void EnterPressed(); virtual void EnterPressed();
virtual void SpacePressed(); virtual void SpacePressed();
virtual void MouseButtonPressed(MEVENT); virtual void MouseButtonPressed(MEVENT);
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong(); virtual MPD::Song *CurrentSong();

View File

@@ -32,6 +32,7 @@
#include <sys/time.h> #include <sys/time.h>
using Global::myScreen; using Global::myScreen;
using Global::myPrevScreen;
using Global::MainStartY; using Global::MainStartY;
using Global::MainHeight; using Global::MainHeight;
@@ -70,6 +71,8 @@ void Visualizer::SwitchTo()
if (hasToBeResized) if (hasToBeResized)
Resize(); Resize();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this; myScreen = this;
w->Clear(); w->Clear();

View File

@@ -48,6 +48,7 @@ class Visualizer : public Screen<Window>
virtual void EnterPressed() { } virtual void EnterPressed() { }
virtual void SpacePressed(); virtual void SpacePressed();
virtual void MouseButtonPressed(MEVENT) { } virtual void MouseButtonPressed(MEVENT) { }
virtual bool isTabbable() { return true; }
virtual NCurses::List *GetList() { return 0; } virtual NCurses::List *GetList() { return 0; }