diff options
author | Mark Tiefenbruck <mark@fluxbox.org> | 2008-08-15 11:02:14 (GMT) |
---|---|---|
committer | Mark Tiefenbruck <mark@fluxbox.org> | 2008-08-15 11:02:14 (GMT) |
commit | 80059c6dae8de4962b14f08bd75f1c773e37a78d (patch) | |
tree | d94651987a6c9a25d87292c2c5d74018ba541473 /src/WinClient.cc | |
parent | 31b47e78147ca20803b123f392bfd2002b70e052 (diff) | |
download | fluxbox-80059c6dae8de4962b14f08bd75f1c773e37a78d.zip fluxbox-80059c6dae8de4962b14f08bd75f1c773e37a78d.tar.bz2 |
move size hints to a struct
Diffstat (limited to 'src/WinClient.cc')
-rw-r--r-- | src/WinClient.cc | 153 |
1 files changed, 78 insertions, 75 deletions
diff --git a/src/WinClient.cc b/src/WinClient.cc index a7e689f..9aac38d 100644 --- a/src/WinClient.cc +++ b/src/WinClient.cc | |||
@@ -67,12 +67,6 @@ WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin): | |||
67 | transient_for(0), | 67 | transient_for(0), |
68 | window_group(0), | 68 | window_group(0), |
69 | x(0), y(0), old_bw(0), | 69 | x(0), y(0), old_bw(0), |
70 | min_width(1), min_height(1), | ||
71 | max_width(0), max_height(0), | ||
72 | width_inc(1), height_inc(1), | ||
73 | min_aspect_x(0), min_aspect_y(0), | ||
74 | max_aspect_x(0), max_aspect_y(0), | ||
75 | base_width(1), base_height(1), | ||
76 | initial_state(0), | 70 | initial_state(0), |
77 | normal_hint_flags(0), | 71 | normal_hint_flags(0), |
78 | wm_hint_flags(0), | 72 | wm_hint_flags(0), |
@@ -87,6 +81,15 @@ WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin): | |||
87 | m_window_type(Focusable::TYPE_NORMAL), | 81 | m_window_type(Focusable::TYPE_NORMAL), |
88 | m_mwm_hint(0), | 82 | m_mwm_hint(0), |
89 | m_strut(0) { | 83 | m_strut(0) { |
84 | |||
85 | m_size_hints.min_width = m_size_hints.min_height = | ||
86 | m_size_hints.width_inc = m_size_hints.height_inc = | ||
87 | m_size_hints.base_width = m_size_hints.base_height = 1; | ||
88 | |||
89 | m_size_hints.max_width = m_size_hints.max_height = | ||
90 | m_size_hints.min_aspect_x = m_size_hints.min_aspect_y = | ||
91 | m_size_hints.max_aspect_x = m_size_hints.max_aspect_y = 0; | ||
92 | |||
90 | updateWMProtocols(); | 93 | updateWMProtocols(); |
91 | updateMWMHints(); | 94 | updateMWMHints(); |
92 | updateWMHints(); | 95 | updateWMHints(); |
@@ -469,65 +472,65 @@ void WinClient::updateWMNormalHints() { | |||
469 | long icccm_mask; | 472 | long icccm_mask; |
470 | XSizeHints sizehint; | 473 | XSizeHints sizehint; |
471 | if (! XGetWMNormalHints(display(), window(), &sizehint, &icccm_mask)) { | 474 | if (! XGetWMNormalHints(display(), window(), &sizehint, &icccm_mask)) { |
472 | min_width = min_height = | 475 | m_size_hints.min_width = m_size_hints.min_height = |
473 | base_width = base_height = | 476 | m_size_hints.base_width = m_size_hints.base_height = |
474 | width_inc = height_inc = 1; | 477 | m_size_hints.width_inc = m_size_hints.height_inc = 1; |
475 | max_width = 0; // unbounded | 478 | m_size_hints.max_width = 0; // unbounded |
476 | max_height = 0; | 479 | m_size_hints.max_height = 0; |
477 | min_aspect_x = min_aspect_y = | 480 | m_size_hints.min_aspect_x = m_size_hints.min_aspect_y = |
478 | max_aspect_x = max_aspect_y = 0; | 481 | m_size_hints.max_aspect_x = m_size_hints.max_aspect_y = 0; |
479 | m_win_gravity = NorthWestGravity; | 482 | m_win_gravity = NorthWestGravity; |
480 | } else { | 483 | } else { |
481 | normal_hint_flags = sizehint.flags; | 484 | normal_hint_flags = sizehint.flags; |
482 | 485 | ||
483 | if (sizehint.flags & PMinSize) { | 486 | if (sizehint.flags & PMinSize) { |
484 | min_width = sizehint.min_width; | 487 | m_size_hints.min_width = sizehint.min_width; |
485 | min_height = sizehint.min_height; | 488 | m_size_hints.min_height = sizehint.min_height; |
486 | if (!(sizehint.flags & PBaseSize)) { | 489 | if (!(sizehint.flags & PBaseSize)) { |
487 | base_width = min_width; | 490 | m_size_hints.base_width = m_size_hints.min_width; |
488 | base_height = min_height; | 491 | m_size_hints.base_height = m_size_hints.min_height; |
489 | } | 492 | } |
490 | } else { | 493 | } else { |
491 | min_width = min_height = 1; | 494 | m_size_hints.min_width = m_size_hints.min_height = 1; |
492 | base_width = base_height = 0; | 495 | m_size_hints.base_width = m_size_hints.base_height = 0; |
493 | } | 496 | } |
494 | 497 | ||
495 | if (sizehint.flags & PBaseSize) { | 498 | if (sizehint.flags & PBaseSize) { |
496 | base_width = sizehint.base_width; | 499 | m_size_hints.base_width = sizehint.base_width; |
497 | base_height = sizehint.base_height; | 500 | m_size_hints.base_height = sizehint.base_height; |
498 | if (!(sizehint.flags & PMinSize)) { | 501 | if (!(sizehint.flags & PMinSize)) { |
499 | min_width = base_width; | 502 | m_size_hints.min_width = m_size_hints.base_width; |
500 | min_height = base_height; | 503 | m_size_hints.min_height = m_size_hints.base_height; |
501 | } | 504 | } |
502 | } // default set in PMinSize | 505 | } // default set in PMinSize |
503 | 506 | ||
504 | if (sizehint.flags & PMaxSize) { | 507 | if (sizehint.flags & PMaxSize) { |
505 | max_width = sizehint.max_width; | 508 | m_size_hints.max_width = sizehint.max_width; |
506 | max_height = sizehint.max_height; | 509 | m_size_hints.max_height = sizehint.max_height; |
507 | } else { | 510 | } else { |
508 | max_width = 0; // unbounded | 511 | m_size_hints.max_width = 0; // unbounded |
509 | max_height = 0; | 512 | m_size_hints.max_height = 0; |
510 | } | 513 | } |
511 | 514 | ||
512 | if (sizehint.flags & PResizeInc) { | 515 | if (sizehint.flags & PResizeInc) { |
513 | width_inc = sizehint.width_inc; | 516 | m_size_hints.width_inc = sizehint.width_inc; |
514 | height_inc = sizehint.height_inc; | 517 | m_size_hints.height_inc = sizehint.height_inc; |
515 | } else | 518 | } else |
516 | width_inc = height_inc = 1; | 519 | m_size_hints.width_inc = m_size_hints.height_inc = 1; |
517 | 520 | ||
518 | if (width_inc == 0) | 521 | if (m_size_hints.width_inc == 0) |
519 | width_inc = 1; | 522 | m_size_hints.width_inc = 1; |
520 | if (height_inc == 0) | 523 | if (m_size_hints.height_inc == 0) |
521 | height_inc = 1; | 524 | m_size_hints.height_inc = 1; |
522 | 525 | ||
523 | if (sizehint.flags & PAspect) { | 526 | if (sizehint.flags & PAspect) { |
524 | min_aspect_x = sizehint.min_aspect.x; | 527 | m_size_hints.min_aspect_x = sizehint.min_aspect.x; |
525 | min_aspect_y = sizehint.min_aspect.y; | 528 | m_size_hints.min_aspect_y = sizehint.min_aspect.y; |
526 | max_aspect_x = sizehint.max_aspect.x; | 529 | m_size_hints.max_aspect_x = sizehint.max_aspect.x; |
527 | max_aspect_y = sizehint.max_aspect.y; | 530 | m_size_hints.max_aspect_y = sizehint.max_aspect.y; |
528 | } else | 531 | } else |
529 | min_aspect_x = min_aspect_y = | 532 | m_size_hints.min_aspect_x = m_size_hints.min_aspect_y = |
530 | max_aspect_x = max_aspect_y = 0; | 533 | m_size_hints.max_aspect_x = m_size_hints.max_aspect_y = 0; |
531 | 534 | ||
532 | if (sizehint.flags & PWinGravity) | 535 | if (sizehint.flags & PWinGravity) |
533 | m_win_gravity = sizehint.win_gravity; | 536 | m_win_gravity = sizehint.win_gravity; |
@@ -725,29 +728,29 @@ void WinClient::applySizeHints(int &width, int &height, | |||
725 | int i = width, j = height; | 728 | int i = width, j = height; |
726 | 729 | ||
727 | // Check minimum size | 730 | // Check minimum size |
728 | if (width < 0 || width < static_cast<signed>(min_width)) | 731 | if (width < 0 || width < static_cast<signed>(m_size_hints.min_width)) |
729 | width = min_width; | 732 | width = m_size_hints.min_width; |
730 | 733 | ||
731 | if (height < 0 || height < static_cast<signed>(min_height)) | 734 | if (height < 0 || height < static_cast<signed>(m_size_hints.min_height)) |
732 | height = min_height; | 735 | height = m_size_hints.min_height; |
733 | 736 | ||
734 | // Check maximum size | 737 | // Check maximum size |
735 | if (max_width > 0 && width > static_cast<signed>(max_width)) | 738 | if (m_size_hints.max_width > 0 && width > static_cast<signed>(m_size_hints.max_width)) |
736 | width = max_width; | 739 | width = m_size_hints.max_width; |
737 | 740 | ||
738 | if (max_height > 0 && height > static_cast<signed>(max_height)) | 741 | if (m_size_hints.max_height > 0 && height > static_cast<signed>(m_size_hints.max_height)) |
739 | height = max_height; | 742 | height = m_size_hints.max_height; |
740 | 743 | ||
741 | // we apply aspect ratios before incrementals | 744 | // we apply aspect ratios before incrementals |
742 | // Too difficult to exactly satisfy both incremental+aspect | 745 | // Too difficult to exactly satisfy both incremental+aspect |
743 | // in most situations | 746 | // in most situations |
744 | // (they really shouldn't happen at the same time anyway). | 747 | // (they really shouldn't happen at the same time anyway). |
745 | 748 | ||
746 | /* aspect ratios are applied exclusive to the base_width | 749 | /* aspect ratios are applied exclusive to the m_size_hints.base_width |
747 | * | 750 | * |
748 | * min_aspect_x width max_aspect_x | 751 | * m_size_hints.min_aspect_x width m_size_hints.max_aspect_x |
749 | * ------------ < ------- < ------------ | 752 | * ------------ < ------- < ------------ |
750 | * min_aspect_y height max_aspect_y | 753 | * m_size_hints.min_aspect_y height m_size_hints.max_aspect_y |
751 | * | 754 | * |
752 | * beware of integer maximum (so I'll use doubles instead and divide) | 755 | * beware of integer maximum (so I'll use doubles instead and divide) |
753 | * | 756 | * |
@@ -764,16 +767,16 @@ void WinClient::applySizeHints(int &width, int &height, | |||
764 | * is used in that case. | 767 | * is used in that case. |
765 | */ | 768 | */ |
766 | 769 | ||
767 | if (min_aspect_y > 0 && max_aspect_y > 0 && | 770 | if (m_size_hints.min_aspect_y > 0 && m_size_hints.max_aspect_y > 0 && |
768 | (height - base_height) > 0) { | 771 | (height - m_size_hints.base_height) > 0) { |
769 | double widthd = static_cast<double>(width - base_width); | 772 | double widthd = static_cast<double>(width - m_size_hints.base_width); |
770 | double heightd = static_cast<double>(height - base_height); | 773 | double heightd = static_cast<double>(height - m_size_hints.base_height); |
771 | 774 | ||
772 | double min = static_cast<double>(min_aspect_x) / | 775 | double min = static_cast<double>(m_size_hints.min_aspect_x) / |
773 | static_cast<double>(min_aspect_y); | 776 | static_cast<double>(m_size_hints.min_aspect_y); |
774 | 777 | ||
775 | double max = static_cast<double>(max_aspect_x) / | 778 | double max = static_cast<double>(m_size_hints.max_aspect_x) / |
776 | static_cast<double>(max_aspect_y); | 779 | static_cast<double>(m_size_hints.max_aspect_y); |
777 | 780 | ||
778 | double actual = widthd / heightd; | 781 | double actual = widthd / heightd; |
779 | 782 | ||
@@ -794,23 +797,23 @@ void WinClient::applySizeHints(int &width, int &height, | |||
794 | } | 797 | } |
795 | 798 | ||
796 | if (changed) { | 799 | if (changed) { |
797 | width = static_cast<int>(widthd) + base_width; | 800 | width = static_cast<int>(widthd) + m_size_hints.base_width; |
798 | height = static_cast<int>(heightd) + base_height; | 801 | height = static_cast<int>(heightd) + m_size_hints.base_height; |
799 | } | 802 | } |
800 | } | 803 | } |
801 | } | 804 | } |
802 | 805 | ||
803 | // enforce incremental size limits, wrt base size | 806 | // enforce incremental size limits, wrt base size |
804 | // only calculate this if we really need to | 807 | // only calculate this if we really need to |
805 | i = (width - static_cast<signed>(base_width)) / | 808 | i = (width - static_cast<signed>(m_size_hints.base_width)) / |
806 | static_cast<signed>(width_inc); | 809 | static_cast<signed>(m_size_hints.width_inc); |
807 | width = i*static_cast<signed>(width_inc) + | 810 | width = i*static_cast<signed>(m_size_hints.width_inc) + |
808 | static_cast<signed>(base_width); | 811 | static_cast<signed>(m_size_hints.base_width); |
809 | 812 | ||
810 | j = (height - static_cast<signed>(base_height)) / | 813 | j = (height - static_cast<signed>(m_size_hints.base_height)) / |
811 | static_cast<signed>(height_inc); | 814 | static_cast<signed>(m_size_hints.height_inc); |
812 | height = j*static_cast<signed>(height_inc) + | 815 | height = j*static_cast<signed>(m_size_hints.height_inc) + |
813 | static_cast<signed>(base_height); | 816 | static_cast<signed>(m_size_hints.base_height); |
814 | 817 | ||
815 | if (display_width) | 818 | if (display_width) |
816 | *display_width = i; | 819 | *display_width = i; |
@@ -821,24 +824,24 @@ void WinClient::applySizeHints(int &width, int &height, | |||
821 | 824 | ||
822 | // check if the given width and height satisfy the size hints | 825 | // check if the given width and height satisfy the size hints |
823 | bool WinClient::checkSizeHints(unsigned int width, unsigned int height) { | 826 | bool WinClient::checkSizeHints(unsigned int width, unsigned int height) { |
824 | if (width < min_width || height < min_height) | 827 | if (width < m_size_hints.min_width || height < m_size_hints.min_height) |
825 | return false; | 828 | return false; |
826 | 829 | ||
827 | if (width > max_width || height > max_height) | 830 | if (width > m_size_hints.max_width || height > m_size_hints.max_height) |
828 | return false; | 831 | return false; |
829 | 832 | ||
830 | if ((width - base_width) % width_inc != 0) | 833 | if ((width - m_size_hints.base_width) % m_size_hints.width_inc != 0) |
831 | return false; | 834 | return false; |
832 | 835 | ||
833 | if ((height - base_height) % height_inc != 0) | 836 | if ((height - m_size_hints.base_height) % m_size_hints.height_inc != 0) |
834 | return false; | 837 | return false; |
835 | 838 | ||
836 | double ratio = (double)width / (double)height; | 839 | double ratio = (double)width / (double)height; |
837 | 840 | ||
838 | if (min_aspect_y > 0 && (double)min_aspect_x / (double)min_aspect_y > ratio) | 841 | if (m_size_hints.min_aspect_y > 0 && (double)m_size_hints.min_aspect_x / (double)m_size_hints.min_aspect_y > ratio) |
839 | return false; | 842 | return false; |
840 | 843 | ||
841 | if (max_aspect_y > 0 && (double)max_aspect_x / (double)max_aspect_y < ratio) | 844 | if (m_size_hints.max_aspect_y > 0 && (double)m_size_hints.max_aspect_x / (double)m_size_hints.max_aspect_y < ratio) |
842 | return false; | 845 | return false; |
843 | 846 | ||
844 | return true; | 847 | return true; |