diff --git a/internal/gui/app.go b/internal/gui/app.go index b185b7a49..3dee8eb0b 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -288,7 +288,10 @@ func Run(version string, showMain bool, link string) error { if runtime.GOOS == "windows" { h.main.OnWindowEvent(events.Windows.WebViewNavigationCompleted, func(*application.WindowEvent) { markReady() }) } else { - h.app.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(*application.ApplicationEvent) { markReady() }) + h.app.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(*application.ApplicationEvent) { + plainTitlebar(h.main) // Linux: the page's header is the title bar + markReady() + }) } if showMain { h.whenReady(func() { h.ShowMain("") }) diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index e47813f55..b2de2e4da 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -137,7 +137,11 @@ code { font: 11.5px var(--code); } body.window.mac .top { padding-left: 96px; height: 50px; padding-top: 2px; } /* the traffic lights centre 25.75pt from the top, not 25 */ body.window.mac .seg { top: calc(50% + 1px); } /* 50% centres in the padding box; the 2px top padding puts the flex row a pixel lower */ .brand { display: flex; align-items: center; gap: 6px; font-weight: 600; letter-spacing: .01em; } -body.window:not(.mac) .brand { display: none; } /* the title bar above already shows the icon and the name */ +body.window:not(.mac):not(.linux) .brand { display: none; } /* Windows' title bar above already shows the icon and the name */ +/* Linux: the header is the title bar, so it closes the window too — round, + as GNOME draws its close button, and set a little apart from the icons */ +.icon.winclose { align-self: center; width: 22px; height: 22px; margin-left: 8px; border-radius: 50%; background: var(--pill); color: var(--fg-2); } +.icon.winclose:hover { background: color-mix(in srgb, var(--fg) 12%, transparent); } /* the magpie flaps, flicks its tail and bobs when the window opens and on hover. It moves in pieces cut from the logo, and is drawn whole at rest, so the cuts never show. */ diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index eee174961..4d94159e3 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -4,12 +4,15 @@ const $$ = (s) => document.querySelectorAll(s); const params = new URLSearchParams(location.search); const mode = params.get("mode") || "window"; document.body.classList.add(mode); -// Only the Mac window draws its title bar inside the page (the traffic lights). +// The Mac window draws its title bar inside the page (the traffic lights); +// on Linux the page's header is the whole title bar (plainTitlebar), so it +// has the name, the close button and a double-click to maximise. if (/^Mac/.test(navigator.platform)) document.body.classList.add("mac"); +if (/^Linux/.test(navigator.platform)) document.body.classList.add("linux"); // The window is dragged by its header, and only where the header says so // (--wails-draggable), so the tabs and buttons in it stay plain clicks. // Outside the app — a browser on the gateway's page — there is no runtime. -if (mode === "window") import("/wails/runtime.js").catch(() => {}); +const winRuntime = mode === "window" ? import("/wails/runtime.js").catch(() => null) : Promise.resolve(null); if (params.get("theme")) document.documentElement.dataset.theme = params.get("theme"); // the saved language and theme from boot.js, so the first paint is in them if (window.bootPrefs) { @@ -4114,8 +4117,13 @@ $("#sync").onclick = async () => { $("#open").onclick = () => api("window/main", {}); $("#openMain").onclick = () => api("window/main", {}); $("#quit").onclick = () => api("window/quit", {}); +$("#winclose").onclick = () => winRuntime.then((w) => w?.Window.Close()); // hides it: the tray stays +$(".top").addEventListener("dblclick", (e) => { + if (document.body.classList.contains("linux") && !e.target.closest("button, nav")) winRuntime.then((w) => w?.Window.ToggleMaximise()); +}); if (mode === "window") { $("#open").remove(); $("#openMain").remove(); $("#quit").remove(); } else { $("#nav").remove(); } +if (mode !== "window" || !document.body.classList.contains("linux")) $("#winclose").remove(); // Config files may change underneath us (another magpie, an editor); reload when // the panel comes back into view. diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index 1fd9ad777..89beeb54e 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -37,6 +37,9 @@ + diff --git a/internal/gui/titlebar_gtk3.go b/internal/gui/titlebar_gtk3.go new file mode 100644 index 000000000..4329b35da --- /dev/null +++ b/internal/gui/titlebar_gtk3.go @@ -0,0 +1,31 @@ +//go:build linux && cgo && gtk3 + +package gui + +/* +#cgo pkg-config: gtk+-3.0 +#include + +static void plain_titlebar(void *w) { + GtkWidget *bar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_set_no_show_all(bar, TRUE); // kept hidden when the window shows all it holds + gtk_window_set_titlebar(GTK_WINDOW(w), bar); +} +*/ +import "C" + +import "github.com/wailsapp/wails/v3/pkg/application" + +// plainTitlebar takes the system's title bar off a window whose page has a +// header of its own. GNOME draws one over it, the name and a close button +// stacked on the tabs; frameless, the window would lose its shadow, rounded +// corners and the edges it is resized by. A hidden widget as its titlebar +// keeps all those and shows no bar: the page's header drags it, and has the +// close button. +func plainTitlebar(w *application.WebviewWindow) { + application.InvokeSync(func() { + if p := w.NativeWindow(); p != nil { + C.plain_titlebar(p) + } + }) +} diff --git a/internal/gui/titlebar_gtk4.go b/internal/gui/titlebar_gtk4.go new file mode 100644 index 000000000..9c5226e65 --- /dev/null +++ b/internal/gui/titlebar_gtk4.go @@ -0,0 +1,31 @@ +//go:build linux && cgo && !gtk3 + +package gui + +/* +#cgo pkg-config: gtk4 +#include + +static void plain_titlebar(void *w) { + GtkWidget *bar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_set_visible(bar, FALSE); + gtk_window_set_titlebar(GTK_WINDOW(w), bar); +} +*/ +import "C" + +import "github.com/wailsapp/wails/v3/pkg/application" + +// plainTitlebar takes the system's title bar off a window whose page has a +// header of its own. GNOME draws one over it, the name and a close button +// stacked on the tabs; frameless, the window would lose its shadow, rounded +// corners and the edges it is resized by. A hidden widget as its titlebar +// keeps all those and shows no bar: the page's header drags it, and has the +// close button. +func plainTitlebar(w *application.WebviewWindow) { + application.InvokeSync(func() { + if p := w.NativeWindow(); p != nil { + C.plain_titlebar(p) + } + }) +} diff --git a/internal/gui/titlebar_other.go b/internal/gui/titlebar_other.go new file mode 100644 index 000000000..287ecbd5e --- /dev/null +++ b/internal/gui/titlebar_other.go @@ -0,0 +1,9 @@ +//go:build !linux || !cgo + +package gui + +import "github.com/wailsapp/wails/v3/pkg/application" + +// plainTitlebar: macOS insets the traffic lights into the page's header +// (MacTitleBarHiddenInset) and Windows keeps its own title bar. +func plainTitlebar(*application.WebviewWindow) {}