mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Requests: Add GetMonitorList
Adds a new request `GetMonitorList` that returns a json Array of objects containing data about connected monitors. See #868
This commit is contained in:
parent
371c414281
commit
2479501879
@ -1,6 +1,6 @@
|
|||||||
# obs-websocket documentation
|
# 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.
|
- `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/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.
|
- `docs/generate_md.py`: Processes `generated/protocol.json` to create `generated/protocol.md`, which is the actual human-readable documentation.
|
||||||
|
@ -181,6 +181,7 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
|
|||||||
{"OpenInputPropertiesDialog", &RequestHandler::OpenInputPropertiesDialog},
|
{"OpenInputPropertiesDialog", &RequestHandler::OpenInputPropertiesDialog},
|
||||||
{"OpenInputFiltersDialog", &RequestHandler::OpenInputFiltersDialog},
|
{"OpenInputFiltersDialog", &RequestHandler::OpenInputFiltersDialog},
|
||||||
{"OpenInputInteractDialog", &RequestHandler::OpenInputInteractDialog},
|
{"OpenInputInteractDialog", &RequestHandler::OpenInputInteractDialog},
|
||||||
|
{"GetMonitorList", &RequestHandler::GetMonitorList},
|
||||||
};
|
};
|
||||||
|
|
||||||
RequestHandler::RequestHandler(SessionPtr session) :
|
RequestHandler::RequestHandler(SessionPtr session) :
|
||||||
|
@ -199,6 +199,7 @@ class RequestHandler {
|
|||||||
RequestResult OpenInputPropertiesDialog(const Request&);
|
RequestResult OpenInputPropertiesDialog(const Request&);
|
||||||
RequestResult OpenInputFiltersDialog(const Request&);
|
RequestResult OpenInputFiltersDialog(const Request&);
|
||||||
RequestResult OpenInputInteractDialog(const Request&);
|
RequestResult OpenInputInteractDialog(const Request&);
|
||||||
|
RequestResult GetMonitorList(const Request&);
|
||||||
|
|
||||||
SessionPtr _session;
|
SessionPtr _session;
|
||||||
static const std::unordered_map<std::string, RequestMethodHandler> _handlerMap;
|
static const std::unordered_map<std::string, RequestMethodHandler> _handlerMap;
|
||||||
|
@ -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/>
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QScreen>
|
||||||
|
#include <QRect>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "RequestHandler.h"
|
#include "RequestHandler.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,3 +153,39 @@ RequestResult RequestHandler::OpenInputInteractDialog(const Request& request)
|
|||||||
|
|
||||||
return RequestResult::Success();
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user