------------------------------------------------------------------------------ Window Control (vital for handling windows via scripts) xdotool General perpose X Window control tool xwit basic window moving/resizing focus (can move move too) wmctrl -l List all the application windows (add -G for icon/position/size) xwininfo window information (title, size, location) xkill basic window kill Shell GUI Popup programs Xdialog Simple on based on the TTY "dialog" GUI kdialog KDE version basied of "dialog" (remote progress bar control) xmessage Display text and multi-choice buttons zentity Common for linux but seems to be 'static'. yad Fork of zentity (yet another dialog) Allows you to have multiple input fields (seems complex) https://github.com/v1cont/yad https://yad-guide.ingk.se/ gtkdialog Generate a full GUI interface making shell script calls. Sub-shell 'actions' are generated, and dialog settings and inputs are store exported variables in those actions. More like a new language! (see below) However "gtkdialog" is not available in fedora repo. notify-send temporary message popup.. (requires d-bus) xmessage Display information and a number of buttons gxmessage A newer GTK version (now just called xmessage) xprompt String input entry program xmenu popup a menu of choices notifier pops up a window whenever input is received (error reporting) and many other window control utility programs Also see "WindowID.hints" for finding and using a windows ID And for password see "../crypto/passwd_input.txt" Note: zenity and yad are GTK. To get stock icon names run "gtk-demo" and double clicking "Stock Item and Icon Browser" ------------------------------------------------------------------------------ Error Message Popup Window remains until user presses button. See my x-windows script "error_message" Xdialog --title 'Failure' --msgbox "$@" 0x0 & # the -center is center of ALL multi-displays, not just one screen xmessage -name "$PROGNAME" -title 'Failure' -center \ -buttons 'OK:0' -default 'OK' \ -xrm '*message.borderWidth: 0' \ -xrm '*message.scrollVertical: Never' \ "$@" & kdialog --msgbox "$@" # blue 'info' icon" kdialog --sorry "$@" # yellow 'caution' icon kdialog --error "$@" # red 'X' icons # zenity windows are large 'in your face' windows zenity --title 'Failure' --error --text="$@" & ------------------------------------------------------------------------------ Notify Message Popup Popup a temporary (timeout) window with a message. No grabs or other interferance to user, just a informational message. May need some coordination to prevent popups from overlaying each other. The trick is to make them small, and somehow avoid overlapping other existing notification pops! See my x-windows script "notify_message" for a general solution https://antofthy.gitlab.io/software#notify_message ------------------------------------------------------------------------------ Zenity notification, with changing icon! This requires DBus to be running! ( i=9; while [ $i -gt 0 ]; do echo icon:projects/im/images/font_$i.gif sleep 1 i=`expr $i - 1` done ) | zenity --notification --listen ------------------------------------------------------------------------------ Percentage & Progress Bars Zenity ( i=5; while [ $i -gt 0 ]; do echo $i sleep 1 i=`expr $i + 5` done ) | zenity --progress -------- kdialog This has got to be one of the most well thought out progress bar designs there is, and uses dbus to allow the user to control the progress bar remotely! https://develop.kde.org/docs/administration/kdialog/ Basic example... # 4 is the max size of the progress bar dbusRef=`kdialog --progressbar "Initializing" 4` echo $dbusRef #> org.kde.kdialog-84138 /ProgressDialog # Note: do not quote the variable as it provides 2 arguments for "qdbus" # set value and change the label! qdbus $dbusRef Set "" value 1 qdbus $dbusRef setLabelText "Thinking really hard" sleep 2 qdbus $dbusRef Set "" value 2 qdbus $dbusRef setLabelText "Thinking some more" sleep 2 qdbus $dbusRef Set "" value 1 qdbus $dbusRef setLabelText "Sorry backtracking!" sleep 2 qdbus $dbusRef Set "" value 2 qdbus $dbusRef setLabelText "Trying again" sleep 2 qdbus $dbusRef Set "" value 3 qdbus $dbusRef setLabelText "Proceeding" sleep 2 qdbus $dbusRef Set "" value 4 qdbus $dbusRef setLabelText "Finished" sleep 2 qdbus $dbusRef close # closes the window! Getting feedback from the Progress Bar The "qdbus" errors if the window application has exited. # get feedback (cancel and value) from progress bar. dbusRef=$( kdialog --progressbar "Press Cancel at Any time" 10 ) # keep looping until user closes the window (cancel button) while true; do sleep 1 if inc=$(qdbus $dbusRef Get "" "value" 2>/dev/null) then qdbus $dbusRef Set "" "value" $(( inc + 1 )) >/dev/null else break fi done # note setting '6' will continue to return 5 # not needed -- as window has been closed by user! #qdbus $dbusRef close ------------------------------------------------------------------------------ Using colors and columns in a list dialog... Yad... # Input file LOGFILE=${1:-/var/log/messages} # Seperate the input into paragraphs or entry, one line per column PARSER='BEGIN { OFS="\n" } { font=""; color="#FFFFFF" tag=substr($5,0,index($5,":")-1) msg=substr($0,index($0,$6)) }; /kernel/ { font="italic" }; /warn/ { color="#FFF4B8" }; /error/ { color="#FFD0D8" }; tag=="audit" {next}; # ignore audit messages msg~/^audit/ {next}; # ignore kernel audit messages too { print $1 " " $2, $3, $4, tag, msg, font, color; fflush(); }' tail -n100 $LOGFILE | awk "$PARSER" | \ yad --title="Log viewer" --window-icon=logviewer \ --button=gtk-close --geometry 600x350 \ --list --text="Content of $LOGFILE" \ --column Date --column Time --column Host \ --column Tag --column Message:TIP \ --column @font@ --column @back@ Note the awk script colors whole lines! ------------------------------------------------------------------------------- gtkdialog Customizable GUI dialog program which runs shell commands. This is more like a new language (like Tk)! It is not in fedora repos, but more part of 'puppy linux' Main Page http://code.google.com/p/gtkdialog/ Good Example (at bottom) http://pclosmag.com/html/Issues/200910/page21.html Tips & FAQ *** http://www.murga-linux.com/puppy/viewtopic.php?t=38608 Code and compile https://github.com/puppylinux-woof-CE/gtkdialog https://github.com/01micko/gtkdialog The XML Script is passed as a "Exported Enviornment Variable" And this program will call the shell commands ('action') specified. Various dialog elements can be stored into variables for use in those actions. Actions can also be pre-defined 'export -f' bash functions. However all shell actions are sub-shells, so only can't easily pass info between to seperate actions. Sub-shell actions may pop up other windows using other dialog programs. It is more like a programable popup menu in a window manager (like "openbox"). ------------------------------------------------------------------------------ Add a Icon image inside a window permanently Using xwininfo get the window id, and its size and position (to root window) NOTE: make sure you pick the appropriate child of the window. xloadimage -windowid 0xWINDOWID -at X,Y IMAGE xrefresh -geometry WIDTHxHEIGHT+X+Y This sets the background pixmap of the window to the a blank white image the size of the window with a copy of the IMAGE at the prosition given. The xrefresh will then get the client to redraw the other parts of the window. This image will be refreshed automatically by the X server whenever required. Do not use this technique for a large window to save server memory. Example add to the current xterms window: image=${1:-/usr/include/bitmaps/std/finger.xbm} child=`xwininfo -children -id $WINDOWID | sed -n 's/^ *\(0x[^ ]*\).*/\1/p'` xloadimage -windowid $child -at 420,10 $image ------------------------------------------------------------------------------ To kill a specific client Kill a client that is runing on the display without asking the user to do so. Example: Look for a xv client. NOTE: This could easily get it wrong. xkill -id `xwininfo -all -children -root | awk '/\"xv\"/ {print $1; exit}'` a winkill 'xkill -id `xwininfo -all -children -root |\\\ awk '\''/\"\!:*\"/ {print $1; exit}'\''`' Better to use the windows title for xwininfo. This must however be exact so a version or patch upgrade could invalidate it. See my "xwin_find" script. ------------------------------------------------------------------------------ Colormap hints xv -clear To remove unused color table entries. This does not include the colors used by the root pixmap. xv -root -quit Clear unused colors including the root pixmap colors. ------------------------------------------------------------------------------ Automation with "visgrep" visgrep let you look for the location of a specific 'sub-image' in a window so you can then move the mouse to that location to perform X window events, like mouse clicking on that image. "visgrep" is part of the "xautomation" package. Information in using it has moved to https://antofthy.gitlab.io/info/apps/visgrep.txt ------------------------------------------------------------------------------