Quantcast
Username/Email:  Password: 

Introduction to Microwindows Programming, Part 2

Check out the recent additions to the Microwindows Project.

A lot has been happening since the first article (ELJ January/February 2001) in this series. In the last couple of months, we've worked hard to enhance Microwindows for the Linux PDA environment, and it sure has been fun! This time I'll cover some of the recent additions to the Microwindows Project and show how to take advantage of these new features with specific programming examples. Many of the enhancements have been written to take advantage of the Compaq iPAQ handheld PDA. In addition, a complete working Linux kernel for the iPAQ, along with a screentop operating environment, precompiled binaries, cross-development libraries and toolchains for Microwindows, is freely available from the Century Software web site at http://embedded.centurysoftware.com/. You can use this runtime and development environment along with the information in this article to develop your own applications for the iPAQ or any other embedded system running Linux. Another great site for the iPAQ is http://www.handhelds.org/. So let's get started!

New Nano-Window Manager

Similar to the X Window System, Microwindows also sports a low-level, Xlib-like graphics API known as Nano-X. As we mentioned in the last article, this client-side library starts a connection with the Nano-X Server and directs the graphics draw requests from the application to the server, where they are formatted onto the kernel framebuffer, which is mapped into the server's address space. The basic data structure used for all drawing is the Window ID, which reserves a portion of the physical display memory as a destination at which all drawing occurs. The Nano-X server doesn't allow any drawing outside a given Window ID, which is specified in every graphics request. But what about window titles, close boxes, borders and all that good stuff? How does that portion of a window get drawn? Like X, Nano-X uses a separate application called a window manager to accomplish this.

The Nano-X Window Manager is a completely normal Nano-X application, except that it selects certain events that also go to user applications, for its own inspection in order to draw window decorations outside of the standard window area and manage mouse or pen-down operations outside the main window area. After the Nano-X server is started, it's usual to start the new window manager, called nanowm, next. The idea is that the look and feel of the operating environment, including what a window caption looks like, what font to use when drawing the title text and whether to run an application full-screen, is actually calculated and performed by the window manager. In this way, application code can stay the same for PDAs and WebPADs, for instance, but running a different window manager could manage the screen real estate differently between the systems.

The source code to the window manager is located in microwin/src/demos/nanowm. Let's get a basic overview of how it functions, and at the same time, discuss the ways a client application can control its own look and feel and behavior. The window manager relies on a neat trick to know whenever an application creates a new ``top-level'' window in the system. Technically, a top-level window is simply a child window of the initial root window created by the server at startup. By requesting update events, any application can be notified when a given window is updated. So one of the first things the window manager executes is:

GrSelectEvents(GR_ROOT_WINDOW_ID,
<@cont_arrow>å<@$p>GR_EVENT_MASK_CHLD_UPDATE);

This specifies that the Nano-X server should send GR_EVENT_TYPE_UPDATE events to the window manager whenever any children of the root window are updated, including when they are created. Here are the subtypes for update events:

  • GR_UPDATE_MAP--sent when a window is initially displayed.

  • GR_UPDATE_UNMAP--sent when a window is hidden.

  • GR_UDPATE_MOVE--sent when a window is moved.

  • GR_UPDATE_SIZE--sent when a window is resized.

  • GR_UPDATE_UNMAPTEMP--sent instead of UNMAP during user move or resize operations.

  • GR_UPDATE_ACTIVATE--sent when a top-level window is activated/deactivated.

  • GR_UPDATE_DESTROY--sent when a window is destroyed.

The window manager waits for initial window mappings for children of the root window, and when it gets one, it uses another cute trick called window reparenting. Initially, the application window's parent is the root window, but the window manager executes the following:
container_window_id = GrNewWindow(GR_ROOT_WINDOW_ID,
x, y, width,height, 0, BLACK, BLACK);
GrReparentWindow(app_window_id,
container_window_id, 1, 12);
The first statement creates a new, top-level ``container window'', which is the window in which it will draw the title bar, close box and borders. The second statement ``reparents'' the application window from the root window to this new window and sticks its inset as a child window at 1,12 offset, which is 1 pixel in for the left border, and 12 pixels down to leave room for the caption. The GrReparentWindow call effectively redirects the application window to start a new life as a child of the window manager's decoration window. Next, the window manager reads the application specified window properties and uses them to determine the style that the application window should appear as. This is where different window managers can interpret various properties to make applications appear differently. The window properties are read using the call:
GR_WM_PROPERTIES props;
GrGetWMProperties(app_window_id, &props);
The GR_WM_PROPERTIES structure is declared in nano-X.h as follows:
typedef struct {
   GR_WM_PROPS flags;    /* Which fields are
                          valid in structure*/
   GR_WM_PROPS props;   /* Window property bits*/
   GR_CHAR *title;       /* Window title*/
   GR_COLOR background;  /* Window background color*/
   GR_SIZE bordersize;   /* Window border size*/
   GR_WM_PROPERTIES;
}
The flags field is used only when setting property bits. The actual window property bits that can be specified by an application can be divided into two categories: general properties and decoration styles. Following are descriptions of each of the window property bits.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Why can't install Nano-X through YUM, Apt or YAST?

Vikas's picture

Hi,

Installing from the source code is pain in the ass, i have been installing this for the past 2 days, it needs Freetype1.3.1 which is not available for fedora 12, when tried to install this from source it again gave me few errors.. andway i forced installed it.. after i try again Nano-X it said few files where missing so i make soft link to Freetype 2 which luckily it worked.

Can't the installation be made more simpler?????

I tried to program but the site itself doesn't hosts and examples nor you will find anything after googling. luckily i found this article.

I hope you can fix these two problems..

1. Write a article on how to install on latest versions of Fedora, Ubuntu or Opensuse.

2. Sample programs as how to program Nano-X and run it, for absolute beginners.

Thnx in advance.

Vikas

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.
  • Use to create page breaks.

More information about formatting options