forked from alexflint/gallium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request alexflint#38 from alexflint/screens
add screen API
- Loading branch information
Showing
10 changed files
with
210 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef GALLIUM_EXPORT_H_ | ||
#define GALLIUM_EXPORT_H_ | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define GALLIUM_EXPORT __attribute__ ((visibility ("default"))) | ||
|
||
// gallium_error represents an error | ||
typedef struct GALLIUM_EXPORT gallium_error { | ||
const char* msg; | ||
} gallium_error_t; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // ifndef GALLIUM_EXPORT_H_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef GALLIUM_RECT_H_ | ||
#define GALLIUM_RECT_H_ | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct GALLIUM_EXPORT { | ||
int width; | ||
int height; | ||
int left; | ||
int bottom; | ||
} gallium_rect_t; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // ifndef GALLIUM_RECT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef GALLIUM_SCREEN_H_ | ||
#define GALLIUM_SCREEN_H_ | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
#include "gallium/export.h" | ||
#include "gallium/rect.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct GALLIUM_EXPORT gallium_screen gallium_screen_t; | ||
|
||
// GalliumScreenCount gets the number of screens | ||
GALLIUM_EXPORT int GalliumScreenCount(); | ||
|
||
// GalliumScreen gets the i-th screen | ||
GALLIUM_EXPORT gallium_screen_t* GalliumScreen(int index); | ||
|
||
// GalliumFocusedScreen gets the screen containing the currently focussed window. | ||
GALLIUM_EXPORT gallium_screen_t* GalliumFocusedScreen(); | ||
|
||
// GalliumScreenShape gets the shape of a screen | ||
GALLIUM_EXPORT gallium_rect_t GalliumScreenShape(gallium_screen_t*); | ||
|
||
// GalliumScreenShape gets the usable area of a screen (excludes dock and menubar) | ||
GALLIUM_EXPORT gallium_rect_t GalliumScreenUsable(gallium_screen_t*); | ||
|
||
// GalliumScreenBitsPerPixel gets the bits per pixels for a screen | ||
GALLIUM_EXPORT int GalliumScreenBitsPerPixel(gallium_screen_t*); | ||
|
||
// GalliumScreenID gets the unique ID for a screen | ||
GALLIUM_EXPORT int GalliumScreenID(gallium_screen_t*); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // ifndef GALLIUM_SCREEN_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"runtime" | ||
|
||
"github.com/alexflint/gallium" | ||
"github.com/kr/pretty" | ||
) | ||
|
||
func onReady(app *gallium.App) { | ||
pretty.Println(gallium.FocusedScreen()) | ||
pretty.Println(gallium.Screens()) | ||
} | ||
|
||
func main() { | ||
runtime.LockOSThread() | ||
gallium.RedirectStdoutStderr(os.ExpandEnv("$HOME/Library/Logs/Gallium.log")) | ||
gallium.Loop(os.Args, onReady) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gallium | ||
|
||
/* | ||
#cgo CFLAGS: -mmacosx-version-min=10.8 | ||
#cgo CFLAGS: -DGALLIUM_DIR=${SRCDIR} | ||
#cgo CFLAGS: -Idist/include | ||
#include <stdlib.h> | ||
#include "gallium/rect.h" | ||
*/ | ||
import "C" | ||
|
||
// Rect represents a rectangular region on the screen | ||
type Rect struct { | ||
Width int // Width in pixels | ||
Height int // Height in pixels | ||
Left int // Left is offset from left in pixel | ||
Bottom int // Left is offset from top in pixels | ||
} | ||
|
||
func rectFromC(c C.gallium_rect_t) Rect { | ||
return Rect{ | ||
Width: int(c.width), | ||
Height: int(c.height), | ||
Left: int(c.left), | ||
Bottom: int(c.bottom), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} |