#!/usr/bin/ruby -w require 'iconv' require 'cgi' # Maximum numbers of characters in client names maxchars = 50 ic = Iconv.new("utf-8", "latin1") # Fetch desktop names desktopNames = Array.new IO.popen("wmctrl -d") do |f| f.each_line do |line| desktopNames << line.split(/\s+/, 10)[9].chomp end end # Fetch client list clientList = Array.new IO.popen("wmctrl -l") do |f| f.each_line do |line| (wid, desktop, host, wname) = line.split(/\s+/, 4) desktop = desktop.to_i next if desktop == -1 wname.chomp! if clientList[desktop].nil? clientList[desktop] = Array.new end clientList[desktop] << [wid, wname] end end # Print menu puts "" count = -1 clientList.each do |d| count = count.next next if d.nil? d.each do |c| title = c[1].sub(/"/, '\\"') title = title.length > maxchars ? title[0..maxchars/2] + "..." + title[-maxchars/2..-1] : title next if title =~ /N\/A/ puts "" puts " wmctrl -i -a \"#{c[0]}\"" puts "" end end puts ""