-- Reno98 - a retro replica of a very recognizable theme
--[[
    Reno98 - A theme for Reno desktop

    Written in 2022 by Yessiest (yessiest@memeware.net)

    To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

    You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. 
--]]
local theme_assets = require("beautiful.theme_assets")
local xresources = require("beautiful.xresources")
local dpi = xresources.apply_dpi
local gears = require("gears")

local gfs = require("gears.filesystem")
local themes_path = root_path.."/themes/"

local theme = {}

theme.font          = "Terminus 8"

theme.bg_normal     = "#c0c0c0"
theme.bg_focus      = "#808080"
theme.bg_urgent     = "#FFEDCC"
theme.bg_minimize   = "#efefef"
theme.bg_highlight_shadow = "#000000FF"
theme.bg_highlight_light = "#FFFFFFFF"
theme.bg_highlight_outline = "#808080FF"
theme.bg_systray    = theme.bg_normal

theme.fg_normal     = "#000000"
theme.fg_focus      = "#000000"
theme.fg_urgent     = "#000000"
theme.fg_minimize   = "#000000"

theme.useless_gap   = dpi(0)
-- technically speaking these are irrelevant since they're not exactly smart
-- borders
theme.border_width  = dpi(0)
theme.border_normal = "#c0c0c0"
theme.border_focus  = "#c0c0c0"
theme.border_marked = "#c0c0c0"

theme.titlebar_bg_focus = {
  type = "linear",
  from = { 0, 0 },
  to = { 640, 0 },
  stops = { {0, "#040582"}, {1, "#0F7FCD"} }
}

theme.titlebar_bg_normal = {
  type = "linear",
  from = { 0, 0 },
  to = { 640, 0 },
  stops = { {0, "#828282"}, {1, "#AFAFAF"} }
}
local taglist_square_size = dpi(4)
theme.taglist_squares_sel = theme_assets.taglist_squares_sel(
    taglist_square_size, theme.fg_normal
)
theme.taglist_squares_unsel = theme_assets.taglist_squares_unsel(
    taglist_square_size, theme.fg_normal
)
theme.menu_height = dpi(15)
theme.menu_width  = dpi(100)
theme.systray_icon_spacing = 2

-- Define the image to load

theme.titlebar_ontop_button_normal_inactive = themes_path.."reno98/titlebar/ontop_normal_inactive.png"
theme.titlebar_ontop_button_focus_inactive  = themes_path.."reno98/titlebar/ontop_focus_inactive.png"
theme.titlebar_ontop_button_normal_active = themes_path.."reno98/titlebar/ontop_normal_active.png"
theme.titlebar_ontop_button_focus_active  = themes_path.."reno98/titlebar/ontop_focus_active.png"

theme.titlebar_sticky_button_normal_inactive = themes_path.."reno98/titlebar/sticky_normal_inactive.png"
theme.titlebar_sticky_button_focus_inactive  = themes_path.."reno98/titlebar/sticky_focus_inactive.png"
theme.titlebar_sticky_button_normal_active = themes_path.."reno98/titlebar/sticky_normal_active.png"
theme.titlebar_sticky_button_focus_active  = themes_path.."reno98/titlebar/sticky_focus_active.png"

theme.titlebar_floating_button_normal_inactive = themes_path.."reno98/titlebar/floating_normal_inactive.png"
theme.titlebar_floating_button_focus_inactive  = themes_path.."reno98/titlebar/floating_focus_inactive.png"
theme.titlebar_floating_button_normal_active = themes_path.."reno98/titlebar/floating_normal_active.png"
theme.titlebar_floating_button_focus_active  = themes_path.."reno98/titlebar/floating_focus_active.png"

theme = theme_assets.recolor_titlebar(theme,theme.fg_normal,"normal")
theme = theme_assets.recolor_titlebar(theme,theme.fg_focus,"focus")

theme.titlebar_close_button_normal = themes_path.."reno98/titlebar/close_normal.png"
theme.titlebar_close_button_focus  = themes_path.."reno98/titlebar/close_focus.png"

theme.titlebar_minimize_button_normal = themes_path.."reno98/titlebar/minimize_normal.png"
theme.titlebar_minimize_button_focus  = themes_path.."reno98/titlebar/minimize_focus.png"

theme.titlebar_maximized_button_normal_inactive = themes_path.."reno98/titlebar/maximized_normal_inactive.png"
theme.titlebar_maximized_button_focus_inactive  = themes_path.."reno98/titlebar/maximized_focus_inactive.png"
theme.titlebar_maximized_button_normal_active = themes_path.."reno98/titlebar/maximized_normal_active.png"
theme.titlebar_maximized_button_focus_active  = themes_path.."reno98/titlebar/maximized_focus_active.png"

