mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-31 06:13:55 +00:00
Merge pull request #459 from go-vgo/bitmap-pr
Add GetMainId and IsMain function support
This commit is contained in:
commit
1fac32d382
@ -215,6 +215,11 @@ func GetMouseColor(displayId ...int) string {
|
||||
return GetPixelColor(x, y, displayId...)
|
||||
}
|
||||
|
||||
// IsMain is main display
|
||||
func IsMain(displayId int) bool {
|
||||
return displayId == GetMainId()
|
||||
}
|
||||
|
||||
func displayIdx(id ...int) int {
|
||||
display := -1
|
||||
if DisplayID != -1 {
|
||||
|
24
robotgo_mac.go
Normal file
24
robotgo_mac.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//go:build darwin
|
||||
// +build darwin
|
||||
|
||||
package robotgo
|
||||
|
||||
/*
|
||||
#include <CoreGraphics/CoreGraphics.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// GetMianId get the main display id
|
||||
func GetMainId() int {
|
||||
return int(C.CGMainDisplayID())
|
||||
}
|
@ -42,8 +42,8 @@ func SendMsg(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uintptr {
|
||||
return win.SendMessage(hwnd, msg, wParam, lParam)
|
||||
}
|
||||
|
||||
// SetActiveWindow set window active with hwnd
|
||||
func SetActiveWindow(hwnd win.HWND) win.HWND {
|
||||
// SetActive set window active with hwnd
|
||||
func SetActive(hwnd win.HWND) win.HWND {
|
||||
return win.SetActiveWindow(hwnd)
|
||||
}
|
||||
|
||||
@ -52,6 +52,16 @@ func SetFocus(hwnd win.HWND) win.HWND {
|
||||
return win.SetFocus(hwnd)
|
||||
}
|
||||
|
||||
// GetMian get the main display hwnd
|
||||
func GetMain() win.HWND {
|
||||
return win.GetActiveWindow()
|
||||
}
|
||||
|
||||
// GetMianId get the main display id
|
||||
func GetMainId() int {
|
||||
return int(GetMain())
|
||||
}
|
||||
|
||||
// ScaleF get the system scale val
|
||||
func ScaleF(displayId ...int) (f float64) {
|
||||
if len(displayId) > 0 && displayId[0] != -1 {
|
||||
|
@ -191,6 +191,25 @@ func DisplaysNum() int {
|
||||
return int(reply.Number)
|
||||
}
|
||||
|
||||
// GetMianId get the main display id
|
||||
func GetMainId() int {
|
||||
conn, err := xgb.NewConn()
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
setup := xproto.Setup(conn)
|
||||
defaultScreen := setup.DefaultScreen(conn)
|
||||
id := -1
|
||||
for i, screen := range setup.Roots {
|
||||
if defaultScreen.Root == screen.Root {
|
||||
id = i
|
||||
break
|
||||
}
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Alert show a alert window
|
||||
// Displays alert with the attributes.
|
||||
// If cancel button is not given, only the default button is displayed
|
||||
|
Loading…
Reference in New Issue
Block a user