X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fclient.cc;h=f9676e7cf7eebd3bbb8cc87722d5f84cb80c7cb5;hb=49974f6916c98a23189daefa19dd79986629fe8f;hp=33e11ce07e1e596621acb3c61fe5070e8feabc38;hpb=1e46a39dc305fe92b0c0eca1e60e76fded3e5214;p=chaz%2Fopenbox diff --git a/src/client.cc b/src/client.cc index 33e11ce0..f9676e7c 100644 --- a/src/client.cc +++ b/src/client.cc @@ -19,6 +19,7 @@ extern "C" { #define _(str) gettext(str) } +#include // for memcpy #include #include #include @@ -46,6 +47,7 @@ Client::Client(int screen, Window window) _disabled_decorations = 0; _group = None; _desktop = 0; + _nicons = 0; getArea(); getDesktop(); @@ -74,7 +76,8 @@ Client::Client(int screen, Window window) updateIconTitle(); updateClass(); updateStrut(); - + updateIcons(); + // this makes sure that these windows appear on all desktops if (/*_type == Type_Dock ||*/ _type == Type_Desktop) _desktop = 0xffffffff; @@ -83,13 +86,17 @@ Client::Client(int screen, Window window) // any changes we've made here otk::Property::set(_window, otk::Property::atoms.net_wm_desktop, otk::Property::atoms.cardinal, (unsigned)_desktop); - changeState(); } Client::~Client() { + assert(_nicons > 0); // there should always be a default.. + for (int j = 0; j < _nicons; ++j) + delete [] _icons[j].data; + delete [] _icons; + // clean up childrens' references while (!_transients.empty()) { _transients.front()->_transient_for = 0; @@ -208,7 +215,7 @@ void Client::getType() void Client::setupDecorAndFunctions() { // start with everything (cept fullscreen) - _decorations = Decor_Titlebar | Decor_Handle | Decor_Border | + _decorations = Decor_Titlebar | Decor_Handle | Decor_Border | Decor_Icon | Decor_AllDesktops | Decor_Iconify | Decor_Maximize; _functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize | Func_Shade; @@ -395,7 +402,6 @@ void Client::getState() } } - void Client::getShaped() { _shaped = false; @@ -414,12 +420,40 @@ void Client::getShaped() #endif // SHAPE } +Client *Client::searchFocusTree(Client *node, Client *skip) +{ + List::const_iterator it, end = node->_transients.end(); + Client *ret; + + for (it = node->_transients.begin(); it != end; ++it) { + if (*it == skip) continue; // circular? + if ((ret = searchModalTree(*it, skip))) return ret; // got one + if ((*it)->_focused) return *it; // got one + } + return 0; +} void Client::calcLayer() { StackLayer l; + bool fs = false; + // are we fullscreen, or do we have a fullscreen transient parent? + Client *c = this; + while (c) { + if (c->_fullscreen) { + fs =true; + break; + } + c = c->_transient_for; + } + if (!fs && _fullscreen) { + // is one of our transients focused? + c = searchFocusTree(this, this); + if (c) fs = true; + } + if (_iconic) l = Layer_Icon; - else if (_fullscreen) l = Layer_Fullscreen; + else if (fs) l = Layer_Fullscreen; else if (_type == Type_Desktop) l = Layer_Desktop; else if (_type == Type_Dock) { if (!_below) l = Layer_Top; @@ -441,7 +475,6 @@ void Client::calcLayer() { } } - void Client::updateProtocols() { Atom *proto; @@ -464,7 +497,6 @@ void Client::updateProtocols() } } - void Client::updateNormalHints() { XSizeHints size; @@ -515,7 +547,6 @@ void Client::updateNormalHints() } } - void Client::updateWMHints(bool initstate) { XWMHints *hints; @@ -550,7 +581,7 @@ void Client::updateWMHints(bool initstate) if (ur != _urgent) { _urgent = ur; #ifdef DEBUG - printf("DEBUG: Urgent Hint for 0x%lx: %s\n", + printf("Urgent Hint for 0x%lx: %s\n", (long)_window, _urgent ? "ON" : "OFF"); #endif // fire the urgent callback if we're mapped, otherwise, wait until after @@ -560,7 +591,6 @@ void Client::updateWMHints(bool initstate) } } - void Client::updateTitle() { _title = ""; @@ -580,7 +610,6 @@ void Client::updateTitle() frame->adjustTitle(); } - void Client::updateIconTitle() { _icon_title = ""; @@ -597,7 +626,6 @@ void Client::updateIconTitle() _icon_title = _("Unnamed Window"); } - void Client::updateClass() { // set the defaults @@ -620,7 +648,6 @@ void Client::updateClass() } } - void Client::updateStrut() { unsigned long num = 4; @@ -644,7 +671,6 @@ void Client::updateStrut() delete [] data; } - void Client::updateTransientFor() { Window t = 0; @@ -677,6 +703,64 @@ void Client::updateTransientFor() } } +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; + if (_nicons > 0) + delete [] _icons; + _nicons = 0; + + 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]; + + // 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); + } + + if (freeit) + delete [] data; + + if (_nicons <= 0) { + _nicons = 1; + _icons = new Icon[1]; + _icons[i].w = 0; + _icons[i].h = 0; + _icons[i].data = 0; + } + + assert(_nicons > 0); // there should always be a default.. + + if (frame) frame->adjustIcon(); +} void Client::propertyHandler(const XPropertyEvent &e) { @@ -721,9 +805,10 @@ void Client::propertyHandler(const XPropertyEvent &e) } else if (e.atom == otk::Property::atoms.net_wm_strut) updateStrut(); + else if (e.atom == otk::Property::atoms.net_wm_icon) + updateIcons(); } - void Client::setWMState(long state) { if (state == _wmstate) return; // no change @@ -738,7 +823,6 @@ void Client::setWMState(long state) } } - void Client::setDesktop(unsigned int target) { if (target == _desktop) return; @@ -750,18 +834,15 @@ void Client::setDesktop(unsigned int target) return; _desktop = target; - // set the desktop hint otk::Property::set(_window, otk::Property::atoms.net_wm_desktop, otk::Property::atoms.cardinal, _desktop); - + frame->adjustState(); // the frame can display the current desktop state // 'move' the window to the new desktop showhide(); - openbox->screen(_screen)->updateStruts(); } - void Client::showhide() { bool show; @@ -777,7 +858,6 @@ void Client::showhide() else frame->hide(); } - void Client::setState(StateAction action, long data1, long data2) { bool shadestate = _shaded; @@ -891,7 +971,6 @@ void Client::setState(StateAction action, long data1, long data2) changeState(); // change the hint to relect these changes } - void Client::toggleClientBorder(bool addborder) { // adjust our idea of where the client is, based on its border. When the @@ -955,7 +1034,6 @@ void Client::toggleClientBorder(bool addborder) XSetWindowBorderWidth(**otk::display, _window, 0); } - void Client::clientMessageHandler(const XClientMessageEvent &e) { otk::EventHandler::clientMessageHandler(e); @@ -1042,7 +1120,6 @@ void Client::clientMessageHandler(const XClientMessageEvent &e) } } - #if defined(SHAPE) void Client::shapeHandler(const XShapeEvent &e) { @@ -1055,14 +1132,12 @@ void Client::shapeHandler(const XShapeEvent &e) } #endif - void Client::resize(Corner anchor, int w, int h) { if (!(_functions & Func_Resize)) return; internal_resize(anchor, w, h); } - void Client::internal_resize(Corner anchor, int w, int h, bool user, int x, int y) { @@ -1143,6 +1218,29 @@ void Client::internal_resize(Corner anchor, int w, int h, internal_move(x, y); } +const Icon *Client::icon(const otk::Size &s) const +{ + unsigned long req = s.width() * s.height(); + // si is the smallest image >= req + // li is the largest image < req + unsigned long smallest = 0xffffffff, largest = 0, si = 0, li = 0; + + assert(_nicons > 0); // there should always be a default.. + for (int i = 0; i < _nicons; ++i) { + unsigned long size = _icons[i].w * _icons[i].h; + if (size < smallest && size >= req) { + smallest = size; + si = i; + } + if (size > largest && size <= req) { + largest = size; + li = i; + } + } + if (smallest == 0xffffffff) // didnt find one bigger than us... + return &_icons[li]; + return &_icons[si]; +} void Client::move(int x, int y) { @@ -1152,7 +1250,6 @@ void Client::move(int x, int y) internal_move(x, y); } - void Client::internal_move(int x, int y) { _area = otk::Rect(otk::Point(x, y), _area.size()); @@ -1188,7 +1285,6 @@ void Client::internal_move(int x, int y) } } - void Client::close() { XEvent ce; @@ -1214,7 +1310,6 @@ void Client::close() XSendEvent(**otk::display, _window, false, NoEventMask, &ce); } - void Client::changeState() { unsigned long state[2]; @@ -1254,7 +1349,6 @@ void Client::changeState() frame->adjustState(); } - void Client::changeAllowedActions(void) { Atom actions[9]; @@ -1298,7 +1392,6 @@ void Client::changeAllowedActions(void) else _max_vert = _max_horz = false; } - void Client::remaximize() { int dir; @@ -1314,7 +1407,6 @@ void Client::remaximize() maximize(true, dir, false); } - void Client::applyStartupState() { // these are in a carefully crafted order.. @@ -1352,7 +1444,6 @@ void Client::applyStartupState() if (_below); // nothing to do for this } - void Client::fireUrgent() { // call the python UrgentWindow callbacks @@ -1360,7 +1451,6 @@ void Client::fireUrgent() openbox->bindings()->fireEvent(&data); } - void Client::shade(bool shade) { if (!(_functions & Func_Shade) || // can't @@ -1374,7 +1464,6 @@ void Client::shade(bool shade) frame->adjustSize(); } - void Client::maximize(bool max, int dir, bool savearea) { assert(dir == 0 || dir == 1 || dir == 2); @@ -1481,7 +1570,6 @@ void Client::maximize(bool max, int dir, bool savearea) internal_resize(TopLeft, w, h, true, x, y); } - void Client::fullscreen(bool fs, bool savearea) { static FunctionFlags saved_func; @@ -1556,7 +1644,6 @@ void Client::fullscreen(bool fs, bool savearea) if (fs) focus(); } - void Client::iconify(bool iconic, bool curdesk) { if (_iconic == iconic) return; // nothing to do @@ -1580,20 +1667,16 @@ void Client::iconify(bool iconic, bool curdesk) XMapWindow(**otk::display, _window); } changeState(); - showhide(); - openbox->screen(_screen)->updateStruts(); } - void Client::disableDecorations(DecorationFlags flags) { _disabled_decorations = flags; setupDecorAndFunctions(); } - void Client::installColormap(bool install) const { XWindowAttributes wa; @@ -1605,9 +1688,6 @@ void Client::installColormap(bool install) const } } - -// recursively searches the client 'tree' for a modal client, always skips the -// topmost node (the window you're starting with) Client *Client::searchModalTree(Client *node, Client *skip) { List::const_iterator it, end = node->_transients.end(); @@ -1700,6 +1780,8 @@ void Client::focusHandler(const XFocusChangeEvent &e) _focused = true; frame->adjustFocus(); + calcLayer(); // focus state can affect the stacking layer + openbox->setFocusedClient(this); } @@ -1715,6 +1797,8 @@ void Client::unfocusHandler(const XFocusChangeEvent &e) _focused = false; frame->adjustFocus(); + calcLayer(); // focus state can affect the stacking layer + if (openbox->focusedClient() == this) openbox->setFocusedClient(0); }