By letting $u = 2x$ and $t = \tan \frac{u}{2}$, I found the continuous antiderivative of the function to be:
$$\int \frac{1}{1+\cos^2 x}dx\\= \int \frac{2}{3+\cos2x} dx\\ = \int \frac{1}{3+\cos u}du \\=\int \frac{\frac{2}{1+t^2}}{3+\frac{1-t^2}{1+t^2}}dt\\= \int\frac{1}{2+t^2}dt \\= \frac{1}{\sqrt2}\arctan\left(\frac{\tan x}{\sqrt2}\right) + \frac{\pi}{\sqrt2} \left\lfloor \frac{x + \frac{\pi}{2} }{\pi} \right\rfloor + C $$
(I graphically deduced the floor function bit as I am not familiar with its algebra.)
However, GeoGebra (notably not wolfram) does it better. It states, without the floor function, that the continuous antiderivative is also:
$$ \frac{x}{\sqrt2} + \frac{1}{\sqrt2} \arctan\left( \frac{(1-\sqrt2)\sin 2x}{(\sqrt2 -1)\cos2x +\sqrt2 + 1}\right) + C$$
How did GeoGebra accomplish such a feat? And how can I prove and apply such ingenuity?

One important thing is while doing u-substitution, the substitution has to be injective. When we substitute $u=\tan x$ in samjoe’s answer, $\tan x$ is not injective on the whole real line, but is injective in intervals of length $\pi$. That’s why you get the right ‘behavior’ only within intervals but not between them.
I believe that the Geogebra’s answer can be derived by noting that $$\frac1{\pi}(arctan(\cot(\pi x))+\pi x-\pi/2)$$ behaves exactly the same as a floor function.
Use also the summation formula for arctan: $$arctan (u)+arctan (v)=arctan(\frac{u+v}{1-uv})$$
ADDED:
To demonstrate the importance of injectivity of substitutions, consider the integral $$\int^1_{0}xdx$$ which equals $\frac12$.
If we substitute in $u=x^2-x$, we obtain something like $$\int^0_0 \cdots du=0$$
What caused the paradox is $x^2-x$ is not injective in the interval $[0,1]$.
Similarly, there is nothing wrong for $$\int^x_k \frac1{1+\cos ^2x}dx=\int^x_k\frac{\sec^2x}{2+\tan^2x}dx=^{u=\tan x}\int^{arctan(x)}_{arctan(k)}\frac{du}{2+u^2}=\frac1{\sqrt2}arctan(\frac{\tan x}{\sqrt2})+C$$ as long as $\tan x$ is injective in the interval $[k,x]$. If the injectivity is not achieved in the interval, $C$ would change when $x$ goes from an injective interval of $\tan x$ to another.
This agrees with what the OP observed: the floor function thing is a constant in each injective interval of $\tan x$, and changes when going across the intervals. You may consider, the floor function thing is part of $C$.
The choice of $k$ is arbitrary. But when we try to find an antiderivative for all $x$ while $k$ remains fixed, it is impossible to always achieve the injectivity in $[k,x]$. As a trade off, we need to add a floor function to compensate for the silent change of $C$.
ADDED 2:
@samjoe derived the antiderivative $$\frac{\pi}{\sqrt2}\left \lfloor\frac{x+\pi/2}{\pi}\right\rfloor + \frac{1}{\sqrt 2}\arctan\left(\frac{\tan x}{\sqrt2}\right) $$
By noting $$\lfloor x\rfloor=\frac1{\pi}(arctan(\cot(\pi x))+\pi x-\pi/2)$$, the above expression can be rewritten to $$\frac{x}{\sqrt2}+\frac{arctan(-\tan x)}{\sqrt2}+\frac{arctan(\frac{\tan x}{\sqrt2})}{\sqrt2}$$ $$=\frac{x}{\sqrt2}+\frac1{\sqrt2}({arctan(-\tan x)}+arctan(\frac{\tan x}{\sqrt2}))$$ By the summation formula stated above $$=\frac{x}{\sqrt2}+\frac1{\sqrt2}arctan(\frac{-\tan x+\frac{\tan x}{\sqrt2}}{1+\frac{\tan^2x}{\sqrt2}})$$ $$=\frac{x}{\sqrt2}+\frac1{\sqrt2}arctan(\frac{\tan x(1-\sqrt2)}{\sqrt2+\tan^2x+1-1})$$ $$=\frac{x}{\sqrt2}+\frac1{\sqrt2}arctan(\frac{\tan x(1-\sqrt2)}{\sqrt2+\sec^2x-1})$$ $$=\frac{x}{\sqrt2}+\frac1{\sqrt2}arctan(\frac{(1-\sqrt2)\sin x\cos x}{(\sqrt2-1)\cos^2 x+1})$$ $$=\frac{x}{\sqrt2}+\frac1{\sqrt2}arctan(\frac{(1-\sqrt2)2\sin x\cos x}{(\sqrt2-1)(2\cos^2 x)+2})$$ $$=\frac{x}{\sqrt2}+\frac1{\sqrt2}arctan(\frac{(1-\sqrt2)\sin 2x}{(\sqrt2-1)(\cos 2x +1)+2})$$ $$=\frac{x}{\sqrt2}+\frac1{\sqrt2}arctan(\frac{(1-\sqrt2)\sin 2x}{(\sqrt2-1)\cos 2x+\sqrt2+1})$$ which is exactly what we want.