Refreshed the code to compile without warning.
[universe.git] / simple_window.cc
index 449ca36..7fee9c2 100644 (file)
@@ -1,25 +1,15 @@
 
-////////////////////////////////////////////////////////////////////////////////
-// This program is free software; you can redistribute it and/or              //
-// modify it under the terms of the GNU General Public License                //
-// version 2 as published by the Free Software Foundation.                    //
-//                                                                            //
-// This program is distributed in the hope that it will be useful, but        //
-// WITHOUT ANY WARRANTY; without even the implied warranty of                 //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          //
-// General Public License for more details.                                   //
-//                                                                            //
-// Written and (C) by François Fleuret                                        //
-// Contact <francois.fleuret@epfl.ch> for comments & bug reports              //
-////////////////////////////////////////////////////////////////////////////////
-
-// $Id: simple_window.cc,v 1.2 2007-04-24 21:22:52 fleuret Exp $
+// Written and (C) by Francois Fleuret
+// Contact <francois.fleuret@idiap.ch> for comments & bug reports
+
+#include <string.h>
+#include <stdlib.h>
 
 #include "simple_window.h"
 
 SimpleEvent::SimpleEvent() : type(UNDEFINED) {}
 
-SimpleWindow::SimpleWindow(char *name, int x, int y, int w, int h) {
+SimpleWindow::SimpleWindow(const char *name, int x, int y, int w, int h) {
 
   _width = w; _height = h;
 
@@ -134,7 +124,7 @@ void SimpleWindow::draw_circle(int x, int y, int r) {
   XDrawArc(_display, _pixmap, _gc, x-r, y-r, 2*r, 2*r, 0, 360*64);
 }
 
-void SimpleWindow::draw_text(char *s, int x, int y) {
+void SimpleWindow::draw_text(const char *s, int x, int y) {
   XDrawString(_display, _pixmap, _gc, x, y, s, strlen(s));
 }
 
@@ -196,17 +186,24 @@ SimpleEvent SimpleWindow::event() {
       break;
 
     case KeyPress:
+      KeySym mykey;
+      mykey = XkbKeycodeToKeysym(_display,
+                                 event.xkey.keycode, 0,
+                                 event.xkey.state & ShiftMask ? 1 : 0);
+
       se.type = SimpleEvent::KEY_PRESS;
-      strncpy(se.key,
-              XKeysymToString(XKeycodeToKeysym(_display, event.xkey.keycode, 0)),
-              (sizeof(se.key)/sizeof(char) - 1));
+      strncpy(se.key, XKeysymToString(mykey), (sizeof(se.key)/sizeof(char) - 1));
+
       break;
 
     case KeyRelease:
+      KeySym mykey;
+      mykey = XkbKeycodeToKeysym(_display,
+                                 event.xkey.keycode, 0,
+                                 event.xkey.state & ShiftMask ? 1 : 0);
+
       se.type = SimpleEvent::KEY_RELEASE;
-      strncpy(se.key,
-              XKeysymToString(XKeycodeToKeysym(_display, event.xkey.keycode, 0)),
-              (sizeof(se.key)/sizeof(char) - 1));
+      strncpy(se.key, XKeysymToString(mykey), (sizeof(se.key)/sizeof(char) - 1));
       break;
 
     default: