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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#include <string.h>
#include <errno.h>
#include <tqstring.h>
#include <tqmap.h>
#include <tqfile.h>
#include <tqdir.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <kprocess.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBfile.h>
#include <X11/extensions/XKBgeom.h>
#include <X11/extensions/XKM.h>
#include "extension.h"
static TQString getLayoutKey(const TQString& layout, const TQString& variant)
{
return layout + "." + variant;
}
XKBExtension::XKBExtension(Display *d)
{
if ( d == NULL )
d = tqt_xdisplay();
m_dpy = d;
// TQStringList dirs = TDEGlobal::dirs()->findDirs ( "tmp", "" );
// m_tempDir = dirs.count() == 0 ? "/tmp/" : dirs[0];
m_tempDir = locateLocal("tmp", "");
}
bool XKBExtension::init()
{
// Verify the Xlib has matching XKB extension.
int major = XkbMajorVersion;
int minor = XkbMinorVersion;
if (!XkbLibraryVersion(&major, &minor))
{
kdError() << "[kxkb-extension] Xlib XKB extension " << major << '.' << minor <<
" != " << XkbMajorVersion << '.' << XkbMinorVersion << endl;
return false;
}
// Verify the X server has matching XKB extension.
int opcode_rtrn;
int error_rtrn;
int xkb_opcode;
if (!XkbQueryExtension(m_dpy, &opcode_rtrn, &xkb_opcode, &error_rtrn,
&major, &minor))
{
kdError() << "[kxkb-extension] X server XKB extension " << major << '.' << minor <<
" != " << XkbMajorVersion << '.' << XkbMinorVersion << endl;
return false;
}
// Do it, or face horrible memory corrupting bugs
::XkbInitAtoms(NULL);
// watch group change events
XkbSelectEventDetails(m_dpy, XkbUseCoreKbd, XkbStateNotify,
XkbAllStateComponentsMask, XkbGroupStateMask);
return true;
}
XKBExtension::~XKBExtension()
{
/* if( m_compiledLayoutFileNames.isEmpty() == false )
deletePrecompiledLayouts();*/
}
bool XKBExtension::setXkbOptions(const XkbOptions options)
{
TQString exe = TDEGlobal::dirs()->findExe("setxkbmap");
if (exe.isEmpty())
return false;
TDEProcess p;
p << exe;
p << "-layout";
p << options.layouts;
p << "-variant";
p << options.variants;
if (!options.model.isEmpty()) {
p << "-model";
p << options.model;
}
if (options.resetOld) {
p << "-option";
}
if (!options.options.isEmpty()) {
p << "-option" << options.options;
}
kdDebug() << "[kxkb-extension] Command: " << p.args() << endl;
p.start(TDEProcess::Block);
return p.normalExit() && (p.exitStatus() == 0);
}
bool XKBExtension::setGroup(unsigned int group)
{
kdDebug() << "[kxkb-extension] Setting group " << group << endl;
return XkbLockGroup( m_dpy, XkbUseCoreKbd, group );
}
unsigned int XKBExtension::getGroup() const
{
XkbStateRec xkbState;
XkbGetState( m_dpy, XkbUseCoreKbd, &xkbState );
return xkbState.group;
}
/** Examines an X Event passed to it and takes actions if the event is of
* interest to KXkb */
void XKBExtension::processXEvent(XEvent *event) {
XkbEvent* xkb_event = (XkbEvent*)event;
if (xkb_event->any.xkb_type == XkbStateNotify) {
emit groupChanged(xkb_event->state.group);
}
}
#include "extension.moc"
|