Exemplo n.º 1
0
// GrabWindowClass waits a user window selection and returns its class.
//
func (Data) GrabWindowClass() (string, error) {
	if !winFocusRegistered {
		winFocusRegistered = true
		notif.RegisterWindowChangeFocus(onChangeFocus)
	}
	// Not sure the buffer is needed, but just in case,
	// this could prevent stupid deadlock as the callback stay active for the session.
	winFocusChan = make(chan cdglobal.Window, 10)
	defer func() { close(winFocusChan); winFocusChan = nil }()
	select {
	case <-time.After(5 * time.Second): // Timeout.
		return "", errors.New("timeout 5s")

	case win := <-winFocusChan: // Get the first window selected, valid or not, to prevent confusion.
		if win == nil {
			return "", errors.New("no window information found")
		}

		if win.IsTransientWin() {
			win = win.GetTransientWin()
		}
		return win.Class(), nil
	}

	return "", errors.New("unknown case")
}
Exemplo n.º 2
0
// Register starts the applets manager service to use go internal applets in the dock.
//
func Register(log cdtype.Logger) *AppManager {
	apps = NewAppManager(log)

	notif.RegisterContainerLeftClick(apps.OnLeftClick)
	notif.RegisterContainerMiddleClick(apps.OnMiddleClick)
	notif.RegisterContainerMouseScroll(apps.OnMouseScroll)
	notif.RegisterContainerDropData(apps.OnDropData)
	notif.RegisterWindowChangeFocus(apps.OnChangeFocus)
	notif.RegisterContainerMenuIcon(backendmenu.WrapDockMenuCallback(apps.BuildMenu))

	apps.registerApplets()

	return apps
}