You are not logged in.

#201 2019-12-28 13:51:23

damo
....moderator....
Registered: 2015-08-20
Posts: 6,268

Re: The great yad hacking thread

Gute Besserung smile


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#202 2020-01-02 18:42:12

achim
Member
Registered: 2019-08-23
Posts: 35

Re: The great yad hacking thread

I changed the code under # 200 a bit and translated the important parts into English.

Greetings,

Achim

PS. @secureIT, please contact me via pm.

Last edited by achim (2020-01-02 18:46:26)

Offline

#203 2020-01-05 05:27:31

misko_2083
Member
Registered: 2016-05-24
Posts: 371

Re: The great yad hacking thread

https://www.youtube.com/watch?v=E8UeHo25N00
I was helping mxlinux devs with idesktool, a script to configure idesk for their Mxlinux Fluxbox respin.
Changed the script from using Xdialog, that depended on GTK+ 1.2 toolkit, to now use yad.
This version is working in bunsenlabs with yad 0.42 but not in MX.
They probably have an older version of yad.

/usr/local/bin/desktool

#!/bin/bash

#mx-mx-idesktool v1.0, released January 2020. 
#A script by the MX Linux Dev Team, user spidermouse and others to configure the idesk app. Based on mx-mx-idesktool v1.36 released August 2004 by John Murray john@jmurray.id.au


#First make sure yad is available
if ! hash yad > /dev/null ; then
    echo "ERROR: Yad not installed or not in path."
    exit
else
    echo "Yad found. So far so good.."
fi


#make sure idesk is available
if ! hash idesk > /dev/null ; then
    echo "ERROR: idesk not installed or not in path. Try http://sourceforge.net/projects/idesk/"
    exit
else
	echo "idesk found - we're on a roll :)"
fi

#make sure the .idesktop folder exists and if not make it now, so idesk can start
mkdir -p ~/.idesktop

#find out whether an argument was used

if [ "$#" -ne 1 ]; then
        argy=nope
else
        argy=yup
fi
argu="${1}"

#See what icons are available
#if [ -d /usr/share/idesk/icons/ ]; then
#        icondir=/usr/share/idesk/icons/
#else
icondir=/usr/share/icons/
#fi

DIALOG=yad

###############################################
############Declare some Functions#############
writeconf()
{
echo -e "table Config
  FontName: arial
  FontSize: 12
  FontColor: #ffffff
  Locked: false
  Transparency: 0
  Shadow: true
  ShadowColor: #000000
  ShadowX: 1
  ShadowY: 2
  Bold: false
  ClickDelay: 200
  IconSnap: false
  SnapWidth: 55
  SnapHeight: 100
  SnapOrigin: BottomRight
  SnapShadow: true
  SnapShadowTrans: 200
  CaptionOnHover: true
  CaptionPlacement: bottom
end
table Actions
  Lock: control left singleClk
  Reload: middle doubleClk
  Drag: right hold
  EndDrag: right singleClk
  Execute[0]: left singleClk
  Execute[1]: left doubleClk
end" > "${HOME}/.ideskrc"
}
################################################
################################################
newcaption()
{
new_caption="$($DIALOG --title "idesktool" \
                       --form --text="Icon Caption:\n(Leave blank for no caption)" \
                       --separator="" \
                       --button="Back":3 \
                       --button="Cancel":1 \
                       --button="Next":0 \
		       --field="Caption" "$cap" 2>/dev/null)"
retval=$?

case $retval in
        0) cap="${new_caption}"
           caption="$(echo "${new_caption}" | sed 's/\$/\\$/g')"
	   ;;
        3) if [ "$firstwindow" = "argynope" ]; then
                argynope
           else
                argyyep
           fi
	   ;;
        *) argynope
           ;;
esac

newcommands
}

##########################################################
##########################################################

newcommands()
{

#We replace troublesome characters with underscores so as to avoid problems writing the file
modcaption="$(echo "${caption}" | sed "s/[\ \$\/\*\&\|\?\^\"\']/_/g")"

#if the icon has no caption (ie. empty string) we need to make a unique filename for it,
#otherwise we just use the caption for the filename

if [ "${modcaption}" = "" ]; then
        modcaption="NoCaption$$"
fi

iconplaceholder="${icondir}"

#We replace troublesome characters with underscores using sed here, so as to avoid problems writing the file
modcaption=`echo $caption | sed "s/[\ \$\/\*\&\|\?\^\"\']/_/g"`

#if the icon has no caption (ie. empty string) we need to make a unique filename for it,
#otherwise we just use the caption for the filename
if [ "$modcaption" = "" ]; then
   modcaption="NoCaption$$"
fi

currentxvalue=400
currentyvalue=500

inputbox="$($DIALOG --form --separator="\n" --title "idesktool 1.36" \
                    --text="NOTE: The default right-click command \nruns this configuration tool (recommended)." \
                    --button="Back":3 --button="Cancel":1 --button="Next":0  \
                    --field="Left-Click Command:":LBL  "" \
                    --field="Right-Click Command:":LBL "" \
                    --field="Select png icon":LBL "" \
                    --field="X":LBL "" \
                    --field="Y":LBL "" \
                    --field="" "$command" \
                    --field="" "idesktool ${modcaption}.lnk" \
                    --field="":FL "${iconplaceholder}" \
                    --field="":NUM "${currentxvalue}" \
                    --field="":NUM "${currentyvalue}" \
                    --columns=2 --file-filter="png | *.png *.PNG" 
          )"
retval=$?

case $retval in
     0) command="$(echo "${inputbox}" | sed -n "6p")"
	rightclick="$(echo "${inputbox}"  | sed -n "7p")"
        icon="$(echo "${inputbox}"  | sed -n "8p")"
        currentxvalue="$(echo "${inputbox}"  | sed -n "9p")"
        currentyvalue="$(echo "${inputbox}"  | sed -n "10p")"
	;;
     3) if [ "$firstwindow" = "argyyep" ]; then
                argyyep
        else
                newcaption
	fi
        ;;
     *) argynope
        ;;
esac

iconvalidate

}

###########################################################
###########################################################

getcurrentvalues()
{

#get the caption
	currentcaption=`cat $currentlnkfile | grep "Caption:" | sed "s/Caption://" | sed "s/^[ \t]*//"`
#get the icon
	currenticon=`cat $currentlnkfile | grep "Icon:" | sed "s/Icon:\ //" | sed "s/^[ \t]*//"`
#get the left click command
	command=`cat $currentlnkfile | grep "Command\[0\]:" | sed "s/Command\[0\]:\ //" | sed "s/^[ \t]*//"`
#get the right click command
	currentrightclick=`cat $currentlnkfile | grep "Command\[1\]:" | sed "s/Command\[1\]:\ //" | sed "s/^[ \t]*//"`
#get the X value
	currentxvalue=`cat $currentlnkfile | grep "X:" | sed "s/X://" | sed "s/^[ \t]*//"`
#get the Y value
	currentyvalue=`cat $currentlnkfile | grep "Y:" | sed "s/Y://" | sed "s/^[ \t]*//"`

modifycaption

}

#################################################################
#################################################################

modifycaption()

{

inputbox="$($DIALOG --title "idesktool" \
                    --form --text="Icon Caption:\n(Leave blank for no caption)" --separator="" \
                    --button="Back":3 --button="Cancel":1 --button="Next":0 \
                    --field="Caption" "$currentcaption" )"
retval=$?

case $retval in
     0) cap="${inputbox}"
	caption="$(echo "${inputbox}" | sed 's/\$/\\$/g')"
	;;
     3) if [ "$firstwindow" = "argyyep" ]; then
                argyyep
        else
                getlnkfile
	fi
        ;;
     *) argynope
        ;;
