1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-02-07 05:31:24 +00:00

Merge pull request #137 from Swordfish90/unstable

Import latest changes from unstable.
This commit is contained in:
Filippo Scognamiglio 2014-10-04 16:36:30 +02:00
commit 9deeb5e405
6 changed files with 89 additions and 36 deletions

View File

@ -1,12 +1,20 @@
#include <QtQml/QQmlApplicationEngine> #include <QtQml/QQmlApplicationEngine>
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
#include <QQmlContext>
#include <QStringList>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <QDebug> #include <QDebug>
#include <stdlib.h> #include <stdlib.h>
QString getNamedArgument(QStringList args, QString name) {
int index = args.indexOf(name);
return (index != -1) ? args[index + 1] : QString("");
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
setenv("QT_QPA_PLATFORMTHEME", "", 1); setenv("QT_QPA_PLATFORMTHEME", "", 1);
@ -16,13 +24,18 @@ int main(int argc, char *argv[])
// Manage command line arguments from the cpp side // Manage command line arguments from the cpp side
QStringList args = app.arguments(); QStringList args = app.arguments();
if (args.contains("-h") || args.contains("--help")) { if (args.contains("-h") || args.contains("--help")) {
qDebug() << "Usage: " + args.at(0) + " [--default-settings] [-h|--help]"; qDebug() << "Usage: " + args.at(0) + " [--default-settings] [--workdir <dir>] [--program <prog>] [-h|--help]";
qDebug() << " --default-settings Run cool-old-term with the default settings"; qDebug() << " --default-settings Run cool-old-term with the default settings";
qDebug() << " --workdir <dir> Change working directory to 'dir'";
qDebug() << " --program <prog> Run the 'prog' in the new terminal.";
qDebug() << " -p|--profile Run cool-old-term with the given profile."; qDebug() << " -p|--profile Run cool-old-term with the given profile.";
qDebug() << " -h|--help Print this help."; qDebug() << " -h|--help Print this help.";
return 0; return 0;
} }
engine.rootContext()->setContextProperty("workdir", getNamedArgument(args, "--workdir"));
engine.rootContext()->setContextProperty("shellProgram", getNamedArgument(args, "--program"));
// Manage import paths // Manage import paths
QStringList importPathList = engine.importPathList(); QStringList importPathList = engine.importPathList();
importPathList.prepend(QCoreApplication::applicationDirPath() + "/imports/"); importPathList.prepend(QCoreApplication::applicationDirPath() + "/imports/");
@ -32,4 +45,3 @@ int main(int argc, char *argv[])
return app.exec(); return app.exec();
} }

View File

@ -137,6 +137,14 @@ Item{
} }
Component.onCompleted: { Component.onCompleted: {
shadersettings.terminalFontChanged.connect(handleFontChange); shadersettings.terminalFontChanged.connect(handleFontChange);
// Retrieve the variable set in main.cpp if arguments are passed.
if (shellProgram)
ksession.setShellProgram(shellProgram);
if (workdir)
ksession.initialWorkingDirectory = workdir;
ksession.startShellProgram();
forceActiveFocus(); forceActiveFocus();
} }
} }

View File

