You are not logged in.

#1 2016-05-19 08:13:08

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Xappspicker, adjust Xapps background and foreground by clicking

I made up a stupid little script from snippets mainly from the BBQLinux forums, to adjust the look of some xapps (xfontsel, xman , xpaint etc) according the current GTK theme.

What does it do ?
It grabs the bg and fg colors from the current theme, and set them as back or freground for the Xapps.
(they can be customized only by Xresources)
In the case your theme gtkrc contains a properly set up color-scheme on-liner, then the script grabs the colors.
When not, then opens the gtkrc file in the default text editor, and prompts you to look for it, and put in manually.
It offers also a choice to pick your colors you like.

Here is the srciptie :

http://pastebin.com/udDhCWNf

Install it in your path.
Then adjust your Xresources. Remove or comment out any back-, or foreground values by putting a "!" for the line.
And add this line at the bottom :
#include </home/user/.xapps-col>

Then run in the terminal :
touch ~/.xapps-col

Dependencies : yad, and colr

colr is a simple sript showing you the hex color codes of your xcolors by color names.
( Wery useful, for example when you run f.e. dzen or lemonbar you can define the colors by colr, according to your xcolors in use )

Colr:

http://pastebin.com/Yh2bbs0N

Have fun, Viel Spaß :-)

Offline

#2 2016-05-19 20:09:48

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Xappspicker, adjust Xapps background and foreground by clicking

update: from now on, please get my version of the script from here.

Nice!

I made some adjustments:
removed redundancy, and added a non-interactive mode: then it simply tries the grepcol function, and if both foreground and background color haven't been determined succesfully, it just exits without changing anything.
that way you can use the script in your autostart.

#!/bin/bash

colorfile="$HOME/.xapps-col"

# set editor only if it is not set yet
: ${GUI_EDITOR=/usr/bin/geany}

picker ()
{
echo "Pick background color"
#~ back=$(yad --color --title "Choose background color")
back=$(grabc 2>/dev/null)

echo "Pick foreground color"
#~ forg=$(yad --color --title "Choose foreground color")
forg=$(grabc 2>/dev/null)
}


adjust ()
{
##backgr
printf "XCalc.ti.Command.background: $back
"   >> "$colorfile"
printf "XCal*background: $back
" >> "$colorfile"
printf "XFontSel*background:  $back
"   >> "$colorfile"
printf "display.background:  $back
"   >> "$colorfile"
printf "Xman*background:  $back
"   >> "$colorfile"
printf "xpdf*background:  $back
"   >> "$colorfile"
printf "xpdf*matteColor:  $back
"   >> "$colorfile"
printf "*background:  $back
"   >> "$colorfile"
##forg
printf "XCalc.ti.Command.foreground:  $forg
" >> "$colorfile"
printf "XCal*foreground: $forg 
" >> "$colorfile"
printf "Xman*foreground: $forg 
" >> "$colorfile"
printf "XFontSel*foreground: $forg 
" >> "$colorfile"
printf "display.foreground: $forg 
" >> "$colorfile"
printf "xpdf*foreground: $forg 
" >> "$colorfile"
printf "*foreground: $forg 
" >> "$colorfile"
}

grepcol ()
{
### GTK2_CURRENT_THEME is probably already part of the env (at least on my systems)
### https://stackoverflow.com/a/11686912
: ${GTK2_CURRENT_THEME=$(/usr/bin/grep gtk-theme-name $GTK2_RC_FILES|cut -d\" -f2)}

if [ ! -f  ~/.themes/$GTK2_CURRENT_THEME/gtk-2.0/gtkrc ]
then 
       path=/usr/share/themes/$GTK2_CURRENT_THEME/gtk-2.0/gtkrc
       col_bg=$(grep scheme "$path" | head -n1 | awk -Fnbg_color: '/#/ {print $2}' | head -c 7)
       col_fg=$(grep scheme "$path" | head -n1 | awk -Ffg_color: '/#/ {print $2}' | head -c 7)  
       echo $path
else
       path=~/.themes/$GTK2_CURRENT_THEME/gtk-2.0/gtkrc
       col_bg=$(grep scheme "$path" | head -n1 | awk -Fnbg_color: '/#/ {print $2}' | head -c 7) 
       col_fg=$(grep scheme "$path" | head -n1 | awk -Ffg_color: '/#/ {print $2}' | head -c 7)  
       echo $path
fi

echo $col_bg
echo $col_fg

if [[ -z $col_bg || -z $col_fg ]]; then
       if [[ -t "0" || -p /dev/stdin ]]
       # are we running this interactively? see tldp.org/LDP/abs/html/intandnonint.html
       then
              echo 'One or more colors are undefined, please set manually'
              $GUI_EDITOR $path &
              echo "Please enter background color : "
              read col_bg
              echo "You entered: $col_bg"
              echo "Please enter foreground color : "
              read col_fg
              echo "You entered: $col_fg"
       else
              exit 1
       fi
fi

back=$col_bg
forg=$col_fg
}

grepx ()
{
back=#$(colr bg)
echo $back
forg=#$(colr fg)
echo $forg
}

if [[ -t "0" || -p /dev/stdin ]]
# are we running this interactively? see tldp.org/LDP/abs/html/intandnonint.html
then
       read -n 1 -p "Do you want to adjust the Xapp's look manually (y) , or apply GTK-colors (n) , or add the Xcolors (x) ? (y/n/x)? " choice
       case "$choice" in 
         y|Y) picker
              rm -f "$colorfile"
              echo "Added the colors of your choice" 
              ;;
         n|N) grepcol
              rm -f "$colorfile" 
              echo "Added colors from $path" 
              ;;
         x|X) grepx
              rm -f "$colorfile" 
              echo "added Xcolors"
              ;;
         * )  echo "Aborted."
              exit 1
              ;;
       esac
