-void OpenboxWindow::downsize(void) {
- frame.y_handle = frame.height - frame.handle_h;
- frame.border_h = frame.y_handle - frame.y_border -
- (decorations.handle ? frame.border_w : 0);
-
- client.x = frame.x + frame.mwm_border_w + frame.border_w;
- client.y = frame.y + frame.y_border + frame.mwm_border_w + frame.border_w;
-
- client.width = frame.width - (frame.mwm_border_w * 2);
- client.height = frame.height - frame.y_border - (frame.mwm_border_w * 2)
- - frame.handle_h - (decorations.handle ? frame.border_w : 0);
-
- frame.y_handle = frame.border_h + frame.y_border + frame.border_w;
-}
-
-
-void OpenboxWindow::right_fixsize(int *gx, int *gy) {
- // calculate the size of the client window and conform it to the
- // size specified by the size hints of the client window...
- int dx = frame.resize_w - client.base_width - (frame.mwm_border_w * 2) -
- (frame.border_w * 2) + (client.width_inc / 2);
- int dy = frame.resize_h - frame.y_border - client.base_height -
- frame.handle_h - (frame.border_w * 3) - (frame.mwm_border_w * 2)
- + (client.height_inc / 2);
-
- if (dx < (signed) client.min_width) dx = client.min_width;
- if (dy < (signed) client.min_height) dy = client.min_height;
- if ((unsigned) dx > client.max_width) dx = client.max_width;
- if ((unsigned) dy > client.max_height) dy = client.max_height;
-
- dx /= client.width_inc;
- dy /= client.height_inc;
-
- if (gx) *gx = dx;
- if (gy) *gy = dy;
-
- dx = (dx * client.width_inc) + client.base_width;
- dy = (dy * client.height_inc) + client.base_height;
-
- frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2);
- frame.resize_h = dy + frame.y_border + frame.handle_h +
- (frame.mwm_border_w * 2) + (frame.border_w * 3);
- if (resize_zone & ZoneTop)
- frame.resize_y = frame.y + frame.height - frame.resize_h +
- screen->getBorderWidth() * 2;
-}
-
-
-void OpenboxWindow::left_fixsize(int *gx, int *gy) {
- // calculate the size of the client window and conform it to the
- // size specified by the size hints of the client window...
- int dx = frame.x + frame.width - frame.resize_x - client.base_width -
- (frame.mwm_border_w * 2) + (client.width_inc / 2);
- int dy = frame.resize_h - frame.y_border - client.base_height -
- frame.handle_h - (frame.border_w * 3) - (frame.mwm_border_w * 2)
- + (client.height_inc / 2);
-
- if (dx < (signed) client.min_width) dx = client.min_width;
- if (dy < (signed) client.min_height) dy = client.min_height;
- if ((unsigned) dx > client.max_width) dx = client.max_width;
- if ((unsigned) dy > client.max_height) dy = client.max_height;
-
- dx /= client.width_inc;
- dy /= client.height_inc;
-
- if (gx) *gx = dx;
- if (gy) *gy = dy;
-
- dx = (dx * client.width_inc) + client.base_width;
- dy = (dy * client.height_inc) + client.base_height;
-
- frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2);
- frame.resize_x = frame.x + frame.width - frame.resize_w +
- (frame.border_w * 2);
- frame.resize_h = dy + frame.y_border + frame.handle_h +
- (frame.mwm_border_w * 2) + (frame.border_w * 3);
- if (resize_zone & ZoneTop)
- frame.resize_y = frame.y + frame.height - frame.resize_h +
- screen->getBorderWidth() * 2;
-
+void BlackboxWindow::constrain(Corner anchor, int *pw, int *ph) {
+ // frame.changing represents the requested frame size, we need to
+ // strip the frame margin off and constrain the client size
+ frame.changing.setCoords(frame.changing.left() + frame.margin.left,
+ frame.changing.top() + frame.margin.top,
+ frame.changing.right() - frame.margin.right,
+ frame.changing.bottom() - frame.margin.bottom);
+
+ int dw = frame.changing.width(), dh = frame.changing.height(),
+ base_width = (client.base_width) ? client.base_width : client.min_width,
+ base_height = (client.base_height) ? client.base_height :
+ client.min_height;
+
+ // constrain
+ if (dw < static_cast<signed>(client.min_width)) dw = client.min_width;
+ if (dh < static_cast<signed>(client.min_height)) dh = client.min_height;
+ if (dw > static_cast<signed>(client.max_width)) dw = client.max_width;
+ if (dh > static_cast<signed>(client.max_height)) dh = client.max_height;
+
+ dw -= base_width;
+ dw /= client.width_inc;
+ dh -= base_height;
+ dh /= client.height_inc;
+
+ if (pw) *pw = dw;
+ if (ph) *ph = dh;
+
+ dw *= client.width_inc;
+ dw += base_width;
+ dh *= client.height_inc;
+ dh += base_height;
+
+ frame.changing.setSize(dw, dh);
+
+ // add the frame margin back onto frame.changing
+ frame.changing.setCoords(frame.changing.left() - frame.margin.left,
+ frame.changing.top() - frame.margin.top,
+ frame.changing.right() + frame.margin.right,
+ frame.changing.bottom() + frame.margin.bottom);
+
+ // move frame.changing to the specified anchor
+ switch (anchor) {
+ case TopLeft:
+ // nothing to do
+ break;
+
+ case TopRight:
+ int dx = frame.rect.right() - frame.changing.right();
+ frame.changing.setPos(frame.changing.x() + dx, frame.changing.y());
+ break;
+ }
+}
+
+
+int WindowStyle::doJustify(const char *text, int &start_pos,
+ unsigned int max_length, unsigned int modifier,
+ bool multibyte) const {
+ size_t text_len = strlen(text);
+ unsigned int length;
+
+ do {
+ if (multibyte) {
+ XRectangle ink, logical;
+ XmbTextExtents(fontset, text, text_len, &ink, &logical);
+ length = logical.width;
+ } else {
+ length = XTextWidth(font, text, text_len);
+ }
+ length += modifier;
+ } while (length > max_length && text_len-- > 0);
+
+ switch (justify) {
+ case RightJustify:
+ start_pos += max_length - length;
+ break;
+
+ case CenterJustify:
+ start_pos += (max_length - length) / 2;
+ break;
+
+ case LeftJustify:
+ default:
+ break;
+ }
+
+ return text_len;
+}
+
+
+BWindowGroup::BWindowGroup(Blackbox *b, Window _group)
+ : blackbox(b), group(_group) {
+ // watch for destroy notify on the group window
+ XSelectInput(blackbox->getXDisplay(), group, StructureNotifyMask);
+ blackbox->saveGroupSearch(group, this);
+}
+
+
+BWindowGroup::~BWindowGroup(void) {
+ blackbox->removeGroupSearch(group);
+}
+
+
+BlackboxWindow *
+BWindowGroup::find(BScreen *screen, bool allow_transients) const {
+ BlackboxWindow *ret = blackbox->getFocusedWindow();
+
+ // does the focus window match (or any transient_fors)?
+ while (ret) {
+ if (ret->getScreen() == screen && ret->getGroupWindow() == group) {
+ if (ret->isTransient() && allow_transients) break;
+ else if (! ret->isTransient()) break;
+ }
+
+ ret = ret->getTransientFor();
+ }
+
+ if (ret) return ret;
+
+ // the focus window didn't match, look in the group's window list
+ BlackboxWindowList::const_iterator it, end = windowList.end();
+ for (it = windowList.begin(); it != end; ++it) {
+ ret = *it;
+ if (ret->getScreen() == screen && ret->getGroupWindow() == group) {
+ if (ret->isTransient() && allow_transients) break;
+ else if (! ret->isTransient()) break;
+ }
+ }
+
+ return ret;