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)
}
//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)
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:
// `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)
}
// 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 {
// 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:
-// The caller is responsible for tracking the lifetime of the returned X
+// Note: The caller is responsible for tracking the lifetime of the returned X
// connection and calling connection.Close() when appropriate.
func connectToXServer() *xgb.Conn {
connection, err := xgb.NewConn()
}
func getAttachedScreens(conn *xgb.Conn) (screens []xinerama.ScreenInfo) {
- // First, attempt to use xinerama to obtain screen information.
+ // Attempt to use xinerama to obtain screen information.
err := xinerama.Init(conn)
if err != nil {
fmt.Fprintf(os.Stderr, "ILLI: Unable to initialize xinerama: %s\n", err.Error())
}
func getKeyboardMap(conn *xgb.Conn) (keymap [256][]xproto.Keysym) { // TODO: Why 256?
- const ( // TODO: WhyTF? How does the keymap work under the hood?
+ const ( // TODO: Why? How does the keymap work under the hood?
loKey = 8
hiKey = 255
)