else
       grepcol
       rm -f "$colorfile"
fi

adjust
xrdb -merge "$colorfile"

when you use "xrdb -merge" you don't even have to comment out the according values in ~/.Xresources.

I also use some selfmade environment variables in my ~/.bash_profile. the script only tries to define them if they're not set.

PS:
any licensing issues? if i continue to work on this i might want to put it up on github.

Last edited by ohnonot (2018-06-21 23:20:20)

Offline

#3 2016-05-20 06:32:17

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: Xappspicker, adjust Xapps background and foreground by clicking

I am glad you like it. I don't want to license it, it so crappy....and as mentioned it is just a collection of snippets. Feel free to use it, share it on the GitHub; you have already cleaned up the code heavily. Thnx, and enjoy.

P.s.
Some questions :
Why should you use it at start ? If the Xresources values are set they load automatically at start up.
I use the script by changing themes for setting a homogeneous color environment.

Last edited by Head_on_a_Stick (2016-05-20 06:59:12)

Offline

#4 2016-05-20 07:40:12

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Xappspicker, adjust Xapps background and foreground by clicking

Where do   you get the 'colr' command from?

/h/m/t/t/quicktests ./t20
Do you want to adjust the Xapp's look manually (y) , or apply GTK-colors (n) , or add the Xcolors (x) ? (y/n/x)? x./t20: line 101: colr: command not found
#
./t20: line 103: colr: command not found
#

Offline

#5 2016-05-20 07:42:44

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Xappspicker, adjust Xapps background and foreground by clicking

Never mind.

It is in the OP. Sorry for the noise.

Offline

#6 2016-05-20 08:06:42

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Xappspicker, adjust Xapps background and foreground by clicking

 /h/m/t/t/quicktests  ./t20
Do you want to adjust the Xapp's look manually (y) , or apply GTK-colors (n) , or add the Xcolors (x) ? (y/n/x)? x#170F0D
/home/me/bin/colr: 41: printf: usage: printf format [arg ...]
#
added Xcolors

in script 'colr':
There should be a test for $(...) returning a non-empty value or else the printf statement fails.

Offline

#7 2016-05-20 11:35:49

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: Xappspicker, adjust Xapps background and foreground by clicking

xaos52 wrote:
 /h/m/t/t/quicktests  ./t20
Do you want to adjust the Xapp's look manually (y) , or apply GTK-colors (n) , or add the Xcolors (x) ? (y/n/x)? x#170F0D
/home/me/bin/colr: 41: printf: usage: printf format [arg ...]
#
added Xcolors

in script 'colr':
There should be a test for $(...) returning a non-empty value or else the printf statement fails.

Sorry I could not reproduce this. But as far as I know this kind of xrdb-query never has an empty output. Xcolor are always set, when not by the user then defaults to the hard coded values.

Offline

#8 2016-05-20 12:10:53

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Xappspicker, adjust Xapps background and foreground by clicking

Oh yes. It is perfectly possible to have this in $HOME/.Xresources:

!!---------------------------------
!! File         : $HOME/.Xresources
!! Description  : X resources file
!! Author       : Thiam H Lee
!! Last Updated : 04 May 2011
!!---------------------------------

!!----------------
!! GLOBAL SETTINGS
!!----------------

