Author: tgoettlicher
Date: Fri Jun 29 14:09:25 2007
New Revision: 5853
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5853&view=rev
Log:
program renamed
Added:
branches/tmp/tgoettlicher/usersaver/mindreader.c
Removed:
branches/tmp/tgoettlicher/usersaver/usersaver.c
Modified:
branches/tmp/tgoettlicher/usersaver/make
Modified: branches/tmp/tgoettlicher/usersaver/make
URL: http://svn.opensuse.org/viewcvs/zypp/branches/tmp/tgoettlicher/usersaver/make?rev=5853&r1=5852&r2=5853&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/usersaver/make (original)
+++ branches/tmp/tgoettlicher/usersaver/make Fri Jun 29 14:09:25 2007
@@ -1,2 +1,2 @@
- gcc -o usersaver usersaver.c net2/SNNS_NET.c -lX11 -lm
+ gcc -o mindreader mindreader.c net2/SNNS_NET.c -lX11 -lm
Added: branches/tmp/tgoettlicher/usersaver/mindreader.c
URL: http://svn.opensuse.org/viewcvs/zypp/branches/tmp/tgoettlicher/usersaver/mindreader.c?rev=5853&view=auto
==============================================================================
--- branches/tmp/tgoettlicher/usersaver/mindreader.c (added)
+++ branches/tmp/tgoettlicher/usersaver/mindreader.c Fri Jun 29 14:09:25 2007
@@ -0,0 +1,265 @@
+/*
+ * Compile: gcc -o mindreader mindreader.c -lX11 -lm
+ *
+ * Run: mindreader displayname:0
+ *
+ * Code borrowed from xkey.c
+ *
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "net2/SNNS_NET.h"
+//#include
+#include
+
+typedef struct {
+ int x;
+ int y;
+ int time;
+} MousePosition;
+
+typedef struct {
+ int keycode;
+ int time;
+} KeyStroke;
+
+
+
+
+void analyze();
+int analyzeKeyStrokes(int interval);
+void analyzeMouseMoves(int interval, int *x, int *y, int *a);
+void handleEvent(XEvent xev);
+Display *d;
+
+MousePosition mouseHistory[1000];
+int mouseHistoryMarker = 0;
+
+KeyStroke keyHistory[1000];
+int keyHistoryMarker = 0;
+
+
+
+static int ErrorHandler(Display *d, XErrorEvent *e)
+{
+ // do nothing;
+}
+
+
+
+void snoop_all_windows(Window root, unsigned long type)
+{
+ static int level = 0;
+ Window parent, *children, *child2;
+ unsigned int nchildren;
+ int stat, i,j,k;
+
+ level++;
+
+ stat = XQueryTree(d, root, &root, &parent, &children, &nchildren);
+ if (stat == FALSE)
+ return;
+
+ if (nchildren == 0)
+ return;
+
+ XSelectInput(d, root, type);
+
+ for(i=0; i < nchildren; i++)
+ {
+ XSelectInput(d, children[i], type);
+ snoop_all_windows(children[i], type);
+ }
+
+ XFree((char *)children);
+}
+
+
+int main(int argc, char **argv)
+{
+ char *hostname;
+ char *string;
+ XEvent xev;
+
+ if (argv[1] == NULL)
+ hostname = ":0";
+ else
+ hostname = argv[1];
+
+ d = XOpenDisplay(hostname);
+ if (d == NULL)
+ {
+ fprintf(stderr, "Can't open display: %s\n", hostname);
+ exit(10);
+ }
+
+
+ XSetErrorHandler(ErrorHandler);
+
+ while(1)
+ {
+ snoop_all_windows(DefaultRootWindow(d), KeyPressMask | PointerMotionMask );
+
+ while ( XCheckMaskEvent(d, KeyPressMask | PointerMotionMask, &xev) )
+ handleEvent(xev);
+
+ analyze();
+
+ }
+}
+
+void analyze()
+{
+ int x1, y1, x3, y3, x10, y10, a1, a3, a10;
+ int k1, k3, k10;
+ int i;
+ float max_emo=0;
+ int emo=0;
+ char *emos[]={ "idle","hectic", "thinking", "working" };
+
+
+ float input[6];
+ float output[4];
+
+ float width=2960.0, height=1050.0;
+
+ width = (float) DisplayWidth(d, DefaultScreen(d));
+ height = (float) DisplayHeight(d, DefaultScreen(d));
+
+ analyzeMouseMoves(1, &x1, &y1, &a1);
+ analyzeMouseMoves(3, &x3, &y3, &a3);
+ analyzeMouseMoves(10, &x10, &y10, &a10);
+
+ k1 = analyzeKeyStrokes(1);
+ k3 = analyzeKeyStrokes(3);
+ k10 = analyzeKeyStrokes(10);
+
+/*
+ printf("%f %f %f ", x1 / width , y1 / height , a1 / width / height);
+ printf("%f %f %f ", x3 / width , y3 / height , a3 / width / height);
+ printf("%f %f %f ", x10 / width , y10 / height , a10 / width / height);
+ printf("%f %f %f\n", k1/1000.0, k3/1000.0, k10/1000.0);
+*/
+
+ input[0]=x3/width;
+ input[1]=y3/height;
+ input[2]=x10/width;
+ input[3]=y10/height;
+ input[4]=k3/1000.0;
+ input[5]=k10/1000.0;
+
+ SNNS_NET ( input, output , 0);
+
+
+
+
+ for (i=0; i <4 ; ++i)
+ {
+ if (output[i] > max_emo)
+ {
+ max_emo=output[i];
+ emo=i;
+ }
+ }
+
+/* printf("%f %f %f %f %f %f\n", input[0], input[1], input[2], input[3], input[4], input[5]);
+ printf("0 0 0 1\n");
+ printf ("%f %f %f %f\n", output[0], output[1], output[2], output[3]); */
+ printf("%s\n",emos[emo]);
+
+ fflush(stdout);
+
+}
+
+
+int analyzeKeyStrokes(int interval)
+{
+ int k=0;
+ int now=time(0);
+ int i=0;
+
+ for (i=0; i<1000; ++i)
+ {
+ if (keyHistory[i].time >= now - interval)
+ k++;
+ }
+ return k;
+}
+
+
+
+void analyzeMouseMoves(int interval, int *x, int *y, int *a)
+{
+
+ int max_x=0, max_y=0;
+ int min_x=99999999, min_y=9999999; // why does MAX_INT not work
+ int i=0;
+ int now=time(0);
+
+ int delta_x = 0;
+ int delta_y = 0;
+ int delta_a = 0;
+
+ for (i=0; i<1000; ++i)
+ {
+ if (mouseHistory[i].time >= now - interval)
+ {
+ if (mouseHistory[i].x > max_x)
+ max_x = mouseHistory[i].x;
+ if (mouseHistory[i].y > max_y)
+ max_y = mouseHistory[i].y;
+ if (mouseHistory[i].x < min_x)
+ min_x = mouseHistory[i].x;
+ if (mouseHistory[i].y < min_y)
+ min_y = mouseHistory[i].y;
+ }
+ }
+
+ delta_x = max_x - min_x;
+ delta_y = max_y - min_y;
+
+ if (delta_x < 0) delta_x = 0;
+ if (delta_y < 0) delta_y = 0;
+
+
+ *x = delta_x;
+ *y = delta_y;
+ *a = delta_x* delta_y;
+
+
+
+}
+
+
+
+void handleEvent(XEvent xev)
+{
+ switch (xev.type)
+ {
+ case KeyPress:
+ keyHistory[keyHistoryMarker].keycode = xev.xkey.keycode;
+ keyHistory[keyHistoryMarker].time = time(0);
+
+ keyHistoryMarker++;
+ keyHistoryMarker%=1000;
+
+ break;
+
+ case MotionNotify:
+ mouseHistory[mouseHistoryMarker].x = xev.xkey.x_root;
+ mouseHistory[mouseHistoryMarker].y = xev.xkey.y_root;
+ mouseHistory[mouseHistoryMarker].time = time(0);
+
+ mouseHistoryMarker++;
+ mouseHistoryMarker%=1000;
+
+ break;
+ }
+}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org