當前位置: 首頁>>代碼示例>>Golang>>正文


Golang keybind.Initialize函數代碼示例

本文整理匯總了Golang中github.com/BurntSushi/xgbutil/keybind.Initialize函數的典型用法代碼示例。如果您正苦於以下問題:Golang Initialize函數的具體用法?Golang Initialize怎麽用?Golang Initialize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Initialize函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: create

// create creates the window, initializes the keybind and mousebind packages
// and sets up the window to act like a real top-level client.
func (w *window) create() {
	keybind.Initialize(w.X)
	mousebind.Initialize(w.X)

	err := w.CreateChecked(w.X.RootWin(), 0, 0, flagWidth, flagHeight,
		xproto.CwBackPixel, 0xffffff)
	if err != nil {
		errLg.Fatalf("Could not create window: %s", err)
	}

	// Make the window close gracefully using the WM_DELETE_WINDOW protocol.
	w.WMGracefulClose(func(w *xwindow.Window) {
		xevent.Detach(w.X, w.Id)
		keybind.Detach(w.X, w.Id)
		mousebind.Detach(w.X, w.Id)
		w.Destroy()
		xevent.Quit(w.X)
	})

	// Set WM_STATE so it is interpreted as top-level and is mapped.
	err = icccm.WmStateSet(w.X, w.Id, &icccm.WmState{
		State: icccm.StateNormal,
	})
	if err != nil { // not a fatal error
		lg("Could not set WM_STATE: %s", err)
	}

	// _NET_WM_STATE = _NET_WM_STATE_NORMAL
	ewmh.WmStateSet(w.X, w.Id, []string{"_NET_WM_STATE_NORMAL"})

	// Set the name to something.
	w.nameSet("Decoding all images...")

	w.Map()
}
開發者ID:BurntSushi,項目名稱:imgv,代碼行數:37,代碼來源:win.go

示例2: NewDisplay

func NewDisplay(width, height, border, heading int, name string) (*Display, error) {
	d := new(Display)
	d.w = float64(width)
	d.h = float64(height)
	d.bord = float64(border)
	d.head = float64(heading)
	X, err := xgbutil.NewConn()
	if err != nil {
		return nil, err
	}
	keybind.Initialize(X)
	d.ximg = xgraphics.New(X, image.Rect(
		0,
		0,
		border*2+width,
		border*2+heading+height))
	err = d.ximg.CreatePixmap()
	if err != nil {
		return nil, err
	}
	painter := NewXimgPainter(d.ximg)
	d.gc = draw2d.NewGraphicContextWithPainter(d.ximg, painter)
	d.gc.Save()
	d.gc.SetStrokeColor(color.White)
	d.gc.SetFillColor(color.White)
	d.gc.Clear()
	d.wid = d.ximg.XShowExtra(name, true)
	d.x = X
	go func() {
		xevent.Main(X)
	}()
	return d, nil
}
開發者ID:stanim,項目名稱:display,代碼行數:33,代碼來源:display.go

示例3: run

func run() error {
	Xu, err := xgbutil.NewConn()
	if err != nil {
		return err
	}
	defer Xu.Conn().Close()
	keybind.Initialize(Xu)
	if err := randr.Init(Xu.Conn()); err != nil {
		return err
	}

	audio, err := newAudio(Xu)
	if err != nil {
		return err
	}
	defer audio.Close()

	brightness, err := newBrightness(Xu)
	if err != nil {
		return err
	}
	defer brightness.Close()

	xevent.Main(Xu)
	return nil
}
開發者ID:tv42,項目名稱:x11-media-keys,代碼行數:26,代碼來源:main.go

示例4: NewImage

// NewImage returns a new image canvas
// that draws to the given image.  The
// minimum point of the given image
// should probably be 0,0.
func NewImage(img draw.Image, name string) (*Canvas, error) {
	w := float64(img.Bounds().Max.X - img.Bounds().Min.X)
	h := float64(img.Bounds().Max.Y - img.Bounds().Min.Y)

	X, err := xgbutil.NewConn()
	if err != nil {
		return nil, err
	}
	keybind.Initialize(X)
	ximg := xgraphics.New(X, image.Rect(0, 0, int(w), int(h)))
	err = ximg.CreatePixmap()
	if err != nil {
		return nil, err
	}
	painter := NewPainter(ximg)
	gc := draw2d.NewGraphicContextWithPainter(ximg, painter)
	gc.SetDPI(dpi)
	gc.Scale(1, -1)
	gc.Translate(0, -h)

	wid := ximg.XShowExtra(name, true)
	go func() {
		xevent.Main(X)
	}()

	c := &Canvas{
		Canvas: vgimg.NewWith(vgimg.UseImageWithContext(img, gc)),
		x:      X,
		ximg:   ximg,
		wid:    wid,
	}
	vg.Initialize(c)
	return c, nil
}
開發者ID:nolenroyalty,項目名稱:bangarang,代碼行數:38,代碼來源:canvas.go

