Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default window position #642

Open
Kangaroux opened this issue Dec 21, 2021 · 3 comments
Open

Set default window position #642

Kangaroux opened this issue Dec 21, 2021 · 3 comments
Labels
type: feature request Issue is a feature request

Comments

@Kangaroux
Copy link

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)
@leiless
Copy link

leiless commented Dec 22, 2021

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
Copy link

leiless commented Dec 22, 2021

@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()
}

@justjosias justjosias added the type: improvement Pull request is an improvement of an existing feature label Feb 9, 2022
@TCB13
Copy link
Contributor

TCB13 commented May 3, 2022

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);

@SteffenL SteffenL added type: feature request Issue is a feature request and removed type: improvement Pull request is an improvement of an existing feature labels Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request Issue is a feature request
Development

No branches or pull requests

5 participants