func (w *Window) setVisibility(v bool) { xproto.ChangeWindowAttributesChecked(w.Conn, w.root, xproto.CwEventMask, windowOff) if v { xproto.MapWindow(w.Conn, w.Window) } else { xproto.UnmapWindow(w.Conn, w.Window) } xproto.ChangeWindowAttributesChecked(w.Conn, w.root, xproto.CwEventMask, windowOn) }
// Listen will tell X to report events corresponding to the event masks // provided for the given window. If a call to Listen is omitted, you will // not receive the events you desire. // Event masks are constants declare in the xgb/xproto package starting with the // EventMask prefix. func (w *Window) Listen(evMasks ...int) error { evMask := 0 for _, mask := range evMasks { evMask |= mask } return xproto.ChangeWindowAttributesChecked(w.X.Conn(), w.Id, xproto.CwEventMask, []uint32{uint32(evMask)}).Check() }
func becomeTheWM() { if err := xp.ChangeWindowAttributesChecked(xConn, rootXWin, xp.CwEventMask, []uint32{ xp.EventMaskButtonPress | xp.EventMaskButtonRelease | xp.EventMaskPointerMotion | xp.EventMaskSubstructureRedirect, }).Check(); err != nil { if _, ok := err.(xp.AccessError); ok { log.Fatal("could not become the window manager. Is another window manager running?") } log.Fatal(err) } }
func start_server(c *xgb.Conn, s *xproto.ScreenInfo, rl_execute_atom xproto.Atom) { win, err := xproto.NewWindowId(c) if err != nil { panic(err) } // Make a window which can be communicated with err = xproto.CreateWindowChecked(c, s.RootDepth, win, s.Root, 0, 0, 1, 1, 0, 0, 0, 0, nil).Check() if err != nil { panic(err) } err = xproto.ChangePropertyChecked(c, xproto.PropModeReplace, win, rl_execute_atom, xproto.AtomString, 8, xproto.PropModeReplace, []byte("\x00")).Check() if err != nil { panic(err) } err = xproto.ChangeWindowAttributesChecked(c, win, xproto.CwEventMask, []uint32{xproto.EventMaskPropertyChange}).Check() if err != nil { panic(err) } get_execute_value := func() string { response, err := xproto.GetProperty(c, false, win, rl_execute_atom, xproto.GetPropertyTypeAny, 0, 1024).Reply() if err != nil { panic(err) } result := string(response.Value) return result } log.Print("Ready and waiting..") // Event loop for { reply, err := c.WaitForEvent() if err != nil { log.Panic("Error in event loop:", err) } switch event := reply.(type) { case xproto.PropertyNotifyEvent: if event.Window == win && event.Atom == rl_execute_atom { values := strings.Split(get_execute_value(), "\x00") run(values) } } } }
func initDesktop(xScreen *xp.ScreenInfo) { xFont, err := xp.NewFontId(xConn) if err != nil { log.Fatal(err) } xCursor, err := xp.NewCursorId(xConn) if err != nil { log.Fatal(err) } err = xp.OpenFontChecked(xConn, xFont, uint16(len("cursor")), "cursor").Check() if err != nil { log.Fatal(err) } const xcLeftPtr = 68 // XC_left_ptr from cursorfont.h. err = xp.CreateGlyphCursorChecked( xConn, xCursor, xFont, xFont, xcLeftPtr, xcLeftPtr+1, 0xffff, 0xffff, 0xffff, 0, 0, 0).Check() if err != nil { log.Fatal(err) } err = xp.CloseFontChecked(xConn, xFont).Check() if err != nil { log.Fatal(err) } desktopXWin, err = xp.NewWindowId(xConn) if err != nil { log.Fatal(err) } desktopXGC, err = xp.NewGcontextId(xConn) if err != nil { log.Fatal(err) } desktopWidth = xScreen.WidthInPixels desktopHeight = xScreen.HeightInPixels if err := xp.CreateWindowChecked( xConn, xScreen.RootDepth, desktopXWin, xScreen.Root, 0, 0, desktopWidth, desktopHeight, 0, xp.WindowClassInputOutput, xScreen.RootVisual, xp.CwOverrideRedirect|xp.CwEventMask, []uint32{ 1, xp.EventMaskExposure, }, ).Check(); err != nil { log.Fatal(err) } if len(xSettings) != 0 { initXSettings() } if err := xp.ConfigureWindowChecked( xConn, desktopXWin, xp.ConfigWindowStackMode, []uint32{ xp.StackModeBelow, }, ).Check(); err != nil { log.Fatal(err) } if err := xp.ChangeWindowAttributesChecked( xConn, desktopXWin, xp.CwBackPixel|xp.CwCursor, []uint32{ xScreen.BlackPixel, uint32(xCursor), }, ).Check(); err != nil { log.Fatal(err) } if err := xp.CreateGCChecked( xConn, desktopXGC, xp.Drawable(xScreen.Root), 0, nil, ).Check(); err != nil { log.Fatal(err) } if err := xp.MapWindowChecked(xConn, desktopXWin).Check(); err != nil { log.Fatal(err) } }
func manage(xWin xp.Window, mapRequest bool) { callFocus := false w := findWindow(func(w *window) bool { return w.xWin == xWin }) if w == nil { wmDeleteWindow, wmTakeFocus := false, false if prop, err := xp.GetProperty(xConn, false, xWin, atomWMProtocols, xp.GetPropertyTypeAny, 0, 64).Reply(); err != nil { log.Println(err) } else if prop != nil { for v := prop.Value; len(v) >= 4; v = v[4:] { switch xp.Atom(u32(v)) { case atomWMDeleteWindow: wmDeleteWindow = true case atomWMTakeFocus: wmTakeFocus = true } } } transientFor := (*window)(nil) if prop, err := xp.GetProperty(xConn, false, xWin, atomWMTransientFor, xp.GetPropertyTypeAny, 0, 64).Reply(); err != nil { log.Println(err) } else if prop != nil { if v := prop.Value; len(v) == 4 { transientForXWin := xp.Window(u32(v)) transientFor = findWindow(func(w *window) bool { return w.xWin == transientForXWin }) } } k := screens[0].workspace if p, err := xp.QueryPointer(xConn, rootXWin).Reply(); err != nil { log.Println(err) } else if p != nil { k = screenContaining(p.RootX, p.RootY).workspace } w = &window{ transientFor: transientFor, xWin: xWin, rect: xp.Rectangle{ X: offscreenXY, Y: offscreenXY, Width: 1, Height: 1, }, wmDeleteWindow: wmDeleteWindow, wmTakeFocus: wmTakeFocus, } f := k.focusedFrame previous := k.dummyWindow.link[prev] if transientFor != nil { previous = transientFor } else if f.window != nil { previous = f.window } w.link[next] = previous.link[next] w.link[prev] = previous w.link[next].link[prev] = w w.link[prev].link[next] = w if transientFor != nil && transientFor.frame != nil { f = transientFor.frame f.window, transientFor.frame = nil, nil } else if f.window != nil { f = k.mainFrame.firstEmptyFrame() } if f != nil { f.window, w.frame = w, f callFocus = f == k.focusedFrame } else { pulseChan <- time.Now() } check(xp.ChangeWindowAttributesChecked(xConn, xWin, xp.CwEventMask, []uint32{xp.EventMaskEnterWindow | xp.EventMaskStructureNotify}, )) w.configure() if transientFor != nil { transientFor.hasTransientFor = true transientFor.configure() } } if mapRequest { check(xp.MapWindowChecked(xConn, xWin)) } if callFocus { focus(w) } makeLists() pulseChan <- time.Now() }