Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceliuice committed Aug 17, 2021
0 parents commit f021235
Show file tree
Hide file tree
Showing 189 changed files with 9,012 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Vince

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

## Firefox Safari theme

<p align="center">A MacOSX Safari theme for Firefox 80+</p>

#### Preview
![01](https://github.com/vinceliuice/WhiteSur-gtk-theme/blob/pictures/pictures/firefox-whitesur.png?raw=true)

## Description

This is a bunch of CSS code to make Firefox look closer to MacOSX Safari theme.
Based on https://github.com/rafaelmardojai/firefox-gnome-theme

## Installation

Run `./install.sh`

if you want to edit the style then:

Run `./install.sh -f -e`

if you want to use `Monterey` style then:

Run `./install.sh -f monterey`

![01](https://github.com/vinceliuice/WhiteSur-gtk-theme/blob/pictures/pictures/firefox-monterey.png?raw=true)

### Manual installation

1. Go to `about:support` in Firefox.
2. Application Basics > Profile Directory > Open Directory.
3. Copy `chrome` folder Firefox config folder.
4. If you are using Firefox 69+:
1. Go to `about:config` in Firefox.
2. Search for `toolkit.legacyUserProfileCustomizations.stylesheets` and set it to `true`.
5. Restart Firefox.
6. Open Firefox customization panel and:
1. Use *Title bar* option to toggle CSD if is not set by default.
2. Move the new tab button to headerbar.
3. Select light or dark variants on theme switcher.
7. Be happy with your new gnomish Firefox.

## Enabling optional features
Open `userChrome.css` with a text editor and follow instructions to enable extra features. Keep in mind this file might change in future versions and your configuration will be lost. You can copy the @imports you want to enable to a new file named `customChrome` directly in your `chrome` directory if you want it to survive updates. Remember all @imports must be at the top of the file, before other statements.

## Known bugs

### CSD have sharp corners
See upstream [bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1408360).

#### Wayland fix:
1. Go to the `about:config` page
2. Search for the `layers.acceleration.force-enabled` preference and set it to true.
3. Now restart Firefox, and it should look good!

#### X11 fix:
1. Go to the `about:config` page
2. Type `mozilla.widget.use-argb-visuals`
3. Set it as a `boolean` and click on the add button
4. Now restart Firefox, and it should look good!

## Development

If you wanna mess around the styles and change something, you might find these
things useful.

To use the Inspector to debug the UI, open the developer tools (F12) on any
page, go to options, check both of those:

- Enable browser chrome and add-on debugging toolboxes
- Enable remote debugging

Now you can close those tools and press Ctrl+Alt+Shift+I to Inspect the browser
UI.
229 changes: 229 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
#! /usr/bin/env bash

set -Eeo pipefail

readonly REPO_DIR="$(dirname "$(readlink -m "${0}")")"

MY_USERNAME="${SUDO_USER:-$(logname 2> /dev/null || echo "${USER}")}"
MY_HOME=$(getent passwd "${MY_USERNAME}" | cut -d: -f6)

THEME_NAME="WhiteSur"

edit_firefox="false"

FIREFOX_SRC_DIR="${REPO_DIR}/src"
FIREFOX_DIR_HOME="${MY_HOME}/.mozilla/firefox"
FIREFOX_THEME_DIR="${MY_HOME}/.mozilla/firefox/firefox-themes"
FIREFOX_FLATPAK_DIR_HOME="${MY_HOME}/.var/app/org.mozilla.firefox/.mozilla/firefox"
FIREFOX_FLATPAK_THEME_DIR="${MY_HOME}/.var/app/org.mozilla.firefox/.mozilla/firefox/firefox-themes"
FIREFOX_SNAP_DIR_HOME="${MY_HOME}/snap/firefox/common/.mozilla/firefox"
FIREFOX_SNAP_THEME_DIR="${MY_HOME}/snap/firefox/common/.mozilla/firefox/firefox-themes"

export c_default="\033[0m"
export c_blue="\033[1;34m"
export c_magenta="\033[1;35m"
export c_cyan="\033[1;36m"
export c_green="\033[1;32m"
export c_red="\033[1;31m"
export c_yellow="\033[1;33m"

prompt() {
case "${1}" in
"-s")
echo -e " ${c_green}${2}${c_default}" ;; # print success message
"-e")
echo -e " ${c_red}${2}${c_default}" ;; # print error message
"-w")
echo -e " ${c_yellow}${2}${c_default}" ;; # print warning message
"-i")
echo -e " ${c_cyan}${2}${c_default}" ;; # print info message
esac
}

has_command() {
command -v "$1" &> /dev/null
}

