]> git.tdb.fi Git - libs/gui.git/blob - source/window.h
0f1dfbaf8c18ca343fbe617c6808ddfc52f800f7
[libs/gui.git] / source / window.h
1 /* $Id$
2
3 This file is part of libmspgbase
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GBASE_WINDOW_H_
9 #define MSP_GBASE_WINDOW_H_
10
11 #include <string>
12 #include <X11/Xlib.h>
13 #include <sigc++/signal.h>
14
15 namespace Msp {
16
17 struct DisplayOptions
18 {
19         std::string display;
20         unsigned width;
21         unsigned height;
22         bool fullscreen;
23
24         DisplayOptions();
25 };
26
27 class Window
28 {
29 public:
30         sigc::signal<void, int, int, unsigned, unsigned> signal_button_press;
31         sigc::signal<void, int, int, unsigned, unsigned> signal_button_release;
32         sigc::signal<void, int, int> signal_pointer_motion;
33         sigc::signal<void, unsigned, unsigned, unsigned> signal_key_press;
34         sigc::signal<void, unsigned, unsigned> signal_key_release;
35         sigc::signal<void, unsigned, unsigned> signal_resize;
36         sigc::signal<void> signal_close;
37
38 protected:
39         typedef ::Window Handle;
40
41         Display *display;
42         DisplayOptions options;
43         Handle  window;
44         Atom    wm_delete_window;
45
46         Window();
47 public:
48         Window(unsigned w, unsigned h);
49         Window(const DisplayOptions &dopt);
50         virtual ~Window();
51
52         unsigned get_width() const  { return options.width; }
53         unsigned get_height() const { return options.height; }
54         void show();
55         void hide();
56         void tick();
57 protected:
58         void prepare();
59         void set_window(Handle wnd);
60         void init();
61         void process_event(const XEvent &event);
62         virtual void on_event(const XEvent &event) { (void)event; }
63
64         static int x_error_handler(Display *, XErrorEvent *);
65 };
66
67 } // namespace Msp
68
69 #endif