From e0ad6704e27397e07ac3ad15a8feb8ab0e4e65e4 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 18 Dec 2011 12:18:21 +0200 Subject: [PATCH] cosmetic renames; better X11Event dumper --- src/jrugr.cpp | 45 ++++++++++++++++++++++++++------------------ src/jrugrconfui.cpp | 12 ++++++------ src/x11tools.cpp | 54 +++++++++++++++++++++++++++++++++-------------------- src/x11tools.h | 6 ++++-- 4 files changed, 71 insertions(+), 46 deletions(-) diff --git a/src/jrugr.cpp b/src/jrugr.cpp index 9b988b8..8be808c 100644 --- a/src/jrugr.cpp +++ b/src/jrugr.cpp @@ -86,7 +86,7 @@ void Jrugr::setStartup () { jrugr.beginGroup("Style"); mLangThemePath = jrugr.value("path").toString()+"/language/"; jrugr.endGroup(); //Style - jCfg = X11tools::loadXKBconf(); + jCfg = X11Tools::loadXKBconf(); mTrayIcon = new QSystemTrayIcon(this); //loadRules(); qDebug() << "Use next status:" << mStatNames.value(jCfg->status); @@ -127,22 +127,6 @@ bool Jrugr::firstStart () { } -bool Jrugr::x11EventFilter (XEvent *event) { - //qDebug() << "Jrugr::x11EventFilter:" << mX11EventNames[event->type]; - switch (event->type) { - case FocusIn: - qDebug() << "FocusIn:" << (int)(event->xfocus.window); - break; - case PropertyNotify: - qDebug() << "PropertyNotify:" << (int)(event->xproperty.window); - default: - mXkb->processEvent(event); - return false; - } - return false; -} - - void Jrugr::init () { mXkb->groupInfo(mGroupInfo); if (jCfg->status == DONT_USE_XKB) return; @@ -313,7 +297,7 @@ void Jrugr::createMenu () { void Jrugr::reconfigure () { - JrugrCfg *newConf = X11tools::loadXKBconf(); + JrugrCfg *newConf = X11Tools::loadXKBconf(); QXkbLayoutList nl; mXkb->groupInfo(nl); bool diffGI = nl.size() != mGroupInfo.size(); @@ -409,3 +393,28 @@ void Jrugr::configure () { } mCfgForm->exec(); } + + +bool Jrugr::x11EventFilter (XEvent *event) { + //qDebug() << "Jrugr::x11EventFilter:" << mX11EventNames[event->type]; + switch (event->type) { + case FocusIn: + case FocusOut: + qDebug() << mX11EventNames[event->type] << (int)(event->xfocus.window) << + "class:" << X11Tools::windowClass(event->xfocus.window) << + "name:" << X11Tools::windowName(event->xfocus.window) << + "pid:" << X11Tools::windowPID(event->xfocus.window); + break; + case PropertyNotify: + qDebug() << "PropertyNotify:" << (int)(event->xproperty.window) << + "class:" << X11Tools::windowClass(event->xproperty.window) << + "name:" << X11Tools::windowName(event->xproperty.window) << + "pid:" << X11Tools::windowPID(event->xproperty.window) << + "atom:" << X11Tools::atomName(event->xproperty.atom) << + "action:" << (event->xproperty.state == PropertyNewValue ? "changed" : "deleted"); + default: + mXkb->processEvent(event); + return false; + } + return false; +} diff --git a/src/jrugrconfui.cpp b/src/jrugrconfui.cpp index 91dfa93..b672355 100644 --- a/src/jrugrconfui.cpp +++ b/src/jrugrconfui.cpp @@ -19,7 +19,7 @@ JrugrConfigForm::JrugrConfigForm (QWidget *parent) : QDialog(parent) { qDebug() << "Theme " << mTheme; qDebug() << "Icons " << mIcoPath; // - mJCfg = X11tools::loadXKBconf(); + mJCfg = X11Tools::loadXKBconf(); // connect(cfgUI.buttonBox, SIGNAL(rejected()), this, SLOT(close())); connect(cfgUI.buttonBox, SIGNAL(accepted()), SLOT(apply())); @@ -51,7 +51,7 @@ JrugrConfigForm::~JrugrConfigForm () { void JrugrConfigForm::apply () { - X11tools::saveXKBconf(mJCfg); + X11Tools::saveXKBconf(mJCfg); // if (cfgUI.stackedWidget->currentIndex() == 0 && mJCfg->status == USE_XKB) { QStringList parm = cfgUI.editCmdLine->text().split(" "); @@ -241,7 +241,7 @@ void JrugrConfigForm::dstClick () { if (row == -1) return; QString layout = mJCfg->layouts[row].layout; qDebug() << layout; - mVariants = X11tools::getVariants(layout, X11tools::findX11Dir()); + mVariants = X11Tools::getVariants(layout, X11Tools::findX11Dir()); qDebug() << "JrugrConfigForm:addItem"; if (cfgUI.comboVariant->count() == 0) { cfgUI.comboVariant->addItem(tr("Default"), "Default"); @@ -265,11 +265,11 @@ void JrugrConfigForm::dstClick () { bool JrugrConfigForm::loadRules () { - QString x11dir = X11tools::findX11Dir(); + QString x11dir = X11Tools::findX11Dir(); if (x11dir.isNull() || x11dir.isEmpty()) return false; - QString rulesFile = X11tools::findXkbRulesFile(x11dir, QX11Info::display()); + QString rulesFile = X11Tools::findXkbRulesFile(x11dir, QX11Info::display()); if (rulesFile.isNull() || rulesFile.isEmpty()) return false; - mCurRule = X11tools::loadRules(rulesFile, false); + mCurRule = X11Tools::loadRules(rulesFile, false); if (mCurRule == NULL) return false; return true; } diff --git a/src/x11tools.cpp b/src/x11tools.cpp index dad62e3..0212e91 100644 --- a/src/x11tools.cpp +++ b/src/x11tools.cpp @@ -109,7 +109,7 @@ static QString getStrProp (Window w, Atom qAtom) { //////////////////////////////////////////////////////////////////////////////// -const QString X11tools::findX11Dir () { +const QString X11Tools::findX11Dir () { /* find directory whith xkb config files */ for (int f = 0; f < X11_DIR_COUNT; ++f) { const char *xDir = X11DirList[f]; @@ -119,7 +119,7 @@ const QString X11tools::findX11Dir () { } -const QString X11tools::findXkbRulesFile (const QString &x11Dir, Display *dpy) { +const QString X11Tools::findXkbRulesFile (const QString &x11Dir, Display *dpy) { QString rulesFile; XkbRF_VarDefsRec vd; char *tmp = NULL; @@ -143,10 +143,10 @@ const QString X11tools::findXkbRulesFile (const QString &x11Dir, Display *dpy) { /* load the list of languages, keybord layouts and option supported by xkb extension X Server and save into hash table */ -RulesInfo *X11tools::loadRules (const QString &file, bool layoutsOnly) { +RulesInfo *X11Tools::loadRules (const QString &file, bool layoutsOnly) { XkbRF_RulesPtr xkbRules = XkbRF_Load(QFile::encodeName(file).data(), (char *)"", true, true); // - qDebug() << " X11tools::loadRule "; + qDebug() << " X11Tools::loadRule "; if (xkbRules == NULL) return 0; // throw Exception // try to translate layout names by countries in desktop_kdebase // this is poor man's translation as it's good only for layout names and only those which match country names @@ -200,7 +200,7 @@ RulesInfo *X11tools::loadRules (const QString &file, bool layoutsOnly) { } -XkbOptionGroup X11tools::createMissingGroup (const QString &groupName) { +XkbOptionGroup X11Tools::createMissingGroup (const QString &groupName) { // workaround for empty 'compose' options group description XkbOptionGroup optionGroup; optionGroup.name = groupName; @@ -210,7 +210,7 @@ XkbOptionGroup X11tools::createMissingGroup (const QString &groupName) { } -bool X11tools::isGroupExclusive (const QString &groupName) { +bool X11Tools::isGroupExclusive (const QString &groupName) { return groupName == "ctrl" || groupName == "keypad" || groupName == "nbsp" || groupName == "kpdl" || groupName == "caps" || groupName == "altwin"; @@ -220,7 +220,7 @@ bool X11tools::isGroupExclusive (const QString &groupName) { /* pretty simple algorithm - reads the layout file and * tries to find "xkb_symbols" * also checks whether previous line contains "hidden" to skip it */ -QList X11tools::getVariants (const QString &layout, const QString &x11Dir) { +QList X11Tools::getVariants (const QString &layout, const QString &x11Dir) { QList result; // QString file = x11Dir+"xkb/symbols/"; @@ -263,7 +263,7 @@ QList X11tools::getVariants (const QString &layout, const QString &x } -JrugrCfg X11tools::groupNames (Display *dpy) { +JrugrCfg X11Tools::groupNames (Display *dpy) { Atom real_prop_type; int fmt; unsigned long nitems, extra_bytes; @@ -275,20 +275,20 @@ JrugrCfg X11tools::groupNames (Display *dpy) { /* no such atom! */ if (rules_atom == None) { /* property cannot exist */ - qCritical() << "X11tools:Failed to fetch layouts from server:" << "could not find the atom" << _XKB_RF_NAMES_PROP_ATOM; + qCritical() << "X11Tools:Failed to fetch layouts from server:" << "could not find the atom" << _XKB_RF_NAMES_PROP_ATOM; return xkbConfig; } // ret = XGetWindowProperty(dpy, QX11Info::appRootWindow(), rules_atom, 0L, _XKB_RF_NAMES_PROP_MAXLEN, False, XA_STRING, &real_prop_type, &fmt, &nitems, &extra_bytes, (unsigned char **)(void *)&prop_data); /* property not found! */ if (ret != Success) { - qCritical() << "X11tools:Failed to fetch layouts from server:" << "Could not get the property"; + qCritical() << "X11Tools:Failed to fetch layouts from server:" << "Could not get the property"; return xkbConfig; } /* has to be array of strings */ if (extra_bytes > 0 || real_prop_type != XA_STRING || fmt != 8) { if (prop_data) XFree(prop_data); - qCritical() << "X11tools:Failed to fetch layouts from server:" << "Wrong property format"; + qCritical() << "X11Tools:Failed to fetch layouts from server:" << "Wrong property format"; return xkbConfig; } // @@ -312,13 +312,13 @@ JrugrCfg X11tools::groupNames (Display *dpy) { lu.layout = layouts[f]; lu.variant = f < variants.count() ? variants[f] : ""; xkbConfig.layouts << lu; - qDebug() << "X11tools:layout nm:" << lu.layout << "variant:" << lu.variant; + qDebug() << "X11Tools:layout nm:" << lu.layout << "variant:" << lu.variant; } // if (names.count() >= 5) { QString options = names[4]; xkbConfig.options = options.split(OPTIONS_SEPARATOR); - qDebug() << "X11tools:options:" << options; + qDebug() << "X11Tools:options:" << options; } } // @@ -327,7 +327,7 @@ JrugrCfg X11tools::groupNames (Display *dpy) { } -JrugrCfg *X11tools::loadXKBconf () { +JrugrCfg *X11Tools::loadXKBconf () { JrugrCfg *Conf = new JrugrCfg(); LayoutUnit lu; QSettings jrugr(QDir::homePath()+"/.config/jrugr.cfg", QSettings::IniFormat); @@ -360,7 +360,7 @@ JrugrCfg *X11tools::loadXKBconf () { } -void X11tools::saveXKBconf (JrugrCfg *conf) { +void X11Tools::saveXKBconf (JrugrCfg *conf) { LayoutUnit lu; QSettings jrugr(QDir::homePath() + "/.config/jrugr.cfg", QSettings::IniFormat); jrugr.beginGroup("KeyLayout"); @@ -388,7 +388,21 @@ void X11tools::saveXKBconf (JrugrCfg *conf) { //////////////////////////////////////////////////////////////////////////////// -Window X11tools::activeWindow () { +QString X11Tools::atomName (Atom atom) { + char *an; + QString res; + // + if (atom == None) return res; + an = XGetAtomName(QX11Info::display(), atom); + if (an == NULL) return res; + res = QString::fromLatin1(an); + XFree(an); + return res; +} + + +//////////////////////////////////////////////////////////////////////////////// +Window X11Tools::activeWindow () { Atom aType; int format; unsigned long itemCount; @@ -412,7 +426,7 @@ Window X11tools::activeWindow () { } -QString X11tools::windowClass (Window w) { +QString X11Tools::windowClass (Window w) { static Atom atomWC = None; // if (atomWC == None) atomWC = XInternAtom(QX11Info::display(), "WM_CLASS", True); @@ -420,7 +434,7 @@ QString X11tools::windowClass (Window w) { } -QString X11tools::windowName (Window w) { +QString X11Tools::windowName (Window w) { static Atom atomNVN = None, atomNN = None, atomWN = None; QString res; // @@ -437,7 +451,7 @@ QString X11tools::windowName (Window w) { } -pid_t X11tools::windowPID (Window w) { +pid_t X11Tools::windowPID (Window w) { Atom aType; int format; unsigned long itemCount; @@ -461,7 +475,7 @@ pid_t X11tools::windowPID (Window w) { } -QX11WindowList X11tools::topLevelWindows () { +QX11WindowList X11Tools::topLevelWindows () { Atom aType; int format; unsigned long itemCount, bytesAfter; diff --git a/src/x11tools.h b/src/x11tools.h index 4b9ae4a..56588fb 100644 --- a/src/x11tools.h +++ b/src/x11tools.h @@ -110,9 +110,9 @@ public: typedef QList QX11WindowList; -class X11tools { +class X11Tools { public: - X11tools () {} + X11Tools () {} static const QString findX11Dir (); static const QString findXkbRulesFile (const QString &x11Dir, Display *dpy); @@ -122,6 +122,8 @@ public: static JrugrCfg *loadXKBconf (); static void saveXKBconf (JrugrCfg *conf); + static QString atomName (Atom atom); + static Window activeWindow (); static QString windowClass (Window w); -- 2.11.4.GIT