]> Dogcows Code - chaz/openbox/blob - src/config.cc
add a default icon
[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 printf("PYLENGTH %d\n", PyString_Size(val));
32 std::string temp(PyString_AsString(val), PyString_Size(val));
33 *value = temp;
34 return true;
35 }
36
37 bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value)
38 {
39 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
40 if (!(val && PyList_Check(val))) return false;
41
42 value->clear();
43
44 for (int i = 0, end = PyList_Size(val); i < end; ++i) {
45 PyObject *str = PyList_GetItem(val, i);
46 if (PyString_Check(str))
47 value->push_back(PyString_AsString(str));
48 }
49 return true;
50 }
51
52 Config::Config()
53 {
54 PyRun_SimpleString("import config;");
55 // set up access to the python global variables
56 PyObject *obmodule = PyImport_AddModule("config");
57 obdict = PyModule_GetDict(obmodule);
58
59 std::vector<otk::ustring> names;
60 python_get_stringlist("DESKTOP_NAMES", &names);
61
62 python_get_string("THEME", &theme);
63
64 if (!python_get_string("TITLEBAR_LAYOUT", &titlebar_layout))
65 titlebar_layout = "NTIMC";
66
67 if (!python_get_long("DOUBLE_CLICK_DELAY", &double_click_delay))
68 double_click_delay = 300;
69 if (!python_get_long("DRAG_THRESHOLD", &drag_threshold))
70 drag_threshold = 3;
71 if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&num_desktops))
72 num_desktops = 1;
73
74 otk::ustring s;
75 long w, h;
76 if (python_get_string("DEFAULT_ICON", &s) && s.bytes() > 2 &&
77 python_get_long("DEFAULT_ICON_WIDTH", &w) &&
78 python_get_long("DEFAULT_ICON_HEIGHT", &h) &&
79 (unsigned)(w * h) == s.bytes() / sizeof(unsigned long)) {
80 default_icon = new unsigned long[s.bytes() / sizeof(unsigned long) + 2];
81 default_icon[0] = w;
82 default_icon[1] = h;
83 memcpy(default_icon + 2, s.data(), s.bytes());
84 printf("%d %d\n", default_icon[0], default_icon[1]);
85 } else {
86 default_icon = 0;
87 }
88
89 icon_length = s.bytes();
90 printf("LENGTH %d\n", icon_length);
91 }
92
93 Config::~Config()
94 {
95 if (default_icon) delete [] default_icon;
96 }
97
98 }
This page took 0.037255 seconds and 4 git commands to generate.