本文整理汇总了Golang中github.com/BurntSushi/xgb/xproto.NewWindowId函数的典型用法代码示例。如果您正苦于以下问题:Golang NewWindowId函数的具体用法?Golang NewWindowId怎么用?Golang NewWindowId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewWindowId函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Generate
// Generate is just like New, but generates a new X resource id for you.
// Geom is initialized to (0, 0) 1x1.
// It is possible for id generation to return an error, in which case, an
// error is returned here.
func Generate(xu *xgbutil.XUtil) (*Window, error) {
wid, err := xproto.NewWindowId(xu.Conn())
if err != nil {
return nil, err
}
return New(xu, wid), nil
}
示例2: NewWindow
func (w *windower) NewWindow() *Window {
win, err := xproto.NewWindowId(w.conn)
if err != nil {
return nil
}
return &Window{w.conn, win, w.root, 0, 0}
}
示例3: usurpWM
// Replace existing window manager
func usurpWM(X *xgb.Conn, screen *xproto.ScreenInfo) {
wmName := fmt.Sprintf("WM_S%d", X.DefaultScreen)
managerAtom, err := xproto.InternAtom(X, true, uint16(len(wmName)), wmName).Reply()
if err != nil {
log.Fatal(err)
}
fakeWindow, _ := xproto.NewWindowId(X)
xproto.CreateWindow(X, // Connection
screen.RootDepth, // Depth
fakeWindow, // Window Id
screen.Root, // Parent Window
-1000, -1000, // x, y
1, 1, // width, height
0, // border_width
xproto.WindowClassInputOutput, // class
screen.RootVisual, // visual
xproto.CwEventMask|xproto.CwOverrideRedirect,
[]uint32{1, xproto.EventMaskPropertyChange}) // masks
xproto.MapWindow(X, fakeWindow)
err = xproto.SetSelectionOwnerChecked(X, fakeWindow, managerAtom.Atom, xproto.TimeCurrentTime).Check()
if err != nil {
log.Fatal(err)
}
}
示例4: initWindow32
func (s *screenImpl) initWindow32() error {
visualid, err := findVisual(s.xsi, 32)
if err != nil {
return err
}
colormap, err := xproto.NewColormapId(s.xc)
if err != nil {
return fmt.Errorf("x11driver: xproto.NewColormapId failed: %v", err)
}
if err := xproto.CreateColormapChecked(
s.xc, xproto.ColormapAllocNone, colormap, s.xsi.Root, visualid).Check(); err != nil {
return fmt.Errorf("x11driver: xproto.CreateColormap failed: %v", err)
}
s.window32, err = xproto.NewWindowId(s.xc)
if err != nil {
return fmt.Errorf("x11driver: xproto.NewWindowId failed: %v", err)
}
s.gcontext32, err = xproto.NewGcontextId(s.xc)
if err != nil {
return fmt.Errorf("x11driver: xproto.NewGcontextId failed: %v", err)
}
const depth = 32
xproto.CreateWindow(s.xc, depth, s.window32, s.xsi.Root,
0, 0, 1, 1, 0,
xproto.WindowClassInputOutput, visualid,
// The CwBorderPixel attribute seems necessary for depth == 32. See
// http://stackoverflow.com/questions/3645632/how-to-create-a-window-with-a-bit-depth-of-32
xproto.CwBorderPixel|xproto.CwColormap,
[]uint32{0, uint32(colormap)},
)
xproto.CreateGC(s.xc, s.gcontext32, xproto.Drawable(s.window32), 0, nil)
return nil
}
示例5: createWindow
func createWindow() xproto.Window {
wid, err := xproto.NewWindowId(X.Conn())
if err != nil {
log.Fatal(err)
}
scrn := X.Screen()
xproto.CreateWindow(X.Conn(), scrn.RootDepth, wid, X.RootWin(),
0, 0, 400, 400, 0,
xproto.WindowClassInputOutput, scrn.RootVisual, 0, []uint32{})
return wid
}
示例6: start_server
func start_server(c *xgb.Conn, s *xproto.ScreenInfo, rl_execute_atom xproto.Atom) {
win, err := xproto.NewWindowId(c)
if err != nil {
panic(err)
}
// Make a window which can be communicated with
err = xproto.CreateWindowChecked(c, s.RootDepth, win, s.Root, 0, 0, 1, 1, 0, 0, 0, 0, nil).Check()
if err != nil {
panic(err)
}
err = xproto.ChangePropertyChecked(c, xproto.PropModeReplace, win,
rl_execute_atom, xproto.AtomString, 8, xproto.PropModeReplace,
[]byte("\x00")).Check()
if err != nil {
panic(err)
}
err = xproto.ChangeWindowAttributesChecked(c, win, xproto.CwEventMask, []uint32{xproto.EventMaskPropertyChange}).Check()
if err != nil {
panic(err)
}
get_execute_value := func() string {
response, err := xproto.GetProperty(c, false, win, rl_execute_atom,
xproto.GetPropertyTypeAny, 0, 1024).Reply()
if err != nil {
panic(err)
}
result := string(response.Value)
return result
}
log.Print("Ready and waiting..")
// Event loop
for {
reply, err := c.WaitForEvent()
if err != nil {
log.Panic("Error in event loop:", err)
}
switch event := reply.(type) {
case xproto.PropertyNotifyEvent:
if event.Window == win && event.Atom == rl_execute_atom {
values := strings.Split(get_execute_value(), "\x00")
run(values)
}
}
}
}
示例7: Open
func Open(c *xgb.Conn, ctx, title, text string) (*Window, error) {
gc, ok := ctxs[ctx]
if !ok {
return nil, BadContextError(ctx)
}
scr := xproto.Setup(c).DefaultScreen(c)
wdwid, err := xproto.NewWindowId(c)
if err != nil {
return nil, err
}
lines := cutLines(c, gc.width-2*gc.border, gc.font, text)
height := uint32(len(lines)) * gc.fontHeight
var mask uint32 = xproto.CwBackPixel | xproto.CwOverrideRedirect | xproto.CwEventMask
values := make([]uint32, 3)
values[0] = scr.WhitePixel
values[1] = 1
values[2] = xproto.EventMaskExposure
err = xproto.CreateWindowChecked(c, xproto.WindowClassCopyFromParent, wdwid, scr.Root,
0, 0, uint16(gc.width), uint16(height+2*gc.border), 1,
xproto.WindowClassInputOutput, scr.RootVisual,
mask, values).Check()
if err != nil {
return nil, err
}
xproto.ChangeProperty(c, xproto.PropModeReplace, wdwid,
xproto.AtomWmName, xproto.AtomString,
8, uint32(len(title)), []byte(title))
var wdw Window
wdw.id = wdwid
wdw.conn = c
wdw.lines = lines
wdw.gc = gc
wdw.geom = types.Geometry{0, 0, int32(gc.width), int32(height + 2*gc.border)}
return &wdw, nil
}
示例8: default1
func default1() {
X, err := xgb.NewConn()
if err != nil {
fmt.Println(err)
return
}
wid, _ := xproto.NewWindowId(X)
screen := xproto.Setup(X).DefaultScreen(X)
xproto.CreateWindow(X, screen.RootDepth, wid, screen.Root,
0, 0, 500, 500, 0,
xproto.WindowClassInputOutput, screen.RootVisual,
xproto.CwBackPixel|xproto.CwEventMask,
[]uint32{
0xffffffff,
xproto.EventMaskStructureNotify |
xproto.EventMaskKeyPress |
xproto.EventMaskKeyRelease})
xproto.MapWindow(X, wid)
for {
ev, xerr := X.WaitForEvent()
if ev == nil && xerr == nil {
fmt.Println("Both event and error are nil. Exiting...")
return
}
if ev != nil {
fmt.Println("Event: %s\r\n", ev)
}
if xerr != nil {
fmt.Println("Error: %s\r\n", xerr)
}
}
}
示例9: mkMotion
func mkMotion(s *xproto.ScreenInfo, c *xgb.Conn) (xproto.Window, error) {
motion, err := xproto.NewWindowId(c)
if err != nil {
return motion, err
}
xproto.CreateWindow(
c,
s.RootDepth,
motion,
s.Root,
0,
0,
s.WidthInPixels,
s.HeightInPixels,
0,
xproto.WindowClassInputOnly,
s.RootVisual,
xproto.CwEventMask,
[]uint32{xproto.EventMaskPointerMotion},
)
xproto.MapWindow(c, motion)
return motion, nil
}
示例10: mkMeta
func mkMeta(s *xproto.ScreenInfo, c *xgb.Conn) (xproto.Window, error) {
meta, err := xproto.NewWindowId(c)
if err != nil {
return meta, err
}
xproto.CreateWindow(
c,
s.RootDepth,
meta,
s.Root,
-1,
-1,
1,
1,
0,
xproto.WindowClassInputOnly,
s.RootVisual,
0, //xproto.CwEventMask|xproto.CwOverrideRedirect,
[]uint32{}, //nil, //[]uint32{1, xproto.EventMaskPropertyChange},
)
xproto.MapWindow(c, meta)
return meta, nil
}
示例11: main
func main() {
// Open the connection to the X server
X, err := xgb.NewConn()
if err != nil {
log.Fatal(err)
}
defer X.Close()
// geometric objects
points := []xproto.Point{
{10, 10},
{10, 20},
{20, 10},
{20, 20}}
polyline := []xproto.Point{
{50, 10},
{5, 20}, // rest of points are relative
{25, -20},
{10, 10}}
segments := []xproto.Segment{
{100, 10, 140, 30},
{110, 25, 130, 60}}
rectangles := []xproto.Rectangle{
{10, 50, 40, 20},
{80, 50, 10, 40}}
arcs := []xproto.Arc{
{10, 100, 60, 40, 0, 90 << 6},
{90, 100, 55, 40, 0, 270 << 6}}
setup := xproto.Setup(X)
// Get the first screen
screen := setup.DefaultScreen(X)
// Create black (foreground) graphic context
foreground, _ := xproto.NewGcontextId(X)
mask := uint32(xproto.GcForeground | xproto.GcGraphicsExposures)
values := []uint32{screen.BlackPixel, 0}
xproto.CreateGC(X, foreground, xproto.Drawable(screen.Root), mask, values)
// Ask for our window's Id
win, _ := xproto.NewWindowId(X)
winDrawable := xproto.Drawable(win)
// Create the window
mask = uint32(xproto.CwBackPixel | xproto.CwEventMask)
values = []uint32{screen.WhitePixel, xproto.EventMaskExposure}
xproto.CreateWindow(X, // Connection
screen.RootDepth, // Depth
win, // Window Id
screen.Root, // Parent Window
0, 0, // x, y
150, 150, // width, height
10, // border_width
xproto.WindowClassInputOutput, // class
screen.RootVisual, // visual
mask, values) // masks
// Map the window on the screen
xproto.MapWindow(X, win)
// Obey the window-delete protocol
tp := "WM_PROTOCOLS"
prp := "WM_DELETE_WINDOW"
typeAtom, _ := xproto.InternAtom(X, true, uint16(len(tp)), tp).Reply()
propertyAtom, _ := xproto.InternAtom(X, true, uint16(len(prp)), prp).Reply()
// It turns out that we need the window ID as a byte-stream... WTF!!
// xprop.ChangeProp(xu, win, 8, "WM_NAME", "STRING", ([]byte)(name))
// ChangeProp(xu *xgbutil.XUtil, win xproto.Window, format byte, prop string, typ string, data []byte)
data := make([]byte, 4)
xgb.Put32(data, uint32(propertyAtom.Atom))
xproto.ChangeProperty(X, xproto.PropModeReplace, win, typeAtom.Atom, xproto.AtomAtom, 32, 1, data)
for {
evt, err := X.WaitForEvent()
fmt.Printf("An event of type %T occured.\n", evt)
if evt == nil && err == nil {
fmt.Println("Exiting....")
return
} else if err != nil {
log.Fatal(err)
}
switch event := evt.(type) {
case xproto.ExposeEvent:
/* We draw the points */
xproto.PolyPoint(X, xproto.CoordModeOrigin, winDrawable, foreground, points)
/* We draw the polygonal line */
xproto.PolyLine(X, xproto.CoordModePrevious, winDrawable, foreground, polyline)
/* We draw the segments */
xproto.PolySegment(X, winDrawable, foreground, segments)
/* We draw the rectangles */
//.........这里部分代码省略.........
示例12: NewWindow
func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
// TODO: look at opts.
const width, height = 1024, 768
xw, err := xproto.NewWindowId(s.xc)
if err != nil {
return nil, fmt.Errorf("x11driver: xproto.NewWindowId failed: %v", err)
}
xg, err := xproto.NewGcontextId(s.xc)
if err != nil {
return nil, fmt.Errorf("x11driver: xproto.NewGcontextId failed: %v", err)
}
xp, err := render.NewPictureId(s.xc)
if err != nil {
return nil, fmt.Errorf("x11driver: render.NewPictureId failed: %v", err)
}
pictformat := render.Pictformat(0)
switch s.xsi.RootDepth {
default:
return nil, fmt.Errorf("x11driver: unsupported root depth %d", s.xsi.RootDepth)
case 24:
pictformat = s.pictformat24
case 32:
pictformat = s.pictformat32
}
w := &windowImpl{
s: s,
xw: xw,
xg: xg,
xp: xp,
pump: pump.Make(),
xevents: make(chan xgb.Event),
}
s.mu.Lock()
s.windows[xw] = w
s.mu.Unlock()
xproto.CreateWindow(s.xc, s.xsi.RootDepth, xw, s.xsi.Root,
0, 0, width, height, 0,
xproto.WindowClassInputOutput, s.xsi.RootVisual,
xproto.CwEventMask,
[]uint32{0 |
xproto.EventMaskKeyPress |
xproto.EventMaskKeyRelease |
xproto.EventMaskButtonPress |
xproto.EventMaskButtonRelease |
xproto.EventMaskPointerMotion |
xproto.EventMaskExposure |
xproto.EventMaskStructureNotify |
xproto.EventMaskFocusChange,
},
)
s.setProperty(xw, s.atomWMProtocols, s.atomWMDeleteWindow, s.atomWMTakeFocus)
xproto.CreateGC(s.xc, xg, xproto.Drawable(xw), 0, nil)
render.CreatePicture(s.xc, xp, xproto.Drawable(xw), pictformat, 0, nil)
xproto.MapWindow(s.xc, xw)
return w, nil
}
示例13: main
func main() {
X, err := xgb.NewConn()
if err != nil {
fmt.Println(err)
return
}
wid, _ := xproto.NewWindowId(X)
screen := xproto.Setup(X).DefaultScreen(X)
xproto.CreateWindow(X, screen.RootDepth, wid, screen.Root,
0, 0, 240, 240, 0,
xproto.WindowClassInputOutput,
screen.RootVisual,
xproto.CwBackPixel|xproto.CwEventMask,
[]uint32{ // values must be in the order defined by the protocol
0xffffffff,
xproto.EventMaskStructureNotify |
xproto.EventMaskKeyPress |
xproto.EventMaskKeyRelease})
xproto.MapWindow(X, wid)
fmt.Printf("%d %d\n", screen.AllowedDepths[0].Visuals[0].VisualId, screen.RootVisual)
var (
ux, uy float64 = 1, 1
fe cairo.FontExtents
te cairo.TextExtents
text = "joy"
x, y, px, dashlength float64
)
surface := cairo.NewSurfaceFromXCB(xproto.Drawable(wid), screen.AllowedDepths[0].Visuals[0], 240, 240)
surface.Scale(240, 240)
surface.SetFontSize(0.5)
/* Drawing code goes here */
surface.SetSourceRGB(0.0, 0.0, 0.0)
surface.SelectFontFace("Georgia", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
surface.FontExtents(&fe)
ux, uy = surface.DeviceToUserDistance(ux, uy)
if ux > uy {
px = ux
} else {
px = uy
}
surface.FontExtents(&fe)
surface.TextExtents(text, &te)
x = 0.5 - te.X_bearing - te.Width/2
y = 0.5 - fe.Descent + fe.Height/2
/* baseline, descent, ascent, height */
surface.SetLineWidth(4 * px)
dashlength = 9 * px
surface.SetDash([]float64{dashlength}, 0)
surface.SetSourceRGBA(0, 0.6, 0, 0.5)
surface.MoveTo(x+te.X_bearing, y)
surface.RelLineTo(te.Width, 0)
surface.MoveTo(x+te.X_bearing, y+fe.Descent)
surface.RelLineTo(te.Width, 0)
surface.MoveTo(x+te.X_bearing, y-fe.Ascent)
surface.RelLineTo(te.Width, 0)
surface.MoveTo(x+te.X_bearing, y-fe.Height)
surface.RelLineTo(te.Width, 0)
surface.Stroke()
/* extents: width & height */
surface.SetSourceRGBA(0, 0, 0.75, 0.5)
surface.SetLineWidth(px)
dashlength = 3 * px
surface.SetDash([]float64{dashlength}, 0)
surface.Rectangle(x+te.X_bearing, y+te.Y_bearing, te.Width, te.Height)
surface.Stroke()
/* text */
surface.MoveTo(x, y)
surface.SetSourceRGB(0, 0, 0)
surface.ShowText(text)
/* bearing */
surface.SetDash(nil, 0)
surface.SetLineWidth(2 * px)
surface.SetSourceRGBA(0, 0, 0.75, 0.5)
surface.MoveTo(x, y)
surface.RelLineTo(te.X_bearing, te.Y_bearing)
surface.Stroke()
/* text's advance */
surface.SetSourceRGBA(0, 0, 0.75, 0.5)
surface.Arc(x+te.X_advance, y+te.Y_advance, 5*px, 0, 2*math.Pi)
surface.Fill()
/* reference point */
surface.Arc(x, y, 5*px, 0, 2*math.Pi)
surface.SetSourceRGBA(0.75, 0, 0, 0.5)
surface.Fill()
surface.Finish()
//.........这里部分代码省略.........
示例14: main
func main() {
// Open the connection to the X server
X, err := xgb.NewConn()
if err != nil {
log.Fatal(err)
}
defer X.Close()
setup := xproto.Setup(X)
// Get the first screen
screen := setup.DefaultScreen(X)
// Replace existing window manager
wmName := fmt.Sprintf("WM_S%d", X.DefaultScreen)
managerAtom, err := xproto.InternAtom(X, true, uint16(len(wmName)), wmName).Reply()
if err != nil {
log.Fatal(err)
}
fakeWindow, _ := xproto.NewWindowId(X)
xproto.CreateWindow(X, // Connection
screen.RootDepth, // Depth
fakeWindow, // Window Id
screen.Root, // Parent Window
-1000, -1000, // x, y
1, 1, // width, height
0, // border_width
xproto.WindowClassInputOutput, // class
screen.RootVisual, // visual
xproto.CwEventMask|xproto.CwOverrideRedirect,
[]uint32{1, xproto.EventMaskPropertyChange}) // masks
xproto.MapWindow(X, fakeWindow)
err = xproto.SetSelectionOwnerChecked(X, fakeWindow, managerAtom.Atom, xproto.TimeCurrentTime).Check()
if err != nil {
fmt.Println("foo")
log.Fatal(err)
}
arcs := []xproto.Arc{
{10, 100, 60, 40, 0, 90 << 6},
{90, 100, 55, 40, 0, 270 << 6}}
// Create black (foreground) graphic context
foreground, _ := xproto.NewGcontextId(X)
mask := uint32(xproto.GcForeground | xproto.GcGraphicsExposures)
values := []uint32{screen.BlackPixel, 0}
xproto.CreateGC(X, foreground, xproto.Drawable(screen.Root), mask, values)
// Ask for our window's Id
win, _ := xproto.NewWindowId(X)
winDrawable := xproto.Drawable(win)
// Create the window
mask = uint32(xproto.CwBackPixel | xproto.CwEventMask)
values = []uint32{screen.WhitePixel, xproto.EventMaskExposure}
xproto.CreateWindow(X, // Connection
screen.RootDepth, // Depth
win, // Window Id
screen.Root, // Parent Window
0, 0, // x, y
150, 150, // width, height
10, // border_width
xproto.WindowClassInputOutput, // class
screen.RootVisual, // visual
mask, values) // masks
// Map the window on the screen
xproto.MapWindow(X, win)
// Obey the window-delete protocol
tp := "WM_PROTOCOLS"
prp := "WM_DELETE_WINDOW"
typeAtom, _ := xproto.InternAtom(X, true, uint16(len(tp)), tp).Reply()
propertyAtom, _ := xproto.InternAtom(X, true, uint16(len(prp)), prp).Reply()
data := make([]byte, 4)
xgb.Put32(data, uint32(propertyAtom.Atom))
xproto.ChangeProperty(X, xproto.PropModeReplace, win, typeAtom.Atom, xproto.AtomAtom, 32, 1, data)
// Main loop
for {
evt, err := X.WaitForEvent()
fmt.Printf("An event of type %T occured.\n", evt)
if evt == nil && err == nil {
fmt.Println("Exiting....")
return
} else if err != nil {
log.Fatal(err)
}
switch event := evt.(type) {
case xproto.ExposeEvent:
/* We draw the arcs */
xproto.PolyArc(X, winDrawable, foreground, arcs)
case xproto.ClientMessageEvent:
if len(event.Data.Data32) > 0 {
data := xproto.Atom(event.Data.Data32[0])
if data == propertyAtom.Atom {
return
//.........这里部分代码省略.........
示例15: initDesktop
func initDesktop(xScreen *xp.ScreenInfo) {
xFont, err := xp.NewFontId(xConn)
if err != nil {
log.Fatal(err)
}
xCursor, err := xp.NewCursorId(xConn)
if err != nil {
log.Fatal(err)
}
err = xp.OpenFontChecked(xConn, xFont, uint16(len("cursor")), "cursor").Check()
if err != nil {
log.Fatal(err)
}
const xcLeftPtr = 68 // XC_left_ptr from cursorfont.h.
err = xp.CreateGlyphCursorChecked(
xConn, xCursor, xFont, xFont, xcLeftPtr, xcLeftPtr+1,
0xffff, 0xffff, 0xffff, 0, 0, 0).Check()
if err != nil {
log.Fatal(err)
}
err = xp.CloseFontChecked(xConn, xFont).Check()
if err != nil {
log.Fatal(err)
}
desktopXWin, err = xp.NewWindowId(xConn)
if err != nil {
log.Fatal(err)
}
desktopXGC, err = xp.NewGcontextId(xConn)
if err != nil {
log.Fatal(err)
}
desktopWidth = xScreen.WidthInPixels
desktopHeight = xScreen.HeightInPixels
if err := xp.CreateWindowChecked(
xConn, xScreen.RootDepth, desktopXWin, xScreen.Root,
0, 0, desktopWidth, desktopHeight, 0,
xp.WindowClassInputOutput,
xScreen.RootVisual,
xp.CwOverrideRedirect|xp.CwEventMask,
[]uint32{
1,
xp.EventMaskExposure,
},
).Check(); err != nil {
log.Fatal(err)
}
if len(xSettings) != 0 {
initXSettings()
}
if err := xp.ConfigureWindowChecked(
xConn,
desktopXWin,
xp.ConfigWindowStackMode,
[]uint32{
xp.StackModeBelow,
},
).Check(); err != nil {
log.Fatal(err)
}
if err := xp.ChangeWindowAttributesChecked(
xConn,
desktopXWin,
xp.CwBackPixel|xp.CwCursor,
[]uint32{
xScreen.BlackPixel,
uint32(xCursor),
},
).Check(); err != nil {
log.Fatal(err)
}
if err := xp.CreateGCChecked(
xConn,
desktopXGC,
xp.Drawable(xScreen.Root),
0,
nil,
).Check(); err != nil {
log.Fatal(err)
}
if err := xp.MapWindowChecked(xConn, desktopXWin).Check(); err != nil {
log.Fatal(err)
}
}