├── Arduino └── Arduino.ino ├── auto.theme ├── chameleon.py ├── demo.sh ├── docs.md ├── rainbow.sh ├── readme.md ├── reload_all.sh └── term_colors.sh /Arduino/Arduino.ino: -------------------------------------------------------------------------------- 1 | int redPin = 9; 2 | int greenPin = 10; 3 | int bluePin = 11; 4 | 5 | int redVal = 255; 6 | int greenVal = 0; 7 | int blueVal = 255; 8 | 9 | String str; 10 | 11 | void setup() { 12 | Serial.begin(9600); 13 | } 14 | 15 | void loop() { 16 | if(Serial.available() > 0) { 17 | redVal = Serial.parseInt(); 18 | greenVal = Serial.parseInt(); 19 | blueVal = Serial.parseInt(); 20 | 21 | if (Serial.read() == '\n') { 22 | analogWrite(redPin, redVal); 23 | delay(30); 24 | analogWrite(greenPin, greenVal); 25 | delay(30); 26 | analogWrite(bluePin, blueVal); 27 | delay(30); 28 | 29 | Serial.print(redVal, HEX); 30 | Serial.print(greenVal, HEX); 31 | Serial.println(blueVal, HEX); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /auto.theme: -------------------------------------------------------------------------------- 1 | ### colors 2 | ### {{{ 3 | set color_cmdline_bg=16 4 | set color_cmdline_fg=231 5 | set color_error=lightred 6 | set color_info=231 7 | set color_separator=231 8 | set color_statusline_bg=16 9 | set color_statusline_fg=231 10 | set color_titleline_bg=16 11 | set color_titleline_fg=231 12 | set color_win_bg=16 13 | set color_win_cur=231 14 | set color_win_cur_sel_bg=188 15 | set color_win_cur_sel_fg=231 16 | set color_win_dir=231 17 | set color_win_fg=231 18 | set color_win_inactive_cur_sel_bg=16 19 | set color_win_inactive_cur_sel_fg=231 20 | set color_win_inactive_sel_bg=16 21 | set color_win_inactive_sel_fg=231 22 | set color_win_sel_bg=188 23 | set color_win_sel_fg=231 24 | set color_win_title_bg=16 25 | set color_win_title_fg=231 26 | ### }}} 27 | 28 | -------------------------------------------------------------------------------- /chameleon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from sys import argv 4 | import os 5 | import re 6 | import serial 7 | import sqlite3 8 | 9 | rofi = "" 10 | dir_path = os.path.dirname(os.path.realpath(__file__)) 11 | home_dir = os.path.expanduser("~") 12 | 13 | 14 | def applyRazer(r, g, b): 15 | os.system( 16 | "echo -n -e \"\\x%s\\x%s\\x%s\" > /sys/bus/hid/drivers/razerkbd/0003:1532:0209.0003/matrix_effect_static" 17 | % (r, g, b)) 18 | 19 | 20 | def applyi3(primary, secondary, background): 21 | i3conf = open("%s/.config/i3/config" % home_dir).read() 22 | i3conf = re.sub(r"set \$color #.{1,6}", "set $color #%s" % primary, i3conf) 23 | i3conf = re.sub(r"set \$color_uf #.{1,6}", "set $color_uf #%s" % secondary, 24 | i3conf) 25 | i3conf = re.sub(r"set \$color_2 #.{1,6}", "set $color_2 #%s" % background, 26 | i3conf) 27 | with open("%s/.config/i3/config" % home_dir, 'w') as file: 28 | file.write(i3conf) 29 | 30 | 31 | def applyPolybar(primary, secondary, background): 32 | polybarConf = open("%s/.config/polybar/config" % home_dir).read() 33 | polybarConf = re.sub(r"primary = #.{1,6}", "primary = #%s" % primary, 34 | polybarConf) 35 | polybarConf = re.sub(r"secondary = #.{1,6}", "secondary = #%s" % secondary, 36 | polybarConf) 37 | polybarConf = re.sub(r"background = #.{1,6}", 38 | "background = #%s" % background, polybarConf) 39 | polybarConf = re.sub(r"secondary = #.{1,6}", "secondary = #%s" % secondary, 40 | polybarConf) 41 | with open("%s/.config/polybar/config" % home_dir, 'w') as file: 42 | file.write(polybarConf) 43 | 44 | 45 | def applyCava(primary): 46 | cavaConf = open("%s/.config/cava/config" % home_dir).read() 47 | cavaConf = re.sub(r"foreground = '#.{1,6}'", 48 | "foreground = '#%s'" % primary, cavaConf) 49 | with open("%s/.config/cava/config" % home_dir, 'w') as file: 50 | file.write(cavaConf) 51 | 52 | 53 | def applyRofi(primary, secondary): 54 | rofiConf = open("%s/.Xdefaults" % home_dir).read() 55 | rofiConf = re.sub(r"rofi.color-normal: .+", 56 | "rofi.color-normal: #111111,#%s,#222222,#444444,#%s" % 57 | (primary, primary), rofiConf) 58 | rofiConf = re.sub(r"rofi.color-urgent: .+", 59 | "rofi.color-urgent: #111111,#%s,#222222,#444444,#%s" % 60 | (secondary, primary), rofiConf) 61 | rofiConf = re.sub(r"rofi.color-active: .+", 62 | "rofi.color-active: #111111,#%s,#222222,#444444,#%s" % 63 | (secondary, primary), rofiConf) 64 | with open("%s/.Xdefaults" % home_dir, 'w') as file: 65 | file.write(rofiConf) 66 | 67 | 68 | def applyTerm(red, green, blue): 69 | with open("%s/.gtcolors" % home_dir, 'w') as file: 70 | file.write("rgb(%d,%d,%d)\nrgb(%d,%d,%d)" % 71 | (red[0], green[0], blue[0], red[2], green[2], blue[2])) 72 | 73 | 74 | def applyFish(primary, secondary): 75 | colors = [ 76 | "main %s" % primary, "command %s" % primary, "quote %s" % secondary, 77 | "redirection %s" % primary, "end %s" % secondary, "param %s" % primary, 78 | "comment %s" % secondary, "match %s" % secondary, 79 | "search_match %s" % secondary, "operator %s" % primary, 80 | "escape %s" % secondary, "cwd %s" % primary, 81 | "autosuggestion %s" % secondary 82 | ] 83 | 84 | for color in colors: 85 | os.system("fish -c \"set -Ux fish_color_%s\"" % color) 86 | 87 | 88 | def applyLed(red, green, blue): 89 | with serial.Serial("/dev/ttyACM0") as ser: 90 | ser.write(b"0 %d %d %d\n" % ((255 - red), (255 - green), (255 - blue))) 91 | 92 | 93 | def applyTwmn(primary, background): 94 | twmnConf = open("%s/.config/twmn/twmn.conf" % home_dir).read() 95 | twmnConf = re.sub(r"foreground_color=#.{1,6}", 96 | "foreground_color=#%s" % primary, twmnConf) 97 | twmnConf = re.sub(r"background_color=#.{1,6}", 98 | "background_color=#%s" % background, twmnConf) 99 | with open("%s/.config/twmn/twmn.conf" % home_dir, 'w') as file: 100 | file.write(twmnConf) 101 | 102 | 103 | def applyi3lock(primary, primary2): 104 | i3lockConf = open("%s/src/BlurLocker/lock.sh" % home_dir).read() 105 | i3lockConf = re.sub(r"COLOR='#.{1,6}'", "COLOR='#%s'" % primary, 106 | i3lockConf) 107 | i3lockConf = re.sub(r"COLOR2='.{1,3}'", "COLOR2='%s'" % primary2, 108 | i3lockConf) 109 | with open("%s/src/BlurLocker/lock.sh" % home_dir, 'w') as file: 110 | file.write(i3lockConf) 111 | 112 | 113 | def applyFirefox(primary, secondary, background): 114 | db = sqlite3.connect( 115 | "%s/.mozilla/firefox/mg23unpc.dev-edition-default/stylish.sqlite" % 116 | home_dir) 117 | cr = db.cursor() 118 | cr.execute("SELECT code FROM styles WHERE name = 'Auto';") 119 | autoStyle = cr.fetchone()[0] 120 | autoStyle = re.sub(r"--foreground: #.{1,6};", 121 | "--foreground: #%s;" % primary, autoStyle) 122 | rofiConf = re.sub(r"--foreground-alt: #.{1,6};", 123 | "--foreground-alt: #%s;" % secondary, autoStyle) 124 | rofiConf = re.sub(r"--background: #.{1,6};", 125 | "--background: #%s;" % background, autoStyle) 126 | cr.execute( 127 | "UPDATE styles SET code = '%s' WHERE name = 'Auto';" % autoStyle) 128 | db.commit() 129 | db.close() 130 | 131 | 132 | def applyCmus(red, green, blue): 133 | primary = (36 * round(red[0] / 51)) + (6 * round(green[0] / 51)) + round( 134 | blue[0] / 51) + 16 135 | secondary = (36 * round(red[1] / 51)) + (6 * round(green[1] / 51)) + round( 136 | blue[1] / 51) + 16 137 | background = (36 * round(red[2] / 51)) + ( 138 | 6 * round(green[2] / 51)) + round(blue[2] / 51) + 16 139 | 140 | colors = [ 141 | "cmdline_fg=%d" % primary, "info=%d" % primary, 142 | "separator=%d" % primary, "statusline_fg=%d" % primary, 143 | "titleline_fg=%d" % primary, "win_cur=%d" % primary, 144 | "win_cur_sel_bg=%d" % secondary, "win_cur_sel_fg=%d" % primary, 145 | "win_dir=%d" % primary, "win_fg=%d" % primary, 146 | "win_inactive_cur_sel_fg=%d" % primary, 147 | "win_inactive_sel_fg=%d" % primary, "win_sel_bg=%d" % secondary, 148 | "win_sel_fg=%d" % primary, "win_title_fg=%d" % primary, 149 | "cmdline_bg=%d" % background, "statusline_bg=%d" % background, 150 | "titleline_bg=%d" % background, "win_bg=%d" % background, 151 | "win_inactive_cur_sel_bg=%d" % background, 152 | "win_inactive_sel_bg=%d" % background, "win_title_bg=%d" % background 153 | ] 154 | 155 | cmusConf = open("%s/.config/cmus/auto.theme" % home_dir).read() 156 | 157 | for color in colors: 158 | cmusConf = re.sub(r"set color_%s=.{1,3}" % color.split("=")[0], 159 | "set color_%s" % color, cmusConf) 160 | 161 | with open("%s/.config/cmus/auto.theme" % home_dir, 'w') as file: 162 | file.write(cmusConf) 163 | 164 | 165 | def main(): 166 | red = [int(argv[1][:2], 16), int(argv[2][:2], 16), int(argv[3][:2], 16)] 167 | green = [ 168 | int(argv[1][2:4], 16), int(argv[2][2:4], 16), int(argv[3][2:4], 16) 169 | ] 170 | blue = [ 171 | int(argv[1][4:6], 16), int(argv[2][4:6], 16), int(argv[3][4:6], 16) 172 | ] 173 | 174 | primaryCode = (36 * round(red[0] / 51)) + (6 * round(green[0] / 51)) + round( 175 | blue[0] / 51) + 16 176 | secondaryCode = (36 * round(red[1] / 51)) + (6 * round(green[1] / 51)) + round( 177 | blue[1] / 51) + 16 178 | backgroundCode = (36 * round(red[2] / 51)) + ( 179 | 6 * round(green[2] / 51)) + round(blue[2] / 51) + 16 180 | 181 | print("Applying to keyboard") 182 | applyRazer(argv[1][:2], argv[1][2:4], argv[1][4:]) 183 | 184 | print("Applying to i3") 185 | applyi3(argv[1], argv[2], argv[3]) 186 | 187 | # print("Applying to Polybar") 188 | # applyPolybar(argv[1], argv[2], argv[3]) 189 | 190 | print("Applying to rofi") 191 | applyRofi(argv[1], argv[2]) 192 | 193 | print("Applying to fish") 194 | applyFish(argv[1], argv[2]) 195 | 196 | print("Applying to gnome_terminal") 197 | applyTerm(red, green, blue) 198 | 199 | print("Applying to Firefox") 200 | applyFirefox(argv[1], argv[2], argv[3]) 201 | 202 | print("Applying to cava") 203 | applyCava(argv[1]) 204 | 205 | # print("Applying to twmn") 206 | # applyTwmn(argv[1], argv[3]) 207 | 208 | print("Applying to cmus") 209 | applyCmus(red, green, blue) 210 | 211 | print("Applying to i3lock") 212 | applyi3lock(argv[1], primaryCode) 213 | 214 | print("Reloading Everything") 215 | os.system("%s/reload_all.sh" % dir_path) 216 | 217 | print("Applying to LED strip") 218 | applyLed(red[0], green[0], blue[0]) 219 | 220 | print("All done :D") 221 | 222 | 223 | if len(argv) < 4: 224 | print("Usage: %s " % 225 | argv[0]) 226 | else: 227 | main() 228 | -------------------------------------------------------------------------------- /demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | figlet "chameleon.py" 3 | figlet "============" 4 | figlet "RED" 5 | ./chameleon.py ff0000 660000 000000 6 | sleep 2 7 | figlet "============" 8 | figlet "GREEN" 9 | ./chameleon.py 00ff00 006600 000000 10 | sleep 2 11 | figlet "============" 12 | figlet "BLUE" 13 | ./chameleon.py 0000ff 000066 000000 14 | sleep 2 15 | figlet "============" 16 | figlet "BLACK" 17 | ./chameleon.py 222222 444444 dddddd 18 | sleep 2 19 | figlet "============" 20 | figlet "WHITE" 21 | ./chameleon.py ffffff dddddd 000000 22 | -------------------------------------------------------------------------------- /docs.md: -------------------------------------------------------------------------------- 1 | # Using this on your system 2 | 3 | ## I AM IN NO WAY RESPONSIBLE FOR ANY ISSUES THAT MAY ARISE DURING THE USE OF THIS SCRIPT. 4 | ## DON'T BE AN IDIOT. BACK UP YOUR CONFIGS. 5 | ## THIS SCRIPT IS A WIP. BREAKING CHANGES WILL MOST LIKELY BE INTRODUCED. I WARNED YOU. 6 | 7 | (Note: I'm assuming you're using either bash or fish on gnome-terminal) 8 | 9 | Requires python3 and PySerial! 10 | 11 | Make sure you edit `chameleon.py` and `reload_all.sh` and comment out everything that you don't have on your system. 12 | 13 | For example, if you're using bash instead of fish comment out 14 | ```python 15 | print("Applying to fish") 16 | applyFish(argv[1], argv[2]) 17 | ``` 18 | in main.py, and ignore instructions for Fish in this document. 19 | 20 | Check all the paths in `chameleon.py` and make sure they're correct for your system. 21 | 22 | If you've followed all the instructions in this document and still can't get it to work, feel free to PM me [here](https://www.reddit.com/message/compose?to=joonatoona&subject=full_rgb) 23 | 24 | ## Special changes 25 | 26 | ### Polybar 27 | 28 | Use the variables `background`, `primary`, and `secondary`. 29 | 30 | The [colors] block of your config should look something like this: 31 | ``` 32 | [colors] 33 | background = #000000 34 | background-alt = ${colors.background} 35 | primary = #ffffff 36 | secondary = #dddddd 37 | alert = #55FF0000 38 | ``` 39 | 40 | Make sure you start polybar with `polybar -c /path/to/config -r bar_name` 41 | 42 | ### gnome-terminal 43 | 44 | Add this to `~/.gtcolors` 45 | ``` 46 | rgb(255,255,255) 47 | rgb(0,0,0) 48 | ``` 49 | 50 | In the profile preferences for `gnome-terminal` check `Run command as a login shell` and `Run a custom command instead of my shell` 51 | 52 | Set the custom command to 53 | ```bash 54 | bash -c '/home/joonatoona/src/ColorTing/term_colors.sh &> /dev/null & fish' 55 | ``` 56 | changing the path to wherever you cloned this repo, and fish to whatever your shell is. 57 | 58 | ### i3 59 | 60 | In your i3 config, make sure all colors are using the variables `color` (Primary), `color_uf` (Secondary), and `color_2` (Background). Add this to the top: 61 | ``` 62 | set $color #ffffff 63 | set $color_2 #222222 64 | set $color_uf #dddddd 65 | ``` 66 | 67 | ### cmus 68 | 69 | Copy `auto.theme` from this repo to `~/.config/cmus/auto.theme` 70 | 71 | ### cava 72 | 73 | Start cava with 74 | ```bash 75 | while :; do 76 | cava 77 | done 78 | ``` 79 | 80 | ### LED Strip 81 | 82 | Connect an LED strip to the arduino in this way: 83 | ``` 84 | Pin9: RED 85 | Pin10: GREEN 86 | Pin11: BLUE 87 | 5V: POWER 88 | ``` 89 | 90 | Then flash the sketch in this repo to the arduino. 91 | 92 | Also change 93 | ```python 94 | with serial.Serial("/dev/ttyACM0") as ser: 95 | ``` 96 | to the serial port your Arduino is connected to. 97 | 98 | ### Keyboard 99 | 100 | (Only works with Razer keyboards as of now) 101 | 102 | Change the path to point to your keyboard bus. 103 | ``` 104 | os.system( 105 | "echo -n -e \"\\x%s\\x%s\\x%s\" > /sys/bus/hid/drivers/razerkbd/0003:1532:0209.0003/matrix_effect_static" 106 | % (r, g, b)) 107 | ``` 108 | 109 | ### ROFI 110 | 111 | Make sure these lines are in your `~/.Xdefaults` 112 | ``` 113 | rofi.color-normal: #111111,#ffffff,#222222,#444444,#ffffff 114 | rofi.color-urgent: #111111,#dddddd,#222222,#444444,#ffffff 115 | rofi.color-active: #111111,#dddddd,#222222,#444444,#ffffff 116 | ``` 117 | 118 | ### Fish 119 | 120 | Add 121 | ``` 122 | set -e -g fish_color_main 123 | set -e -g fish_color_command 124 | set -e -g fish_color_quote 125 | set -e -g fish_color_redirection 126 | set -e -g fish_color_param 127 | set -e -g fish_color_comment 128 | set -e -g fish_color_match 129 | set -e -g fish_color_search_match 130 | set -e -g fish_color_operator 131 | set -e -g fish_color_escape 132 | set -e -g fish_color_cwd 133 | set -e -g fish_color_autosuggestion 134 | set -e -g fish_color_end 135 | ``` 136 | to `~/.config/fish/config.fish` 137 | -------------------------------------------------------------------------------- /rainbow.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | i3conf=~/.config/i3/config 4 | 5 | change_colors() { 6 | sed -i -e "s/\$color\ \#.\{6\}/\$color\ \#$1/" $i3conf 7 | sed -i -e "s/\$color_2\ \#.\{6\}/\$color_2\ \#$2/" $i3conf 8 | sed -i -e "s/\$color_uf\ \#.\{6\}/\$color_uf\ \#$3/" $i3conf 9 | i3-msg reload &> /dev/null 10 | } 11 | 12 | change_term_colors() { 13 | echo "rgb($1,$2,$3)" > ~/.gtcolors 14 | } 15 | 16 | get_hex() { 17 | printf "%02x%02x%02x" $1 $2 $3 18 | } 19 | 20 | RED=255 21 | GREEN=0 22 | BLUE=0 23 | 24 | while :; do 25 | for i in `seq 1 255`; do 26 | let RED-=1 27 | let GREEN+=1 28 | let RED_D=RED-100 29 | if [ $RED_D -lt 0 ]; then RED_D=0; fi 30 | let GREEN_D=GREEN-100 31 | if [ $GREEN_D -lt 0 ]; then GREEN_D=0; fi 32 | HEX=$(get_hex $RED $GREEN $BLUE) 33 | HEX_DARK=$(get_hex $RED_D $GREEN_D $BLUE) 34 | change_colors $HEX "000000" $HEX_DARK 35 | change_term_colors $RED $GREEN $BLUE 36 | done 37 | 38 | for i in `seq 1 255`; do 39 | let GREEN-=1 40 | let BLUE+=1 41 | let GREEN_D=GREEN-100 42 | if [ $GREEN_D -lt 0 ]; then GREEN_D=0; fi 43 | let BLUE_D=BLUE-100 44 | if [ $BLUE_D -lt 0 ]; then BLUE_D=0; fi 45 | HEX=$(get_hex $RED $GREEN $BLUE) 46 | HEX_DARK=$(get_hex $RED $GREEN_D $BLUE_D) 47 | change_colors $HEX "000000" $HEX_DARK 48 | change_term_colors $RED $GREEN $BLUE 49 | done 50 | 51 | for i in `seq 1 255`; do 52 | let BLUE-=1 53 | let RED+=1 54 | let BLUE_D=BLUE-100 55 | if [ $BLUE_D -lt 0 ]; then BLUE_D=0; fi 56 | let RED_D=RED-100 57 | if [ $RED_D -lt 0 ]; then RED_D=0; fi 58 | HEX=$(get_hex $RED $GREEN $BLUE) 59 | HEX_DARK=$(get_hex $RED_D $GREEN $BLUE_D) 60 | change_colors $HEX "000000" $HEX_DARK 61 | change_term_colors $RED $GREEN $BLUE 62 | done 63 | done 64 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Do not run this. 2 | 3 | I mean it. This is integrated with the rest of my system. If you try and run it, it will not work. It will also probably break something. 4 | 5 | If you reeeeeeally want to try it, read `docs.md` 6 | 7 | You can see this script in action [here](https://www.reddit.com/r/unixporn/comments/6al0o8/fully_automated_color_changing_i3_hardware/) 8 | 9 | Just so people don't need to ask for info: 10 | 11 | * Info Display: [Neofetch](https://github.com/dylanaraps/neofetch) 12 | * Color Changing: This repo, silly. 13 | * Media Player: [cmus](https://cmus.github.io/) 14 | * Media Visualizer: [CAVA](https://github.com/karlstav/cava) 15 | -------------------------------------------------------------------------------- /reload_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Reloading i3" 4 | i3-msg reload &> /dev/null & 5 | 6 | echo "Reloading rofi" 7 | xrdb -merge ~/.Xdefaults & 8 | 9 | echo "Restarting all instances of cava" 10 | killall /usr/bin/cava &> /dev/null & 11 | 12 | echo "Reloading cmus" 13 | cmus-remote -C "colorscheme auto" &> /dev/null & 14 | 15 | echo "Reloading twmn" 16 | killall twmnd 17 | nohup twmnd &> /dev/null & 18 | 19 | sleep 1 && twmnc "chameleon.py done" & 20 | echo "Done!" 21 | -------------------------------------------------------------------------------- /term_colors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | while inotifywait -e close_write ~/.gtcolors; do 4 | dconf write /org/gnome/terminal/legacy/profiles:/:6f42fd60-c298-4dd0-852d-f8f4a4577078/foreground-color $(echo \'$(head -n 1 ~/.gtcolors)\') 5 | dconf write /org/gnome/terminal/legacy/profiles:/:6f42fd60-c298-4dd0-852d-f8f4a4577078/background-color $(echo \'$(tail -n 1 ~/.gtcolors)\') 6 | done 7 | --------------------------------------------------------------------------------