]> Dogcows Code - chaz/openbox/commitdiff
set the close protocol on the app's main widget
authorDana Jansens <danakj@orodu.net>
Sat, 16 Nov 2002 13:50:59 +0000 (13:50 +0000)
committerDana Jansens <danakj@orodu.net>
Sat, 16 Nov 2002 13:50:59 +0000 (13:50 +0000)
otk/application.cc
otk/application.hh
otk/widget.cc

index 16b9e0f5cbe57915c24da28b2799c4d071476817..0a250ea36ea8fa292fd4b3f8a1cd094fa6942de9 100644 (file)
@@ -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 @@ 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;
+}
+
 }
index d266287dfcebfb1e7ceaa5465dfaaf1b6f882429..d6f1ed8dac7f24fff6084291c49a65d180fa529d 100644 (file)
@@ -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
 };
 
 }
index 9ae25cfc4c2c2b31087697c440939111faf040a7..130bafeaf54189f69e039170a2c325a7094d2b8c 100644 (file)
@@ -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,
This page took 0.027144 seconds and 4 git commands to generate.