diff --git a/CMakeLists.txt b/CMakeLists.txt index a190b3800..98dc45fff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,525 +1,522 @@ project(KWIN) cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) set(QT_MIN_VERSION "5.2.0") # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked # TODO: this includes the cmake modules from kde-workspace. Need to move those to KWin set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules ${CMAKE_MODULE_PATH} ) find_package(ECM 0.0.11 REQUIRED NO_MODULE) include(FeatureSummary) include(WriteBasicConfigVersionFile) # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings) include(ECMInstallIcons) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Concurrent Core DBus Quick Script Test UiTools Widgets X11Extras ) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0) # required frameworks by Core find_package(KF5 CONFIG REQUIRED COMPONENTS Config ConfigWidgets CoreAddons Crash GlobalAccel I18n Notifications Service Plasma WidgetsAddons WindowSystem ) # required frameworks by config modules find_package(KF5 CONFIG REQUIRED COMPONENTS Completion KCMUtils KIO NewStuff XmlGui ) # optional frameworks find_package(KF5 CONFIG COMPONENTS Activities) # TODO: remove once the build system is completely cleaned find_package(KF5KDE4Support REQUIRED NO_MODULE) # HACK: remove after split if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") # screensaver and ksmserver dbus interface - find_package(KSMServerDBusInterface CONFIG REQUIRED) find_package(ScreenSaverDBusInterface CONFIG REQUIRED) else() - set(KSMSERVER_DBUS_INTERFACE ${ksmserver_SOURCE_DIR}/org.kde.KSMServerInterface.xml) set(SCREENSAVER_DBUS_INTERFACE ${ksmserver_SOURCE_DIR}/screenlocker/dbus/org.freedesktop.ScreenSaver.xml) endif() if(${Qt5Gui_OPENGL_IMPLEMENTATION} STREQUAL "GL") find_package(OpenGL) set_package_properties(OpenGL PROPERTIES DESCRIPTION "The OpenGL libraries" URL "http://www.opengl.org" TYPE REQUIRED ) else() find_package(OpenGLES) set_package_properties(OpenGLES PROPERTIES DESCRIPTION "The OpenGLES libraries" URL "http://www.khronos.org/opengles" TYPE REQUIRED ) endif() find_package(EGL) set_package_properties(EGL PROPERTIES TYPE REQUIRED PURPOSE "Required to build KWin with EGL support" ) find_package(Wayland 1.2 COMPONENTS Client Egl Cursor) set_package_properties(Wayland PROPERTIES TYPE OPTIONAL PURPOSE "Required for building KWin with Wayland support" ) add_feature_info("Wayland-Client" Wayland_Client_FOUND "Required for building the Wayland backend in KWin") add_feature_info("Wayland-EGL" Wayland_Egl_FOUND "Required for building the Wayland EGL compositing backend in KWin") find_package(XKB) set_package_properties(XKB PROPERTIES TYPE OPTIONAL PURPOSE "Required for building KWin with Wayland support" ) find_package(X11) set_package_properties(X11 PROPERTIES DESCRIPTION "X11 libraries" URL "http://www.x.org" TYPE REQUIRED ) # All the required XCB components find_package(XCB REQUIRED COMPONENTS XCB XFIXES DAMAGE COMPOSITE SHAPE SYNC RENDER RANDR KEYSYMS IMAGE SHM XTEST ) set_package_properties(XCB PROPERTIES TYPE REQUIRED) # and the optional XCB dependencies find_package(XCB COMPONENTS ICCCM) add_feature_info("XCB-ICCCM" XCB_ICCCM_FOUND "Required for building test applications for KWin") if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) endif() ########### configure tests ############### include(CMakeDependentOption) option(KWIN_BUILD_DECORATIONS "Enable building of KWin decorations." ON) option(KWIN_BUILD_OXYGEN "Enable building of default decoration Oxygen" ON) option(KWIN_BUILD_KCMS "Enable building of KWin configuration modules." ON) option(KWIN_BUILD_TABBOX "Enable building of KWin Tabbox functionality" ON) option(KWIN_BUILD_SCREENEDGES "Enable building of KWin with screen edge support" ON) option(KWIN_BUILD_KAPPMENU "Enable building of KWin with application menu support" ON) option(KWIN_BUILD_XRENDER_COMPOSITING "Enable building of KWin with XRender Compositing support" ON) cmake_dependent_option(KWIN_BUILD_ACTIVITIES "Enable building of KWin with kactivities support" ON "KF5Activities_FOUND" OFF) option(KWIN_PLASMA_ACTIVE "Enable building KWin for Plasma Active." OFF) # Binary name of KWin set(KWIN_NAME "kwin") set(KWIN_VERSION_MAJOR 4) set(KWIN_VERSION_MINOR 90) set(KWIN_VERSION_PATCH 1) set(KWIN_VERSION ${KWIN_VERSION_MAJOR}.${KWIN_VERSION_MINOR}.${KWIN_VERSION_PATCH} ) set(KWIN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(GENERIC_LIB_SOVERSION ${KWIN_VERSION_MAJOR}) set(GENERIC_LIB_VERSION "${KWIN_VERSION_MAJOR}.${KWIN_VERSION_MINOR}.${KWIN_VERSION_PATCH}") if(KWIN_PLASMA_ACTIVE) set(KWIN_BUILD_DECORATIONS OFF) set(KWIN_BUILD_KCMS OFF) set(KWIN_BUILD_SCREENEDGES OFF) set(KWIN_BUILD_XRENDER_COMPOSITING OFF) set(KWIN_BUILD_WITH_OPENGLES ON) set(KWIN_NAME "kwinactive") endif() cmake_dependent_option(KWIN_BUILD_KAPPMENU "Build without appmenu support" ON "KWIN_BUILD_DECORATIONS" FALSE) set(KWIN_BUILD_OPENGL FALSE) set(KWIN_BUILD_OPENGLES FALSE) if(OPENGL_FOUND AND (${Qt5Gui_OPENGL_IMPLEMENTATION} STREQUAL "GL")) set(KWIN_BUILD_OPENGL TRUE) message("Building KWin with OpenGL support") endif() if(OPENGLES_FOUND AND (${Qt5Gui_OPENGL_IMPLEMENTATION} STREQUAL "GLESv2")) set(KWIN_BUILD_OPENGLES TRUE) message("Building KWin with OpenGL ES 2 support") endif() if(NOT KWIN_BUILD_OPENGL AND NOT KWIN_BUILD_OPENGLES) message(FATAL_ERROR "KWin needs to be built against either OpenGL or OpenGL ES 2. Check your Qt config!") endif() # KWIN_HAVE_XRENDER_COMPOSITING - whether XRender-based compositing support is available: may be disabled if( KWIN_BUILD_XRENDER_COMPOSITING ) set( KWIN_HAVE_XRENDER_COMPOSITING 1 ) endif() if(KWIN_BUILD_OPENGL) include_directories(${OPENGL_INCLUDE_DIR}) endif() set(KWIN_HAVE_EGL ${EGL_FOUND}) if(KWIN_BUILD_OPENGLES) include_directories(${OPENGLES_INCLUDE_DIR}) endif() # for things that are also used by kwin libraries configure_file(libkwineffects/kwinconfig.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/libkwineffects/kwinconfig.h ) # for kwin internal things if(Wayland_Client_FOUND AND XKB_FOUND) set(HAVE_WAYLAND ${Wayland_Client_FOUND}) set(HAVE_XKB ${XKB_FOUND}) set(HAVE_WAYLAND_EGL ${Wayland_Egl_FOUND}) else() set(HAVE_WAYLAND FALSE) set(HAVE_XKB FALSE) set(HAVE_WAYLAND_EGL FALSE) endif() include(CheckIncludeFiles) check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(malloc.h HAVE_MALLOC_H) configure_file(config-kwin.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kwin.h ) ########### global ############### set(kwin_effects_dbus_xml ${CMAKE_CURRENT_SOURCE_DIR}/org.kde.kwin.Effects.xml) include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/libkdecorations ${CMAKE_CURRENT_BINARY_DIR}/libkwineffects ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libkwineffects ${CMAKE_CURRENT_SOURCE_DIR}/libkdecorations ${CMAKE_CURRENT_SOURCE_DIR}/effects ${CMAKE_CURRENT_SOURCE_DIR}/tabbox ) add_subdirectory( libkdecorations ) add_subdirectory( libkwineffects ) add_subdirectory( killer ) if(KWIN_BUILD_KCMS) add_subdirectory( kcmkwin ) endif() if( KWIN_BUILD_DECORATIONS ) add_subdirectory( clients ) endif() add_subdirectory( data ) add_subdirectory( effects ) add_subdirectory( scripts ) add_subdirectory( tabbox ) add_subdirectory(scripting) add_definitions(-DKDE_DEFAULT_DEBUG_AREA=1212) ########### next target ############### set(kwin_KDEINIT_SRCS workspace.cpp dbusinterface.cpp client.cpp client_machine.cpp cursor.cpp tabgroup.cpp focuschain.cpp globalshortcuts.cpp input.cpp netinfo.cpp placement.cpp atoms.cpp utils.cpp layers.cpp main.cpp options.cpp outline.cpp decorations.cpp events.cpp killwindow.cpp geometrytip.cpp screens.cpp shadow.cpp sm.cpp group.cpp bridge.cpp manage.cpp overlaywindow.cpp activation.cpp useractions.cpp geometry.cpp rules.cpp composite.cpp toplevel.cpp unmanaged.cpp scene.cpp scene_xrender.cpp scene_opengl.cpp scene_qpainter.cpp glxbackend.cpp thumbnailitem.cpp lanczosfilter.cpp deleted.cpp effects.cpp compositingprefs.cpp paintredirector.cpp virtualdesktops.cpp xcbutils.cpp scripting/scripting.cpp scripting/workspace_wrapper.cpp scripting/meta.cpp scripting/scriptedeffect.cpp scripting/scriptingutils.cpp scripting/timer.cpp scripting/scripting_model.cpp scripting/dbuscall.cpp scripting/screenedgeitem.cpp ) if(KWIN_BUILD_TABBOX) set( kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} tabbox/tabbox.cpp tabbox/clientmodel.cpp tabbox/desktopchain.cpp tabbox/desktopmodel.cpp tabbox/switcheritem.cpp tabbox/tabboxconfig.cpp tabbox/tabboxhandler.cpp ) endif() if(KWIN_BUILD_SCREENEDGES) set( kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} screenedge.cpp ) endif() if(KWIN_BUILD_KAPPMENU) set( kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} appmenu.cpp ) qt5_add_dbus_interface(kwin_KDEINIT_SRCS ${KDEBASE_WORKSPACE_SOURCE_DIR}/plasma-workspace/appmenu/org.kde.kappmenu.xml appmenu_interface) endif() if(KWIN_BUILD_ACTIVITIES) set( kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} activities.cpp ) endif() if(KWIN_HAVE_EGL) set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} eglonxbackend.cpp) endif() if(Wayland_Client_FOUND AND XKB_FOUND) set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} wayland_backend.cpp) if(KWIN_HAVE_EGL AND Wayland_Egl_FOUND) set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} egl_wayland_backend.cpp) endif() endif() kconfig_add_kcfg_files(kwin_KDEINIT_SRCS settings.kcfgc) qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.KWin.xml dbusinterface.h KWin::DBusInterface ) qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.Compositing.xml composite.h KWin::Compositor ) qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.Effects.xml effects.h KWin::EffectsHandlerImpl ) -qt5_add_dbus_interface( kwin_KDEINIT_SRCS ${KSMSERVER_DBUS_INTERFACE} ksmserver_interface) qt5_add_dbus_interface( kwin_KDEINIT_SRCS ${SCREENSAVER_DBUS_INTERFACE} screenlocker_interface) qt5_add_resources( kwin_KDEINIT_SRCS resources.qrc ) qt5_wrap_ui(kwin_KDEINIT_SRCS shortcutdialog.ui ) ########### target link libraries ############### set(kwin_OWN_LIBS kdecorations kwineffects kwin4_effect_builtins ) set(kwin_QT_LIBS Qt5::Concurrent Qt5::DBus Qt5::Quick Qt5::Script Qt5::X11Extras ) set(kwin_KDE_LIBS KF5::ConfigCore KF5::CoreAddons KF5::ConfigWidgets KF5::Crash KF5::GlobalAccel KF5::I18n KF5::Notifications KF5::Service KF5::Plasma KF5::WindowSystem ) set(kwin_XLIB_LIBS ${X11_X11_LIB} ${X11_Xext_LIB} ${X11_Xcursor_LIB} ${X11_ICE_LIB} ${X11_SM_LIB} ) set(kwin_XCB_LIBS XCB::XCB XCB::XFIXES XCB::DAMAGE XCB::COMPOSITE XCB::SHAPE XCB::SYNC XCB::RENDER XCB::RANDR XCB::KEYSYMS XCB::SHM XCB::XTEST ) set(kwin_WAYLAND_LIBS Wayland::Client Wayland::Cursor XCB::XTEST XKB::XKB ) set(kwin_WAYLAND_EGL_LIBS Wayland::Egl ) set(kwin_OPENGL_LIBS ) find_library(XF86VM_LIBRARY Xxf86vm) if (XF86VM_LIBRARY) set(kwin_XLIB_LIBS ${kwin_XLIB_LIBS} ${XF86VM_LIBRARY}) else() add_definitions(-DKWIN_NO_XF86VM) endif() if(KWIN_BUILD_ACTIVITIES) set(kwin_KDE_LIBS ${kwin_KDE_LIBS} KF5::Activities) endif() if(KWIN_HAVE_EGL) set(kwin_OPENGL_LIBS ${kwin_OPENGL_LIBS} EGL::EGL) endif() set(kwinLibs ${kwin_OWN_LIBS} ${kwin_QT_LIBS} ${kwin_KDE_LIBS} ${kwin_XLIB_LIBS} ${kwin_XCB_LIBS} ${kwin_OPENGL_LIBS} ) if(Wayland_Client_FOUND AND XKB_FOUND) set(kwinLibs ${kwinLibs} ${kwin_WAYLAND_LIBS}) if(KWIN_HAVE_EGL AND Wayland_Egl_FOUND) set(kwinLibs ${kwinLibs} ${kwin_WAYLAND_EGL_LIBS}) endif() endif() kf5_add_kdeinit_executable( kwin ${kwin_KDEINIT_SRCS}) target_link_libraries(kdeinit_kwin ${kwinLibs}) set_target_properties(kwin PROPERTIES OUTPUT_NAME ${KWIN_NAME}) generate_export_header(kdeinit_kwin EXPORT_FILE_NAME kwin_export.h) if(KWIN_BUILD_OPENGL) target_link_libraries(kdeinit_kwin kwinglutils ${OPENGL_gl_LIBRARY}) # -ldl used by OpenGL code find_library(DL_LIBRARY dl) if (DL_LIBRARY) target_link_libraries(kdeinit_kwin ${DL_LIBRARY}) endif() elseif(KWIN_BUILD_OPENGLES) target_link_libraries(kdeinit_kwin ${kwinLibs} kwinglesutils ${OPENGLES_LIBRARIES}) set_target_properties(kdeinit_kwin PROPERTIES COMPILE_FLAGS "-DKWIN_HAVE_OPENGLES") endif() install(TARGETS kdeinit_kwin ${INSTALL_TARGETS_DEFAULT_ARGS} ) install(TARGETS kwin ${INSTALL_TARGETS_DEFAULT_ARGS} ) ########### install files ############### install( FILES kwin.kcfg DESTINATION ${KCFG_INSTALL_DIR} RENAME ${KWIN_NAME}.kcfg ) install( FILES kwin.notifyrc DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME} RENAME ${KWIN_NAME}.notifyrc) install( FILES org.kde.KWin.xml org.kde.kwin.Compositing.xml org.kde.kwin.Effects.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/kwin_export.h DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel) # Install the KWin/Script service type install( FILES scripting/kwinscript.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) ecm_install_icons( ${ICON_INSTALL_DIR} ) add_subdirectory(qml) add_subdirectory(autotests) add_subdirectory(tests) configure_file(KWinDBusInterfaceConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/KWinDBusInterfaceConfig.cmake" @ONLY) set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KWinDBusInterface") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/KWinDBusInterfaceConfig.cmake DESTINATION ${CMAKECONFIG_INSTALL_DIR}) diff --git a/main.cpp b/main.cpp index 327dda449..fe50176b0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,565 +1,559 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 1999, 2000 Matthias Ettrich Copyright (C) 2003 Lubos Lunak This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "main.h" #include // kwin #include "atoms.h" #include "options.h" #include "sm.h" #include "workspace.h" #include "xcbutils.h" -// KDE workspace -#include - // KDE #include #include #include #include #include #include // Qt #include #include #include #include #include #include #include #include #include #include #include #include #include // TODO: remove once QX11Info provides the X screen #include // system #ifdef HAVE_UNISTD_H #include #endif // HAVE_UNISTD_H #ifdef HAVE_MALLOC_H #include #endif // HAVE_MALLOC_H namespace KWin { Options* options; Atoms* atoms; int screen_number = -1; bool is_multihead = false; //************************************ // KWinSelectionOwner //************************************ KWinSelectionOwner::KWinSelectionOwner(int screen_P) : KSelectionOwner(make_selection_atom(screen_P), screen_P) { } xcb_atom_t KWinSelectionOwner::make_selection_atom(int screen_P) { if (screen_P < 0) screen_P = DefaultScreen(display()); QByteArray screen(QByteArrayLiteral("WM_S")); screen.append(QByteArray::number(screen_P)); ScopedCPointer atom(xcb_intern_atom_reply( connection(), xcb_intern_atom_unchecked(connection(), false, screen.length(), screen.constData()), nullptr)); if (atom.isNull()) { return XCB_ATOM_NONE; } return atom->atom; } void KWinSelectionOwner::getAtoms() { KSelectionOwner::getAtoms(); if (xa_version == XCB_ATOM_NONE) { const QByteArray name(QByteArrayLiteral("VERSION")); ScopedCPointer atom(xcb_intern_atom_reply( connection(), xcb_intern_atom_unchecked(connection(), false, name.length(), name.constData()), nullptr)); if (!atom.isNull()) { xa_version = atom->atom; } } } void KWinSelectionOwner::replyTargets(xcb_atom_t property_P, xcb_window_t requestor_P) { KSelectionOwner::replyTargets(property_P, requestor_P); xcb_atom_t atoms[ 1 ] = { xa_version }; // PropModeAppend ! xcb_change_property(connection(), XCB_PROP_MODE_APPEND, requestor_P, property_P, XCB_ATOM_ATOM, 32, 1, atoms); } bool KWinSelectionOwner::genericReply(xcb_atom_t target_P, xcb_atom_t property_P, xcb_window_t requestor_P) { if (target_P == xa_version) { int32_t version[] = { 2, 0 }; xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, requestor_P, property_P, XCB_ATOM_INTEGER, 32, 2, version); } else return KSelectionOwner::genericReply(target_P, property_P, requestor_P); return true; } xcb_atom_t KWinSelectionOwner::xa_version = XCB_ATOM_NONE; class AlternativeWMDialog : public QDialog { public: AlternativeWMDialog() : QDialog() { QWidget* mainWidget = new QWidget(this); QVBoxLayout* layout = new QVBoxLayout(mainWidget); QString text = i18n( "KWin is unstable.\n" "It seems to have crashed several times in a row.\n" "You can select another window manager to run:"); QLabel* textLabel = new QLabel(text, mainWidget); layout->addWidget(textLabel); wmList = new QComboBox(mainWidget); wmList->setEditable(true); layout->addWidget(wmList); addWM(QStringLiteral("metacity")); addWM(QStringLiteral("openbox")); addWM(QStringLiteral("fvwm2")); addWM(QStringLiteral(KWIN_NAME)); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(mainWidget); QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); buttons->button(QDialogButtonBox::Ok)->setDefault(true); connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); mainLayout->addWidget(buttons); raise(); } void addWM(const QString& wm) { // TODO: Check if WM is installed if (!QStandardPaths::findExecutable(wm).isEmpty()) wmList->addItem(wm); } QString selectedWM() const { return wmList->currentText(); } private: QComboBox* wmList; }; int Application::crashes = 0; Application::Application(int &argc, char **argv) : QApplication(argc, argv) , owner() , m_eventFilter(new XcbEventFilter()) , m_replace(false) , m_configLock(false) , m_operationMode(OperationModeX11) { } void Application::setConfigLock(bool lock) { m_configLock = lock; } void Application::setReplace(bool replace) { m_replace = replace; } Application::OperationMode Application::operationMode() const { return m_operationMode; } void Application::setOperationMode(OperationMode mode) { m_operationMode = mode; } bool Application::shouldUseWaylandForCompositing() const { return m_operationMode == OperationModeWaylandAndX11; } bool Application::requiresCompositing() const { return shouldUseWaylandForCompositing(); } void Application::start() { setQuitOnLastWindowClosed(false); KSharedConfig::Ptr config = KSharedConfig::openConfig(); if (!config->isImmutable() && m_configLock) { // TODO: This shouldn't be necessary //config->setReadOnly( true ); config->reparseConfiguration(); } if (screen_number == -1) screen_number = QX11Info::appScreen(); owner.reset(new KWinSelectionOwner(screen_number)); connect(owner.data(), &KSelectionOwner::failedToClaimOwnership, []{ fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").toLocal8Bit().constData(), stderr); ::exit(1); }); connect(owner.data(), SIGNAL(lostOwnership()), SLOT(lostSelection())); connect(owner.data(), &KSelectionOwner::claimedOwnership, [this]{ // we want all QQuickWindows with an alpha buffer QQuickWindow::setDefaultAlphaBuffer(true); installNativeEventFilter(m_eventFilter.data()); // first load options - done internally by a different thread options = new Options; // Check whether another windowmanager is running const uint32_t maskValues[] = {XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT}; ScopedCPointer redirectCheck(xcb_request_check(connection(), xcb_change_window_attributes_checked(connection(), rootWindow(), XCB_CW_EVENT_MASK, maskValues))); if (!redirectCheck.isNull()) { fputs(i18n("kwin: another window manager is running (try using --replace)\n").toLocal8Bit().constData(), stderr); ::exit(1); } atoms->retrieveHelpers(); // This tries to detect compositing options and can use GLX. GLX problems // (X errors) shouldn't cause kwin to abort, so this is out of the // critical startup section where x errors cause kwin to abort. // create workspace. (void) new Workspace(isSessionRestored()); Xcb::sync(); // Trigger possible errors, there's still a chance to abort // Tell KSplash that KWin has started QDBusMessage ksplashProgressMessage = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KSplash"), QStringLiteral("/KSplash"), QStringLiteral("org.kde.KSplash"), QStringLiteral("setStage")); ksplashProgressMessage.setArguments(QList() << QStringLiteral("wm")); QDBusConnection::sessionBus().asyncCall(ksplashProgressMessage); }); crashChecking(); // we need to do an XSync here, otherwise the QPA might crash us later on Xcb::sync(); owner->claim(m_replace, true); atoms = new Atoms; } Application::~Application() { delete Workspace::self(); if (!owner.isNull() && owner->ownerWindow() != XCB_WINDOW_NONE) // If there was no --replace (no new WM) Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT); delete options; delete atoms; } void Application::crashChecking() { KCrash::setEmergencySaveFunction(Application::crashHandler); if (crashes >= 4) { // Something has gone seriously wrong AlternativeWMDialog dialog; QString cmd = QStringLiteral(KWIN_NAME); if (dialog.exec() == QDialog::Accepted) cmd = dialog.selectedWM(); else ::exit(1); if (cmd.length() > 500) { qDebug() << "Command is too long, truncating"; cmd = cmd.left(500); } qDebug() << "Starting" << cmd << "and exiting"; char buf[1024]; sprintf(buf, "%s &", cmd.toAscii().data()); system(buf); ::exit(1); } if (crashes >= 2) { // Disable compositing if we have had too many crashes qDebug() << "Too many crashes recently, disabling compositing"; KConfigGroup compgroup(KSharedConfig::openConfig(), "Compositing"); compgroup.writeEntry("Enabled", false); } // Reset crashes count if we stay up for more that 15 seconds QTimer::singleShot(15 * 1000, this, SLOT(resetCrashesCount())); } void Application::lostSelection() { sendPostedEvents(); delete Workspace::self(); // Remove windowmanager privileges Xcb::selectInput(rootWindow(), XCB_EVENT_MASK_PROPERTY_CHANGE); quit(); } bool Application::notify(QObject* o, QEvent* e) { if (Workspace::self()->workspaceEvent(e)) return true; return QApplication::notify(o, e); } static void sighandler(int) { QApplication::exit(); } void Application::crashHandler(int signal) { crashes++; fprintf(stderr, "Application::crashHandler() called with signal %d; recent crashes: %d\n", signal, crashes); char cmd[1024]; sprintf(cmd, "%s --crashes %d &", QFile::encodeName(QCoreApplication::applicationFilePath()).constData(), crashes); sleep(1); system(cmd); } void Application::resetCrashesCount() { crashes = 0; } void Application::setCrashCount(int count) { crashes = count; } bool Application::wasCrash() { return crashes > 0; } bool XcbEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long int *result) { Q_UNUSED(result) if (!Workspace::self()) { // Workspace not yet created return false; } if (eventType != "xcb_generic_event_t") { return false; } return Workspace::self()->workspaceEvent(static_cast(message)); } } // namespace static const char version[] = KWIN_VERSION_STRING; static const char description[] = I18N_NOOP("KDE window manager"); extern "C" KWIN_EXPORT int kdemain(int argc, char * argv[]) { #ifdef M_TRIM_THRESHOLD // Prevent fragmentation of the heap by malloc (glibc). // // The default threshold is 128*1024, which can result in a large memory usage // due to fragmentation especially if we use the raster graphicssystem. On the // otherside if the threshold is too low, free() starts to permanently ask the kernel // about shrinking the heap. #ifdef HAVE_UNISTD_H const int pagesize = sysconf(_SC_PAGESIZE); #else const int pagesize = 4*1024; #endif // HAVE_UNISTD_H mallopt(M_TRIM_THRESHOLD, 5*pagesize); #endif // M_TRIM_THRESHOLD QLoggingCategory::setFilterRules(QStringLiteral("aurorae.debug = true\n") + QStringLiteral("kwineffects.debug = true")); int primaryScreen = 0; xcb_connection_t *c = xcb_connect(nullptr, &primaryScreen); if (!c || xcb_connection_has_error(c)) { fprintf(stderr, "%s: FATAL ERROR while trying to open display %s\n", argv[0], qgetenv("DISPLAY").constData()); exit(1); } const int number_of_screens = xcb_setup_roots_length(xcb_get_setup(c)); // multi head auto isMultiHead = []() -> bool { QByteArray multiHead = qgetenv("KDE_MULTIHEAD"); if (!multiHead.isEmpty()) { return (multiHead.toLower() == "true"); } return true; }; if (number_of_screens != 1 && isMultiHead()) { KWin::is_multihead = true; KWin::screen_number = primaryScreen; int pos; // Temporarily needed to reconstruct DISPLAY var if multi-head QByteArray display_name = qgetenv("DISPLAY"); xcb_disconnect(c); c = nullptr; if ((pos = display_name.lastIndexOf('.')) != -1) display_name.remove(pos, 10); // 10 is enough to be sure we removed ".s" QString envir; for (int i = 0; i < number_of_screens; i++) { // If execution doesn't pass by here, then kwin // acts exactly as previously if (i != KWin::screen_number && fork() == 0) { KWin::screen_number = i; // Break here because we are the child process, we don't // want to fork() anymore break; } } // In the next statement, display_name shouldn't contain a screen // number. If it had it, it was removed at the "pos" check envir.sprintf("DISPLAY=%s.%d", display_name.data(), KWin::screen_number); if (putenv(strdup(envir.toAscii().constData()))) { fprintf(stderr, "%s: WARNING: unable to set DISPLAY environment variable\n", argv[0]); perror("putenv()"); } } if (signal(SIGTERM, KWin::sighandler) == SIG_IGN) signal(SIGTERM, SIG_IGN); if (signal(SIGINT, KWin::sighandler) == SIG_IGN) signal(SIGINT, SIG_IGN); if (signal(SIGHUP, KWin::sighandler) == SIG_IGN) signal(SIGHUP, SIG_IGN); // Disable the glib event loop integration, since it seems to be responsible // for several bug reports about high CPU usage (bug #239963) setenv("QT_NO_GLIB", "1", true); // enforce xcb plugin, unfortunately command line switch has precedence setenv("QT_QPA_PLATFORM", "xcb", true); - org::kde::KSMServerInterface ksmserver(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QDBusConnection::sessionBus()); - ksmserver.suspendStartup(QStringLiteral(KWIN_NAME)); KWin::Application a(argc, argv); a.setApplicationName(QStringLiteral(KWIN_NAME)); a.setApplicationVersion(QStringLiteral(KWIN_VERSION_STRING)); a.setApplicationDisplayName(i18n("KWin")); KAboutData aboutData(QStringLiteral(KWIN_NAME), // The program name used internally QString(), // The message catalog name. If null, program name is used instead i18n("KWin"), // A displayable program name string QStringLiteral(KWIN_VERSION_STRING), // The program version string i18n(description), // Short description of what the app does KAboutData::License_GPL, // The license this code is released under i18n("(c) 1999-2013, The KDE Developers")); // Copyright Statement aboutData.addAuthor(i18n("Matthias Ettrich"), QString(), QStringLiteral("ettrich@kde.org")); aboutData.addAuthor(i18n("Cristian Tibirna"), QString(), QStringLiteral("tibirna@kde.org")); aboutData.addAuthor(i18n("Daniel M. Duley"), QString(), QStringLiteral("mosfet@kde.org")); aboutData.addAuthor(i18n("Luboš Luňák"), QString(), QStringLiteral("l.lunak@kde.org")); aboutData.addAuthor(i18n("Martin Gräßlin"), i18n("Maintainer"), QStringLiteral("mgraesslin@kde.org")); QCommandLineOption lockOption(QStringLiteral("lock"), i18n("Disable configuration options")); QCommandLineOption replaceOption(QStringLiteral("replace"), i18n("Replace already-running ICCCM2.0-compliant window manager")); QCommandLineOption crashesOption(QStringLiteral("crashes"), i18n("Indicate that KWin has recently crashed n times"), QStringLiteral("n")); QCommandLineParser parser; parser.setApplicationDescription(i18n("KDE window manager")); parser.addVersionOption(); parser.addHelpOption(); parser.addOption(lockOption); parser.addOption(replaceOption); parser.addOption(crashesOption); parser.process(a); KWin::Application::setCrashCount(parser.value(crashesOption).toInt()); a.setConfigLock(parser.isSet(lockOption)); a.setReplace(parser.isSet(replaceOption)); // perform sanity checks if (a.platformName().toLower() != QStringLiteral("xcb")) { fprintf(stderr, "%s: FATAL ERROR expecting platform xcb but got platform %s\n", argv[0], qPrintable(a.platformName())); exit(1); } if (!KWin::display()) { fprintf(stderr, "%s: FATAL ERROR KWin requires Xlib support in the xcb plugin. Do not configure Qt with -no-xcb-xlib\n", argv[0]); exit(1); } a.start(); - ksmserver.resumeStartup(QStringLiteral(KWIN_NAME)); #warning SessionManager needs porting #if KWIN_QT5_PORTING KWin::SessionManager weAreIndeed; #endif KWin::SessionSaveDoneHelper helper; #warning insertCatalog needs porting #if KWIN_QT5_PORTING KGlobal::locale()->insertCatalog("kwin_effects"); KGlobal::locale()->insertCatalog("kwin_scripts"); KGlobal::locale()->insertCatalog("kwin_scripting"); #endif QString appname; if (KWin::screen_number == 0) appname = QStringLiteral("org.kde.kwin"); else appname.sprintf("org.kde.kwin-screen-%d", KWin::screen_number); QDBusConnection::sessionBus().interface()->registerService( appname, QDBusConnectionInterface::DontQueueService); return a.exec(); } #include "main.moc"