예제 #1
0
func isNormalWindow(xid xproto.Window) bool {
	winProps, err := xproto.GetWindowAttributes(XU.Conn(), xid).Reply()
	if err != nil {
		logger.Debug("faild Get WindowAttributes:", xid, err)
		return false
	}
	if winProps.MapState != xproto.MapStateViewable {
		return false
	}
	// logger.Debug("enter isNormalWindow:", xid)
	if wmClass, err := icccm.WmClassGet(XU, xid); err == nil {
		if wmClass.Instance == "explorer.exe" && wmClass.Class == "Wine" {
			return false
		} else if wmClass.Class == "DDELauncher" {
			// FIXME:
			// start_monitor_launcher_window like before?
			return false
		} else if wmClass.Class == "Desktop" {
			// FIXME:
			// get_desktop_pid like before?
			return false
		} else if wmClass.Class == "Dlock" {
			return false
		}
	}
	if isSkipTaskbar(xid) {
		return false
	}
	types, err := ewmh.WmWindowTypeGet(XU, xid)
	if err != nil {
		logger.Debug("Get Window Type failed:", err)
		if _, err := xprop.GetProperty(XU, xid, "_XEMBED_INFO"); err != nil {
			logger.Debug("has _XEMBED_INFO")
			return true
		} else {
			logger.Debug("Get _XEMBED_INFO failed:", err)
			return false
		}
	}

	mayBeDocked := false
	cannotBeDoced := false
	for _, wmType := range types {
		if wmType == "_NET_WM_WINDOW_TYPE_NORMAL" {
			mayBeDocked = true
		} else if wmType == "_NET_WM_WINDOW_TYPE_DIALOG" {
			if !canBeMinimized(xid) {
				mayBeDocked = false
				break
			} else {
				mayBeDocked = true
			}
		} else if contains(cannotBeDockedType, wmType) {
			cannotBeDoced = true
		}
	}

	isNormal := mayBeDocked && !cannotBeDoced
	return isNormal
}
예제 #2
0
//GetClients get windows list
func GetClients() []Client {
	clients := []Client{}
	var err error
	X, err = xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}
	wids, err := ewmh.ClientListGet(X)
	if err != nil {
		log.Fatal(err)
	}
	a, _ := ewmh.ActiveWindowGet(X)
	for _, wid := range wids {
		name, err := ewmh.WmNameGet(X, wid)
		if name == "Shadow" {
			SHADOW = wid
			continue
		}
		if err != nil { // not a fatal error
			log.Println(err)
			name = ""
		}
		desk, _ := ewmh.WmDesktopGet(X, wid)
		class, _ := icccm.WmClassGet(X, wid)
		clients = append(clients, Client{
			wid, name, desk, wid == a, class.Class,
		})
	}
	return clients

}
예제 #3
0
func isDeepinLauncher(xid xproto.Window) bool {
	res, err := icccm.WmClassGet(XU, xid)
	if err != nil {
		return false
	}

	return res.Instance == DDELauncher
}
예제 #4
0
func (r *Region) getDockWindow() (xproto.Window, error) {
	windows, _ := ewmh.ClientListGet(XU)
	for _, xid := range windows {
		res, err := icccm.WmClassGet(XU, xid)
		if err == nil && res.Instance == "dde-dock" {
			return xid, nil
		}
	}
	return 0, errors.New("find dock window failed, it's not existed.")
}
예제 #5
0
func main() {
	X, _ := xgbutil.NewConn()

	active, err := ewmh.ActiveWindowGet(X)

	wmName, err := icccm.WmNameGet(X, active)
	showTest("WM_NAME get", wmName, err)

	err = icccm.WmNameSet(X, active, "hooblah")
	wmName, _ = icccm.WmNameGet(X, active)
	showTest("WM_NAME set", wmName, err)

	wmNormHints, err := icccm.WmNormalHintsGet(X, active)
	showTest("WM_NORMAL_HINTS get", wmNormHints, err)

	wmNormHints.Width += 5
	err = icccm.WmNormalHintsSet(X, active, wmNormHints)
	showTest("WM_NORMAL_HINTS set", wmNormHints, err)

	wmHints, err := icccm.WmHintsGet(X, active)
	showTest("WM_HINTS get", wmHints, err)

	wmHints.InitialState = icccm.StateNormal
	err = icccm.WmHintsSet(X, active, wmHints)
	showTest("WM_NORMAL_HINTS set", wmHints, err)

	wmClass, err := icccm.WmClassGet(X, active)
	showTest("WM_CLASS get", wmClass, err)

	wmClass.Instance = "hoopdy hoop"
	err = icccm.WmClassSet(X, active, wmClass)
	showTest("WM_CLASS set", wmClass, err)

	wmTrans, err := icccm.WmTransientForGet(X, active)
	showTest("WM_TRANSIENT_FOR get", wmTrans, err)

	wmProts, err := icccm.WmProtocolsGet(X, active)
	showTest("WM_PROTOCOLS get", wmProts, err)

	wmClient, err := icccm.WmClientMachineGet(X, active)
	showTest("WM_CLIENT_MACHINE get", wmClient, err)

	err = icccm.WmClientMachineSet(X, active, "Leopard")
	wmClient, _ = icccm.WmClientMachineGet(X, active)
	showTest("WM_CLIENT_MACHINE set", wmClient, err)

	wmState, err := icccm.WmStateGet(X, active)
	showTest("WM_STATE get", wmState, err)

	wmState.Icon = xproto.Window(8365538)
	wmState.State = icccm.StateNormal
	err = icccm.WmStateSet(X, active, wmState)
	wmState, _ = icccm.WmStateGet(X, active)
	showTest("WM_STATE set", wmState, err)
}
예제 #6
0
func find_app_id_by_xid(xid xproto.Window, displayMode DisplayModeType) string {
	var appId string
	if displayMode == DisplayModeModernMode {
		if id, err := xprop.PropValStr(xprop.GetProperty(XU, xid, "_DDE_DOCK_APP_ID")); err == nil {
			appId = getAppIDFromDesktopID(normalizeAppID(id))
			logger.Debug("get app id from _DDE_DOCK_APP_ID", appId)
			return appId
		}
	}
	wmClass, _ := icccm.WmClassGet(XU, xid)
	var wmInstance, wmClassName string
	if wmClass != nil {
		wmInstance = wmClass.Instance
		wmClassName = wmClass.Class
	}
	name, _ := ewmh.WmNameGet(XU, xid)
	pid, err := ewmh.WmPidGet(XU, xid)
	if err != nil {
		logger.Info("get pid failed, ", name)
		if name != "" {
			pid = lookthroughProc(name)
		} else {
			appId = getAppIDFromDesktopID(normalizeAppID(wmClassName))
			logger.Debug("get Pid failed, using wm class name as app id", appId)
			return appId
		}
	}
	iconName, _ := ewmh.WmIconNameGet(XU, xid)
	if pid == 0 {
		appId = normalizeAppID(wmClassName)
		logger.Debug("get window name failed, using wm class name as app id", appId)
		return appId
	} else {
	}
	appId = find_app_id(pid, name, wmInstance, wmClassName, iconName)
	appId = getAppIDFromDesktopID(normalizeAppID(appId))
	logger.Debug(fmt.Sprintf("get appid %q", appId))
	return appId
}
예제 #7
0
func (self *SessionModule) GetWindow(window_id string) (SessionWindow, error) {
	window := SessionWindow{}

	if id, err := self.toX11WindowId(window_id); err == nil {
		xgbWindow := xwindow.New(self.X, id)
		geom, _ := xgbWindow.DecorGeometry()
		process := SessionProcess{}
		window.ID = uint32(id)
		window.Title, _ = ewmh.WmNameGet(self.X, id)
		//window.IconUri           = r.Path() + "/" + id
		windowWorkspace, _ := ewmh.WmDesktopGet(self.X, id)
		activeWinId, _ := ewmh.ActiveWindowGet(self.X)

		if windowWorkspace == 0xFFFFFFFF {
			window.AllWorkspaces = true
		} else {
			window.Workspace = windowWorkspace
		}

		if id == activeWinId {
			window.Active = true
		}

		//  calculate window dimensions from desktop and window frame boundaries
		window.Dimensions.Width = uint(geom.Width())
		window.Dimensions.Height = uint(geom.Height())
		window.Dimensions.X = geom.X()
		window.Dimensions.Y = geom.Y()

		//  fill in process details
		process.PID, _ = ewmh.WmPidGet(self.X, id)
		window.Process = process

		//  get window state flags
		window.Flags = make(map[string]bool)

		//  minimized
		if self.x11HasWmState(id, `_NET_WM_STATE_HIDDEN`) {
			window.Flags["minimized"] = true
		}

		//  shaded
		if self.x11HasWmState(id, `_NET_WM_STATE_SHADED`) {
			window.Flags[`shaded`] = true
		}

		//  maximized
		if self.x11HasWmState(id, `_NET_WM_STATE_MAXIMIZED_VERT`) && self.x11HasWmState(id, `_NET_WM_STATE_MAXIMIZED_HORZ`) {
			window.Flags[`maximized`] = true
		}

		//  above
		if self.x11HasWmState(id, `_NET_WM_STATE_ABOVE`) {
			window.Flags[`above`] = true
		}

		//  below
		if self.x11HasWmState(id, `_NET_WM_STATE_BELOW`) {
			window.Flags[`below`] = true
		}

		//  urgent
		if self.x11HasWmState(id, `_NET_WM_STATE_DEMANDS_ATTENTION`) {
			window.Flags[`urgent`] = true
		}

		//  skip_taskbar
		if self.x11HasWmState(id, `_NET_WM_STATE_SKIP_TASKBAR`) {
			window.Flags[`skip_taskbar`] = true
		}

		//  skip_pager
		if self.x11HasWmState(id, `_NET_WM_STATE_SKIP_PAGER`) {
			window.Flags[`skip_pager`] = true
		}

		//  sticky
		if self.x11HasWmState(id, `_NET_WM_STATE_STICKY`) {
			window.Flags[`sticky`] = true
		}

		//  fullscreen
		if self.x11HasWmState(id, `_NET_WM_STATE_FULLSCREEN`) {
			window.Flags[`fullscreen`] = true
		}

		//  modal
		if self.x11HasWmState(id, `_NET_WM_STATE_MODAL`) {
			window.Flags[`modal`] = true
		}

		//  ICCCM WM_CLASS instance
		if wmClass, err := icccm.WmClassGet(self.X, id); err == nil {
			window.ClassInstance = wmClass.Instance
			window.ClassName = wmClass.Class

			if entry, ok := self.Applications.Entries[window.ClassInstance]; ok {
				window.EntryName = entry.Key
			}
		}

		return window, nil
	} else {
		return window, err
	}
}
예제 #8
0
func (c *Client) fetchXProperties() {
	var err error

	c.hints, err = icccm.WmHintsGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Println(err)
		logger.Message.Printf("Using reasonable defaults for WM_HINTS for %X",
			c.Id())
		c.hints = &icccm.Hints{
			Flags:        icccm.HintInput | icccm.HintState,
			Input:        1,
			InitialState: icccm.StateNormal,
		}
	}

	c.nhints, err = icccm.WmNormalHintsGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Println(err)
		logger.Message.Printf("Using reasonable defaults for WM_NORMAL_HINTS "+
			"for %X", c.Id())
		c.nhints = &icccm.NormalHints{}
	}

	c.protocols, err = icccm.WmProtocolsGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Printf(
			"Window %X does not have WM_PROTOCOLS set.", c.Id())
	}

	c.winTypes, err = ewmh.WmWindowTypeGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Printf("Could not find window type for window %X, "+
			"using 'normal'.", c.Id())
		c.winTypes = []string{"_NET_WM_WINDOW_TYPE_NORMAL"}
	}

	c.winStates, err = ewmh.WmStateGet(wm.X, c.Id())
	if err != nil {
		c.winStates = []string{}
		ewmh.WmStateSet(wm.X, c.Id(), c.winStates)
	}

	c.class, err = icccm.WmClassGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Printf("Could not find window class for window %X: %s",
			c.Id(), err)
		c.class = &icccm.WmClass{
			Instance: "",
			Class:    "",
		}
	}

	trans, _ := icccm.WmTransientForGet(wm.X, c.Id())
	if trans == 0 {
		for _, c2_ := range wm.Clients {
			c2 := c2_.(*Client)
			if c2.transient(c) {
				c.transientFor = c2
				break
			}
		}
	} else if transCli := wm.FindManagedClient(trans); transCli != nil {
		c.transientFor = transCli.(*Client)
	}

	c.setShaped()
}