Tuesday, February 22, 2011

Key mapping and binding in Openbox

If you have used Linux for any amount of time you will know that there are little vendor support and this can be frustrating if you would like to use all 18 000 keys on your brand spanking new keyboard!

I have this keyboard, the Microsoft Natural Ergonomic 4000, and we know that Microsoft will not have any support for it under any other operating system save Windows, hey, do not look at me like that, they actually make some decent keyboards!


So, we will have to map and bind all those extra keys ourselves.

Luckily, binding keys in Openbox is actually a fairly simple task, you only need xev and your favourite editor. This is going to be fast and dirty, but it is really simple and you should have no problems at all.

First of, open the following file:

Code:
# nano -w .config/openbox/rc.xml

Next, run xev, in a terminal just type:

Code:
# xev

You can press one key at a time on the keyboard to get the key code, this is important. The output will look something like this:

Code:
KeyPress event, serial 39, synthetic NO, window 0x2a00001,
    root 0x15a, subw 0x0, time 245502289, (1104,290), root:(1136,701),
    state 0x10, keycode 195 (keysym 0x1008ff48, XF86Launch8), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

What we are interested in is this part:
(keysym 0x1008ff48, XF86Launch8)


Go back the file you opened earlier, scroll down the file until you come across this section in the file:

Code:
<keyboard>
..........
</keyboard>

There will be a lot of text in that section, general Openbox key bindings. You can look over them and change them as you want, remember to make a back-up of the original file first!

Just above </keyboard> at the end of the keyboard section we are going to enter our own custom key binding like this:

Code:
<keybind key="XF86Launch8">
      <action name="Execute">
        <execute>/usr/bin/vlc</execute>
      </action> 
</keybind>

Do this for all the keys. I suggest doing one key at a time for obvious reasons. Log out, log back in and test out all your keys.

Perfect right? Told you it was easy!

Here is the map to all the custom keys on my keyboard.

Code:
<keybind key="XF86HomePage">
      <action name="Execute">
        <execute>/usr/bin/pcmanfm</execute>
      </action>
    </keybind>
    <keybind key="XF86Search">
      <action name="Execute">
        <execute>/usr/bin/chromium</execute>
      </action>
    </keybind>
    <keybind key="XF86Mail">
      <action name="Execute">
        <execute>/usr/bin/thunderbird</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioMute">
      <action name="Execute">
        <execute>/usr/bin/amixer set Master 0</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioLowerVolume">
      <action name="Execute">
        <execute>/usr/bin/amixer set Master 2-</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <execute>/usr/bin/amixer set Master 2+</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioPlay">
      <action name="Execute">
        <execute>/usr/bin/audacious --play-pause</execute>
      </action>
    </keybind>
    <keybind key="XF86Calculator">
      <action name="Execute">
        <execute>/usr/bin/xcalc</execute>
      </action>
    </keybind>
    <keybind key="XF86Launch5">
      <action name="Execute">
        <execute>/usr/bin/vlc</execute>
      </action>
    </keybind>
    <keybind key="XF86Launch6">
      <action name="Execute">
        <execute>/usr/bin/gnome-terminal</execute>
      </action>
    </keybind>
    <keybind key="XF86Launch7">
      <action name="Execute">
        <execute>/usr/bin/soffice -writer</execute>
      </action>
    </keybind>
<!--   Reserved for future use, do not need it now 
#    <keybind key="XF86Launch8">
#      <action name="Execute">
#        <execute></execute>
#      </action>
#    </keybind> -->
    <keybind key="XF86Launch9">
      <action name="Execute">
        <execute>/usr/bin/dcompmgr</execute>
      </action>
    </keybind>
  </keyboard>

You can bind the extra keys on your mouse in the same way in Openbox under the mouse section in that file!
Neat!

Wednesday, February 16, 2011

Caps lock in Linux. Do you really need it?

I'm just stumped that we still have some archaic tech on our keyboards that we never ever seem to use, SysRq, ScrLk and of course, CAPS LOCK!

How many times has it happened that you accidentally hit the caps lock key and suddenly YOU HAVE TO RE-TYPE A COMPLETE SENTENCE because of this. Shift should be fine, right?

Hitting it by accident while gaming is also getting old fast!

Okay, end rant... here is what you need to do to disable it or map it to another key:

Code:
$ xmodmap -e "remove lock = Caps_Lock"

If you only want to disable it for the current session, or put this in your /etc/bash.bashrc to disable it permanently and system wide:

