view include/App.h @ 6:1b73e60d53b4

Now with keyboard support
author Eris Caffee <discordia@eldalin.com>
date Tue, 17 Apr 2012 01:56:49 -0500
parents 008e28de2870
children 713e3c5db1e1
line source
1 #include <map>
2 #include <string>
4 #include <X11/Xlib.h>
6 ////////////////////////////////////////////////////////////////////////////////
7 class App
8 {
9 public:
11 /////////////////////////////////////
12 class BitMap
13 {
14 public:
15 BitMap(const std::string & file);
16 ~BitMap();
18 void make_pixmap(Display * dpy, Drawable d);
20 // Yeah, it's all public here. Keeping it simple.
21 std::string name;
22 unsigned int width;
23 unsigned int height;
24 unsigned char * data;
25 Pixmap pixmap;
27 private:
28 BitMap(const App::BitMap & b);
30 int read_from_file(const std::string & file);
31 };
33 /////////////////////////////////////
34 // TODO: Need to be able to support child windows.
35 class WindowData
36 {
37 public:
38 WindowData(const std::string & n, Window w, App::BitMap * i) :
39 name(n), win(w), icon(i) {};
40 ~WindowData()
41 {
42 if (icon) { delete icon; icon = NULL; }
43 }
46 std::string name;
47 Window win;
48 App::BitMap * icon;
49 };
51 /////////////////////////////////////
53 typedef std::pair<std::string, App::WindowData *> win_pair;
54 typedef std::map<std::string, App::WindowData *> WindowMap;
56 App(const std::string & appname);
57 ~App();
59 static int x_error_handler(Display * dpy, XErrorEvent *err);
61 void create_window(const std::string& win_name,
62 int x, int y,
63 unsigned int width, unsigned int height,
64 App::BitMap * icon);
66 inline int display_height(void) const
67 { return DisplayHeight(dpy, DefaultScreen(dpy)); };
69 inline int display_width(void) const
70 { return DisplayWidth(dpy, DefaultScreen(dpy)); };
72 void run(void);
74 private:
75 App();
76 App(const App & a);
78 Display * dpy;
79 WindowMap windows;
80 long event_mask;
81 Atom wm_delete_window; // Need this in contructor and run().
83 };