-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathscreen.go
58 lines (52 loc) · 1.78 KB
/
screen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package gallium
/*
#cgo CFLAGS: -mmacosx-version-min=10.8
#cgo CFLAGS: -DGALLIUM_DIR=${SRCDIR}
#cgo CFLAGS: -Idist/include
#include <stdlib.h>
#include "gallium/screen.h"
*/
import "C"
import "fmt"
// A screen represents a rectangular display, normally corresponding to a
// physical display. "Device coordinates" means a position on a screen
// measured from (0, 0) at the bottom left of the device. "Global coordinates"
// means the coordinate system in which each of the screens are positioned
// relative to each other. Global and device coordinates almost always have
// the same scale factor. It is possible for screens to overlap in global
// coordinates (such as when mirroring a display.)
type Screen struct {
Shape Rect // the size and position of this screen in global coords
Usable Rect // excludes the menubar and dock
BitsPerPixel int // color depth of this screen (total of all color components)
ID int // unique identifier for this screen
}
func screenFromC(c *C.gallium_screen_t) Screen {
return Screen{
Shape: rectFromC(C.GalliumScreenShape(c)),
Usable: rectFromC(C.GalliumScreenUsable(c)),
BitsPerPixel: int(C.GalliumScreenBitsPerPixel(c)),
ID: int(C.GalliumScreenID(c)),
}
}
// Screens gets a list of available screens
func Screens() []Screen {
var screens []Screen
n := int(C.GalliumScreenCount())
for i := 0; i < n; i++ {
c := C.GalliumScreen(C.int(i))
if c == nil {
panic(fmt.Sprintf("GalliumScreen returned nil for index %d", i))
}
screens = append(screens, screenFromC(c))
}
return screens
}
// FocusedScreen gets the screen containing the currently focused window
func FocusedScreen() Screen {
c := C.GalliumFocusedScreen()
if c == nil {
panic("GalliumFocusedScreen returned nil")
}
return screenFromC(c)
}