def resize_window(window: Gtk.Window, width: int, height: int) -> None: """ Resize window, but also checks if huge window or negative values """ screen_w, screen_h = get_total_screen_geometry() if not width or not height: return if width > screen_w: width = screen_w if height > screen_h: height = screen_h window.resize(abs(width), abs(height))
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)