00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef Q2X_H
00022 #define Q2X_H
00023
00024 #include <X11/keysym.h>
00025 #include <X11/XF86keysym.h>
00026 #include <X11/Xlib.h>
00027 #include <X11/Xutil.h>
00028 #include <IMdkit.h>
00029 #include <Xi18n.h>
00030
00031 static const unsigned int KeyTbl[] = {
00032 #include "keysym2qtkey.tbl"
00033 0, 0
00034 };
00035
00036 namespace Qt2X11
00037 {
00038 inline XRectangle *convert(const QRect &rect)
00039 {
00040 XRectangle *ret = new XRectangle;
00041 ret->x = rect.x();
00042 ret->y = rect.y();
00043 ret->width = rect.width();
00044 ret->height = rect.height();
00045 return ret;
00046 }
00047
00048 inline XPoint *convert(const QPoint &point)
00049 {
00050 XPoint *ret = new XPoint;
00051 ret->x = point.x();
00052 ret->y = point.y();
00053 return ret;
00054 }
00055
00056 inline XID *convert(qulonglong value)
00057 {
00058 XID *ret = new XID;
00059 *ret = value;
00060 return ret;
00061 }
00062
00063 inline char *convert(const QString &value)
00064 {
00065 return value.toLatin1().data();
00066 }
00067 }
00068
00069 namespace X112Qt
00070 {
00071 inline qint32 convert(INT32 *id)
00072 {
00073 if (!id) return 0;
00074 return (qint32)*id;
00075 }
00076
00077 inline QString convert(char *value)
00078 {
00079 return QString(value);
00080 }
00081
00082 inline unsigned long convert(XID *xid)
00083 {
00084 if (!xid) return 0;
00085 return (unsigned long)*xid;
00086 }
00087
00088 inline QPoint convert(const XPoint *point)
00089 {
00090 if (!point) return QPoint();
00091 return QPoint(point->x, point->y);
00092 }
00093
00094 inline QRect convert(const XRectangle *rect)
00095 {
00096 if (!rect) return QRect();
00097 return QRect(rect->x, rect->y, rect->width, rect->height);
00098 }
00099
00100 inline QChar convert(XKeyEvent *xev, int &key)
00101 {
00102 QChar ret;
00103 QByteArray chars;
00104 chars.resize(513);
00105 KeySym keysym;
00106 int count = XLookupString(xev, chars.data(), chars.size(), &keysym, 0);
00107 for (int i = 0; KeyTbl[i]; i += 2) {
00108 if (KeyTbl[i+1] == keysym) {
00109 key = KeyTbl[i];
00110 break;
00111 }
00112 }
00113 if (key == 0) {
00114 qimsysDebug() << xev->keycode << keysym;
00115 }
00116 switch (count) {
00117 case 0:
00118 break;
00119 case 1:
00120 ret = chars.at(0);
00121 break;
00122 default:
00123 qimsysWarning() << chars;
00124 }
00125 return ret;
00126 }
00127 }
00128 #endif // Q2X_H