Example #1
0
    def _find_close_position(self, view, home,
                             app_rect, acc_rect, limit_rects,
                             test_clearance, move_clearance,
                             horizontal = True, vertical = True):
        rh = home
        move_clearance = Rect(10, 10, 10, 10)

        # Leave a different clearance for the new, yet to be found, positions.
        ra = acc_rect.apply_border(*move_clearance)
        rp = app_rect.apply_border(*move_clearance)

        # candidate positions
        vp = []
        if vertical:
            xc = acc_rect.get_center()[0] - rh.w / 2
            if app_rect.w > rh.w:
                xc = max(xc, app_rect.left())
                xc = min(xc, app_rect.right() - rh.w)

            # below window
            vp.append([xc, rp.bottom(), app_rect])

            # above window
            vp.append([xc, rp.top() - rh.h, app_rect])

            # inside maximized window, y at home.y
            vp.append([xc, home.y, acc_rect])
            # vp.append([xc, rp.bottom()-ymargin, app_rect.deflate(rh.h+move_clearance[3]+ymargin)])

            # below text entry
            vp.append([xc, ra.bottom(), acc_rect])

            # above text entry
            vp.append([xc, ra.top() - rh.h, acc_rect])

        # limited, non-intersecting candidate rectangles
        rresult = None
        for p in vp:
            pl = view.limit_position(p[0], p[1],
                                     view.canvas_rect,
                                     limit_rects)
            r = Rect(pl[0], pl[1], rh.w, rh.h)
            ri = p[2]
            rcs = [ri, acc_rect] # collision rects
            if not any(r.intersects(rc) for rc in rcs):
                rresult = r
                break

        if rresult is None:
            # try again, this time horizontally and vertically
            rhtmp = Rect(vp[0][0], vp[0][1], home.w, home.h)
            return self._find_non_occluding_position(view, home,
                                                acc_rect, limit_rects,
                                                test_clearance, move_clearance,
                                                horizontal, vertical)
        else:
            return rresult.get_position()
Example #2
0
    def _find_non_occluding_position(self,
                                     view,
                                     home,
                                     acc_rect,
                                     limit_rects,
                                     test_clearance,
                                     move_clearance,
                                     horizontal=True,
                                     vertical=True):
        rh = home

        # Leave some clearance around the accessible to account for
        # window frames and position errors of firefox entries.
        ra = acc_rect.apply_border(*test_clearance)

        if rh.intersects(ra):

            # Leave a different clearance for the new,
            # yet to be found positions.
            ra = acc_rect.apply_border(*move_clearance)
            x, y = rh.get_position()

            # candidate positions
            vp = []
            if horizontal:
                vp.append([ra.left() - rh.w, y])
                vp.append([ra.right(), y])
            if vertical:
                vp.append([x, ra.top() - rh.h])
                vp.append([x, ra.bottom()])

            # limited, non-intersecting candidate rectangles
            vr = []
            for p in vp:
                pl = view.limit_position(p[0], p[1], view.canvas_rect,
                                         limit_rects)
                r = Rect(pl[0], pl[1], rh.w, rh.h)
                if not r.intersects(ra):
                    vr.append(r)

            # candidate with smallest center-to-center distance wins
            chx, chy = rh.get_center()
            dmin = None
            rmin = None
            for r in vr:
                cx, cy = r.get_center()
                dx, dy = cx - chx, cy - chy
                d2 = dx * dx + dy * dy
                if dmin is None or dmin > d2:
                    dmin = d2
                    rmin = r

            if not rmin is None:
                return rmin.get_position()

        return None, None
Example #3
0
    def _find_non_occluding_position(self, view, home,
                                     acc_rect, limit_rects,
                                     test_clearance, move_clearance,
                                     horizontal = True, vertical = True):
        rh = home

        # Leave some clearance around the accessible to account for
        # window frames and position errors of firefox entries.
        ra = acc_rect.apply_border(*test_clearance)

        if rh.intersects(ra):

            # Leave a different clearance for the new, yet to be found, positions.
            ra = acc_rect.apply_border(*move_clearance)
            x, y = rh.get_position()

            # candidate positions
            vp = []
            if horizontal:
                vp.append([ra.left() - rh.w, y])
                vp.append([ra.right(), y])
            if vertical:
                vp.append([x, ra.top() - rh.h])
                vp.append([x, ra.bottom()])

            # limited, non-intersecting candidate rectangles
            vr = []
            for p in vp:
                pl = view.limit_position(p[0], p[1],
                                         view.canvas_rect,
                                         limit_rects)
                r = Rect(pl[0], pl[1], rh.w, rh.h)
                if not r.intersects(ra):
                    vr.append(r)

            # candidate with smallest center-to-center distance wins
            chx, chy = rh.get_center()
            dmin = None
            rmin = None
            for r in vr:
                cx, cy = r.get_center()
                dx, dy = cx - chx, cy - chy
                d2 = dx * dx + dy * dy
                if dmin is None or dmin > d2:
                    dmin = d2
                    rmin = r

            if not rmin is None:
                return rmin.get_position()

        return None, None