!!--------------------------------------------------------
!! XFT SETTINGS (for using truetype fonts in the terminal)
!!--------------------------------------------------------

!! Xft*dpi:                        96
Xft*antialias:                  true
Xft*hinting:                    true
Xft*hintstyle:                  hintfull
Xft*rgba:                       rgb
Xft*lcdfilter: 			lcddefault
!!---------------
!! XTERM SETTINGS
!!---------------

!!-- The 'xterm-256color' terminal definition is in the ncurses-term package on
!!-- Debian-based distributions
!!-- This lets programs know that this xterm supports 256 colors, which is
!!-- compiled into xterms of most distributions
!!-- If compiling xterm oneself, specify the '--enable-256-color' flag when
!!-- running configure
*xterm*termName:                xterm-256color
! *xterm*pointerMode:             2
! *xterm*scrollBar:               false
! *xterm*saveLines:               8192
! *xterm*rightScrollBar:          false
! *xterm*bellIsUrgent:            true

!!-- Fix alt key input
! *xterm*altIsNotMeta:            true
! *xterm*altSendsEscape:          true

!!-- Locale and UTF-8
*xterm*locale:                  true
! *xterm*utf8Title:               true

!!-- Prevent idle wakeups due to XTerm checking for session management events
!!-- This reduces power draw
! *xterm*sessionMgt:              false

!!-- Fonts
!!-- Choose one of the following sets, depending on CJK (East Asian Language)
!!-- font requirements
!!-- Set 1 : Smaller fonts (worse CJK character support, more space efficient)
!!-- The terminus fonts used here are in the xfonts-terminus package on
!!-- Debian-based distributions. Run 'xfontsel' to see available xfonts
! *xterm*font:                    -*-terminus-medium-*-*-*-14-*-*-*-*-*-*-*
! *xterm*boldFont:                -*-terminus-bold-*-*-*-14-*-*-*-*-*-*-*
! *xterm*italicFont:              -*-terminus-medium-*-*-*-14-*-*-*-*-*-*-*
! *xterm*boldItalicFont:          -*-terminus-bold-*-*-*-14-*-*-*-*-*-*-*
! *xterm*wideFont:                -misc-fixed-medium-r-normal-ja-13-125-75-75-c-120-iso10646-1
! *xterm*wideBoldFont:            -misc-fixed-bold-r-normal-ja-13-125-75-75-c-120-iso10646-1
!!-- Set 2 : Larger fonts (better CJK character support, less space efficient)
! *xterm*font:                    -Misc-Fixed-Medium-R-Normal--18-120-100-100-C-90-ISO10646-1
! *xterm*wideFont:                -Misc-Fixed-Medium-R-Normal-ja-18-120-100-100-C-180-ISO10646-1

!!-- Colors
!!-- Tango Color Scheme
!!-- See http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines
!!-- Foreground and background are set to different colors
! *xterm*background:              #000000
! *xterm*foreground:              #babdb6
! *xterm*cursorColor:             #729fcf
! *xterm*pointerColorBackground:  #2e3436
! *xterm*pointerColorForeground:  #eeeeec
! *xterm*color0:                  #2e3436
! *xterm*color1:                  #cc0000
! *xterm*color2:                  #4e9a06
! *xterm*color3:                  #c4a000
! *xterm*color4:                  #3465a4
! *xterm*color5:                  #75507b
! *xterm*color6:                  #06989a
! *xterm*color7:                  #d3d7cf
! *xterm*color8:                  #555753
! *xterm*color9:                  #ef2929
! *xterm*color10:                 #8ae234
! *xterm*color11:                 #fce94f
! *xterm*color12:                 #729fcf
! *xterm*color13:                 #ad7fa8
! *xterm*color14:                 #34e2e2
! *xterm*color15:                 #eeeeec


