]>
Dogcows Code - chaz/openbox/blob - src/config.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 #include "otk/screeninfo.hh"
7 #include "otk/renderstyle.hh"
9 #include "otk/property.hh"
10 #include "otk/display.hh"
16 #define _(str) gettext(str)
23 static PyObject
*obdict
= NULL
;
25 bool python_get_long(const char *name
, long *value
)
27 PyObject
*val
= PyDict_GetItemString(obdict
, const_cast<char*>(name
));
28 if (!(val
&& PyInt_Check(val
))) return false;
30 *value
= PyInt_AsLong(val
);
34 bool python_get_string(const char *name
, otk::ustring
*value
)
36 PyObject
*val
= PyDict_GetItemString(obdict
, const_cast<char*>(name
));
37 if (!(val
&& PyString_Check(val
))) return false;
39 std::string
temp(PyString_AsString(val
), PyString_Size(val
));
44 bool python_get_stringlist(const char *name
, std::vector
<otk::ustring
> *value
)
46 PyObject
*val
= PyDict_GetItemString(obdict
, const_cast<char*>(name
));
47 if (!(val
&& PyList_Check(val
))) return false;
51 for (int i
= 0, end
= PyList_Size(val
); i
< end
; ++i
) {
52 PyObject
*str
= PyList_GetItem(val
, i
);
53 if (PyString_Check(str
))
54 value
->push_back(PyString_AsString(str
));
61 const otk::ScreenInfo
*info
= otk::display
->screenInfo(_screen
);
62 Window root
= info
->rootWindow();
64 // set up access to the python global variables
65 PyObject
*obmodule
= PyImport_ImportModule("config");
66 obdict
= PyModule_GetDict(obmodule
);
69 python_get_stringlist("DESKTOP_NAMES", &desktop_names
);
71 python_get_string("THEME", &theme
);
72 // initialize the screen's style
73 otk::RenderStyle::setStyle(_screen
, theme
);
74 // draw the root window
75 otk::bexec("obsetroot " + otk::RenderStyle::style(_screen
)->rootArgs(),
76 info
->displayString());
79 if (!python_get_string("TITLEBAR_LAYOUT", &titlebar_layout
)) {
80 fprintf(stderr
, _("Unable to load config.%s\n"), "TITLEBAR_LAYOUT");
84 if (!python_get_long("DOUBLE_CLICK_DELAY", &double_click_delay
)) {
85 fprintf(stderr
, _("Unable to load config.%s\n"), "DOUBLE_CLICK_DELAY");
88 if (!python_get_long("DRAG_THRESHOLD", &drag_threshold
)) {
89 fprintf(stderr
, _("Unable to load config.%s\n"), "DRAG_THRESHOLD");
92 if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&num_desktops
)) {
93 fprintf(stderr
, _("Unable to load config.%s\n"), "NUMBER_OF_DESKTOPS");
97 // Set the net_desktop_names property
98 otk::Property::set(root
,
99 otk::Property::atoms
.net_desktop_names
,
100 otk::Property::utf8
, desktop_names
);
101 // the above set() will cause screen::updateDesktopNames to fire right away
102 // so we have a list of desktop names
105 ce
.xclient
.type
= ClientMessage
;
106 ce
.xclient
.message_type
= otk::Property::atoms
.net_number_of_desktops
;
107 ce
.xclient
.display
= **otk::display
;
108 ce
.xclient
.window
= root
;
109 ce
.xclient
.format
= 32;
110 ce
.xclient
.data
.l
[0] = num_desktops
;
111 XSendEvent(**otk::display
, root
, False
,
112 SubstructureNotifyMask
| SubstructureRedirectMask
, &ce
);
115 Config::Config(int screen
)
This page took 0.040303 seconds and 4 git commands to generate.