From b22053dadb0b4ecb72d38567f17a616030f3bc55 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 4 May 2021 00:34:52 +1000 Subject: [PATCH] UI rotation follows device --- data/camera.ui | 18 ++++++++++++------ src/main.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/data/camera.ui b/data/camera.ui index c3c8732..23dd058 100644 --- a/data/camera.ui +++ b/data/camera.ui @@ -31,7 +31,8 @@ 0 - horizontal + + 1 1 start 5 @@ -101,10 +102,13 @@ end - horizontal + 1 - end + 1 + center + center 5 + 5 5 5 5 @@ -141,10 +145,12 @@ - horizontal + 1 - end - end + 1 + center + center + 5 5 5 5 diff --git a/src/main.c b/src/main.c index 8458daa..947b651 100644 --- a/src/main.c +++ b/src/main.c @@ -746,6 +746,41 @@ create_simple_action(GtkApplication *app, const char *name, GCallback callback) return action; } +static void update_ui_rotation() +{ + if (device_rotation == 0 || device_rotation == 180) { + // Portrait + gtk_widget_set_halign(preview_top_box, GTK_ALIGN_FILL); + gtk_orientable_set_orientation(GTK_ORIENTABLE(preview_top_box), GTK_ORIENTATION_VERTICAL); + + gtk_widget_set_halign(preview_bottom_box, GTK_ALIGN_FILL); + gtk_orientable_set_orientation(GTK_ORIENTABLE(preview_bottom_box), GTK_ORIENTATION_HORIZONTAL); + + if (device_rotation == 0) { + gtk_widget_set_valign(preview_top_box, GTK_ALIGN_START); + gtk_widget_set_valign(preview_bottom_box, GTK_ALIGN_END); + } else { + gtk_widget_set_valign(preview_top_box, GTK_ALIGN_END); + gtk_widget_set_valign(preview_bottom_box, GTK_ALIGN_START); + } + } else { + // Landscape + gtk_widget_set_valign(preview_top_box, GTK_ALIGN_FILL); + gtk_orientable_set_orientation(GTK_ORIENTABLE(preview_top_box), GTK_ORIENTATION_HORIZONTAL); + + gtk_widget_set_valign(preview_bottom_box, GTK_ALIGN_FILL); + gtk_orientable_set_orientation(GTK_ORIENTABLE(preview_bottom_box), GTK_ORIENTATION_VERTICAL); + + if (device_rotation == 90) { + gtk_widget_set_halign(preview_top_box, GTK_ALIGN_END); + gtk_widget_set_halign(preview_bottom_box, GTK_ALIGN_START); + } else { + gtk_widget_set_halign(preview_top_box, GTK_ALIGN_START); + gtk_widget_set_halign(preview_bottom_box, GTK_ALIGN_END); + } + } +} + static void display_config_received(GDBusConnection *conn, GAsyncResult *res, gpointer user_data) { GError *error = NULL; @@ -771,6 +806,7 @@ static void display_config_received(GDBusConnection *conn, GAsyncResult *res, gp if (new_rotation != device_rotation) { device_rotation = new_rotation; update_io_pipeline(); + update_ui_rotation(); } }