Code:
if [ "$PS1" ]; then
# Disables the CapsLock button
xmodmap -e "remove lock = Caps_Lock"
...
fi

But now you have a dead key, but fear not, you can map it to any action you would like, like for instance shit?

Code:
xmodmap -e "remove lock = Caps_Lock"
xmodmap -e "add shift = Caps_Lock"

Again, you can of course map it to any key you want, shift just seems logical to me.

There you go, no more HITTING THAT DARN KEY BY ACCIDENT!

Monday, February 14, 2011

Content filtering made easy

There are quite a few options on the market to filter web content, like pornography, but most of these require either a server setup or some other time spend configuring files that is totally overkill for a normal household network.

Most of us have a router/modem and a couple of PC's that connect to this.
Here is a very easy method to filter you online experience!

  • OpenDNS
    Get yourself the free account at OpenDNS.
    Once you have created the account it will guide you through an easy setup where you can choose how to configure your hardware. I suggest choosing the router method, all it requires you to do is to manually change the nameserver or DNS servers in your router/modem to:
    208.67.222.222
    208.67.220.220


    If your router is also acting as the DHCP server, remember to change those DNS/nameserver settings as well!

    Make the required changes in your dashboard, adding and removing filters as you wish and save it.You can now read up a bit on dynamic IP's to educate yourself a bit.
  • DNSomatic
    Now we head on over to DNSomatic. Your account details used for OpenDNS should work here as well.
    Click the "Add Service" to get you started. That is all, I told you it is easy!
    Again you can look around to educate yourself a bit if you are so inclined.

  • ddclient
    Next install ddclient. It should be in your distro repositories so it should be easy to install.
    We only need to edit one file:

    Code:
    $ nano -w /etc/ddclient/ddclient.conf
    

    Put the following in there:

    Code: 
    ##
    ## DNS-O-Matic account-configuration
    ##
    ssl=yes
    use=web, web=myip.dnsomatic.com
    server=updates.dnsomatic.com,      \
    protocol=dyndns2,                  \
    login=your account user name,                 \
    password=your password                 \
    all.dnsomatic.com
    

    Change only the username and password you used to the ones you used to log into the DNSomatic site. You can now manually run ddclient to update your IP, or you can simply add it to a cron job. If you only want to update your IP once every hour (your ISP does not reset your account more often than that), then just do the following:

    Code:
    $ ln -s /usr/sbin/ddclient /etc/cron.hourly/opendns
    

    My ISP resets the IP address at irregular intervals, so I had to add this to crontab to get ddclient to run every thirty minutes.

    Code:
    $ crontab -e
    
    */30  * * * * /usr/sbin/ddclient
    

That is it. Try it out to see if your filtering is working and adjust the settings in OpenDNS as you see fit. Happy and safe browsing for the whole family!

The tech savvy users can stop reading now, this section is a bit overboard, but I would like to add it for people who do not want to take any risks while testing to see if everything works like it should.


Testing OpenDNS the safe way

The easiest way to see if it works is to test it by trying to enter a forbidden/filtered site. You will immediately see an OpenDNS error message warning you that this site is being blocked.



To be on the safe side, let me walk you through this without leading you into unnecessary temptation.
In OpenDNS after you have logged in, click on dashboard and then click on settings.
Click on your IP address and under "Manage individual domains" enter a safe site here that you do no mind getting blocked, something like:
bing.com

Add it and wait around 5-10 minutes for everything to get updated.

Now each time you want to know if ddclient is working without taking risks, just try and access www.bing.com. If the normal page displays then your ddclient isn't updating your IP correctly, if it is blocked then you know it is working.

Without getting technical this is a safe way to test and see if it works correctly.

Thanks to shane2peru for the initial writeup.

Saturday, February 12, 2011

Top 10 list 2011

It has been a couple of years since I last reviewed my "Top 10 list" of Linux applications, so let's have a go at it again and see what has changed and why.

2008:
1. Music player - MP3Blaster
2.
Web browser - Firefox
3. CD/DVD burning application - K3B
4. Video player - Kaffeine
5. Image editor - Gimp
6. BitTorrent client - Ktorrent
7. IRC client - Xchat / irssi
8. Terminal application - Yakuake
9. Image viewer - Eye of GNOME
10. text editor - Nano

2011
1. Music player - none
I cannot remember when last I listened to a song on the PC, months, years ago. I do not even have a music player installed, the closest to one is probably VLC. I do, however, use MP3Blaster on occasion for work to play sound files over ssh, but that is not on my desktop PC.

