Automatically rotate image based on accelerometer values

Device orientation is provided by net.hadess.SensorProxy
iio-proxy-service. If there is no accelerometer on target platform,
then window orientation from X11/wayland is used as before.
This commit is contained in:
Andrey Skvortsov
2025-05-04 00:33:51 +03:00
parent b4b0a61230
commit 4db24ddc5e
8 changed files with 233 additions and 3 deletions

View File

@@ -4,6 +4,7 @@
#include "gl_util.h"
#include "io_pipeline.h"
#include "process_pipeline.h"
#include "rotation.h"
#include "state.h"
#include <asm/errno.h>
#include <assert.h>
@@ -120,6 +121,8 @@ update_io_pipeline()
.preview_width = state.preview_width,
.preview_height = state.preview_height,
.device_rotation = state.device_rotation,
.device_accel_rotation = state.device_accel_rotation,
.device_accel_rotation_good = state.device_accel_rotation_good,
.gain.control = state.gain.control,
.gain.auto_control = state.gain.auto_control,
@@ -1291,6 +1294,17 @@ xevent_handler(GdkDisplay *display, XEvent *xevent, gpointer data)
}
#endif // GDK_WINDOWING_X11
static void
rotation_sensor_handler(int rotation, bool good)
{
if (rotation != state.device_accel_rotation ||
good != state.device_accel_rotation_good) {
state.device_accel_rotation = rotation;
state.device_accel_rotation_good = good;
update_io_pipeline();
}
}
static void
activate(GtkApplication *app, gpointer data)
{
@@ -1472,6 +1486,7 @@ activate(GtkApplication *app, gpointer data)
GDBusConnection *conn =
g_application_get_dbus_connection(G_APPLICATION(app));
mp_flash_gtk_init(conn);
mp_device_rotation_init(rotation_sensor_handler);
if (state.configuration->count > 0) {
mp_io_pipeline_start();
@@ -1501,6 +1516,7 @@ shutdown(GApplication *app, gpointer data)
#ifdef DEBUG
mp_io_pipeline_stop();
mp_flash_gtk_clean();
mp_device_rotation_clean();
g_clear_object(&fb_settings);
g_clear_object(&capture_event);