Let $\mathfrak{g}$ be a semisimple Lie algebra over $\mathbb C$ equipped with an inner product $<,>$ such that
$$\langle ad_X Y,Z\rangle=-\langle Y, ad_X Z\rangle$$
and $\mathfrak{h}$ be a Cartan subalgebra. It follows that the linear operators $ad(x),x\in \mathfrak{h}$ on $\mathfrak{h}$ commute with each other, so they are simutaneously diagonalizable. The references I have read so far say that it follows from here that we have
$$\mathfrak{g}=\mathfrak{h}\oplus \bigoplus_{\alpha \in R} \mathfrak{g}_\alpha,$$
where $$\mathfrak{g}_\alpha:=\left\{X\in \mathfrak{g}: [H,X]=\langle\alpha, H\rangle X, \forall H\in \mathfrak h \right\}$$ and $R$ is the set of roots (all possible $\alpha$'s satisfying the equation above).
My question is that given an element in $\mathfrak{g}$, how do we use the simultaneous diagonalization to write it as a sum of elements of $\mathfrak{h}$ and $\mathfrak{g}_\alpha$. This should be pure linear algebra but I can't figure out how.
The answer https://math.stackexchange.com/a/1685174/185631 doesn't address how is the simultaneous diagonalization being used exactly I think. Yes, one can take a basis of $\mathfrak g$ so that for any $h\in \mathfrak h$, the matrix of $\text{ad}(h)$ is diagonal. But how to write an element in $\mathfrak{g}$ as a sum?
If there are any mistakes in my description above, please let me know.