mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-30 22:13:54 +00:00
add get DisplaysNum support
This commit is contained in:
parent
ce0972d699
commit
a860bbcff9
@ -239,6 +239,10 @@ func displayIdx(id ...int) int {
|
||||
return display
|
||||
}
|
||||
|
||||
func getNumDisplays() int {
|
||||
return int(C.get_num_displays())
|
||||
}
|
||||
|
||||
// SysScale get the sys scale
|
||||
func SysScale(displayId ...int) float64 {
|
||||
display := displayIdx(displayId...)
|
||||
|
@ -50,3 +50,8 @@ func ActivePID(pid int32, args ...int) error {
|
||||
internalActive(pid, hwnd)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DisplaysNum get the count of displays
|
||||
func DisplaysNum() int {
|
||||
return getNumDisplays()
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
"github.com/robotn/xgb/xinerama"
|
||||
"github.com/robotn/xgb/xproto"
|
||||
"github.com/robotn/xgbutil"
|
||||
"github.com/robotn/xgbutil/ewmh"
|
||||
@ -149,3 +150,24 @@ func GetXidFromPid(xu *xgbutil.XUtil, pid int32) (xproto.Window, error) {
|
||||
|
||||
return 0, errors.New("failed to find a window with a matching pid.")
|
||||
}
|
||||
|
||||
// DisplaysNum get the count of displays
|
||||
func DisplaysNum() int {
|
||||
c, err := xgb.NewConn()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
err = xinerama.Init(c)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
reply, err := xinerama.QueryScreens(c).Reply()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return int(reply.Number)
|
||||
}
|
||||
|
@ -96,6 +96,33 @@ char* get_XDisplay_name(){
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(IS_WINDOWS)
|
||||
bool CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
|
||||
uint32_t *count = (uint32_t*)dwData;
|
||||
(*count)++;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t get_num_displays() {
|
||||
#if defined(IS_MACOSX)
|
||||
uint32_t count = 0;
|
||||
if (CGGetActiveDisplayList(0, nil, &count) == kCGErrorSuccess) {
|
||||
return count;
|
||||
}
|
||||
return 0;
|
||||
#elif defined(USE_X11)
|
||||
return 0;
|
||||
#elif defined(IS_WINDOWS)
|
||||
uint32_t count = 0;
|
||||
if (EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM)&count)) {
|
||||
return count;
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void bitmap_dealloc(MMBitmapRef bitmap){
|
||||
if (bitmap != NULL) {
|
||||
destroyMMBitmap(bitmap);
|
||||
|
Loading…
Reference in New Issue
Block a user