+
+ if (unfocus != None) {
+ // the last focus event was an FocusOut, so where the hell is the focus at?
+ //printf("UNFOCUSING: %lx\n", unfocus);
+ _focus_e.xfocus.type = FocusOut;
+ _focus_e.xfocus.window = unfocus;
+ dispatch(_focus_e.xfocus.window, _focus_e);
+
+ _focus = None;
+ } else if (focus != None && focus != _focus) {
+ // the last focus event was a FocusIn, so unfocus what used to be focus and
+ // focus this new target
+ //printf("FOCUSING: %lx\n", focus);
+ _focus_e.xfocus.type = FocusIn;
+ _focus_e.xfocus.window = focus;
+ dispatch(_focus_e.xfocus.window, _focus_e);
+
+ if (_focus != None) {
+ //printf("UNFOCUSING: %lx\n", _focus);
+ _focus_e.xfocus.type = FocusOut;
+ _focus_e.xfocus.window = _focus;
+ dispatch(_focus_e.xfocus.window, _focus_e);
+ }
+
+ _focus = focus;
+ }
+
+ if (leave != None) {
+ _crossing_e.xcrossing.type = LeaveNotify;
+ _crossing_e.xcrossing.window = leave;
+ _crossing_e.xcrossing.root = leave_root;
+ dispatch(_crossing_e.xcrossing.window, _crossing_e);
+ }
+ if (enter != None) {
+ _crossing_e.xcrossing.type = EnterNotify;
+ _crossing_e.xcrossing.window = enter;
+ _crossing_e.xcrossing.root = enter_root;
+ dispatch(_crossing_e.xcrossing.window, _crossing_e);
+ }
+}
+
+void OtkEventDispatcher::dispatch(Window win, const XEvent &e) {
+ OtkEventHandler *handler = 0;
+ OtkEventMap::iterator it;
+
+ if (_master)
+ _master->handle(e);
+
+ it = _map.find(win);
+
+ if (it != _map.end())
+ handler = it->second;
+ // these ConfigureRequests require some special attention
+ else if (e.type == ConfigureRequest) {
+ // unhandled configure requests must be used to configure the window
+ // directly
+ XWindowChanges xwc;
+
+ xwc.x = e.xconfigurerequest.x;
+ xwc.y = e.xconfigurerequest.y;
+ xwc.width = e.xconfigurerequest.width;
+ xwc.height = e.xconfigurerequest.height;
+ xwc.border_width = e.xconfigurerequest.border_width;
+ xwc.sibling = e.xconfigurerequest.above;
+ xwc.stack_mode = e.xconfigurerequest.detail;
+
+ XConfigureWindow(otk::OBDisplay::display, e.xconfigurerequest.window,
+ e.xconfigurerequest.value_mask, &xwc);
+ } else
+ handler = _fallback;
+
+ if (handler)
+ handler->handle(e);
+}
+
+OtkEventHandler *OtkEventDispatcher::findHandler(Window win)
+{
+ OtkEventMap::iterator it = _map.find(win);
+ if (it != _map.end())
+ return it->second;
+ return 0;