some changes to updatesizehints, I don't change the aspect ratio algorithm now - I can't think, it is a mess
9ca5c3b1
2 file(s) · +24 −17
| 227 | 227 | ||
| 228 | 228 | void |
|
| 229 | 229 | resize(Client *c, int x, int y, int w, int h, Bool sizehints) { |
|
| 230 | - | float actual, dx, dy, max, min; |
|
| 230 | + | float dx, dy, max, min, ratio; |
|
| 231 | 231 | XWindowChanges wc; |
|
| 232 | 232 | ||
| 233 | 233 | if(w <= 0 || h <= 0) |
|
| 234 | 234 | return; |
|
| 235 | 235 | if(sizehints) { |
|
| 236 | - | if(c->minw && w < c->minw) |
|
| 237 | - | w = c->minw; |
|
| 238 | - | if(c->minh && h < c->minh) |
|
| 239 | - | h = c->minh; |
|
| 240 | - | if(c->maxw && w > c->maxw) |
|
| 241 | - | w = c->maxw; |
|
| 242 | - | if(c->maxh && h > c->maxh) |
|
| 243 | - | h = c->maxh; |
|
| 244 | - | /* inspired by algorithm from fluxbox */ |
|
| 245 | 236 | if(c->minay > 0 && c->maxay && (h - c->baseh) > 0) { |
|
| 246 | 237 | dx = (float)(w - c->basew); |
|
| 247 | 238 | dy = (float)(h - c->baseh); |
|
| 248 | 239 | min = (float)(c->minax) / (float)(c->minay); |
|
| 249 | 240 | max = (float)(c->maxax) / (float)(c->maxay); |
|
| 250 | - | actual = dx / dy; |
|
| 251 | - | if(max > 0 && min > 0 && actual > 0) { |
|
| 252 | - | if(actual < min) { |
|
| 241 | + | ratio = dx / dy; |
|
| 242 | + | if(max > 0 && min > 0 && ratio > 0) { |
|
| 243 | + | if(ratio < min) { |
|
| 253 | 244 | dy = (dx * min + dy) / (min * min + 1); |
|
| 254 | 245 | dx = dy * min; |
|
| 255 | 246 | w = (int)dx + c->basew; |
|
| 256 | 247 | h = (int)dy + c->baseh; |
|
| 257 | 248 | } |
|
| 258 | - | else if(actual > max) { |
|
| 249 | + | else if(ratio > max) { |
|
| 259 | 250 | dy = (dx * min + dy) / (max * max + 1); |
|
| 260 | 251 | dx = dy * min; |
|
| 261 | 252 | w = (int)dx + c->basew; |
|
| 263 | 254 | } |
|
| 264 | 255 | } |
|
| 265 | 256 | } |
|
| 257 | + | if(c->minw && w < c->minw) |
|
| 258 | + | w = c->minw; |
|
| 259 | + | if(c->minh && h < c->minh) |
|
| 260 | + | h = c->minh; |
|
| 261 | + | if(c->maxw && w > c->maxw) |
|
| 262 | + | w = c->maxw; |
|
| 263 | + | if(c->maxh && h > c->maxh) |
|
| 264 | + | h = c->maxh; |
|
| 266 | 265 | if(c->incw) |
|
| 267 | 266 | w -= (w - c->basew) % c->incw; |
|
| 268 | 267 | if(c->inch) |
|
| 313 | 312 | c->basew = size.base_width; |
|
| 314 | 313 | c->baseh = size.base_height; |
|
| 315 | 314 | } |
|
| 315 | + | else if(c->flags & PMinSize) { |
|
| 316 | + | c->basew = size.min_width; |
|
| 317 | + | c->baseh = size.min_height; |
|
| 318 | + | } |
|
| 316 | 319 | else |
|
| 317 | 320 | c->basew = c->baseh = 0; |
|
| 318 | 321 | if(c->flags & PResizeInc) { |
|
| 331 | 334 | c->minw = size.min_width; |
|
| 332 | 335 | c->minh = size.min_height; |
|
| 333 | 336 | } |
|
| 337 | + | else if(c->flags & PBaseSize) { |
|
| 338 | + | c->minw = size.base_width; |
|
| 339 | + | c->minh = size.base_height; |
|
| 340 | + | } |
|
| 334 | 341 | else |
|
| 335 | 342 | c->minw = c->minh = 0; |
|
| 336 | 343 | if(c->flags & PAspect) { |
|
| 337 | 344 | c->minax = size.min_aspect.x; |
|
| 338 | - | c->minay = size.min_aspect.y; |
|
| 339 | 345 | c->maxax = size.max_aspect.x; |
|
| 346 | + | c->minay = size.min_aspect.y; |
|
| 340 | 347 | c->maxay = size.max_aspect.y; |
|
| 341 | 348 | } |
|
| 342 | 349 | else |
|
| 343 | - | c->minax = c->minay = c->maxax = c->maxay = 0; |
|
| 350 | + | c->minax = c->maxax = c->minay = c->maxay = 0; |
|
| 344 | 351 | c->isfixed = (c->maxw && c->minw && c->maxh && c->minh |
|
| 345 | 352 | && c->maxw == c->minw && c->maxh == c->minh); |
|
| 346 | 353 | } |
|
| 47 | 47 | int x, y, w, h; |
|
| 48 | 48 | int rx, ry, rw, rh; /* revert geometry */ |
|
| 49 | 49 | int basew, baseh, incw, inch, maxw, maxh, minw, minh; |
|
| 50 | - | int minax, minay, maxax, maxay; |
|
| 50 | + | int minax, maxax, minay, maxay; |
|
| 51 | 51 | long flags; |
|
| 52 | 52 | unsigned int border; |
|
| 53 | 53 | Bool isbanned, isfixed, ismax, isfloating; |