diff options
author | fluxgen <fluxgen> | 2006-05-13 16:17:00 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2006-05-13 16:17:00 (GMT) |
commit | 73f6e2bdb48be844474ca688c19b8cb3d3ce8e6b (patch) | |
tree | 616d9427d46f4858e242bd60b9f654cc49d24e5f /src/AttentionNoticeHandler.cc | |
parent | 8267672d73d498224bda0fd6680fd2db6aac49db (diff) | |
download | fluxbox-73f6e2bdb48be844474ca688c19b8cb3d3ce8e6b.zip fluxbox-73f6e2bdb48be844474ca688c19b8cb3d3ce8e6b.tar.bz2 |
handles flashing of titlebar if the window demands attention
Diffstat (limited to 'src/AttentionNoticeHandler.cc')
-rw-r--r-- | src/AttentionNoticeHandler.cc | 106 |
1 files changed, 106 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 | |||
34 | namespace { | ||
35 | class ToggleFrameFocusCmd: public FbTk::Command { | ||
36 | public: | ||
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 | } | ||
43 | private: | ||
44 | FluxboxWindow& m_win; | ||
45 | }; | ||
46 | |||
47 | } // end anonymous namespace | ||
48 | |||
49 | |||
50 | AttentionNoticeHandler::~AttentionNoticeHandler() { | ||
51 | STLUtil::destroyAndClearSecond(m_attentions); | ||
52 | } | ||
53 | |||
54 | void 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 | |||
97 | void 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 | |||