Skip to content

Commit

Permalink
Get task switcher working
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 31, 2024
1 parent 04dd4df commit 8c7832a
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 173 deletions.
1 change: 0 additions & 1 deletion applications/display-server/dbusinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ QList<std::shared_ptr<Surface>> DbusInterface::visibleSurfaces(){
if(
surface->visible()
&& connection->isRunning()
&& !connection->isStopped()
){
surfaces.append(surface);
}
Expand Down
1 change: 0 additions & 1 deletion applications/launcher/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ OxideWindow {
visible: true
title: qsTr("Oxide")
focus: true
backgroundColor: "white"
FontLoader { id: iconFont; source: "/font/icomoon.ttf" }
onAfterSynchronizing: {
if (stateController.state == "loading") {
Expand Down
2 changes: 0 additions & 2 deletions applications/lockscreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ using namespace Oxide;
using namespace Oxide::QML;
using namespace Oxide::Sentry;

#define DEBUG_EVENTS

int main(int argc, char *argv[]){
deviceSettings.setupQtEnvironment();
QGuiApplication app(argc, argv);
Expand Down
1 change: 1 addition & 0 deletions applications/lockscreen/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ OxideWindow {
objectName: "window"
visible: stateController.state != "loading"
title: qsTr("Oxide")
color: "black"
property int itemPadding: 10
FontLoader { id: iconFont; source: "/font/icomoon.ttf" }
Component.onCompleted: {
Expand Down
1 change: 0 additions & 1 deletion applications/process-manager/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import "widgets"
OxideWindow {
id: window
visible: true
backgroundColor: "white"
onAfterSynchronizing: {
if (stateController.state == "loading") {
stateController.state = "loaded";
Expand Down
1 change: 0 additions & 1 deletion applications/screenshot-viewer/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ OxideWindow {
id: window
objectName: "window"
visible: stateController.state !== "loading"
backgroundColor: "white"
title: {
if(stateController.state !== "viewing" || !viewer.model){
return Qt.application.displayName;
Expand Down
1 change: 0 additions & 1 deletion applications/system-service/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ void Application::interruptApplication(){
startSpan("stopped", "Application is stopped");
}
});
getCompositorDBus()->lower(QString("connection/%1").arg(m_process->processId()));
});
}
void Application::waitForPause(){
Expand Down
2 changes: 1 addition & 1 deletion applications/system-service/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OxideWindow{
height: 1
visible: true
opacity: 0
backgroundColor: "transparent"
color: "transparent"
Shortcut{
sequences: ["Alt+Tab"]
context: Qt.ApplicationShortcut
Expand Down
58 changes: 2 additions & 56 deletions applications/task-switcher/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <signal.h>
#include <liboxide.h>

#include "screenprovider.h"
#include "appitem.h"

using namespace codes::eeems::oxide1;
Expand All @@ -28,10 +27,8 @@ class Controller : public QObject {
Q_OBJECT

public:
Controller(QObject* parent, ScreenProvider* screenProvider)
Controller(QObject* parent)
: QObject(parent),applications() {
blankImage = new QImage(qApp->primaryScreen()->geometry().size(), QImage::Format_Mono);
this->screenProvider = screenProvider;
auto bus = QDBusConnection::systemBus();
qDebug() << "Waiting for tarnish to start up...";
while(!bus.interface()->registeredServiceNames().value().contains(OXIDE_SERVICE)){
Expand All @@ -47,16 +44,8 @@ class Controller : public QObject {
connect(signalHandler, &SignalHandler::sigUsr1, this, &Controller::sigUsr1);
connect(signalHandler, &SignalHandler::sigUsr2, this, &Controller::sigUsr2);

qDebug() << "Requesting screen API...";
QDBusObjectPath path = api->requestAPI("screen");
if(path.path() == "/"){
qDebug() << "Unable to get screen API";
throw "";
}
screenApi = new Screen(OXIDE_SERVICE, path.path(), bus, this);

qDebug() << "Requesting apps API...";
path = api->requestAPI("apps");
QDBusObjectPath path = api->requestAPI("apps");
if(path.path() == "/"){
qDebug() << "Unable to get apps API";
throw "";
Expand All @@ -66,8 +55,6 @@ class Controller : public QObject {
connect(appsApi, &Apps::applicationRegistered, this, &Controller::registerApplication);
connect(appsApi, &Apps::applicationLaunched, this, &Controller::reload);
connect(appsApi, &Apps::applicationExited, this, &Controller::reload);

updateImage();
}
~Controller(){}

Expand Down Expand Up @@ -190,43 +177,6 @@ class Controller : public QObject {
}
stateControllerUI->setProperty("state", state);
}
void updateImage(){
qDebug() << "Updating background...";
Oxide::Sentry::sentry_transaction("controller", "updateImage", [this](Oxide::Sentry::Transaction* t){
QImage* img = nullptr;
Oxide::Sentry::sentry_span(t, "previousApplications", "Get image from previous application", [this, &img](Oxide::Sentry::Span* s){
auto previousApplications = appsApi->previousApplications();
while(img == nullptr && !previousApplications.isEmpty()){
auto name = previousApplications.takeLast();
Oxide::Sentry::sentry_span(s, name.toStdString(), "Load image from application", [this, &img, previousApplications, name]{
auto path = ((QDBusObjectPath)appsApi->getApplicationPath(name)).path();
if(path == "/"){
O_WARNING("Unable to get save screen for" << name);
return;
}
auto bus = QDBusConnection::systemBus();
Application app(OXIDE_SERVICE, path, bus, this);
auto data = app.screenCapture();
auto image = QImage::fromData(data, "JPG");
if(image.isNull()){
O_WARNING("Image for " << name << " is corrupt, trying next application");
return;
}
img = new QImage(image);
qDebug() << "Using save screen from " << name;
});
}
});
Oxide::Sentry::sentry_span(t, "update", "Update image", [this, img]{
if(img != nullptr){
screenProvider->updateImage(img);
return;
}
qWarning() << "No previous application. Using blank screen";
screenProvider->updateImage(blankImage);
});
});
}

void setRoot(QObject* root){ this->root = root; }
Apps* getAppsApi() { return appsApi; }
Expand All @@ -239,7 +189,6 @@ private slots:
::kill(tarnishPid(), SIGUSR1);
qDebug() << "Sent to the foreground...";
setState("loading");
updateImage();
}
void sigUsr2(){
qDebug() << "Sent to the background...";
Expand Down Expand Up @@ -268,13 +217,10 @@ private slots:

private:
General* api;
Screen* screenApi;
Apps* appsApi;
QObject* root = nullptr;
QObject* stateControllerUI = nullptr;
ScreenProvider* screenProvider;
QList<QObject*> applications;
QImage* blankImage;

int tarnishPid() { return api->tarnishPid(); }
QObject* getStateControllerUI(){
Expand Down
3 changes: 0 additions & 3 deletions applications/task-switcher/corrupt_stable.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>

#include "controller.h"
#include "screenprovider.h"
#endif
10 changes: 1 addition & 9 deletions applications/task-switcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
#include <cstdlib>
#include <signal.h>
#include <liboxide.h>
#include <liboxide/eventfilter.h>
#include <liboxide/oxideqml.h>

#include "controller.h"

#include "screenprovider.h"

using namespace std;
using namespace Oxide;
using namespace Oxide::QML;
Expand All @@ -31,22 +27,18 @@ int main(int argc, char *argv[]){
app.setOrganizationDomain(OXIDE_SERVICE);
app.setApplicationName("corrupt");
app.setApplicationVersion(APP_VERSION);
auto screenProvider = new ScreenProvider(&app);
Controller controller(&app, screenProvider);
Controller controller(&app);
QQmlApplicationEngine engine;
registerQML(&engine);
QQmlContext* context = engine.rootContext();
context->setContextProperty("apps", QVariant::fromValue(controller.getApps()));
context->setContextProperty("controller", &controller);
engine.rootContext()->setContextProperty("screenProvider", screenProvider);
engine.addImageProvider("screen", screenProvider);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty()){
qDebug() << "Nothing to display";
return -1;
}
auto root = engine.rootObjects().first();
root->installEventFilter(new EventFilter(&app));
controller.setRoot(root);

signal(SIGINT, sigHandler);
Expand Down
49 changes: 9 additions & 40 deletions applications/task-switcher/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,36 @@ import "./widgets"
OxideWindow {
id: window
objectName: "window"
visible: stateController.state === "loaded"
backgroundColor: "transparent"
flags: Qt.FramelessWindowHint
title: qsTr("Corrupt")
property int itemPadding: 10
Connections{
target: screenProvider
onImageChanged: background.reload()
}
color: "transparent"
Component.onCompleted: controller.startup()
visible: true
Connections {
target: controller
onReload: {
function onReload(){
appsView.model = controller.getApps();
if(appsView.currentIndex > appsView.count){
appsView.currentIndex = appsView.count
}
}
}
Shortcut{
sequence: [StandardKey.Cancel, Qt.Key_Backspace]
sequences: [StandardKey.Cancel, "Backspace"]
context: Qt.ApplicationShortcut
onActivated: controller.previousApplication()
}

Component.onCompleted: {
controller.startup();
}
background: Rectangle {
Image {
id: background
objectName: "background"
anchors.fill: parent
cache: false
source: "image://screen/image"
visible: stateController.state === "loaded"
property bool counter: false
function reload(){
controller.breadcrumb("background", "reload");
console.log("Reloading background");
counter = !counter
source = "image://screen/image?id=" + counter
}
}
}
initialItem: MouseArea {
initialItem: MouseArea{
anchors.fill: parent
enabled: stateController.state === "loaded"
onClicked: {
controller.breadcrumb("background", "click", "ui");
controller.previousApplication();
}
onClicked: controller.previousApplication()
}
page.header: Item{}
page.footer: Rectangle {
id: footer
color: "white"
border.color: "black"
border.width: 1
width: parent.width
height: 150
anchors.left: parent.left
anchors.right: parent.right
visible: stateController.state === "loaded"
clip: true
RowLayout {
anchors.fill: parent
Expand Down
35 changes: 0 additions & 35 deletions applications/task-switcher/screenprovider.h

This file was deleted.

3 changes: 1 addition & 2 deletions applications/task-switcher/task-switcher.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ INSTALLS += applications
INCLUDEPATH += ../../shared
HEADERS += \
appitem.h \
controller.h \
screenprovider.h
controller.h

RESOURCES += \
qml.qrc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"bin": "/opt/bin/corrupt",
"flags": ["hidden", "nosavescreen", "nosplash"],
"type": "backgroundable",
"permissions": ["apps", "screen"]
"permissions": ["apps"]
}
3 changes: 1 addition & 2 deletions shared/liboxide/OxideWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ApplicationWindow {
property alias centerMenu: centerMenu.children
property alias stack: stack
property alias initialItem: stack.initialItem
property alias backgroundColor: background.color
property alias headerBackgroundColor: header.color
property bool landscape: Oxide.landscape
Component.onCompleted: stack.forceActiveFocus()
Expand Down Expand Up @@ -55,7 +54,7 @@ ApplicationWindow {
}
background: Rectangle {
id: background
color: "black"
color: window.color
}
contentData: [
StackView {
Expand Down
6 changes: 4 additions & 2 deletions shared/liboxide/devicesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,17 @@ namespace Oxide {
QCoreApplication::addLibraryPath("/opt/usr/lib/plugins");
qputenv("QMLSCENE_DEVICE", "software");
qputenv("QT_QUICK_BACKEND","software");
QString platform("oxide:enable_fonts:freetype:freetype");
if(touch){
qputenv(
"QT_QPA_PLATFORM",
QString("oxide:enable_fonts:%1")
QString("%1:%2")
.arg(platform)
.arg(deviceSettings.getTouchEnvSetting())
.toUtf8()
);
}else{
qputenv("QT_QPA_PLATFORM", "oxide:enable_fonts");
qputenv("QT_QPA_PLATFORM", platform.toUtf8());
}
}

Expand Down
Loading

0 comments on commit 8c7832a

Please sign in to comment.