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 # ifdef LONG64
00072 inline quint32 convert(CARD32 *id)
00073 {
00074 if (!id) return 0;
00075 return (quint32)*id;
00076 }
00077 #endif
00078
00079 inline qint32 convert(INT32 *id)
00080 {
00081 if (!id) return 0;
00082 return (qint32)*id;
00083 }
00084
00085 inline QString convert(char *value)
00086 {
00087 return QString(value);
00088 }
00089
00090 inline unsigned long convert(XID *xid)
00091 {
00092 if (!xid) return 0;
00093 return (unsigned long)*xid;
00094 }
00095
00096 inline QPoint convert(const XPoint *point)
00097 {
00098 if (!point) return QPoint();
00099 return QPoint(point->x, point->y);
00100 }
00101
00102 inline QRect convert(const XRectangle *rect)
00103 {
00104 if (!rect) return QRect();
00105 return QRect(rect->x, rect->y, rect->width, rect->height);
00106 }
00107
00108 inline QChar convert(XKeyEvent *xev, int &key)
00109 {
00110 QChar ret;
00111 QByteArray chars;
00112 chars.resize(513);
00113 KeySym keysym;
00114 int count = XLookupString(xev, chars.data(), chars.size(), &keysym, 0);
00115 for (int i = 0; KeyTbl[i]; i += 2) {
00116 if (KeyTbl[i+1] == keysym) {
00117 key = KeyTbl[i];
00118 break;
00119 }
00120 }
00121 if (key == 0) {
00122 qimsysDebug() << xev->keycode << keysym;
00123 }
00124 switch (count) {
00125 case 0:
00126 break;
00127 case 1:
00128 ret = chars.at(0);
00129 break;
00130 default:
00131 qimsysWarning() << chars;
00132 }
00133 return ret;
00134 }
00135 }
00136 #endif // Q2X_H