Source/Gorgon/WindowManager/X11/Input.cpp

Sun, 15 Mar 2020 11:12:38 +0200

author
cemkalyoncu
date
Sun, 15 Mar 2020 11:12:38 +0200
branch
4.x-dev
changeset 1380
8ea1cd4f856e
parent 1359
aa01145832ef
child 1400
2312b91a08c0
permissions
-rw-r--r--

* To<float/double> will no longer cause exceptions
* X11 numpad key 9 now works

1345
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
1 #include "X11.h"
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
2 #include "X11Keysym.h"
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
3
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
4
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
5 long keysym2ucs(KeySym keysym)
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
6 {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
7 int min = 0;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
8 int max = sizeof(keysymtab) / sizeof(struct codepair) - 1;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
9 int mid;
1359
aa01145832ef #107: Enter and tab generates char event in linux.
cemkalyoncu
parents: 1354
diff changeset
10
aa01145832ef #107: Enter and tab generates char event in linux.
cemkalyoncu
parents: 1354
diff changeset
11 if(keysym == 13 || keysym == 10) {
aa01145832ef #107: Enter and tab generates char event in linux.
cemkalyoncu
parents: 1354
diff changeset
12 return keysym;
aa01145832ef #107: Enter and tab generates char event in linux.
cemkalyoncu
parents: 1354
diff changeset
13 }
1345
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
14
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
15 /* first check for Latin-1 characters (1:1 mapping) */
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
16 if ((keysym >= 0x0020 && keysym <= 0x007e) ||
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
17 (keysym >= 0x00a0 && keysym <= 0x00ff))
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
18 return keysym;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
19
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
20 /* also check for directly encoded 24-bit UCS characters */
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
21 if ((keysym & 0xff000000) == 0x01000000)
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
22 return keysym & 0x00ffffff;
1354
c3939ce7e50a #113: Moving a layer with a parent causing crash, another try
cemkalyoncu
parents: 1353
diff changeset
23
c3939ce7e50a #113: Moving a layer with a parent causing crash, another try
cemkalyoncu
parents: 1353
diff changeset
24 /* checkfor numpad */
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1359
diff changeset
25 if (keysym > 0xff80 && keysym <= 0xffb9)
1354
c3939ce7e50a #113: Moving a layer with a parent causing crash, another try
cemkalyoncu
parents: 1353
diff changeset
26 return keysym - 0xff80;
1345
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
27
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
28 /* binary search in table */
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
29 while (max >= min) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
30 mid = (min + max) / 2;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
31 if (keysymtab[mid].keysym < keysym)
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
32 min = mid + 1;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
33 else if (keysymtab[mid].keysym > keysym)
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
34 max = mid - 1;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
35 else {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
36 /* found it */
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
37 return keysymtab[mid].ucs;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
38 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
39 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
40
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
41 /* no matching Unicode value found */
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
42 return 0xfffd;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
43 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
44
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
45 namespace Gorgon { namespace WindowManager {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
46
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
47
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
48 std::string osgetkeyname(Input::Keyboard::Key key) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
49 int keycount;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
50
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
51 KeySym *keys = XGetKeyboardMapping(display,
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
52 key,
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
53 1,
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
54 &keycount
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
55 );
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
56
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
57 if(keycount < 1) return "";
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
58
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
59 KeySym keysym;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
60
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
61 if(keycount > 1) keysym = keys[1]; //capital key
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
62 else keysym = keys[0];
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
63
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
64
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
65 XFree(keys);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
66
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
67 std::string ret;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
68 Char c = keysym2ucs(keysym);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
69 String::AppendUnicode(ret, c);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
70
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
71 return ret;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
72 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
73
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
74 Input::Mouse::Button buttonfromx11(unsigned btn) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
75 using Input::Mouse::Button;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
76 switch(btn) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
77 case 1:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
78 return Button::Left;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
79 case 2:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
80 return Button::Middle;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
81 case 3:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
82 return Button::Right;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
83 case 8:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
84 return Button::X1;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
85 case 9:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
86 return Button::X2;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
87 default:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
88 return Button::None;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
89 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
90 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
91
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
92 Input::Keyboard::Key mapx11key(KeySym key, unsigned int keycode) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
93 if(key == 'i') {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
94 int keycount;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
95
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
96 KeySym *keys = XGetKeyboardMapping(WindowManager::display,
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
97 keycode,
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
98 1,
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
99 &keycount
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
100 );
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
101
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
102 if(keycount < 2) return 'I';
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
103
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
104 KeySym keysym;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
105
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
106 keysym = keys[1]; //capital key
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
107
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
108 if(keysym != 'I')
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
109 return keycode + Input::Keyboard::Keycodes::OSTransport;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
110 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
111
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
112 if(key >= 'a' && key <='z')
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
113 return key + ('A' - 'a');
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
114
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
115 if(key >= '0' && key <='9')
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
116 return key;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
117
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
118 if(key >= 'A' && key <='Z')
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
119 return key;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
120
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
121 switch(key) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
122 case XK_Shift_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
123 return Input::Keyboard::Keycodes::Shift;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
124 case XK_Shift_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
125 return Input::Keyboard::Keycodes::RShift;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
126 case XK_Control_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
127 return Input::Keyboard::Keycodes::Control;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
128 case XK_Control_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
129 return Input::Keyboard::Keycodes::RControl;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
130 case XK_Alt_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
131 return Input::Keyboard::Keycodes::Alt;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
132 case XK_Alt_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
133 return Input::Keyboard::Keycodes::RAlt;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
134 case XK_Super_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
135 return Input::Keyboard::Keycodes::Meta;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
136 case XK_Super_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
137 return Input::Keyboard::Keycodes::RMeta;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
138
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
139 case XK_Home:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
140 return Input::Keyboard::Keycodes::Home;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
141 case XK_End:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
142 return Input::Keyboard::Keycodes::End;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
143 case XK_Insert:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
144 return Input::Keyboard::Keycodes::Insert;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
145 case XK_Delete:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
146 return Input::Keyboard::Keycodes::Delete;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
147 case XK_Prior:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
148 return Input::Keyboard::Keycodes::PageUp;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
149 case XK_Next:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
150 return Input::Keyboard::Keycodes::PageDown;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
151
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
152 case XK_Print:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
153 return Input::Keyboard::Keycodes::PrintScreen;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
154 case XK_Pause:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
155 return Input::Keyboard::Keycodes::Pause;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
156
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
157 case XK_Menu:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
158 return Input::Keyboard::Keycodes::Menu;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
159
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
160 case XK_Caps_Lock:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
161 return Input::Keyboard::Keycodes::CapsLock;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
162 case XK_Num_Lock:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
163 return Input::Keyboard::Keycodes::Numlock;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
164 case XK_Scroll_Lock:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
165 return Input::Keyboard::Keycodes::ScrollLock;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
166
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
167 case XK_Return:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
168 return Input::Keyboard::Keycodes::Enter;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
169 case XK_Tab:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
170 return Input::Keyboard::Keycodes::Tab;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
171 case XK_BackSpace:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
172 return Input::Keyboard::Keycodes::Backspace;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
173 case XK_space:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
174 return Input::Keyboard::Keycodes::Space;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
175 case XK_Escape:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
176 return Input::Keyboard::Keycodes::Escape;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
177
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
178 case XK_Left:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
179 return Input::Keyboard::Keycodes::Left;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
180 case XK_Up:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
181 return Input::Keyboard::Keycodes::Up;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
182 case XK_Right:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
183 return Input::Keyboard::Keycodes::Right;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
184 case XK_Down:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
185 return Input::Keyboard::Keycodes::Down;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
186
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
187 case XK_F1:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
188 return Input::Keyboard::Keycodes::F1;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
189 case XK_F2:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
190 return Input::Keyboard::Keycodes::F2;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
191 case XK_F3:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
192 return Input::Keyboard::Keycodes::F3;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
193 case XK_F4:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
194 return Input::Keyboard::Keycodes::F4;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
195 case XK_F5:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
196 return Input::Keyboard::Keycodes::F5;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
197 case XK_F6:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
198 return Input::Keyboard::Keycodes::F6;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
199 case XK_F7:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
200 return Input::Keyboard::Keycodes::F7;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
201 case XK_F8:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
202 return Input::Keyboard::Keycodes::F8;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
203 case XK_F9:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
204 return Input::Keyboard::Keycodes::F9;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
205 case XK_F10:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
206 return Input::Keyboard::Keycodes::F10;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
207 case XK_F11:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
208 return Input::Keyboard::Keycodes::F11;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
209 case XK_F12:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
210 return Input::Keyboard::Keycodes::F12;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
211
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
212
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
213 case XK_KP_0:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
214 case XK_KP_Insert:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
215 return Input::Keyboard::Keycodes::Numpad_0;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
216 case XK_KP_1:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
217 case XK_KP_End:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
218 return Input::Keyboard::Keycodes::Numpad_1;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
219 case XK_KP_2:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
220 case XK_KP_Down:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
221 return Input::Keyboard::Keycodes::Numpad_2;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
222 case XK_KP_3:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
223 case XK_KP_Next:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
224 return Input::Keyboard::Keycodes::Numpad_3;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
225 case XK_KP_4:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
226 case XK_KP_Left:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
227 return Input::Keyboard::Keycodes::Numpad_4;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
228 case XK_KP_5:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
229 case XK_KP_Begin:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
230 return Input::Keyboard::Keycodes::Numpad_5;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
231 case XK_KP_6:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
232 case XK_KP_Right:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
233 return Input::Keyboard::Keycodes::Numpad_6;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
234 case XK_KP_7:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
235 case XK_KP_Home:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
236 return Input::Keyboard::Keycodes::Numpad_7;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
237 case XK_KP_8:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
238 case XK_KP_Up:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
239 return Input::Keyboard::Keycodes::Numpad_8;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
240 case XK_KP_9:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
241 case XK_KP_Prior:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
242 return Input::Keyboard::Keycodes::Numpad_9;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
243 case XK_KP_Decimal:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
244 return Input::Keyboard::Keycodes::Numpad_Decimal;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
245 case XK_KP_Divide:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
246 return Input::Keyboard::Keycodes::Numpad_Div;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
247 case XK_KP_Multiply:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
248 return Input::Keyboard::Keycodes::Numpad_Mult;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
249 case XK_KP_Enter:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
250 return Input::Keyboard::Keycodes::Numpad_Enter;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
251 case XK_KP_Add:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
252 return Input::Keyboard::Keycodes::Numpad_Plus;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
253 case XK_KP_Subtract:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
254 return Input::Keyboard::Keycodes::Numpad_Minus;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
255 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
256 return keycode + Input::Keyboard::Keycodes::OSTransport;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
257 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
258
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
259 void assertkeys(Window &wind, Gorgon::internal::windowdata *data) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
260 char keys[32];
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
261 XQueryKeymap(WindowManager::display, keys);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
262
1353
3be35aeb382b #87: alt+tab on linux causing freeze
cemkalyoncu
parents: 1345
diff changeset
263 for(auto it=data->pressed.begin(); it!=data->pressed.end();) {
1345
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
264 auto key = *it;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
265 KeyCode kc = XKeysymToKeycode(WindowManager::display, key);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
266 if((keys[kc >> 3] & (1 << (kc & 7))) == 0) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
267 auto ggekey = mapx11key(key, kc);
1353
3be35aeb382b #87: alt+tab on linux causing freeze
cemkalyoncu
parents: 1345
diff changeset
268
1345
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
269 it = data->pressed.erase(it);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
270
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
271 //modifiers
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
272 switch(key) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
273 case XK_Shift_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
274 case XK_Shift_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
275 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Shift);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
276 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
277
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
278 case XK_Control_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
279 case XK_Control_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
280 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Ctrl);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
281 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
282
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
283 case XK_Alt_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
284 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Alt);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
285 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
286
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
287 case XK_Alt_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
288 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Alt);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
289 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
290
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
291 case XK_Super_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
292 case XK_Super_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
293 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Meta);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
294 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
295 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
296
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
297
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
298 if(data->handlers.count(ggekey)>0 && data->handlers[ggekey] != wind.KeyEvent.EmptyToken) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
299 wind.KeyEvent.FireFor(data->handlers[ggekey], ggekey, 0.f);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
300 data->handlers[ggekey] = wind.KeyEvent.EmptyToken;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
301 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
302 else {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
303 wind.KeyEvent(ggekey, 0.f);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
304 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
305 }
1353
3be35aeb382b #87: alt+tab on linux causing freeze
cemkalyoncu
parents: 1345
diff changeset
306 else {
3be35aeb382b #87: alt+tab on linux causing freeze
cemkalyoncu
parents: 1345
diff changeset
307 ++it;
3be35aeb382b #87: alt+tab on linux causing freeze
cemkalyoncu
parents: 1345
diff changeset
308 }
1345
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
309 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
310 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
311
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
312 void handlekeypressevent(XEvent event, Window &wind) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
313 auto key=XLookupKeysym(&event.xkey,0);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
314 auto data = WindowManager::internal::getdata(wind);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
315
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
316 data->pressed.insert(key);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
317
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
318 //modifiers
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
319 switch(key) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
320 case XK_Shift_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
321 case XK_Shift_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
322 Input::Keyboard::CurrentModifier.Add(Input::Keyboard::Modifier::Shift);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
323 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
324
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
325 case XK_Control_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
326 case XK_Control_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
327 Input::Keyboard::CurrentModifier.Add(Input::Keyboard::Modifier::Ctrl);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
328 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
329
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
330 case XK_Alt_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
331 Input::Keyboard::CurrentModifier.Add(Input::Keyboard::Modifier::Alt);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
332 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
333
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
334 case XK_Alt_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
335 Input::Keyboard::CurrentModifier.Add(Input::Keyboard::Modifier::Alt);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
336 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
337
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
338 case XK_Super_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
339 case XK_Super_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
340 Input::Keyboard::CurrentModifier.Add(Input::Keyboard::Modifier::Meta);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
341 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
342 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
343 auto ggekey = WindowManager::mapx11key(key, event.xkey.keycode);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
344 auto token = wind.KeyEvent(ggekey, true);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
345 if(token != wind.KeyEvent.EmptyToken) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
346 data->handlers[ggekey]=token;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
347
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
348 return;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
349 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
350
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
351 if(!Input::Keyboard::CurrentModifier.IsModified()) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
352 XLookupString(&event.xkey, nullptr, 0, &key, nullptr); //append shift and other mods
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
353 Input::Keyboard::Char c = keysym2ucs(key);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
354
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
355 if(c != 0xfffd) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
356 if( (c>=0x20 || c == '\t' || c ==13) && (c < 0x7f || c > 0x9f)) { //exclude c0 & c1 but keep tab
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
357 wind.CharacterEvent(c);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
358 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
359 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
360 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
361 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
362
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
363 void handlekeyreleaseevent(XEvent event, Window &wind) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
364 auto key=XLookupKeysym(&event.xkey,0);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
365 auto data = WindowManager::internal::getdata(wind);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
366
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
367 auto ggekey = WindowManager::mapx11key(key, event.xkey.keycode);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
368
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
369 if(XEventsQueued(WindowManager::display, QueuedAfterReading)) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
370 XEvent nextevent;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
371 XPeekEvent(WindowManager::display, &nextevent);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
372
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
373 if(nextevent.type == KeyPress && nextevent.xkey.time == event.xkey.time &&
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
374 nextevent.xkey.keycode == event.xkey.keycode
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
375 ) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
376
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
377 if(data->handlers.count(ggekey)>0 && data->handlers[ggekey] != wind.KeyEvent.EmptyToken) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
378 //if keypress handled, key will not be repeated.
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
379 //what about backspace, arrow keys and delete?
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
380 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
381 else if(!Input::Keyboard::CurrentModifier.IsModified()) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
382 XLookupString(&event.xkey, nullptr, 0, &key, nullptr);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
383 Input::Keyboard::Char c = keysym2ucs(key);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
384
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
385 if(c != 0xfffd) {
1359
aa01145832ef #107: Enter and tab generates char event in linux.
cemkalyoncu
parents: 1354
diff changeset
386 if( (c>=0x20 || c == '\t' || c ==13) && (c < 0x7f || c > 0x9f)) { //exclude c0 & c1 but keep enter and tab
1345
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
387 wind.CharacterEvent(c);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
388 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
389 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
390 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
391
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
392 XNextEvent(WindowManager::display, &nextevent);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
393 return;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
394 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
395 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
396
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
397 data->pressed.erase(key);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
398
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
399 //modifiers
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
400 switch(key) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
401 case XK_Shift_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
402 case XK_Shift_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
403 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Shift);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
404 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
405
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
406 case XK_Control_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
407 case XK_Control_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
408 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Ctrl);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
409 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
410
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
411 case XK_Alt_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
412 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Alt);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
413 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
414
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
415 case XK_Alt_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
416 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Alt);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
417 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
418
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
419 case XK_Super_L:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
420 case XK_Super_R:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
421 Input::Keyboard::CurrentModifier.Remove(Input::Keyboard::Modifier::Meta);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
422 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
423 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
424
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
425
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
426 if(data->handlers.count(ggekey)>0 && data->handlers[ggekey] != wind.KeyEvent.EmptyToken) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
427 wind.KeyEvent.FireFor(data->handlers[ggekey], ggekey, 0.f);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
428 data->handlers[ggekey] = wind.KeyEvent.EmptyToken;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
429 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
430 else {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
431 wind.KeyEvent(ggekey, 0.f);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
432 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
433
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
434 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
435
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
436 void handlebuttonpressevent(XEvent event, Window &wind) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
437 if(event.xbutton.button==4) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
438 wind.mouse_event(Input::Mouse::EventType::Scroll_Vert, {event.xbutton.x, event.xbutton.y}, WindowManager::buttonfromx11(event.xbutton.button), 1);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
439 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
440 else if(event.xbutton.button==5) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
441 wind.mouse_event(Input::Mouse::EventType::Scroll_Vert, {event.xbutton.x, event.xbutton.y}, WindowManager::buttonfromx11(event.xbutton.button), -1);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
442 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
443 else {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
444 wind.mouse_down({event.xbutton.x, event.xbutton.y}, WindowManager::buttonfromx11(event.xbutton.button));
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
445 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
446 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
447
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
448 void handlebuttonreleaseevent(XEvent event, Window &wind) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
449 if(event.xbutton.button!=4 && event.xbutton.button!=5) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
450 wind.mouse_up({event.xbutton.x, event.xbutton.y}, WindowManager::buttonfromx11(event.xbutton.button));
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
451 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
452 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
453
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
454 void handleinputevent(XEvent event, Window &wind) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
455 switch(event.type) {
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
456 case KeyPress:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
457 handlekeypressevent(event, wind);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
458 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
459
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
460 case KeyRelease:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
461 handlekeyreleaseevent(event, wind);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
462 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
463
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
464 case ButtonPress:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
465 handlebuttonpressevent(event, wind);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
466 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
467
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
468 case ButtonRelease:
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
469 handlebuttonreleaseevent(event, wind);
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
470 break;
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
471 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
472 }
c8e54573063a #105 X11.cpp is broken down to parts to be more managable.
cemkalyoncu
parents:
diff changeset
473 } }

mercurial