-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
161 lines (121 loc) · 5.4 KB
/
app.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (c) 2018, The GoKi Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// based on golang.org/x/exp/shiny:
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package oswin
import (
"image"
"github.com/goki/gi/oswin/clip"
"github.com/goki/gi/oswin/cursor"
"github.com/goki/ki/kit"
)
// TheApp is the current oswin App -- only ever one in effect
var TheApp App
// App represents the overall OS GUI hardware, and creates Images, Textures
// and Windows, appropriate for that hardware / OS, and maintains data about
// the physical screen(s)
type App interface {
// Platform returns the platform type -- can use this for conditionalizing
// behavior in minor, simple ways
Platform() Platforms
// Name is the overall name of the application -- used for specifying an
// application-specific preferences directory, etc
Name() string
// SetName sets the application name -- defaults to GoGi if not otherwise set
SetName(name string)
// NScreens returns the number of different logical and/or physical
// screens managed under this overall screen hardware
NScreens() int
// Screen returns screen for given screen number, or nil if not a
// valid screen number.
Screen(scrN int) *Screen
// NWindows returns the number of windows open for this app.
NWindows() int
// Window returns given window in list of windows opened under this screen
// -- list is not in any guaranteed order, but typically in order of
// creation (see also WindowByName) -- returns nil for invalid index.
Window(win int) Window
// WindowByName returns given window in list of windows opened under this
// screen, by name -- nil if not found.
WindowByName(name string) Window
// WindowInFocus returns the window currently in focus (receiving keyboard
// input) -- could be nil if none are.
WindowInFocus() Window
// ContextWindow returns the window passed as context for clipboard, cursor, etc calls.
ContextWindow() Window
// NewWindow returns a new Window for this screen. A nil opts is valid and
// means to use the default option values.
NewWindow(opts *NewWindowOptions) (Window, error)
// NewImage returns a new Image for this screen. Images can be drawn upon
// directly using image and other packages, and have an accessible []byte
// slice holding the image data.
NewImage(size image.Point) (Image, error)
// NewTexture returns a new Texture for the given window. Textures are opaque
// and could be non-local, but very fast for rendering to windows --
// typically create a texture of each window and render to that texture,
// then Draw that texture to the window when it is time to update (call
// Publish on window after drawing).
NewTexture(win Window, size image.Point) (Texture, error)
// ClipBoard returns the clip.Board handler for the system, in context of given window.
ClipBoard(win Window) clip.Board
// Cursor returns the cursor.Cursor handler for the system, in context of given window.
Cursor(win Window) cursor.Cursor
// PrefsDir returns the OS-specific preferences directory: Mac: ~/Library,
// Linux: ~/.config, Windows: ?
PrefsDir() string
// GoGiPrefsDir returns the GoGi preferences directory: PrefsDir + GoGi --
// ensures that the directory exists first.
GoGiPrefsDir() string
// AppPrefsDir returns the application-specific preferences directory:
// PrefsDir + App.Name --ensures that the directory exists first.
AppPrefsDir() string
// FontPaths returns the default system font paths.
FontPaths() []string
// About is an informative message about the app. Can use HTML
// formatting, including links.
About() string
// SetAbout sets the about info.
SetAbout(about string)
// OpenURL opens the given URL in the user's default browser. On Linux
// this requires that xdg-utils package has been installed -- uses
// xdg-open command.
OpenURL(url string)
// SetQuitReqFunc sets the function that is called whenever there is a
// request to quit the app (via a OS or a call to QuitReq() method). That
// function can then adjudicate whether and when to actually call Quit.
SetQuitReqFunc(fun func())
// SetQuitCleanFunc sets the function that is called whenever app is
// actually about to quit (irrevocably) -- can do any necessary
// last-minute cleanup here.
SetQuitCleanFunc(fun func())
// QuitReq is a quit request, triggered either by OS or user call (e.g.,
// via Quit menu action) -- calls function previously-registered by
// SetQuitReqFunc, which is then solely responsible for actually calling
// Quit.
QuitReq()
// IsQuitting returns true when the app is actually quitting -- it is set
// to true just before the QuitClean function is called, and before all
// the windows are closed.
IsQuitting() bool
// QuitClean calls the function setup in SetQuitCleanFunc and does other
// app cleanup -- called on way to quitting.
QuitClean()
// Quit closes all windows and exits the program.
Quit()
}
// Platforms are all the supported platforms for OSWin
type Platforms int32
const (
// MacOS is a mac desktop machine (aka Darwin)
MacOS Platforms = iota
// LinuxX11 is a Linux OS machine running X11 window server
LinuxX11
// Windows is a Microsoft Windows machine
Windows
PlatformsN
)
//go:generate stringer -type=Platforms
var KiT_Platforms = kit.Enums.AddEnum(PlatformsN, false, nil)