46 lines
1.2 KiB
C
46 lines
1.2 KiB
C
|
#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**)
|
||
|
{
|
||
|
struct accel_monitor* monitor =
|
||
|
accel_start_monitor(DEFAULT_MOTION_SENSOR);
|
||
|
|
||
|
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);
|
||
|
if (rotation == ACCEL_ROTATION_NO_CHANGE || rotation == last_accel_rotation) continue;
|
||
|
miix_wlr_head_set_transform(
|
||
|
state, DEFAULT_OUTPUT, SENSOR_TO_OUTPUT_ROTATION[rotation]);
|
||
|
last_accel_rotation = rotation;
|
||
|
}
|
||
|
|
||
|
accel_stop_monitor(monitor);
|
||
|
miix_wlr_cleanup(state);
|
||
|
}
|