theme.wallpaper = themes_path.."reno98/background.png"
theme.wallpapers_icon = themes_path.."reno98/icons/wallpapers.png"

-- You can use your own layout icons like this:
theme.layout_fairh = themes_path.."reno98/layouts/fairhw.png"
theme.layout_fairv = themes_path.."reno98/layouts/fairvw.png"
theme.layout_floating  = themes_path.."reno98/layouts/floatingw.png"
theme.layout_magnifier = themes_path.."reno98/layouts/magnifierw.png"
theme.layout_max = themes_path.."reno98/layouts/maxw.png"
theme.layout_fullscreen = themes_path.."reno98/layouts/fullscreenw.png"
theme.layout_tilebottom = themes_path.."reno98/layouts/tilebottomw.png"
theme.layout_tileleft   = themes_path.."reno98/layouts/tileleftw.png"
theme.layout_tile = themes_path.."reno98/layouts/tilew.png"
theme.layout_tiletop = themes_path.."reno98/layouts/tiletopw.png"
theme.layout_spiral  = themes_path.."reno98/layouts/spiralw.png"
theme.layout_dwindle = themes_path.."reno98/layouts/dwindlew.png"
theme.layout_cornernw = themes_path.."reno98/layouts/cornernww.png"
theme.layout_cornerne = themes_path.."reno98/layouts/cornernew.png"
theme.layout_cornersw = themes_path.."reno98/layouts/cornersww.png"
theme.layout_cornerse = themes_path.."reno98/layouts/cornersew.png"

-- Generate Awesome icon:
theme.awesome_icon = theme_assets.awesome_icon(
    theme.menu_height, theme.bg_focus, theme.fg_focus
)

theme.bgimage_outset = function(context, cr, width, height,...)
    local light = gears.color(theme.bg_highlight_light)
    local shadow = gears.color(theme.bg_highlight_shadow)
    local outline = gears.color(theme.bg_highlight_outline)
    -- Background

    -- Light
    cr:set_source(light)
    cr.line_width=2
    cr:move_to(0,0)
    cr:line_to(width,0)
    cr:move_to(0,0)
    cr:line_to(0,height)
    cr:stroke()

    -- Outline
    cr:set_source(outline)
    cr:move_to(width-1,height-1)
    cr:line_to(width-1,1)
    cr:move_to(width-2,height-1)
    cr:line_to(1,height-1)
    cr:stroke()

    -- Shadow
    cr:set_source(shadow)
    cr:move_to(width,height)
    cr:line_to(width,0)
    cr:move_to(width-1,height)
    cr:line_to(0,height)
    cr:stroke()
end

theme.bgimage_inset = function(context,cr,width,height)
    local light = gears.color(theme.bg_highlight_light)
    local shadow = gears.color(theme.bg_highlight_shadow)
    local outline = gears.color(theme.bg_highlight_outline)

    -- Light
    cr:set_source(light)
    cr.line_width=2
    cr:move_to(width,height)
    cr:line_to(width,0)
    cr:move_to(width,height)
    cr:line_to(0,height)
    cr:stroke()
    
    -- Shadow
    cr:set_source(shadow)
    cr.line_width=2
    cr:move_to(0,0)
    cr:line_to(0,height)
    cr:move_to(0,0)
    cr:line_to(width,0)
    cr:stroke()
end

theme.bgimage_highlight = function(context,cr,width,height)
    local light = gears.color(theme.bg_highlight_light)
    local shadow = gears.color(theme.bg_highlight_shadow)
    local outline = gears.color(theme.bg_highlight_outline)
    
    -- Light
    cr:set_source(light)
    cr.line_width=2
    cr:move_to(1,1)
    cr:line_to(1,height-2)
    cr:move_to(1,1)
    cr:line_to(width-2,1)
    cr:stroke()
 
    -- Outline
    cr:set_source(outline)
    cr.line_width=2
    cr:rectangle(0,0,width-1,height-1)
    cr:stroke()

    -- Light (bottom)
    cr:set_source(light)
    cr:move_to(width,height)
    cr:line_to(width,0)
    cr:move_to(width,height)
    cr:line_to(0,height)
    cr:stroke()
end

-- A complex piece of "code" to simulate borders.
theme.titlebar_bgimage_top = function(context, cr, width, height,...)
    local light = gears.color(theme.bg_highlight_light)
    local shadow = gears.color(theme.bg_highlight_shadow)
    local outline = gears.color(theme.bg_highlight_outline)
    cr.line_width = 2
    cr:set_source(gears.color(theme.bg_normal))
    cr:rectangle(2,2,width-5,height-3)
    cr:stroke()
    -- Light
    cr:set_source(light)
    cr.line_width=2
    cr:move_to(0,0)
    cr:line_to(width,0)
    cr:move_to(0,0)
    cr:line_to(0,height)
    cr:stroke()

    -- Outline
    cr:set_source(outline)
    cr:move_to(width-1,height)
    cr:line_to(width-1,1)
    cr:stroke()

    -- Shadow
    cr:set_source(shadow)
    cr:move_to(width,height)
    cr:line_to(width,0)
    cr:stroke()
