-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
432 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=draft launcher | ||
#StartLimitIntervalSec=600 | ||
#StartLimitBurst=4 | ||
After=home.mount | ||
|
||
[Service] | ||
ExecStart=/usr/bin/draft | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name=xochitl | ||
desc=The standard environment for reMarkable. | ||
call=/usr/bin/xochitl | ||
term=killall xochitl | ||
imgFile=xochitl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name=fingerterm | ||
desc=Touchscreen accessible terminal. | ||
call=/usr/bin/fingerterm | ||
term=: | ||
imgFile=fingerterm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name=shutdown | ||
desc=Switch off the reMarkable. | ||
call=shutdown now | ||
term=: | ||
imgFile=power |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "handler.h" | ||
#include "mainview.h" | ||
#include <QtQuick> | ||
#include <QString> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <time.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
|
||
time_t lastReturn; | ||
int qSize = 1404; | ||
|
||
Handler::Handler(std::string lT, std::string term, QGuiApplication* app, MainView* mainView, QObject* obj) | ||
: link(lT), term(term), ef(obj), app(app), mainView(mainView){ | ||
|
||
time(&lastReturn); | ||
|
||
} | ||
|
||
bool Handler::eventFilter(QObject* obj, QEvent* event) | ||
{ | ||
if (event->type() == QEvent::MouseButtonPress) { | ||
obj->parent()->setProperty("color", QVariant("#22000000")); | ||
return true; | ||
} | ||
|
||
else if (event->type() == QEvent::MouseButtonRelease) { | ||
obj->parent()->setProperty("color", QVariant("white")); | ||
time_t tim; | ||
time(&tim); | ||
// 1 second cooldown before opening again! | ||
if(difftime(tim, lastReturn) > 1) { | ||
handleEvent(); | ||
} | ||
return true; | ||
} | ||
else | ||
return false; | ||
} | ||
|
||
void Handler::handleEvent() { | ||
|
||
std::cout << "Setting termfile /etc/draft/.terminate" << std::endl; | ||
std::ofstream termfile; | ||
termfile.open("/etc/draft/.terminate"); | ||
termfile << term << std::endl; | ||
|
||
std::cout << "Running command " << link << "..." << std::endl; | ||
system((link).c_str()); | ||
|
||
// Don't exit any more - just head back to the launcher! | ||
std::cout << "Running again" << std::endl; | ||
|
||
// Yes, this is an exceptionally hacky way of repainting the screen | ||
qSize = 1-(qSize-1403)+1403; | ||
|
||
usleep(500000); | ||
|
||
mainView->rootObject()->setProperty("width",QVariant(qSize)); | ||
|
||
// Cooldown | ||
time(&lastReturn); | ||
|
||
} | ||
|
||
Handler::~Handler() { | ||
ef->removeEventFilter(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <QObject> | ||
#include <QQuickItem> | ||
#include <QDebug> | ||
#include <QtGui> | ||
#include "mainview.h" | ||
#include <time.h> | ||
|
||
extern time_t lastReturn; | ||
|
||
class Handler : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
Handler(std::string lT, std::string term, QGuiApplication* app, MainView* mainView, QObject* obj); | ||
~Handler(); | ||
bool eventFilter(QObject* obj, QEvent* event); | ||
void handleEvent(); | ||
|
||
private: | ||
std::string link; | ||
std::string term; | ||
QObject* ef; | ||
QGuiApplication* app; | ||
MainView* mainView; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#include "options.h" | ||
#include "handler.h" | ||
#include <dirent.h> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <QtQuick> | ||
#include <algorithm> | ||
|
||
const std::string configDir = "/etc/draft"; | ||
|
||
// Create options and add them to the screen. | ||
Options::Options(MainView* mainView, QGuiApplication* app) : | ||
mainView(mainView), | ||
optionsView(mainView->rootObject()->findChild<QQuickItem*>("optionsArea")), | ||
app(app) | ||
{ | ||
|
||
std::vector<std::string> filenames; | ||
|
||
// If the config directory doesn't exist, | ||
// then print an error and stop. | ||
if(!Options::read_directory(configDir, filenames)) { | ||
Options::error("Failed to read directory - it does not exist."); | ||
return; | ||
} | ||
|
||
std::sort(filenames.begin(), filenames.end()); | ||
|
||
for(std::string f : filenames) { | ||
|
||
std::cout << "parsing file " << f << std::endl; | ||
QFile file((configDir + "/" + f).c_str()); | ||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||
Options::error("Couldn't find the file " + f + "."); | ||
break; | ||
} | ||
|
||
QTextStream in(&file); | ||
|
||
OptionItem opt; | ||
|
||
while (!in.atEnd()) { | ||
std::string line = in.readLine().toStdString(); | ||
if(line.length() > 0) { | ||
size_t sep = line.find("="); | ||
if(sep != line.npos) { | ||
std::string lhs = line.substr(0,sep); | ||
std::string rhs = line.substr(sep+1); | ||
|
||
if (lhs == "name") opt.name = rhs; | ||
else if(lhs == "desc") opt.desc = rhs; | ||
else if(lhs == "imgFile") opt.imgFile = rhs; | ||
else if(lhs == "call") opt.call = rhs; | ||
else if(lhs == "term") opt.term = rhs; | ||
else std::cout << "ignoring unknown parameter \"" << line | ||
<< "\" in file \"" << f << "\"" << std::endl; | ||
} | ||
} | ||
else { | ||
std::cout << "ignoring malformed line \"" << line | ||
<< "\" in file \"" << f << "\"" << std::endl; | ||
} | ||
} | ||
|
||
if(opt.call == "" || opt.term == "") continue; | ||
createOption(opt, optionList.size()); | ||
optionList.push_back(opt); | ||
|
||
} | ||
|
||
} | ||
|
||
void Options::createOption(OptionItem &option, size_t index) { | ||
|
||
QQuickView* opt = new QQuickView(); | ||
opt->setSource(QDir(DEPLOYMENT_PATH).filePath("qml/MenuItem.qml")); | ||
opt->show(); | ||
|
||
QQuickItem* root = opt->rootObject(); | ||
root->setProperty("itemNumber", QVariant(index)); | ||
root->setParentItem(optionsView); | ||
|
||
root->setProperty("t_name",QVariant(option.name.c_str())); | ||
root->setProperty("t_desc",QVariant(option.desc.c_str())); | ||
root->setProperty("t_imgFile",QVariant(("file://"+configDir+"/icons/"+option.imgFile+".png").c_str())); | ||
|
||
QObject* mouseArea = root->children().at(0); | ||
Handler* handler = new Handler(option.call, option.term, app, mainView, mouseArea); | ||
root->children().at(0)->installEventFilter(handler); | ||
|
||
option.object = opt; | ||
option.handler = handler; | ||
} | ||
|
||
void Options::error(std::string text) { | ||
std::cout << "!! Error: " << text << std::endl; | ||
} | ||
|
||
|
||
// Stolen shamelessly from Martin Broadhurst | ||
bool Options::read_directory(const std::string name, | ||
std::vector<std::string>& filenames) | ||
{ | ||
DIR* dirp = opendir(name.c_str()); | ||
if(dirp == nullptr) { | ||
return false; | ||
} | ||
|
||
struct dirent * dp; | ||
while ((dp = readdir(dirp)) != NULL) { | ||
std::string dn = dp->d_name; | ||
|
||
if(dn == "." || dn == ".."|| dn == "icons") continue; | ||
|
||
filenames.push_back(dn); | ||
} | ||
closedir(dirp); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include <QObject> | ||
#include <QQuickView> | ||
#include <QDebug> | ||
#include <QGuiApplication> | ||
#include "mainview.h" | ||
|
||
struct OptionItem { | ||
std::string name; | ||
std::string desc; | ||
std::string call; | ||
std::string term; | ||
std::string imgFile; | ||
QObject* object; | ||
QObject* handler; | ||
}; | ||
|
||
class Options | ||
{ | ||
public: | ||
Options(MainView* mainView, QGuiApplication* app); | ||
bool read_directory(const std::string name, std::vector<std::string>& files); | ||
private: | ||
void error(std::string text); | ||
void createOption(OptionItem &option, size_t index); | ||
|
||
MainView* mainView; | ||
QQuickItem* optionsView; | ||
std::vector<OptionItem> optionList; | ||
QGuiApplication* app; | ||
}; |
Oops, something went wrong.