File indexing completed on 2024-05-05 17:41:53
0001 /* 0002 SPDX-FileCopyrightText: 2000 Matthias Hölzer-Klüpfel <hoelzer@kde.org> 0003 SPDX-FileCopyrightText: 2014 Frederik Gladhorn <gladhorn@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include "kaccess.h" 0009 0010 #include <KAboutData> 0011 #include <KLocalizedString> 0012 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0013 #include <Kdelibs4ConfigMigrator> 0014 #endif 0015 #include <QApplication> 0016 #include <QDebug> 0017 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0018 #include <QX11Info> 0019 #else 0020 #include <QtGui/private/qtx11extras_p.h> 0021 #endif 0022 0023 int main(int argc, char *argv[]) 0024 { 0025 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0026 Kdelibs4ConfigMigrator migrate(QStringLiteral("kaccess")); 0027 migrate.setConfigFiles(QStringList() << QStringLiteral("kaccessrc")); 0028 migrate.migrate(); 0029 #endif 0030 0031 qunsetenv("SESSION_MANAGER"); 0032 0033 // this application is currently only relevant on X, force to run under X 0034 // note if someone does port this we still need to run kaccess under X for xwayland apps 0035 qputenv("QT_QPA_PLATFORM", "xcb"); 0036 0037 // verify the Xlib has matching XKB extension 0038 int major = XkbMajorVersion; 0039 int minor = XkbMinorVersion; 0040 if (!XkbLibraryVersion(&major, &minor)) { 0041 qWarning() << "Xlib XKB extension does not match"; 0042 return 1; 0043 } 0044 qDebug() << "Xlib XKB extension major=" << major << " minor=" << minor; 0045 0046 // we need an application object for QX11Info 0047 QApplication app(argc, argv); 0048 0049 KAboutData about(QStringLiteral("kaccess"), QString(), i18n("Accessibility"), {}, KAboutLicense::GPL_V2, i18n("(c) 2000, Matthias Hoelzer-Kluepfel")); 0050 0051 about.addAuthor(i18n("Matthias Hoelzer-Kluepfel"), i18n("Author"), QStringLiteral("hoelzer@kde.org")); 0052 // set data as used for D-Bus by KAccessApp 0053 KAboutData::setApplicationData(about); 0054 0055 KAccessApp acc; 0056 if (acc.isFailed()) { 0057 return 1; 0058 } 0059 0060 // verify the X server has matching XKB extension 0061 // if yes, the XKB extension is initialized 0062 int opcode_rtrn; 0063 int error_rtrn; 0064 int xkb_opcode; 0065 if (!XkbQueryExtension(QX11Info::display(), &opcode_rtrn, &xkb_opcode, &error_rtrn, &major, &minor)) { 0066 qWarning() << "X server has not matching XKB extension" << Qt::endl; 0067 return 1; 0068 } 0069 qDebug() << "X server XKB extension major=" << major << " minor=" << minor; 0070 0071 app.installNativeEventFilter(&acc); 0072 0073 // Without that, the application dies when the dialog is closed only once. 0074 app.setQuitOnLastWindowClosed(false); 0075 0076 acc.setXkbOpcode(xkb_opcode); 0077 return app.exec(); 0078 }