aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/EventManager.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-08-23 15:44:06 (GMT)
committerfluxgen <fluxgen>2003-08-23 15:44:06 (GMT)
commitefc1ec4b206f3e24c1fd9ca29096f23735f2e7ae (patch)
tree063d0ecdf263d60e8a083f285bf84696b3978a48 /src/FbTk/EventManager.cc
parentbc8e67136f9df2d0475f0e2f01e03976aabfa259 (diff)
downloadfluxbox-efc1ec4b206f3e24c1fd9ca29096f23735f2e7ae.zip
fluxbox-efc1ec4b206f3e24c1fd9ca29096f23735f2e7ae.tar.bz2
fixed dispatch to parent
Diffstat (limited to 'src/FbTk/EventManager.cc')
-rw-r--r--src/FbTk/EventManager.cc82
1 files changed, 57 insertions, 25 deletions
diff --git a/src/FbTk/EventManager.cc b/src/FbTk/EventManager.cc
index 1f2aef1..cd23416 100644
--- a/src/FbTk/EventManager.cc
+++ b/src/FbTk/EventManager.cc
@@ -19,10 +19,11 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: EventManager.cc,v 1.6 2003/05/17 10:40:12 fluxgen Exp $ 22// $Id: EventManager.cc,v 1.7 2003/08/23 15:44:06 fluxgen Exp $
23 23
24#include "EventManager.hh" 24#include "EventManager.hh"
25#include "FbWindow.hh" 25#include "FbWindow.hh"
26#include "App.hh"
26 27
27#include <iostream> 28#include <iostream>
28using namespace std; 29using namespace std;
@@ -40,17 +41,45 @@ EventManager::~EventManager() {
40} 41}
41 42
42void EventManager::handleEvent(XEvent &ev) { 43void EventManager::handleEvent(XEvent &ev) {
43 // find eventhandler for event window 44 dispatch(ev.xany.window, ev);
44 if (m_eventhandlers.find(ev.xany.window) == m_eventhandlers.end()) { 45}
45 //cerr<<"Can't find window="<<ev.xany.window<<endl; 46
46 return; 47void EventManager::add(EventHandler &ev, const FbWindow &win) {
48 registerEventHandler(ev, win.window());
49}
50
51void EventManager::addParent(EventHandler &ev, const FbWindow &win) {
52 if (win.window() != 0)
53 m_parent[win.window()] = &ev;
54}
55
56void EventManager::remove(const FbWindow &win) {
57 unregisterEventHandler(win.window());
58}
59
60void EventManager::registerEventHandler(EventHandler &ev, Window win) {
61 if (win != None)
62 m_eventhandlers[win] = &ev;
63}
64
65void EventManager::unregisterEventHandler(Window win) {
66 if (win != None) {
67 m_eventhandlers.erase(win);
68 m_parent.erase(win);
47 } 69 }
48 EventHandler *evhand = m_eventhandlers[ev.xany.window]; 70}
49 if (evhand == 0) { 71
50 cerr<<"FbTk::EventManager: Warning: evhand == 0!"<<endl; 72void EventManager::dispatch(Window win, XEvent &ev, bool parent) {
73
74 EventHandler *evhand = 0;
75 if (parent)
76 evhand = m_parent[win];
77 else
78 evhand = m_eventhandlers[win];
79
80 if (evhand == 0)
51 return; 81 return;
52 } 82
53
54 switch (ev.xany.type) { 83 switch (ev.xany.type) {
55 case KeyPress: 84 case KeyPress:
56 evhand->keyPressEvent(ev.xkey); 85 evhand->keyPressEvent(ev.xkey);
@@ -80,24 +109,27 @@ void EventManager::handleEvent(XEvent &ev) {
80 evhand->handleEvent(ev); 109 evhand->handleEvent(ev);
81 break; 110 break;
82 }; 111 };
83}
84 112
85void EventManager::add(EventHandler &ev, const FbWindow &win) { 113 // find out which window is the parent and
86 registerEventHandler(ev, win.window()); 114 // dispatch event
87} 115 Window root, parent_win, *children = 0;
116 unsigned int num_children;
117 if (XQueryTree(FbTk::App::instance()->display(), win,
118 &root, &parent_win, &children, &num_children) != 0 &&
119 parent_win != 0 &&
120 parent_win != root) {
88 121
89void EventManager::remove(const FbWindow &win) { 122 if (children != 0)
90 unregisterEventHandler(win.window()); 123 XFree(children);
91}
92 124
93void EventManager::registerEventHandler(EventHandler &ev, Window win) { 125 if (m_parent[parent_win] == 0)
94 if (win != None) 126 return;
95 m_eventhandlers[win] = &ev; 127
96} 128 // dispatch event to parent
129 dispatch(parent_win, ev, true);
130
131 }
97 132
98void EventManager::unregisterEventHandler(Window win) {
99 if (win != None)
100 m_eventhandlers.erase(win);
101} 133}
102 134
103}; 135}; // end namespace FbTk