Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hotkeys to allow jumping back and forth between defined apps #1084

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ SOURCES += \
cli/quitstream.cpp \
cli/startstream.cpp \
settings/compatfetcher.cpp \
settings/hotkeymanager.cpp \
settings/mappingfetcher.cpp \
settings/streamingpreferences.cpp \
streaming/input/abstouch.cpp \
Expand All @@ -185,6 +186,7 @@ SOURCES += \
streaming/audio/renderers/sdlaud.cpp \
gui/computermodel.cpp \
gui/appmodel.cpp \
gui/hotkeymodel.cpp \
streaming/streamutils.cpp \
backend/autoupdatechecker.cpp \
path.cpp \
Expand All @@ -199,6 +201,7 @@ HEADERS += \
backend/nvapp.h \
cli/pair.h \
settings/compatfetcher.h \
settings/hotkeymanager.h \
settings/mappingfetcher.h \
utils.h \
backend/computerseeker.h \
Expand All @@ -220,6 +223,7 @@ HEADERS += \
streaming/audio/renderers/sdl.h \
gui/computermodel.h \
gui/appmodel.h \
gui/hotkeymodel.h \
streaming/video/decoder.h \
streaming/streamutils.h \
backend/autoupdatechecker.h \
Expand Down
55 changes: 53 additions & 2 deletions app/backend/computermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,57 @@ QVector<NvComputer*> ComputerManager::getComputers()
return hosts;
}

int ComputerManager::getComputerIndex(QString computerName)
{
QReadLocker lock(&m_Lock);
auto hosts = getComputers();
for (int i = 0; i < hosts.size(); i++) {
if (hosts[i]->name.toLower() == computerName.toLower()) {
return i;
}
}
return -1;
}

NvComputer* ComputerManager::getComputer(QString computerName)
{
QReadLocker lock(&m_Lock);
// NOTE: Does **not** need to be sorted...
auto hosts = m_KnownHosts.values();
for (int i = 0; i < hosts.size(); i++) {
auto host = hosts[i];
if (host->name.toLower() == computerName.toLower()) {
return host;
}
}
return nullptr;
}

bool ComputerManager::getApp(QString computerName, QString appName, NvApp& app)
{
QReadLocker lock(&m_Lock);
auto computer = getComputer(computerName);
if (!computer) {
qDebug() << "getApp: Computer not found: computerName=" << computerName;
return false;
}
return getApp(computer, appName, app);
}

bool ComputerManager::getApp(NvComputer* computer, QString appName, NvApp& app)
{
QReadLocker lock(&m_Lock);
auto appList = computer->appList;
for (int i = 0; i < appList.size(); i++) {
auto& it = appList[i];
if (it.name.toLower() == appName.toLower()) {
app = it;
return true;
}
}
return false;
}

class DeferredHostDeletionTask : public QRunnable
{
public:
Expand Down Expand Up @@ -528,12 +579,12 @@ void ComputerManager::deleteHost(NvComputer* computer)
QThreadPool::globalInstance()->start(new DeferredHostDeletionTask(this, computer));
}

