xosview  1.23
About: xosview is an X Windows based system monitor (cpu, memory, swap and network usage; interrupt and serial activities; load average).
  Fossies Dox: xosview-1.23.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

xwin.h
Go to the documentation of this file.
1 #ifndef _XWIN_H_
2 #define _XWIN_H_
3 
4 #include "Xrm.h"
5 #include <string.h>
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8 #include <iostream>
9 
10 class XWin;
11 
12 typedef void (XWin::*EventCallBack)( XEvent &event );
13 
14 
15 class XWin {
16 public:
17  XWin ();
18  XWin( int argc, char *argv[], int x, int y, int width, int height );
19  //XWin( int& argc, char *argv[], char *geometry );
20  virtual ~XWin( void );
21  void XWinInit ( int argc, char* argv[], char* geometry, Xrm* xrmp );
22 
23  int width( void ) { return width_; }
24  void width( int val ) { width_ = val; }
25  int height( void ) { return height_; }
26  void height( int val ) { height_ = val; }
27  Display *display( void ) { return display_; }
28  Window window( void ) { return window_; }
29  int done( void ) { return done_; }
30  void done( int val ) { done_ = val; }
31  void title( const char *str ) { XStoreName( display_, window_, str ); }
32  void iconname( const char *str ) { XSetIconName( display_, window_, str ); }
33 
34  void clear( void ) { XClearWindow( display_, window_ ); }
35  void clear( int x, int y, int width, int height )
36  { XClearArea( display_, window_, x, y, width, height, False ); }
37  unsigned long allocColor( const char *name );
38  void setForeground( unsigned long pixelvalue )
39  { XSetForeground( display_, gc_, pixelvalue ); }
40  void setBackground( unsigned long pixelvalue )
41  { XSetBackground( display_, gc_, pixelvalue ); }
42  void setStipple( Pixmap stipple)
43  { if (!doStippling_) return;
44  XSetStipple(display_, gc_, stipple);
45  XGCValues xgcv;
46  xgcv.fill_style = FillOpaqueStippled;
47  XChangeGC (display_, gc_, GCFillStyle, &xgcv); }
48  void setStippleN (int n) {setStipple(stipples_[n]); }
49  Pixmap createPixmap(const char* data, unsigned int w, unsigned int h) {
50  return XCreatePixmapFromBitmapData(display_, window_,
51  const_cast<char *>(data), w, h, 0, 1, 1); }
52 
53  unsigned long foreground( void ) { return fgcolor_; }
54  unsigned long background( void ) { return bgcolor_; }
55  void resize( int width, int height )
56  { XResizeWindow( display_, window_, width, height ); }
57  void lineWidth( int width )
58  {
59  XGCValues xgcv;
60  xgcv.line_width = width;
61  XChangeGC( display_, gc_, GCLineWidth, &xgcv );
62  }
63  void drawLine( int x1, int y1, int x2, int y2 )
64  { XDrawLine( display_, window_, gc_, x1, y1, x2, y2 ); }
65  void drawRectangle( int x, int y, int width, int height )
66  { XDrawRectangle( display_, window_, gc_, x, y, width, height ); }
67  void drawFilledRectangle( int x, int y, int width, int height )
68  { XFillRectangle( display_, window_, gc_, x, y, width + 1, height + 1 ); }
69  void drawString( int x, int y, const char *str )
70  { XDrawString( display_, window_, gc_, x, y, str, strlen( str ) ); }
71  void copyArea( int src_x, int src_y, int width, int height, int dest_x, int dest_y )
72  { XCopyArea( display_, window_, window_, gc_, src_x, src_y, width, height, dest_x, dest_y ); }
73  int textWidth( const char *str, int n )
74  { return XTextWidth( font_, str, n ); }
75  int textWidth( const char *str )
76  { return textWidth( str, strlen( str ) ); }
77  int textAscent( void ) { return font_->ascent; }
78  int textDescent( void ) { return font_->descent; }
79  int textHeight( void ) { return textAscent() + textDescent(); }
80 
81 
82  virtual void checkevent( void );
83  void map( void ) { XMapWindow( display_, window_ ); }
84  void unmap( void ) { XUnmapWindow( display_, window_ ); }
85  void flush( void ) { XFlush( display_ ); }
86 
87  const char *getResource( const char *name );
88  const char *getResourceOrUseDefault( const char *name, const char* defaultVal );
89  int isResourceTrue( const char* name ) {
90  return (!strncasecmp(getResource(name),"True", 5)); }
91  void dumpResources(std::ostream &os );
92 
93 protected:
94  class Event {
95  public:
96  Event( XWin *parent, int event, EventCallBack callBack );
97  virtual ~Event( void ){}
98 
99  friend class XWin;
100 
101  void callBack( XEvent &event )
102  { if ( event.type == event_ ) (parent_->*callBack_)( event ); }
103 
104  protected:
107  int event_;
108  long mask_;
109  private:
111  };
112 
113  int borderwidth_; // width of border
114  int x_, y_; // position of the window
115  int width_, height_; // width and height of the window
116  Display *display_; // Connection to X display
117  Window window_; // Application's main window
118  GC gc_; // The graphics context for the window
119  XFontStruct *font_; // Info on the default font
120  char *name_; // Application's name
121  XTextProperty title_; // Window name for title bar
122  XTextProperty iconname_; // Icon name for icon label
123  unsigned long fgcolor_; // Foreground color of the window
124  unsigned long bgcolor_; // Background color of the window
125  XWindowAttributes attr_; // Attributes of the window
126  XWMHints *wmhints_; // Hints for the window manager
127  XSizeHints *sizehints_; // Size hints for window manager
128  XClassHint *classhints_; // Class hint for window manager
129  Event *events_; // List of Events for this window
130  int done_; // If true the application is finished.
131  Atom wm_, wmdelete_; // Used to handle delete Events
132  Colormap colormap_; // The colormap
133  char display_name_[256]; // Display name string.
134  char* geometry_; // geometry string.
135  Xrm* xrmptr_; // Pointer to the XOSView xrm. FIXME???
136  int doStippling_; // Either 0 or 1.
137  Pixmap stipples_[4]; // Array of Stipple masks.
138 
139  void init( int argc, char *argv[] );
140  void getGeometry( void );
141  int getPixmap(Pixmap *);
142  void setDisplayName (const char* new_display_name) { strncpy
143  (display_name_, new_display_name, 256); }
144  const char* displayName () { return display_name_; }
145 
146  void addEvent( Event *event );
147  void setColors( void );
148  void openDisplay( void );
149  void setHints( int argc, char *argv[] );
150  void setFont( void );
151  void selectEvents( long mask );
152  void ignoreEvents( long mask );
153  void configureEvent( XEvent &event );
154  void mappingNotify( XEvent &event )
155  { XRefreshKeyboardMapping( &event.xmapping ); }
156  void deleteEvent( XEvent &event );
157  //void usage( void );
158  Colormap colormap( void ) { return colormap_; }
159  int screen( void ) { return DefaultScreen( display_ ); }
160 private:
161 };
162 
163 #endif
virtual ~Event(void)
Definition: xwin.h:97
long mask_
Definition: xwin.h:108
void callBack(XEvent &event)
Definition: xwin.h:101
int event_
Definition: xwin.h:107
EventCallBack callBack_
Definition: xwin.h:106
Event * next_
Definition: xwin.h:110
XWin * parent_
Definition: xwin.h:105
Event(XWin *parent, int event, EventCallBack callBack)
Definition: xwin.cc:400
Definition: xwin.h:15
Xrm * xrmptr_
Definition: xwin.h:135
void width(int val)
Definition: xwin.h:24
Display * display(void)
Definition: xwin.h:27
Window window_
Definition: xwin.h:117
void XWinInit(int argc, char *argv[], char *geometry, Xrm *xrmp)
Definition: xwin.cc:35
XTextProperty title_
Definition: xwin.h:121
unsigned long foreground(void)
Definition: xwin.h:53
void height(int val)
Definition: xwin.h:26
Atom wm_
Definition: xwin.h:131
void copyArea(int src_x, int src_y, int width, int height, int dest_x, int dest_y)
Definition: xwin.h:71
Colormap colormap(void)
Definition: xwin.h:158
void mappingNotify(XEvent &event)
Definition: xwin.h:154
Window window(void)
Definition: xwin.h:28
unsigned long allocColor(const char *name)
Definition: xwin.cc:383
const char * getResourceOrUseDefault(const char *name, const char *defaultVal)
Definition: xwin.cc:351
char display_name_[256]
Definition: xwin.h:133
unsigned long background(void)
Definition: xwin.h:54
int done(void)
Definition: xwin.h:29
void setForeground(unsigned long pixelvalue)
Definition: xwin.h:38
void setDisplayName(const char *new_display_name)
Definition: xwin.h:142
int x_
Definition: xwin.h:114
void configureEvent(XEvent &event)
void clear(int x, int y, int width, int height)
Definition: xwin.h:35
XSizeHints * sizehints_
Definition: xwin.h:127
int textAscent(void)
Definition: xwin.h:77
void iconname(const char *str)
Definition: xwin.h:32
void setFont(void)
Definition: xwin.cc:141
void drawString(int x, int y, const char *str)
Definition: xwin.h:69
XFontStruct * font_
Definition: xwin.h:119
int textHeight(void)
Definition: xwin.h:79
XWindowAttributes attr_
Definition: xwin.h:125
void setStippleN(int n)
Definition: xwin.h:48
Event * events_
Definition: xwin.h:129
int textWidth(const char *str)
Definition: xwin.h:75
int y_
Definition: xwin.h:114
void openDisplay(void)
Definition: xwin.cc:195
int done_
Definition: xwin.h:130
void deleteEvent(XEvent &event)
Definition: xwin.cc:393
virtual void checkevent(void)
Definition: xwin.cc:322
int screen(void)
Definition: xwin.h:159
XClassHint * classhints_
Definition: xwin.h:128
XTextProperty iconname_
Definition: xwin.h:122
void title(const char *str)
Definition: xwin.h:31
void setStipple(Pixmap stipple)
Definition: xwin.h:42
int isResourceTrue(const char *name)
Definition: xwin.h:89
void lineWidth(int width)
Definition: xwin.h:57
GC gc_
Definition: xwin.h:118
const char * displayName()
Definition: xwin.h:144
void drawRectangle(int x, int y, int width, int height)
Definition: xwin.h:65
int getPixmap(Pixmap *)
Definition: xwin.cc:227
int doStippling_
Definition: xwin.h:136
void resize(int width, int height)
Definition: xwin.h:55
void addEvent(Event *event)
Definition: xwin.cc:338
int textWidth(const char *str, int n)
Definition: xwin.h:73
virtual ~XWin(void)
Definition: xwin.cc:57
int textDescent(void)
Definition: xwin.h:78
int height(void)
Definition: xwin.h:25
void selectEvents(long mask)
Definition: xwin.cc:301
Pixmap createPixmap(const char *data, unsigned int w, unsigned int h)
Definition: xwin.h:49
const char * getResource(const char *name)
Definition: xwin.cc:362
void setHints(int argc, char *argv[])
Definition: xwin.cc:155
unsigned long fgcolor_
Definition: xwin.h:123
int width_
Definition: xwin.h:115
void setColors(void)
Definition: xwin.cc:206
Display * display_
Definition: xwin.h:116
void init(int argc, char *argv[])
Definition: xwin.cc:80
int width(void)
Definition: xwin.h:23
void setBackground(unsigned long pixelvalue)
Definition: xwin.h:40
void flush(void)
Definition: xwin.h:85
void drawLine(int x1, int y1, int x2, int y2)
Definition: xwin.h:63
char * name_
Definition: xwin.h:120
void ignoreEvents(long mask)
Definition: xwin.cc:311
unsigned long bgcolor_
Definition: xwin.h:124
Atom wmdelete_
Definition: xwin.h:131
XWMHints * wmhints_
Definition: xwin.h:126
void map(void)
Definition: xwin.h:83
void getGeometry(void)
Definition: xwin.cc:256
void dumpResources(std::ostream &os)
Definition: xwin.cc:377
int borderwidth_
Definition: xwin.h:113
char * geometry_
Definition: xwin.h:134
void done(int val)
Definition: xwin.h:30
Pixmap stipples_[4]
Definition: xwin.h:137
void clear(void)
Definition: xwin.h:34
Colormap colormap_
Definition: xwin.h:132
void unmap(void)
Definition: xwin.h:84
void drawFilledRectangle(int x, int y, int width, int height)
Definition: xwin.h:67
XWin()
Definition: xwin.cc:14
int height_
Definition: xwin.h:115
Definition: Xrm.h:15
void(XWin::* EventCallBack)(XEvent &event)
Definition: xwin.h:12