summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley Smith2008-03-09 00:16:59 +0000
committerBradley Smith2008-03-09 00:16:59 +0000
commit3ae61ef96f2051d955224f1a0d43a97b61c6b627 (patch)
tree04cef275ccb04ab7630031378155ca3cea1b4484
parentAdd needed headers to dist. (diff)
downloadgnurobots-3ae61ef96f2051d955224f1a0d43a97b61c6b627.tar.gz
Tidy up x11plugin.c and make window respond to close events.
Signed-off-by: Bradley Smith <brad@brad-smith.co.uk>
-rw-r--r--ChangeLog8
-rw-r--r--lib/x11plugin.c227
2 files changed, 127 insertions, 108 deletions
diff --git a/ChangeLog b/ChangeLog
index 3446a76..2966efe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-03-09 Bradley Smith <brad@brad-smith.co.uk>
+
+ * src/api.c:
+ Change deprecated SCM_STRING_CHARS to scm_to_locale_string
+ * lib/x11plugin.c:
+ Make window respond to DestroyNotify and ClientMessage
+
2008-03-08 Bradley Smith <brad@brad-smith.co.uk>
* include/map.h:
@@ -11,6 +18,7 @@
Add readline support to text plugin
* lib/Makefile.am:
Add readline libs/includes to text plugin
+ Add headers to dist.
* src/Makefile.am:
Change binary name to gnurobots
diff --git a/lib/x11plugin.c b/lib/x11plugin.c
index 1459530..9145784 100644
--- a/lib/x11plugin.c
+++ b/lib/x11plugin.c
@@ -34,7 +34,7 @@
enum
{
ARG_0,
- ARG_MAP
+ ARG_MAP
};
GType _x11_plugin_type = 0;
@@ -44,8 +44,8 @@ static void x11_plugin_class_init (X11PluginClass * klass);
static void x11_plugin_init (GObject * object);
static void x11_plugin_interface_init (gpointer g_iface, gpointer iface_data);
-static GObject * x11_plugin_constructor (GType type,
- guint n_construct_properties,
+static GObject * x11_plugin_constructor (GType type,
+ guint n_construct_properties,
GObjectConstructParam *construct_properties);
static void x11_plugin_finalize (GObject * object);
@@ -62,9 +62,9 @@ static void put_winbuf (X11Plugin *x11);
static void setup_winbuf (X11Plugin *x11);
void create_image (X11Plugin *x11, gchar **data, XImage ** image);
inline void x11_plugin_update_status (X11Plugin *x11,
- const gchar *s,
- glong energy,
- glong score,
+ const gchar *s,
+ glong energy,
+ glong score,
glong shields);
static GObjectClass *parent_class = NULL;
@@ -93,11 +93,11 @@ x11_plugin_get_type (void)
};
_x11_plugin_type =
- g_type_register_static (G_TYPE_OBJECT,
- "X11Plugin",
+ g_type_register_static (G_TYPE_OBJECT,
+ "X11Plugin",
&object_info,
0);
-
+
g_type_add_interface_static (_x11_plugin_type,
_parent_type,
&interface_info);
@@ -134,8 +134,8 @@ x11_plugin_init (GObject * object)
}
static GObject *
-x11_plugin_constructor (GType type,
- guint n_construct_properties,
+x11_plugin_constructor (GType type,
+ guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
/* Initialize X11 */
@@ -159,21 +159,22 @@ x11_plugin_constructor (GType type,
Atom delete_win;
/* Chain up to the parent first */
- object = parent_class->constructor (type, n_construct_properties, construct_properties);
-
+ object = parent_class->constructor (type, n_construct_properties,
+ construct_properties);
+
x11 = X11_PLUGIN (object);
if ((x11->dpy = XOpenDisplay ("")) == NULL) {
g_printf ("Couldn't open the X Server Display!\n");
- exit (1); /* Exit nicely isn't needed yet, and causes segfault */
+ exit (1); /* Exit nicely isn't needed yet, and causes segfault */
}
delete_win = XInternAtom (x11->dpy, "WM_DELETE_WINDOW", False);
x11->win_width = x11->map_size->num_cols * TILE_SIZE;
x11->win_height = x11->map_size->num_rows * TILE_SIZE + 32;
- x11->x_win = XCreateSimpleWindow (x11->dpy, DefaultRootWindow (x11->dpy), 0, 0,
- x11->win_width, x11->win_height, 0, 0, 0);
+ x11->x_win = XCreateSimpleWindow (x11->dpy, DefaultRootWindow (x11->dpy),
+ 0, 0, x11->win_width, x11->win_height, 0, 0, 0);
prots[0] = delete_win;
XSetWMProtocols (x11->dpy, x11->x_win, prots, 1);
@@ -191,15 +192,18 @@ x11_plugin_constructor (GType type,
XSetWMHints (x11->dpy, x11->x_win, &wmhints);
XSelectInput (x11->dpy, x11->x_win,
- KeyPressMask | KeyReleaseMask | StructureNotifyMask | FocusChangeMask);
+ KeyPressMask | KeyReleaseMask | StructureNotifyMask
+ | FocusChangeMask);
XMapWindow (x11->dpy, x11->x_win);
- x11->text = XLoadFont (x11->dpy, "-*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*");
+ x11->text = XLoadFont (x11->dpy,
+ "-*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*");
values.font = x11->text;
values.foreground = WhitePixel (x11->dpy, DefaultScreen (x11->dpy));
- x11->gc = XCreateGC (x11->dpy, x11->x_win, GCFont | GCForeground, &values);
+ x11->gc = XCreateGC (x11->dpy, x11->x_win,
+ GCFont | GCForeground, &values);
create_image (x11, statusbar_xpm, &x11->statusbar);
create_image (x11, space_xpm, &x11->space);
@@ -276,7 +280,7 @@ x11_plugin_set_property (GObject * object, guint prop_id,
case ARG_MAP:
obj = g_value_get_object (value);
g_return_if_fail (obj != NULL);
-
+
if (x11->map != NULL) {
g_object_unref (x11->map);
}
@@ -344,8 +348,8 @@ user_interface_new (Map *map, GType parent_type)
/* note that hook_delete_thing(x,y) is the same as
hook_add_thing(x,y,space) */
inline void x11_plugin_add_thing (X11Plugin *x11,
- gint x,
- gint y,
+ gint x,
+ gint y,
gint thing)
{
gint w_x, w_y;
@@ -384,7 +388,7 @@ inline void x11_plugin_add_thing (X11Plugin *x11,
inline void x11_plugin_draw (X11Plugin *x11)
{
gint i, j;
-
+
/* Draw the map for the GNU Robots game. */
for (j = 0; j < x11->map_size->num_rows; j++) {
for (i = 0; i < x11->map_size->num_cols; i++) {
@@ -418,19 +422,19 @@ inline void x11_plugin_draw (X11Plugin *x11)
} /* switch */
} /* for i */
} /* for j */
-
+
put_winbuf (x11);
XSync (x11->dpy, FALSE);
}
inline void x11_plugin_move_robot (X11Plugin *x11,
- gint from_x,
- gint from_y,
- gint to_x,
- gint to_y,
+ gint from_x,
+ gint from_y,
+ gint to_x,
+ gint to_y,
gint cdir,
glong energy,
- glong score,
+ glong score,
glong shields)
{
const static gint movement = TILE_SIZE / 16;
@@ -506,11 +510,11 @@ inline void x11_plugin_move_robot (X11Plugin *x11,
/* hooks to animate the robot */
inline void x11_plugin_robot_smell (X11Plugin *x11,
- gint x,
- gint y,
+ gint x,
+ gint y,
gint cdir,
glong energy,
- glong score,
+ glong score,
glong shields)
{
/* If we want to change the pic, do it here */
@@ -519,13 +523,13 @@ inline void x11_plugin_robot_smell (X11Plugin *x11,
}
inline void x11_plugin_robot_zap (X11Plugin *x11,
- gint x,
- gint y,
- gint cdir,
- gint x_to,
+ gint x,
+ gint y,
+ gint cdir,
+ gint x_to,
gint y_to,
glong energy,
- glong score,
+ glong score,
glong shields)
{
x11_plugin_update_status (x11, "robot fires his little gun...", energy, score, shields);
@@ -533,13 +537,13 @@ inline void x11_plugin_robot_zap (X11Plugin *x11,
}
inline void x11_plugin_robot_feel (X11Plugin *x11,
- gint x,
- gint y,
- gint cdir,
- gint x_to,
+ gint x,
+ gint y,
+ gint cdir,
+ gint x_to,
gint y_to,
glong energy,
- glong score,
+ glong score,
glong shields)
{
x11_plugin_update_status (x11, "robot feels for a thing...", energy, score, shields);
@@ -547,13 +551,13 @@ inline void x11_plugin_robot_feel (X11Plugin *x11,
}
inline void x11_plugin_robot_grab (X11Plugin *x11,
- gint x,
- gint y,
- gint cdir,
- gint x_to,
+ gint x,
+ gint y,
+ gint cdir,
+ gint x_to,
gint y_to,
glong energy,
- glong score,
+ glong score,
glong shields)
{
x11_plugin_update_status (x11, "robot grabs thing...", energy, score, shields);
@@ -561,13 +565,13 @@ inline void x11_plugin_robot_grab (X11Plugin *x11,
}
inline void x11_plugin_robot_look (X11Plugin *x11,
- gint x,
- gint y,
- gint cdir,
- gint x_to,
+ gint x,
+ gint y,
+ gint cdir,
+ gint x_to,
gint y_to,
glong energy,
- glong score,
+ glong score,
glong shields)
{
x11_plugin_update_status (x11, "robot looks for a thing...", energy, score, shields);
@@ -576,8 +580,8 @@ inline void x11_plugin_robot_look (X11Plugin *x11,
/* hooks to get/display data from/to user */
inline void x11_plugin_get_string (X11Plugin *x11,
- gchar *prompt,
- gchar *buff,
+ gchar *prompt,
+ gchar *buff,
gint len)
{
char* line = (char*)NULL;
@@ -597,9 +601,9 @@ inline void x11_plugin_get_string (X11Plugin *x11,
}
inline void x11_update_status (X11Plugin *x11,
- const gchar *s,
- glong energy,
- glong score,
+ const gchar *s,
+ glong energy,
+ glong score,
glong shields)
{
gchar status[20];
@@ -633,26 +637,33 @@ inline void x11_update_status (X11Plugin *x11,
}
inline void x11_plugin_update_status (X11Plugin *x11,
- const gchar *s,
- glong energy,
- glong score,
+ const gchar *s,
+ glong energy,
+ glong score,
glong shields)
{
XEvent ev;
x11_update_status (x11, s, energy, score, shields);
- while (XPending (x11->dpy)) {
+ while (XPending (x11->dpy))
+ {
XNextEvent (x11->dpy, &ev);
- switch (ev.type) {
+ switch (ev.type)
+ {
case KeyPress:
case KeyRelease:
- switch (XKeycodeToKeysym (x11->dpy, ev.xkey.keycode, 0)) {
+ switch (XKeycodeToKeysym (x11->dpy, ev.xkey.keycode, 0))
+ {
case XK_Escape:
exit (0);
break;
}
+ case DestroyNotify:
+ case ClientMessage: /* Need to do some checks? */
+ exit(0);
+ break;
}
}
@@ -766,7 +777,7 @@ static void put_winbuf (X11Plugin *x11)
else
#endif
XCopyArea (x11->dpy, x11->win_buf, x11->x_win, x11->gc, 0, 0, x11->win_width, x11->win_height, 0, 0);
-
+
XSync (x11->dpy, 0);
}
@@ -775,79 +786,79 @@ static void x11_plugin_interface_init (gpointer g_iface, gpointer iface_data)
UserInterfaceClass *klass = (UserInterfaceClass *)g_iface;
klass->user_interface_add_thing = (void (*) (UserInterface *ui,
- gint x,
- gint y,
- gint thing))
+ gint x,
+ gint y,
+ gint thing))
x11_plugin_add_thing;
klass->user_interface_draw = (void (*) (UserInterface *ui)) x11_plugin_draw;
klass->user_interface_update_status = (void (*) (UserInterface *ui,
- const gchar *s,
+ const gchar *s,
glong energy,
- glong score,
- glong shields))
+ glong score,
+ glong shields))
x11_plugin_update_status;
- klass->user_interface_move_robot = (void (*) (UserInterface *ui,
- gint from_x,
- gint from_y,
- gint to_x,
- gint to_y,
+ klass->user_interface_move_robot = (void (*) (UserInterface *ui,
+ gint from_x,
+ gint from_y,
+ gint to_x,
+ gint to_y,
gint cdir,
- glong energy,
- glong score,
+ glong energy,
+ glong score,
glong shields))
x11_plugin_move_robot;
- klass->user_interface_robot_smell = (void (*) (UserInterface *ui,
- gint x,
- gint y,
+ klass->user_interface_robot_smell = (void (*) (UserInterface *ui,
+ gint x,
+ gint y,
gint cdir,
- glong energy,
- glong score,
+ glong energy,
+ glong score,
glong shields))
x11_plugin_robot_smell;
klass->user_interface_robot_zap = (void (*) (UserInterface *ui,
- gint x,
- gint y,
- gint cdir,
- gint x_to,
+ gint x,
+ gint y,
+ gint cdir,
+ gint x_to,
gint y_to,
- glong energy,
- glong score,
+ glong energy,
+ glong score,
glong shields))
x11_plugin_robot_zap;
- klass->user_interface_robot_feel = (void (*) (UserInterface *ui,
- gint x,
- gint y,
- gint cdir,
- gint x_to,
+ klass->user_interface_robot_feel = (void (*) (UserInterface *ui,
+ gint x,
+ gint y,
+ gint cdir,
+ gint x_to,
gint y_to,
- glong energy,
- glong score,
+ glong energy,
+ glong score,
glong shields))
x11_plugin_robot_grab;
klass->user_interface_robot_grab = (void (*) (UserInterface *ui,
- gint x,
- gint y,
- gint cdir,
- gint x_to,
+ gint x,
+ gint y,
+ gint cdir,
+ gint x_to,
gint y_to,
glong energy,
- glong score,
+ glong score,
glong shields))
x11_plugin_robot_grab;
klass->user_interface_robot_look = (void (*) (UserInterface *ui,
- gint x,
- gint y,
- gint cdir,
- gint x_to,
+ gint x,
+ gint y,
+ gint cdir,
+ gint x_to,
gint y_to,
- glong energy,
- glong score,
+ glong energy,
+ glong score,
glong shields))
x11_plugin_robot_look;
klass->user_interface_get_string = (void (*) (UserInterface *ui,
- gchar *prompt,
- gchar *buff,
+ gchar *prompt,
+ gchar *buff,
gint len))
x11_plugin_get_string;
}