Update.
[universe.git] / simple_window.cc
index 502e1dd..2864168 100644 (file)
@@ -1,23 +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              //
-////////////////////////////////////////////////////////////////////////////////
+// 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;
 
@@ -132,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));
 }
 
@@ -164,6 +156,7 @@ int  SimpleWindow::file_descriptor() {
 
 SimpleEvent SimpleWindow::event() {
   SimpleEvent se;
+  KeySym mykey;
 
   if(XPending(_display) > 0) {
 
@@ -195,21 +188,24 @@ SimpleEvent SimpleWindow::event() {
 
     case KeyPress:
       se.type = SimpleEvent::KEY_PRESS;
-      strncpy(se.key,
-              XKeysymToString(XKeycodeToKeysym(_display, event.xkey.keycode, 0)),
-              (sizeof(se.key)/sizeof(char) - 1));
+      mykey = XkbKeycodeToKeysym(_display,
+                                 event.xkey.keycode, 0,
+                                 event.xkey.state & ShiftMask ? 1 : 0);
+      strncpy(se.key, XKeysymToString(mykey), (sizeof(se.key)/sizeof(char) - 1));
       break;
 
     case KeyRelease:
       se.type = SimpleEvent::KEY_RELEASE;
-      strncpy(se.key,
-              XKeysymToString(XKeycodeToKeysym(_display, event.xkey.keycode, 0)),
-              (sizeof(se.key)/sizeof(char) - 1));
+      mykey = XkbKeycodeToKeysym(_display,
+                                 event.xkey.keycode, 0,
+                                 event.xkey.state & ShiftMask ? 1 : 0);
+      strncpy(se.key, XKeysymToString(mykey), (sizeof(se.key)/sizeof(char) - 1));
       break;
 
     default:
       se.type = SimpleEvent::UNDEFINED;
       break;
+
     }
   } else se.type = SimpleEvent::NO_EVENT;
   return se;