using namespace std;
-#include <iostream>
-
namespace Msp {
GLDisplayOptions::GLDisplayOptions():
GLWindow::~GLWindow()
{
- glXMakeCurrent(display, window, 0);
+ glXMakeCurrent(display, 0, 0);
glXDestroyContext(display, context);
}
if(!context)
throw Exception("Couldn't create a GLX context");
- window=XCreateWindow(display, DefaultRootWindow(display), 0, 0, options.width, options.height, 0, CopyFromParent, InputOutput, CopyFromParent, 0, 0);
- if(!window)
- throw Exception("Couldn't create a window");
-
- XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask);
+ create();
glXMakeCurrent(display, window, context);
}
+void GLWindow::on_resize()
+{
+ glViewport(0, 0, options.width, options.height);
+}
+
} // namespace Msp
void swap_buffers();
protected:
void init();
+ virtual void on_resize();
};
} // namespace Msp
*/
#include <vector>
-#include <GL/glx.h>
+#include <X11/Xutil.h>
#include <msp/core/error.h>
#include "window.h"
using namespace std;
-#include <msp/strings/lexicalcast.h>
-
namespace Msp {
DisplayOptions::DisplayOptions():
if(!display)
throw Exception("Couldn't open X display");
+ wm_delete_window=XInternAtom(display, "WM_DELETE_WINDOW", true);
+
//XSetErrorHandler(x_error_handler);
}
-void Window::init()
+void Window::create()
{
- prepare();
-
window=XCreateWindow(display, DefaultRootWindow(display), 0, 0, options.width, options.height, 0, CopyFromParent, InputOutput, CopyFromParent, 0, 0);
if(!window)
throw Exception("Couldn't create a window");
XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|StructureNotifyMask);
+
+ XSetWMProtocols(display, window, &wm_delete_window, 1);
+}
+
+void Window::init()
+{
+ prepare();
+ create();
}
void Window::process_event(const XEvent &event)
case ConfigureNotify:
options.width=event.xconfigure.width;
options.height=event.xconfigure.height;
+ on_resize();
+ signal_resize.emit(options.width, options.height);
+ break;
+ case ClientMessage:
+ if(event.xclient.data.l[0]==static_cast<long>(wm_delete_window))
+ signal_close.emit();
break;
default:;
}
sigc::signal<void, int, int> signal_pointer_motion;
sigc::signal<void, unsigned, unsigned, unsigned> signal_key_press;
sigc::signal<void, unsigned, unsigned> signal_key_release;
+ sigc::signal<void, unsigned, unsigned> signal_resize;
+ sigc::signal<void> signal_close;
protected:
typedef ::Window Handle;
Display *display;
DisplayOptions options;
Handle window;
+ Atom wm_delete_window;
Window();
public:
void tick();
protected:
void prepare();
+ void create();
void init();
void process_event(const XEvent &);
+ virtual void on_resize() { }
static int x_error_handler(Display *, XErrorEvent *);
};