void disp(void);\r
void reshape(int x, int y);\r
void keyb(unsigned char key, int x, int y);\r
-void sbmot(int x, int y, int z); /* spaceball translation */\r
-void sbrot(int x, int y, int z); /* spaceball rotation */\r
-void sbbut(int bn, int state); /* spaceball button */\r
+void sbmot(int x, int y, int z); /* spaceball translation */\r
+void sbrot(int x, int y, int z); /* spaceball rotation */\r
+void sbbut(int bn, int state); /* spaceball button */\r
\r
vec3_t pos = {0, 0, -6};\r
quat_t rot = {0, 0, 0, 1};\r
\r
int main(int argc, char **argv)\r
{\r
- glutInit(&argc, argv);\r
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);\r
- glutCreateWindow("spaceball demo");\r
+ glutInit(&argc, argv);\r
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);\r
+ glutCreateWindow("spaceball demo");\r
\r
- glutDisplayFunc(disp);\r
- glutReshapeFunc(reshape);\r
- glutKeyboardFunc(keyb);\r
- glutSpaceballMotionFunc(sbmot);\r
- glutSpaceballRotateFunc(sbrot);\r
- glutSpaceballButtonFunc(sbbut);\r
+ glutDisplayFunc(disp);\r
+ glutReshapeFunc(reshape);\r
+ glutKeyboardFunc(keyb);\r
+ glutSpaceballMotionFunc(sbmot);\r
+ glutSpaceballRotateFunc(sbrot);\r
+ glutSpaceballButtonFunc(sbbut);\r
\r
- glEnable(GL_CULL_FACE);\r
+ glEnable(GL_CULL_FACE);\r
\r
- glutMainLoop();\r
- return 0;\r
+ glutMainLoop();\r
+ return 0;\r
}\r
\r
void disp(void)\r
{\r
- mat4_t xform;\r
+ mat4_t xform;\r
\r
- quat_to_mat(xform, rot);\r
+ quat_to_mat(xform, rot);\r
\r
- glClear(GL_COLOR_BUFFER_BIT);\r
+ glClear(GL_COLOR_BUFFER_BIT);\r
\r
- glMatrixMode(GL_MODELVIEW);\r
- glLoadIdentity();\r
- glTranslatef(pos.x, pos.y, pos.z);\r
- glMultTransposeMatrixf((float*)xform);\r
+ glMatrixMode(GL_MODELVIEW);\r
+ glLoadIdentity();\r
+ glTranslatef(pos.x, pos.y, pos.z);\r
+ glMultTransposeMatrixf((float*)xform);\r
\r
- draw_cube();\r
+ draw_cube();\r
\r
- glutSwapBuffers();\r
+ glutSwapBuffers();\r
}\r
\r
void draw_cube(void)\r
{\r
- glBegin(GL_QUADS);\r
- /* face +Z */\r
- glNormal3f(0, 0, 1);\r
- glColor3f(1, 0, 0);\r
- glVertex3f(-1, -1, 1);\r
- glVertex3f(1, -1, 1);\r
- glVertex3f(1, 1, 1);\r
- glVertex3f(-1, 1, 1);\r
- /* face +X */\r
- glNormal3f(1, 0, 0);\r
- glColor3f(0, 1, 0);\r
- glVertex3f(1, -1, 1);\r
- glVertex3f(1, -1, -1);\r
- glVertex3f(1, 1, -1);\r
- glVertex3f(1, 1, 1);\r
- /* face -Z */\r
- glNormal3f(0, 0, -1);\r
- glColor3f(0, 0, 1);\r
- glVertex3f(1, -1, -1);\r
- glVertex3f(-1, -1, -1);\r
- glVertex3f(-1, 1, -1);\r
- glVertex3f(1, 1, -1);\r
- /* face -X */\r
- glNormal3f(-1, 0, 0);\r
- glColor3f(1, 1, 0);\r
- glVertex3f(-1, -1, -1);\r
- glVertex3f(-1, -1, 1);\r
- glVertex3f(-1, 1, 1);\r
- glVertex3f(-1, 1, -1);\r
- /* face +Y */\r
- glNormal3f(0, 1, 0);\r
- glColor3f(0, 1, 1);\r
- glVertex3f(-1, 1, 1);\r
- glVertex3f(1, 1, 1);\r
- glVertex3f(1, 1, -1);\r
- glVertex3f(-1, 1, -1);\r
- /* face -Y */\r
- glNormal3f(0, -1, 0);\r
- glColor3f(1, 0, 1);\r
- glVertex3f(-1, -1, -1);\r
- glVertex3f(1, -1, -1);\r
- glVertex3f(1, -1, 1);\r
- glVertex3f(-1, -1, 1);\r
- glEnd();\r
+ glBegin(GL_QUADS);\r
+ /* face +Z */\r
+ glNormal3f(0, 0, 1);\r
+ glColor3f(1, 0, 0);\r
+ glVertex3f(-1, -1, 1);\r
+ glVertex3f(1, -1, 1);\r
+ glVertex3f(1, 1, 1);\r
+ glVertex3f(-1, 1, 1);\r
+ /* face +X */\r
+ glNormal3f(1, 0, 0);\r
+ glColor3f(0, 1, 0);\r
+ glVertex3f(1, -1, 1);\r
+ glVertex3f(1, -1, -1);\r
+ glVertex3f(1, 1, -1);\r
+ glVertex3f(1, 1, 1);\r
+ /* face -Z */\r
+ glNormal3f(0, 0, -1);\r
+ glColor3f(0, 0, 1);\r
+ glVertex3f(1, -1, -1);\r
+ glVertex3f(-1, -1, -1);\r
+ glVertex3f(-1, 1, -1);\r
+ glVertex3f(1, 1, -1);\r
+ /* face -X */\r
+ glNormal3f(-1, 0, 0);\r
+ glColor3f(1, 1, 0);\r
+ glVertex3f(-1, -1, -1);\r
+ glVertex3f(-1, -1, 1);\r
+ glVertex3f(-1, 1, 1);\r
+ glVertex3f(-1, 1, -1);\r
+ /* face +Y */\r
+ glNormal3f(0, 1, 0);\r
+ glColor3f(0, 1, 1);\r
+ glVertex3f(-1, 1, 1);\r
+ glVertex3f(1, 1, 1);\r
+ glVertex3f(1, 1, -1);\r
+ glVertex3f(-1, 1, -1);\r
+ /* face -Y */\r
+ glNormal3f(0, -1, 0);\r
+ glColor3f(1, 0, 1);\r
+ glVertex3f(-1, -1, -1);\r
+ glVertex3f(1, -1, -1);\r
+ glVertex3f(1, -1, 1);\r
+ glVertex3f(-1, -1, 1);\r
+ glEnd();\r
}\r
\r
/* 45deg fov */\r
-#define FOV (M_PI / 4.0)\r
+#define FOV (M_PI / 4.0)\r
\r
void reshape(int x, int y)\r
{\r
- float aspect = (float)x / (float)y;\r
- float halfy = tan(FOV / 2.0);\r
- float halfx = halfy * aspect;\r
+ float aspect = (float)x / (float)y;\r
+ float halfy = tan(FOV / 2.0);\r
+ float halfx = halfy * aspect;\r
\r
- glViewport(0, 0, x, y);\r
+ glViewport(0, 0, x, y);\r
\r
- glMatrixMode(GL_PROJECTION);\r
- glLoadIdentity();\r
- glFrustum(-halfx, halfx, -halfy, halfy, 1.0, 1000.0);\r
+ glMatrixMode(GL_PROJECTION);\r
+ glLoadIdentity();\r
+ glFrustum(-halfx, halfx, -halfy, halfy, 1.0, 1000.0);\r
}\r
\r
void keyb(unsigned char key, int x, int y)\r
{\r
- switch(key) {\r
- case 'q':\r
- case 'Q':\r
- case 27:\r
- exit(0);\r
-\r
- case ' ':\r
- /* reset initial view */\r
- pos = v3_cons(0, 0, -6);\r
- rot = quat_cons(1, 0, 0, 0);\r
- glutPostRedisplay();\r
-\r
- default:\r
- break;\r
- }\r
+ switch(key) {\r
+ case 'q':\r
+ case 'Q':\r
+ case 27:\r
+ exit(0);\r
+\r
+ case ' ':\r
+ /* reset initial view */\r
+ pos = v3_cons(0, 0, -6);\r
+ rot = quat_cons(1, 0, 0, 0);\r
+ glutPostRedisplay();\r
+\r
+ default:\r
+ break;\r
+ }\r
}\r
\r
void sbmot(int x, int y, int z)\r
{\r
- pos.x += x * 0.001;\r
- pos.y += y * 0.001;\r
- pos.z -= z * 0.001;\r
- glutPostRedisplay();\r
+ pos.x += x * 0.001;\r
+ pos.y += y * 0.001;\r
+ pos.z -= z * 0.001;\r
+ glutPostRedisplay();\r
}\r
\r
void sbrot(int x, int y, int z)\r
{\r
- float axis_len = sqrt(x * x + y * y + z * z);\r
- rot = quat_rotate(rot, axis_len * 0.001, -x / axis_len, -y / axis_len, z / axis_len);\r
- glutPostRedisplay();\r
+ float axis_len = sqrt(x * x + y * y + z * z);\r
+ rot = quat_rotate(rot, axis_len * 0.001, -x / axis_len, -y / axis_len, z / axis_len);\r
+ glutPostRedisplay();\r
}\r
\r
void sbbut(int bn, int state)\r
{\r
- if(state == GLUT_DOWN) {\r
- pos = v3_cons(0, 0, -6);\r
- rot = quat_cons(1, 0, 0, 0);\r
- glutPostRedisplay();\r
- }\r
+ if(state == GLUT_DOWN) {\r
+ pos = v3_cons(0, 0, -6);\r
+ rot = quat_cons(1, 0, 0, 0);\r
+ glutPostRedisplay();\r
+ }\r
}\r
\r
quat_t quat_rotate(quat_t q, float angle, float x, float y, float z)\r
{\r
- quat_t rq;\r
- float half_angle = angle * 0.5;\r
- float sin_half = sin(half_angle);\r
+ quat_t rq;\r
+ float half_angle = angle * 0.5;\r
+ float sin_half = sin(half_angle);\r
\r
- rq.w = cos(half_angle);\r
- rq.x = x * sin_half;\r
- rq.y = y * sin_half;\r
- rq.z = z * sin_half;\r
+ rq.w = cos(half_angle);\r
+ rq.x = x * sin_half;\r
+ rq.y = y * sin_half;\r
+ rq.z = z * sin_half;\r
\r
- return quat_mul(q, rq);\r
+ return quat_mul(q, rq);\r
}\r
\r
/* matrix functions */\r
static inline void m4_cons(mat4_t m,\r
- float m11, float m12, float m13, float m14,\r
- float m21, float m22, float m23, float m24,\r
- float m31, float m32, float m33, float m34,\r
- float m41, float m42, float m43, float m44);\r
+ float m11, float m12, float m13, float m14,\r
+ float m21, float m22, float m23, float m24,\r
+ float m31, float m32, float m33, float m34,\r
+ float m41, float m42, float m43, float m44);\r
\r
#include "vmath.inl"\r
\r
-#endif /* VMATH_H_ */\r
+#endif /* VMATH_H_ */\r
/* vector functions */\r
static inline vec3_t v3_cons(float x, float y, float z)\r
{\r
- vec3_t res;\r
- res.x = x;\r
- res.y = y;\r
- res.z = z;\r
- return res;\r
+ vec3_t res;\r
+ res.x = x;\r
+ res.y = y;\r
+ res.z = z;\r
+ return res;\r
}\r
\r
static inline vec3_t quat_vec(quat_t q)\r
{\r
- vec3_t v;\r
- v.x = q.x;\r
- v.y = q.y;\r
- v.z = q.z;\r
- return v;\r
+ vec3_t v;\r
+ v.x = q.x;\r
+ v.y = q.y;\r
+ v.z = q.z;\r
+ return v;\r
}\r
\r
static inline float v3_dot(vec3_t v1, vec3_t v2)\r
{\r
- return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;\r
+ return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;\r
}\r
\r
/* quaternion functions */\r
static inline quat_t quat_cons(float s, float x, float y, float z)\r
{\r
- quat_t q;\r
- q.x = x;\r
- q.y = y;\r
- q.z = z;\r
- q.w = s;\r
- return q;\r
+ quat_t q;\r
+ q.x = x;\r
+ q.y = y;\r
+ q.z = z;\r
+ q.w = s;\r
+ return q;\r
}\r
\r
static inline quat_t quat_mul(quat_t q1, quat_t q2)\r
{\r
- quat_t res;\r
- vec3_t v1 = quat_vec(q1);\r
- vec3_t v2 = quat_vec(q2);\r
+ quat_t res;\r
+ vec3_t v1 = quat_vec(q1);\r
+ vec3_t v2 = quat_vec(q2);\r
\r
- res.w = q1.w * q2.w - v3_dot(v1, v2);\r
- res.x = v2.x * q1.w + v1.x * q2.w + (v1.y * v2.z - v1.z * v2.y);\r
- res.y = v2.y * q1.w + v1.y * q2.w + (v1.z * v2.x - v1.x * v2.z);\r
- res.z = v2.z * q1.w + v1.z * q2.w + (v1.x * v2.y - v1.y * v2.x);\r
- return res;\r
+ res.w = q1.w * q2.w - v3_dot(v1, v2);\r
+ res.x = v2.x * q1.w + v1.x * q2.w + (v1.y * v2.z - v1.z * v2.y);\r
+ res.y = v2.y * q1.w + v1.y * q2.w + (v1.z * v2.x - v1.x * v2.z);\r
+ res.z = v2.z * q1.w + v1.z * q2.w + (v1.x * v2.y - v1.y * v2.x);\r
+ return res;\r
}\r
\r
static inline void quat_to_mat(mat4_t res, quat_t q)\r
{\r
- m4_cons(res, 1.0 - 2.0 * q.y*q.y - 2.0 * q.z*q.z, 2.0 * q.x * q.y + 2.0 * q.w * q.z, 2.0 * q.z * q.x - 2.0 * q.w * q.y, 0,\r
- 2.0 * q.x * q.y - 2.0 * q.w * q.z, 1.0 - 2.0 * q.x*q.x - 2.0 * q.z*q.z, 2.0 * q.y * q.z + 2.0 * q.w * q.x, 0,\r
- 2.0 * q.z * q.x + 2.0 * q.w * q.y, 2.0 * q.y * q.z - 2.0 * q.w * q.x, 1.0 - 2.0 * q.x*q.x - 2.0 * q.y*q.y, 0,\r
- 0, 0, 0, 1);\r
+ m4_cons(res, 1.0 - 2.0 * q.y*q.y - 2.0 * q.z*q.z, 2.0 * q.x * q.y + 2.0 * q.w * q.z, 2.0 * q.z * q.x - 2.0 * q.w * q.y, 0,\r
+ 2.0 * q.x * q.y - 2.0 * q.w * q.z, 1.0 - 2.0 * q.x*q.x - 2.0 * q.z*q.z, 2.0 * q.y * q.z + 2.0 * q.w * q.x, 0,\r
+ 2.0 * q.z * q.x + 2.0 * q.w * q.y, 2.0 * q.y * q.z - 2.0 * q.w * q.x, 1.0 - 2.0 * q.x*q.x - 2.0 * q.y*q.y, 0,\r
+ 0, 0, 0, 1);\r
}\r
\r
/* matrix functions */\r
static inline void m4_cons(mat4_t m,\r
- float m11, float m12, float m13, float m14,\r
- float m21, float m22, float m23, float m24,\r
- float m31, float m32, float m33, float m34,\r
- float m41, float m42, float m43, float m44)\r
+ float m11, float m12, float m13, float m14,\r
+ float m21, float m22, float m23, float m24,\r
+ float m31, float m32, float m33, float m34,\r
+ float m41, float m42, float m43, float m44)\r
{\r
- m[0][0] = m11; m[0][1] = m12; m[0][2] = m13; m[0][3] = m14;\r
- m[1][0] = m21; m[1][1] = m22; m[1][2] = m23; m[1][3] = m24;\r
- m[2][0] = m31; m[2][1] = m32; m[2][2] = m33; m[2][3] = m34;\r
- m[3][0] = m41; m[3][1] = m42; m[3][2] = m43; m[3][3] = m44;\r
+ m[0][0] = m11; m[0][1] = m12; m[0][2] = m13; m[0][3] = m14;\r
+ m[1][0] = m21; m[1][1] = m22; m[1][2] = m23; m[1][3] = m24;\r
+ m[2][0] = m31; m[2][1] = m32; m[2][2] = m33; m[2][3] = m34;\r
+ m[3][0] = m41; m[3][1] = m42; m[3][2] = m43; m[3][3] = m44;\r
}\r
#include <X11/Xlib.h>\r
\r
enum {\r
- SPNAV_EVENT_ANY, /* used by spnav_remove_events() */\r
+ SPNAV_EVENT_ANY, /* used by spnav_remove_events() */\r
SPNAV_EVENT_MOTION,\r
- SPNAV_EVENT_BUTTON /* includes both press and release */\r
+ SPNAV_EVENT_BUTTON /* includes both press and release */\r
};\r
\r
struct spnav_event_motion {\r
#if TARGET_HOST_POSIX_X11\r
{\r
Window w;\r
- \r
+\r
if(!fgStructure.CurrentWindow)\r
return;\r
\r
}\r
\r
#if TARGET_HOST_POSIX_X11\r
- return 2; /* TODO implement this properly */\r
+ return 2; /* TODO implement this properly */\r
#else\r
return 0;\r
#endif\r
INVOKE_WCB(*spnav_win, SpaceMotion, (sev.motion.x, sev.motion.y, sev.motion.z));\r
}\r
if(sev.motion.rx | sev.motion.ry | sev.motion.rz) {\r
- INVOKE_WCB(*spnav_win, SpaceRotation, (sev.motion.rx, sev.motion.ry, sev.motion.rz));\r
+ INVOKE_WCB(*spnav_win, SpaceRotation, (sev.motion.rx, sev.motion.ry, sev.motion.rz));\r
}\r
spnav_remove_events(SPNAV_EVENT_MOTION);\r
break;\r
static Atom motion_event, button_press_event, button_release_event, command_event;\r
\r
enum {\r
- CMD_APP_WINDOW = 27695,\r
- CMD_APP_SENS\r
+ CMD_APP_WINDOW = 27695,\r
+ CMD_APP_SENS\r
};\r
\r
-#define IS_OPEN dpy\r
+#define IS_OPEN dpy\r
\r
struct event_node {\r
- spnav_event event;\r
- struct event_node *next;\r
+ spnav_event event;\r
+ struct event_node *next;\r
};\r
\r
static int spnav_x11_open(Display *display, Window win)\r
{\r
- if(IS_OPEN) {\r
- return -1;\r
- }\r
+ if(IS_OPEN) {\r
+ return -1;\r
+ }\r
\r
- dpy = display;\r
+ dpy = display;\r
\r
- motion_event = XInternAtom(dpy, "MotionEvent", True);\r
- button_press_event = XInternAtom(dpy, "ButtonPressEvent", True);\r
- button_release_event = XInternAtom(dpy, "ButtonReleaseEvent", True);\r
- command_event = XInternAtom(dpy, "CommandEvent", True);\r
+ motion_event = XInternAtom(dpy, "MotionEvent", True);\r
+ button_press_event = XInternAtom(dpy, "ButtonPressEvent", True);\r
+ button_release_event = XInternAtom(dpy, "ButtonReleaseEvent", True);\r
+ command_event = XInternAtom(dpy, "CommandEvent", True);\r
\r
- if(!motion_event || !button_press_event || !button_release_event || !command_event) {\r
- dpy = 0;\r
- return -1; /* daemon not started */\r
- }\r
+ if(!motion_event || !button_press_event || !button_release_event || !command_event) {\r
+ dpy = 0;\r
+ return -1; /* daemon not started */\r
+ }\r
\r
- if(spnav_x11_window(win) == -1) {\r
- dpy = 0;\r
- return -1; /* daemon not started */\r
- }\r
+ if(spnav_x11_window(win) == -1) {\r
+ dpy = 0;\r
+ return -1; /* daemon not started */\r
+ }\r
\r
- app_win = win;\r
- return 0;\r
+ app_win = win;\r
+ return 0;\r
}\r
\r
static int spnav_close(void)\r
{\r
- if(dpy) {\r
- spnav_x11_window(DefaultRootWindow(dpy));\r
- app_win = 0;\r
- dpy = 0;\r
- return 0;\r
- }\r
- return -1;\r
+ if(dpy) {\r
+ spnav_x11_window(DefaultRootWindow(dpy));\r
+ app_win = 0;\r
+ dpy = 0;\r
+ return 0;\r
+ }\r
+ return -1;\r
}\r
\r
static int spnav_x11_window(Window win)\r
{\r
- int (*prev_xerr_handler)(Display*, XErrorEvent*);\r
- XEvent xev;\r
- Window daemon_win;\r
-\r
- if(!IS_OPEN) {\r
- return -1;\r
- }\r
-\r
- if(!(daemon_win = get_daemon_window(dpy))) {\r
- return -1;\r
- }\r
-\r
- prev_xerr_handler = XSetErrorHandler(catch_badwin);\r
-\r
- xev.type = ClientMessage;\r
- xev.xclient.send_event = False;\r
- xev.xclient.display = dpy;\r
- xev.xclient.window = win;\r
- xev.xclient.message_type = command_event;\r
- xev.xclient.format = 16;\r
- xev.xclient.data.s[0] = ((unsigned int)win & 0xffff0000) >> 16;\r
- xev.xclient.data.s[1] = (unsigned int)win & 0xffff;\r
- xev.xclient.data.s[2] = CMD_APP_WINDOW;\r
-\r
- XSendEvent(dpy, daemon_win, False, 0, &xev);\r
- XSync(dpy, False);\r
-\r
- XSetErrorHandler(prev_xerr_handler);\r
- return 0;\r
+ int (*prev_xerr_handler)(Display*, XErrorEvent*);\r
+ XEvent xev;\r
+ Window daemon_win;\r
+\r
+ if(!IS_OPEN) {\r
+ return -1;\r
+ }\r
+\r
+ if(!(daemon_win = get_daemon_window(dpy))) {\r
+ return -1;\r
+ }\r
+\r
+ prev_xerr_handler = XSetErrorHandler(catch_badwin);\r
+\r
+ xev.type = ClientMessage;\r
+ xev.xclient.send_event = False;\r
+ xev.xclient.display = dpy;\r
+ xev.xclient.window = win;\r
+ xev.xclient.message_type = command_event;\r
+ xev.xclient.format = 16;\r
+ xev.xclient.data.s[0] = ((unsigned int)win & 0xffff0000) >> 16;\r
+ xev.xclient.data.s[1] = (unsigned int)win & 0xffff;\r
+ xev.xclient.data.s[2] = CMD_APP_WINDOW;\r
+\r
+ XSendEvent(dpy, daemon_win, False, 0, &xev);\r
+ XSync(dpy, False);\r
+\r
+ XSetErrorHandler(prev_xerr_handler);\r
+ return 0;\r
}\r
\r
static int spnav_fd(void)\r
{\r
- if(dpy) {\r
- return ConnectionNumber(dpy);\r
- }\r
- return -1;\r
+ if(dpy) {\r
+ return ConnectionNumber(dpy);\r
+ }\r
+ return -1;\r
}\r
\r
/*static int spnav_wait_event(spnav_event *event)\r
{\r
- if(dpy) {\r
- for(;;) {\r
- XEvent xev;\r
- XNextEvent(dpy, &xev);\r
-\r
- if(spnav_x11_event(&xev, event) > 0) {\r
- return event->type;\r
- }\r
- }\r
- }\r
- return 0;\r
+ if(dpy) {\r
+ for(;;) {\r
+ XEvent xev;\r
+ XNextEvent(dpy, &xev);\r
+\r
+ if(spnav_x11_event(&xev, event) > 0) {\r
+ return event->type;\r
+ }\r
+ }\r
+ }\r
+ return 0;\r
}\r
\r
static int spnav_poll_event(spnav_event *event)\r
{\r
- if(dpy) {\r
- if(XPending(dpy)) {\r
- XEvent xev;\r
- XNextEvent(dpy, &xev);\r
-\r
- return spnav_x11_event(&xev, event);\r
- }\r
- }\r
- return 0;\r
+ if(dpy) {\r
+ if(XPending(dpy)) {\r
+ XEvent xev;\r
+ XNextEvent(dpy, &xev);\r
+\r
+ return spnav_x11_event(&xev, event);\r
+ }\r
+ }\r
+ return 0;\r
}*/\r
\r
static Bool match_events(Display *dpy, XEvent *xev, char *arg)\r
{\r
- int evtype = *(int*)arg;\r
-\r
- if(xev->type != ClientMessage) {\r
- return False;\r
- }\r
-\r
- if(xev->xclient.message_type == motion_event) {\r
- return !evtype || evtype == SPNAV_EVENT_MOTION ? True : False;\r
- }\r
- if(xev->xclient.message_type == button_press_event ||\r
- xev->xclient.message_type == button_release_event) {\r
- return !evtype || evtype == SPNAV_EVENT_BUTTON ? True : False;\r
- }\r
- return False;\r
+ int evtype = *(int*)arg;\r
+\r
+ if(xev->type != ClientMessage) {\r
+ return False;\r
+ }\r
+\r
+ if(xev->xclient.message_type == motion_event) {\r
+ return !evtype || evtype == SPNAV_EVENT_MOTION ? True : False;\r
+ }\r
+ if(xev->xclient.message_type == button_press_event ||\r
+ xev->xclient.message_type == button_release_event) {\r
+ return !evtype || evtype == SPNAV_EVENT_BUTTON ? True : False;\r
+ }\r
+ return False;\r
}\r
\r
static int spnav_remove_events(int type)\r
{\r
- int rm_count = 0;\r
+ int rm_count = 0;\r
\r
- if(dpy) {\r
- XEvent xev;\r
+ if(dpy) {\r
+ XEvent xev;\r
\r
- while(XCheckIfEvent(dpy, &xev, match_events, (char*)&type)) {\r
- rm_count++;\r
- }\r
- return rm_count;\r
- }\r
- return 0;\r
+ while(XCheckIfEvent(dpy, &xev, match_events, (char*)&type)) {\r
+ rm_count++;\r
+ }\r
+ return rm_count;\r
+ }\r
+ return 0;\r
}\r
\r
static int spnav_x11_event(const XEvent *xev, spnav_event *event)\r
{\r
- int i;\r
- int xmsg_type;\r
-\r
- if(xev->type != ClientMessage) {\r
- return 0;\r
- }\r
-\r
- xmsg_type = xev->xclient.message_type;\r
-\r
- if(xmsg_type != motion_event && xmsg_type != button_press_event &&\r
- xmsg_type != button_release_event) {\r
- return 0;\r
- }\r
-\r
- if(xmsg_type == motion_event) {\r
- event->type = SPNAV_EVENT_MOTION;\r
- event->motion.data = &event->motion.x;\r
-\r
- for(i=0; i<6; i++) {\r
- event->motion.data[i] = xev->xclient.data.s[i + 2];\r
- }\r
- event->motion.period = xev->xclient.data.s[8];\r
- } else {\r
- event->type = SPNAV_EVENT_BUTTON;\r
- event->button.press = xmsg_type == button_press_event ? 1 : 0;\r
- event->button.bnum = xev->xclient.data.s[2];\r
- }\r
- return event->type;\r
+ int i;\r
+ int xmsg_type;\r
+\r
+ if(xev->type != ClientMessage) {\r
+ return 0;\r
+ }\r
+\r
+ xmsg_type = xev->xclient.message_type;\r
+\r
+ if(xmsg_type != motion_event && xmsg_type != button_press_event &&\r
+ xmsg_type != button_release_event) {\r
+ return 0;\r
+ }\r
+\r
+ if(xmsg_type == motion_event) {\r
+ event->type = SPNAV_EVENT_MOTION;\r
+ event->motion.data = &event->motion.x;\r
+\r
+ for(i=0; i<6; i++) {\r
+ event->motion.data[i] = xev->xclient.data.s[i + 2];\r
+ }\r
+ event->motion.period = xev->xclient.data.s[8];\r
+ } else {\r
+ event->type = SPNAV_EVENT_BUTTON;\r
+ event->button.press = xmsg_type == button_press_event ? 1 : 0;\r
+ event->button.bnum = xev->xclient.data.s[2];\r
+ }\r
+ return event->type;\r
}\r
\r
\r
static Window get_daemon_window(Display *dpy)\r
{\r
- Window win, root_win;\r
- XTextProperty wname;\r
- Atom type;\r
- int fmt;\r
- unsigned long nitems, bytes_after;\r
- unsigned char *prop;\r
+ Window win, root_win;\r
+ XTextProperty wname;\r
+ Atom type;\r
+ int fmt;\r
+ unsigned long nitems, bytes_after;\r
+ unsigned char *prop;\r
\r
- root_win = DefaultRootWindow(dpy);\r
+ root_win = DefaultRootWindow(dpy);\r
\r
- XGetWindowProperty(dpy, root_win, command_event, 0, 1, False, AnyPropertyType, &type, &fmt, &nitems, &bytes_after, &prop);\r
- if(!prop) {\r
- return 0;\r
- }\r
+ XGetWindowProperty(dpy, root_win, command_event, 0, 1, False, AnyPropertyType, &type, &fmt, &nitems, &bytes_after, &prop);\r
+ if(!prop) {\r
+ return 0;\r
+ }\r
\r
- win = *(Window*)prop;\r
- XFree(prop);\r
+ win = *(Window*)prop;\r
+ XFree(prop);\r
\r
- if(!XGetWMName(dpy, win, &wname) || strcmp("Magellan Window", (char*)wname.value) != 0) {\r
- return 0;\r
- }\r
+ if(!XGetWMName(dpy, win, &wname) || strcmp("Magellan Window", (char*)wname.value) != 0) {\r
+ return 0;\r
+ }\r
\r
- return win;\r
+ return win;\r
}\r
\r
static int catch_badwin(Display *dpy, XErrorEvent *err)\r
{\r
- char buf[256];\r
-\r
- if(err->error_code == BadWindow) {\r
- /* do nothing? */\r
- } else {\r
- XGetErrorText(dpy, err->error_code, buf, sizeof buf);\r
- fprintf(stderr, "Caught unexpected X error: %s\n", buf);\r
- }\r
- return 0;\r
+ char buf[256];\r
+\r
+ if(err->error_code == BadWindow) {\r
+ /* do nothing? */\r
+ } else {\r
+ XGetErrorText(dpy, err->error_code, buf, sizeof buf);\r
+ fprintf(stderr, "Caught unexpected X error: %s\n", buf);\r
+ }\r
+ return 0;\r
}\r
\r
-#endif /* TARGET_HOST_POSIX_X11 */\r
+#endif /* TARGET_HOST_POSIX_X11 */\r