]> Dogcows Code - chaz/openbox/blob - src/rootwindow.cc
add an OBRootWindow class that watches events/properties on root windows
[chaz/openbox] / 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 "otk/display.hh"
10
11 namespace ob {
12
13 OBRootWindow::OBRootWindow(int screen)
14 : _info(otk::OBDisplay::screenInfo(screen))
15 {
16 updateDesktopNames();
17
18 Openbox::instance->registerHandler(_info->getRootWindow(), this);
19 }
20
21
22 OBRootWindow::~OBRootWindow()
23 {
24 }
25
26
27 void OBRootWindow::updateDesktopNames()
28 {
29 const int numWorkspaces = 1; // XXX: change this to the number of workspaces!
30
31 const otk::OBProperty *property = Openbox::instance->property();
32
33 unsigned long num = (unsigned) -1;
34
35 if (!property->get(_info->getRootWindow(),
36 otk::OBProperty::net_desktop_names,
37 otk::OBProperty::utf8, &num, &_names))
38 _names.clear();
39 for (int i = 0; i < numWorkspaces; ++i)
40 if (i <= static_cast<int>(_names.size()))
41 _names.push_back("Unnamed workspace");
42 }
43
44
45 void OBRootWindow::propertyHandler(const XPropertyEvent &e)
46 {
47 otk::OtkEventHandler::propertyHandler(e);
48
49 const otk::OBProperty *property = Openbox::instance->property();
50
51 if (e.atom == property->atom(otk::OBProperty::net_desktop_names))
52 updateDesktopNames();
53 }
54
55
56 void OBRootWindow::clientMessageHandler(const XClientMessageEvent &e)
57 {
58 otk::OtkEventHandler::clientMessageHandler(e);
59
60 if (e.format != 32) return;
61
62 //const otk::OBProperty *property = Openbox::instance->property();
63
64 // XXX: so many client messages to handle here!
65 }
66
67
68 void OBRootWindow::setDesktopName(int i, const std::string &name)
69 {
70 const int numWorkspaces = 1; // XXX: change this to the number of workspaces!
71 assert(i >= 0);
72 assert(i < numWorkspaces);
73
74 const otk::OBProperty *property = Openbox::instance->property();
75
76 otk::OBProperty::StringVect newnames = _names;
77 newnames[i] = name;
78 property->set(_info->getRootWindow(), otk::OBProperty::net_desktop_names,
79 otk::OBProperty::utf8, newnames);
80 }
81
82
83 }
This page took 0.035318 seconds and 4 git commands to generate.