Example #1
0
def resize_to_match_screen(window: Gtk.Window):
    '''Try to detect desktop or mobile screen, and resize to promote the horizontal or vertical layout.'''
    scale = window.get_scale_factor()
    best_horizontal_width = BEST_HORIZONTAL_WIDTH / scale
    best_vertical_height = BEST_VERTICAL_HEIGHT / scale
    sw, sh = get_monitor_screen(window)
    w, h = window.get_size()
    logger.debug('Current window size: {}', (w, h))
    if sw > best_horizontal_width:
        window.resize(best_horizontal_width, h)
    elif sh > best_vertical_height:
        window.resize(w, best_vertical_height)
Example #2
0
def move_window(window: Gtk.Window, pos_x: int, pos_y: int) -> None:
    """
    Move the window, but also check if out of screen
    """
    screen_w, screen_h = get_total_screen_geometry()
    if pos_x < 0:
        pos_x = 0
    if pos_y < 0:
        pos_y = 0
    width, height = window.get_size()
    if pos_x + width > screen_w:
        pos_x = screen_w - width
    if pos_y + height > screen_h:
        pos_y = screen_h - height
    window.move(pos_x, pos_y)