Showing posts with label awesome. Show all posts
Showing posts with label awesome. Show all posts

Sunday, June 24, 2012

12 - Hour clock in Awesome WM

Awesome Window Manager comes with a widget called "Text Clock" that displays the time in a text box in the upper right-hand corner of the screen. It is in 24-hour format instead of 12, which can cause some confusion for users used to the standard 12-hour time.  Your options are to live with it, or change it. If you want a Day,date, hours:minute:second: am/pm format, look at the end of this post.

Option one- Living with it
I found a neat trick to convert 24-hour time into 12-hour time. Take 13:00, for instance. Subtract 2 from the second number and get the second number of 12-hour time. (3-2=1, so it is 1:00). At 23:00 you get "1" again, meaning that it is 11 O' clock. This method uses too many brain cycles, so I decided to get lazy and just change the source of the script.

Option two - Taking Action
Use this command: sudo gedit /usr/share/awesome/lib/awful/widget/textclock.lua
where gedit is any text editor. This is the source code for the clock widget. Make a backup of the real one. I was a ninny and didn't do this. The two important lines are lines 22 and 23: format and timeout. Format uses the strftime function to display the time. Some important things to note: %H is 24-hour hours and %l is 12-hour time with a whitespace instead of a 0 in the first digit in 1-digit times. (For instance 9:42 would by 9:42, not 09:42). All you need to change is %H to %l.


Now, you are faced with a decision. By default this resets itself every 60 seconds. If you use %S (seconds), you need to change this setting to "1". (5 is also commonly used, but it's a pain if you log in on a non-multiple of 5). This way the clock will reset every second.


The two lines for me look like this:

%p should be the only unfamiliar one. This means am or pm (great for any basement dweller with odd sleeping habits!).

You will not notice changes right away. Restart awesome. If you did something wrong the text clock may not be there. Just use your old source in place of the one you edited. This is the advantage of always keeping a backup.

Here is the FULL source of my script. This is what it outputs:


---------------------------------------------------------------------------
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2009 Julien Danjou
-- @release v3.4.11
---------------------------------------------------------------------------


local setmetatable = setmetatable
local os = os
local capi = { widget = widget,
               timer = timer }


--- Text clock widget.
module("awful.widget.textclock")


--- Create a textclock widget. It draws the time it is in a textbox.
-- @param args Standard arguments for textbox widget.
-- @param format The time format. Default is " %a %b %d, %H:%M ".
-- @param timeout How often update the time. Default is 60.
-- @return A textbox widget.
function new(args, format, timeout)
    local args = args or {}
    local format =  " %a %b %d, %l:%M:%S %p "
    local timeout = 1
    args.type = "textbox"
    local w = capi.widget(args)
    local timer = capi.timer { timeout = timeout }
    w.text = os.date(format)
    timer:add_signal("timeout", function() w.text = os.date(format) end)
    timer:start()
    return w
end


setmetatable(_M, { __call = function(_, ...) return new(...) end })


-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80


You can replace your script with this and it will give you the output I showed you above.

Sunday, June 17, 2012

Everyday use of Awesome WM

I recently tried out awesome, and I was a huge fan of it. It provides the type of keyboard control that I sought since switching between the keyboard and the mouse is inefficient. Also, constant movement between the keyboard and mouse can wear one down after a long session of computing, so awesome window manager introduces a whole new level of comfort and laziness. The mouse still plays an important part in the usage, but it is a sidekick to the power of the key commands. The one thing that I noticed was that the window manager had a pretty high learning curve. I needed to take some physical notes on how to use it. I ran into a few problems, too, but I overcame them. Here is how I did that.

General Usage
Something that I used to use a whole bunch in XFCE was the session management that would start some programs as soon as I logged in. I liked Clementine, Thunderbird, and GNU emacs to start as soon as I began an XFCE session. In awesome this was a bit harder. I had to manually edit the rc.lua configuration file in /etc/xdg/awesome/rc.lua. I added this to the bottom:

-- Autorun programs
autorun = true
autorunApps = 
{ 
   "clementine",
   "thunderbird",
   "emacs",
}
if autorun then
   for app = 1, #autorunApps do
       awful.util.spawn(autorunApps[app])
   end
end
I did this in gedit with the command "gksudo gedit /etc/xdg/awesome/rc.lua". If this type of configuration scares you, Awesome may not be for you. Awesome is all about configuring the window manager to act just like you want it to with LUA. I do not know LUA, but I still find myself editing the configuration file quite often.

Everyday Things
When I first logged into Awesome, I struggled to find out how to even launch an application. Then I found out about the right-click menu. From there I launched a web browser and found out about win+r. This is the first of the key combinations that I learned. The super, or as it is sometimes called "win" key acts as a controller over the window manager. Win+r will open a prompt that says "run" at the top. Just type the name of a program you want. Important: The Run dialog supports tab completion, so you only need to type the first few letters and then tab.
To launch a terminal, Win+r does the trick. Launch as many terminals as you want. You will notice a weird arrangement of windows. This is because Awesome is a dynamic window manager, meaning it has quite a few layouts. I highly recommend the main-left tiling. To change what layout awesome uses, use win+space or the icon at the very top right side of the screen. The one that I use has the icon of two blocks on the left and 6 on the right. This will have one main window on the left and the rest stacked on the left side of the screen. To switch which window is the main one, focus another one by hovering over it with the mouse, using the window list at the top, or using win+j or win+k. Then, use win+ctrl+enter.
If you grow tired of a Window, minimize it with win+n. If you want the window window to maximize to the whole screen you can usually use win-m. An angelic figure will appear to the right of the maximized window on the window list.
If you used to use Unity, Gnome, XFCE, LXDE, or KDE you are probably familiar with the idea of Desktops or Workspaces. Awesome has tags that can be moved to with the mouse or Win+number 1-6 (win+6 would move to tag 6). These work in the same way.
Advanced
rc.lua can literally be edited to do anything that a Window manager can. Here are some important parts of the config:
Line 55: Change which layouts are moved through with Win-Space
Line 219: Some keybindings
Awesome can be themed quite easily. At the top of rc.lua, add beautiful.init("path_to_theme_file")

Annoyances
I haven't come across many. One is controlling the sound. I was able to do this with a custom keybinding, but for a while I used a terminal with alsamixer in it. On "The Linux Action Show", one of the people stated that they would log out, log into XFCE to change the volume, and log back into Awesome. This is really not necessary.
Advantages
This is the fastest WM I have ever used. It boots in about 3 seconds (literally) and is great with working with text. I have heard that it has AMAZING multiple monitor support with their 9 tags, but I cannot confirm this as I only use one. The thing window border makes great use of screen real estate.