end
theme.titlebar_bgimage_bottom = function(context, cr, width, height, ...)
    local light = gears.color(theme.bg_highlight_light)
    local shadow = gears.color(theme.bg_highlight_shadow)
    local outline = gears.color(theme.bg_highlight_outline)
    -- Background

    -- Light
    cr:set_source(light)
    cr.line_width=2
    cr:move_to(0,0)
    cr:line_to(0,height)
    cr:stroke()

    -- Outline
    cr:set_source(outline)
    cr:move_to(width-1,height-1)
    cr:line_to(width-1,0)
    cr:move_to(width-2,height-1)
    cr:line_to(1,height-1)
    cr:stroke()

    -- Shadow
    cr:set_source(shadow)
    cr:move_to(width,height)
    cr:line_to(width,0)
    cr:move_to(width-1,height)
    cr:line_to(0,height)
    cr:stroke()
    
end
theme.titlebar_bgimage_left = function(context, cr, width, height,...)
    local light = gears.color(theme.bg_highlight_light)
    -- Light
    cr:set_source(light)
    cr.line_width=2
    cr:move_to(0,0)
    cr:line_to(0,height)
    cr:stroke()
end
theme.titlebar_bgimage_right = function(context, cr, width, height,...)
    local shadow = gears.color(theme.bg_highlight_shadow)
    local outline = gears.color(theme.bg_highlight_outline)
    cr.line_width=2
    
    -- Outline
    cr:set_source(outline)
    cr:move_to(width-1,height)
    cr:line_to(width-1,0)
    cr:stroke()

    -- Shadow
    cr:set_source(shadow)
    cr:move_to(width,height)
    cr:line_to(width,0)
    cr:stroke()
end

---theme.bgimage_outset
-- Define the icon theme for application icons. If not set then the icons
-- from /usr/share/icons and /usr/share/icons/hicolor will be used.
theme.icon_theme = "Chicago95"

-- Icons
local icons = {
    "battery-caution-charging-symbolic",
    "battery-empty-charging-symbolic",
    "battery-full-charging-symbolic",
    "battery-good-charging-symbolic",
    "battery-low-charging-symbolic"
}
for k,v in pairs(icons) do
    theme[v] = themes_path.."reno98/icons/"..v..".png"
    theme[v:gsub("-charging","")] = themes_path.."reno98/icons/"..v:gsub("-charging","")..".png"
end
theme["battery-full-charged-symbolic"] = themes_path.."reno98/icons/battery-full-charged-symbolic.png"
theme["battery-missing-symbolic"] = themes_path.."reno98/icons/battery-missing-symbolic.png"
theme["ac-adapter-symbolic"] = themes_path.."reno98/icons/ac-adapter-symbolic.png"
theme["backlight-symbolic"] = themes_path.."reno98/icons/backlight-symbolic.png"
theme["notifications-area-symbolic"] = themes_path.."reno98/icons/notifications-area-symbolic.png"

theme["mpc-previous-symbolic"] = themes_path.."reno98/icons/mpc-previous-symbolic.png"

theme["mpc-play-symbolic"] = themes_path.."reno98/icons/mpc-play-symbolic.png"
theme["mpc-pause-symbolic"] = themes_path.."reno98/icons/mpc-pause-symbolic.png"
theme["mpc-next-symbolic"] = themes_path.."reno98/icons/mpc-next-symbolic.png"

theme["action-poweroff-symbolic"] = themes_path.."reno98/icons/action-poweroff-symbolic.png"
theme["action-lock-screen-symbolic"] = themes_path.."reno98/icons/action-lock-screen-symbolic.png"
theme["action-suspend-symbolic"] = themes_path.."reno98/icons/action-suspend-symbolic.png"
-- Notification popups settings
theme.notification_width = 240
theme.notification_height = 60

-- Default icon for clients
-- This one has to be baked as a surface to avoid memory leaks
theme.icon_default = gears.surface(themes_path.."reno98/icons/unknown-app.png")

