mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
feature: add runtime func WindowSetAlwaysOnTop (#1442)
* feature: add runtime func WindowSetAlwaysOnTop * add runtime WindowSetUnalwaysOnTop * add JavaScript runtime method , docs update * WindowSetAlwaysOnTop(b bool) * Add AlwaysOnTop for MacOS Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
@@ -23,6 +23,7 @@ void Run(void*, const char* url);
|
||||
void SetTitle(void* ctx, const char *title);
|
||||
void Center(void* ctx);
|
||||
void SetSize(void* ctx, int width, int height);
|
||||
void SetAlwaysOnTop(void* ctx, int onTop);
|
||||
void SetMinSize(void* ctx, int width, int height);
|
||||
void SetMaxSize(void* ctx, int width, int height);
|
||||
void SetPosition(void* ctx, int x, int y);
|
||||
|
||||
@@ -95,6 +95,13 @@ void SetSize(void* inctx, int width, int height) {
|
||||
);
|
||||
}
|
||||
|
||||
void SetAlwaysOnTop(void* ctx, int onTop) {
|
||||
WailsContext *ctx = (__bridge WailsContext*) inctx;
|
||||
ON_MAIN_THREAD(
|
||||
[ctx SetAlwaysOnTop:onTop];
|
||||
);
|
||||
}
|
||||
|
||||
void SetMinSize(void* inctx, int width, int height) {
|
||||
WailsContext *ctx = (__bridge WailsContext*) inctx;
|
||||
ON_MAIN_THREAD(
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
- (void) SetMinSize:(int)minWidth :(int)minHeight;
|
||||
- (void) SetMaxSize:(int)maxWidth :(int)maxHeight;
|
||||
- (void) SetTitle:(NSString*)title;
|
||||
- (void) SetAlwaysOnTop:(int)onTop;
|
||||
- (void) Center;
|
||||
- (void) Fullscreen;
|
||||
- (void) UnFullscreen;
|
||||
|
||||
@@ -372,6 +372,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void) SetAlwaysOnTop:(int)onTop {
|
||||
if (onTop) {
|
||||
[self.mainWindow setLevel:NSStatusWindowLevel];
|
||||
} else {
|
||||
[self.mainWindow setLevel:NSNormalWindowLevel];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) ExecJS:(NSString*)script {
|
||||
[self.webview evaluateJavaScript:script completionHandler:nil];
|
||||
}
|
||||
|
||||
@@ -156,6 +156,9 @@ func (f *Frontend) Run(ctx context.Context) error {
|
||||
func (f *Frontend) WindowCenter() {
|
||||
f.mainWindow.Center()
|
||||
}
|
||||
func (f *Frontend) WindowSetAlwaysOnTop(onTop bool) {
|
||||
f.mainWindow.AlwaysOnTop(onTop)
|
||||
}
|
||||
|
||||
func (f *Frontend) WindowSetPosition(x, y int) {
|
||||
f.mainWindow.SetPosition(x, y)
|
||||
|
||||
@@ -147,6 +147,10 @@ func (w *Window) SetSize(width int, height int) {
|
||||
C.SetSize(w.context, C.int(width), C.int(height))
|
||||
}
|
||||
|
||||
func (w *Window) SetAlwaysOnTop(onTop bool) {
|
||||
C.SetAlwaysOnTop(w.context, bool2Cint(onTop))
|
||||
}
|
||||
|
||||
func (w *Window) SetTitle(title string) {
|
||||
t := C.CString(title)
|
||||
C.SetTitle(w.context, t)
|
||||
|
||||
@@ -144,6 +144,10 @@ func (f *Frontend) WindowCenter() {
|
||||
f.mainWindow.Center()
|
||||
}
|
||||
|
||||
func (f *Frontend) WindowSetAlwaysOnTop(b bool) {
|
||||
f.mainWindow.SetKeepAbove(b)
|
||||
}
|
||||
|
||||
func (f *Frontend) WindowSetPosition(x, y int) {
|
||||
f.mainWindow.SetPosition(x, y)
|
||||
}
|
||||
|
||||
@@ -181,6 +181,11 @@ func (f *Frontend) WindowCenter() {
|
||||
f.mainWindow.Center()
|
||||
}
|
||||
|
||||
func (f *Frontend) WindowSetAlwaysOnTop(b bool) {
|
||||
runtime.LockOSThread()
|
||||
f.mainWindow.SetAlwaysOnTop(b)
|
||||
}
|
||||
|
||||
func (f *Frontend) WindowSetPosition(x, y int) {
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
@@ -267,6 +267,13 @@ func (cba *ControlBase) SetPos(x, y int) {
|
||||
|
||||
w32.SetWindowPos(cba.hwnd, w32.HWND_TOP, int(workRect.Left)+x, int(workRect.Top)+y, 0, 0, w32.SWP_NOSIZE)
|
||||
}
|
||||
func (cba *ControlBase) SetAlwaysOnTop(b bool) {
|
||||
if b {
|
||||
w32.SetWindowPos(cba.hwnd, w32.HWND_TOPMOST, 0, 0, 0, 0, w32.SWP_NOSIZE|w32.SWP_NOMOVE)
|
||||
} else {
|
||||
w32.SetWindowPos(cba.hwnd, w32.HWND_NOTOPMOST, 0, 0, 0, 0, w32.SWP_NOSIZE|w32.SWP_NOMOVE)
|
||||
}
|
||||
}
|
||||
|
||||
func (cba *ControlBase) Pos() (x, y int) {
|
||||
rect := w32.GetWindowRect(cba.hwnd)
|
||||
|
||||
@@ -207,6 +207,9 @@ func (d *DevWebServer) WindowMinimise() {
|
||||
func (d *DevWebServer) WindowUnminimise() {
|
||||
d.desktopFrontend.WindowUnminimise()
|
||||
}
|
||||
func (d *DevWebServer) WindowSetAlwaysOnTop(b bool) {
|
||||
d.desktopFrontend.WindowSetAlwaysOnTop(b)
|
||||
}
|
||||
|
||||
func (d *DevWebServer) WindowSetPosition(x int, y int) {
|
||||
d.desktopFrontend.WindowSetPosition(x, y)
|
||||
|
||||
@@ -32,6 +32,12 @@ func (d *Dispatcher) processWindowMessage(message string, sender frontend.Fronte
|
||||
go sender.WindowSetLightTheme()
|
||||
case "DT":
|
||||
go sender.WindowSetDarkTheme()
|
||||
case "TP:0", "TP:1":
|
||||
if message[2:] == "TP:0" {
|
||||
go sender.WindowSetAlwaysOnTop(false)
|
||||
} else if message[2:] == "TP:1" {
|
||||
go sender.WindowSetAlwaysOnTop(true)
|
||||
}
|
||||
}
|
||||
case 'c':
|
||||
go sender.WindowCenter()
|
||||
|
||||
@@ -77,6 +77,7 @@ type Frontend interface {
|
||||
WindowUnmaximise()
|
||||
WindowMinimise()
|
||||
WindowUnminimise()
|
||||
WindowSetAlwaysOnTop(b bool)
|
||||
WindowSetPosition(x int, y int)
|
||||
WindowGetPosition() (int, int)
|
||||
WindowSetSize(width int, height int)
|
||||
|
||||
@@ -11,7 +11,7 @@ The electron alternative for Go
|
||||
/* jshint esversion: 9 */
|
||||
|
||||
|
||||
import {Call} from "./calls";
|
||||
import { Call } from "./calls";
|
||||
|
||||
export function WindowReload() {
|
||||
window.location.reload();
|
||||
@@ -114,6 +114,21 @@ export function WindowSetMinSize(width, height) {
|
||||
window.WailsInvoke('Wz:' + width + ':' + height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the window AlwaysOnTop or not on top
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export function WindowSetAlwaysOnTop(b) {
|
||||
|
||||
window.WailsInvoke('WATP:' + (b ? '1' : '0'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the Position of the window
|
||||
*
|
||||
@@ -209,7 +224,7 @@ export function WindowUnminimise() {
|
||||
* @param {number} A Alpha
|
||||
*/
|
||||
export function WindowSetRGBA(R, G, B, A) {
|
||||
let rgba = JSON.stringify({r: R || 0, g: G || 0, b: B || 0, a: A || 255});
|
||||
let rgba = JSON.stringify({ r: R || 0, g: G || 0, b: B || 0, a: A || 255 });
|
||||
window.WailsInvoke('Wr:' + rgba);
|
||||
}
|
||||
|
||||
|
||||
+809
-1
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
+1
@@ -5,6 +5,7 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "runtime",
|
||||
"version": "2.0.0",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
|
||||
@@ -18,4 +18,4 @@
|
||||
"npm-run-all": "^4.1.5",
|
||||
"svelte": "^3.42.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -92,6 +92,12 @@ func WindowSetMaxSize(ctx context.Context, width int, height int) {
|
||||
appFrontend.WindowSetMaxSize(width, height)
|
||||
}
|
||||
|
||||
// WindowSetAlwaysOnTop sets the window AlwaysOnTop or not on top
|
||||
func WindowSetAlwaysOnTop(ctx context.Context, b bool) {
|
||||
appFrontend := getFrontend(ctx)
|
||||
appFrontend.WindowSetAlwaysOnTop(b)
|
||||
}
|
||||
|
||||
// WindowSetPosition sets the position of the window
|
||||
func WindowSetPosition(ctx context.Context, x int, y int) {
|
||||
appFrontend := getFrontend(ctx)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user