Răsfoiți Sursa

Launcher: use QDesktopWidget to get display list instead of SDL2

First of all SDL2 trying to use dbus and this conflict with Qt. Check mantis#2704.
And there no reason to use SDL2 in launcher when Qt can do the same thing as well.
Arseniy Shestakov 8 ani în urmă
părinte
comite
1110dd27d1

+ 1 - 4
launcher/CMakeLists.txt

@@ -2,7 +2,6 @@
 # https://doc.qt.io/qt-5/cmake-manual.html
 include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIR})
 include_directories(${ZLIB_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS})
-include_directories(${SDL2_INCLUDE_DIR})
 
 set(launcher_modmanager_SRCS
 		modManager/cdownloadmanager_moc.cpp
@@ -38,7 +37,6 @@ set(launcher_SRCS
 		mainwindow_moc.cpp
 		launcherdirs.cpp
 		jsonutils.cpp
-		sdldisplayquery.cpp
 )
 
 set(launcher_HEADERS
@@ -48,7 +46,6 @@ set(launcher_HEADERS
 		mainwindow_moc.h
 		launcherdirs.h
 		jsonutils.h
-		sdldisplayquery.h
 )
 
 set(launcher_FORMS
@@ -102,7 +99,7 @@ if(APPLE)
 	set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER vcmilauncher)
 endif()
 
-target_link_libraries(vcmilauncher vcmi Qt5::Widgets Qt5::Network ${SDL2_LIBRARY})
+target_link_libraries(vcmilauncher vcmi Qt5::Widgets Qt5::Network)
 
 vcmi_set_output_dir(vcmilauncher "")
 

+ 1 - 3
launcher/main.cpp

@@ -10,13 +10,11 @@
 #include <QApplication>
 #include "StdInc.h"
 #include "mainwindow_moc.h"
-#include "sdldisplayquery.h"
 
 int main(int argc, char * argv[])
 {
 	QApplication vcmilauncher(argc, argv);
-	auto displayList = getDisplays();
-	MainWindow mainWindow(displayList);
+	MainWindow mainWindow;
 	mainWindow.show();
 	return vcmilauncher.exec();
 }

+ 2 - 2
launcher/mainwindow_moc.cpp

@@ -39,7 +39,7 @@ void MainWindow::load()
 	settings.init();
 }
 
-MainWindow::MainWindow(const QStringList& displayList, QWidget *parent) :
+MainWindow::MainWindow(QWidget * parent) :
     QMainWindow(parent),
     ui(new Ui::MainWindow)
 {
@@ -62,7 +62,7 @@ MainWindow::MainWindow(const QStringList& displayList, QWidget *parent) :
 		ui->tabSelectList->setMaximumWidth(width + 4);
 	}
 	ui->tabListWidget->setCurrentIndex(0);
-	ui->settingsView->setDisplayList(displayList);
+	ui->settingsView->setDisplayList();
 
 	connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)),
 	        ui->tabListWidget, SLOT(setCurrentIndex(int)));

+ 1 - 1
launcher/mainwindow_moc.h

@@ -25,7 +25,7 @@ private:
 	void load();
 	void startExecutable(QString name);
 public:
-	explicit MainWindow(const QStringList& displayList, QWidget *parent = 0);
+	explicit MainWindow(QWidget * parent = 0);
 	~MainWindow();
 
 private slots:

+ 0 - 42
launcher/sdldisplayquery.cpp

@@ -1,42 +0,0 @@
-/*
- * sdldisplayquery.cpp, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
-#include "StdInc.h"
-#include "sdldisplayquery.h"
-
-#include <QString>
-#include <QTextStream>
-
-#include <SDL.h>
-#include <SDL_video.h>
-
-QStringList getDisplays()
-{
-  if(SDL_Init(SDL_INIT_VIDEO))
-    return QStringList("default display");
-
-  const int displays = SDL_GetNumVideoDisplays();
-  QStringList list;
-
-  for (int display = 0; display < displays; ++display)
-    {
-      SDL_Rect rect;
-
-      if (SDL_GetDisplayBounds (display, &rect))
-	continue;
-
-      QString string;
-      QTextStream(&string) << display << " - " << rect.w << "x" << rect.h << " (at " << rect.x << ", " << rect.y << ")";
-
-      list << string;
-    }
-
-  SDL_Quit();
-  return list;
-}

+ 0 - 14
launcher/sdldisplayquery.h

@@ -1,14 +0,0 @@
-/*
- * sdldisplayquery.h, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
-#pragma once
-
-#include <QStringList>
-
-QStringList getDisplays();

+ 22 - 11
launcher/settingsView/csettingsview_moc.cpp

@@ -29,19 +29,30 @@ static const std::string knownEncodingsList[] = //TODO: remove hardcode
     "GB2312"  // basic set for Simplified Chinese. Separate from GBK to allow proper detection of H3 fonts
 };
 
-void CSettingsView::setDisplayList(const QStringList& displayList)
+void CSettingsView::setDisplayList()
 {
-	if (displayList.count() < 2)
-	  {
-	    ui->comboBoxDisplayIndex->hide ();
-	    ui->labelDisplayIndex->hide ();
-	  }
+	QStringList list;
+	QDesktopWidget * widget = QApplication::desktop();
+	for(int display = 0; display < widget->screenCount(); display++)
+	{
+		QString string;
+		auto rect = widget->screenGeometry(display);
+		QTextStream(&string) << display << " - " << rect.width() << "x" << rect.height();
+		list << string;
+	}
+
+	if(list.count() < 2)
+	{
+		ui->comboBoxDisplayIndex->hide();
+		ui->labelDisplayIndex->hide();
+	}
 	else
-	  {
-	    ui->comboBoxDisplayIndex->clear();
-	    ui->comboBoxDisplayIndex->addItems(displayList);
-	    ui->comboBoxDisplayIndex->setCurrentIndex(settings["video"]["displayIndex"].Float());
-	  }
+	{
+		int displayIndex = settings["video"]["displayIndex"].Integer();
+		ui->comboBoxDisplayIndex->clear();
+		ui->comboBoxDisplayIndex->addItems(list);
+		ui->comboBoxDisplayIndex->setCurrentIndex(displayIndex);
+	}
 }
 
 void CSettingsView::loadSettings()

+ 1 - 1
launcher/settingsView/csettingsview_moc.h

@@ -22,7 +22,7 @@ public:
 	~CSettingsView();
 
 	void loadSettings();
-	void setDisplayList(const QStringList& displayList);
+	void setDisplayList();
 
 private slots:
 	void on_checkBoxFullScreen_stateChanged(int state);