aboutsummaryrefslogtreecommitdiff
path: root/src/WinClient.cc
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-08-15 11:04:56 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-08-15 11:04:56 (GMT)
commit4fa3773267362f8ca9f653bb8ee7c98baa09d5fd (patch)
treed77ee1cde06ab0b5d4a403f236aff4a51d418c89 /src/WinClient.cc
parent80059c6dae8de4962b14f08bd75f1c773e37a78d (diff)
downloadfluxbox_pavel-4fa3773267362f8ca9f653bb8ee7c98baa09d5fd.zip
fluxbox_pavel-4fa3773267362f8ca9f653bb8ee7c98baa09d5fd.tar.bz2
move size hint code to FbWinFrame
Diffstat (limited to 'src/WinClient.cc')
-rw-r--r--src/WinClient.cc132
1 files changed, 0 insertions, 132 deletions
diff --git a/src/WinClient.cc b/src/WinClient.cc
index 9aac38d..b9602ec 100644
--- a/src/WinClient.cc
+++ b/src/WinClient.cc
@@ -690,138 +690,6 @@ void WinClient::updateWMProtocols() {
690 690
691} 691}
692 692
693/* For aspect ratios
694 Note that its slightly simplified in that only the
695 line gradient is given - this is because for aspect
696 ratios, we always have the line going through the origin
697
698 * Based on this formula:
699 http://astronomy.swin.edu.au/~pbourke/geometry/pointline/
700
701 Note that a gradient from origin goes through ( grad , 1 )
702 */
703
704void closestPointToLine(double &ret_x, double &ret_y,
705 double point_x, double point_y,
706 double gradient) {
707 double u = (point_x * gradient + point_y) /
708 (gradient*gradient + 1);
709
710 ret_x = u*gradient;
711 ret_y = u;
712}
713
714/**
715 * Changes width and height to the nearest (lower) value
716 * that conforms to it's size hints.
717 *
718 * display_* give the values that would be displayed
719 * to the user when resizing.
720 * We use pointers for display_* since they are optional.
721 *
722 * See ICCCM section 4.1.2.3
723 */
724void WinClient::applySizeHints(int &width, int &height,
725 int *display_width, int *display_height,
726 bool maximizing) {
727
728 int i = width, j = height;
729
730 // Check minimum size
731 if (width < 0 || width < static_cast<signed>(m_size_hints.min_width))
732 width = m_size_hints.min_width;
733
734 if (height < 0 || height < static_cast<signed>(m_size_hints.min_height))
735 height = m_size_hints.min_height;
736
737 // Check maximum size
738 if (m_size_hints.max_width > 0 && width > static_cast<signed>(m_size_hints.max_width))
739 width = m_size_hints.max_width;
740
741 if (m_size_hints.max_height > 0 && height > static_cast<signed>(m_size_hints.max_height))
742 height = m_size_hints.max_height;
743
744 // we apply aspect ratios before incrementals
745 // Too difficult to exactly satisfy both incremental+aspect
746 // in most situations
747 // (they really shouldn't happen at the same time anyway).
748
749 /* aspect ratios are applied exclusive to the m_size_hints.base_width
750 *
751 * m_size_hints.min_aspect_x width m_size_hints.max_aspect_x
752 * ------------ < ------- < ------------
753 * m_size_hints.min_aspect_y height m_size_hints.max_aspect_y
754 *
755 * beware of integer maximum (so I'll use doubles instead and divide)
756 *
757 * The trick is how to get back to the aspect ratio with minimal
758 * change - do we modify x, y or both?
759 * A: we minimise the distance between the current point, and
760 * the target aspect ratio (consider them as x,y coordinates)
761 * Consider that the aspect ratio is a line, and the current
762 * w/h is a point, so we're just using the formula for
763 * shortest distance from a point to a line!
764 *
765 * When maximizing, we must not increase any of the sizes, because we
766 * would end up with the window partly off a screen, so a simpler formula
767 * is used in that case.
768 */
769
770 if (m_size_hints.min_aspect_y > 0 && m_size_hints.max_aspect_y > 0 &&
771 (height - m_size_hints.base_height) > 0) {
772 double widthd = static_cast<double>(width - m_size_hints.base_width);
773 double heightd = static_cast<double>(height - m_size_hints.base_height);
774
775 double min = static_cast<double>(m_size_hints.min_aspect_x) /
776 static_cast<double>(m_size_hints.min_aspect_y);
777
778 double max = static_cast<double>(m_size_hints.max_aspect_x) /
779 static_cast<double>(m_size_hints.max_aspect_y);
780
781 double actual = widthd / heightd;
782
783 if (max > 0 && min > 0 && actual > 0) { // don't even try otherwise
784 bool changed = false;
785 if (actual < min) {
786 changed = true;
787 if (maximizing)
788 heightd = widthd / min;
789 else
790 closestPointToLine(widthd, heightd, widthd, heightd, min);
791 } else if (actual > max) {
792 changed = true;
793 if (maximizing)
794 widthd = heightd * max;
795 else
796 closestPointToLine(widthd, heightd, widthd, heightd, max);
797 }
798
799 if (changed) {
800 width = static_cast<int>(widthd) + m_size_hints.base_width;
801 height = static_cast<int>(heightd) + m_size_hints.base_height;
802 }
803 }
804 }
805
806 // enforce incremental size limits, wrt base size
807 // only calculate this if we really need to
808 i = (width - static_cast<signed>(m_size_hints.base_width)) /
809 static_cast<signed>(m_size_hints.width_inc);
810 width = i*static_cast<signed>(m_size_hints.width_inc) +
811 static_cast<signed>(m_size_hints.base_width);
812
813 j = (height - static_cast<signed>(m_size_hints.base_height)) /
814 static_cast<signed>(m_size_hints.height_inc);
815 height = j*static_cast<signed>(m_size_hints.height_inc) +
816 static_cast<signed>(m_size_hints.base_height);
817
818 if (display_width)
819 *display_width = i;
820
821 if (display_height)
822 *display_height = j;
823}
824
825// check if the given width and height satisfy the size hints 693// check if the given width and height satisfy the size hints
826bool WinClient::checkSizeHints(unsigned int width, unsigned int height) { 694bool WinClient::checkSizeHints(unsigned int width, unsigned int height) {
827 if (width < m_size_hints.min_width || height < m_size_hints.min_height) 695 if (width < m_size_hints.min_width || height < m_size_hints.min_height)