-
Notifications
You must be signed in to change notification settings - Fork 1
/
App_linux.go
111 lines (96 loc) · 2.01 KB
/
App_linux.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
// +build freebsd linux netbsd openbsd solaris
package frame
/*
#cgo pkg-config: gtk+-3.0 webkit2gtk-4.0
#cgo CFLAGS: -DWEBVIEW_GTK=1 -Wno-deprecated-declarations
#cgo LDFLAGS: -lX11
#ifndef WEBVIEW_GTK
#define WEBVIEW_GTK
#endif
#include "c_linux.h"
*/
import "C"
import (
"runtime"
"sync"
"sync/atomic"
)
type (
// App is main application object
App struct {
app *C.GtkApplication
openedWns sync.WaitGroup
shown chan bool
}
)
// MakeApp is make and run one instance of application (At the moment, it is possible to create only one instance)
func MakeApp(appName string) *App {
lock.Lock()
go func() {
runtime.LockOSThread()
C.makeApp(C.CString(appName))
runtime.UnlockOSThread()
}()
return <-appChan
}
// SetIconFromFile sets application icon
func (a *App) SetIconFromFile(filename string) {
C.gtk_window_set_default_icon_from_file(C.gcharptr(C.CString(filename)), nil)
}
// WaitAllWindowClose locker
func (a *App) WaitAllWindowClose() {
<-a.shown
a.openedWns.Wait()
}
// WaitWindowClose locker
func (a *App) WaitWindowClose(win *Window) {
<-a.shown
shown := false
for {
if !win.state.Hidden {
shown = true
}
if win.state.Hidden && shown {
break
}
}
}
// NewWindow returns window with webview
func (a *App) NewWindow(title string, sizes ...int) *Window {
mutexNew.Lock()
defer mutexNew.Unlock()
id := atomic.AddInt64(&idItr, 1)
width := 500
height := 400
if len(sizes) > 0 {
width = sizes[0]
}
if len(sizes) > 1 {
height = sizes[1]
}
cRet := cRequest(func(reqid uint64) {
C.makeWindow(&C.idleData{
id: C.int(int(id)),
app: a.app,
content: C.gcharptr(C.CString(title)),
width: C.int(width),
height: C.int(height),
req_id: C.ulonglong(reqid),
})
})
ret, _ := cRet.(*C.WindowObj)
wind := &Window{
id: id,
window: ret.window,
box: ret.box,
webview: ret.webview,
menubar: ret.menubar,
state: State{Hidden: true},
MainMenu: &Menu{
menu: ret.menubar,
},
app: a,
}
winds = append(winds, wind)
return wind
}