xterm*font:                       terminus-12
xterm*boldFont:                   terminus-12
xterm*loginShell:                 true
xterm*vt100*geometry:             80x50
xterm*saveLines:                  8192
xterm*charClass:                  33:48,35:48,37:48,43:48,45-47:48,64:48,95:48,126:48
xterm*termName:                   xterm-256color
xterm*eightBitInput:              false
! xterm*foreground:                 rgb:a8/a8/a8
! xterm*background:                 rgb:30/30/30
! xterm*color0:                     rgb:00/00/00
! xterm*color1:                     rgb:a8/00/00
! xterm*color2:                     rgb:00/a8/00
! xterm*color3:                     rgb:a8/54/00
! xterm*color4:                     rgb:00/00/c8
! xterm*color5:                     rgb:a8/00/a8
! xterm*color6:                     rgb:00/a8/a8
! xterm*color7:                     rgb:a8/a8/a8
! xterm*color8:                     rgb:54/54/54
! xterm*color9:                     rgb:fc/54/54
! xterm*color10:                    rgb:54/fc/54
! xterm*color11:                    rgb:fc/fc/54
! xterm*color12:                    rgb:54/54/fc
! xterm*color13:                    rgb:fc/54/fc
! xterm*color14:                    rgb:54/fc/fc
! xterm*color15:                    rgb:fc/fc/fc
!black
! xterm*color0:                     #111111
! xterm*color8:                     #090909
!red
! xterm*color1:                     #5A5A5A
! xterm*color9:                     #636363
!green
! xterm*color2:                     #91BA0D
! xterm*color10:                    #AADB0F
!yellow
! xterm*color3:                     #969696
! xterm*color11:                    #969696
!blue
! xterm*color4:                     #D0D0D0
! xterm*color12:                    #F0F0F0
!magenta
! xterm*color5:                     #717171
! xterm*color13:                    #818181
!cyan
! xterm*color6:                     #818181
! xterm*color14:                    #A1A1A1
!white
! xterm*color7:                     #303030
! xterm*color15:                    #202020

xterm*boldMode:                   true
xterm*colorBDMode:                false
xterm*colorBD:                    rgb:fc/fc/fc
*xterm*pointerColorBackground:    #2e3436
*xterm*pointerColorForeground:    #eeeeec
*xterm*hold:                      true
XTerm*utf8:                       1

! #define t_bg_floor     #010000
! #define t_bg_dip       #3F3E3B
! #define t_background   #464542
! #define t_bg_bump      #545350
! #define t_fg_comment   #96969A
! #define t_foreground   #BEBFC2
! #define t_fg_highlight #CFCFD3
! #define t_fg_ceiling   #FEFFFF

! xterm.background: t_background
! xterm.foreground: t_foreground

! xterm.colorBD: t_fg_highlight
! xterm.colorIT: t_fg_highlight
! xterm.colorUL: t_fg_highlight

! xterm.cursorColor: #E7ACDF

! ! BLK
! xterm.color0: t_bg_bump
! xterm.color8: t_fg_comment

! ! WHT
! xterm.color7: t_fg_highlight
! xterm.color15: t_fg_ceiling

! ! RED
! xterm.color1: #CC827B
! xterm.color9: #FFBBB3

! ! YEL
! xterm.color3: #A5955B
! xterm.color11: #E0CE91

! ! GRN
! xterm.color2: #67A477
! xterm.color10: #9EDEAE

! ! CYN
! xterm.color6: #38A6B2
! xterm.color14: #79E0ED

! ! BLU
! xterm.color4: #7998D1
! xterm.color12: #B3D1FF

! ! MAG
! xterm.color5: #BD84B6
! xterm.color13: #F9BDF0

!!----------------------
!! RXVT-UNICODE SETTINGS
!!----------------------

URxvt*termName:                 rxvt-unicode
URxvt*saveLines:                8192
URxvt*scrollBar:                false
URxvt*scrollBar_right:          false
URxvt*urgentOnBell:             true
URxvt*dynamicColors:            on
URxvt*font:                     terminus-12
URxvt*boldFont:                 terminus-12
!! DONE Sun Dec 29 14:53:55 CET 2013
!! setting utmpInhibit to true does not work for Debian urxvt which
!! is compiled with setgid utmp
! URxvt.utmpInhibit:              true

!!-- Fonts
!!-- The terminus fonts used here are in the xfonts-terminus package on
!!-- Debian-based distributions. Run 'xfontsel' to see available xfonts
! URxvt*font:                     -*-terminus-medium-*-*-*-14-*-*-*-*-*-*-*,-misc-fixed-medium-r-semicondensed-*-13-*-*-*-*-*-*-*
! URxvt*boldFont:                 -*-terminus-bold-*-*-*-14-*-*-*-*-*-*-*,-misc-fixed-bold-r-semicondensed-*-13-*-*-*-*-*-*-*
! URxvt*italicFont:               -*-terminus-medium-*-*-*-14-*-*-*-*-*-*-*,-misc-fixed-medium-o-semicondensed-*-13-*-*-*-*-*-*-*
! URxvt*boldItalicFont:           -*-terminus-bold-*-*-*-14-*-*-*-*-*-*-*,-misc-fixed-bold-o-semicondensed-*-13-*-*-*-*-*-*-*

