         :parent-of-focused (if (= parent-focused-child (:id component))
                              ;; My parent is ready to give me focus. If I have any child requesting focus then I
                              ;; give focus to it. Otherwise I leave focus with myself. (*1)
-                             (if (= child-mode :requests-focus)
+                             ;(if (= child-mode :requests-focus)
+                             ;  (focus-child child-id)
+                             ;  {:mode :has-focus
+                             ;   :focused-child nil})
+                             (if-let [child-id (:id (first (filter
+                                                             #(= :requests-focus (:mode (:focus-state %)))
+                                                             (for [[_ c] (:children component)] c))))]
                                (focus-child child-id)
                                {:mode :has-focus
                                 :focused-child nil})

; You must not remove this notice, or any other, from this software.

(ns flatgui.focus
  (:require [flatgui.base :as fg]
            [flatgui.comlogic :as fgc]
            [flatgui.inputchannels.awtbase :as inputbase]
            [flatgui.inputchannels.mouse :as mouse]
            [flatgui.inputchannels.keyboard :as keyboard])
  (:import (java.awt.event KeyEvent)))


(def clean-state {:mode :none
                  :focused-child nil})

(defn focus-child [child-id] {:mode :parent-of-focused
                              :focused-child child-id})


(defn accepts-focus? [component]
  (or
    ;; If the component is focusable itself
    (:focusable component)
    ;; If the component has :focus-policy and therefore is a focus cycle root
    (:focus-policy component)))

(defn get-in-cycle
  ([component dir c-id]
    (let [child-count (count (:children component))
          child-ids (mapv (fn [[k _]] k) (:children component))
          closed (:closed-focus-root component)
          cycle-keeper (fn [i]
                         (cond

        :throws-focus old-focus-state)

      (fgc/child-reason? reason)
      (let [child-id (nth reason 1)
            child-focus-state (get-property [:this child-id] :focus-state)
            child-mode (:mode child-focus-state)
            child-throw-mode (:throw-mode child-focus-state)]
        (case child-mode
          ;; Nothing to change in this case
          :none old-focus-state

          ;; If my child is the parent of focused component (or parent of parent ...)
          ;; then I'm :parent-of-focused as well