esac

comefrom=modif

modifycommands

}

##############################################################
##############################################################

modifycommands()

{

if [ "$comefrom" = "modif" ]; then
        iconplaceholder="${currenticon}"
else
        iconplaceholder="${icondir}"
fi

#We replace troublesome characters with underscores using sed here, so as to avoid problems writing the file
modcaption=`echo $caption | sed "s/[\ \$\/\*\&\|\?\^\"\']/_/g"`

#if the icon has no caption (ie. empty string) we need to make a unique filename for it,
#otherwise we just use the caption for the filename
if [ "$modcaption" = "" ]; then
   modcaption="NoCaption$$"
fi

inputbox="$($DIALOG --form --separator="\n" --title "idesktool 1.36" \
                    --text="NOTE: The default right-click command \nruns this configuration tool (recommended)." \
                    --button="Back":3 --button="Cancel":1 --button="Next":0  \
                    --field="Left-Click Command:":LBL  "" \
                    --field="Right-Click Command:":LBL "" \
                    --field="Select png icon":LBL "" \
                    --field="X":LBL "" \
                    --field="Y":LBL "" \
                    --field="" "$command" \
                    --field="" "idesktool ${modcaption}.lnk" \
                    --field="":FL "${iconplaceholder}" \
                    --field="":NUM "${currentxvalue}" \
                    --field="":NUM "${currentyvalue}" \
                    --columns=2 --file-filter="png | *.png *.PNG" 
          )"
retval=$?

case $retval in
     0) command="$(echo "${inputbox}" | sed -n "6p")"
	rightclick="$(echo "${inputbox}"  | sed -n "7p")"
        icon="$(echo "${inputbox}"  | sed -n "8p")"
        currentxvalue="$(echo "${inputbox}"  | sed -n "9p")"
        currentyvalue="$(echo "${inputbox}"  | sed -n "10p")"
	;;
     3) if [ "$firstwindow" = "argyyep" ]; then
                argyyep
        else
                modifycaption
	fi
        ;;
     *) argynope
        ;;
esac

iconvalidate
}

###########################################################
###########################################################

iconvalidate()
{
if [ -e "${icon}" ]; then
        iconexists=yep
else
        $DIALOG --title "D'OH!" \
                --icon "./warning.xpm" \
                --text "Error: Icon Image File Not Found." \
                --button="Quit":1 \
                --button="Back":0
        case $? in
                0) if [ "${comefrom}" = "modif" ]; then
                             modifycommands
	           else
                             newcommands
                   fi
                   ;;
                *) argynope
                   ;;
        esac
fi

iconcheck="$(echo "${icon}" | grep -i "\.png")"

if [ "${iconcheck}" = "$icon" ]; then
        writefile
else
        $DIALOG --title "D'OH!" \
                --icon ./warning.xpm \
                --text "Error: Unknown Filetype. The icon should be be a png image."
        case $? in
                0) if [ "${comefrom}" = "modif" ]; then
                             modifycommands
	           else
                             newcommands
                   fi
                   ;;
                *) argynope
                   ;;
        esac
fi

}

###########################################################

deleteandrefresh()
{
rm -f "${currentlnkfile}"
killall idesk
exec idesk &
argynope
}

#############################################################
#############################################################

getlnkfile()
{

cd "${HOME}/.idesktop"
currentlnkfile="$($DIALOG --width 500 --height 500 \
                          --button="Back":3 --button="Cancel":1 --button="Next":0 \
                          --title "Please choose a file" \
                          --file-selection --file-filter="lnk | *.lnk")"
retval=$?

case $retval in
        0) fileselectedyet=yes
           filecheck="$(echo "${currentlnkfile}" | grep -i "\.lnk")"
           if [ "${filecheck}" = "${currentlnkfile}" ] && [ -e "${currentlnkfile}" ]; then
                  if [ "${choice}" = "Properties" ]; then
                          getcurrentvalues
                  else
                          deleteandrefresh
                  fi
           else
                  $DIALOG --title "D'OH!" \
                          --icon ./warning.xpm \
                          --text "Error: You need to select a valid file"
                  case $? in
                       0) fileselectedyet=no
                          getlnkfile
                          ;;
                       *) argynope
                          ;;
                  esac
           fi
           ;;
        3) argynope
           ;;
        *) argynope
           ;;
esac

}

##############################################################
##############################################################

refresh()
{
killall idesk
exec idesk &
argynope
}

###################################################################
###################################################################

writefile()
{

if [ "${choice}" = "Properties" ]; then
        rm -f "${currentlnkfile}"
else
        currentxvalue=400
        currentyvalue=500
fi

touch "${HOME}/.idesktop/${modcaption}.lnk"
echo "table Icon" > "${HOME}/.idesktop/${modcaption}.lnk"
echo "  Caption: ${caption}" | sed 's/.\$/\$/g' >> "${HOME}/.idesktop/${modcaption}.lnk"
echo "  Icon: ${icon}" >> "${HOME}/.idesktop/${modcaption}.lnk"
echo "  X: ${currentxvalue}" >> "${HOME}/.idesktop/${modcaption}.lnk"
echo "  Y: ${currentyvalue}" >> "${HOME}/.idesktop/${modcaption}.lnk"
echo "  Command[0]: ${command}" >> "${HOME}/.idesktop/${modcaption}.lnk"
echo "  Command[1]: ${rightclick}" >> "${HOME}/.idesktop/${modcaption}.lnk"
echo "end" >> "${HOME}/.idesktop/${modcaption}.lnk"

$DIALOG --no-buttons --width 500 --title "Finished!" \
        --text "All done. Restarting idesk now..." --timeout=3
refresh

}

####################################################################
####################################################################

argyyep()
{

firstwindow=argyyep

choice="$($DIALOG  --title  "idesktool" --width 500 --height 400 \
                   --list --select-action='bash -c "kill -s SIGUSR1 ${YAD_PID}"' \
                   --column "select" --column "description" \
                   --text "Desktop Icon Manager" \
                   --button="Quit":1 \
                "Properties" "View or Edit an Icon"  \
                "Delete" "Remove an Icon"  \
                "New" "Add a New Icon"  \
                "Refresh" "Reload the Desktop"  \
	        "Configure" "Edit iDesk's conf. file" \
                "Help" "Help" 2>/dev/null)"
retval=$?

choice="$(echo ${choice} | cut -d '|' -f1)"

case $retval in
        0) case ${choice} in
                Delete)	     deleteandrefresh
                ;;
                Properties)  getcurrentvalues      
                ;;
	        Refresh)     refresh
                ;;
	        New)         cap=""
                             command=""
	                     newcaption
                ;;
                Configure)   editconfig
                ;;
                Help)        mxdesktool_help
                ;;
           esac
           ;;
        *)      exit
                ;;
esac
}

##################################################################
###################################################################

