aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go24
-rw-r--r--restart.go1
2 files changed, 21 insertions, 4 deletions
diff --git a/main.go b/main.go
index 93d5cf9..272b100 100644
--- a/main.go
+++ b/main.go
@@ -112,9 +112,11 @@ func handleEvent(conn *xgb.Conn, ev xgb.Event) {
drawBar(conn)
}
case xproto.EnterNotifyEvent: // change focused window event
- focused = e.Event
- setInputFocus(conn, focused)
- drawBar(conn)
+ if _, ok := clients[e.Event]; ok && e.Event != focused {
+ focused = e.Event
+ setInputFocus(conn, focused)
+ drawBar(conn)
+ }
case xproto.ExposeEvent:
if e.Window == barWindow {
drawBar(conn)
@@ -785,6 +787,20 @@ func trimTitle(value []byte) string {
return string(value)
}
+func refocus(conn *xgb.Conn) {
+ for _, c := range ActiveClients {
+ if c.Win == focused {
+ return
+ }
+ }
+ focused = 0
+ if len(ActiveClients) > 0 {
+ focused = ActiveClients[0].Win
+ }
+ setInputFocus(conn, focused)
+ drawBar(conn)
+}
+
func updateWindows(conn *xgb.Conn) {
ActiveClients = ActiveClients[:0]
for _, client := range clientList {
@@ -806,4 +822,6 @@ func updateWindows(conn *xgb.Conn) {
default:
log.Fatal("Unknown layout ", layout)
}
+
+ refocus(conn)
}
diff --git a/restart.go b/restart.go
index 87c6c41..74ff48f 100644
--- a/restart.go
+++ b/restart.go
@@ -96,7 +96,6 @@ func restoreState(conn *xgb.Conn) bool {
if _, ok := clients[st.Focused]; ok {
focused = st.Focused
- setInputFocus(conn, focused)
}
for _, c := range clients {