Skip to content

Commit

Permalink
Added plugin for Suru++ icon theme (themix-project#209)
Browse files Browse the repository at this point in the history
* Added icons_suruplus plugin

* Added suru-plus submodule
  • Loading branch information
SmartFinn authored and actionless committed Jan 30, 2019
1 parent e7bd9b7 commit c1dbaab
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@
[submodule "papirus-icon-theme"]
path = plugins/icons_papirus/papirus-icon-theme
url = https://github.com/PapirusDevelopmentTeam/papirus-icon-theme.git
[submodule "suru-plus"]
path = plugins/icons_suruplus/suru-plus
url = https://github.com/gusbemacbe/suru-plus.git
172 changes: 172 additions & 0 deletions plugins/icons_suruplus/change_color.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env bash
set -ueo pipefail
root="$(readlink -f "$(dirname "$0")")"


print_usage() {
local -i exit_code="$1"

echo "
usage:
$0 [-o OUTPUT_THEME_NAME] [-c COLOR] PRESET_NAME_OR_PATH
examples:
$0 -o droid_test_3 -c 5e468c
$0 monovedek
$0 -o my-theme-name ./colors/lcars"

exit "${exit_code:-1}"
}


darker_channel() {
local value="0x$1"
local light_delta="0x$2"
local -i result

result=$(( value - light_delta ))

(( result < 0 )) && result=0
(( result > 255 )) && result=255

echo "$result"
}


darker() {
local hexinput="$1"
local light_delta=${2-10}

r=$(darker_channel "${hexinput:0:2}" "$light_delta")
g=$(darker_channel "${hexinput:2:2}" "$light_delta")
b=$(darker_channel "${hexinput:4:2}" "$light_delta")

printf '%02x%02x%02x\n' "$r" "$g" "$b"
}


while [[ $# -gt 0 ]]
do
case "$1" in
-h|--help)
print_usage 0
;;
-o|--output)
OUTPUT_THEME_NAME="$2"
shift
;;
-c|--color)
ICONS_COLOR="${2#\#}" # remove leading hash symbol
shift
;;
-*)
echo "unknown option $1"
print_usage 2
;;
*)
THEME="$1"
;;
esac
shift
done

if [ -z "${THEME:-}" ]; then
[ -n "${OUTPUT_THEME_NAME:-}" ] || print_usage 1
[ -n "${ICONS_COLOR:-}" ] || print_usage 1

THEME="$OUTPUT_THEME_NAME"
else
# shellcheck disable=SC1090
if [ -f "$THEME" ]; then
source "$THEME"
THEME=$(basename "$THEME")
elif [ -f "$root/colors/$THEME" ]; then
source "$root/colors/$THEME"
else
echo "'$THEME' preset not found."
exit 1
fi
fi


tmp_dir="$(mktemp -d)"
function post_clean_up {
rm -r "$tmp_dir" || true
}
trap post_clean_up EXIT SIGHUP SIGINT SIGTERM


: "${ICONS_COLOR:=$SEL_BG}"
: "${OUTPUT_THEME_NAME:=oomox-$THEME}"

output_dir="$HOME/.icons/$OUTPUT_THEME_NAME"

light_folder_fallback="$ICONS_COLOR"
medium_base_fallback="$(darker "$ICONS_COLOR" 20)"
dark_stroke_fallback="$(darker "$ICONS_COLOR" 56)"

: "${ICONS_LIGHT_FOLDER:=$light_folder_fallback}"
: "${ICONS_MEDIUM:=$medium_base_fallback}"
: "${ICONS_DARK:=$dark_stroke_fallback}"
: "${ICONS_SYMBOLIC_ACTION:=${MENU_FG:-}}"
: "${ICONS_SYMBOLIC_PANEL:=${HDR_FG:-}}"


echo ":: Copying theme template..."
cp -R "$root/suru-plus/Suru++" "$tmp_dir/"
echo "== Template was copied to $tmp_dir"


