[Project] Avant Window Navigator Colors

Tempat nongkrong. Diskusi bebas di luar topik.
User avatar
linuxers_cilik
Posts: 306
Joined: 24 Nov 2011, 22:45
Location: Medan, Indonesia

[Project] Avant Window Navigator Colors

Postby linuxers_cilik » 01 Jul 2012, 22:55

Assalamualaikum

Jadi saya akan mengadakan project tentang AWN dengan isi:
AWN akan berubah warna sesuai warna wallpaper atau tema gtk atau bisa dibilang chameleonic

nah alur logika-nya agar AWN bisa berubah warna yaitu mengubah konfigurasi warna panel AWN dengan "gconftool" memakai sebuah script
sebagai contoh, saya akan tunjukkan script dari tema gnome-shell elegance-colors

Code: Select all

#!/bin/bash
# Script to change the colors of Elegance Colors Gnome Shell theme
#
# Copyright (C) 2012  Satyajit sahoo
#
# Contains code for getting color from wallpaper by Matthew Richardson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

function read_config()
{
# Define default config first, can be overriden in the config file
mode="automatic"
color="rgb(75,141,249)"
config="$HOME/.elegance-colors.conf"
tempdir="$HOME/.elegance-colors"
installdir="/usr/share/elegance-colors"
# Source the config file if exists
if [ -f "$config" ]; then
source "$config"
fi
}

function init_files()
{
# If config doesn't exist, copy the default one
if [ ! -f "$config" ]; then
cp -f "$installdir/elegance-colors.conf" "$config"
fi
# Create the temporary directory
if [ ! -d "$tempdir" ]; then
mkdir -p "$tempdir"
fi
# If elegance-colors doesn't exist in ~./themes, create it
if [ ! -d "$HOME/.themes/elegance-colors" ]; then
make_theme
fi
}

function get_color()
{
if [ "$mode" = "automatic" ]; then
gtktheme=$(gsettings get org.gnome.desktop.interface gtk-theme)
themename=$(echo "$gtktheme" | sed "s/'//g")
theme=$(printf "${themename//%/\\x}")
   if [ -f "$HOME/.themes/$theme/gtk-3.0/gtk.css" ]; then
   themepath="$HOME/.themes/$theme"
   elif [ -f "/usr/share/themes/$theme/gtk-3.0/gtk.css" ]; then
   themepath="/usr/share/themes/$theme"
   fi
   c=`cat "$themepath/gtk-3.0/gtk.css" | grep "@define-color selected_bg_color #"`
   if [ -n "$c" ]; then
   # Get the selected_bg_color value from the gtk.css file
   color=$(cat "$themepath/gtk-3.0/gtk.css" | grep "@define-color selected_bg_color" | sed "s/@define-color selected_bg_color //g" | sed "s/;//g")
   fi
elif [ "$mode" = "wallpaper" ]; then
# Scale image to 2x2 and take the color from top-left
color=$(convert "$img" -alpha off -filter cubic -resize 2x2 -transparent black -format '%[pixel:s]' info:-)
fi
}

function make_theme()
{
# Get the color value
get_color
# Delete any old copies of theme
if [ -d "$HOME/.themes/elegance-colors" ]; then
rm -rf "$HOME/.themes/elegance-colors"
fi
# Copy Elegance Colors to create a new theme
if [ -d "$installdir/gnome-shell" ]; then
mkdir -p "$HOME/.themes/elegance-colors"
cp -r "$installdir/gnome-shell" "$HOME/.themes/elegance-colors/"
else
exit 1
fi
# Replace color values
sed -i "s/elegance-colors-custom/$color/g" "$HOME/.themes/elegance-colors/gnome-shell/gnome-shell.css"
}

function set_theme()
{
# Make the theme
make_theme
# Set the theme
gsettings set org.gnome.shell.extensions.user-theme name "elegance-colors"
}

function check_changes()
{
# Check if config has changed
md5conf="$tempdir/conf-md5"
md5c=`md5sum "$config"`
if [ -f "$md5conf" ]; then
oldmd5c=`cat "$md5conf"`
   if [ ! "$oldmd5c" = "$md5c" ]; then
   set_theme
   fi
fi
echo "$md5c" > "$md5conf"
# Check if the gtk theme or wallpaper have changed
if [ "$mode" = "automatic" ]; then
# Get the theme name
gtktheme=$(gsettings get org.gnome.desktop.interface gtk-theme)
# Check if it matches the previous value
gtkfile="$tempdir/gtk-theme-detect"
   if [ -f "$gtkfile" ]; then
   oldtheme=`cat "$gtkfile"`
      if [ ! "$oldtheme" = "$gtktheme" ]; then
      set_theme
      fi
   fi
echo "$gtktheme" > "$gtkfile"
elif [ "$mode" = "wallpaper" ]; then
# Get the background image path
path=$(gsettings get org.gnome.desktop.background picture-uri)
bg=$(echo "$path" | sed "s/'//g" | sed "s/file:\/\///g")
img=$(printf "${bg//%/\\x}")
# Check if it matches the previous value
md5bg="$tempdir/background-md5"
md5=`md5sum "$img"`
   if [ -f "$md5bg" ]; then
   oldmd5=`cat "$md5bg"`
      if [ ! "$oldmd5" = "$md5" ]; then
      set_theme
      fi
   fi
echo "$md5" > "$md5bg"
fi
}

