3 #include <msp/core/error.h>
11 DisplayOptions::DisplayOptions():
22 Window::Window(unsigned w, unsigned h)
31 Window::Window(const DisplayOptions &dopt)
38 XCloseDisplay(display);
43 XMapWindow(display, window);
50 int pending=XPending(display);
54 for(int i=0; i<pending; ++i)
57 XNextEvent(display, &event);
63 void Window::init(const DisplayOptions &dopt)
67 display=XOpenDisplay(0);
69 throw Exception("Couldn't open X display");
72 attribs.push_back(GLX_BUFFER_SIZE);
73 attribs.push_back(dopt.depth);
74 attribs.push_back(GLX_DOUBLEBUFFER);
76 if(dopt.multisample>0)
78 attribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
79 attribs.push_back(dopt.multisample);
82 XVisualInfo *visual=glXChooseVisual(display, DefaultScreen(display), &attribs.front());
84 throw Exception("Couldn't get a matching visual");
86 window=XCreateWindow(display, DefaultRootWindow(display), 0, 0, dopt.width, dopt.height, 0, CopyFromParent, InputOutput, visual->visual, 0, 0);
88 XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|MotionMask|KeyPressMask|KeyReleaseMask);
91 void Window::process_event(const XEvent &event)
96 signal_button_press.emit(event.button.x, event.button.y, event.button.button, event.button.state);
99 signal_button_release.emit(event.button.x, event.button.y, event.button.button, event.button.state);
102 signal_pointer_motion.emit(event.motion.x, event.motion.y);
107 XLookupString(event.key, buf, sizeof(buf), 0, 0);
108 // XXX Handle the result according to locale
109 signal_key_press.emit(event.key.keycode, event.key.state, buf[0]);
113 signal_key_release.emit(event.key.keycode, event.key.state);