func getWindowPid(X *xgbutil.XUtil, xid uint32) (uint32, error) {
	pid, err := ewmh.WmPidGet(X, xproto.Window(xid))
	if err != nil {
		logger.Warning("Get window pid failed:", err)
		return 0, err
	}

	return uint32(pid), nil
}
func find_exec_by_xid(xid xproto.Window) string {
	pid, _ := ewmh.WmPidGet(XU, xid)
	if pid == 0 {
		name, _ := ewmh.WmNameGet(XU, xid)
		if name != "" {
			pid = lookthroughProc(name)
		}
	}
	return find_exec_by_pid(pid)
}
Exemple #3
0
func getActiveApp(X *xgbutil.XUtil) (app App) {
	active, err := ewmh.ActiveWindowGet(X)
	if err != nil {
		log.Fatal(err)
	}

	app.PID, err = ewmh.WmPidGet(X, active)
	if err != nil {
		log.Println("Couldn't get PID of window (0x%x)", active)
	}

	app.Name, err = ewmh.WmNameGet(X, active)
	if err != nil || len(app.Name) == 0 {
		app.Name, err = icccm.WmNameGet(X, active)
		// If we still can't find anything, give up.
		if err != nil || len(app.Name) == 0 {
			app.Name = "N/A"
		}
	}
	return
}
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
}
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
	}
}