Display::Display(const std::string &):
priv(new Private)
{
+ static ErrorDialog err_dlg(0);
+
priv->display = create_display();
}
--- /dev/null
+#include "errordialog.h"
+
+using namespace std;
+
+extern "C" void run_alert(const char *, const char *);
+
+namespace Msp {
+namespace Graphics {
+
+bool ErrorDialog::report_uncaught_exception(const exception &e) const
+{
+ if(Application::get_data())
+ {
+ string type = Debug::demangle(typeid(e).name());
+ run_alert(type.c_str(), e.what());
+ return true;
+ }
+ return false;
+}
+
+} // namespace Graphics
+} // namespace Msp
--- /dev/null
+#import <Foundation/NSString.h>
+#import <AppKit/NSAlert.h>
+
+// The function gets incorrect linkage without a prototype
+void run_alert(const char *, const char *);
+
+void run_alert(const char *type, const char *what)
+{
+ NSString *message = [[[NSString stringWithUTF8String:type] stringByAppendingString:@": "]
+ stringByAppendingString:[NSString stringWithUTF8String:what]];
+ NSAlert *alert = [NSAlert alertWithMessageText:@"Uncaught exception"
+ defaultButton:nil alternateButton:nil otherButton:nil
+ informativeTextWithFormat:@"%@", message];
+ [alert runModal];
+}
+
#include <list>
#include <stdexcept>
#include <string>
+#include "errordialog.h"
#include "monitor.h"
#include "videomode.h"
Monitor *primary_monitor;
std::list<VideoMode> modes;
Private *priv;
+ ErrorDialog *err_dialog;
public:
Display(const std::string &disp_name = std::string());
--- /dev/null
+#ifndef MSP_GRAPHICS_ERRORDIALOG_H_
+#define MSP_GRAPHICS_ERRORDIALOG_H_
+
+#include <msp/debug/errorreporter.h>
+
+namespace Msp {
+namespace Graphics {
+
+class Display;
+
+class ErrorDialog: public Debug::ErrorReporter
+{
+private:
+ Display *display;
+
+public:
+ ErrorDialog(Display *d): display(d) { }
+
+ virtual bool report_uncaught_exception(const std::exception &) const;
+};
+
+} // namespace Graphics
+} // namespace Msp
+
+#endif
primary_monitor(0),
priv(new Private)
{
+ static ErrorDialog err_dlg(0);
+
for(unsigned i=0;; ++i)
{
DISPLAY_DEVICE adapter_dev;
--- /dev/null
+#include <windows.h>
+#include <typeinfo>
+#include <msp/debug/demangle.h>
+#include "errordialog.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Graphics {
+
+bool ErrorDialog::report_uncaught_exception(const exception &e) const
+{
+ string msg = Debug::demangle(typeid(e).name())+":\n"+e.what();
+ MessageBoxA(0, msg.c_str(), "Uncaught exception", MB_OK|MB_ICONERROR);
+ return false;
+}
+
+} // namespace Graphics
+} // namespace Msp
XSetErrorHandler(x_error_handler);
+ err_dialog = new ErrorDialog(this);
+
#ifdef WITH_XRANDR
int event_base;
int error_base;
{
XCloseDisplay(priv->display);
delete priv;
+ delete err_dialog;
}
void Display::set_mode(const VideoMode &requested_mode, bool exclusive)
--- /dev/null
+#include "errordialog.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Graphics {
+
+bool ErrorDialog::report_uncaught_exception(const exception &) const
+{
+ // TODO Implement a simple dialog with basic X11 primitives
+ return false;
+}
+
+} // namespace Graphics
+} // namespace Msp