diff options
Diffstat (limited to 'src/Container.cc')
-rw-r--r-- | src/Container.cc | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/src/Container.cc b/src/Container.cc index 4cd0fa8..5e7cb7d 100644 --- a/src/Container.cc +++ b/src/Container.cc | |||
@@ -272,35 +272,10 @@ void Container::setMaxTotalSize(unsigned int size) { | |||
272 | if (m_max_total_size == size) | 272 | if (m_max_total_size == size) |
273 | return; | 273 | return; |
274 | 274 | ||
275 | unsigned int old = m_max_total_size; | ||
276 | m_max_total_size = size; | 275 | m_max_total_size = size; |
277 | 276 | ||
278 | repositionItems(); | 277 | repositionItems(); |
279 | return; | 278 | return; |
280 | |||
281 | if (m_max_total_size && width() > m_max_total_size) { | ||
282 | resize(m_max_total_size, height()); | ||
283 | } else if (!m_max_total_size && old) { // going from restricted to unrestricted | ||
284 | repositionItems(); | ||
285 | } else { | ||
286 | // this is a bit of duplication from repositionItems | ||
287 | // for when we are allowed to grow ourself | ||
288 | Alignment align = alignment(); | ||
289 | size_t num_items = m_item_list.size(); | ||
290 | if (m_max_total_size && (align == RIGHT || align == LEFT) && | ||
291 | num_items) { | ||
292 | unsigned int max_width_per_client = maxWidthPerClient(); | ||
293 | unsigned int borderW = m_item_list.front()->borderWidth(); | ||
294 | |||
295 | unsigned int preferred_width = (max_width_per_client + borderW) * num_items - borderW; | ||
296 | |||
297 | if (preferred_width > m_max_total_size) | ||
298 | preferred_width = m_max_total_size; | ||
299 | |||
300 | if (preferred_width != width()) | ||
301 | repositionItems(); | ||
302 | } | ||
303 | } | ||
304 | } | 279 | } |
305 | 280 | ||
306 | void Container::setAlignment(Container::Alignment a) { | 281 | void Container::setAlignment(Container::Alignment a) { |
@@ -401,7 +376,6 @@ void Container::repositionItems() { | |||
401 | total_width = m_max_total_size; | 376 | total_width = m_max_total_size; |
402 | if (m_max_total_size > ((num_items - 1)*borderW)) { // don't go negative with unsigned nums | 377 | if (m_max_total_size > ((num_items - 1)*borderW)) { // don't go negative with unsigned nums |
403 | max_width_per_client = ( m_max_total_size - (num_items - 1)*borderW ) / num_items; | 378 | max_width_per_client = ( m_max_total_size - (num_items - 1)*borderW ) / num_items; |
404 | total_width = (max_width_per_client + borderW) * num_items - borderW; | ||
405 | } else | 379 | } else |
406 | max_width_per_client = 1; | 380 | max_width_per_client = 1; |
407 | } | 381 | } |
@@ -429,7 +403,11 @@ void Container::repositionItems() { | |||
429 | ItemList::iterator it = m_item_list.begin(); | 403 | ItemList::iterator it = m_item_list.begin(); |
430 | const ItemList::iterator it_end = m_item_list.end(); | 404 | const ItemList::iterator it_end = m_item_list.end(); |
431 | 405 | ||
432 | int rounding_error = total_width - ((max_width_per_client + borderW)* num_items - borderW); | 406 | int rounding_error = 0; |
407 | |||
408 | if (align == RELATIVE || total_width == m_max_total_size) { | ||
409 | rounding_error = total_width - ((max_width_per_client + borderW)* num_items - borderW); | ||
410 | } | ||
433 | 411 | ||
434 | int next_x = -borderW; // zero so the border of the first shows | 412 | int next_x = -borderW; // zero so the border of the first shows |
435 | int extra = 0; | 413 | int extra = 0; |
@@ -443,10 +421,16 @@ void Container::repositionItems() { | |||
443 | unsigned int tmpw, tmph; | 421 | unsigned int tmpw, tmph; |
444 | for (; it != it_end; ++it, next_x += direction*(max_width_per_client + borderW + extra)) { | 422 | for (; it != it_end; ++it, next_x += direction*(max_width_per_client + borderW + extra)) { |
445 | // we only need to do error stuff with alignment RELATIVE | 423 | // we only need to do error stuff with alignment RELATIVE |
446 | if (rounding_error != 0 && align == RELATIVE) { | 424 | // OR with max_total_size triggered |
425 | if (rounding_error) { | ||
447 | --rounding_error; | 426 | --rounding_error; |
448 | extra = 1; | 427 | extra = 1; |
428 | //counter for different direction | ||
429 | if (align == RIGHT && !extra) | ||
430 | --next_x; | ||
449 | } else { | 431 | } else { |
432 | if (extra && align == RIGHT) // last extra | ||
433 | ++next_x; | ||
450 | extra = 0; | 434 | extra = 0; |
451 | } | 435 | } |
452 | // rotate the x and y coords | 436 | // rotate the x and y coords |