app/window,app/internal/window: allow min/max window size

The app.MinSize and app.MaxSize options restricts the window size:

w := app.NewWindow(
	app.Size(unit.Dp(600), unit.Dp(596)),
	app.MinSize(unit.Dp(600), unit.Dp(596)),
	app.MaxSize(unit.Dp(600), unit.Dp(596)),
	app.Title(APPNAME),
)

Signed-off-by: Jason <sourcehut@sweatyballs.es>
This commit is contained in:
Jason
2020-06-22 12:49:41 +02:00
committed by Elias Naur
parent 20cf570709
commit 9cfbdafe14
7 changed files with 150 additions and 33 deletions
+15
View File
@@ -514,6 +514,21 @@ func newX11Window(gioWin Callbacks, opts *Options) error {
hints.flags = C.InputHint
C.XSetWMHints(dpy, win, &hints)
var shints C.XSizeHints
if opts.MinWidth.V != 0 || opts.MinHeight.V != 0 {
shints.min_width = C.int(cfg.Px(opts.MinWidth))
shints.min_height = C.int(cfg.Px(opts.MinHeight))
shints.flags = C.PMinSize
}
if opts.MaxWidth.V != 0 || opts.MaxHeight.V != 0 {
shints.max_width = C.int(cfg.Px(opts.MaxWidth))
shints.max_height = C.int(cfg.Px(opts.MaxHeight))
shints.flags = shints.flags | C.PMaxSize
}
if shints.flags != 0 {
C.XSetWMNormalHints(dpy, win, &shints)
}
name := C.CString(filepath.Base(os.Args[0]))
defer C.free(unsafe.Pointer(name))
wmhints := C.XClassHint{name, name}