function start_process()
{
while true; do
   # No need to run in background if Gnome Shell is not running
   if ( [ ! "$(pidof gnome-shell)" ] ); then
   exit 1
   fi
   # Read the config
   read_config
   # Initialize missing files
   init_files
   # Check if the current theme name matches elegance-colors
   s=$(gsettings get org.gnome.shell.extensions.user-theme name | grep -i "elegance-colors")
   if [ -n "$s" ]; then
      check_changes
   fi
   sleep 5
done
}

start_process


karna AWN memakai "gconftool" bukan "gsettings" maka akan ada beberapa bagian yang diubah dan ini skrip hasil kreasi saya yang belum selesai

Code: Select all

#!/bin/bash
# Contains code for getting color from wallpaper by Matthew Richardson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Get the background image path
path=$(gsettings get org.gnome.desktop.background picture-uri)
bg=$(echo "$path" | sed "s/'//g" | sed "s/file:\/\///g")
img=$(printf "${bg//%/\\x}")
# Get wallpaper color value
color=$(convert "$img" -alpha off -filter cubic -resize 2x2 -transparent black -format '%[pixel:s]' info:-)
fi
}
colorvalue=$(echo $color)
.............

lalu masalah yang terjadi dari skrip diatas adalah format nama warna yang akan dimasukkan dalam konfigurasi warna panel AWN adalah format "rgba(r,g,b,a)" bukan format "#RRRRGGGGBBBBAAAA"
(lihat di http://www.imagemagick.org/RMagick/doc/imusage.html)

setelah skrip jadi maka skrip diatas akan dijalankan dengan skrip berikut

Code: Select all

#!/bin/bash
nohup /usr/share/elegance-colors/elegance-colors  > /dev/null 2>&1 &


ayo berkontribusi dalam proyek ini
mana tahu bisa masuk sebagai paket pertama dalam ppa fui(kalo ada buat) :D :D :D
User avatar
ninja
Posts: 2260
Joined: 27 Jan 2010, 16:23
Location: Tangerang, Banten, indonesia
Contact:

Re: [Project] Avant Window Navigator Colors

Postby ninja » 02 Jul 2012, 00:00

linuxers_cilik wrote:Assalamualaikum

Jadi saya akan mengadakan project tentang AWN dengan isi:
AWN akan berubah warna sesuai warna wallpaper atau tema gtk atau bisa dibilang chameleonic

nah alur logika-nya agar AWN bisa berubah warna yaitu mengubah konfigurasi warna panel AWN dengan "gconftool" memakai sebuah script
sebagai contoh, saya akan tunjukkan script dari tema gnome-shell elegance-colors

Code: Select all

#!/bin/bash
# Script to change the colors of Elegance Colors Gnome Shell theme
#
# Copyright (C) 2012  Satyajit sahoo
#
# Contains code for getting color from wallpaper by Matthew Richardson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

function read_config()
{
# Define default config first, can be overriden in the config file
mode="automatic"
color="rgb(75,141,249)"
config="$HOME/.elegance-colors.conf"
tempdir="$HOME/.elegance-colors"
installdir="/usr/share/elegance-colors"
# Source the config file if exists
if [ -f "$config" ]; then
source "$config"
fi
}

function init_files()
{
# If config doesn't exist, copy the default one
if [ ! -f "$config" ]; then
cp -f "$installdir/elegance-colors.conf" "$config"
fi
# Create the temporary directory
if [ ! -d "$tempdir" ]; then
mkdir -p "$tempdir"
fi
# If elegance-colors doesn't exist in ~./themes, create it
if [ ! -d "$HOME/.themes/elegance-colors" ]; then
make_theme
fi
}

function get_color()
{
if [ "$mode" = "automatic" ]; then
gtktheme=$(gsettings get org.gnome.desktop.interface gtk-theme)
themename=$(echo "$gtktheme" | sed "s/'//g")
theme=$(printf "${themename//%/\\x}")
   if [ -f "$HOME/.themes/$theme/gtk-3.0/gtk.css" ]; then
   themepath="$HOME/.themes/$theme"
   elif [ -f "/usr/share/themes/$theme/gtk-3.0/gtk.css" ]; then
   themepath="/usr/share/themes/$theme"
   fi
   c=`cat "$themepath/gtk-3.0/gtk.css" | grep "@define-color selected_bg_color #"`
   if [ -n "$c" ]; then
   # Get the selected_bg_color value from the gtk.css file
   color=$(cat "$themepath/gtk-3.0/gtk.css" | grep "@define-color selected_bg_color" | sed "s/@define-color selected_bg_color //g" | sed "s/;//g")
   fi
elif [ "$mode" = "wallpaper" ]; then
# Scale image to 2x2 and take the color from top-left
color=$(convert "$img" -alpha off -filter cubic -resize 2x2 -transparent black -format '%[pixel:s]' info:-)
fi
}

function make_theme()
{
# Get the color value
get_color
# Delete any old copies of theme
if [ -d "$HOME/.themes/elegance-colors" ]; then
rm -rf "$HOME/.themes/elegance-colors"
fi
# Copy Elegance Colors to create a new theme
if [ -d "$installdir/gnome-shell" ]; then
mkdir -p "$HOME/.themes/elegance-colors"
cp -r "$installdir/gnome-shell" "$HOME/.themes/elegance-colors/"
else
exit 1
fi
# Replace color values
sed -i "s/elegance-colors-custom/$color/g" "$HOME/.themes/elegance-colors/gnome-shell/gnome-shell.css"
}

function set_theme()
{
# Make the theme
make_theme
# Set the theme
gsettings set org.gnome.shell.extensions.user-theme name "elegance-colors"
}

function check_changes()
{
# Check if config has changed
md5conf="$tempdir/conf-md5"
md5c=`md5sum "$config"`
if [ -f "$md5conf" ]; then
oldmd5c=`cat "$md5conf"`
   if [ ! "$oldmd5c" = "$md5c" ]; then
   set_theme
   fi
fi
echo "$md5c" > "$md5conf"
# Check if the gtk theme or wallpaper have changed
if [ "$mode" = "automatic" ]; then
# Get the theme name
gtktheme=$(gsettings get org.gnome.desktop.interface gtk-theme)
# Check if it matches the previous value
gtkfile="$tempdir/gtk-theme-detect"
   if [ -f "$gtkfile" ]; then
   oldtheme=`cat "$gtkfile"`
      if [ ! "$oldtheme" = "$gtktheme" ]; then
      set_theme
      fi
   fi
echo "$gtktheme" > "$gtkfile"
elif [ "$mode" = "wallpaper" ]; then
# Get the background image path
path=$(gsettings get org.gnome.desktop.background picture-uri)
bg=$(echo "$path" | sed "s/'//g" | sed "s/file:\/\///g")
img=$(printf "${bg//%/\\x}")
# Check if it matches the previous value
md5bg="$tempdir/background-md5"
md5=`md5sum "$img"`
   if [ -f "$md5bg" ]; then
   oldmd5=`cat "$md5bg"`
      if [ ! "$oldmd5" = "$md5" ]; then
      set_theme
      fi
   fi
echo "$md5" > "$md5bg"
fi
}

function start_process()
{
while true; do
   # No need to run in background if Gnome Shell is not running
   if ( [ ! "$(pidof gnome-shell)" ] ); then
   exit 1
   fi
   # Read the config
   read_config
   # Initialize missing files
   init_files
   # Check if the current theme name matches elegance-colors
   s=$(gsettings get org.gnome.shell.extensions.user-theme name | grep -i "elegance-colors")
   if [ -n "$s" ]; then
      check_changes
   fi
   sleep 5
done
}

start_process


karna AWN memakai "gconftool" bukan "gsettings" maka akan ada beberapa bagian yang diubah dan ini skrip hasil kreasi saya yang belum selesai

Code: Select all

#!/bin/bash
# Contains code for getting color from wallpaper by Matthew Richardson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Get the background image path
path=$(gsettings get org.gnome.desktop.background picture-uri)
bg=$(echo "$path" | sed "s/'//g" | sed "s/file:\/\///g")
img=$(printf "${bg//%/\\x}")
# Get wallpaper color value
color=$(convert "$img" -alpha off -filter cubic -resize 2x2 -transparent black -format '%[pixel:s]' info:-)
fi
}
colorvalue=$(echo $color)
.............