!!-- Colors
!!-- Tango Color Scheme
!!-- See http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines
!!-- Foreground and background are set to different colors
! URxvt*background:               #303030
! URxvt*foreground:               #babdb6
! URxvt*cursorColor:              #729fcf
! URxvt*pointerColorBackground:   #2e3436
! URxvt*pointerColorForeground:   #eeeeec
! URxvt*color0:                   #2e3436
! URxvt*color1:                   #cc0000
! URxvt*color2:                   #4e9a06
! URxvt*color3:                   #c4a000
! URxvt*color4:                   #3465a4
! URxvt*color5:                   #75507b
! URxvt*color6:                   #06989a
! URxvt*color7:                   #d3d7cf
! URxvt*color8:                   #555753
! URxvt*color9:                   #ef2929
! URxvt*color10:                  #8ae234
! URxvt*color11:                  #fce94f
! URxvt*color12:                  #729fcf
! URxvt*color13:                  #ad7fa8
! URxvt*color14:                  #34e2e2
! URxvt*color15:                  #eeeeec

! Color scheme from gutterslob: http://crunchbang.org/forums/viewtopic.php?pid=271453#p271453

! URxvt*background:         #140C0B
! URxvt*foreground:         #877A70

!BLACK
! URxvt*color0:             #403F3E
! URxvt*color8:             #666362
!RED
! URxvt*color1:             #91444D
! URxvt*color9:             #C78186
!GREEN
! URxvt*color2:             #6B853D
! URxvt*color10:            #ABBD80
!YELLOW
! URxvt*color3:             #916949
! URxvt*color11:            #CCA88B
!BLUE
! URxvt*color4:             #557282
! URxvt*color12:            #8EABBD
!MAGENTA
! URxvt*color5:             #78516D
! URxvt*color13:            #A8879F
!CYAN
! URxvt*color6:             #58756C
! URxvt*color14:            #8CA8A2
!WHITE
! URxvt*color7:             #94928F
! URxvt*color15:            #CDCDCD




!!-- See 'man URxvtperl' for info about the URxvt internal perl interpreter
URxvt*perl-ext:                 default,matcher
! URxvt*matcher.button:           1
! URxvt*urlLauncher:              sensible-browser

! ================
! Emacs
! ================
Emacs.toolBar: off
Emacs.menuBar: off
Emacs.verticalScrollBars: off
Emacs.cursorColor: red
! Emacs.cursorColor: magenta
! Emacs.Foreground: wheat
! Emacs.Background: darkslategrey
! Emacs.menu.attributeForeground: wheat
! Emacs.menu.attributeBackground: darkslategrey
!Emacs.cursorColor: Darkgrey
! modeline
! Emacs.mode-line.attributeForeground: white
! Emacs.mode-line.attributeBackground: grey15
! Emacs.modeline.attributeForeground: white
! Emacs.modeline.attributeBackground: grey15
! selection
! Emacs.region.attributeBackground: lightblue
! Emacs.region.attributeForeground: darkslategrey
! Emacs.primary-selection.attributeBackground: blue
! Emacs.secondary-selection.attributeBackground: darkslateblue
! Emacs.show-paren-match-face.attributeBackground: Aquamarine
! Emacs.show-paren-match-face.attributeForeground: SlateBlue
! Emacs.show-paren-mismatch-face.attributeBackground: Red
! Emacs.show-paren-mismatch-face.attributeForeground: White
Emacs.title: emacs - the extensible editor
Emacs.font: terminus-8
! Emacs.font: terminus-12
! Emacs.font: Source Code Pro-10

! xscreensaver ---------------------------------------------------------------

