all repos — fluxbox @ efc1ec4b206f3e24c1fd9ca29096f23735f2e7ae

custom fork of the fluxbox windowmanager

fixed dispatch to parent
fluxgen fluxgen
commit

efc1ec4b206f3e24c1fd9ca29096f23735f2e7ae

parent

bc8e67136f9df2d0475f0e2f01e03976aabfa259

2 files changed, 62 insertions(+), 27 deletions(-)

jump to
M src/FbTk/EventManager.ccsrc/FbTk/EventManager.cc

@@ -19,10 +19,11 @@ // 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: EventManager.cc,v 1.6 2003/05/17 10:40:12 fluxgen Exp $ +// $Id: EventManager.cc,v 1.7 2003/08/23 15:44:06 fluxgen Exp $ #include "EventManager.hh" #include "FbWindow.hh" +#include "App.hh" #include <iostream> using namespace std;

@@ -40,17 +41,45 @@ cerr<<"FbTk::EventManager: Warning: unregistered eventhandlers!"<<endl;

} void EventManager::handleEvent(XEvent &ev) { - // find eventhandler for event window - if (m_eventhandlers.find(ev.xany.window) == m_eventhandlers.end()) { - //cerr<<"Can't find window="<<ev.xany.window<<endl; - return; + dispatch(ev.xany.window, ev); +} + +void EventManager::add(EventHandler &ev, const FbWindow &win) { + registerEventHandler(ev, win.window()); +} + +void EventManager::addParent(EventHandler &ev, const FbWindow &win) { + if (win.window() != 0) + m_parent[win.window()] = &ev; +} + +void EventManager::remove(const FbWindow &win) { + unregisterEventHandler(win.window()); +} + +void EventManager::registerEventHandler(EventHandler &ev, Window win) { + if (win != None) + m_eventhandlers[win] = &ev; +} + +void EventManager::unregisterEventHandler(Window win) { + if (win != None) { + m_eventhandlers.erase(win); + m_parent.erase(win); } - EventHandler *evhand = m_eventhandlers[ev.xany.window]; - if (evhand == 0) { - cerr<<"FbTk::EventManager: Warning: evhand == 0!"<<endl; +} + +void EventManager::dispatch(Window win, XEvent &ev, bool parent) { + + EventHandler *evhand = 0; + if (parent) + evhand = m_parent[win]; + else + evhand = m_eventhandlers[win]; + + if (evhand == 0) return; - } - + switch (ev.xany.type) { case KeyPress: evhand->keyPressEvent(ev.xkey);

@@ -80,24 +109,27 @@ default:

evhand->handleEvent(ev); break; }; -} + + // find out which window is the parent and + // dispatch event + Window root, parent_win, *children = 0; + unsigned int num_children; + if (XQueryTree(FbTk::App::instance()->display(), win, + &root, &parent_win, &children, &num_children) != 0 && + parent_win != 0 && + parent_win != root) { + + if (children != 0) + XFree(children); -void EventManager::add(EventHandler &ev, const FbWindow &win) { - registerEventHandler(ev, win.window()); -} + if (m_parent[parent_win] == 0) + return; -void EventManager::remove(const FbWindow &win) { - unregisterEventHandler(win.window()); -} + // dispatch event to parent + dispatch(parent_win, ev, true); -void EventManager::registerEventHandler(EventHandler &ev, Window win) { - if (win != None) - m_eventhandlers[win] = &ev; -} + } -void EventManager::unregisterEventHandler(Window win) { - if (win != None) - m_eventhandlers.erase(win); } -}; +}; // end namespace FbTk
M src/FbTk/EventManager.hhsrc/FbTk/EventManager.hh

@@ -19,7 +19,7 @@ // 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: EventManager.hh,v 1.4 2002/12/03 17:05:45 fluxgen Exp $ +// $Id: EventManager.hh,v 1.5 2003/08/23 15:44:06 fluxgen Exp $ #include "EventHandler.hh" #include <map>

@@ -36,6 +36,8 @@ public:

static EventManager *instance(); void handleEvent(XEvent &ev); + // adds a parent to listen to the childrens events + void addParent(EventHandler &ev, const FbWindow &parent); void add(EventHandler &ev, const FbWindow &win); void remove(const FbWindow &win); void add(EventHandler &ev, Window win) { registerEventHandler(ev, win); }

@@ -45,8 +47,9 @@ void unregisterEventHandler(Window win);

private: EventManager() { } ~EventManager(); - + void dispatch(Window win, XEvent &event, bool parent = false); std::map<Window, EventHandler *> m_eventhandlers; + std::map<Window, EventHandler *> m_parent; }; }; //end namespace FbTk