-bool Window::event(const Event &evnt)
-{
-#ifdef WIN32
- WPARAM wp = evnt.wparam;
- LPARAM lp = evnt.lparam;
- switch(evnt.msg)
- {
- case WM_KEYDOWN:
- signal_key_press.emit(wp, 0, wp);
- break;
- case WM_KEYUP:
- signal_key_release.emit(wp, 0);
- break;
- case WM_LBUTTONDOWN:
- signal_button_press.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 1, 0);
- break;
- case WM_LBUTTONUP:
- signal_button_release.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 1, 0);
- break;
- case WM_MBUTTONDOWN:
- signal_button_press.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 2, 0);
- break;
- case WM_MBUTTONUP:
- signal_button_release.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 2, 0);
- break;
- case WM_RBUTTONDOWN:
- signal_button_press.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 3, 0);
- break;
- case WM_RBUTTONUP:
- signal_button_release.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 3, 0);
- break;
- case WM_MOUSEWHEEL:
- {
- unsigned btn = (HIWORD(wp)&0x8000) ? 5 : 4;
- signal_button_press.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), btn, 0);
- signal_button_release.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), btn, 0);
- }
- break;
- case WM_MOUSEMOVE:
- signal_pointer_motion.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp));
- break;
- case WM_SIZE:
- options.width = LOWORD(lp);
- options.height = HIWORD(lp);
- signal_resize.emit(options.width, options.height);
- break;
- case WM_CLOSE:
- signal_close.emit();
- break;
- default:
- return false;
- }
-#else
- const XEvent &ev = evnt.xevent;
- switch(ev.type)
- {
- case ButtonPress:
- signal_button_press.emit(ev.xbutton.x, ev.xbutton.y, ev.xbutton.button, ev.xbutton.state);
- break;
- case ButtonRelease:
- signal_button_release.emit(ev.xbutton.x, ev.xbutton.y, ev.xbutton.button, ev.xbutton.state);
- break;
- case MotionNotify:
- signal_pointer_motion.emit(ev.xmotion.x, ev.xmotion.y);
- break;
- case KeyPress:
- {
- char buf[16];
- XLookupString(const_cast<XKeyEvent *>(&ev.xkey), buf, sizeof(buf), 0, 0);
- // XXX Handle the result according to locale
- signal_key_press.emit(XKeycodeToKeysym(display.get_private().display, ev.xkey.keycode, 0), ev.xkey.state, buf[0]);
- }
- break;
- case KeyRelease:
- signal_key_release.emit(XKeycodeToKeysym(display.get_private().display, ev.xkey.keycode, 0), ev.xkey.state);
- break;
- case ConfigureNotify:
- if((ev.xconfigure.width==static_cast<int>(options.width) && ev.xconfigure.height==static_cast<int>(options.height)) == resizing)
- {
- options.width = ev.xconfigure.width;
- options.height = ev.xconfigure.height;
- resizing = false;
- signal_resize.emit(options.width, options.height);
- }
-#ifdef WITH_XF86VIDMODE
- if(options.fullscreen)
- {
- ::Display *dpy = display.get_private().display;
- int screen = DefaultScreen(dpy);
- XF86VidModeSetViewPort(dpy, screen, ev.xconfigure.x, ev.xconfigure.y);
- }
-#endif
- break;
- case ClientMessage:
- if(ev.xclient.data.l[0]==static_cast<long>(priv->wm_delete_window))
- signal_close.emit();
- break;
- case EnterNotify:
- if(options.fullscreen)
- XSetInputFocus(display.get_private().display, priv->window, RevertToParent, CurrentTime);
- break;
- case MapNotify:
- if(options.fullscreen)
- XGrabPointer(display.get_private().display, priv->window, true, None, GrabModeAsync, GrabModeAsync, priv->window, None, CurrentTime);
- break;
- default:
- return false;
- }
-#endif
- return true;
-}
-