Merge pull request #441 from go-vgo/bitmap-pr

add get DisplaysNum support
This commit is contained in:
Evans 2022-01-20 13:14:07 -04:00 committed by GitHub
commit 4021a8bb92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 0 deletions

View File

@ -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...)

View File

@ -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()
}

View File

@ -17,6 +17,8 @@ import (
"errors"
"log"
"github.com/robotn/xgb"
"github.com/robotn/xgb/xinerama"
"github.com/robotn/xgb/xproto"
"github.com/robotn/xgbutil"
"github.com/robotn/xgbutil/ewmh"
@ -149,3 +151,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)
}

View File

@ -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);