Skip to content

Commit 8b944e5

Browse files
committed
Detect primary monitor on windows
1 parent 9d42a34 commit 8b944e5

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/api/screen/desktop_capture_monitor.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include "ui/gfx/image/image.h"
3737
#include "ui/gfx/image/image_skia.h"
3838

39+
#ifdef _WIN32
40+
#include <windows.h>
41+
#endif
3942

4043
namespace nwapi {
4144

@@ -47,6 +50,25 @@ DesktopCaptureMonitor::DesktopCaptureMonitor(int id,
4750

4851
DesktopCaptureMonitor::~DesktopCaptureMonitor() {}
4952

53+
int DesktopCaptureMonitor::GetPrimaryMonitorIndex(){
54+
#ifdef _WIN32
55+
int count=0;
56+
for (int i = 0;; ++i) {
57+
DISPLAY_DEVICE device;
58+
device.cb = sizeof(device);
59+
BOOL ret = EnumDisplayDevices(NULL, i, &device, 0);
60+
if(!ret)
61+
break;
62+
if (device.StateFlags & DISPLAY_DEVICE_ACTIVE){
63+
if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE){
64+
return count;
65+
}
66+
count++;
67+
}
68+
}
69+
#endif
70+
return -1;
71+
}
5072

5173
void DesktopCaptureMonitor::CallSync(const std::string& method, const base::ListValue& arguments, base::ListValue* result){
5274
if (method == "start") {
@@ -99,6 +121,9 @@ void DesktopCaptureMonitor::OnSourceAdded(int index){
99121
param.AppendString(src.name);
100122
param.AppendInteger(index);
101123
param.AppendString(type);
124+
if(src.id.type == content::DesktopMediaID::TYPE_SCREEN){
125+
param.AppendBoolean(GetPrimaryMonitorIndex()==index);
126+
}
102127
this->dispatcher_host()->SendEvent(this, "__nw_desktop_capture_monitor_listner_added", param);
103128
}
104129
void DesktopCaptureMonitor::OnSourceRemoved(int index){

src/api/screen/desktop_capture_monitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace nwapi {
4040
private:
4141
DesktopCaptureMonitor();
4242
DISALLOW_COPY_AND_ASSIGN(DesktopCaptureMonitor);
43+
int GetPrimaryMonitorIndex();
4344
void Start(bool screens, bool windows);
4445
void Stop();
4546

src/api/screen/screen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ DesktopCaptureMonitor.prototype.stop = function () {
4343
return true;
4444
}
4545

46-
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_added', function (id, name, order, type) {
46+
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_added', function (id, name, order, type, primaryindex) {
4747
if(this.sources.indexOf(id)!=-1)
4848
{
4949
//TODO: Find out what this event comes twice on some platforms
5050
return;
5151
}
5252
this.sources.splice(order, 0, id);
53-
this.emit("added", id, name, order, type);
53+
this.emit("added", id, name, order, type, primaryindex);
5454
for (var i = order + 1; i <= this.sources.length - 1; i++) {
5555
this.emit("orderchanged", this.sources[i], i, i - 1);
5656
}

0 commit comments

Comments
 (0)