/* GTollina v0.1 (Codename: "Lorenzo nos va a hacer un Gazpacho en la GUADEC") * ("Lorenzo is going to cook a Gazpacho for us during GUADEC") * * Compile with: * gcc `pkg-config --libs --cflags gtk+-2.0 dbus-glib-1` gtollina.c -o gtollina */ #include #include #include #include #include enum { LEFT, RIGHT }; #define DEFAULT_PUSILAMINIDAD 7 #define POSITION_FILE "/sys/devices/platform/hdaps/position" void rotate (int direction) { DBusGConnection *bus; DBusGProxy *proxy; GError *error = NULL; bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); proxy = dbus_g_proxy_new_for_name (bus, "org.compiz.dbus", "/org/compiz/dbus/screen0", "org.compiz.rotate"); if (direction == LEFT) { dbus_g_proxy_call_no_reply (proxy, "rotateLeft", G_TYPE_INVALID); } else if (direction == RIGHT) { dbus_g_proxy_call_no_reply (proxy, "rotateRight", G_TYPE_INVALID); } } gboolean check_pos (gpointer data) { char buf[255]; size_t res; FILE *f; int current_x; int current_y; int pusilaminidad; static int x = 0; static int ignore_count = 0; if (ignore_count > 0) { ignore_count--; return TRUE; } pusilaminidad = GPOINTER_TO_INT (data); f = fopen (POSITION_FILE, "r"); if (f == NULL) return FALSE; res = fread (buf, 255, 1, f); fclose (f); sscanf (buf, "(%d,%d)", ¤t_x, ¤t_y); g_print ("%d,%d\n", current_x, current_y); if (x == 0) { x = current_x; } else { if (x - current_x > pusilaminidad) { ignore_count = 10; rotate (RIGHT); g_print ("X was %d, current X is %d, so going RIGHT\n", x, current_x); return TRUE; } if (current_x - x > pusilaminidad) { ignore_count = 10; rotate (LEFT); g_print ("X was %d, current X is %d, so going LEFT\n", x, current_x); return TRUE; } } return TRUE; } int main (int argc, char **argv) { int pusilaminidad; if (!g_file_test (POSITION_FILE, G_FILE_TEST_EXISTS)) { g_print ("No position detection suport!\n"); return -1; } if (argc == 2) { pusilaminidad = atoi (argv[1]); } else { pusilaminidad = DEFAULT_PUSILAMINIDAD; } gtk_init (&argc, &argv); g_timeout_add (100, check_pos, GINT_TO_POINTER (pusilaminidad)); gtk_main (); return 0; }