From a5b5be5e09ef4488d7dcebf2091e94b8e4d6e727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Mon, 29 Aug 2016 22:13:44 +0200 Subject: Add "Unclutter" command Unclutter the desktop by using the MinOverlapPlacement for all matching windows. REQUEST: 248 --- doc/asciidoc/fluxbox-keys.txt | 5 +++++ src/WorkspaceCmd.cc | 39 +++++++++++++++++++++++++++++++++++++++ src/WorkspaceCmd.hh | 8 ++++++++ 3 files changed, 52 insertions(+) diff --git a/doc/asciidoc/fluxbox-keys.txt b/doc/asciidoc/fluxbox-keys.txt index 7d295f2..52037ab 100644 --- a/doc/asciidoc/fluxbox-keys.txt +++ b/doc/asciidoc/fluxbox-keys.txt @@ -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. diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc index 6422c3f..3a1a3b4 100644 --- a/src/WorkspaceCmd.cc +++ b/src/WorkspaceCmd.cc @@ -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 *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() { diff --git a/src/WorkspaceCmd.hh b/src/WorkspaceCmd.hh index b118d02..4f294fe 100644 --- a/src/WorkspaceCmd.hh +++ b/src/WorkspaceCmd.hh @@ -187,6 +187,14 @@ private: const ClientPattern m_pat; }; +class UnclutterCmd: public FbTk::Command { +public: + explicit UnclutterCmd(std::string &pat): m_pat(pat.c_str()) { } + void execute(); +private: + const ClientPattern m_pat; +}; + class ShowDesktopCmd: public FbTk::Command { public: void execute(); -- cgit v0.11.2