lalu masalah yang terjadi dari skrip diatas adalah format nama warna yang akan dimasukkan dalam konfigurasi warna panel AWN adalah format "rgba(r,g,b,a)" bukan format "#RRRRGGGGBBBBAAAA"
(lihat di http://www.imagemagick.org/RMagick/doc/imusage.html)

setelah skrip jadi maka skrip diatas akan dijalankan dengan skrip berikut

Code: Select all

#!/bin/bash
nohup /usr/share/elegance-colors/elegance-colors  > /dev/null 2>&1 &


ayo berkontribusi dalam proyek ini
mana tahu bisa masuk sebagai paket pertama dalam ppa fui(kalo ada buat) :D :D :D


subhanallah... mantap banget masbro proyeknya...
User avatar
linuxers_cilik
Posts: 306
Joined: 24 Nov 2011, 22:45
Location: Medan, Indonesia

Re: [Project] Avant Window Navigator Colors

Postby linuxers_cilik » 04 Jul 2012, 22:17

Cuma masalah output format nama warna. Jadi sedang mencari
yang pandai bermain Imagemagick. Kalau sudah jadi jadi, tinggal
dipaketkan.
User avatar
Malsasa
Posts: 2974
Joined: 07 Jun 2010, 22:37
Location: Mojokerto, Indonesia
Contact:

Re: [Project] Avant Window Navigator Colors

Postby Malsasa » 05 Jul 2012, 16:24

Subhanallah, saya ikut senang seperti kang ninja.

Return to “Pembicaraan Bebas”

Who is online

Users browsing this forum: Douglasluh and 23 guests