summaryrefslogtreecommitdiff
path: root/src/Focusable.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/Focusable.hh')
-rw-r--r--src/Focusable.hh140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/Focusable.hh b/src/Focusable.hh
new file mode 100644
index 0000000..e02e0d7
--- /dev/null
+++ b/src/Focusable.hh
@@ -0,0 +1,140 @@
1// Focusable.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 FOCUSABLE_HH
25#define FOCUSABLE_HH
26
27#include "FbTk/PixmapWithMask.hh"
28#include "FbTk/ITypeAheadable.hh"
29#include "FbTk/Subject.hh"
30
31#include <string>
32
33class BScreen;
34class FluxboxWindow;
35
36/**
37 * A Base class for any object that might be "focused".
38 * Such as FluxboxWindow, Menu etc
39 */
40class Focusable: public FbTk::ITypeAheadable {
41public:
42 Focusable(BScreen &scr, FluxboxWindow *fbwin = 0):
43 m_screen(scr), m_fbwin(fbwin),
44 m_instance_name("fluxbox"), m_class_name("fluxbox"),
45 m_focused(false), m_attention_state(false),
46 m_titlesig(*this), m_focussig(*this), m_diesig(*this),
47 m_attentionsig(*this) { }
48 virtual ~Focusable() { }
49 /**
50 * Take focus.
51 * @return true if the focuable took focus
52 */
53 virtual bool focus() { return false; }
54
55 /// @return true if the focusable has input focus
56 virtual bool isFocused() const { return m_focused; }
57 /// @return return true if it can be focused
58 virtual bool acceptsFocus() const { return true; }
59
60 /// @return true if icon button should appear focused
61 inline bool getAttentionState() const { return m_attention_state; }
62 /// @set the attention state
63 virtual void setAttentionState(bool value) {
64 m_attention_state = value; attentionSig().notify();
65 }
66
67 /// @return the screen in which this object resides
68 inline BScreen &screen() { return m_screen; }
69 /// @return the screen in which this object resides
70 inline const BScreen &screen() const { return m_screen; }
71
72 /**
73 * For accessing window properties, like shaded, minimized, etc.
74 * @return window context
75 */
76 inline const FluxboxWindow *fbwindow() const { return m_fbwin; }
77 /**
78 * For accessing window properties, like shaded, minimized, etc.
79 * @return window context
80 */
81 inline FluxboxWindow *fbwindow() { return m_fbwin; }
82
83 /// @return WM_CLASS class string (for pattern matching)
84 virtual const std::string &getWMClassClass() const { return m_class_name; }
85 /// @return WM_CLASS name string (for pattern matching)
86 virtual const std::string &getWMClassName() const { return m_instance_name; }
87 /// @return wm role string ( for pattern matching)
88 virtual std::string getWMRole() const { return "Focusable"; }
89
90 // so we can make nice buttons, menu entries, etc.
91 /// @return icon pixmap of the focusable
92 virtual const FbTk::PixmapWithMask &icon() const { return m_icon; }
93 /// @return title string
94 virtual const std::string &title() const { return m_title; }
95 /// @return type ahead string
96 const std::string &iTypeString() const { return title(); }
97 /**
98 * Signaling object to attatch observers to.
99 */
100 class FocusSubject: public FbTk::Subject {
101 public:
102 explicit FocusSubject(Focusable &w):m_win(w) { }
103 /// @return context focusable for this signal
104 Focusable &win() { return m_win; }
105 /// @return context focusable for this signal
106 const Focusable &win() const { return m_win; }
107 private:
108 Focusable &m_win; //< the context
109 };
110
111 /**
112 @name signals
113 @{
114 */
115 // Used for both title and icon changes.
116 FbTk::Subject &titleSig() { return m_titlesig; }
117 // Used for both title and icon changes.
118 const FbTk::Subject &titleSig() const { return m_titlesig; }
119 FbTk::Subject &focusSig() { return m_focussig; }
120 const FbTk::Subject &focusSig() const { return m_focussig; }
121 FbTk::Subject &dieSig() { return m_diesig; }
122 const FbTk::Subject &dieSig() const { return m_diesig; }
123 FbTk::Subject &attentionSig() { return m_attentionsig; }
124 const FbTk::Subject &attentionSig() const { return m_attentionsig; }
125 /** @} */ // end group signals
126
127protected:
128 BScreen &m_screen; //< the screen in which it works
129 FluxboxWindow *m_fbwin; //< the working fluxbox window
130
131 std::string m_title, m_instance_name, m_class_name;
132 bool m_focused; //< whether or not it has focus
133 bool m_attention_state; //< state of icon button while demanding attention
134 FbTk::PixmapWithMask m_icon; //< icon pixmap with mask
135
136 // state and hint signals
137 FocusSubject m_titlesig, m_focussig, m_diesig, m_attentionsig;
138};
139
140#endif // FOCUSABLE_HH