Skip to content

Commit a597347

Browse files
committed
Add screenCapturable support
Signed-off-by: xiaoming <2014500726@smail.xtu.edu.cn>
1 parent 4fd3054 commit a597347

File tree

10 files changed

+102
-23
lines changed

10 files changed

+102
-23
lines changed

.github/workflows/linux.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
- name: Install Qt
5050
uses: jurplel/install-qt-action@v4
5151
with:
52-
version: '6.5.3'
52+
version: '6.8.1'
5353
modules: 'qtwebsockets qtserialport qtmultimedia'
54-
aqtversion: ==3.1.7
54+
aqtversion: '==3.1.20'
5555

5656
- name: Install prerequisites
5757
run: |
@@ -84,7 +84,7 @@ jobs:
8484
run: |
8585
git fetch --tags --force
8686
sed -i 's/--long --dirty/--long/g' ./tools/generate_info.sh
87-
sed -i 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.5.3\/gcc_64/g' build_deb.sh
87+
sed -i 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.8.1\/gcc_64/g' build_deb.sh
8888
sed -i 's/LIBSSH2_DIR=\/libssh2/LIBSSH2_DIR=\/usr\/local\/output/g' ./lib/qtssh/qtssh.pri
8989
mkdir prebuilt_plugins
9090
python3 ./.github/scripts/get_plugin.py ./.github/scripts/plugin_list.json ./prebuilt_plugins

.github/workflows/linux_appimage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
- name: Install Qt
5050
uses: jurplel/install-qt-action@v4
5151
with:
52-
version: '6.5.3'
52+
version: '6.8.1'
5353
modules: 'qtwebsockets qtserialport qtmultimedia'
54-
aqtversion: ==3.1.7
54+
aqtversion: '==3.1.20'
5555

5656
- name: Install prerequisites
5757
run: |
@@ -84,7 +84,7 @@ jobs:
8484
run: |
8585
git fetch --tags --force
8686
sed -i 's/--long --dirty/--long/g' ./tools/generate_info.sh
87-
sed -i 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.5.3\/gcc_64/g' build_AppImage.sh
87+
sed -i 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.8.1\/gcc_64/g' build_AppImage.sh
8888
sed -i 's/LIBSSH2_DIR=\/libssh2/LIBSSH2_DIR=\/usr\/local\/output/g' ./lib/qtssh/qtssh.pri
8989
mkdir prebuilt_plugins
9090
python3 ./.github/scripts/get_plugin.py ./.github/scripts/plugin_list.json ./prebuilt_plugins

.github/workflows/macos.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
- name: Install Qt
5050
uses: jurplel/install-qt-action@v4
5151
with:
52-
version: '6.5.3'
52+
version: '6.8.1'
5353
modules: 'qtwebsockets qtserialport qtmultimedia'
54-
aqtversion: ==3.1.7
54+
aqtversion: '==3.1.20'
5555

5656
- name: Install prerequisites
5757
run: |
@@ -76,7 +76,7 @@ jobs:
7676
run: |
7777
git fetch --tags --force
7878
sed -i'.original' -e 's/--long --dirty/--long/g' ./tools/generate_info.sh
79-
sed -i'.original' -e 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.5.3\/macos/g' build_dmg.sh
79+
sed -i'.original' -e 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.8.1\/macos/g' build_dmg.sh
8080
sed -i'.original' -e 's/LIBSSH2_DIR=\/libssh2/LIBSSH2_DIR=\/usr\/local\/output/g' ./lib/qtssh/qtssh.pri
8181
mkdir prebuilt_plugins
8282
python3 ./.github/scripts/get_plugin.py ./.github/scripts/plugin_list.json ./prebuilt_plugins

.github/workflows/macos_arm64.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
- name: Install Qt
5050
uses: jurplel/install-qt-action@v4
5151
with:
52-
version: '6.5.3'
52+
version: '6.8.1'
5353
modules: 'qtwebsockets qtserialport qtmultimedia'
54-
aqtversion: ==3.1.7
54+
aqtversion: '==3.1.20'
5555

5656
- name: Install prerequisites
5757
run: |
@@ -76,7 +76,7 @@ jobs:
7676
run: |
7777
git fetch --tags --force
7878
sed -i'.original' -e 's/--long --dirty/--long/g' ./tools/generate_info.sh
79-
sed -i'.original' -e 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.5.3\/macos/g' build_dmg.sh
79+
sed -i'.original' -e 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.8.1\/macos/g' build_dmg.sh
8080
sed -i'.original' -e 's/LIBSSH2_DIR=\/libssh2/LIBSSH2_DIR=\/usr\/local\/output/g' ./lib/qtssh/qtssh.pri
8181
mkdir prebuilt_plugins
8282
python3 ./.github/scripts/get_plugin.py ./.github/scripts/plugin_list.json ./prebuilt_plugins

.github/workflows/windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ jobs:
5050
uses: jurplel/install-qt-action@v4
5151
with:
5252
arch: win64_mingw
53-
version: '6.5.3'
53+
version: '6.8.1'
5454
modules: 'qtwebsockets qtserialport qtmultimedia'
55-
aqtversion: ==3.1.7
55+
aqtversion: '==3.1.19'
5656

