680 struct SizeRect { |
680 struct SizeRect { |
681 int left,top,width,height; |
681 int left,top,width,height; |
682 }; |
682 }; |
683 |
683 |
684 |
684 |
685 static SizeRect _awap_r; |
685 static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos) |
686 |
686 { |
687 static bool IsGoodAutoPlace1(int left, int top) |
687 Window* const *wz; |
688 { |
688 |
689 int right,bottom; |
689 int right = width + left; |
690 Window* const *wz; |
690 int bottom = height + top; |
691 |
|
692 _awap_r.left= left; |
|
693 _awap_r.top = top; |
|
694 right = _awap_r.width + left; |
|
695 bottom = _awap_r.height + top; |
|
696 |
691 |
697 if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) |
692 if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) |
698 return false; |
693 return false; |
699 |
694 |
700 /* Make sure it is not obscured by any window. */ |
695 /* Make sure it is not obscured by any window. */ |
737 w->top + w->height > top) { |
728 w->top + w->height > top) { |
738 return false; |
729 return false; |
739 } |
730 } |
740 } |
731 } |
741 |
732 |
|
733 pos.x = left; |
|
734 pos.y = top; |
742 return true; |
735 return true; |
743 } |
736 } |
744 |
737 |
745 static Point GetAutoPlacePosition(int width, int height) |
738 static Point GetAutoPlacePosition(int width, int height) |
746 { |
739 { |
747 Window* const *wz; |
740 Window* const *wz; |
748 Point pt; |
741 Point pt; |
749 |
742 |
750 _awap_r.width = width; |
743 if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt; |
751 _awap_r.height = height; |
|
752 |
|
753 if (IsGoodAutoPlace1(0, 24)) goto ok_pos; |
|
754 |
744 |
755 FOR_ALL_WINDOWS(wz) { |
745 FOR_ALL_WINDOWS(wz) { |
756 const Window *w = *wz; |
746 const Window *w = *wz; |
757 if (w->window_class == WC_MAIN_WINDOW) continue; |
747 if (w->window_class == WC_MAIN_WINDOW) continue; |
758 |
748 |
759 if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos; |
749 if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt; |
760 if (IsGoodAutoPlace1(w->left- width-2,w->top)) goto ok_pos; |
750 if (IsGoodAutoPlace1(w->left - width - 2, w->top, width, height, pt)) return pt; |
761 if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos; |
751 if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt; |
762 if (IsGoodAutoPlace1(w->left,w->top- height-2)) goto ok_pos; |
752 if (IsGoodAutoPlace1(w->left, w->top - height - 2, width, height, pt)) return pt; |
763 if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos; |
753 if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pt)) return pt; |
764 if (IsGoodAutoPlace1(w->left- width-2,w->top+w->height-height)) goto ok_pos; |
754 if (IsGoodAutoPlace1(w->left - width - 2, w->top + w->height - height, width, height, pt)) return pt; |
765 if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos; |
755 if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pt)) return pt; |
766 if (IsGoodAutoPlace1(w->left+w->width-width,w->top- height-2)) goto ok_pos; |
756 if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height - 2, width, height, pt)) return pt; |
767 } |
757 } |
768 |
758 |
769 FOR_ALL_WINDOWS(wz) { |
759 FOR_ALL_WINDOWS(wz) { |
770 const Window *w = *wz; |
760 const Window *w = *wz; |
771 if (w->window_class == WC_MAIN_WINDOW) continue; |
761 if (w->window_class == WC_MAIN_WINDOW) continue; |
772 |
762 |
773 if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos; |
763 if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt; |
774 if (IsGoodAutoPlace2(w->left- width-2,w->top)) goto ok_pos; |
764 if (IsGoodAutoPlace2(w->left - width - 2, w->top, width, height, pt)) return pt; |
775 if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos; |
765 if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt; |
776 if (IsGoodAutoPlace2(w->left,w->top- height-2)) goto ok_pos; |
766 if (IsGoodAutoPlace2(w->left, w->top - height - 2, width, height, pt)) return pt; |
777 } |
767 } |
778 |
768 |
779 { |
769 { |
780 int left=0,top=24; |
770 int left = 0, top = 24; |
781 |
771 |
782 restart:; |
772 restart: |
783 FOR_ALL_WINDOWS(wz) { |
773 FOR_ALL_WINDOWS(wz) { |
784 const Window *w = *wz; |
774 const Window *w = *wz; |
785 |
775 |
786 if (w->left == left && w->top == top) { |
776 if (w->left == left && w->top == top) { |
787 left += 5; |
777 left += 5; |
1631 x -= vp->left; |
1616 x -= vp->left; |
1632 y -= vp->top; |
1617 y -= vp->top; |
1633 /* here allows scrolling in both x and y axis */ |
1618 /* here allows scrolling in both x and y axis */ |
1634 #define scrollspeed 3 |
1619 #define scrollspeed 3 |
1635 if (x - 15 < 0) { |
1620 if (x - 15 < 0) { |
1636 WP(w, vp_d).scrollpos_x += (x - 15) * scrollspeed << vp->zoom; |
1621 WP(w, vp_d).scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom); |
1637 } else if (15 - (vp->width - x) > 0) { |
1622 } else if (15 - (vp->width - x) > 0) { |
1638 WP(w, vp_d).scrollpos_x += (15 - (vp->width - x)) * scrollspeed << vp->zoom; |
1623 WP(w, vp_d).scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom); |
1639 } |
1624 } |
1640 if (y - 15 < 0) { |
1625 if (y - 15 < 0) { |
1641 WP(w, vp_d).scrollpos_y += (y - 15) * scrollspeed << vp->zoom; |
1626 WP(w, vp_d).scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom); |
1642 } else if (15 - (vp->height - y) > 0) { |
1627 } else if (15 - (vp->height - y) > 0) { |
1643 WP(w,vp_d).scrollpos_y += (15 - (vp->height - y)) * scrollspeed << vp->zoom; |
1628 WP(w,vp_d).scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom); |
1644 } |
1629 } |
1645 #undef scrollspeed |
1630 #undef scrollspeed |
1646 } |
1631 } |
1647 } |
1632 } |
1648 } |
1633 } |
1983 |
1968 |
1984 if (w->window_class == WC_MAIN_WINDOW) { |
1969 if (w->window_class == WC_MAIN_WINDOW) { |
1985 ViewPort *vp = w->viewport; |
1970 ViewPort *vp = w->viewport; |
1986 vp->width = w->width = neww; |
1971 vp->width = w->width = neww; |
1987 vp->height = w->height = newh; |
1972 vp->height = w->height = newh; |
1988 vp->virtual_width = neww << vp->zoom; |
1973 vp->virtual_width = ScaleByZoom(neww, vp->zoom); |
1989 vp->virtual_height = newh << vp->zoom; |
1974 vp->virtual_height = ScaleByZoom(newh, vp->zoom); |
1990 continue; // don't modify top,left |
1975 continue; // don't modify top,left |
1991 } |
1976 } |
1992 |
1977 |
1993 /* XXX - this probably needs something more sane. For example specying |
1978 /* XXX - this probably needs something more sane. For example specying |
1994 * in a 'backup'-desc that the window should always be centred. */ |
1979 * in a 'backup'-desc that the window should always be centred. */ |