本文整理匯總了Golang中github.com/BurntSushi/xgbutil/xwindow.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MakeDraggable
// drag around windows with the mouse.
func MakeDraggable(X *xgbutil.XUtil, win xproto.Window) {
// utility window for movement
xwin := xwindow.New(X, win)
// state
var offsetX, offsetY int
var lastX, lastY int
// saves initial click location
startDrag := func(X *xgbutil.XUtil, rootX, rootY, eventX, eventY int) (bool, xproto.Cursor) {
offsetX = eventX
offsetY = eventY
lastX = rootX
lastY = rootY
// apparently the cursor is just ID 0
return true, 0
}
// moves the window
stepDrag := func(X *xgbutil.XUtil, rootX, rootY, eventX, eventY int) {
// maintain mouse position within window
toX := rootX - offsetX
toY := rootY - offsetY
// move window
xwin.Move(toX, toY)
}
stopDrag := func(X *xgbutil.XUtil, rx, ry, ex, ey int) {}
// actually bind handler to window
mousebind.Drag(X, win, win, "1", true, startDrag, stepDrag, stopDrag)
log.Printf("MakeDraggable: activated window %v\n", xwin)
}
示例2: detachXid
func (app *RuntimeApp) detachXid(xid xproto.Window) {
if info, ok := app.xids[xid]; ok {
xwindow.New(XU, xid).Listen(xproto.EventMaskNoEvent)
xevent.Detach(XU, xid)
if len(app.xids) == 1 {
ENTRY_MANAGER.destroyRuntimeApp(app)
} else {
delete(app.xids, xid)
if info == app.CurrentInfo {
for _, nextInfo := range app.xids {
if nextInfo != nil {
app.CurrentInfo = nextInfo
app.updateState(app.CurrentInfo.Xid)
app.notifyChanged()
} else {
ENTRY_MANAGER.destroyRuntimeApp(app)
}
break
}
}
}
}
if len(app.xids) == 0 {
app.setChangedCB(nil)
} else {
app.notifyChanged()
}
}
示例3: Root
func Root() {
rwin := xwindow.New(X, X.RootWin())
for _, c := range Clients {
c.Unfocused()
}
rwin.Focus()
}
示例4: addTrayIcon
func (m *TrayManager) addTrayIcon(xid xproto.Window) {
m.checkValid()
for _, id := range m.TrayIcons {
if xproto.Window(id) == xid {
return
}
}
if d, err := damage.NewDamageId(TrayXU.Conn()); err != nil {
return
} else {
m.dmageInfo[xid] = d
if err := damage.CreateChecked(TrayXU.Conn(), d, xproto.Drawable(xid), damage.ReportLevelRawRectangles).Check(); err != nil {
logger.Debug("DamageCreate Failed:", err)
return
}
}
composite.RedirectWindow(TrayXU.Conn(), xid, composite.RedirectAutomatic)
m.TrayIcons = append(m.TrayIcons, uint32(xid))
icon := xwindow.New(TrayXU, xid)
icon.Listen(xproto.EventMaskVisibilityChange | damage.Notify | xproto.EventMaskStructureNotify)
icon.Change(xproto.CwBackPixel, 0)
name, err := ewmh.WmNameGet(TrayXU, xid)
if err != nil {
logger.Debug("WmNameGet failed:", err, xid)
}
m.nameInfo[xid] = name
m.notifyInfo[xid] = true
dbus.Emit(m, "Added", uint32(xid))
logger.Infof("Added try icon: \"%s\"(%d)", name, uint32(xid))
}
示例5: isWindowOnPrimaryScreen
func isWindowOnPrimaryScreen(xid xproto.Window) bool {
var err error
win := xwindow.New(XU, xid)
// include shadow
gemo, err := win.DecorGeometry()
if err != nil {
logger.Debug(err)
return false
}
displayRectX := (int)(displayRect.X)
displayRectY := (int)(displayRect.Y)
displayRectWidth := (int)(displayRect.Width)
displayRectHeight := (int)(displayRect.Height)
SHADOW_OFFSET := 10
gemoX := gemo.X() + SHADOW_OFFSET
gemoY := gemo.Y() + SHADOW_OFFSET
isOnPrimary := gemoX+SHADOW_OFFSET >= displayRectX &&
gemoX < displayRectX+displayRectWidth &&
gemoY >= displayRectY &&
gemoY < displayRectY+displayRectHeight
logger.Debugf("isWindowOnPrimaryScreen: %dx%d, %dx%d, %v", gemo.X(),
gemo.Y(), displayRect.X, displayRect.Y, isOnPrimary)
return isOnPrimary
}
示例6: isWindowOverlapDock
func isWindowOverlapDock(xid xproto.Window) bool {
win := xwindow.New(XU, xid)
rect, err := win.DecorGeometry()
if err != nil {
logger.Warning(err)
return false
}
winX := int32(rect.X())
winY := int32(rect.Y())
winWidth := int32(rect.Width())
winHeight := int32(rect.Height())
dockX := int32(displayRect.X) + (int32(displayRect.Width)-
dockProperty.PanelWidth)/2
dockY := int32(displayRect.Y) + int32(displayRect.Height) -
dockProperty.Height
dockWidth := int32(displayRect.Width)
if DisplayModeType(setting.GetDisplayMode()) == DisplayModeModernMode {
dockWidth = dockProperty.PanelWidth
}
// TODO: dock on the other side like top, left.
return dockY < winY+winHeight &&
dockX < winX+winWidth && dockX+dockWidth > winX
}
示例7: createNotify
func createNotify(X *xgbutil.XUtil, event xgb.Event) {
ev := event.(xproto.CreateNotifyEvent)
// values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE;
// xcb_change_window_attributes(wm->conn, id, XCB_CW_EVENT_MASK, values);
win := xwindow.New(X, ev.Window)
win.Listen(xproto.EventMaskPropertyChange)
XWins[ev.Window] = &XWin{
surfaceId: 0,
}
}
示例8: headGeom
func headGeom(X *xgbutil.XUtil) xrect.Rect {
if X.ExtInitialized("XINERAMA") {
heads, err := xinerama.PhysicalHeads(X)
if err == nil {
return heads[0]
}
}
geom, err := xwindow.New(X, X.RootWin()).Geometry()
fatal(err)
return geom
}
示例9: currentTime
// currentTime forcefully causes a PropertyNotify event to fire on the root
// window, then scans the event queue and picks up the time.
//
// It is NOT SAFE to call this function in a place other than Wingo's
// initialization. Namely, this function subverts xevent's queue and reads
// events directly from X.
func currentTime(X *xgbutil.XUtil) (xproto.Timestamp, error) {
wmClassAtom, err := xprop.Atm(X, "WM_CLASS")
if err != nil {
return 0, err
}
stringAtom, err := xprop.Atm(X, "STRING")
if err != nil {
return 0, err
}
// Make sure we're listening to PropertyChange events on the root window.
err = xwindow.New(X, X.RootWin()).Listen(xproto.EventMaskPropertyChange)
if err != nil {
return 0, fmt.Errorf(
"Could not listen to Root window events (PropertyChange): %s", err)
}
// Do a zero-length append on a property as suggested by ICCCM 2.1.
err = xproto.ChangePropertyChecked(
X.Conn(), xproto.PropModeAppend, X.RootWin(),
wmClassAtom, stringAtom, 8, 0, nil).Check()
if err != nil {
return 0, err
}
// Now look for the PropertyNotify generated by that zero-length append
// and return the timestamp attached to that event.
// Note that we do this outside of xgbutil/xevent, since ownership
// is literally the first thing we do after connecting to X.
// (i.e., we don't have our event handling system initialized yet.)
timeout := time.After(3 * time.Second)
for {
select {
case <-timeout:
return 0, fmt.Errorf(
"Expected a PropertyNotify event to get a valid timestamp, " +
"but never received one.")
default:
ev, err := X.Conn().PollForEvent()
if err != nil {
continue
}
if propNotify, ok := ev.(xproto.PropertyNotifyEvent); ok {
X.TimeSet(propNotify.Time) // why not?
return propNotify.Time, nil
}
time.Sleep(100 * time.Millisecond)
}
}
panic("unreachable")
}
示例10: NewSocket
func NewSocket(X *xgbutil.XUtil, wid xproto.Window) (*XEmbedSocket, error) {
sock := &XEmbedSocket{
Window: xwindow.New(X, wid),
id: wid,
X: X,
}
if err := sock.load(); err != nil {
return nil, err
}
return sock, nil
}
示例11: configureRequest
func configureRequest(X *xgbutil.XUtil, event xgb.Event) {
ev := event.(xproto.ConfigureRequestEvent)
win := xwindow.New(X, ev.Window)
win.Configure(
xproto.ConfigWindowX|
xproto.ConfigWindowY|
xproto.ConfigWindowWidth|
xproto.ConfigWindowHeight,
(int)(ev.X), (int)(ev.Y),
(int)(ev.Width), (int)(ev.Height),
ev.Sibling,
ev.StackMode,
)
log.Info("configure request:", ev)
}
示例12: main
func main() {
X, err := xgbutil.NewConn()
if err != nil {
log.Fatal(err)
}
// Start generating other source events.
otherChan := otherSource()
// Start generating X events (by sending client messages to root window).
go xSource(X)
// Listen to those X events.
xwindow.New(X, X.RootWin()).Listen(xproto.EventMaskSubstructureNotify)
// Respond to those X events.
xevent.ClientMessageFun(
func(X *xgbutil.XUtil, ev xevent.ClientMessageEvent) {
atmName, err := xprop.AtomName(X, ev.Type)
if err != nil {
log.Fatal(err)
}
fmt.Printf("ClientMessage: %d. %s\n", ev.Data.Data32[0], atmName)
}).Connect(X, X.RootWin())
// Instead of using the usual xevent.Main, we use xevent.MainPing.
// It runs the main event loop inside a goroutine and returns ping
// channels, which are sent benign values right before an event is
// dequeued and right after that event has finished running all callbacks
// associated with it, respectively.
pingBefore, pingAfter, pingQuit := xevent.MainPing(X)
for {
select {
case <-pingBefore:
// Wait for the event to finish processing.
<-pingAfter
case otherVal := <-otherChan:
fmt.Printf("Processing other event: %d\n", otherVal)
case <-pingQuit:
fmt.Printf("xevent loop has quit")
return
}
}
}
示例13: start
func (wa *fullScreenWorkaround) start() {
var runner func()
runner = func() {
w, _ := ewmh.ActiveWindowGet(wa.xu)
wa.detectTarget(w)
time.AfterFunc(time.Second*5, runner)
}
runner()
root := xwindow.New(wa.xu, wa.xu.RootWin())
root.Listen(xproto.EventMaskPropertyChange)
xevent.PropertyNotifyFun(func(XU *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
if wa.activeWindowAtom == ev.Atom {
w, _ := ewmh.ActiveWindowGet(XU)
wa.detectTarget(w)
}
}).Connect(wa.xu, root.Id)
xevent.Main(wa.xu)
}
示例14: 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)
}
示例15: getViewport
func getViewport() (geom string) {
// new X server connection
X, err := xgbutil.NewConn()
if err != nil {
log.Error(err)
}
// get root window
root := xwindow.New(X, X.RootWin())
// geometry of the root window
rgeom, err := root.Geometry()
if err != nil {
log.Error(err)
}
// Get the rectangles for each of the active physical heads.
// These are returned sorted in order from left to right and then top
// to bottom.
// But first check if Xinerama is enabled. If not, use root geometry.
var heads xinerama.Heads
if X.ExtInitialized("XINERAMA") {
heads, err = xinerama.PhysicalHeads(X)
if err != nil {
log.Error(err)
}
} else {
heads = xinerama.Heads{rgeom}
}
// looking for the first screen, position X: 0, Y: 0
for _, head := range heads {
if head.X() == 0 && head.Y() == 0 {
screenWidth = head.Width()
screenHeight = head.Height()
}
}
geom = fmt.Sprintf("%dx%d", screenWidth-165, screenHeight-165)
return geom
}