aboutsummaryrefslogtreecommitdiff
path: root/src/Workspace.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-08-11 22:35:40 (GMT)
committerfluxgen <fluxgen>2002-08-11 22:35:40 (GMT)
commitb32511f4118e678c82d32801f9f1776f213188a3 (patch)
treeafd0076f1adaab964e6b8d831abbf85ab13ab5e4 /src/Workspace.cc
parent9f3f5720ff0bea8210b2f9102f18770dd465d78e (diff)
downloadfluxbox-b32511f4118e678c82d32801f9f1776f213188a3.zip
fluxbox-b32511f4118e678c82d32801f9f1776f213188a3.tar.bz2
added autogrouping functions
Diffstat (limited to 'src/Workspace.cc')
-rw-r--r--src/Workspace.cc128
1 files changed, 96 insertions, 32 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 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: Workspace.cc,v 1.22 2002/08/04 15:37:37 fluxgen Exp $ 25// $Id: Workspace.cc,v 1.23 2002/08/11 22:35:40 fluxgen Exp $
26 26
27// use GNU extensions 27#include "Workspace.hh"
28#ifndef _GNU_SOURCE
29#define _GNU_SOURCE
30#endif // _GNU_SOURCE
31
32#ifdef HAVE_CONFIG_H
33# include "../config.h"
34#endif // HAVE_CONFIG_H
35 28
36#include "i18n.hh" 29#include "i18n.hh"
37#include "fluxbox.hh" 30#include "fluxbox.hh"
@@ -39,20 +32,30 @@
39#include "Screen.hh" 32#include "Screen.hh"
40#include "Toolbar.hh" 33#include "Toolbar.hh"
41#include "Window.hh" 34#include "Window.hh"
42#include "Workspace.hh"
43#include "Windowmenu.hh" 35#include "Windowmenu.hh"
44#include "StringUtil.hh" 36#include "StringUtil.hh"
45 37
46#include <stdio.h> 38// use GNU extensions
47#include <string.h> 39#ifndef _GNU_SOURCE
40#define _GNU_SOURCE
41#endif // _GNU_SOURCE
42
43#ifdef HAVE_CONFIG_H
44#include "../config.h"
45#endif // HAVE_CONFIG_H
48 46
49#include <X11/Xlib.h> 47#include <X11/Xlib.h>
50#include <X11/Xatom.h> 48#include <X11/Xatom.h>
51 49
50#include <cstdio>
51#include <cstring>
52
52#include <algorithm> 53#include <algorithm>
53#include <iostream> 54#include <iostream>
55
54using namespace std; 56using namespace std;
55 57
58Workspace::GroupList Workspace::m_groups;
56 59
57Workspace::Workspace(BScreen *scrn, unsigned int i): 60Workspace::Workspace(BScreen *scrn, unsigned int i):
58screen(scrn), 61screen(scrn),
@@ -60,15 +63,10 @@ lastfocus(0),
60m_clientmenu(this), 63m_clientmenu(this),
61m_name(""), 64m_name(""),
62m_id(i), 65m_id(i),
63cascade_x(32), cascade_y(32) 66cascade_x(32), cascade_y(32) {
64{
65 67
66 char *tmp; 68 setName(screen->getNameOfWorkspace(m_id));
67 screen->getNameOfWorkspace(m_id, &tmp);
68 setName(tmp);
69 69
70 if (tmp)
71 delete [] tmp;
72} 70}
73 71
74 72
@@ -90,7 +88,7 @@ int Workspace::addWindow(FluxboxWindow *w, bool place) {
90 stackingList.push_front(w); 88 stackingList.push_front(w);
91 89
92 //insert window after the currently focused window 90 //insert window after the currently focused window
93 FluxboxWindow *focused = Fluxbox::instance()->getFocusedWindow(); 91 //FluxboxWindow *focused = Fluxbox::instance()->getFocusedWindow();
94 92
95 //if there isn't any window that's focused, just add it to the end of the list 93 //if there isn't any window that's focused, just add it to the end of the list
96 /* 94 /*
@@ -328,18 +326,91 @@ FluxboxWindow *Workspace::getWindow(unsigned int index) {
328} 326}
329 327
330 328
331int Workspace::getCount(void) const { 329int Workspace::getCount() const {
332 return windowList.size(); 330 return windowList.size();
333} 331}
334 332
333namespace {
334// helper class for checkGrouping
335class FindInGroup {
336public:
337 FindInGroup(const FluxboxWindow &w):m_w(w) { }
338 bool operator ()(const string &name) {
339 return (name == m_w.instanceName());
340 }
341private:
342 const FluxboxWindow &m_w;
343};
344
345};
346
347//Note: this function doesn't check if the window is groupable
348void Workspace::checkGrouping(FluxboxWindow &win) {
349#ifdef DEBUG
350 cerr<<__FILE__<<"("<<__LINE__<<"): Checking grouping. ("<<win.instanceName()<<"/"<<
351 win.className()<<")"<<endl;
352#endif // DEBUG
353
354 // go throu every group and search for matching win instancename
355 GroupList::iterator g(m_groups.begin());
356 GroupList::iterator g_end(m_groups.end());
357 for (; g != g_end; ++g) {
358 Group::iterator name((*g).begin());
359 Group::iterator name_end((*g).end());
360 for (; name != name_end; ++name) {
361
362 if ((*name) != win.instanceName())
363 continue;
364
365 // find a window with the specific name
366 Windows::iterator wit(getWindowList().begin());
367 Windows::iterator wit_end(getWindowList().end());
368 for (; wit != wit_end; ++wit) {
369#ifdef DEBUG
370 cerr<<__FILE__<<" check group with : "<<(*wit)->instanceName()<<endl;
371#endif // DEBUG
372 if (find_if((*g).begin(), (*g).end(), FindInGroup(*(*wit))) != (*g).end()) {
373 //toggle tab on
374 if ((*wit)->getTab() == 0)
375 (*wit)->setTab(true);
376 if (win.getTab() == 0)
377 win.setTab(true);
378 (*wit)->getTab()->insert(win.getTab());
379
380 return; // grouping done
381 }
382 }
383
384 }
335 385
336void Workspace::update(void) { 386 }
387}
388
389bool Workspace::loadGroups(const std::string &filename) {
390 ifstream infile(filename.c_str());
391 if (!infile)
392 return false;
393 m_groups.clear(); // erase old groups
394
395 // load new groups
396 while (!infile.eof()) {
397 string line;
398 vector<string> names;
399 getline(infile, line);
400 StringUtil::stringtok(names, line);
401 m_groups.push_back(names);
402 }
403
404 return true;
405}
406
407void Workspace::update() {
337 m_clientmenu.update(); 408 m_clientmenu.update();
338 screen->getToolbar()->redrawWindowLabel(True); 409 screen->getToolbar()->redrawWindowLabel(True);
339} 410}
340 411
341 412
342bool Workspace::isCurrent(void) const{ 413bool Workspace::isCurrent() const{
343 return (m_id == screen->getCurrentWorkspaceID()); 414 return (m_id == screen->getCurrentWorkspaceID());
344} 415}
345 416
@@ -353,9 +424,8 @@ void Workspace::setCurrent(void) {
353} 424}
354 425
355 426
356void Workspace::setName(const char *name) { 427void Workspace::setName(const std::string &name) {
357 428 if (name.size() != 0) {
358 if (name) {
359 m_name = name; 429 m_name = name;
360 } else { //if name == 0 then set default name from nls 430 } else { //if name == 0 then set default name from nls
361 char tname[128]; 431 char tname[128];
@@ -515,12 +585,6 @@ void Workspace::placeWindow(FluxboxWindow *win) {
515 ? screen->getTabHeight() 585 ? screen->getTabHeight()
516 : screen->getTabWidth(); 586 : screen->getTabWidth();
517 break; 587 break;
518 default:
519 #ifdef DEBUG
520 cerr << __FILE__ << ":" <<__LINE__ << ": " <<
521 "Unsupported Placement" << endl;
522 #endif // DEBUG
523 break;
524 } 588 }
525 } else { // shaded window 589 } else { // shaded window
526 if (screen->getTabPlacement() == Tab::PTOP) 590 if (screen->getTabPlacement() == Tab::PTOP)