Debian Linux Fundamentals-Graphical User Interface - Software Foundations - Hacking Raspberry Pi (2014)

Hacking Raspberry Pi (2014)

Part II. Software Foundations

Chapter 6. Debian Linux Fundamentals-Graphical User Interface

“Why run a graphical user interface (GUI, pronounced gooey) at all on a Raspberry Pi?” some computer enthusiasts complain. They’ll tell you that the Pi’s hardware is slow enough as it is. Not to mention that any self-respecting Linux user should be able to accomplish everything he needs by using the command line.

Yes, some Linux aficionados take user experience (UX) matters that seriously. And with the Raspberry Pi they have a point to a certain extent. Shouldn’t we conserve as much of the Pi’s CPU and GPU resources for actual work instead of for drawing fancy windows?

Well, friends, the raw truth of the matter is that many computer users simply prefer the simplicity and intuitiveness of a GUI. Most of us who have grown accustomed to the keyboard and mouse-based navigational methods in OSs such as Microsoft Windows and OS X don’t want to bother learning something new. Thus, the Foundation saw fit to include a graphical shell in the Raspbian Linux distribution. In this chapter you learn how to start, configure, use, and exit the GUI shell.

LXDE—The Desktop Environment

The official Raspbian Linux distribution includes the Lightweight X11 Desktop Environment, or simply LXDE. The main benefit of LXDE is that it was written to be as light on system resources as possible, while at the same time offering the Linux user as much functionality as possible. I show you the default LXDE Desktop in Raspberry Pi later on in this chapter, in Figure 6.1. Ignore the annotations for now; the “Touring the LXDE Interface” section later in this chapter describes all of the user interface parts.

Image

FIGURE 6.1 LXDE is the default GUI shell in Raspbian.

Oh, in case you are wondering—there isn’t anything wrong with your video if you compared Figure 6.1 with your Pi’s desktop and thought, “Why don’t I see the blue background like Tim has?” I simply swapped out the default white background to one that isn’t so harsh on my eyes. Take heart—you’ll learn how to customize your LXDE environment soon enough.

Understand that LXDE is by no means the only game in town when it comes to Linux GUI desktops in general and system resource-friendly systems in particular. Some popular Linux GUIs include

Image KDE, GNOME (pronounced guh-nome): These are the most popular GUI desktops on full Linux installations. However, you will be hard-pressed to run these GUIs on the Pi because they are too resource-intensive.

Image XFCE: This is the main competitor of LXDE in terms of low-overhead Linux.


Note: X Factor

X-Windows, X Window System, and X11 are all synonyms that refer to the software system and network protocol that makes GUI desktop environments available locally or remotely on Linux systems. You can consider X the “engine” that powers the actual Windowing systems such as GNOME, KDE, or LXDE. Many Linux fans use X generically to refer to the GUI.


Starting and Exiting LXDE

If you started your Pi the traditional way, which is to say, by booting to the terminal prompt, then you can start LXDE by typing startx and pressing Enter on your keyboard.

The most straightforward way to close your LXDE session and return to a shell prompt is to click the Logout button on the LXPanel task bar. We’ll delve deeply into LXPanel as we move through the chapter.

Remember our good friend raspi-config? We can customize boot behavior using this tool.


Task: Using Raspi-Config to Adjust Boot Behavior

To configure your Raspberry Pi to boot directly to the graphical desktop, follow these steps:

1. From a Raspberry Pi terminal prompt, type sudo raspi-config.

2. From the Raspi-Config main menu, arrow down to the boot_behaviour option and press Enter.

3. Answer the question Should we boot straight to desktop? by typing either Yes (to enable GUI boot at launch) or No (to disable GUI autolaunch).

4. When you exit Raspi-Config, answer the question Would you like to reboot now? by typing in Yes and pressing Enter.


Touring the LXDE Interface

Using Figure 6.1 as our guide, let’s review each of the Desktop icons and user interface elements in LXDE. Please continue to ignore the annotations at the bottom of the figure for now; we’ll cover those in just a moment. For now concentrate instead on the icons that run along the left-hand side of the screen.

Image Midori: This is a shortcut to Midori, which is (surprise-surprise) a minimalist web browser that conserves system resources.

Image Scratch: This is a link to Scratch 1.4. You learn how to create Scratch programs in Chapters 8, “Programming Raspberry Pi with Scratch—Beginnings,” and 9, “Programming Raspberry Pi with Scratch—Next Steps.”

Image Pi Store: This is a marketplace for the exchange of Pi-compatible apps. The Pi Store later is covered in more detail later.

Image WiFi Config: This is an incredibly helpful tool for setting up a WiFi connection. You learn about the Pi’s networking options in Chapter 7, “Networking Raspberry Pi.”

Image Debian Reference: This is a shortcut that opens the Dillo web browser and presents the Debian reference pages in HTML format. These files are stored locally, so you don’t need to be connected to the Internet to read the pages. You can see this interface in Figure 6.2.

Image

FIGURE 6.2 Raspbian gives you offline access to Debian Linux help files.

Image IDLE 3: This is the integrated development environment (IDE) for Python 3. As you learn in the next chapter, Raspbian includes both Python 2 and Python 3. Python is the default and recommended programming language for the Raspberry Pi (recall that the “Pi” in “Raspberry Pi” is an indirect allusion to the Python language).

Image LXTerminal: This is the command-line interface for the Pi. You can do everything in LXTerminal that you can from outside of X in the terminal environment.

Image OCR Resources: This is a shortcut that opens Midori and opens the ICT and Computing page of the Oxford Cambridge and RSA Examinations (OCR) website. Basically, this is a site for teachers to get ideas on how to integrate Raspberry Pi into their academic curricula.

Image IDLE: This is the IDE for Python 2.

Image Python Games: This is a simple app launcher that enables you to try out a handful of Python games.

Now let’s turn our attention to the annotations at the bottom of Figure 6.1. Because there are so many tiny icons, I thought than numbering them would make it easier for you to differentiate them.

1. Main Menu: An app launcher that functions the same way the Windows 7 Start menu does.

2. PCManFM: A lightweight file manager that functions the same as Windows Explorer or the OS X Finder. You can take a look at PCManFM in Figure 6.3.

Image

FIGURE 6.3 The PCManFM file manager.

3. Midori: The lightweight web browser.

4. Minimize All: When you click this button, all onscreen windows minimize to the LXPanel.

5. Virtual Desktops: Linux has had this capability for a long time. You get two desktops by default, but you can customize this number by right-clicking one of the virtual desktop icons, selecting Desktop Pager Settings from the shortcut menu, and adjusting the Desktops options in Openbox Configuration Manager.


Note: Understanding Virtual Desktops

A virtual desktop in the context of Linux in general and the Raspberry Pi in particular is a software-based method for extending your computer’s desktop environment beyond the borders of the physical monitor. That is, you can have multiple copies of the desktop that each display separate application or document windows. This technology is less expensive, although less convenient, than connecting multiple physical monitors to your computer.


6. LXPanel (the bottom bar as a whole): Behaves exactly like the Task Bar in Windows 7. Actually, every element you see on this bar is nothing more than an applet that is enabled in LXPanel. To customize LXPanel, right-click an empty part of the task bar and select Panel Settings. Select the Panel Settings option to turn LXPanel panel applets on or off.

7. CPU Usage Monitor: Gives you real time, at-a-glance data on how busy the Pi’s CPU is.

8. Digital Clock: Right-click this applet and select Digital Clock settings to edit it. The clock format uses a wonky, propeller-head style; visit http://is.gd/XHcNwN to learn the syntax.

9. Screenlock: You click this button to protect your Pi against unauthorized access while you aren’t using the system.

10. Logout: You use this control to leave X and return to a terminal prompt, reboot the system, or shutdown (halt) the Pi.

Buttons B–D represent what is called the Application Launch Bar. The three shortcuts that exist there by default are simply that—defaults. To add additional shortcuts to the Application Launch Bar, right-click one of the app shortcuts and select Application Launch Bar Settings from the shortcut menu.

Essentially the entire bottom task bar in LXDE represents the modular LXPanel. It’s quite a nifty toolset, actually. For more information on LXPanel, visit http://is.gd/yINVrP.

