]> icculus.org git repositories - mikachu/openbox.git/blob - otk/application.cc
better msgs
[mikachu/openbox.git] / otk / application.cc
1 #include "application.hh"
2 #include "eventhandler.hh"
3 #include "widget.hh"
4
5 extern "C" {
6 #include <X11/Xlib.h>
7   
8 #ifdef HAVE_STDLIB_H
9 # include <stdlib.h>
10 #endif
11 }
12
13 #include <iostream>
14
15 namespace otk {
16
17 OtkApplication::OtkApplication(int argc, char **argv)
18   : OtkEventDispatcher(), _main_widget(0), _dockable(false)
19 {
20   argc = argc;
21   argv = argv;
22
23   OBDisplay::initialize(0);
24   const ScreenInfo *s_info = OBDisplay::screenInfo(DefaultScreen(OBDisplay::display));
25
26   _timer_manager = new OBTimerQueueManager();
27   _img_ctrl = new BImageControl(_timer_manager, s_info, True, 4, 5, 200);
28   _style_conf = new Configuration(False);
29   _style = new Style(_img_ctrl);
30
31   loadStyle();
32 }
33
34 OtkApplication::~OtkApplication()
35 {
36   delete _style_conf;
37   delete _img_ctrl;
38   delete _timer_manager;
39   delete _style;
40   
41   OBDisplay::destroy();
42 }
43
44 void OtkApplication::loadStyle(void)
45 {
46   // find the style name as a property
47   std::string style = "/usr/local/share/openbox/styles/artwiz";
48   _style_conf->setFile(style);
49   if (!_style_conf->load()) {
50     std::cerr << "Unable to load style \"" << style << "\". Aborting.\n";
51     ::exit(1);
52   }
53   _style->load(*_style_conf);
54 }
55
56 void OtkApplication::exec(void)
57 {
58   if (!_main_widget) {
59     std::cerr << "ERROR: No main widget set. You must create a main " <<
60       "OtkWidget for the OtkApplication before calling " <<
61       "OtkApplication::exec().\n";
62     ::exit(1);
63   }
64   while (1) {
65     dispatchEvents();
66     _timer_manager->fire(); // fire pending events
67   }
68 }
69
70 bool OtkApplication::setMainWidget(const OtkWidget *main_widget)
71 {
72   // ignore it if it has already been set
73   if (_main_widget) {
74     std::cerr << "WARNING: More than one main OtkWidget being created for " <<
75       "the OtkApplication!\n";
76     return false;
77   }
78
79   _main_widget = main_widget;
80
81   // set WM Protocols on the window
82   Atom protocols[2];
83   protocols[0] = XInternAtom(OBDisplay::display, "WM_PROTOCOLS", false);
84   protocols[1] = XInternAtom(OBDisplay::display, "WM_DELETE_WINDOW", false);
85   XSetWMProtocols(OBDisplay::display, _main_widget->getWindow(), protocols, 2);
86
87   return true;
88 }
89
90 }