示例5: main

func main() {
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatalln(err)
	}

	// The message box uses the keybind module, so we must initialize it.
	keybind.Initialize(X)

	// Creating a new message prompt is as simple as supply an X connection,
	// a theme and a configuration. We use built in defaults here.
	msgPrompt := prompt.NewMessage(X,
		prompt.DefaultMessageTheme, prompt.DefaultMessageConfig)

	// Show maps the message prompt window.
	// If a duration is specified, the window does NOT acquire focus and
	// automatically disappears after the specified time.
	// If a duration is not specified (i.e., '0'), then the window is mapped,
	// and acquires focus. It does not disappear until it loses focus or when
	// the user hits the "confirm" or "cancel" keys (usually "enter" and
	// "escape").
	timeout := 2 * time.Second // or "0" for no timeout.
	msgPrompt.Show(xwindow.RootGeometry(X), "Hello, world!", timeout, hidden)

	xevent.Main(X)
}
開發者ID:pascience,項目名稱:foci,代碼行數:26,代碼來源:main.go

示例6: main

func main() {
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	keybind.Initialize(X) // call once before using keybind package

	// Read an example gopher image into a regular png image.
	img, _, err := image.Decode(bytes.NewBuffer(gopher.GopherPng()))
	if err != nil {
		log.Fatal(err)
	}

	// Now convert it into an X image.
	ximg := xgraphics.NewConvert(X, img)

	// Now show it in a new window.
	// We set the window title and tell the program to quit gracefully when
	// the window is closed.
	// There is also a convenience method, XShow, that requires no parameters.
	win := showImage(ximg, "The Go Gopher!", true)

	// Listen for key press events.
	win.Listen(xproto.EventMaskKeyPress)

	err = keybind.KeyPressFun(
		func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
			println("fullscreen!")
			err := ewmh.WmStateReq(X, win.Id, ewmh.StateToggle,
				"_NET_WM_STATE_FULLSCREEN")
			if err != nil {
				log.Fatal(err)
			}
		}).Connect(X, win.Id, "f", false)
	if err != nil {
		log.Fatal(err)
	}

	err = keybind.KeyPressFun(
		func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
			println("quit fullscreen!")
			err := ewmh.WmStateReq(X, win.Id, ewmh.StateToggle,
				"_NET_WM_STATE_FULLSCREEN")
			if err != nil {
				log.Fatal(err)
			}
		}).Connect(X, win.Id, "Escape", false)
	if err != nil {
		log.Fatal(err)
	}

	// If we don't block, the program will end and the window will disappear.
	// We could use a 'select{}' here, but xevent.Main will emit errors if
	// something went wrong, so use that instead.
	xevent.Main(X)
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:57,代碼來源:main.go

示例7: grabKeyboardAndMouse

