Beispiel #1
0
func (c *Client) cbPropertyNotify() xevent.PropertyNotifyFun {
	f := func(X *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
		name, err := xprop.AtomName(wm.X, ev.Atom)
		if err != nil {
			logger.Warning.Printf("Could not get property atom name for '%s' "+
				"because: %s.", ev, err)
			return
		}

		logger.Lots.Printf("Updating property %s with state %v on window %s",
			name, ev.State, c)
		c.handleProperty(name)
	}
	return xevent.PropertyNotifyFun(f)
}
Beispiel #2
0
func (c *client) cbPropertyNotify() xevent.PropertyNotifyFun {
	// helper function to log property vals
	showVals := func(o, n interface{}) {
		logger.Lots.Printf("\tOld value: '%s', new value: '%s'", o, n)
	}
	f := func(X *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
		name, err := xprop.AtomName(c.X, ev.Atom)
		if err != nil {
			logger.Warning.Printf("Could not get property atom name for '%s' "+
				"because: %s.", ev, err)
		}

		logger.Lots.Printf("Updating property %s with state %v on window %s",
			name, ev.State, c)
		switch name {
		case "_NET_WM_VISIBLE_NAME":
			fallthrough
		case "_NET_WM_NAME":
			fallthrough
		case "WM_NAME":
			c.refreshName()
		case "_NET_WM_ICON":
		case "WM_HINTS":
			if hints, err := icccm.WmHintsGet(X, c.Id()); err == nil {
				c.hints = hints
			}
		case "WM_NORMAL_HINTS":
			if nhints, err := icccm.WmNormalHintsGet(X, c.Id()); err == nil {
				c.nhints = nhints
			}
		case "WM_TRANSIENT_FOR":
			if trans, err := icccm.WmTransientForGet(X, c.Id()); err == nil {
				if transCli := wingo.findManagedClient(trans); transCli != nil {
					c.transientFor = transCli
				}
			}
		case "_NET_WM_USER_TIME":
			if newTime, err := ewmh.WmUserTimeGet(X, c.Id()); err == nil {
				showVals(c.time, newTime)
				c.time = xproto.Timestamp(newTime)
			}
		case "_NET_WM_STRUT_PARTIAL":
		}

	}
	return xevent.PropertyNotifyFun(f)
}
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)
}
func (m *ClientManager) listenRootWindow() {
	var update = func() {
		list, err := ewmh.ClientListGet(XU)
		if err != nil {
			logger.Warning("Can't Get _NET_CLIENT_LIST", err)
		}
		isLauncherShown = false
		for _, xid := range list {
			if !isDeepinLauncher(xid) {
				continue
			}

			winProps, err :=
				xproto.GetWindowAttributes(XU.Conn(),
					xid).Reply()
			if err != nil {
				break
			}
			if winProps.MapState == xproto.MapStateViewable {
				isLauncherShown = true
			}
			break
		}
		ENTRY_MANAGER.runtimeAppChanged(list)
	}

	xwindow.New(XU, XU.RootWin()).Listen(xproto.EventMaskPropertyChange)
	xevent.PropertyNotifyFun(func(XU *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
		switch ev.Atom {
		case _NET_CLIENT_LIST:
			update()
		case _NET_ACTIVE_WINDOW:
			var err error
			isLauncherShown = false
			if activeWindow, err = ewmh.ActiveWindowGet(XU); err == nil {
				appId := find_app_id_by_xid(activeWindow,
					DisplayModeType(setting.GetDisplayMode()))
				logger.Debug("current active window:", appId)
				if rApp, ok := ENTRY_MANAGER.runtimeApps[appId]; ok {
					logger.Debug("find runtime app")
					rApp.setLeader(activeWindow)
					rApp.updateState(activeWindow)
				}

				logger.Debug("active window is", appId)
				if appId != DDELauncher {
					LAUNCHER, err := launcher.NewLauncher(
						"com.deepin.dde.launcher",
						"/com/deepin/dde/launcher",
					)
					if err != nil {
						logger.Debug(err)
					} else {
						LAUNCHER.Hide()
						launcher.DestroyLauncher(LAUNCHER)
					}
				} else {
					isLauncherShown = true
				}

				lastActive = appId
				dbus.Emit(m, "ActiveWindowChanged", uint32(activeWindow))
			}

			hideMode := HideModeType(setting.GetHideMode())
			if hideMode == HideModeSmartHide || hideMode == HideModeKeepHidden {
				hideModemanager.UpdateState()
			}
		case _NET_SHOWING_DESKTOP:
			dbus.Emit(m, "ShowingDesktopChanged")
		case DEEPIN_SCREEN_VIEWPORT:
			updateCurrentViewport()
		}
	}).Connect(XU, XU.RootWin())

	update()
	xevent.Main(XU)
}
Beispiel #5
0
func main() {
	sleepy := time.Millisecond
	X, _ := xgbutil.NewConn()
	conn := X.Conn()

	aDesktop := "_NET_WM_DESKTOP"
	aActive := "_NET_ACTIVE_WINDOW"

	xwindow.Listen(X, X.RootWin(), xproto.EventMaskPropertyChange)
	xevent.PropertyNotifyFun(
		func(X *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
			for i := 0; i < 1; i++ {
				log.Println("PROPERTY CHANGE")
			}
		}).Connect(X, X.RootWin())

	go func() {
		for {
			reply, err := xproto.InternAtom(conn, true, uint16(len(aDesktop)),
				aDesktop).Reply()
			if err != nil {
				log.Fatal(err)
			}

			log.Println("A1-299", reply.Sequence, reply.Atom)
			time.Sleep(sleepy)
		}
	}()

	go func() {
		for {
			reply, err := xproto.InternAtom(conn, true, uint16(len(aActive)),
				aActive).Reply()
			if err != nil {
				log.Fatal(err)
			}

			log.Println("A2-294", reply.Sequence, reply.Atom)
			time.Sleep(sleepy)
		}
	}()

	go func() {
		for {
			reply, err := xproto.GetGeometry(conn, 0x1).Reply()
			if err != nil {
				log.Println("0x1:", err)
			} else {
				log.Println("0x1:", reply)
			}
			time.Sleep(sleepy)
		}
	}()

	go func() {
		for {
			reply, err := xproto.GetGeometry(conn, 0x2).Reply()
			if err != nil {
				log.Println("0x2:", err)
			} else {
				log.Println("0x2:", reply)
			}
			time.Sleep(sleepy)
		}
	}()

	go xevent.Main(X)
	select {}
}
Beispiel #6
0
func (app *RuntimeApp) attachXid(xid xproto.Window) {
	logger.Debugf("attach 0x%x to %s", xid, app.Id)
	if _, ok := app.xids[xid]; ok {
		logger.Debugf("0x%x is already on %s", xid, app.Id)
		return
	}
	xwin := xwindow.New(XU, xid)
	xwin.Listen(xproto.EventMaskPropertyChange | xproto.EventMaskStructureNotify | xproto.EventMaskVisibilityChange)
	winfo := &WindowInfo{Xid: xid}
	xevent.UnmapNotifyFun(func(XU *xgbutil.XUtil, ev xevent.UnmapNotifyEvent) {
		app.detachXid(xid)
	}).Connect(XU, xid)
	xevent.DestroyNotifyFun(func(XU *xgbutil.XUtil, ev xevent.DestroyNotifyEvent) {
		app.detachXid(xid)
	}).Connect(XU, xid)
	xevent.PropertyNotifyFun(func(XU *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
		app.lock.Lock()
		defer app.lock.Unlock()
		switch ev.Atom {
		case ATOM_WINDOW_ICON:
			app.updateIcon(xid)
			app.updateAppid(xid)
			app.notifyChanged()
		case ATOM_WINDOW_NAME:
			if app.updateWMNameTimer != nil {
				app.updateWMNameTimer.Stop()
				app.updateWMNameTimer = nil
			}
			app.updateWMNameTimer = time.AfterFunc(time.Millisecond*20, func() {
				app.updateWmName(xid)
				app.updateAppid(xid)
				app.notifyChanged()
				app.updateWMNameTimer = nil
			})
		case ATOM_WINDOW_STATE:
			logger.Debugf("%s(0x%x) WM_STATE is changed", app.Id, xid)
			if app.CurrentInfo.Xid == xid {
				logger.Debug("is current window info changed")
				app.updateState(xid)
			}
			app.notifyChanged()

			if HideModeType(setting.GetHideMode()) != HideModeSmartHide {
				break
			}

			time.AfterFunc(time.Millisecond*20, func() {
				app.updateOverlap(xid)
			})
		// case ATOM_DEEPIN_WINDOW_VIEWPORTS:
		// 	app.updateViewports(xid)
		case ATOM_WINDOW_TYPE:
			if !isNormalWindow(ev.Window) {
				app.detachXid(xid)
			}
		case ATOM_DOCK_APP_ID:
			app.updateAppid(xid)
			app.notifyChanged()
		}
	}).Connect(XU, xid)
	update := func(xid xproto.Window) {
		app.lock.Lock()
		defer app.lock.Unlock()
		app.updateOverlap(xid)
	}
	xevent.ConfigureNotifyFun(func(XU *xgbutil.XUtil, ev xevent.ConfigureNotifyEvent) {
		app.lock.Lock()
		defer app.lock.Unlock()
		if app.updateConfigureTimer != nil {
			app.updateConfigureTimer.Stop()
			app.updateConfigureTimer = nil
		}
		app.updateConfigureTimer = time.AfterFunc(time.Millisecond*20, func() {
			update(ev.Window)
			app.updateConfigureTimer = nil
		})
	}).Connect(XU, xid)
	app.xids[xid] = winfo
	update(xid)
	app.updateIcon(xid)
	app.updateWmName(xid)
	app.updateState(xid)
	// app.updateViewports(xid)
	app.notifyChanged()
}
Beispiel #7
0
func main() {
	X, err := xgbutil.Dial("")
	if err != nil {
		logger.Error.Println(err)
		logger.Error.Println("Error connecting to X, quitting...")
		return
	}
	defer X.Conn().Close()

	// Get command from arguments
	flag.Parse()
	if flag.NArg() < 1 {
		fmt.Fprintln(os.Stderr, "Usage: wingo-cmd CommandName [CommandArgs]")
		return
	}

	commandPieces := flag.Args()
	cmdName := commandPieces[0]
	cmdFull := strings.Join(commandPieces, " ")

	// make sure we start with failure
	cmdusage.StatusSet(X, false)
	success := false

	// Set the command before sending request to run command.
	err = cmdusage.CmdSet(X, cmdFull)
	if err != nil {
		logger.Error.Printf("Could not set command: %s", err)
		return
	}

	// Issue the command!
	ewmh.ClientEvent(X, X.RootWin(), "_WINGO_CMD")

	// Now let's set up a handler to detect when the status changes
	xevent.PropertyNotifyFun(
		func(X *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
			name, err := xprop.AtomName(X, ev.Atom)
			if err != nil {
				logger.Warning.Println(
					"Could not get property atom name for", ev.Atom)
				return
			}

			if name == "_WINGO_CMD_STATUS" {
				success = cmdusage.StatusGet(X)
				if success {
					os.Exit(0)
				} else {
					logger.Warning.Printf("Error running '%s'", cmdFull)
					cmdusage.ShowUsage(cmdName)
					os.Exit(1)
				}
			}
		}).Connect(X, X.RootWin())

	// Listen to Root property change events
	xwindow.Listen(X, X.RootWin(), xproto.EventMaskPropertyChange)

	go xevent.Main(X)

	time.Sleep(time.Second * 5)

	logger.Error.Println(
		"Timed out while trying to issue command to Wingo. " +
			"Are you sure Wingo is running?")
	os.Exit(1)
}