Welcome to the most active Linux Forum on the web.
Go Back > Blogs > linux-related notes
User Name


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Adding painting-friendly GUI functionalities to GIMP with questionable bash scripts and openbox configuration

Posted 03-06-2019 at 03:44 PM by the dsc
Updated 03-12-2019 at 01:26 AM by the dsc (minor improvement in logic)
Tags gimp

GIMP is much lighter than Krita on older hardware, but its GUI lacks some handy features, particularly when one's painting or drawing.
While MyPaint has some of those GUI features, it lacks some things like even basic transformations to selections.

These functionalities are the ability to use the stylus' "right click" (or whatever button it is) as a color picker, and handier/"exposed" buttons for undo, redo, mirroring view, de-selecting , resetting rotation, zooming in and out.

I managed to kind of add such tools with a wrap-around script that changes what the stylus button is set to depending on the active window is (it becomes control+button if it's GIMP, so for all intents and purposes it's like you have a click-only color picker), and creates a persistent YAD dialog that calls gimp-command scriptlets that are nothing but "wmxtrl -a GIMP && xdotool whatever-gimp-key-shortcut is set up".

Probably not the best way to set those things, but that's what I could come up with so far.


trap "kill -kill $gimpyadpid ; kill $$ " EXIT


gimp $@ & 


until xdotool getactivewindow getwindowname | grep "GIMP\|GNU Image" ; do
sleep 0.5

sleep 3

# NEW YAD METHOD: no need for individual scriptlets files or symlinks to a single file with different names
# YAD's fbtn can issue multiple commands within a larger "bash -c" command
# Apparently it should be possible with functions (still invoked through bash -c), but for some reason I couldn't do it.
# The advantage would be that it would be somewhat more readable.

yad --geometry=48x214+1030+425 --title=yadgimp --undecorated --no-buttons --form \
--field="!/usr/share/icons/breeze/actions/22/edit-undo.svg":fbtn 'bash -c "wmctrl -a GIMP && xdotool key Ctrl+z"' \
--field="!/usr/share/icons/breeze/actions/22/edit-redo.svg":fbtn 'bash -c "wmctrl -a GIMP && xdotool key Ctrl+y"' \
--field="!/usr/share/icons/ContrastHigh/22x22/actions/zoom-in.png":fbtn 'bash -c "wmctrl -a GIMP && xdotool key equal"' \
--field="!/usr/share/icons/ContrastHigh/22x22/actions/zoom-out.png":fbtn 'bash -c "wmctrl -a GIMP && xdotool key minus"' \
--field="!/usr/share/icons/Adwaita/scalable/status/rotation-allowed-symbolic.svg":fbtn 'bash -c "wmctrl -a GIMP && xdotool key 0"' \
--field="!/usr/share/icons/Adwaita/24x24/actions/object-flip-horizontal.png":fbtn 'bash -c "wmctrl -a GIMP && xdotool key m"' \
--field="!/usr/share/icons/breeze/actions/24/edit-select-none.svg":fbtn 'bash -c "wmctrl -a GIMP && xdotool key a"' &


while true ; do ## allows for quick color-picking, Mypaint-style

# Also "minimizes" yad toolbar with GIMP, kind of. It will actually minimize even if one GIMP sub-window
# that hasn't the words GIMP, Layers, Tool, or yadgimp is focused, so GIMP may well be full screen and it
# will disappear, but it will show up once the focus returns to any of the main windows. I wonder if that's 
# kind of awful if one doesn't have focus following the cursor, as I have.

#if xdotool getactivewindow getwindowname | grep "GIMP$\|Layers\|Tool\|yadgimp" > /dev/null  ; then
#	if ((xsetwlock==0)) ; then
#                wmctrl -r yadgimp -b remove,hidden
#		 xsetwacom set "Wacom Bamboo Pen stylus" Button 3 "key Control button 1" 
#		 xsetwlock=1 
#	fi
#	if ((xsetwlock==1)) ; then
#		wmctrl -r yadgimp -b add,hidden

#		xsetwacom set "Wacom Bamboo Pen stylus" Button 3 "button 3"
#		xsetwlock=0 
#	fi


# CHANGE IN APPROACH, preserving old version commented just in case the new method sucks
# case/esac mode seems like a better way to achieve higher window specificity than just a single grep/if/fi
# that way the normal right button for the stylus can be used on GIMP's non-painting windows, such as when
# one wants to merge layers and whatnot.

case "$window" in

    ((xsetwlock==0)) && xsetwacom set "Wacom Bamboo Pen stylus" Button 3 "key Control button 1" && xsetwlock=1
    wmctrl -r yadgimp -b remove,hidden
    ((xsetwlock==1)) && xsetwacom set "Wacom Bamboo Pen stylus" Button 3 "button 3" && xsetwlock=0
    # wmctrl -r yadgimp -b remove,hidden 
    # I guess those wmctrl lines are not needed besides on GIMP main window, sparing the CPU from useless work...
    ((xsetwlock==1)) && xsetwacom set "Wacom Bamboo Pen stylus" Button 3 "button 3" && xsetwlock=0
    #wmctrl -r yadgimp -b remove,hidden
    #wmctrl -r yadgimp -b remove,hidden
    # just does nothing, so to not minimize yadgimp
*) wmctrl -r yadgimp -b add,hidden

		xsetwacom set "Wacom Bamboo Pen stylus" Button 3 "button 3"

sleep 0.3 

 done &

wait $gimppid

kill -kill $gimpyadpid 

kill -kill $$

On my openbox' rc.xml I also have on the "applications" section:

        <application type="normal" name="gimp" class="Gimp" role="gimp-image-window-1">
  <application class="Gimp" name="gimp" role="gimp-scale-tool">
      <position force="yes">
    <application class="Gimp" name="gimp" role="gimp-rotate-tool">
      <position force="yes">
        <application class="Yad" name="yad" title="yadgimp" type="normal">
    <application role="gimp-toolbox-1">
    <application role="gimp-dock-1">
    <application role="gimp-dock-2">
        <application type="splash" class="Gimp.bin">
      <position force="yes">
I also have window focus following the mouse just hovering them, they'll also be raised accordingly.

That's the result:

My setup is also "faking" a single-window mode, with always-on-top undecorated subwindows, and an undecorated main window.That way you can have a new view of the same image floating around smaller, rather than having it tabbed or maybe on some kind of grid with a size that competes too much, whatever the real single-window mode does. Also, openbox skips having the sub-windows on the tint2 toolbar, so it's rather not that messy, very single-windowy.

There are limitations, such as the YAD toolbar not minimizing together with GIMP (achieved/mimicked with the newer updates), and also its functions not necessarily focusing GIMP if there's another competing "GIMP"-named window that wmctrl finds first.
I'm also not sure that the whole thing of the wrap-around script killing everything it generated is working (seems to be working), it's still very preliminary.
Posted in Uncategorized
Views 1428 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 03:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration