From 8734a7ef2b7a9b79ad358e7e0169c1f407063849 Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Thu, 31 Oct 2024 16:52:10 +0100 Subject: [PATCH] Set Configuration.screenLayout depending on monitor geometry With this configuration, NewPipe enables tablet mode on larger screens. --- src/main-executable/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main-executable/main.c b/src/main-executable/main.c index ec36b370..7cad57fe 100644 --- a/src/main-executable/main.c +++ b/src/main-executable/main.c @@ -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