webview icon indicating copy to clipboard operation
webview copied to clipboard

Set default window position

Open Kangaroux opened this issue 4 years ago • 5 comments

It would be great to be able to specify the window's coordinates when it first is created.

  • Absolute coordinates (x, y)
  • Center window
  • Don't care (let the window manager decide)

Kangaroux avatar Dec 21 '21 19:12 Kangaroux

Upvote, please consider implementing this feature.

https://stackoverflow.com/questions/17908584/how-to-set-the-gtk-window-to-the-center-of-screen/35144125#35144125 might be helpful.

see: #129 #27

leiless avatar Dec 22 '21 08:12 leiless

@zserge, with the following code, and in Ubuntu 20.04.3 LTS, libwebkit2gtk-4.0-37 version 2.34.1 The window always appeared in the top-left of the screen.

package main

import (
	"fmt"
	"github.com/webview/webview"
)

func main() {
	w := webview.New(true)
	defer w.Destroy()
	w.SetTitle("Choices")
	w.SetSize(300, 60, webview.HintNone)

	var count uint
	if err := w.Bind("btnClicked", func() {
		fmt.Printf("Button click count: %v\n", count)
		count++
	}); err != nil {
		panic(err)
	}

	w.Navigate(`data:text/html,
		<!doctype html>
		<html>
			<body>
				<button onclick="btnClicked()">AA</button>
				<button onclick="btnClicked()">BB</button>
				<button onclick="btnClicked()">CC</button>
			</body>
		</html>`)

	w.Run()
}

leiless avatar Dec 22 '21 09:12 leiless

Here is an example on how to center the window under Windows and C++:


    // Create the webview
    webview::webview w(false, nullptr);
    w.set_title("Test");
    w.set_size(980, 650, WEBVIEW_HINT_NONE);
    w.set_size(585, 550, WEBVIEW_HINT_MIN);

    // Center
    HWND hwndApp = static_cast<HWND>(w.window());
    HWND hwndScreen = GetDesktopWindow();  
    RECT  rectScreen;      
    GetWindowRect(hwndScreen, &rectScreen);      
    int ConsolePosX = ((rectScreen.right - rectScreen.left) / 2 - 1000 /2 );
    int ConsolePosY = ((rectScreen.bottom - rectScreen.top)/ 2 - 500 /2 );   
    SetWindowPos(hwndApp, NULL, ConsolePosX, ConsolePosY,0,0, SWP_SHOWWINDOW || SWP_NOSIZE);

TCB13 avatar May 03 '22 23:05 TCB13