aboutsummaryrefslogtreecommitdiff
path: root/src/FocusableList.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FocusableList.hh')
-rw-r--r--src/FocusableList.hh121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/FocusableList.hh b/src/FocusableList.hh
new file mode 100644
index 0000000..7cca298
--- /dev/null
+++ b/src/FocusableList.hh
@@ -0,0 +1,121 @@
1// FocusableList.hh
2// Copyright (c) 2007 Fluxbox Team (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: $
23
24#ifndef FOCUSABLELIST_HH
25#define FOCUSABLELIST_HH
26
27#include "FbTk/NotCopyable.hh"
28#include "FbTk/Observer.hh"
29#include "FbTk/Subject.hh"
30
31#include "ClientPattern.hh"
32
33#include <list>
34#include <string>
35
36class BScreen;
37class Focusable;
38
39class FocusableList: public FbTk::Observer, private FbTk::NotCopyable {
40public:
41 typedef std::list<Focusable *> Focusables;
42
43 /// list option bits
44 enum {
45 LIST_GROUPS = 0x01, //< list groups instead of clients
46 STATIC_ORDER = 0x02, ///< use creation order instead of focused order
47 };
48
49 FocusableList(BScreen &scr): m_pat(0), m_parent(0), m_screen(scr) { }
50 FocusableList(BScreen &scr, const std::string pat);
51 FocusableList(BScreen &scr, const FocusableList &parent,
52 const std::string pat);
53
54 static void parseArgs(const std::string &in, int &opts, std::string &out);
55 static const FocusableList *getListFromOptions(BScreen &scr, int opts);
56
57 void update(FbTk::Subject *subj);
58
59 /// functions for modifying the list contents
60 void pushFront(Focusable &win);
61 void pushBack(Focusable &win);
62 void moveToFront(Focusable &win);
63 void moveToBack(Focusable &win);
64 void remove(Focusable &win);
65
66 /// accessor for list
67 Focusables &clientList() { return m_list; }
68 const Focusables &clientList() const { return m_list; }
69
70 /// does the list contain any windows?
71 bool empty() const { return m_list.empty(); }
72 /// does the list contain the given window?
73 bool contains(const Focusable &win) const;
74
75 /**
76 @name signals
77 @{
78 */
79 FbTk::Subject &orderSig() { return m_ordersig; }
80 const FbTk::Subject &orderSig() const { return m_ordersig; }
81 FbTk::Subject &addSig() { return m_addsig; }
82 const FbTk::Subject &addSig() const { return m_addsig; }
83 FbTk::Subject &removeSig() { return m_removesig; }
84 const FbTk::Subject &removeSig() const { return m_removesig; }
85 FbTk::Subject &resetSig() { return m_resetsig; }
86 const FbTk::Subject &resetSig() const { return m_resetsig; }
87 /** @} */ // end group signals
88
89 /**
90 * Signaling object to attatch observers to.
91 */
92 class FocusableListSubject: public FbTk::Subject {
93 public:
94 explicit FocusableListSubject(): m_win(0) { }
95 void notify(Focusable *win) { m_win = win; FbTk::Subject::notify(); }
96 /// @return context for this signal
97 Focusable *win() { return m_win; }
98
99 private:
100 Focusable *m_win;
101 };
102
103private:
104 void init();
105 void addMatching();
106 void checkUpdate(Focusable &win);
107 bool insertFromParent(Focusable &win);
108 void attachSignals(Focusable &win);
109 void detachSignals(Focusable &win);
110 void reset();
111 void attachChild(FocusableList &child) const;
112
113 std::auto_ptr<ClientPattern> m_pat;
114 const FocusableList *m_parent;
115 BScreen &m_screen;
116 std::list<Focusable *> m_list;
117
118 mutable FocusableListSubject m_ordersig, m_addsig, m_removesig, m_resetsig;
119};
120
121#endif // FOCUSABLELIST_HH