set the close protocol on the app's main widget
This commit is contained in:
parent
77342413ef
commit
81e1982744
3 changed files with 34 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue