-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapplication.go
More file actions
executable file
·697 lines (577 loc) · 18.4 KB
/
application.go
File metadata and controls
executable file
·697 lines (577 loc) · 18.4 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
package x11ui
import (
"fmt"
"image/color"
"log"
"os"
"strings"
"time"
"github.com/lucasb-eyer/go-colorful"
"github.com/BurntSushi/xgb/xproto"
"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/ewmh"
"github.com/BurntSushi/xgbutil/keybind"
"github.com/BurntSushi/xgbutil/mousebind"
"github.com/BurntSushi/xgbutil/xevent"
"github.com/BurntSushi/xgbutil/xwindow"
)
// LayoutDirection specifies the direction for automatic widget layout.
type LayoutDirection int
const (
// LayoutNone indicates no automatic layout direction.
LayoutNone LayoutDirection = iota
// LayoutHor indicates horizontal layout.
LayoutHor
// LayoutVer indicates vertical layout.
LayoutVer
)
// Handler is a function type for event handlers.
type Handler func()
// Application represents an X11 application, managing windows and events.
type Application struct {
xu *xgbutil.XUtil
appWin *Window
NWindows int
Childs []*xwindow.Window
keycallbacks keybind.KeyPressFun
KeyMaps map[string]Handler
ClickMaps map[xproto.Window]OnClickFn
w, h int
title string
Debug bool
Dark bool
bg, fg color.Color
l LayoutDirection
pvsChildRect Rect
defW, defH int
hspacing, vspacing int
hpadding, vpadding int
moveTimer *time.Timer
resizeTimer *time.Timer
}
// X returns the underlying *xgbutil.XUtil connection for the application.
func (a *Application) X() *xgbutil.XUtil {
return a.xu
}
// Width returns the width of the application's screen in pixels.
func (a *Application) Width() int {
return int(a.xu.Screen().WidthInPixels)
}
// Height returns the height of the application's screen in pixels.
func (a *Application) Height() int {
return int(a.xu.Screen().HeightInPixels)
}
// AutoLayout sets the automatic layout direction for new child windows.
func (a *Application) AutoLayout(l LayoutDirection, newpos ...int) {
a.l = l
if len(newpos) > 0 {
a.pvsChildRect = newRect(newpos...)
if l == LayoutHor {
a.pvsChildRect.ShiftRight(-(a.pvsChildRect.Width + a.hspacing))
}
if l == LayoutVer {
a.pvsChildRect.ShiftDown(-(a.pvsChildRect.Height + a.vspacing))
}
}
}
// calculateChildrenBoundingBox calculates the bounding box of all child windows.
// func (a *Application) calculateChildrenBoundingBox() Rect {
// if len(a.childrenWindows) == 0 {
// return Rect{}
// }
// minX, minY := a.childrenWindows[0].Rect.X, a.childrenWindows[0].Rect.Y
// maxX, maxY := a.childrenWindows[0].Rect.X+a.childrenWindows[0].Rect.Width,
// a.childrenWindows[0].Rect.Y+a.childrenWindows[0].Rect.Height
// for _, child := range a.childrenWindows {
// childRect := child.Rect
// if childRect.X < minX {
// minX = childRect.X
// }
// if childRect.Y < minY {
// minY = childRect.Y
// }
// if childRect.X+childRect.Width > maxX {
// maxX = childRect.X + childRect.Width
// }
// if childRect.Y+childRect.Height > maxY {
// maxY = childRect.Y + childRect.Height
// }
// }
// return Rect{minX, minY, maxX - minX, maxY - minY}
// }
// NewApp creates a new application with a default title and specified dimensions.
func NewApp(fullscreen bool, width, height int) *Application {
return NewApplication("X11 Application", width, height, true, fullscreen)
}
// NewApplication creates a new X11 application with the given title, dimensions, and resize/fullscreen options.
func NewApplication(title string, width, height int, resizeable, fullApplication bool) *Application {
s := Application{w: width, h: height, title: title, Dark: false}
s.KeyMaps = make(map[string]Handler)
s.title = title
s.Debug = true
s.defW, s.defH = width, height
s.l = LayoutHor
var err error
s.xu, err = xgbutil.NewConn()
if err != nil {
log.Fatal("Application: ", err)
}
keybind.Initialize(s.xu)
mousebind.Initialize(s.xu)
s.defaultWindow()
if fullApplication {
s.FullScreen()
}
s.title = title
s.appWin.SetTitle(title)
s.keycallbacks = s.keybHandler
xevent.KeyPressFun(s.keybHandler).Connect(s.xu, s.AppWin().Id)
s.appWin.keybFn = s.handleKey
// var mkey xgbutil.KeyKey
mousebind.ButtonPressFun(s.mouseHandler).Connect(s.xu, s.appWin.Id, "1", false, false)
// cb1 := keybind.KeyPressFun(
// func(X *xgbutil.XUtil, e xevent.KeyPressEvent) {
// log.Println("Key press!")
// })
// root, err := xwindow.Generate(X)
// if err != nil {
// log.Fatal(err)
// }
return &s
}
// AppWin returns the main application window.
func (a *Application) AppWin() *Window {
return a.appWin
}
// mouseHandler processes mouse button press events for the application.
func (s *Application) mouseHandler(X *xgbutil.XUtil, e xevent.ButtonPressEvent) {
// log.Println("Application ", s.appWin.Title(), " clicked at ", e.EventX, e.EventY)
if s.appWin.clkAdv != nil {
s.appWin.clkAdv(s.appWin, int(e.EventX), int(e.EventY))
}
if s.appWin.clk != nil {
s.appWin.clk()
}
}
func (s *Application) mouseReleaseHandler(X *xgbutil.XUtil, e xevent.ButtonReleaseEvent) {
// No-op, as isDragging is removed
}
// keybHandler processes keyboard press events for the application.
func (s *Application) handleKey(key string) {
if fn, ok := s.KeyMaps[key]; ok {
if s.Debug {
}
fn()
} else {
log.Printf("Caught Key : %s", key)
}
}
// keybHandler processes keyboard press events for the application.
func (s *Application) keybHandler(X *xgbutil.XUtil, e xevent.KeyPressEvent) {
if s.xu != X {
return
}
modStr := keybind.ModifierString(e.State)
keyStr := keybind.LookupString(X, e.State, e.Detail)
modStr = strings.Replace(modStr, "lock-", "", -1)
modStr = strings.Replace(modStr, "mod2", "", -1)
finalstr := keyStr
if modStr != "" {
finalstr = fmt.Sprint(modStr, keyStr)
}
s.handleKey(finalstr)
}
// RegisterGlobalKey registers a key to be handled globally by the application.
// This will grab the keyboard, meaning no other application will receive keyboard input.
func (s *Application) RegisterGlobalKey(keyname string, fn Handler) bool {
if s.RegisterKey(keyname, fn) {
if err := keybind.GrabKeyboard(s.xu, s.xu.RootWin()); err != nil {
log.Fatalf("Could not grab keyboard: %s", err)
return false
}
log.Println("WARNING: We are taking *complete* control of the root " +
"window. The only way out is to press 'Control + Escape' or to " +
"close the window with the mouse.")
} else {
return false
}
return true
}
// RegisterKey registers a key with a function to be handled by the application.
func (s *Application) RegisterKey(keyname string, fn Handler) bool {
// log.Println("Current Root ", s.xu)
s.KeyMaps[keyname] = fn
if s.Debug {
log.Println("Registering ", keyname, " with this ", fn)
}
// if len(s.KeyMaps) == 0 {
// xevent.KeyPressFun(s.keybHandler).Connect(s.xu, s.bgWin.Id)
// }
return true
}
// Show starts the application's event loop and displays the main window.
func (s *Application) Show() {
xevent.Main(s.xu)
}
// DefaultKeys enables or disables default keybindings for the application (e.g., 'q' for close, 'f' for fullscreen).
func (s *Application) DefaultKeys(enable bool) {
if enable {
s.RegisterKey("q", s.Close)
s.RegisterKey("Q", s.Close)
s.RegisterKey("f", s.FullScreen)
s.RegisterKey("F", s.FullScreen)
}
}
// Close terminates the application.
func (s *Application) Close() {
xevent.Quit(s.xu)
}
// XWin returns the underlying *xwindow.Window of the application's main window.
func (s *Application) XWin() *xwindow.Window {
return s.appWin.Window
}
// Empty returns an empty Window associated with the application's root window.
func (s *Application) Empty() *Window {
var w Window
w.Id = s.xu.RootWin()
return &w
}
func (s *Application) defaultWindow() {
// s.NWindows++
// s.appWin = s.NewFloatingWindow("Application ")
// s.appWin.WMMoveResize(0, 0, 1024, 523)
var err error
s.appWin = new(Window)
s.appWin.Window, err = xwindow.Generate(s.xu)
if err != nil {
log.Fatalln(err)
}
sinfo := s.xu.Screen()
w, h := int(sinfo.WidthInPixels)/2, int(sinfo.HeightInPixels)/2
w, h = s.defW, s.defH
s.appWin.Create(s.xu.RootWin(), 0, 0, w, h, xproto.CwBackPixel, 0x000000)
s.appWin.Rect = Rect{0, 0, w, h}
s.appWin.prevRect = s.appWin.Rect
ewmh.WmAllowedActionsSet(s.xu, s.appWin.Id, []string{
"_NET_WM_ACTION_MOVE",
"_NET_WM_ACTION_RESIZE",
"_NET_WM_ACTION_SHADE",
})
// Listen for Key{Press,Release} events.
s.appWin.Listen(xproto.EventMaskKeyPress, xproto.EventMaskKeyRelease, xproto.EventMaskButtonPress, xproto.EventMaskButtonPress, xproto.EventMaskSubstructureNotify, xproto.EventMaskStructureNotify, xproto.EventMaskFocusChange)
// xevent.ResizeRequestFun(
// func(p *xgbutil.XUtil, e xevent.ResizeRequestEvent) {
// log.Printf("2. Received event ", e)
//
// }).Connect(s.xu, s.appWin.Id)
//
xevent.ConfigureRequestFun(
func(p *xgbutil.XUtil, e xevent.ConfigureRequestEvent) {
//
// log.Printf("4. CONFIGURE REEQUEST ", e)
}).Connect(s.xu, s.appWin.Id)
xevent.ConfigureNotifyFun(
func(p *xgbutil.XUtil, e xevent.ConfigureNotifyEvent) {
currentRect := Rect{int(e.X), int(e.Y), int(e.Width), int(e.Height)}
// Check for size change
sizeChanged := currentRect.Width != s.appWin.prevRect.Width || currentRect.Height != s.appWin.prevRect.Height
if sizeChanged {
if s.appWin.onSizeChange != nil {
s.appWin.onSizeChange(currentRect.Width, currentRect.Height)
}
// Reset or start the resize timer
if s.resizeTimer != nil {
s.resizeTimer.Stop()
}
s.resizeTimer = time.AfterFunc(100*time.Millisecond, func() {
// log.Println("Window resize complete")
if s.appWin.onResizeComplete != nil {
s.appWin.onResizeComplete(currentRect.Width, currentRect.Height)
}
})
}
// Check for position change
positionChanged := currentRect.X != s.appWin.prevRect.X || currentRect.Y != s.appWin.prevRect.Y
if positionChanged {
// log.Println("Window is moving")
if s.appWin.onMove != nil {
s.appWin.onMove(currentRect.X, currentRect.Y)
}
// Reset or start the move timer
if s.moveTimer != nil {
s.moveTimer.Stop()
}
s.moveTimer = time.AfterFunc(100*time.Millisecond, func() {
// log.Println("Window move complete")
if s.appWin.onMoveComplete != nil {
s.appWin.onMoveComplete(currentRect.X, currentRect.Y)
}
})
}
s.appWin.prevRect = currentRect
}).Connect(s.xu, s.appWin.Id)
// Make this window close gracefully.
s.appWin.WMGracefulClose(
func(w *xwindow.Window) {
xevent.Detach(w.X, w.Id)
keybind.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
// if quit {
xevent.Quit(w.X)
// }
})
// Map the window.
s.appWin.Map()
// // Get a random background color, create the window (ask to receive button
// // release events while we're at it) and map the window.
// bgColor := rand.Intn(0xffffff + 1)
// win.Create(X.RootWin(), 0, 0, 200, 200,
// xproto.CwBackPixel|xproto.CwEventMask,
// uint32(bgColor), xproto.EventMaskButtonRelease)
// // WMGracefulClose does all of the work for us. It sets the appropriate
// // values for WM_PROTOCOLS, and listens for ClientMessages that implement
// // the WM_DELETE_WINDOW protocol. When one is found, the provided callback
// // is executed.
// win.WMGracefulClose(
// func(w *xwindow.Window) {
// // Detach all event handlers.
// // This should always be done when a window can no longer
// // receive events.
// xevent.Detach(w.X, w.Id)
// mousebind.Detach(w.X, w.Id)
// w.Destroy()
// // Exit if there are no more windows left.
// counter--
// if counter == 0 {
// os.Exit(0)
// }
// })
// // It's important that the map comes after setting WMGracefulClose, since
// // the WM isn't obliged to watch updates to the WM_PROTOCOLS property.
// win.Map()
// // A mouse binding so that a left click will spawn a new window.
// // Note that we don't issue a grab here. Typically, window managers will
// // grab a button press on the client window (which usually activates the
// // window), so that we'd end up competing with the window manager if we
// // tried to grab it.
// // Instead, we set a ButtonRelease mask when creating the window and attach
// // a mouse binding *without* a grab.
// err = mousebind.ButtonReleaseFun(
// func(X *xgbutil.XUtil, ev xevent.ButtonReleaseEvent) {
// newWindow(X)
// }).Connect(X, win.Id, "1", false, false)
// if err != nil {
// log.Fatal(err)
// }
}
func (s *Application) NewFloatingWindow(title string, dims ...int) *Window {
// X := s.xu
w := s.newWindow(0, newRect(dims...))
w.SetTitle(title)
if len(dims) < 3 {
w.Resize(700, 500)
}
return w
}
func (s *Application) Restore() {
// _NET_WM_ACTION_SHADE
// err := ewmh.WmStateReq(s.xu, s.appWin.Id, ewmh.StateToggle, "_NET_WM_ACTION_SHADE")
// if err != nil {
// log.Fatal(err)
// }
// Restore the window by setting an empty state.
err := ewmh.WmStateSet(s.xu, s.appWin.Id, []string{})
if err != nil {
panic(err)
}
}
// https://specifications.freedesktop.org/wm-spec/1.3/ar01s05.html
func (s *Application) Hide() {
// _NET_WM_STATE_HIDDEN
// Get the _NET_WM_STATE_HIDDEN atom.
_, err := ewmh.WmStateGet(s.xu, s.appWin.Id)
if err != nil {
panic(err)
}
ewmh.WmNameSet(s.xu, s.appWin.Id, "Minimize Example")
// Set the WM_STATE property to hidden.
err = ewmh.WmStateSet(s.xu, s.appWin.Id, []string{"_NET_WM_STATE_FULLSCREEN"})
// err = ewmh.WmStateReq(s.xu, s.appWin.Id, ewmh.StateToggle, "_NET_WM_STATE_FOCUSED")
if err != nil {
panic(err)
}
// err := ewmh.WmStateReq(s.xu, s.appWin.Id, ewmh.StateToggle, "_NET_WM_ACTION_MINIMIZE")
// if err != nil {
// log.Fatal(err)
// }
}
func (s *Application) Maximize() {
err := ewmh.WmStateReq(s.xu, s.appWin.Id, ewmh.StateToggle, "_NET_WM_STATE_MAXIMIZED_HORZ")
// ewmh.WmStateGet(s.xu, s.appWin.Id)
// s.appWin.ClearAll()
if err != nil {
log.Fatal(err)
}
}
func (s *Application) FullScreen() {
err := ewmh.WmStateReq(s.xu, s.appWin.Id, ewmh.StateToggle, "_NET_WM_STATE_FULLSCREEN")
// err := ewmh.WmStateReq(s.xu, s.appWin.Id, ewmh.StateAdd, "_NET_WM_STATE_HIDDEN")
// ewmh.WmStateGet(s.xu, s.appWin.Id)
// s.appWin.ClearAll()
if err != nil {
log.Fatal(err)
}
}
func (s *Application) InvertBackGround() {
if s.appWin != nil {
if s.Dark {
s.appWin.Change(xproto.CwBackPixel, 0x265170)
} else {
s.appWin.Change(xproto.CwBackPixel, 0x1f1f1f)
}
s.Dark = !s.Dark
s.appWin.ClearAll()
}
}
func toUint32(colorful.Color) uint32 {
return 0
}
func (a *Application) SetDefaultKeys() {
a.RegisterKey("q", a.Close)
a.RegisterKey("i", a.InvertBackGround)
a.RegisterKey("f", a.FullScreen)
}
func (s *Application) newWindow(p xproto.Window, r Rect) *Window {
w := new(Window)
var parent xproto.Window
if p == 0 {
parent = s.xu.RootWin()
} else {
parent = p
}
win, err := xwindow.Generate(s.xu)
win.Create(parent, r.X, r.Y, r.Width, r.Height, xproto.CwBackPixel, 0x000000)
if err != nil {
log.Fatal(err)
}
// // win.MoveResize(r.X, r.Y, r.Width, r.Height)
// if p == 0 {
// win.Change(xproto.CwBackPixel, 0x1f1f1f)
// } else {
// // win.Change(xproto.CwBackPixel, 0xC0FFC0)
// win.Change(xproto.CwBackPixel)
// }
w.Rect = r
w.Window = win
cb1 := mousebind.ButtonPressFun(w.mouseHandler)
if p == 0 {
err = cb1.Connect(s.xu, win.Id, "2", false, true)
} else {
err = cb1.Connect(s.xu, win.Id, "1", false, true)
}
if err != nil {
log.Println("Error in binding mouse press ", err)
}
win.WMGracefulClose(
func(w *xwindow.Window) {
// Detach all event handlers.
// This should always be done when a window can no longer
// receive events.
xevent.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
// Exit if there are no more windows left.
s.NWindows--
if s.NWindows == 0 {
os.Exit(0)
}
})
// It's important that the map comes after setting WMGracefulClose, since
// the WM isn't obliged to watch updates to the WM_PROTOCOLS property.
win.Map()
return w
}
func (a *Application) NewContainer(layout LayoutDirection, dims ...int) *Container {
tempWindow := a.NewChildWindow("", dims...)
container := &Container{
Window: *tempWindow, // Dereference the pointer to assign to the embedded value
layoutDirection: layout,
children: make([]WindowProvider, 0),
hspacing: a.hspacing, // Default spacing
vspacing: a.vspacing,
pvsChildRect: tempWindow.Rect, // Use the Rect from the temporary window
defaultFontSize: 12.0, // Initialize default font size
}
container.SetBGcolor(color.RGBA{0, 0, 0, 0}) // Fully transparent black
container.OnResizeComplete(func(w, h int) {
container.RelayoutChildren()
})
return container
}
func (a *Application) AddButton(caption string, geo ...int) *Window {
var r Rect
if len(geo) > 0 {
r = newRect(geo...)
} else {
switch a.l {
case LayoutVer:
a.pvsChildRect.ShiftDown(a.pvsChildRect.Height + a.vspacing)
r = a.pvsChildRect
case LayoutHor:
a.pvsChildRect.ShiftRight(a.pvsChildRect.Width + a.hspacing)
r = a.pvsChildRect
}
}
paddedRect := r.WithPadding(a.hpadding, a.vpadding)
obj := NewButton(caption, a.AppWin(), paddedRect.X-a.AppWin().Rect.X, paddedRect.Y-a.AppWin().Rect.Y, paddedRect.Width, paddedRect.Height)
a.pvsChildRect = r
return obj
}
func (a *Application) AddToggleBtn(caption string, geo ...int) *Window {
var r Rect
if len(geo) > 0 {
r = newRect(geo...)
} else {
switch a.l {
case LayoutVer:
a.pvsChildRect.ShiftDown(a.pvsChildRect.Height + a.vspacing)
r = a.pvsChildRect
case LayoutHor:
a.pvsChildRect.ShiftRight(a.pvsChildRect.Width + a.hspacing)
r = a.pvsChildRect
}
}
paddedRect := r.WithPadding(a.hpadding, a.vpadding)
obj := NewToggleButton(caption, a.AppWin(), paddedRect.X-a.AppWin().Rect.X, paddedRect.Y-a.AppWin().Rect.Y, paddedRect.Width, paddedRect.Height)
a.pvsChildRect = r
return obj
}
func (a *Application) SetLayoutSpacing(dx, dy int) {
a.hspacing, a.vspacing = dx, dy
}
func (a *Application) SetLayoutPadding(dx, dy int) {
a.hpadding, a.vpadding = dx, dy
}
func (a *Application) NewChildWindow(title string, dims ...int) *Window {
var r Rect
if len(dims) > 0 {
r = newRect(dims...)
} else {
switch a.l {
case LayoutVer:
a.pvsChildRect.ShiftDown(a.pvsChildRect.Height + a.vspacing)
r = a.pvsChildRect
case LayoutHor:
a.pvsChildRect.ShiftRight(a.pvsChildRect.Width + a.hspacing)
r = a.pvsChildRect
}
}
paddedRect := r.WithPadding(a.hpadding, a.vpadding)
w := a.newWindow(a.appWin.Id, paddedRect)
a.pvsChildRect = r
// w.SetBackGround(colorful.LinearRgb(0, 0, 0))
// w.SetTitle(title)
w.Detach()
return w
}