mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 23:51:44 +08:00
[linux] Fix min/max size
This commit is contained in:
parent
668da3a827
commit
30a4f47cba
@ -43,11 +43,10 @@ type Frontend struct {
|
|||||||
startURL string
|
startURL string
|
||||||
|
|
||||||
// main window handle
|
// main window handle
|
||||||
mainWindow *Window
|
mainWindow *Window
|
||||||
minWidth, minHeight, maxWidth, maxHeight int
|
bindings *binding.Bindings
|
||||||
bindings *binding.Bindings
|
dispatcher frontend.Dispatcher
|
||||||
dispatcher frontend.Dispatcher
|
servingFromDisk bool
|
||||||
servingFromDisk bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {
|
func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {
|
||||||
@ -62,10 +61,6 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
|
|||||||
dispatcher: dispatcher,
|
dispatcher: dispatcher,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
startURL: "file://wails/",
|
startURL: "file://wails/",
|
||||||
minHeight: appoptions.MinHeight,
|
|
||||||
minWidth: appoptions.MinWidth,
|
|
||||||
maxHeight: appoptions.MaxHeight,
|
|
||||||
maxWidth: appoptions.MaxWidth,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bindingsJSON, err := appBindings.ToJSON()
|
bindingsJSON, err := appBindings.ToJSON()
|
||||||
@ -161,15 +156,11 @@ func (f *Frontend) WindowSetTitle(title string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) WindowFullscreen() {
|
func (f *Frontend) WindowFullscreen() {
|
||||||
f.mainWindow.SetMaxSize(0, 0)
|
|
||||||
f.mainWindow.SetMinSize(0, 0)
|
|
||||||
f.mainWindow.Fullscreen()
|
f.mainWindow.Fullscreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) WindowUnFullscreen() {
|
func (f *Frontend) WindowUnFullscreen() {
|
||||||
f.mainWindow.UnFullscreen()
|
f.mainWindow.UnFullscreen()
|
||||||
f.mainWindow.SetMaxSize(f.maxWidth, f.maxHeight)
|
|
||||||
f.mainWindow.SetMinSize(f.minWidth, f.minHeight)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) WindowShow() {
|
func (f *Frontend) WindowShow() {
|
||||||
@ -193,13 +184,9 @@ func (f *Frontend) WindowUnminimise() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) WindowSetMinSize(width int, height int) {
|
func (f *Frontend) WindowSetMinSize(width int, height int) {
|
||||||
f.minWidth = width
|
|
||||||
f.minHeight = height
|
|
||||||
f.mainWindow.SetMinSize(width, height)
|
f.mainWindow.SetMinSize(width, height)
|
||||||
}
|
}
|
||||||
func (f *Frontend) WindowSetMaxSize(width int, height int) {
|
func (f *Frontend) WindowSetMaxSize(width int, height int) {
|
||||||
f.maxWidth = width
|
|
||||||
f.maxHeight = height
|
|
||||||
f.mainWindow.SetMaxSize(width, height)
|
f.mainWindow.SetMaxSize(width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,25 +32,15 @@ static GtkBox* GTKBOX(void *pointer) {
|
|||||||
return GTK_BOX(pointer);
|
return GTK_BOX(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetMinSize(GtkWindow* window, int width, int height) {
|
static void SetMinMaxSize(GtkWindow* window, int min_width, int min_height, int max_width, int max_height) {
|
||||||
GdkGeometry size;
|
GdkGeometry size;
|
||||||
size.min_height = height;
|
size.min_width = size.min_height = size.max_width = size.max_height = 0;
|
||||||
size.min_width = width;
|
int flags = GDK_HINT_MAX_SIZE | GDK_HINT_MIN_SIZE;
|
||||||
gtk_window_set_geometry_hints(window, NULL, &size, GDK_HINT_MIN_SIZE);
|
size.max_height = (max_height == 0 ? INT_MAX : max_height);
|
||||||
}
|
size.max_width = (max_width == 0 ? INT_MAX : max_width);
|
||||||
|
size.min_height = min_height;
|
||||||
static void SetMaxSize(GtkWindow* window, int width, int height) {
|
size.min_width = min_width;
|
||||||
GdkGeometry size;
|
gtk_window_set_geometry_hints(window, NULL, &size, flags);
|
||||||
if( width == 0 ) {
|
|
||||||
width = INT_MAX;
|
|
||||||
}
|
|
||||||
if( height == 0 ) {
|
|
||||||
height = INT_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
size.max_height = height;
|
|
||||||
size.max_width = width;
|
|
||||||
gtk_window_set_geometry_hints(window, NULL, &size, GDK_HINT_MAX_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkRectangle getCurrentMonitorGeometry(GtkWindow *window) {
|
GdkRectangle getCurrentMonitorGeometry(GtkWindow *window) {
|
||||||
@ -505,15 +495,16 @@ func gtkBool(input bool) C.gboolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Window struct {
|
type Window struct {
|
||||||
appoptions *options.App
|
appoptions *options.App
|
||||||
debug bool
|
debug bool
|
||||||
gtkWindow unsafe.Pointer
|
gtkWindow unsafe.Pointer
|
||||||
contentManager unsafe.Pointer
|
contentManager unsafe.Pointer
|
||||||
webview unsafe.Pointer
|
webview unsafe.Pointer
|
||||||
applicationMenu *menu.Menu
|
applicationMenu *menu.Menu
|
||||||
menubar *C.GtkWidget
|
menubar *C.GtkWidget
|
||||||
vbox *C.GtkWidget
|
vbox *C.GtkWidget
|
||||||
accels *C.GtkAccelGroup
|
accels *C.GtkAccelGroup
|
||||||
|
minWidth, minHeight, maxWidth, maxHeight int
|
||||||
}
|
}
|
||||||
|
|
||||||
func bool2Cint(value bool) C.int {
|
func bool2Cint(value bool) C.int {
|
||||||
@ -528,6 +519,10 @@ func NewWindow(appoptions *options.App, debug bool) *Window {
|
|||||||
result := &Window{
|
result := &Window{
|
||||||
appoptions: appoptions,
|
appoptions: appoptions,
|
||||||
debug: debug,
|
debug: debug,
|
||||||
|
minHeight: appoptions.MinHeight,
|
||||||
|
minWidth: appoptions.MinWidth,
|
||||||
|
maxHeight: appoptions.MaxHeight,
|
||||||
|
maxWidth: appoptions.MaxWidth,
|
||||||
}
|
}
|
||||||
|
|
||||||
gtkWindow := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
|
gtkWindow := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
|
||||||
@ -591,11 +586,15 @@ func (w *Window) cWebKitUserContentManager() *C.WebKitUserContentManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) Fullscreen() {
|
func (w *Window) Fullscreen() {
|
||||||
|
w.SetMaxSize(0, 0)
|
||||||
|
w.SetMinSize(0, 0)
|
||||||
C.ExecuteOnMainThread(C.gtk_window_fullscreen, C.gpointer(w.asGTKWindow()))
|
C.ExecuteOnMainThread(C.gtk_window_fullscreen, C.gpointer(w.asGTKWindow()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) UnFullscreen() {
|
func (w *Window) UnFullscreen() {
|
||||||
C.ExecuteOnMainThread(C.gtk_window_unfullscreen, C.gpointer(w.asGTKWindow()))
|
C.ExecuteOnMainThread(C.gtk_window_unfullscreen, C.gpointer(w.asGTKWindow()))
|
||||||
|
w.SetMaxSize(w.maxWidth, w.maxHeight)
|
||||||
|
w.SetMinSize(w.minWidth, w.minHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) Destroy() {
|
func (w *Window) Destroy() {
|
||||||
@ -628,11 +627,15 @@ func (w *Window) GetPosition() (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) SetMaxSize(maxWidth int, maxHeight int) {
|
func (w *Window) SetMaxSize(maxWidth int, maxHeight int) {
|
||||||
C.SetMaxSize(w.asGTKWindow(), C.int(maxWidth), C.int(maxHeight))
|
w.maxHeight = maxHeight
|
||||||
|
w.maxWidth = maxWidth
|
||||||
|
C.SetMinMaxSize(w.asGTKWindow(), C.int(w.minWidth), C.int(w.minHeight), C.int(w.maxWidth), C.int(w.maxHeight))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) SetMinSize(minWidth int, minHeight int) {
|
func (w *Window) SetMinSize(minWidth int, minHeight int) {
|
||||||
C.SetMinSize(w.asGTKWindow(), C.int(minWidth), C.int(minHeight))
|
w.minHeight = minHeight
|
||||||
|
w.minWidth = minWidth
|
||||||
|
C.SetMinMaxSize(w.asGTKWindow(), C.int(w.minWidth), C.int(w.minHeight), C.int(w.maxWidth), C.int(w.maxHeight))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) Show() {
|
func (w *Window) Show() {
|
||||||
|
Loading…
Reference in New Issue
Block a user