Skip to content

Commit

Permalink
Next|PrevWorkspace 0 toggles former Workspace
Browse files Browse the repository at this point in the history
REQUEST: 185
also PATCH 92
  • Loading branch information
luebking committed Sep 3, 2016
1 parent 36993a8 commit a2fc845
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions doc/asciidoc/fluxbox-keys.txt
Expand Up @@ -359,6 +359,8 @@ called).
offset value 'n', which defaults to *1* and refers to the number of
workspaces to move at one time. {Next,Prev}Workspace wrap around when
going past the last workspace, whereas {Right,Left}Workspace do not.
The special offset "0" will toggle the former workspace for Next- and
PrevWorkspace

*Workspace* 'number'::
Jumps to the given workspace 'number'. The first workspace is *1*.
Expand Down
15 changes: 13 additions & 2 deletions src/Screen.cc
Expand Up @@ -194,6 +194,7 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
m_layermanager(num_layers),
root_colormap_installed(false),
m_current_workspace(0),
m_former_workspace(0),
m_focused_windowtheme(new FbWinFrameTheme(scrn, ".focus", ".Focus")),
m_unfocused_windowtheme(new FbWinFrameTheme(scrn, ".unfocus", ".Unfocus")),
// the order of windowtheme and winbutton theme is important
Expand Down Expand Up @@ -919,6 +920,8 @@ int BScreen::removeLastWorkspace() {

if (m_current_workspace->workspaceID() == wkspc->workspaceID())
changeWorkspaceID(m_current_workspace->workspaceID() - 1);
if (m_former_workspace && m_former_workspace->workspaceID() == wkspc->workspaceID())
m_former_workspace = 0;

wkspc->removeAll(wkspc->workspaceID()-1);

Expand Down Expand Up @@ -950,6 +953,8 @@ void BScreen::changeWorkspaceID(unsigned int id, bool revert) {
id == m_current_workspace->workspaceID())
return;

m_former_workspace = m_current_workspace;

/* Ignore all EnterNotify events until the pointer actually moves */
this->focusControl().ignoreAtPointer();

Expand Down Expand Up @@ -1524,14 +1529,20 @@ void BScreen::setLayer(FbTk::LayerItem &item, int layernum) {
Goes to the workspace "right" of the current
*/
void BScreen::nextWorkspace(int delta) {
changeWorkspaceID( (currentWorkspaceID() + delta) % numberOfWorkspaces());
if (delta)
changeWorkspaceID( (currentWorkspaceID() + delta) % numberOfWorkspaces());
else if (m_former_workspace)
changeWorkspaceID(m_former_workspace->workspaceID());
}

/**
Goes to the workspace "left" of the current
*/
void BScreen::prevWorkspace(int delta) {
changeWorkspaceID( (static_cast<signed>(numberOfWorkspaces()) + currentWorkspaceID() - (delta % numberOfWorkspaces())) % numberOfWorkspaces());
if (delta)
changeWorkspaceID( (static_cast<signed>(numberOfWorkspaces()) + currentWorkspaceID() - (delta % numberOfWorkspaces())) % numberOfWorkspaces());
else if (m_former_workspace)
changeWorkspaceID(m_former_workspace->workspaceID());
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Screen.hh
Expand Up @@ -502,6 +502,7 @@ private:
std::unique_ptr<ToolButtonMap> m_toolButtonMap;

Workspace *m_current_workspace;
Workspace *m_former_workspace;

WorkspaceNames m_workspace_names;
Workspaces m_workspaces_list;
Expand Down
10 changes: 4 additions & 6 deletions src/WorkspaceCmd.cc
Expand Up @@ -357,15 +357,13 @@ REGISTER_COMMAND_PARSER(workspace, parseIntCmd, void);
} // end anonymous namespace

void NextWorkspaceCmd::execute() {
BScreen *screen = Fluxbox::instance()->mouseScreen();
if (screen != 0)
screen->nextWorkspace(m_option == 0 ? 1 : m_option);
if (BScreen *screen = Fluxbox::instance()->mouseScreen())
screen->nextWorkspace(m_option);
}

void PrevWorkspaceCmd::execute() {
BScreen *screen = Fluxbox::instance()->mouseScreen();
if (screen != 0)
screen->prevWorkspace(m_option == 0 ? 1 : m_option);
if (BScreen *screen = Fluxbox::instance()->mouseScreen())
screen->prevWorkspace(m_option);
}

void LeftWorkspaceCmd::execute() {
Expand Down

0 comments on commit a2fc845

Please sign in to comment.