mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 06:51:26 +08:00
Fix linux unexpected signal errors (#1200)
* Fix fatal error on otherwise clean exit. * Fix race condition while setting title during window creation. * Fix unexpected signal error when clicking webview should initiate a drag window operation. * Ensure ExecuteOnMainThread callbacks are removed from the event source list on completion. * Ensure all ExecuteOnMainThread callbacks use the expected return value on completion. * Fix potential memory leak when exiting early from startDrag.
This commit is contained in:
parent
8eae31d865
commit
c378d935f3
@ -57,8 +57,7 @@ GdkRectangle getCurrentMonitorGeometry(GtkWindow *window) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Center(gpointer data)
|
gboolean Center(gpointer data) {
|
||||||
{
|
|
||||||
GtkWindow *window = (GtkWindow*)data;
|
GtkWindow *window = (GtkWindow*)data;
|
||||||
|
|
||||||
// Get the geometry of the monitor
|
// Get the geometry of the monitor
|
||||||
@ -73,6 +72,8 @@ void Center(gpointer data)
|
|||||||
|
|
||||||
// Place the window at the center of the monitor
|
// Place the window at the center of the monitor
|
||||||
gtk_window_move(window, newX, newY);
|
gtk_window_move(window, newX, newY);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IsFullscreen(GtkWidget *widget) {
|
int IsFullscreen(GtkWidget *widget) {
|
||||||
@ -196,16 +197,20 @@ typedef struct DragOptions {
|
|||||||
GtkWindow* mainwindow;
|
GtkWindow* mainwindow;
|
||||||
} DragOptions;
|
} DragOptions;
|
||||||
|
|
||||||
static void startDrag(gpointer data)
|
static gboolean startDrag(gpointer data) {
|
||||||
{
|
|
||||||
DragOptions* options = (DragOptions*)data;
|
DragOptions* options = (DragOptions*)data;
|
||||||
|
|
||||||
// Ignore non-toplevel widgets
|
// Ignore non-toplevel widgets
|
||||||
GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(options->webview));
|
GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(options->webview));
|
||||||
if (!GTK_IS_WINDOW(window)) return;
|
if (!GTK_IS_WINDOW(window)) {
|
||||||
|
free(data);
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
gtk_window_begin_move_drag(options->mainwindow, 1, xroot, yroot, dragTime);
|
gtk_window_begin_move_drag(options->mainwindow, 1, xroot, yroot, dragTime);
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StartDrag(void *webview, GtkWindow* mainwindow) {
|
static void StartDrag(void *webview, GtkWindow* mainwindow) {
|
||||||
@ -220,7 +225,7 @@ typedef struct JSCallback {
|
|||||||
char* script;
|
char* script;
|
||||||
} JSCallback;
|
} JSCallback;
|
||||||
|
|
||||||
int executeJS(gpointer data) {
|
gboolean executeJS(gpointer data) {
|
||||||
struct JSCallback *js = data;
|
struct JSCallback *js = data;
|
||||||
webkit_web_view_run_javascript(js->webview, js->script, NULL, NULL, NULL);
|
webkit_web_view_run_javascript(js->webview, js->script, NULL, NULL, NULL);
|
||||||
free(js->script);
|
free(js->script);
|
||||||
@ -236,7 +241,7 @@ typedef struct MessageDialogOptions {
|
|||||||
int messageType;
|
int messageType;
|
||||||
} MessageDialogOptions;
|
} MessageDialogOptions;
|
||||||
|
|
||||||
void messageDialog(gpointer data) {
|
gboolean messageDialog(gpointer data) {
|
||||||
|
|
||||||
GtkDialogFlags flags;
|
GtkDialogFlags flags;
|
||||||
GtkMessageType messageType;
|
GtkMessageType messageType;
|
||||||
@ -278,6 +283,8 @@ void messageDialog(gpointer data) {
|
|||||||
gtk_widget_destroy(dialog);
|
gtk_widget_destroy(dialog);
|
||||||
free(options->title);
|
free(options->title);
|
||||||
free(options->message);
|
free(options->message);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void extern processOpenFileResult(void*);
|
void extern processOpenFileResult(void*);
|
||||||
@ -302,7 +309,7 @@ void freeFileFilterArray(GtkFileFilter** filters) {
|
|||||||
free(filters);
|
free(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
int opendialog(gpointer data) {
|
gboolean opendialog(gpointer data) {
|
||||||
struct OpenFileDialogOptions *options = data;
|
struct OpenFileDialogOptions *options = data;
|
||||||
char *label = "_Open";
|
char *label = "_Open";
|
||||||
if (options->action == GTK_FILE_CHOOSER_ACTION_SAVE) {
|
if (options->action == GTK_FILE_CHOOSER_ACTION_SAVE) {
|
||||||
@ -407,10 +414,12 @@ typedef struct RGBAOptions {
|
|||||||
void *webview;
|
void *webview;
|
||||||
} RGBAOptions;
|
} RGBAOptions;
|
||||||
|
|
||||||
void setRGBA(gpointer* data) {
|
gboolean setRGBA(gpointer* data) {
|
||||||
RGBAOptions* options = (RGBAOptions*)data;
|
RGBAOptions* options = (RGBAOptions*)data;
|
||||||
GdkRGBA colour = {options->r / 255.0, options->g / 255.0, options->b / 255.0, options->a / 255.0};
|
GdkRGBA colour = {options->r / 255.0, options->g / 255.0, options->b / 255.0, options->a / 255.0};
|
||||||
webkit_web_view_set_background_color(WEBKIT_WEB_VIEW(options->webview), &colour);
|
webkit_web_view_set_background_color(WEBKIT_WEB_VIEW(options->webview), &colour);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct SetTitleArgs {
|
typedef struct SetTitleArgs {
|
||||||
@ -418,11 +427,13 @@ typedef struct SetTitleArgs {
|
|||||||
char* title;
|
char* title;
|
||||||
} SetTitleArgs;
|
} SetTitleArgs;
|
||||||
|
|
||||||
void setTitle(gpointer data) {
|
gboolean setTitle(gpointer data) {
|
||||||
SetTitleArgs* args = (SetTitleArgs*)data;
|
SetTitleArgs* args = (SetTitleArgs*)data;
|
||||||
gtk_window_set_title(args->window, args->title);
|
gtk_window_set_title(args->window, args->title);
|
||||||
free((void*)args->title);
|
free((void*)args->title);
|
||||||
free((void*)data);
|
free((void*)data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTitle(GtkWindow* window, char* title) {
|
void SetTitle(GtkWindow* window, char* title) {
|
||||||
@ -438,10 +449,12 @@ typedef struct SetPositionArgs {
|
|||||||
void* window;
|
void* window;
|
||||||
} SetPositionArgs;
|
} SetPositionArgs;
|
||||||
|
|
||||||
void setPosition(gpointer data) {
|
gboolean setPosition(gpointer data) {
|
||||||
SetPositionArgs* args = (SetPositionArgs*)data;
|
SetPositionArgs* args = (SetPositionArgs*)data;
|
||||||
gtk_window_move((GtkWindow*)args->window, args->x, args->y);
|
gtk_window_move((GtkWindow*)args->window, args->x, args->y);
|
||||||
free(args);
|
free(args);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetPosition(void* window, int x, int y) {
|
void SetPosition(void* window, int x, int y) {
|
||||||
@ -453,28 +466,52 @@ void SetPosition(void* window, int x, int y) {
|
|||||||
ExecuteOnMainThread(setPosition, (gpointer)args);
|
ExecuteOnMainThread(setPosition, (gpointer)args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Show(gpointer data) {
|
gboolean Show(gpointer data) {
|
||||||
gtk_widget_show((GtkWidget*)data);
|
gtk_widget_show((GtkWidget*)data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hide(gpointer data) {
|
gboolean Hide(gpointer data) {
|
||||||
gtk_widget_hide((GtkWidget*)data);
|
gtk_widget_hide((GtkWidget*)data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Maximise(gpointer data) {
|
gboolean Maximise(gpointer data) {
|
||||||
gtk_window_maximize((GtkWindow*)data);
|
gtk_window_maximize((GtkWindow*)data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnMaximise(gpointer data) {
|
gboolean UnMaximise(gpointer data) {
|
||||||
gtk_window_unmaximize((GtkWindow*)data);
|
gtk_window_unmaximize((GtkWindow*)data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Minimise(gpointer data) {
|
gboolean Minimise(gpointer data) {
|
||||||
gtk_window_iconify((GtkWindow*)data);
|
gtk_window_iconify((GtkWindow*)data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnMinimise(gpointer data) {
|
gboolean UnMinimise(gpointer data) {
|
||||||
gtk_window_present((GtkWindow*)data);
|
gtk_window_present((GtkWindow*)data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean Fullscreen(gpointer data) {
|
||||||
|
gtk_window_fullscreen((GtkWindow*)data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean UnFullscreen(gpointer data) {
|
||||||
|
gtk_window_unfullscreen((GtkWindow*)data);
|
||||||
|
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disableContextMenu(GtkWindow* window) {
|
bool disableContextMenu(GtkWindow* window) {
|
||||||
@ -596,21 +633,21 @@ func (w *Window) cWebKitUserContentManager() *C.WebKitUserContentManager {
|
|||||||
|
|
||||||
func (w *Window) Fullscreen() {
|
func (w *Window) Fullscreen() {
|
||||||
C.SetMinMaxSize(w.asGTKWindow(), C.int(0), C.int(0), C.int(0), C.int(0))
|
C.SetMinMaxSize(w.asGTKWindow(), C.int(0), C.int(0), C.int(0), C.int(0))
|
||||||
C.ExecuteOnMainThread(C.gtk_window_fullscreen, C.gpointer(w.asGTKWindow()))
|
C.ExecuteOnMainThread(C.Fullscreen, C.gpointer(w.asGTKWindow()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) UnFullscreen() {
|
func (w *Window) UnFullscreen() {
|
||||||
if !w.IsFullScreen() {
|
if !w.IsFullScreen() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
C.ExecuteOnMainThread(C.gtk_window_unfullscreen, C.gpointer(w.asGTKWindow()))
|
C.ExecuteOnMainThread(C.UnFullscreen, C.gpointer(w.asGTKWindow()))
|
||||||
w.SetMinSize(w.minWidth, w.minHeight)
|
w.SetMinSize(w.minWidth, w.minHeight)
|
||||||
w.SetMaxSize(w.maxWidth, w.maxHeight)
|
w.SetMaxSize(w.maxWidth, w.maxHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) Destroy() {
|
func (w *Window) Destroy() {
|
||||||
C.g_object_unref(C.gpointer(w.gtkWindow))
|
|
||||||
C.gtk_widget_destroy(w.asGTKWidget())
|
C.gtk_widget_destroy(w.asGTKWidget())
|
||||||
|
C.g_object_unref(C.gpointer(w.gtkWindow))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) Close() {
|
func (w *Window) Close() {
|
||||||
|
Loading…
Reference in New Issue
Block a user