本文整理汇总了Golang中github.com/BurntSushi/xgbutil/xwindow.Generate函数的典型用法代码示例。如果您正苦于以下问题:Golang Generate函数的具体用法?Golang Generate怎么用?Golang Generate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Generate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CreateWindow
// When a cross is declared in its object literal form, it may not have the appropriate window.
// this function creates a new X11 window for the cross with the correct geometry depending
// on its Icon* parameters.
func (c *Cross) CreateWindow(X *xgbutil.XUtil, icons_per_direction int, bg_color uint32) (*xwindow.Window, error) {
// calculate the dimensions of the spars of our cross +
// width/height reflect the vertical-orientation rectangle
width := c.IconMargin*2 + c.IconSize
// padding between the icons, margin on the edges
height := c.IconSize*icons_per_direction + c.IconPadding*(icons_per_direction-1) + c.IconMargin*2
// intitialize a basic window for the cross
win, err := xwindow.Generate(X)
if err != nil {
return nil, err
}
win.Create(X.RootWin(), 0, 0, height, height,
xproto.CwBackPixel|xproto.CwOverrideRedirect, bg_color, 1)
// the rects we will be adding together to form the shape of the cross
vert := xrect.New(0, 0, width, height)
horiz := xrect.New(0, 0, height, width)
struts := []xrect.Rect{vert, horiz}
geom, err := win.Geometry()
if err != nil {
return nil, err
}
// center struts over window
x, y := util.CenterChild(vert, geom)
vert.XSet(x)
vert.YSet(y)
x, y = util.CenterChild(horiz, geom)
horiz.XSet(x)
horiz.YSet(y)
// build the cross shape from our friendly rectangles
err = ComposeShape(X, win.Id, struts)
if err != nil {
return nil, err
}
// add the window to our cross struct
c.Window = win
// create icons from our images
clr := RGB(bg_color)
if c.imagesToBecomeIcons != nil {
icons := make(map[string]*Icon, len(c.imagesToBecomeIcons))
for name, img := range c.imagesToBecomeIcons {
icon := NewIcon(X, img, win.Id)
icon.Background = clr
icons[name] = icon
}
c.Icons = icons
} else {
return nil, errors.New("Cross: you must create crosses using the NewCross function (this cross has now iconsToBecomeImage)")
}
return win, nil
}
开发者ID:justjake,项目名称:j3,代码行数:63,代码来源:cross.go
示例2: newParent
func newParent(X *xgbutil.XUtil, cid xproto.Window) (*Parent, error) {
parent, err := xwindow.Generate(X)
if err != nil {
logger.Error.Printf("Could not create a parent window for client "+
"with id '%d' because: %s", cid, err)
logger.Error.Fatalf("In a state where no new windows can be created. " +
"Unfortunately, we must exit.")
}
err = parent.CreateChecked(X.RootWin(), 0, 0, 1, 1,
xproto.CwEventMask,
xproto.EventMaskSubstructureRedirect|
xproto.EventMaskButtonPress|xproto.EventMaskButtonRelease)
if err != nil {
return nil, err
}
err = xproto.ReparentWindowChecked(X.Conn(),
cid, parent.Id, 0, 0).Check()
if err != nil {
return nil, err
}
return &Parent{parent}, nil
}
开发者ID:dlintw,项目名称:wingo,代码行数:25,代码来源:parent.go
示例3: ComposeShape
// compose a number of rectabgles into a window shape
func ComposeShape(X *xgbutil.XUtil, dst xproto.Window, rects []xrect.Rect) (err error) {
combine_bounds := make([]shape.CombineCookie, len(rects))
combine_clip := make([]shape.CombineCookie, len(rects))
var operation shape.Op
for i, rect := range rects {
// make rectangular window of correct goemetry
win, err := xwindow.Generate(X)
if err != nil {
log.Fatalf("ComposeShape: Error creating rectange %v window.", rect)
return err
}
win.Create(X.RootWin(), rect.X(), rect.Y(), rect.Width(), rect.Height(), xproto.CwBackPixel, 0xffffff)
// choose operation. on the first one, we want to set the shape.
if i == 0 {
operation = shape.SoSet
} else {
operation = shape.SoUnion
}
// combine window request
x, y := int16(rect.X()), int16(rect.Y())
combine_kind := shape.Kind(shape.SkBounding)
combine_bounds[i] = shape.CombineChecked(X.Conn(), operation, combine_kind, combine_kind, dst, x, y, win.Id)
combine_kind = shape.Kind(shape.SkClip)
combine_clip[i] = shape.CombineChecked(X.Conn(), operation, combine_kind, combine_kind, dst, x, y, win.Id)
}
return nil
}
开发者ID:justjake,项目名称:j3,代码行数:34,代码来源:shape.go
示例4: newWindow
func newWindow(X *xgbutil.XUtil) {
win, err := xwindow.Generate(X)
if err != nil {
log.Fatal(err)
}
win.Create(X.RootWin(), 0, 0, 200, 200,
xproto.CwBackPixel|xproto.CwEventMask,
0, xproto.EventMaskButtonRelease)
win.WMGracefulClose(
func(w *xwindow.Window) {
xevent.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
xevent.Quit(X)
Done <- true
})
win.Map()
err = mousebind.ButtonReleaseFun(
func(X *xgbutil.XUtil, ev xevent.ButtonReleaseEvent) {
newWindow(X)
}).Connect(X, win.Id, "1", false, false)
if err != nil {
log.Fatal(err)
}
}
开发者ID:remogatto,项目名称:egles,代码行数:28,代码来源:window.go
示例5: newWindow
func newWindow(X *xgbutil.XUtil, width, height int) *xwindow.Window {
var (
err error
win *xwindow.Window
)
win, err = xwindow.Generate(X)
if err != nil {
log.Fatal(err)
}
win.Create(X.RootWin(), 0, 0, width, height,
xproto.CwBackPixel|xproto.CwEventMask,
0, xproto.EventMaskButtonRelease)
win.WMGracefulClose(
func(w *xwindow.Window) {
xevent.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
xevent.Quit(X)
})
win.Map()
if err != nil {
log.Fatal(err)
}
return win
}
开发者ID:remogatto,项目名称:egl,代码行数:27,代码来源:xorg_test.go
示例6: newWindow
func newWindow(controlCh *controlCh, X *xgbutil.XUtil, width, height int) *xwindow.Window {
var (
err error
win *xwindow.Window
)
win, err = xwindow.Generate(X)
if err != nil {
panic(err)
}
win.Create(X.RootWin(), 0, 0, width, height,
xproto.CwBackPixel|xproto.CwEventMask,
0, xproto.EventMaskButtonRelease)
// Xorg application exits when the window is closed.
win.WMGracefulClose(
func(w *xwindow.Window) {
xevent.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
xevent.Quit(X)
controlCh.exit <- true
})
// In order to get ConfigureNotify events, we must listen to the window
// using the 'StructureNotify' mask.
win.Listen(xproto.EventMaskButtonPress |
xproto.EventMaskButtonRelease |
xproto.EventMaskKeyPress |
xproto.EventMaskKeyRelease |
xproto.EventMaskStructureNotify)
win.Map()
return win
}
开发者ID:remogatto,项目名称:egl-examples,代码行数:35,代码来源:init.go
示例7: New
// New allocates and initializes a new DockApp. NewDockApp does not initialize
// the window contents and does not map the window to the display screen. The
// window is mapped to the screen when the Main method is called on the
// returned DockApp.
func New(x *xgbutil.XUtil, rect image.Rectangle) (*DockApp, error) {
win, err := xwindow.Generate(x)
if err != nil {
log.Fatalf("generate window: %v", err)
}
win.Create(x.RootWin(), 0, 0, rect.Size().X, rect.Size().Y, 0)
// Set WM hints so that Openbox puts the window into the dock.
hints := &icccm.Hints{
Flags: icccm.HintState | icccm.HintIconWindow,
InitialState: icccm.StateWithdrawn,
IconWindow: win.Id,
WindowGroup: win.Id,
}
err = icccm.WmHintsSet(x, win.Id, hints)
if err != nil {
win.Destroy()
return nil, fmt.Errorf("wm hints: %v", err)
}
img := xgraphics.New(x, rect)
err = img.XSurfaceSet(win.Id)
if err != nil {
img.Destroy()
win.Destroy()
return nil, fmt.Errorf("xsurface set: %v", err)
}
app := &DockApp{
x: x,
img: img,
win: win,
}
return app, nil
}
开发者ID:bmatsuo,项目名称:dockapp-go,代码行数:37,代码来源:dockapp.go
示例8: newPieceWindow
func (f *Borders) newPieceWindow(ident string,
cursor xproto.Cursor) *xwindow.Window {
win, err := xwindow.Generate(f.X)
if err != nil {
logger.Error.Printf("Could not create a frame window for client "+
"with id '%d' because: %s", f.client.Id(), err)
logger.Error.Fatalf("In a state where no new windows can be created. " +
"Unfortunately, we must exit.")
}
err = win.CreateChecked(f.parent.Id, 0, 0, 1, 1,
xproto.CwBackPixmap|xproto.CwEventMask|xproto.CwCursor,
xproto.BackPixmapParentRelative,
xproto.EventMaskButtonPress|xproto.EventMaskButtonRelease|
xproto.EventMaskButtonMotion|xproto.EventMaskPointerMotion,
uint32(cursor))
if err != nil {
logger.Warning.Println(err)
}
f.client.FramePieceMouseSetup("borders_"+ident, win.Id)
return win
}
开发者ID:flying99999,项目名称:wingo,代码行数:25,代码来源:borders_pieces.go
示例9: Manage
func (m *TrayManager) Manage() bool {
m.destroyOwnerWindow()
win, _ := xwindow.Generate(TrayXU)
m.owner = win.Id
xproto.CreateWindowChecked(TrayXU.Conn(), 0, m.owner, TrayXU.RootWin(), 0, 0, 1, 1, 0, xproto.WindowClassInputOnly, m.visual, 0, nil)
TrayXU.Sync()
win.Listen(xproto.EventMaskStructureNotify)
return m.tryOwner()
}
开发者ID:felixonmars,项目名称:dde-daemon,代码行数:11,代码来源:traymanager.go
示例10: newWindow
// newWindow creates a new window with a random background color. It sets the
// WM_PROTOCOLS property to contain the WM_DELETE_WINDOW atom. It also sets
// up a ClientMessage event handler so that we know when to destroy the window.
// We also set up a mouse binding so that clicking inside a window will
// create another one.
func newWindow(X *xgbutil.XUtil) {
counter++
win, err := xwindow.Generate(X)
if err != nil {
log.Fatal(err)
}
// Get a random background color, create the window (ask to receive button
// release events while we're at it) and map the window.
bgColor := rand.Intn(0xffffff + 1)
win.Create(X.RootWin(), 0, 0, 200, 200,
xproto.CwBackPixel|xproto.CwEventMask,
uint32(bgColor), xproto.EventMaskButtonRelease)
// WMGracefulClose does all of the work for us. It sets the appropriate
// values for WM_PROTOCOLS, and listens for ClientMessages that implement
// the WM_DELETE_WINDOW protocol. When one is found, the provided callback
// is executed.
win.WMGracefulClose(
func(w *xwindow.Window) {
// Detach all event handlers.
// This should always be done when a window can no longer
// receive events.
xevent.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
w.Destroy()
// Exit if there are no more windows left.
counter--
if counter == 0 {
os.Exit(0)
}
})
// It's important that the map comes after setting WMGracefulClose, since
// the WM isn't obliged to watch updates to the WM_PROTOCOLS property.
win.Map()
// A mouse binding so that a left click will spawn a new window.
// Note that we don't issue a grab here. Typically, window managers will
// grab a button press on the client window (which usually activates the
// window), so that we'd end up competing with the window manager if we
// tried to grab it.
// Instead, we set a ButtonRelease mask when creating the window and attach
// a mouse binding *without* a grab.
err = mousebind.ButtonReleaseFun(
func(X *xgbutil.XUtil, ev xevent.ButtonReleaseEvent) {
newWindow(X)
}).Connect(X, win.Id, "1", false, false)
if err != nil {
log.Fatal(err)
}
}
开发者ID:auroralaboratories,项目名称:corona-api,代码行数:58,代码来源:main.go
示例11: showImage
// This is a slightly modified version of xgraphics.XShowExtra that does
// not set any resize constraints on the window (so that it can go
// fullscreen).
func showImage(im *xgraphics.Image, name string, quit bool) *xwindow.Window {
if len(name) == 0 {
name = "xgbutil Image Window"
}
w, h := im.Rect.Dx(), im.Rect.Dy()
win, err := xwindow.Generate(im.X)
if err != nil {
xgbutil.Logger.Printf("Could not generate new window id: %s", err)
return nil
}
// Create a very simple window with dimensions equal to the image.
win.Create(im.X.RootWin(), 0, 0, w, h, 0)
// Make this window close gracefully.
win.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()
if quit {
xevent.Quit(w.X)
}
})
// Set WM_STATE so it is interpreted as a top-level window.
err = icccm.WmStateSet(im.X, win.Id, &icccm.WmState{
State: icccm.StateNormal,
})
if err != nil { // not a fatal error
xgbutil.Logger.Printf("Could not set WM_STATE: %s", err)
}
// Set _NET_WM_NAME so it looks nice.
err = ewmh.WmNameSet(im.X, win.Id, name)
if err != nil { // not a fatal error
xgbutil.Logger.Printf("Could not set _NET_WM_NAME: %s", err)
}
// Paint our image before mapping.
im.XSurfaceSet(win.Id)
im.XDraw()
im.XPaint(win.Id)
// Now we can map, since we've set all our properties.
// (The initial map is when the window manager starts managing.)
win.Map()
return win
}
开发者ID:auroralaboratories,项目名称:corona-api,代码行数:55,代码来源:main.go
示例12: newWindow
// newWndow creates a new window and dies on failure.
// This includes mapping the window but not setting up the event handlers.
// (The event handlers require the channels, and we don't create the channels
// until all images have been decoded. But we want to show the window to the
// user before that task is complete.)
func newWindow(X *xgbutil.XUtil) *window {
xwin, err := xwindow.Generate(X)
if err != nil {
errLg.Fatalf("Could not create window: %s", err)
}
w := &window{
Window: xwin,
}
w.create()
return w
}
开发者ID:BurntSushi,项目名称:imgv,代码行数:18,代码来源:win.go
示例13: NewWindow
func NewWindow(width, height int) (w *Window, err error) {
w = new(Window)
w.width, w.height = width, height
w.xu, err = xgbutil.NewConn()
if err != nil {
return
}
w.conn = w.xu.Conn()
screen := w.xu.Screen()
w.win, err = xwindow.Generate(w.xu)
if err != nil {
return
}
err = w.win.CreateChecked(screen.Root, 600, 500, width, height, 0)
if err != nil {
return
}
w.win.Listen(AllEventsMask)
err = icccm.WmProtocolsSet(w.xu, w.win.Id, []string{"WM_DELETE_WINDOW"})
if err != nil {
fmt.Println(err)
err = nil
}
w.bufferLck = &sync.Mutex{}
w.buffer = xgraphics.New(w.xu, image.Rect(0, 0, width, height))
w.buffer.XSurfaceSet(w.win.Id)
keyMap, modMap := keybind.MapsGet(w.xu)
keybind.KeyMapSet(w.xu, keyMap)
keybind.ModMapSet(w.xu, modMap)
w.events = make(chan interface{})
w.SetIcon(Gordon)
w.SetIconName("Go")
go w.handleEvents()
return
}
开发者ID:nickoneill,项目名称:go.wde,代码行数:48,代码来源:xgb.go
示例14: 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
示例15: newParent
func newParent(X *xgbutil.XUtil, cid xproto.Window) (*Parent, error) {
parent, err := xwindow.Generate(X)
if err != nil {
logger.Error.Printf("Could not create a parent window for client "+
"with id '%d' because: %s", cid, err)
logger.Error.Fatalf("In a state where no new windows can be created. " +
"Unfortunately, we must exit.")
}
// clientAttrs, err := xproto.GetWindowAttributes(X.Conn(), cid).Reply()
// if err != nil {
// return nil, fmt.Errorf("Could not get window attributes: %s", err)
// }
// visual := clientAttrs.Visual
// vdepth := getVisualDepth(X, visual)
visual := X.Screen().RootVisual
vdepth := X.Screen().RootDepth
// logger.Debug.Printf("Visualid: %x, Depth: %d", visual, vdepth)
err = xproto.CreateWindowChecked(X.Conn(),
vdepth, parent.Id, X.RootWin(),
0, 0, 1, 1, 0, xproto.WindowClassInputOutput, visual,
xproto.CwEventMask,
[]uint32{
xproto.EventMaskSubstructureRedirect |
xproto.EventMaskButtonPress |
xproto.EventMaskButtonRelease |
xproto.EventMaskFocusChange,
}).Check()
if err != nil {
return nil, fmt.Errorf("Could not create window: %s", err)
}
err = xproto.ReparentWindowChecked(X.Conn(),
cid, parent.Id, 0, 0).Check()
if err != nil {
return nil, fmt.Errorf("Could not reparent window: %s", err)
}
return &Parent{
Window: parent,
MoveState: &MoveState{},
ResizeState: &ResizeState{},
isMapped: false,
}, nil
}
开发者ID:mkrull,项目名称:wingo,代码行数:46,代码来源:parent.go
示例16: newWindow
func newWindow(X *xgbutil.XUtil, width, height int) *xwindow.Window {
var (
err error
win *xwindow.Window
)
win, err = xwindow.Generate(X)
if err != nil {
log.Fatal(err)
}
win.Create(X.RootWin(), 0, 0, width, height,
xproto.CwBackPixel|xproto.CwEventMask,
0, xproto.EventMaskButtonRelease)
win.WMGracefulClose(
func(w *xwindow.Window) {
xevent.Detach(w.X, w.Id)
mousebind.Detach(w.X, w.Id)
// w.Destroy()
xevent.Quit(X)
application.Exit()
})
// In order to get ConfigureNotify events, we must listen to the window
// using the 'StructureNotify' mask.
win.Listen(xproto.EventMaskStructureNotify)
win.Map()
xevent.ConfigureNotifyFun(
func(X *xgbutil.XUtil, ev xevent.ConfigureNotifyEvent) {
reshape(int(ev.Width), int(ev.Height))
}).Connect(X, win.Id)
// err = mousebind.ButtonReleaseFun(
// func(X *xgbutil.XUtil, ev xevent.ButtonReleaseEvent) {
// newWindow(X)
// }).Connect(X, win.Id, "1", false, false)
if err != nil {
log.Fatal(err)
}
return win
}
开发者ID:nick-fedesna,项目名称:egles,代码行数:42,代码来源:window.go
示例17: main
func main() {
var err error
X, err = xgbutil.NewConn()
if err != nil {
log.Fatal(err)
}
clientids, err := ewmh.ClientListGet(X)
if err != nil {
log.Fatal(err)
}
for _, clientid := range clientids {
name, err := ewmh.WmNameGet(X, clientid)
if err != nil {
continue
}
if name == "Super Hexagon" {
HexWindow = xwindow.New(X, clientid)
break
}
}
if HexWindow == nil {
log.Fatal("Couldn't find Super Hexagon window.")
}
//Create a window
DisplayWindow, err = xwindow.Generate(X)
if err != nil {
log.Fatalf("Could not generate a new window X id: %s", err)
}
dgeom, _ := HexWindow.DecorGeometry()
DisplayWindow.Create(X.RootWin(), 0, 0, dgeom.Width(), dgeom.Height(), xproto.CwBackPixel, 0)
DisplayWindow.Map()
//Start the routine that updates the window
go updater()
xevent.Main(X)
}
开发者ID:xthexder,项目名称:superhexagon,代码行数:42,代码来源:superhexagon.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()
if err != nil {
log.Fatal(err)
}
// Create the cursor. You can find a list of available cursors in
// xcursor/cursordef.go.
// We'll make an umbrella here, with an orange foreground and a blue
// background. (The background it typically the outline of the cursor.)
// Note that each component of the RGB color is a 16 bit color. I think
// using the most significant byte to specify each component is good
// enough.
cursor, err := xcursor.CreateCursorExtra(X, xcursor.Umbrella,
0xff00, 0x5500, 0x0000,
0x3300, 0x6600, 0xff00)
if err != nil {
log.Fatal(err)
}
// Create a new window. In the create window request, we'll set the
// background color and set the cursor we created above.
// This results in changing the cursor only when it moves into this window.
win, err := xwindow.Generate(X)
if err != nil {
log.Fatal(err)
}
win.Create(X.RootWin(), 0, 0, 500, 500,
xproto.CwBackPixel|xproto.CwCursor,
0xffffffff, uint32(cursor))
win.Map()
// We can free the cursor now that we've set it.
// If you plan on using this cursor again, then it shouldn't be freed.
// (i.e., if you try to free this before setting it as the cursor in a
// window, you'll get a BadCursor error when trying to use it.)
xproto.FreeCursor(X.Conn(), cursor)
// Block. No need to process any events.
select {}
}
开发者ID:auroralaboratories,项目名称:corona-api,代码行数:41,代码来源:main.go
示例20: newGradientWindow
// newGradientWindow creates a new X window, paints the initial gradient
// image, and listens for ConfigureNotify events. (A new gradient image must
// be painted in response to each ConfigureNotify event, since a
// ConfigureNotify event corresponds to a change in the window's geometry.)
func newGradientWindow(X *xgbutil.XUtil, width, height int,
start, end color.RGBA) {
// Generate a new window id.
win, err := xwindow.Generate(X)
if err != nil {
log.Fatal(err)
}
// Create the window and die if it fails.
err = win.CreateChecked(X.RootWin(), 0, 0, width, height, 0)
if err != nil {
log.Fatal(err)
}
// In order to get ConfigureNotify events, we must listen to the window
// using the 'StructureNotify' mask.
win.Listen(xproto.EventMaskStructureNotify)
// Paint the initial gradient to the window and then map the window.
paintGradient(X, win.Id, width, height, start, end)
win.Map()
xevent.ConfigureNotifyFun(
func(X *xgbutil.XUtil, ev xevent.ConfigureNotifyEvent) {
// If the width and height have not changed, skip this one.
if int(ev.Width) == width && int(ev.Height) == height {
return
}
// Compress ConfigureNotify events so that we don't lag when
// drawing gradients in response.
ev = compressConfigureNotify(X, ev)
// Update the width and height and paint the gradient image.
width, height = int(ev.Width), int(ev.Height)
paintGradient(X, win.Id, width, height, start, end)
}).Connect(X, win.Id)
}
开发者ID:auroralaboratories,项目名称:corona-api,代码行数:43,代码来源:main.go
注:本文中的github.com/BurntSushi/xgbutil/xwindow.Generate函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论