Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

An Example: The GtkEv Widget

This section describes a very simple widget called GtkEv, inspired by the xev client that comes with X. GtkEv has two components: a small sub-window that receives events, and a larger window where information about each event is reported. Figure 1 shows GtkEv in action. The complete GtkEv source code is in Appendix E. GtkEv would be a lovely way to implement an xev-style application for Gnome; it packages the core application functionality in a nice module.

Figure 1. The GtkEv widget. Events are reported for the white subwindow.

Overview

GtkEv uses two GdkWindows; the larger one, GtkEv's widget->window, has a gray background and is used to render text describing each event. The smaller one is a child of the primary window, and is the window the widget reports events for.

Here are the class and instance structs for GtkEv:


typedef struct _GtkEv       GtkEv;
typedef struct _GtkEvClass  GtkEvClass;

struct _GtkEv
{
  GtkWidget widget;
  
  GdkWindow*     event_window;

  GdkRectangle   event_window_rect;

  GdkRectangle   description_rect;

  GList*         buffer;
  GList*         buffer_end;
  gint           buffer_size;
};

struct _GtkEvClass
{
  GtkWidgetClass parent_class;


};
      

As you can see, GtkEv has no class functions or signals of its own. Each instance stores a pointer to the small event window in event_window. Two rectangles cache the area covered by the event window, and the area covered by the event description text. The widget's allocation is divided between these two areas. Finally, GtkEv stores a list of string vectors describing events; it caches the end of the list and the length of the list. As events are received, text describing them is pushed on to the front of the buffer. When the list becomes too long to fit on the screen, GtkEv removes an event from the back of the buffer each time it adds a new event to the front, keeping the buffer size constant.

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire