Set Configuration.screenLayout depending on monitor geometry

With this configuration, NewPipe enables tablet mode on larger screens.
This commit is contained in:
Julian Winkler
2024-10-31 16:52:10 +01:00
parent 6068ac2eb8
commit 8734a7ef2b

View File

@@ -554,6 +554,15 @@ static void open(GtkApplication *app, GFile **files, gint nfiles, const gchar *h
if (GDK_IS_WAYLAND_TOPLEVEL(toplevel)) {
gdk_wayland_toplevel_set_application_id(GDK_WAYLAND_TOPLEVEL(toplevel), package_name);
}
GdkMonitor *monitor = gdk_display_get_monitor_at_surface(gdk_display_get_default(), GDK_SURFACE(toplevel));
GdkRectangle monitor_geometry;
gdk_monitor_get_geometry(monitor, &monitor_geometry);
jobject resources = _GET_STATIC_OBJ_FIELD(handle_cache.context.class, "r", "Landroid/content/res/Resources;");
jobject configuration = _GET_OBJ_FIELD(resources, "mConfiguration", "Landroid/content/res/Configuration;");
if (monitor_geometry.width >= 800 && monitor_geometry.height >= 800)
_SET_INT_FIELD(configuration, "screenLayout", /*SCREENLAYOUT_SIZE_LARGE*/ 0x03);
else
_SET_INT_FIELD(configuration, "screenLayout", /*SCREENLAYOUT_SIZE_NORMAL*/ 0x02);
if (app_icon_path) {
char *app_icon_path_full = malloc(strlen(app_data_dir) + 1 + strlen(app_icon_path) + 1); // +1 for /, +1 for NULL