#!/bin/bash

export DISPLAY=:0.0

NAMES=$1

if [ "$NAMES" = "" ]; then
  echo "Usage: $0 <name or name1,name2...>"
  exit
fi

NAMES_SPLIT=$(echo $NAMES | tr "," "\n")

while [ true ]; do
  for name in $NAMES_SPLIT
  do
    running=`ps xa | grep $name | grep -v grep | grep -v window_on_top`

    if [ "$running" != "" ]; then
      #echo "### $name"
      #wmctrl -r $name -b toggle,above
      wmctrl -r $name -b add,above
      sleep 1
      continue 2
    fi
  done

  sleep 1
done