argynope()
{

firstwindow=argynope

choice="$($DIALOG  --title  "idesktool" --width 500 --height 400 \
                   --list --select-action='bash -c "kill -s SIGUSR1 ${YAD_PID}"' \
                   --column "select" --column "description" \
                   --text "Desktop Icon Manager" \
                   --button="Quit":1 \
                "Properties" "View or Edit This Icon"  \
                "Delete" "Remove This Icon"  \
                "New" "Add a New Icon"  \
                "Refresh" "Reload the Desktop"  \
	        "Configure" "Edit iDesk's conf. file" \
                "Help" "Help" 2>/dev/null)"
retval=$?

choice="$(echo "${choice}" | cut -d '|' -f1)"

#echo $retval $choice

case $retval in
        0) case ${choice} in
                Delete)	     getlnkfile
                             deleteandrefresh
                ;;
                Properties)  getlnkfile
                ;;
	        Refresh)     refresh
                ;;
	        New)         cap=""
                             command=""
	                     newcaption
                ;;
                Configure)   editconfig
                ;;
                Help)        mxdesktool_help
                ;;
           esac
           ;;
        *)      exit
                ;;
esac
}

##########################################################
##########################################################
editconfig()
{
yad --title "iDesk Configuration" --width 500 --height 600  \
	--text-info --editable < <(cat "${HOME}/.ideskrc") 2>/dev/null > /tmp/editbox.txt.$$

case $? in
      0) cat "/tmp/editbox.txt.$$" > "${HOME}/.ideskrc"
         rm -f "/tmp/editbox.txt.$$"
         refresh
         argynope
         ;;
      *) rm -f "/tmp/editbox.txt.$$"
         argynope
         ;;
esac

}

##########################################################
##########################################################

mxdesktool_help()
{
     $DIALOG --title "idesktool" --text="Help or about this script GPL licence" --button="gtk-close":0 2>/dev/null
     if [ "${argy}" = "nope" ]; then
             argynope
     else
             argyyep
     fi
}

##########################################################
##########################################################

#now let's see whether the configuration files are present
if [ -e "${HOME}/.ideskrc" ]; then
        echo "Config. file  found - excellent!"
else
        $DIALOG --title "iDesk Configuration" \
                --text "WARNING: No ideskrc file was found.\nWould you like to have this file\nadded now?" \
                --button="No!gtk-no":1 --button="Yes!gtk-yes":0
case $? in
        0) writeconf
           $DIALOG --title "iDesk Configuration"\
                --button="No!gtk-no":1 --button="Yes!gtk-yes":0 \
                --text "\tThe configuration file has been written. \n
                Drag any icons you create to the
                desired locations and they will
                be remembered between sessions \n\n 
                Would you like to run the icon wizard now?" 2>/dev/null
           case $? in
                   0) argynope
                      ;;
                   *) exit
                      ;;
           esac
           ;;
        *) exit
           ;;
esac
fi

echo "$argy"
if [ "${argy}" = "nope" ]; then
        argynope
else
        currentlnkfile="${HOME}/.idesktop/${argu}"
        argyyep
fi

I think they use the idesk from AUR. https://aur.archlinux.org/packages/idesk/
There is also idesktool with Xdialog but that requires long atime ago deprecated stuff (GTK+ 1.2 and Xdialog). And that one crashed on Buster. https://aur.archlinux.org/packages/idesk-extras/

Last edited by misko_2083 (2020-01-05 05:41:29)


Што ни оштровиди ум сагледати не може - љубав превазилази.

Offline

#204 2020-03-24 01:18:11

misko_2083
Member
Registered: 2016-05-24
Posts: 371

Re: The great yad hacking thread

Conky mover:
requrements:  xdotool

#!/usr/bin/env bash

yad --text="Click 'Select Conky' to pick a conky.\n\nThen use the 'xwininfo' cursor on the chosen conky\nto record its position." \
     --button="Select Conky:0" --button="gtk-cancel:1"

if (( $? == 0 ));then
   conky="$(xwininfo)"
else
    echo "  Cancelled: exiting..."
    exit 0
fi

conky_xid="$(grep -m1 -Eow "0x[a-f0-9]+{7}" <<<"$conky")"
conky_width="$(grep -m1 -oP '(?<=Width:\s)\w+' <<<"$conky")"
conky_height="$(grep -m1 -oP '(?<=Height:\s)\w+' <<<"$conky")"

screen_width="$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1 | grep "[0-9]\+")"
screen_height="$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2 | grep "[0-9]\+")"

yadkey="$((${RANDOM} * $$))"

get_x(){
xwininfo -id $conky_xid | grep -m1 -oP '(?<=X:\s\s)\w+'
}

get_y(){
xwininfo -id $conky_xid | grep -m1 -oP '(?<=Y:\s\s)\w+'
}

yad --plug=${yadkey} --tabnum=1 \
    --scale --print-partial \
    --text="Move Conky Horizontaly and Verticaly" \
    --value=$(get_x) \
    --max-value=$((screen_width - conky_width)) \
    | xargs -I{} xdotool windowmove $conky_xid {} y &

yad --plug=${yadkey} --tabnum=2 \
    --scale --print-partial \
    --value=$(get_y) --vertical --invert \
    --max-value=$((screen_height - conky_height)) \
    | xargs -I{} xdotool windowmove $conky_xid x {} &

yad --paned --key="${yadkey}" \
    --title="Move Conky" \
    --width=500 --height=300 --no-buttons \
    --splitter=450 --orient=horizontal

Select a conky and move it.  Will not not save the position.
Working only with Conky not other windows.

Last edited by misko_2083 (2020-03-24 01:31:58)


Што ни оштровиди ум сагледати не може - љубав превазилази.

Offline

#205 2020-03-24 01:30:54

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,303
Website

Re: The great yad hacking thread

^ @misko, you know of course that BL already ships a conky mover that does save the position?
Preferences > Conky > Move a Conky

(The script is quite a bit longer than yours though.)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#206 2020-03-24 02:31:29

Sector11
Conky 1.9er Mod Squid
From: Upstairs
Registered: 2015-08-20
Posts: 6,397

Re: The great yad hacking thread

Off Topic

Mine is shorter: [Alt]+[Click-n-Hold] a conky and move it.  big_smile


The sun will never set if you keep walking towards it. - my son
Being positive doesn't understand physics.
_______________________________
Debian 10 Buster = SharpBang ♯!

Offline

#207 2020-03-24 02:31:59

misko_2083
Member
Registered: 2016-05-24
Posts: 371

Re: The great yad hacking thread

johnraff wrote:

^ @misko, you know of course that BL already ships a conky mover that does save the position?
Preferences > Conky > Move a Conky

(The script is quite a bit longer than yours though.)

Made the version that saves position too. smile
Added  the sliders to the existing script.
I'm not sure how it will work with the multi-monitor setup.
But the Alt-Click&Drag still works.

Clicking cancel on the paned dialog will move conky back to the previous position.

#!/bin/bash
##
#    bl-conkypin: a script to set the position of a moveable Conky
#    Copyright (C) 2015-2017 damo    <damo@bunsenlabs.org>
#    Copyright (C) 2015-2017 John Crawley <john@bunsenlabs.org>
#    Copyright (C) 2016 xaos52  <xaos52@gmail.com>
#
#    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/>.

HELP="    bl-conkypin: a script to set the position of a moveable Conky
Options:
    -h --help   show this message
No other options are supported.
After invoking the script, follow the displayed instructions
to move a selected conky to a new position on the screen.
"

# look for a help option somewhere
for i in "$@"
do
    case "$i" in
    -h|--help)
        echo "$HELP"
        exit 0
        ;;
    esac
done

error_exit(){
    echo "$0 error: $1" >&2
    exit 1
}

## check necessary tools are installed
required_commands=(xwininfo xprop yad xrandr xdotool xargs) # array, space-separated words

