unity-mir-0.3+14.04.20140417/0000755000015301777760000000000012323677263015724 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/cmake/0000755000015301777760000000000012323677263017004 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/cmake/LinuxCrossCompile.cmake0000644000015301777760000000346712323676377023447 0ustar pbusernogroup00000000000000set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_VERSION 1) set(UNITYMIR_CHROOT_DIR $ENV{UNITYMIR_CHROOT_DIR} CACHE STRING "directory containing partial chroot for unity-mir cross-compilation") set(UNITYMIR_ARM_EABI "arm-linux-gnueabihf") set(CMAKE_C_COMPILER /usr/bin/${UNITYMIR_ARM_EABI}-gcc) set(CMAKE_CXX_COMPILER /usr/bin/${UNITYMIR_ARM_EABI}-g++) # where to look to find dependencies in the target environment set(CMAKE_FIND_ROOT_PATH "${UNITYMIR_CHROOT_DIR}") #treat the chroot's includes as system includes include_directories(SYSTEM "${UNITYMIR_CHROOT_DIR}/usr/include" "${UNITYMIR_CHROOT_DIR}/usr/include/${UNITYMIR_ARM_EABI}") list(APPEND CMAKE_SYSTEM_INCLUDE_PATH "${UNITYMIR_CHROOT_DIR}/usr/include" "${UNITYMIR_CHROOT_DIR}/usr/include/${UNITYMIR_ARM_EABI}" ) # Add the chroot libraries as system libraries list(APPEND CMAKE_SYSTEM_LIBRARY_PATH "${UNITYMIR_CHROOT_DIR}/lib" "${UNITYMIR_CHROOT_DIR}/lib/${UNITYMIR_ARM_EABI}" "${UNITYMIR_CHROOT_DIR}/usr/lib" "${UNITYMIR_CHROOT_DIR}/usr/lib/${UNITYMIR_ARM_EABI}" ) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_EXECUTABLE_RUNTIME_C_FLAG "-Wl,-rpath-link,") set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG "-Wl,-rpath-link,") set(CMAKE_INSTALL_RPATH "${UNITYMIR_CHROOT_DIR}/lib:${UNITYMIR_CHROOT_DIR}/lib/${UNITYMIR_ARM_EABI}:${UNITYMIR_CHROOT_DIR}/usr/lib:${UNITYMIR_CHROOT_DIR}/usr/lib/${UNITYMIR_ARM_EABI}:${UNITYMIR_CHROOT_DIR}/usr/lib/${UNITYMIR_ARM_EABI}/mesa-egl") set(ENV{PKG_CONFIG_PATH} "${UNITYMIR_CHROOT_DIR}/usr/lib/pkgconfig:${UNITYMIR_CHROOT_DIR}/usr/lib/${UNITYMIR_ARM_EABI}/pkgconfig") set(ENV{PKG_CONFIG_SYSROOT_DIR} "${UNITYMIR_CHROOT_DIR}") #use only the cross compile system set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) unity-mir-0.3+14.04.20140417/tests/0000755000015301777760000000000012323677263017066 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/tests/application/0000755000015301777760000000000012323677263021371 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/tests/application/Fullscreen.qml0000644000015301777760000000315412323676377024216 0ustar pbusernogroup00000000000000// This file is part of QtUbuntu, a set of Qt components for Ubuntu. // Copyright © 2013 Canonical Ltd. // // This program is free software: you can redistribute it and/or modify it under // the terms of the GNU General Public License version 3, as published by the // Free Software Foundation. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, // SATISFACTORY QUALITY, 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 . // Non graphical test watching fullscreen states of main and side stages. import QtQuick 2.0 import Ubuntu.Application 0.1 Item { Timer { id: time interval: 1000 repeat: true onTriggered: { if (ApplicationManager.mainStageFocusedApplication) { print(ApplicationManager.sideStageFocusedApplication.name, "in main stage is fullscreen: ", ApplicationManager.sideStageFocusedApplication.fullscreen) } if (ApplicationManager.sideStageFocusedApplication) { print(ApplicationManager.sideStageFocusedApplication.name, "in side stage is fullscreen: ", ApplicationManager.sideStageFocusedApplication.fullscreen) } } Component.onCompleted: time.start() } Component.onCompleted: { time.start() } } unity-mir-0.3+14.04.20140417/tests/application/Application.qml0000644000015301777760000001172312323676377024360 0ustar pbusernogroup00000000000000// This file is part of QtUbuntu, a set of Qt components for Ubuntu. // Copyright © 2013 Canonical Ltd. // // This program is free software: you can redistribute it and/or modify it under // the terms of the GNU General Public License version 3, as published by the // Free Software Foundation. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, // SATISFACTORY QUALITY, 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 . // That example demonstrates the types added by the Ubuntu application plugin and how to use them. // // Here is how to create a window with specific surface role (Greeter here) from QML. // // import QtQuick.Window 2.0 // // Window { // width: 400 // height: 400 // Component.onCompleted: { // window.role = ApplicationManager.Greeter // window.visible = true // } // } // // Here is how to start a new process: // ApplicationManager.startProcess("/usr/share/applications/snowshoe.desktop") // // In order to pass additional arguments, a second optional argument can be used: // ApplicationManager.startProcess("/usr/share/applications/snowshoe.desktop", // [ "http://www.ubuntu.com" ]) // // An application can be stopped by using: // ApplicationManager.stopProcess(application) // // A good way to use Application.qml is to launch it using: // qmlscene-ubuntu --fullscreen --session 1 --role 0 Application.qml // and then to launch other applications using: // qmlscene-ubuntu --session 0 --role 1 MovingLogo.qml \ // --desktop_file_hint=/usr/share/applications/goodhope.desktop --stage_hint=main_stage import QtQuick 2.0 import Ubuntu.Application 0.1 Rectangle { id: surface width: 2560 height: 1600 color: "#000020" Connections { target: ApplicationManager onFocusRequested: { print("focus request:", appId) } } Column { id: mainHeader anchors { left: parent.left right: parent.right } spacing: 10 Text { font.family: "Ubuntu Mono"; font.weight: Font.Bold; font.pixelSize: 40; color: "white" text: "Main stage:" } } Row { id: mainRow anchors { top: mainHeader.bottom topMargin: 10 } Repeater { model: ApplicationManager.mainStageApplications delegate: ApplicationImage { id: applicationImage width: 2560 / 5; height: 1600 / 5 source: application Text { font.family: "Ubuntu Mono"; font.weight: Font.Bold; font.pixelSize: 30; color: "white" text: application.name } MouseArea { anchors.fill: parent onClicked: applicationImage.scheduleUpdate() } Timer { running: true onTriggered: applicationImage.scheduleUpdate() } } } } Column { id: sideHeader y: surface.height / 2 anchors { left: parent.left right: parent.right } spacing: 10 Text { font.family: "Ubuntu Mono"; font.weight: Font.Bold; font.pixelSize: 40; color: "white" text: "Side stage:" } } Row { anchors { top: sideHeader.bottom topMargin: 10 } Repeater { model: ApplicationManager.sideStageApplications delegate: ApplicationImage { id: applicationImage width: 2560 / 5; height: 1600 / 5 source: application Text { font.family: "Ubuntu Mono"; font.weight: Font.Bold; font.pixelSize: 30; color: "white" text: application.name } MouseArea { anchors.fill: parent onClicked: applicationImage.scheduleUpdate() } Timer { running: true onTriggered: applicationImage.scheduleUpdate() } } } } Component.onCompleted: { // Display form factor and stage hints. var formFactorHintStr = [ 'Desktop', 'Phone', 'Tablet' ]; var stageHintStr = [ 'Main', 'Integration', 'Share', 'ContentPicking', 'Side', 'Configuration' ]; print('Form factor hint:', formFactorHintStr[ApplicationManager.formFactorHint]); print('Stage hint:', stageHintStr[ApplicationManager.stageHint]); } } unity-mir-0.3+14.04.20140417/tests/application/InputFilter.qml0000644000015301777760000000370012323676377024356 0ustar pbusernogroup00000000000000// This file is part of QtUbuntu, a set of Qt components for Ubuntu. // Copyright © 2013 Canonical Ltd. // // This program is free software: you can redistribute it and/or modify it under // the terms of the GNU General Public License version 3, as published by the // Free Software Foundation. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, // SATISFACTORY QUALITY, 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 . import QtQuick 2.0 import Ubuntu.Application 0.1 Item { width: 700; height: 700 InputFilterArea { id: topLeftFilter width: 500 height: 500 blockInput: true Rectangle { anchors.fill: parent color: parent.blockInput ? "red" : "green" opacity: parent.blockInput ? 1.0 : 0.8 } } MouseArea { anchors.centerIn: parent width: 500 height: 200 onClicked: { topLeftFilter.blockInput = !topLeftFilter.blockInput; bottomRightFilter.blockInput = !bottomRightFilter.blockInput; } Rectangle { anchors.fill: parent color: "grey" } Text { anchors.centerIn: parent text: "Press to toggle filters" font.pixelSize: 45 color: "lightgrey" } } InputFilterArea { id: bottomRightFilter anchors.right: parent.right anchors.bottom: parent.bottom width: 500 height: 500 blockInput: true Rectangle { anchors.fill: parent color: parent.blockInput ? "red" : "green" opacity: parent.blockInput ? 1.0 : 0.8 } } } unity-mir-0.3+14.04.20140417/tests/mock_oom_controller.h0000644000015301777760000000206712323676377023317 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef MOCK_OOM_CONTROLLER_H #define MOCK_OOM_CONTROLLER_H #include #include namespace testing { struct MockOomController : public unitymir::ProcessController::OomController { MOCK_METHOD1(ensureProcessLikelyToBeKilled, void(pid_t)); MOCK_METHOD1(ensureProcessUnlikelyToBeKilled, void(pid_t)); }; } #endif // MOCK_OOM_CONTROLLER_H unity-mir-0.3+14.04.20140417/tests/mock_process_controller.h0000644000015301777760000000267112323676377024204 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef MOCK_PROCESS_CONTROLLER_H #define MOCK_PROCESS_CONTROLLER_H #include #include namespace testing { struct MockProcessController : public unitymir::ProcessController { MockProcessController(const QSharedPointer& oomController) : m_oomController(oomController) { } const QSharedPointer& oomController() const { return m_oomController; } MOCK_CONST_METHOD1(sigStopProcessGroupForPid, bool(pid_t)); MOCK_CONST_METHOD1(sigContinueProcessGroupForPid, bool(pid_t)); QSharedPointer m_oomController; }; } #endif // MOCK_PROCESS_CONTROLLER_H unity-mir-0.3+14.04.20140417/tests/auto/0000755000015301777760000000000012323677263020036 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/tests/auto/CMakeLists.txt0000644000015301777760000000003212323676377022576 0ustar pbusernogroup00000000000000add_subdirectory(modules) unity-mir-0.3+14.04.20140417/tests/auto/modules/0000755000015301777760000000000012323677263021506 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/0000755000015301777760000000000012323677263022616 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/Application/0000755000015301777760000000000012323677263025061 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/Application/main.cpp0000644000015301777760000000523312323676377026521 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include #include "application_manager.h" #include "processcontroller.h" #include "proc_info.h" #include "taskcontroller.h" #include "upstart/applicationcontroller.h" #include "qmirserverapplication.h" #include "qmirserver.h" #include using namespace unitymir; static QString pidCommandLine(qint64 pid) { QFile cmdline(QString("/proc/%1/cmdline").arg(pid)); cmdline.open(QIODevice::ReadOnly | QIODevice::Text); QByteArray command = cmdline.readLine().replace('\0', ' '); cmdline.close(); return command.simplified(); } class ApplicationManagerTests: public QObject { Q_OBJECT private Q_SLOTS: void testStartStop(); }; void ApplicationManagerTests::testStartStop() { ApplicationManager::Factory appFactory; QSharedPointer manager{appFactory.create()}; Application *app = manager->startApplication("unity-mir-test-helper-app", QStringList()); QVERIFY(app); QCOMPARE(app->desktopFile(), QString("/usr/share/applications/unity-mir-test-helper-app.desktop")); QCOMPARE(app->name(), QString("My Fake App")); QCOMPARE(app->comment(), QString("My Fake App Comment")); QCOMPARE(app->icon(), QUrl("image://theme/fakeIcon")); QCOMPARE(app->exec(), QString("unity-mir-test-helper-app")); QTRY_VERIFY(!pidCommandLine(app->pid()).isEmpty()); QString simplifiedCommand = pidCommandLine(app->pid()); QCOMPARE(simplifiedCommand, QString("unity-mir-test-helper-app")); manager->stopApplication(app->appId()); QDir d; QTRY_VERIFY(!d.exists(QString("/proc/%1").arg(app->pid()))); } static int startShell(int argc, const char* argv[], ShellServerConfiguration* server) { QMirServerApplication application(argc, (char**)argv, server); ApplicationManagerTests tc; int res = QTest::qExec(&tc, argc, (char**)argv); raise(SIGTERM); return res; } int main(int argc, const char *argv[]) { QMirServer mirServer(argc, argv); return mirServer.runWithClient(startShell); } #include "main.moc" unity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/Application/CMakeLists.txt0000644000015301777760000000105412323676377027626 0ustar pbusernogroup00000000000000add_subdirectory(fakeApp) include_directories( ${CMAKE_SOURCE_DIR}/src/modules/Unity/Application ${CMAKE_SOURCE_DIR}/src/unity-mir ${MIRSERVER_INCLUDE_DIRS} ${UPSTART_APP_LAUNCH_INCLUDE_DIRS}) add_executable( unity-mir-test-app main.cpp) qt5_use_modules(unity-mir-test-app Test DBus Gui) target_link_libraries( unity-mir-test-app unity-mir unityapplicationplugin ${MIRSERVER_LDFLAGS} ${UPSTART_APP_LAUNCH_LDFLAGS}) install( TARGETS unity-mir-test-app RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) unity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/Application/fakeApp/0000755000015301777760000000000012323677263026430 5ustar pbusernogroup00000000000000././@LongLink0000000000000000000000000000015400000000000011215 Lustar 00000000000000unity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/Application/fakeApp/unity-mir-test-helper-app.desktopunity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/Application/fakeApp/unity-mir-test-helper-app.0000644000015301777760000000023012323676377033376 0ustar pbusernogroup00000000000000[Desktop Entry] Exec=unity-mir-test-helper-app Name=My Fake App Comment=My Fake App Comment Type=Application Icon=fakeIcon X-Ubuntu-StageHint=mainStage unity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/Application/fakeApp/main.cpp0000644000015301777760000000143712323676377030072 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include int main(int argc, char *argv[]) { QGuiApplication a(argc, argv); return a.exec(); } unity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/Application/fakeApp/CMakeLists.txt0000644000015301777760000000043412323676377031176 0ustar pbusernogroup00000000000000add_executable(unity-mir-test-helper-app main.cpp) qt5_use_modules(unity-mir-test-helper-app Gui) install(TARGETS unity-mir-test-helper-app RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES unity-mir-test-helper-app.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) unity-mir-0.3+14.04.20140417/tests/auto/modules/Unity/CMakeLists.txt0000644000015301777760000000003612323676377025362 0ustar pbusernogroup00000000000000add_subdirectory(Application) unity-mir-0.3+14.04.20140417/tests/auto/modules/CMakeLists.txt0000644000015301777760000000003012323676377024244 0ustar pbusernogroup00000000000000add_subdirectory(Unity) unity-mir-0.3+14.04.20140417/tests/mock_session.h0000644000015301777760000000423112323676377021740 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef MOCK_MIR_SHELL_SESSION_H #define MOCK_MIR_SHELL_SESSION_H #include #include #include #include #include namespace testing { struct MockSession : public mir::shell::Session { MockSession() {} MockSession(std::string const& sessionName, pid_t processId) : m_sessionName(sessionName), m_sessionId(processId) {} std::string name() const override { return m_sessionName; } pid_t process_id() const override { return m_sessionId; } typedef mir::frontend::SurfaceId SurfaceId; MOCK_METHOD0(force_requests_to_complete, void()); MOCK_CONST_METHOD0(default_surface, std::shared_ptr()); MOCK_CONST_METHOD1(get_surface, std::shared_ptr(SurfaceId)); MOCK_METHOD1(take_snapshot, void(mir::shell::SnapshotCallback const&)); MOCK_METHOD1(set_lifecycle_state, void(MirLifecycleState)); MOCK_METHOD1(create_surface, SurfaceId(mir::shell::SurfaceCreationParameters const&)); MOCK_METHOD1(destroy_surface, void (SurfaceId)); MOCK_METHOD0(hide, void()); MOCK_METHOD0(show, void()); MOCK_METHOD1(send_display_config, void(mir::graphics::DisplayConfiguration const&)); MOCK_METHOD3(configure_surface, int(SurfaceId, MirSurfaceAttrib, int)); private: std::string m_sessionName; pid_t m_sessionId; }; } #endif // MOCK_MIR_SHELL_SESSION_H unity-mir-0.3+14.04.20140417/tests/mock_proc_info.h0000644000015301777760000000212512323676377022233 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef MOCK_PROC_INFO_H #define MOCK_PROC_INFO_H #include #include namespace testing { struct MockProcInfo : public unitymir::ProcInfo { MOCK_METHOD1(command_line, QByteArray(quint64)); std::unique_ptr commandLine(quint64 pid) { return std::unique_ptr(new CommandLine{command_line(pid)}); } }; } #endif // MOCK_OOM_CONTROLLER_H unity-mir-0.3+14.04.20140417/tests/mock_application_controller.h0000644000015301777760000000603512323676377025027 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef MOCK_APPLICATION_CONTROLLER_H #define MOCK_APPLICATION_CONTROLLER_H #include #include #include namespace testing { struct MockApplicationController : public unitymir::ApplicationController { MOCK_METHOD1(primaryPidForAppId, pid_t(const QString& appId)); MOCK_METHOD2(appIdHasProcessId, bool(pid_t, const QString&)); MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&)); MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&)); MockApplicationController() { using namespace ::testing; ON_CALL(*this, primaryPidForAppId(_)) .WillByDefault( Invoke(this, &MockApplicationController::doPrimaryPidForAppId)); ON_CALL(*this, appIdHasProcessId(_, _)) .WillByDefault( Invoke(this, &MockApplicationController::doAppIdHasProcessId)); ON_CALL(*this, stopApplicationWithAppId(_)) .WillByDefault( Invoke(this, &MockApplicationController::doStopApplicationWithAppId)); ON_CALL(*this, startApplicationWithAppIdAndArgs(_, _)) .WillByDefault( Invoke(this, &MockApplicationController::doStartApplicationWithAppIdAndArgs)); } pid_t doPrimaryPidForAppId(const QString& appId) { auto it = children.find(appId); if (it == children.end()) return -1; return it->pid(); } bool doAppIdHasProcessId(pid_t pid, const QString& appId) { auto it = children.find(appId); if (it == children.end()) return -1; return it->pid() == pid; } bool doStopApplicationWithAppId(const QString& appId) { (void) appId; return false; } bool doStartApplicationWithAppIdAndArgs(const QString& appId, const QStringList& args) { (void) args; auto child = core::posix::fork([]() { while (true); return core::posix::exit::Status::success; }, core::posix::StandardStream::empty); if (child.pid() > 0) { children.insert(appId, child); return true; } return false; } QMap children; }; } #endif // MOCK_APPLICATION_CONTROLLER_H unity-mir-0.3+14.04.20140417/tests/application_manager_test.cpp0000644000015301777760000004060312323676377024636 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #include #include #include #include #include #include #include #include #include "mock_application_controller.h" #include "mock_desktop_file_reader.h" #include "mock_oom_controller.h" #include "mock_process_controller.h" #include "mock_proc_info.h" #include "mock_session.h" #include "mock_focus_controller.h" using namespace unitymir; class ApplicationManagerTests : public ::testing::Test { public: ApplicationManagerTests() : processController{ QSharedPointer ( &oomController, [](ProcessController::OomController*){}) }, applicationManager{ QSharedPointer{ new TaskController( nullptr, QSharedPointer( &appController, [](ApplicationController*){}), QSharedPointer( &processController, [](ProcessController*){}) )}, QSharedPointer( &desktopFileReaderFactory, [](DesktopFileReader::Factory*){}), QSharedPointer(&procInfo,[](ProcInfo *){}), std::shared_ptr(&focusController, [](void*){}), QSize(400,400) } { } testing::NiceMock oomController; testing::NiceMock processController; testing::NiceMock appController; testing::NiceMock procInfo; testing::NiceMock desktopFileReaderFactory; testing::NiceMock focusController; ApplicationManager applicationManager; }; TEST_F(ApplicationManagerTests, SuspendingAndResumingARunningApplicationResultsInOomScoreAdjustment) { using namespace ::testing; const QString appId("com.canonical.does.not.exist"); EXPECT_CALL(appController, startApplicationWithAppIdAndArgs(_, _)).Times(1); EXPECT_CALL(desktopFileReaderFactory, createInstanceForAppId(appId)).Times(1); EXPECT_CALL(processController, sigStopProcessGroupForPid(_)).Times(1); EXPECT_CALL(processController, sigContinueProcessGroupForPid(_)).Times(1); EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(_)).Times(1); EXPECT_CALL(oomController, ensureProcessLikelyToBeKilled(_)).Times(1); auto application = applicationManager.startApplication( appId, ApplicationManager::NoFlag, QStringList()); application->suspend(); application->resume(); } // Currently disabled as we need to make sure that we have a corresponding mir session, too. TEST_F(ApplicationManagerTests, DISABLED_FocusingRunningApplicationResultsInOomScoreAdjustment) { using namespace ::testing; const QString appId("com.canonical.does.not.exist"); QSet appIds; for (unsigned int i = 0; i < 50; i++) { QString appIdFormat("%1.does.not.exist"); auto appId = appIdFormat.arg(i); auto application = applicationManager.startApplication( appId, ApplicationManager::NoFlag, QStringList()); std::shared_ptr mirSession = std::make_shared(appIdFormat.toStdString(), i); applicationManager.onSessionStarting( mirSession ); EXPECT_NE(nullptr, application); appIds.insert(appId); auto it = appController.children.find(appId); if (it != appController.children.end()) EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(it->pid())).Times(1); } for (auto appId : appIds) { applicationManager.focusApplication(appId); } } TEST_F(ApplicationManagerTests,bug_case_1240400_second_dialer_app_fails_to_authorize_and_gets_mixed_up_with_first_one) { using namespace ::testing; std::shared_ptr aSurface(nullptr); quint64 firstProcId = 5921; quint64 secondProcId = 5922; const char dialer_app_id[] = "dialer-app"; QByteArray cmdLine( "/usr/bin/dialer-app --desktop_file_hint=dialer-app"); QByteArray secondcmdLine( "/usr/bin/dialer-app"); EXPECT_CALL(procInfo,command_line(firstProcId)) .Times(1) .WillOnce(Return(cmdLine)); EXPECT_CALL(procInfo,command_line(secondProcId)) .Times(1) .WillOnce(Return(secondcmdLine)); bool authed = true; std::shared_ptr mirSession = std::make_shared(dialer_app_id, firstProcId); applicationManager.authorizeSession(firstProcId, authed); EXPECT_EQ(true, authed); applicationManager.onSessionStarting(mirSession); applicationManager.onSessionCreatedSurface(mirSession.get(),aSurface); Application * app = applicationManager.findApplication(dialer_app_id); EXPECT_NE(nullptr,app); // now a second session without desktop file is launched: applicationManager.authorizeSession(secondProcId, authed); applicationManager.onProcessStartReportReceived(dialer_app_id, true); EXPECT_EQ(false,authed); EXPECT_EQ(app,applicationManager.findApplication(dialer_app_id)); EXPECT_EQ(QString(dialer_app_id),applicationManager.focusedApplicationId()); } TEST_F(ApplicationManagerTests,application_dies_while_starting) { using namespace ::testing; quint64 procId = 5921; const char app_id[] = "my-app"; QByteArray cmdLine( "/usr/bin/my-app --desktop_file_hint=my-app"); EXPECT_CALL(procInfo,command_line(procId)) .Times(1) .WillOnce(Return(cmdLine)); bool authed = true; std::shared_ptr mirSession = std::make_shared(app_id, procId); applicationManager.authorizeSession(procId, authed); applicationManager.onSessionStarting(mirSession); Application * beforeFailure = applicationManager.findApplication(app_id); applicationManager.onProcessStartReportReceived(app_id,true); Application * afterFailure = applicationManager.findApplication(app_id); EXPECT_EQ(true, authed); EXPECT_NE(nullptr, beforeFailure); EXPECT_EQ(nullptr, afterFailure); } TEST_F(ApplicationManagerTests,application_start_failure_after_starting) { using namespace ::testing; quint64 procId = 5921; std::shared_ptr aSurface(nullptr); const char app_id[] = "my-app"; QByteArray cmdLine( "/usr/bin/my-app --desktop_file_hint=my-app"); EXPECT_CALL(procInfo,command_line(procId)) .Times(1) .WillOnce(Return(cmdLine)); bool authed = true; std::shared_ptr mirSession = std::make_shared(app_id, procId); applicationManager.authorizeSession(procId, authed); applicationManager.onSessionStarting(mirSession); Application * beforeFailure = applicationManager.findApplication(app_id); applicationManager.onSessionCreatedSurface(mirSession.get(), aSurface); applicationManager.onProcessStartReportReceived(app_id, true); Application * afterFailure = applicationManager.findApplication(app_id); EXPECT_EQ(true, authed); EXPECT_NE(nullptr, beforeFailure); EXPECT_EQ(beforeFailure, afterFailure); } TEST_F(ApplicationManagerTests,bug_case_1281075_session_ptrs_always_distributed_to_last_started_app) { using namespace ::testing; quint64 first_procId = 5921; quint64 second_procId = 5922; quint64 third_procId = 5923; std::shared_ptr aSurface(nullptr); const char first_app_id[] = "app1"; QByteArray first_cmdLine( "/usr/bin/app1 --desktop_file_hint=app1"); const char second_app_id[] = "app2"; QByteArray second_cmdLine( "/usr/bin/app2--desktop_file_hint=app2"); const char third_app_id[] = "app3"; QByteArray third_cmdLine( "/usr/bin/app3 --desktop_file_hint=app3"); EXPECT_CALL(procInfo,command_line(first_procId)) .Times(1) .WillOnce(Return(first_cmdLine)); ON_CALL(appController,appIdHasProcessId(_,_)).WillByDefault(Return(false)); EXPECT_CALL(procInfo,command_line(second_procId)) .Times(1) .WillOnce(Return(second_cmdLine)); EXPECT_CALL(procInfo,command_line(third_procId)) .Times(1) .WillOnce(Return(third_cmdLine)); bool authed = true; std::shared_ptr first_session = std::make_shared("Oo", first_procId); std::shared_ptr second_session = std::make_shared("oO", second_procId); std::shared_ptr third_session = std::make_shared("OO", third_procId); applicationManager.authorizeSession(first_procId, authed); applicationManager.authorizeSession(second_procId, authed); applicationManager.authorizeSession(third_procId, authed); applicationManager.onSessionStarting(first_session); applicationManager.onSessionStarting(third_session); applicationManager.onSessionStarting(second_session); Application * firstApp = applicationManager.findApplication(first_app_id); Application * secondApp = applicationManager.findApplication(second_app_id); Application * thirdApp = applicationManager.findApplication(third_app_id); EXPECT_EQ(first_session, firstApp->session()); EXPECT_EQ(second_session, secondApp->session()); EXPECT_EQ(third_session, thirdApp->session()); } TEST_F(ApplicationManagerTests,two_session_on_one_application) { using namespace ::testing; quint64 a_procId = 5921; const char an_app_id[] = "some_app"; QByteArray a_cmd( "/usr/bin/app1 --desktop_file_hint=some_app"); ON_CALL(procInfo,command_line(_)).WillByDefault(Return(a_cmd)); ON_CALL(appController,appIdHasProcessId(_,_)).WillByDefault(Return(false)); bool authed = true; std::shared_ptr first_session = std::make_shared("Oo", a_procId); std::shared_ptr second_session = std::make_shared("oO", a_procId); applicationManager.authorizeSession(a_procId, authed); applicationManager.onSessionStarting(first_session); applicationManager.onSessionStarting(second_session); Application * the_app = applicationManager.findApplication(an_app_id); EXPECT_EQ(true, authed); EXPECT_EQ(second_session, the_app->session()); } TEST_F(ApplicationManagerTests,upstart_launching_sidestage_app_on_phone_forced_into_mainstage) { using namespace ::testing; QString appId("sideStage"); auto mockDesktopFileReader = new NiceMock(appId); ON_CALL(*mockDesktopFileReader, loaded()).WillByDefault(Return(true)); ON_CALL(*mockDesktopFileReader, stageHint()).WillByDefault(Return("SideStage")); ON_CALL(desktopFileReaderFactory, createInstanceForAppId(appId)).WillByDefault(Return(mockDesktopFileReader)); // mock upstart launching an app which reports itself as sidestage, but we're on phone applicationManager.onProcessStartReportReceived(appId, false); // ensure the app stage is overridden to be main stage Application* theApp = applicationManager.findApplication(appId); ASSERT_NE(theApp, nullptr); EXPECT_EQ(Application::MainStage, theApp->stage()); } TEST_F(ApplicationManagerTests,two_session_on_one_application_after_starting) { using namespace ::testing; quint64 a_procId = 5921; const char an_app_id[] = "some_app"; QByteArray a_cmd( "/usr/bin/app1 --desktop_file_hint=some_app"); std::shared_ptr aSurface(nullptr); ON_CALL(procInfo,command_line(_)).WillByDefault(Return(a_cmd)); ON_CALL(appController,appIdHasProcessId(_,_)).WillByDefault(Return(false)); bool authed = true; std::shared_ptr first_session = std::make_shared("Oo", a_procId); std::shared_ptr second_session = std::make_shared("oO", a_procId); applicationManager.authorizeSession(a_procId, authed); applicationManager.onSessionStarting(first_session); applicationManager.onSessionCreatedSurface(first_session.get(), aSurface); applicationManager.onSessionStarting(second_session); Application * the_app = applicationManager.findApplication(an_app_id); EXPECT_EQ(true, authed); EXPECT_EQ(Application::Running, the_app->state()); EXPECT_EQ(first_session, the_app->session()); } TEST_F(ApplicationManagerTests,suspended_suspends_focused_app) { using namespace ::testing; quint64 a_procId = 5921; const char an_app_id[] = "some_app"; QByteArray a_cmd( "/usr/bin/app1 --desktop_file_hint=some_app"); std::shared_ptr aSurface(nullptr); ON_CALL(procInfo,command_line(_)).WillByDefault(Return(a_cmd)); ON_CALL(appController,appIdHasProcessId(_,_)).WillByDefault(Return(false)); bool authed = true; std::shared_ptr first_session = std::make_shared("Oo", a_procId); std::shared_ptr second_session = std::make_shared("oO", a_procId); applicationManager.authorizeSession(a_procId, authed); applicationManager.onSessionStarting(first_session); applicationManager.onSessionCreatedSurface(first_session.get(), aSurface); applicationManager.onSessionStarting(second_session); Application * the_app = applicationManager.findApplication(an_app_id); EXPECT_EQ(Application::Running, the_app->state()); applicationManager.setSuspended(true); EXPECT_EQ(Application::Suspended, the_app->state()); applicationManager.setSuspended(false); EXPECT_EQ(Application::Running, the_app->state()); } TEST_F(ApplicationManagerTests,requestFocusApplication) { using namespace ::testing; quint64 first_procId = 5921; quint64 second_procId = 5922; quint64 third_procId = 5923; std::shared_ptr aSurface(nullptr); QByteArray first_cmdLine( "/usr/bin/app1 --desktop_file_hint=app1"); QByteArray second_cmdLine( "/usr/bin/app2--desktop_file_hint=app2"); QByteArray third_cmdLine( "/usr/bin/app3 --desktop_file_hint=app3"); EXPECT_CALL(procInfo,command_line(first_procId)) .Times(1) .WillOnce(Return(first_cmdLine)); ON_CALL(appController,appIdHasProcessId(_,_)).WillByDefault(Return(false)); EXPECT_CALL(procInfo,command_line(second_procId)) .Times(1) .WillOnce(Return(second_cmdLine)); EXPECT_CALL(procInfo,command_line(third_procId)) .Times(1) .WillOnce(Return(third_cmdLine)); bool authed = true; std::shared_ptr first_session = std::make_shared("Oo", first_procId); std::shared_ptr second_session = std::make_shared("oO", second_procId); std::shared_ptr third_session = std::make_shared("OO", third_procId); applicationManager.authorizeSession(first_procId, authed); applicationManager.authorizeSession(second_procId, authed); applicationManager.authorizeSession(third_procId, authed); applicationManager.onSessionStarting(first_session); applicationManager.onSessionStarting(third_session); applicationManager.onSessionStarting(second_session); QSignalSpy spy(&applicationManager, SIGNAL(focusRequested(const QString &))); applicationManager.requestFocusApplication("app3"); EXPECT_EQ(spy.count(), 1); QList arguments = spy.takeFirst(); // take the first signal EXPECT_EQ(arguments.at(0).toString(), "app3"); } unity-mir-0.3+14.04.20140417/tests/taskcontroller_test.cpp0000644000015301777760000002265112323676377023712 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #include #include "mock_oom_controller.h" #include "mock_process_controller.h" #include #include #include #include namespace { using namespace unitymir; struct TriggerableApplicationController : public ApplicationController { void triggerApplicationStarted(const QString& appId) { Q_EMIT applicationStarted(appId); } void triggerApplicationStopped(const QString& appId) { Q_EMIT applicationStopped(appId); } void triggerApplicationFocusRequest(const QString& appId) { Q_EMIT applicationFocusRequest(appId); } MOCK_METHOD1(primaryPidForAppId, pid_t (const QString&)); MOCK_METHOD2(appIdHasProcessId, bool(pid_t, const QString&)); MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&)); MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&)); }; } TEST(TaskController, startingAnApplicationCallsCorrectlyIntoApplicationController) { using namespace ::testing; const QString appId{"com.canonical.does.not.exist"}; testing::NiceMock appController; QSharedPointer appControllerPtr( &appController, [](ApplicationController*){}); EXPECT_CALL(appController, startApplicationWithAppIdAndArgs(appId, QStringList())).Times(1).WillRepeatedly(Return(true)); testing::NiceMock oomController; QSharedPointer oomControllerPtr( &oomController, [](ProcessController::OomController*){}); NiceMock processController(oomControllerPtr); QSharedPointer processControllerPtr( &processController, [](ProcessController*){}); TaskController taskController(nullptr, appControllerPtr, processControllerPtr); taskController.start(appId, QStringList()); } TEST(TaskController, stoppingAnApplicationCallsCorrectlyIntoApplicationController) { using namespace ::testing; const QString appId{"com.canonical.does.not.exist"}; testing::NiceMock appController; QSharedPointer appControllerPtr( &appController, [](ApplicationController*){}); EXPECT_CALL(appController, stopApplicationWithAppId(appId)).Times(1).WillRepeatedly(Return(true)); testing::NiceMock oomController; QSharedPointer oomControllerPtr( &oomController, [](ProcessController::OomController*){}); NiceMock processController(oomControllerPtr); QSharedPointer processControllerPtr( &processController, [](ProcessController*){}); TaskController taskController(nullptr, appControllerPtr, processControllerPtr); taskController.stop(appId); } TEST(TaskController, suspendingAnApplicationAdjustsOomScoreForCorrectPid) { using namespace ::testing; const QString appId{"com.canonical.does.not.exist"}; testing::NiceMock appController; QSharedPointer appControllerPtr( &appController, [](ApplicationController*){}); EXPECT_CALL(appController, primaryPidForAppId(appId)).Times(1).WillRepeatedly(Return(-1)); testing::NiceMock oomController; QSharedPointer oomControllerPtr( &oomController, [](ProcessController::OomController*){}); NiceMock processController(oomControllerPtr); QSharedPointer processControllerPtr( &processController, [](ProcessController*){}); EXPECT_CALL(oomController, ensureProcessLikelyToBeKilled(-1)).Times(1); TaskController taskController(nullptr, appControllerPtr, processControllerPtr); taskController.suspend(appId); } TEST(TaskController, resumingAnApplicationAdjustsOomScoreForCorrectPid) { using namespace ::testing; const QString appId{"com.canonical.does.not.exist"}; testing::NiceMock appController; QSharedPointer appControllerPtr( &appController, [](ApplicationController*){}); EXPECT_CALL(appController, primaryPidForAppId(appId)).Times(1).WillRepeatedly(Return(-1)); testing::NiceMock oomController; QSharedPointer oomControllerPtr( &oomController, [](ProcessController::OomController*){}); NiceMock processController(oomControllerPtr); QSharedPointer processControllerPtr( &processController, [](ProcessController*){}); EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(-1)).Times(1); TaskController taskController(nullptr, appControllerPtr, processControllerPtr); taskController.resume(appId); } TEST(TaskController, aStartedApplicationIsOomScoreAdjusted) { using namespace ::testing; const QString appId{"com.canonical.does.not.exist"}; testing::NiceMock appController; QSharedPointer appControllerPtr( &appController, [](ApplicationController*){}); EXPECT_CALL(appController, primaryPidForAppId(appId)).Times(1).WillRepeatedly(Return(42)); testing::NiceMock oomController; QSharedPointer oomControllerPtr( &oomController, [](ProcessController::OomController*){}); NiceMock processController(oomControllerPtr); QSharedPointer processControllerPtr( &processController, [](ProcessController*){}); EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(42)).Times(1); TaskController taskController(nullptr, appControllerPtr, processControllerPtr); appControllerPtr->triggerApplicationStarted(appId); } TEST(TaskController, aFocusedApplicationIsOomScoreAdjusted) { using namespace ::testing; const QString appId{"com.canonical.does.not.exist"}; testing::NiceMock appController; QSharedPointer appControllerPtr( &appController, [](ApplicationController*){}); EXPECT_CALL(appController, primaryPidForAppId(appId)).Times(1).WillRepeatedly(Return(42)); testing::NiceMock oomController; QSharedPointer oomControllerPtr( &oomController, [](ProcessController::OomController*){}); NiceMock processController(oomControllerPtr); QSharedPointer processControllerPtr( &processController, [](ProcessController*){}); EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(42)).Times(1); TaskController taskController(nullptr, appControllerPtr, processControllerPtr); appControllerPtr->triggerApplicationFocusRequest(appId); } TEST(TaskController, oomControllerUpdatesOomScoreAdjCorrectly) { ProcessController::OomController oomController; auto child = core::posix::fork([]() { while (true); return core::posix::exit::Status::success; }, core::posix::StandardStream::empty); EXPECT_GT(child.pid(), 0); core::posix::linux::proc::process::OomScoreAdj oomScoreAdj; child >> oomScoreAdj; core::posix::linux::proc::process::OomScoreAdj likelyOomScoreAdj, unlikelyOomScoreAdj; { oomController.ensureProcessLikelyToBeKilled(child.pid()); child >> likelyOomScoreAdj; EXPECT_GE(likelyOomScoreAdj.value, oomScoreAdj.value); } { oomController.ensureProcessUnlikelyToBeKilled(child.pid()); child >> unlikelyOomScoreAdj; EXPECT_LE(unlikelyOomScoreAdj.value, likelyOomScoreAdj.value); } } unity-mir-0.3+14.04.20140417/tests/CMakeLists.txt0000644000015301777760000000346612323676377021644 0ustar pbusernogroup00000000000000find_package(Qt5Core REQUIRED) find_package(Qt5Quick REQUIRED) find_package(Qt5DBus REQUIRED) # Build with system gmock and embedded gtest set (GMOCK_INCLUDE_DIR "/usr/include/gmock/include" CACHE PATH "gmock source include directory") set (GMOCK_SOURCE_DIR "/usr/src/gmock" CACHE PATH "gmock source directory") set (GTEST_INCLUDE_DIR "${GMOCK_SOURCE_DIR}/gtest/include" CACHE PATH "gtest source include directory") add_subdirectory(${GMOCK_SOURCE_DIR} "${CMAKE_CURRENT_BINARY_DIR}/gmock") #set (OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Don't treat warnings as errors in 3rd_party/{gmock,cucumber-cpp} #string (REPLACE " -Werror " " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) #find_package(Gtest REQUIRED) #include_directories(${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR}) #set (CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS}) include_directories( ${CMAKE_SOURCE_DIR}/src/modules ${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR} ${MIRSERVER_INCLUDE_DIRS} ${QT_TEST} ) add_executable( application_manager_test application_manager_test.cpp ) add_executable( taskcontroller_test taskcontroller_test.cpp ) # We should not need this line according to the Qt5/CMake docs. # However, when removing it, include paths are not set and linking to Qt5 fails. qt5_use_modules(application_manager_test Core Quick DBus Test) qt5_use_modules(taskcontroller_test Core Quick DBus) target_link_libraries( application_manager_test unityapplicationplugin Qt5::Core Qt5::Quick Qt5::DBus gtest gtest_main gmock ) target_link_libraries( taskcontroller_test unityapplicationplugin Qt5::Core Qt5::Quick Qt5::DBus gtest gtest_main gmock ) add_test(taskcontroller_test ${CMAKE_CURRENT_BINARY_DIR}/taskcontroller_test) add_test(application_manager_test ${CMAKE_CURRENT_BINARY_DIR}/application_manager_test) add_subdirectory(auto) unity-mir-0.3+14.04.20140417/tests/mock_desktop_file_reader.h0000644000015301777760000001342312323676377024252 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef MOCK_DESKTOP_FILE_READER_H #define MOCK_DESKTOP_FILE_READER_H #include #include namespace testing { struct MockDesktopFileReader : public unitymir::DesktopFileReader { MockDesktopFileReader(const QString& appId) : unitymir::DesktopFileReader(appId) { using namespace ::testing; ON_CALL(*this, file()).WillByDefault(Invoke(this, &MockDesktopFileReader::doFile)); ON_CALL(*this, appId()).WillByDefault(Invoke(this, &MockDesktopFileReader::doAppId)); ON_CALL(*this, name()).WillByDefault(Invoke(this, &MockDesktopFileReader::doName)); ON_CALL(*this, comment()).WillByDefault(Invoke(this, &MockDesktopFileReader::doComment)); ON_CALL(*this, icon()).WillByDefault(Invoke(this, &MockDesktopFileReader::doIcon)); ON_CALL(*this, exec()).WillByDefault(Invoke(this, &MockDesktopFileReader::doExec)); ON_CALL(*this, path()).WillByDefault(Invoke(this, &MockDesktopFileReader::doPath)); ON_CALL(*this, stageHint()).WillByDefault(Invoke(this, &MockDesktopFileReader::doStageHint)); ON_CALL(*this, loaded()).WillByDefault(Invoke(this, &MockDesktopFileReader::doLoaded)); ON_CALL(*this, findDesktopFile(_)).WillByDefault(Invoke(this, &MockDesktopFileReader::doFindDesktopFile)); } MockDesktopFileReader(const QFileInfo& fileInfo) : DesktopFileReader(fileInfo) { using namespace ::testing; ON_CALL(*this, file()).WillByDefault(Invoke(this, &MockDesktopFileReader::doFile)); ON_CALL(*this, appId()).WillByDefault(Invoke(this, &MockDesktopFileReader::doAppId)); ON_CALL(*this, name()).WillByDefault(Invoke(this, &MockDesktopFileReader::doName)); ON_CALL(*this, comment()).WillByDefault(Invoke(this, &MockDesktopFileReader::doComment)); ON_CALL(*this, icon()).WillByDefault(Invoke(this, &MockDesktopFileReader::doIcon)); ON_CALL(*this, exec()).WillByDefault(Invoke(this, &MockDesktopFileReader::doExec)); ON_CALL(*this, path()).WillByDefault(Invoke(this, &MockDesktopFileReader::doPath)); ON_CALL(*this, stageHint()).WillByDefault(Invoke(this, &MockDesktopFileReader::doStageHint)); ON_CALL(*this, loaded()).WillByDefault(Invoke(this, &MockDesktopFileReader::doLoaded)); ON_CALL(*this, findDesktopFile(_)).WillByDefault(Invoke(this, &MockDesktopFileReader::doFindDesktopFile)); } MOCK_CONST_METHOD0(file, QString()); MOCK_CONST_METHOD0(appId, QString ()); MOCK_CONST_METHOD0(name, QString()); MOCK_CONST_METHOD0(comment, QString()); MOCK_CONST_METHOD0(icon, QString()); MOCK_CONST_METHOD0(exec, QString()); MOCK_CONST_METHOD0(path, QString()); MOCK_CONST_METHOD0(stageHint, QString()); MOCK_CONST_METHOD0(loaded, bool()); MOCK_CONST_METHOD1(findDesktopFile, QString(const QString&)); QString doFile() const { return DesktopFileReader::file(); } QString doAppId() const { return DesktopFileReader::appId(); } QString doName() const { return DesktopFileReader::name(); } QString doComment() const { return DesktopFileReader::comment(); } QString doIcon() const { return DesktopFileReader::icon(); } QString doExec() const { return DesktopFileReader::exec(); } QString doPath() const { return DesktopFileReader::path(); } QString doStageHint() const { return DesktopFileReader::stageHint(); } bool doLoaded() const { return DesktopFileReader::loaded(); } QString doFindDesktopFile(const QString& appId) const { return DesktopFileReader::findDesktopFile(appId); } }; struct MockDesktopFileReaderFactory : public unitymir::DesktopFileReader::Factory { MockDesktopFileReaderFactory() { using namespace ::testing; ON_CALL(*this, createInstanceForAppId(_)) .WillByDefault( Invoke( this, &MockDesktopFileReaderFactory::doCreateInstanceForAppId)); ON_CALL(*this, createInstanceForDesktopFile(_)) .WillByDefault( Invoke( this, &MockDesktopFileReaderFactory::doCreateInstanceForDesktopFile)); } virtual unitymir::DesktopFileReader* doCreateInstanceForAppId(const QString& appId) { using namespace ::testing; auto instance = new NiceMock(appId); ON_CALL(*instance, loaded()).WillByDefault(Return(true)); return instance; } virtual unitymir::DesktopFileReader* doCreateInstanceForDesktopFile(const QFileInfo& fi) { using namespace ::testing; auto instance = new NiceMock(fi); ON_CALL(*instance, loaded()).WillByDefault(Return(true)); return instance; } MOCK_METHOD1(createInstanceForAppId, unitymir::DesktopFileReader*(const QString&)); MOCK_METHOD1(createInstanceForDesktopFile, unitymir::DesktopFileReader*(const QFileInfo&)); }; } #endif // MOCK_DESKTOP_FILE_READER_H unity-mir-0.3+14.04.20140417/tests/mock_focus_controller.h0000644000015301777760000000225612323676377023644 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef MOCK_MIR_SHELL_FOCUS_CONTROLLER_H #define MOCK_MIR_SHELL_FOCUS_CONTROLLER_H #include #include #include namespace testing { class MockFocusController : public mir::shell::FocusController { public: MOCK_METHOD0(focus_next, void()); MOCK_CONST_METHOD0(focussed_application, std::weak_ptr()); MOCK_METHOD1(set_focus_to, void(std::shared_ptrconst&)); }; } #endif // MOCK_MIR_SHELL_FOCUS_CONTROLLER_H_ unity-mir-0.3+14.04.20140417/cross-compile.sh0000755000015301777760000000426512323676377021056 0ustar pbusernogroup00000000000000#!/bin/bash # build script to compile unity-mir for armhf devices set -e usage() { echo "usage: $(basename $0) [-c] [-u]" echo "-c clean before building" echo "-u update partial chroot directory" echo "-h this message" } clean_build_dir() { rm -rf ${1} mkdir ${1} } BUILD_DIR=build-android-arm NUM_JOBS=$(( $(grep -c ^processor /proc/cpuinfo) + 1 )) _do_update_chroot=0 while getopts "cuh" OPTNAME do case $OPTNAME in c ) clean_build_dir ${BUILD_DIR} ;; u ) _do_update_chroot=1 ;; h ) usage exit 0 ;; * ) echo "invalid option specified" usage exit 1 ;; esac done if [ "${UNITYMIR_CHROOT_DIR}" = "" ]; then export UNITYMIR_CHROOT_DIR=$(pwd)/partial-armhf-chroot fi if [ ! -d ${UNITYMIR_CHROOT_DIR} ]; then echo "no partial chroot dir detected. attempting to create one" _do_update_chroot=1 fi if [ ! -d ${BUILD_DIR} ]; then mkdir ${BUILD_DIR} fi if [ ${_do_update_chroot} -eq 1 ] ; then pushd scripts > /dev/null ./setup-partial-armhf-chroot.sh ${UNITYMIR_CHROOT_DIR} popd > /dev/null # force a clean build after an update, since CMake cache maybe out of date clean_build_dir ${BUILD_DIR} fi echo "Using UNITYMIR_CHROOT_DIR: ${UNITYMIR_CHROOT_DIR}" pushd ${BUILD_DIR} > /dev/null export CMAKE_PREFIX_PATH=${UNITYMIR_CHROOT_DIR}/usr/lib/arm-linux-gnueabihf/cmake export PKG_CONFIG_PATH="${UNITYMIR_CHROOT_DIR}/usr/lib/pkgconfig:${UNITYMIR_CHROOT_DIR}/usr/lib/arm-linux-gnueabihf/pkgconfig" export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 export PKG_CONFIG_SYSROOT_DIR=${UNITYMIR_CHROOT_DIR} export PKG_CONFIG_EXECUTABLE=`which pkg-config` echo "Using PKG_CONFIG_PATH: $PKG_CONFIG_PATH" echo "Using PKG_CONFIG_EXECUTABLE: $PKG_CONFIG_EXECUTABLE" # These are used to make cmake select the host machine QT MOC compiler in the AutoMocInfo module export DEB_HOST_MULTIARCH=arm-linux-gnueabihf export DEB_BUILD_MULTIARCH=$(gcc -dumpmachine) cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/LinuxCrossCompile.cmake .. make -j${NUM_JOBS} popd ${BUILD_DIR} > /dev/null unity-mir-0.3+14.04.20140417/data/0000755000015301777760000000000012323677263016635 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/data/CMakeLists.txt0000644000015301777760000000033512323676377021403 0ustar pbusernogroup00000000000000configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/unity-mir.pc.in ${CMAKE_CURRENT_BINARY_DIR}/unity-mir.pc @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/unity-mir.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) unity-mir-0.3+14.04.20140417/data/unity-mir.pc.in0000644000015301777760000000067212323676377021535 0ustar pbusernogroup00000000000000prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ Name: @CMAKE_PROJECT_NAME@ Description: Qt wrapper for Mir functionality required by Unity Version: @UNITY_MIR_VERSION_MAJOR@.@UNITY_MIR_VERSION_MINOR@.@UNITY_MIR_VERSION_PATCH@ Libs: -L${libdir} -lunity-mir Cflags: -I${includedir}/unity-mir Requires: ubuntu-platform-api mirclient mirserver Qt5Core unity-mir-0.3+14.04.20140417/CMakeLists.txt0000644000015301777760000000562212323676377020476 0ustar pbusernogroup00000000000000cmake_minimum_required(VERSION 2.8) project(Unity-Mir) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON) include(GNUInstallDirs) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -pedantic -Wextra") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fno-strict-aliasing -pedantic -Wextra") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") option(Werror "Treat warnings as errors" ON) if (Werror) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wno-error=format") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-error=format") endif() if(NOT CMAKE_BUILD_TYPE) message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.") set(CMAKE_BUILD_TYPE RelWithDebInfo) endif() string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower) if(cmake_build_type_lower MATCHES relwithdebinfo) # workaround for http://public.kitware.com/Bug/view.php?id=14696 add_definitions(-DQT_NO_DEBUG) endif() # Disable Qt keywords add_definitions(-DQT_NO_KEYWORDS) ##################################################################### # Enable code coverage calculation with gcov/gcovr/lcov # Usage: # * Switch build type to coverage (use ccmake or cmake-gui) # * Invoke make, make test, make coverage # * Find html report in subdir coveragereport # * Find xml report feasible for jenkins in coverage.xml ##################################################################### IF(cmake_build_type_lower MATCHES coverage) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs" ) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs" ) SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -ftest-coverage -fprofile-arcs" ) SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ftest-coverage -fprofile-arcs" ) ENDIF(cmake_build_type_lower MATCHES coverage) include(CTest) set(UNITY_MIR_VERSION_MAJOR 1) set(UNITY_MIR_VERSION_MINOR 0) set(UNITY_MIR_VERSION_PATCH 0) find_package(PkgConfig REQUIRED) find_package(Threads REQUIRED) find_package(Qt5Core REQUIRED) find_package(Qt5Quick REQUIRED) find_package(Qt5DBus REQUIRED) find_package(Boost 1.50 COMPONENTS system REQUIRED) find_package(Protobuf REQUIRED) if(PROTOBUF_PROTOC_EXECUTABLE STREQUAL "PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND") message(SEND_ERROR "protoc executable not found! Missing protobuf-compiler package?") endif() pkg_check_modules(MIRSERVER mirserver REQUIRED) pkg_check_modules(MIRCOMMON mircommon REQUIRED) pkg_check_modules(UBUNTU_PLATFORM_API ubuntu-platform-api REQUIRED) add_subdirectory(src) add_subdirectory(data) add_subdirectory(tests) # TODO(tvoss): Enable coverage reporting once we have tests in place. #enable_coverage_report(posix_process_test linux_process_test) unity-mir-0.3+14.04.20140417/COPYING0000644000015301777760000010451312323676377016770 0ustar pbusernogroup00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 3 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 . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . unity-mir-0.3+14.04.20140417/src/0000755000015301777760000000000012323677263016513 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/src/unity-mir/0000755000015301777760000000000012323677263020450 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/src/unity-mir/sessionauthorizer.h0000644000015301777760000000257312323676377024435 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef SESSIONAUTHORIZER_H #define SESSIONAUTHORIZER_H //std #include // mir #include // Qt #include class SessionAuthorizer : public QObject, public mir::frontend::SessionAuthorizer { Q_OBJECT public: SessionAuthorizer(QObject *parent = 0); ~SessionAuthorizer(); virtual bool connection_is_allowed(pid_t pid) override; virtual bool configure_display_is_allowed(pid_t pid) override; virtual bool screencast_is_allowed(pid_t pid) override; Q_SIGNALS: // needs to be blocked queued signal which returns value for authorized void requestAuthorizationForSession(const quint64 &pid, bool &authorized); }; #endif // SESSIONAUTHORIZER_H unity-mir-0.3+14.04.20140417/src/unity-mir/sessioncreator.h0000644000015301777760000000327012323676377023673 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef SESSIONCREATOR_H #define SESSIONCREATOR_H #include namespace unity { namespace protobuf { class UnityService; } } class SessionCreator : public mir::frontend::ProtobufSessionCreator { public: SessionCreator( std::shared_ptr const& unityService, std::shared_ptr const& ipc_factory, std::shared_ptr const& session_authorizer, std::shared_ptr const& report); std::shared_ptr create_processor( std::shared_ptr const& sender, std::shared_ptr const& display_server, std::shared_ptr const& report) const override; private: std::shared_ptr m_unityService; }; #endif // SESSIONCREATOR_H unity-mir-0.3+14.04.20140417/src/unity-mir/logging.h0000644000015301777760000000303712323676377022257 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef UBUNTU_APPLICATION_PLUGIN_LOGGING_H #define UBUNTU_APPLICATION_PLUGIN_LOGGING_H #pragma GCC diagnostic ignored "-Wformat" #include // Logging and assertion macros. #define LOG(...) qDebug(__VA_ARGS__) #define LOG_IF(cond,...) do { if (cond) qDebug(__VA_ARGS__); } while(0) #define ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop()) #define NOT_REACHED() qt_assert("Not reached!",__FILE__,__LINE__) // Logging and assertion macros are compiled out for release builds. #if !defined(QT_NO_DEBUG) #define DLOG(...) LOG(__VA_ARGS__) #define DLOG_IF(cond,...) LOG_IF((cond), __VA_ARGS__) #define DASSERT(cond) ASSERT((cond)) #define DNOT_REACHED() NOT_REACHED() #else #define DLOG(...) qt_noop() #define DLOG_IF(cond,...) qt_noop() #define DASSERT(cond) qt_noop() #define DNOT_REACHED() qt_noop() #endif #endif // UBUNTU_APPLICATION_PLUGIN_LOGGING_H unity-mir-0.3+14.04.20140417/src/unity-mir/initialsurfaceplacementstrategy.h0000644000015301777760000000341712323676377027311 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef INITIALSURFACEPLACEMENTSTRATEGY_H #define INITIALSURFACEPLACEMENTSTRATEGY_H #include #include "mirserver/mir/shell/placement_strategy.h" #include "mirserver/mir/shell/display_layout.h" #include "mir/shell/session.h" #include "mir/scene/depth_id.h" #include #include class InitialSurfacePlacementStrategy : public QObject, public mir::shell::PlacementStrategy { Q_OBJECT public: InitialSurfacePlacementStrategy(const std::shared_ptr &displayLayout, QObject *parent = 0); ~InitialSurfacePlacementStrategy(); mir::shell::SurfaceCreationParameters place(const mir::shell::Session &session, const mir::shell::SurfaceCreationParameters &requestParameters) override; Q_SIGNALS: void requestPlacementForSession(const mir::shell::Session *session, uint32_t &x, uint32_t &y); private: const std::shared_ptr m_displayLayout; QMutex m_mutex; bool m_mainShellSurfaceFound; }; #endif // INITIALSURFACEPLACEMENTSTRATEGY_H unity-mir-0.3+14.04.20140417/src/unity-mir/sessioncreator.cpp0000644000015301777760000000333512323676377024230 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "sessioncreator.h" #include SessionCreator::SessionCreator( std::shared_ptr const& unityService, std::shared_ptr const& ipc_factory, std::shared_ptr const& session_authorizer, std::shared_ptr const& report) : ProtobufSessionCreator(ipc_factory, session_authorizer, report) , m_unityService(unityService) { } std::shared_ptr SessionCreator::create_processor( std::shared_ptr const& sender, std::shared_ptr const& display_server, std::shared_ptr const& report) const { auto const wrapped = mir::frontend::ProtobufSessionCreator::create_processor( sender, display_server, report); return std::make_shared(m_unityService, sender, wrapped); } unity-mir-0.3+14.04.20140417/src/unity-mir/shellserverconfiguration.h0000644000015301777760000000511312323676377025754 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013-2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef SHELLSERVERCONFIGURATION_H #define SHELLSERVERCONFIGURATION_H #include #include namespace unity { namespace protobuf { class UnityService; } } class FocusSetter; class SessionListener; class SessionAuthorizer; class SurfaceConfigurator; class InitialSurfacePlacementStrategy; class ShellServerConfiguration : public QObject, public mir::DefaultServerConfiguration { Q_OBJECT Q_PROPERTY(SessionAuthorizer* sessionAuthorizer READ sessionAuthorizer CONSTANT) Q_PROPERTY(SessionListener* sessionListener READ sessionListener CONSTANT) Q_PROPERTY(SurfaceConfigurator* surfaceConfigurator READ surfaceConfigurator CONSTANT) public: ShellServerConfiguration(int argc, char const* argv[], QObject* parent = 0); ~ShellServerConfiguration(); /* mir specific */ std::shared_ptr the_display_configuration_policy() override; std::shared_ptr the_shell_placement_strategy() override; std::shared_ptr the_shell_session_listener() override; std::shared_ptr the_surface_configurator() override; std::shared_ptr the_shell_focus_setter() override; std::shared_ptr the_server_status_listener() override; std::shared_ptr the_session_authorizer() override; std::shared_ptr the_session_creator() override; /* qt specific */ // getters InitialSurfacePlacementStrategy *placementStrategy(); SessionAuthorizer *sessionAuthorizer(); SessionListener *sessionListener(); SurfaceConfigurator *surfaceConfigurator(); FocusSetter *focusSetter(); protected: std::shared_ptr m_unityService; }; #endif // SHELLSERVERCONFIGURATION_H unity-mir-0.3+14.04.20140417/src/unity-mir/qmirserver.h0000644000015301777760000000261512323676377023031 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef QMIRSERVER_H #define QMIRSERVER_H #include #include #include "shellserverconfiguration.h" class QMirServer: public QObject { Q_OBJECT public: QMirServer(int argc, const char *argv[], QObject* parent=0); ~QMirServer(); int runWithClient(std::function); private: int m_argc; const char** m_argv; Q_DISABLE_COPY(QMirServer) }; // class factory extern "C" { QMirServer *createQMirServer(int argc, const char **argv); int runQMirServerWithClient(QMirServer *mirServer, std::function client); void destroyQMirServer(QMirServer *mirServer); } #endif // QMIRSERVER_H unity-mir-0.3+14.04.20140417/src/unity-mir/sessionauthorizer.cpp0000644000015301777760000000307712323676377024770 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "sessionauthorizer.h" #include "logging.h" SessionAuthorizer::SessionAuthorizer(QObject *parent) : QObject(parent) { } SessionAuthorizer::~SessionAuthorizer() { } bool SessionAuthorizer::connection_is_allowed(pid_t pid) { DLOG("SessionAuthorizer::connection_is_allowed (this=%p, pid=%d", this, pid); bool authorized = true; Q_EMIT requestAuthorizationForSession(pid, authorized); // needs to block until authorized value returned return authorized; } bool SessionAuthorizer::configure_display_is_allowed(pid_t pid) { DLOG("SessionAuthorizer::configure_display_is_allowed (this=%p, pid=%d)", this, pid); //FIXME(ricmm) Actually mediate this access for clients Q_UNUSED(pid) return true; } bool SessionAuthorizer::screencast_is_allowed(pid_t pid) { DLOG("SessionAuthorizer::screencast_is_allowed (this=%p, pid=%d)", this, pid); Q_UNUSED(pid) return true; } unity-mir-0.3+14.04.20140417/src/unity-mir/initialsurfaceplacementstrategy.cpp0000644000015301777760000000546512323676377027651 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // local #include "initialsurfaceplacementstrategy.h" #include "logging.h" // mir #include "mir/shell/surface_creation_parameters.h" #include "mir/geometry/rectangle.h" namespace msh = mir::shell; namespace msc = mir::scene; InitialSurfacePlacementStrategy::InitialSurfacePlacementStrategy( const std::shared_ptr &displayLayout, QObject *parent) : QObject(parent) , m_displayLayout(displayLayout) , m_mainShellSurfaceFound(false) { DLOG("InitialSurfacePlacementStrategy::InitialSurfacePlacementStrategy (%p)", this); } InitialSurfacePlacementStrategy::~InitialSurfacePlacementStrategy() { } msh::SurfaceCreationParameters InitialSurfacePlacementStrategy::place(const msh::Session &session, const msh::SurfaceCreationParameters &requestParameters) { DLOG("InitialSurfacePlacementStrategy::place (%p, %s, %d)", this, session.name().c_str(), session.process_id()); using namespace mir::geometry; auto placedParameters = requestParameters; // decide surface depth static const msc::DepthId shellSurfaceDepth{1}; static const msc::DepthId oskSurfaceDepth{2}; { // as this method may be called by multiple threads, need to lock for m_mainShellSurfaceFound QMutexLocker lock(&m_mutex); if (session.process_id() == 0 && !m_mainShellSurfaceFound) { DLOG("Shell main surface found, placed at shell depth"); m_mainShellSurfaceFound = true; placedParameters.depth = shellSurfaceDepth; placedParameters.input_mode = mir::input::InputReceptionMode::receives_all_input; return placedParameters; } else if (placedParameters.name == "MaliitOnScreenKeyboard") { // FIXME: string hardcoded into maliit DLOG("OSK depth"); placedParameters.depth = oskSurfaceDepth; } else { DLOG("Default depth"); } } // determine x,y position of the surface by asking shell, if it is up uint32_t x = 0; uint32_t y = 0; Q_EMIT requestPlacementForSession(&session, x, y); placedParameters.top_left = Point{ X{x}, Y{y} }; return placedParameters; } unity-mir-0.3+14.04.20140417/src/unity-mir/serverstatuslistener.h0000644000015301777760000000173012323676377025147 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef SERVERSTATUSLISTENER_H #define SERVERSTATUSLISTENER_H #include class ServerStatusListener : public virtual mir::ServerStatusListener { public: void paused() override; void resumed() override; void started() override; }; #endif // SERVERSTATUSLISTENER_H unity-mir-0.3+14.04.20140417/src/unity-mir/qmirserverapplication.h0000644000015301777760000000312012323676377025245 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef QMIRSERVERAPPLICATION_H #define QMIRSERVERAPPLICATION_H #include class ShellServerConfiguration; class QMirServerApplicationPrivate; class QMirServerApplication : public QGuiApplication { Q_OBJECT public: explicit QMirServerApplication(int &argc, char **argv, ShellServerConfiguration* serverConfiguration); ~QMirServerApplication(); ShellServerConfiguration* server() const; protected: QMirServerApplicationPrivate * const d_ptr; private: Q_DECLARE_PRIVATE(QMirServerApplication) }; // class factory extern "C" { QMirServerApplication *createQMirServerApplication(int &argc, char **argv, ShellServerConfiguration *serverConfiguration); ShellServerConfiguration* server(QMirServerApplication *mirServer); void destroyQMirServerApplication(QMirServerApplication *mirServer); } #endif // QMIRSERVERAPPLICATION_H unity-mir-0.3+14.04.20140417/src/unity-mir/focussetter.h0000644000015301777760000000326312323676377023200 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef FOCUSSETTER_H #define FOCUSSETTER_H // mir #include // Qt #include namespace mir { namespace shell { class InputTargeter; class Surface; } } class FocusSetter : public QObject, public mir::shell::FocusSetter { Q_OBJECT public: FocusSetter(std::shared_ptr const& underlying_setter, std::shared_ptr const& keyboard_input_targeter, QObject *parent = 0); ~FocusSetter(); void set_focus_to(std::shared_ptr const& session) override; // We support a surface to be given key input when focus is otherwise to be cleared. void set_default_keyboard_target(std::weak_ptr const& default_keyboard_target); private: std::shared_ptr const underlying_setter; std::shared_ptr const keyboard_input_targeter; std::weak_ptr default_keyboard_target; }; #endif // FOCUSSETTER_H unity-mir-0.3+14.04.20140417/src/unity-mir/qmirserverapplication.cpp0000644000015301777760000000372412323676377025612 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "qmirserverapplication.h" class QMirServerApplicationPrivate { public: QMirServerApplicationPrivate(ShellServerConfiguration* serverConfiguration, QMirServerApplication *qq) : q_ptr(qq) , serverConfiguration(serverConfiguration) {} QMirServerApplication * const q_ptr; ShellServerConfiguration *serverConfiguration; Q_DECLARE_PUBLIC(QMirServerApplication) }; QMirServerApplication::QMirServerApplication(int &argc, char **argv, ShellServerConfiguration* serverConfiguration) : QGuiApplication(argc, argv) , d_ptr(new QMirServerApplicationPrivate(serverConfiguration, this)) { } QMirServerApplication::~QMirServerApplication() { delete d_ptr; } ShellServerConfiguration* QMirServerApplication::server() const { Q_D(const QMirServerApplication); return d->serverConfiguration; } // class factory implemenation extern "C" { QMirServerApplication *createQMirServerApplication(int &argc, char **argv, ShellServerConfiguration *serverConfiguration) { return new QMirServerApplication(argc, argv, serverConfiguration); } ShellServerConfiguration* server(QMirServerApplication *mirServer) { return mirServer->server(); } void destroyQMirServerApplication(QMirServerApplication *mirServer) { delete mirServer; } } unity-mir-0.3+14.04.20140417/src/unity-mir/surfaceconfigurator.cpp0000644000015301777760000000220512323676377025233 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "surfaceconfigurator.h" namespace ms = mir::scene; SurfaceConfigurator::SurfaceConfigurator() { qRegisterMetaType("MirSurfaceAttrib"); } int SurfaceConfigurator::select_attribute_value(ms::Surface const&, MirSurfaceAttrib, int requested_value) { return requested_value; } void SurfaceConfigurator::attribute_set(ms::Surface const& surface, MirSurfaceAttrib attrib, int value) { Q_EMIT surfaceAttributeChanged(&surface, attrib, value); } unity-mir-0.3+14.04.20140417/src/unity-mir/unityrpc.proto0000644000015301777760000000043112323676377023415 0ustar pbusernogroup00000000000000option cc_generic_services = true; package unity.protobuf; message Clip { required bytes content = 1; optional string error = 127; } message Void { optional string error = 127; } service UnityService { rpc copy(Clip) returns (Void); rpc paste(Void) returns (Clip); } unity-mir-0.3+14.04.20140417/src/unity-mir/sessionlistener.cpp0000644000015301777760000000605612323676377024421 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "sessionlistener.h" #include "logging.h" #include namespace msh = mir::shell; Q_DECLARE_METATYPE(std::shared_ptr) SessionListener::SessionListener(QObject *parent) : QObject(parent) { DLOG("SessionListener::SessionListener (this=%p)", this); // need to register type to send over threads with signal/slot qRegisterMetaType>("std::shared_ptr"); qRegisterMetaType>("std::shared_ptr"); } SessionListener::~SessionListener() { DLOG("SessionListener::~SessionListener (this=%p)", this); } // Mir's default SurfaceManager calls these methods with instance of msh::Session // it is not a plain msh::Session void SessionListener::starting(std::shared_ptr const& session) { DLOG("SessionListener::starting (this=%p, session=%p)", this, (void*)session.get()); Q_EMIT sessionStarting(std::static_pointer_cast(session)); } void SessionListener::stopping(std::shared_ptr const& session) { DLOG("SessionListener::stopping (this=%p, session=%p)", this, (void*)session.get()); Q_EMIT sessionStopping(std::static_pointer_cast(session)); } void SessionListener::focused(std::shared_ptr const& session) { DLOG("SessionListener::focused (this=%p, session=%p)", this, (void*)session.get()); Q_EMIT sessionFocused(std::static_pointer_cast(session)); } void SessionListener::unfocused() { DLOG("SessionListener::unfocused (this=%p)", this); Q_EMIT sessionUnfocused(); } void SessionListener::surface_created(msh::Session& session, std::shared_ptr const& surface) { DLOG("SessionListener::surface_created (this=%p, session=%p, surface=%p)", this, &session, (void*)surface.get()); static bool mainShellSurfaceFound = false; if (session.process_id() == 0 && !mainShellSurfaceFound) { Q_EMIT shellSurfaceCreated(surface); mainShellSurfaceFound = true; } else { Q_EMIT sessionCreatedSurface(&session, surface); } } void SessionListener::destroying_surface(msh::Session& session, std::shared_ptr const& surface) { DLOG("SessionListener::destroying_surface (this=%p, session=%p, surface=%p)", this, &session, (void*)surface.get()); Q_EMIT sessionDestroyingSurface(&session, surface); } unity-mir-0.3+14.04.20140417/src/unity-mir/unityprotobufservice.h0000644000015301777760000000253512323676377025145 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef UNITY_PROTOBUF_SERVICE_H #define UNITY_PROTOBUF_SERVICE_H #include "unityrpc.pb.h" #include class UnityProtobufService : public unity::protobuf::UnityService { public: void copy(::google::protobuf::RpcController* controller, const ::unity::protobuf::Clip* request, ::unity::protobuf::Void* response, ::google::protobuf::Closure* done) override; void paste(::google::protobuf::RpcController* controller, const ::unity::protobuf::Void* request, ::unity::protobuf::Clip* response, ::google::protobuf::Closure* done) override; private: std::string m_clip; }; #endif // UNITY_PROTOBUF_SERVICE_H unity-mir-0.3+14.04.20140417/src/unity-mir/serverstatuslistener.cpp0000644000015301777760000000252712323676377025507 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // local #include "serverstatuslistener.h" // Qt #include #include // std #include void ServerStatusListener::paused() { } void ServerStatusListener::resumed() { } void ServerStatusListener::started() { // Emit signal to notify Upstart that Mir is ready to receive client connections // see http://upstart.ubuntu.com/cookbook/#expect-stop // FIXME: should not be unity-mir's job, instead should notify the user of this library // that they should emit this signal, perhaps by posting an event to the // QMirServerApplication event loop when it comes up if (qgetenv("UPSTART_JOB") == "unity8") { raise(SIGSTOP); } } unity-mir-0.3+14.04.20140417/src/unity-mir/messageprocessor.cpp0000644000015301777760000000303112323676377024542 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "messageprocessor.h" #include bool MessageProcessor::dispatch(mir::frontend::detail::Invocation const& invocation) { if ("copy" == invocation.method_name()) { mir::frontend::detail::invoke( this, m_unityService.get(), &unity::protobuf::UnityService::copy, invocation); return true; } else if ("paste" == invocation.method_name()) { mir::frontend::detail::invoke( this, m_unityService.get(), &unity::protobuf::UnityService::paste, invocation); return true; } else { return m_wrapped->dispatch(invocation); } } void MessageProcessor::send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response) { m_sender->send_response(id, response, {}); } unity-mir-0.3+14.04.20140417/src/unity-mir/displayconfigurationpolicy.cpp0000644000015301777760000000420012323676377026632 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013,2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "displayconfigurationpolicy.h" #include "logging.h" #include "mir/graphics/display_configuration.h" #include "mir/graphics/pixel_format_utils.h" #include namespace geom = mir::geometry; namespace mg = mir::graphics; DisplayConfigurationPolicy::DisplayConfigurationPolicy(std::shared_ptr const& base_policy, bool with_alpha) : base_policy{base_policy}, with_alpha{with_alpha} { } void DisplayConfigurationPolicy::apply_to(mg::DisplayConfiguration& conf) { DLOG("DisplayConfigurationPolicy::apply_to (this=%p, conf=%p)", this, &conf); base_policy->apply_to(conf); conf.for_each_output( [&](mg::UserDisplayConfigurationOutput& conf_output) { if (!conf_output.connected || !conf_output.used) return; auto const& format = find_if(conf_output.pixel_formats.begin(), conf_output.pixel_formats.end(), [&](MirPixelFormat format) -> bool { return mg::contains_alpha(format) == with_alpha; } ); // keep the default settings if nothing was found if (format == conf_output.pixel_formats.end()) return; conf_output.current_format = *format; }); } unity-mir-0.3+14.04.20140417/src/unity-mir/CMakeLists.txt0000644000015301777760000000346612323676377023226 0ustar pbusernogroup00000000000000include_directories( ${MIRCOMMON_INCLUDE_DIRS} ${MIRSERVER_INCLUDE_DIRS} ${UBUNTU_PLATFORM_API_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ) protobuf_generate_cpp( GENERATED_PROTOBUF_SRCS GENERATED_PROTOBUF_HDRS unityrpc.proto ) set( UNITY_MIR_HEADERS displayconfigurationpolicy.h initialsurfaceplacementstrategy.h qmirserverapplication.h qmirserver.h messageprocessor.h sessionauthorizer.h sessioncreator.h sessionlistener.h shellserverconfiguration.h surfaceconfigurator.h unityprotobufservice.h logging.h focussetter.h serverstatuslistener.h ${GENERATED_PROTOBUF_HDRS} ) add_library( unity-mir SHARED displayconfigurationpolicy.cpp initialsurfaceplacementstrategy.cpp qmirserverapplication.cpp qmirserver.cpp messageprocessor.cpp sessionauthorizer.cpp sessioncreator.cpp sessionlistener.cpp shellserverconfiguration.cpp surfaceconfigurator.cpp unityprotobufservice.cpp focussetter.cpp serverstatuslistener.cpp ${UNITY_MIR_HEADERS} ${GENERATED_PROTOBUF_SRCS} ) # We should not need this line according to the Qt5/CMake docs. # However, when removing it, include paths are not set and linking to Qt5 fails. qt5_use_modules(unity-mir Core Quick) set_target_properties( unity-mir PROPERTIES VERSION ${UNITY_MIR_VERSION_MAJOR}.${UNITY_MIR_VERSION_MINOR}.${UNITY_MIR_VERSION_PATCH} SOVERSION ${UNITY_MIR_VERSION_MAJOR}) target_link_libraries( unity-mir Qt5::Core Qt5::Quick ${CMAKE_THREAD_LIBS_INIT} ${UBUNTU_PLATFORM_API_LDFLAGS} ${MIRSERVER_LDFLAGS} ${PROTOBUF_LIBRARIES} ${Boost_SYSTEM_LIBRARY_RELEASE} ubuntu_application_api_mirserver) install( TARGETS unity-mir LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) install( FILES ${UNITY_MIR_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unity-mir) unity-mir-0.3+14.04.20140417/src/unity-mir/unityprotobufservice.cpp0000644000015301777760000000237212323676377025477 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "unityprotobufservice.h" void UnityProtobufService::copy(::google::protobuf::RpcController* /*controller*/, const ::unity::protobuf::Clip* newClip, ::unity::protobuf::Void* /*response*/, ::google::protobuf::Closure* done) { m_clip = newClip->content(); done->Run(); } void UnityProtobufService::paste(::google::protobuf::RpcController* /*controller*/, const ::unity::protobuf::Void* /*request*/, ::unity::protobuf::Clip* clipReturned, ::google::protobuf::Closure* done) { clipReturned->set_content(m_clip); done->Run(); } unity-mir-0.3+14.04.20140417/src/unity-mir/displayconfigurationpolicy.h0000644000015301777760000000243512323676377026307 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013,2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef DISPLAYCONFIGURATIONPOLICY_H #define DISPLAYCONFIGURATIONPOLICY_H #include "mir/graphics/display_configuration_policy.h" #include class DisplayConfigurationPolicy : public mir::graphics::DisplayConfigurationPolicy { public: DisplayConfigurationPolicy(std::shared_ptr const& base_policy, bool with_alpha); void apply_to(mir::graphics::DisplayConfiguration& conf); private: std::shared_ptr const base_policy; bool const with_alpha; }; #endif // DISPLAYCONFIGURATIONPOLICY_H unity-mir-0.3+14.04.20140417/src/unity-mir/focussetter.cpp0000644000015301777760000000355312323676377023535 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include #include "focussetter.h" #include "logging.h" namespace msh = mir::shell; FocusSetter::FocusSetter(std::shared_ptr const& underlying_setter, std::shared_ptr const& keyboard_input_targeter, QObject *parent) : QObject(parent), underlying_setter(underlying_setter), keyboard_input_targeter(keyboard_input_targeter) { } FocusSetter::~FocusSetter() { } void FocusSetter::set_focus_to(std::shared_ptr const& session) { DLOG("FocusSetter::set_focus_to(session=%p):%d", session.get(), __LINE__); // Ensure we always call the underlying setter to dispatch focus/unfocus notifications. underlying_setter->set_focus_to(session); if (session == nullptr) { auto default_target = default_keyboard_target.lock(); if (!default_target) return; default_target->take_input_focus(keyboard_input_targeter); } } void FocusSetter::set_default_keyboard_target(std::weak_ptr const& default_target) { auto t = default_target.lock(); assert(t); default_keyboard_target = default_target; t->take_input_focus(keyboard_input_targeter); } unity-mir-0.3+14.04.20140417/src/unity-mir/sessionlistener.h0000644000015301777760000000377512323676377024073 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef SESSIONLISTENER_H #define SESSIONLISTENER_H #include #include "mir/shell/session_listener.h" class SessionListener : public QObject, public mir::shell::SessionListener { Q_OBJECT public: explicit SessionListener(QObject *parent = 0); ~SessionListener(); void starting(std::shared_ptr const& session) override; void stopping(std::shared_ptr const& session) override; void focused(std::shared_ptr const& session) override; void unfocused() override; void surface_created(mir::shell::Session&, std::shared_ptr const&) override; void destroying_surface(mir::shell::Session&, std::shared_ptr const&) override; Q_SIGNALS: void sessionStarting(std::shared_ptr const& session); void sessionStopping(std::shared_ptr const& session); void sessionFocused(std::shared_ptr const& session); void sessionUnfocused(); void sessionCreatedSurface(mir::shell::Session const*, std::shared_ptr const&); void sessionDestroyingSurface(mir::shell::Session const*, std::shared_ptr const&); void shellSurfaceCreated(std::shared_ptr const&); }; #endif // SESSIONLISTENER_H unity-mir-0.3+14.04.20140417/src/unity-mir/messageprocessor.h0000644000015301777760000000321212323676377024210 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include #include #include "unityrpc.pb.h" #include class MessageProcessor : public mir::frontend::detail::MessageProcessor { public: MessageProcessor( std::shared_ptr const& unityService, std::shared_ptr const& sender, std::shared_ptr const& wrapped) : m_sender(sender), m_wrapped(wrapped), m_unityService(unityService) {} bool dispatch(mir::frontend::detail::Invocation const& invocation); void send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response); private: std::shared_ptr const m_sender; std::shared_ptr const m_wrapped; std::shared_ptr const m_unityService; }; unity-mir-0.3+14.04.20140417/src/unity-mir/shellserverconfiguration.cpp0000644000015301777760000001227212323676377026313 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013-2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "shellserverconfiguration.h" #include "displayconfigurationpolicy.h" #include "unityprotobufservice.h" #include "initialsurfaceplacementstrategy.h" #include "serverstatuslistener.h" #include "sessioncreator.h" #include "sessionlistener.h" #include "surfaceconfigurator.h" #include "sessionauthorizer.h" #include "focussetter.h" #include "logging.h" namespace mg = mir::graphics; namespace msh = mir::shell; namespace ms = mir::scene; ShellServerConfiguration::ShellServerConfiguration(int argc, char const* argv[], QObject* parent) : QObject(parent) , DefaultServerConfiguration(argc, argv) , m_unityService(std::make_shared()) { DLOG("ShellServerConfiguration created"); } ShellServerConfiguration::~ShellServerConfiguration() { } std::shared_ptr ShellServerConfiguration::the_display_configuration_policy() { return display_configuration_policy( [this] { bool alpha = (qgetenv("XDG_SESSION_CLASS") == "greeter"); return std::make_shared(DefaultServerConfiguration::the_display_configuration_policy(), alpha); }); } std::shared_ptr ShellServerConfiguration::the_shell_placement_strategy() { return shell_placement_strategy( [this] { return std::make_shared(the_shell_display_layout()); }); } std::shared_ptr ShellServerConfiguration::the_shell_session_listener() { return shell_session_listener( [this] { return std::make_shared(); }); } std::shared_ptr ShellServerConfiguration::the_surface_configurator() { return surface_configurator( [this]() { return std::make_shared(); }); } std::shared_ptr ShellServerConfiguration::the_session_authorizer() { return session_authorizer( [] { return std::make_shared(); }); } std::shared_ptr ShellServerConfiguration::the_session_creator() { return session_creator([this] { return std::make_shared( m_unityService, the_ipc_factory(the_frontend_shell(), the_buffer_allocator()), the_session_authorizer(), the_message_processor_report()); }); } std::shared_ptr ShellServerConfiguration::the_shell_focus_setter() { return shell_focus_setter( [this] { return std::make_shared(DefaultServerConfiguration::the_shell_focus_setter(), the_input_targeter()); }); } std::shared_ptr ShellServerConfiguration::the_server_status_listener() { return server_status_listener( []() { return std::make_shared(); }); } /************************************ Shell side ************************************/ // // Note about the // if (sharedPtr.unique()) return 0; // constructs used in the functions below. // The rationale is that if when you do // the_session_authorizer() // get a pointer that is unique means that Mir is not // holding the pointer and thus when we return from the // sessionAuthorizer() // scope the unique pointer will be destroyed so we return 0 // InitialSurfacePlacementStrategy *ShellServerConfiguration::placementStrategy() { auto sharedPtr = the_shell_placement_strategy(); if (sharedPtr.unique()) return 0; return static_cast(sharedPtr.get()); } SessionAuthorizer *ShellServerConfiguration::sessionAuthorizer() { auto sharedPtr = the_session_authorizer(); if (sharedPtr.unique()) return 0; return static_cast(sharedPtr.get()); } SessionListener *ShellServerConfiguration::sessionListener() { auto sharedPtr = the_shell_session_listener(); if (sharedPtr.unique()) return 0; return static_cast(sharedPtr.get()); } SurfaceConfigurator *ShellServerConfiguration::surfaceConfigurator() { auto sharedPtr = the_surface_configurator(); if (sharedPtr.unique()) return 0; return static_cast(sharedPtr.get()); } FocusSetter *ShellServerConfiguration::focusSetter() { auto sharedPtr = the_shell_focus_setter(); if (sharedPtr.unique()) return 0; return static_cast(sharedPtr.get()); } unity-mir-0.3+14.04.20140417/src/unity-mir/qmirserver.cpp0000644000015301777760000000534412323676377023366 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // Mir support #include #include #include // Platform API #include // Qt #include #include #include // Std #include #include // local #include "qmirserver.h" QMirServer::QMirServer(int argc, const char* argv[], QObject *parent) : QObject(parent) , m_argc(argc) , m_argv(argv) { } QMirServer::~QMirServer() { } int QMirServer::runWithClient(std::function client) { // need local copies as lambda function will not capture class members int argc = m_argc; auto argv = m_argv; auto config = new ShellServerConfiguration(m_argc, m_argv); std::thread *t; mir::run_mir(*config, [config, &client, &argc, &argv, &t](mir::DisplayServer&) { ua_ui_mirserver_init(*config); try { t = new std::thread(client, argc, argv, config); } catch (...) { qDebug() << "Exception caught, quitting"; } }); if (QCoreApplication::instance()) { bool aboutToQuitSignaled = false; QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, [&]() { aboutToQuitSignaled = true; } ); QCoreApplication::quit(); while (!aboutToQuitSignaled) { std::chrono::milliseconds duration(100); std::this_thread::sleep_for(duration); QCoreApplication::quit(); } } t->join(); ua_ui_mirserver_finish(); delete config; return 0; } // class factory implementation extern "C" { QMirServer *createQMirServer(int argc, const char **argv) { return new QMirServer(argc, argv); } int runQMirServerWithClient(QMirServer *mirServer, std::function client) { return mirServer->runWithClient(client); } void destroyQMirServer(QMirServer *mirServer) { delete mirServer; } } unity-mir-0.3+14.04.20140417/src/unity-mir/surfaceconfigurator.h0000644000015301777760000000250012323676377024676 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef SURFACECONFIGURATOR_H #define SURFACECONFIGURATOR_H #include #include #include namespace mir { namespace shell { class Surface; }} class SurfaceConfigurator : public QObject, public mir::scene::SurfaceConfigurator { Q_OBJECT public: SurfaceConfigurator(); int select_attribute_value(mir::scene::Surface const&, MirSurfaceAttrib, int) override; void attribute_set(mir::scene::Surface const&, MirSurfaceAttrib, int) override; Q_SIGNALS: void surfaceAttributeChanged(mir::scene::Surface const*, const MirSurfaceAttrib, const int); }; #endif // SURFACECONFIGURATOR_H unity-mir-0.3+14.04.20140417/src/CMakeLists.txt0000644000015301777760000000006612323676377021262 0ustar pbusernogroup00000000000000add_subdirectory(unity-mir) add_subdirectory(modules) unity-mir-0.3+14.04.20140417/src/modules/0000755000015301777760000000000012323677263020163 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/src/modules/Unity/0000755000015301777760000000000012323677263021273 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/0000755000015301777760000000000012323677263023536 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/application_manager.cpp0000644000015301777760000010712612323676377030253 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // local #include "application_manager.h" #include "proc_info.h" #include "application.h" #include "desktopfilereader.h" #include "dbuswindowstack.h" #include "taskcontroller.h" #include "upstart/applicationcontroller.h" // unity-mir #include "qmirserverapplication.h" #include "shellserverconfiguration.h" #include "sessionlistener.h" #include "sessionauthorizer.h" #include "initialsurfaceplacementstrategy.h" #include "taskcontroller.h" #include "logging.h" // mir #include #include #include #include #include #include #include // Qt #include // std #include // Default element sizes #define SIDE_STAGE_WIDTH_GU 40 #define TABLET_MODE_MINIMUM_WIDTH_GU 100 namespace msh = mir::shell; using namespace unity::shell::application; namespace unitymir { namespace { QSize get_display_size(const std::shared_ptr & display) { // Obtain display size mir::geometry::Rectangles view_area; display->for_each_display_buffer( [&view_area](const mir::graphics::DisplayBuffer & db) { view_area.add(db.view_area()); }); return QSize( view_area.bounding_rectangle().size.width.as_uint32_t(), view_area.bounding_rectangle().size.height.as_uint32_t() ); } void connectToSessionListener(ApplicationManager * manager, SessionListener * listener) { QObject::connect(listener, &SessionListener::sessionStarting, manager, &ApplicationManager::onSessionStarting); QObject::connect(listener, &SessionListener::sessionStopping, manager, &ApplicationManager::onSessionStopping); QObject::connect(listener, &SessionListener::sessionFocused, manager, &ApplicationManager::onSessionFocused, Qt::QueuedConnection); QObject::connect(listener, &SessionListener::sessionUnfocused, manager, &ApplicationManager::onSessionUnfocused); QObject::connect(listener, &SessionListener::sessionCreatedSurface, manager, &ApplicationManager::onSessionCreatedSurface); } void connectToSessionAuthorizer(ApplicationManager * manager, SessionAuthorizer * authorizer) { QObject::connect(authorizer, &SessionAuthorizer::requestAuthorizationForSession, manager, &ApplicationManager::authorizeSession, Qt::BlockingQueuedConnection); } void connectToPlacementStrategy(ApplicationManager * manager, InitialSurfacePlacementStrategy * strategy) { QObject::connect(strategy, &InitialSurfacePlacementStrategy::requestPlacementForSession, manager, &ApplicationManager::placeSession, Qt::DirectConnection); } void connectToTaskController(ApplicationManager * manager, TaskController * controller) { QObject::connect(controller, &TaskController::processStartReport, manager, &ApplicationManager::onProcessStartReportReceived); QObject::connect(controller, &TaskController::processStopped, manager, &ApplicationManager::onProcessStopped); QObject::connect(controller, &TaskController::requestFocus, manager, &ApplicationManager::onFocusRequested); QObject::connect(controller, &TaskController::requestResume, manager, &ApplicationManager::onResumeRequested); } } ApplicationManager* ApplicationManager::Factory::Factory::create() { QMirServerApplication* mirServerApplication = dynamic_cast(QCoreApplication::instance()); if (mirServerApplication == nullptr) { LOG("Need to use QMirServerApplication"); QCoreApplication::quit(); return nullptr; } ShellServerConfiguration * mirServer = mirServerApplication->server(); QSize displaySize{get_display_size(mirServer->the_display())}; QSharedPointer appController(new upstart::ApplicationController()); QSharedPointer taskController(new TaskController(nullptr, appController)); QSharedPointer fileReaderFactory(new DesktopFileReader::Factory()); QSharedPointer procInfo(new ProcInfo()); // FIXME: We should use a QSharedPointer to wrap this ApplicationManager object, which requires us // to use the data() method to pass the raw pointer to the QML engine. However the QML engine appears // to take ownership of the object, and deletes it when it wants to. This conflicts with the purpose // of the QSharedPointer, and a double-delete results. Trying QQmlEngine::setObjectOwnership on the // object no effect, which it should. Need to investigate why. ApplicationManager* appManager = new ApplicationManager( taskController, fileReaderFactory, procInfo, mirServer->the_focus_controller(), displaySize ); connectToSessionListener(appManager, mirServer->sessionListener()); connectToSessionAuthorizer(appManager, mirServer->sessionAuthorizer()); connectToPlacementStrategy(appManager, mirServer->placementStrategy()); connectToTaskController(appManager, taskController.data()); return appManager; } ApplicationManager* ApplicationManager::singleton() { static ApplicationManager* instance; if (!instance) { Factory appFactory; instance = appFactory.create(); } return instance; } ApplicationManager::ApplicationManager( const QSharedPointer& taskController, const QSharedPointer& desktopFileReaderFactory, const QSharedPointer& procInfo, const std::shared_ptr& controller, const QSize& displaySize, QObject *parent) : ApplicationManagerInterface(parent) , m_focusedApplication(nullptr) , m_mainStageApplication(nullptr) , m_sideStageApplication(nullptr) , m_msApplicationToBeFocused(nullptr) , m_ssApplicationToBeFocused(nullptr) , m_lifecycleExceptions(QStringList() << "com.ubuntu.music") , m_focusController(controller) , m_dbusWindowStack(new DBusWindowStack(this)) , m_taskController(taskController) , m_desktopFileReaderFactory(desktopFileReaderFactory) , m_procInfo(procInfo) , m_gridUnitPx(8) , m_fenceNext(false) , m_displaySize(displaySize) , m_panelHeight(54) { DLOG("ApplicationManager::ApplicationManager (this=%p)", this); // Setup panel height QByteArray gridUnitString = qgetenv("GRID_UNIT_PX"); if (!gridUnitString.isEmpty()) { bool ok; int value = gridUnitString.toInt(&ok); if (ok) { m_gridUnitPx = value; } } int densityPixelPx = qFloor( (float)m_gridUnitPx / 8 ); m_panelHeight = 3 * m_gridUnitPx + 2 * densityPixelPx; } ApplicationManager::~ApplicationManager() { DLOG("ApplicationManager::~ApplicationManager"); } int ApplicationManager::panelHeight() { return m_panelHeight; } int ApplicationManager::rowCount(const QModelIndex &parent) const { return !parent.isValid() ? m_applications.size() : 0; } QVariant ApplicationManager::data(const QModelIndex &index, int role) const { if (index.row() >= 0 && index.row() < m_applications.size()) { Application *application = m_applications.at(index.row()); switch (role) { case RoleAppId: return QVariant::fromValue(application->appId()); case RoleName: return QVariant::fromValue(application->name()); case RoleComment: return QVariant::fromValue(application->comment()); case RoleIcon: return QVariant::fromValue(application->icon()); case RoleStage: return QVariant::fromValue((int)application->stage()); case RoleState: return QVariant::fromValue((int)application->state()); case RoleFocused: return QVariant::fromValue(application->focused()); case RoleScreenshot: return QVariant::fromValue(application->screenshot()); default: return QVariant(); } } else { return QVariant(); } } Application* ApplicationManager::get(int index) const { DLOG("ApplicationManager::get (this=%p, index=%i, count=%i)", this, index, m_applications.count()); if (index < 0 || index >= m_applications.count()) { return nullptr; } return m_applications.at(index); } Application* ApplicationManager::findApplication(const QString &appId) const { for (Application *app : m_applications) { if (app->appId() == appId) { return app; } } return nullptr; } bool ApplicationManager::requestFocusApplication(const QString &appId) { DLOG("ApplicationManager::requestFocusApplication (this=%p, appId=%s)", this, qPrintable(appId)); Application *application = findApplication(appId); if (!application) { DLOG("No such running application '%s'", qPrintable(appId)); return false; } if (application == m_focusedApplication) { DLOG("Application %s is already focused", qPrintable(appId)); return false; } // If there is a currently focused application, first update the screenshot // for it and only emit focusRequested() when the screenshot is ready. Application *currentlyFocusedApplication = findApplication(focusedApplicationId()); if (currentlyFocusedApplication) { m_nextFocusedAppId = appId; currentlyFocusedApplication->updateScreenshot(); } else { Q_EMIT focusRequested(appId); } return true; } QString ApplicationManager::focusedApplicationId() const { if (m_focusedApplication) { return m_focusedApplication->appId(); } else { return QString(); } } bool ApplicationManager::suspended() const { return m_suspended; } void ApplicationManager::setSuspended(bool suspended) { if (suspended == m_suspended) { return; } m_suspended = suspended; Q_EMIT suspendedChanged(); if (m_suspended) { suspendApplication(m_mainStageApplication); suspendApplication(m_sideStageApplication); } else { resumeApplication(m_mainStageApplication); resumeApplication(m_sideStageApplication); } } void ApplicationManager::suspendApplication(Application *application) { if (application == nullptr) return; updateScreenshot(application->appId()); DLOG("ApplicationManager::suspend(this=%p, application(%p)->appId(%s) )",this, application, qPrintable(application->appId())); // Present in exceptions list, return. if (!m_lifecycleExceptions.filter(application->appId().section('_',0,0)).empty()) return; if (application->state() == Application::Running) application->setState(Application::Suspended); } void ApplicationManager::resumeApplication(Application *application) { if (application == nullptr) return; if (application->state() != Application::Running) application->setState(Application::Running); } bool ApplicationManager::focusApplication(const QString &appId) { Application *application = findApplication(appId); DLOG("ApplicationManager::focusApplication (this=%p, application=%p, appId=%s)", this, application, qPrintable(appId)); if (!application) { DLOG("No such running application '%s'", qPrintable(appId)); return false; } if (application->stage() == Application::MainStage && m_sideStageApplication) suspendApplication(m_sideStageApplication); if (application->stage() == Application::MainStage) m_msApplicationToBeFocused = application; else m_ssApplicationToBeFocused = application; if (application->state() == Application::Stopped) { // Respawning this app, move to end of application list so onSessionStarting works ok // FIXME: this happens pretty late, shell could request respawn earlier application->setState(Application::Running); int from = m_applications.indexOf(application); move(from, m_applications.length()-1); } else { if (application->session()) { m_focusController->set_focus_to(application->session()); int from = m_applications.indexOf(application); move(from, 0); } } // FIXME(dandrader): lying here. The operation is async. So we will only know whether // the focusing was successful once the server replies. Maybe the API in unity-api should // reflect that? return true; } void ApplicationManager::unfocusCurrentApplication() { DLOG("ApplicationManager::unfocusCurrentApplication (this=%p)", this); suspendApplication(m_sideStageApplication); suspendApplication(m_mainStageApplication); // Clear both stages m_msApplicationToBeFocused = nullptr; m_ssApplicationToBeFocused = nullptr; m_focusController->set_focus_to(nullptr); //FIXME(greyback) } Application* ApplicationManager::startApplication(const QString &appId, const QStringList &arguments) { return startApplication(appId, NoFlag, arguments); } Application *ApplicationManager::startApplication(const QString &appId, ExecFlags flags, const QStringList &arguments) { DLOG("ApplicationManager::startApplication (this=%p, appId=%s)", this, qPrintable(appId)); if (!m_taskController->start(appId, arguments)) { LOG("Asking Upstart to start application '%s' failed", qPrintable(appId)); return nullptr; } { Application * application = findApplication(appId); if (application) { DLOG("ApplicationManager::startApplication - application already " "exists: (this=%p, app=%p, appId=%s)", this, application, qPrintable(appId)); } } Application* application = new Application( m_taskController, m_desktopFileReaderFactory->createInstanceForAppId(appId), Application::Starting, arguments, this); if (!application->isValid()) { DLOG("Unable to instantiate application with appId '%s'", qPrintable(appId)); return nullptr; } // override stage if necessary if (application->stage() == Application::SideStage && flags.testFlag(ApplicationManager::ForceMainStage)) { application->setStage(Application::MainStage); } add(application); return application; } void ApplicationManager::onProcessStartReportReceived(const QString &appId, const bool failure) { DLOG("ApplicationManager::onProcessStartReportReceived (this=%p, appId=%s, failure=%c)", this, qPrintable(appId), (failure) ? 'Y' : 'N'); if (failure) { DLOG("ApplicationManager::onProcessStartReportReceived handling failure:"); stopStartingApplication(appId); return; } Application *application = findApplication(appId); if (!application) { // if shell did not start this application, but upstart did application = new Application( m_taskController, m_desktopFileReaderFactory->createInstanceForAppId(appId), Application::Starting, QStringList(), this); if (!application->isValid()) { DLOG("Unable to instantiate application with appId '%s'", qPrintable(appId)); return; } // override stage if necessary (i.e. side stage invalid on phone) if (application->stage() == Application::SideStage && m_displaySize.width() < (TABLET_MODE_MINIMUM_WIDTH_GU * m_gridUnitPx)) { application->setStage(Application::MainStage); } add(application); Q_EMIT focusRequested(appId); } else { DLOG("ApplicationManager::onProcessStartReportReceived application already found: (app=%p, appId=%s)", application, qPrintable(appId)); } } bool ApplicationManager::stopApplication(const QString &appId) { Application *application = findApplication(appId); DLOG("ApplicationManager::stopApplication (this=%p, application=%p, appId=%s)", this, application, qPrintable(appId)); if (!application) { DLOG("No such running application '%s'", qPrintable(appId)); return false; } checkFocusOnRemovedApplication(application); remove(application); m_dbusWindowStack->WindowDestroyed(0, application->appId()); bool result = m_taskController->stop(application->appId()); LOG_IF(result == false, "FAILED to ask Upstart to stop application '%s'", qPrintable(application->appId())); if (!result && application->pid() > 0) { DLOG("TaskController::stop UAL failed. Sending SIGTERM to %i", application->pid()); kill(application->pid(), SIGTERM); } delete application; // FIXME(dandrader): lying here. The operation is async. So we will only know whether // the focusing was successful once the server replies. Maybe the API in unity-api should // reflect that? return result; } bool ApplicationManager::updateScreenshot(const QString &appId) { Application *application = findApplication(appId); if (!application) { DLOG("No such running application '%s'", qPrintable(appId)); return false; } application->updateScreenshot(); QModelIndex appIndex = findIndex(application); Q_EMIT dataChanged(appIndex, appIndex, QVector() << RoleScreenshot); return true; } void ApplicationManager::stopStartingApplication(const QString &appId) { Application *application = findApplication(appId); if (application && application->state() == Application::Starting) { shutdownApplication(application); } else if (application) { DLOG("ApplicationManager::stopStartingApplication start failure report received - but application=%p, appId=%s is not in Starting state",application, qPrintable(appId)); } } void ApplicationManager::onProcessStopped(const QString &appId, const bool unexpected) { Application *application = findApplication(appId); DLOG("ApplicationManager::onProcessStopped (this=%p, application=%p, appId=%s)", this, application, qPrintable(appId)); // if shell did not stop the application, but upstart says it died, we assume the process has been // killed, so it can be respawned later. Only exception is if that application is focused or running // as then it most likely crashed. Update this logic when upstart gives some failure info. if (application) { shutdownApplication(application); } if (unexpected) { // TODO: pop up a message box/notification? LOG("ApplicationManager: application '%s' died unexpectedly!", qPrintable(appId)); } } void ApplicationManager::shutdownApplication(Application* application) { bool removeApplication = checkFocusOnRemovedApplication(application); if (application->state() == Application::Running || application->state() == Application::Starting) { // Application probably crashed, else OOM killer struck. Either way state wasn't saved // so just remove application removeApplication = true; } else if (application->state() == Application::Suspended) { application->setState(Application::Stopped); application->setSession(nullptr); } if (removeApplication) { remove(application); m_dbusWindowStack->WindowDestroyed(0, application->appId()); delete application; } } void ApplicationManager::onFocusRequested(const QString& appId) { DLOG("ApplicationManager::onFocusRequested (this=%p, appId=%s)", this, qPrintable(appId)); Q_EMIT focusRequested(appId); } void ApplicationManager::onResumeRequested(const QString& appId) { Application *application = findApplication(appId); DLOG("ApplicationManager::onResumeRequested (this=%p, application=%p, appId=%s)", this, application, qPrintable(appId)); if (!application) { DLOG("ApplicationManager::onResumeRequested: No such running application '%s'", qPrintable(appId)); return; } // If app Stopped, trust that upstart-app-launch respawns it itself, and AppManager will // be notified of that through the onProcessStartReportReceived slot. Else resume. if (application->state() == Application::Suspended) { application->setState(Application::Running); } } void ApplicationManager::screenshotUpdated() { if (sender()) { Application *application = static_cast(sender()); QModelIndex appIndex = findIndex(application); Q_EMIT dataChanged(appIndex, appIndex, QVector() << RoleScreenshot); DLOG("ApplicationManager::screenshotUpdated: Received new screenshot for %s", qPrintable(application->appId())); } else { DLOG("ApplicationManager::screenshotUpdated: Received screenshotUpdated signal but application has disappeard."); } // Now that the screenshot is ready, check if there // is a pending app focusing request. if (!m_nextFocusedAppId.isEmpty()) { Q_EMIT focusRequested(m_nextFocusedAppId); m_nextFocusedAppId.clear(); } } /************************************* Mir-side methods *************************************/ void ApplicationManager::authorizeSession(const quint64 pid, bool &authorized) { authorized = false; //to be proven wrong DLOG("ApplicationManager::authorizeSession (this=%p, pid=%lld)", this, pid); for (Application *app : m_applications) { if (app->state() == Application::Starting && m_taskController->appIdHasProcessId(app->appId(), pid)) { app->setPid(pid); DLOG("ApplicationManager::authorizeSession - connecting: application=%p and pid=%lld", app, pid); authorized = true; return; } } /* * Hack: Allow applications to be launched externally, but must be executed with the * "desktop_file_hint" parameter attached. This exists until upstart-app-launch can * notify shell it is starting an application and so shell should allow it. Also reads * the --stage parameter to determine the desired stage */ std::unique_ptr info = m_procInfo->commandLine(pid); if (!info) { DLOG("ApplicationManager REJECTED connection from app with pid %lld as unable to read process command", pid); return; } if (info->startsWith("maliit-server") || info->contains("qt5/libexec/QtWebProcess") || info->startsWith("/usr/bin/signon-ui")) { authorized = true; m_fenceNext = true; return; } boost::optional desktopFileName{ info->getParameter("--desktop_file_hint=") }; if (!desktopFileName) { LOG("ApplicationManager REJECTED connection from app with pid %lld as no desktop_file_hint specified", pid); return; } DLOG("Process supplied desktop_file_hint, loading '%s'", desktopFileName.get().toLatin1().data()); // FIXME: right now we support --desktop_file_hint=appId for historical reasons. So let's try that in // case we didn't get an existing .desktop file path DesktopFileReader* desktopData; if (QFileInfo(desktopFileName.get()).exists()) { desktopData = m_desktopFileReaderFactory->createInstanceForDesktopFile(QFileInfo(desktopFileName.get())); } else { desktopData = m_desktopFileReaderFactory->createInstanceForAppId(desktopFileName.get()); } if (!desktopData->loaded()) { delete desktopData; LOG("ApplicationManager REJECTED connection from app with pid %lld as desktop_file_hint file not found", pid); return; } // some naughty applications use a script to launch the actual application. Check for the // case where shell actually launched the script. Application *application = findApplication(desktopData->appId()); if (application && application->state() == Application::Starting) { DLOG("Process with pid %lld appeared, attached to existing entry '%s' in application lists", pid, application->appId().toLatin1().data()); delete desktopData; application->setSessionName(application->appId()); application->setPid(pid); authorized = true; return; } // if stage supplied in CLI, fetch that Application::Stage stage = Application::MainStage; boost::optional stageParam = info->getParameter("--stage_hint="); if (stageParam && stageParam.get() == "side_stage") { stage = Application::SideStage; } DLOG("Existing process with pid %lld appeared, adding '%s' to application lists", pid, desktopData->name().toLatin1().data()); QStringList arguments(info->asStringList()); application = new Application(m_taskController, desktopData, Application::Starting, arguments, this); application->setPid(pid); application->setStage(stage); add(application); authorized = true; } void ApplicationManager::placeSession(msh::Session const* session, uint32_t &x, uint32_t &y) { Application* application = findApplicationWithSession(session); DLOG("ApplicationManager::placeSession (this=%p, application=%p, session=%p, name=%s)", this, application, session, session?(session->name().c_str()):"null"); // Application defaults x = 0; y = m_panelHeight; // Shell client override if (!session) { y = 0; return; } // Fullscreen applications override if (application && application->fullscreen()) y = 0; // SideStage override if (application && application->stage() == Application::SideStage) x = m_displaySize.width() - (SIDE_STAGE_WIDTH_GU * m_gridUnitPx); DLOG("ApplicationManager::placeSession (x=%d, y=%d)", x, y); } void ApplicationManager::onSessionStarting(const std::shared_ptr& session) { DLOG("ApplicationManager::onSessionStarting (this=%p, application=%s)", this, session?session->name().c_str():"null"); if (m_fenceNext) { m_fenceNext = false; return; } Application* application = findApplicationWithPid(session->process_id()); if (application && application->state() != Application::Running) { application->setSession(session); if (application->stage() == Application::MainStage) m_msApplicationToBeFocused = application; else m_ssApplicationToBeFocused = application; } else { DLOG("ApplicationManager::onSessionStarting - unauthorized application!!"); } } void ApplicationManager::onSessionStopping(const std::shared_ptr& session) { // in case application closed not by hand of shell, check again here: Application* application = findApplicationWithSession(session); DLOG("ApplicationManager::onSessionStopping (this=%p, application=%p, appId=%s, session name=%s)", this, application, application?qPrintable(application->appId()):"null", session?session->name().c_str():"null"); if (application) { bool removeApplication = true; if (application->state() != Application::Starting) { application->setState(Application::Stopped); application->setSession(nullptr); m_dbusWindowStack->WindowDestroyed(0, application->appId()); if (application != m_focusedApplication) { removeApplication = false; } } if (m_mainStageApplication == application) m_mainStageApplication = nullptr; if (m_sideStageApplication == application) m_sideStageApplication = nullptr; if (removeApplication) { // TODO(greyback) What to do?? Focus next app, or unfocus everything?? m_focusedApplication = nullptr; remove(application); delete application; Q_EMIT focusedApplicationIdChanged(); } } } void ApplicationManager::onSessionFocused(const std::shared_ptr& session) { Application* application = findApplicationWithSession(session); DLOG("ApplicationManager::onSessionFocused (this=%p, application=%p, appId=%s, session name=%s)", this, application, application?qPrintable(application->appId()):"null", session?session->name().c_str():"null"); // Don't give application focus until it has created it's surface, when it is set as state "Running" // and only notify shell of focus changes that it actually expects if (application && application->state() != Application::Starting && (application == m_msApplicationToBeFocused || application == m_ssApplicationToBeFocused) && application != m_focusedApplication) { setFocused(application); QModelIndex appIndex = findIndex(application); Q_EMIT dataChanged(appIndex, appIndex, QVector() << RoleFocused); } else { if (application == nullptr) { DLOG("Invalid application focused, discarding the event"); if (nullptr != m_focusedApplication) focusApplication(m_focusedApplication->appId()); } } } void ApplicationManager::onSessionUnfocused() { DLOG("ApplicationManager::onSessionUnfocused (this=%p, application=%p)", this, m_focusedApplication); if (nullptr != m_focusedApplication) { Q_ASSERT(m_focusedApplication->focused()); m_focusedApplication->setFocused(false); suspendApplication(m_focusedApplication); m_focusedApplication = nullptr; Q_EMIT focusedApplicationIdChanged(); m_dbusWindowStack->FocusedWindowChanged(0, QString(), 0); QModelIndex appIndex = findIndex(m_focusedApplication); Q_EMIT dataChanged(appIndex, appIndex, QVector() << RoleFocused << RoleState); } } void ApplicationManager::onSessionCreatedSurface(const msh::Session * session, const std::shared_ptr & surface) { DLOG("ApplicationManager::onSessionCreatedSurface (this=%p)", this); Q_UNUSED(surface); Application* application = findApplicationWithSession(session); if (application && application->state() == Application::Starting) { m_dbusWindowStack->WindowCreated(0, application->appId()); // only when Session creates a Surface will we actually mark it focused setFocused(application); QModelIndex appIndex = findIndex(application); Q_EMIT dataChanged(appIndex, appIndex, QVector() << RoleFocused); } } void ApplicationManager::setFocused(Application *application) { DLOG("ApplicationManager::setFocused (application=%p, appId=%s)", application, qPrintable(application->appId())); if (application == m_focusedApplication) return; // set state of previously focused app to suspended if (m_focusedApplication && m_lifecycleExceptions.filter(m_focusedApplication->appId().section('_',0,0)).empty()) { Application *lastApplication = applicationForStage(application->stage()); suspendApplication(lastApplication); } if (application->stage() == Application::MainStage) m_mainStageApplication = application; else m_sideStageApplication = application; m_focusedApplication = application; m_focusedApplication->setFocused(true); m_focusedApplication->setState(Application::Running); move(m_applications.indexOf(application), 0); Q_EMIT focusedApplicationIdChanged(); m_dbusWindowStack->FocusedWindowChanged(0, application->appId(), application->stage()); } Application* ApplicationManager::findApplicationWithSession(const std::shared_ptr &session) { return findApplicationWithSession(session.get()); } Application* ApplicationManager::findApplicationWithSession(const msh::Session *session) { for (Application *app : m_applications) { if (app->session().get() == session) { return app; } } return nullptr; } Application* ApplicationManager::findApplicationWithPid(const qint64 pid) { if (pid <= 0) return nullptr; for (Application *app : m_applications) { if (app->m_pid == pid) { return app; } } return nullptr; } Application* ApplicationManager::applicationForStage(Application::Stage stage) { DLOG("ApplicationManager::focusedApplicationForStage(this=%p)", this); if (stage == Application::MainStage) return m_mainStageApplication; else return m_sideStageApplication; } void ApplicationManager::add(Application* application) { DASSERT(application != nullptr); DLOG("ApplicationManager::add (this=%p, application='%s')", this, qPrintable(application->name())); connect(application, &Application::screenshotChanged, this, &ApplicationManager::screenshotUpdated); beginInsertRows(QModelIndex(), m_applications.size(), m_applications.size()); m_applications.append(application); endInsertRows(); Q_EMIT countChanged(); Q_EMIT applicationAdded(application->appId()); } void ApplicationManager::remove(Application *application) { DASSERT(application != nullptr); DLOG("ApplicationManager::remove (this=%p, application='%s')", this, qPrintable(application->name())); if (application == m_sideStageApplication) m_sideStageApplication = nullptr; if (application == m_mainStageApplication) m_mainStageApplication = nullptr; int i = m_applications.indexOf(application); if (i != -1) { beginRemoveRows(QModelIndex(), i, i); m_applications.removeAt(i); endRemoveRows(); Q_EMIT applicationRemoved(application->appId()); Q_EMIT countChanged(); } } void ApplicationManager::move(int from, int to) { DLOG("ApplicationManager::move (this=%p, from=%d, to=%d)", this, from, to); if (from == to) return; if (from >= 0 && from < m_applications.size() && to >= 0 && to < m_applications.size()) { QModelIndex parent; /* When moving an item down, the destination index needs to be incremented by one, as explained in the documentation: http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */ beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0)); m_applications.move(from, to); endMoveRows(); } } QModelIndex ApplicationManager::findIndex(Application* application) { for (int i = 0; i < m_applications.size(); ++i) { if (m_applications.at(i) == application) { return index(i); } } return QModelIndex(); } bool ApplicationManager::checkFocusOnRemovedApplication(Application * application) { if (application == m_focusedApplication) { // TODO(greyback) What to do?? Focus next app, or unfocus everything?? m_focusedApplication = nullptr; Q_EMIT focusedApplicationIdChanged(); return true; } return false; } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/inputarea.h0000644000015301777760000000413512323676377025707 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef INPUTAREA_H #define INPUTAREA_H // Qt #include #include #include // mir #include namespace mir { namespace shell { class Surface; }} namespace unitymir { class MirSurface; class InputArea : public QQuickItem { Q_OBJECT Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(unitymir::MirSurface* surface READ surface WRITE setSurface NOTIFY surfaceChanged) public: explicit InputArea(QQuickItem *parent = 0); ~InputArea(); bool enabled() const; MirSurface *surface() const; void setEnabled(bool enabled); virtual void setSurface(MirSurface *surface); Q_SIGNALS: void enabledChanged(); void surfaceChanged(); protected: virtual void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry); void doSetSurface(MirSurface *surface); private Q_SLOTS: void onAscendantChanged(); void onAscendantGeometryChanged(); void setNullSurface(); private: void listenToAscendantsChanges(); void disconnectFromAscendantsChanges(); void setMirInputArea(const QRectF& relativeGeometry); bool m_enabled; QRectF m_geometry; MirSurface* m_surface; mir::geometry::Rectangle m_mirInputArea; QLinkedList m_connections; friend class MirSurface; }; } // namespace unitymir #endif // INPUTAREA_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/taskcontroller.cpp0000644000015301777760000001323112323676377027315 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Ricardo Mendoza */ // local #include "taskcontroller.h" // unity-mir #include // Qt #include // Process C++ #include #include #include #include // STL #include // glib #include // std #include #include namespace unitymir { TaskController::TaskController( QObject* parent, const QSharedPointer& appController, const QSharedPointer& processController) : QObject(parent), m_appController(appController), m_processController(processController) { connect(m_appController.data(), &ApplicationController::applicationAboutToBeStarted, this, &TaskController::onApplicationAboutToBeStarted); connect(m_appController.data(), &ApplicationController::applicationStarted, this, &TaskController::onApplicationStarted); connect(m_appController.data(), &ApplicationController::applicationStopped, this, &TaskController::onApplicationStopped); connect(m_appController.data(), &ApplicationController::applicationFocusRequest, this, &TaskController::onApplicationFocusRequest); connect(m_appController.data(), &ApplicationController::applicationResumeRequest, this, &TaskController::onApplicationResumeRequest); connect(m_appController.data(), &ApplicationController::applicationError, this, &TaskController::onApplicationError); } TaskController::~TaskController() { } bool TaskController::start(const QString& appId, const QStringList& arguments) { DLOG("TaskController::start appId='%s'", qPrintable(appId)); return m_appController->startApplicationWithAppIdAndArgs(appId, arguments); } bool TaskController::stop(const QString& appId) { DLOG("TaskController::stop appId='%s'", qPrintable(appId)); auto result = m_appController->stopApplicationWithAppId(appId); DLOG_IF(!result, "TaskController::stopApplication appId='%s' FAILED", qPrintable(appId)); return result; } bool TaskController::appIdHasProcessId(const QString& appId, const quint64 pid) { DLOG("TaskController::isApplicationPid appId='%s', pid=%lld", qPrintable(appId), pid); return m_appController->appIdHasProcessId(pid, appId); } bool TaskController::suspend(const QString& appId) { DLOG("TaskController::suspend (this=%p, application=%p)", this, qPrintable(appId)); pid_t pid = m_appController->primaryPidForAppId(appId); m_processController->oomController()->ensureProcessLikelyToBeKilled(pid); if (pid) { // We do assume that the app was launched by upstart and with that, // in its own process group. For that, we interpret the pid as pgid and // sigstop the complete process group on suspend. return m_processController->sigStopProcessGroupForPid(pid); } else { return false; } } bool TaskController::resume(const QString& appId) { DLOG("TaskController::resume (this=%p, application=%p)", this, qPrintable(appId)); pid_t pid = m_appController->primaryPidForAppId(appId); m_processController->oomController()->ensureProcessUnlikelyToBeKilled(pid); if (pid) { // We do assume that the app was launched by upstart and with that, // in its own process group. For that, we interpret the pid as pgid and // sigcont the complete process group on resume. return m_processController->sigContinueProcessGroupForPid(pid); return true; } else { return false; } } void TaskController::onApplicationAboutToBeStarted(const QString& id) { Q_EMIT processStartReport(id, false); } void TaskController::onApplicationStarted(const QString& id) { pid_t pid = m_appController->primaryPidForAppId(id); m_processController->oomController()->ensureProcessUnlikelyToBeKilled(pid); } void TaskController::onApplicationStopped(const QString& id) { Q_EMIT processStopped(id, false); } void TaskController::onApplicationFocusRequest(const QString& id) { pid_t pid = m_appController->primaryPidForAppId(id); m_processController->oomController()->ensureProcessUnlikelyToBeKilled(pid); Q_EMIT requestFocus(id); } void TaskController::onApplicationResumeRequest(const QString& id) { Q_EMIT requestResume(id); } void TaskController::onApplicationError(const QString& id, ApplicationController::Error error) { switch(error) { case ApplicationController::Error::APPLICATION_CRASHED: Q_EMIT processStopped(id, true); break; case ApplicationController::Error::APPLICATION_FAILED_TO_START: Q_EMIT processStartReport(id, true); break; } // Is this really the signal we want to emit? Q_EMIT requestResume(id); } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/application.h0000644000015301777760000000666112323676377026230 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef APPLICATION_H #define APPLICATION_H // std #include //Qt #include #include #include // Unity API #include class QImage; namespace mir { namespace shell { class Session; }} namespace unitymir { class DesktopFileReader; class TaskController; class Application : public unity::shell::application::ApplicationInfoInterface { Q_OBJECT Q_PROPERTY(QString desktopFile READ desktopFile CONSTANT) Q_PROPERTY(QString exec READ exec CONSTANT) Q_PROPERTY(bool fullscreen READ fullscreen NOTIFY fullscreenChanged) Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged) Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged) public: Application(const QSharedPointer& taskController, DesktopFileReader *desktopFileReader, State state, const QStringList &arguments, QObject *parent = 0); virtual ~Application(); // ApplicationInfoInterface QString appId() const override; QString name() const override; QString comment() const override; QUrl icon() const override; Stage stage() const override; State state() const override; bool focused() const override; QUrl screenshot() const override; bool visible() const; void setStage(Stage stage); void setVisible(const bool); QImage screenshotImage() const; void updateScreenshot(); bool isValid() const; QString desktopFile() const; QString exec() const; bool fullscreen() const; std::shared_ptr session() const; pid_t pid() const; public Q_SLOTS: void suspend(); void resume(); void respawn(); Q_SIGNALS: void fullscreenChanged(); void stageChanged(Stage stage); void visibleChanged(); private: void setPid(pid_t pid); void setState(State state); void setFocused(bool focus); void setFullscreen(bool fullscreen); void setSession(const std::shared_ptr& session); void setSessionName(const QString& name); QSharedPointer m_taskController; DesktopFileReader* m_desktopData; qint64 m_pid; Stage m_stage; State m_state; bool m_focused; QUrl m_screenshot; QImage m_screenshotImage; bool m_fullscreen; bool m_visible; // duplicating internal Mir data :( std::shared_ptr m_session; QString m_sessionName; QStringList m_arguments; QTimer* m_suspendTimer; friend class ApplicationManager; friend class ApplicationListModel; friend class MirSurfaceManager; }; } // namespace unity-mir Q_DECLARE_METATYPE(unitymir::Application*) #endif // APPLICATION_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/taskcontroller.h0000644000015301777760000000442312323676377026765 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Ricardo Mendoza */ #ifndef TASKCONTROLLER_H #define TASKCONTROLLER_H #include #include "application.h" #include "applicationcontroller.h" #include "processcontroller.h" namespace unitymir { class TaskController : public QObject { Q_OBJECT public: TaskController( QObject* parent, const QSharedPointer& app_controller, const QSharedPointer& processController = QSharedPointer(new ProcessController())); ~TaskController(); bool start(const QString& appId, const QStringList& args); bool stop(const QString& appId); bool suspend(const QString& appId); bool resume(const QString& appId); bool appIdHasProcessId(const QString& appId, const quint64 pid); Q_SIGNALS: void processStartReport(const QString& appId, const bool failure); void processStopped(const QString& appId, const bool unexpectedly); void requestFocus(const QString& appId); void requestResume(const QString& appId); private Q_SLOTS: void onApplicationAboutToBeStarted(const QString& id); void onApplicationStarted(const QString& id); void onApplicationStopped(const QString& id); void onApplicationFocusRequest(const QString& id); void onApplicationResumeRequest(const QString& id); void onApplicationError(const QString& id, ApplicationController::Error error); private: QSharedPointer m_appController; QSharedPointer m_processController; }; } // namespace unitymir #endif // TASKCONTROLLER_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/mirsurfacemanager.h0000644000015301777760000000427312323676377027415 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef MIR_SURFACE_MANAGER_H #define MIR_SURFACE_MANAGER_H // std #include // Qt #include // Mir #include // local #include "mirsurface.h" namespace mir { namespace scene { class Surface; }} namespace mir { namespace shell { class Surface; class Session; }} class ShellServerConfiguration; namespace unitymir { class MirSurfaceManager : public QObject { Q_OBJECT public: static MirSurfaceManager* singleton(); MirSurfaceManager(QObject *parent = 0); ~MirSurfaceManager(); MirSurface *shellSurface() const; MirSurface *surfaceFor(std::shared_ptr const& surface); Q_SIGNALS: void surfaceCreated(MirSurface* surface); void surfaceDestroyed(MirSurface* surface); void shellSurfaceChanged(MirSurface* surface); // void surfaceResized(MirSurface*); // void fullscreenSurfaceChanged(); public Q_SLOTS: void sessionCreatedSurface(mir::shell::Session const* session, std::shared_ptr const&); void sessionDestroyingSurface(mir::shell::Session const*, std::shared_ptr const&); void shellSurfaceCreated(std::shared_ptr const&); void surfaceAttributeChanged(mir::scene::Surface const*, MirSurfaceAttrib, int); private: QHash m_surfaces; MirSurface* m_shellSurface; ShellServerConfiguration* m_mirServer; static MirSurfaceManager *the_surface_manager; }; } // namespace unitymir #endif // MIR_SURFACE_MANAGER_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/upstart/0000755000015301777760000000000012323677263025240 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/upstart/applicationcontroller.cpp0000644000015301777760000001266312323676410032354 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #include "applicationcontroller.h" // unity-mir #include // upstart extern "C" { #include "upstart-app-launch.h" } namespace unitymir { namespace upstart { struct ApplicationController::Private { upstart_app_launch_app_observer_t preStartCallback = nullptr; upstart_app_launch_app_observer_t startedCallback = nullptr; upstart_app_launch_app_observer_t stopCallback = nullptr; upstart_app_launch_app_observer_t focusCallback = nullptr; upstart_app_launch_app_observer_t resumeCallback = nullptr; upstart_app_launch_app_failed_observer_t failureCallback = nullptr; }; ApplicationController::ApplicationController() : unitymir::ApplicationController(), impl(new Private()) { impl->preStartCallback = [](const gchar * appId, gpointer userData) { auto thiz = static_cast(userData); Q_EMIT(thiz->applicationAboutToBeStarted(appId)); }; impl->startedCallback = [](const gchar * appId, gpointer userData) { auto thiz = static_cast(userData); Q_EMIT(thiz->applicationStarted(appId)); }; impl->stopCallback = [](const gchar * appId, gpointer userData) { auto thiz = static_cast(userData); Q_EMIT(thiz->applicationStopped(appId)); }; impl->focusCallback = [](const gchar * appId, gpointer userData) { auto thiz = static_cast(userData); Q_EMIT(thiz->applicationFocusRequest(appId)); }; impl->resumeCallback = [](const gchar * appId, gpointer userData) { auto thiz = static_cast(userData); Q_EMIT(thiz->applicationResumeRequest(appId)); }; impl->failureCallback = [](const gchar * appId, upstart_app_launch_app_failed_t failureType, gpointer userData) { ApplicationController::Error error; switch(failureType) { case UPSTART_APP_LAUNCH_APP_FAILED_CRASH: error = ApplicationController::Error::APPLICATION_CRASHED; case UPSTART_APP_LAUNCH_APP_FAILED_START_FAILURE: error = ApplicationController::Error::APPLICATION_FAILED_TO_START; } auto thiz = static_cast(userData); Q_EMIT(thiz->applicationError(appId, error)); }; upstart_app_launch_observer_add_app_starting(impl->preStartCallback, this); upstart_app_launch_observer_add_app_started(impl->startedCallback, this); upstart_app_launch_observer_add_app_stop(impl->stopCallback, this); upstart_app_launch_observer_add_app_focus(impl->focusCallback, this); upstart_app_launch_observer_add_app_resume(impl->resumeCallback, this); upstart_app_launch_observer_add_app_failed(impl->failureCallback, this); } ApplicationController::~ApplicationController() { upstart_app_launch_observer_delete_app_starting(impl->preStartCallback, this); upstart_app_launch_observer_delete_app_started(impl->startedCallback, this); upstart_app_launch_observer_delete_app_stop(impl->stopCallback, this); upstart_app_launch_observer_delete_app_focus(impl->focusCallback, this); upstart_app_launch_observer_delete_app_resume(impl->resumeCallback, this); upstart_app_launch_observer_delete_app_failed(impl->failureCallback, this); } pid_t ApplicationController::primaryPidForAppId(const QString& appId) { GPid pid = upstart_app_launch_get_primary_pid(appId.toLatin1().constData()); DLOG_IF(!pid, "ApplicationController::stopApplication appId='%s' FAILED", qPrintable(appId)); return pid; } bool ApplicationController::appIdHasProcessId(pid_t pid, const QString& appId) { return upstart_app_launch_pid_in_app_id(pid, appId.toLatin1().constData()); } bool ApplicationController::stopApplicationWithAppId(const QString& appId) { auto result = upstart_app_launch_stop_application(appId.toLatin1().constData()); DLOG_IF(!result, "ApplicationController::stopApplicationWithAppId appId='%s' FAILED", qPrintable(appId)); return result; } bool ApplicationController::startApplicationWithAppIdAndArgs(const QString& appId, const QStringList& arguments) { // Convert arguments QStringList into format suitable for upstart-app-launch // The last item should be null, which is done by g_new0, we just don't fill it. auto upstartArgs = g_new0(gchar *, arguments.length() + 1); for (int i=0; i(upstartArgs)); g_strfreev(upstartArgs); DLOG_IF(!result, "Application::Controller::startApplicationWithAppIdAndArgs appId='%s' FAILED", qPrintable(appId)); return result; } } // namespace upstart } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/upstart/applicationcontroller.h0000644000015301777760000000260012323676377032023 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef UPSTART_APPLICATION_CONTROLLER_H #define UPSTART_APPLICATION_CONTROLLER_H #include "../applicationcontroller.h" namespace unitymir { namespace upstart { class ApplicationController : public unitymir::ApplicationController { public: ApplicationController(); ~ApplicationController(); pid_t primaryPidForAppId(const QString& appId); bool appIdHasProcessId(pid_t pid, const QString& appId); bool stopApplicationWithAppId(const QString& appId); bool startApplicationWithAppIdAndArgs(const QString& appId, const QStringList& arguments); private: struct Private; QScopedPointer impl; }; } // namespace upstart } // namespace unitymir #endif // UPSTART_APPLICATION_CONTROLLER_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/application.cpp0000644000015301777760000001731112323676377026555 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // local #include "application.h" #include "application_manager.h" #include "desktopfilereader.h" #include "taskcontroller.h" // unity-mir #include "logging.h" // mir #include #include namespace unitymir { Application::Application(const QSharedPointer& taskController, DesktopFileReader *desktopFileReader, State state, const QStringList &arguments, QObject *parent) : ApplicationInfoInterface(desktopFileReader->appId(), parent) , m_taskController(taskController) , m_desktopData(desktopFileReader) , m_pid(0) , m_stage((m_desktopData->stageHint() == "SideStage") ? Application::SideStage : Application::MainStage) , m_state(state) , m_focused(false) , m_fullscreen(false) , m_visible(false) , m_arguments(arguments) , m_suspendTimer(new QTimer(this)) { DLOG("Application::Application (this=%p, appId=%s, state=%d", this, qPrintable(desktopFileReader->appId()), static_cast(state)); m_suspendTimer->setSingleShot(true); connect(m_suspendTimer, SIGNAL(timeout()), this, SLOT(suspend())); } Application::~Application() { DLOG("Application::~Application (this=%p)", this); delete m_desktopData; } bool Application::isValid() const { return m_desktopData->loaded(); } QString Application::desktopFile() const { return m_desktopData->file(); } QString Application::appId() const { return m_desktopData->appId(); } QString Application::name() const { return m_desktopData->name(); } QString Application::comment() const { return m_desktopData->comment(); } QUrl Application::icon() const { QString iconString = m_desktopData->icon(); QString pathString = m_desktopData->path(); if (QFileInfo(iconString).exists()) { return QUrl(iconString); } else if (QFileInfo(pathString + '/' + iconString).exists()) { return QUrl(pathString + '/' + iconString); } else { return QUrl("image://theme/" + iconString); } } QString Application::exec() const { return m_desktopData->exec(); } Application::Stage Application::stage() const { return m_stage; } Application::State Application::state() const { return m_state; } bool Application::focused() const { return m_focused; } QUrl Application::screenshot() const { return m_screenshot; } bool Application::fullscreen() const { return m_fullscreen; } std::shared_ptr Application::session() const { return m_session; } bool Application::visible() const { return m_visible; } pid_t Application::pid() const { return m_pid; } void Application::setPid(pid_t pid) { m_pid = pid; } void Application::setSession(const std::shared_ptr& session) { DLOG("Application::setSession (this=%p, session=%p)", this, session.get()); // TODO(greyback) what if called with new surface? m_session = session; m_visible = true; // bit of an assumption that, but no other way to deduce an actual Surface has been created } void Application::setSessionName(const QString& name) { DLOG("Application::setSessionName (this=%p, name=%s)", this, name.toLatin1().constData()); if (m_session) { LOG("Application::setSessionName should not be called once session exists"); return; } m_sessionName = name; } void Application::setStage(Application::Stage stage) { DLOG("Application::setStage (this=%p, stage=%d)", this, static_cast(stage)); if (m_stage != stage) { m_stage = stage; Q_EMIT stageChanged(stage); } } QImage Application::screenshotImage() const { return m_screenshotImage; } void Application::updateScreenshot() { session()->take_snapshot( [&](mir::shell::Snapshot const& snapshot) { DLOG("ApplicationScreenshotProvider - Mir snapshot ready with size %d x %d", snapshot.size.height.as_int(), snapshot.size.width.as_int()); m_screenshotImage = QImage( (const uchar*)snapshot.pixels, // since we mirror, no need to offset starting position snapshot.size.width.as_int(), snapshot.size.height.as_int(), QImage::Format_ARGB32_Premultiplied).mirrored(); m_screenshot = QString("image://application/%1/%2").arg(m_desktopData->appId()).arg(QDateTime::currentMSecsSinceEpoch()); Q_EMIT screenshotChanged(m_screenshot); }); } void Application::setState(Application::State state) { DLOG("Application::setState (this=%p, state=%d)", this, static_cast(state)); if (m_state != state) { switch (state) { case Application::Suspended: if (m_state == Application::Running) { session()->set_lifecycle_state(mir_lifecycle_state_will_suspend); session()->hide(); m_suspendTimer->start(3000); } break; case Application::Running: if (m_suspendTimer->isActive()) m_suspendTimer->stop(); if (m_state == Application::Suspended) { resume(); session()->set_lifecycle_state(mir_lifecycle_state_resumed); session()->show(); } else if (m_state == Application::Stopped) { respawn(); state = Application::Starting; } break; case Application::Stopped: if (m_suspendTimer->isActive()) m_suspendTimer->stop(); break; default: break; } m_state = state; Q_EMIT stateChanged(state); } } void Application::setFocused(bool focused) { DLOG("Application::setFocused (this=%p, focus=%s)", this, focused ? "yes" : "no"); if (m_focused != focused) { m_focused = focused; Q_EMIT focusedChanged(focused); } } void Application::setFullscreen(bool fullscreen) { DLOG("Application::setFullscreen (this=%p, fullscreen=%s)", this, fullscreen ? "yes" : "no"); if (m_fullscreen != fullscreen) { m_fullscreen = fullscreen; Q_EMIT fullscreenChanged(); } } void Application::setVisible(const bool visible) { DLOG("Application::setVisible (this=%p, visible=%s)", this, visible ? "yes" : "no"); // FIXME: this is bad, as should a MirSurface of this app exist, it won't be notified of the visiblity change. if (visible != m_visible) { if (visible) { m_session->show(); } else { m_session->hide(); } m_visible = visible; Q_EMIT visibleChanged(); } } void Application::suspend() { DLOG("Application::suspend (this=%p)", this); m_taskController->suspend(appId()); } void Application::resume() { DLOG("Application::resume (this=%p)", this); m_taskController->resume(appId()); } void Application::respawn() { DLOG("Application::respawn (this=%p)", this); m_taskController->start(appId(), m_arguments); } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/applicationscreenshotprovider.h0000644000015301777760000000226612323676377032076 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef APPLICATIONSCREENSHOTPROVIDER_H #define APPLICATIONSCREENSHOTPROVIDER_H #include namespace unitymir { class ApplicationManager; class ApplicationScreenshotProvider : public QQuickImageProvider { public: explicit ApplicationScreenshotProvider(ApplicationManager *appManager); QImage requestImage(const QString &appId, QSize *size, const QSize &requestedSize) override; private: ApplicationManager* m_appManager; }; } // namespace unitymir #endif // APPLICATIONSCREENSHOTPROVIDER_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/proc_info.h0000644000015301777760000000245012323676377025673 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // Process Information #ifndef PROC_INFO_H #define PROC_INFO_H #include #include #include #include class QString; namespace unitymir { class ProcInfo { public: class CommandLine { public: QByteArray m_command; bool startsWith(const char* prefix) const; bool contains(const char* prefix) const; boost::optional getParameter(const char* name) const; QStringList asStringList() const; }; virtual std::unique_ptr commandLine(quint64 pid); virtual ~ProcInfo(); }; } // namespace unitymir #endif unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/processcontroller.h0000644000015301777760000000326412323676377027503 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef PROCESS_CONTROLLER_H #define PROCESS_CONTROLLER_H #include #include namespace unitymir { class ProcessController { public: class OomController { public: OomController(); OomController(const OomController&) = delete; virtual ~OomController() = default; OomController& operator=(const OomController&) = delete; virtual void ensureProcessLikelyToBeKilled(pid_t); virtual void ensureProcessUnlikelyToBeKilled(pid_t); }; ProcessController(); ProcessController(const ProcessController&) = delete; virtual ~ProcessController(); ProcessController& operator=(const ProcessController&) = delete; virtual const QSharedPointer& oomController() const; virtual bool sigStopProcessGroupForPid(pid_t pid) const; virtual bool sigContinueProcessGroupForPid(pid_t pid) const; protected: QSharedPointer m_oomController; }; } // namespace unitymir #endif // PROCESS_CONTROLLER_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/desktopfilereader.cpp0000644000015301777760000001540612323676377027751 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // local #include "desktopfilereader.h" // unity-mir #include "logging.h" // Qt #include #include #include namespace unitymir { DesktopFileReader::Factory::Factory() { } DesktopFileReader::Factory::~Factory() { } DesktopFileReader* DesktopFileReader::Factory::createInstanceForAppId(const QString& appId) { return new DesktopFileReader(appId); } DesktopFileReader* DesktopFileReader::Factory::createInstanceForDesktopFile(const QFileInfo& fi) { return new DesktopFileReader(fi); } // Retrieves the size of an array at compile time. #define ARRAY_SIZE(a) \ ((sizeof(a) / sizeof(*(a))) / static_cast(!(sizeof(a) % sizeof(*(a))))) DesktopFileReader::DesktopFileReader(const QString &appId) : appId_(appId) , entries_(DesktopFileReader::kNumberOfEntries, "") { DLOG("DesktopFileReader::DesktopFileReader (this=%p, appId='%s')", this, appId.toLatin1().data()); DASSERT(appId != NULL); file_ = findDesktopFile(appId); loaded_ = loadDesktopFile(file_); } DesktopFileReader::DesktopFileReader(const QFileInfo &desktopFile) : entries_(DesktopFileReader::kNumberOfEntries, "") { DLOG("DesktopFileReader::DesktopFileReader (this=%p, desktopFile='%s')", this, desktopFile.absoluteFilePath().toLatin1().data()); DASSERT(desktopFile.exists()); appId_ = desktopFile.completeBaseName(); file_ = desktopFile.absoluteFilePath(); loaded_ = loadDesktopFile(file_); } DesktopFileReader::~DesktopFileReader() { DLOG("DesktopFileReader::~DesktopFileReader"); entries_.clear(); } QString DesktopFileReader::findDesktopFile(const QString &appId) const { DLOG("DesktopFileReader::findDesktopFile (appId='%s')", appId.toLatin1().data()); int dashPos = -1; QString helper = appId; QString desktopFile; do { if (dashPos != -1) { helper = helper.replace(dashPos, 1, '/'); } desktopFile = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, QString("%1.desktop").arg(helper)); if (!desktopFile.isEmpty()) return desktopFile; dashPos = helper.indexOf("-"); } while (dashPos != -1); return QString(); } bool DesktopFileReader::loadDesktopFile(QString desktopFile) { DLOG("DesktopFileReader::loadDesktopFile (this=%p, desktopFile='%s')", this, desktopFile.toLatin1().data()); if (this->file().isNull() || this->file().isEmpty()) { DLOG("No desktop file found for appId: %s", qPrintable(appId_)); return false; } DASSERT(desktopFile != NULL); const struct { const char* const name; int size; unsigned int flag; } kEntryNames[] = { { "Name=", sizeof("Name=") - 1, 1 << DesktopFileReader::kNameIndex }, { "Comment=", sizeof("Comment=") - 1, 1 << DesktopFileReader::kCommentIndex }, { "Icon=", sizeof("Icon=") - 1, 1 << DesktopFileReader::kIconIndex }, { "Exec=", sizeof("Exec=") - 1, 1 << DesktopFileReader::kExecIndex }, { "Path=", sizeof("Path=") - 1, 1 << DesktopFileReader::kPathIndex }, { "X-Ubuntu-StageHint=", sizeof("X-Ubuntu-StageHint=") - 1, 1 << DesktopFileReader::kStageHintIndex } }; const unsigned int kAllEntriesMask = (1 << DesktopFileReader::kNameIndex) | (1 << DesktopFileReader::kCommentIndex) | (1 << DesktopFileReader::kIconIndex) | (1 << DesktopFileReader::kExecIndex) | (1 << DesktopFileReader::kPathIndex) | (1 << DesktopFileReader::kStageHintIndex); const unsigned int kMandatoryEntriesMask = (1 << DesktopFileReader::kNameIndex) | (1 << DesktopFileReader::kIconIndex) | (1 << DesktopFileReader::kExecIndex); const int kEntriesCount = ARRAY_SIZE(kEntryNames); const int kBufferSize = 256; static char buffer[kBufferSize]; QFile file(desktopFile); // Open file. if (!file.open(QFile::ReadOnly | QIODevice::Text)) { DLOG("can't open file: %s", file.errorString().toLatin1().data()); return false; } // Validate "magic key" (standard group header). if (file.readLine(buffer, kBufferSize) != -1) { if (strncmp(buffer, "[Desktop Entry]", sizeof("[Desktop Entry]") - 1)) { DLOG("not a desktop file"); return false; } } int length; unsigned int entryFlags = 0; while ((length = file.readLine(buffer, kBufferSize)) != -1) { // Skip empty lines. if (length > 1) { // Stop when reaching unsupported next group header. if (buffer[0] == '[') { DLOG("reached next group header, leaving loop"); break; } // Lookup entries ignoring duplicates if any. for (int i = 0; i < kEntriesCount; i++) { if (!strncmp(buffer, kEntryNames[i].name, kEntryNames[i].size)) { if (~entryFlags & kEntryNames[i].flag) { buffer[length-1] = '\0'; entries_[i] = QString::fromLatin1(&buffer[kEntryNames[i].size]); entryFlags |= kEntryNames[i].flag; break; } } } // Stop when matching the right number of entries. if (entryFlags == kAllEntriesMask) { break; } } } // Check that the mandatory entries are set. if ((entryFlags & kMandatoryEntriesMask) == kMandatoryEntriesMask) { DLOG("loaded desktop file with name='%s', comment='%s', icon='%s', exec='%s', path='%s', stagehint='%s'", entries_[DesktopFileReader::kNameIndex].toLatin1().data(), entries_[DesktopFileReader::kCommentIndex].toLatin1().data(), entries_[DesktopFileReader::kIconIndex].toLatin1().data(), entries_[DesktopFileReader::kExecIndex].toLatin1().data(), entries_[DesktopFileReader::kPathIndex].toLatin1().data(), entries_[DesktopFileReader::kStageHintIndex].toLatin1().data()); return true; } else { DLOG("not a valid desktop file, missing mandatory entries in the standard group header"); return false; } } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/mirsurface.cpp0000644000015301777760000001273112323676377026413 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // local #include "mirsurface.h" #include "inputarea.h" // unity-mir #include "logging.h" // Mir #include #include namespace mg = mir::geometry; namespace unitymir { MirSurface::MirSurface(std::shared_ptr surface, Application* application, QQuickItem *parent) : QQuickItem(parent) , m_surface(surface) , m_application(application) { DLOG("MirSurface::MirSurface"); setFlag(QQuickItem::ItemHasContents, false); //so scene graph will not render this item } MirSurface::~MirSurface() { m_inputAreas.clear(); } Application* MirSurface::application() const { return m_application; } qreal MirSurface::x() const { int xAbsolute = m_surface->top_left().x.as_int(); return mapFromScene((QPointF(xAbsolute, 0))).x(); } qreal MirSurface::y() const { int yAbsolute = m_surface->top_left().y.as_int(); return mapFromScene((QPointF(0, yAbsolute))).y(); } void MirSurface::setX(qreal xValue) { using namespace mir::geometry; qreal xAbsolute = mapToScene(QPointF(xValue, 0)).x(); Point position = m_surface->top_left(); if (position.x.as_int() != (int) xAbsolute) { position.x = X{xAbsolute}; m_surface->move_to(position); Q_EMIT xChanged(); } } void MirSurface::setY(qreal yValue) { using namespace mir::geometry; qreal yAbsolute = mapToScene(QPointF(0, yValue)).y(); Point position = m_surface->top_left(); if (position.y.as_int() != (int) yAbsolute) { position.y = Y{yAbsolute}; m_surface->move_to(position); Q_EMIT yChanged(); } } qreal MirSurface::width() const { return m_surface->size().width.as_int(); } qreal MirSurface::height() const { return m_surface->size().height.as_int(); } void MirSurface::setWidth(qreal widthValue) { using namespace mir::geometry; Size size = m_surface->size(); if (size.width.as_int() != (int) widthValue) { size.width = Width{widthValue}; m_surface->resize(size); Q_EMIT widthChanged(); } } void MirSurface::setHeight(qreal heightValue) { using namespace mir::geometry; Size size = m_surface->size(); if (size.height.as_int() != (int) heightValue) { size.height = Height{heightValue}; m_surface->resize(size); Q_EMIT heightChanged(); } } bool MirSurface::isVisible() const { return m_visible; } void MirSurface::setVisible(const bool visible) { if (visible == m_visible) return; if (visible) { m_surface->show(); } else { m_surface->hide(); } m_visible = visible; Q_EMIT visibleChanged(); } MirSurface::Type MirSurface::type() const { return static_cast(m_surface->type()); } MirSurface::State MirSurface::state() const { return static_cast(m_surface->state()); } QString MirSurface::name() const { //FIXME - how to listen to change in this property return QString::fromStdString(m_surface->name()); } void MirSurface::installInputArea(const InputArea* area) { if (!m_surface->supports_input()) { LOG("MirSurface::installInputArea - surface does not support input"); } m_inputAreas.insert(area); updateMirInputRegion(); } bool MirSurface::removeInputArea(const InputArea* area) { const bool res = m_inputAreas.remove(area); updateMirInputRegion(); return res; } bool MirSurface::enableInputArea(const InputArea* area, bool enable) { bool res; if (enable) { m_inputAreas.insert(area); res = true; } else { res = m_inputAreas.remove(area); } updateMirInputRegion(); return res; } void MirSurface::updateMirInputRegion() { /* WARNING: by default, a surface has an input region covering the whole surface. Once the surface input region is set, the default will *not* be restored when all input regions are removed/disabled */ std::vector mirInputAreas; for (auto const& area : m_inputAreas) { mirInputAreas.push_back(area->m_mirInputArea); } m_surface->set_input_region(mirInputAreas); } void MirSurface::setType(const Type &type) { if (this->type() != type) { m_surface->configure(mir_surface_attrib_type, static_cast(type)); } } void MirSurface::setState(const State &state) { if (this->state() != state) { m_surface->configure(mir_surface_attrib_state, static_cast(state)); } } // Called by MirSurfaceManager upon a msh::Surface attribute change void MirSurface::setAttribute(const MirSurfaceAttrib attribute, const int /*value*/) { switch (attribute) { case mir_surface_attrib_type: Q_EMIT typeChanged(); break; case mir_surface_attrib_state: Q_EMIT stateChanged(); break; default: break; } } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/applicationscreenshotprovider.cpp0000644000015301777760000000454412323676377032432 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // local #include "applicationscreenshotprovider.h" #include "application_manager.h" #include "application.h" // unity-mir #include "logging.h" // mir #include "mirserver/mir/shell/session.h" namespace unitymir { ApplicationScreenshotProvider::ApplicationScreenshotProvider(ApplicationManager *appManager) : QQuickImageProvider(QQuickImageProvider::Image) , m_appManager(appManager) { } QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize * size, const QSize &requestedSize) { // We ignore requestedSize here intentionally to avoid keeping scaled copies around Q_UNUSED(requestedSize) DLOG("ApplicationScreenshotProvider::requestImage (this=%p, id=%s)", this, imageId.toLatin1().constData()); QString appId = imageId.split('/').first(); Application* app = static_cast(m_appManager->findApplication(appId)); if (app == NULL) { LOG("ApplicationScreenshotProvider - app with appId %s not found", appId.toLatin1().constData()); return QImage(); } // TODO: if app not ready, return an app-provided splash image. If app has been stopped with saved state // return the screenshot that was saved to disk. if (!app->session() || !app->session()->default_surface()) { LOG("ApplicationScreenshotProvider - app session not found - asking for screenshot too early"); return QImage(); } QImage image = app->screenshotImage(); DLOG("ApplicationScreenshotProvider - working with size %d x %d", image.width(), image.height()); size->setWidth(image.width()); size->setHeight(image.height()); return image; } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/dbuswindowstack.cpp0000644000015301777760000000662312323676377027471 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // local #include "dbuswindowstack.h" #include "application_manager.h" // Qt #include #include namespace unitymir { DBusWindowStack::DBusWindowStack(ApplicationManager *parent) : QObject(parent) { qRegisterMetaType(); qDBusRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType< QList >(); qDBusRegisterMetaType(); qDBusRegisterMetaType< QList >(); QDBusConnection::sessionBus().registerService("com.canonical.Unity.WindowStack"); // TODO ExportScriptableSlots shouldn't be needed but without it i don't get the methods :-/ QDBusConnection::sessionBus().registerObject("/com/canonical/Unity/WindowStack", this, QDBusConnection::ExportAllSignals | QDBusConnection::ExportScriptableSlots |QDBusConnection::ExportScriptableInvokables ); } DBusWindowStack::~DBusWindowStack() { } AppIdDesktopFile DBusWindowStack::GetAppIdFromPid(unsigned int pid) { AppIdDesktopFile res; ApplicationManager *appMgr = static_cast(parent()); const Application* app = static_cast(appMgr->findApplicationWithPid(pid)); if (app) { res.app_id = app->appId(); res.desktop_file = app->desktopFile(); } return res; } QList DBusWindowStack::GetWindowStack() { QList res; ApplicationManager *appMgr = static_cast(parent()); const QList &applications = appMgr->list(); for(Application* app : applications) { WindowInfo wi; wi.window_id = 0; wi.app_id = app->appId(); wi.focused = app->focused(); wi.stage = 0; res << wi; } return res; } QStringList DBusWindowStack::GetWindowProperties(unsigned int window_id, const QString &app_id, const QStringList &names) { Q_UNUSED(window_id); Q_UNUSED(app_id); Q_UNUSED(names); return QStringList(); } QDBusArgument &operator<<(QDBusArgument &a, const AppIdDesktopFile &aidf) { a.beginStructure(); a << aidf.app_id << aidf.desktop_file; a.endStructure(); return a; } const QDBusArgument &operator>>(const QDBusArgument &a, AppIdDesktopFile &aidf) { a.beginStructure(); a >> aidf.app_id >> aidf.desktop_file; a.endStructure(); return a; } QDBusArgument &operator<<(QDBusArgument &a, const WindowInfo &wi) { a.beginStructure(); a << wi.window_id << wi.app_id << wi.focused << wi.stage; a.endStructure(); return a; } const QDBusArgument &operator>>(const QDBusArgument &a, WindowInfo &wi) { a.beginStructure(); a >> wi.window_id >> wi.app_id >> wi.focused >> wi.stage; a.endStructure(); return a; } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/inputarea.cpp0000644000015301777760000001303712323676377026243 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ //Qt #include // mir #include // local #include "inputarea.h" #include "mirsurface.h" #include "mirsurfacemanager.h" // unity-mir #include "qmirserverapplication.h" #include "shellserverconfiguration.h" #include "logging.h" namespace unitymir { InputArea::InputArea(QQuickItem *parent) : QQuickItem(parent) , m_enabled(true) , m_surface(nullptr) { DLOG("InputArea::InputArea (this=%p)", this); } InputArea::~InputArea() { DLOG("InputArea::~InputArea (this=%p)", this); if (m_surface) { m_surface->removeInputArea(this); } } bool InputArea::enabled() const { return m_enabled; } void InputArea::setEnabled(bool enabled) { DLOG("InputArea::setEnabled (this=%p, enabled=%p)", this, enabled ? "yes" : "no"); if (enabled != m_enabled) { m_enabled = enabled; if (m_enabled) { setMirInputArea(m_geometry); } if (m_surface) { m_surface->enableInputArea(this, enabled); } Q_EMIT enabledChanged(); } } MirSurface *InputArea::surface() const { return m_surface; } void InputArea::setSurface(MirSurface *surface) { doSetSurface(surface); } void InputArea::doSetSurface(MirSurface *surface) { DLOG("InputArea::doSetSurface (this=%p, surface=%p)", this, surface); if (surface == m_surface) return; if (surface) { // If surface is destroyed, make sure this InputArea doesn't point to it any more // For now, the QML engine owns this object so the MirSurface cannot delete it connect(surface, &MirSurface::destroyed, this, &InputArea::setNullSurface); } if (m_surface) { disconnect(surface, &MirSurface::destroyed, 0, 0); m_surface->removeInputArea(this); } m_surface = surface; if (m_enabled) { if (m_surface) { m_surface->installInputArea(this); } } Q_EMIT surfaceChanged(); } void InputArea::setNullSurface() { doSetSurface(nullptr); } void InputArea::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) { DLOG("InputArea::geometryChanged (this=%p)", this); if (newGeometry != oldGeometry) { m_geometry = newGeometry; if (m_enabled) { setMirInputArea(m_geometry); } } QQuickItem::geometryChanged(newGeometry, oldGeometry); } void InputArea::onAscendantChanged() { DLOG("InputArea::onAscendantChanged (this=%p)", this); listenToAscendantsChanges(); setMirInputArea(m_geometry); } void InputArea::onAscendantGeometryChanged() { DLOG("InputArea::onAscendantGeometryChanged (this=%p)", this); setMirInputArea(m_geometry); } void InputArea::listenToAscendantsChanges() { DLOG("InputArea::listenToAscendantsChanges (this=%p)", this); disconnectFromAscendantsChanges(); /* FIXME: Listen to geometry changes and parent changes on all the ascendants. Listening on x, y, width, height changes on all the ascendants is necessary because there is no API that notifies of absolute geometry changes. Ref.: https://bugreports.qt-project.org/browse/QTBUG-19746 */ m_connections.append(connect(this, &QQuickItem::parentChanged, this, &InputArea::onAscendantChanged)); QQuickItem* parent = parentItem(); while (parent != NULL) { m_connections.append(connect(parent, &QQuickItem::parentChanged, this, &InputArea::onAscendantChanged)); m_connections.append(connect(parent, &QQuickItem::xChanged, this, &InputArea::onAscendantGeometryChanged)); m_connections.append(connect(parent, &QQuickItem::yChanged, this, &InputArea::onAscendantGeometryChanged)); m_connections.append(connect(parent, &QQuickItem::widthChanged, this, &InputArea::onAscendantGeometryChanged)); m_connections.append(connect(parent, &QQuickItem::heightChanged, this, &InputArea::onAscendantGeometryChanged)); parent = parent->parentItem(); } } void InputArea::disconnectFromAscendantsChanges() { DLOG("InputArea::disconnectFromAscendantsChanges (this=%p)", this); // disconnect all previously connected signals Q_FOREACH (const QMetaObject::Connection& connection, m_connections) { disconnect(connection); } m_connections.clear(); } void InputArea::setMirInputArea(const QRectF& relativeGeometry) { DLOG("InputArea::setMirInputArea (this=%p, x=%lf, y=%lf, width=%lf, height=%lf)", this, relativeGeometry.x(), relativeGeometry.y(), relativeGeometry.width(), relativeGeometry.height()); using namespace mir::geometry; const QRect rect = parentItem()->mapRectToScene(relativeGeometry).toRect(); m_mirInputArea.top_left.x = X{rect.x()}; m_mirInputArea.top_left.y = Y{rect.y()}; m_mirInputArea.size.width = Width{rect.width()}; m_mirInputArea.size.height = Height{rect.height()}; if (m_surface) { m_surface->installInputArea(this); } } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/plugin.cpp0000644000015301777760000000741612323676377025555 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // Qt #include // local #include "application.h" #include "application_manager.h" #include "applicationscreenshotprovider.h" #include "mirsurfacemanager.h" #include "mirsurface.h" #include "inputarea.h" #include "inputfilterarea.h" #include "shellinputarea.h" #include "ubuntukeyboardinfo.h" // unity-mir #include "logging.h" static QObject* applicationManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) { Q_UNUSED(engine); Q_UNUSED(scriptEngine); DLOG("applicationManagerSingleton (engine=%p, scriptEngine=%p)", engine, scriptEngine); return unitymir::ApplicationManager::singleton(); } static QObject* surfaceManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) { Q_UNUSED(engine); Q_UNUSED(scriptEngine); DLOG("surfaceManagerSingleton (engine=%p, scriptEngine=%p)", engine, scriptEngine); return unitymir::MirSurfaceManager::singleton(); } class UnityApplicationPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") virtual void registerTypes(const char* uri) { DLOG("UnityApplicationPlugin::registerTypes (this=%p, uri='%s')", this, uri); ASSERT(QLatin1String(uri) == QLatin1String("Unity.Application")); qRegisterMetaType("ApplicationManager*"); //need for queueing signals qmlRegisterUncreatableType( uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML"); qmlRegisterSingletonType( uri, 0, 1, "ApplicationManager", applicationManagerSingleton); qmlRegisterUncreatableType( uri, 0, 1, "ApplicationInfoInterface", "Abstract interface. Cannot be created in QML"); qmlRegisterUncreatableType( uri, 0, 1, "ApplicationInfo", "ApplicationInfo can't be instantiated"); qmlRegisterSingletonType( uri, 0, 1, "SurfaceManager", surfaceManagerSingleton); qmlRegisterUncreatableType( uri, 0, 1, "MirSurface", "MirSurface can't be instantiated"); qmlRegisterType(uri, 0, 1, "InputArea"); qmlRegisterType(uri, 0, 1, "ShellInputArea"); qmlRegisterType(uri, 0, 1, "InputFilterArea"); qmlRegisterType(uri, 0, 1, "UbuntuKeyboardInfo"); } virtual void initializeEngine(QQmlEngine *engine, const char *uri) { QQmlExtensionPlugin::initializeEngine(engine, uri); unitymir::ApplicationManager* appManager = static_cast(applicationManagerSingleton(engine, NULL)); engine->addImageProvider(QLatin1String("application"), new unitymir::ApplicationScreenshotProvider(appManager)); } }; #include "plugin.moc" unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/qmldir0000644000015301777760000000020512323676377024753 0ustar pbusernogroup00000000000000module Unity.Application plugin unityapplicationplugin ApplicationImage 0.1 ApplicationImage.qml OSKController 0.1 OSKController.qml unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/applicationcontroller.h0000644000015301777760000000361712323676377030332 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef APPLICATION_CONTROLLER_H #define APPLICATION_CONTROLLER_H #include #include #include namespace unitymir { class ApplicationController : public QObject { Q_OBJECT public: enum class Error { APPLICATION_CRASHED, APPLICATION_FAILED_TO_START }; ApplicationController(const ApplicationController&) = delete; virtual ~ApplicationController() = default; ApplicationController& operator=(const ApplicationController&) = delete; virtual pid_t primaryPidForAppId(const QString& appId) = 0; virtual bool appIdHasProcessId(pid_t pid, const QString& appId) = 0; virtual bool stopApplicationWithAppId(const QString& appId) = 0; virtual bool startApplicationWithAppIdAndArgs(const QString& appId, const QStringList& arguments) = 0; Q_SIGNALS: void applicationAboutToBeStarted(QString id); void applicationStarted(QString id); void applicationStopped(QString id); void applicationFocusRequest(QString id); void applicationResumeRequest(QString id); void applicationError(QString id, ApplicationController::Error error); protected: ApplicationController() = default; }; } // namespace unitymir #endif // APPLICATION_CONTROLLER_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/mirsurface.h0000644000015301777760000000752212323676377026062 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef MIRSURFACE_H #define MIRSURFACE_H // Qt #include #include // mir #include #include namespace mir { namespace geometry { struct Rectangle; }} namespace unitymir { class MirSurfaceManager; class InputArea; class Application; class MirSurface : public QQuickItem { Q_OBJECT Q_ENUMS(Type) Q_ENUMS(State) Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY xChanged) Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY xChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) Q_PROPERTY(Type type READ type NOTIFY typeChanged) Q_PROPERTY(State state READ state NOTIFY stateChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged) public: explicit MirSurface(std::shared_ptr surface, Application* application, QQuickItem *parent = 0); ~MirSurface(); enum Type { Normal = mir_surface_type_normal, Utility = mir_surface_type_utility, Dialog = mir_surface_type_dialog, Overlay = mir_surface_type_overlay, Freestyle = mir_surface_type_freestyle, Popover = mir_surface_type_popover, }; enum State { Unknown = mir_surface_state_unknown, Restored = mir_surface_state_restored, Minimized = mir_surface_state_minimized, Maximized = mir_surface_state_maximized, VertMaximized = mir_surface_state_vertmaximized, /* SemiMaximized = mir_surface_state_semimaximized, // see mircommon/mir_toolbox/common.h*/ Fullscreen = mir_surface_state_fullscreen, }; //getters Application* application() const; Type type() const; State state() const; QString name() const; qreal x() const; qreal y() const; qreal width() const; qreal height() const; bool isVisible() const; //setters void setX(qreal); void setY(qreal); void setWidth(qreal); void setHeight(qreal); void setVisible(bool); void setAttribute(const MirSurfaceAttrib, const int); Q_SIGNALS: void typeChanged(); void stateChanged(); void nameChanged(); void xChanged(); void yChanged(); void widthChanged(); void heightChanged(); void visibleChanged(); protected: std::shared_ptr m_surface; private: // start of methods used by InputArea void installInputArea(const InputArea* area); bool removeInputArea(const InputArea* area); bool enableInputArea(const InputArea* area, bool enable = true); // end of methods used by InputArea void updateMirInputRegion(); void setType(const Type&); void setState(const State&); bool disableMirInputArea(const mir::geometry::Rectangle& rect); QSet m_inputAreas; bool m_visible = true; //FIXME(greyback) state should be in Mir::Shell::Surface, not here Application* m_application; friend class MirSurfaceManager; friend class InputArea; }; } // namespace unitymir Q_DECLARE_METATYPE(unitymir::MirSurface*) #endif // MIRSURFACE_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/inputfilterarea.h0000644000015301777760000000324412323676377027115 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef INPUTFILTERAREA_H #define INPUTFILTERAREA_H #include "inputarea.h" namespace unitymir { class MirSurface; /* Mimic the API provided by the SurfaceFlinger backend of the shell, in order to avoid unnecessary code branches in Shell's QML files. The API doesn't really do what it says, so it can be a bit confusing, but nevermind. Once we no longer desire to have Unity shell working with both SurfaceFlinger and Mir "backends", we can remove this file and make shell's QML code use ShellInputArea instead. */ class InputFilterArea : public InputArea { Q_OBJECT Q_PROPERTY(bool blockInput READ blockInput WRITE setBlockInput NOTIFY blockInputChanged) public: explicit InputFilterArea(QQuickItem *parent = 0); virtual void setSurface(MirSurface *surface); bool blockInput() const; void setBlockInput(bool enable); Q_SIGNALS: void blockInputChanged(); private Q_SLOT: void setShellSurface(MirSurface *surface); }; } // namespace unitymir #endif // INPUTFILTERAREA_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/ubuntukeyboardinfo.h0000644000015301777760000000502312323676377027633 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef UBUNTU_KEYBOARD_INFO_H #define UBUNTU_KEYBOARD_INFO_H #include #include namespace unitymir { // Temporary solution to get information about the onscreen keyboard // This shouldn't be needed once the OSK is a properly sized surface // instead of a fullscreen one. class UbuntuKeyboardInfo : public QObject { Q_OBJECT Q_PROPERTY(qreal x READ x NOTIFY xChanged) Q_PROPERTY(qreal y READ y NOTIFY yChanged) Q_PROPERTY(qreal width READ width NOTIFY widthChanged) Q_PROPERTY(qreal height READ height NOTIFY heightChanged) public: UbuntuKeyboardInfo(QObject *parent = 0); virtual ~UbuntuKeyboardInfo(); qreal x() const { return m_lastX; } qreal y() const { return m_lastY; } qreal width() const { return m_lastWidth; } qreal height() const { return m_lastHeight; } Q_SIGNALS: void xChanged(qreal x); void yChanged(qreal y); void widthChanged(qreal width); void heightChanged(qreal height); private Q_SLOTS: void tryConnectingToServer(); void onSocketStateChanged(QLocalSocket::LocalSocketState socketState); void onSocketError(QLocalSocket::LocalSocketError socketError); void readAllBytesFromSocket(); private: // NB! Must match the definition in ubuntu-keyboard. Not worth creating a shared header // just for that. struct SharedInfo { qint32 keyboardX; qint32 keyboardY; qint32 keyboardWidth; qint32 keyboardHeight; }; void readInfoFromSocket(); void retryConnection(); void buildSocketFilePath(); int m_consecutiveAttempts; QLocalSocket m_socket; qint32 m_lastX; qint32 m_lastY; qint32 m_lastWidth; qint32 m_lastHeight; QTimer m_connectionRetryTimer; // Path to the socket file created by ubuntu-keyboard QString m_socketFilePath; }; } // namespace unitymir #endif // UBUNTU_KEYBOARD_INFO_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/inputfilterarea.cpp0000644000015301777760000000317712323676377027455 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // own #include "inputfilterarea.h" // local #include "mirsurfacemanager.h" // Qt #include namespace unitymir { InputFilterArea::InputFilterArea(QQuickItem *parent) : InputArea(parent) { auto surface = MirSurfaceManager::singleton()->shellSurface(); if (surface) { doSetSurface(surface); } connect(MirSurfaceManager::singleton(), &MirSurfaceManager::shellSurfaceChanged, this, &InputFilterArea::setShellSurface); connect(this, &InputFilterArea::enabledChanged, this, &InputFilterArea::blockInputChanged); } void InputFilterArea::setSurface(MirSurface * /*surface*/) { qWarning() << "InputFilterArea::setSurface called, you're doing something wrong"; } void InputFilterArea::setShellSurface(MirSurface *surface) { doSetSurface(surface); } bool InputFilterArea::blockInput() const { return enabled(); } void InputFilterArea::setBlockInput(bool enable) { setEnabled(enable); } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/CMakeLists.txt0000644000015301777760000000457212323676377026313 0ustar pbusernogroup00000000000000pkg_check_modules(GLIB glib-2.0 REQUIRED) pkg_check_modules(PROCESS_CPP process-cpp REQUIRED) pkg_check_modules(UPSTART_APP_LAUNCH upstart-app-launch-2 REQUIRED) add_definitions(-DQT_PLUGIN) include_directories( ${GLIB_INCLUDE_DIRS} ${MIRCOMMON_INCLUDE_DIRS} ${MIRSERVER_INCLUDE_DIRS} ${PROCESS_CPP_INCLUDE_DIRS} ${UBUNTU_PLATFORM_API_INCLUDE_DIRS} ${UPSTART_APP_LAUNCH_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/src/unity-mir ) add_library( unityapplicationplugin SHARED application_manager.cpp application.cpp desktopfilereader.cpp plugin.cpp applicationscreenshotprovider.cpp dbuswindowstack.cpp taskcontroller.cpp mirsurface.cpp mirsurfacemanager.cpp inputarea.cpp inputfilterarea.cpp processcontroller.h processcontroller.cpp proc_info.cpp shellinputarea.cpp ubuntukeyboardinfo.cpp upstart/applicationcontroller.h upstart/applicationcontroller.cpp applicationcontroller.h application_manager.h application.h desktopfilereader.h applicationscreenshotprovider.h dbuswindowstack.h taskcontroller.h mirsurface.h mirsurfacemanager.h shellinputarea.h inputarea.h inputfilterarea.h ubuntukeyboardinfo.h # We need to pull in some external header files /usr/include/unity/shell/application/ApplicationManagerInterface.h /usr/include/unity/shell/application/ApplicationInfoInterface.h ) # We should not need this line according to the Qt5/CMake docs. # However, when removing it, include paths are not set and linking to Qt5 fails. qt5_use_modules(unityapplicationplugin Core Quick DBus) target_link_libraries( unityapplicationplugin unity-mir ubuntu_application_api_mirserver Qt5::Core Qt5::Quick Qt5::DBus ${CMAKE_THREAD_LIBS_INIT} ${GLIB_LDFLAGS} ${UBUNTU_PLATFORM_API_LDFLAGS} ${MIRSERVER_LDFLAGS} ${PROCESS_CPP_LDFLAGS} ${UPSTART_APP_LAUNCH_LDFLAGS} ubuntu_application_api_mirserver ) execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=plugindir_suffix unity-shell-api OUTPUT_VARIABLE SHELL_PLUGINDIR OUTPUT_STRIP_TRAILING_WHITESPACE) if(SHELL_PLUGINDIR STREQUAL "") set(SHELL_PLUGINDIR ${CMAKE_INSTALL_LIBDIR}/unity8/qml) endif() install( TARGETS unityapplicationplugin ARCHIVE DESTINATION ${SHELL_PLUGINDIR}/Unity/Application LIBRARY DESTINATION ${SHELL_PLUGINDIR}/Unity/Application ) install( FILES qmldir OSKController.qml DESTINATION ${SHELL_PLUGINDIR}/Unity/Application ) unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/mirsurfacemanager.cpp0000644000015301777760000001360212323676377027744 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // Qt #include // local #include "mirsurfacemanager.h" #include "mirsurface.h" #include "application_manager.h" // unity-mir #include "qmirserverapplication.h" #include "shellserverconfiguration.h" #include "sessionlistener.h" #include "surfaceconfigurator.h" #include "focussetter.h" #include "logging.h" // mir #include #include namespace msh = mir::shell; namespace ms = mir::scene; namespace unitymir { MirSurfaceManager *MirSurfaceManager::the_surface_manager = nullptr; MirSurfaceManager* MirSurfaceManager::singleton() { if (!the_surface_manager) { the_surface_manager = new MirSurfaceManager(); } return the_surface_manager; } MirSurfaceManager::MirSurfaceManager(QObject *parent) : QObject(parent) , m_shellSurface(nullptr) { DLOG("MirSurfaceManager::MirSurfaceManager (this=%p)", this); QMirServerApplication* mirServerApplication = dynamic_cast(QCoreApplication::instance()); if (mirServerApplication == NULL) { LOG("Need to use QMirServerApplication"); QCoreApplication::quit(); return; } m_mirServer = mirServerApplication->server(); QObject::connect(m_mirServer->sessionListener(), &SessionListener::shellSurfaceCreated, this, &MirSurfaceManager::shellSurfaceCreated); QObject::connect(m_mirServer->sessionListener(), &SessionListener::sessionCreatedSurface, this, &MirSurfaceManager::sessionCreatedSurface); QObject::connect(m_mirServer->sessionListener(), &SessionListener::sessionDestroyingSurface, this, &MirSurfaceManager::sessionDestroyingSurface); QObject::connect(m_mirServer->surfaceConfigurator(), &SurfaceConfigurator::surfaceAttributeChanged, this, &MirSurfaceManager::surfaceAttributeChanged); } MirSurfaceManager::~MirSurfaceManager() { DLOG("MirSurfaceManager::~MirSurfaceManager (this=%p)", this); Q_FOREACH(auto surface, m_surfaces) { delete surface; } m_surfaces.clear(); delete m_shellSurface; } MirSurface *MirSurfaceManager::shellSurface() const { return m_shellSurface; } MirSurface *MirSurfaceManager::surfaceFor(std::shared_ptr const& surface) { auto it = m_surfaces.find(surface.get()); if (it != m_surfaces.end()) { return *it; } else { DLOG("MirSurfaceManager::surfaceFor (this=%p) with surface name '%s' asking for a surface that was not created", this, surface->name().c_str()); return nullptr; } } void MirSurfaceManager::sessionCreatedSurface(mir::shell::Session const* session, std::shared_ptr const& surface) { DLOG("MirSurfaceManager::sessionCreatedSurface (this=%p) with surface name '%s'", this, surface->name().c_str()); ApplicationManager* appMgr = static_cast(ApplicationManager::singleton()); Application* application = appMgr->findApplicationWithSession(session); auto qmlSurface = new MirSurface(surface, application); m_surfaces.insert(surface.get(), qmlSurface); Q_EMIT surfaceCreated(qmlSurface); } void MirSurfaceManager::sessionDestroyingSurface(mir::shell::Session const*, std::shared_ptr const& surface) { DLOG("MirSurfaceManager::sessionDestroyingSurface (this=%p) with surface name '%s'", this, surface->name().c_str()); auto it = m_surfaces.find(surface.get()); if (it != m_surfaces.end()) { Q_EMIT surfaceDestroyed(*it); delete *it; m_surfaces.erase(it); return; } DLOG("MirSurfaceManager::sessionDestroyingSurface: unable to find MirSurface corresponding to surface '%s'", surface->name().c_str()); } void MirSurfaceManager::shellSurfaceCreated(const std::shared_ptr &surface) { DLOG("MirSurfaceManager::shellSurfaceCreated (this=%p)", this); m_shellSurface = new MirSurface(surface, nullptr); FocusSetter *fs = m_mirServer->focusSetter(); if (fs) { fs->set_default_keyboard_target(surface); } Q_EMIT shellSurfaceChanged(m_shellSurface); } void MirSurfaceManager::surfaceAttributeChanged(const ms::Surface *surface, const MirSurfaceAttrib attribute, const int value) { DLOG("MirSurfaceManager::surfaceAttributeChanged (this=%p, attrib=%d, value=%d)", this, static_cast(attribute), value); auto it = m_surfaces.find(surface); if (it != m_surfaces.end()) { it.value()->setAttribute(attribute, value); if (attribute == mir_surface_attrib_state && value == mir_surface_state_fullscreen) { // Only screen-wide applications are allowed to go fullscreen if (it.value()->application()->stage() == Application::MainStage) { it.value()->application()->setFullscreen(static_cast(value)); ApplicationManager* appMgr = static_cast(ApplicationManager::singleton()); QSize displaySize = appMgr->displaySize(); it.value()->setWidth(displaySize.width()); it.value()->setHeight(displaySize.height()); it.value()->setX(0); it.value()->setY(0); } } } } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/shellinputarea.h0000644000015301777760000000207012323676377026733 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef SHELLINPUTAREA_H #define SHELLINPUTAREA_H #include "inputarea.h" namespace unitymir { class MirSurface; class ShellInputArea : public InputArea { Q_OBJECT public: explicit ShellInputArea(QQuickItem *parent = 0); virtual void setSurface(MirSurface *surface); private Q_SLOT: void setShellSurface(MirSurface *surface); }; } // namespace unitymir #endif // SHELLINPUTAREA_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/ubuntukeyboardinfo.cpp0000644000015301777760000001126712323676377030175 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "ubuntukeyboardinfo.h" #include namespace { const int gConnectionAttemptIntervalMs = 5000; const int gMaxConsecutiveAttempts = 10; const char gServerName[] = "ubuntu-keyboard-info"; } namespace unitymir { UbuntuKeyboardInfo::UbuntuKeyboardInfo(QObject *parent) : QObject(parent), m_consecutiveAttempts(0), m_lastWidth(0), m_lastHeight(0) { connect(&m_socket, &QLocalSocket::stateChanged, this, &UbuntuKeyboardInfo::onSocketStateChanged); connect(&m_socket, &QIODevice::readyRead, this, &UbuntuKeyboardInfo::readAllBytesFromSocket); buildSocketFilePath(); typedef void (QLocalSocket::*MemberFunctionType)(QLocalSocket::LocalSocketError); MemberFunctionType funcPointer = &QLocalSocket::error; connect(&m_socket, funcPointer, this, &UbuntuKeyboardInfo::onSocketError); m_connectionRetryTimer.setInterval(gConnectionAttemptIntervalMs); m_connectionRetryTimer.setSingleShot(true); connect(&m_connectionRetryTimer, &QTimer::timeout, this, &UbuntuKeyboardInfo::tryConnectingToServer); tryConnectingToServer(); } UbuntuKeyboardInfo::~UbuntuKeyboardInfo() { // Make sure we don't get onSocketStateChanged() called during // destruction. m_socket.disconnect(this); } void UbuntuKeyboardInfo::tryConnectingToServer() { ++m_consecutiveAttempts; Q_ASSERT(!m_socketFilePath.isEmpty()); m_socket.connectToServer(m_socketFilePath, QIODevice::ReadOnly); } void UbuntuKeyboardInfo::onSocketStateChanged(QLocalSocket::LocalSocketState socketState) { switch (socketState) { case QLocalSocket::UnconnectedState: retryConnection(); break; case QLocalSocket::ConnectedState: m_consecutiveAttempts = 0; break; default: break; } } void UbuntuKeyboardInfo::onSocketError(QLocalSocket::LocalSocketError socketError) { Q_UNUSED(socketError); qWarning() << "UbuntuKeyboardInfo - socket error:" << m_socket.errorString(); } void UbuntuKeyboardInfo::retryConnection() { // Polling every gConnectionAttemptIntervalMs. Not the best approach but could be worse. if (m_consecutiveAttempts < gMaxConsecutiveAttempts) { if (!m_connectionRetryTimer.isActive()) { m_connectionRetryTimer.start(); } } else { qCritical() << "Failed to connect to" << m_socketFilePath << "after" << m_consecutiveAttempts << "failed attempts"; // it shouldn't be running, but just to be sure. m_connectionRetryTimer.stop(); } } void UbuntuKeyboardInfo::readAllBytesFromSocket() { while (m_socket.bytesAvailable() > 0) { readInfoFromSocket(); } } void UbuntuKeyboardInfo::readInfoFromSocket() { const size_t sharedInfoSize = sizeof(struct SharedInfo); QByteArray bytes = m_socket.read(sharedInfoSize); if (bytes.size() != sharedInfoSize) { qWarning() << "UbuntuKeyboardInfo: expected to receive" << sharedInfoSize << "but got" << bytes.size(); return; } { struct SharedInfo *sharedInfo = reinterpret_cast(bytes.data()); if (m_lastX != sharedInfo->keyboardX) { m_lastX = sharedInfo->keyboardX; Q_EMIT xChanged(m_lastX); } if (m_lastY != sharedInfo->keyboardY) { m_lastY = sharedInfo->keyboardY; Q_EMIT yChanged(m_lastY); } if (m_lastWidth != sharedInfo->keyboardWidth) { m_lastWidth = sharedInfo->keyboardWidth; Q_EMIT widthChanged(m_lastWidth); } if (m_lastHeight != sharedInfo->keyboardHeight) { m_lastHeight = sharedInfo->keyboardHeight; Q_EMIT heightChanged(m_lastHeight); } } } void UbuntuKeyboardInfo::buildSocketFilePath() { char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); if (xdgRuntimeDir) { m_socketFilePath = QDir(xdgRuntimeDir).filePath(gServerName); } else { m_socketFilePath = QDir("/tmp").filePath(gServerName); } } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/desktopfilereader.h0000644000015301777760000000455412323676377027420 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef DESKTOPFILEREADER_H #define DESKTOPFILEREADER_H #include #include #include namespace unitymir { class DesktopFileReader { public: class Factory { public: Factory(); Factory(const Factory&) = delete; virtual ~Factory(); Factory& operator=(const Factory&) = delete; virtual DesktopFileReader* createInstanceForAppId(const QString& appId); virtual DesktopFileReader* createInstanceForDesktopFile(const QFileInfo& fi); }; virtual ~DesktopFileReader(); virtual QString file() const { return file_; } virtual QString appId() const { return appId_; } virtual QString name() const { return entries_[kNameIndex]; } virtual QString comment() const { return entries_[kCommentIndex]; } virtual QString icon() const { return entries_[kIconIndex]; } virtual QString exec() const { return entries_[kExecIndex]; } virtual QString path() const { return entries_[kPathIndex]; } virtual QString stageHint() const { return entries_[kStageHintIndex]; } virtual bool loaded() const { return loaded_; } virtual QString findDesktopFile(const QString &appId) const; protected: friend class DesktopFileReaderFactory; DesktopFileReader(const QString &appId); DesktopFileReader(const QFileInfo &desktopFile); private: static const int kNameIndex = 0, kCommentIndex = 1, kIconIndex = 2, kExecIndex = 3, kPathIndex = 4, kStageHintIndex = 5, kNumberOfEntries = 6; virtual bool loadDesktopFile(QString desktopFile); QString appId_; QString file_; QVector entries_; bool loaded_; }; } // namespace unitymir #endif // DESKTOPFILEREADER_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/dbuswindowstack.h0000644000015301777760000000430612323676377027132 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef DBUSWINDOWSTACK_H #define DBUSWINDOWSTACK_H #include #include namespace unitymir { class ApplicationManager; class AppIdDesktopFile { public: QString app_id; QString desktop_file; }; QDBusArgument &operator<<(QDBusArgument &a, const AppIdDesktopFile &aidf); const QDBusArgument &operator>>(const QDBusArgument &a, AppIdDesktopFile &aidf); class WindowInfo { public: unsigned int window_id; QString app_id; bool focused; unsigned int stage; }; QDBusArgument &operator<<(QDBusArgument &a, const WindowInfo &aidf); const QDBusArgument &operator>>(const QDBusArgument &a, WindowInfo &aidf); class DBusWindowStack : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.WindowStack") public: explicit DBusWindowStack(ApplicationManager* parent); ~DBusWindowStack(); Q_INVOKABLE Q_SCRIPTABLE unitymir::AppIdDesktopFile GetAppIdFromPid(unsigned int pid); Q_INVOKABLE Q_SCRIPTABLE QList GetWindowStack(); Q_INVOKABLE Q_SCRIPTABLE QStringList GetWindowProperties(unsigned int window_id, const QString &app_id, const QStringList &names); Q_SIGNALS: void FocusedWindowChanged(unsigned int window_id, const QString &app_id, unsigned int stage); void WindowCreated(unsigned int window_id, const QString &app_id); void WindowDestroyed(unsigned int window_id, const QString &app_id); }; } // namespace unitymir Q_DECLARE_METATYPE(unitymir::AppIdDesktopFile) Q_DECLARE_METATYPE(unitymir::WindowInfo) #endif // DBUSWINDOWSTACK_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/OSKController.qml0000644000015301777760000000435412323676377026764 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ import QtQuick 2.0 import QtQuick.Window 2.0 import Unity.Application 0.1 Item { id: root property var __oskSurface: null readonly property bool enabled: __oskSurface !== null && __oskSurface !== undefined UbuntuKeyboardInfo { id: ubuntuKeyboardInfo } Connections { target: SurfaceManager onSurfaceCreated: { // FIXME(greyback) Not using "type" as it set after surface created if (surface.name === "MaliitOnScreenKeyboard") { __oskSurface = surface; } } onSurfaceDestroyed: { if (surface.name === "MaliitOnScreenKeyboard") { __oskSurface = null; } } } /* Do not let touches that are meant for the OSK hit the Shell components behind it. */ MouseArea { enabled: oskInputArea.enabled anchors.fill: oskInputArea } /* Need to position InputArea of oskSurface to cover the keyboard. */ InputArea { id: oskInputArea x: ubuntuKeyboardInfo.x y: ubuntuKeyboardInfo.y width: ubuntuKeyboardInfo.width height: ubuntuKeyboardInfo.height surface: __oskSurface enabled: false } Connections { target: __oskSurface onStateChanged: { if (__oskSurface.state === MirSurface.Maximized) { __oskSurface.visible = true; oskInputArea.enabled = true; } else { __oskSurface.visible = false; oskInputArea.enabled = false; } } } } unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/application_manager.h0000644000015301777760000001430312323676377027712 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef APPLICATIONMANAGER_H #define APPLICATIONMANAGER_H // local #include "desktopfilereader.h" // std #include // Qt #include #include #include // Unity API #include // local #include "application.h" namespace mir { namespace geometry { class Size; } namespace shell { class Session; class Surface; class FocusController; } } class ShellServerConfiguration; namespace unitymir { class DBusWindowStack; class MirSurfaceManager; class TaskController; class ProcInfo; class ApplicationManager : public unity::shell::application::ApplicationManagerInterface { Q_OBJECT Q_FLAGS(ExecFlags) public: class Factory { public: ApplicationManager* create(); }; // Mapping enums to Ubuntu Platform API enums. enum Flag { NoFlag = 0x0, ForceMainStage = 0x1, }; Q_DECLARE_FLAGS(ExecFlags, Flag) static ApplicationManager* singleton(); explicit ApplicationManager(const QSharedPointer& taskController, const QSharedPointer& desktopFileReaderFactory, const QSharedPointer& processInfo, std::shared_ptr const& controller, QSize const& displaySize, QObject *parent = 0); virtual ~ApplicationManager(); // ApplicationManagerInterface QString focusedApplicationId() const override; bool suspended() const; void setSuspended(bool suspended); Q_INVOKABLE unitymir::Application* get(int index) const override; Q_INVOKABLE unitymir::Application* findApplication(const QString &appId) const override; Q_INVOKABLE bool requestFocusApplication(const QString &appId) override; Q_INVOKABLE bool focusApplication(const QString &appId) override; Q_INVOKABLE void unfocusCurrentApplication() override; Q_INVOKABLE unitymir::Application* startApplication(const QString &appId, const QStringList &arguments) override; Q_INVOKABLE bool stopApplication(const QString &appId) override; Q_INVOKABLE bool updateScreenshot(const QString &appId); // QAbstractListModel int rowCount(const QModelIndex & parent = QModelIndex()) const override; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; Q_INVOKABLE unitymir::Application *startApplication(const QString &appId, ExecFlags flags, const QStringList &arguments = QStringList()); Q_INVOKABLE void move(int from, int to); const QList &list() const { return m_applications; } unitymir::Application* findApplicationWithPid(const qint64 pid); // Internal helpers void suspendApplication(Application *application); void resumeApplication(Application *application); int panelHeight(); QSize displaySize() const { return m_displaySize; } public Q_SLOTS: void authorizeSession(const quint64 pid, bool &authorized); void placeSession(mir::shell::Session const*, uint32_t &x, uint32_t &y); void onSessionStarting(std::shared_ptr const& session); void onSessionStopping(std::shared_ptr const& session); void onSessionFocused(std::shared_ptr const& session); void onSessionUnfocused(); void onSessionCreatedSurface(mir::shell::Session const*, std::shared_ptr const&); void onProcessStartReportReceived(const QString& appId, const bool failure); void onProcessStopped(const QString& appId, const bool unexpected); void onFocusRequested(const QString& appId); void onResumeRequested(const QString& appId); Q_SIGNALS: void focusRequested(const QString &appId); private Q_SLOTS: void screenshotUpdated(); private: void setFocused(Application *application); void add(Application *application); void remove(Application* application); Application* findApplicationWithSession(const std::shared_ptr &session); Application* findApplicationWithSession(const mir::shell::Session *session); Application* applicationForStage(Application::Stage stage); QModelIndex findIndex(Application* application); bool checkFocusOnRemovedApplication(Application* application); void shutdownApplication(Application* application); void stopStartingApplication(const QString &appId); QList m_applications; Application* m_focusedApplication; // remove as Mir has API for this Application* m_mainStageApplication; Application* m_sideStageApplication; Application* m_msApplicationToBeFocused; // placeholder store for async focusing Application* m_ssApplicationToBeFocused; // placeholder store for async focusing QStringList m_lifecycleExceptions; std::shared_ptr m_focusController; DBusWindowStack* m_dbusWindowStack; QSharedPointer m_taskController; QSharedPointer m_desktopFileReaderFactory; QSharedPointer m_procInfo; int m_gridUnitPx; bool m_fenceNext; QString m_nextFocusedAppId; QSize m_displaySize; int m_panelHeight; bool m_suspended; friend class DBusWindowStack; friend class MirSurfaceManager; }; } // namespace unitymir Q_DECLARE_METATYPE(unitymir::ApplicationManager*) #endif // APPLICATIONMANAGER_H unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/processcontroller.cpp0000644000015301777760000000745412323676377030043 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #include "processcontroller.h" #include "logging.h" // Process C++ #include #include #include #include // std #include #include namespace plpp = core::posix::linux::proc::process; namespace unitymir { ProcessController::OomController::OomController() { } void ProcessController::OomController::ensureProcessLikelyToBeKilled(pid_t pid) { // We avoid boundary values for oom_score_adj. For that, we // set it to 80% of the total available range. static const float defaultPercentage = 0.8; core::posix::Process process(pid); try { plpp::OomScoreAdj shellScore; core::posix::this_process::instance() >> shellScore; plpp::OomScoreAdj processScore { static_cast((plpp::OomScoreAdj::max_value() - shellScore.value) * defaultPercentage) + shellScore.value }; process << processScore; } catch(...) { // Accessing OomScoreAdj resulted in an exception being thrown. // Trying with the deprecated OomAdj now as a last resort. try { process << plpp::OomAdj{plpp::OomAdj::max_value()}; } catch(...) { LOG("ensureProcessIsLikelyToBeKilled failed"); } } } void ProcessController::OomController::ensureProcessUnlikelyToBeKilled(pid_t pid) { // By system default, we set the oom_score_adj of Unity8 to -10 (via lightdm). // As we want to avoid that any app's oom_score_adj is <= Unity8's oom_score_adj, // we choose a default increase of +1. static const int default_increase = 1; core::posix::Process process(pid); try { plpp::OomScoreAdj shellScore; core::posix::this_process::instance() >> shellScore; plpp::OomScoreAdj processScore { shellScore.value + default_increase }; process << processScore; } catch(...) { // Accessing OomScoreAdj resulted in an exception being thrown. // Trying with the deprecated OomAdj now as a last resort. // By system default, we set the oom_score_adj of Unity8 to -10 (via lightdm). // As we want to avoid that any app's oom_score_adj or oom_adj is <= Unity8's oom_score_adj, // we choose a default value of -9 for oom_score_adj and 0 for oom_adj. static const int defaultValue = 0; try { process << plpp::OomAdj{defaultValue}; } catch(...) { LOG("ensureProcessIsUnlikelyToBeKilled failed"); } } } ProcessController::ProcessController() : m_oomController(new ProcessController::OomController()) { } ProcessController::~ProcessController() { } const QSharedPointer& ProcessController::oomController() const { return m_oomController; } bool ProcessController::sigStopProcessGroupForPid(pid_t pid) const { return -1 != kill(-pid, SIGSTOP); } bool ProcessController::sigContinueProcessGroupForPid(pid_t pid) const { return -1 != kill(-pid, SIGCONT); } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/proc_info.cpp0000644000015301777760000000354312323676377026232 0ustar pbusernogroup00000000000000/* * Copyright (C) 2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "proc_info.h" #include #include namespace unitymir { ProcInfo::~ProcInfo() { } std::unique_ptr ProcInfo::commandLine(quint64 pid) { QFile cmdline(QString("/proc/%1/cmdline").arg(pid)); if (!cmdline.open(QIODevice::ReadOnly | QIODevice::Text)) { return nullptr; } return std::unique_ptr(new CommandLine{ cmdline.readLine().replace('\0', ' ') }); } QStringList ProcInfo::CommandLine::asStringList() const { return QString(m_command.data()).split(' '); } bool ProcInfo::CommandLine::startsWith(char const* prefix) const { return m_command.startsWith(prefix); } bool ProcInfo::CommandLine::contains(char const* prefix) const { return m_command.contains(prefix); } boost::optional ProcInfo::CommandLine::getParameter(const char* name) const { QString pattern = QRegularExpression::escape(name) + "(\\S+)"; QRegularExpression regExp(pattern); QRegularExpressionMatch regExpMatch = regExp.match(m_command); if (!regExpMatch.hasMatch()) { return boost::optional{}; } return boost::optional{regExpMatch.captured(1)}; } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/Application/shellinputarea.cpp0000644000015301777760000000257112323676377027274 0ustar pbusernogroup00000000000000/* * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ // own #include "shellinputarea.h" // local #include "mirsurfacemanager.h" // Qt #include namespace unitymir { ShellInputArea::ShellInputArea(QQuickItem *parent) : InputArea(parent) { auto surface = MirSurfaceManager::singleton()->shellSurface(); if (surface) { doSetSurface(surface); } connect(MirSurfaceManager::singleton(), &MirSurfaceManager::shellSurfaceChanged, this, &ShellInputArea::setShellSurface); } void ShellInputArea::setSurface(MirSurface * /*surface*/) { qWarning() << "ShellInputArea::setSurface called, you're doing something wrong"; } void ShellInputArea::setShellSurface(MirSurface *surface) { doSetSurface(surface); } } // namespace unitymir unity-mir-0.3+14.04.20140417/src/modules/Unity/CMakeLists.txt0000644000015301777760000000003612323676377024037 0ustar pbusernogroup00000000000000add_subdirectory(Application) unity-mir-0.3+14.04.20140417/src/modules/CMakeLists.txt0000644000015301777760000000003012323676377022721 0ustar pbusernogroup00000000000000add_subdirectory(Unity) unity-mir-0.3+14.04.20140417/scripts/0000755000015301777760000000000012323677263017413 5ustar pbusernogroup00000000000000unity-mir-0.3+14.04.20140417/scripts/fix-qt-cmake.sh0000755000015301777760000000047212323676377022250 0ustar pbusernogroup00000000000000#!/bin/bash # $1 must contain path to QT cmake files # Given that path, all hardcoded root paths are fixed up for file in $(find ${1} -type f -name \*.cmake) do echo "fixing $file" sed -i 's/NO_DEFAULT_PATH/ONLY_CMAKE_FIND_ROOT_PATH/g' $file sed -i 's/\/usr/${CMAKE_FIND_ROOT_PATH}\/usr/g' $file done unity-mir-0.3+14.04.20140417/scripts/setup-partial-armhf-chroot.sh0000755000015301777760000000411612323676377025142 0ustar pbusernogroup00000000000000#!/bin/bash set -e if [ -z ${1} ]; then echo "please supply directory to create partial chroot in. (eg, ./setup-partial-armhf-chroot.sh mychroot-dir)" exit fi echo "creating phablet-compatible armhf partial chroot for unity-mir compilation in directory ${1}" if [ ! -d ${1} ]; then mkdir -p ${1} fi DEBCONTROL=$(pwd)/../debian/control pushd ${1} > /dev/null # Empty dpkg status file, so that ALL dependencies are listed with dpkg-checkbuilddeps echo "" > status # Manual error code checking is needed for dpkg-checkbuilddeps set +e # Parse dependencies from debian/control # dpkg-checkbuilddeps returns 1 when dependencies are not met and the list is sent to stderr builddeps=$(dpkg-checkbuilddeps -a armhf --admindir=. ${DEBCONTROL} 2>&1 ) if [ $? -ne 1 ] ; then echo "${builddeps}" exit 2 fi # now turn exit on error option set -e # Sanitize dependencies list for submission to debootstrap # build-essential is not needed as we are cross-compiling builddeps=$(echo ${builddeps} | sed -e 's/dpkg-checkbuilddeps://g' -e 's/Unmet build dependencies://g' -e 's/build-essential:native//g') builddeps=$(echo ${builddeps} | sed 's/([^)]*)//g') # TODO: figure out why debootstrap is not finding libunity-api-dev package - it doesn't seem to be needed for cross-compilation - is it needed in debian/control? builddeps=$(echo ${builddeps} | sed 's/libunity-api-dev//g') builddeps=$(echo ${builddeps} | sed 's/ /,/g') fakeroot debootstrap --include=${builddeps} --arch=armhf --download-only --variant=buildd trusty . # Remove libc libraries that confuse the cross-compiler rm var/cache/apt/archives/libc-dev*.deb rm var/cache/apt/archives/libc6*.deb for deb in var/cache/apt/archives/* ; do if [ ! -d ${deb} ] ; then echo "unpacking: ${deb}" dpkg -x ${deb} . fi done # Fix up symlinks which asssumed the usual root path for broken_symlink in $(find . -name \*.so -type l -xtype l) ; do ln -sf $(pwd)$(readlink ${broken_symlink}) ${broken_symlink} done popd > /dev/null # QT CMake files have hardcoded root paths - fix them up ./fix-qt-cmake.sh ${1}/usr/lib/arm-linux-gnueabihf/cmake/ unity-mir-0.3+14.04.20140417/README0000644000015301777760000000110212323676377016603 0ustar pbusernogroup00000000000000 1. Description 2. Building 1. Description -------------- This repository provides Qt bindings for those Mir APIs that are not exposed through the QPA plugins but are needed for the functionality of the Unity shell. 2. Building ----------- To compile Unity-Mir, create the makefiles with cmake and build with make: $ cmake . -DCMAKE_INSTALL_PREFIX=/usr $ make By default, Unity-Mir compiles a release build. To compile a debug build, the following cmake command should be used: $ cmake . -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug unity-mir-0.3+14.04.20140417/COPYING.LGPL0000644000015301777760000001674312323676377017534 0ustar pbusernogroup00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.