LGI  1.0
Lliurex Graphic Interface
 All Classes Namespaces Files Functions Variables Macros
x11window.hpp
Go to the documentation of this file.
1 
2 #ifndef _LGI_X11_WINDOW_
3 #define _LGI_X11_WINDOW_
4 
5 /* including window before xlib avoids some name collision*/
6 #include "window.hpp"
7 
8 #include <X11/Xlib.h>
9 #include <X11/Xutil.h>
10 #include <X11/cursorfont.h>
11 #include <X11/Xcursor/Xcursor.h>
12 #include <GL/gl.h>
13 #include <GL/glx.h>
14 #include <sys/time.h>
15 #include <pthread.h>
16 #include <cairo-xlib.h>
17 #include <stdint.h>
18 #include <vector>
19 #include <queue>
20 
21 
23 #define LGI_FLAG_EXT_RENDER_SOFTWARE 0x010000
24 #define LGI_FLAG_EXT_RENDER_OPENGL 0x020000
25 
26 #define LGI_MESSAGE_DND_ENTER 0x00010000
27 #define LGI_MESSAGE_DND_LEAVE 0x00020000
28 #define LGI_MESSAGE_DND_DROP 0x00030000
29 
30 
31 namespace net
32 {
33  namespace lliurex
34  {
35  namespace lgi
36  {
37 
38  struct click_t
39  {
40  int x;
41  int y;
42  int count;
43  long time;
44  };
45 
46  typedef struct
47  {
48  unsigned long flags;
49  unsigned long functions;
50  unsigned long decorations;
51  long inputMode;
52  unsigned long status;
53  } wm_hints;
54 
55 
56  class X11Window : public BaseWindow
57  {
58  private:
59 
60  int width;
61  int height;
62 
63  Display * display;
64  Window xwindow;
65  int screen;
66  GC gc;
67  timeval init_time;
68 
69  /* render method */
70  int render_method;
71 
72  /* OpenGL render */
73  XVisualInfo * visual;
74  GLuint framebuffer_texture;
75  GLXContext glc;
76 
77  Atom wm_delete_window;
78  Atom wm_protocols;
79 
80 
81  /* keyboard mapping */
82  KeySym * keymap;
83  int keysym_per_code;
84  XComposeStatus kcompose_status;
85 
86  /* x11 render */
87  Pixmap pix_buffer;
88  XImage* back_buffer;
89 
90  /* mouse click detection */
91  click_t clicks[6];
92 
93  std::vector<Layer * > layers;
94  std::queue<RawEvent *> event_queue;
95  pthread_mutex_t queue_mutex;
96 
97  Widget * dragging;
98 
99  int double_click_ms;
100 
101  /* cursor mode, you know, none, x11 or custom one */
102  int cursor_x;
103  int cursor_y;
104  int cursor_mode;
105  int cursor_type;
106  BaseCursor * custom_cursor;
107 
108  /* X11 dnd */
109  std::vector<std::string>dnd_targets;
110  bool dnd_allowed;
111 
112  /* current focused layer */
113  Layer * focus_layer;
114 
115 
116  void Log(std::string msg);
117 
118  void Resize(int w,int h);
119  /* draws widgets bounding box, for debugging purposes */
120  void DrawBB();
121 
122  int ReadProperty(Atom property,unsigned char * data);
123  int MapKey(KeySym k);
124  std::string GetX11CursorName(int type);
125  void Latin1ToUTF8(unsigned char * in,unsigned char * out);
126  float GetDist(float x1,float y1,float x2,float y2);
127 
128  void SetFocus(Layer * layer,Widget * widget);
129 
130  public:
131  uint8_t * framebuffer;
132  cairo_t * cairo;
133  cairo_surface_t * cairo_surface;
134 
135  /* Inherited methods */
136 
143  X11Window(int w,int h,int flags=0);
144 
148  unsigned long GetXWindow();
149 
150  void Destroy();
151  void SetTitle(const char * title);
152 
153  void GetEvent();
154  void DispatchEvents(int mode);
155  void PushEvent(RawEvent * raw_event);
156  RawEvent * PopEvent();
157  void ProcessEvent(RawEvent * raw_event);
158 
159  void Flip();
160 
161  int GetWidth();
162  int GetHeight();
163 
164  void SetSize(int width,int height);
165 
166  void AddLayer(Layer * layer);
167  void RemoveLayer(Layer * layer);
168  void ShowLayer(Layer * layer);
169  void HideLayer(Layer * layer);
170 
171  void SetCursor(int type);
172  void SetCursorMode(int mode);
173  void SetCustomCursor(BaseCursor * cursor);
174 
175  void SetDoubleClickTime(int ms);
176 
177  void SendMessage(Layer * layer,Widget * widget,Message * msg);
178 
179  int GetTicks();
180 
181  /* ******* */
182  virtual ~X11Window();
183 
184  cairo_t * GetCairo();
185 
186  void GetScreenSize(int * width,int * height);
187 
188  void FullScreen();
189 
190  bool GetCollision(int x,int y,Widget ** widget,Layer ** layer);
191 
192  void SetDndTargets(std::vector<std::string> targets);
193 
194  Widget * GetFocus();
195  void NextFocus(Layer * layer=nullptr);
196 
197  };
198  }
199  }
200 }
201 
202 
203 #endif
void ShowLayer(Layer *layer)
uint8_t * framebuffer
Definition: x11window.hpp:131
void SetDndTargets(std::vector< std::string > targets)
void GetScreenSize(int *width, int *height)
Definition: x11window.hpp:46
void SetTitle(const char *title)
Definition: layer.hpp:23
Definition: window.hpp:145
void SendMessage(Layer *layer, Widget *widget, Message *msg)
unsigned long functions
Definition: x11window.hpp:49
void NextFocus(Layer *layer=nullptr)
void RemoveLayer(Layer *layer)
Definition: x11window.hpp:38
unsigned long status
Definition: x11window.hpp:52
unsigned long flags
Definition: x11window.hpp:48
void HideLayer(Layer *layer)
void AddLayer(Layer *layer)
long time
Definition: x11window.hpp:43
long inputMode
Definition: x11window.hpp:51
void SetCustomCursor(BaseCursor *cursor)
int y
Definition: x11window.hpp:41
int x
Definition: x11window.hpp:40
void PushEvent(RawEvent *raw_event)
cairo_t * cairo
Definition: x11window.hpp:132
Definition: cursor.hpp:13
unsigned long decorations
Definition: x11window.hpp:50
cairo_surface_t * cairo_surface
Definition: x11window.hpp:133
void ProcessEvent(RawEvent *raw_event)
void SetSize(int width, int height)
X11Window(int w, int h, int flags=0)
Definition: x11window.hpp:56
int count
Definition: x11window.hpp:42
Definition: widget.hpp:18
bool GetCollision(int x, int y, Widget **widget, Layer **layer)
Definition: message.hpp:83
Definition: window.hpp:137