theme.widgets = {
    -- {{{ Widget base
    default = {
        container = {
            bgimage = theme.bgimage_highlight,
            shape = function(cr,width,height)
                return require("gears").shape.rounded_rect(cr,width,height,0)
            end
        },
        button = {
            bgimage = theme.bgimage_outset,
            shape = function(cr,width,height)
                return require("gears").shape.rounded_rect(cr,width,height,0)
            end,
            onpress = function(widget)
                widget:set_bg(theme.bg_focus)
                widget:set_bgimage(theme.bgimage_inset)
            end,
            onrelease = function(widget)
                widget:set_bg(theme.bg_normal)
                widget:set_bgimage(theme.bgimage_outset)
            end
        },
        popup = {
            bgimage = theme.bgimage_outset,          
            shape = function(cr,width,height)
                return gears.shape.rounded_rect(cr,width,height,0)
            end,
        },
        titlebar = {
            bgimage = theme.bgimage_outset,
            --margins = 5,
            left = 4,
            right = 5,
            top = 4,
            bottom = 3,
            spacing = 1
        },
        wibar = {
            height = 26,
            width = 60,
            margins = 3,
            shape = function(cr,width,height)
                return gears.shape.rounded_rect(cr,width,height,0)
            end,
            bgimage = theme.bgimage_outset,
            stretch = true
        },
        slider = {
            shape = function(cr,width,height)
                return gears.shape.rounded_rect(cr,width,height,0)
            end,
            height = 20,
            width = 140,
            handle_width = 8,
            handle_border_color = theme.bg_focus,
            handle_border_width = 2,
            bar_height = 6
        }
    },
    -- }}}
    -- {{{ Menus
    generic_menu = {
        base = {
            spacing = 2,
            menu_slide = true
        },
        button = {
            forced_height = 20,
            forced_width = 160
        },
    },
    --}}}
    -- {{{ Status panel widgets
    generic_status_widget = {
        container = {
            bgimage = function() end,
            margins = 0
        },
        button = {
            margins = 0,
            onpress = function() end,
            onrelease = function() end,
            bgimage = function() end
        }
    },
    -- }}}
    soundclown = {
        base = {
            width = 140
        },
        container = {
            bgimage = theme.bgimage_inset,
            bg = "#9CA875"
        }
    },
    notifications = {
        button = {
            height = 40,
            width = 200
        },
        article = {
            icon_size = 50,
            title_valign = "top",
            desc_valign = "top"
        }
    },
    taglist = {
        base = {
            spacing = 2
        },
        button = {
            bgimage_focus = theme.bgimage_inset,
            bgimage_normal = theme.bgimage_outset,
            margins = 2
        },
        container = {
            margins = 3
        }
    },
    subpanel = {
        container = {
            bgimage = theme.bgimage_inset,
            bg = theme.bgimage_normal,
            margins = 2
        }
    },
    dismal = {
        container = {
            bg = theme.bg_focus
        },
        button = {
            height = 34
        }
    },
    tasklist = {
        button = {
            width = 160,
            height = 50,
            bgimage_focus = theme.bgimage_inset,
            bgimage_normal = theme.bgimage_outset,
            bgimage_urgent = theme.bgimage_outset,
            bgimage_minimize = theme.bgimage_outset
        }
    },
    lockscreen = {
        popup = {
            margins = 0
        }
    },
    lockbar = {
        base = {
            height = 22
        }
    },
    lockpanel = {
        base = {
            icon_height = 60,
            icon_width = 60,
            panel_height = 300,
            panel_width = 200,
            panel_bgimage = theme.bgimage_outset
        }
    },
    lock_clock = {
        textbox = {
            font = "Terminus 20"
        }
    },
    client_buttons = {
        button = {
            forced_width = 20,
            forced_height = 20
        },
        base = {
            spacing = 2
        }
    },
    root_buttons = {
        button = {
            forced_width = 20,
            forced_height = 20
        },
        base = {
            spacing = 2
        }
    },
    titlebar = {
        titlebar_top = {
            bgimage_normal = theme.titlebar_bgimage_top,
            bgimage_focus = theme.titlebar_bgimage_top,
            bg_focus = theme.titlebar_bg_focus,
            bg_normal = theme.titlebar_bg_normal,
            fg_focus = "#FAFAFA",
            fg_normal = theme.fg_normal,
            size = 22,
        },
        titlebar_left = {
            bgimage_normal = theme.titlebar_bgimage_left,
            bgimage_focus = theme.titlebar_bgimage_left,
            size = 4,
            bg_focus = theme.bg_normal
        },
        titlebar_right = {
            bgimage_normal = theme.titlebar_bgimage_right,
            bgimage_focus = theme.titlebar_bgimage_right,
            size = 4,
            bg_focus = theme.bg_normal
        },
        titlebar_bottom = {
            bgimage_normal = theme.titlebar_bgimage_bottom,
            bgimage_focus = theme.titlebar_bgimage_bottom,
            size = 4,
            bg_focus = theme.bg_normal
        }
    }
}

return theme

-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
