[1+1=2]

OneAndOneIs2

« Heart of Linux - part 3Heart of Linux - part 1 »

Sat, May 28, 2011

[Icon][Icon]Heart of Linux - part 2

• Post categories: Omni, FOSS, Technology, My Life, Programming, Helpful

So having done my best to explain why the core software of Linux, whilst it might be considered "old-school" by some, is still more than worth a look, I moved onto the command-line-heavy section of my talk.

Despite having been a Linux user for.. rather more years than I care to admit to, come to think of it.. I was only ever a hobby user until last year.

Admittedly, that hobby saw me build a computer to install Slackware on, progress to LinuxFromScratch, and then a migration to Gentoo before it became easiest just to shunt Ubuntu onto whatever computer I happened to be using at the time.

But last year, I went to work as a programmer for a company that's all-Linux. The web servers run Linux, the client servers run Linux, and our desktop PCs run Linux. Specifically, the latest Ubuntu LTS (10.04?)

Now, I've used Ubuntu for years and I knew that Gnome would get on my nerves eventually. But I had more pressing things to worry about, so I stuck with it as long as I could.

I managed a couple of months. There were niggles and issues, but I gritted my teeth and bore with it until one day, I snapped.

It was a trivial issue, really: Gnome-screensaver was conflicting in an odd way with xscreensaver, and I wound up unable to change any of my screensaver settings. Which was annoying, because the screen kept locking me out.

So in what might be considered a slight over-reaction to a malfunctioning screensaver, I sacrificed an hour of productivity and wrote my own GUI.

I started with an old, old friend: FVWM2. The first WM I ever used, and my perennial favourite. I found an old config file on my web server that had enough basic settings to save me some time, and the rest of what was needed to get it into a workable state, I burned through quickly and got back to work with.

I've continued to tweak it ever since, but it's only ever been tweaks: The core functionality was added in an hour or so. Admittedly, it would take considerably longer than that for a newcomer. But the point still stands: If you can spare a few hours to sit down and write your own GUI, I heartily recommend you do so.

Because the thing to remember about Gnome, KDE, et al, is that they're designed to be pretty good for the average user. Which means that they'll never be PERFECT for YOU. And although it might seem like they're a good starting place, being very customisable, I find it harder to change an existing setup than it is to build a new one from scratch.

So I have a GUI that is 100% tailored to do what I want it to do. Which means it's got a plethora of shortcut keys; does massively helpful things for a dual-monitor setup, and does next to nothing other than make it very easy for me to organise and use multiple command-line sessions.

For starters, here's my list of shortcut keys, which are accessed via holding down the Windows key plus the letter:


c - Center window in screen
d - Detatch all screen sessions
e - Deiconify all windows
h - Resize ^h - move
j - Resize ^h - move
k - Resize ^h - move
l - Resize ^h - move
m - Maximise window
n - Iconify window
o - Toggle screen cursor is in
s - Toggle window sticking to screen
t - Toggle window between screens
w - Toggle window handles
x - Display window list
z - Display main menu

The Start key (which is Meta 4 in Ubuntu) is my 'command' key for everything in FVWM. So Start-arrow will move me between virtual desktops. Start-Z gets me my main menu - and unlike Windows, Gnome, KDE etc., the main menu pops up wherever my mouse is instead of requiring me to move the mouse all the way to that corner - which can take a while when you have two screens and you're in the wrong one.

Although it takes less time when you have a script to toggle your cursor between screens, which I have thanks to some X11 scripting and creative use of a little C program...


#include<stdio.h>
#include<stdlib.h>
#include<X11/Xlib.h>

int main(int argc, char *argv[])
{
XEvent e;
Display *d = XOpenDisplay(NULL);

if(!d)
return EXIT_FAILURE;

/* get info about current pointer position */
XQueryPointer(d, RootWindow(d, DefaultScreen(d)),
&e.xbutton.root, &e.xbutton.window,
&e.xbutton.x_root, &e.xbutton.y_root,
&e.xbutton.x, &e.xbutton.y,
&e.xbutton.state);

printf("X: %d\nY: %d\n", e.xbutton.x, e.xbutton.y);

XCloseDisplay(d);

return EXIT_SUCCESS;
}

That's "getcurpos.c" - allows me to find where my mouse is. And this is the shell script that makes use of it to toggle me between screens:

#!/bin/bash

# get monitorWidth
monitorLine=$(xwininfo -root | grep "Width")
monitorWidth=$((${monitorLine:8}/2 ))

# Get mouse pointer position
mXPos=$(getcurpos | grep "X")
mXPos=${mXPos:3}
mYPos=$(getcurpos | grep "Y")
mYPos=${mYPos:3}