Delving into the Main Menu

The Start menu has worked well for Microsoft operating systems since Windows 95. Personally, I’m furious that Microsoft removed the Start menu from Windows 8; however, that is a discussion for another time. The good news for fans of the functionality the Windows Start menu used to give us, is that you’ll find one very much like it here.

Because the LXPanel Main Menu is such a central part of the LXDE user experience, I wanted to spend a bit of time giving you the lay of the land with this tool. You can see the expanded Main Menu in Figure 6.4 (I highlighted the Main Menu button to make it easier for you to identify).

Image

FIGURE 6.4 The LXPanel Main Menu functions similarly to the Windows 7 Start menu.

Following is the top-level navigation of the Main Menu:

Image Accessories: Here you will find links to an image viewer, the Leafpad text editor, LXTerminal, and the Xarchiver zip/unzip tool, among other tools.

Image Education: Here you can launch Scratch or its underlying Squeak management tool. Scratch is based on an old programming language called Smalltalk, and Squeak is the specific Smalltalk dialect that is used in Scratch.

Image Graphics: Here you can view Adobe Acrobat Portable Document Format (PDF) files by using the open-source xpdf viewer.

Image Internet: Here you can open the Midori and Dillo lightweight web browsers, as well as configure Wi-Fi settings.

Image Office: Here you find the tiny yet functional Orage Calendar and Orage Globaltime utilities. These tools are actually part of the XFCE desktop environment briefly discussed earlier in the chapter.

Image Other: This is a catch-all bucket for tools that the Raspbian developers could not or did not want to pigeonhole into another program group. You’ll find a little of everything in this folder.

Image Programming: As expected, from here you can launch Scratch or the Python 2/3 IDLE development environments.

Image Sound & Video: Here you can open a simple audio mixer application to configure Pi’s onboard audio. Remember that system audio comes directly from the Broadcom SoC; there is no dedicated sound “chip” on the Pi PCB.

Image System Tools: Here you can rename files, view and manage running tasks, and use the Thunar File Manager (Thunar is nothing more than an alternative to PCManFM).

Image Preferences: This folder contains several file and system management utilities.

Image Run: You can use Run to issue terminal prompt statements from the GUI. This tool is directly analogous to the Run box in Windows 7.

Image Logout: Exit and return to the command prompt environment.

The ordering and organization of the LX Panel Main Menu feels haphazard and not well thought out to me. Surprisingly (or not, depending on your attitude about Linux), there is no graphical method for customizing the Main Menu. The LXDE Wiki shows you how to manage the *.desktop files in the /usr/share/applications directory to customize the Main Menu; see http://is.gd/OTcpFy for more details.

Installing, Updating, and Removing Software

In Chapter 5, “Debian Linux Fundamentals—Terminal,” you learned how to use the apt-get commands to update configured software repositories and update all installed software, including Raspbian itself. Open up LXTerminal, and let’s now revisit the Advanced Packaging Tool, or apt.

First, what is a repository? In Linux terminology, a repository is an online source of regularly updated installation packages. Repositories are specific (almost) to every Linux distribution.

From LXTerminal, type sudo nano /etc/apt/sources.list to view the list of Raspbian repositories. On my system, the file contained only one line:

deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi

Type CTRL+X, N to exit the sources.list configuration file without saving any changes.

Now let’s review how to find and install software by using apt. But first let’s update the repository:

sudo apt-get update

If you know the name of the software package that you are interested in (let’s say the XFCE graphical environment—why not?), run this command:

sudo apt-get install xfce4

If you don’t remember the precise name of the package of interest, try this:

sudo apt-cache search xfce4

To get a list of installed software packages, you should switch gears just a little bit and use the dpkg command instead, like so:

sudo dpkg —get-selections > ~/Desktop/packages

What the dpkg command does in this context is generate a list of installed packages into a file called packages that will appear on the LXDE desktop. Remember that the tilde (~) character denotes your home directory.

You can then view the list of installed packages by running

nano ~/Desktop/packages

You should know that the apt tools we’ve been using so far represent a (more) user-friendly front-end to the dpkg package management system that has been a component of Debian Linux for quite some time.

