X-Git-Url: http://git.subgeniuskitty.com/illi/.git/blobdiff_plain/bbee7b5f33590e498927818c23b160466d4ee546..effccebef90bd43bdfc8dc3bdd59e0c7c346ecb2:/illi.go diff --git a/illi.go b/illi.go index e535cc5..ad324c1 100644 --- a/illi.go +++ b/illi.go @@ -16,29 +16,24 @@ const ( XK_Return = 0xff0d ) -// TODO: These module-level global variables have arisen while establishing -// basic functionality. Before proceeding much further, figure out what to do -// with them. -var xc *xgb.Conn -var keymap [256][]xproto.Keysym - func main() { + fmt.Println("ILLI: Execution begins") + xconn := connectToXServer() attachedScreens := getAttachedScreens(xconn) xroot := getXRoot(xconn) - keymap = getKeyboardMap(xconn) + keymap := getKeyboardMap(xconn) registerForKeyEvents(xconn, xroot, keymap) becomeWM(xconn, xroot) // Build a list of windows needing management ------------------------------ - xc = xconn if len(attachedScreens) > 0 { fmt.Println("The Go compiler is waaaaay too picky about unused variables...") } - tree, err := xproto.QueryTree(xc, xroot.Root).Reply() + tree, err := xproto.QueryTree(xconn, xroot.Root).Reply() if err != nil { log.Fatal(err) } @@ -46,7 +41,7 @@ func main() { //workspaces = make(map[string]*Workspace) //defaultw := &Workspace{mu: &sync.Mutex{}} for _, c := range tree.Children { - if isMappedWindow(c) { + if isMappedWindow(xconn, c) { // err := defaultw.Add(c) // if err != nil { // log.Println(err) @@ -72,14 +67,14 @@ func main() { eventloop: for { - xevent, err := xc.WaitForEvent() + xevent, err := xconn.WaitForEvent() if err != nil { log.Println(err) continue } switch e := xevent.(type) { case xproto.KeyPressEvent: - if err := handleKeyPressEvent(e); err != nil { + if err := handleKeyPressEvent(keymap, e); err != nil { break eventloop } default: @@ -93,8 +88,8 @@ eventloop: // `MapState` value of 2 should be viewable. TODO: Verify this. // - https://github.com/BurntSushi/xgb/blob/master/xproto/xproto.go#L3772 // - https://github.com/BurntSushi/xgb/blob/master/xproto/xproto.go#L10287 -func isMappedWindow(windowID xproto.Window) bool { - reply, err := xproto.GetWindowAttributes(xc, windowID).Reply() +func isMappedWindow(conn *xgb.Conn, windowID xproto.Window) bool { + reply, err := xproto.GetWindowAttributes(conn, windowID).Reply() if err != nil { log.Fatal(err) } @@ -108,7 +103,7 @@ func isMappedWindow(windowID xproto.Window) bool { // event handlers (like this keypress handler). It shouldn't grow too // fragmented, nor should it grow into a monolithic beast, but the balance // needs to be selected after the handlers are built out more completely. -func handleKeyPressEvent(key xproto.KeyPressEvent) error { +func handleKeyPressEvent(keymap [256][]xproto.Keysym, key xproto.KeyPressEvent) error { switch keymap[key.Detail][0] { case XK_q: switch key.State { @@ -118,7 +113,7 @@ func handleKeyPressEvent(key xproto.KeyPressEvent) error { // We must manually close the X connection since we used // `defer` when setting it up and os.Exit() short-circuits // that deferral. - xc.Close() + //xc.Close() os.Exit(0) } case XK_Return: