forked from sergei-mironov/xkb-switch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XKeyboard.h
90 lines (72 loc) · 2.14 KB
/
XKeyboard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Interface for a class to get keyboard layout information and change layouts
*
* Copyright (C) 2008 by Jay Bromley <jbromley@gmail.com>
*
* This file is part of Xkb-switch.
* Xkb-switch is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xkb-switch 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.
*
* You should have received a copy of the GNU General Public License
* along with Xkb-switch. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XKEYBOARD_H
#define XKEYBOARD_H
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <map>
#include <string>
using std::string;
namespace kb {
typedef std::vector<std::string> string_vector;
class XKeyboard
{
public:
Display* _display;
int _deviceId;
XkbDescRec* _kbdDescPtr;
XKeyboard();
~XKeyboard();
// Gets the current layout
int get_group() const;
// Sets the layout
void set_group(int num);
// Returns keyboard layout string
void BuildLayout(string_vector& vec);
// Waits for kb event
void wait_event();
private:
};
// Parses keyboard string returned by get_kb_stirng. ns are symbols to ignore,
// normally the result of nonsyms()
string_vector parse1(const std::string& symbols, const string_vector& ns);
string_vector parse2(const std::string& symbols, const string_vector& ns);
string_vector parse3(const std::string& symbols, const string_vector& ns);
// Symbols to be ignored by the parser
inline string_vector nonsyms()
{
string_vector nonsyms;
nonsyms.push_back("group");
nonsyms.push_back("inet");
nonsyms.push_back("ctr");
nonsyms.push_back("pc");
nonsyms.push_back("ctrl");
nonsyms.push_back("capslock");
nonsyms.push_back("compose");
nonsyms.push_back("terminate");
nonsyms.push_back("eurosign");
return nonsyms;
}
}
#endif