In Chapter 5 you were introduced to the man command. Be sure to access the man pages for the apt-get and dpkg commands so you can learn more about them.

To uninstall an installed software package, try this:

sudo apt-get remove xfce4


Note: Performing a Complete Uninstall

To remove both an installed application package as well as any associated configuration files, run the command sudo apt-get —purge remove pkgname.


Finally, by way of review: You’ll want to run the following command periodically to update the repositories known by your Pi system:

sudo apt-get update

Remember that running update is only half the battle; you must also install any detected updates:

sudo apt-get upgrade

Accessing the Pi Store

The Pi Store, shown in Figure 6.5, is the Raspberry Foundation’s version of the Microsoft Store or the Apple Store. The Store is meant to be a place where you can easily find software that has been developed specifically for the Raspberry Pi platform. You can start the Pi Store by double-clicking the desktop shortcut.

Image

FIGURE 6.5 The Pi Store is to the Raspberry Pi what the Apple Store is to a Mac.

To do anything meaningful at the Pi Store (this means downloading software or uploading your own stuff), you must first create a free account. To do this, click Login in the upper-right corner of the Pi Store interface and then click Register.

You’ll observe a few things about the basic operation of the Pi Store. One, as of spring 2013, there aren’t a whole lot of apps in the Store. This situation should improve over time as the Pi develops a critical mass and sizable user base. Two, apps are of both the free and paid varieties. Also you need a PayPal account (http://www.paypal.com) to purchase a Pi Store app.

As with everything else in the open source community, the Pi Store is all about sharing your work with others. Visit the Upload tab in the Pi Store to register as a developer and then begin the process of building and sharing your Pi Store games and apps. There is even the possibility of some extra money if your paid app is successful! Figure 6.6 shows you my newly created developer page.

Image

FIGURE 6.6 When you register as a developer, you get your own profile page in the Pi Store.


Task: Downloading a Free App from the Pi Store

1. From the LXDE desktop, double-click the Pi Store icon to open the program.

2. In the upper-right corner of the Pi Store, click Login, and then click Register to create a free user account.

3. Once you’re logged in, navigate to the Games section and find the free app called CrazyWorms2. If for some reason the game is no longer available, choose another free game.

4. Click Free Download to download the game to your library. Note that the Pi Store takes you from the Explore tab to the My Library tab.

5. To play your newly downloaded game, select CrazyWorms2 in My Library and then click Launch in the right-hand information panel. Have fun!


Tweaking the LXDE UI

In this section I take a task-centered approach in showing you the most common interface tweaks in LXDE. It’s important that I show you how this works so you can make the LXDE graphical environment your own.

For instance, I find the default white background color to be much too harsh for my light-sensitive eyes. Thus, the first interface tweak I always make on my Pi systems is to swap out the background color to something a bit more neutral.

I think you’ll find that LXDE gives you the same kind of control you have in, say, Windows or OS X, but the interface controls are a bit less intuitive to find and use. (Hey, welcome to Linux!)


Task: Change the Desktop Background

Speaking of swapping out the desktop background, why don’t we use that as our first procedure?

1. To tweak the LXDE desktop background, right-click an empty area of the desktop and select Desktop Preferences from the shortcut menu (see Figure 6.7).

Image

FIGURE 6.7 You can customize the LXDE desktop by using GUI configuration applets.

2. You can perform the following actions in the Desktop Preferences dialog box:

Image Change the wallpaper independently of the background color. For instance, to specify a solid color background, set the Wallpaper Mode property to Fill with background color only and then adjust the Background color property.

Image Adjust the font and color of icon label text. To do this, adjust the Font of label text, Color of label text, and Color of shadow properties.



Task: Customize the LXTerminal

I find that even when I’m working in a Linux GUI I still have at least one Terminal session going on at any point in time. Let’s make that command prompt environment as user-friendly as possible, shall we?

1. Open LXTerminal and then click Edit, Preferences.

2. In the LXTerminal dialog box, make any necessary changes. My “tricked out” LXTerminal along with the Preferences window are shown in Figure 6.8. You can perform several terminal configuration tweaks:

Image Change the terminal font and colors. The background color denotes the LXTerminal screen, and the foreground color refers to the onscreen text. You can do this by setting properties on the Style tab.

Image Customize the cursor. For instance, you can change the cursor style from block to underline by editing the Cursor style property on the Style tab.

Image Edit the default scrollback value by adjusting the Scrollback lines property on the Display tab. This is an important setting because it determines how far back you can scroll in an LXTerminal session. For instance, you may display a large text file on-screen and you want to ensure that you can scroll back to see every single line of text.

Image

FIGURE 6.8 You can customize LXTerminal to suit your individual preferences.



Task: Customize the LXPanel

LXPanel represents the primary navigation system used in LXDE, as you’ve already learned. Each component that you see on the Task Bar at the bottom of the LXDE screen represents a particular LXPanel applet. Follow these steps to visit the major configuration touch points:

1. Right-click an applet in the panel and select the first option in the shortcut menu to customize that particular applet. For instance, you can right-click an empty area of the Task Bar and select Task Bar (Window List) Settings to customize the position, appearance, and so on of the task bar. Right-clicking the CPU meter gives you the option CPU Usage Monitor Settings.

2. From any LXPanel shortcut menu, select Panel Settings to open the global configuration dialog for the panel. The Panel Preferences dialog box consists of four tabs:

Image Geometry: Position, size, alignment, and icon of the LXPanel bar.

Image Appearance: Background color and/or wallpaper used to “color” the LXPanel.

Image Panel Applets: Add, remove, and edit the applets that are included on the LXPanel. You can also specify the order in which you want these applets to appear.

Image Advanced: Set preferred applications, task bar hiding, and so on.


Openbox

Let’s finish this part of the chapter by briefly discussing Openbox. Openbox is different from LXPanel; LXPanel is a navigation user interface host, but Openbox is the Window Manager that runs behind LXPanel.

Open the Main Menu and click Preferences, Openbox Configuration Manager. Here you can make further tweaks to applets resident in the LXPanel (the number of virtual desktops, for instance) and globally in the system (see Figure 6.9).

Image

FIGURE 6.9 The Openbox Configuration Manager.

Actually, you can find pretty much everything you want or need, GUI look and feel-wise, by browsing the Preferences program group of the LXPanel Main Menu.

Editing Configuration Files

You’ll find that despite the control that GUIs like LXDE give you over the environment, the unavoidable truth is that you accomplish most tweaking and system configuration by editing text files.

For instance, let’s say that you want to disable the Raspbian screensaver (it looks cool, but it consumes valuable system resources). Now it is true that you can disable or enable the XScreensaver in LXDE by opening the Main Menu and clicking Other, Disable XScreenSaver or Other, Enable XScreenSaver, respectively. You can also change the currently active screensaver by opening the Main Menu and clicking Preferences, Screensaver. However, you can also permanently disable the screensaver by editing the LXDE autostart file with

sudo nano /etc/xdg/lxsession/LXDE/autostart

When you are in the file, you need to remove the following line from the file:

@xscreensaver -no-splash

Simply place your cursor at the end of the line and use Backspace to remove it. Next, press Ctrl+O to save changes and then press Ctrl+X to exit the nano editor. Done and done!

Remember always to invoke sudo when you attempt to edit a configuration file; you won’t be able to save your changes due to the default access permissions that are set on those files.

You are probably asking, “Tim, how did you know to edit the /etc/xtg/lxsession/LXDE/autostart file?” My answer is simple: “Google it.” With Linux, we have a huge community of computer scientists, experts, and enthusiasts at our disposal. I like to tell my students, “If you are experiencing a problem with your Pi, chances are good that hundreds of other people are having the same problem, and somebody has figured out how to fix it.”

To that end, let me share with you some of my favorite Raspberry Pi discussion forums. These online discussion boards are a wonderful way not only to get your questions answered, but also to connect and swap tips with other Raspberry Pi enthusiasts who are located throughout the world:

Image Official Raspberry Pi Forums: http://is.gd/6nBR5Z

Image Element 14 Raspberry Pi Forums: http://is.gd/2urLqa

Image Elinux.org Communities Reference: http://is.gd/yIeGIw