func grabKeyboardAndMouse(m *Manager) {
	if m == nil {
		return
	}

	//go func() {
	X, err := xgbutil.NewConn()
	if err != nil {
		logger.Info("Get New Connection Failed:", err)
		return
	}
	keybind.Initialize(X)
	mousebind.Initialize(X)

	err = keybind.GrabKeyboard(X, X.RootWin())
	if err != nil {
		logger.Info("Grab Keyboard Failed:", err)
		return
	}

	grabAllMouseButton(X)

	xevent.ButtonPressFun(
		func(X *xgbutil.XUtil, e xevent.ButtonPressEvent) {
			dbus.Emit(m, "KeyReleaseEvent", "")
			ungrabAllMouseButton(X)
			keybind.UngrabKeyboard(X)
			logger.Info("Button Press Event")
			xevent.Quit(X)
		}).Connect(X, X.RootWin())

	xevent.KeyPressFun(
		func(X *xgbutil.XUtil, e xevent.KeyPressEvent) {
			value := parseKeyEnvent(X, e.State, e.Detail)
			pressKeyStr = value
			dbus.Emit(m, "KeyPressEvent", value)
		}).Connect(X, X.RootWin())

	xevent.KeyReleaseFun(
		func(X *xgbutil.XUtil, e xevent.KeyReleaseEvent) {
			if strings.ToLower(pressKeyStr) == "super_l" ||
				strings.ToLower(pressKeyStr) == "super_r" {
				pressKeyStr = "Super"
			}

			dbus.Emit(m, "KeyReleaseEvent", pressKeyStr)
			pressKeyStr = ""
			ungrabAllMouseButton(X)
			keybind.UngrabKeyboard(X)
			logger.Infof("Key: %s\n", pressKeyStr)
			xevent.Quit(X)
		}).Connect(X, X.RootWin())

	xevent.Main(X)
	//}()
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:56,代碼來源:grab.go

示例8: main

func main() {
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatalf("Could not connect to X: %v", err)
	}

	keybind.Initialize(X)
	keybind.KeyPressFun(
		func(X *xgbutil.XUtil, e xevent.KeyPressEvent) {
			fmt.Println("Key press!")
		}).Connect(X, X.RootWin(), "Mod4-j")

	xevent.Main(X)
}
開發者ID:droundy,項目名稱:xgbutil,代碼行數:14,代碼來源:tst_keypress.go

示例9: initEGL

func initEGL(controlCh *controlCh, width, height int) *platform.EGLState {
	X, err := xgbutil.NewConn()
	if err != nil {
		panic(err)
	}
	mousebind.Initialize(X)
	keybind.Initialize(X)
	xWindow := newWindow(controlCh, X, width, height)
	go xevent.Main(X)
	return xorg.Initialize(
		egl.NativeWindowType(uintptr(xWindow.Id)),
		xorg.DefaultConfigAttributes,
		xorg.DefaultContextAttributes,
	)
}
開發者ID:remogatto,項目名稱:egl-examples,代碼行數:15,代碼來源:init.go

示例10: initXUtil

func initXUtil() error {
	var err error

	if X, err = xgbutil.NewConn(); err != nil {
		fmt.Println("New XUtil Failed:", err)
		return err
	}

	if !initFlag {
		keybind.Initialize(X)
		initFlag = true
	}

	return nil
}
開發者ID:jouyouyun,項目名稱:XRecordGrab,代碼行數:15,代碼來源:grab.go

示例11: main

func main() {
	X, err := xgbutil.NewConn()
	fatal(err)

	keybind.Initialize(X)

	slct := prompt.NewSelect(X,
		prompt.DefaultSelectTheme, prompt.DefaultSelectConfig)

	// Create some artifical groups to use.
	artGroups := []prompt.SelectGroup{
		slct.NewStaticGroup("Group 1"),
		slct.NewStaticGroup("Group 2"),
		slct.NewStaticGroup("Group 3"),
		slct.NewStaticGroup("Group 4"),
		slct.NewStaticGroup("Group 5"),
	}

	// And now create some artificial items.
	items := []*item{
		newItem("andrew", 1), newItem("bruce", 2),
		newItem("kaitlyn", 3),
		newItem("cauchy", 4), newItem("plato", 1),
		newItem("platonic", 2),
		newItem("andrew gallant", 3),
		newItem("Andrew Gallant", 4), newItem("Andrew", 1),
		newItem("jim", 1), newItem("jimmy", 2),
		newItem("jimbo", 3),
	}

	groups := make([]*prompt.SelectGroupItem, len(artGroups))
	for i, artGroup := range artGroups {
		groups[i] = slct.AddGroup(artGroup)
	}
	for _, item := range items {
		item.promptItem = slct.AddChoice(item)
	}

	geom := headGeom(X)
	keybind.KeyPressFun(
		func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
			showGroups := newGroups(groups, items)
			slct.Show(geom, prompt.TabCompletePrefix, showGroups)
		}).Connect(X, X.RootWin(), selectActivate, true)

	println("Loaded...")
	xevent.Main(X)
}
開發者ID:dlintw,項目名稱:wingo,代碼行數:48,代碼來源:main.go

示例12: main

