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