Merge pull request #889 from csunday95/feature-csunday95-get-screen-info

Requests: Add GetMonitorList
This commit is contained in:
tt2468 2022-04-25 20:25:37 -07:00 committed by GitHub
commit f42cd2177a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# obs-websocket documentation
This is the documentation for obs-websocket. Run build_docs.sh to auto generate the latest docs from the `src` directory. There are 3 components to the docs generation:
This is the documentation for obs-websocket. Run `build_docs.sh` to auto generate the latest docs from the `src` directory. There are 3 components to the docs generation:
- `comments/comments.js`: Generates the `work/comments.json` file from the code comments in the src directory.
- `docs/process_comments.py`: Processes `work/comments.json` to create `generated/protocol.json`, which is a machine-readable documentation format that can be used to create obs-websocket client libraries.
- `docs/generate_md.py`: Processes `generated/protocol.json` to create `generated/protocol.md`, which is the actual human-readable documentation.

View File

@ -181,6 +181,7 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
{"OpenInputPropertiesDialog", &RequestHandler::OpenInputPropertiesDialog},
{"OpenInputFiltersDialog", &RequestHandler::OpenInputFiltersDialog},
{"OpenInputInteractDialog", &RequestHandler::OpenInputInteractDialog},
{"GetMonitorList", &RequestHandler::GetMonitorList},
};
RequestHandler::RequestHandler(SessionPtr session) :

View File

@ -199,6 +199,7 @@ class RequestHandler {
RequestResult OpenInputPropertiesDialog(const Request&);
RequestResult OpenInputFiltersDialog(const Request&);
RequestResult OpenInputInteractDialog(const Request&);
RequestResult GetMonitorList(const Request&);
SessionPtr _session;
static const std::unordered_map<std::string, RequestMethodHandler> _handlerMap;

View File

@ -17,6 +17,11 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <https://www.gnu.org/licenses/>
*/
#include <QGuiApplication>
#include <QScreen>
#include <QRect>
#include <sstream>
#include "RequestHandler.h"
/**
@ -148,3 +153,39 @@ RequestResult RequestHandler::OpenInputInteractDialog(const Request& request)
return RequestResult::Success();
}
/**
* Gets a list of connected monitors and information about them.
*
* @responseField monitors | Array<Object> | a list of detected monitors with some information
*
* @requestType GetMonitorList
* @complexity 2
* @rpcVersion -1
* @initialVersion 5.0.0
* @category ui
* @api requests
*/
RequestResult RequestHandler::GetMonitorList(const Request&)
{
json responseData;
std::vector<json> monitorsData;
QList<QScreen *> screensList = QGuiApplication::screens();
for (int screenIndex = 0; screenIndex < screensList.size(); screenIndex++)
{
json screenData;
QScreen const* screen = screensList[screenIndex];
std::stringstream nameAndIndex;
nameAndIndex << screen->name().toStdString();
nameAndIndex << '(' << screenIndex << ')';
screenData["monitorName"] = nameAndIndex.str();
const QRect screenGeometry = screen->geometry();
screenData["monitorWidth"] = screenGeometry.width();
screenData["monitorHeight"] = screenGeometry.height();
screenData["monitorPositionX"] = screenGeometry.x();
screenData["monitorPositionY"] = screenGeometry.y();
monitorsData.push_back(screenData);
}
responseData["monitors"] = monitorsData;
return RequestResult::Success(responseData);
}