summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/AttentionNoticeHandler.cc106
-rw-r--r--src/AttentionNoticeHandler.hh55
2 files changed, 161 insertions, 0 deletions
diff --git a/src/AttentionNoticeHandler.cc b/src/AttentionNoticeHandler.cc
new file mode 100644
index 0000000..7cc2760
--- /dev/null
+++ b/src/AttentionNoticeHandler.cc
@@ -0,0 +1,106 @@
1// AttentionNoticeHandler.cc for fluxbox
2// Copyright (c) 2006 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#include "AttentionNoticeHandler.hh"
25
26#include "Window.hh"
27#include "Screen.hh"
28#include "STLUtil.hh"
29
30#include "FbTk/Subject.hh"
31#include "FbTk/Timer.hh"
32#include "FbTk/Resource.hh"
33
34namespace {
35class ToggleFrameFocusCmd: public FbTk::Command {
36public:
37 ToggleFrameFocusCmd(FluxboxWindow &win):
38 m_win(win) {}
39 void execute() {
40 m_win.frame().setFocus( ! m_win.frame().focused() );
41 m_win.attentionSig().notify();
42 }
43private:
44 FluxboxWindow& m_win;
45};
46
47} // end anonymous namespace
48
49
50AttentionNoticeHandler::~AttentionNoticeHandler() {
51 STLUtil::destroyAndClearSecond(m_attentions);
52}
53
54void AttentionNoticeHandler::addAttention(FluxboxWindow &win) {
55 // no need to add already focused window
56 if (win.isFocused())
57 return;
58
59 // Already have a notice for it?
60 NoticeMap::iterator it = m_attentions.find(&win);
61 if (it != m_attentions.end()) {
62 return;
63 }
64
65 using namespace FbTk;
66
67 ResourceManager &res = win.screen().resourceManager();
68 std::string res_name = win.screen().name() + ".demandsAttentionTimeout";
69 std::string res_alt_name = win.screen().name() + ".DemandsAttentionTimeout";
70 Resource<int> *timeout_res = dynamic_cast<Resource<int>* >(res.findResource(res_name));
71 if (timeout_res == 0) {
72 // no resource, create one and add it to managed resources
73 timeout_res = new FbTk::Resource<int>(res, 500, res_name, res_alt_name);
74 win.screen().addManagedResource(timeout_res);
75 }
76 // disable if timeout is zero
77 if (**timeout_res == 0)
78 return;
79
80 Timer *timer = new Timer();
81 // setup timer
82 timeval timeout;
83 timeout.tv_sec = 0;
84 timeout.tv_usec = **timeout_res * 1000;
85 RefCount<Command> cmd(new ToggleFrameFocusCmd(win));
86 timer->setCommand(cmd);
87 timer->setTimeout(timeout);
88 timer->fireOnce(false); // will repeat until window has focus
89 timer->start();
90
91 m_attentions[&win] = timer;
92 // attach signals that will make notice go away
93 win.dieSig().attach(this);
94 win.focusSig().attach(this);
95}
96
97void AttentionNoticeHandler::update(FbTk::Subject *subj) {
98
99 // all signals results in destruction of the notice
100
101 FluxboxWindow::WinSubject *winsubj =
102 static_cast<FluxboxWindow::WinSubject*>(subj);
103 delete m_attentions[&winsubj->win()];
104 m_attentions.erase(&winsubj->win());
105}
106
diff --git a/src/AttentionNoticeHandler.hh b/src/AttentionNoticeHandler.hh
new file mode 100644
index 0000000..aa2f9f2
--- /dev/null
+++ b/src/AttentionNoticeHandler.hh
@@ -0,0 +1,55 @@
1// AttentionNoticeHandler.hh for fluxbox
2// Copyright (c) 2006 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#ifndef ATTENTIONNOTICEHANDLER_HH
24#define ATTENTIONNOTICEHANDLER_HH
25
26#include "FbTk/Observer.hh"
27
28#include <map>
29
30class FluxboxWindow;
31
32namespace FbTk {
33class Timer;
34}
35/**
36 * Handles demands attention signals.
37 * Makes the title and iconbutton flash when the window
38 * demands attention.
39 */
40class AttentionNoticeHandler: public FbTk::Observer {
41public:
42 ~AttentionNoticeHandler();
43
44 typedef std::map<FluxboxWindow*, FbTk::Timer*> NoticeMap;
45 /// Adds a window that requires attention,
46 /// will fail if the window is already focused
47 void addAttention(FluxboxWindow &win);
48 /// removes the window from the attention map
49 void update(FbTk::Subject *subj);
50
51private:
52 NoticeMap m_attentions;
53};
54
55#endif // ATTENTIONNOTICEHANDLER_HH