diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Workspace.cc | 128 | ||||
-rw-r--r-- | 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 @@ | |||
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 | |||
54 | using namespace std; | 56 | using namespace std; |
55 | 57 | ||
58 | Workspace::GroupList Workspace::m_groups; | ||
56 | 59 | ||
57 | Workspace::Workspace(BScreen *scrn, unsigned int i): | 60 | Workspace::Workspace(BScreen *scrn, unsigned int i): |
58 | screen(scrn), | 61 | screen(scrn), |
@@ -60,15 +63,10 @@ lastfocus(0), | |||
60 | m_clientmenu(this), | 63 | m_clientmenu(this), |
61 | m_name(""), | 64 | m_name(""), |
62 | m_id(i), | 65 | m_id(i), |
63 | cascade_x(32), cascade_y(32) | 66 | cascade_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 | ||
331 | int Workspace::getCount(void) const { | 329 | int Workspace::getCount() const { |
332 | return windowList.size(); | 330 | return windowList.size(); |
333 | } | 331 | } |
334 | 332 | ||
333 | namespace { | ||
334 | // helper class for checkGrouping | ||
335 | class FindInGroup { | ||
336 | public: | ||
337 | FindInGroup(const FluxboxWindow &w):m_w(w) { } | ||
338 | bool operator ()(const string &name) { | ||
339 | return (name == m_w.instanceName()); | ||
340 | } | ||
341 | private: | ||
342 | const FluxboxWindow &m_w; | ||
343 | }; | ||
344 | |||
345 | }; | ||
346 | |||
347 | //Note: this function doesn't check if the window is groupable | ||
348 | void 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 | ||
336 | void Workspace::update(void) { | 386 | } |
387 | } | ||
388 | |||
389 | bool 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 | |||
407 | void 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 | ||
342 | bool Workspace::isCurrent(void) const{ | 413 | bool 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 | ||
356 | void Workspace::setName(const char *name) { | 427 | void 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) |
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: | |||
50 | /** | 50 | /** |
51 | Set workspace name | 51 | Set workspace name |
52 | */ | 52 | */ |
53 | void setName(const char *name); | 53 | void setName(const std::string &name); |
54 | void showAll(); | 54 | void showAll(); |
55 | void hideAll(); | 55 | void hideAll(); |
56 | void removeAll(); | 56 | void removeAll(); |
@@ -86,21 +86,29 @@ public: | |||
86 | */ | 86 | */ |
87 | FluxboxWindow *getWindow(unsigned int id); | 87 | FluxboxWindow *getWindow(unsigned int id); |
88 | const FluxboxWindow *getWindow(unsigned int id) const; | 88 | const FluxboxWindow *getWindow(unsigned int id) const; |
89 | inline const Windows &getWindowList() const { return windowList; } | 89 | const Windows &getWindowList() const { return windowList; } |
90 | Windows &getWindowList() { return windowList; } | ||
91 | |||
90 | bool isCurrent() const; | 92 | bool isCurrent() const; |
91 | bool isLastWindow(FluxboxWindow *window) const; | 93 | bool isLastWindow(FluxboxWindow *window) const; |
92 | int getCount() const; | 94 | int getCount() const; |
93 | 95 | void checkGrouping(FluxboxWindow &win); | |
96 | static bool loadGroups(const std::string &filename); | ||
94 | protected: | 97 | protected: |
95 | void placeWindow(FluxboxWindow *win); | 98 | void placeWindow(FluxboxWindow *win); |
96 | 99 | ||
97 | private: | 100 | private: |
101 | |||
102 | |||
98 | BScreen *screen; | 103 | BScreen *screen; |
99 | FluxboxWindow *lastfocus; | 104 | FluxboxWindow *lastfocus; |
100 | Clientmenu m_clientmenu; | 105 | Clientmenu m_clientmenu; |
101 | 106 | ||
102 | typedef std::list<FluxboxWindow *> WindowStack; | 107 | typedef std::list<FluxboxWindow *> WindowStack; |
103 | 108 | typedef std::vector<std::string> Group; | |
109 | typedef std::vector<Group> GroupList; | ||
110 | |||
111 | static GroupList m_groups; ///< handle auto groupings | ||
104 | 112 | ||
105 | WindowStack stackingList; | 113 | WindowStack stackingList; |
106 | Windows windowList; | 114 | Windows windowList; |