void ComputerManager::renameHost(NvComputer* computer, QString name)
void ComputerManager::renameHost(NvComputer* computer, QString computerName)
{
{
QWriteLocker lock(&computer->lock);

computer->name = name;
computer->name = computerName;
computer->hasCustomName = true;
}

Expand Down
11 changes: 10 additions & 1 deletion app/backend/computermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,19 @@ class ComputerManager : public QObject

QVector<NvComputer*> getComputers();

Q_INVOKABLE int getComputerIndex(QString computerName);

// Used by hotkeymodel to show the computer state
NvComputer* getComputer(QString computerName);

// Used by hotkeymodel to show the app state
bool getApp(QString computerName, QString appName, NvApp& app);
bool getApp(NvComputer* computer, QString appName, NvApp& app);

// computer is deleted inside this call
void deleteHost(NvComputer* computer);

void renameHost(NvComputer* computer, QString name);
void renameHost(NvComputer* computer, QString computerName);

void clientSideAttributeUpdated(NvComputer* computer);

Expand Down
8 changes: 6 additions & 2 deletions app/cli/startstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class LauncherPrivate
m_TimeoutTimer->stop();
if (isNotStreaming() || isStreamingApp(app)) {
m_State = StateStartSession;
session = new Session(m_Computer, app, m_Preferences);
session = new Session(m_Computer, app, m_Preferences, m_HotkeyManager);
emit q->sessionCreated(app.name, session);
} else {
emit q->appQuitRequired(getCurrentAppName());
Expand Down Expand Up @@ -174,6 +174,7 @@ class LauncherPrivate
QString m_ComputerName;
QString m_AppName;
StreamingPreferences *m_Preferences;
HotkeyManager *m_HotkeyManager;
ComputerManager *m_ComputerManager;
ComputerSeeker *m_ComputerSeeker;
NvComputer *m_Computer;
Expand All @@ -182,14 +183,17 @@ class LauncherPrivate
};

Launcher::Launcher(QString computer, QString app,
StreamingPreferences* preferences, QObject *parent)
StreamingPreferences* preferences,
HotkeyManager* hotkeyManager,
QObject *parent)
: QObject(parent),
m_DPtr(new LauncherPrivate(this))
{
Q_D(Launcher);
d->m_ComputerName = computer;
d->m_AppName = app;
d->m_Preferences = preferences;
d->m_HotkeyManager = hotkeyManager;
d->m_State = StateInit;
d->m_TimeoutTimer = new QTimer(this);
d->m_TimeoutTimer->setSingleShot(true);
Expand Down
3 changes: 3 additions & 0 deletions app/cli/startstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <QObject>
#include <QVariant>

#include "settings/hotkeymanager.h"

class ComputerManager;
class NvComputer;
class Session;
Expand All @@ -22,6 +24,7 @@ class Launcher : public QObject
public:
explicit Launcher(QString computer, QString app,
StreamingPreferences* preferences,
HotkeyManager* hotkeyManager,
QObject *parent = nullptr);
~Launcher();
Q_INVOKABLE void execute(ComputerManager *manager);
Expand Down
63 changes: 47 additions & 16 deletions app/gui/AppView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import QtQuick.Controls.Material 2.2
import AppModel 1.0
import ComputerManager 1.0
import SdlGamepadKeyNavigation 1.0
import HotkeyManager 1.0

CenteredGridView {
property int computerIndex
property AppModel appModel : createModel()
property bool activated
property bool showHiddenGames
property AppModel appModel : createAppModel(computerIndex, showHiddenGames)
property bool activated
property bool showGames

id: appGrid
Expand Down Expand Up @@ -61,13 +62,6 @@ CenteredGridView {
activated = false
}

function createModel()
{
var model = Qt.createQmlObject('import AppModel 1.0; AppModel {}', parent, '')
model.initialize(ComputerManager, computerIndex, showHiddenGames)
return model
}

model: appModel

delegate: NavigableItemDelegate {
Expand Down Expand Up @@ -222,13 +216,10 @@ CenteredGridView {
return
}

var component = Qt.createComponent("StreamSegue.qml")
var segue = component.createObject(stackView, {
"appName": model.name,
"session": appModel.createSessionForApp(index),
"isResume": runningId === model.appid
})
stackView.push(segue)
var appName = model.name
var session = appModel.createSessionForApp(index)
var isResume = runningId === model.appid
startStream(appModel, appName, session, isResume)
}

onClicked: {
Expand Down Expand Up @@ -335,7 +326,47 @@ CenteredGridView {
ToolTip.timeout: 5000
ToolTip.visible: hovered
}
NavigableMenuItem {
parentMenu: appContextMenu
text: hotkeyText(appModel, model)
onTriggered: {
hotkeyTriggered(appModel, model)
text = hotkeyText(appModel, model)
}
}
}
}
}

function hotkeyExists(computerName, appName) {
return HotkeyManager.hotkeyNumber(computerName, appName) >= 0
}

function hotkeyText(appModel, model) {
var computerName = appModel.getComputerName()
var appName = model.name
return hotkeyExists(computerName, appName) ? qsTr("Remove Hotkey") : qsTr("Add Hotkey")
}

function hotkeyTriggered(appModel, model) {
var computerName = appModel.getComputerName()
var appName = model.name
var hotkeyNumber = HotkeyManager.hotkeyNumber(computerName, appName)
if (hotkeyNumber >= 0) {
HotkeyManager.remove(hotkeyNumber)
displayToast(qsTr("Hotkey \"%1\" \"%2\" removed").arg(computerName).arg(appName))
} else {
// presented index 0,1,2,3,4,5,6,7,8,9
// keyboard number 1,2,3,4,5,6,7,8,9,0
var hotkeyCount = HotkeyManager.count()
if (hotkeyCount >= 10) {
displayToast(qsTr("Maximum number of hotkeys reached"))
return
}
// Add the next hotkeyNumber
hotkeyNumber = hotkeyCount === 9 ? 0 : hotkeyCount + 1
HotkeyManager.put(hotkeyNumber, computerName, appName)
displayToast(qsTr("Hotkey \"%1\" \"%2\" added").arg(computerName).arg(appName))
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/gui/CenteredGridView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GridView {
property bool hasBrokenMargins: this.synchronousDrag === undefined

property int minMargin: 10
property real availableWidth: (parent.width - 2 * minMargin)
property real availableWidth: parent ? (parent.width - 2 * minMargin) : minMargin
property int itemsPerRow: availableWidth / cellWidth
property real horizontalMargin: itemsPerRow < count && availableWidth >= cellWidth ?
(availableWidth % cellWidth) / 2 : minMargin
Expand Down
Loading