4 * Copyright (C) 2004-2011 Simon Wunderlich <dotslash@packetmixer.de>
6 * This file is part of s3d, a 3d network display server.
7 * See http://s3d.berlios.de/ for more updates.
9 * s3d is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * s3d is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with s3d; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <stdio.h> /* sprintf() */
30 #include <netinet/in.h> /* htonl(),htons() */
32 #include <string.h> /* strlen(),strcpy() */
34 /* I don't plan to keep this until the end, but it can show us how */
36 int event_obj_click(struct t_process
*p
, int32_t oid
)
38 uint32_t moid
= htonl(oid
);
39 s3dprintf(MED
, "telling client that oid %d got clicked", oid
);
40 prot_com_out(p
, S3D_P_S_CLICK
, (uint8_t *) & moid
, 4);
44 /* this functions sends keystroke events to the focused program. */
45 /* maybe mcp-keystrokes should be catched here. */
46 /* state = 0 -> pressed, 1 -> released */
47 int event_key_pressed(uint16_t key
, uint16_t uni
, uint16_t mod
, int state
)
55 if (OBJ_VALID(get_proc_by_pid(MCP
), focus_oid
, o
))
56 prot_com_out(get_proc_by_pid(o
->virtual_pid
), S3D_P_S_KEY
, (uint8_t *) k
, 8);
57 prot_com_out(get_proc_by_pid(MCP
), S3D_P_S_KEY
, (uint8_t *) k
, 8); /* mcp always gets a copy */
61 /* mouse button changes are sent to the client */
62 int event_mbutton_clicked(uint8_t button
, uint8_t state
)
68 if (OBJ_VALID(get_proc_by_pid(MCP
), focus_oid
, o
))
69 prot_com_out(get_proc_by_pid(o
->virtual_pid
), S3D_P_S_MBUTTON
, (uint8_t *) & b
, 2);
70 prot_com_out(get_proc_by_pid(MCP
), S3D_P_S_MBUTTON
, (uint8_t *) & b
, 2); /* mcp always gets a copy */
74 /* tell the client something about us */
75 int event_init(struct t_process
*p
)
77 char s
[S3D_NAME_MAX
+ 3];
78 sprintf(s
, "%c%c%c%s", S3D_SERVER_MAJOR
, S3D_SERVER_MINOR
, S3D_SERVER_PATCH
, S3D_SERVER_NAME
); /* thanks award */
79 prot_com_out(p
, S3D_P_S_INIT
, (uint8_t *) s
, strlen(S3D_SERVER_NAME
) + 4);
83 /* this lets a process quit gracefully ... */
84 int event_quit(struct t_process
*p
)
86 prot_com_out(p
, S3D_P_S_QUIT
, NULL
, 0);
87 s3dprintf(HIGH
, "sending pid %d QUIT signal", p
->id
);
92 /* the cam changed?! we should run and tell this the mcp/focused client! */
93 int event_cam_changed(void)
97 p
= get_proc_by_pid(MCP
);
99 if (OBJ_VALID(p
, focus_oid
, o
))
100 event_obj_info(get_proc_by_pid(o
->virtual_pid
), 0);
104 /* same for the mouse movement! */
105 int event_ptr_changed(void)
109 p
= get_proc_by_pid(MCP
);
110 event_obj_info(p
, get_pointer(p
));
111 if (OBJ_VALID(p
, focus_oid
, o
)) {
112 p
= get_proc_by_pid(o
->virtual_pid
); /* focused program pointer */
113 event_obj_info(p
, get_pointer(p
));
118 /* inform client about an available shm-segment for the texture */
119 int event_texshm(struct t_process
*p
, int32_t oid
, int32_t tex
)
123 int32_t oid
, tex
, shmid
;
124 uint16_t tw
, th
, w
, h
;
125 } __attribute__ ((__packed__
)) shmtex_packet
;
126 if (OBJ_VALID(p
, oid
, o
)) {
127 s3dprintf(LOW
, "informing process about new texture on oid %d, texture %d, which is available under id %d\n", oid
, tex
, o
->p_tex
[tex
].shmid
);
128 shmtex_packet
.oid
= htonl(oid
);
129 shmtex_packet
.tex
= htonl(tex
);
130 shmtex_packet
.shmid
= htonl(o
->p_tex
[tex
].shmid
);
131 shmtex_packet
.tw
= htons(o
->p_tex
[tex
].tw
);
132 shmtex_packet
.th
= htons(o
->p_tex
[tex
].th
);
133 shmtex_packet
.w
= htons(o
->p_tex
[tex
].w
);
134 shmtex_packet
.h
= htons(o
->p_tex
[tex
].h
);
135 prot_com_out(p
, S3D_P_S_SHMTEX
, (uint8_t *) & shmtex_packet
, sizeof(shmtex_packet
));
140 /* this should replace the mcp_rep_object() function later ... */
141 int event_obj_info(struct t_process
*p
, int32_t oid
)
146 float trans_x
, trans_y
, trans_z
;
147 float rot_x
, rot_y
, rot_z
;
150 char name
[S3D_NAME_MAX
];
151 } __attribute__ ((__packed__
)) mo
;
153 struct t_process
*ap
;
155 if (OBJ_VALID(p
, oid
, o
)) {
156 mo
.object
= htonl(oid
);
157 mo
.trans_x
= p
->object
[oid
]->translate
.x
;
158 mo
.trans_y
= p
->object
[oid
]->translate
.y
;
159 mo
.trans_z
= p
->object
[oid
]->translate
.z
;
161 mo
.rot_x
= p
->object
[oid
]->rotate
.x
;
162 mo
.rot_y
= p
->object
[oid
]->rotate
.y
;
163 mo
.rot_z
= p
->object
[oid
]->rotate
.z
;
165 mo
.scale
= p
->object
[oid
]->scale
;
167 mo
.r
= p
->object
[oid
]->r
;
169 memset(mo
.name
, 0, S3D_NAME_MAX
);
170 switch (o
->oflags
& OF_TYPE
) {
172 ap
= get_proc_by_pid(o
->virtual_pid
);
173 strncpy(mo
.name
, ap
->name
, S3D_NAME_MAX
);
176 mo
.scale
= (float)((float)winw
) / winh
; /* give aspect ratio to program */
177 strncpy(mo
.name
, "sys_camera0", S3D_NAME_MAX
);
180 strncpy(mo
.name
, "sys_pointer0", S3D_NAME_MAX
);
184 htonfb(&mo
.trans_x
, 8);
185 prot_com_out(p
, S3D_P_S_OINFO
, (uint8_t *) & mo
, sizeof(mo
));