Cleanup/familiarization commit after spending some time away from illi.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Sat, 4 Mar 2023 00:37:37 +0000 (16:37 -0800)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Sat, 4 Mar 2023 00:37:37 +0000 (16:37 -0800)
illi.go
initialization.go

diff --git a/illi.go b/illi.go
index e535cc5..ad324c1 100644 (file)
--- a/illi.go
+++ b/illi.go
@@ -16,29 +16,24 @@ const (
     XK_Return = 0xff0d
 )
 
     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() {
 func main() {
+    fmt.Println("ILLI: Execution begins")
+
     xconn := connectToXServer()
     attachedScreens := getAttachedScreens(xconn)
     xroot := getXRoot(xconn)
     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 ------------------------------
 
     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...")
     }
 
     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)
     }
     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 {
         //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)
 //                err := defaultw.Add(c)
 //                if err != nil {
 //                    log.Println(err)
@@ -72,14 +67,14 @@ func main() {
 
 eventloop:
     for {
 
 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 != 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:
                     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
 // `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)
     }
     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.
 // 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 {
     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.
                     // 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:
                     os.Exit(0)
             }
         case XK_Return:
index 7f2a50a..45f6f6e 100644 (file)
@@ -21,7 +21,7 @@ import (
 
 
 
 
 
 
-// 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()
 // connection and calling connection.Close() when appropriate.
 func connectToXServer() *xgb.Conn {
     connection, err := xgb.NewConn()
@@ -33,7 +33,7 @@ func connectToXServer() *xgb.Conn {
 }
 
 func getAttachedScreens(conn *xgb.Conn) (screens []xinerama.ScreenInfo) {
 }
 
 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())
     err := xinerama.Init(conn)
     if err != nil {
         fmt.Fprintf(os.Stderr, "ILLI: Unable to initialize xinerama: %s\n", err.Error())
@@ -77,7 +77,7 @@ func getXRoot(conn *xgb.Conn) xproto.ScreenInfo {
 }
 
 func getKeyboardMap(conn *xgb.Conn) (keymap [256][]xproto.Keysym) { // TODO: Why 256?
 }
 
 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
     )
         loKey = 8
         hiKey = 255
     )