% Beamer theme for Bootlin presentations
% Copyright (C) 2010 Maxime Petazzoni <maxime.petazzoni@bulix.org>
% Creative Commons CC-by-sa 3.0

\usepackage[absolute,verbose,overlay]{textpos}
\usepackage{fancyvrb,xcolor}
\setlength{\TPHorizModule}{\paperwidth}
\setlength{\TPVertModule}{\paperheight}


\usetheme{default}
\useinnertheme{default}
\useoutertheme{default}
\usecolortheme{seahorse}

\usepackage{fontspec}
\setmainfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\setmonofont{Inconsolata}

\setbeamercolor*{palette primary}{bg=white}
\definecolor{blorange}{rgb}{0.96,0.5,0.1}

\definecolor{blcode}{rgb}{0.35,0.35,0.35}
\setbeamercolor{code}{fg=blcode}

\fvset{formatcom=\color{blcode}}
\renewcommand\verbatim@font{\normalfont\ttfamily\color{blcode}}

\definecolor{blcodebg}{rgb}{0.9,0.9,0.9}
\setbeamercolor{block body}{bg=blcodebg}

\setbeamerfont{block title}{size=\scriptsize}

\definecolor{bldarkblue}{rgb}{0.25,0.25,0.75}
\setbeamercolor{darkblue}{fg=bldarkblue}
\hypersetup{colorlinks,linkcolor=,urlcolor=bldarkblue}

\setbeamertemplate{blocks}[rounded][shadow=false]

\setbeamercolor{itemize item}{fg=blorange}
\setbeamercolor{itemize subitem}{fg=blorange}
\setbeamercolor{itemize subsubitem}{fg=blorange}
\setbeamertemplate{itemize subitem}[circle]
\setbeamertemplate{itemize subsubitem}[square]
\setbeamercolor{enumerate item}{fg=blorange}

