<?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>Ctrl-C &#187; Linux</title>
	<atom:link href="http://ctrl-c.us/blog/archives/category/computers/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://ctrl-c.us/blog</link>
	<description>a friendly interruption</description>
	<lastBuildDate>Fri, 28 May 2010 11:49:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Adding &#8216;addremove&#8217; to Git</title>
		<link>http://ctrl-c.us/blog/archives/849</link>
		<comments>http://ctrl-c.us/blog/archives/849#comments</comments>
		<pubDate>Fri, 09 Apr 2010 21:57:38 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[addremove]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[hg]]></category>
		<category><![CDATA[mercurial]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/blog/?p=849</guid>
		<description><![CDATA[I&#8217;m a happy git user, but mercurial has a nifty command with no git equivalent: hg addremove. This command removes deleted files from the repository and also adds new files in the current directory. For me, at least, it&#8217;s a useful command that I&#8217;d like to have. Of course, git is nothing if not flexible, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a happy git user, but mercurial has a nifty command with no git equivalent: <code>hg addremove</code>. This command removes deleted files from the repository and also adds new files in the current directory. For me, at least, it&#8217;s a useful command that I&#8217;d like to have. Of course, git is nothing if not flexible, so let&#8217;s add this command! I&#8217;m using a suggestion for a script that I found <a href="http://ionrails.com/2009/08/07/git-commands-adding-and-committing-cheatsheet/">here</a>. Add the following lines to your <code>$HOME/.gitconfig</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>alias<span style="">&#93;</span></span>
    <span style="color: #000099;">addremove</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #000066; font-weight:bold;"><span style="color: #660066;"> !git add . &amp;&amp; git ls-files --deleted | xargs --no-run-if-empty git rm</span></span></pre></div></div>

<p>Tada&mdash;<code>git addremove</code> puts new files in the staging area and also removes deleted files. Now you don&#8217;t have to pay attention to your hipster friends who try to tell you how great mercurial is.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/849/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using notify-send to Slack Off Efficiently</title>
		<link>http://ctrl-c.us/blog/archives/746</link>
		<comments>http://ctrl-c.us/blog/archives/746#comments</comments>
		<pubDate>Thu, 17 Dec 2009 12:25:16 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[libnotify]]></category>
		<category><![CDATA[notify-send]]></category>
		<category><![CDATA[procrastination]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/blog/?p=746</guid>
		<description><![CDATA[I&#8217;ve been working on a big project in MPI and the execution times on my code are annoyingly long (on the order of minutes). I like to keep my work in a separate workspace from my browser to minimize distractions, but then when I set my code running and head over to visit reddit or [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a big project in MPI and the execution times on my code are annoyingly long (on the order of minutes). I like to keep my work in a separate workspace from my browser to minimize distractions, but then when I set my code running and head over to visit <a href="http://reddit.com">reddit</a> or something I often don&#8217;t notice when my code finishes. Today it occurred to me that this would be a good use for libnotify. There is a command-line utility called <code>notify-send</code> (you should have it if you have a recent version of Ubuntu; not sure about other distros) which gives a simple interface to libnotify, so I whipped up a tiny script to call it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">EVAL_STRING</span>=<span style="color: #ff0000;">&quot;notify-send -u normal -t 5000 -i info <span style="color: #000099; font-weight: bold;">\&quot;</span>Task completed<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>$@<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">eval</span> $<span style="color: #000000; font-weight: bold;">@</span>; <span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #007800;">$EVAL_STRING</span></pre></div></div>

<p>I put it in a folder which is in my path, and now I just do<br />
<pre>$ notify ./takes_forever</pre><br />
and I know as soon as it&#8217;s done. OK, <a href="http://xkcd.com/303/">back to work</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/746/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keyboard Remapping in Windows XP</title>
		<link>http://ctrl-c.us/blog/archives/302</link>
		<comments>http://ctrl-c.us/blog/archives/302#comments</comments>
		<pubDate>Tue, 02 Jun 2009 17:36:55 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/blog/?p=302</guid>
		<description><![CDATA[When I found that I had to use Windows for work, the first thing I did was to install gvim and my usual host of plugins. The next thing was to remap caps lock and escape. I switch these when I&#8217;m using Linux because I don&#8217;t really ever use caps lock, but I use escape [...]]]></description>
			<content:encoded><![CDATA[<p>When I found that I had to use Windows for work, the first thing I did was to install <a href="http://www.vim.org/download.php">gvim</a> and my usual host of plugins. The next thing was to remap caps lock and escape. I switch these when I&#8217;m using Linux because I don&#8217;t really ever use caps lock, but I use escape all the time (especially in vim). In Linux it&#8217;s a simple <code>.Xmodmap</code> entry:</p>
<p><span id="more-302"></span></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">remove Lock = Caps_Lock
add Lock = Escape
keysym Caps_Lock = Escape
keysym Escape = Caps_Lock</pre></div></div>

<p>In Windows, it&#8217;s a <a href="http://www.usnetizen.com/fix_capslock.php">bit trickier</a>. You have to add a registry key, and look up the hex codes for the escape and caps lock keys. I found a lot of premade registry files for switching other keys, but apparently I&#8217;m the only person who swaps escape with caps lock. Anyway, you just need to paste the following in a file, name it something with a <code>.reg</code> extension, and then double-click it to import the key into the registry.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Windows Registry Editor Version 5.00
&nbsp;
[HKEY_CURRENT_USER\Keyboard Layout]
&quot;Scancode Map&quot;=hex:00,00,00,00,00,00,00,00,03,00,00,00,3a,00,01,00,01,00,3a,00,00,00,00,00</pre></div></div>

<p>This only applies the change to the current user, and you have to log out and log back in for the changes to take effect. You have to change the <code>[HKEY_CURRENT_USER\Keyboard Layout]</code> to <code>[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]</code> if you want it to apply to all users.</p>
<p>While you&#8217;re at it, you can find a small utility to allow for alt + left-click window dragging and alt + right-click resizing <a href="http://corz.org/windows/software/accessories/KDE-resizing-moving-for-XP-or-Vista.php">here</a> and another for background window scrolling <a href="http://www.thefreewindows.com/?p=1387">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/302/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interfacing C and Python 3 using SWIG</title>
		<link>http://ctrl-c.us/blog/archives/99</link>
		<comments>http://ctrl-c.us/blog/archives/99#comments</comments>
		<pubDate>Mon, 27 Apr 2009 09:06:17 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python 3]]></category>
		<category><![CDATA[swig]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/?p=99</guid>
		<description><![CDATA[I like Python, and I use it for almost all of my personal projects and whenever I can get away with it in school. Sometimes, however, (rarely, these days) you&#8217;re looking for raw speed. Python, alas, is not the fastest kid on the block, and at these times you might have to turn to a [...]]]></description>
			<content:encoded><![CDATA[<p>I like Python, and I use it for almost all of my personal projects and whenever I can get away with it in school. Sometimes, however, (rarely, these days) you&#8217;re looking for raw speed. Python, alas, is not the fastest kid on the block, and at these times you might have to turn to a different language to give you the necessary speed. (Another option you might consider first is <a title="Psyco" href="http://psyco.sourceforge.net/" target="_blank">Psyco</a>.) In these situations it is often the case that only particular operations or functions really have to be fast. Even if you want to write the whole piece of software in C, you might like to use Python to write the front end. There are a lot of different ways to do this, but my favorite is <a title="Simplified Wrapper and Interface Generator" href="http://www.swig.org/" target="_blank">SWIG</a>, because it&#8217;s easy and I&#8217;m lazy.</p>
<p><span id="more-99"></span>SWIG is a great tool that supports a host of high-level languages; I&#8217;ve only ever used it with Python. At the other end, you get your choice of C and C++—crappy languages aren&#8217;t really my thing, so this tutorial will be about C. I&#8217;m going to use Python 3 because all the cool kids live on the bleeding edge. This requires SWIG 1.3.37 or better; if you&#8217;re on Ubuntu like me, you&#8217;re going to have to go grab it from the website and compile it yourself (I&#8217;m using 1.3.39). Also, remember that you need the header files for python installed (python3-dev on Ubuntu). If you&#8217;re too lazy to copy-paste, you can download the files <a href='http://ctrl-c.us/wordpress/wp-content/uploads/2009/04/swig_intro.tar.gz'>here</a>.</p>
<p>We&#8217;ll start out with the obligatory hello world program just to test that SWIG is set up correctly. First make a C function that prints the text and name it <code>hello.c</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include&lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">void</span> hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hello, World!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we&#8217;ll get SWIG to generate a wrapper for us so that we can call it in Python. Make a file called hello.i and put this in it (my code highlighting isn&#8217;t feeling very confident about SWIG files, sorry):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span>module hello
<span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">void</span> hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">%</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>This file is the interface file, and it tells SWIG what functions and data structures are going to be shared between C and Python. Now we&#8217;ll have SWIG process the interface file to make a wrapper for a python module:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ swig <span style="color: #660033;">-python</span> hello.i</pre></div></div>

<p>This should generate two files: <code>hello.py</code> and <code>hello_wrap.c</code>. Compile the C files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-fPIC</span> hello_wrap.c hello.c -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>python3.0 -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>python3.0</pre></div></div>

<p>Make sure that the direcotories are correct. Unfortunately, gcc generates a warning when I compile, which is bothersome as I&#8217;m a <code>-Werror</code> kind of guy. The <code>-fPIC</code> flag is necessary, because we&#8217;re making a shared library the python module is going to use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ld</span> <span style="color: #660033;">-shared</span> hello.o hello_wrap.o <span style="color: #660033;">-o</span> _hello.so</pre></div></div>

<p>If that works, you are ready to fire up Python and try it. At a Python3 prompt:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">from</span> hello <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> hello<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
Hello, World<span style="color: #66cc66;">!</span></pre></div></div>

<p>Easy, right? Now I&#8217;ll show you some of the features that I most frequently use. First, we&#8217;ll pass some data through by wrapping a C function to multiply integers. Make a file called <code>swig_intro.h</code>, and put in the following declaration:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include&lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include&lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> mult<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then in <code>swig_intro.c</code> we can write</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;swig_intro.h&quot;</span>
&nbsp;
<span style="color: #993333;">int</span> mult<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> a <span style="color: #339933;">*</span> b<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally, the interface file, <code>swig_intro.i</code>, will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span>module swig_intro
<span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">#include &quot;swig_intro.h&quot;</span>
<span style="color: #339933;">%</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> mult<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To make things easier, let&#8217;s write a makefile for this little project:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">TARGET     <span style="color: #004400;">=</span> swig_intro
CC         <span style="color: #004400;">=</span> gcc
CFLAGS     <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>g <span style="color: #004400;">-</span>fPIC <span style="color: #004400;">-</span>Wall <span style="color: #004400;">-</span>Wextra
HEADERS    <span style="color: #004400;">=</span> swig_intro<span style="color: #004400;">.</span>h
SRCS       <span style="color: #004400;">=</span> swig_intro<span style="color: #004400;">.</span>c
INCLUDES   <span style="color: #004400;">=</span>
INTERFACE  <span style="color: #004400;">=</span> swig_intro<span style="color: #004400;">.</span>i
SWIG       <span style="color: #004400;">=</span> swig
&nbsp;
LDSHARED   <span style="color: #004400;">=</span> ld
CSHARED    <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>shared
&nbsp;
OBJS       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>SRCS<span style="color: #004400;">:.</span>c<span style="color: #004400;">=.</span>o<span style="color: #004400;">&#41;</span>
&nbsp;
IWRAP      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>INTERFACE<span style="color: #004400;">:.</span>i<span style="color: #004400;">=</span>_wrap<span style="color: #004400;">.</span>i<span style="color: #004400;">&#41;</span>
ISRCS      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>IWRAP<span style="color: #004400;">:.</span>i<span style="color: #004400;">=.</span>c<span style="color: #004400;">&#41;</span>
IOBJS      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>IWRAP<span style="color: #004400;">:.</span>i<span style="color: #004400;">=.</span>o<span style="color: #004400;">&#41;</span>
&nbsp;
PYTHON_INCLUDE<span style="color: #004400;">=</span> <span style="color: #004400;">-</span>I<span style="color: #004400;">/</span>usr<span style="color: #004400;">/</span><span style="color: #666622; font-weight: bold;">include</span><span style="color: #004400;">/</span>python3<span style="color: #004400;">.</span>0 <span style="color: #004400;">-</span>I<span style="color: #004400;">/</span>usr<span style="color: #004400;">/</span>lib<span style="color: #004400;">/</span>python3<span style="color: #004400;">.</span>0
PYTHON_SO     <span style="color: #004400;">=</span> <span style="color: #004400;">.</span>so
&nbsp;
all<span style="color: #004400;">:</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SRCS</span><span style="color: #004400;">&#41;</span>
	<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SWIG</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>python <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INTERFACE</span><span style="color: #004400;">&#41;</span>
	<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>c <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CCSHARED</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ISRCS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HEADERS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SRCS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCLUDES</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PYTHON_INCLUDE</span><span style="color: #004400;">&#41;</span>
	<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LDSHARED</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CSHARED</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">IOBJS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>o _<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TARGET</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PYTHON_SO</span><span style="color: #004400;">&#41;</span>
&nbsp;
clean<span style="color: #004400;">:</span>
	rm <span style="color: #004400;">-</span>f <span style="color: #004400;">*</span>_wrap<span style="color: #004400;">*</span> <span style="color: #004400;">*</span>~ <span style="color: #004400;">.</span>~<span style="color: #004400;">*</span> <span style="color: #004400;">*.</span>pyc
	rm <span style="color: #004400;">-</span>f <span style="color: #004400;">*.</span>o <span style="color: #004400;">*.</span>so <span style="color: #004400;">*.</span>so</pre></div></div>

<p>If that works, you can launch a Python3 shell (from now on I&#8217;ll assume you do the import first):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">from</span> swig_intro <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> mult<span style="color: black;">&#40;</span>-<span style="color: #ff4500;">10</span>, <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
-<span style="color: #ff4500;">50</span></pre></div></div>

<p>Behind the scenes, SWIG uses something called typemaps to specify how each type is from Python to C and vice versa. In many cases, such as this, we don&#8217;t need to worry about that at all, because SWIG has default typemaps for all the fundamental datatypes. For example, you might wonder what SWIG does with a C struct. Go ahead and add this definition to the header file and the interface file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> Person <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>first_name<span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>last_name<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> birth_year<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> Person<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> print_person<span style="color: #009900;">&#40;</span>Person <span style="color: #339933;">*</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and put the following function into the <code>.c</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> print_person<span style="color: #009900;">&#40;</span>Person <span style="color: #339933;">*</span>p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>p<span style="color: #339933;">-&gt;</span>first_name <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>p<span style="color: #339933;">-&gt;</span>last_name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;The person is not properly defined.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s %s was born in %d.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>first_name<span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>last_name<span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>birth_year<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now recompile and try this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> p = Person<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> p.<span style="color: black;">first_name</span> = <span style="color: #483d8b;">&quot;Paul&quot;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> p.<span style="color: black;">last_name</span> = <span style="color: #483d8b;">&quot;Black&quot;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> p.<span style="color: black;">birth_year</span> = <span style="color: #ff4500;">1977</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> print_person<span style="color: black;">&#40;</span>p<span style="color: black;">&#41;</span>
Paul Black was born <span style="color: #ff7700;font-weight:bold;">in</span> 1977.</pre></div></div>

<p>As you can see, the the struct Person was wrapped in a very simple Python class with the three public data fields <code>first_name</code>, <code>last_name</code>, and <code>birth_year</code>.</p>
<p>Next, let&#8217;s see how to use typemaps ourselves to pass a more complex structure from Python to C. We&#8217;re going to make a (rather contrived) C function that will return the product of a list of integers. We&#8217;ll do this by turning a Python list into a C struct that specifies an int array and a size. Add the following code to the header and interface files:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> IntList <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> size<span style="color: #339933;">;</span>
    <span style="color: #993333;">long</span> <span style="color: #339933;">*</span>list<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> IntList<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> product<span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span>l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the <code>.c</code> file, add the function:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> product<span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span>l<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>l<span style="color: #339933;">-&gt;</span>size <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #993333;">int</span> ret_val <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ret_val <span style="color: #339933;">*=</span> l<span style="color: #339933;">-&gt;</span>list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> ret_val<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we need to define the typemap in the <code>.i</code> file. This isn&#8217;t too difficult; we just make use of several functions from the Python C API:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span>typemap<span style="color: #009900;">&#40;</span>in<span style="color: #009900;">&#41;</span> IntList <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>PyList_Check<span style="color: #009900;">&#40;</span>$input<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        PyErr_SetString<span style="color: #009900;">&#40;</span>PyExc_TypeError<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Not a list.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #993333;">int</span> size <span style="color: #339933;">=</span> PyList_Size<span style="color: #009900;">&#40;</span>$input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #0000dd;">1</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>IntList<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">long</span> <span style="color: #339933;">*</span>list <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #0000dd;">1</span><span style="color: #339933;">-&gt;</span>list <span style="color: #339933;">=</span> list<span style="color: #339933;">;</span>
    $<span style="color: #0000dd;">1</span><span style="color: #339933;">-&gt;</span>size <span style="color: #339933;">=</span> size<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        PyObject <span style="color: #339933;">*</span>item <span style="color: #339933;">=</span> PyList_GetItem<span style="color: #009900;">&#40;</span>$input<span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>PyInt_Check<span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            PyErr_SetString<span style="color: #009900;">&#40;</span>PyExc_TypeError<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;List item is not an integer.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            free<span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            free<span style="color: #009900;">&#40;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> PyInt_AsLong<span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">%</span>typemap<span style="color: #009900;">&#40;</span>freearg<span style="color: #009900;">&#41;</span> IntList <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span>
    free<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>list<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    free<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This also illustrates how to tell SWIG to free your objects and how to handle errors. Now we can see it in action:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">from</span> swig_intro <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> product<span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
Traceback <span style="color: black;">&#40;</span>most recent call last<span style="color: black;">&#41;</span>:
  File <span style="color: #483d8b;">&quot;&lt;stdin&gt;&quot;</span>, line <span style="color: #ff4500;">1</span>, <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>module<span style="color: #66cc66;">&gt;</span>
<span style="color: #008000;">TypeError</span>: Not a <span style="color: #008000;">list</span>.
<span style="color: #66cc66;">&gt;&gt;&gt;</span> product<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;five&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
Traceback <span style="color: black;">&#40;</span>most recent call last<span style="color: black;">&#41;</span>:
  File <span style="color: #483d8b;">&quot;&lt;stdin&gt;&quot;</span>, line <span style="color: #ff4500;">1</span>, <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>module<span style="color: #66cc66;">&gt;</span>
<span style="color: #008000;">TypeError</span>: List item <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> an integer.
<span style="color: #66cc66;">&gt;&gt;&gt;</span> product<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">9</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff4500;">945</span></pre></div></div>

<p>As you would expect, transferring data the other way is similar. For an example, let&#8217;s make a function that takes a list and returns a dictionary mapping the list elements to their squares. Add these definitions to the header and interface files:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> IntMap <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> size<span style="color: #339933;">;</span>
    <span style="color: #993333;">long</span> <span style="color: #339933;">*</span>list1<span style="color: #339933;">;</span>
    <span style="color: #993333;">long</span> <span style="color: #339933;">*</span>list2<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> IntMap<span style="color: #339933;">;</span>
&nbsp;
IntMap <span style="color: #339933;">*</span>square<span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span>l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The actual C function will take a pointer to an <code>IntList</code> and return a pointer to an <code>IntMap</code>, allocating space for a second list as needed. The conversion to a <code>dict</code> will be specified with an out typemap. In the <code>.c</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">IntMap <span style="color: #339933;">*</span>square<span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span>l<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    IntMap <span style="color: #339933;">*</span>ret_map <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>IntMap <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>IntMap<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ret_map<span style="color: #339933;">-&gt;</span>size <span style="color: #339933;">=</span> l<span style="color: #339933;">-&gt;</span>size<span style="color: #339933;">;</span>
    ret_map<span style="color: #339933;">-&gt;</span>list1 <span style="color: #339933;">=</span> l<span style="color: #339933;">-&gt;</span>list<span style="color: #339933;">;</span>
    ret_map<span style="color: #339933;">-&gt;</span>list2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> l<span style="color: #339933;">-&gt;</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ret_map<span style="color: #339933;">-&gt;</span>list2<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> l<span style="color: #339933;">-&gt;</span>list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> l<span style="color: #339933;">-&gt;</span>list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> ret_map<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Add the typemap to the <code>.i</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span>typemap<span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span> IntMap <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span>
    $result <span style="color: #339933;">=</span> PyDict_New<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        PyObject <span style="color: #339933;">*</span>key <span style="color: #339933;">=</span> PyInt_FromLong<span style="color: #009900;">&#40;</span>$<span style="color: #0000dd;">1</span><span style="color: #339933;">-&gt;</span>list1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        PyObject <span style="color: #339933;">*</span>val <span style="color: #339933;">=</span> PyInt_FromLong<span style="color: #009900;">&#40;</span>$<span style="color: #0000dd;">1</span><span style="color: #339933;">-&gt;</span>list2<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        PyDict_SetItem<span style="color: #009900;">&#40;</span>$result<span style="color: #339933;">,</span> key<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">%</span>typemap<span style="color: #009900;">&#40;</span>freearg<span style="color: #009900;">&#41;</span> IntMap <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span>
    free<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IntMap <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>list2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    free<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IntMap <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And we&#8217;re done!</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> square<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,-<span style="color: #ff4500;">12</span>,<span style="color: #ff4500;">60000</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#123;</span><span style="color: #ff4500;">60000</span>: <span style="color: #ff4500;">3600000000</span>, <span style="color: #ff4500;">1</span>: <span style="color: #ff4500;">1</span>, -<span style="color: #ff4500;">12</span>: <span style="color: #ff4500;">144</span><span style="color: black;">&#125;</span></pre></div></div>

<p>I&#8217;ve only shown some of the more useful capabilities of SWIG that I find myself using a lot. For more information, consult the official <a href="http://www.swig.org/Doc1.3/Python.html">SWIG docs</a>. Unfortunately, they&#8217;re not entirely complete, so it is sometime easier to get answers by just browsing the built-in SWIG interface files to see how the typemaps work.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/99/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>64-bit Flash Player!</title>
		<link>http://ctrl-c.us/blog/archives/92</link>
		<comments>http://ctrl-c.us/blog/archives/92#comments</comments>
		<pubDate>Mon, 17 Nov 2008 06:47:39 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/?p=92</guid>
		<description><![CDATA[Today Adobe is releasing an alpha version of a 64-bit Flash player for Linux. I cannot explain how happy this makes me. I have been dealing with shitty 32-bit Flash players running on 32-bit emulation in 64-bit browsers in Linux for about the past five years, and it has caused me nothing but endless annoyance [...]]]></description>
			<content:encoded><![CDATA[<p>Today <a title="Press release" href="http://news.cnet.com/8301-1001_3-10097931-92.html" target="_blank">Adobe is releasing an alpha version of a 64-bit Flash player for Linux</a>. I cannot explain how happy this makes me. I have been dealing with shitty 32-bit Flash players running on 32-bit emulation in 64-bit browsers in Linux for about the past five years, and it has caused me nothing but endless annoyance and frustration. Half the time I have to refresh a page a few times because Flash keeps dying, and even when it manages to play it&#8217;s a complete coin toss as to whether there will be sound. With my current setup I basically have to close Amarok to play a Flash video if I want to hear sound. Adobe is years late to the party with this one, but better late than never, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/92/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Howto: Dual Monitors with Ubuntu and NVidia</title>
		<link>http://ctrl-c.us/blog/archives/54</link>
		<comments>http://ctrl-c.us/blog/archives/54#comments</comments>
		<pubDate>Mon, 29 Sep 2008 07:26:29 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/?p=54</guid>
		<description><![CDATA[Pursuant to my previous post on using dual monitors in Linux, I decided to post a some information that would have definitely appreciated having a long time ago. This specifically covers how get two monitors working in a reasonable fashion in Ubuntu and Xubuntu, but I originally figured it out in Gentoo (and it applies [...]]]></description>
			<content:encoded><![CDATA[<p>Pursuant to my previous post on using dual monitors in Linux, I decided to post a some information that would have definitely appreciated having a long time ago. This specifically covers how get two monitors working in a reasonable fashion in Ubuntu and Xubuntu, but I originally figured it out in Gentoo (and it applies to other distros).</p>
<p><span id="more-54"></span></p>
<ol>
<li>Make sure that you&#8217;re using the proprietary nvidia driver and that you have nvidia settings installed:

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sudo apt-get install nvidia-settings</pre></div></div>

</li>
<li>Open up nvidia-settings (under System -&gt; Administration in Ubuntu and System in Xubuntu).</li>
<li>Under &#8220;X Server Display Configuration&#8221;, you need to set each monitor to have the correct resolution. Also specify the layout you want, and change the configuration to TwinView. Finally, set the position of <strong>both</strong> to &#8220;Absolute&#8221;.</li>
<li>Now hit &#8220;Save to X Configuration File&#8221;. Save this to your home directory (i.e. change the path to <code>~/xorg.conf</code>).</li>
<li>(Optional.) If you want to get rid of the NVidia splash screen every time X restarts, open the <code>xorg.conf</code> file in the editor of your choice and make sure that the line

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Option   &quot;NoLogo&quot; &quot;True&quot;</pre></div></div>

<p>appears under each &#8220;Device&#8221; section.</li>
<li>Move the file to the proper directory (you need root access):

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sudo mv ~/xorg.conf /etc/X11/</pre></div></div>

</li>
<li>Restart the X server. The easiest way to do this is to log out and log back in.</li>
<li>Now the Xinerama info should be getting sent properly. In Ubuntu you can tell that this is the case if you are able to place your panel on just one screen instead of both of them (drag it around a bit). Unfortunately, Gnome doesn&#8217;t let you set separate desktop backgrounds, so if you want something different on each screen you&#8217;ll need to make an image the width of both screens added together and paste the two pictures in (you can do this easily in the Gimp). In Xubuntu, when you open up the properties for your panel, you&#8217;ll be able to choose the monitor on which it should appear. Additionally, Xfce allows you to set separate desktop backgrounds.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/54/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dear Xinerama: Goodbye, and Good Riddance</title>
		<link>http://ctrl-c.us/blog/archives/10</link>
		<comments>http://ctrl-c.us/blog/archives/10#comments</comments>
		<pubDate>Wed, 06 Aug 2008 07:34:03 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/index.php?page=articles&amp;article=dear_xinerama_goodby</guid>
		<description><![CDATA[Having used many distros of Linux with a variety of graphics cards during the past five or so years, I&#8217;ve had plenty of opportunities to get my hands dirty with xorg.conf. When I eventually got an Nvidia card and discovered nvidia-settings, it was great to not have to mess with xorg.conf any more…or not. I [...]]]></description>
			<content:encoded><![CDATA[<p>Having used many distros of Linux with a variety of graphics cards during the past five or so years, I&#8217;ve had plenty of opportunities to get my hands dirty with xorg.conf. When I eventually got an Nvidia card and discovered nvidia-settings, it was great to not have to mess with xorg.conf any more…or not. I still had to read up on xorg.conf options whenever I wanted to do something fancy, but I found nvidia-settings to be a useful tool for generating xorg.confs that I could later modify.</p>
<p>A few years ago I started using two monitors with my desktop computer. In nvidia-settings I had two options for configuring the monitors: either with TwinView or Separate X servers. Separate X servers is hugely annoying, so that was out. TwinView made my window manager (Fluxbox, at the time) think that I basically had one screen. This meant that maximizing applications caused them to fill both screens. It also meant that no edge snapping occurred at the border between the monitors. I have seen experienced the same behavior with TwinView in Xfce. This means that for at least two years I&#8217;ve associated TwinView with pure suck.</p>
<p><span id="more-10"></span></p>
<p>The solution I found was Xinerama. This is an X extension that allows for more logical multi-screen behavior. Unfortunately, it has some downsides. It is slow (although having a fairly fast video card I never noticed this), and it does not work with compositing. So, no shadows, transparency, or other fanciness. I decided that having two monitors (without retarded edge behavior) was more important than super-shiny glowing translucent windows with drop shadows, so I&#8217;ve lived without compositing as long as I&#8217;ve used two monitors.</p>
<p>About an hour ago, while setting up Ubuntu on my dad&#8217;s computer (which also has two monitors), I ran into the same exact issue. TwinView made Gnome think that I only had one big monitor, and turning on Xinerama disabled compositing. This was more noticeable in Gnome, though, because without compositing you don&#8217;t have fancy alt-tabbing and dragging a window to the edge of the screen doesn&#8217;t move it to the next workspace, among several other annoyances. When I checked the Ubuntu forums, the consistent advice I saw was to disable Xinerama and use TwinView. This made no sense to me, but I kept fiddling with it. After at least an hour of disabling and enabling Xinerama, playing with the xorg.conf, restarting X, and reading the Xorg log, everything suddenly started working. With Xinerama disabled, Gnome suddenly started understanding that there were two separate screens. Windows were maximizing. Compositing was working. Birds were singing.</p>
<p>But what had changed? After poking around on Google for a while, I figured out that TwinView, which I&#8217;d written off as basically a pile of shit a long time ago, can send the WM Xinerama info (e.g., where the break between the screens is). When this works properly, there&#8217;s really no reason (that I can discern) to use Xinerama at all. Apparently it&#8217;s aimed more at people with cards that don&#8217;t support a solution like TwinView or MergedFB. Also, there&#8217;s a little option you can set in the Device section of xorg.conf:<br />
<pre class="code">Option &quot;NoTwinViewXineramaInfo&quot;</pre><br />
to turn this feature of TwinView off. As best I can figure, one of two things was occurring:</p>
<ul>
<li>For reasons unknown, nvidia-settings likes to set this option and in all my mangling of xorg.conf I&#8217;d managed to get one that didn&#8217;t include it.</li>
<li>That option had not been set but Gnome had temporarily been ignoring the Xinerama info before getting its shit together.</li>
</ul>
<p>If the first one is the case, then that was also my problem in the past on my own computer and I&#8217;ll be fixing it first thing when I get my hands on it (I don&#8217;t have access to it at the moment). If the second is the case, then maybe Xfce doesn&#8217;t use the Xinerama info properly with TwinView. This would probably be a deal-breaker that would cause me to switch to Gnome. I kind of doubt this is the case though, considering how perfectly Xfce does work with Xinerama enabled. Regardless, it&#8217;s great to no longer have to use Xinerama.</p>
<p>Before I got this working, this was going to be a rant about the state of dual screens in Linux and nvidia-settings in particular. I&#8217;m going to go ahead and mention two that still annoy me about nvidia-settings:</p>
<ul>
<li>It doesn&#8217;t require root access. Now, with XRandR or whatever you can make some changes without being root, so that may be the reasoning there. However, I just use the command <span class="code">xrandr</span> to do this, and every time I use nvidia-settings I&#8217;m trying to make a new xorg.conf. I usually forget to run it as root, so when I&#8217;m done making my changes I have to save the file to my home directory and move it manually. This isn&#8217;t a huge deal, but it happens just about every time.</li>
<li>If you are going to use Xinerama, you have enable separate X screens before it reveals the Xinerama checkbox. Why not make Xinerama a separate option in addition to TwinView and separate X servers?</li>
</ul>
<p>Additionally, Gnome doesn&#8217;t let you set separate wallpapers, so the best option is basically to make one image from two separate wallpapers. I&#8217;m hoping that this functionality can be added; Xfce already does it properly.</p>
<p>On the whole, though, the dual monitor situation is pretty good. After the initial annoyance of getting it set up it pretty much works. This is much better than the Nvidia situation on Windows, where it likes to forget half of my settings periodically and makes me reboot after making trivial changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
