]> icculus.org git repositories - mikachu/openbox.git/blob - src/rootwindow.cc
better focus passing around for now
[mikachu/openbox.git] / src / rootwindow.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 #include "rootwindow.hh"
8 #include "openbox.hh"
9 #include "screen.hh"
10 #include "otk/display.hh"
11
12 namespace ob {
13
14 OBRootWindow::OBRootWindow(int screen)
15   : OBWidget(OBWidget::Type_Root),
16     _info(otk::OBDisplay::screenInfo(screen))
17 {
18   updateDesktopNames();
19
20   Openbox::instance->registerHandler(_info->rootWindow(), this);
21 }
22
23
24 OBRootWindow::~OBRootWindow()
25 {
26 }
27
28
29 void OBRootWindow::updateDesktopNames()
30 {
31   const int numWorkspaces = 1; // XXX: change this to the number of workspaces!
32
33   const otk::OBProperty *property = Openbox::instance->property();
34
35   unsigned long num = (unsigned) -1;
36   
37   if (!property->get(_info->rootWindow(),
38                      otk::OBProperty::net_desktop_names,
39                      otk::OBProperty::utf8, &num, &_names))
40     _names.clear();
41   while ((signed)_names.size() < numWorkspaces)
42     _names.push_back("Unnamed");
43 }
44
45
46 void OBRootWindow::propertyHandler(const XPropertyEvent &e)
47 {
48   otk::OtkEventHandler::propertyHandler(e);
49
50   const otk::OBProperty *property = Openbox::instance->property();
51
52   // compress changes to a single property into a single change
53   XEvent ce;
54   while (XCheckTypedEvent(otk::OBDisplay::display, e.type, &ce)) {
55     // XXX: it would be nice to compress ALL changes to a property, not just
56     //      changes in a row without other props between.
57     if (ce.xproperty.atom != e.atom) {
58       XPutBackEvent(otk::OBDisplay::display, &ce);
59       break;
60     }
61   }
62
63   if (e.atom == property->atom(otk::OBProperty::net_desktop_names)) 
64     updateDesktopNames();
65 }
66
67
68 void OBRootWindow::clientMessageHandler(const XClientMessageEvent &e)
69 {
70   otk::OtkEventHandler::clientMessageHandler(e);
71
72   if (e.format != 32) return;
73
74   //const otk::OBProperty *property = Openbox::instance->property();
75   
76   // XXX: so many client messages to handle here! ..or not.. they go to clients
77 }
78
79
80 void OBRootWindow::setDesktopNames(const otk::OBProperty::StringVect &names)
81 {
82   _names = names;
83   const otk::OBProperty *property = Openbox::instance->property();
84   property->set(_info->rootWindow(), otk::OBProperty::net_desktop_names,
85                 otk::OBProperty::utf8, names);
86 }
87
88 void OBRootWindow::setDesktopName(int i, const std::string &name)
89 {
90   const int numWorkspaces = 1; // XXX: change this to the number of workspaces!
91   assert(i >= 0);
92   assert(i < numWorkspaces); 
93
94   const otk::OBProperty *property = Openbox::instance->property();
95   
96   otk::OBProperty::StringVect newnames = _names;
97   newnames[i] = name;
98   property->set(_info->rootWindow(), otk::OBProperty::net_desktop_names,
99                 otk::OBProperty::utf8, newnames);
100 }
101
102
103 void OBRootWindow::mapRequestHandler(const XMapRequestEvent &e)
104 {
105 #ifdef    DEBUG
106   printf("MapRequest for 0x%lx\n", e.window);
107 #endif // DEBUG
108
109   OBClient *client = Openbox::instance->findClient(e.window);
110
111   if (client) {
112     // XXX: uniconify and/or unshade the window
113   } else {
114     Openbox::instance->screen(_info->screen())->manageWindow(e.window);
115   }
116 }
117
118 }