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