# Calculate new mouse pointer position
if ((${mXPos} > ${monitorWidth}))
then mXPos=$(( ${mXPos} - ${monitorWidth} ))
else mXPos=$(( ${mXPos} + ${monitorWidth} ))
fi

# Move mouse pointer to other screen
$(xdotool mousemove ${mXPos} ${mYPos})

I have another that moves the window as well as the cursor. It makes it incredibly easy to navigate my two monitors.

My main menu is severely minimal: It has half a dozen ways of starting up xterms, a few other entries for regularly-used software - Firefox, Evolution, Gimp and Virtualbox - and nothing else.

Any other applications I need, I use Alt-F2 to bring up an application called fbrun, which allows me to type in any application name and have it run.

As a general rule, I have graphical apps in my left-hand screen - Firefox, Evolution, Windows via Virtualbox, etc - and Xterms on my right. I keep the xterms "stuck" so they stay put when I switch desktops.

The only other thing of any major note in terms of my GUI are what I call "TinyTerms" - these are simply xterms run with a font size of two. Too small to be legible, but wonderfully good at monitor duty. I can see what logs are being updated, and usually tell from the pattern of text whether what's come out was an error or a successful request. All with a minimum of screen estate taken up by them. I recommend them to anyone who needs to monitor any kind of logs.

Because TinyTerms are only good for looking at - far too small to type useful commands in - it's a given that I never them to be my active window. This means there's no point them being in my alt-tab window list. Nor will I want to move them around, so I don't need titlebars or window handles.

FVWM2 allows me to make all this happen. In my top right screen corner, I have several TinyTerms providing me with masses of useful data at all times, without using up more than a fraction of my screen estate nor cluttering my window list.

Oh, and my window list? I actually have two of them. Alt-tab shows me all the windows on my current screen. Start-X shows me all windows on all screens. It's helpful to have the choice.