echo ":: Replacing folder colors..."
for icon_path in \
"$tmp_dir/Suru++/places/64/folder-custom"{-*,}.svg \
"$tmp_dir/Suru++/places/64/user-custom"{-*,}.svg
do
[ -f "$icon_path" ] || continue # it's a file
[ -L "$icon_path" ] && continue # it's not a symlink

new_icon_path="${icon_path/-custom/-oomox}"
icon_name="${new_icon_path##*/}"
symlink_path="${new_icon_path/-oomox/}" # remove color suffix

sed -e "s/value_light/$ICONS_LIGHT_FOLDER/g" \
-e "s/value_dark/$ICONS_MEDIUM/g" \
-e "s/323232/$ICONS_DARK/g" "$icon_path" > "$new_icon_path"

ln -sf "$icon_name" "$symlink_path"
done

if [ -n "${ICONS_SYMBOLIC_ACTION:-}" ]; then
echo ":: Replacing symbolic actions colors..."
find "$tmp_dir"/Suru++/actions/{16,22,24,symbolic} \
"$tmp_dir"/Suru++/apps/{16,symbolic} \
"$tmp_dir"/Suru++/devices/{16,symbolic} \
"$tmp_dir"/Suru++/mimetypes/16 \
"$tmp_dir"/Suru++/places/{16,symbolic} \
"$tmp_dir"/Suru++/status/symbolic \
-type f -name '*.svg' \
-exec sed -i'' -e "s/5c616c/$ICONS_SYMBOLIC_ACTION/g" '{}' \;
fi

if [ -n "${ICONS_SYMBOLIC_PANEL:-}" ]; then
echo ":: Replacing symbolic panel colors..."
find "$tmp_dir"/Suru++/panel/{16,22,24} \
"$tmp_dir"/Suru++/animations/{22,24} \
-type f -name '*.svg' \
-exec sed -i'' -e "s/d3dae3/$ICONS_SYMBOLIC_PANEL/g" '{}' \;
fi


echo ":: Exporting theme..."
sed -i \
-e "s/Name=Suru++/Name=$OUTPUT_THEME_NAME/g" \
"$tmp_dir/Suru++/index.theme"

if [ -d "$output_dir" ] ; then
rm -r "$output_dir"
fi