2.
Web browser - Firefox
Google Chrome has been around for a while and I did grow fond of it, but there are just too many bugs still to recommend it. I have some issues with YouTube videos, ironic, I know, and Firefox handles plug-ins and extensions just that little better. So, I'm partial towards Firefox, but only just. Chrome IS going to launch a full system take-over on my desktop any time now...

3. CD/DVD burning application - K3B
Can't beat the best of the best, so yea, K3B it is.

4. Video player - VLC
Kaffeine made place for VLC and this is pretty much the only media player I ever use.

5. Image editor - The Gimp
Again, Gimp just stays at the top for the moment. Don't think that spot is not being contested, no sir, there are some serious alternatives on the rise.
Well, sort of.
You see, The Gimp is a complete solution, giving you everything you could ever need and shake a stick at for your graphical needs, the alternatives that are giving The Gimp a run for it's money, on the other hand, are application specific, for the lack of a better word, like F-Spot for photo manipulation, Krita and MyPaint for image creation/manipulation.
So far The Gimp still comes out tops for me.

6. BitTorrent client - none
I do not use torrents any more, but rather news servers, and if you need a good news server client, then sabnzbd is the way to go.

7. IRC client - none
I do not use IRC any more, it has been ages since last I logged in to any IRC server, I'm not that chatty any more...

8. Terminal application - Yakuake for KDE and Gnome Terminal for Openbox
When I run Openbox I want as little KDE dependence as I possibly can have. Yea, I have a thing against the recent plasma libs and kde libs that chews my resources...

9. Image viewer - Eye of GNOME
Not much to choose from here, either choose GTK based viewer or KDE based viewer... for now Eye of Gnome is doing what it must.

10. Text editor - Nano
I still use this editor almost every single day, this is one must have for me, and I do everything with nano, from coding simple scripts to building websites, awesome editor, not too complex and certainly not too much of a ligthweight.

Well, seems like age is catching up and I do not "play" on Linux any more, I need it for day-to-day work...

Openbox random desktop wallpaper script

There are a lot of ways to change the desktop background of Openbox, but for this tutorial we are going to focus our thoughts on feh.

To set the background in Openbox, simply open a terminal and type the following command:

Code:
# feh --bg-scale /path/to/file.jpg

If you want to only use a single wallpaper for your desktop, the put this line in your autostart file:

Code:
# nano -w ~/.config/openbox/autostart.sh
# feh --bg-scale /path/to/file.jpg &

Remember the & at the end, very important!

Random wallpaper script
Let's take this one step further and take a look at a script that will randomly change the desktop wallpaper each time we log into Openbox.

Here is the script first:

