]> Dogcows Code - chaz/openbox/blob - src/config.cc
dont provide a default icon in the python stuff, itll come from the style
[chaz/openbox] / src / config.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #include "config.h"
4
5 #include "config.hh"
6
7 extern "C" {
8 #include <Python.h>
9 }
10
11 #include <cstring>
12
13 namespace ob {
14
15 static PyObject *obdict = NULL;
16
17 bool python_get_long(const char *name, long *value)
18 {
19 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
20 if (!(val && PyInt_Check(val))) return false;
21
22 *value = PyInt_AsLong(val);
23 return true;
24 }
25
26 bool python_get_string(const char *name, otk::ustring *value)
27 {
28 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
29 if (!(val && PyString_Check(val))) return false;
30
31 std::string temp(PyString_AsString(val), PyString_Size(val));
32 *value = temp;
33 return true;
34 }
35
36 bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value)
37 {
38 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
39 if (!(val && PyList_Check(val))) return false;
40
41 value->clear();
42
43 for (int i = 0, end = PyList_Size(val); i < end; ++i) {
44 PyObject *str = PyList_GetItem(val, i);
45 if (PyString_Check(str))
46 value->push_back(PyString_AsString(str));
47 }
48 return true;
49 }
50
51 Config::Config()
52 {
53 PyRun_SimpleString("import config;");
54 // set up access to the python global variables
55 PyObject *obmodule = PyImport_AddModule("config");
56 obdict = PyModule_GetDict(obmodule);
57
58 std::vector<otk::ustring> names;
59 python_get_stringlist("DESKTOP_NAMES", &names);
60
61 python_get_string("THEME", &theme);
62
63 if (!python_get_string("TITLEBAR_LAYOUT", &titlebar_layout))
64 titlebar_layout = "NTIMC";
65
66 if (!python_get_long("DOUBLE_CLICK_DELAY", &double_click_delay))
67 double_click_delay = 300;
68 if (!python_get_long("DRAG_THRESHOLD", &drag_threshold))
69 drag_threshold = 3;
70 if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&num_desktops))
71 num_desktops = 1;
72 }
73
74 Config::~Config()
75 {
76 }
77
78 }
This page took 0.037516 seconds and 5 git commands to generate.