├── AUTHORS ├── LICENSE ├── README.md ├── chwall ├── extprimcol ├── rgb2hsl ├── rgb2hsl.c ├── screenshots ├── 1.png ├── 2.png ├── 3.png └── 4.png └── setdwmcol /AUTHORS: -------------------------------------------------------------------------------- 1 | BogdanTheGeek - Initial version 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 BogdanTheGeek 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dwm-primcol 2 | A set of scripts that extract primary colours from a wallpaper and uses them as border/statusbar colours 3 | 4 | This script also sets a random wallpaper from your wallpaperfolder as the background and aplys the colors to dwm 5 | 6 | ![Screenshot](https://github.com/BogdanTheGeek/dwm-primcol/blob/master/screenshots/1.png "Screenshot 1") 7 | ![Screenshot](https://github.com/BogdanTheGeek/dwm-primcol/blob/master/screenshots/2.png "Screenshot 2") 8 | ![Screenshot](https://github.com/BogdanTheGeek/dwm-primcol/blob/master/screenshots/3.png "Screenshot 3") 9 | ![Screenshot](https://github.com/BogdanTheGeek/dwm-primcol/blob/master/screenshots/4.png "Screenshot 4") 10 | 11 | 12 | ## Dependencies/Requirements 13 | 14 | imagemagick 15 | 16 | You should launch dwm from the source code folder and not install it, otherwise the script requires super user privileges. 17 | 18 | feh / xwallpaper for setting the wallpaper 19 | 20 | ## Installation 21 | 22 | Copy the repository anywhere on your computer :) 23 | Make sure all the files without an extension have execution rights(`chmod +x ...`) 24 | 25 | ## How it works 26 | 27 | 1. Run `./extprimcol ` to extract the 5 most dominant colours in all of your wallpapers and store those files in myprimarycolours.txt 28 | 2. Edit setdwmcol and change the dwm variable to the location of your dwm source code (make a backup just in case). 29 | 3. (OPTIONAL) Compile `rgb2hsl.c` if you have to, idk.(`gcc rgb2hsl.c -o rgb2hsl`) 30 | 4. Run `./setdwmcol ` and hope for the best (be wary, this also closes dwm, so that the changes can be applied. So save all of your work before executing the script or comment the `killall dwm` line in `setdwmcol` and restart manually) 31 | 32 | You can now launch setdwmcol from a keyboard shortcut. 33 | 34 | Every time you add a new wallpaper, you must run extprimcol, but it doesn't have to redo the wallpapers already in the file so thats ok. 35 | 36 | ## Bugs 37 | 38 | 1. Primary colours are not removed from myprimarycolours.txt if a wallpaper is removed from the wallpapers folder. 39 | -------------------------------------------------------------------------------- /chwall: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | image="$(find $1 -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -type f | shuf -n 1 )" 4 | 5 | case $DESKTOP_SESSION in 6 | #gnome 7 | gnome*) gsettings set org.gnome.desktop.background picture-uri file://$image;; 8 | #normal xorg 9 | *) ls /usr/bin/ | grep feh 10 | if [ $? -eq 0 ]; then 11 | feh --bg-fill "$image" 12 | else [ $? -eq 1 ] 13 | xwallpaper --zoom "$image" 14 | fi;; 15 | esac 16 | 17 | echo $image 18 | notify-send $(echo $image | sed 's/.*\///g') 19 | -------------------------------------------------------------------------------- /extprimcol: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | find "$1" -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -type f | 4 | 5 | while read -r line ; do 6 | if [ -z $(grep "$line" "$1/myprimarycolours.txt") ]; then 7 | echo "Analysing : $(echo $line | sed 's/.*\///g')" && 8 | convert "$line" +dither -colors 5 temp.png && 9 | identify -verbose temp.png | 10 | grep ' [0-9]: ' | 11 | awk '{print substr($3, 1,7)}'| 12 | tr -d '\n' | 13 | rev | cut -b 8- | rev | 14 | xargs -I{} echo "'$line\'{}" >> $1/myprimarycolours.txt 15 | fi 16 | done 17 | 18 | rm temp.png 19 | 20 | -------------------------------------------------------------------------------- /rgb2hsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogdanTheGeek/dwm-primcol/b88ad8dfd639df45a6d8e742117c7b8b13b9ee0f/rgb2hsl -------------------------------------------------------------------------------- /rgb2hsl.c: -------------------------------------------------------------------------------- 1 | #include"stdlib.h" 2 | #include"stdio.h" 3 | 4 | 5 | float Min( float fR, float fG, float fB ); 6 | float Max( float fR, float fG, float fB); 7 | 8 | void RGBToHSL( int R, int G, int B, int* h, int* s, int* l ); 9 | 10 | 11 | int main(int argc, char *argv[]){ 12 | 13 | int r, g, b, h, s, l; 14 | 15 | if(argc < 2) { 16 | printf("Please input RGB hex code in this format : XXXXXX\n"); 17 | return 1; 18 | } 19 | 20 | for(int i = 1; i> 16) & 0x0000FF; 25 | g = (rgb >> 8) & 0x0000FF; 26 | b = rgb & 0x0000FF; 27 | 28 | RGBToHSL(r, g, b, &h, &s, &l); 29 | 30 | // printf("%d %d %d\n", h, s, l); 31 | printf("%d %s\n", s + (int)(l*0.7), hexrgb ); 32 | } 33 | 34 | return 0; 35 | } 36 | 37 | 38 | float Min( float fR, float fG, float fB ){ 39 | float fMin = fR; 40 | 41 | if (fG < fMin){ 42 | fMin = fG; 43 | } 44 | if (fB < fMin){ 45 | fMin = fB; 46 | } 47 | return fMin; 48 | } 49 | 50 | 51 | float Max( float fR, float fG, float fB){ 52 | float fMax = fR; 53 | 54 | if (fG > fMax){ 55 | fMax = fG; 56 | } 57 | if (fB > fMax){ 58 | fMax = fB; 59 | } 60 | return fMax; 61 | } 62 | 63 | void RGBToHSL( int R, int G, int B, int* h, int* s, int* l ){ 64 | int H = *h; 65 | int S = *s; 66 | int L = *l; 67 | 68 | float fR = R / 255.0; 69 | float fG = G / 255.0; 70 | float fB = B / 255.0; 71 | 72 | float fCMin = Min(fR, fG, fB); 73 | float fCMax = Max(fR, fG, fB); 74 | 75 | L = 50 * (fCMin + fCMax); 76 | 77 | if (fCMin == fCMax){ 78 | S = 0; 79 | H = 0; 80 | 81 | *s = S; 82 | *h = H; 83 | *l = L; 84 | 85 | return ; 86 | } 87 | else if (L < 50){ 88 | S = 100 * (fCMax - fCMin) / (fCMax + fCMin); 89 | } 90 | else{ 91 | S = 100 * (fCMax - fCMin) / (2.0 - fCMax - fCMin); 92 | } 93 | 94 | if (fCMax == fR){ 95 | H = 60 * (fG - fB) / (fCMax - fCMin); 96 | } 97 | if (fCMax == fG){ 98 | H = 60 * (fB - fR) / (fCMax - fCMin) + 120; 99 | } 100 | if (fCMax == fB){ 101 | H = 60 * (fR - fG) / (fCMax - fCMin) + 240; 102 | } 103 | if (H < 0){ 104 | H = H + 360; 105 | } 106 | *h = H; 107 | *s = S; 108 | *l = L; 109 | 110 | } 111 | -------------------------------------------------------------------------------- /screenshots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogdanTheGeek/dwm-primcol/b88ad8dfd639df45a6d8e742117c7b8b13b9ee0f/screenshots/1.png -------------------------------------------------------------------------------- /screenshots/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogdanTheGeek/dwm-primcol/b88ad8dfd639df45a6d8e742117c7b8b13b9ee0f/screenshots/2.png -------------------------------------------------------------------------------- /screenshots/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogdanTheGeek/dwm-primcol/b88ad8dfd639df45a6d8e742117c7b8b13b9ee0f/screenshots/3.png -------------------------------------------------------------------------------- /screenshots/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BogdanTheGeek/dwm-primcol/b88ad8dfd639df45a6d8e742117c7b8b13b9ee0f/screenshots/4.png -------------------------------------------------------------------------------- /setdwmcol: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | dwm='.tools/dwm' 4 | 5 | backgound=$(./chwall $1) 6 | 7 | 8 | field=$(grep "$backgound" "$1"/myprimarycolours.txt) 9 | 10 | colours="$(echo $field | awk 'BEGIN {FS ="#"};{print $2 " " $3 " " $4 " " $5 " " $6}' | xargs $PWD/rgb2hsl | sort -rn | awk '{print $2}' | tr '\n' ' ')'\n'" 11 | 12 | 13 | colour1=$( echo $colours | awk '{print $1}' ) 14 | colour2=$( echo $colours | awk '{print $2}' ) 15 | colour3=$( echo $colours | awk '{print $3}' ) 16 | colour4=$( echo $colours | awk '{print $4}' ) 17 | colour5=$( echo $colours | awk '{print $5}' ) 18 | 19 | 20 | sed -i "s/col_gray1\[\].*/col_gray1\[\] = \"#$colour1\";/" "$dwm/config.h" 21 | sed -i "s/col_gray2\[\].*/col_gray2\[\] = \"#$colour2\";/" "$dwm/config.h" 22 | sed -i "s/col_gray3\[\].*/col_gray3\[\] = \"#$colour3\";/" "$dwm/config.h" 23 | sed -i "s/col_gray4\[\].*/col_gray4\[\] = \"#$colour4\";/" "$dwm/config.h" 24 | sed -i "s/col_cyan\[\].*/col_cyan\[\] = \"#$colour5\";/" "$dwm/config.h" 25 | 26 | cd $dwm && 27 | make && 28 | killall dwm 29 | --------------------------------------------------------------------------------