]> icculus.org git repositories - dana/openbox.git/blob - src/config.cc
add a Config class with config data from the scripts.
[dana/openbox.git] / 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 namespace ob {
12
13 static PyObject *obdict = NULL;
14
15 bool python_get_long(const char *name, long *value)
16 {
17   PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
18   if (!(val && PyInt_Check(val))) return false;
19   
20   *value = PyInt_AsLong(val);
21   return true;
22 }
23
24 bool python_get_string(const char *name, otk::ustring *value)
25 {
26   PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
27   if (!(val && PyString_Check(val))) return false;
28   
29   *value = PyString_AsString(val);
30   return true;
31 }
32
33 bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value)
34 {
35   PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
36   if (!(val && PyList_Check(val))) return false;
37
38   value->clear();
39   
40   for (int i = 0, end = PyList_Size(val); i < end; ++i) {
41     PyObject *str = PyList_GetItem(val, i);
42     if (PyString_Check(str))
43       value->push_back(PyString_AsString(str));
44   }
45   return true;
46 }
47
48 Config::Config()
49 {
50   PyRun_SimpleString("import config;");
51   // set up access to the python global variables
52   PyObject *obmodule = PyImport_AddModule("config");
53   obdict = PyModule_GetDict(obmodule);
54
55   std::vector<otk::ustring> names;
56   python_get_stringlist("DESKTOP_NAMES", &names);
57
58   python_get_string("THEME", &theme);
59
60   if (!python_get_string("TITLEBAR_LAYOUT", &titlebar_layout))
61     titlebar_layout = "NTIMC";
62   printf("LAYOUT %s\n", titlebar_layout.c_str());
63
64   if (!python_get_long("DOUBLE_CLICK_DELAY", &double_click_delay))
65     double_click_delay = 300;
66   if (!python_get_long("DRAG_THRESHOLD", &drag_threshold))
67     drag_threshold = 3;
68   if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&num_desktops))
69     num_desktops = 1;
70 }
71
72 }