% uuminimal -- unofficial Beamer theme for Uppsala University
%
% Copyright (C) 2025 John Ankarström
%
% Author: John Ankarström <john@ankarstrom.se>
% Created: 21 Feb 2025
% Version: 0.1
%
% `uuminimal' is an unofficial Beamer theme for Uppsala University.
%
% The theme looks for a file in the current directory with the
% basename `uulogo', containing a gray copy of the university logo
% from the official PowerPoint template.  If present, it will be
% inserted as a background at 70% opacity in the top-right corner.
%
% `uuminimal' is based on themes included with Beamer, whose copyright
% is specified below:
%
% Copyright (C) 2007      Till Tantau
% Copyright (C) 2015      Vedran Mileti\'c, Joseph Wright
% Copyright (C) 2019-2024 Joseph Wright, samcarter
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.

\mode<presentation>

\beamer@compresstrue
\xdefinecolor{uured}{RGB}{151,31,48}

\setbeamercolor{structure}{fg=uured}
\setbeamercolor{frametitle}{parent=palette primary}
\setbeamercolor{subsection in head/foot}{parent=palette secondary}
\setbeamercolor{section in head/foot}{parent=palette quaternary}

\setbeamertemplate{section in toc shaded}[default][50]
\setbeamertemplate{navigation symbols}{}

% Insert university logo on every page in top-right corner.
\IfFileExists{uulogo.pdf}{
  \RequirePackage{tikz}
  \usebackgroundtemplate {
    \begin {tikzpicture} [overlay,remember picture,opacity=0.7]
      \node [at=(current page.north east), anchor=north east, inner
      sep=0pt, outer sep=0pt] {\includegraphics[keepaspectratio,
        height=0.5\paperheight]{uulogo}};
    \end {tikzpicture}
  }
}

% Head.  Insert navigation, but not for subsections.
\defbeamertemplate*{headline}{uuminimal theme}
{%
  \vskip0.5cm%
  \hskip0.69cm%
  \begin{beamercolorbox}{section in head/foot}%
    \insertnavigation{\dimexpr(\paperwidth-1.33cm)}%
  \end{beamercolorbox}%
}%

% Frame title.
\defbeamertemplate*{frametitle}{uuminimal theme}
{%
  \nointerlineskip%
  \vskip-0.1ex%
  \usebeamerfont{headline}%
  \vskip-.09ex%
  \nointerlineskip%
  \begin{beamercolorbox}[wd=\paperwidth,leftskip=.3cm,rightskip=.3cm plus1fil]{frametitle}
    \vskip0.3cm%
    \hskip0.69cm%
    \usebeamerfont*{frametitle}\strut\insertframetitle%
    \ifx\insertframesubtitle\@empty%
      \strut\par%
    \else
      \par{\hskip0.69cm\hskip0.07ex\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\strut\insertframesubtitle}\strut\par}%
    \fi%
    \usebeamerfont{headline}%
  \end{beamercolorbox}%
  \nointerlineskip%
  \vskip-1.05ex%
}

% Foot.  Add space as offset on frames with navigation and title.
\defbeamertemplate*{footline}{uuminimal theme}
{%
  \ifx\insertnavigation\@empty\else\vskip\baselineskip\fi%
  \ifx\insertframetitle\@empty\else\vskip\baselineskip\fi%
}

% Title page.  Remove unnecessary space.
\defbeamertemplate*{title page}{uuminimal theme}[1][]
{
  \vbox{}
  \vfill
  \begingroup
    \centering
    \usebeamertemplate{title}
    \par
    \usebeamertemplate{author}
    \ifx\insertinstitute\@empty\else
      \usebeamertemplate{institute}
    \fi
    \usebeamertemplate{date}
    \ifx\inserttitlegraphic\@empty\else
      vskip0.5em
      \usebeamertemplate{titlegraphic}
    \fi
  \endgroup
  \vfill
}[action]{
  \setbeamertemplate{title}[default][#1]
  \setbeamertemplate{author}[default][#1]
  \setbeamertemplate{institute}[default][#1]
  \setbeamertemplate{date}[default][#1]
  \setbeamertemplate{titlegraphic}[default]
}

% Actually center content on plain frames.
\RequirePackage{etoolbox}
\apptocmd{\beamer@frametemplate@plain}{%
  \beamer@frametopskip=0pt plus 1fill\relax%
  \beamer@framebottomskip=0pt plus 1fill\relax%
}{}{}

\mode<all>