So I created a GUI that renders the mouse almost superfluous (I once worked out that using the mouse instead of all my shortcuts would add up to about an hour's worth of lost time PER DAY) and in fact, via mousekeys (you can usually activate these through Shift-NumLock) and the Vimperator Firefox extension, I can in fact quite happily go mouseless if need be. And that freed me up to do what I really need to do all day, which is mess around with text files via a text-based interface.

I contend that, even if using a 100% FOSS desktop, if you can only use it via GUIs, you're still not truly free: Yes, all those helpful menus and dialogues make it easy to do what you want. But you can only do the things that the GUI-maker has put in a way of doing.

For example: Suppose you go on holiday, and take a bunch of photos with your digital camera. Now you get home and you want to organise them into a photo album. So you want them saved in a directory called "Elbonia '11". You also want them renamed from the usual camera filenames of "DSC000123.JPEG" to the format "Day01_Photo01.jpg". Lastly, because your hard drive isn't so big and also because you want to upload these to share them online, you want to shrink them down to a maximum width of, say, 800 pixels.

If all you know how to use is a GUI, you have two choices: Pray that somebody has written a GUI that does all these things for you; or prepare yourself for lots of simple, easy, but tedious point-and-click-ing.

But if you can employ a little command-line-fu, you can use the output of "ls -l" to give you all the info you need for the new naming convention; you can use 'convert' or 'mogrify' from the ImageMagick suite to resize all the images, and you'll be done in no time. And you can then re-use that script for any future holidays and be even faster in future!

GUIs are easy, but limiting. They only allow you to do what the GUI creator programmed it to do. The command-line, by being able to tie many simple commands together so well that you can't distinguish between a built-in system command and a command that's really just a bunch of other commands tied together; can do ANYTHING.

And for that matter, all GUIs are text at their heart: All computer code is still based on code written in text files. All it takes is a little time on a text editor, and you can make any application you may find on your Linux computer do ANYTHING you want.

This is something it's worth pausing and thinking about for a moment. We all know that Linux is open source, free software, etc. We know that you can get the source code for almost any application you run on it. But how often do you really think about what that MEANS?

It means you, personally, could download a bunch of text files, from the internet, for free, without any restrictions based on who you are, who you work for, or anything else. You, and anyone else in the world, without limit, can download a bunch of text files, which you can easily and legally edit in any way you like, and then you can compile those text files into a suite of applications that can initialise and boot your computer, and then run almost any application imaginable on it.

And I know this from firsthand experience, because I've actually done just that, when I installed LinuxFromScratch.

When you think about all the ways in which many very rich and influential organisations try to exert control of hardware that you personally bought and own outright, this really is something amazing. Think about your DVD player - it's annoying as hell, isn't it, that that little black box that YOU OWN won't allow you to put in a disc that YOU OWN and watch the movie on it, without first bombarding you with "Piracy is bad" slogans and "Here's some adverts for other stuff you don't care about" that you CANNOT SKIP.

Your hardware, your property.. and you don't control it. Sure, it seems trivial.. but how many other places do you have computer hardware? Your computer, obviously, has lots. Your car's got it. So's your phone. And your camera.

When you think about the draconian direction that some content-creators are trying to push technology, it should be an overwhelming relief to know that there's an alternative that, whatever faults it may have, will never, ever say "No, I won't let you do that" because if it did, you could just re-write it not to.

If you think that, say, Disney wouldn't like the idea of making your digital camera refuse to take pictures whilst you were in Disneyland, ostensibly on the grounds that it might infringe their copyright, but really so they can make you pay them to take authorised souvenir photos, then I don't know what planet you've been living on but it certainly isn't this one.

So, to come back to my point, it's my genuine belief that you only truly control your computer if you can use its command line. And I genuinely enjoy using the command-line: I don't fall back on it out of protest when there's not a GUI to do what I want. It's my first choice for almost any task.

One thing I may never forgive Ubuntu, Suse, Gnome, KDE, etc. for, is the way that they've all perpetuated the belief that the command-line is an arcane, scary, hard-to-understand place that needs to be hidden as much as possible. When in fact, although I will absolutely admit that it needs a bit of learning, the Linux command-line is the most well-integrated, consistent, and useful environment that I have ever encountered. And I've programmed on Windows with Adobe Homesite; and I've developed for the iPhone using Xcode on OS X, and I find both of them actually painfully bad for programming compared to a Linux machine with my own GUI, the bash shell, the Vim text editor, and the GNU applications.

Oh yes.. GNU. Most Linux users will have heard at some time or another that they should call it GNU/Linux. And they've probably wondered why. And this is actually a valid question, these days. After all, who USES the GNU stuff these days?

I put this question to the audience when I was giving a talk. Bearing in mind, this was a Linux User Group. I asked them to name some GNU applications. They managed a half-dozen or so. Then I asked them how many they used on a daily basis. Blank looks. One person got a half-mark for saying she used "ls" a lot. That was about it.

So.. why should anyone call it GNU/Linux when they don't USE the GNU tools? Why not call it Gnome Linux or KDE Linux instead? Do we need to say "I use Mozilla Gnome Xorg Gnu Linux" in order to be consistent with our naming convention?

Well, maybe you do. I personally have no problem with saying "I use GNU/Linux" because I use a multitude of GNU software, all day every day. In fact, I'd be hard pressed to get through my working day without it.

And I'll go into detail about that in part 3.


4 comments

Maxim Z.
Comment from: Maxim Z. [Visitor] Email
Hey, great series of articles! I've always loved your blog, but this is my first comment on it. Thanks for these tips - I completely agree with you.

Quick question: could you release more of your GUI? That sounds like something I'd love to use.
30/05/11 @ 00:46
crb3
Comment from: crb3 [Visitor]
"I asked them to name some GNU applications. They managed a half-dozen or so. Then I asked them how many they used on a daily basis. Blank looks. One person got a half-mark for saying she used "ls" a lot. That was about it."

Maybe they couldn't name it, but, without GNU's libc, the Linux kernel wouldn't do much of anything end-user useful in the typical distro; it's in constant use under the hood. AFAIC, even ignoring the build-environment, that one chunk of code earns Richard his spliced naming (GNU/Linux) when one is being precise (with the proviso that its casual nickname is still a simple 'Linux').
31/05/11 @ 01:03
oneandoneis2
Comment from: oneandoneis2 [Member] · http://geekblog.oneandoneis2.org/
@max: Thank you, and thanks for de-lurking ;)

I do intend to do release something for my GUI, as soon as I tidy up some final niggles I have with it.

@crb3: True, but kind of proves my point, really - it's not that the GNU stuff isn't there/used, it's that it's not generally VISIBLE. Early Linux users *lived* on the command line and used the GNU suite pretty much nonstop. Nowadays you get people who can't even name a GNU application, and they're the ones who wonder why they should call it GNU/Linux.
31/05/11 @ 20:42
roliver
Comment from: roliver [Visitor] Email
@oneandoneis2: I would also be interested in seeing some more of you GUI. I really like the idea of using a WM but I think I'd struggle without the eye-candy that DEs provide. Credit to you by the way for completing Linux from Scratch, I got about half way through before I got bored and switched to arch! I'm just not sure I could survive without a package manager!
28/06/11 @ 01:21
 

[Links][icon] My links

[Icon][Icon]About Me

[Icon][Icon]About this blog

[Icon][Icon]My /. profile

[Icon][Icon]My Wishlist

[Icon]MyCommerce

[FSF Associate Member]


July 2014
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Search

User tools

XML Feeds

eXTReMe Tracker

Valid XHTML 1.0 Transitional

Valid CSS!

[Valid RSS feed]

blog software