missing_commands=()
for i in "${required_commands[@]}"
do
    hash $i || missing_commands+=(" $i")
done
[[ ${missing_commands[0]} ]] && error_exit "This script requires the following commands: ${missing_commands[*]}
Please install the packages containing the missing commands
and rerun the script."

BL_COMMON_LIBDIR='/usr/lib/bunsen/common'
if ! . "$BL_COMMON_LIBDIR/yad-includes" 2> /dev/null; then
    echo $"Error: Failed to locate yad-includes in $BL_COMMON_LIBDIR" >&2
    exit 1
fi

#####FUNCTIONS#####

# makes array "config"
parse_conkyfile(){
    [[ -f $1 ]] || { echo "$1 is not a file." >&2;return 1;}
    unset config
    declare -Ag config
    local line parse=false comment=false conkyconf name value
    while read -r line
    do
        if [[ $line =~ ^[[:blank:]]*'--[[' ]]
        then
            comment=true # ignore comment blocks
            continue
        else
            line=${line%%--*} # remove inline comments
        fi
        if [[ $comment = true ]]
        then
            if [[ $line = *']]'* ]]
            then
                comment=false
                line=${line#*]]}
            else
                continue
            fi
        fi
        [[ $line ]] || continue
        if [[ $line =~ ^[[:blank:]]*'conky.config'[[:blank:]]*(=[[:blank:]]*'{'(.*))?$ ]]
        then
            parse=true
            conkyconf=${BASH_REMATCH[2]}
            continue
        fi
        if [[ $parse = true ]]
        then
            if [[ $line =~ ([^}]*)'}' ]]
            then
                conkyconf+=${BASH_REMATCH[1]}
                break
            else
                conkyconf+=$line
            fi
        fi
    done < "$1"
    entry_regex="([[:alnum:]_]+)[[:blank:]]*=[[:blank:]]*([[:alnum:]]+|'[^']+'|\"[^\"]+\")"
    while [[ $conkyconf =~ $entry_regex ]]
    do
        name=${BASH_REMATCH[1]}
        value=${BASH_REMATCH[2]#[\'\"]} # strip quotes
        value=${value%[\'\"]}
        config["${name}"]="${value}"
        conkyconf=${conkyconf#*${BASH_REMATCH[0]}}
    done
}

# for version 1.09 conky files
# makes array "config"
parse_conkyfile_1.09(){
    [[ -f $1 ]] || { echo "$1 is not a file." >&2;return 1;}
    unset config
    declare -Ag config
    local name value
    while read name value
    do
        [[ $name ]] || continue
        [[ $name = TEXT* ]] && break
        config["$name"]="$value"
    done < <(sed 's/\#.*$//' "$1")
}


# usage: edit_conkyfile file name=value [name2=value2...]
# parse_conkyfile should already have been run
edit_conkyfile(){
    file=$1
    shift
    local name value sed_pattern sed_replace
    declare -a sed_args
    while [[ $1 ]]; do
        unset name value sed_pattern sed_replace
        name="${1%%=*}"
        value="${1#*=}"
        shift
        [[ ${config["$name"]+x} ]] || {
            echo "$0: config key $name does not exist" >&2
            return 1
        }
        [[ ${config["$name"]} = "${value}" ]] && continue
        [[ $value =~ ^([0-9-]+|true|false)$ ]] || value=\'"$value"\' # add quotes
        (( ${#sed_args[@]} == 0 )) && sed_args=("-ri")
        sed_pattern="[[:blank:]]*${name}[[:blank:]]*=[[:blank:]]*([[:alnum:]]+|'[^']+'|\"[^\"]+\")"
        grep -q -- "-- bl-conkypin, original value for $name:" "$file" ||
            sed_replace="-- bl-conkypin, original value for $name: ${config[$name]}\n"
        sed_replace+="\t$name = $value"
        sed_args+=("-e")
        sed_args+=("s/$sed_pattern/$sed_replace/")
    done
   (( ${#sed_args[@]} )) && sed "${sed_args[@]}" "$file"
}

# for version 1.09 conky files
# usage: edit_conkyfile file name=value [name2=value2...]
# parse_conkyfile should already have been run
edit_conkyfile_1.09(){
    file=$1
    shift
    local name value
    declare -a sed_args
    while [[ $1 ]]; do
        unset name value sed_pattern sed_replace
        name="${1%%=*}"
        value="${1#*=}"
        shift
        [[ ${config["$name"]+x} ]] || {
            echo "$0: config key $name does not exist" >&2
            return 1
        }
        [[ ${config["$name"]//[[:space:]]} = "${value//[[:space:]]}" ]] && continue
        (( ${#sed_args[@]} == 0 )) && sed_args=("-ri")
        sed_pattern="^ *$name .*$"
        grep -q "#conkymove, original value for $name:" "$file" ||
            sed_replace="#conkymove, original value for $name: ${config[$name]}\n"
        sed_replace+="$name $value"
        sed_args+=("-e")
        sed_args+=("s/$sed_pattern/$sed_replace/")
    done
    (( ${#sed_args[@]} )) && sed "${sed_args[@]}" "$file"
}

getStart(){    #   Get initial Conky position
    unset CONKYPATH
    unset info1
    declare -A info1
    while read line
    do
        unset key value
        [[ $line =~ Window\ id: ]] && {
            ID=${line#*id:}
            ID=${ID% \"*}
        }
        [[ $line != xwininfo:* && $line = *:* ]] && {
            key=${line%:*}
            value=${line#*:}
            info1[$key]=$value
        }
    done < <(xwininfo)
    # info now contains all the output of xwininfo

    wmc=$(xprop -id $ID  WM_COMMAND)
    wmc=${wmc#*\"} # strip first & last quotes & everything outside
    wmc=${wmc%\"*}
    CMD=${wmc%% *} # separate first word
    CMD=${CMD%\"*}
    CONKYPATH=$(awk -F '", "' '{
        for (i=1;i<=NF;i++){
            if ($i ~ /^-[a-zA-Z]*c$/) {
                i++
                gsub(/\\\"/,"\"",$i) # unescape quotes
                print $i
                exit
            }
            if ($i ~ /^--config/) {
                sub(/--config=/,"",$i)
                gsub(/\\\"/,"\"",$i)
                print $i
                exit
            }
        }
    }' <<< "$wmc")

    [[ -z "$CONKYPATH" ]] && CONKYPATH="$HOME/.conkyrc"

    redo_dialog(){
        echo "$0: $1" >&2
        yad_error '--button=Exit:1' "$1\n\nChoose again?"
        if (( $? == 1 ));then
            echo "  Cancelled: exiting..."
            exit 0
        fi
        getStart
    }

    if [[ $CMD != conky ]];then
        redo_dialog 'Selection is not a conky'
    elif [[ $CONKYPATH != /* ]];then
        redo_dialog "$CONKYPATH is not an absolute path."
    else
        #echo "Found a conky"
        posX_1=${info1[Absolute upper-left X]}
        posY_1=${info1[Absolute upper-left Y]}
    fi
}

getFinish(){   #   Get new Conky position
    unset info2
    declare -A info2
    while read line
    do
        unset key value
        [[ $line != xwininfo:* && $line = *:* ]] && {
            key=${line%:*}
            value=${line#*:}
            info2[$key]=$value
        }
    done < <(xwininfo -id $ID)
    posX_2=${info2[Absolute upper-left X]}
    posY_2=${info2[Absolute upper-left Y]}
}

getOffset(){   # parse_conkyfile should already have been run
    if [[ ${config[alignment]} = none ]];then   # placement managed by Openbox
        yad_info "This Conky has 'alignment none'\nso placement is handled by the Window Manager.\n"
        echo -e "\nConky has 'alignment none',\nso placement is handled by the Window Manager\nExiting...\n"
        exit 0
    fi

    OFFSET_X=$(( posX_2 - posX_1 ))
    OFFSET_Y=$(( posY_2 - posY_1 ))

    case ${config[alignment]} in
        tr|top_right|mr|middle_right|br|bottom_right|mm|middle_middle|bm|bottom_middle|tm|top_middle)
            gapX=$(( ${config[gap_x]} - OFFSET_X ))
            ;;
        tl|top_left|ml|middle_left|bl|bottom_left)
            gapX=$(( ${config[gap_x]} + OFFSET_X ))
            ;;
    esac
    case ${config[alignment]} in
        tr|top_right|tl|top_left|tm|top_middle)
            gapY=$(( ${config[gap_y]} + OFFSET_Y ))
            ;;
        br|bottom_right|bl|bottom_left|bm|bottom_middle|mm|middle_middle|ml|middle_left|mr|middle_right)
            gapY=$(( ${config[gap_y]} - OFFSET_Y ))
            ;;
    esac
}

adjust_wintype() {
    [[ ${CONKYPATH:-X} = 'X' || ${config[own_window_type]:-normal} = 'normal' ]] && return 0
    original_wintype=${config[own_window_type]}
    edit_conkyfile "$CONKYPATH" "own_window_type=normal"
    config[own_window_type]=normal
}
restore_wintype() {
    [[ ${CONKYPATH:-X} = 'X' || ${original_wintype:-X} = 'X' ]] && return 0
    edit_conkyfile "$CONKYPATH" "own_window_type=$original_wintype"
}

########################################################################

unset CONKYPATH config posX_1 posY_1 posX_2 posY_2 OFFSET_X OFFSET_Y gapX gapY

trap restore_wintype EXIT

yad_question "Click 'Select Conky' to pick a conky.\n\nThen use the 'xwininfo' cursor on the chosen conky\nto record its position." \
     --button="Select Conky:0" --button="gtk-cancel:1"

if (( $? == 0 ));then
    getStart
    if ! grep -Eq '(^|[[:blank:]])conky\.config[[:blank:]]*=?' "$CONKYPATH"
    then
        yad_info "This conky uses v1.09 syntax.\nIt is recommended to convert the conky to v1.10 syntax.\nSee: https://forums.bunsenlabs.org/viewtopic.php?id=3983"
        parse_conkyfile() {
            parse_conkyfile_1.09 "$@"
        }
        edit_conkyfile() {
            edit_conkyfile_1.09 "$@"
        }
    fi
else
    echo "  Cancelled: exiting..."
    exit 0
fi

parse_conkyfile "$CONKYPATH"

adjust_wintype

screen_width="$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1 | grep "[0-9]\+")"
screen_height="$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2 | grep "[0-9]\+")"

conky_width="$(xwininfo -id $ID | grep -m1 -oP '(?<=Width:\s)\w+')"
conky_height="$(xwininfo -id $ID | grep -m1 -oP '(?<=Height:\s)\w+')"

conky_x="$(xwininfo -id $ID | grep -m1 -oP '(?<=X:\s\s)\w+')"
conky_y="$(xwininfo -id $ID | grep -m1 -oP '(?<=Y:\s\s)\w+')"

yadkey="$((${RANDOM} * $$))"

yad --plug=${yadkey} --tabnum=1 \
    --scale --print-partial \
    --text="\nMove the Conky to the desired location\n\nUse the sliders or Alt+L-mousebutton Drag.\n\nThen click 'OK' to record the new position." \
    --value=$conky_x \
    --max-value=$((screen_width - conky_width)) 2>/dev/null \
    | xargs -I{} xdotool windowmove $ID {} y &

yad --plug=${yadkey} --tabnum=2 \
    --scale --print-partial \
    --value=$conky_y --vertical --invert \
    --max-value=$((screen_height - conky_height)) 2>/dev/null \
    | xargs -I{} xdotool windowmove $ID x {} &

yad --paned --key="${yadkey}" \
    --title="Move Conky" \
    --width=500 --height=300 \
    --splitter=450 --orient=horizontal \
    --button="gtk-cancel":1 --button="gtk-ok":0 2>/dev/null

if (( $? == 0 ));then
    getFinish
else
    echo "  Cancelled: exiting..."
    xdotool windowmove $ID $conky_x $conky_y
    exit 0
fi

getOffset

edit_conkyfile "$CONKYPATH" "gap_x=$gapX" "gap_y=$gapY"

exit 0

-----------------------------------

Sector11 wrote:

Off Topic

Mine is shorter: [Alt]+[Click-n-Hold] a conky and move it.  big_smile

With that you shoot faster than your shadow. smile
[youtube]https://www.youtube.com/watch?v=miowofVdng4[/youtube]

Last edited by misko_2083 (2020-03-24 04:29:25)


Што ни оштровиди ум сагледати не може - љубав превазилази.

Offline

#208 2020-03-25 12:21:06

misko_2083
Member
Registered: 2016-05-24
Posts: 371

Re: The great yad hacking thread

Conky is easy to move because it's window does not have a title bar.
When you want to move a decorated window things are more complex.
Plus, xdotool's relative positions have some bugs. Ugh.
"xdotool windowmove $WIN_XID x y" doesn't include the window borders or a title bar.
If you want to move a window with a title bar horizontaly without changing the y axis, window moves in weird directions.

xdotool windowmove $WIN_XID 500 y
xdotool windowmove $WIN_XID 520 y
xdotool windowmove $WIN_XID 550 y
xdotool windowmove $WIN_XID 520 y
xdotool windowmove $WIN_XID 500 y

Same thing with vertical movement and x axis.

Tried to move the window inside _NET_WORKSPACE and found out that the gtk3 has a _GTK_FRAME_EXTENTS protocol.
This is what I came up with:

#!/usr/bin/env bash

yad --text="Click 'Select a Window' to pick a window.\n\nThen use the 'xwininfo' cursor on the chosen window\nto move it." \
     --button="Select a Window:0" --button="gtk-cancel:1"

if (( $? == 0 ));then
   window="$(xwininfo)"
else
    echo "  Cancelled: exiting..."
    exit 0
fi

window_xid="$(grep -m1 -Eow "0x[a-f0-9]+{7}" <<<"$window")"
export window_xid

window_width="$(grep -m1 -oP '(?<=Width:\s)\w+' <<<"$window")"
window_height="$(grep -m1 -oP '(?<=Height:\s)\w+' <<<"$window")"

relative_x=$(xwininfo -id $window_xid | grep -oP '(?<=X:\s\s)\w+' | cut -d $'\n' -f2)
relative_y=$(xwininfo -id $window_xid | grep -oP '(?<=Y:\s\s)\w+' | cut -d $'\n' -f2)

# if supports _GTK_FRAME_EXTENTS protocol then it's a gtk3+ window
if [[ "$(xprop -id $window_xid _GTK_FRAME_EXTENTS)" != '_GTK_FRAME_EXTENTS:  not found.' ]];
then
    left=$(xprop -id $window_xid _GTK_FRAME_EXTENTS | cut -d',' -f1 | sed 's/^_GTK_FRAME_EXTENTS(CARDINAL) = //')
    right=$(xprop -id $window_xid _GTK_FRAME_EXTENTS | cut -d',' -f2)
    top=$(xprop -id $window_xid _GTK_FRAME_EXTENTS | cut -d',' -f3)
    bottom=$(xprop -id $window_xid _GTK_FRAME_EXTENTS | cut -d',' -f4)
    window_width=$((window_width - left - right))
    window_height=$((window_height - top - bottom))
fi

workarea_width="$(xprop -root _NET_WORKAREA | cut -d',' -f3 | sed 's/^[ ]//')"
workarea_height="$(xprop -root _NET_WORKAREA | cut -d',' -f4 | sed 's/^[ ]//')"

workarea_x=$(xprop -root _NET_WORKAREA | cut -d',' -f1 | sed 's/^_NET_WORKAREA(CARDINAL) = //')
workarea_y=$(xprop -root _NET_WORKAREA | cut -d',' -f2 |sed 's/^[ ]//')

workarea_width=$((workarea_width + workarea_x))
workarea_height=$((workarea_height + workarea_y))


max_scale_x=$((workarea_width - window_width))
max_scale_x=$((max_scale_x - relative_x))

max_scale_y=$((workarea_height - window_height))
max_scale_y=$((max_scale_y - relative_y))

initial_value_x=$(xwininfo -id $window_xid | grep -m1 -oP '(?<=X:\s\s)\w+')
initial_value_x=$((initial_value_x - relative_x))
[[ $initial_value_x -gt $max_scale_x ]] && initial_value_x=$max_scale_x
[[ $initial_value_x -lt $workarea_x ]] && initial_value_x=$workarea_x

initial_value_y=$(xwininfo -id $window_xid | grep -m1 -oP '(?<=Y:\s\s)\w+')
initial_value_y=$((initial_value_y - relative_y))
[[ $initial_value_y -gt $max_scale_y ]] && initial_value_y=$max_scale_y
[[ $initial_value_y -lt $workarea_y ]] && initial_value_y=$workarea_y

yadkey="$((${RANDOM} * $$))"

get_x(){
    local X
    X=$(xwininfo -id $window_xid | grep -m1 -oP '(?<=X:\s\s)\w+')
    X=$((X-relative_x))
    echo $X
}

get_y(){
    local Y
    local relative
    Y=$(xwininfo -id $window_xid | grep -m1 -oP '(?<=Y:\s\s)\w+')
    Y=$((Y-relative_y))
    echo $Y
}


yad --plug=${yadkey} --tabnum=1 \
    --scale --print-partial \
    --text="\nMove the window to the desired location\n\nUse the sliders." \
    --value=$initial_value_x \
    --max-value=$max_scale_x \
    --min-value=$workarea_x \
    | while read -r line; do xdotool windowmove $window_xid $((line-left)) $(get_y); done &

yad --plug=${yadkey} --tabnum=2 \
    --scale --print-partial \
    --value=$initial_value_y --vertical --invert \
    --max-value=$max_scale_y \
    --min-value=$workarea_y \
    | while read -r line; do xdotool windowmove $window_xid $(get_x) $((line-top)); done &

yad --paned --key="${yadkey}" \
    --title="Move" \
    --width=500 --height=300 \
    --splitter=450 --orient=horizontal \
    --button="Restart":0 --button="Close":1 2>/dev/null

[ $? -eq 0 ] && exec $0

But if you resize the window or change a panel position or add a new panel you will have to click Reset. Because the yad has it's limitations, can't reset the minimum and maximim values.

If nothing else - it was a fun exercise.

Last edited by misko_2083 (2020-03-25 12:23:50)


Што ни оштровиди ум сагледати не може - љубав превазилази.

Offline

#209 2020-03-31 01:57:14

achim
Member
Registered: 2019-08-23
Posts: 35

Re: The great yad hacking thread

Hello everyone, I hope everyone is fine and nobody has contracted this dangerous virus. I am currently distracting myself and modifying various yad scripts. However, I now have a problem with this icon finder and need help. The script works with the commented out find command in line without problems, but my variant "for f in do" finds more icons from lines 21 to 23, although I am limited to "png". The results are redirected to a text file, but so far I have not been able to read them formatted with yad.
Does anyone have any idea how it could work?

Stay healthy, achim

#!/bin/bash
# Name:iconfind.sh
# benötigt: sudo apt install rox-filer + sudo apt install gxmessage
#
XMESSAGE=$(which gxmessage) || XMESSAGE=xmessage
fd="/home/achim/bin/icons"
function close_exit(){
    kill -s SIGUSR1 $YAD_PID
}
export -f close_exit
#
export TMPFILE=/tmp/yadvalues
function savevalues { echo -e "IMGNAME=\"$2\"\nIMGSIZE=$3\nIMGPATH=\"$4\"" > $TMPFILE ;} ; export -f savevalues
function showinfo   { source $TMPFILE ; exiv2   "$IMGPATH" 2>/dev/null | xmessage -file -c -geometry 400x300 -f monospace ;} ; export -f showinfo
function showinrox  { source $TMPFILE ; rox -s  "$IMGPATH"  ;} ; export -f showinrox
function copypath   { source $TMPFILE ; echo -n "$IMGPATH" | xclip -i -selection clipboard  ;} ; export -f copypath
SEP=";"

# FOUND=$(find -L /usr/share/icons/Mint-Y/actions/22 -regextype gnu-awk -iregex  ".*\.(svg|png|jpg|gif|xpm)$" -printf "%p${SEP}%f${SEP}%s${SEP}%p${SEP}")

for f in /usr/share/icons/*/*/*/*.png; do
echo "$f" >> /tmp/test.txt
done
exit
IFS=$SEP
GTK_THEME="gtk-3.0" yad --list --geometry=1500x500 \
--window-icon="$fd/Gnome-System-Search-32.png" \
--title="  Icon-Finder" --center \
--select-action='bash -c "savevalues %s"' \
--column=icon:IMG \
--column=name \
--column=size:NUM \
--column=path \
--button=" Info!$fd/Gnome-Dialog-Information-32.png":'bash -c "showinfo"' \
--button=" Zeige Standort!$fd/locale32.png":'bash -c "showinrox"' \
--button=" Pfad kopieren!$fd/copy32.png":'bash -c "copypath"' \
--button=" Beenden!$fd/close-program-32.png":1
<< /tmp/test.txt

	ac=$(echo $?)									# Exit-Code auswerten
	
	if [[ $ac == 1 ]] || [[ $ac == 9 ]] || [[ $ac == 252 ]]; then	# Taste Abbrechen gedrückt || Skript-Ende mit [X] || Skript-Ende mit [Esc]
	bash -c close_exit &>/dev/null
	exit
	fi
exit

Text that has to be colorized

Offline

#210 2020-03-31 02:49:57

damo
....moderator....
Registered: 2015-08-20
Posts: 6,268

Re: The great yad hacking thread

Are you aware of yad-icon-browser? Or is this just a personal project/exercise?


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#211 2020-03-31 02:56:54

achim
Member
Registered: 2019-08-23
Posts: 35

Re: The great yad hacking thread

It is a personal project. I don't know the yad-icon-browser yet. Where can I watch it?

Offline

#212 2020-03-31 03:40:33

achim
Member
Registered: 2019-08-23
Posts: 35

Re: The great yad hacking thread

Thanks for the tip, I found the yad-icon browser. However, I find the "iconfind.sh" project even more comfortable. Therefore I would be very grateful for a support.

Last edited by achim (2020-03-31 03:50:00)

Offline

#213 2020-03-31 08:05:59

misko_2083
Member
Registered: 2016-05-24
Posts: 371

Re: The great yad hacking thread

Achimovski, you have to separate values with newline for every column of the list dialog

echo -e "1\n2\n3\n4" | yad --list --geometry=1500x500 --window-icon="$fd/Gnome-System-Search-32.png" --title="  Icon-Finder" --center --column=icon:IMG --column=name --column=size:NUM --column=pat

something like this

for f in /usr/share/icons/*/*/*/*.png; do
       size=$(grep  -o "[0-9]\+x[0-9]\+" <<<"${f}")
       printf "%s\n%s\n%s\n%s\n" "$f" "${f##*/}" "${size##*'x'}" "$f"
done | yad --list --geometry=1500x500 --window-icon="$fd/Gnome-System-Search-32.png" --title="  Icon-Finder" --center --column=icon:IMG --column=name --column=size:NUM --column=path

But some icons are very big in the first column.


Што ни оштровиди ум сагледати не може - љубав превазилази.

Offline

#214 2020-03-31 12:11:33

achim
Member
Registered: 2019-08-23
Posts: 35

Re: The great yad hacking thread

Dear misko_2083, thank you for the quick help. I couldn't have done it without her. I have been observing for a long time that they always help users in the development of their projects in several forums (including Puppy Linux). I find this very remarkable, so I would like to expressly express my praise for it. For me, they are therefore explicitly "Mr. YAD". Finally two questions: Did you actually participate in the development of yad? Second, is it generally possible to influence the column widths in yad? This option would be particularly appropriate for "iconfind.sh".

Achimovski, (so you say in their homeland) wink

P.S. "But some icons are very big in the first column."

That is surely due to the icon size 256. I could also accept that I could exclude it from the search. Unfortunately, I don't know how to do that.

Last edited by achim (2020-03-31 12:19:31)

Offline

#215 2020-04-01 13:01:05

misko_2083
Member
Registered: 2016-05-24
Posts: 371

Re: The great yad hacking thread

I did not write any code for yad, only complained about it. smile
Columns can be wrapped --wrap-width=30

@Achim Achimovski would be perfect combination wink

To skip icon sizes of 256 tcheck if the variable size is 256x256 and use "continue" to skip to a next cycle in a for loop.

for **something***; do
     size=$(grep  -o "[0-9]\+x[0-9]\+" <<<"${f}")
     If [[ "$size" == "256x256" ]];
           then
                   continue
       fi
done

Што ни оштровиди ум сагледати не може - љубав превазилази.

Offline

#216 2020-04-01 17:06:50

achim
Member
Registered: 2019-08-23
Posts: 35

Re: The great yad hacking thread

With that I have come a lot further. Thanks a lot for this. In my opinion I have now reached the final phase, the script works very satisfactorily for me. If someone has suggestions for improvement, they are welcome to contribute them here. At this point, however, I would like once again misko_2083's willingness to help, but also the moderator damo, both of whom helped me with their excellent knowledge. This is not a matter of course. Maybe I can return the favor in some form.

Achim Achimovski wink

#!/bin/bash
# Name:iconfind.sh
# benötigt: sudo apt install rox-filer + sudo apt-get install libimage-exiftool-perl perl-doc 
#
function close_exit(){
    kill -s SIGUSR1 $YAD_PID
}
export -f close_exit
#
export fd=/home/achim/bin/icons
export TMPFILE=/tmp/yadvalues
#
function savevalues(){ 
echo -e "IMGNAME=\"$2\"\nIMGSIZE=$3\nIMGPATH=\"$4\"" > $TMPFILE 
}
export -f savevalues
#
function showinfo(){ 
source $TMPFILE ; exiv2   "$IMGPATH" 2>/dev/null 
exiftool $IMGPATH > /tmp/meta.txt 
GTK_THEME="gtk-3.0" yad --text-info --center --title=" Detailinformationen" --width=850 --height=600 \
--borders=15 --fixed --window-icon=$fd/Gnome-Dialog-Information-16.png --back=gainsboro \
--fore=black < /tmp/meta.txt fontname="Monospace 12" --button=" Schließen!$fd/Gnome-Process-Stop-32.png":1
}
export -f showinfo
#
function showinrox(){
source $TMPFILE ; rox -s  "$IMGPATH"  
}
export -f showinrox
#
function copypath(){ 
source $TMPFILE ; echo -n "$IMGPATH" | xclip -i -selection clipboard  
}
export -f copypath
#
SEP=";"

for f in /usr/share/icons/*/*/*/*.png; do     
     size=$(grep  -o "[0-9]\+x[0-9]\+" <<<"${f}")
     if [[ "$size" == "" ]]
     then
                   continue
     fi
#
     if [[ "$size" == "256" ]]
     then
                   continue
     fi
#
     if [[ "$size" == "512" ]]
     then
                   continue
     fi
#
     if [[ "$size" == "256x256" ]]
     then
                   continue
     fi
#
     if [[ "$size" == "512x512" ]]
     then
                   continue
     fi
#

printf "%s\n%s\n%s\n%s\n" "$f" "${f##*/}" "${size##*'x'}" "$f"
done | GTK_THEME="gtk-3.0" yad --list --geometry=1500x500 \
--wrap-width=300 \
--wrap-height=36 \
--window-icon="$fd/Gnome-System-Search-32.png" \
--title="  Icon-Finder" --center --borders=15 --fixed \
--select-action='bash -c "savevalues %s"' \
--column=icon:IMG \
--column=name \
--column=size: \
--column=path \
--button=" Info!$fd/Gnome-Dialog-Information-32.png":'bash -c "showinfo"' \
--button=" Zeige Standort!$fd/locale32.png":'bash -c "showinrox"' \
--button=" Pfad kopieren!$fd/copy32.png":'bash -c "copypath"' \
--button=" Beenden!$fd/Gnome-Process-Stop-32.png":1

	ac=$(echo $?)									# Exit-Code auswerten
	
	if [[ $ac == 1 ]] || [[ $ac == 9 ]] || [[ $ac == 252 ]]; then	# Taste Abbrechen gedrückt || Skript-Ende mit [X] || Skript-Ende mit [Esc]
	bash -c close_exit &>/dev/null
	exit
	fi
exit

Last edited by achim (2020-04-01 17:09:29)

Offline

#217 2020-04-03 20:57:42

ohnonot
...again
Registered: 2015-09-29
Posts: 4,880
Website

Re: The great yad hacking thread

Is it possible to (ab)use yad as an image viewer?

Is it possible to use keyboard shortcuts (e.g. spacebar for next image) in yad?

I had a look at the docs, the answer would seem to be no - or?


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#218 2020-04-03 22:18:22

damo
....moderator....
Registered: 2015-08-20
Posts: 6,268

Re: The great yad hacking thread

ohnonot wrote:

Is it possible to (ab)use yad as an image viewer?

Is it possible to use keyboard shortcuts (e.g. spacebar for next image) in yad?

I had a look at the docs, the answer would seem to be no - or?

Kind of... Add the images to an array, then use --image=$IMAGE to display them (but they need to be scaled first to fit the yad window). Each image would need its own yad window, so the dialog needs to be in a while loop - see the bl tint2 and conky chooser scripts for examples of replacing yad windows with a loop.

I imagine xdotool could be used to simulate a button press to show the next image dialog.

Much easier to use feh (theme) though wink


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#219 2020-04-04 23:28:33

misko_2083
Member
Registered: 2016-05-24
Posts: 371

Re: The great yad hacking thread

ohnonot wrote:

Is it possible to (ab)use yad as an image viewer?

Is it possible to use keyboard shortcuts (e.g. spacebar for next image) in yad?

I had a look at the docs, the answer would seem to be no - or?

Picture dialog can show a picture and that's about it.
https://github.com/v1cont/yad/blob/mast … yad.1#L779
Lost track in what version was added.

Html dialog can can be used but with javascript and likely jquery.
Why bother when you can install ristretto.

I wanted to ask if this sleep 0.03 is overkill? smile
Someone asked if it's possible to close this undecorated window when it's clicked.
Perhaps I click too fast but that's what it takes to close the window consistently with this script.

#!/bin/bash
# close undecorated dialog with left mouse click
# behaves like notification

yad --image "dialog-warning" --geometry=200x70+1190+600 --undecorated --on-top --no-buttons --skip-taskbar --text "Notification Message" & YPID=$!

# wait until yad opens
until xdotool search --onlyvisible --pid "$YPID" >/dev/null 2>&1; do
     sleep .1
done

# get xwid
XWID=$(xdotool search --onlyvisible --pid "$YPID")

# get mouse id
MOUSE_ID=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]\+' | grep -o '[0-9]\+')

# while the window exists
while xdotool search --onlyvisible --pid "$YPID" >/dev/null 2>&1; do
    # get mouse button 1 state
    STATE=$(xinput --query-state $MOUSE_ID | grep 'button\[1' | sort)
    # get the window in focus
    FOCUS=$(xdotool getwindowfocus)
    # if mouse button 1 is down and the window has focus kill it
    if [[ "${STATE#*=}" == "down" ]] && [[ $XWID == $FOCUS ]]
    then
        kill -15 $YPID
        wait $YPID  2>/dev/null
    fi
    sleep .03
done

exit

Што ни оштровиди ум сагледати не може - љубав превазилази.

Offline

#220 2020-04-05 08:48:52

ohnonot
...again
Registered: 2015-09-29
Posts: 4,880
Website

Re: The great yad hacking thread

Thanks damo & misko.

damo wrote:

Add the images to an array, then use --image=$IMAGE to display them (but they need to be scaled first to fit the yad window). Each image would need its own yad window, so the dialog needs to be in a while loop - see the bl tint2 and conky chooser scripts for examples of replacing yad windows with a loop.

I imagine xdotool could be used to simulate a button press to show the next image dialog.

So each time I click the according button in the yad window it would advance in the array and display the next image?
I just tried the bl conky chooser, it does not even respond to e.g. Alt-c for close or Alt-a for apply.
I'm guessing yad is not very keyboard-friendly?

The reason I'm asking is because I want to loop through a directory with images and apply some simple modifications with imagemagick, if the user chooses so, and the option to save good-looking results as a new image.

Doesn't have to be yad.
I'm currently achieving this with a terminal script (utilizing w3mimgdisplay) but a GUI solution would be nicer.
However, spacebar for next image is the essential bare minimum keyboard functionality.


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#221 2020-04-05 11:37:21

misko_2083
Member
Registered: 2016-05-24
Posts: 371

Re: The great yad hacking thread

So that is what you had in mind. smile

In that case gtkdialog would be better.
I mean gtkwialog because it uses bash as default shell.
While in Debian sh is a symlink to dash, in puppy linux sh is a symlink to bash.
With bash you can do more complex dialogs.
https://github.com/DebianDog/Gtkwialog
Gtkwialog has the same executable as gtkdialog but it's safer in a way it executes commands.
The documentation is basic but there is a lot of examples on puppy forums.
http://murga-linux.com/puppy/viewtopic.php?t=38608
To get you started

 export script='<pixmap><input file>/path/to/image.jpg</input><height>40</height><width>70</width></pixmap>'
 gtkdialog --program=script EXIT="abort"

There is a support for hotkeys also.
It can be much more complex than yad. http://murga-linux.com/puppy/viewtopic.php?t=109573
But it takes more time to learn.


Што ни оштровиди ум сагледати не може - љубав превазилази.

Offline

#222 2020-04-07 05:09:00

ohnonot
...again
Registered: 2015-09-29
Posts: 4,880
Website

Re: The great yad hacking thread

^ Amazing!
Thanks for that information and the links.
It will take a little time to work through it, but gtkdialog is installed already (since bash is the default on ArchLinux I probably won't be needing gtkwialog).


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#223 2020-06-15 21:23:37

Naik
Member
From: Lipsia
Registered: 2015-10-03
Posts: 262

Re: The great yad hacking thread

Hey there,

I recently added this to my prepend.csv for starting/stopping kali-anonsurf via jgmenu

^tag(anonsurf)
Back,^back()
Start,x-terminal-emulator -T 'AnonSurf' -r 'popterm' -c 'popterm' -p 'lithium' --geometry=420x123+430+340 -e "sudo anonsurf start; sleep 27s; exit"
Stopp,x-terminal-emulator -T 'AnonSurf' -r 'popterm' -c 'popterm' -p 'lithium' --geometry='420x123+430+340' -e "sudo anonsurf stop; sleep 27s; exit"

It works so far, only that the placing and geometry is not working and for the overall consitency of look and feel, I'd like to raise it with yad now.
My problems are:

1. anonsurf won't work when invoked with pkexec which would be need as I suggest and
2. I can't find a way to pipe stdout to yad to see what is happening.

Does any of you have an idea how to get around this?
Thanks for your help.

naik --greetz


"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen on GitHub

Offline

#224 2020-06-16 01:42:56

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 7,303
Website

Re: The great yad hacking thread

The only options guaranteed to be supported by x-terminal-emulator are -T and -e.
https://www.debian.org/doc/debian-polic … l-emulator
Others you have used above ( -r -c  -p and --geometry ) depend on the terminal currently acting as x-terminal-emulator. If you need them to work you'll have to call that specific terminal instead.

Then, calling yad, getting a sudo password etc etc would probably be easier to handle if you put it all in a separate script (give it --start and --stop options), and called that from jgmenu.

You can get a password to run sudo with something like:

yad <options> --entry --hide-text | sudo -S <command>

Last edited by johnraff (2020-06-16 01:44:01)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#225 2020-06-16 10:52:34

Naik
Member
From: Lipsia
Registered: 2015-10-03
Posts: 262

Re: The great yad hacking thread

Thanks for the quick reply!

johnraff wrote:

The only options guaranteed to be supported by x-terminal-emulator are -T and -e.
https://www.debian.org/doc/debian-polic … l-emulator
Others you have used above ( -r -c  -p and --geometry ) depend on the terminal currently acting as x-terminal-emulator. If you need them to work you'll have to call that specific terminal instead.

I tried that, but when I try calling terminator directly nothing happens at all, as if jgmenu refuses to cooperate with it (terminator == x-terminal-emulator BTW).

So you are saying I could come up with a little ~/bin/anonsurf-helper.sh
and call it like this in jgmenu:

yad <options> --entry --hide-text | sudo -S $HOME/bin/anonsurf-helper.sh

Sounds easy, but I guess I would not be able to see any of the output this script (or the comand invoked by it) is writing to stdout, right?

Is there any option to do so, other than piping it to a temporary logfile and opening another dialogue afterwards to print it?

naik --greetz


"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen on GitHub

Offline

Board footer

Powered by FluxBB