本文整理汇总了Golang中github.com/BurntSushi/xgbutil/keybind.Initialize函数的典型用法代码示例。如果您正苦于以下问题:Golang Initialize函数的具体用法?Golang Initialize怎么用?Golang Initialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Initialize函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: main
func main() {
X, err := xgbutil.NewConn()
if err != nil {
log.Fatal(err)
}
keybind.Initialize(X)
currentuser, err := user.Current()
if err != nil {
log.Fatal(err)
}
configfile := currentuser.HomeDir + "/.config/hotkeys.conf.json"
watcher, err := inotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
err = watcher.AddWatch(configfile, inotify.IN_CLOSE_WRITE)
if err != nil {
log.Fatal(err)
}
go func() {
for {
select {
case ev := <-watcher.Event:
log.Println(ev)
err := bindall(configfile, X)
if err != nil {
log.Println(err)
continue
}
case err := <-watcher.Error:
log.Println("error:", err)
}
}
}()
err = bindall(configfile, X)
if err != nil {
log.Panicln(err)
}
xevent.Main(X)
}
开发者ID:jeromenerf,项目名称:hotkeys,代码行数:44,代码来源:hotkeys.go
示例17: StartKeyBinding
func StartKeyBinding() error {
var err error
X, err = xgbutil.NewConn()
if err != nil {
return err
}
keybind.Initialize(X)
initXRecord()
initSystemIdDescList()
//initMediaIdDescList()
initWindowIdDescList()
initWorkspaceIdDescList()
grabKeyPairs(getSystemKeyPairs(), true)
grabKeyPairs(getCustomKeyPairs(), true)
grabMediaKeys(true)
return nil
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:20,代码来源:main.go
示例18: newWindow
// newWindow creates the window, initializes the keybind and mousebind packages
// and sets up the window to act like a real top-level client.
func newWindow(X *xgbutil.XUtil) *Window {
w, err := xwindow.Generate(X)
if err != nil {
errLg.Fatalf("Could not create window: %s", err)
}
keybind.Initialize(w.X)
mousebind.Initialize(w.X)
err = w.CreateChecked(w.X.RootWin(), 0, 0, 600, 600, 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 {
lg("Could not set WM_STATE: %s", err)
}
// _NET_WM_STATE = _NET_WM_STATE_NORMAL
// not needed because we we set FS later anyway?
//ewmh.WmStateSet(w.X, w.Id, []string{"_NET_WM_STATE_NORMAL"})
w.Map()
err = ewmh.WmStateReq(w.X, w.Id, ewmh.StateToggle, "_NET_WM_STATE_FULLSCREEN")
if err != nil {
lg("Failed to go FullScreen:", err)
}
return &Window{w}
}
开发者ID:uriel,项目名称:vimg,代码行数:43,代码来源:win.go
示例19: main
func main() {
X, err := xgbutil.NewConn()
fatal(err)
keybind.Initialize(X)
cycle := prompt.NewCycle(X,
prompt.DefaultCycleTheme, prompt.DefaultCycleConfig)
clients, err := ewmh.ClientListStackingGet(X)
fatal(err)
items := make([]*prompt.CycleItem, 0)
for i := len(clients) - 1; i >= 0; i-- {
item := cycle.AddChoice(newWindow(X, cycle.Id(), clients[i]))
items = append(items, item)
}
keyHandlers(X, cycle, items)
println("Loaded...")
xevent.Main(X)
}
开发者ID:cshapeshifter,项目名称:wingo,代码行数:22,代码来源:main.go
示例20: 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) (*XImgCanvas, 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 := NewXimgPainter(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 := &XImgCanvas{
gc: gc,
w: vg.Inches(w / dpi),
h: vg.Inches(h / dpi),
color: []color.Color{color.Black},
x: X,
ximg: ximg,
wid: wid,
}
vg.Initialize(c)
return c, nil
}
开发者ID:stanim,项目名称:vgximg,代码行数:41,代码来源:vgximg.go
注:本文中的github.com/BurntSushi/xgbutil/keybind.Initialize函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论