Add "Unclutter" command

Unclutter the desktop by using the MinOverlapPlacement
for all matching windows.

REQUEST: 248
This commit is contained in:
Thomas Lübking 2016-08-29 22:13:44 +02:00
parent 8a6623040e
commit a5b5be5e09
3 changed files with 52 additions and 0 deletions

View file

@ -434,6 +434,11 @@ doing so.
*ArrangeWindowsStackTop* places the main window on the BOTTOM half of the
screen and the tiled windows on the top half of the screen.
*Unclutter* 'pattern'::
Arrange all matching windows to reduce the overall window overlap as much
as possible. Windows are not resized.
See *CLIENT PATTERNS* for more about the 'pattern' arguments.
*ShowDesktop*::
Minimizes all windows on the current workspace. If they are already all
minimized, then it restores them.

View file

@ -23,6 +23,7 @@
#include "WorkspaceCmd.hh"
#include "Layer.hh"
#include "MinOverlapPlacement.hh"
#include "Workspace.hh"
#include "Window.hh"
#include "Screen.hh"
@ -203,6 +204,8 @@ FbTk::Command<void> *parseWindowList(const string &command,
} else if (command == "arrangewindowsstackbottom") {
int method = ArrangeWindowsCmd::STACKBOTTOM;
return new ArrangeWindowsCmd(method,pat);
} else if (command == "unclutter") {
return new UnclutterCmd(pat);
}
return 0;
@ -220,6 +223,7 @@ REGISTER_COMMAND_PARSER(arrangewindowsstackleft, parseWindowList, void);
REGISTER_COMMAND_PARSER(arrangewindowsstackright, parseWindowList, void);
REGISTER_COMMAND_PARSER(arrangewindowsstacktop, parseWindowList, void);
REGISTER_COMMAND_PARSER(arrangewindowsstackbottom, parseWindowList, void);
REGISTER_COMMAND_PARSER(unclutter, parseWindowList, void);
} // end anonymous namespace
@ -588,6 +592,41 @@ void ArrangeWindowsCmd::execute() {
}
}
void UnclutterCmd::execute() {
BScreen *screen = Fluxbox::instance()->mouseScreen();
if (screen == 0)
return;
Workspace *space = screen->currentWorkspace();
if (space->windowList().empty())
return;
const int head = screen->getCurrHead();
Workspace::Windows::iterator win;
Workspace::Windows placed_windows;
// list and clean up
for (win = space->windowList().begin(); win != space->windowList().end(); ++win) {
int winhead = screen->getHead((*win)->fbWindow());
if ((winhead == head || winhead == 0) && m_pat.match(**win)) {
placed_windows.push_back(*win);
(*win)->move(-(*win)->width(), -(*win)->height());
}
}
if (placed_windows.empty())
return;
// place
MinOverlapPlacement mopp;
int x, y;
for (win = placed_windows.begin(); win != placed_windows.end(); ++win) {
mopp.placeWindow(**win, head, x, y);
(*win)->move(x, y);
}
}
REGISTER_COMMAND(showdesktop, ShowDesktopCmd, void);
void ShowDesktopCmd::execute() {

View file

@ -187,6 +187,14 @@ private:
const ClientPattern m_pat;
};
class UnclutterCmd: public FbTk::Command<void> {
public:
explicit UnclutterCmd(std::string &pat): m_pat(pat.c_str()) { }
void execute();
private:
const ClientPattern m_pat;
};
class ShowDesktopCmd: public FbTk::Command<void> {
public:
void execute();