func (k *Keyboard) initLEDWatch() { C.gtk_init(nil, nil) win := C.gdk_x11_get_default_xdisplay() var state C.uint var lstate byte for range time.Tick(16 * time.Millisecond) { lstate = 0 // Caps: 0, Num: 1, Scroll: 2 C.XkbGetIndicatorState(win, C.XkbUseCoreKbd, &state) if 0x4&state != 0 { lstate += 0x4 } if 0x2&state != 0 { lstate += 1 } if 0x1&state != 0 { lstate += 2 } // Num: 0, Caps: 1, Scroll: 2 k.device0.Control(0x21, 0x09, 0x0200, 0, []byte{lstate}) } }
func startGui(width, height int, title string, port int) { C.gtk_init(nil, nil) //gtk.Init(nil) window := C.window window = C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) C.gtk_window_set_title(C.to_GtkWindow(window), C.to_gcharptr(C.CString(title))) C.connect_destroy(window) vbox := C.gtk_hbox_new(0, 1) C.webview = C._new_webkit() C.gtk_container_add(C.to_GtkContainer(vbox), C.webview) C.loadUri(C.webview, C.to_gcharptr(C.CString(fmt.Sprintf("http://127.0.0.1:%d", port)))) C.gtk_container_add(C.to_GtkContainer(window), vbox) C.gtk_widget_set_size_request(window, C.gint(width), C.gint(height)) C.gtk_widget_show(vbox) C.gtk_widget_show(window) //Window.ShowAll() C.gtk_widget_show(C.webview) /* This only matters if proxy is stupid! proxy := os.Getenv("HTTP_PROXY") if len(proxy) > 0 { ptr := C.CString(uri) C.proxyshit(ptr) C.free(ptr) } */ C.gtk_main() //gtk.GtkMain() }
func Init(args []string) { argc := C.int(len(args)) c_args := make([]*C.char, argc) for i, arg := range args { c_args[i] = C.CString(arg) } p_c_args := &c_args[0] C.gtk_init(&argc, &p_c_args) for i, _ := range c_args { C.free(unsafe.Pointer(c_args[i])) } }
// GTKInit call gtk_init with the given program arguments. func GTKInit(args []string) { // Convert the args to C args. argc := C.int(len(args)) argv := make([]*C.char, argc) // Convert each argument. for i := 0; i < len(args); i++ { argv[i] = C.CString(args[i]) defer C.free(unsafe.Pointer(argv[i])) } // Init GTK. argvPtr := (**C.char)(unsafe.Pointer(&argv[0])) C.gtk_init(&argc, &argvPtr) }
func (window *GTKWindow) Create(width uint, height uint, title string) bool { C.gtk_init(nil, nil) gtk_window := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) C.gtk_window_set_title((*C.GtkWindow)(unsafe.Pointer(gtk_window)), (*C.gchar)(C.CString(title))) f := func() { window.destroy = true } r := func() { window.render = true } //g_signal_connect (G_OBJECT (canvas), "expose-event", G_CALLBACK (expose_cb), NULL); C.GtkSetEvent((*C.gpointer)(unsafe.Pointer(gtk_window)), C.CString("destroy"), unsafe.Pointer(&f)) C.GtkSetEvent((*C.gpointer)(unsafe.Pointer(gtk_window)), C.CString("expose-event"), unsafe.Pointer(&r)) C.gtk_widget_show(gtk_window) return true }
func Init() { C.gtk_init(nil, nil) }
func main() { // init gtk var argc C.int C.gtk_init(&argc, nil) // root window win := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) connect(win, "destroy", func() { // quit gtk when window is closed C.gtk_main_quit() }) // root grid grid := C.gtk_grid_new() C.gtk_container_add(asContainer(win), grid) // webview container pages := C.gtk_notebook_new() C.gtk_grid_attach(asGrid(grid), pages, 0, 0, 1, 1) C.gtk_widget_set_vexpand(pages, C.gtk_true()) C.gtk_widget_set_hexpand(pages, C.gtk_true()) C.gtk_notebook_set_tab_pos(asNotebook(pages), C.GTK_POS_LEFT) // new view constructor var newView func() *View newView = func() *View { view := NewView() label := C.gtk_label_new(nil) C.gtk_label_set_use_markup(asLabel(label), C.gtk_true()) C.gtk_misc_set_alignment(asMisc(label), 0, 0.5) C.gtk_notebook_append_page(asNotebook(pages), view.Widget, label) // new view is requested connect(view.View, "create", func() *C.GtkWidget { return newView().Widget }) // set tab label to page title connect(view.View, "notify::title", func() { var title string // trim long title for _, r := range fromGStr(C.webkit_web_view_get_title(view.View)) { if len(title) > 32 { break } title += string(r) } C.gtk_label_set_markup(asLabel(label), toGStr(fmt.Sprintf(`<span font="10">%s</span>`, title))) }) return view } // first view view := newView() C.webkit_web_view_load_uri(view.View, toGStr("http://www.bilibili.tv")) // show window and run C.gtk_widget_show_all(win) C.gtk_main() }
func gtk_init() { C.gtk_init(0, 0) }
func Initialize() { C.gtk_init(nil, nil) C.ConnectTerminationSignal() }