Ejemplo n.º 1
0
func (w *window) CycleText() string {
	name, err := ewmh.WmNameGet(w.X, w.id)
	if err != nil {
		return "N/A"
	}
	return name
}
Ejemplo n.º 2
0
func (c *Client) refreshName() {
	var newName string

	defer func() {
		if newName != c.name {
			c.name = newName
			c.frames.full.UpdateTitle()
			c.prompts.updateName()
			ewmh.WmVisibleNameSet(wm.X, c.Id(), c.name)

			event.Notify(event.ChangedClientName{c.Id()})
		}
	}()

	newName, _ = ewmh.WmNameGet(wm.X, c.Id())
	if len(newName) > 0 {
		return
	}

	newName, _ = icccm.WmNameGet(wm.X, c.Id())
	if len(newName) > 0 {
		return
	}

	newName = "Unnamed Window"
}
Ejemplo n.º 3
0
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))
}
Ejemplo n.º 4
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

}
Ejemplo n.º 5
0
func getWindowName(X *xgbutil.XUtil, xid uint32) (string, error) {
	name, err := ewmh.WmNameGet(X, xproto.Window(xid))
	if err != nil {
		logger.Warning("Get window name failed:", err)
		return "", err
	}

	return name, nil
}
Ejemplo n.º 6
0
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)
}
Ejemplo n.º 7
0
func (app *RuntimeApp) updateWmName(xid xproto.Window) {
	if name, err := ewmh.WmNameGet(XU, xid); err == nil && name != "" {
		app.xids[xid].Title = name
		return
	}

	if name, err := xprop.PropValStr(xprop.GetProperty(XU, xid,
		"WM_NAME")); err == nil {
		app.xids[xid].Title = name
	}
}
Ejemplo n.º 8
0
func main() {
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	// Get the list of window ids managed by the window manager.
	clients, err := ewmh.ClientListGet(X)
	if err != nil {
		log.Fatal(err)
	}

	// For each client, try to find its icon. If we find one, blend it with
	// a nice background color and show it in its own window.
	// Otherwise, skip it.
	for _, wid := range clients {
		// FindIcon will find an icon closest to the size specified.
		// If one can't be found, the resulting image will be scaled
		// automatically.
		// To avoid scaling the icon, specify '0' for both the width and height.
		// In this case, the largest icon found will be returned.
		xicon, err := xgraphics.FindIcon(X, wid, iconWidth, iconHeight)
		if err != nil {
			log.Printf("Could not find icon for window %d.", wid)
			continue
		}

		// Get the name of this client. (It will be set as the icon window's
		// name.)
		name, err := ewmh.WmNameGet(X, wid)
		if err != nil { // not a fatal error
			log.Println(err)
			name = ""
		}

		// Blend a pink background color so its easy to see that alpha blending
		// works.
		xgraphics.BlendBgColor(xicon, color.RGBA{0xff, 0x0, 0xff, 0xff})
		xicon.XShowExtra(name, false)
	}

	// All we really need to do is block, so a 'select{}' would be sufficient.
	// But running the event loop will emit errors if anything went wrong.
	xevent.Main(X)
}
Ejemplo n.º 9
0
func (c *client) refreshName() {
	c.name, _ = ewmh.WmVisibleNameGet(c.X, c.Id())
	if len(c.name) > 0 {
		return
	}

	c.name, _ = ewmh.WmNameGet(c.X, c.Id())
	if len(c.name) > 0 {
		return
	}

	c.name, _ = icccm.WmNameGet(c.X, c.Id())
	if len(c.name) > 0 {
		return
	}

	c.name = "Unnamed Window"
}
Ejemplo n.º 10
0
func main() {
	// Connect to the X server using the DISPLAY environment variable.
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	// Get a list of all client ids.
	clientids, err := ewmh.ClientListGet(X)
	if err != nil {
		log.Fatal(err)
	}

	// Iterate through each client, find its name and find its size.
	for _, clientid := range clientids {
		name, err := ewmh.WmNameGet(X, clientid)

		// If there was a problem getting _NET_WM_NAME or if its empty,
		// try the old-school version.
		if err != nil || len(name) == 0 {
			name, err = icccm.WmNameGet(X, clientid)

			// If we still can't find anything, give up.
			if err != nil || len(name) == 0 {
				name = "N/A"
			}
		}

		// Now find the geometry, including decorations, of the client window.
		// Note that DecorGeometry actually traverses the window tree by
		// issuing QueryTree requests until a top-level window (i.e., its
		// parent is the root window) is found. The geometry of *that* window
		// is then returned.
		dgeom, err := xwindow.New(X, clientid).DecorGeometry()
		if err != nil {
			log.Printf("Could not get geometry for %s (0x%X) because: %s",
				name, clientid, err)
			continue
		}

		fmt.Printf("%s (0x%x)\n", name, clientid)
		fmt.Printf("\tGeometry: %s\n", dgeom)
	}
}
Ejemplo n.º 11
0
func (c *Client) refreshName() {
	defer func() {
		c.frames.full.UpdateTitle()
		c.prompts.updateName()
	}()

	c.name, _ = ewmh.WmNameGet(wm.X, c.Id())
	if len(c.name) > 0 {
		return
	}

	c.name, _ = icccm.WmNameGet(wm.X, c.Id())
	if len(c.name) > 0 {
		return
	}

	c.name = "Unnamed Window"
	ewmh.WmVisibleNameSet(wm.X, c.Id(), c.name)
}
Ejemplo n.º 12
0
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)
}
Ejemplo n.º 13
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
}
Ejemplo n.º 14
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
}
Ejemplo n.º 15
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
	}
}
Ejemplo n.º 16
0
func main() {
	X, Xerr = xgbutil.NewConn()
	if Xerr != nil {
		panic(Xerr)
	}

	active, _ := ewmh.ActiveWindowGet(X)

	parent, _ := xwindow.ParentWindow(X, active)
	actOpacity, _ := ewmh.WmWindowOpacityGet(X, parent)
	fmt.Printf("Opacity for active window: %f\n", actOpacity)

	showDesk, _ := ewmh.ShowingDesktopGet(X)
	fmt.Printf("Showing desktop? %v\n", showDesk)

	wmName, err := ewmh.GetEwmhWM(X)
	if err != nil {
		fmt.Printf("No conforming window manager found... :-(\n")
		fmt.Println(err)
	} else {
		fmt.Printf("Window manager: %s\n", wmName)
	}

	pager := xproto.Window(0x160001e)
	middle := xproto.Window(0x3200016)
	geom, _ := ewmh.DesktopGeometryGet(X)
	desktops, _ := ewmh.DesktopNamesGet(X)
	curdesk, _ := ewmh.CurrentDesktopGet(X)
	clients, _ := ewmh.ClientListGet(X)
	activeName, _ := ewmh.WmNameGet(X, active)

	fmt.Printf("Active window: %x\n", active)
	fmt.Printf("Current desktop: %d\n", curdesk)
	fmt.Printf("Client list: %v\n", clients)
	fmt.Printf("Desktop geometry: (width: %d, height: %d)\n",
		geom.Width, geom.Height)
	fmt.Printf("Active window name: %s\n", activeName)
	fmt.Printf("Desktop names: %s\n", desktops)

	var desk string
	if curdesk < len(desktops) {
		desk = desktops[curdesk]
	} else {
		desk = string(curdesk)
	}
	fmt.Printf("Current desktop: %s\n", desk)

	// fmt.Printf("\nChanging current desktop to 25 from %d\n", curdesk)
	ewmh.CurrentDesktopSet(X, curdesk)
	// fmt.Printf("Current desktop is now: %d\n", ewmh.CurrentDesktop(X))

	fmt.Printf("Setting active win to %x\n", middle)
	// ewmh.ActiveWindowReq(X, middle)

	rand.Seed(int64(time.Now().Nanosecond()))
	randStr := make([]byte, 20)
	for i, _ := range randStr {
		if rf := rand.Float32(); rf < 0.40 {
			randStr[i] = byte('a' + rand.Intn('z'-'a'))
		} else if rf < 0.80 {
			randStr[i] = byte('A' + rand.Intn('Z'-'A'))
		} else {
			randStr[i] = ' '
		}
	}

	ewmh.WmNameSet(X, active, string(randStr))
	newName, _ := ewmh.WmNameGet(X, active)
	fmt.Printf("New name: %s\n", newName)

	// deskNames := ewmh.DesktopNamesGet(X)
	// fmt.Printf("Desktop names: %s\n", deskNames)
	// deskNames[len(deskNames) - 1] = "xgbutil"
	// ewmh.DesktopNamesSet(X, deskNames)
	// fmt.Printf("Desktop names: %s\n", ewmh.DesktopNamesGet(X))

	supported, _ := ewmh.SupportedGet(X)
	fmt.Printf("Supported hints: %v\n", supported)
	fmt.Printf("Setting supported hints...\n")
	ewmh.SupportedSet(X, []string{"_NET_CLIENT_LIST", "_NET_WM_NAME",
		"_NET_WM_DESKTOP"})

	numDesks, _ := ewmh.NumberOfDesktopsGet(X)
	fmt.Printf("Number of desktops: %d\n", numDesks)
	// ewmh.NumberOfDesktopsReq(X.EwmhNumberOfDesktops(X) + 1)
	// time.Sleep(time.Second)
	// fmt.Printf("Number of desktops: %d\n", ewmh.NumberOfDesktops(X))

	viewports, _ := ewmh.DesktopViewportGet(X)
	fmt.Printf("Viewports (%d): %v\n", len(viewports), viewports)

	// viewports[2].X = 50
	// viewports[2].Y = 293
	// ewmh.DesktopViewportSet(X, viewports)
	// time.Sleep(time.Second)
	//
	// viewports = ewmh.DesktopViewport(X)
	// fmt.Printf("Viewports (%d): %v\n", len(viewports), viewports)

	// ewmh.CurrentDesktopReq(X, 3)

	visDesks, _ := ewmh.VisibleDesktopsGet(X)
	workarea, _ := ewmh.WorkareaGet(X)
	fmt.Printf("Visible desktops: %v\n", visDesks)
	fmt.Printf("Workareas: %v\n", workarea)
	// fmt.Printf("Virtual roots: %v\n", ewmh.VirtualRoots(X))
	// fmt.Printf("Desktop layout: %v\n", ewmh.DesktopLayout(X))
	fmt.Printf("Closing window %x\n", 0x2e004c5)
	ewmh.CloseWindow(X, 0x1e00cdf)

	fmt.Printf("Moving/resizing window: %x\n", 0x2e004d0)
	ewmh.MoveresizeWindow(X, 0x2e004d0, 1920, 30, 500, 500)

	// fmt.Printf("Trying to initiate a moveresize...\n")
	// ewmh.WmMoveresize(X, 0x2e004db, xgbutil.EwmhMove)
	// time.Sleep(5 * time.Second)
	// ewmh.WmMoveresize(X, 0x2e004db, xgbutil.EwmhCancel)

	// fmt.Printf("Stacking window %x...\n", 0x2e00509)
	// ewmh.RestackWindow(X, 0x2e00509)

	fmt.Printf("Requesting frame extents for active window...\n")
	ewmh.RequestFrameExtents(X, active)

	activeDesk, _ := ewmh.WmDesktopGet(X, active)
	activeType, _ := ewmh.WmWindowTypeGet(X, active)
	fmt.Printf("Active window's desktop: %d\n", activeDesk)
	fmt.Printf("Active's types: %v\n", activeType)
	// fmt.Printf("Pager's types: %v\n", ewmh.WmWindowType(X, 0x180001e))

	// fmt.Printf("Pager's state: %v\n", ewmh.WmState(X, 0x180001e))

	// ewmh.WmStateReq(X, active, xgbutil.EwmhStateToggle,
	// "_NET_WM_STATE_HIDDEN")
	// ewmh.WmStateReqExtra(X, active, xgbutil.EwmhStateToggle,
	// "_NET_WM_STATE_MAXIMIZED_VERT",
	// "_NET_WM_STATE_MAXIMIZED_HORZ", 2)

	activeAllowed, _ := ewmh.WmAllowedActionsGet(X, active)
	fmt.Printf("Allowed actions on active: %v\n", activeAllowed)

	struts, err := ewmh.WmStrutGet(X, pager)
	if err != nil {
		fmt.Printf("Pager struts: %v\n", err)
	} else {
		fmt.Printf("Pager struts: %v\n", struts)
	}

	pstruts, err := ewmh.WmStrutPartialGet(X, pager)
	if err != nil {
		fmt.Printf("Pager struts partial: %v - %v\n", pstruts, err)
	} else {
		fmt.Printf("Pager struts partial: %v\n", pstruts.BottomStartX)
	}

	// fmt.Printf("Icon geometry for active: %v\n",
	// ewmh.WmIconGeometry(X, active))

	icons, _ := ewmh.WmIconGet(X, active)
	fmt.Printf("Active window's (%x) icon data: (length: %v)\n",
		active, len(icons))
	for _, icon := range icons {
		fmt.Printf("\t(%d, %d)", icon.Width, icon.Height)
		fmt.Printf(" :: %d == %d\n", icon.Width*icon.Height, len(icon.Data))
	}
	// fmt.Printf("Now set them again...\n")
	// ewmh.WmIconSet(X, active, icons[:len(icons) - 1])
}