Tag Archives: i3

Building a Volume Popup using Dzen2

If you have been following my blog at all lately, you’ll know that I’ve been pretty obsessed with my brand new ASUS ux305. After browsing /r/unixporn for days without doing anything, I decided to take a stand against my bland i3 setup and get things rolling. One of the things that has always bothered me about my Linux machines is the fact that a lot of the hardware keys don’t work because I am too lazy to make them work.

This was changing. Now.

So far, for my volume keys, I had them hooked up to a small BASH script which called on alsamixer to raise or lower the volume by 5%. My volume level is also continuously displayed in a conky panel at the bottom of my screen; however, the conky panel only updates every second, and sometimes this second is a little too slow when the volume button is being pressed in rapid succession. Thus, I needed something to alert me in realtime when I was changing the volume.

The main thing I was interested in was making something like GNOME or OSX have – something that pops up and alerts you of the volume (Preferably without an annoying popping noise). Something like this:

volumetrickformacIn order to do so, I needed to find a tool that would display something on the screen. Some sort of notification/message platform that was extremely lightweight. I have heard of some of my friends using dzen2 to power their panels, so I decided to look into that. It was the perfect solution. Basically, now every time I call my volume changing scripts, I can display the current volume level in some sort of alert.

First, I had to create an alert script that would make my alert designs a little more portable and easily customizable. I went with something that allowed me to create alerts in both the middle and the top of the screen and with colors that matched my status bar. The result was this mess:

# This script shows an alert using dzen                                         
screenWidth=$(xdpyinfo | grep 'dimensions' | egrep -o "[0-9]+x[0-9]+ pixels" | sed "s/x.*//")
screenHeight=$(xdpyinfo | grep 'dimensions' | egrep -o "[0-9]+x[0-9]+ pixels" | egrep -o "x[0-9]*" | sed "s/x//")
let "middleY = $screenHeight / 2 - ($HEIGHT/2)"                                 
let "middleX = $screenWidth / 2 - ($WIDTH/2)"                                   
if [ "${2}" == "top" ]; then                                                    
        echo $1 | dzen2 -fn "DejaVu Sans Mono 8" -p $3 -h $HEIGHT               
        echo $1 | dzen2 -fn "DejaVu Sans Mono 8" -p $3 -y $middleY -x $middleX -h $HEIGHT -w $WIDTH &

Basically, this script takes 3 arguments – The message, the position, and the wait time. This is all of the information I am going to need to ever specify for my popups. Now all that is left is to get the volume buttons working with the script. My volume buttons are already linked to two scripts via my i3 config file, mainly the two lines:

bindsym XF86AudioRaiseVolume exec $HOME/.i3/bin/raiseVolume.sh
bindsym XF86AudioLowerVolume exec $HOME/.i3/bin/lowerVolume.sh

The final step is simply creating the lowerVolume.sh and raiseVolume.sh scripts. They are simple, now. They basically call amixer to handle the volume control, save the output, and display it in an alert. Here’s the code to lowerVolume.sh

volume=$(amixer -c 1 set Master 5%- | egrep -o "[0-9]+%")                       
`$HOME/.i3/bin/showAlert.sh "Volume: $volume" middle 1`                         

Note that this uses our alert script to display a message in the middle of the screen for 1 second. It’s perfect. The raiseVolume.sh script is exactly the same, but there is a “5%+” instead of a “5%-“.

The end result is beautiful.


This alert system will soon be implemented into the script I use to detect new emails and brightness keys, once I get them working.

I Dislike The Mouse


My Desktop

The above picture is a screenshot of my Linux machine. What is unique about it? Well, everything is controlled by the keyboard. I have a tiling window manager (i3) and do all of my text editing in vim. What does this mean? It means that I rarely touch the mouse.

I grew up using Windows. It was my primary operating system for the past 10 or 11 years. I got very used to it, its semantics, and using the mouse+keyboard combo in order to navigate around my Windows machine. There was nothing wrong with it. As I got more into computers, however, I got bored of using Windows. There’s nothing wrong with the operating system – I just got bored of using the same thing for 10 straight years. Because of this, I installed Linux.

When I first install Linux, I tried to emulate my Windows experience as much as possible. I installed LXDE as my desktop environment and Openbox as my window manager. I used these just like I used Windows.

As I used Linux more and more, though, I realized that most of the power of Linux was not in the interface, but rather, the terminal. This led me to be in the terminal a lot more than I ever was. I no longer needed a file manager as I did all of my file operations in the terminal. I no longer needed desktop icons because I launched everything in the terminal. Eventually, I no longer needed my mouse to switch Windows, as I just used keyboard shortcuts. I no longer needed my mouse to open terminals because I used keyboard shortcuts.

What did I need my mouse for, then? I decided to experimentally ditch the mouse entirely and switch to a tiling window manager that allowed me to manipulate my windows and their positions by just using the keyboard. At first, I used Awesome. However, Awesome felt very static. In order to move windows around, I had to switch the layouts entirely. I wanted something more dynamic, so I switched to i3.

It definitely took some getting used to. I had to train myself to not reach for my mouse every time that I wanted to do something. Eventually, however, I got used to it. Once I did, it felt awesome. It made me feel like a whole new breed. I was able to rearrange windows, launch applications, and do everything from my keyboard. Not to mention that when my mouse isn’t around, it has the added bonus of keeping people from using my computer since they don’t know how to use things.

As I practiced more and more, I felt that I was getting faster and faster. In fact, I felt that I was doing things faster than if I needed to reach for my mouse. Need to listen to Spotify and type some notes at the same time? Easy.
<WINDOWS>+3 – Switch to a new Desktop
<WINDOWS>+D – Open the app-launcher
‘spotify’              – Launch spotify
<WINDOWS>+B – Open the next window to the right of Spotify
<WINDOWS>+<ENTER> – Open a terminal window
‘vim notes.txt’   – Launch vim and write some notes
Of course, this is a lot of steps, but they can be executed very quickly without reaching for the mouse to resize the windows in order to get the right proportions between the vim and Spotify windows.

Of course, as time goes on, I will only get faster and faster. However, this experience has made me realize that I really dislike using the mouse. Of course, this experience is only on my laptop, where I often find myself reaching for my touchpad because it is easy to reach with the keyboard so close. However, I plan on getting a new Desktop soon and installing Linux on it with my i3 setup. I am excited to see how everything will end up working out on my setup with two monitors and so much screen space. I will report back.

If you’re wondering whether or not you want to take a shot at using a computer without the mouse, try it. It’s a great experience and it looks super awesome whilst doing it.