From: Dana Jansens Date: Sat, 16 Nov 2002 13:50:59 +0000 (+0000) Subject: set the close protocol on the app's main widget X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=81e1982744e1d692fbe54cc840e93099cbe974af;p=chaz%2Fopenbox set the close protocol on the app's main widget --- diff --git a/otk/application.cc b/otk/application.cc index 16b9e0f5..0a250ea3 100644 --- a/otk/application.cc +++ b/otk/application.cc @@ -1,7 +1,10 @@ #include "application.hh" #include "eventhandler.hh" +#include "widget.hh" extern "C" { +#include + #ifdef HAVE_STDLIB_H # include #endif @@ -12,7 +15,7 @@ extern "C" { namespace otk { OtkApplication::OtkApplication(int argc, char **argv) - : OtkEventDispatcher(), _dockable(false) + : OtkEventDispatcher(), _main_widget(0), _dockable(false) { argc = argc; argv = argv; @@ -52,10 +55,31 @@ void OtkApplication::loadStyle(void) void OtkApplication::exec(void) { + if (!_main_widget) { + std::cerr << "No main widget set. You must create a main OtkWidget for " << + "the OtkApplication before calling OtkApplication::exec().\n"; + ::exit(1); + } while (1) { dispatchEvents(); _timer_manager->fire(); // fire pending events } } +bool OtkApplication::setMainWidget(const OtkWidget *main_widget) +{ + // ignore it if it has already been set + if (_main_widget) return false; + + _main_widget = main_widget; + + // set WM Protocols on the window + Atom protocols[2]; + protocols[0] = XInternAtom(OBDisplay::display, "WM_PROTOCOLS", false); + protocols[1] = XInternAtom(OBDisplay::display, "WM_DELETE_WINDOW", false); + XSetWMProtocols(OBDisplay::display, _main_widget->getWindow(), protocols, 2); + + return true; +} + } diff --git a/otk/application.hh b/otk/application.hh index d266287d..d6f1ed8d 100644 --- a/otk/application.hh +++ b/otk/application.hh @@ -10,6 +10,8 @@ namespace otk { +class OtkWidget; + class OtkApplication : public OtkEventDispatcher { public: @@ -26,14 +28,20 @@ public: inline Style *getStyle(void) const { return _style; } // more accessors +protected: + bool setMainWidget(const OtkWidget *main_widget); + private: void loadStyle(void); + const OtkWidget *_main_widget; OBTimerQueueManager *_timer_manager; BImageControl *_img_ctrl; Configuration *_style_conf; Style *_style; bool _dockable; + + friend class OtkWidget; // for access to setMainWidget }; } diff --git a/otk/widget.cc b/otk/widget.cc index 9ae25cfc..130bafea 100644 --- a/otk/widget.cc +++ b/otk/widget.cc @@ -40,6 +40,7 @@ OtkWidget::OtkWidget(OtkApplication *app, Direction direction, assert(app); create(); _event_dispatcher->registerHandler(_window, this); + app->setMainWidget(this); } OtkWidget::OtkWidget(Style *style, Direction direction,