! !font settings
! xscreensaver.Dialog.headingFont:        -*-Modd-bold-r-*-*-10-*-*-*-*-*-*-*
! xscreensaver.Dialog.bodyFont:           -*-Modd-medium-r-*-*-10-*-*-*-*-*-*-*
! xscreensaver.Dialog.labelFont:          -*-Modd-medium-r-*-*-10-*-*-*-*-*-*-*
! xscreensaver.Dialog.unameFont:          -*-Modd-medium-r-*-*-10-*-*-*-*-*-*-*
! xscreensaver.Dialog.buttonFont:         -*-Modd-bold-r-*-*-10-*-*-*-*-*-*-*
! xscreensaver.Dialog.dateFont:           -*-Modd-medium-r-*-*-10-*-*-*-*-*-*-*
! xscreensaver.passwd.passwdFont:         -*-Modd-bold-r-*-*-10-*-*-*-*-*-*-*
! !general dialog box (affects main hostname, username, password text)
! xscreensaver.Dialog.foreground:         #000000
! xscreensaver.Dialog.background:         #525252
! xscreensaver.Dialog.topShadowColor:     #333333
! xscreensaver.Dialog.bottomShadowColor:  #333333
! xscreensaver.Dialog.Button.foreground:  #000000
! xscreensaver.Dialog.Button.background:  #525252
! !username/password input box and date text colour
! xscreensaver.Dialog.text.foreground:    #000000
! xscreensaver.Dialog.text.background:    #525252
! xscreensaver.Dialog.internalBorderWidth:0
! xscreensaver.Dialog.borderWidth:        0
! xscreensaver.Dialog.shadowThickness:    1
! !timeout bar (background is actually determined by Dialog.text.background)
! xscreensaver.passwd.thermometer.foreground:  #272727
! xscreensaver.passwd.thermometer.background:  #525252
! xscreensaver.passwd.thermometer.width:       8
! !datestamp format--see the strftime(3) manual page for details
! xscreensaver.dateFormat:%A, %B %d


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Added by console_colors !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! autumnfence !!!!

xterm*background:   #170F0D
! ! xterm*background:   #D0D0D0

! xterm*foreground:    #746C48

! xterm*color0:           #343436
! xterm*color8:           #3C4537

! xterm*color1:           #473C37
! xterm*color9:           #544639

! xterm*color2:           #6A6E39
! xterm*color10:         #6C9242

! xterm*color3:           #6D533A
! xterm*color11:         #735E45

! xterm*color4:           #8F6F4A
! xterm*color12:         #99663A

! xterm*color5:           #A0883A
! xterm*color13:         #A97749

! xterm*color6:           #AD8F62
! xterm*color14:         #C47B40

! xterm*color7:           #CD9561
! xterm*color15:         #CFBDA4

! xterm*color25:         #CFBDA4

! xterm*cursor:          #FF0000
! xterm*mouse_background: #FF0000
! ! xterm*mouse_foreground: #0000FF
! xterm*highlight:       #00FF00
! xterm*border:          #FF0000

Then xrdb -query will  give

 /h/m/t/t/quicktests xrdb -query | grep -E '*foreground'
*foreground:	#
XCal*foreground:	#
XCalc.ti.Command.foreground:	#
XFontSel*foreground:	#
Xman*foreground:	#
display.foreground:	#
xpdf*foreground:	#

and function fg() in in colr will return the empty string,
which will cause the printf $(fg) to fail because there are no arguments to the printf call.

In my case:

 /h/m/t/t/quicktests ./t20
Do you want to adjust the Xapp's look manually (y) , or apply GTK-colors (n) , or add the Xcolors (x) ? (y/n/x)? x#170F0D
/home/me/bin/colr: 41: printf: usage: printf format [arg ...]
#
added Xcolors

and the generated file contains:

 /h/m/t/t/quicktests cat ~/.xapps-col 
XCalc.ti.Command.background: #170F0D
XCal*background: #170F0D
XFontSel*background:  #170F0D
display.background:  #170F0D
Xman*background:  #170F0D
xpdf*background:  #170F0D
xpdf*matteColor:  #170F0D
*background:  #170F0D
XCalc.ti.Command.foreground:  #
XCal*foreground: # 
Xman*foreground: # 
XFontSel*foreground: # 
display.foreground: # 
xpdf*foreground: # 
*foreground: # 
 

Offline

#9 2016-05-20 12:30:16

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: Xappspicker, adjust Xapps background and foreground by clicking

Hi Xaos, see this new version:

http://pastebin.com/eZXvyAnV

Test it please, I would like to know if it works for you.

Offline

#10 2016-05-21 04:51:03

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Xappspicker, adjust Xapps background and foreground by clicking

kleiner_hussar wrote:

Why should you use it at start?

so that gtk theme changes are automatically detected.
but you are right, it should be executed after the theme change.
in any case, i think it's good to habve a non-interactive version.
maybe a pipemenu version would be good too, one that returns a success/failure value.

Offline

#11 2016-05-23 06:39:08

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Xappspicker, adjust Xapps background and foreground by clicking

i added support for dmenu.
this is not really unix philosophy anymore (do one thing, and do it well), but meh.
the script is doing the work of extracting the colors from gtk themes once, why do it twice?

#!/bin/bash

