]> Dogcows Code - chaz/openbox/blob - application.cc
29dc6bf4b4be70491c97b4028a2799ad9f145a2a
[chaz/openbox] / 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 << "No main widget set. You must create a main OtkWidget for " <<
60 "the OtkApplication before calling OtkApplication::exec().\n";
61 ::exit(1);
62 }
63 while (1) {
64 dispatchEvents();
65 _timer_manager->fire(); // fire pending events
66 }
67 }
68
69 bool OtkApplication::setMainWidget(const OtkWidget *main_widget)
70 {
71 // ignore it if it has already been set
72 if (_main_widget) {
73 std::cerr << "More than one main OtkWidget being created for the " <<
74 "OtkApplication!\n";
75 return false;
76 }
77
78 _main_widget = main_widget;
79
80 // set WM Protocols on the window
81 Atom protocols[2];
82 protocols[0] = XInternAtom(OBDisplay::display, "WM_PROTOCOLS", false);
83 protocols[1] = XInternAtom(OBDisplay::display, "WM_DELETE_WINDOW", false);
84 XSetWMProtocols(OBDisplay::display, _main_widget->getWindow(), protocols, 2);
85
86 return true;
87 }
88
89 }
This page took 0.036631 seconds and 3 git commands to generate.