2023-07-11 15:55:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "output_manager.h"
|
|
|
|
|
|
|
|
#include "accel_monitor.h"
|
|
|
|
|
|
|
|
static enum wl_output_transform const SENSOR_TO_OUTPUT_ROTATION[] = {
|
|
|
|
[ACCEL_ROTATION_0DEG] = WL_OUTPUT_TRANSFORM_270,
|
|
|
|
[ACCEL_ROTATION_90DEG] = WL_OUTPUT_TRANSFORM_NORMAL,
|
|
|
|
[ACCEL_ROTATION_180DEG] = WL_OUTPUT_TRANSFORM_90,
|
|
|
|
[ACCEL_ROTATION_270DEG] = WL_OUTPUT_TRANSFORM_180,
|
|
|
|
};
|
|
|
|
|
|
|
|
static char const* const DEFAULT_OUTPUT = "DSI-1";
|
|
|
|
static char const* const DEFAULT_MOTION_SENSOR =
|
|
|
|
"/sys/bus/iio/devices/iio:device0";
|
|
|
|
|
|
|
|
static enum accel_rotation last_accel_rotation = ACCEL_ROTATION_NO_CHANGE;
|
|
|
|
|
|
|
|
int main(int, char**)
|
|
|
|
{
|
2023-07-11 19:02:24 +00:00
|
|
|
struct accel_monitor* monitor = accel_start_monitor(DEFAULT_MOTION_SENSOR);
|
2023-07-11 15:55:43 +00:00
|
|
|
|
|
|
|
if (!monitor) {
|
|
|
|
fprintf(stderr, "Failed to start iio motion monitoring\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct miix_wlr_state* state = miix_wlr_init();
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!monitor->data_is_ready) continue;
|
|
|
|
|
|
|
|
enum accel_rotation rotation = accel_get_current_rotation(monitor);
|
2023-07-11 19:02:24 +00:00
|
|
|
if (rotation == ACCEL_ROTATION_NO_CHANGE ||
|
|
|
|
rotation == last_accel_rotation)
|
|
|
|
continue;
|
2023-07-11 15:55:43 +00:00
|
|
|
miix_wlr_head_set_transform(
|
|
|
|
state, DEFAULT_OUTPUT, SENSOR_TO_OUTPUT_ROTATION[rotation]);
|
|
|
|
last_accel_rotation = rotation;
|
|
|
|
}
|
|
|
|
|
2023-07-11 19:02:24 +00:00
|
|
|
accel_stop_monitor(monitor);
|
2023-07-11 15:55:43 +00:00
|
|
|
miix_wlr_cleanup(state);
|
|
|
|
}
|