From 73f6e2bdb48be844474ca688c19b8cb3d3ce8e6b Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 13 May 2006 16:17:00 +0000 Subject: handles flashing of titlebar if the window demands attention --- src/AttentionNoticeHandler.cc | 106 ++++++++++++++++++++++++++++++++++++++++++ src/AttentionNoticeHandler.hh | 55 ++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 src/AttentionNoticeHandler.cc create mode 100644 src/AttentionNoticeHandler.hh 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 @@ +// AttentionNoticeHandler.cc for fluxbox +// Copyright (c) 2006 Fluxbox Team (fluxgen at fluxbox dot org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id$ + +#include "AttentionNoticeHandler.hh" + +#include "Window.hh" +#include "Screen.hh" +#include "STLUtil.hh" + +#include "FbTk/Subject.hh" +#include "FbTk/Timer.hh" +#include "FbTk/Resource.hh" + +namespace { +class ToggleFrameFocusCmd: public FbTk::Command { +public: + ToggleFrameFocusCmd(FluxboxWindow &win): + m_win(win) {} + void execute() { + m_win.frame().setFocus( ! m_win.frame().focused() ); + m_win.attentionSig().notify(); + } +private: + FluxboxWindow& m_win; +}; + +} // end anonymous namespace + + +AttentionNoticeHandler::~AttentionNoticeHandler() { + STLUtil::destroyAndClearSecond(m_attentions); +} + +void AttentionNoticeHandler::addAttention(FluxboxWindow &win) { + // no need to add already focused window + if (win.isFocused()) + return; + + // Already have a notice for it? + NoticeMap::iterator it = m_attentions.find(&win); + if (it != m_attentions.end()) { + return; + } + + using namespace FbTk; + + ResourceManager &res = win.screen().resourceManager(); + std::string res_name = win.screen().name() + ".demandsAttentionTimeout"; + std::string res_alt_name = win.screen().name() + ".DemandsAttentionTimeout"; + Resource *timeout_res = dynamic_cast* >(res.findResource(res_name)); + if (timeout_res == 0) { + // no resource, create one and add it to managed resources + timeout_res = new FbTk::Resource(res, 500, res_name, res_alt_name); + win.screen().addManagedResource(timeout_res); + } + // disable if timeout is zero + if (**timeout_res == 0) + return; + + Timer *timer = new Timer(); + // setup timer + timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = **timeout_res * 1000; + RefCount cmd(new ToggleFrameFocusCmd(win)); + timer->setCommand(cmd); + timer->setTimeout(timeout); + timer->fireOnce(false); // will repeat until window has focus + timer->start(); + + m_attentions[&win] = timer; + // attach signals that will make notice go away + win.dieSig().attach(this); + win.focusSig().attach(this); +} + +void AttentionNoticeHandler::update(FbTk::Subject *subj) { + + // all signals results in destruction of the notice + + FluxboxWindow::WinSubject *winsubj = + static_cast(subj); + delete m_attentions[&winsubj->win()]; + m_attentions.erase(&winsubj->win()); +} + 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 @@ +// AttentionNoticeHandler.hh for fluxbox +// Copyright (c) 2006 Fluxbox Team (fluxgen at fluxbox dot org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id$ +#ifndef ATTENTIONNOTICEHANDLER_HH +#define ATTENTIONNOTICEHANDLER_HH + +#include "FbTk/Observer.hh" + +#include + +class FluxboxWindow; + +namespace FbTk { +class Timer; +} +/** + * Handles demands attention signals. + * Makes the title and iconbutton flash when the window + * demands attention. + */ +class AttentionNoticeHandler: public FbTk::Observer { +public: + ~AttentionNoticeHandler(); + + typedef std::map NoticeMap; + /// Adds a window that requires attention, + /// will fail if the window is already focused + void addAttention(FluxboxWindow &win); + /// removes the window from the attention map + void update(FbTk::Subject *subj); + +private: + NoticeMap m_attentions; +}; + +#endif // ATTENTIONNOTICEHANDLER_HH -- cgit v0.11.2