1

1 - 4   [4]

Automating X11 Rootless Mode

Also relates to OSX

Many of the applications I use on a daily basis come from the KDE toolkit or other X11 software most notably Konqueror, eSVN, Kompare, Karm, XEmacs and (of course) Amarok. If I am working extensively with KDE apps I will load up the K Desktop Environment as my window manager in full screen mode. However, sometimes I find I want to share X11 and native OS X applications. It is a little frustrating having to keep changing the initialisation file for X11 and switch to rootless mode in the Preferences pane. So I decided to concote a script to do this automatically.

By default my .xinitrc file will start up KDE with:

startkde >/tmp/kde.log 2>&1

Then I also have a start up file for the quartz window manager (.xinitrc.quartz) with:

exec quartz-wm

Then the startup script for X11 applications (based on the Xdroplets scripts) looks to see if X11 is already running by searching for display lock files in the tmp dir. If it is not another script is called which switches X11 to rootless mode and boots it with the Quartz window manager initialisation file. This allows me to start up X11 using its application link if I want to use KDE or to just open an X11 application if I want it to run in rootless mode seamlessly with native OSX applications.

The main challenge with achieveing this is switching the preference since this is stored in a binary plist file (~/Library/Preferences/com.apple.x11.plist). Fortunately the property list utility (plutil command) makes this task relatively simple:


if [ ! -z $1 ] && [ $1 == 'false' ] ; then
  pattern='s/true/false/'
else
  pattern='s/false/true/'
fi
plutil -convert xml1 -o /tmp/com.apple.x11.plist ~/Library/Preferences/com.apple.x11.plist
sed "/rootless/{ n; $pattern; }" /tmp/com.apple.x11.plist > /tmp/com.apple.x11-new.plist
plutil -convert binary1 -o ~/Library/Preferences/com.apple.x11.plist /tmp/com.apple.x11-new.plist
\rm /tmp/com.apple.x11{,-new}.plist

The property list utility converts the binary file to XML so that sed can then replace the state of the rootless property. So now I can open an X11 app or two without having to either boot a KDE session or reconfigure my .xinitrc or X11 preferences.

Posted on Aug 19, 2005 at 00:40:13. [Comments for Automating X11 Rootless Mode- 0]

Plastic Fantastic KDE

Also relates to Browsers

Last week I finally installed Tiger and at the same time set up a dedicated partition for Fink to simplify future upgrades in the absence of extensive backup media. The disadvantage of this decision was that I could no longer use the default /sw directory for Fink package management - well by mounting the directory onto the partition I probably could (a course of action I choose for the OS X Users directory on a third partition) but I also wanted to store other open source material in the partition so the /sw directory would not be at the root level. This did not present any major problems other than the fact I would be restricted to only building source from the Fink tree. Just calls for a little patience - and the occassional piece of detective work!

Unfortunately progress was slow when I initially choose to build QCad being half way through a scale drawing of my soon to materialise new home - probably one of the few programs acknowledged to be incompatible with Tiger's GCC version 4. Still following a trip to a colleague's broadband fitted office I had the source for bundle-gnome and bundle-kde waiting to go. The plan was to leave them alone for a while and try and settle on a comfortable working environment in Tiger, but finally having the mammoth tetex source files that would allow me to build the monopd server was just too tempting. Of course I didn't consider at the time this would also mean building the entire KDE-games package which in turn would mean building the KDE-base package.

So around about 6 hours later (not bad for my lowly iBook!) I had the core KDE 3.4 ready to go as a full-screen replacement for Apple's rootless quartz window manager. At first I disregarded this as I had not found the binary KDE 3.1 build that inspiring on Panther, and had generally stuck with Gnome or WindowMaker if I wanted to use a full screen window manager for X11. But the Plastik theme and the countless number of improvements over 3.1 are simply delectable! Performance is excellent on Tiger and other than the erratic sound behaviour and current absence of several office applications I can see this becoming a regular set up. Most noticeable, and pleasing, is the vast improvement in the CSS and script support of the Konqueror browser which now, among other odds and ends, handles my CSS negative margins experiment from last year perfectly.

Ok, its not quite pure Linux (yet) but this laptop never ceases to amaze me!

Posted on Jul 19, 2005 at 02:26:12.

PHP Function Lookup from XEmacs

Also relates to PHP and Apache, IDEs

Ok, I have gone all XEmacs, and am really impressed. For the best part of two years now I have been using UltraEdit for must web scripting with a little bit of Eclipse on the side for command line testing with PHP5 development. With a large amount of the development work now migrated to my IBook, it was time to seek out a new editor. Currently I am undecided between Eclipse, BBEdit, Vim, Quanta, Kate and XEmacs, although I am very drawn to the latter.

Despite the learning curve, with a bit of Lisp knowledge in hand, the power of XEmacs quickly becomes apparent. Of course an essential feature for any scripting language is syntax highlighting and efficient function lookup. The first is easy enough - add the prog-modes package (which includes an Emacs lisp file for PHP major mode) and all other dependant packages from the package manager. I also enabled syntax highlighting by default in ~/.xemcas/init.el with:


