-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus_icon.go
227 lines (193 loc) · 6.69 KB
/
status_icon.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package gotk3extra
// #cgo pkg-config: gdk-3.0 gio-2.0 glib-2.0 gobject-2.0 gtk+-3.0
// #include <stdlib.h>
// #include <gtk/gtk.h>
// #include "status_icon.go.h"
// #cgo CFLAGS: -Wno-deprecated-declarations
import "C"
import (
"errors"
"unsafe"
"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
)
func init() {
tm := []glib.TypeMarshaler{
{glib.Type(C.gtk_status_icon_get_type()), marshalStatusIcon},
}
glib.RegisterGValueMarshalers(tm)
gtk.WrapMap["GtkStatusIcon"] = wrapStatusIcon
}
// StatusIcon is a representation of GTK's GtkStatusIcon.
// Deprecated since 3.14 in favor of notifications
// (no replacement, see https://stackoverflow.com/questions/41917903/gtk-3-statusicon-replacement)
type StatusIcon struct {
*glib.Object
}
func marshalStatusIcon(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := glib.Take(unsafe.Pointer(c))
return wrapStatusIcon(obj), nil
}
func wrapStatusIcon(obj *glib.Object) *StatusIcon {
return &StatusIcon{obj}
}
func (v *StatusIcon) native() *C.GtkStatusIcon {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGtkStatusIcon(p)
}
// StatusIconNew is a wrapper around gtk_status_icon_new()
func StatusIconNew() (*StatusIcon, error) {
c := C.gtk_status_icon_new()
if c == nil {
return nil, nilPtrErr
}
return wrapStatusIcon(glib.Take(unsafe.Pointer(c))), nil
}
// StatusIconNewFromFile is a wrapper around gtk_status_icon_new_from_file()
func StatusIconNewFromFile(filename string) (*StatusIcon, error) {
cstr := C.CString(filename)
defer C.free(unsafe.Pointer(cstr))
c := C.gtk_status_icon_new_from_file((*C.gchar)(cstr))
if c == nil {
return nil, nilPtrErr
}
return wrapStatusIcon(glib.Take(unsafe.Pointer(c))), nil
}
// StatusIconNewFromIconName is a wrapper around gtk_status_icon_new_from_icon_name()
func StatusIconNewFromIconName(iconName string) (*StatusIcon, error) {
cstr := C.CString(iconName)
defer C.free(unsafe.Pointer(cstr))
c := C.gtk_status_icon_new_from_icon_name((*C.gchar)(cstr))
if c == nil {
return nil, nilPtrErr
}
return wrapStatusIcon(glib.Take(unsafe.Pointer(c))), nil
}
// StatusIconNewFromPixbuf is a wrapper around gtk_status_icon_new_from_pixbuf().
func StatusIconNewFromPixbuf(pixbuf *gdk.Pixbuf) (*StatusIcon, error) {
c := C.gtk_status_icon_new_from_pixbuf(C.toGdkPixbuf(unsafe.Pointer(pixbuf.Native())))
if c == nil {
return nil, nilPtrErr
}
obj := glib.Take(unsafe.Pointer(c))
return wrapStatusIcon(obj), nil
}
// SetFromFile is a wrapper around gtk_status_icon_set_from_file()
func (v *StatusIcon) SetFromFile(filename string) {
cstr := C.CString(filename)
defer C.free(unsafe.Pointer(cstr))
C.gtk_status_icon_set_from_file(v.native(), (*C.gchar)(cstr))
}
// SetFromIconName is a wrapper around gtk_status_icon_set_from_icon_name()
func (v *StatusIcon) SetFromIconName(iconName string) {
cstr := C.CString(iconName)
defer C.free(unsafe.Pointer(cstr))
C.gtk_status_icon_set_from_icon_name(v.native(), (*C.gchar)(cstr))
}
// SetFromPixbuf is a wrapper around gtk_status_icon_set_from_pixbuf()
func (v *StatusIcon) SetFromPixbuf(pixbuf *gdk.Pixbuf) {
C.gtk_status_icon_set_from_pixbuf(v.native(), C.toGdkPixbuf(unsafe.Pointer(pixbuf.Native())))
}
// GetStorageType is a wrapper around gtk_status_icon_get_storage_type()
func (v *StatusIcon) GetStorageType() gtk.ImageType {
return (gtk.ImageType)(C.gtk_status_icon_get_storage_type(v.native()))
}
// SetTooltipText is a wrapper around gtk_status_icon_set_tooltip_text()
func (v *StatusIcon) SetTooltipText(text string) {
cstr := C.CString(text)
defer C.free(unsafe.Pointer(cstr))
C.gtk_status_icon_set_tooltip_text(v.native(), (*C.gchar)(cstr))
}
// GetTooltipText is a wrapper around gtk_status_icon_get_tooltip_text()
func (v *StatusIcon) GetTooltipText() string {
c := C.gtk_status_icon_get_tooltip_text(v.native())
if c == nil {
return ""
}
return C.GoString((*C.char)(c))
}
// SetTooltipMarkup is a wrapper around gtk_status_icon_set_tooltip_markup()
func (v *StatusIcon) SetTooltipMarkup(markup string) {
cstr := C.CString(markup)
defer C.free(unsafe.Pointer(cstr))
C.gtk_status_icon_set_tooltip_markup(v.native(), (*C.gchar)(cstr))
}
// GetTooltipMarkup is a wrapper around gtk_status_icon_get_tooltip_markup()
func (v *StatusIcon) GetTooltipMarkup() string {
c := C.gtk_status_icon_get_tooltip_markup(v.native())
if c == nil {
return ""
}
return C.GoString((*C.char)(c))
}
// SetHasTooltip is a wrapper around gtk_status_icon_set_has_tooltip()
func (v *StatusIcon) SetHasTooltip(hasTooltip bool) {
C.gtk_status_icon_set_has_tooltip(v.native(), gbool(hasTooltip))
}
// GetTitle is a wrapper around gtk_status_icon_get_title()
func (v *StatusIcon) GetTitle() string {
c := C.gtk_status_icon_get_title(v.native())
if c == nil {
return ""
}
return C.GoString((*C.char)(c))
}
// SetName is a wrapper around gtk_status_icon_set_name()
func (v *StatusIcon) SetName(name string) {
cstr := C.CString(name)
defer C.free(unsafe.Pointer(cstr))
C.gtk_status_icon_set_name(v.native(), (*C.gchar)(cstr))
}
// SetVisible is a wrapper around gtk_status_icon_set_visible()
func (v *StatusIcon) SetVisible(visible bool) {
C.gtk_status_icon_set_visible(v.native(), gbool(visible))
}
// GetVisible is a wrapper around gtk_status_icon_get_visible()
func (v *StatusIcon) GetVisible() bool {
return gobool(C.gtk_status_icon_get_visible(v.native()))
}
// IsEmbedded is a wrapper around gtk_status_icon_is_embedded()
func (v *StatusIcon) IsEmbedded() bool {
return gobool(C.gtk_status_icon_is_embedded(v.native()))
}
// GetX11WindowID is a wrapper around gtk_status_icon_get_x11_window_id()
func (v *StatusIcon) GetX11WindowID() uint32 {
return uint32(C.gtk_status_icon_get_x11_window_id(v.native()))
}
// GetHasTooltip is a wrapper around gtk_status_icon_get_has_tooltip()
func (v *StatusIcon) GetHasTooltip() bool {
return gobool(C.gtk_status_icon_get_has_tooltip(v.native()))
}
// SetTitle is a wrapper around gtk_status_icon_set_title()
func (v *StatusIcon) SetTitle(title string) {
cstr := C.CString(title)
defer C.free(unsafe.Pointer(cstr))
C.gtk_status_icon_set_title(v.native(), (*C.gchar)(cstr))
}
// GetIconName is a wrapper around gtk_status_icon_get_icon_name()
func (v *StatusIcon) GetIconName() string {
c := C.gtk_status_icon_get_icon_name(v.native())
if c == nil {
return ""
}
return C.GoString((*C.char)(c))
}
// GetSize is a wrapper around gtk_status_icon_get_size()
func (v *StatusIcon) GetSize() int {
return int(C.gtk_status_icon_get_size(v.native()))
}
var nilPtrErr = errors.New("cgo returned unexpected nil pointer")
func gbool(b bool) C.gboolean {
if b {
return C.gboolean(1)
}
return C.gboolean(0)
}
func gobool(b C.gboolean) bool {
return b != C.FALSE
}