func main() {
	runtime.GOMAXPROCS(64)

	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	keybind.Initialize(X)

	font := loadFont("/usr/share/fonts/truetype/freefont/FreeMono.ttf")
	font.Color = xgraphics.BGRA{B: 0x00, G: 0xff, R: 0x00, A: 0xff}
	font.Size = 12.0

	ximage := xgraphics.New(X, image.Rect(0, 0, 300, 300))
	ximage.CreatePixmap()
	window, obscured := makeWindow(ximage)

	battery := batteryItem(font, 10, ximage, window)
	cpu := cpuItem(font, 30, ximage, window)
	memory := memoryItem(font, 50, ximage, window)
	before, after, quit := xevent.MainPing(X)
loop:
	for {
		select {
		case <-before:
			<-after
		case <-quit:
			break loop
		case text := <-battery.Text:
			if *obscured {
				continue loop
			}
			battery.update(text)
		case text := <-cpu.Text:
			if *obscured {
				continue loop
			}
			cpu.update(text)
		case text := <-memory.Text:
			if *obscured {
				continue loop
			}
			memory.update(text)
		}
	}
}
開發者ID:pointlander,項目名稱:csm,代碼行數:47,代碼來源:csm.go

示例13: main

func main() {
	// Connect to the X server using the DISPLAY environment variable.
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	// Anytime the keybind (mousebind) package is used, keybind.Initialize
	// *should* be called once. It isn't strictly necessary, but allows your
	// keybindings to persist even if the keyboard mapping is changed during
	// run-time. (Assuming you're using the xevent package's event loop.)
	// It also handles the case when your modifier map is changed.
	keybind.Initialize(X)

	// Create a new window. We will listen for key presses and translate them
	// only when this window is in focus. (Similar to how `xev` works.)
	win, err := xwindow.Generate(X)
	if err != nil {
		log.Fatalf("Could not generate a new window X id: %s", err)
	}
	win.Create(X.RootWin(), 0, 0, 500, 500, xproto.CwBackPixel, 0xffffffff)

	// Listen for Key{Press,Release} events.
	win.Listen(xproto.EventMaskKeyPress, xproto.EventMaskKeyRelease)

	// Map the window.
	win.Map()

	// Notice that we use xevent.KeyPressFun instead of keybind.KeyPressFun,
	// because we aren't trying to make a grab *and* because we want to listen
	// to *all* key press events, rather than just a particular key sequence
	// that has been pressed.
	xevent.KeyPressFun(
		func(X *xgbutil.XUtil, e xevent.KeyPressEvent) {
			// keybind.LookupString does the magic of implementing parts of
			// the X Keyboard Encoding to determine an english representation
			// of the modifiers/keycode tuple.
			// N.B. It's working for me, but probably isn't 100% correct in
			// all environments yet.
			log.Println("Key:", keybind.LookupString(X, e.State, e.Detail))
		}).Connect(X, win.Id)

	// Finally, start the main event loop. This will route any appropriate
	// KeyPressEvents to your callback function.
	log.Println("Program initialized. Start pressing keys!")
	xevent.Main(X)
}
開發者ID:droundy,項目名稱:xgbutil,代碼行數:47,代碼來源:main.go

示例14: main

func main() {
	X, _ := xgbutil.NewConn()

	keybind.Initialize(X)

	// should output "{"
	fmt.Println(string(keybind.LookupString(X, 1, 34)))
	// should output "["
	fmt.Println(string(keybind.LookupString(X, 0, 34)))

	fmt.Println("---------------------------------------")

	// should output "A"
	fmt.Println(string(keybind.LookupString(X, 1, 38)))
	// should output "a"
	fmt.Println(string(keybind.LookupString(X, 0, 38)))
}
開發者ID:droundy,項目名稱:xgbutil,代碼行數:17,代碼來源:tst_encoding.go

示例15: BindKeys

func BindKeys(keymap map[string]string) {
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}
	keybind.Initialize(X)
	for k, v := range keymap {
		v := v
		err = keybind.KeyPressFun(func(X *xgbutil.XUtil, e xevent.KeyPressEvent) {
			h.broadcast <- v
		}).Connect(X, X.RootWin(), k, true)
		if err != nil {
			log.Fatal(err)
		}
	}
	log.Println("Program initialized. Start pressing keys!")
	xevent.Main(X)
}
開發者ID:hobeone,項目名稱:keysocket-server,代碼行數:18,代碼來源:main.go


注:本文中的github.com/BurntSushi/xgbutil/keybind.Initialize函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。