#~ What does it do ?
#~ It grabs the bg and fg colors from the current theme, and set them as back or 
#~ foreground for the Xapps. (they can be customized only by Xresources)
#~ In the case your theme gtkrc contains a properly set up color-scheme on-liner,
#~ then the script grabs the colors. When not, then opens the gtkrc file in the
#~ default text editor, and prompts you to look for it, and put in manually.
#~ It offers also a choice to pick your colors you like.
#~ https://forums.bunsenlabs.org/viewtopic.php?id=1941

# since dmenu is not an Xapp, this is optional.
# set to empty string to disable.
dmenurc="$HOME/.config/dmenu/dmenurc"
#~ dmenurc=""

# font definitions in dmenu 4.6 are unclear to me. they also differ from
# suckless-tools 4.5 - one cannot pass xfont-strings.
# the one below should work on all systems, or at least fail silently.
dmenufont="terminus"

colorfile="$HOME/.local/share/xorg/xapps-col.xres"
#~ adjust your Xresources. Remove or comment out any back-, or foreground
#~ values by putting a "!" for the line. add this line at the bottom :
#~ #include </absolute/path/to/colorfile>

# set editor only if it is not set yet
: ${GUI_EDITOR=/usr/bin/geany}

picker ()
{
echo "Pick background color"
#~ back=$(yad --color --title "Choose background color")
back=$(grabc 2>/dev/null)

echo "Pick foreground color"
#~ forg=$(yad --color --title "Choose foreground color")
forg=$(grabc 2>/dev/null)
}

adjust ()
{
##backgr
#~ printf "XCalc.ti.Command.background: $back
#~ "   >> "$colorfile"
#~ printf "XCal*background: $back
#~ " >> "$colorfile"
#~ printf "XFontSel*background:  $back
#~ "   >> "$colorfile"
printf "display.background:  $back
"   >> "$colorfile"
printf "bitmap*background:  $back
"   >> "$colorfile"
printf "Xmag*background:  $back
"   >> "$colorfile"
printf "Xmag*helpLabel*background:  $forg
"   >> "$colorfile"
printf "Xman*background:  $back
"   >> "$colorfile"
printf "xpdf*background:  $back
"   >> "$colorfile"
printf "xpdf*matteColor:  $back
"   >> "$colorfile"
printf "xscreensaver*background:  $back
"   >> "$colorfile"
#~ printf "*background:  $back
#~ "   >> "$colorfile"
##forg
#~ printf "XCalc.ti.Command.foreground:  $forg
#~ " >> "$colorfile"
#~ printf "XCal*foreground: $forg 
#~ " >> "$colorfile"
#~ printf "XFontSel*foreground: $forg 
#~ " >> "$colorfile"
printf "display.foreground: $forg 
" >> "$colorfile"
printf "bitmap*foreground: $forg 
" >> "$colorfile"
printf "Xmag*foreground: $forg 
" >> "$colorfile"
printf "Xmag*helpLabel*foreground:  $back
"   >> "$colorfile"
printf "Xman*foreground: $forg 
" >> "$colorfile"
printf "xpdf*foreground: $forg 
" >> "$colorfile"
printf "xscreensaver*foreground: $forg 
" >> "$colorfile"
#~ printf "*foreground: $forg 
#~ " >> "$colorfile"
}

adjust_dmenu ()
{
       [ -n "$dmenufont" ] && echo -n "-fn $dmenufont " > "$dmenurc"
       echo "-nb $back -nf $forg -sb $forg -sf $back " >> "$dmenurc"
       echo "Created $dmenurc."
}

