(w xproto.Window, createdBeforeWM bool)
| 2213 | } |
| 2214 | |
| 2215 | func (wm *WindowManager) Frame(w xproto.Window, createdBeforeWM bool) { |
| 2216 | |
| 2217 | if _, exists := wm.windows[w]; exists { |
| 2218 | fmt.Println("Already framed", w) |
| 2219 | return |
| 2220 | } |
| 2221 | BorderWidth := wm.config.BorderWidth |
| 2222 | Col := wm.config.BorderUnactive |
| 2223 | |
| 2224 | // get the geometry of the window so we can match the frame to it |
| 2225 | geometry, err := xproto.GetGeometry(wm.conn, xproto.Drawable(w)).Reply() |
| 2226 | |
| 2227 | if err != nil { |
| 2228 | slog.Error("Couldn't get window geometry", "error:", err.Error()) |
| 2229 | return |
| 2230 | } |
| 2231 | |
| 2232 | attribs, err := xproto.GetWindowAttributes( |
| 2233 | wm.conn, |
| 2234 | w, |
| 2235 | ).Reply() |
| 2236 | |
| 2237 | if err != nil { |
| 2238 | slog.Error("Couldn't get window attributes", "error:", err.Error()) |
| 2239 | return |
| 2240 | } |
| 2241 | |
| 2242 | wm.isAbove(w) |
| 2243 | |
| 2244 | // skips |
| 2245 | if attribs.OverrideRedirect { |
| 2246 | fmt.Println("Skipping override-redirect window", w) |
| 2247 | return |
| 2248 | } |
| 2249 | |
| 2250 | if createdBeforeWM && attribs.MapState != xproto.MapStateViewable { |
| 2251 | fmt.Println("Skipping unmapped pre-existing window", w) |
| 2252 | return |
| 2253 | } |
| 2254 | |
| 2255 | // map the frame |
| 2256 | _ = xproto.MapWindowChecked( |
| 2257 | wm.conn, |
| 2258 | w, |
| 2259 | ).Check() |
| 2260 | |
| 2261 | // center it |
| 2262 | windowMidX := math.Round(float64(geometry.Width) / 2) |
| 2263 | windowMidY := math.Round(float64(geometry.Height) / 2) |
| 2264 | screenMidX := math.Round(float64(wm.width) / 2) |
| 2265 | screenMidY := math.Round(float64(wm.height) / 2) |
| 2266 | topLeftX := screenMidX - windowMidX |
| 2267 | topLeftY := screenMidY - windowMidY |
| 2268 | |
| 2269 | err = xproto.ConfigureWindowChecked(wm.conn, w, xproto.ConfigWindowX|xproto.ConfigWindowY|xproto.ConfigWindowWidth|xproto.ConfigWindowHeight, []uint32{ |
| 2270 | uint32(topLeftX), |
| 2271 | uint32(topLeftY), |
| 2272 | uint32(geometry.Width), |
no test coverage detected