diff --git a/v3/internal/runtime/desktop/api/event_types.js b/v3/internal/runtime/desktop/api/event_types.js index f130789a2..e2a7857e3 100644 --- a/v3/internal/runtime/desktop/api/event_types.js +++ b/v3/internal/runtime/desktop/api/event_types.js @@ -147,9 +147,6 @@ export const EventTypes = { WindowFileDraggingPerformed: "mac:WindowFileDraggingPerformed", WindowFileDraggingExited: "mac:WindowFileDraggingExited", }, - Linux: { - SystemThemeChanged: "linux:SystemThemeChanged", -}, Common: { ApplicationStarted: "common:ApplicationStarted", WindowMaximise: "common:WindowMaximise", diff --git a/v3/pkg/application/application_linux.go b/v3/pkg/application/application_linux.go index 0b7d268a3..17dc6a7cd 100644 --- a/v3/pkg/application/application_linux.go +++ b/v3/pkg/application/application_linux.go @@ -3,10 +3,13 @@ package application import ( + "fmt" "log" "os" "strings" "sync" + + "github.com/wailsapp/wails/v3/pkg/events" ) func init() { @@ -100,12 +103,10 @@ func (m *linuxApp) run() error { // Add a hook to the ApplicationDidFinishLaunching event // FIXME: add Wails specific events - i.e. Shouldn't platform specific ones be translated to Wails events? - //m.parent.On(events.Mac.ApplicationDidFinishLaunching, func(evt *Event) { - // // Do we need to do anything now? - // fmt.Println("events.Mac.ApplicationDidFinishLaunching received!") - //}) - - m.setupCommonEvents() + m.parent.On(events.Mac.ApplicationDidFinishLaunching, func(evt *Event) { + // Do we need to do anything now? + fmt.Println("events.Mac.ApplicationDidFinishLaunching received!") + }) return appRun(m.application) } diff --git a/v3/pkg/application/events_common_linux.go b/v3/pkg/application/events_common_linux.go deleted file mode 100644 index bafe8379d..000000000 --- a/v3/pkg/application/events_common_linux.go +++ /dev/null @@ -1,20 +0,0 @@ -//go:build linux - -package application - -import "github.com/wailsapp/wails/v3/pkg/events" - -var commonApplicationEventMap = map[events.ApplicationEventType]events.ApplicationEventType{ - events.Linux.SystemThemeChanged: events.Common.ThemeChanged, -} - -func (m *linuxApp) setupCommonEvents() { - for sourceEvent, targetEvent := range commonApplicationEventMap { - sourceEvent := sourceEvent - targetEvent := targetEvent - m.parent.On(sourceEvent, func(event *Event) { - event.Id = uint(targetEvent) - applicationEvents <- event - }) - } -} diff --git a/v3/pkg/events/events.go b/v3/pkg/events/events.go index d674ea0e6..fd0134f78 100644 --- a/v3/pkg/events/events.go +++ b/v3/pkg/events/events.go @@ -33,25 +33,25 @@ type commonEvents struct { func newCommonEvents() commonEvents { return commonEvents{ - ApplicationStarted: 1168, - WindowMaximise: 1169, - WindowUnMaximise: 1170, - WindowFullscreen: 1171, - WindowUnFullscreen: 1172, - WindowRestore: 1173, - WindowMinimise: 1174, - WindowUnMinimise: 1175, - WindowClosing: 1176, - WindowZoom: 1177, - WindowZoomIn: 1178, - WindowZoomOut: 1179, - WindowZoomReset: 1180, - WindowFocus: 1181, - WindowLostFocus: 1182, - WindowShow: 1183, - WindowHide: 1184, - WindowDPIChanged: 1185, - ThemeChanged: 1186, + ApplicationStarted: 1167, + WindowMaximise: 1168, + WindowUnMaximise: 1169, + WindowFullscreen: 1170, + WindowUnFullscreen: 1171, + WindowRestore: 1172, + WindowMinimise: 1173, + WindowUnMinimise: 1174, + WindowClosing: 1175, + WindowZoom: 1176, + WindowZoomIn: 1177, + WindowZoomOut: 1178, + WindowZoomReset: 1179, + WindowFocus: 1180, + WindowLostFocus: 1181, + WindowShow: 1182, + WindowHide: 1183, + WindowDPIChanged: 1184, + ThemeChanged: 1185, } } @@ -311,18 +311,6 @@ func newMacEvents() macEvents { } } -var Linux = newLinuxEvents() - -type linuxEvents struct { - SystemThemeChanged ApplicationEventType -} - -func newLinuxEvents() linuxEvents { - return linuxEvents{ - SystemThemeChanged: 1167, - } -} - var Windows = newWindowsEvents() type windowsEvents struct { @@ -521,23 +509,23 @@ var eventToJS = map[uint]string{ 1164: "windows:WindowClose", 1165: "windows:WindowSetFocus", 1166: "windows:WindowKillFocus", - 1168: "common:ApplicationStarted", - 1169: "common:WindowMaximise", - 1170: "common:WindowUnMaximise", - 1171: "common:WindowFullscreen", - 1172: "common:WindowUnFullscreen", - 1173: "common:WindowRestore", - 1174: "common:WindowMinimise", - 1175: "common:WindowUnMinimise", - 1176: "common:WindowClosing", - 1177: "common:WindowZoom", - 1178: "common:WindowZoomIn", - 1179: "common:WindowZoomOut", - 1180: "common:WindowZoomReset", - 1181: "common:WindowFocus", - 1182: "common:WindowLostFocus", - 1183: "common:WindowShow", - 1184: "common:WindowHide", - 1185: "common:WindowDPIChanged", - 1186: "common:ThemeChanged", + 1167: "common:ApplicationStarted", + 1168: "common:WindowMaximise", + 1169: "common:WindowUnMaximise", + 1170: "common:WindowFullscreen", + 1171: "common:WindowUnFullscreen", + 1172: "common:WindowRestore", + 1173: "common:WindowMinimise", + 1174: "common:WindowUnMinimise", + 1175: "common:WindowClosing", + 1176: "common:WindowZoom", + 1177: "common:WindowZoomIn", + 1178: "common:WindowZoomOut", + 1179: "common:WindowZoomReset", + 1180: "common:WindowFocus", + 1181: "common:WindowLostFocus", + 1182: "common:WindowShow", + 1183: "common:WindowHide", + 1184: "common:WindowDPIChanged", + 1185: "common:ThemeChanged", } diff --git a/v3/pkg/events/events.txt b/v3/pkg/events/events.txt index 2f724e7d4..288714acf 100644 --- a/v3/pkg/events/events.txt +++ b/v3/pkg/events/events.txt @@ -141,7 +141,6 @@ windows:WindowUnMinimise windows:WindowClose windows:WindowSetFocus windows:WindowKillFocus -linux:SystemThemeChanged common:ApplicationStarted common:WindowMaximise common:WindowUnMaximise diff --git a/v3/pkg/events/events_linux.go b/v3/pkg/events/events_linux.go deleted file mode 100644 index a7bc3b1fc..000000000 --- a/v3/pkg/events/events_linux.go +++ /dev/null @@ -1,21 +0,0 @@ -//go:build linux - -package events - -/* -#include "events_linux.h" -#include -#include - -bool hasListener[MAX_EVENTS] = {false}; - -void registerListener(unsigned int event) { - hasListener[event] = true; -} - -bool hasListeners(unsigned int event) { - return hasListener[event]; -} - -*/ -import "C" diff --git a/v3/pkg/events/events_linux.h b/v3/pkg/events/events_linux.h deleted file mode 100644 index 58aa558ba..000000000 --- a/v3/pkg/events/events_linux.h +++ /dev/null @@ -1,14 +0,0 @@ -//go:build linux - -#ifndef _events_linux_h -#define _events_linux_h - -extern void processApplicationEvent(unsigned int, void* data); -extern void processWindowEvent(unsigned int, unsigned int); - -#define EventSystemThemeChanged 1167 - -#define MAX_EVENTS 2 - - -#endif \ No newline at end of file diff --git a/v3/tasks/events/generate.go b/v3/tasks/events/generate.go index 82ba932aa..970f8b3a9 100644 --- a/v3/tasks/events/generate.go +++ b/v3/tasks/events/generate.go @@ -36,16 +36,6 @@ func newMacEvents() macEvents { $$MACEVENTSVALUES } } -var Linux = newLinuxEvents() - -type linuxEvents struct { -$$LINUXEVENTSDECL} - -func newLinuxEvents() linuxEvents { - return linuxEvents{ -$$LINUXEVENTSVALUES } -} - var Windows = newWindowsEvents() type windowsEvents struct { @@ -65,27 +55,15 @@ $$EVENTTOJS} ` -var eventsDarwinH = `//go:build darwin +var eventsH = `//go:build darwin -#ifndef _events_darwin_h -#define _events_darwin_h +#ifndef _events_h +#define _events_h extern void processApplicationEvent(unsigned int, void* data); extern void processWindowEvent(unsigned int, unsigned int); -$$CDARWINHEADEREVENTS - -#endif` - -var eventsLinuxH = `//go:build linux - -#ifndef _events_linux_h -#define _events_linux_h - -extern void processApplicationEvent(unsigned int, void* data); -extern void processWindowEvent(unsigned int, unsigned int); - -$$CLINUXHEADEREVENTS +$$CHEADEREVENTS #endif` @@ -95,8 +73,6 @@ export const EventTypes = { $$WINDOWSJSEVENTS }, Mac: { $$MACJSEVENTS }, - Linux: { -$$LINUXJSEVENTS}, Common: { $$COMMONJSEVENTS }, }; @@ -111,7 +87,7 @@ func main() { macEventsDecl := bytes.NewBufferString("") macEventsValues := bytes.NewBufferString("") - cDarwinHeaderEvents := bytes.NewBufferString("") + cHeaderEvents := bytes.NewBufferString("") windowDelegateEvents := bytes.NewBufferString("") applicationDelegateEvents := bytes.NewBufferString("") webviewDelegateEvents := bytes.NewBufferString("") @@ -128,14 +104,8 @@ func main() { eventToJS := bytes.NewBufferString("") - linuxEventsDecl := bytes.NewBufferString("") - linuxEventsValues := bytes.NewBufferString("") - linuxJSEvents := bytes.NewBufferString("") - cLinuxHeaderEvents := bytes.NewBufferString("") - var id int var maxMacEvents int - var maxLinuxEvents int var line []byte // Loop over each line in the file for id, line = range bytes.Split(eventNames, []byte{'\n'}) { @@ -165,22 +135,6 @@ func main() { // Add to buffer switch platform { - case "linux": - eventType := "ApplicationEventType" - if strings.HasPrefix(event, "Window") { - eventType = "WindowEventType" - } - if strings.HasPrefix(event, "WebView") { - eventType = "WindowEventType" - } - cLinuxHeaderEvents.WriteString("#define Event" + eventTitle + " " + strconv.Itoa(id) + "\n") - linuxEventsDecl.WriteString("\t" + eventTitle + " " + eventType + "\n") - linuxEventsValues.WriteString("\t\t" + event + ": " + strconv.Itoa(id) + ",\n") - linuxJSEvents.WriteString("\t\t" + event + ": \"" + strings.TrimSpace(string(line)) + "\",\n") - maxLinuxEvents++ - if ignoreEvent { - continue - } case "mac": eventType := "ApplicationEventType" if strings.HasPrefix(event, "Window") { @@ -192,9 +146,9 @@ func main() { macEventsDecl.WriteString("\t" + eventTitle + " " + eventType + "\n") macEventsValues.WriteString("\t\t" + event + ": " + strconv.Itoa(id) + ",\n") macJSEvents.WriteString("\t\t" + event + ": \"" + strings.TrimSpace(string(line)) + "\",\n") - cDarwinHeaderEvents.WriteString("#define Event" + eventTitle + " " + strconv.Itoa(id) + "\n") + cHeaderEvents.WriteString("#define Event" + eventTitle + " " + strconv.Itoa(id) + "\n") eventToJS.WriteString("\t" + strconv.Itoa(id) + ": \"" + strings.TrimSpace(string(line)) + "\",\n") - maxMacEvents++ + maxMacEvents = id if ignoreEvent { continue } @@ -256,13 +210,10 @@ func main() { } } - cLinuxHeaderEvents.WriteString("\n#define MAX_EVENTS " + strconv.Itoa(maxLinuxEvents+1) + "\n") - cDarwinHeaderEvents.WriteString("\n#define MAX_EVENTS " + strconv.Itoa(maxMacEvents+1) + "\n") + cHeaderEvents.WriteString("\n#define MAX_EVENTS " + strconv.Itoa(maxMacEvents+1) + "\n") // Save the eventsGo template substituting the values and decls templateToWrite := strings.ReplaceAll(eventsGo, "$$MACEVENTSDECL", macEventsDecl.String()) - templateToWrite = strings.ReplaceAll(templateToWrite, "$$LINUXEVENTSDECL", linuxEventsDecl.String()) - templateToWrite = strings.ReplaceAll(templateToWrite, "$$LINUXEVENTSVALUES", linuxEventsValues.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$MACEVENTSVALUES", macEventsValues.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSEVENTSDECL", windowsEventsDecl.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSEVENTSVALUES", windowsEventsValues.String()) @@ -277,23 +228,15 @@ func main() { // Save the eventsJS template substituting the values and decls templateToWrite = strings.ReplaceAll(eventsJS, "$$MACJSEVENTS", macJSEvents.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSJSEVENTS", windowsJSEvents.String()) - templateToWrite = strings.ReplaceAll(templateToWrite, "$$LINUXJSEVENTS", linuxJSEvents.String()) templateToWrite = strings.ReplaceAll(templateToWrite, "$$COMMONJSEVENTS", commonJSEvents.String()) err = os.WriteFile("../../internal/runtime/desktop/api/event_types.js", []byte(templateToWrite), 0644) if err != nil { panic(err) } - // Save the eventsDarwinH template substituting the values and decls - templateToWrite = strings.ReplaceAll(eventsDarwinH, "$$CDARWINHEADEREVENTS", cDarwinHeaderEvents.String()) - err = os.WriteFile("../../pkg/events/events_darwin.h", []byte(templateToWrite), 0644) - if err != nil { - panic(err) - } - - // Save the eventsDarwinH template substituting the values and decls - templateToWrite = strings.ReplaceAll(eventsLinuxH, "$$CLINUXHEADEREVENTS", cLinuxHeaderEvents.String()) - err = os.WriteFile("../../pkg/events/events_linux.h", []byte(templateToWrite), 0644) + // Save the eventsH template substituting the values and decls + templateToWrite = strings.ReplaceAll(eventsH, "$$CHEADEREVENTS", cHeaderEvents.String()) + err = os.WriteFile("../../pkg/events/events.h", []byte(templateToWrite), 0644) if err != nil { panic(err) }