- xConn, err := xgb.NewConn()
- if err != nil {
- log.Fatal(err)
- }
- xc = xConn
- defer xc.Close()
-
- setup := xproto.Setup(xc)
- if setup == nil || len(setup.Roots) < 1 {
- log.Fatal("ILLI: Unable to parse received SetupInfo from X11 server.")
- }
-
- if err := xinerama.Init(xc); err != nil {
- log.Fatal(err)
- }
-
- if r, err := xinerama.QueryScreens(xc).Reply(); err != nil {
- log.Fatal(err)
- } else {
- if len(r.ScreenInfo) == 0 {
- attachedScreens = []xinerama.ScreenInfo{
- xinerama.ScreenInfo{
- Width: setup.Roots[0].WidthInPixels,
- Height: setup.Roots[0].HeightInPixels,
- },
- }
- } else {
- attachedScreens = r.ScreenInfo
- }
- }
-
- connInfo := xproto.Setup(xc)
- if connInfo == nil {
- log.Fatal("ILLI: Unable to parse X connection information")
- }
- if len(connInfo.Roots) != 1 {
- log.Fatal("ILLI: Inappropriate number of roots. Did xinerama initialize correctly?")
- }
- xroot = connInfo.Roots[0]
-
- // Attempt to register as the window manager
- if err := TakeWMOwnership(); err != nil {
- if _, ok := err.(xproto.AccessError); ok {
- log.Fatal("ILLI: Unable to register as window manager with X server. Perhaps another WM is already running?")
- }
- log.Fatal(err)
- }
+ xconn := connectToXServer()
+ attachedScreens := getAttachedScreens(xconn)
+ xroot := getXRoot(xconn)
+ keymap = getKeyboardMap(xconn)
+ registerForKeyEvents(xconn, xroot, keymap)