@ -56,6 +56,9 @@ ShaderEffect {
property real time: timeManager.time property real time: timeManager.time
property variant randomFunctionSource: randfuncsource property variant randomFunctionSource: randfuncsource
// If something goes wrong activate the fallback version of the shader.
property bool fallBack: false
blending: false blending: false
//Smooth random texture used for flickering effect. //Smooth random texture used for flickering effect.
@ -84,7 +87,6 @@ ShaderEffect {
vertexShader: " vertexShader: "
uniform highp mat4 qt_Matrix; uniform highp mat4 qt_Matrix;
uniform highp float time; uniform highp float time;
uniform sampler2D randomFunctionSource;
uniform highp float disp_left; uniform highp float disp_left;
uniform highp float disp_right; uniform highp float disp_right;
@ -96,10 +98,13 @@ ShaderEffect {
varying highp vec2 qt_TexCoord0;" + varying highp vec2 qt_TexCoord0;" +
(brightness_flickering !== 0.0 ?" (!fallBack ? "
uniform sampler2D randomFunctionSource;" : "") +
(!fallBack && brightness_flickering !== 0.0 ?"
varying lowp float brightness; varying lowp float brightness;
uniform lowp float brightness_flickering;" : "") + uniform lowp float brightness_flickering;" : "") +
(horizontal_sincronization !== 0.0 ?" (!fallBack && horizontal_sincronization !== 0.0 ?"
varying lowp float horizontal_distortion; varying lowp float horizontal_distortion;
uniform lowp float horizontal_sincronization;" : "") + uniform lowp float horizontal_sincronization;" : "") +
" "
@ -107,11 +112,11 @@ ShaderEffect {
qt_TexCoord0.x = (qt_MultiTexCoord0.x - disp_left) / (1.0 - disp_left - disp_right); qt_TexCoord0.x = (qt_MultiTexCoord0.x - disp_left) / (1.0 - disp_left - disp_right);
qt_TexCoord0.y = (qt_MultiTexCoord0.y - disp_top) / (1.0 - disp_top - disp_bottom); qt_TexCoord0.y = (qt_MultiTexCoord0.y - disp_top) / (1.0 - disp_top - disp_bottom);
vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" + vec2 coords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" +
(brightness_flickering !== 0.0 ? " (!fallBack && brightness_flickering !== 0.0 ? "
brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * brightness_flickering;" brightness = 1.0 + (texture2D(randomFunctionSource, coords).g - 0.5) * brightness_flickering;"
: "") + : "") +
(horizontal_sincronization !== 0.0 ? " (!fallBack && horizontal_sincronization !== 0.0 ? "
float randval = 1.5 * texture2D(randomFunctionSource,(vec2(1.0) -coords) * 0.5).g; float randval = 1.5 * texture2D(randomFunctionSource,(vec2(1.0) -coords) * 0.5).g;
float negsinc = 1.0 - 0.6 * horizontal_sincronization;" + " float negsinc = 1.0 - 0.6 * horizontal_sincronization;" + "
horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * 0.3*horizontal_sincronization;" horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * 0.3*horizontal_sincronization;"
@ -148,9 +153,16 @@ ShaderEffect {
uniform lowp float jitter;" : "") + uniform lowp float jitter;" : "") +
(rgb_shift !== 0 ? " (rgb_shift !== 0 ? "
uniform lowp float rgb_shift;" : "") + uniform lowp float rgb_shift;" : "") +
(brightness_flickering !== 0 ? "
(fallBack && (brightness_flickering || horizontal_sincronization) ? "
uniform lowp sampler2D randomFunctionSource;" : "") +
(fallBack && horizontal_sincronization !== 0 ? "
uniform lowp float horizontal_sincronization;" : "") +
(fallBack && brightness_flickering !== 0.0 ?"
uniform lowp float brightness_flickering;" : "") +
(!fallBack && brightness_flickering !== 0 ? "
varying lowp float brightness;" : "") + varying lowp float brightness;" : "") +
(horizontal_sincronization !== 0 ? " (!fallBack && horizontal_sincronization !== 0 ? "
varying lowp float horizontal_distortion;" : "") + varying lowp float horizontal_distortion;" : "") +
(glowing_line_strength !== 0 ? " (glowing_line_strength !== 0 ? "
@ -166,6 +178,20 @@ ShaderEffect {
"vec2 cc = vec2(0.5) - qt_TexCoord0;" + "vec2 cc = vec2(0.5) - qt_TexCoord0;" +
"float distance = length(cc);" + "float distance = length(cc);" +
//FallBack if there are problem
(fallBack && (brightness_flickering || horizontal_sincronization) ? "
vec2 randCoords = vec2(fract(time/(1024.0*2.0)), fract(time/(1024.0*1024.0)));" : "") +
(fallBack && brightness_flickering !== 0.0 ? "
float brightness = 1.0 + (texture2D(randomFunctionSource, randCoords).g - 0.5) * brightness_flickering;"
: "") +
(fallBack && horizontal_sincronization !== 0.0 ? "
float randval = 1.5 * texture2D(randomFunctionSource,(vec2(1.0) - randCoords) * 0.5).g;
float negsinc = 1.0 - 0.6 * horizontal_sincronization;" + "
float horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * 0.3*horizontal_sincronization;"
: "") +
(noise_strength ? " (noise_strength ? "
float noise = noise_strength;" : "") + float noise = noise_strength;" : "") +
@ -238,5 +264,14 @@ ShaderEffect {
"gl_FragColor = vec4(finalColor * screen_brightness, qt_Opacity);" + "gl_FragColor = vec4(finalColor * screen_brightness, qt_Opacity);" +
"}" "}"
onStatusChanged: if (log) console.log(log) //Print warning messages onStatusChanged: {
// Print warning messages
if (log)
console.log(log);
// Activate fallback mode
if (status == ShaderEffect.Error) {
fallBack = true;
}
}
} }

View File

@ -31,8 +31,7 @@
#include <stdlib.h> #include <stdlib.h>
// Qt // Qt
#include <QGuiApplication> #include <QQuickWindow>
#include <QtGui/QWindow>
#include <QtCore/QByteRef> #include <QtCore/QByteRef>
#include <QtCore/QDir> #include <QtCore/QDir>
@ -143,7 +142,12 @@ WId Session::windowId() const
// window = window->parentWidget(); // window = window->parentWidget();
// } // }
return QGuiApplication::focusWindow()->winId(); //return QGuiApplication::focusWindow()->winId();
//There is an issue here! Probably this always returns zero.
//but I try to preseve the behavior there was before.
QQuickWindow * window = _views.first()->window();
return (window ? window->winId() : 0);
} }
} }

View File

@ -35,8 +35,6 @@ KSession::KSession(QObject *parent) :
QObject(parent), m_session(createSession("KSession")) QObject(parent), m_session(createSession("KSession"))
{ {
connect(m_session, SIGNAL(finished()), this, SLOT(sessionFinished())); connect(m_session, SIGNAL(finished()), this, SLOT(sessionFinished()));
m_session->run();
} }
KSession::~KSession() KSession::~KSession()
@ -159,33 +157,27 @@ void KSession::setEnvironment(const QStringList &environment)
void KSession::setShellProgram(const QString &progname) void KSession::setShellProgram(const QString &progname)
{ {
if (!m_session)
return;
m_session->setProgram(progname); m_session->setProgram(progname);
} }
void KSession::setWorkingDirectory(const QString &dir) void KSession::setInitialWorkingDirectory(const QString &dir)
{ {
if (!m_session) _initialWorkingDirectory = dir;
return;
m_session->setInitialWorkingDirectory(dir); m_session->setInitialWorkingDirectory(dir);
} }
QString KSession::getInitialWorkingDirectory()
{
return _initialWorkingDirectory;
}
void KSession::setArgs(QStringList &args) void KSession::setArgs(QStringList &args)
{ {
if (!m_session)
return;
m_session->setArguments(args); m_session->setArguments(args);
} }
void KSession::setTextCodec(QTextCodec *codec) void KSession::setTextCodec(QTextCodec *codec)
{ {
if (!m_session)
return;
m_session->setCodec(codec); m_session->setCodec(codec);
} }

View File

@ -34,6 +34,7 @@ class KSession : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString kbScheme READ getKeyBindings WRITE setKeyBindings NOTIFY changedKeyBindings) Q_PROPERTY(QString kbScheme READ getKeyBindings WRITE setKeyBindings NOTIFY changedKeyBindings)
Q_PROPERTY(QString initialWorkingDirectory READ getInitialWorkingDirectory WRITE setInitialWorkingDirectory)
public: public:
KSession(QObject *parent = 0); KSession(QObject *parent = 0);
@ -43,9 +44,6 @@ public:
//bool setup(); //bool setup();
void addView(KTerminalDisplay *displa); void addView(KTerminalDisplay *displa);
//start shell program if it was not started in constructor
void startShellProgram();
int getRandomSeed(); int getRandomSeed();
QString getKeyBindings(); QString getKeyBindings();
@ -54,11 +52,9 @@ public:
//environment //environment
void setEnvironment(const QStringList & environment); void setEnvironment(const QStringList & environment);
// Shell program, default is /bin/bash //Initial working directory
void setShellProgram(const QString & progname); void setInitialWorkingDirectory(const QString & dir);
QString getInitialWorkingDirectory();
//working directory
void setWorkingDirectory(const QString & dir);
// Shell program args, default is none // Shell program args, default is none
void setArgs(QStringList & args); void setArgs(QStringList & args);
@ -106,6 +102,11 @@ public slots:
void setKeyBindings(const QString & kb); void setKeyBindings(const QString & kb);
void setTitle(QString name); void setTitle(QString name);
void startShellProgram();
// Shell program, default is /bin/bash
void setShellProgram(const QString & progname);
int getShellPID(); int getShellPID();
void changeDir(const QString & dir); void changeDir(const QString & dir);
@ -125,6 +126,7 @@ private slots:
private: private:
//Konsole::KTerminalDisplay *m_terminalDisplay; //Konsole::KTerminalDisplay *m_terminalDisplay;
QString _initialWorkingDirectory;
Session *m_session; Session *m_session;
}; };