mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-08-08 06:46:53 +02:00
Add an option to choose which screen to use for full screen mode
This commit is contained in:
parent
4fff634d50
commit
8884988336
4 changed files with 200 additions and 17 deletions
|
@ -481,6 +481,106 @@ Item {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Layout.topMargin: 20
|
||||
Layout.preferredWidth: parent.width
|
||||
spacing: 0
|
||||
|
||||
Item {
|
||||
Layout.preferredWidth: parent.width
|
||||
Layout.preferredHeight: 35
|
||||
|
||||
HifiStylesUit.RalewayRegular {
|
||||
id: fullScreenDisplayHeader
|
||||
text: "Full screen display"
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
width: 130
|
||||
height: parent.height
|
||||
size: 16
|
||||
color: "#FFFFFF"
|
||||
}
|
||||
|
||||
ListModel {
|
||||
id: fullScreenDisplayModel
|
||||
|
||||
ListElement {
|
||||
text: "Screen 1"
|
||||
}
|
||||
|
||||
function refreshScreens() {
|
||||
fullScreenDisplayModel.clear();
|
||||
Render.getScreens().forEach(function(screen) {
|
||||
fullScreenDisplayModel.append({"text" : screen});
|
||||
});
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
fullScreenDisplayModel.refreshScreens();
|
||||
}
|
||||
}
|
||||
|
||||
HifiControlsUit.ComboBox {
|
||||
id: fullScreenDisplayDropdown
|
||||
anchors.left: fullScreenDisplayHeader.right
|
||||
anchors.leftMargin: 20
|
||||
anchors.top: parent.top
|
||||
width: 280
|
||||
height: parent.height
|
||||
colorScheme: hifi.colorSchemes.dark
|
||||
model: fullScreenDisplayModel
|
||||
currentIndex: 0
|
||||
|
||||
function refreshFullScreenDisplayDropdown() {
|
||||
var screens = Render.getScreens();
|
||||
var selected = Render.getFullScreenScreen();
|
||||
|
||||
for(let idx = 0; idx < screens.length; idx++) {
|
||||
if (screens[idx] == selected) {
|
||||
fullScreenDisplayDropdown.currentIndex = idx;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Selected full screen screen", selected, "not found, falling back to primary screen");
|
||||
console.log("List of screens is:", screens);
|
||||
fullScreenDisplayDropdown.currentIndex = 0;
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
model.refreshScreens();
|
||||
fullScreenDisplayDropdown.refreshFullScreenDisplayDropdown();
|
||||
fullScreenDisplayDropdown.displayText = model.get(currentIndex).text;
|
||||
}
|
||||
|
||||
onCurrentIndexChanged: {
|
||||
if (currentIndex >= 0) {
|
||||
// Somehow, we end up going through here twice on every change of the combo box.
|
||||
// The first one is with the new selected index, and the second one is with the
|
||||
// index at -1.
|
||||
//
|
||||
// The first one comes from a sensible stack of:
|
||||
// onCurrentIndexChanged (qrc:/qml/hifi/dialogs/graphics/GraphicsSettings.qml:559)
|
||||
// refreshScreens (qrc:/qml/hifi/dialogs/graphics/GraphicsSettings.qml:514)
|
||||
// onCompleted (qrc:/qml/hifi/dialogs/graphics/GraphicsSettings.qml:553)
|
||||
// load (qrc:/qml/hifi/tablet/WindowRoot.qml:170)
|
||||
// loadSource (qrc:/qml/hifi/tablet/WindowRoot.qml:63)
|
||||
//
|
||||
// The second seems to be called out of nowhere. This likely indicates some sort of bug.
|
||||
// Might be related to Wayland?
|
||||
|
||||
Render.setFullScreenScreen(model.get(currentIndex).text);
|
||||
fullScreenDisplayDropdown.displayText = model.get(currentIndex).text;
|
||||
} else {
|
||||
console.log("Called with currentIndex =", currentIndex);
|
||||
console.trace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "RenderScriptingInterface.h"
|
||||
|
||||
#include "LightingModel.h"
|
||||
#include <QScreen>
|
||||
|
||||
|
||||
RenderScriptingInterface* RenderScriptingInterface::getInstance() {
|
||||
|
@ -31,7 +32,17 @@ void RenderScriptingInterface::loadSettings() {
|
|||
//_antialiasingMode = (_antialiasingModeSetting.get());
|
||||
_antialiasingMode = static_cast<AntialiasingConfig::Mode>(_antialiasingModeSetting.get());
|
||||
_viewportResolutionScale = (_viewportResolutionScaleSetting.get());
|
||||
_fullScreenScreen = (_fullScreenScreenSetting.get());
|
||||
});
|
||||
|
||||
// If full screen screen is not initialized, or set to an invalid value,
|
||||
// set to the first screen.
|
||||
auto screens = getScreens();
|
||||
if (std::find(screens.begin(), screens.end(), _fullScreenScreen) == screens.end()) {
|
||||
setFullScreenScreen(screens.first());
|
||||
}
|
||||
|
||||
|
||||
forceRenderMethod((RenderMethod)_renderMethod);
|
||||
forceShadowsEnabled(_shadowsEnabled);
|
||||
forceAmbientOcclusionEnabled(_ambientOcclusionEnabled);
|
||||
|
@ -193,6 +204,41 @@ void RenderScriptingInterface::setViewportResolutionScale(float scale) {
|
|||
}
|
||||
}
|
||||
|
||||
QStringList RenderScriptingInterface::getScreens() const {
|
||||
QStringList screens;
|
||||
|
||||
for(QScreen *screen : qApp->screens()) {
|
||||
screens << screen->model();
|
||||
}
|
||||
|
||||
return screens;
|
||||
}
|
||||
|
||||
bool RenderScriptingInterface::setFullScreenScreen(QString name) {
|
||||
auto screens = getScreens();
|
||||
|
||||
if (std::find(screens.begin(), screens.end(), name) == screens.end()) {
|
||||
// Screens can come and go and don't have a stable opaque ID, so we
|
||||
// go by model here. For multiple screens with the same model we get names
|
||||
// that include a serial number, so it works.
|
||||
return false;
|
||||
}
|
||||
|
||||
_renderSettingLock.withWriteLock([&] {
|
||||
_fullScreenScreen = name;
|
||||
_fullScreenScreenSetting.set(name);
|
||||
});
|
||||
|
||||
emit settingsChanged();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString RenderScriptingInterface::getFullScreenScreen() const {
|
||||
return _fullScreenScreen;
|
||||
}
|
||||
|
||||
|
||||
void RenderScriptingInterface::forceViewportResolutionScale(float scale) {
|
||||
// just not negative values or zero
|
||||
if (scale <= 0.f) {
|
||||
|
|
|
@ -172,6 +172,30 @@ public slots:
|
|||
*/
|
||||
void setViewportResolutionScale(float resolutionScale);
|
||||
|
||||
/*@jsdoc
|
||||
* Returns the list of screens
|
||||
* @function Render.getScreens
|
||||
* @returns {string[]} The names of the available screens
|
||||
*/
|
||||
QStringList getScreens() const;
|
||||
|
||||
/*@jsdoc
|
||||
* Gets the screen used when switching to full screen mode
|
||||
* @function Render.getFullScreenScreen
|
||||
* @returns {string} The name of the screen used for full screen mode
|
||||
*/
|
||||
QString getFullScreenScreen() const;
|
||||
|
||||
/*@jsdoc
|
||||
* Sets the screen used when switching to full screen mode
|
||||
* This function will only succeed if the name passed is one of the entries from Render.getScreens.
|
||||
* Otherwise, it will return False and have no effect.
|
||||
*
|
||||
* @function Render.setFullScreenScreen
|
||||
* @returns {bool} True if the setting was successful
|
||||
*/
|
||||
bool setFullScreenScreen(QString name);
|
||||
|
||||
signals:
|
||||
|
||||
/*@jsdoc
|
||||
|
@ -196,6 +220,8 @@ private:
|
|||
bool _ambientOcclusionEnabled{ false };
|
||||
AntialiasingConfig::Mode _antialiasingMode{ AntialiasingConfig::Mode::NONE };
|
||||
float _viewportResolutionScale{ 1.0f };
|
||||
QString _fullScreenScreen;
|
||||
|
||||
|
||||
// Actual settings saved on disk
|
||||
Setting::Handle<int> _renderMethodSetting { "renderMethod", RENDER_FORWARD ? render::Args::RenderMethod::FORWARD : render::Args::RenderMethod::DEFERRED };
|
||||
|
@ -204,6 +230,7 @@ private:
|
|||
//Setting::Handle<AntialiasingConfig::Mode> _antialiasingModeSetting { "antialiasingMode", AntialiasingConfig::Mode::TAA };
|
||||
Setting::Handle<int> _antialiasingModeSetting { "antialiasingMode", AntialiasingConfig::Mode::NONE };
|
||||
Setting::Handle<float> _viewportResolutionScaleSetting { "viewportResolutionScale", 1.0f };
|
||||
Setting::Handle<QString> _fullScreenScreenSetting { "fullScreenScreen", "" };
|
||||
|
||||
// Force assign both setting AND runtime value to the parameter value
|
||||
void forceRenderMethod(RenderMethod renderMethod);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include <ui-plugins/PluginContainer.h>
|
||||
#include <PathUtils.h>
|
||||
#include "SettingHandle.h"
|
||||
|
||||
const QString Basic2DWindowOpenGLDisplayPlugin::NAME("Desktop");
|
||||
|
||||
|
@ -165,8 +166,17 @@ bool Basic2DWindowOpenGLDisplayPlugin::isThrottled() const {
|
|||
return _isThrottled;
|
||||
}
|
||||
|
||||
// FIXME target the screen the window is currently on
|
||||
QScreen* Basic2DWindowOpenGLDisplayPlugin::getFullscreenTarget() {
|
||||
Setting::Handle<QString> _fullScreenScreenSetting { "fullScreenScreen", "" };
|
||||
QString selectedModel = _fullScreenScreenSetting.get();
|
||||
|
||||
for(QScreen *screen : qApp->screens()) {
|
||||
if (screen->model() == selectedModel) {
|
||||
return screen;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Failed to find selected screen" << selectedModel << "for full screen mode, using primary screen";
|
||||
return qApp->primaryScreen();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue