all repos — openbox @ 81e1982744e1d692fbe54cc840e93099cbe974af

openbox fork - make it a bit more like ryudo

set the close protocol on the app's main widget
Dana Jansens danakj@orodu.net
commit

81e1982744e1d692fbe54cc840e93099cbe974af

parent

77342413efd183bd1c0681a57b68acc836022923

3 files changed, 34 insertions(+), 1 deletions(-)

jump to
M otk/application.ccotk/application.cc

@@ -1,7 +1,10 @@

#include "application.hh" #include "eventhandler.hh" +#include "widget.hh" extern "C" { +#include <X11/Xlib.h> + #ifdef HAVE_STDLIB_H # include <stdlib.h> #endif

@@ -12,7 +15,7 @@

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::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; } }
M otk/application.hhotk/application.hh

@@ -10,6 +10,8 @@ #include "style.hh"

namespace otk { +class OtkWidget; + class OtkApplication : public OtkEventDispatcher { public:

@@ -26,14 +28,20 @@

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 }; }
M otk/widget.ccotk/widget.cc

@@ -40,6 +40,7 @@ {

assert(app); create(); _event_dispatcher->registerHandler(_window, this); + app->setMainWidget(this); } OtkWidget::OtkWidget(Style *style, Direction direction,