From f15440c3c3c8ca865acf66202eaa29ca97a63920 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 4 Oct 2014 14:09:49 +0200 Subject: [PATCH 1/4] Provide a fallback if samplers in vertex shader are not supported. --- app/qml/ShaderTerminal.qml | 51 ++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/app/qml/ShaderTerminal.qml b/app/qml/ShaderTerminal.qml index dc30bbd..b035ad4 100644 --- a/app/qml/ShaderTerminal.qml +++ b/app/qml/ShaderTerminal.qml @@ -56,6 +56,9 @@ ShaderEffect { property real time: timeManager.time property variant randomFunctionSource: randfuncsource + // If something goes wrong activate the fallback version of the shader. + property bool fallBack: false + blending: false //Smooth random texture used for flickering effect. @@ -84,7 +87,6 @@ ShaderEffect { vertexShader: " uniform highp mat4 qt_Matrix; uniform highp float time; - uniform sampler2D randomFunctionSource; uniform highp float disp_left; uniform highp float disp_right; @@ -96,10 +98,13 @@ ShaderEffect { varying highp vec2 qt_TexCoord0;" + - (brightness_flickering !== 0.0 ?" + (!fallBack ? " + uniform sampler2D randomFunctionSource;" : "") + + + (!fallBack && brightness_flickering !== 0.0 ?" varying lowp float brightness; uniform lowp float brightness_flickering;" : "") + - (horizontal_sincronization !== 0.0 ?" + (!fallBack && horizontal_sincronization !== 0.0 ?" varying lowp float horizontal_distortion; 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.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)));" + - (brightness_flickering !== 0.0 ? " + (!fallBack && brightness_flickering !== 0.0 ? " 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 negsinc = 1.0 - 0.6 * horizontal_sincronization;" + " horizontal_distortion = step(negsinc, randval) * (randval - negsinc) * 0.3*horizontal_sincronization;" @@ -148,9 +153,16 @@ ShaderEffect { uniform lowp float jitter;" : "") + (rgb_shift !== 0 ? " 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;" : "") + - (horizontal_sincronization !== 0 ? " + (!fallBack && horizontal_sincronization !== 0 ? " varying lowp float horizontal_distortion;" : "") + (glowing_line_strength !== 0 ? " @@ -166,6 +178,20 @@ ShaderEffect { "vec2 cc = vec2(0.5) - qt_TexCoord0;" + "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 ? " float noise = noise_strength;" : "") + @@ -238,5 +264,14 @@ ShaderEffect { "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; + } + } } -- 2.47.2 From 15a951288d9d65f9b2c78b7e3516a8abb751cab8 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 4 Oct 2014 15:01:50 +0200 Subject: [PATCH 2/4] Imported initial directory implementation from terminal-app. --- app/qml/PreprocessedTerminal.qml | 1 + konsole-qml-plugin/src/Session.cpp | 10 +++++++--- konsole-qml-plugin/src/ksession.cpp | 22 +++++++--------------- konsole-qml-plugin/src/ksession.h | 12 +++++++----- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index 0c0d033..6ca87ad 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -137,6 +137,7 @@ Item{ } Component.onCompleted: { shadersettings.terminalFontChanged.connect(handleFontChange); + ksession.startShellProgram(); forceActiveFocus(); } } diff --git a/konsole-qml-plugin/src/Session.cpp b/konsole-qml-plugin/src/Session.cpp index 5eee57f..a3aeb68 100644 --- a/konsole-qml-plugin/src/Session.cpp +++ b/konsole-qml-plugin/src/Session.cpp @@ -31,8 +31,7 @@ #include // Qt -#include -#include +#include #include #include @@ -143,7 +142,12 @@ WId Session::windowId() const // 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); } } diff --git a/konsole-qml-plugin/src/ksession.cpp b/konsole-qml-plugin/src/ksession.cpp index a12e838..a1ced10 100644 --- a/konsole-qml-plugin/src/ksession.cpp +++ b/konsole-qml-plugin/src/ksession.cpp @@ -35,8 +35,6 @@ KSession::KSession(QObject *parent) : QObject(parent), m_session(createSession("KSession")) { connect(m_session, SIGNAL(finished()), this, SLOT(sessionFinished())); - - m_session->run(); } KSession::~KSession() @@ -159,33 +157,27 @@ void KSession::setEnvironment(const QStringList &environment) void KSession::setShellProgram(const QString &progname) { - if (!m_session) - return; - m_session->setProgram(progname); } -void KSession::setWorkingDirectory(const QString &dir) +void KSession::setInitialWorkingDirectory(const QString &dir) { - if (!m_session) - return; - + _initialWorkingDirectory = dir; m_session->setInitialWorkingDirectory(dir); } +QString KSession::getInitialWorkingDirectory() +{ + return _initialWorkingDirectory; +} + void KSession::setArgs(QStringList &args) { - if (!m_session) - return; - m_session->setArguments(args); } void KSession::setTextCodec(QTextCodec *codec) { - if (!m_session) - return; - m_session->setCodec(codec); } diff --git a/konsole-qml-plugin/src/ksession.h b/konsole-qml-plugin/src/ksession.h index eb18339..c935b4d 100644 --- a/konsole-qml-plugin/src/ksession.h +++ b/konsole-qml-plugin/src/ksession.h @@ -34,6 +34,7 @@ class KSession : public QObject { Q_OBJECT Q_PROPERTY(QString kbScheme READ getKeyBindings WRITE setKeyBindings NOTIFY changedKeyBindings) + Q_PROPERTY(QString initialWorkingDirectory READ getInitialWorkingDirectory WRITE setInitialWorkingDirectory) public: KSession(QObject *parent = 0); @@ -43,9 +44,6 @@ public: //bool setup(); void addView(KTerminalDisplay *displa); - //start shell program if it was not started in constructor - void startShellProgram(); - int getRandomSeed(); QString getKeyBindings(); @@ -57,8 +55,9 @@ public: // Shell program, default is /bin/bash void setShellProgram(const QString & progname); - //working directory - void setWorkingDirectory(const QString & dir); + //Initial working directory + void setInitialWorkingDirectory(const QString & dir); + QString getInitialWorkingDirectory(); // Shell program args, default is none void setArgs(QStringList & args); @@ -106,6 +105,8 @@ public slots: void setKeyBindings(const QString & kb); void setTitle(QString name); + void startShellProgram(); + int getShellPID(); void changeDir(const QString & dir); @@ -125,6 +126,7 @@ private slots: private: //Konsole::KTerminalDisplay *m_terminalDisplay; + QString _initialWorkingDirectory; Session *m_session; }; -- 2.47.2 From a9ed10573bd3cc6189691e15fc355bc5d07db10a Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 4 Oct 2014 15:26:09 +0200 Subject: [PATCH 3/4] Plugin: export shell program to QML. --- konsole-qml-plugin/src/ksession.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/konsole-qml-plugin/src/ksession.h b/konsole-qml-plugin/src/ksession.h index c935b4d..dbb912e 100644 --- a/konsole-qml-plugin/src/ksession.h +++ b/konsole-qml-plugin/src/ksession.h @@ -52,9 +52,6 @@ public: //environment void setEnvironment(const QStringList & environment); - // Shell program, default is /bin/bash - void setShellProgram(const QString & progname); - //Initial working directory void setInitialWorkingDirectory(const QString & dir); QString getInitialWorkingDirectory(); @@ -107,6 +104,9 @@ public slots: void startShellProgram(); + // Shell program, default is /bin/bash + void setShellProgram(const QString & progname); + int getShellPID(); void changeDir(const QString & dir); -- 2.47.2 From 614793ecd062199e0b1fc4efaa733aa3bf845b67 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 4 Oct 2014 16:21:17 +0200 Subject: [PATCH 4/4] Added --workdir and --program flags. --- app/main.cpp | 16 ++++++++++++++-- app/qml/PreprocessedTerminal.qml | 7 +++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index 10c6b96..0cb4bb6 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,12 +1,20 @@ #include #include +#include +#include + #include #include #include +QString getNamedArgument(QStringList args, QString name) { + int index = args.indexOf(name); + return (index != -1) ? args[index + 1] : QString(""); +} + int main(int argc, char *argv[]) { setenv("QT_QPA_PLATFORMTHEME", "", 1); @@ -16,13 +24,18 @@ int main(int argc, char *argv[]) // Manage command line arguments from the cpp side QStringList args = app.arguments(); if (args.contains("-h") || args.contains("--help")) { - qDebug() << "Usage: " + args.at(0) + " [--default-settings] [-h|--help]"; + qDebug() << "Usage: " + args.at(0) + " [--default-settings] [--workdir ] [--program ] [-h|--help]"; qDebug() << " --default-settings Run cool-old-term with the default settings"; + qDebug() << " --workdir Change working directory to 'dir'"; + qDebug() << " --program Run the 'prog' in the new terminal."; qDebug() << " -p|--profile Run cool-old-term with the given profile."; qDebug() << " -h|--help Print this help."; return 0; } + engine.rootContext()->setContextProperty("workdir", getNamedArgument(args, "--workdir")); + engine.rootContext()->setContextProperty("shellProgram", getNamedArgument(args, "--program")); + // Manage import paths QStringList importPathList = engine.importPathList(); importPathList.prepend(QCoreApplication::applicationDirPath() + "/imports/"); @@ -32,4 +45,3 @@ int main(int argc, char *argv[]) return app.exec(); } - diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index 6ca87ad..97318c5 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -137,6 +137,13 @@ Item{ } Component.onCompleted: { 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(); } -- 2.47.2