10#include <QHyodaX11XtermLog.h>
16QHyodaX11XtermLog::QHyodaX11XtermLog(
QHyodaJob *j,
21 xterm(new QProcess()),
22 xwininfo(new QProcess()),
23 xdotool(new QProcess()),
25 xtermTitle(QString(
"xtermHyoda0x%1").arg(qHash(QUuid::createUuid()),0,16).toLocal8Bit().constData()),
29 qDebug() <<
"\33[32m[QHyodaX11XtermLog::QHyodaX11XtermLog] NEW"<<
"\33[m";
33 connect(xterm, SIGNAL(finished(
int,QProcess::ExitStatus)),
34 this,SLOT(xtermFinished(
int,QProcess::ExitStatus)));
36 QString executable(
"xterm");
37 QStringList arguments=
38 QStringList() <<
"-fg" <<
"green" <<
"-bg" <<
"black"
40 <<
"-title" << xtermTitle
44 <<
"-sb" <<
"-sl" <<
"8192"
52 <<
"-into" << QString::number(xWidget->winId())
55 QString xterm_execute;
56 for(
int i=1;i<job->argc;i+=1)
57 xterm_execute.append(QString(
"%1%2").arg((i>1)?
" ":
"",job->argv[i]));
58 xterm_execute.append(
";/bin/bash");
59 arguments << xterm_execute;
60 qDebug() <<
"\33[32m[QHyodaX11XtermLog] arguments: "<<arguments<<
"\33[m";
62 xterm->start(executable,arguments);
63 if (!xterm->waitForStarted()) qFatal(
"QHyodaX11XtermLog::refresh NOT started!");
65 xwininfo->setProcessChannelMode(QProcess::MergedChannels);
66 connect(xwininfo,SIGNAL(readyReadStandardOutput()),
this,SLOT(xwininfoOutput()));
73void QHyodaX11XtermLog::setupUI(QWidget *parent){
74 QGroupBox *groupBox =
new QGroupBox(QString(
"Log"),parent);
75 QVBoxLayout *layout =
new QVBoxLayout(
this);
76 QVBoxLayout *vbox =
new QVBoxLayout;
77 vbox->addWidget(xWidget=
new QWidget(
this));
78 groupBox->setLayout(vbox);
79 layout->addWidget(groupBox);
86void QHyodaX11XtermLog::xwininfoStart(){
87 xwininfo->start(QString(
"xwininfo"), QStringList()<<
"-name" << xtermTitle);
88 if (!xwininfo->waitForStarted()) qFatal(
"xlsclients NOT started!");
94void QHyodaX11XtermLog::setXtermSizeWithXdotool(
const QSize size){
96 if (xdotool->state()==QProcess::Running)
return;
97 xdotool->start(QString(
"xdotool"),
100 << QString::number(WinId)
101 << QString::number(size.width())
102 << QString::number(size.height()));
103 if (!xdotool->waitForStarted()) qFatal(
"xlsclients NOT started!");
109void QHyodaX11XtermLog::resizeEvent(QResizeEvent *e){
110 setXtermSizeWithXdotool(size=e->size());
116void QHyodaX11XtermLog::xtermFinished(
int exitCode, QProcess::ExitStatus exitStatus){
117 qDebug() <<
"\33[32m[QHyodaX11XtermLog] xterm has finished with exitCode"
118 <<exitCode<<
", and exitStatus"<<exitStatus<<
"\33[m";
119 xterm->closeWriteChannel();
120 if (xterm->waitForFinished()) qFatal(
"xterm NOT finished!");
121 if (exitStatus==QProcess::NormalExit) job->
quit();
127void QHyodaX11XtermLog::xwininfoOutput(){
129 if (WinId!=0)
return;
130 const QStringList lines=QString(xwininfo->readAllStandardOutput()).split(QRegExp(
"\\s+"));
132 if (lines.size()>=4 && lines.at(4).startsWith(
"0x")){
134 WinId = lines.at(4).toLong(&ok, 16);
135 qDebug()<<
"␛[1;32m[xwininfoOutput] WinId is"
136 <<QString(
"0x%1").arg(WinId,0,16).toLocal8Bit().constData()<<
"␛[0m";
137 if (!ok) qFatal(
"Could not play with WinID");
138 setXtermSizeWithXdotool(size);
143 if (xwininfo->waitForFinished()) qFatal(
"xwininfo NOT closed!");