(require 'font-lock)

While perusing the settings for PHP mode from the Options menu (and directly from the package file prog-modes/php-mode.el) I discovered that the key command sequence Ctrl C Ctrl F performs a search for the function currently selected at php.net. This was a problem since the machine is not going to be on a permanant connection. So, I decided to store the PHP Documentation on my local server. Nothing out of the ordinary, except it give me the opportunity to use the RewriteMap directive in the Apache configuration.

  1. Grab the multi-file PHP documentation from php.net. And extract all files to a suitable location on disc (note there are over two thousand separate HTML files and they will all be extracted to same directory, so make sure it is the right place!)
  2. Create a name-based virtual server to access the documentation locally by first adding a new machine name (eg phpdocumentation) to the Netinfo Database in OSX.
  3. Add a virtual server entry to the httpd configuration file. I currently have the system configured to reboot Apache with a different principle conf file for each PHP version - as with my Window 98 box - so I put virtual server directives in one of the user conf files (from /etc/httpd/users) instead.

    
    <VirtualHost 127.0.0.1>
      ServerName phpdocumentation
      
      # Rewrite Directives will go here…
      
      DocumentRoot "/path/to/php/documentation/dir"
      <Directory "/path/to/php/documentation/dir">
        AllowOverride All
        Options +FollowSymLinks
      </Directory>
    </VirtualHost>
    
  4. Now, instead of hacking the Lisp code in php-mode.el, which could readily be destroyed by a future update of prog-modes, I decided to throw in a rewrite rule to fix the request URI. From XEmacs the request would be for http://phpdocumentation/function_name, so the following might work:

    
    RewriteEngine On
    RewriteRule  ^([-_a-z0-9])$ /function.$1.html
    

    Sadly not! All function help files take the form function.[the-function-name].html. And that is where I hit the stumbling block! Underscores are replaced by hyphens in the HTML file names for functions.

I was reluctant to resort to Lisp hacking, so decided to try one of the rewrite directives I have had little use for previously - RewriteMap.

  1. Create an executable script that can be called in the rewriting process to replace the underscores. I choose Perl and, due the simplicity of the rewrite, only needed one more line of code than the actual Apache manual:

    
    #!/usr/bin/perl
    # php-func-map.pl
    
    # avoid buffered I/O
    $| = 1;
    
    while (<STDIN>) {
      # globally change the underscore to a hyphen
      s/_/-/g;
      print $_;
    }
    
  2. Then set up the rewriting directives - for RewriteMap these have to go under the VirtualHost directive in the conf rather than in .htaccess file.

    
    RewriteEngine On
    RewriteMap php-func-map prg:/path/to/php-func-map.pl
    RewriteRule /([-_a-z0-9]+)$ /function.${php-func-map:$1}.html
    

And that is that. The magic is in ${php-func-map:$1} which will pass the pattern match $1 to the file defined by php-func-map and get back a PHP manual friendly file name. Of course this could be extended further to perform searches beyond just the manual's function set but servers my purpose well for the time being. So, now when I forget if the needle or the haystack goes first, a quick key combination and the manual entry is available.

Posted on Jun 15, 2005 at 18:58:33. [Comments for PHP Function Lookup from XEmacs- 0]

AWOL Explained

Also relates to OSX

Not been much time to blog recently with all out of hours preoccupied with my newly acquired Apple Ibook. Only a week old, she has far and away exceeded all expectations. Within 48 hours I felt familiar with the OSX interface - considerably more user friendly than its PC counterpart and had filled up half a gigabyte with my favourite songs, plus a few nostalgic memories courtesy of the ITunes store. One frustration was the apparent absence of Apples X11 disk image anywhere on the hard drive or accompanying discs. But this probably was for the best, as I decided rather than downloading the installer from the Apple site to instead go with Fink and the somewhat purer XFree86 variant, XDarwin. So a few sleepless nights and longhaul downloads later, I now have GNOME set up and running smoothly (bar one or two glitches), giving me access to the Gimp, Nautilus (a great file explorer!), Bluefish editor and an Amaya release which actually includes the bookmarks feature to name just a few. Add the ability to run the Xserver rootless (actually using Xnest) I still have access to all those OSX applications - superb! And then there is my free OSX upgrade to Tiger still to come once it has stabilised.

This is just a quick summary really, and if I can find time to drag myself away from the captivating transit of Io in my RXVT shell - courtesy of Xplanet - I will post some extended blogs on my first experiences and the tools that assisted me in getting my Ibook development ready.

Posted on May 05, 2005 at 16:23:59. [Comments for AWOL Explained- 2]

Breadcrumbs Trail

[ Home ] -> TW Blog -> X11
Site Map

The Severn Solutions website achieves the following standards:

[ XHTML 1.0 ] [ CSS 2 ] [ WAI AA ] [ Bobby AA ]

Page compiled in 0.005 seconds