Step 1: Remove the odd part:
Break the numerator as $2x(1+\sin x) = 2x + 2x\sin x$.
The term $\frac{2x}{1+\cos^2 x}$ is an odd function, and it is integrated over the symmetric interval $[-\pi, \pi]$. Its integral is $0$.
The term $\frac{2x\sin x}{1+\cos^2 x}$ is even, so we may double the integral over $[0, \pi]$.
\[ I = 4\int_0^{\pi}\frac{x\sin x}{1+\cos^2 x}\,dx \]
Step 2: Choose integration by parts:
Take $u = x$ and $dv = \frac{\sin x}{1+\cos^2 x}\,dx$.
To find $v$, put $t = \cos x$. Then $\int \frac{\sin x}{1+\cos^2 x}\,dx = -\int\frac{dt}{1+t^2} = -\tan^{-1}(\cos x)$.
So $v = -\tan^{-1}(\cos x)$.
Step 3: Apply the by-parts formula:
\[ \int_0^{\pi}\frac{x\sin x}{1+\cos^2 x}\,dx = \Big[-x\tan^{-1}(\cos x)\Big]_0^{\pi} + \int_0^{\pi}\tan^{-1}(\cos x)\,dx \]
Step 4: Evaluate the boundary term:
At $x = \pi$: $-\pi\tan^{-1}(-1) = -\pi\left(-\frac{\pi}{4}\right) = \frac{\pi^2}{4}$.
At $x = 0$: $-0 \cdot \tan^{-1}(1) = 0$.
So the boundary term equals $\frac{\pi^2}{4}$.
Step 5: Show the last integral is zero:
Let $K = \int_0^{\pi}\tan^{-1}(\cos x)\,dx$. Replace $x$ by $\pi - x$. Since $\cos(\pi - x) = -\cos x$ and $\tan^{-1}$ is odd, $K = -K$.
So $K = 0$.
Step 6: Combine:
\[ \int_0^{\pi}\frac{x\sin x}{1+\cos^2 x}\,dx = \frac{\pi^2}{4} + 0 = \frac{\pi^2}{4} \]
\[ I = 4 \times \frac{\pi^2}{4} = \pi^2 \]
Final Answer:
The integral equals $\pi^2$.
\[ \boxed{\pi^2} \]