Elementary geometry problem about two squares. 
Consider the picture above, where $ABCD$ and $EFGC$ are squares with areas respectively $A$ and $B$. Find the shaded area.
Well, I observerd the following: If the intersection between $BG$ and $EF$ is the midpoint of $EF$, then the area will be $\dfrac{A}{2} + \dfrac{3B}{4}$, since the square $EFGC$ will be divided into a rectangle plus a triangle with half the area of the rectangle, leaving out an identical triangle. But then when I change the square $EFGC$, the intersection will change, and the expression will change. Is there a more general formula that includes this case? I can't see how that's possible.
A colleague of mine did the following:
"Area of triangle $DBC$ is $\dfrac{A}{2}$. Area of triangle $GCB$ is $\dfrac{\sqrt{A}\sqrt{B}}{2}$. If $H$ is $BG \cap EF$, triangle $BEH$ has height $\sqrt{A}-\sqrt{B}$ and is similar to $GFH$, with ratio $\dfrac{\sqrt{A}-\sqrt{B}}{\sqrt{B}} = \dfrac{\sqrt{A}}{\sqrt{B}}-1$, then base of $BEH$ is $\dfrac{A}{\sqrt{B}} - \sqrt{A}$. Then the trapezoid $EHGC$ has area $\dfrac{\Bigg(\dfrac{A}{\sqrt{B}} - \sqrt{A}+\sqrt{B}\Bigg)\sqrt{B}}{2} = \dfrac{A - \sqrt{AB} + B}{2}$, then the shaded area is equal to $A + \dfrac{B-\sqrt{AB}}{2} $."
But I don't understand this part: "then base of $BEH$ is $\dfrac{A}{\sqrt{B}} - \sqrt{A}$". 
I think his formula is not correct because I tried an example with $A=2$,$B=1$ and $H$ being midpoint of $EF$, and it didn't work, but maybe I'm doing something wrong.
Can someone please explain what's happening? Thanks.
 A: Let $BC=p$ and $EC=q.$ The area of square $ABCD$ is $p^2,$ which we will also call $a.$ The area of $EFGC$ is $q^2,$ which we will also call $b.$ (The letters $A,B$ are already in use, for vertices.)
The area of $\triangle BCD$ is $\frac {p^2}{2}.$ The area of $\triangle BCG$ is $\frac{ pq}{2}.$ 
Let $H$ be the point of  intersection of $EF$ with $BG.$ By similar triangles the area of $\triangle BEH$ is $$ \text {Area}(BCG)\cdot \left(\frac {BE}{BC}\right)^2=\frac {pq}{2}\cdot \left(\frac {BE}{BC}\right)^2=\frac {pq}{2}\cdot \left(\frac {p-q}{p}\right)^2.$$ 
So the area of $EHCG$ is therefore Area$(BCG)$-Area$(BEH)$, which is $$\frac {pq}{2}-\frac {pq}{2}\left(\frac {p-q}{p}\right)^2$$ which  we will call $X.$
Therefore the shaded area is Area$(BCD)+X=\frac {p^2}{2}+X,$ which, using the above value for $X$, simplifies to $$\frac {p^2}{2}+q^2-\frac {q^2}{2}\cdot \frac {q}{p}=\frac {a}{2}+b-\frac {b}{2}\sqrt {\frac {b}{a}}\;.$$
A: $$  \triangle EHB \sim \triangle FHG   
\\ \implies \frac{FH}{EH} = \frac{FG}{EB} = \frac{\sqrt B}{\sqrt A - \sqrt B}$$
So $$ EH = FH ( \frac {\sqrt A -\sqrt B} {\sqrt B} ) $$
But we also know that 
$$   FH + EH = EF = \sqrt B   $$
So
$$FH(1+   \frac {\sqrt A -\sqrt B} {\sqrt B} ) = \sqrt B  $$
$$ \implies FH(\sqrt B + \sqrt A  - \sqrt B ) = B  $$
$$\implies FH = \frac { B }{\sqrt A}   $$
$$ A_{TOT}=  \frac 12A + B - \frac 12 FH\cdot FG 
\\ =  \frac 12A + B - \frac 12 \frac { B }{\sqrt A}   \cdot \sqrt B 
\\ =  \frac 12A + \left (1- \frac 12 \sqrt \frac BA \right )B 
$$
