Skip to content

Commit 4021a8b

Browse files
authored
Merge pull request #441 from go-vgo/bitmap-pr
add get DisplaysNum support
2 parents b81aad6 + 30f4520 commit 4021a8b

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

robotgo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ func displayIdx(id ...int) int {
239239
return display
240240
}
241241

242+
func getNumDisplays() int {
243+
return int(C.get_num_displays())
244+
}
245+
242246
// SysScale get the sys scale
243247
func SysScale(displayId ...int) float64 {
244248
display := displayIdx(displayId...)

robotgo_mac_win.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ func ActivePID(pid int32, args ...int) error {
5050
internalActive(pid, hwnd)
5151
return nil
5252
}
53+
54+
// DisplaysNum get the count of displays
55+
func DisplaysNum() int {
56+
return getNumDisplays()
57+
}

robotgo_x11.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"errors"
1818
"log"
1919

20+
"github.com/robotn/xgb"
21+
"github.com/robotn/xgb/xinerama"
2022
"github.com/robotn/xgb/xproto"
2123
"github.com/robotn/xgbutil"
2224
"github.com/robotn/xgbutil/ewmh"
@@ -149,3 +151,24 @@ func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
149151

150152
return 0, errors.New("failed to find a window with a matching pid.")
151153
}
154+
155+
// DisplaysNum get the count of displays
156+
func DisplaysNum() int {
157+
c, err := xgb.NewConn()
158+
if err != nil {
159+
return 0
160+
}
161+
defer c.Close()
162+
163+
err = xinerama.Init(c)
164+
if err != nil {
165+
return 0
166+
}
167+
168+
reply, err := xinerama.QueryScreens(c).Reply()
169+
if err != nil {
170+
return 0
171+
}
172+
173+
return int(reply.Number)
174+
}

screen/goScreen.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,33 @@ char* get_XDisplay_name(){
9696
#endif
9797
}
9898

99+
#if defined(IS_WINDOWS)
100+
bool CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
101+
uint32_t *count = (uint32_t*)dwData;
102+
(*count)++;
103+
return true;
104+
}
105+
#endif
106+
107+
uint32_t get_num_displays() {
108+
#if defined(IS_MACOSX)
109+
uint32_t count = 0;
110+
if (CGGetActiveDisplayList(0, nil, &count) == kCGErrorSuccess) {
111+
return count;
112+
}
113+
return 0;
114+
#elif defined(USE_X11)
115+
return 0;
116+
#elif defined(IS_WINDOWS)
117+
uint32_t count = 0;
118+
if (EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM)&count)) {
119+
return count;
120+
}
121+
return 0;
122+
#endif
123+
}
124+
125+
99126
void bitmap_dealloc(MMBitmapRef bitmap){
100127
if (bitmap != NULL) {
101128
destroyMMBitmap(bitmap);

0 commit comments

Comments
 (0)