% 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}
\setlength{\TPHorizModule}{\paperwidth}
\setlength{\TPVertModule}{\paperheight}

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

% Define the "Bootlin blue" color
\definecolor{blblue}{rgb}{0.5976,0.5976,0.7968}
\setbeamercolor*{palette primary}{bg=blblue}

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

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

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

% Custom bootlin commands
\newcommand{\code}[1]{{\usebeamercolor[fg]{code} \path{#1}}}
\newcommand{\codewithhash}[1]{{\usebeamercolor[fg]{code} \tt{#1}}}
\newcommand\kfunc[1]{\href{https://elixir.bootlin.com/linux/latest/ident/#1}{\code{#1()}}}
\newcommand\ksym[1]{\href{https://elixir.bootlin.com/linux/latest/ident/#1}{\code{#1}}}
\newcommand\kstruct[1]{\href{https://elixir.bootlin.com/linux/latest/ident/#1}{\code{struct #1}}}
\newcommand\kfile[1]{\href{https://elixir.bootlin.com/linux/latest/source/#1}{\code{#1}}}
\newcommand\kfileversion[2]{\href{https://elixir.bootlin.com/linux/v#2/source/#1}{\code{#1}}}
\newcommand\kdir[1]{\href{https://elixir.bootlin.com/linux/latest/source/#1/}{\code{#1/}}}
\newcommand\ksubarch[1]{\href{https://elixir.bootlin.com/linux/latest/source/arch/#1/}{\code{#1}}}
\newcommand\kerneldoctext[1]{\href{https://kernel.org/doc/Documentation/#1}{\code{Documentation/#1}}}
\newcommand\kerneldochtml[1]{\href{https://www.kernel.org/doc/html/latest/#1.html}{\code{#1}}}
\newcommand\kerneldochtmlsection[3]{\href{https://www.kernel.org/doc/html/latest/#1/index.html\##2}{\code{#1} (section {\em #3})}}

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

\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}
  }
}

% Footer
\defbeamertemplate*{footline}{bootlintheme}
{
  \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.03\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{\@authors}{}
\newcommand{\authors}[1]
{
  \renewcommand{\@authors}{#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
      \@authors\\
      \vspace{1cm}
      \tinyv
      © Copyright 2004-\the\year, Bootlin.\\
      Creative Commons BY-SA 3.0 license.\\
      Latest update: \today.\\
      \ifdefempty{\sessionurl}{}{
        Electronic copies of these materials:\\
        \url{\sessionurl}\\
      }
      Document updates and sources:\\
      \url{\@trainingurl}\\
      Corrections, suggestions, contributions and translations are welcome!
      \column{0.5\textwidth}
      \includegraphics[height=4cm]{common/logo-square.pdf}
    \end{columns}
  \end{frame}
}

\AtBeginSection[]
{
  \begin{frame}{\insertconference}
    \begin{columns}[b]
      \column{0.5\textwidth}
      \huge
      \insertsection\\
      \vspace{0.5cm}
      \footnotesize
      \@authors\\
      {\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}
      \includegraphics[scale=0.45]{common/logo-square.pdf}
    \end{columns}
  \end{frame}
}

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

%% 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-penguin.png}
      \column{0.6\textwidth}
      #2
      \end{columns}
  \end{frame}
}

\newcommand\questionslide
{
  \begin{frame}
    \centering
    \Huge
    Questions? Suggestions? Comments?\\
    \vspace{1.5cm}
    \huge
    \@authors\\
    \large
    {\em \insertemail}\\
    \vspace{0.5cm}
    Slides under CC-BY-SA 3.0\\
    \scriptsize
    \url{\insertslidesurl}
  \end{frame}
}

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

\usemintedstyle{perldoc}
