]>
Commit | Line | Data |
---|---|---|
7d9f12f3 | 1 | ///////////////////////////////////////////////////////////////////////////// |
cb8cc250 | 2 | // Name: src/gtk/toplevel.cpp |
7d9f12f3 VS |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
7d9f12f3 VS |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
93763ad5 WS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
7d9f12f3 VS |
13 | // ============================================================================ |
14 | // declarations | |
15 | // ============================================================================ | |
16 | ||
17 | // ---------------------------------------------------------------------------- | |
18 | // headers | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
7d9f12f3 VS |
21 | #ifdef __VMS |
22 | #define XIconifyWindow XICONIFYWINDOW | |
23 | #endif | |
24 | ||
e1bf3ad3 | 25 | #include "wx/toplevel.h" |
e4db172a WS |
26 | |
27 | #ifndef WX_PRECOMP | |
d281df50 PC |
28 | #include "wx/frame.h" |
29 | #include "wx/icon.h" | |
e4db172a | 30 | #include "wx/log.h" |
670f9935 | 31 | #include "wx/app.h" |
e4db172a WS |
32 | #endif |
33 | ||
fab591c5 | 34 | #include "wx/gtk/private.h" |
924b84ab | 35 | #include "wx/evtloop.h" |
a95a6eb4 | 36 | #include "wx/sysopt.h" |
7d9f12f3 | 37 | |
7d9f12f3 | 38 | #include <gtk/gtk.h> |
7d9f12f3 VS |
39 | #include <gdk/gdkx.h> |
40 | ||
bbd92d1d | 41 | #include "wx/gtk/private/win_gtk.h" |
7d9f12f3 | 42 | |
f618020a MB |
43 | #include "wx/unix/utilsx11.h" |
44 | ||
8a9650ea RR |
45 | // XA_CARDINAL |
46 | #include <X11/Xatom.h> | |
47 | ||
e2f3bc41 VZ |
48 | #if wxUSE_LIBHILDON |
49 | #include <hildon-widgets/hildon-program.h> | |
50 | #include <hildon-widgets/hildon-window.h> | |
51 | #endif // wxUSE_LIBHILDON | |
52 | ||
426d19f1 JS |
53 | #if wxUSE_LIBHILDON2 |
54 | #include <hildon/hildon.h> | |
55 | #endif // wxUSE_LIBHILDON2 | |
56 | ||
7d9f12f3 VS |
57 | // ---------------------------------------------------------------------------- |
58 | // data | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
64c11164 VZ |
61 | // this is incremented while a modal dialog is shown |
62 | int wxOpenModalDialogsCount = 0; | |
63 | ||
06fda9e8 RR |
64 | // the frame that is currently active (i.e. its child has focus). It is |
65 | // used to generate wxActivateEvents | |
d3b9f782 VZ |
66 | static wxTopLevelWindowGTK *g_activeFrame = NULL; |
67 | static wxTopLevelWindowGTK *g_lastActiveFrame = NULL; | |
06fda9e8 RR |
68 | |
69 | // if we detect that the app has got/lost the focus, we set this variable to | |
70 | // either TRUE or FALSE and an activate event will be sent during the next | |
71 | // OnIdle() call and it is reset to -1: this value means that we shouldn't | |
72 | // send any activate events at all | |
0a164d4c | 73 | static int g_sendActivateEvent = -1; |
06fda9e8 | 74 | |
f5c0761f PC |
75 | // Whether _NET_REQUEST_FRAME_EXTENTS support is working |
76 | // 0 == not tested yet, 1 == working, 2 == broken | |
77 | static int gs_requestFrameExtentsStatus; | |
78 | ||
dca92ddf MR |
79 | //----------------------------------------------------------------------------- |
80 | // RequestUserAttention related functions | |
81 | //----------------------------------------------------------------------------- | |
82 | ||
98185146 | 83 | #ifndef __WXGTK30__ |
dca92ddf MR |
84 | static void wxgtk_window_set_urgency_hint (GtkWindow *win, |
85 | gboolean setting) | |
86 | { | |
98185146 PC |
87 | #if GTK_CHECK_VERSION(2,7,0) |
88 | if (gtk_check_version(2,7,0) == NULL) | |
89 | gtk_window_set_urgency_hint(win, setting); | |
90 | else | |
91 | #endif | |
92 | { | |
93 | GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(win)); | |
94 | wxCHECK_RET(window, "wxgtk_window_set_urgency_hint: GdkWindow not realized"); | |
dca92ddf | 95 | |
98185146 PC |
96 | Display* dpy = GDK_WINDOW_XDISPLAY(window); |
97 | Window xid = GDK_WINDOW_XID(window); | |
98 | XWMHints* wm_hints = XGetWMHints(dpy, xid); | |
dca92ddf | 99 | |
98185146 PC |
100 | if (!wm_hints) |
101 | wm_hints = XAllocWMHints(); | |
dca92ddf | 102 | |
98185146 PC |
103 | if (setting) |
104 | wm_hints->flags |= XUrgencyHint; | |
105 | else | |
106 | wm_hints->flags &= ~XUrgencyHint; | |
dca92ddf | 107 | |
98185146 PC |
108 | XSetWMHints(dpy, xid, wm_hints); |
109 | XFree(wm_hints); | |
110 | } | |
dca92ddf | 111 | } |
98185146 PC |
112 | #define gtk_window_set_urgency_hint wxgtk_window_set_urgency_hint |
113 | #endif | |
dca92ddf | 114 | |
98185146 | 115 | extern "C" { |
92ed8bec | 116 | static gboolean gtk_frame_urgency_timer_callback( wxTopLevelWindowGTK *win ) |
dca92ddf | 117 | { |
98185146 | 118 | gtk_window_set_urgency_hint(GTK_WINDOW(win->m_widget), false); |
dca92ddf | 119 | |
ef1a9be4 | 120 | win->m_urgency_hint = -2; |
dca92ddf MR |
121 | return FALSE; |
122 | } | |
123 | } | |
124 | ||
06fda9e8 RR |
125 | //----------------------------------------------------------------------------- |
126 | // "focus_in_event" | |
127 | //----------------------------------------------------------------------------- | |
128 | ||
865bb325 | 129 | extern "C" { |
4c20ee63 | 130 | static gboolean gtk_frame_focus_in_callback( GtkWidget *widget, |
06fda9e8 RR |
131 | GdkEvent *WXUNUSED(event), |
132 | wxTopLevelWindowGTK *win ) | |
133 | { | |
06fda9e8 RR |
134 | switch ( g_sendActivateEvent ) |
135 | { | |
136 | case -1: | |
137 | // we've got focus from outside, synthetize wxActivateEvent | |
138 | g_sendActivateEvent = 1; | |
139 | break; | |
140 | ||
141 | case 0: | |
142 | // another our window just lost focus, it was already ours before | |
143 | // - don't send any wxActivateEvent | |
144 | g_sendActivateEvent = -1; | |
145 | break; | |
146 | } | |
147 | ||
148 | g_activeFrame = win; | |
149 | g_lastActiveFrame = g_activeFrame; | |
0a164d4c | 150 | |
06fda9e8 | 151 | // wxPrintf( wxT("active: %s\n"), win->GetTitle().c_str() ); |
0a164d4c | 152 | |
dca92ddf | 153 | // MR: wxRequestUserAttention related block |
ef1a9be4 | 154 | switch( win->m_urgency_hint ) |
dca92ddf MR |
155 | { |
156 | default: | |
92ed8bec | 157 | g_source_remove( win->m_urgency_hint ); |
dca92ddf MR |
158 | // no break, fallthrough to remove hint too |
159 | case -1: | |
98185146 | 160 | gtk_window_set_urgency_hint(GTK_WINDOW(widget), false); |
ef1a9be4 | 161 | win->m_urgency_hint = -2; |
dca92ddf MR |
162 | break; |
163 | ||
164 | case -2: break; | |
165 | } | |
166 | ||
06fda9e8 | 167 | wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame); |
0a164d4c | 168 | wxActivateEvent event(wxEVT_ACTIVATE, true, g_activeFrame->GetId()); |
06fda9e8 | 169 | event.SetEventObject(g_activeFrame); |
937013e0 | 170 | g_activeFrame->HandleWindowEvent(event); |
06fda9e8 | 171 | |
4c20ee63 | 172 | return FALSE; |
06fda9e8 | 173 | } |
865bb325 | 174 | } |
06fda9e8 RR |
175 | |
176 | //----------------------------------------------------------------------------- | |
177 | // "focus_out_event" | |
178 | //----------------------------------------------------------------------------- | |
179 | ||
865bb325 | 180 | extern "C" { |
e4161a2a VZ |
181 | static |
182 | gboolean gtk_frame_focus_out_callback(GtkWidget * WXUNUSED(widget), | |
183 | GdkEventFocus *WXUNUSED(gdk_event), | |
184 | wxTopLevelWindowGTK * WXUNUSED(win)) | |
06fda9e8 | 185 | { |
06fda9e8 RR |
186 | // if the focus goes out of our app alltogether, OnIdle() will send |
187 | // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset | |
188 | // g_sendActivateEvent to -1 | |
189 | g_sendActivateEvent = 0; | |
0a164d4c | 190 | |
06fda9e8 | 191 | // wxASSERT_MSG( (g_activeFrame == win), wxT("TLW deactivatd although it wasn't active") ); |
0a164d4c | 192 | |
06fda9e8 | 193 | // wxPrintf( wxT("inactive: %s\n"), win->GetTitle().c_str() ); |
06fda9e8 | 194 | |
cc0c05cd JS |
195 | if (g_activeFrame) |
196 | { | |
197 | wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame); | |
0a164d4c | 198 | wxActivateEvent event(wxEVT_ACTIVATE, false, g_activeFrame->GetId()); |
cc0c05cd | 199 | event.SetEventObject(g_activeFrame); |
937013e0 | 200 | g_activeFrame->HandleWindowEvent(event); |
cc0c05cd JS |
201 | |
202 | g_activeFrame = NULL; | |
203 | } | |
0a164d4c | 204 | |
4c20ee63 | 205 | return FALSE; |
06fda9e8 | 206 | } |
865bb325 | 207 | } |
7d9f12f3 | 208 | |
7d9f12f3 | 209 | //----------------------------------------------------------------------------- |
cca410b3 | 210 | // "size_allocate" from m_wxwindow |
7d9f12f3 VS |
211 | //----------------------------------------------------------------------------- |
212 | ||
865bb325 | 213 | extern "C" { |
cca410b3 PC |
214 | static void |
215 | size_allocate(GtkWidget*, GtkAllocation* alloc, wxTopLevelWindowGTK* win) | |
7d9f12f3 | 216 | { |
cca410b3 PC |
217 | if (win->m_oldClientWidth != alloc->width || |
218 | win->m_oldClientHeight != alloc->height) | |
219 | { | |
220 | win->m_oldClientWidth = alloc->width; | |
221 | win->m_oldClientHeight = alloc->height; | |
0ab0d0e1 | 222 | |
385e8575 PC |
223 | GtkAllocation a; |
224 | gtk_widget_get_allocation(win->m_widget, &a); | |
225 | wxSize size(a.width, a.height); | |
53e3cd04 | 226 | size += win->m_decorSize; |
0ab0d0e1 PC |
227 | win->m_width = size.x; |
228 | win->m_height = size.y; | |
229 | ||
cca410b3 PC |
230 | if (!win->IsIconized()) |
231 | { | |
0ab0d0e1 | 232 | wxSizeEvent event(size, win->GetId()); |
cca410b3 | 233 | event.SetEventObject(win); |
937013e0 | 234 | win->HandleWindowEvent(event); |
cca410b3 PC |
235 | } |
236 | // else the window is currently unmapped, don't generate size events | |
7d9f12f3 VS |
237 | } |
238 | } | |
865bb325 | 239 | } |
7d9f12f3 | 240 | |
6e264997 VZ |
241 | // ---------------------------------------------------------------------------- |
242 | // "size_request" | |
243 | // ---------------------------------------------------------------------------- | |
244 | ||
245 | extern "C" { | |
290cd301 | 246 | static |
6e264997 VZ |
247 | void wxgtk_tlw_size_request_callback(GtkWidget * WXUNUSED(widget), |
248 | GtkRequisition *requisition, | |
249 | wxTopLevelWindowGTK *win) | |
250 | { | |
251 | // we must return the size of the window without WM decorations, otherwise | |
252 | // GTK+ gets confused, so don't call just GetSize() here | |
290cd301 | 253 | win->GTKDoGetSize(&requisition->width, &requisition->height); |
6e264997 VZ |
254 | } |
255 | } | |
290cd301 | 256 | |
7d9f12f3 VS |
257 | //----------------------------------------------------------------------------- |
258 | // "delete_event" | |
259 | //----------------------------------------------------------------------------- | |
260 | ||
865bb325 | 261 | extern "C" { |
5d4c0833 MR |
262 | static gboolean |
263 | gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), | |
264 | GdkEvent *WXUNUSED(event), | |
265 | wxTopLevelWindowGTK *win ) | |
7d9f12f3 | 266 | { |
7d9f12f3 | 267 | if (win->IsEnabled() && |
64c11164 | 268 | (wxOpenModalDialogsCount == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) || |
5152b0e5 | 269 | win->IsGrabbed())) |
7d9f12f3 VS |
270 | win->Close(); |
271 | ||
272 | return TRUE; | |
273 | } | |
865bb325 | 274 | } |
7d9f12f3 | 275 | |
7d9f12f3 VS |
276 | //----------------------------------------------------------------------------- |
277 | // "configure_event" | |
278 | //----------------------------------------------------------------------------- | |
279 | ||
865bb325 | 280 | extern "C" { |
5d4c0833 | 281 | static gboolean |
dc89b7bf | 282 | gtk_frame_configure_callback( GtkWidget* widget, |
5d4c0833 MR |
283 | GdkEventConfigure *WXUNUSED(event), |
284 | wxTopLevelWindowGTK *win ) | |
7d9f12f3 | 285 | { |
48f72114 | 286 | if (!win->m_hasVMT || !win->IsShown()) |
7d9f12f3 VS |
287 | return FALSE; |
288 | ||
dc89b7bf PC |
289 | wxPoint point; |
290 | gtk_window_get_position((GtkWindow*)widget, &point.x, &point.y); | |
32f2ebbf | 291 | |
afde1667 PC |
292 | win->m_x = point.x; |
293 | win->m_y = point.y; | |
294 | wxMoveEvent mevent(point, win->GetId()); | |
295 | mevent.SetEventObject( win ); | |
937013e0 | 296 | win->HandleWindowEvent( mevent ); |
7d9f12f3 VS |
297 | |
298 | return FALSE; | |
299 | } | |
865bb325 | 300 | } |
7d9f12f3 VS |
301 | |
302 | //----------------------------------------------------------------------------- | |
303 | // "realize" from m_widget | |
304 | //----------------------------------------------------------------------------- | |
305 | ||
bb25a741 | 306 | // we cannot the WM hints and icons before the widget has been realized, |
e1f14d22 | 307 | // so we do this directly after realization |
7d9f12f3 | 308 | |
612515af | 309 | void wxTopLevelWindowGTK::GTKHandleRealized() |
7d9f12f3 | 310 | { |
612515af VZ |
311 | wxNonOwnedWindow::GTKHandleRealized(); |
312 | ||
313 | gdk_window_set_decorations(gtk_widget_get_window(m_widget), | |
314 | (GdkWMDecoration)m_gdkDecor); | |
315 | gdk_window_set_functions(gtk_widget_get_window(m_widget), | |
316 | (GdkWMFunction)m_gdkFunc); | |
7d9f12f3 | 317 | |
e1f14d22 | 318 | // GTK's shrinking/growing policy |
612515af VZ |
319 | if ( !(m_gdkFunc & GDK_FUNC_RESIZE) ) |
320 | gtk_window_set_resizable(GTK_WINDOW(m_widget), FALSE); | |
385e8575 | 321 | #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED) |
7d9f12f3 | 322 | else |
612515af | 323 | gtk_window_set_policy(GTK_WINDOW(m_widget), 1, 1, 1); |
385e8575 | 324 | #endif |
7d9f12f3 | 325 | |
612515af | 326 | const wxIconBundle& icons = GetIcons(); |
0617ba3e | 327 | if (icons.GetIconCount()) |
612515af | 328 | SetIcons(icons); |
7d9f12f3 VS |
329 | } |
330 | ||
331 | //----------------------------------------------------------------------------- | |
332 | // "map_event" from m_widget | |
333 | //----------------------------------------------------------------------------- | |
334 | ||
865bb325 | 335 | extern "C" { |
0e795b05 | 336 | static gboolean |
53e3cd04 | 337 | gtk_frame_map_callback( GtkWidget*, |
7d9f12f3 VS |
338 | GdkEvent * WXUNUSED(event), |
339 | wxTopLevelWindow *win ) | |
340 | { | |
2a74bd27 | 341 | const bool wasIconized = win->IsIconized(); |
2a74bd27 PC |
342 | if (wasIconized) |
343 | { | |
344 | // Because GetClientSize() returns (0,0) when IsIconized() is true, | |
345 | // a size event must be generated, just in case GetClientSize() was | |
346 | // called while iconized. This specifically happens when restoring a | |
347 | // tlw that was "rolled up" with some WMs. | |
348 | // Queue a resize rather than sending size event directly to allow | |
349 | // children to be made visible first. | |
350 | win->m_oldClientWidth = 0; | |
351 | gtk_widget_queue_resize(win->m_wxwindow); | |
352 | } | |
e955eee5 PC |
353 | // it is possible for m_isShown to be false here, see bug #9909 |
354 | if (win->wxWindowBase::Show(true)) | |
355 | { | |
356 | wxShowEvent eventShow(win->GetId(), true); | |
357 | eventShow.SetEventObject(win); | |
358 | win->GetEventHandler()->ProcessEvent(eventShow); | |
359 | } | |
995d5aa2 VZ |
360 | |
361 | #if GTK_CHECK_VERSION(2,6,0) | |
362 | if (!gtk_check_version(2,6,0)) | |
363 | { | |
364 | // restore focus-on-map setting in case ShowWithoutActivating() was called | |
365 | gtk_window_set_focus_on_map(GTK_WINDOW(win->m_widget), true); | |
366 | } | |
367 | #endif // GTK+ 2.6+ | |
368 | ||
0e795b05 | 369 | return false; |
7d9f12f3 | 370 | } |
865bb325 | 371 | } |
7d9f12f3 VS |
372 | |
373 | //----------------------------------------------------------------------------- | |
f0f0542d | 374 | // "window-state-event" from m_widget |
7d9f12f3 VS |
375 | //----------------------------------------------------------------------------- |
376 | ||
865bb325 | 377 | extern "C" { |
0e795b05 | 378 | static gboolean |
f0f0542d RR |
379 | gtk_frame_window_state_callback( GtkWidget* WXUNUSED(widget), |
380 | GdkEventWindowState *event, | |
7d9f12f3 VS |
381 | wxTopLevelWindow *win ) |
382 | { | |
34d2ab14 PC |
383 | if (event->changed_mask & GDK_WINDOW_STATE_ICONIFIED) |
384 | win->SetIconizeState((event->new_window_state & GDK_WINDOW_STATE_ICONIFIED) != 0); | |
385 | ||
89c6e024 PC |
386 | // if maximized bit changed and it is now set |
387 | if (event->changed_mask & event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) | |
388 | { | |
389 | wxMaximizeEvent event(win->GetId()); | |
390 | event.SetEventObject(win); | |
391 | win->HandleWindowEvent(event); | |
392 | } | |
393 | ||
34d2ab14 | 394 | return false; |
7d9f12f3 | 395 | } |
865bb325 | 396 | } |
7d9f12f3 | 397 | |
166b4de7 PC |
398 | //----------------------------------------------------------------------------- |
399 | ||
400 | bool wxGetFrameExtents(GdkWindow* window, int* left, int* right, int* top, int* bottom) | |
401 | { | |
402 | static GdkAtom property = gdk_atom_intern("_NET_FRAME_EXTENTS", false); | |
403 | Atom xproperty = gdk_x11_atom_to_xatom_for_display( | |
404 | gdk_drawable_get_display(window), property); | |
405 | Atom type; | |
406 | int format; | |
407 | gulong nitems, bytes_after; | |
408 | guchar* data; | |
409 | Status status = XGetWindowProperty( | |
410 | gdk_x11_drawable_get_xdisplay(window), | |
411 | gdk_x11_drawable_get_xid(window), | |
412 | xproperty, | |
413 | 0, 4, false, XA_CARDINAL, | |
414 | &type, &format, &nitems, &bytes_after, &data); | |
415 | const bool success = status == Success && data && nitems == 4; | |
416 | if (success) | |
417 | { | |
418 | long* p = (long*)data; | |
419 | if (left) *left = int(p[0]); | |
420 | if (right) *right = int(p[1]); | |
421 | if (top) *top = int(p[2]); | |
422 | if (bottom) *bottom = int(p[3]); | |
423 | } | |
424 | if (data) | |
425 | XFree(data); | |
426 | return success; | |
427 | } | |
428 | ||
290cd301 PC |
429 | //----------------------------------------------------------------------------- |
430 | // "property_notify_event" from m_widget | |
431 | //----------------------------------------------------------------------------- | |
432 | ||
433 | extern "C" { | |
434 | static gboolean property_notify_event( | |
435 | GtkWidget*, GdkEventProperty* event, wxTopLevelWindowGTK* win) | |
436 | { | |
437 | // Watch for changes to _NET_FRAME_EXTENTS property | |
438 | static GdkAtom property = gdk_atom_intern("_NET_FRAME_EXTENTS", false); | |
53e3cd04 | 439 | if (event->state == GDK_PROPERTY_NEW_VALUE && event->atom == property) |
290cd301 | 440 | { |
f5c0761f PC |
441 | if (win->m_netFrameExtentsTimerId) |
442 | { | |
443 | // WM support for _NET_REQUEST_FRAME_EXTENTS is working | |
444 | gs_requestFrameExtentsStatus = 1; | |
445 | g_source_remove(win->m_netFrameExtentsTimerId); | |
446 | win->m_netFrameExtentsTimerId = 0; | |
447 | } | |
448 | ||
d2c5fe6e | 449 | wxSize decorSize = win->m_decorSize; |
166b4de7 PC |
450 | int left, right, top, bottom; |
451 | if (wxGetFrameExtents(event->window, &left, &right, &top, &bottom)) | |
d2c5fe6e PC |
452 | decorSize.Set(left + right, top + bottom); |
453 | ||
454 | win->GTKUpdateDecorSize(decorSize); | |
290cd301 PC |
455 | } |
456 | return false; | |
457 | } | |
458 | } | |
459 | ||
f5c0761f PC |
460 | extern "C" { |
461 | static gboolean request_frame_extents_timeout(void* data) | |
462 | { | |
463 | // WM support for _NET_REQUEST_FRAME_EXTENTS is broken | |
464 | gs_requestFrameExtentsStatus = 2; | |
465 | gdk_threads_enter(); | |
466 | wxTopLevelWindowGTK* win = static_cast<wxTopLevelWindowGTK*>(data); | |
467 | win->m_netFrameExtentsTimerId = 0; | |
468 | wxSize decorSize = win->m_decorSize; | |
469 | int left, right, top, bottom; | |
470 | if (wxGetFrameExtents(gtk_widget_get_window(win->m_widget), &left, &right, &top, &bottom)) | |
471 | decorSize.Set(left + right, top + bottom); | |
472 | win->GTKUpdateDecorSize(decorSize); | |
473 | gdk_threads_leave(); | |
474 | return false; | |
475 | } | |
476 | } | |
477 | ||
7d9f12f3 VS |
478 | // ---------------------------------------------------------------------------- |
479 | // wxTopLevelWindowGTK creation | |
480 | // ---------------------------------------------------------------------------- | |
481 | ||
482 | void wxTopLevelWindowGTK::Init() | |
483 | { | |
d3b9f782 | 484 | m_mainWidget = NULL; |
0a164d4c WS |
485 | m_isIconized = false; |
486 | m_fsIsShowing = false; | |
487 | m_themeEnabled = true; | |
bb25a741 VZ |
488 | m_gdkDecor = |
489 | m_gdkFunc = 0; | |
0a164d4c | 490 | m_grabbed = false; |
53e3cd04 | 491 | m_deferShow = true; |
6089c4c8 | 492 | m_deferShowAllowed = true; |
11d8dfd2 | 493 | m_updateDecorSize = true; |
f5c0761f | 494 | m_netFrameExtentsTimerId = 0; |
dca92ddf | 495 | |
ef1a9be4 | 496 | m_urgency_hint = -2; |
7d9f12f3 VS |
497 | } |
498 | ||
499 | bool wxTopLevelWindowGTK::Create( wxWindow *parent, | |
f819b4a3 VS |
500 | wxWindowID id, |
501 | const wxString& title, | |
502 | const wxPoint& pos, | |
503 | const wxSize& sizeOrig, | |
504 | long style, | |
505 | const wxString &name ) | |
7d9f12f3 VS |
506 | { |
507 | // always create a frame of some reasonable, even if arbitrary, size (at | |
508 | // least for MSW compatibility) | |
509 | wxSize size = sizeOrig; | |
1111cedc | 510 | size.x = WidthDefault(size.x); |
66202a7e | 511 | size.y = HeightDefault(size.y); |
7d9f12f3 VS |
512 | |
513 | wxTopLevelWindows.Append( this ); | |
514 | ||
7d9f12f3 VS |
515 | if (!PreCreation( parent, pos, size ) || |
516 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
517 | { | |
518 | wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") ); | |
0a164d4c | 519 | return false; |
7d9f12f3 VS |
520 | } |
521 | ||
522 | m_title = title; | |
523 | ||
63c5efa3 VS |
524 | // NB: m_widget may be !=NULL if it was created by derived class' Create, |
525 | // e.g. in wxTaskBarIconAreaGTK | |
526 | if (m_widget == NULL) | |
527 | { | |
426d19f1 | 528 | #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 |
e2f3bc41 VZ |
529 | // we must create HildonWindow and not a normal GtkWindow as the latter |
530 | // doesn't look correctly in Maemo environment and it must also be | |
531 | // registered with the main program object | |
532 | m_widget = hildon_window_new(); | |
533 | hildon_program_add_window(wxTheApp->GetHildonProgram(), | |
534 | HILDON_WINDOW(m_widget)); | |
426d19f1 | 535 | #else // !wxUSE_LIBHILDON || !wxUSE_LIBHILDON2 |
cca410b3 | 536 | m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
63c5efa3 VS |
537 | if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) |
538 | { | |
4d8d6490 VS |
539 | // Tell WM that this is a dialog window and make it center |
540 | // on parent by default (this is what GtkDialog ctor does): | |
541 | gtk_window_set_type_hint(GTK_WINDOW(m_widget), | |
542 | GDK_WINDOW_TYPE_HINT_DIALOG); | |
543 | gtk_window_set_position(GTK_WINDOW(m_widget), | |
544 | GTK_WIN_POS_CENTER_ON_PARENT); | |
63c5efa3 | 545 | } |
4d8d6490 VS |
546 | else |
547 | { | |
ff654490 | 548 | if (style & wxFRAME_TOOL_WINDOW) |
11475235 | 549 | { |
ff654490 VZ |
550 | gtk_window_set_type_hint(GTK_WINDOW(m_widget), |
551 | GDK_WINDOW_TYPE_HINT_UTILITY); | |
552 | ||
553 | // On some WMs, like KDE, a TOOL_WINDOW will still show | |
554 | // on the taskbar, but on Gnome a TOOL_WINDOW will not. | |
555 | // For consistency between WMs and with Windows, we | |
556 | // should set the NO_TASKBAR flag which will apply | |
557 | // the set_skip_taskbar_hint if it is available, | |
558 | // ensuring no taskbar entry will appear. | |
559 | style |= wxFRAME_NO_TASKBAR; | |
11475235 | 560 | } |
4d8d6490 | 561 | } |
426d19f1 | 562 | #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2 |
9ff9d30c PC |
563 | |
564 | g_object_ref(m_widget); | |
63c5efa3 | 565 | } |
7d9f12f3 | 566 | |
e25c7537 VS |
567 | wxWindow *topParent = wxGetTopLevelParent(m_parent); |
568 | if (topParent && (((GTK_IS_WINDOW(topParent->m_widget)) && | |
0a164d4c WS |
569 | (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)) || |
570 | (style & wxFRAME_FLOAT_ON_PARENT))) | |
7cd95599 | 571 | { |
e25c7537 VS |
572 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), |
573 | GTK_WINDOW(topParent->m_widget) ); | |
7cd95599 | 574 | } |
7d9f12f3 | 575 | |
ff654490 | 576 | if (style & wxFRAME_NO_TASKBAR) |
2be125e6 | 577 | { |
ff654490 | 578 | gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget), TRUE); |
2be125e6 | 579 | } |
2be125e6 | 580 | |
ff654490 | 581 | if (style & wxSTAY_ON_TOP) |
2fca39c9 | 582 | { |
ff654490 | 583 | gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE); |
2fca39c9 | 584 | } |
68893d58 PC |
585 | if (style & wxMAXIMIZE) |
586 | gtk_window_maximize(GTK_WINDOW(m_widget)); | |
2fca39c9 | 587 | |
5503a51c | 588 | #if 0 |
0a164d4c | 589 | if (!name.empty()) |
5503a51c MR |
590 | gtk_window_set_role( GTK_WINDOW(m_widget), wxGTK_CONV( name ) ); |
591 | #endif | |
7d9f12f3 | 592 | |
fab591c5 | 593 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) ); |
385e8575 | 594 | gtk_widget_set_can_focus(m_widget, false); |
7d9f12f3 | 595 | |
9fa72bd2 MR |
596 | g_signal_connect (m_widget, "delete_event", |
597 | G_CALLBACK (gtk_frame_delete_callback), this); | |
7d9f12f3 | 598 | |
cca410b3 PC |
599 | // m_mainWidget is a GtkVBox, holding the bars and client area (m_wxwindow) |
600 | m_mainWidget = gtk_vbox_new(false, 0); | |
7d9f12f3 | 601 | gtk_widget_show( m_mainWidget ); |
385e8575 | 602 | gtk_widget_set_can_focus(m_mainWidget, false); |
7d9f12f3 VS |
603 | gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); |
604 | ||
cca410b3 | 605 | // m_wxwindow is the client area |
0f52f610 | 606 | m_wxwindow = wxPizza::New(); |
7d9f12f3 VS |
607 | gtk_widget_show( m_wxwindow ); |
608 | gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); | |
609 | ||
e1f14d22 RR |
610 | // we donm't allow the frame to get the focus as otherwise |
611 | // the frame will grab it at arbitrary focus changes | |
385e8575 | 612 | gtk_widget_set_can_focus(m_wxwindow, false); |
7d9f12f3 VS |
613 | |
614 | if (m_parent) m_parent->AddChild( this ); | |
615 | ||
cca410b3 PC |
616 | g_signal_connect(m_wxwindow, "size_allocate", |
617 | G_CALLBACK(size_allocate), this); | |
7d9f12f3 | 618 | |
6e264997 VZ |
619 | g_signal_connect (m_widget, "size_request", |
620 | G_CALLBACK (wxgtk_tlw_size_request_callback), this); | |
7d9f12f3 VS |
621 | PostCreation(); |
622 | ||
385e8575 | 623 | #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED) |
7d9f12f3 VS |
624 | if ((m_x != -1) || (m_y != -1)) |
625 | gtk_widget_set_uposition( m_widget, m_x, m_y ); | |
385e8575 | 626 | #endif |
6aeb6f2a | 627 | |
f0f0542d | 628 | // for some reported size corrections |
9fa72bd2 MR |
629 | g_signal_connect (m_widget, "map_event", |
630 | G_CALLBACK (gtk_frame_map_callback), this); | |
f0f0542d RR |
631 | |
632 | // for iconized state | |
633 | g_signal_connect (m_widget, "window_state_event", | |
634 | G_CALLBACK (gtk_frame_window_state_callback), this); | |
635 | ||
7d9f12f3 | 636 | |
dc89b7bf | 637 | // for wxMoveEvent |
9fa72bd2 MR |
638 | g_signal_connect (m_widget, "configure_event", |
639 | G_CALLBACK (gtk_frame_configure_callback), this); | |
7d9f12f3 | 640 | |
06fda9e8 | 641 | // activation |
4c20ee63 | 642 | g_signal_connect_after (m_widget, "focus_in_event", |
9fa72bd2 | 643 | G_CALLBACK (gtk_frame_focus_in_callback), this); |
4c20ee63 | 644 | g_signal_connect_after (m_widget, "focus_out_event", |
9fa72bd2 | 645 | G_CALLBACK (gtk_frame_focus_out_callback), this); |
0a164d4c | 646 | |
290cd301 PC |
647 | gtk_widget_add_events(m_widget, GDK_PROPERTY_CHANGE_MASK); |
648 | g_signal_connect(m_widget, "property_notify_event", | |
649 | G_CALLBACK(property_notify_event), this); | |
650 | ||
bb25a741 VZ |
651 | // translate wx decorations styles into Motif WM hints (they are recognized |
652 | // by other WMs as well) | |
653 | ||
654 | // always enable moving the window as we have no separate flag for enabling | |
655 | // it | |
656 | m_gdkFunc = GDK_FUNC_MOVE; | |
657 | ||
658 | if ( style & wxCLOSE_BOX ) | |
659 | m_gdkFunc |= GDK_FUNC_CLOSE; | |
660 | ||
661 | if ( style & wxMINIMIZE_BOX ) | |
662 | m_gdkFunc |= GDK_FUNC_MINIMIZE; | |
663 | ||
664 | if ( style & wxMAXIMIZE_BOX ) | |
665 | m_gdkFunc |= GDK_FUNC_MAXIMIZE; | |
666 | ||
667 | if ( (style & wxSIMPLE_BORDER) || (style & wxNO_BORDER) ) | |
f819b4a3 VS |
668 | { |
669 | m_gdkDecor = 0; | |
f819b4a3 | 670 | } |
bb25a741 | 671 | else // have border |
f819b4a3 | 672 | { |
290cd301 | 673 | m_gdkDecor = GDK_DECOR_BORDER; |
82c9f85c | 674 | |
bb25a741 | 675 | if ( style & wxCAPTION ) |
f819b4a3 | 676 | m_gdkDecor |= GDK_DECOR_TITLE; |
bb25a741 VZ |
677 | |
678 | if ( style & wxSYSTEM_MENU ) | |
f819b4a3 | 679 | m_gdkDecor |= GDK_DECOR_MENU; |
bb25a741 VZ |
680 | |
681 | if ( style & wxMINIMIZE_BOX ) | |
f819b4a3 | 682 | m_gdkDecor |= GDK_DECOR_MINIMIZE; |
bb25a741 VZ |
683 | |
684 | if ( style & wxMAXIMIZE_BOX ) | |
f819b4a3 | 685 | m_gdkDecor |= GDK_DECOR_MAXIMIZE; |
bb25a741 VZ |
686 | |
687 | if ( style & wxRESIZE_BORDER ) | |
f819b4a3 VS |
688 | { |
689 | m_gdkFunc |= GDK_FUNC_RESIZE; | |
690 | m_gdkDecor |= GDK_DECOR_RESIZEH; | |
691 | } | |
692 | } | |
693 | ||
fce611e4 PC |
694 | m_decorSize = GetCachedDecorSize(); |
695 | int w, h; | |
696 | GTKDoGetSize(&w, &h); | |
697 | gtk_window_set_default_size(GTK_WINDOW(m_widget), w, h); | |
290cd301 | 698 | |
0a164d4c | 699 | return true; |
7d9f12f3 VS |
700 | } |
701 | ||
702 | wxTopLevelWindowGTK::~wxTopLevelWindowGTK() | |
703 | { | |
c0866512 VZ |
704 | if ( m_netFrameExtentsTimerId ) |
705 | { | |
706 | // Don't let the timer callback fire as the window pointer passed to it | |
707 | // will become invalid very soon. | |
708 | g_source_remove(m_netFrameExtentsTimerId); | |
709 | } | |
710 | ||
426d19f1 | 711 | #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 |
1510ba2c VZ |
712 | // it can also be a (standard) dialog |
713 | if ( HILDON_IS_WINDOW(m_widget) ) | |
714 | { | |
715 | hildon_program_remove_window(wxTheApp->GetHildonProgram(), | |
716 | HILDON_WINDOW(m_widget)); | |
717 | } | |
426d19f1 | 718 | #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2 |
e2f3bc41 | 719 | |
5152b0e5 JS |
720 | if (m_grabbed) |
721 | { | |
9a83f860 | 722 | wxFAIL_MSG(wxT("Window still grabbed")); |
5152b0e5 JS |
723 | RemoveGrab(); |
724 | } | |
1cbee0b4 | 725 | |
c6212a0c | 726 | SendDestroyEvent(); |
6aeb6f2a | 727 | |
710968c3 VZ |
728 | // it may also be GtkScrolledWindow in the case of an MDI child |
729 | if (GTK_IS_WINDOW(m_widget)) | |
730 | { | |
731 | gtk_window_set_focus( GTK_WINDOW(m_widget), NULL ); | |
732 | } | |
0a164d4c | 733 | |
06fda9e8 RR |
734 | if (g_activeFrame == this) |
735 | g_activeFrame = NULL; | |
736 | if (g_lastActiveFrame == this) | |
737 | g_lastActiveFrame = NULL; | |
7d9f12f3 VS |
738 | } |
739 | ||
0d635035 RR |
740 | bool wxTopLevelWindowGTK::EnableCloseButton( bool enable ) |
741 | { | |
742 | if (enable) | |
743 | m_gdkFunc |= GDK_FUNC_CLOSE; | |
744 | else | |
745 | m_gdkFunc &= ~GDK_FUNC_CLOSE; | |
a6cdd521 | 746 | |
385e8575 PC |
747 | GdkWindow* window = gtk_widget_get_window(m_widget); |
748 | if (window) | |
749 | gdk_window_set_functions(window, (GdkWMFunction)m_gdkFunc); | |
a6cdd521 | 750 | |
0d635035 RR |
751 | return true; |
752 | } | |
8a9650ea | 753 | |
1529bc41 | 754 | bool wxTopLevelWindowGTK::ShowFullScreen(bool show, long) |
7d9f12f3 | 755 | { |
8a8997c3 | 756 | if (show == m_fsIsShowing) |
0a164d4c | 757 | return false; // return what? |
7d9f12f3 VS |
758 | |
759 | m_fsIsShowing = show; | |
0a164d4c | 760 | |
1542ea39 | 761 | wxX11FullScreenMethod method = |
8166ab43 VS |
762 | wxGetFullScreenMethodX11((WXDisplay*)GDK_DISPLAY(), |
763 | (WXWindow)GDK_ROOT_WINDOW()); | |
1542ea39 | 764 | |
feb1c9fb VS |
765 | // NB: gtk_window_fullscreen() uses freedesktop.org's WMspec extensions |
766 | // to switch to fullscreen, which is not always available. We must | |
767 | // check if WM supports the spec and use legacy methods if it | |
768 | // doesn't. | |
ff654490 | 769 | if ( method == wxX11_FS_WMSPEC ) |
7d9f12f3 | 770 | { |
feb1c9fb VS |
771 | if (show) |
772 | gtk_window_fullscreen( GTK_WINDOW( m_widget ) ); | |
773 | else | |
774 | gtk_window_unfullscreen( GTK_WINDOW( m_widget ) ); | |
7d9f12f3 VS |
775 | } |
776 | else | |
777 | { | |
385e8575 | 778 | GdkWindow* window = gtk_widget_get_window(m_widget); |
feb1c9fb VS |
779 | |
780 | if (show) | |
8166ab43 | 781 | { |
feb1c9fb VS |
782 | GetPosition( &m_fsSaveFrame.x, &m_fsSaveFrame.y ); |
783 | GetSize( &m_fsSaveFrame.width, &m_fsSaveFrame.height ); | |
784 | ||
785 | int screen_width,screen_height; | |
786 | wxDisplaySize( &screen_width, &screen_height ); | |
787 | ||
788 | gint client_x, client_y, root_x, root_y; | |
789 | gint width, height; | |
790 | ||
ff654490 VZ |
791 | m_fsSaveGdkFunc = m_gdkFunc; |
792 | m_fsSaveGdkDecor = m_gdkDecor; | |
793 | m_gdkFunc = m_gdkDecor = 0; | |
794 | gdk_window_set_decorations(window, (GdkWMDecoration)0); | |
795 | gdk_window_set_functions(window, (GdkWMFunction)0); | |
feb1c9fb | 796 | |
385e8575 PC |
797 | gdk_window_get_origin(window, &root_x, &root_y); |
798 | gdk_window_get_geometry(window, &client_x, &client_y, &width, &height, NULL); | |
feb1c9fb | 799 | |
385e8575 PC |
800 | gdk_window_move_resize( |
801 | window, -client_x, -client_y, screen_width + 1, screen_height + 1); | |
feb1c9fb VS |
802 | |
803 | wxSetFullScreenStateX11((WXDisplay*)GDK_DISPLAY(), | |
804 | (WXWindow)GDK_ROOT_WINDOW(), | |
805 | (WXWindow)GDK_WINDOW_XWINDOW(window), | |
806 | show, &m_fsSaveFrame, method); | |
807 | } | |
3b2931fb | 808 | else // hide |
feb1c9fb | 809 | { |
ff654490 VZ |
810 | m_gdkFunc = m_fsSaveGdkFunc; |
811 | m_gdkDecor = m_fsSaveGdkDecor; | |
812 | gdk_window_set_decorations(window, (GdkWMDecoration)m_gdkDecor); | |
813 | gdk_window_set_functions(window, (GdkWMFunction)m_gdkFunc); | |
feb1c9fb VS |
814 | |
815 | wxSetFullScreenStateX11((WXDisplay*)GDK_DISPLAY(), | |
816 | (WXWindow)GDK_ROOT_WINDOW(), | |
817 | (WXWindow)GDK_WINDOW_XWINDOW(window), | |
818 | show, &m_fsSaveFrame, method); | |
819 | ||
820 | SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y, | |
821 | m_fsSaveFrame.width, m_fsSaveFrame.height); | |
8166ab43 | 822 | } |
7d9f12f3 | 823 | } |
8166ab43 | 824 | |
3b2931fb VZ |
825 | // documented behaviour is to show the window if it's still hidden when |
826 | // showing it full screen | |
1529bc41 | 827 | if (show) |
3b2931fb VZ |
828 | Show(); |
829 | ||
0a164d4c | 830 | return true; |
7d9f12f3 VS |
831 | } |
832 | ||
833 | // ---------------------------------------------------------------------------- | |
834 | // overridden wxWindow methods | |
835 | // ---------------------------------------------------------------------------- | |
836 | ||
d0285203 RR |
837 | void wxTopLevelWindowGTK::Refresh( bool WXUNUSED(eraseBackground), const wxRect *WXUNUSED(rect) ) |
838 | { | |
839 | wxCHECK_RET( m_widget, wxT("invalid frame") ); | |
03647350 | 840 | |
92f9888c FM |
841 | gtk_widget_queue_draw( m_widget ); |
842 | ||
385e8575 PC |
843 | GdkWindow* window = NULL; |
844 | if (m_wxwindow) | |
845 | window = gtk_widget_get_window(m_wxwindow); | |
846 | if (window) | |
847 | gdk_window_invalidate_rect(window, NULL, true); | |
d0285203 RR |
848 | } |
849 | ||
7d9f12f3 VS |
850 | bool wxTopLevelWindowGTK::Show( bool show ) |
851 | { | |
82b978d7 | 852 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
7d9f12f3 | 853 | |
40fd70f1 | 854 | bool deferShow = show && !m_isShown && m_deferShow; |
aacd4b50 PC |
855 | if (deferShow) |
856 | { | |
f5c0761f PC |
857 | deferShow = gs_requestFrameExtentsStatus != 2 && |
858 | m_deferShowAllowed && !gtk_widget_get_realized(m_widget); | |
d2c5fe6e PC |
859 | if (deferShow) |
860 | { | |
861 | deferShow = g_signal_handler_find(m_widget, | |
aacd4b50 PC |
862 | GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA), |
863 | g_signal_lookup("property_notify_event", GTK_TYPE_WIDGET), | |
d2c5fe6e PC |
864 | 0, NULL, NULL, this) != 0; |
865 | } | |
866 | GdkScreen* screen = NULL; | |
867 | if (deferShow) | |
11d8dfd2 | 868 | { |
d2c5fe6e PC |
869 | screen = gtk_widget_get_screen(m_widget); |
870 | GdkAtom atom = gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false); | |
871 | deferShow = gdk_x11_screen_supports_net_wm_hint(screen, atom) != 0; | |
40fd70f1 PC |
872 | // If _NET_REQUEST_FRAME_EXTENTS not supported, don't allow changes |
873 | // to m_decorSize, it breaks saving/restoring window size with | |
874 | // GetSize()/SetSize() because it makes window bigger between each | |
875 | // restore and save. | |
876 | m_updateDecorSize = deferShow; | |
11d8dfd2 | 877 | } |
d2c5fe6e | 878 | |
11d8dfd2 | 879 | m_deferShow = deferShow; |
aacd4b50 | 880 | } |
53e3cd04 | 881 | if (deferShow) |
7d9f12f3 | 882 | { |
d475dd22 PC |
883 | // Initial show. If WM supports _NET_REQUEST_FRAME_EXTENTS, defer |
884 | // calling gtk_widget_show() until _NET_FRAME_EXTENTS property | |
885 | // notification is received, so correct frame extents are known. | |
886 | // This allows resizing m_widget to keep the overall size in sync with | |
887 | // what wxWidgets expects it to be without an obvious change in the | |
888 | // window size immediately after it becomes visible. | |
889 | ||
390f44af PC |
890 | // Realize m_widget, so m_widget->window can be used. Realizing normally |
891 | // causes the widget tree to be size_allocated, which generates size | |
892 | // events in the wrong order. However, the size_allocates will not be | |
893 | // done if the allocation is not the default (1,1). | |
385e8575 PC |
894 | GtkAllocation alloc; |
895 | gtk_widget_get_allocation(m_widget, &alloc); | |
896 | const int alloc_width = alloc.width; | |
390f44af | 897 | if (alloc_width == 1) |
385e8575 PC |
898 | { |
899 | alloc.width = 2; | |
900 | gtk_widget_set_allocation(m_widget, &alloc); | |
901 | } | |
d475dd22 | 902 | gtk_widget_realize(m_widget); |
390f44af | 903 | if (alloc_width == 1) |
385e8575 PC |
904 | { |
905 | alloc.width = 1; | |
906 | gtk_widget_set_allocation(m_widget, &alloc); | |
907 | } | |
d475dd22 | 908 | |
53e3cd04 PC |
909 | // send _NET_REQUEST_FRAME_EXTENTS |
910 | XClientMessageEvent xevent; | |
911 | memset(&xevent, 0, sizeof(xevent)); | |
912 | xevent.type = ClientMessage; | |
385e8575 PC |
913 | GdkWindow* window = gtk_widget_get_window(m_widget); |
914 | xevent.window = gdk_x11_drawable_get_xid(window); | |
53e3cd04 | 915 | xevent.message_type = gdk_x11_atom_to_xatom_for_display( |
385e8575 | 916 | gdk_drawable_get_display(window), |
53e3cd04 PC |
917 | gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false)); |
918 | xevent.format = 32; | |
385e8575 | 919 | Display* display = gdk_x11_drawable_get_xdisplay(window); |
53e3cd04 PC |
920 | XSendEvent(display, DefaultRootWindow(display), false, |
921 | SubstructureNotifyMask | SubstructureRedirectMask, | |
922 | (XEvent*)&xevent); | |
923 | ||
f5c0761f PC |
924 | if (gs_requestFrameExtentsStatus == 0) |
925 | { | |
926 | // if WM does not respond to request within 1 second, | |
927 | // we assume support for _NET_REQUEST_FRAME_EXTENTS is not working | |
928 | m_netFrameExtentsTimerId = | |
929 | g_timeout_add(1000, request_frame_extents_timeout, this); | |
930 | } | |
931 | ||
53e3cd04 PC |
932 | // defer calling gtk_widget_show() |
933 | m_isShown = true; | |
934 | return true; | |
935 | } | |
d475dd22 | 936 | |
fc9ab22a | 937 | if (show && !gtk_widget_get_realized(m_widget)) |
53e3cd04 | 938 | { |
cca410b3 PC |
939 | // size_allocate signals occur in reverse order (bottom to top). |
940 | // Things work better if the initial wxSizeEvents are sent (from the | |
941 | // top down), before the initial size_allocate signals occur. | |
942 | wxSizeEvent event(GetSize(), GetId()); | |
943 | event.SetEventObject(this); | |
937013e0 | 944 | HandleWindowEvent(event); |
7d9f12f3 | 945 | } |
0a164d4c | 946 | |
3c7620f6 | 947 | bool change = base_type::Show(show); |
aa34396c | 948 | |
cca410b3 | 949 | if (change && !show) |
aa34396c PC |
950 | { |
951 | // make sure window has a non-default position, so when it is shown | |
952 | // again, it won't be repositioned by WM as if it were a new window | |
953 | // Note that this must be done _after_ the window is hidden. | |
954 | gtk_window_move((GtkWindow*)m_widget, m_x, m_y); | |
955 | } | |
956 | ||
cca410b3 | 957 | return change; |
7d9f12f3 VS |
958 | } |
959 | ||
52802b07 PC |
960 | void wxTopLevelWindowGTK::ShowWithoutActivating() |
961 | { | |
e88f9403 PC |
962 | if (!m_isShown) |
963 | { | |
995d5aa2 VZ |
964 | #if GTK_CHECK_VERSION(2,6,0) |
965 | if (!gtk_check_version(2,6,0)) | |
966 | gtk_window_set_focus_on_map(GTK_WINDOW(m_widget), false); | |
967 | #endif // GTK+ 2.6+ | |
968 | ||
e88f9403 PC |
969 | Show(true); |
970 | } | |
52802b07 PC |
971 | } |
972 | ||
a2ac55f5 RR |
973 | void wxTopLevelWindowGTK::Raise() |
974 | { | |
a2ac55f5 | 975 | gtk_window_present( GTK_WINDOW( m_widget ) ); |
a2ac55f5 RR |
976 | } |
977 | ||
7d9f12f3 VS |
978 | void wxTopLevelWindowGTK::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) ) |
979 | { | |
980 | wxFAIL_MSG( wxT("DoMoveWindow called for wxTopLevelWindowGTK") ); | |
981 | } | |
982 | ||
a6cdd521 VZ |
983 | // ---------------------------------------------------------------------------- |
984 | // window geometry | |
985 | // ---------------------------------------------------------------------------- | |
986 | ||
6e264997 VZ |
987 | void wxTopLevelWindowGTK::GTKDoGetSize(int *width, int *height) const |
988 | { | |
290cd301 | 989 | wxSize size(m_width, m_height); |
53e3cd04 PC |
990 | size -= m_decorSize; |
991 | if (size.x < 0) size.x = 0; | |
992 | if (size.y < 0) size.y = 0; | |
426d19f1 JS |
993 | #if wxUSE_LIBHILDON2 |
994 | if (width) { | |
995 | if (size.x == 720) | |
996 | *width = 696; | |
997 | else | |
998 | *width = size.x; | |
999 | } | |
1000 | if (height) { | |
1001 | if (size.y == 420) | |
1002 | *height = 396; | |
1003 | else if (size.y == 270) | |
1004 | *height = 246; | |
1005 | else | |
1006 | *height = size.y; | |
1007 | } | |
1008 | #else // wxUSE_LIBHILDON2 | |
290cd301 PC |
1009 | if (width) *width = size.x; |
1010 | if (height) *height = size.y; | |
426d19f1 | 1011 | #endif // wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON2 |
a6cdd521 VZ |
1012 | } |
1013 | ||
7d9f12f3 VS |
1014 | void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
1015 | { | |
a6cdd521 | 1016 | wxCHECK_RET( m_widget, wxT("invalid frame") ); |
82b978d7 | 1017 | |
6089c4c8 PC |
1018 | m_deferShowAllowed = true; |
1019 | ||
a6cdd521 | 1020 | // deal with the position first |
7d9f12f3 VS |
1021 | int old_x = m_x; |
1022 | int old_y = m_y; | |
1023 | ||
a6cdd521 | 1024 | if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
7d9f12f3 | 1025 | { |
a6cdd521 VZ |
1026 | // -1 means "use existing" unless the flag above is specified |
1027 | if ( x != -1 ) | |
1028 | m_x = x; | |
1029 | if ( y != -1 ) | |
1030 | m_y = y; | |
7d9f12f3 | 1031 | } |
a6cdd521 | 1032 | else // wxSIZE_ALLOW_MINUS_ONE |
7d9f12f3 VS |
1033 | { |
1034 | m_x = x; | |
1035 | m_y = y; | |
7d9f12f3 | 1036 | } |
7d9f12f3 | 1037 | |
a6cdd521 | 1038 | if ( m_x != old_x || m_y != old_y ) |
7d9f12f3 | 1039 | { |
a6cdd521 | 1040 | gtk_window_move( GTK_WINDOW(m_widget), m_x, m_y ); |
7d9f12f3 | 1041 | } |
7d9f12f3 | 1042 | |
290cd301 PC |
1043 | const wxSize oldSize(m_width, m_height); |
1044 | if (width >= 0) | |
1045 | m_width = width; | |
1046 | if (height >= 0) | |
1047 | m_height = height; | |
1048 | ConstrainSize(); | |
1049 | if (m_width != oldSize.x || m_height != oldSize.y) | |
a6cdd521 | 1050 | { |
290cd301 PC |
1051 | int w, h; |
1052 | GTKDoGetSize(&w, &h); | |
1053 | gtk_window_resize(GTK_WINDOW(m_widget), w, h); | |
cca410b3 PC |
1054 | |
1055 | GetClientSize(&m_oldClientWidth, &m_oldClientHeight); | |
1056 | wxSizeEvent event(GetSize(), GetId()); | |
1057 | event.SetEventObject(this); | |
937013e0 | 1058 | HandleWindowEvent(event); |
7d9f12f3 | 1059 | } |
7d9f12f3 VS |
1060 | } |
1061 | ||
428f841b PC |
1062 | void wxTopLevelWindowGTK::DoSetClientSize(int width, int height) |
1063 | { | |
3c7620f6 | 1064 | base_type::DoSetClientSize(width, height); |
d6b17e1a | 1065 | |
6089c4c8 | 1066 | // Since client size is being explicitly set, don't change it later |
d6b17e1a PC |
1067 | // Has to be done after calling base because it calls SetSize, |
1068 | // which sets this true | |
6089c4c8 | 1069 | m_deferShowAllowed = false; |
428f841b PC |
1070 | } |
1071 | ||
7d9f12f3 VS |
1072 | void wxTopLevelWindowGTK::DoGetClientSize( int *width, int *height ) const |
1073 | { | |
cca410b3 PC |
1074 | wxASSERT_MSG(m_widget, wxT("invalid frame")); |
1075 | ||
bb596005 VZ |
1076 | if ( IsIconized() ) |
1077 | { | |
1078 | // for consistency with wxMSW, client area is supposed to be empty for | |
1079 | // the iconized windows | |
1080 | if ( width ) | |
1081 | *width = 0; | |
1082 | if ( height ) | |
1083 | *height = 0; | |
bb596005 | 1084 | } |
cca410b3 | 1085 | else |
290cd301 | 1086 | { |
cca410b3 | 1087 | GTKDoGetSize(width, height); |
290cd301 | 1088 | } |
7d9f12f3 VS |
1089 | } |
1090 | ||
9379c0d7 RR |
1091 | void wxTopLevelWindowGTK::DoSetSizeHints( int minW, int minH, |
1092 | int maxW, int maxH, | |
1093 | int incW, int incH ) | |
7d9f12f3 | 1094 | { |
3c7620f6 | 1095 | base_type::DoSetSizeHints(minW, minH, maxW, maxH, incW, incH); |
d6c11fa9 PC |
1096 | |
1097 | const wxSize minSize = GetMinSize(); | |
1098 | const wxSize maxSize = GetMaxSize(); | |
1099 | GdkGeometry hints; | |
1100 | int hints_mask = 0; | |
1101 | if (minSize.x > 0 || minSize.y > 0) | |
1102 | { | |
1103 | hints_mask |= GDK_HINT_MIN_SIZE; | |
0ab0d0e1 | 1104 | hints.min_width = minSize.x - m_decorSize.x; |
290cd301 PC |
1105 | if (hints.min_width < 0) |
1106 | hints.min_width = 0; | |
0ab0d0e1 | 1107 | hints.min_height = minSize.y - m_decorSize.y; |
290cd301 PC |
1108 | if (hints.min_height < 0) |
1109 | hints.min_height = 0; | |
d6c11fa9 PC |
1110 | } |
1111 | if (maxSize.x > 0 || maxSize.y > 0) | |
1112 | { | |
1113 | hints_mask |= GDK_HINT_MAX_SIZE; | |
0ab0d0e1 | 1114 | hints.max_width = maxSize.x - m_decorSize.x; |
290cd301 PC |
1115 | if (hints.max_width < 0) |
1116 | hints.max_width = INT_MAX; | |
0ab0d0e1 | 1117 | hints.max_height = maxSize.y - m_decorSize.y; |
290cd301 PC |
1118 | if (hints.max_height < 0) |
1119 | hints.max_height = INT_MAX; | |
d6c11fa9 PC |
1120 | } |
1121 | if (incW > 0 || incH > 0) | |
7d9f12f3 | 1122 | { |
d6c11fa9 PC |
1123 | hints_mask |= GDK_HINT_RESIZE_INC; |
1124 | hints.width_inc = incW > 0 ? incW : 1; | |
1125 | hints.height_inc = incH > 0 ? incH : 1; | |
9379c0d7 | 1126 | } |
d6c11fa9 PC |
1127 | gtk_window_set_geometry_hints( |
1128 | (GtkWindow*)m_widget, NULL, &hints, (GdkWindowHints)hints_mask); | |
9379c0d7 | 1129 | } |
7d9f12f3 | 1130 | |
81b0235f PC |
1131 | void wxTopLevelWindowGTK::GTKUpdateDecorSize(const wxSize& decorSize) |
1132 | { | |
fce611e4 PC |
1133 | if (!IsMaximized() && !IsFullScreen()) |
1134 | GetCachedDecorSize() = decorSize; | |
11d8dfd2 | 1135 | if (m_updateDecorSize && m_decorSize != decorSize) |
81b0235f PC |
1136 | { |
1137 | const wxSize diff = decorSize - m_decorSize; | |
1138 | m_decorSize = decorSize; | |
593354ca | 1139 | bool resized = false; |
81b0235f PC |
1140 | if (m_deferShow) |
1141 | { | |
1142 | // keep overall size unchanged by shrinking m_widget | |
1143 | int w, h; | |
1144 | GTKDoGetSize(&w, &h); | |
593354ca PC |
1145 | // but not if size would be less than minimum, it won't take effect |
1146 | const wxSize minSize = GetMinSize(); | |
1147 | if (w >= minSize.x && h >= minSize.y) | |
1148 | { | |
1149 | gtk_window_resize(GTK_WINDOW(m_widget), w, h); | |
1150 | resized = true; | |
1151 | } | |
81b0235f | 1152 | } |
593354ca | 1153 | if (!resized) |
81b0235f PC |
1154 | { |
1155 | // adjust overall size to match change in frame extents | |
1156 | m_width += diff.x; | |
1157 | m_height += diff.y; | |
1158 | if (m_width < 0) m_width = 0; | |
1159 | if (m_height < 0) m_height = 0; | |
390f44af PC |
1160 | m_oldClientWidth = 0; |
1161 | gtk_widget_queue_resize(m_wxwindow); | |
81b0235f PC |
1162 | } |
1163 | } | |
1164 | if (m_deferShow) | |
1165 | { | |
1166 | // gtk_widget_show() was deferred, do it now | |
1167 | m_deferShow = false; | |
1168 | GetClientSize(&m_oldClientWidth, &m_oldClientHeight); | |
1169 | wxSizeEvent sizeEvent(GetSize(), GetId()); | |
1170 | sizeEvent.SetEventObject(this); | |
1171 | HandleWindowEvent(sizeEvent); | |
1172 | ||
1173 | gtk_widget_show(m_widget); | |
1174 | ||
1175 | wxShowEvent showEvent(GetId(), true); | |
1176 | showEvent.SetEventObject(this); | |
1177 | HandleWindowEvent(showEvent); | |
1178 | } | |
1179 | } | |
1180 | ||
fce611e4 PC |
1181 | wxSize& wxTopLevelWindowGTK::GetCachedDecorSize() |
1182 | { | |
1183 | static wxSize size[8]; | |
1184 | ||
1185 | int index = 0; | |
1186 | // title bar | |
1187 | if (m_gdkDecor & (GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE | GDK_DECOR_TITLE)) | |
1188 | index = 1; | |
1189 | // border | |
1190 | if (m_gdkDecor & GDK_DECOR_BORDER) | |
1191 | index |= 2; | |
1192 | // utility window decor can be different | |
1193 | if (m_windowStyle & wxFRAME_TOOL_WINDOW) | |
1194 | index |= 4; | |
1195 | return size[index]; | |
1196 | } | |
1197 | ||
7d9f12f3 VS |
1198 | void wxTopLevelWindowGTK::OnInternalIdle() |
1199 | { | |
6a50a2c4 | 1200 | wxTopLevelWindowBase::OnInternalIdle(); |
0a164d4c | 1201 | |
06fda9e8 RR |
1202 | // Synthetize activate events. |
1203 | if ( g_sendActivateEvent != -1 ) | |
1204 | { | |
1205 | bool activate = g_sendActivateEvent != 0; | |
0a164d4c | 1206 | |
576f7127 RR |
1207 | // if (!activate) wxPrintf( wxT("de") ); |
1208 | // wxPrintf( wxT("activate\n") ); | |
0a164d4c | 1209 | |
06fda9e8 RR |
1210 | // do it only once |
1211 | g_sendActivateEvent = -1; | |
1212 | ||
1213 | wxTheApp->SetActive(activate, (wxWindow *)g_lastActiveFrame); | |
1214 | } | |
7d9f12f3 VS |
1215 | } |
1216 | ||
7d9f12f3 VS |
1217 | // ---------------------------------------------------------------------------- |
1218 | // frame title/icon | |
1219 | // ---------------------------------------------------------------------------- | |
1220 | ||
1221 | void wxTopLevelWindowGTK::SetTitle( const wxString &title ) | |
1222 | { | |
82b978d7 RD |
1223 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
1224 | ||
cb8cc250 WS |
1225 | if ( title == m_title ) |
1226 | return; | |
1227 | ||
7d9f12f3 | 1228 | m_title = title; |
cb8cc250 | 1229 | |
fab591c5 | 1230 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) ); |
7d9f12f3 VS |
1231 | } |
1232 | ||
f618020a MB |
1233 | void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons ) |
1234 | { | |
82b978d7 | 1235 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
f618020a | 1236 | |
3c7620f6 | 1237 | base_type::SetIcons(icons); |
f618020a | 1238 | |
0617ba3e PC |
1239 | // Setting icons before window is realized can cause a GTK assertion if |
1240 | // another TLW is realized before this one, and it has this one as it's | |
1241 | // transient parent. The life demo exibits this problem. | |
fc9ab22a | 1242 | if (gtk_widget_get_realized(m_widget)) |
52d6235d | 1243 | { |
0617ba3e PC |
1244 | GList* list = NULL; |
1245 | for (size_t i = icons.GetIconCount(); i--;) | |
1246 | list = g_list_prepend(list, icons.GetIconByIndex(i).GetPixbuf()); | |
1247 | gtk_window_set_icon_list(GTK_WINDOW(m_widget), list); | |
1248 | g_list_free(list); | |
87e53e2a | 1249 | } |
f618020a MB |
1250 | } |
1251 | ||
7d9f12f3 VS |
1252 | // ---------------------------------------------------------------------------- |
1253 | // frame state: maximized/iconized/normal | |
1254 | // ---------------------------------------------------------------------------- | |
1255 | ||
8805e155 | 1256 | void wxTopLevelWindowGTK::Maximize(bool maximize) |
7d9f12f3 | 1257 | { |
8805e155 RR |
1258 | if (maximize) |
1259 | gtk_window_maximize( GTK_WINDOW( m_widget ) ); | |
1260 | else | |
1261 | gtk_window_unmaximize( GTK_WINDOW( m_widget ) ); | |
7d9f12f3 VS |
1262 | } |
1263 | ||
1264 | bool wxTopLevelWindowGTK::IsMaximized() const | |
1265 | { | |
385e8575 PC |
1266 | GdkWindow* window = gtk_widget_get_window(m_widget); |
1267 | return window && (gdk_window_get_state(window) & GDK_WINDOW_STATE_MAXIMIZED); | |
7d9f12f3 VS |
1268 | } |
1269 | ||
1270 | void wxTopLevelWindowGTK::Restore() | |
1271 | { | |
8805e155 RR |
1272 | // "Present" seems similar enough to "restore" |
1273 | gtk_window_present( GTK_WINDOW( m_widget ) ); | |
7d9f12f3 VS |
1274 | } |
1275 | ||
1276 | void wxTopLevelWindowGTK::Iconize( bool iconize ) | |
1277 | { | |
8805e155 RR |
1278 | if (iconize) |
1279 | gtk_window_iconify( GTK_WINDOW( m_widget ) ); | |
1280 | else | |
1281 | gtk_window_deiconify( GTK_WINDOW( m_widget ) ); | |
7d9f12f3 VS |
1282 | } |
1283 | ||
1284 | bool wxTopLevelWindowGTK::IsIconized() const | |
1285 | { | |
1286 | return m_isIconized; | |
1287 | } | |
1288 | ||
1289 | void wxTopLevelWindowGTK::SetIconizeState(bool iconize) | |
1290 | { | |
1291 | if ( iconize != m_isIconized ) | |
1292 | { | |
1293 | m_isIconized = iconize; | |
1294 | (void)SendIconizeEvent(iconize); | |
1295 | } | |
1296 | } | |
1297 | ||
5152b0e5 JS |
1298 | void wxTopLevelWindowGTK::AddGrab() |
1299 | { | |
1300 | if (!m_grabbed) | |
1301 | { | |
0a164d4c | 1302 | m_grabbed = true; |
5152b0e5 | 1303 | gtk_grab_add( m_widget ); |
b46b1d59 | 1304 | wxGUIEventLoop().Run(); |
5152b0e5 JS |
1305 | gtk_grab_remove( m_widget ); |
1306 | } | |
1307 | } | |
1308 | ||
1309 | void wxTopLevelWindowGTK::RemoveGrab() | |
1310 | { | |
1311 | if (m_grabbed) | |
1312 | { | |
1313 | gtk_main_quit(); | |
0a164d4c | 1314 | m_grabbed = false; |
5152b0e5 JS |
1315 | } |
1316 | } | |
801225c1 | 1317 | |
6b30a44e | 1318 | bool wxTopLevelWindowGTK::IsActive() |
35ff90a0 | 1319 | { |
06fda9e8 | 1320 | return (this == (wxTopLevelWindowGTK*)g_activeFrame); |
35ff90a0 | 1321 | } |
dca92ddf MR |
1322 | |
1323 | void wxTopLevelWindowGTK::RequestUserAttention(int flags) | |
1324 | { | |
1325 | bool new_hint_value = false; | |
1326 | ||
1327 | // FIXME: This is a workaround to focus handling problem | |
977a41ec FM |
1328 | // If RequestUserAttention is called for example right after a wxSleep, OnInternalIdle |
1329 | // hasn't yet been processed, and the internal focus system is not up to date yet. | |
1330 | // YieldFor(wxEVT_CATEGORY_UI) ensures the processing of it (hopefully it | |
1331 | // won't have side effects) - MR | |
1332 | wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI); | |
dca92ddf | 1333 | |
dca92ddf | 1334 | if(m_urgency_hint >= 0) |
92ed8bec | 1335 | g_source_remove(m_urgency_hint); |
dca92ddf | 1336 | |
ef1a9be4 | 1337 | m_urgency_hint = -2; |
dca92ddf | 1338 | |
fc9ab22a | 1339 | if( gtk_widget_get_realized(m_widget) && !IsActive() ) |
dca92ddf MR |
1340 | { |
1341 | new_hint_value = true; | |
1342 | ||
1343 | if (flags & wxUSER_ATTENTION_INFO) | |
1344 | { | |
92ed8bec | 1345 | m_urgency_hint = g_timeout_add(5000, (GSourceFunc)gtk_frame_urgency_timer_callback, this); |
dca92ddf | 1346 | } else { |
ef1a9be4 | 1347 | m_urgency_hint = -1; |
dca92ddf MR |
1348 | } |
1349 | } | |
1350 | ||
98185146 | 1351 | gtk_window_set_urgency_hint(GTK_WINDOW(m_widget), new_hint_value); |
dca92ddf | 1352 | } |
015dca24 MR |
1353 | |
1354 | void wxTopLevelWindowGTK::SetWindowStyleFlag( long style ) | |
1355 | { | |
1356 | // Store which styles were changed | |
1357 | long styleChanges = style ^ m_windowStyle; | |
1358 | ||
1359 | // Process wxWindow styles. This also updates the internal variable | |
1360 | // Therefore m_windowStyle bits carry now the _new_ style values | |
1361 | wxWindow::SetWindowStyleFlag(style); | |
1362 | ||
1363 | // just return for now if widget does not exist yet | |
1364 | if (!m_widget) | |
1365 | return; | |
1366 | ||
ff654490 VZ |
1367 | if ( styleChanges & wxSTAY_ON_TOP ) |
1368 | { | |
1369 | gtk_window_set_keep_above(GTK_WINDOW(m_widget), | |
1370 | m_windowStyle & wxSTAY_ON_TOP); | |
1371 | } | |
1372 | ||
1373 | if ( styleChanges & wxFRAME_NO_TASKBAR ) | |
8fb82418 | 1374 | { |
ff654490 VZ |
1375 | gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget), |
1376 | m_windowStyle & wxFRAME_NO_TASKBAR); | |
8fb82418 | 1377 | } |
015dca24 | 1378 | } |
07e49707 | 1379 | |
07e49707 MR |
1380 | /* Get the X Window between child and the root window. |
1381 | This should usually be the WM managed XID */ | |
1382 | static Window wxGetTopmostWindowX11(Display *dpy, Window child) | |
1383 | { | |
1384 | Window root, parent; | |
1385 | Window* children; | |
1386 | unsigned int nchildren; | |
1387 | ||
1388 | XQueryTree(dpy, child, &root, &parent, &children, &nchildren); | |
1389 | XFree(children); | |
1390 | ||
1391 | while (parent != root) { | |
1392 | child = parent; | |
1393 | XQueryTree(dpy, child, &root, &parent, &children, &nchildren); | |
1394 | XFree(children); | |
1395 | } | |
1396 | ||
1397 | return child; | |
1398 | } | |
1399 | ||
1400 | bool wxTopLevelWindowGTK::SetTransparent(wxByte alpha) | |
1401 | { | |
385e8575 PC |
1402 | GdkWindow* window = NULL; |
1403 | if (m_widget) | |
1404 | window = gtk_widget_get_window(m_widget); | |
1405 | if (window == NULL) | |
07e49707 MR |
1406 | return false; |
1407 | ||
385e8575 | 1408 | Display* dpy = GDK_WINDOW_XDISPLAY(window); |
07e49707 MR |
1409 | // We need to get the X Window that has the root window as the immediate parent |
1410 | // and m_widget->window as a child. This should be the X Window that the WM manages and | |
1411 | // from which the opacity property is checked from. | |
385e8575 | 1412 | Window win = wxGetTopmostWindowX11(dpy, GDK_WINDOW_XID(window)); |
07e49707 | 1413 | |
07e49707 MR |
1414 | |
1415 | // Using pure Xlib to not have a GTK version check mess due to gtk2.0 not having GdkDisplay | |
1416 | if (alpha == 0xff) | |
1417 | XDeleteProperty(dpy, win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False)); | |
1418 | else | |
d48687a0 PC |
1419 | { |
1420 | long opacity = alpha * 0x1010101L; | |
07e49707 MR |
1421 | XChangeProperty(dpy, win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False), |
1422 | XA_CARDINAL, 32, PropModeReplace, | |
1423 | (unsigned char *) &opacity, 1L); | |
d48687a0 | 1424 | } |
07e49707 MR |
1425 | XSync(dpy, False); |
1426 | return true; | |
1427 | } | |
1428 | ||
1429 | bool wxTopLevelWindowGTK::CanSetTransparent() | |
1430 | { | |
a95a6eb4 | 1431 | // allow to override automatic detection as it's far from perfect |
68893d58 | 1432 | const wxString SYSOPT_TRANSPARENT = "gtk.tlw.can-set-transparent"; |
a95a6eb4 VZ |
1433 | if ( wxSystemOptions::HasOption(SYSOPT_TRANSPARENT) ) |
1434 | { | |
1435 | return wxSystemOptions::GetOptionInt(SYSOPT_TRANSPARENT) != 0; | |
1436 | } | |
1437 | ||
60169b7a MR |
1438 | #if GTK_CHECK_VERSION(2,10,0) |
1439 | if (!gtk_check_version(2,10,0)) | |
1440 | { | |
0b241226 | 1441 | return (gtk_widget_is_composited (m_widget)); |
60169b7a MR |
1442 | } |
1443 | else | |
1444 | #endif // In case of lower versions than gtk+-2.10.0 we could look for _NET_WM_CM_Sn ourselves | |
1445 | { | |
1446 | return false; | |
1447 | } | |
1448 | ||
1449 | #if 0 // Don't be optimistic here for the sake of wxAUI | |
07e49707 MR |
1450 | int opcode, event, error; |
1451 | // Check for the existence of a RGBA visual instead? | |
1452 | return XQueryExtension(gdk_x11_get_default_xdisplay (), | |
1453 | "Composite", &opcode, &event, &error); | |
60169b7a | 1454 | #endif |
07e49707 | 1455 | } |