ad324c16e947e8b564c0a289e659af40d732235e
"github.com/jezek/xgb/xproto"
// TODO: Make a separate keysym file and fully populate it.
fmt
.Println("ILLI: Execution begins")
xconn
:= connectToXServer()
attachedScreens
:= getAttachedScreens(xconn
)
keymap
:= getKeyboardMap(xconn
)
registerForKeyEvents(xconn
, xroot
, keymap
)
// Build a list of windows needing management ------------------------------
if len(attachedScreens
) > 0 {
fmt
.Println("The Go compiler is waaaaay too picky about unused variables...")
tree
, err
:= xproto
.QueryTree(xconn
, xroot
.Root
).Reply()
//workspaces = make(map[string]*Workspace)
//defaultw := &Workspace{mu: &sync.Mutex{}}
for _
, c
:= range tree
.Children
{
if isMappedWindow(xconn
, c
) {
// err := defaultw.Add(c)
fmt
.Println("ILLI: Found a client.")
// if len(attachedScreens) > 0 {
// defaultw.Screen = &attachedScreens[0]
// workspaces["default"] = defaultw
// if err := defaultw.TileWindows(); err != nil {
// Main program loop reacts to X events ------------------------------------
xevent
, err
:= xconn
.WaitForEvent()
switch e
:= xevent
.(type) {
case xproto
.KeyPressEvent
:
if err
:= handleKeyPressEvent(keymap
, e
); err
!= nil {
// The client list appears to have some entries for windows that shouldn't
// actually be viewable. For now, it appears that only windows with a
// `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(conn
*xgb
.Conn
, windowID xproto
.Window
) bool {
reply
, err
:= xproto
.GetWindowAttributes(conn
, windowID
).Reply()
if reply
!= nil && reply
.MapState
== 2 {
// TODO: Determine how I want to split the main event loop from the various
// 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(keymap
[256][]xproto
.Keysym
, key xproto
.KeyPressEvent
) error
{
switch keymap
[key
.Detail
][0] {
case xproto
.ModMask1 | xproto
.ModMaskShift
:
// TODO: Where and how do I want to handle exit/restart?
// -------------------------
// We must manually close the X connection since we used
// `defer` when setting it up and os.Exit() short-circuits
case xproto
.ModMask1 | xproto
.ModMaskShift
:
cmd
:= exec
.Command("xterm")
return nil // TODO: What do I actually want to return here?