示例#1
0
文件: gtk.go 项目: kayon/cef2go
func CreateWindow(title string, width int, height int) unsafe.Pointer {
	Logger.Println("CreateWindow")

	// Create window.
	window := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)

	// Default size.
	C.gtk_window_set_default_size(C.ToGtkWindow(window),
		C.gint(width), C.gint(height))

	// Center.
	C.gtk_window_set_position(C.ToGtkWindow(window), C.GTK_WIN_POS_CENTER)

	// Title.
	csTitle := C.CString(title)
	defer C.free(unsafe.Pointer(csTitle))
	C.gtk_window_set_title(C.ToGtkWindow(window), (*C.gchar)(csTitle))

	// TODO: focus
	// g_signal_connect(window, "focus", G_CALLBACK(&HandleFocus), NULL);

	// CEF requires a container. Embedding browser in a top
	// level window fails.
	vbox := C.gtk_vbox_new(0, 0)
	C.gtk_container_add(C.ToGtkContainer(window), vbox)

	// Show.
	C.gtk_widget_show_all(window)

	return unsafe.Pointer(vbox)
}
示例#2
0
func (s *sysData) center() {
	ret := make(chan struct{})
	defer close(ret)
	uitask <- func() {
		if C.gtk_widget_get_visible(s.widget) == C.FALSE {
			// hint to the WM to make it centered when it is shown again
			// thanks to Jasper in irc.gimp.net/#gtk+
			C.gtk_window_set_position(togtkwindow(s.widget), C.GTK_WIN_POS_CENTER)
		} else {
			var width, height C.gint

			s.resetposition()
			//we should be able to use gravity to simplify this, but it doesn't take effect immediately, and adding show calls does nothing (thanks Jasper in irc.gimp.net/#gtk+)
			C.gtk_window_get_size(togtkwindow(s.widget), &width, &height)
			C.gtk_window_move(togtkwindow(s.widget),
				(C.gdk_screen_width()/2)-(width/2),
				(C.gdk_screen_height()/2)-(width/2))
		}
		ret <- struct{}{}
	}
	<-ret
}
示例#3
0
文件: window.go 项目: twstrike/gotk3
// SetPosition is a wrapper around gtk_window_set_position().
func (v *Window) SetPosition(position WindowPosition) {
	C.gtk_window_set_position(v.native(), C.GtkWindowPosition(position))
}
示例#4
0
// see sysData.center()
func (s *sysData) resetposition() {
	C.gtk_window_set_position(togtkwindow(s.widget), C.GTK_WIN_POS_NONE)
}
示例#5
0
文件: linux_gtk.go 项目: axet/desktop
func gtk_window_set_position(p GtkWidget, t int) {
	C.gtk_window_set_position(Arg(p), C.int(t))
}