\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage[justification=centering]{caption}
\usepackage{graphics}
\usepackage[listings,skins,minted]{tcolorbox}
\usepackage{etoolbox,xpatch}
\usepackage{multicol}

\setdefaultlanguage{english}

\newfontfamily\emotifont{Noto Emoji}

% ---------------------------------------------------------------------

% new commands
\newcommand\hint[1]{\tiny \color{Black} {#1}\\}
\newcommand\todo[1]{\tiny \color{Red} {TODO: #1}\\}
\newcommand\code[1]{\scriptsize \ttfamily \color{blue} {#1}}
\newcommand\info[1]{\scriptsize \slshape {#1}}

% ---------------------------------------------------------------------

% style thingies
\usetheme{Malmoe}

\tikzset{
  every overlay node/.style={
    rounded corners,anchor=north west,
  },
}
% Usage:
% \tikzoverlay at (-1cm,-5cm) {content};
% or
% \tikzoverlay[text width=5cm] at (-1cm,-5cm) {content};
\def\tikzoverlay{%
   \tikz[baseline,overlay]\node[every overlay node]
}%


\addtobeamertemplate{headline}{}{%
  \tikzoverlay at (-.97\textwidth,.18\textheight) {%
    \includegraphics[height=.15\textheight,keepaspectratio]{images/cmake-logo.png}%
  };
}

\definecolor{herenavy}{RGB}{15,22,33}
\definecolor{hereblue}{RGB}{72,218,208}

\setbeamercolor{structure}{fg=herenavy}

\setbeamercolor{palette primary}{fg=white,bg=herenavy!70}
\setbeamercolor{palette secondary}{fg=white,bg=herenavy!80}
\setbeamercolor{palette tertiary}{fg=white,bg=herenavy!90}
\setbeamercolor{palette quaternary}{fg=white,bg=herenavy}

\setbeamercolor{titlelike}{parent=palette quaternary}

\setbeamercolor{subsection in head/foot}{bg=herenavy!90}

\setbeamercolor{block title}{fg=white,bg=herenavy}
\setbeamercolor{block title alerted}{use=alerted text,fg=white,bg=alerted text.fg!75!bg}
\setbeamercolor{block title example}{use=example text,fg=white,bg=example text.fg!75!bg}

\setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!25!bg}
\setbeamercolor{block body alerted}{parent=normal text,use=block title alerted,bg=block title alerted.bg!25!bg}
\setbeamercolor{block body example}{parent=normal text,use=block title example,bg=block title example.bg!25!bg}

\setbeamercolor{sidebar}{bg=hereblue!70}

\setbeamercolor{palette sidebar primary}{fg=herenavy}
\setbeamercolor{palette sidebar secondary}{fg=herenavy!75}
\setbeamercolor{palette sidebar tertiary}{fg=herenavy!75}
\setbeamercolor{palette sidebar quaternary}{fg=herenavy}

\setbeamercolor*{separation line}{}
\setbeamercolor*{fine separation line}{}

% ---------------------------------------------------------------------

\newcommand\fullscreenimage[2]{
  \begin{figure}
    \centering
    \includegraphics[width=\textwidth,height=.7\textheight,keepaspectratio]{#1}
    \caption*{\tiny #2}
  \end{figure}
}

% ---------------------------------------------------------------------

% Listings stuff

\newcommand{\mynewminted}[3]{%
  \newminted[#1]{#2}{#3}%
  \tcbset{myminted/#1/.style={minted language=#2,minted options={#3}}}}

\mynewminted{CMake}{cmake}{tabsize=2,fontsize=\footnotesize}
\mynewminted{C++}{cpp}{tabsize=4,fontsize=\footnotesize}
\mynewminted{Bash}{bash}{tabsize=2,fontsize=\footnotesize}
\mynewminted{Shell}{shell-session}{tabsize=2,fontsize=\footnotesize,breaklines}


\newtcblisting{codebox}[3][]{%
  listing only,%
  title={#3},%
  enhanced,%
  colback=structure.bg!20,%
  colframe=black!60,%
  drop fuzzy shadow,%
  myminted/#2,%
  #1}

\newtcblisting{goodcodebox}[2][]{%
  listing only,%
  title={Good},%
  enhanced,%
  top=.3em,%
  left=.3em,%
  fonttitle=\tiny\bfseries,%
  colback=structure.bg!20,%
  colframe=green!80!black!90,%
  drop fuzzy shadow,%
  myminted/#2,%
  minted options={fontsize=\tiny},%
  #1}

\newtcblisting{badcodebox}[2][]{%
  listing only,%
  title={Bad},%
  enhanced,%
  top=.3em,%
  left=.3em,%
  fonttitle=\tiny\bfseries,%
  colback=structure.bg!20,%
  colframe=red!90!black!90,%
  drop fuzzy shadow,%
  myminted/#2,%
  minted options={fontsize=\tiny},%
  #1}

% We ignore parsing errors as part of this presentation
\makeatletter
\AtBeginEnvironment{minted}{\dontdofcolorbox}
\def\dontdofcolorbox{\renewcommand\fcolorbox[4][]{##4}}
\xpatchcmd{\inputminted}{\minted@fvset}{\minted@fvset\dontdofcolorbox}{}{}
\makeatother
