From 50002f2ceb4234145f3977bb14752dc930ada26c Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 14 Feb 2003 05:48:31 +0000 Subject: [PATCH] add a default icon --- scripts/config.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++ src/client.cc | 44 ++++++++++++++++++++--------------- src/config.cc | 31 +++++++++++++++++++++++-- src/config.hh | 6 +++++ 4 files changed, 119 insertions(+), 21 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index df1e7eb4..a0f3b603 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -32,6 +32,65 @@ DESKTOP_NAMES = ["one", "two", "three", "four", "five", "six", "seven", \ NUMBER_OF_DESKTOPS = 4 """The number of desktops/workspaces which can be scrolled between.""" +DEFAULT_ICON_WIDTH = 16 +"""The width of the default icon.""" +DEFAULT_ICON_HEIGHT = 16 +"""The height of the default icon.""" +DEFAULT_ICON = \ +"\377\377\377\0SSS\377\251\251\251\377\251\251\251\377\251\251\251\377\251"+\ +"\251\251\377\251\251\251\377\251\251\251\377\251\251\251\377\251\251\251"+\ +"\377\251\251\251\377\251\251\251\377\216\216\216\377bbb\377\366\366\366\0"+\ +"\377\377\377\0\377\377\377\0SSS\377\377\377\377\377\377\377\377\377\377\377"+\ +"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\376\376\376\377"+\ +"\376\376\376\377\373\373\373\377\371\371\370\377\302\302\302\377\244\244"+\ +"\244\377EEE\377\377\377\377\0\377\377\377\0SSS\377\377\377\377\377\377\377"+\ +"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\376\376\376\377"+\ +"\374\374\374\377\372\372\372\377\367\367\367\377\365\365\365\377\265\265"+\ +"\265\377``_\377\30\30\30\377\377\377\377\0\377\377\377\0SSS\377\377\377\377"+\ +"\377\377\377\377\377\377\377\377\377\376\376\376\377\374\374\374\377\372"+\ +"\372\372\377\367\367\367\377\365\365\365\377\363\363\362\377\361\361\360"+\ +"\377\356\356\355\377\354\354\351\377jjj\377\377\377\377\0\377\377\377\0S"+\ +"SS\377\377\377\377\377\377\377\377\377\375\375\375\377\373\373\373\377\371"+\ +"\371\370\377\366\366\366\377\364\364\363\377\362\362\361\377\357\357\356"+\ +"\377\355\355\354\377\352\352\351\377\350\350\347\377mmm\377\377\377\377\0"+\ +"\377\377\377\0SSS\377\376\376\376\377\373\373\373\377\371\371\370\377\366"+\ +"\366\366\377\364\364\363\377\362\362\361\377\357\357\356\377\355\355\354"+\ +"\377\352\352\351\377\350\350\347\377\346\346\343\377\344\344\341\377lll\377"+\ +"\377\377\377\0\377\377\377\0SSS\377\375\375\375\377\370\370\367\377\365\365"+\ +"\364\377\363\363\362\377\360\360\357\377\356\356\355\377\354\354\351\377"+\ +"\352\352\347\377\347\347\344\377\345\345\342\377\342\342\337\377\340\340"+\ +"\335\377lll\377\377\377\377\0\377\377\377\0SSS\377\373\373\373\377\363\363"+\ +"\362\377\360\360\357\377\356\356\355\377\354\354\351\377\351\351\350\377"+\ +"\347\347\344\377\345\345\342\377\342\342\337\377\340\340\335\377\336\336"+\ +"\332\377\333\333\330\377llk\377\377\377\377\0\377\377\377\0SSS\377\372\372"+\ +"\372\377\357\357\356\377\355\355\352\377\353\353\350\377\350\350\345\377"+\ +"\346\346\343\377\343\343\340\377\341\341\336\377\337\337\333\377\335\335"+\ +"\331\377\332\332\326\377\330\330\324\377kkj\377\377\377\377\0\377\377\377"+\ +"\0SSS\377\370\370\370\377\353\353\350\377\350\350\345\377\346\346\343\377"+\ +"\343\343\340\377\341\341\336\377\337\337\333\377\335\335\331\377\332\332"+\ +"\326\377\330\330\324\377\325\325\321\377\323\323\317\377kkk\377\377\377\377"+\ +"\0\377\377\377\0SSS\377\367\367\367\377\347\347\344\377\345\345\342\377\342"+\ +"\342\337\377\340\340\335\377\336\336\332\377\333\333\327\377\331\331\325"+\ +"\377\326\326\322\377\324\324\320\377\322\322\315\377\320\320\313\377jjj\377"+\ +"\377\377\377\0\377\377\377\0SSS\377\366\366\365\377\342\342\337\377\340\340"+\ +"\335\377\336\336\332\377\333\333\330\377\331\331\325\377\326\326\322\377"+\ +"\324\324\320\377\322\322\315\377\320\320\313\377\315\315\310\377\314\314"+\ +"\307\377llk\377\377\377\377\0\377\377\377\0SSS\377\364\364\364\377\337\337"+\ +"\333\377\334\334\331\377\332\332\326\377\330\330\324\377\326\326\321\377"+\ +"\323\323\317\377\321\321\314\377\316\316\311\377\315\315\307\377\314\314"+\ +"\306\377\314\314\306\377jjj\377\377\377\377\0\377\377\377\0SSS\377\344\344"+\ +"\343\377\316\316\312\377\312\312\306\377\304\304\300\377\302\302\276\377"+\ +"\301\301\274\377\274\274\267\377\267\267\263\377\266\266\261\377\265\265"+\ +"\261\377\265\265\260\377\263\263\256\377[[[\377\377\377\377\0\377\377\377"+\ +"\0SSS\377AAA\377;;;\377998\377554\377554\377552\377110\377..-\377..-\377"+\ +"---\377--,\377+++\377333\377\377\377\377\0\377\377\377\0\377\377\377\0\377"+\ +"\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"+\ +"\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"+\ +"\0\377\377\377\0\377\377\377\0\377\377\377\0" +"""The icon which will be used when an application doesn't supply one. This + was generated by making the icon in gimp (with an alpha channel!) and saving + it as a C source file.""" + ############################################################################# print "Loaded config.py" diff --git a/src/client.cc b/src/client.cc index bd7f7b83..70671442 100644 --- a/src/client.cc +++ b/src/client.cc @@ -708,6 +708,7 @@ void Client::updateIcons() unsigned long num = (unsigned) -1; unsigned long *data; unsigned long w, h, i = 0; + bool freeit = false; for (int j = 0; j < _nicons; ++j) delete [] _icons[j].data; @@ -715,35 +716,40 @@ void Client::updateIcons() delete [] _icons; _nicons = 0; - if (otk::Property::get(_window, otk::Property::atoms.net_wm_icon, - otk::Property::atoms.cardinal, &num, &data)) { - // figure out how man valid icons are in here - while (num - i > 2) { - w = data[i++]; - h = data[i++]; - i += w * h; - if (i > num) break; - ++_nicons; - } + if (!otk::Property::get(_window, otk::Property::atoms.net_wm_icon, + otk::Property::atoms.cardinal, &num, &data)) { + // use default icon(s) + num = openbox->screen(_screen)->config().icon_length; + data = openbox->screen(_screen)->config().default_icon; + } else + freeit = true; + + // figure out how man valid icons are in here + while (num - i > 2) { + w = data[i++]; + h = data[i++]; + i += w * h; + if (i > num) break; + ++_nicons; + } - _icons = new Icon[_nicons]; + _icons = new Icon[_nicons]; - // store the icons - i = 0; - for (int j = 0; j < _nicons; ++j) { - w = _icons[j].w = data[i++]; + // store the icons + i = 0; + for (int j = 0; j < _nicons; ++j) { + w = _icons[j].w = data[i++]; h = _icons[j].h = data[i++]; _icons[j].data = new unsigned long[w * h]; ::memcpy(_icons[j].data, &data[i], w * h * sizeof(unsigned long)); i += w * h; assert(i <= num); - } - - delete [] data; } + if (freeit) + delete [] data; + if (_nicons <= 0) { - // set the default icon(s) XXX load these from the py _nicons = 1; _icons = new Icon[1]; _icons[i].w = 0; diff --git a/src/config.cc b/src/config.cc index e4df70e1..79250e3d 100644 --- a/src/config.cc +++ b/src/config.cc @@ -8,6 +8,8 @@ extern "C" { #include } +#include + namespace ob { static PyObject *obdict = NULL; @@ -25,8 +27,10 @@ bool python_get_string(const char *name, otk::ustring *value) { PyObject *val = PyDict_GetItemString(obdict, const_cast(name)); if (!(val && PyString_Check(val))) return false; - - *value = PyString_AsString(val); + + printf("PYLENGTH %d\n", PyString_Size(val)); + std::string temp(PyString_AsString(val), PyString_Size(val)); + *value = temp; return true; } @@ -66,6 +70,29 @@ Config::Config() drag_threshold = 3; if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&num_desktops)) num_desktops = 1; + + otk::ustring s; + long w, h; + if (python_get_string("DEFAULT_ICON", &s) && s.bytes() > 2 && + python_get_long("DEFAULT_ICON_WIDTH", &w) && + python_get_long("DEFAULT_ICON_HEIGHT", &h) && + (unsigned)(w * h) == s.bytes() / sizeof(unsigned long)) { + default_icon = new unsigned long[s.bytes() / sizeof(unsigned long) + 2]; + default_icon[0] = w; + default_icon[1] = h; + memcpy(default_icon + 2, s.data(), s.bytes()); + printf("%d %d\n", default_icon[0], default_icon[1]); + } else { + default_icon = 0; + } + + icon_length = s.bytes(); + printf("LENGTH %d\n", icon_length); +} + +Config::~Config() +{ + if (default_icon) delete [] default_icon; } } diff --git a/src/config.hh b/src/config.hh index 8f8144e3..cfa0adc5 100644 --- a/src/config.hh +++ b/src/config.hh @@ -21,7 +21,13 @@ struct Config { long drag_threshold; long num_desktops; + unsigned long *default_icon; + long icon_w; + long icon_h; + long icon_length; + Config(); + ~Config(); }; } -- 2.39.2