This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement simple X11 screen/window picker
- Loading branch information
Showing
6 changed files
with
111 additions
and
2 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
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,70 @@ | ||
#include "mediapicker.h" | ||
|
||
#include <QBoxLayout> | ||
#include <QLabel> | ||
#include <QListView> | ||
#include <QPushButton> | ||
#include <qicon.h> | ||
|
||
MediaPicker::MediaPicker(const QWebEngineDesktopMediaRequest &request, | ||
QWidget *parent) | ||
: QDialog(parent), m_request(request) { | ||
auto layout = new QVBoxLayout(this); | ||
layout->setSizeConstraint(QLayout::SetFixedSize); | ||
|
||
auto screensLabel = new QLabel("Screens", this); | ||
layout->addWidget(screensLabel); | ||
|
||
auto screensView = new QListView(this); | ||
screensView->setModel(request.screensModel()); | ||
screensView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); | ||
layout->addWidget(screensView); | ||
|
||
auto windowsLabel = new QLabel("Windows", this); | ||
layout->addWidget(windowsLabel); | ||
|
||
auto windowsView = new QListView(this); | ||
windowsView->setModel(request.windowsModel()); | ||
windowsView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); | ||
windowsView->setMaximumWidth(300); | ||
layout->addWidget(windowsView); | ||
|
||
auto startButton = new QPushButton("Start Stream", this); | ||
layout->addWidget(startButton); | ||
|
||
setWindowTitle("discord-screenaudio Media Picker"); | ||
|
||
connect(screensView, &QListView::clicked, | ||
[&, windowsView](const QModelIndex &index) { | ||
m_selectedWindow = false; | ||
m_selectedIndex = index; | ||
windowsView->clearSelection(); | ||
}); | ||
|
||
connect(windowsView, &QListView::clicked, | ||
[&, screensView](const QModelIndex &index) { | ||
m_selectedWindow = true; | ||
m_selectedIndex = index; | ||
screensView->clearSelection(); | ||
}); | ||
|
||
connect(startButton, &QPushButton::clicked, this, &MediaPicker::startStream); | ||
connect(screensView, &QListView::doubleClicked, this, | ||
&MediaPicker::startStream); | ||
connect(windowsView, &QListView::doubleClicked, this, | ||
&MediaPicker::startStream); | ||
} | ||
|
||
void MediaPicker::startStream() { | ||
if (m_selectedWindow) { | ||
m_request.selectWindow(m_selectedIndex); | ||
} else { | ||
m_request.selectScreen(m_selectedIndex); | ||
} | ||
accept(); | ||
} | ||
|
||
void MediaPicker::reject() { | ||
m_request.cancel(); | ||
QDialog::reject(); | ||
} |
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,25 @@ | ||
// SPDX-FileCopyrightText: 2022 Malte Jürgens and contributors | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#pragma once | ||
|
||
#include <QDialog> | ||
#include <QWebEngineDesktopMediaRequest> | ||
|
||
class MediaPicker : public QDialog { | ||
Q_OBJECT | ||
|
||
public: | ||
explicit MediaPicker(const QWebEngineDesktopMediaRequest &request, | ||
QWidget *parent = nullptr); | ||
|
||
private: | ||
bool m_selectedWindow; | ||
QModelIndex m_selectedIndex; | ||
const QWebEngineDesktopMediaRequest &m_request; | ||
|
||
private slots: | ||
void startStream(); | ||
void reject() override; | ||
}; |
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