5757
- name: Install cmake
5858
uses: crazy-max/ghaction-chocolatey@v3

.github/workflows/windows_msvc.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ on:
4040
workflow_dispatch:
4141

4242
jobs:
43-
windows_msvc2019:
43+
windows_msvc2022:
4444
runs-on: windows-2022
4545

4646
steps:
@@ -49,10 +49,10 @@ jobs:
4949
- name: Install Qt
5050
uses: jurplel/install-qt-action@v4
5151
with:
52-
arch: 'win64_msvc2019_64'
53-
version: '6.5.3'
52+
arch: 'win64_msvc2022_64'
53+
version: '6.8.1'
5454
modules: 'qtwebsockets qtserialport qtmultimedia'
55-
aqtversion: '==3.1.7'
55+
aqtversion: '==3.1.19'
5656

5757
- name: Install cmake
5858
uses: crazy-max/ghaction-chocolatey@v3
@@ -81,7 +81,7 @@ jobs:
8181
uses: ilammy/msvc-dev-cmd@v1
8282
with:
8383
arch: x64
84-
toolset: 14.29
84+
toolset: 14.37
8585

8686
- name: Install libssh2
8787
run: |
@@ -111,7 +111,7 @@ jobs:
111111
- name: Upload build asserts
112112
uses: actions/upload-artifact@v4
113113
with:
114-
name: quardCRT_windows_msvc2019
114+
name: quardCRT_windows_msvc2022
115115
path: |
116116
./output/*.exe
117117

depend/build_fcitx_qt6_linux.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ set -e
33

44
# ubuntu20.04 need install
55
# sudo apt install fcitx-libs-dev qtbase5-private-dev libxkbcommon-dev extra-cmake-modules
6-
# export PATH="~/Qt/6.5.3/gcc_64/bin":$PATH
6+
# export PATH="~/Qt/6.8.1/gcc_64/bin":$PATH
77
# export PATH="~/Qt/Tools/CMake/bin":$PATH
8-
# export Qt6GuiTools_DIR=/home/qqm/Qt/6.5.3/gcc_64
8+
# export Qt6GuiTools_DIR=/home/qqm/Qt/6.8.1/gcc_64
99
SHELL_FOLDER=$(cd "$(dirname "$0")";pwd)
1010
tar -xzvf fcitx-qt5-1.2.7.tar.gz
1111
cd $SHELL_FOLDER/fcitx-qt5-1.2.7

lib/QGoodWindow/QGoodWindow/src/qgoodwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ void QGoodWindow::setup()
657657
#endif
658658

659659
#ifdef Q_OS_LINUX
660-
qputenv("XDG_SESSION_TYPE", "xcb");
660+
qputenv("XDG_SESSION_TYPE", "x11");
661661
qputenv("QT_QPA_PLATFORM", "xcb");
662662

663663
int argc = 0;

src/mainwindow.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ CentralWidget::CentralWidget(QString dir, StartupUIMode mode, QLocale lang, bool
9090
pyRun = new PyRun(this);
9191
#endif
9292

93+
m_mediaCaptureSession = new QMediaCaptureSession(this);
94+
m_windowCapture = new QWindowCapture(this);
95+
m_mediaRecorder = new QMediaRecorder(this);
96+
m_mediaCaptureSession->setWindowCapture(m_windowCapture);
97+
m_mediaCaptureSession->setRecorder(m_mediaRecorder);
98+
m_mediaRecorder->setQuality(QMediaRecorder::HighQuality);
99+
93100
splitter = new QSplitter(Qt::Horizontal,this);
94101
splitter->setHandleWidth(1);
95102
ui->centralwidget->layout()->addWidget(splitter);
@@ -1710,6 +1717,9 @@ void CentralWidget::menuAndToolBarRetranslateUi(void) {
17101717
screenShotAction->setIcon(QFontIcon::icon(QChar(0xf03e)));
17111718
screenShotAction->setStatusTip(tr("Screen shot current screen <Alt+P>"));
17121719
screenShotAction->setShortcut(QKeySequence(Qt::ALT|Qt::Key_P));
1720+
screenCapturableAction->setText(tr("Screen Capturable"));
1721+
screenCapturableAction->setStatusTip(tr("Screen capturable current screen"));
1722+
screenCapturableAction->setShortcut(QKeySequence(Qt::ALT|Qt::Key_G));
17131723
sessionExportAction->setText(tr("Session Export"));
17141724
sessionExportAction->setIcon(QFontIcon::icon(QChar(0xf093)));
17151725
sessionExportAction->setStatusTip(tr("Export current session to a file <Alt+O>"));
@@ -2035,6 +2045,9 @@ void CentralWidget::menuAndToolBarInit(bool disable_plugin) {
20352045
ui->toolBar->addAction(printScreenAction);
20362046
screenShotAction = new QAction(this);
20372047
editMenu->addAction(screenShotAction);
2048+
screenCapturableAction = new QAction(this);
2049+
screenCapturableAction->setCheckable(true);
2050+
editMenu->addAction(screenCapturableAction);
20382051
sessionExportAction = new QAction(this);
20392052
editMenu->addAction(sessionExportAction);
20402053
editMenu->addSeparator();
@@ -2604,6 +2617,7 @@ void CentralWidget::setSessionClassActionEnable(bool enable)
26042617
findAction->setEnabled(enable);
26052618
printScreenAction->setEnabled(enable);
26062619
screenShotAction->setEnabled(enable);
2620+
screenCapturableAction->setEnabled(enable);
26072621
sessionExportAction->setEnabled(enable);
26082622
clearScrollbackAction->setEnabled(enable);
26092623
clearScreenAction->setEnabled(enable);
@@ -2928,6 +2942,48 @@ void CentralWidget::menuAndToolBarConnectSignals(void) {
29282942
settings.setValue("Global/Options/ScreenShotPath",QFileInfo(fileName).absolutePath());
29292943
ui->statusBar->showMessage(tr("Screenshot saved to %1").arg(fileName),3000);
29302944
});
2945+
connect(screenCapturableAction,&QAction::triggered,this,[=](){
2946+
if(!screenCapturableAction->isChecked()) {
2947+
m_mediaRecorder->stop();
2948+
m_windowCapture->stop();
2949+
ui->statusBar->showMessage(tr("ScreenCapturable stop."),3000);
2950+
} else {
2951+
QWidget *widget = findCurrentFocusWidget();
2952+
if(widget == nullptr) return;
2953+
2954+
QList<QCapturableWindow> windowList = QWindowCapture::capturableWindows();
2955+
bool find = false;
2956+
foreach(const QCapturableWindow &w, windowList) {
2957+
auto handle = QCapturableWindowPrivate::handle(w);
2958+
if(handle && handle->id == this->mainWindow->winId()) {
2959+
m_windowCapture->setWindow(w);
2960+
find = true;
2961+
break;
2962+
}
2963+
}
2964+
if(!find) {
2965+
screenCapturableAction->setChecked(false);
2966+
return;
2967+
}
2968+
2969+
GlobalSetting settings;
2970+
QString screenCapturablePath = settings.value("Global/Options/ScreenCapturablePath",QDir::homePath()).toString();
2971+
QString willsaveName = screenCapturablePath + "/quartCRT-" + QDateTime::currentDateTime().toString("yyyyMMddhhmmss") + ".mp4";
2972+
QString fileName = FileDialog::getSaveFileName(this,tr("Save Screenshot"),willsaveName,tr("Video Files (*.mp4)"));
2973+
if(fileName.isEmpty()) {
2974+
screenCapturableAction->setChecked(false);
2975+
return;
2976+
}
2977+
if(!fileName.endsWith(".mp4")) fileName.append(".mp4");
2978+
2979+
m_mediaRecorder->setOutputLocation(QUrl::fromLocalFile(fileName));
2980+
m_windowCapture->start();
2981+
m_mediaRecorder->record();
2982+
2983+
settings.setValue("Global/Options/ScreenCapturablePath",QFileInfo(fileName).absolutePath());
2984+
ui->statusBar->showMessage(tr("ScreenCapturable saved to %1").arg(fileName),3000);
2985+
}
2986+
});
29312987
connect(sessionExportAction,&QAction::triggered,this,[=](){
29322988
QWidget *widget = findCurrentFocusWidget();
29332989
if(widget == nullptr) return;

src/mainwindow.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#include <QStatusTipEvent>
3535
#include <QFontMetrics>
3636
#include <QDateTime>
37+
#include <QMediaCaptureSession>
38+
#include <QWindowCapture>
39+
#include <QMediaRecorder>
3740

3841
#include "mainwidgetgroup.h"
3942
#include "sessiontab.h"
@@ -337,6 +340,7 @@ private slots:
337340
QAction *findAction;
338341
QAction *printScreenAction;
339342
QAction *screenShotAction;
343+
QAction *screenCapturableAction;
340344
QAction *sessionExportAction;
341345
QAction *clearScrollbackAction;
342346
QAction *clearScreenAction;
@@ -443,6 +447,10 @@ private slots:
443447
QShortcut *shortcutConnectAddressEdit;
444448
QShortcut *shortcutExitFullScreen;
445449

450+
QMediaCaptureSession *m_mediaCaptureSession;
451+
QWindowCapture *m_windowCapture;
452+
QMediaRecorder *m_mediaRecorder;
453+
446454
QLabel *statusBarMessage;
447455
StatusBarWidget *statusBarWidget;
448456
QTimer *statusBarWidgetRefreshTimer;
@@ -529,4 +537,19 @@ class MainWindow : public QGoodWindow
529537
CentralWidget *m_central_widget;
530538
};
531539

540+
class QCapturableWindowPrivate : public QSharedData {
541+
public:
542+
using Id = size_t;
543+
544+
QString description;
545+
Id id = 0;
546+
547+
static const QCapturableWindowPrivate *handle(const QCapturableWindow &window)
548+
{
549+
return window.d.get();
550+
}
551+
552+
QCapturableWindow create() { return QCapturableWindow(this); }
553+
};
554+
532555
#endif // MAINWINDOW_H

0 commit comments

Comments
 (0)