\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{wwustyle-mod}[%
	2017/11/01 Modifications/patches for wwustyle.sty%
]

\RequirePackage{graphicx}
% add resource directory to search path
\graphicspath{{wwustyle/}}

% load the same packages as wwustyle
\RequirePackage{tikz}
\RequirePackage{xxcolor}
\RequirePackage{microtype}

% intercept option “english” to fix avoid error in wwustyle.sty
\newif\ifwwumod@english
\DeclareOption{english}{\wwumod@englishtrue}
% pass all (other) options to wwustyle
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{wwustyle}}
\ProcessOptions\relax

% save commands that will temporarily be overwritten
\let\RequirePackage@saved=\RequirePackage
\let\usefont@saved=\usefont
\let\rmdefault@saved=\rmdefault
\let\sfdefault@saved=\sfdefault
\let\@listii@saved=\@listii
\let\@listiii@saved=\@listiii
% disable the commands \RequirePackage and \usefont before loading wwustyle
% so that it doesn’t load fontenc.sty or meta.sty and doesn’t set the fonts
\renewcommand*{\RequirePackage}[2][]{}
\renewcommand*{\usefont}[4]{}
% load wwustyle
\RequirePackage@saved{wwustyle}
% restore commands
\let\RequirePackage=\RequirePackage@saved
\let\usefont=\usefont@saved
\let\rmdefault=\rmdefault@saved
\let\sfdefault=\sfdefault@saved
\let\@listii=\@listii@saved
\let\@listiii=\@listiii@saved

% =============================================================================

% fix broken package option “english”
\renewcommand{\switchToEnglish}{
	\renewcommand{\claimTextWissen}{living}
	\renewcommand{\claimTextLeben}{knowledge}
	% this line had to be fixed (was “\newcommand{\claimText}{livingknowledge}”)
	\renewcommand{\claimText}{livingknowledge}
	\renewcommand{\claimPunktXShift}{-6.2mm}
	\renewcommand{\claimPunktYShift}{-0.6mm}
	\renewcommand{\claimLebenXShift}{0.5mm}
	\renewcommand{\claimWWUYShift}{26.9mm}
	\renewcommand{\claimWWUXShift}{0mm}
	\renewcommand{\claimWWUXXShift}{2.3366mm}
	\renewcommand{\claimDeEn}{-en}
}
% switch to English if package option “english” was specified
\ifwwumod@english
	\switchToEnglish
\fi

% redefine \@arrayparboxrestore so that the presentation title (which is set
% using a \parbox) uses \raggedright instead of justifying text
\g@addto@macro\@arrayparboxrestore{\raggedright}

% some improvements and modifications to wwustyle.sty
\renewcommand*{\bgbox}[1]{\texorpdfstring{\colorbox{maincolor}{#1}}{#1}}

% use standard WWU logo files instead of redrawing the logo in TikZ
\renewcommand*{\wwu@logo}[2]{%
	\def\temp@a{#2}\def\temp@b{white}%
	% \ifx\temp@a\temp@b%
		\includegraphics[scale=#1]{unims}
	% \else%
		% The file WWUMuenster_Logo_2017_4c.pdf contains margins which have to
		% be cropped. There is a horizontal margin of 2.5mm and a vertical
		% margin of 2.66mm on each side. The trim option of \includegraphics
		% takes values in bp (1bp = 1/72in), so 2.5mm ≈ 7.08bp and
		% 2.66mm ≈ 7.54bp.
		% \includegraphics[trim=7.08 7.54 7.08 7.54, clip, scale=#1]{unims}
		\hspace{0.3cm}\includegraphics[scale=0.13]{wwustyle/rtg_logo.png}
		% \hspace{0.3cm}\includegraphics[scale=0.45]{wwustyle/rqcd_logo.pdf}
	% \fi%
}

% make right sidebar smaller now that the claim isn’t shown there anymore
% (same size as left sidebar)
\setbeamersize{sidebar width right=0.25cm}

% define an actual white (since the normal white was overwritten in wwustyle)
\definecolor{truewhite}{RGB}{255,255,255}
% correct definition of pantoneblack7
\definecolor{pantoneblack7}{RGB}{62,62,59}
% set text color to 80% of pantoneblack7
\colorlet{wwublack}{pantoneblack7!80}
\setbeamercolor*{normal text}{fg=pantoneblack7!80}
% restore block title colors
\setbeamercolor*{block title}{fg=truewhite,bg=maincolor}
\setbeamercolor*{block title alerted}{fg=truewhite,bg=fu-red}
\setbeamercolor*{block title example}{fg=truewhite,bg=fu-green}
% restore block background color
\setbeamercolor*{block body}{bg=maincolor!5}

% make footline background non-transparent so that frame content cannot “slide
% into” the footer
\setbeamercolor*{footlinecolor}{bg=truewhite}
\setbeamertemplate{footline}{%
	\begin{beamercolorbox}[wd=\paperwidth]{footlinecolor}
		\fontsize{6pt}{1pt}%
		\selectfont%
		\color{maincolor}%
		\rule{\textwidth}{0.8pt}% horizontal line
		\vskip2mm%
		\hspace{5mm}%
		% fix frame numbering (use \insertframenumber instead of \thepage)
		\textcolor{wwublack}{\let\bgbox\relax\insertshortauthor}\hfill\textcolor{maincolor}{\fontsize{9pt}{12pt}\selectfont\smash{\textbf{\insertframenumber}}}\hspace{5mm}\strut%
		\vskip2mm%
	\end{beamercolorbox}%
}

% restore original beamer list settings overwritten by wwustyle.sty
\setbeamercolor{item}{fg=maincolor}
\setbeamertemplate{itemize/enumerate body begin}[default]
\setbeamertemplate{itemize/enumerate subbody begin}[default]
\setbeamertemplate{itemize/enumerate subsubbody begin}[default]
\setbeamertemplate{items}[default]

% fix \frametitle and add output for \framesubtitle
\setbeamertemplate{frametitle}{%
	%\vskip4mm
	\vskip0mm %shift the frametitle slighty to the top
	\fontsize{14pt}{14pt}
	\selectfont
	\color{maincolor}
	\bfseries
	\insertframetitle
	\par
	\ifx\insertframesubtitle\empty%
	\else
	\fontsize{12pt}{12pt}
	\selectfont
	\color{pantoneblack7}
	\mdseries
	\insertframesubtitle
	\fi%
}

\setbeamertemplate{headline}{
	\fontsize{6pt}{1pt}%
	\selectfont%
	\hfill%
	\bfseries%
	\color{maincolor}%
	\let\bgbox\relax\insertshorttitle%
	% same space to the right as text margin
	\hspace{0.5cm}%
	% invisible rule to set headline height
%	\rule{0pt}{10mm}%
	\rule{0pt}{5mm}%
}
