]> git.tdb.fi Git - libs/gui.git/blob - source/window.h
Add Window::set_title
[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         void set_title(const std::string &);
53
54         unsigned get_width() const  { return options.width; }
55         unsigned get_height() const { return options.height; }
56         void show();
57         void hide();
58         void tick();
59 protected:
60         void prepare();
61         void set_window(Handle wnd);
62         void init();
63         void process_event(const XEvent &event);
64         virtual void on_event(const XEvent &event) { (void)event; }
65
66         static int x_error_handler(Display *, XErrorEvent *);
67 };
68
69 } // namespace Msp
70
71 #endif