Code:
#!/bin/sh 
WALLPAPERS="/path/to/folder/containing/wallpapers"
ALIST=( `ls -w1 /path/to/folder/containing/wallpapers` )
RANGE=${#ALIST[@]}
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last

feh --bg-scale $WALLPAPERS/${ALIST[$number]}

Name it something easy and save it, on my PC all my scripts (conky, wallpaper, etc.) is saved in the same folder (~/.scripts). Let's name it randomwall.sh.

Make it executable:

Code:
# chmod +x .scripts/randomwall.sh

Test the script by running it from a terminal:

Code:
# cd .scripts
# ./randomwall.sh

If all went well you should see the desktop background changing. On my machine the script complained about a file (.last) not being present in the wallpaper directory, so just create that file:

Code:
# cd /path/to/wallpaper/folder
# nano .last
ctrl+o to save the file
ctrl+x to exit

No need to write anything in it, just create it.
If everything is working as expected, simply add the script to your autostart file:

Code:
# nano -w .config/openbox/autostart.sh 

~/.scripts/randomwall.sh &

If you have problems with the script not being found, use the full path to the file:

Code:
/home/user/.scripts/randomwall.sh &

Log out and log back in, you should see a new wallpaper now!


Other alternatives
There are some scripts out there that allows you to change the desktop wallpaper with a menu click inside the Openbox right-click menu, if you want to try them out you can have a look here.

Wednesday, February 09, 2011

Autostart applications and services in Openbox

To autostart applications you need to have the following file:

Code:
~/.config/openbox/autostart.sh

Chances are good that it is not there so lets create it and put out startup applications in there:

Code:
# nano -w ~/.config/openbox/autostart.sh

In a previous post I described how to install dcompmgr and Avant Window Navigator, lets add this to the file to autotstart at next login:

Code:
#!/bin/sh
dcompmgr --gl &
avant-window-navigator &

Note the &, this is very important, without it the applications will not be started in the background and they will not run properly or at all.
dcompmgr has only a handful of options to choose from, you can view it by typing dcompmgr --help in a terminal.

Safe your work and exit, in nano:

Code:
ctrl+o to safe
ctrl+x to exit

Make the script executable:

Code:
# chmod +x ~/.config/openbox/autostart.sh

Log out and log in again, the services or applications should have automatically started.

If you find something not working, go over your commands again and make sure they are typed correctly, most of the time it is only a simple typo or the & that is left out.

Application Launcher for Openbox

If you log into Openbox for the first time you are greeted with nothing except a basic and generic right click Openbox menu. At least that is how it is in ArchLinux, also note that I have no other Desktop Environment or Window Manager installed...

The first thing I was looking for is an easy to use application launcher.

You can edit the Openbox menu yourself, or use something like obmenu to help you edit it, or even generate a menu with an app like MenuMaker. Great, but in my old age I'm looking for ease, for comfort, something that I can just click and there you have it, every single app and service available is listed.

This is where Avant Window Navigator comes in. What started out as me just looking for a neat Kde/Gnome like application launcher ended up bringing along a somewhat complete solution to my initial needs.

To install AWN you will need some composite manager to help out and bring out all the effects of AWN. I have tried quite a few and finally settled on dcompmgr.
Xompmngr and Cairo Composite Manager were very unstable and crashed when relocating tabs in Firefox, switching between some windows, etc.

The only time dcompmgr has let me down so far is when I play Steam games, but I'll come to that later.

  • Install your composite manager of choise.
    After you have it installed, start it from a terminal:

    Code:
    # dcompmgr
    

    Notice that I did not put the & to start it in the background, this way I can see what is wrong if it crashes and fix it. If we are happy later on that everything is working like it should, then we can run it in the background.

  • Now install Avant Window Navigator and Avant Window Manager extra applets.
    If you do a search in your package manager for Avant or AWN you will see all available packages for AWN, choose what you think you will need and install it.

    Start it from another terminal like we did with dcompmgr:

    Code:
    # avant-window-navigator
    

    If all goes well you should now see the standard AWN bar somewhere on your screen (middle top or middle bottom), go into the AWN settings and edit it to your hearts content.
    What I added to solve my application launcher problem is the "Yet Another Menu Applet".

    After adding the volume control, date and a few applications to the taskbar I ended up with this setup:

I'll get to the icon theme a bit later. But that is it, a functional "office friendly" application launcher, nice!


There are times when the composite manager will crash for some odd reason, like mentioned earlier dcompmgr crashes whenever I start Steam or play a Steam game. You can always start the composite manager from a terminal, but even if you open it in the background you need to have that terminal open at all times otherwise the program will stop.

The solution to this is to bind the composite manager to a key on the keyboard and then use this to start the composite manager whenever you need to. Painless and elegant.

Look for the post on binding key to see how to do it.

Openbox, the lazy way...

I have recently switched over to OpenBox because I just had enough of random KDE bugs, especially with regards to plasma eating 99% of the CPU, and so far I'm very, very pleased with the result.

For the uninitiated out there, there is one thing you have to remember is that people think you know everything to know about coding and scripting once you tackle a more "advanced" window manager, so be prepared for hours of frustration while trying to figure out the smallest detail. Take heart though, someone like you have gone through it before and is willing to share his knowledge.

To me the main problem with Fluxbox, Openbox and all the other *box window managers is that they are not geared for the person who has productivity as a high priority. As an office worker you do not have time to call up a terminal type out the command for OpenOffice Writer.
You want to browse a file in a file manager, click on it and let the rest just happen.

That is why, after this long silence, I'm going to blog my progress and what I did to make OpenBox as "office friendly" as one can get.
Each post will be a different feature to make it easy to follow and reproduce without reading stuff that doesn't concern you at that time.

Just a few notes before I get started:
I'm not going to handle the installation of all the various software. I'm using Arch Linux and have no idea what some of the software are named and how they are installed on other distros.
Use Google for that, if you want to know how to install Avant Window Navigator on Ubuntu then search for:
"Avant Window Navigator"+Ubuntu+install

This goes for all other software as well.

If you have questions, ask!
I will answer whatever problems you have, so fire away!

That is that. Enjoy!

Enjoy some videos after reading the blog!

Loading...