<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>J-Doc &#187; HowTo</title>
	<atom:link href="http://jsilva.komodoopenlab.com/blog/archives/tag/howto/feed" rel="self" type="application/rss+xml" />
	<link>http://jsilva.komodoopenlab.com/blog</link>
	<description>inclusion, equity, open source</description>
	<lastBuildDate>Sun, 21 Feb 2010 00:14:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Make compiz-fusion work with xscreensaver (the quick &amp; dirty way)</title>
		<link>http://jsilva.komodoopenlab.com/blog/archives/187</link>
		<comments>http://jsilva.komodoopenlab.com/blog/archives/187#comments</comments>
		<pubDate>Mon, 24 Nov 2008 04:09:59 +0000</pubDate>
		<dc:creator>Jorge</dc:creator>
				<category><![CDATA[GNU | Linux]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[compiz]]></category>
		<category><![CDATA[compiz-fusion]]></category>
		<category><![CDATA[gkrellm]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[GNU linux]]></category>
		<category><![CDATA[metacity]]></category>
		<category><![CDATA[Ubuntu 8.04]]></category>
		<category><![CDATA[wmctrl]]></category>
		<category><![CDATA[xscreensaver]]></category>

		<guid isPermaLink="false">http://jsilva.komodoopenlab.com/blog/?p=187</guid>
		<description><![CDATA[The beautiful desktop experience provided by compiz-fusion represents a significant aesthetic contribution to the pleasure of using Linux. Besides, it makes it really easy to impress even the most committed Apple disciple. The same is true for the cool gl screensavers written for xscreensavers. Unfortunately, these two don&#8217;t really work together (my computer freezes everytime [...]]]></description>
			<content:encoded><![CDATA[<p>The beautiful desktop experience provided by <a title="compiz-fusion compositing engine" href="http://www.compiz-fusion.org/">compiz-fusion</a> represents a significant aesthetic contribution to the pleasure of using Linux. Besides, it makes it really easy to impress even the most committed Apple disciple. The same is true for the cool gl screensavers written for <a title="xscreensaver homepage" href="http://www.jwz.org/xscreensaver/">xscreensavers</a>. Unfortunately, these two don&#8217;t really work together (my computer freezes everytime xscreensaver comes up while running compiz-fusion) and although the screensaver plugin for compiz-fusion shows <a title="compiz fusion screensaver plugin" href="http://www.youtube.com/watch?v=sigmLNbF0AU">great potential</a>, the gl collection for xscreensaver is still a bit ahead and has a lot more variety, so I really wanted to make them work together.</p>
<p>Here is what I did:</p>
<ol>
<li>You can use <code>xscreensaver-command -watch</code> to monitor xscreensaver events, so you can actually run a program when xscreensaver is activated (for example, to disable compiz-fusion), and another one when it is deactivated (to bring compiz-fusion back). I modified the following script available from the <a title="xscreensaver man pages" href="http://www.jwz.org/xscreensaver/man3.html">xscreensaver man pages</a> and saved it as <code>~/bin/fixscreensaver</code>:
<pre>#!/usr/bin/perl

# Fixes xscreensaver when compiz is running

my $blanked = 0;
open (IN, "xscreensaver-command -watch |");
while () {
  if (m/^(BLANK|LOCK)/) {
    if (!$blanked) {
      system "usemetacity";
      $blanked = 1;
    }
  } elsif (m/^UNBLANK/) {
    system "usecompiz";
    $blanked = 0;
  }
}</pre>
</li>
<li>As you can see, the script above calls <code>usemetacity</code> when xscreensaver is activated and <code>usecompiz</code> when it is deactivated. Save the following script as <code>~/bin/usemetacity</code>:
<pre>#!/bin/bash

#killall gkrellm
metacity --replace &amp;
#sleep 1
#gkrellm &amp;</pre>
</li>
<li>Now save this one as <code>~/bin/usecompiz</code>:
<pre>#!/bin/bash

#killall gkrellm
compiz --replace &amp;
#sleep 2
#gkrellm &amp;
#windowranger</pre>
</li>
<li>Add <code>~/bin/fixscreensaver</code> to the list of startup applications (System &gt; Preferences &gt; Sessions &gt; Startup programs) and also make sure that <code>~/bin/</code> is in your $PATH environment variable.</li>
<li><strong>Optional</strong>: If you use gkrellm, you should uncomment the corresponding lines in the scripts above. Those lines will prevent metacity (the default gnome window manager) and compiz-fusion from changing the position of the gkrellm window, which happens everytime you switch between the two because these window managers use different ways to describe desktop geometry.</li>
<li><strong>Optional</strong>: You can also use the <code>usecompiz</code> and <code>usemetacity</code> scripts to manage any other application that misbehaves when metacity or compiz-fusion take over your desktop. In fact, I use the <code>windowranger</code> script below to automatically put windows back into their corresponding viewports since everything gets shoved into the first viewport once you go back into compiz from metacity (thanks for pointing it out <strong>darken</strong>). You will need <code>wmctrl</code> for this to work properly:
<pre>#!/usr/bin/python

import os, time, wnck, sys

def dec2hex(n):
  #"""return the hexadecimal string representation of integer n"""#
  return "%X" % n

def hex2dec(s):
  #"""return the integer value of a hexadecimal string s"""#
  return int(s, 16)

def MoveWindow(wID, wtitle, xpos, ypos):

    time.sleep(0.2)
    os.system('wmctrl -i -r ' + wID + ' -e 0,'+str(xpos)+','+str(ypos)+',-1,-1')
    #time.sleep(0.4)
    #os.system('wmctrl -i -a ' + wID)
    if DEBUG: print "Moved to", xpos, ypos, 'n'

def Place(x, y, wID, wclass, wtitle):

  fin,dout = os.popen4('wmctrl -d')   # output desktop geometry
  for line in dout:
    line = line[line.find('VP: ') + 4:len(line)]  # get current viewport offset
    line = line[0:line.find(' ')]
    offset = line.split(',')      # split in x,y viewport offset coordinates
    vpxpos = int(offset[0])       # convert into integer
    vpypos = int(offset[1])       # convert into integer
    absxpos = vpxpos+x            # absolute window position (x)
    absypos = vpypos+y            # absolute window position (y)
    wxpos = absxpos
    wypos = absypos
    while wxpos &gt;= width:
      wxpos = wxpos - width       # relative window position (x)
    while wypos &gt;= height:
      wypos = wypos - height      # relative window position (y)
    if (wxpos &gt;= 0)&amp;(wxpos &lt;= 2): wxpos = 0
    if (wypos &gt;= 0)&amp;(wypos &lt;= 2): wypos = 0

  dout.close()                    # close command output
  if DEBUG: print 'Position:', absxpos, 'x', absypos

  #Send Firefox to viewport 1
  if wclass.find('Firefox') != -1:
    # Flash fullscreen windows are titled 'Firefox' so we need to ignore them...
    if wtitle != 'Firefox':
      MoveWindow(wID, wtitle, wxpos - vpxpos + vpx1, wypos - vpypos + vpy1)

  #Send GYachI to viewport 2
  elif wclass.find('GYachI') != -1:
    MoveWindow(wID, wtitle, wxpos - vpxpos + vpx2, wypos - vpypos + vpy2)

  #Send VirtualBox to viewport 5
  elif wclass.find('VirtualBox') != -1:
    MoveWindow(wID, wtitle, wxpos - vpxpos + vpx5, wypos - vpypos + vpy5)

  #Send Amarok to viewport 6
  elif wclass.find('Amarokapp') != -1:
    MoveWindow(wID, wtitle, wxpos - vpxpos + vpx6, wypos - vpypos + vpy6)

  #Send Azureus to viewport 6
  elif wclass.find('SWT') != -1:
    MoveWindow(wID, wtitle, wxpos - vpxpos + vpx6, wypos - vpypos + vpy6)

  #Send Qbittorrent to viewport 6
  elif wclass.find('Qbittorrent') != -1:
    MoveWindow(wID, wtitle, wxpos - vpxpos + vpx6, wypos - vpypos + vpy6)

  #Send Pidgin to viewport 7
  elif wclass.find('Pidgin') != -1:
    MoveWindow(wID, wtitle, wxpos - vpxpos + vpx7, wypos - vpypos + vpy7)

  #Send Skype to viewport 7
  elif wclass.find('Skype') != -1:
    MoveWindow(wID, wtitle, wxpos - vpxpos + vpx7, wypos - vpypos + vpy7)

  #Send Thunderbird to viewport 8
  elif wclass.find('Thunderbird-bin') != -1:
    MoveWindow(wID, wtitle, wxpos - vpxpos + vpx8, wypos - vpypos + vpy8)

  #Send all other windows in viewport 1 to viewport 2
  elif (wclass.find('Gnome-panel')==-1)&amp;(wtitle != 'Desktop')&amp;(wclass.find('Gkrellm')==-1)&amp;(wclass.find('Launcher')==-1)&amp;(absxpos &lt; width)&amp;(absypos &lt;= height):
    MoveWindow(wID, wtitle, wxpos - vpxpos + vpx2, wypos - vpypos + vpy2)

  else:
    if DEBUG: print 'Ignoredn'

#---------------------------- MAIN -------------------------------------
s = wnck.screen_get_default()
width = s.get_width()
height = s.get_height()
vpx1 = (width * 0);vpy1 = (height * 0)
vpx2 = (width * 1);vpy2 = (height * 0)
vpx3 = (width * 2);vpy3 = (height * 0)
vpx4 = (width * 3);vpy4 = (height * 0)
vpx5 = (width * 0);vpy5 = (height * 1)
vpx6 = (width * 1);vpy6 = (height * 1)
vpx7 = (width * 2);vpy7 = (height * 1)
vpx8 = (width * 3);vpy8 = (height * 1)
DEBUG = False;

for arg in sys.argv:
  if arg=='--debug':
    DEBUG=True;

if DEBUG: print 'Viewport geometry:', width, 'x', height, 'n'

fin,wout = os.popen4('wmctrl -lGx')
for line in wout:
  wID = line[0:line.find(' ')]                      # get the window ID
  line = line[line.find(' '):len(line)]
  line = line.lstrip()
  wdesk = line[0:line.find(' ')]                    # get the window desktop
  line = line[line.find(' '):len(line)]
  line = line.lstrip()
  wxoffset = line[0:line.find(' ')]                 # get the window x offset
  wxoffset = (int(wxoffset) / 2)
  line = line[line.find(' '):len(line)]
  line = line.lstrip()
  wyoffset = line[0:line.find(' ')]                 # get the window y offset
  wyoffset = (int(wyoffset) / 2) - 24
  line = line[line.find(' '):len(line)]
  line = line.lstrip()
  wwidth = line[0:line.find(' ')]                   # get the window width
  line = line[line.find(' '):len(line)]
  line = line.lstrip()
  wheight = line[0:line.find(' ')]                  # get the window height
  line = line[line.find(' '):len(line)]
  line = line.lstrip()
  wclass = line[0:line.find(' jsilva')]             # get the window class
  line = line[line.find(' jsilva'):len(line)]
  line = line.lstrip()
  whost = line[0:line.find(' ')]                    # get the window host
  line = line[line.find(' '):len(line)]
  line = line.lstrip()
  wtitle = line[0:len(line) - 1]                    # get the window title
  if DEBUG:
    print 'Class:', wclass
    print 'Host:', whost
    print 'Title:', wtitle
  Place(wxoffset,wyoffset,wID,wclass,wtitle)  # place window
wout.close()</pre>
</li>
<li>Enjoy!</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://jsilva.komodoopenlab.com/blog/archives/187/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
