diff --git a/docs/README.md b/docs/README.md index 84f446d9..195d81a7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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. diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index 251fc75a..19f9a79a 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -181,6 +181,7 @@ const std::unordered_map RequestHandler::_han {"OpenInputPropertiesDialog", &RequestHandler::OpenInputPropertiesDialog}, {"OpenInputFiltersDialog", &RequestHandler::OpenInputFiltersDialog}, {"OpenInputInteractDialog", &RequestHandler::OpenInputInteractDialog}, + {"GetMonitorList", &RequestHandler::GetMonitorList}, }; RequestHandler::RequestHandler(SessionPtr session) : diff --git a/src/requesthandler/RequestHandler.h b/src/requesthandler/RequestHandler.h index e0c77160..8df1e9e5 100644 --- a/src/requesthandler/RequestHandler.h +++ b/src/requesthandler/RequestHandler.h @@ -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 _handlerMap; diff --git a/src/requesthandler/RequestHandler_Ui.cpp b/src/requesthandler/RequestHandler_Ui.cpp index 12fa5d04..7aa2e277 100644 --- a/src/requesthandler/RequestHandler_Ui.cpp +++ b/src/requesthandler/RequestHandler_Ui.cpp @@ -17,6 +17,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ +#include +#include +#include +#include + #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 | 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 monitorsData; + QList 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); +}