From b32511f4118e678c82d32801f9f1776f213188a3 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sun, 11 Aug 2002 22:35:40 +0000 Subject: added autogrouping functions --- src/Workspace.cc | 128 +++++++++++++++++++++++++++++++++++++++++-------------- src/Workspace.hh | 16 +++++-- 2 files changed, 108 insertions(+), 36 deletions(-) diff --git a/src/Workspace.cc b/src/Workspace.cc index e1854c6..6218a69 100644 --- a/src/Workspace.cc +++ b/src/Workspace.cc @@ -22,16 +22,9 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Workspace.cc,v 1.22 2002/08/04 15:37:37 fluxgen Exp $ +// $Id: Workspace.cc,v 1.23 2002/08/11 22:35:40 fluxgen Exp $ -// use GNU extensions -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif // _GNU_SOURCE - -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif // HAVE_CONFIG_H +#include "Workspace.hh" #include "i18n.hh" #include "fluxbox.hh" @@ -39,20 +32,30 @@ #include "Screen.hh" #include "Toolbar.hh" #include "Window.hh" -#include "Workspace.hh" #include "Windowmenu.hh" #include "StringUtil.hh" -#include -#include +// use GNU extensions +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif // _GNU_SOURCE + +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif // HAVE_CONFIG_H #include #include +#include +#include + #include #include + using namespace std; +Workspace::GroupList Workspace::m_groups; Workspace::Workspace(BScreen *scrn, unsigned int i): screen(scrn), @@ -60,15 +63,10 @@ lastfocus(0), m_clientmenu(this), m_name(""), m_id(i), -cascade_x(32), cascade_y(32) -{ +cascade_x(32), cascade_y(32) { - char *tmp; - screen->getNameOfWorkspace(m_id, &tmp); - setName(tmp); + setName(screen->getNameOfWorkspace(m_id)); - if (tmp) - delete [] tmp; } @@ -90,7 +88,7 @@ int Workspace::addWindow(FluxboxWindow *w, bool place) { stackingList.push_front(w); //insert window after the currently focused window - FluxboxWindow *focused = Fluxbox::instance()->getFocusedWindow(); + //FluxboxWindow *focused = Fluxbox::instance()->getFocusedWindow(); //if there isn't any window that's focused, just add it to the end of the list /* @@ -328,18 +326,91 @@ FluxboxWindow *Workspace::getWindow(unsigned int index) { } -int Workspace::getCount(void) const { +int Workspace::getCount() const { return windowList.size(); } +namespace { +// helper class for checkGrouping +class FindInGroup { +public: + FindInGroup(const FluxboxWindow &w):m_w(w) { } + bool operator ()(const string &name) { + return (name == m_w.instanceName()); + } +private: + const FluxboxWindow &m_w; +}; + +}; + +//Note: this function doesn't check if the window is groupable +void Workspace::checkGrouping(FluxboxWindow &win) { +#ifdef DEBUG + cerr<<__FILE__<<"("<<__LINE__<<"): Checking grouping. ("<instanceName()<getTab() == 0) + (*wit)->setTab(true); + if (win.getTab() == 0) + win.setTab(true); + (*wit)->getTab()->insert(win.getTab()); + + return; // grouping done + } + } + + } -void Workspace::update(void) { + } +} + +bool Workspace::loadGroups(const std::string &filename) { + ifstream infile(filename.c_str()); + if (!infile) + return false; + m_groups.clear(); // erase old groups + + // load new groups + while (!infile.eof()) { + string line; + vector names; + getline(infile, line); + StringUtil::stringtok(names, line); + m_groups.push_back(names); + } + + return true; +} + +void Workspace::update() { m_clientmenu.update(); screen->getToolbar()->redrawWindowLabel(True); } -bool Workspace::isCurrent(void) const{ +bool Workspace::isCurrent() const{ return (m_id == screen->getCurrentWorkspaceID()); } @@ -353,9 +424,8 @@ void Workspace::setCurrent(void) { } -void Workspace::setName(const char *name) { - - if (name) { +void Workspace::setName(const std::string &name) { + if (name.size() != 0) { m_name = name; } else { //if name == 0 then set default name from nls char tname[128]; @@ -515,12 +585,6 @@ void Workspace::placeWindow(FluxboxWindow *win) { ? screen->getTabHeight() : screen->getTabWidth(); break; - default: - #ifdef DEBUG - cerr << __FILE__ << ":" <<__LINE__ << ": " << - "Unsupported Placement" << endl; - #endif // DEBUG - break; } } else { // shaded window if (screen->getTabPlacement() == Tab::PTOP) diff --git a/src/Workspace.hh b/src/Workspace.hh index dc640ac..e461bd5 100644 --- a/src/Workspace.hh +++ b/src/Workspace.hh @@ -50,7 +50,7 @@ public: /** Set workspace name */ - void setName(const char *name); + void setName(const std::string &name); void showAll(); void hideAll(); void removeAll(); @@ -86,21 +86,29 @@ public: */ FluxboxWindow *getWindow(unsigned int id); const FluxboxWindow *getWindow(unsigned int id) const; - inline const Windows &getWindowList() const { return windowList; } + const Windows &getWindowList() const { return windowList; } + Windows &getWindowList() { return windowList; } + bool isCurrent() const; bool isLastWindow(FluxboxWindow *window) const; int getCount() const; - + void checkGrouping(FluxboxWindow &win); + static bool loadGroups(const std::string &filename); protected: void placeWindow(FluxboxWindow *win); private: + + BScreen *screen; FluxboxWindow *lastfocus; Clientmenu m_clientmenu; typedef std::list WindowStack; - + typedef std::vector Group; + typedef std::vector GroupList; + + static GroupList m_groups; ///< handle auto groupings WindowStack stackingList; Windows windowList; -- cgit v0.11.2