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
master
Frank Blendinger 16 years ago committed by Andrzej Rybczak
parent 64f64895ac
commit b504b346af
  1. 8
      doc/config
  2. 3
      doc/ncmpcpp.1
  3. 3
      src/browser.cpp
  4. 1
      src/browser.h
  5. 2
      src/clock.cpp
  6. 1
      src/clock.h
  7. 4
      src/global.h
  8. 7
      src/help.cpp
  9. 1
      src/help.h
  10. 2
      src/media_library.cpp
  11. 1
      src/media_library.h
  12. 23
      src/ncmpcpp.cpp
  13. 2
      src/outputs.cpp
  14. 1
      src/outputs.h
  15. 2
      src/playlist.cpp
  16. 1
      src/playlist.h
  17. 2
      src/playlist_editor.cpp
  18. 1
      src/playlist_editor.h
  19. 5
      src/screen.h
  20. 3
      src/search_engine.cpp
  21. 1
      src/search_engine.h
  22. 5
      src/settings.cpp
  23. 1
      src/settings.h
  24. 3
      src/tag_editor.cpp
  25. 1
      src/tag_editor.h
  26. 3
      src/visualizer.cpp
  27. 1
      src/visualizer.h

@ -263,6 +263,14 @@
#
#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"
#
#ask_before_clearing_main_playlist = "no"

@ -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
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
.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
If enabled, ncmpcpp will jump at start to now playing song if mpd is playing or paused.
.TP

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

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

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

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

@ -28,7 +28,9 @@
namespace Global
{
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 *wFooter;

@ -55,6 +55,8 @@ void Help::SwitchTo()
if (hasToBeResized)
Resize();
if (myScreen != this && myScreen->isTabbable())
myPrevScreen = myScreen;
myScreen = this;
RedrawHeader = 1;
@ -133,7 +135,10 @@ void Help::GetKeybindings()
*w << DisplayKeys(Key.Home) << "Home\n";
*w << DisplayKeys(Key.End) << "End\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.Playlist) << "Playlist screen\n";
*w << DisplayKeys(Key.Browser) << "Browse screen\n";

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

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

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

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

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

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

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

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

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

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

@ -118,6 +118,11 @@ class BasicScreen
/// cast to List if available or null pointer otherwise
///
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
///

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

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

@ -294,6 +294,7 @@ void DefaultConfiguration(ncmpcpp_config &conf)
conf.header_text_scrolling = true;
conf.statusbar_visibility = true;
conf.centered_cursor = false;
conf.screen_switcher_browser_only = true;
conf.autocenter_mode = false;
conf.wrapped_search = true;
conf.space_selects = false;
@ -754,6 +755,10 @@ void ReadConfiguration(ncmpcpp_config &conf)
{
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)
{
conf.autocenter_mode = v == "yes";

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

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

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

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

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

Loading…
Cancel
Save