grepcol ()
{
### GTK2_CURRENT_THEME is probably already part of the env (at least on my systems)
### https://stackoverflow.com/a/11686912
: ${GTK2_CURRENT_THEME=$(/usr/bin/grep gtk-theme-name $GTK2_RC_FILES|cut -d\" -f2)}

#### then extract the colors

if [ ! -f  ~/.themes/$GTK2_CURRENT_THEME/gtk-2.0/gtkrc ]
then 
       path=/usr/share/themes/$GTK2_CURRENT_THEME/gtk-2.0/gtkrc
       col_bg=$(grep scheme "$path" | head -n1 | awk -Fnbg_color: '/#/ {print $2}' | head -c 7)
       col_fg=$(grep scheme "$path" | head -n1 | awk -Ffg_color: '/#/ {print $2}' | head -c 7)  
else
       path=~/.themes/$GTK2_CURRENT_THEME/gtk-2.0/gtkrc
       col_bg=$(grep scheme "$path" | head -n1 | awk -Fnbg_color: '/#/ {print $2}' | head -c 7) 
       col_fg=$(grep scheme "$path" | head -n1 | awk -Ffg_color: '/#/ {print $2}' | head -c 7)  
fi

echo $col_bg
echo $col_fg

if [[ -z $col_bg || -z $col_fg ]]; then
       if [[ -t "0" || -p /dev/stdin ]]
       # are we running this interactively? see tldp.org/LDP/abs/html/intandnonint.html
       then
              echo 'One or more colors are undefined, please set manually'
              $GUI_EDITOR $path &
              echo "Please enter background color : "
              read col_bg
              echo "You entered: $col_bg"
              echo "Please enter foreground color : "
              read col_fg
              echo "You entered: $col_fg"
       else
              exit 1
       fi
fi

back=$col_bg
forg=$col_fg
}

grepx ()
{
back=#$(colr bg)
echo $back
forg=#$(colr fg)
echo $forg
}

if [[ -t "0" || -p /dev/stdin ]]
# are we running this interactively? see tldp.org/LDP/abs/html/intandnonint.html
then
       echo -n "Do you want to adjust the Xapp's"
       [ -n "$dmenurc" ] && echo -n " and dmenu's"
       read -n 1 -p " look manually (y) , or apply GTK-colors (n) , or add the Xcolors (x) ? (y/n/x)? " choice
       echo
       case "$choice" in 
         y|Y) picker
              rm -f "$colorfile"
              echo "Adding the colors of your choice" 
              ;;
         n|N) grepcol
              rm -f "$colorfile" 
              echo "Adding colors from $path" 
              ;;
         x|X) grepx
              rm -f "$colorfile" 
              echo "Adding Xcolors"
              ;;
         * )  echo "Aborted."
              exit 1
              ;;
       esac
else
       grepcol
       rm -f "$colorfile"
fi

adjust
[ -n "$dmenurc" ] && adjust_dmenu
xrdb -merge "$colorfile"

and if you're wondering "Wait a minute, dmenu doesn't parse a config file?" - well, put this in your ~/bin, and it does:

#!/bin/dash

args=''
[ -f "$HOME/.config/dmenu/dmenurc" ] && args="$(cat "$HOME/.config/dmenu/dmenurc")"

exec /usr/bin/dmenu $args $@

Last edited by ohnonot (2021-07-03 10:32:38)

Offline

#12 2016-05-23 11:23:07

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: Xappspicker, adjust Xapps background and foreground by clicking

@ohnonot , it is amazing. But that is what I like in a Linux community, the one (without any coding knowledge) puts up some ideas, and the other ones brush it up, and make it even better.
Thnx mate, I feel glad you liked my little ideas.

Offline

#13 2016-06-04 16:09:58

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Xappspicker, adjust Xapps background and foreground by clicking

time and again i've been annoyed by the fact that i can't simply ask gtk to give me the current theme colors.

looking at the above script: grep'ing and sed'ing for "gtk_color_scheme" - it can fail in many ways, because gtk's config file format is fairly flexible!

the above script will fail for this:

gtk_color_scheme = "bg_color:#CFCFCF;fg_color:#404040"						# Window
gtk_color_scheme = "base_color:#F7F9FA;text_color:#404040"					# Base
gtk_color_scheme = "selected_bg_color:#8BAAD7;selected_fg_color:#F7F9FA"	# Selection
gtk_color_scheme = "tooltip_bg_color:#F5F5B5;tooltip_fg_color:#4D4D4D"		# Tooltip

or this:

# this is just a comment about color schemes

or this:

fg[NORMAL]        = "#323B23"
bg[NORMAL]         = "#E0E9D0"

(no scheme at all)

and all are valid syntax and working themes.

so, instead of messinfg around with sed & grep, i finally found how to do it with python.
i guess it would be more prudent to just rewrite the whole script, but since i'm no good with python i just added this snippet:

# fgbg array: fgbg[0] is foreground, fgbg[1] is background
fgbg=($(python2 -c 'import gtk
w = gtk.Window()
w.realize()
style=w.get_style()
print style.fg[gtk.STATE_NORMAL].to_string()
print style.bg[gtk.STATE_NORMAL].to_string()' 2>/dev/null))

and that takes care of it!
(source)

i've added lots of functionality, but it's fairly modular and it's easy to only use what you like.
the idea is to run it automatically on login, and subsequently manually if so desired.
i have completely dropped the interactive part of the script, because that python snippet is sufficiently reliable in itself (and if you look at the source, you will see that you can easily expand this to complete re-use all gtk colors).

Last edited by ohnonot (2021-07-03 10:30:14)

Offline

Board footer

Powered by FluxBB