#define _(str) gettext(str)
}
+#include <cstring> // for memcpy
#include <climits>
#include <cassert>
#include <algorithm>
_disabled_decorations = 0;
_group = None;
_desktop = 0;
+ _nicons = 0;
getArea();
getDesktop();
updateIconTitle();
updateClass();
updateStrut();
-
+ updateIcons();
+
// this makes sure that these windows appear on all desktops
if (/*_type == Type_Dock ||*/ _type == Type_Desktop)
_desktop = 0xffffffff;
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;
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;
}
+void Client::updateIcons()
+{
+ unsigned long num = (unsigned) -1;
+ unsigned long *data;
+ unsigned long w, h, i = 0;
+
+ 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)) {
+ // 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);
+ }
+ printf("i: %lu\n", i);
+ printf("bleffffffff\n");
+
+ 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;
+ _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)
{
otk::EventHandler::propertyHandler(e);
}
else if (e.atom == otk::Property::atoms.net_wm_strut)
updateStrut();
+ else if (e.atom == otk::Property::atoms.net_wm_icon)
+ updateIcons();
}
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)
{
enum Decoration { Decor_Titlebar = 1 << 0, //!< Display a titlebar
Decor_Handle = 1 << 1, //!< Display a handle (bottom)
Decor_Border = 1 << 2, //!< Display a border
- Decor_Iconify = 1 << 3, //!< Display an iconify button
- Decor_Maximize = 1 << 4, //!< Display a maximize button
+ Decor_Icon = 1 << 3, //!< Display the window's icon
+ Decor_Iconify = 1 << 4, //!< Display an iconify button
+ Decor_Maximize = 1 << 5, //!< Display a maximize button
//! Display a button to toggle the window's placement on
//! all desktops
- Decor_AllDesktops = 1 << 5,
- Decor_Close = 1 << 6 //!< Display a close button
+ Decor_AllDesktops = 1 << 6,
+ Decor_Close = 1 << 7 //!< Display a close button
};
//! Holds a bitmask of Client::Decoration values
typedef unsigned char DecorationFlags;
*/
FunctionFlags _functions;
+ //! Icons for the client as specified on the client window
+ Icon *_icons;
+ //! The number of icons in _icons
+ int _nicons;
+
//! Retrieves the window's initial gravity
void getGravity();
//! Retrieves the desktop hint's value and sets Client::_desktop
void updateStrut();
//! Updates the window's transient status, and any parents of it
void updateTransientFor();
+ //! Updates the window's icons
+ void updateIcons();
//! Change the client's state hints to match the class' data
void changeState();
//! Returns the client's strut definition
inline const otk::Strut &strut() const { return _strut; }
+ //! Returns an icon for the window
+ /*!
+ The icon chosen will be the smallest icon available that is still bigger or
+ equal to the specified Size.<br>
+ If none that meet the requirements is found, the largest icon that is
+ smaller than the specified size will be returned.
+ */
+ const Icon *icon(const otk::Size &s) const;
+
//! Move the window (actually, its frame) to a position.
/*!
This moves the window so that the top-left corner of its frame will be at
}
#include "frame.hh"
-#include "client.hh"
#include "openbox.hh"
#include "otk/display.hh"
#include "otk/surface.hh"
void Frame::adjustSize()
{
- Client::DecorationFlags decorations = _client->decorations();
+ _decorations = _client->decorations();
const otk::RenderStyle *style = otk::RenderStyle::style(_client->screen());
- if (decorations & Client::Decor_Border) {
+ if (_decorations & Client::Decor_Border) {
geom.bwidth = style->frameBorderWidth();
geom.cbwidth = style->clientBorderWidth();
} else {
// position/size and map/unmap all the windows
- if (decorations & Client::Decor_Titlebar) {
+ if (_decorations & Client::Decor_Titlebar) {
XMoveResizeWindow(**otk::display, _title, -geom.bwidth, -geom.bwidth,
geom.width, geom.title_height());
_innersize.top += geom.title_height() + geom.bwidth;
// layout the title bar elements
layoutTitle();
- } else
+ } else {
XUnmapWindow(**otk::display, _title);
+ // make all the titlebar stuff not render
+ _decorations &= ~(Client::Decor_Icon | Client::Decor_Iconify |
+ Client::Decor_Maximize | Client::Decor_Close |
+ Client::Decor_AllDesktops);
+ }
- if (decorations & Client::Decor_Handle) {
+ if (_decorations & Client::Decor_Handle) {
geom.handle_y = _innersize.top + _client->area().height() + geom.cbwidth;
XMoveResizeWindow(**otk::display, _handle, -geom.bwidth, geom.handle_y,
geom.width, geom.handle_height);
// render all the elements
int screen = _client->screen();
bool focus = _client->focused();
- if (decorations & Client::Decor_Titlebar) {
+ if (_decorations & Client::Decor_Titlebar) {
render(screen, otk::Size(geom.width, geom.title_height()), _title,
&_title_sur, *(focus ? style->titlebarFocusBackground() :
style->titlebarUnfocusBackground()), false);
renderClose();
}
- if (decorations & Client::Decor_Handle) {
+ if (_decorations & Client::Decor_Handle) {
render(screen, otk::Size(geom.width, geom.handle_height), _handle,
&_handle_sur, *(focus ? style->handleFocusBackground() :
style->handleUnfocusBackground()));
XSetWindowBackgroundPixmap(**otk::display, win, s->pixmap());
XClearWindow(**otk::display, win);
if (*sur) delete *sur;
+ s->freePixelData();
*sur = s;
}
void Frame::renderMax()
{
+ if (!(_decorations & Client::Decor_Maximize)) return;
bool press = _max_press || _client->maxVert() || _client->maxHorz();
renderButton(_client->screen(), _client->focused(), press, _max,
&_max_sur, geom.button_size,
void Frame::renderDesk()
{
+ if (!(_decorations & Client::Decor_AllDesktops)) return;
bool press = _desk_press || _client->desktop() == 0xffffffff;
renderButton(_client->screen(), _client->focused(), press, _desk,
&_desk_sur, geom.button_size,
void Frame::renderIconify()
{
+ if (!(_decorations & Client::Decor_Iconify)) return;
renderButton(_client->screen(), _client->focused(), _iconify_press, _iconify,
&_iconify_sur, geom.button_size,
otk::RenderStyle::style(_client->screen())->iconifyMask());
void Frame::renderClose()
{
+ if (!(_decorations & Client::Decor_Close)) return;
renderButton(_client->screen(), _client->focused(), _close_press, _close,
&_close_sur, geom.button_size,
otk::RenderStyle::style(_client->screen())->closeMask());
void Frame::renderIcon()
{
+ if (!(_decorations & Client::Decor_Icon)) return;
const int screen = _client->screen();
const otk::RenderControl *control = otk::display->renderControl(screen);
for (int y = 0; y < geom.button_size; ++y, src += w - geom.button_size)
for (int x = 0; x < geom.button_size; ++x, ++dest, ++src)
*dest = *src;
- control->drawImage(*s, 0, 0, 0);
+ // draw the icon over it
+ const Icon *icon = _client->icon(otk::Size(geom.button_size,
+ geom.button_size));
+ control->drawImage(*s, icon->w, icon->h, icon->data);
XSetWindowBackgroundPixmap(**otk::display, _icon, s->pixmap());
XClearWindow(**otk::display, _icon);
void Frame::layoutTitle()
{
- geom.label_width = geom.width - geom.bevel * 2 -
- (geom.button_size + geom.bevel) * (_layout.size() - 1);
+ // figure out whats being shown, and the width of the label
+ geom.label_width = geom.width - geom.bevel * 2;
+ bool n, d, i, t, m ,c;
+ n = d = i = t = m = c = false;
+ for (const char *l = _layout.c_str(); *l; ++l) {
+ switch (*l) {
+ case 'n':
+ case 'N':
+ if (!(_decorations & Client::Decor_Icon)) break;
+ n = true;
+ geom.label_width -= geom.button_size + geom.bevel;
+ break;
+ case 'd':
+ case 'D':
+ if (!(_decorations & Client::Decor_AllDesktops)) break;
+ d = true;
+ geom.label_width -= geom.button_size + geom.bevel;
+ break;
+ case 'i':
+ case 'I':
+ if (!(_decorations & Client::Decor_Iconify)) break;
+ i = true;
+ geom.label_width -= geom.button_size + geom.bevel;
+ break;
+ case 't':
+ case 'T':
+ t = true;
+ break;
+ case 'm':
+ case 'M':
+ if (!(_decorations & Client::Decor_Maximize)) break;
+ m = true;
+ geom.label_width -= geom.button_size + geom.bevel;
+ break;
+ case 'c':
+ case 'C':
+ if (!(_decorations & Client::Decor_Close)) break;
+ c = true;
+ geom.label_width -= geom.button_size + geom.bevel;
+ break;
+ }
+ }
if (geom.label_width < 1) geom.label_width = 1;
XResizeWindow(**otk::display, _label, geom.label_width, geom.font_height);
+ if (!n) {
+ _decorations &= ~Client::Decor_Icon;
+ XUnmapWindow(**otk::display, _icon);
+ }
+ if (!d) {
+ _decorations &= ~Client::Decor_AllDesktops;
+ XUnmapWindow(**otk::display, _desk);
+ }
+ if (!i) {
+ _decorations &= ~Client::Decor_Iconify;
+ XUnmapWindow(**otk::display, _iconify);
+ }
+ if (!t)
+ XUnmapWindow(**otk::display, _label);
+ if (!m) {
+ _decorations &= ~Client::Decor_Maximize;
+ XUnmapWindow(**otk::display, _max);
+ }
+ if (!c) {
+ _decorations &= ~Client::Decor_Close;
+ XUnmapWindow(**otk::display, _close);
+ }
+
int x = geom.bevel;
- bool n, d, i, l, m ,c;
- n = d = i = l = m = c = false;
for (const char *lc = _layout.c_str(); *lc; ++lc) {
switch (*lc) {
case 'n':
case 'N':
+ if (!n) break;
geom.icon_x = x;
XMapWindow(**otk::display, _icon);
XMoveWindow(**otk::display, _icon, x, geom.bevel + 1);
- n = true;
x += geom.button_size;
break;
case 'd':
case 'D':
+ if (!d) break;
XMapWindow(**otk::display, _desk);
XMoveWindow(**otk::display, _desk, x, geom.bevel + 1);
- d = true;
x += geom.button_size;
break;
case 'i':
case 'I':
+ if (!i) break;
XMapWindow(**otk::display, _iconify);
XMoveWindow(**otk::display, _iconify, x, geom.bevel + 1);
- i = true;
x += geom.button_size;
break;
case 't':
case 'T':
+ if (!t) break;
XMapWindow(**otk::display, _label);
XMoveWindow(**otk::display, _label, x, geom.bevel);
- l = true;
x += geom.label_width;
break;
case 'm':
case 'M':
+ if (!m) break;
XMapWindow(**otk::display, _max);
XMoveWindow(**otk::display, _max, x, geom.bevel + 1);
- m = true;
x += geom.button_size;
break;
case 'c':
case 'C':
+ if (!c) break;
XMapWindow(**otk::display, _close);
XMoveWindow(**otk::display, _close, x, geom.bevel + 1);
- c = true;
x += geom.button_size;
break;
}
x += geom.bevel;
}
- if (!n) XUnmapWindow(**otk::display, _icon);
- if (!d) XUnmapWindow(**otk::display, _desk);
- if (!i) XUnmapWindow(**otk::display, _iconify);
- if (!l) XUnmapWindow(**otk::display, _label);
- if (!m) XUnmapWindow(**otk::display, _max);
- if (!c) XUnmapWindow(**otk::display, _close);
}
void Frame::adjustPosition()
void Frame::adjustShape()
{
#ifdef SHAPE
- Client::DecorationFlags decorations = _client->decorations();
-
if (!_client->shaped()) {
// clear the shape on the frame window
XShapeCombineMask(**otk::display, _frame, ShapeBounding,
int num = 0;
XRectangle xrect[2];
- if (decorations & Client::Decor_Titlebar) {
+ if (_decorations & Client::Decor_Titlebar) {
xrect[0].x = -geom.bevel;
xrect[0].y = -geom.bevel;
xrect[0].width = geom.width + geom.bwidth * 2;
++num;
}
- if (decorations & Client::Decor_Handle) {
+ if (_decorations & Client::Decor_Handle) {
xrect[1].x = -geom.bevel;
xrect[1].y = geom.handle_y;
xrect[1].width = geom.width + geom.bwidth * 2;
#endif // SHAPE
}
-
void Frame::adjustState()
{
renderDesk();
renderMax();
}
+void Frame::adjustIcon()
+{
+ renderIcon();
+}
void Frame::grabClient()
{