% Custom Bootlin commands
\newcommand{\codecolor}{\usebeamercolor[fg]{code}}
\newcommand{\code}[1]{{\codecolor \path{#1}}}
\newcommand{\codelink}[1]{{\usebeamercolor[fg]{darkblue} \path{#1}}}
\newcommand{\codewithhash}[1]{{\codecolor \tt{#1}}}

% Generic Elixir commands
\newcommand\projdir[2]{\href{https://elixir.bootlin.com/#1/latest/source/#2/}{\codelink{#2/}}}
\newcommand\projfile[2]{\href{https://elixir.bootlin.com/#1/latest/source/#2}{\codelink{#2}}}
\newcommand\projsym[2]{\href{https://elixir.bootlin.com/#1/latest/ident/#2}{\codelink{#2}}}
\newcommand\projfunc[2]{\href{https://elixir.bootlin.com/#1/latest/ident/#2}{\codelink{#2()}}}
\newcommand\projconfig[2]{\href{https://elixir.bootlin.com/#1/latest/K/ident/#2}{\codelink{#2}}}
\newcommand\projconfigval[3]{\href{https://elixir.bootlin.com/#1/latest/K/ident/#2}{\codelink{#2=#3}}}
\newcommand\projconfignotset[2]{\href{https://elixir.bootlin.com/#1/latest/K/ident/#2}{\codelink{## #2 is not set}}}

% Linux Elixir commands
\newcommand\kfunc[1]{\href{https://elixir.bootlin.com/linux/latest/ident/#1}{\codelink{#1()}}}
\newcommand\ksym[1]{\href{https://elixir.bootlin.com/linux/latest/ident/#1}{\codelink{#1}}}
\newcommand\kcompat[2]{\href{https://elixir.bootlin.com/linux/latest/B/ident/#1}{\codelink{#2}}}
\newcommand\kstruct[1]{\href{https://elixir.bootlin.com/linux/latest/ident/#1}{\codelink{struct #1}}}
\newcommand\kfile[1]{\projfile{linux}{#1}}
\newcommand\krelfile[2]{\href{https://elixir.bootlin.com/linux/latest/source/#1/#2}{\codelink{#2}}} % For relative file paths
\newcommand\kfileversion[2]{\href{https://elixir.bootlin.com/linux/v#2/source/#1}{\codelink{#1}}}
\newcommand\kdir[1]{\projdir{linux}{#1}}
\newcommand\kreldir[2]{\href{https://elixir.bootlin.com/linux/latest/source/#1/#2}{\codelink{#2/}}} % For relative directory paths
\newcommand\ksubarch[1]{\href{https://elixir.bootlin.com/linux/latest/source/arch/#1/}{\codelink{#1}}}
\newcommand\kconfig[1]{\href{https://elixir.bootlin.com/linux/latest/K/ident/#1}{\codelink{#1}}}
\newcommand\kconfigval[2]{\href{https://elixir.bootlin.com/linux/latest/K/ident/#1}{\codelink{#1=#2}}}
\newcommand\kconfignotset[1]{\href{https://elixir.bootlin.com/linux/latest/K/ident/#1}{\codelink{## #1 is not set}}}
\newcommand\kdoctext[1]{\href{https://kernel.org/doc/Documentation/#1}{\codelink{Documentation/#1}}}
\newcommand\kdochtml[1]{\href{https://www.kernel.org/doc/html/latest/#1.html}{\codelink{#1}}}
\newcommand\kdochtmldir[1]{\href{https://www.kernel.org/doc/html/latest/#1/}{\codelink{#1/}}}
\newcommand\kdochtmlsection[3]{\href{https://www.kernel.org/doc/html/latest/#1/index.html\##2}{\codelink{#1} (section {\em #3})}}

\usepackage{listings}
\usepackage{environ}
\usepackage{minted}
\usepackage{setspace}
\usepackage{etoolbox}
\usepackage{makecell}

% Display straight quotes instead of curly ones in verbatim mode
\usepackage{upquote}

\usepackage{ifthen}

\lstloadlanguages{C}
\lstset{%
  basicstyle=\tiny \ttfamily,
  emphstyle=\color{blue}\bfseries\ttfamily,
}

\lstnewenvironment{codeblock}
 {\begin{block}{}}
 {\end{block}}

%% Mode presentation
\mode<presentation>

% Remove navigation symbols
\setbeamertemplate{navigation symbols}{}

\defbeamertemplate*{frametitle}{bootlintheme}
{
  \vskip-2pt
  \hbox{%
    \begin{beamercolorbox}[wd=\paperwidth,ht=3ex,dp=1.5ex]{frametitle}%
      \usebeamerfont{frametitle}
      \begin{textblock}{.2}[0.5,0.5](0.12,0.07)
       \includegraphics[width=1cm]{common/logo-penguins.pdf}
      \end{textblock}
      \hspace{1.25cm}
      \insertframetitle
    \end{beamercolorbox}
  }
  \vskip-1em\vskip2pt
  \hbox{\hskip-1cm\color{blorange}\vrule width \paperwidth height 1pt}%
}

% Footer
\defbeamertemplate*{footline}{bootlintheme}
{
  \hbox{\color{black}\vrule width \paperwidth height 0.1pt}
  \hbox{%
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,leftskip=0.5em]{palette primary}%
      \Tiny
      \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} lr}
        \includegraphics[width=0.04\textwidth]{common/bootlin-logo.pdf}
        - Kernel, drivers and embedded Linux - Development,
        consulting, training and support -
        ~{\tt https://bootlin.com} & \insertframenumber{}/\inserttotalframenumber{}
      \end{tabular*}
    \end{beamercolorbox}
  }
  \vskip0pt
}

\newcommand\tinyv{\@setfontsize\tinyv{4pt}{6}}

\newcommand{\insertconference}{}
\newcommand{\conference}[1]
{
  \renewcommand{\insertconference}{#1}
}

\newcommand{\insertemail}{}
\newcommand{\email}[1]
{
  \renewcommand{\insertemail}{#1}
}

\newcommand{\insertslidesurl}{}
\newcommand{\slidesurl}[1]
{
  \renewcommand{\insertslidesurl}{#1}
}

\newcommand{\insertauthors}{}
\newcommand{\authors}[1]
{
  \renewcommand{\insertauthors}{#1}
}

\newcommand{\@trainingurl}{}
\newcommand{\trainingurl}[1]
{
  \renewcommand{\@trainingurl}{#1}
}

\newcommand\titleframe[1]
{
  \begin{frame}{#1}
    \begin{columns}[b]
      \column{0.5\textwidth}
      \Large
      #1\\
      \vspace{0.5cm}
      \footnotesize
      \insertauthors\\
      \vspace{1cm}
      \tinyv
      © Copyright 2004-\the\year, Bootlin.\\
      Creative Commons BY-SA 3.0 license.\\
      Latest update: \lastupdateen{}.\\
      Document updates and sources:\\
      \url{\@trainingurl}\\
      Corrections, suggestions, contributions and translations are welcome!
      \column{0.5\textwidth}
      \begin{center}
        \includegraphics[height=4cm]{common/logo-square.pdf}
      \end{center}
    \end{columns}
  \end{frame}
}

\AtBeginSection[]
{
  \begin{frame}{\insertconference}
    \begin{columns}[b]
      \column{0.5\textwidth}
      \huge
      \insertsection\\
      \vspace{0.5cm}
      \footnotesize
      \insertauthors\\
      {\em \insertemail}\\
      \vspace{1cm}
      \tinyv
      © Copyright 2004-\the\year, Bootlin.\\
      Creative Commons BY-SA 3.0 license.\\
      Corrections, suggestions, contributions and translations are welcome!
      \column{0.5\textwidth}
      \begin{center}
        \includegraphics[scale=0.45]{common/logo-square.pdf}
      \end{center}
    \end{columns}
  \end{frame}
}

\AtBeginSubsection[]
{
  \begin{frame}{\inserttitle}
    \huge
    \begin{center}
      \insertsubsection
    \end{center}
  \end{frame}
}

\newcommand\todo[1]{
  {\large \color{red}TODO: #1}
}

\usemintedstyle{perldoc}

%% Create a slide announcing a lab, with the beautiful worker penguin
%% on the left.
%%  first argument: slide title (will be prepended by 'Practical lab - ')
%%  second argument: contents of the slide
\newcommand\setuplabframe[2]{
  \begin{frame}{Practical lab - #1}
    \begin{columns}
      \column{0.4\textwidth}
      \includegraphics[width=\textwidth]{common/lab-penguins.pdf}
      \column{0.6\textwidth}
      #2
      \end{columns}
  \end{frame}
}

\newcommand\questionslide
{
\begin{frame}
    \centering
    \Huge
    Questions? Suggestions? Comments?\\
    \vspace{1.5cm}
    \huge
    \insertauthors\\
    \large
    {\em \insertemail}\\
    \includegraphics[height=0.06\textheight]{common/mastodon.pdf}
    {\small \url{https://fosstodon.org/@MichaelOpdenacker}}\\
    \vspace{0.5cm}
    Slides under CC-BY-SA 3.0\\
    \scriptsize
    \url{\insertslidesurl}
\end{frame}
}

\usemintedstyle{perldoc}
