]> git.tdb.fi Git - libs/gui.git/blob - source/input/x11/keyboard.cpp
Split platform-specific parts into separate directories
[libs/gui.git] / source / input / x11 / keyboard.cpp
1 #include <X11/Xlib.h>
2 #include <X11/Xutil.h>
3 #include <msp/graphics/window_private.h>
4 #include "keyboard.h"
5 #include "keys_private.h"
6
7 namespace Msp {
8 namespace Input {
9
10 std::string Keyboard::get_button_name(unsigned btn) const
11 {
12         if(btn==0)
13                 return "None";
14
15         const char *str = XKeysymToString(key_to_sys(btn));
16         if(!str)
17                 return Device::get_button_name(btn);
18         return str;
19 }
20
21 void Keyboard::input_event(const Graphics::Window::Event &event)
22 {
23         switch(event.xevent.type)
24         {
25         case KeyPress:
26         case KeyRelease:
27                 {
28                         KeySym keysym = XLookupKeysym(const_cast<XKeyEvent *>(&event.xevent.xkey), 0);
29                         if(keysym!=NoSymbol)
30                                 if(unsigned key = key_from_sys(keysym))
31                                         set_button_state(key, event.xevent.type==KeyPress, true);
32                         if(event.xevent.type==KeyPress)
33                         {
34                                 char ch;
35                                 if(XLookupString(const_cast<XKeyEvent *>(&event.xevent.xkey), &ch, 1, 0, 0))
36                                         // XLookupString always returns Latin-1
37                                         signal_character.emit(static_cast<unsigned char>(ch));
38                         }
39                 }
40                 break;
41         }
42 }
43
44 } // namespace Input
45 } // namespace Msp