1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "eventdispatcher.hh"
13 OtkEventDispatcher::OtkEventDispatcher()
14 : _fallback(0), _master(0)
18 OtkEventDispatcher::~OtkEventDispatcher()
22 void OtkEventDispatcher::clearAllHandlers(void)
27 void OtkEventDispatcher::registerHandler(Window id, OtkEventHandler *handler)
29 _map.insert(std::pair<Window, OtkEventHandler*>(id, handler));
32 void OtkEventDispatcher::clearHandler(Window id)
37 void OtkEventDispatcher::dispatchEvents(void)
41 while (XPending(OBDisplay::display)) {
42 XNextEvent(OBDisplay::display, &e);
45 printf("Event %d window %lx\n", e.type, e.xany.window);
48 if (e.type == FocusIn || e.type == FocusOut) {
49 // focus events are a beast all their own.. yuk, hate, etc.
57 win = e.xunmap.window;
60 win = e.xdestroywindow.window;
62 case ConfigureRequest:
63 win = e.xconfigurerequest.window;
69 // grab the lasttime and hack up the modifiers
73 _lasttime = e.xbutton.time;
74 e.xbutton.state &= ~(LockMask | OBDisplay::numLockMask() |
75 OBDisplay::scrollLockMask());
78 e.xkey.state &= ~(LockMask | OBDisplay::numLockMask() |
79 OBDisplay::scrollLockMask());
82 _lasttime = e.xmotion.time;
83 e.xmotion.state &= ~(LockMask | OBDisplay::numLockMask() |
84 OBDisplay::scrollLockMask());
87 _lasttime = e.xproperty.time;
91 _lasttime = e.xcrossing.time;
100 void OtkEventDispatcher::dispatchFocus(const XEvent &e)
102 if (e.type == FocusIn) {
103 //printf("Got FocusIn!\n");
105 // send a FocusIn to whatever was just focused
106 dispatch(e.xfocus.window, e);
107 //printf("Sent FocusIn 0x%lx\n", e.xfocus.window);
109 } else if (e.type == FocusOut) {
110 //printf("Got FocusOut!\n");
112 // ignore FocusOut changes from grabs
113 if (e.xfocus.mode == NotifyGrab)
116 // FocusOut events just make us look for FocusIn events. They are ignored
119 if (XCheckTypedEvent(OBDisplay::display, FocusIn, &fi)) {
120 //printf("Found FocusIn\n");
122 // dont unfocus the window we just focused!
123 if (fi.xfocus.window == e.xfocus.window)
127 dispatch(e.xfocus.window, e);
128 //printf("Sent FocusOut 0x%lx\n", e.xfocus.window);
132 void OtkEventDispatcher::dispatch(Window win, const XEvent &e)
134 OtkEventHandler *handler = 0;
135 OtkEventMap::iterator it;
137 // master gets everything first
141 // find handler for the chosen window
144 if (it != _map.end()) {
145 // if we found a handler
146 handler = it->second;
147 } else if (e.type == ConfigureRequest) {
148 // unhandled configure requests must be used to configure the window
152 xwc.x = e.xconfigurerequest.x;
153 xwc.y = e.xconfigurerequest.y;
154 xwc.width = e.xconfigurerequest.width;
155 xwc.height = e.xconfigurerequest.height;
156 xwc.border_width = e.xconfigurerequest.border_width;
157 xwc.sibling = e.xconfigurerequest.above;
158 xwc.stack_mode = e.xconfigurerequest.detail;
160 XConfigureWindow(otk::OBDisplay::display, e.xconfigurerequest.window,
161 e.xconfigurerequest.value_mask, &xwc);
163 // grab a falback if it exists
171 OtkEventHandler *OtkEventDispatcher::findHandler(Window win)
173 OtkEventMap::iterator it = _map.find(win);
174 if (it != _map.end())