mkdir -p "$output_dir"
mv "$tmp_dir"/Suru++/* "$output_dir/"

echo "== Theme was generated in $output_dir"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<svg xmlns="http:https://www.w3.org/2000/svg" width="24" height="24" version="1.1">
<defs>
<style id="current-color-scheme" type="text/css">
.ColorScheme-Text { color:#%SYMBOLIC_PANEL%; } .ColorScheme-Highlight { color:#5294e2; }
</style>
</defs>
<g transform="matrix(1,0,0,1,4,4)">
<path class="ColorScheme-Text" d="M 8,1 4,5 H 1 V 11 H 4 L 8,15 Z M 10,5 V 11 C 11.06,10.42 11.79,9.3 11.79,8 11.79,6.7 11.07,5.58 10,5 Z" style="fill:currentColor"/>
<path class="ColorScheme-Text" d="M 10,1 V 2.5 C 12.32,3.24 14,5.43 14,8 14,10.57 12.32,12.76 10,13.5 V 15 C 13.15,14.22 15.5,11.4 15.5,8 15.5,4.6 13.15,1.78 10,1 Z" style="opacity:0.3;fill:currentColor"/>
</g>
</svg>
10 changes: 10 additions & 0 deletions plugins/icons_suruplus/icon_previews/user-desktop.svg.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<svg xmlns="http:https://www.w3.org/2000/svg" width="24" height="24" version="1.1">
<defs>
<style id="current-color-scheme" type="text/css">
.ColorScheme-Text { color:#%SYMBOLIC_ACTION%; } .ColorScheme-Highlight { color:#5294e2; }
</style>
</defs>
<g transform="matrix(1,0,0,1,4,4)">
<path class="ColorScheme-Text" d="M 6.5 1 A 5.5 5.5 0 0 0 1 6.5 A 5.5 5.5 0 0 0 6.5 12 A 5.5 5.5 0 0 0 9.6172 11.031 L 13.279 14.693 A 1 1 0 0 0 14 15 A 1 1 0 0 0 15 14 A 1 1 0 0 0 14.697 13.283 L 11.027 9.6133 A 5.5 5.5 0 0 0 12 6.5 A 5.5 5.5 0 0 0 6.5 1 z M 6.5 3 A 3.5 3.5 0 0 1 10 6.5 A 3.5 3.5 0 0 1 6.5 10 A 3.5 3.5 0 0 1 3 6.5 A 3.5 3.5 0 0 1 6.5 3 z" style="fill:currentColor"/>
</g>
</svg>
26 changes: 26 additions & 0 deletions plugins/icons_suruplus/icon_previews/user-home.svg.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<svg xmlns="http:https://www.w3.org/2000/svg" width="256" height="256" style="isolation:isolate">
<path fill="#%MEDIUM%" d="M53.039 21C16.724 21 13 23.055 13 59.371v52.167h230V79.563c0-36.316-3.724-42.102-40.039-42.102h-89.336L97.198 21H53.039z"/>
<path fill="#%LIGHT%" d="M53.039 70.384C16.722 70.384 13 74.114 13 110.429v84.524C13 231.269 16.722 235 53.039 235h149.922c36.317 0 40.039-3.731 40.039-40.047V93.969c0-36.316-3.722-40.047-40.039-40.047H119.53l-16.438 16.462H53.039z"/>
<linearGradient id="a" x2="0" y1=".5" y2="-.5" gradientTransform="matrix(230 0 0 181.078 13 53.922)" gradientUnits="userSpaceOnUse">
<stop offset="0%" stop-color="#ffffff" stop-opacity=".07"/>
<stop offset="67.282%" stop-color="#fcefe8" stop-opacity="0"/>
</linearGradient>
<path fill="url(#a)" d="M53.039 70.384C16.722 70.384 13 74.114 13 110.429v84.524C13 231.269 16.722 235 53.039 235h149.922c36.317 0 40.039-3.731 40.039-40.047V93.969c0-36.316-3.722-40.047-40.039-40.047H119.53l-16.438 16.462H53.039z"/>
<g opacity=".4">
<radialGradient id="b" cx=".5" cy=".5" r=".272" fx=".5" fy=".136" gradientTransform="matrix(230 0 0 60.62 13 21)" gradientUnits="userSpaceOnUse">
<stop offset="0%" stop-color="#ffffff"/>
<stop offset="100%" stop-color="#ffffff" stop-opacity=".204"/>
</radialGradient>
<path fill="url(#b)" d="M53.039 21C16.724 21 13 23.055 13 59.371v2.059c0-36.316 3.724-38.373 40.039-38.373h44.159l16.427 16.461h89.336c36.315 0 40.039 5.786 40.039 42.102v-2.057c0-36.316-3.724-42.102-40.039-42.102h-89.336L97.198 21H53.039z"/>
</g>
<g opacity=".4">
<radialGradient id="c" cx=".5" cy=".5" r=".272" fx=".482" fy=".211" gradientTransform="matrix(230 0 0 58.565 13 53.922)" gradientUnits="userSpaceOnUse">
<stop offset="0%" stop-color="#ffffff"/>
<stop offset="100%" stop-color="#ffffff" stop-opacity=".204"/>
</radialGradient>
<path fill="url(#c)" d="M119.53 53.922l-16.438 16.462H53.039C16.724 70.384 13 74.112 13 110.427v2.06c0-36.316 3.724-40.046 40.039-40.046h50.053l16.438-16.46h83.431c36.315 0 40.039 3.727 40.039 40.043v-2.057c0-36.316-3.724-40.045-40.039-40.045H119.53z"/>
</g>
<path fill="#ffffff" opacity=".1" d="M243 167.096l-65.715 65.845h25.676c36.315 0 40.039-3.727 40.039-40.043v-25.802z"/>
<path fill="#%DARK%" d="M123.334 204.799H86.015l-.012-60.429 41.996-43.143 41.999 43.145V209.5h4.681l-.013-60.334 9.996 10.269 3.338-3.283L128.001 94.5 68 156.152l3.338 3.283 9.997-10.27V209.5h65.331v-33.631c0-1.977-.185-3.786-.556-5.428-.37-1.641-1.018-3.04-1.944-4.197-.889-1.193-2.092-2.107-3.611-2.742-1.518-.671-3.426-1.007-5.722-1.007-2.555 0-4.814.168-6.777.504-1.963.336-3.537.653-4.722.951v40.849zm51.331-75.207V115.49h-14.012l14.012 14.102z"/>
<path opacity=".2" d="M13 192.898v2.057C13 231.271 16.724 235 53.039 235h149.922c36.315 0 40.039-3.729 40.039-40.045v-2.057c0 36.316-3.724 40.043-40.039 40.043H53.039c-36.315 0-40.039-3.727-40.039-40.043z"/>
</svg>
83 changes: 83 additions & 0 deletions plugins/icons_suruplus/oomox_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import os

from oomox_gui.config import FALLBACK_COLOR
from oomox_gui.export_common import FileBasedExportDialog
from oomox_gui.plugin_api import OomoxIconsPlugin
from oomox_gui.i18n import _
from oomox_gui.color import mix_theme_colors


PLUGIN_DIR = os.path.dirname(os.path.realpath(__file__))


class SuruPlusIconsExportDialog(FileBasedExportDialog):
timeout = 100

def do_export(self):
self.command = [
"bash",
os.path.join(PLUGIN_DIR, "change_color.sh"),
"-o", self.theme_name,
self.temp_theme_path,
]
super().do_export()

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.do_export()


class Plugin(OomoxIconsPlugin):
name = 'suruplus_icons'
display_name = 'Suru++'
export_dialog = SuruPlusIconsExportDialog
preview_svg_dir = os.path.join(PLUGIN_DIR, "icon_previews/")

theme_model_icons = [
{
'key': 'ICONS_LIGHT_FOLDER',
'type': 'color',
'fallback_key': 'SEL_BG',
'display_name': _('Light Base (Folders)'),
},
{
'key': 'ICONS_MEDIUM',
'type': 'color',
'fallback_key': 'BTN_BG',
'display_name': _('Medium Base'),
},
{
'key': 'ICONS_DARK',
'type': 'color',
'fallback_key': 'HDR_BG',
'display_name': _('Dark Stroke'),
},
{
'key': 'ICONS_SYMBOLIC_ACTION',
'type': 'color',
'fallback_function': lambda colors: mix_theme_colors(
colors['MENU_FG'], colors['BTN_FG'],
0.66
),
'display_name': _('Actions Icons'),
},
{
'key': 'ICONS_SYMBOLIC_PANEL',
'type': 'color',
'fallback_key': 'FG',
'display_name': _('Panel Icons'),
},
]

def preview_transform_function(self, svg_template, colorscheme):
return svg_template.replace(
"%LIGHT%", colorscheme["ICONS_LIGHT_FOLDER"] or FALLBACK_COLOR
).replace(
"%MEDIUM%", colorscheme["ICONS_MEDIUM"] or FALLBACK_COLOR
).replace(
"%DARK%", colorscheme["ICONS_DARK"] or FALLBACK_COLOR
).replace(
"%SYMBOLIC_ACTION%", colorscheme["ICONS_SYMBOLIC_ACTION"] or FALLBACK_COLOR
).replace(
"%SYMBOLIC_PANEL%", colorscheme["ICONS_SYMBOLIC_PANEL"] or FALLBACK_COLOR
)
1 change: 1 addition & 0 deletions plugins/icons_suruplus/suru-plus
Submodule suru-plus added at 8c18ca

0 comments on commit c1dbaab

Please sign in to comment.