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


Golang xwindow.New函數代碼示例

本文整理匯總了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)
}
開發者ID:justjake,項目名稱:j3,代碼行數:34,代碼來源:action.go

示例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()
	}
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:29,代碼來源:runtime_apps.go

示例3: Root

func Root() {
	rwin := xwindow.New(X, X.RootWin())
	for _, c := range Clients {
		c.Unfocused()
	}
	rwin.Focus()
}
開發者ID:dlintw,項目名稱:wingo,代碼行數:7,代碼來源:focus.go

示例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))
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:33,代碼來源:traymanager.go

示例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
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:29,代碼來源:client_manager.go

示例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
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:26,代碼來源:client_manager.go

示例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,
	}
}
開發者ID:fangyuanziti,項目名稱:wayland-html,代碼行數:11,代碼來源:xwm.go

示例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
}
開發者ID:cshapeshifter,項目名稱:wingo,代碼行數:12,代碼來源:main.go

示例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")
}
開發者ID:mkrull,項目名稱:wingo,代碼行數:58,代碼來源:ownership.go

示例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
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:13,代碼來源:embedder.go

示例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)
}
開發者ID:fangyuanziti,項目名稱:wayland-html,代碼行數:16,代碼來源:xwm.go

示例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
		}
	}
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:44,代碼來源:main.go

示例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)
}
開發者ID:felixonmars,項目名稱:dde-daemon,代碼行數:19,代碼來源:workaround_fullscreen.go

示例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)
}
開發者ID:xthexder,項目名稱:superhexagon,代碼行數:42,代碼來源:superhexagon.go

示例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
}
開發者ID:cabrel,項目名稱:xfcm,代碼行數:42,代碼來源:xfcm.go


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