Example #4
0
    def _find_non_occluding_position(self, home, acc_rect,
                                     vertical = True, horizontal = True):

        # Leave some clearance around the accessible to account for
        # window frames and position errors of firefox entries.
        ra = acc_rect.apply_border(*config.auto_show.widget_clearance)
        rh = home

        if rh.intersects(ra):
            x, y = rh.get_position()

            # candidate positions
            vp = []
            if horizontal:
                vp.append([ra.left() - rh.w, y])
                vp.append([ra.right(), y])
            if vertical:
                vp.append([x, ra.top() - rh.h])
                vp.append([x, ra.bottom()])

            # limited, non-intersecting candidate rectangles
            vr = []
            for p in vp:
                pl = self._keyboard.limit_position( p[0], p[1],
                                                  self._keyboard.canvas_rect)
                r = Rect(pl[0], pl[1], rh.w, rh.h)
                chx, chy = rh.get_center()
                cx, cy = r.get_center()
                d2 = cx * chx + cy * chy
                if not r.intersects(ra):
                    vr.append(r)

            # candidate with smallest center-to-center distance wins
            chx, chy = rh.get_center()
            dmin = None
            rmin = None
            for r in vr:
                cx, cy = r.get_center()
                dx, dy = cx - chx, cy - chy
                d2 = dx * dx + dy * dy
                if dmin is None or dmin > d2:
                    dmin = d2
                    rmin = r

            if not rmin is None:
                return rmin.get_position()

        return None, None
Example #5
0
    def _find_close_position(self,
                             view,
                             home,
                             app_rect,
                             acc_rect,
                             limit_rects,
                             test_clearance,
                             move_clearance,
                             horizontal=True,
                             vertical=True):
        rh = home

        # Closer clearance for toplevels. There's usually nothing
        # that can be obscured.
        move_clearance_frame = Rect(10, 10, 10, 10)

        # Leave a different clearance for the new, yet to be found, positions.
        ra = acc_rect.apply_border(*move_clearance)
        if not app_rect.is_empty():
            rp = app_rect.apply_border(*move_clearance_frame)

        # candidate positions
        vp = []
        if vertical:
            xc = acc_rect.get_center()[0] - rh.w / 2
            if app_rect.w > rh.w:
                xc = max(xc, app_rect.left())
                xc = min(xc, app_rect.right() - rh.w)

            if not app_rect.is_empty():
                # below window
                vp.append([xc, rp.bottom(), app_rect])

                # above window
                vp.append([xc, rp.top() - rh.h, app_rect])

            # inside maximized window, y at home.y
            vp.append([xc, home.y, acc_rect])

            # below text entry
            vp.append([xc, ra.bottom(), acc_rect])

            # above text entry
            vp.append([xc, ra.top() - rh.h, acc_rect])

        # limited, non-intersecting candidate rectangles
        rresult = None
        for p in vp:
            pl = view.limit_position(p[0], p[1], view.canvas_rect, limit_rects)
            r = Rect(pl[0], pl[1], rh.w, rh.h)
            ri = p[2]
            rcs = [ri, acc_rect]  # collision rects
            if not any(r.intersects(rc) for rc in rcs):
                rresult = r
                break

        if rresult is None:
            # try again, this time horizontally and vertically
            rhtmp = Rect(vp[0][0], vp[0][1], home.w, home.h)
            return self._find_non_occluding_position(view, home, acc_rect,
                                                     limit_rects,
                                                     test_clearance,
                                                     move_clearance,
                                                     horizontal, vertical)
        else:
            return rresult.get_position()
    def _find_non_occluding_position(self,
                                     home,
                                     acc_rect,
                                     limit_rects,
                                     test_clearance,
                                     move_clearance,
                                     horizontal=True,
                                     vertical=True):

        # The home_rect doesn't include window decoration,
        # make sure to add decoration for correct clearance.
        rh = home.copy()
        window = self._keyboard_widget.get_kbd_window()
        if window:
            offset = window.get_client_offset()
            rh.w += offset[0]
            rh.h += offset[1]

        # Leave some clearance around the accessible to account for
        # window frames and position errors of firefox entries.
        ra = acc_rect.apply_border(*test_clearance)

        if rh.intersects(ra):

            # Leave a different clearance for the new to be found positions.
            ra = acc_rect.apply_border(*move_clearance)
            x, y = rh.get_position()

            # candidate positions
            vp = []
            if horizontal:
                vp.append([ra.left() - rh.w, y])
                vp.append([ra.right(), y])
            if vertical:
                vp.append([x, ra.top() - rh.h])
                vp.append([x, ra.bottom()])

            # limited, non-intersecting candidate rectangles
            vr = []
            for p in vp:
                pl = self._keyboard_widget.limit_position(
                    p[0], p[1], self._keyboard_widget.canvas_rect, limit_rects)
                r = Rect(pl[0], pl[1], rh.w, rh.h)
                if not r.intersects(ra):
                    vr.append(r)

            # candidate with smallest center-to-center distance wins
            chx, chy = rh.get_center()
            dmin = None
            rmin = None
            for r in vr:
                cx, cy = r.get_center()
                dx, dy = cx - chx, cy - chy
                d2 = dx * dx + dy * dy
                if dmin is None or dmin > d2:
                    dmin = d2
                    rmin = r

            if not rmin is None:
                return rmin.get_position()

        return None, None