File indexing completed on 2024-04-28 05:33:06
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 #include <QApplication> 0013 #include <QDebug> 0014 #include <QtGui/private/qtx11extras_p.h> 0015 0016 int main(int argc, char *argv[]) 0017 { 0018 qunsetenv("SESSION_MANAGER"); 0019 0020 // this application is currently only relevant on X, force to run under X 0021 // note if someone does port this we still need to run kaccess under X for xwayland apps 0022 qputenv("QT_QPA_PLATFORM", "xcb"); 0023 0024 // verify the Xlib has matching XKB extension 0025 int major = XkbMajorVersion; 0026 int minor = XkbMinorVersion; 0027 if (!XkbLibraryVersion(&major, &minor)) { 0028 qWarning() << "Xlib XKB extension does not match"; 0029 return 1; 0030 } 0031 qDebug() << "Xlib XKB extension major=" << major << " minor=" << minor; 0032 0033 // we need an application object for QX11Info 0034 QApplication app(argc, argv); 0035 0036 KAboutData about(QStringLiteral("kaccess"), QString(), i18n("Accessibility"), {}, KAboutLicense::GPL_V2, i18n("(c) 2000, Matthias Hoelzer-Kluepfel")); 0037 0038 about.addAuthor(i18n("Matthias Hoelzer-Kluepfel"), i18n("Author"), QStringLiteral("hoelzer@kde.org")); 0039 about.setDesktopFileName(QStringLiteral("kaccess")); 0040 // set data as used for D-Bus by KAccessApp 0041 KAboutData::setApplicationData(about); 0042 0043 KAccessApp acc; 0044 if (acc.isFailed()) { 0045 return 1; 0046 } 0047 0048 // verify the X server has matching XKB extension 0049 // if yes, the XKB extension is initialized 0050 int opcode_rtrn; 0051 int error_rtrn; 0052 int xkb_opcode; 0053 if (!XkbQueryExtension(QX11Info::display(), &opcode_rtrn, &xkb_opcode, &error_rtrn, &major, &minor)) { 0054 qWarning() << "X server has not matching XKB extension" << Qt::endl; 0055 return 1; 0056 } 0057 qDebug() << "X server XKB extension major=" << major << " minor=" << minor; 0058 0059 app.installNativeEventFilter(&acc); 0060 0061 // Without that, the application dies when the dialog is closed only once. 0062 app.setQuitOnLastWindowClosed(false); 0063 0064 acc.setXkbOpcode(xkb_opcode); 0065 return app.exec(); 0066 }