From de5cff799effaf45ec17eac2d1b84aabcaebb41b Mon Sep 17 00:00:00 2001 From: Travis McLane Date: Fri, 23 Jun 2023 21:44:02 -0500 Subject: [PATCH] [v3 linux] setEnabled --- v3/pkg/application/linux_cgo.go | 11 ++++++++++- v3/pkg/application/linux_purego.go | 14 ++++++++++++++ v3/pkg/application/webview_window_linux.go | 18 ++++++++++++------ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/v3/pkg/application/linux_cgo.go b/v3/pkg/application/linux_cgo.go index 955dea05d..5762c599f 100644 --- a/v3/pkg/application/linux_cgo.go +++ b/v3/pkg/application/linux_cgo.go @@ -412,6 +412,15 @@ func getScreens(app pointer) ([]*Screen, error) { } // widgets +func widgetSetSensitive(widget pointer, enabled bool) { + value := C.int(0) + if enabled { + value = C.int(1) + } + + C.gtk_widget_set_sensitive((*C.GtkWidget)(widget), value) +} + func widgetSetVisible(widget pointer, hidden bool) { if hidden { C.gtk_widget_hide((*C.GtkWidget)(widget)) @@ -488,7 +497,7 @@ func windowGetSize(window pointer) (int, int) { return int(windowWidth), int(windowHeight) } -func windowGetPosition(window pointer) (int, int) { +func windowGetRelativePosition(window pointer) (int, int) { var x C.int var y C.int C.gtk_window_get_position((*C.GtkWindow)(window), &x, &y) diff --git a/v3/pkg/application/linux_purego.go b/v3/pkg/application/linux_purego.go index ff2a64095..3a358bfcc 100644 --- a/v3/pkg/application/linux_purego.go +++ b/v3/pkg/application/linux_purego.go @@ -614,6 +614,14 @@ func getScreens(app pointer) ([]*Screen, error) { } // widgets +func widgetSetSensitive(widget pointer, enabled bool) { + value := 0 + if enabled { + value = 1 + } + gtkWidgetSetSensitive(widget, value) +} + func widgetSetVisible(widget pointer, hidden bool) { if hidden { gtkWidgetHide(widget) @@ -665,6 +673,12 @@ func windowFullscreen(window pointer) { gtkWindowFullScreen(window) } +func windowGetAbsolutePosition(window pointer) (int, int) { + var x, y int + gtkWindowGetPosition(window, &x, &y) + return x, y +} + func windowGetCurrentMonitor(window pointer) pointer { // Get the monitor that the window is currently on display := gtkWidgetGetDisplay(window) diff --git a/v3/pkg/application/webview_window_linux.go b/v3/pkg/application/webview_window_linux.go index 508ce7cd5..e2fe95ed9 100644 --- a/v3/pkg/application/webview_window_linux.go +++ b/v3/pkg/application/webview_window_linux.go @@ -159,7 +159,7 @@ func (w *linuxWebviewWindow) fullscreen() { w.setMinMaxSize(0, 0, width*scale, height*scale) w.setSize(width*scale, height*scale) windowFullscreen(w.window) - w.setPosition(0, 0) + w.setRelativePosition(0, 0) }) } @@ -356,7 +356,7 @@ func (w *linuxWebviewWindow) size() (int, int) { return windowGetSize(w.window) } -func (w *linuxWebviewWindow) setPosition(x, y int) { +func (w *linuxWebviewWindow) setRelativePosition(x, y int) { mx, my, _, _, _ := windowGetCurrentMonitorGeometry(w.window) globalApplication.dispatchOnMainThread(func() { windowMove(w.window, x+mx, y+my) @@ -426,7 +426,7 @@ func (w *linuxWebviewWindow) run() { w.setFrameless(w.parent.options.Frameless) if w.parent.options.X != 0 || w.parent.options.Y != 0 { - w.setPosition(w.parent.options.X, w.parent.options.Y) + w.setRelativePosition(w.parent.options.X, w.parent.options.Y) } else { fmt.Println("attempting to set in the center") w.center() @@ -460,7 +460,7 @@ func (w *linuxWebviewWindow) run() { if !w.parent.options.Hidden { w.show() if w.parent.options.X != 0 || w.parent.options.Y != 0 { - w.setPosition(w.parent.options.X, w.parent.options.Y) + w.setRelativePosition(w.parent.options.X, w.parent.options.Y) } else { w.center() // needs to be queued until after GTK starts up! } @@ -479,12 +479,12 @@ func (w *linuxWebviewWindow) setBackgroundColour(colour RGBA) { windowSetBackgroundColour(w.webview, colour) } -func (w *linuxWebviewWindow) position() (int, int) { +func (w *linuxWebviewWindow) relativePosition() (int, int) { var x, y int var wg sync.WaitGroup wg.Add(1) go globalApplication.dispatchOnMainThread(func() { - x, y = windowGetPosition(w.window) + x, y = windowGetRelativePosition(w.window) wg.Done() }) wg.Wait() @@ -495,6 +495,12 @@ func (w *linuxWebviewWindow) destroy() { windowDestroy(w.window) } +func (w *linuxWebviewWindow) setEnabled(enabled bool) { + globalApplication.dispatchOnMainThread(func() { + widgetSetSensitive(w.window, enabled) + }) +} + func (w *linuxWebviewWindow) setHTML(html string) { windowSetHTML(w.webview, html) }