has_flatpak_app() {
flatpak list --columns=application | grep "${1}" &> /dev/null || return 1
}

has_snap_app() {
snap list "${1}" &> /dev/null || return 1
}

udoify_file() {
if [[ -f "${1}" && "$(ls -ld "${1}" | awk '{print $3}')" != "${MY_USERNAME}" ]]; then
schown "${MY_USERNAME}:" "${1}"
fi
}

helpify_title() {
printf "${c_cyan}%s${c_blue}%s ${c_green}%s\n\n" "Usage: " "$0" "[OPTIONS...]"
printf "${c_cyan}%s\n" "OPTIONS:"
}

helpify() {
printf " ${c_blue}%s ${c_green}%s\n ${c_magenta}%s. ${c_cyan}%s\n\n${c_default}" "${1}"
}

usage() {
helpify_title
helpify "-f, --firefox" "[default|monterey]" "Install '${THEME_NAME}|Monterey' theme for Firefox and connect it to the current Firefox profiles" "Default is ${THEME_NAME}"
helpify "-e, --edit-firefox" "" "Edit '${THEME_NAME}' theme for Firefox settings and also connect the theme to the current Firefox profiles" ""
helpify "-h, --help" "" "Show this help" ""
}

install_firefox_theme() {
if has_snap_app firefox; then
local TARGET_DIR="${FIREFOX_SNAP_THEME_DIR}"
elif has_flatpak_app org.mozilla.firefox; then
local TARGET_DIR="${FIREFOX_FLATPAK_THEME_DIR}"
else
local TARGET_DIR="${FIREFOX_THEME_DIR}"
fi

local name=${1}

mkdir -p "${TARGET_DIR}"
cp -rf "${FIREFOX_SRC_DIR}/${name}" "${TARGET_DIR}"
[[ -f "${TARGET_DIR}"/customChrome.css ]] && mv "${TARGET_DIR}"/customChrome.css "${TARGET_DIR}"/customChrome.css.bak
cp -rf "${FIREFOX_SRC_DIR}"/customChrome.css "${TARGET_DIR}"
cp -rf "${FIREFOX_SRC_DIR}"/common/* "${TARGET_DIR}/${name}"
[[ -f "${TARGET_DIR}"/userChrome.css ]] && mv "${TARGET_DIR}"/userChrome.css "${TARGET_DIR}"/userChrome.css.bak
cp -rf "${FIREFOX_SRC_DIR}"/userChrome-"${name}".css "${TARGET_DIR}"/userChrome.css

config_firefox
}

config_firefox() {
if has_snap_app firefox; then
local TARGET_DIR="${FIREFOX_SNAP_THEME_DIR}"
local FIREFOX_DIR="${FIREFOX_SNAP_DIR_HOME}"
elif has_flatpak_app org.mozilla.firefox; then
local TARGET_DIR="${FIREFOX_FLATPAK_THEME_DIR}"
local FIREFOX_DIR="${FIREFOX_FLATPAK_DIR_HOME}"
else
local TARGET_DIR="${FIREFOX_THEME_DIR}"
local FIREFOX_DIR="${FIREFOX_DIR_HOME}"
fi

killall "firefox" "firefox-bin" &> /dev/null || true

for d in "${FIREFOX_DIR}/"*"default"*; do
if [[ -f "${d}/prefs.js" ]]; then
rm -rf "${d}/chrome"
ln -sf "${TARGET_DIR}" "${d}/chrome"
udoify_file "${d}/prefs.js"
echo "user_pref(\"toolkit.legacyUserProfileCustomizations.stylesheets\", true);" >> "${d}/prefs.js"
echo "user_pref(\"browser.tabs.drawInTitlebar\", true);" >> "${d}/prefs.js"
echo "user_pref(\"browser.uidensity\", 0);" >> "${d}/prefs.js"
echo "user_pref(\"layers.acceleration.force-enabled\", true);" >> "${d}/prefs.js"
echo "user_pref(\"mozilla.widget.use-argb-visuals\", true);" >> "${d}/prefs.js"
fi
done
}

edit_firefox_theme_prefs() {
if has_snap_app firefox; then
local TARGET_DIR="${FIREFOX_SNAP_THEME_DIR}"
elif has_flatpak_app org.mozilla.firefox; then
local TARGET_DIR="${FIREFOX_FLATPAK_THEME_DIR}"
else
local TARGET_DIR="${FIREFOX_THEME_DIR}"
fi

install_firefox_theme ; config_firefox
${EDITOR:-nano} "${TARGET_DIR}/userChrome.css"
${EDITOR:-nano} "${TARGET_DIR}/customChrome.css"
}

remove_firefox_theme() {
#rm -rf "${FIREFOX_DIR_HOME}/"*"default"*"/chrome"
rm -rf "${FIREFOX_THEME_DIR}/${THEME_NAME}"
[[ -f "${FIREFOX_THEME_DIR}"/customChrome.css ]] && rm -rf "${FIREFOX_THEME_DIR}"/customChrome.css
[[ -f "${FIREFOX_THEME_DIR}"/userChrome.css ]] && rm -rf "${FIREFOX_THEME_DIR}"/userChrome.css
#rm -rf "${FIREFOX_FLATPAK_DIR_HOME}/"*"default"*"/chrome"
rm -rf "${FIREFOX_FLATPAK_THEME_DIR}/${THEME_NAME}"
[[ -f "${FIREFOX_FLATPAK_THEME_DIR}"/customChrome.css ]] && rm -rf "${FIREFOX_FLATPAK_THEME_DIR}"/customChrome.css
[[ -f "${FIREFOX_FLATPAK_THEME_DIR}"/userChrome.css ]] && rm -rf "${FIREFOX_FLATPAK_THEME_DIR}"/userChrome.css
#rm -rf "${FIREFOX_SNAP_DIR_HOME}/"*"default"*"/chrome"
rm -rf "${FIREFOX_SNAP_THEME_DIR}/${THEME_NAME}"
[[ -f "${FIREFOX_SNAP_THEME_DIR}"/customChrome.css ]] && rm -rf "${FIREFOX_SNAP_THEME_DIR}"/customChrome.css
[[ -f "${FIREFOX_SNAP_THEME_DIR}"/userChrome.css ]] && rm -rf "${FIREFOX_SNAP_THEME_DIR}"/userChrome.css
}

echo

while [[ $# -gt 0 ]]; do
# Don't show any dialog here. Let this loop checks for errors or shows help
# We can only show dialogs when there's no error and no -r parameter
#
# * shift for parameters that have no value
# * shift 2 for parameter that have a value
#
# Please don't exit any error here if possible. Let it show all error warnings
# at once

case "${1}" in
# Parameters that don't require value
-r|--remove|--revert)
uninstall='true'; shift ;;
-h|--help)
need_help="true"; shift ;;
-f|--firefox|-e|--edit-firefox)
case "${1}" in
-f|--firefox)
firefox="true" ;;
-e|--edit-firefox)
edit_firefox="true" ;;
esac

for variant in "${@}"; do
case "${variant}" in
default)
shift 1
;;
monterey)
monterey="true"
THEME_NAME="Monterey"
shift 1
;;
esac
done

if ! has_command firefox && ! has_flatpak_app org.mozilla.firefox && ! has_snap_app firefox; then
prompt -e "'${1}' ERROR: There's no Firefox installed in your system"
has_any_error="true"
elif [[ ! -d "${FIREFOX_DIR_HOME}" && ! -d "${FIREFOX_FLATPAK_DIR_HOME}" && ! -d "${FIREFOX_SNAP_DIR_HOME}" ]]; then
prompt -e "'${1}' ERROR: Firefox is installed but not yet initialized."
prompt -w "'${1}': Don't forget to close it after you run/initialize it"
elif pidof "firefox" &> /dev/null || pidof "firefox-bin" &> /dev/null; then
prompt -e "'${1}' ERROR: Firefox is running, please close it"
has_any_error="true"
fi; shift ;;
*)
prompt -e "ERROR: Unrecognized tweak option '${1}'."
has_any_error="true"; shift ;;
esac
done

if [[ "${uninstall}" == 'true' ]]; then
prompt -i "Removing '${THEME_NAME}' Firefox theme..."
remove_firefox_theme
prompt -s "Done! '${THEME_NAME}' Firefox theme has been removed."; echo
else
prompt -i "Installing '${THEME_NAME}' Firefox theme..."
install_firefox_theme "${name:-${THEME_NAME}}"
prompt -s "Done! '${THEME_NAME}' Firefox theme has been installed."; echo

if [[ "${edit_firefox}" == 'true' ]]; then
prompt -i "Editing '${THEME_NAME}' Firefox theme preferences..."
edit_firefox_theme_prefs
prompt -s "Done! '${THEME_NAME}' Firefox theme preferences has been edited."; echo
fi

prompt -w "FIREFOX: Please go to [Firefox menu] > [Customize...], and customize your Firefox to make it work. Move your 'new tab' button to the titlebar instead of tab-switcher."
prompt -i "FIREFOX: Anyways, you can also edit 'userChrome.css' and 'customChrome.css' later in your Firefox profile directory."
echo
fi
Loading

0 comments on commit f021235

Please sign in to comment.