Pages

Showing posts with label geek. Show all posts
Showing posts with label geek. Show all posts

November 22, 2009

Different GTK settings for different sessions

Here's the situation:

You like using different window managers for different things. For example, sometimes you want to use IceWM, other times Openbox, etc. This is easy enough to do if you are using GDM, but there's a small thing that bothers you. All the above WMs will use the same configuration files for GTK settings, but you want to use different settings for each. For example, in Openbox you may want to use Tango icons but you like the default Gnome icons better in IceWM.

I describe below a way you can make this happen. It's a tiny bit hackish, but it seems to work just fine. It assumes you are not using gnome-settings-daemon.

GTK settings--the easy way

First of all, make life easy for yourself and install LXAppearance. It is part of the LXDE desktop environment, but many distributions let you install it as a standalone package. It is the best tool I know of to adjust GTK appearance settings. You do not need LXAppearance to do what I describe below, but you will love life a little more if you have it.

Different settings per Window Manager

Here's where the fun begins. This should work with any WM that has a startup script (required) and a shutdown script (strongly recommended but not strictly necessary). I used IceWM to test the idea.

GTK settings are stored in the .gtkrc-2.0 file in your home directory. What we are going to do at startup is redirect this by doing the following:
  • create a file .gtkrc-icewm-2.0 to store the GTK settings for icewm
  • copy the original .gtkrc-2.0 file to a backup location.
  • delete the original .gtkrc-2.0 file
  • then create a link from .gtkrc-2.0 to .gtkrc-icewm-2.0
And at session end, we will:
  • remove the link, and
  • restore the backed up .gtkrc-2.0
There are a few test we should do in the process to make sure we don't mess anything up. Below are experts from my ~/.icewm/startup and ~/.icewm/shutdown files that outline the needed tests.

Excerpt from ~/.icewm/startup:
### This section lets icewm use its own gtk settings ###
# it uses the following files
# .gtkrc-2.0 original gtk settings file
# .gtkrc-icewm-2.0 file where gtk settings for icewm session are stored
# .gtkrc-2.0-orig.BAK file where original .gtkrc-2.0 is stored
#
# if .gtkrc-icewm-2.0 doesn't exist, make it
if [ ! -f ~/.gtkrc-icewm-2.0 ] ; then
if [ -f ~/.gtkrc-2.0 ] ; then
cp ~/.gtkrc-2.0 ~/.gtkrc-icewm-2.0
else
touch ~/.gtkrc-icewm-2.0
fi
fi

# if .gtkrc-2.0 is a regular file, move .gtkrc-2.0 to a backup file,
# then link to .gtkrc-icewm-2.0. (This should be undone in shutdown.)
if [ -f ~/.gtkrc-2.0 ] ; then
cp ~/.gtkrc-2.0 ~/.gtkrc-2.0-orig.BAK
ln -sf ~/.gtkrc-icewm-2.0 ~/.gtkrc-2.0
fi
#
### end gtk settings stuff
Excerpt from ~/.icewm/shutdown:
# if .gtkrc-2.0 is a link then remove link and restore backed up .gtkrc-2.0
if [ -h ~/.gtkrc-2.0 ] ; then
rm ~/.gtkrc-2.0
cp ~/.gtkrc-2.0-orig.BAK ~/.gtkrc-2.0
fi
If you don't do the shutdown bits, then the link to the .gtkrc-icewm-2.0 file will remain in place when you start a session in a different WM. This means that every WM you use that doesn't use gnome-settings-daemon (and maybe xfce-mcs-manager) must do a restore on startup if things are not to get really wonky.

September 29, 2009

Starting up gnubiff



I am using gnubiff as my email notifier because it's cuter and more flexible than the defacto standard Mail Notification. In fact, I use two different instances of gnubiff to provide notification for two different groups of email accounts. (Yeah ... I have too many email accounts.)

However, one of gnubiff's issues is that once it encounters an error (such as if the Internet connection isn't up) it tends to get stuck even when whatever caused the error is fixed. To help with this problem, I wrote a script that I call when my session starts up. The script waits until the Internet connection is up before starting my biffs. You'll need to modify the specific biff/gnubiff/whatever calls for your needs.
#!/bin/bash

# Copyright (c) 2009, Mithat Konar
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions are
# met:
# 
#     * Redistributions of source code must retain the above copyright 
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the
#       distribution.
#     * Neither the name of the  nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Delays the launching of biffs so the network can get setup.
# Requires wget, zenity.

MAX_TRIES=4   # max number of attempts to verify connection
DELAY=15   # time between attmepts to verify connection
TEST_URL=http://www.google.com # the URL used to verify connection
TMP_FILE=/tmp/start-biffs-mfk # a needed temp file; must be user r-w

###########################################################################

rm -f $TMP_FILE
numTries=0
while [ "a" == "a" ]
do
if [ $numTries -ge $MAX_TRIES ] ; then
zenity --question --title "biff startup issues" --text "I haven't been able to detect an Internet connection.\n\nShould I continue trying?"
if [ "$?" == "0" ] ; then
numTries=0
else
exit 1
fi
fi
wget $TEST_URL -O $TMP_FILE
if [ -s $TMP_FILE ] ; then
break 
fi
sleep $DELAY
let numTries=numTries+1
done
rm -f $TMP_FILE

###########################################################################
sleep 5
gnubiff -n --systemtray -c ~/.gnubiffrc-gmail&
sleep 10
gnubiff -n --systemtray -c ~/.gnubiffrc-misc&
# the following isn't really a biff, but it's close enough to count as one
sleep 10
~/Apps/scripts/email-notify-mfk&

September 25, 2009

Running commands on GNOME logout

This post deals with GNOME, which disqualifies it from any reasonable "light-and-lean" discussion, but I don't exactly know where else to make a note of this.

One of the bigger omissions from GNOME is that there is no built-in mechanism for executing commands at logout. I discovered this the hard way when trying to set up MPD to run completely in userspace (to be documented in an upcoming post). However, it is possible to make GDM run arbitrary stuff at the end of the session, and that can be used to good effect as described here. In the event that that link goes bad, in summary what you do is edit /etc/gdm/PostSession/Default
and add
logoutscript="$HOME/.gdmlogout";
if [ -x "$logoutscript" ] ; then
su $USER -c "$logoutscript"
fi
to the file. Then create a file .gdmlogout in your home directory and make it executable.

You need to note that this will only work if you are using GDM and the .gdmlogout file will execute no matter what desktop environment you log into.