1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/toplevel.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
22 #define XIconifyWindow XICONIFYWINDOW
25 #include "wx/toplevel.h"
34 #include "wx/gtk/private.h"
35 #include "wx/evtloop.h"
36 #include "wx/sysopt.h"
41 #include "wx/gtk/private/win_gtk.h"
43 #include "wx/unix/utilsx11.h"
46 #include <X11/Xatom.h>
49 #include <hildon-widgets/hildon-program.h>
50 #include <hildon-widgets/hildon-window.h>
51 #endif // wxUSE_LIBHILDON
54 #include <hildon/hildon.h>
55 #endif // wxUSE_LIBHILDON2
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // this is incremented while a modal dialog is shown
62 int wxOpenModalDialogsCount
= 0;
64 // the frame that is currently active (i.e. its child has focus). It is
65 // used to generate wxActivateEvents
66 static wxTopLevelWindowGTK
*g_activeFrame
= NULL
;
67 static wxTopLevelWindowGTK
*g_lastActiveFrame
= NULL
;
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
73 static int g_sendActivateEvent
= -1;
75 // Whether _NET_REQUEST_FRAME_EXTENTS support is working
76 // 0 == not tested yet, 1 == working, 2 == broken
77 static int gs_requestFrameExtentsStatus
;
79 //-----------------------------------------------------------------------------
80 // RequestUserAttention related functions
81 //-----------------------------------------------------------------------------
84 static void wxgtk_window_set_urgency_hint (GtkWindow
*win
,
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
);
93 GdkWindow
* window
= gtk_widget_get_window(GTK_WIDGET(win
));
94 wxCHECK_RET(window
, "wxgtk_window_set_urgency_hint: GdkWindow not realized");
96 Display
* dpy
= GDK_WINDOW_XDISPLAY(window
);
97 Window xid
= GDK_WINDOW_XID(window
);
98 XWMHints
* wm_hints
= XGetWMHints(dpy
, xid
);
101 wm_hints
= XAllocWMHints();
104 wm_hints
->flags
|= XUrgencyHint
;
106 wm_hints
->flags
&= ~XUrgencyHint
;
108 XSetWMHints(dpy
, xid
, wm_hints
);
112 #define gtk_window_set_urgency_hint wxgtk_window_set_urgency_hint
116 static gboolean
gtk_frame_urgency_timer_callback( wxTopLevelWindowGTK
*win
)
118 gtk_window_set_urgency_hint(GTK_WINDOW(win
->m_widget
), false);
120 win
->m_urgency_hint
= -2;
125 //-----------------------------------------------------------------------------
127 //-----------------------------------------------------------------------------
130 static gboolean
gtk_frame_focus_in_callback( GtkWidget
*widget
,
131 GdkEvent
*WXUNUSED(event
),
132 wxTopLevelWindowGTK
*win
)
134 switch ( g_sendActivateEvent
)
137 // we've got focus from outside, synthetize wxActivateEvent
138 g_sendActivateEvent
= 1;
142 // another our window just lost focus, it was already ours before
143 // - don't send any wxActivateEvent
144 g_sendActivateEvent
= -1;
149 g_lastActiveFrame
= g_activeFrame
;
151 // wxPrintf( wxT("active: %s\n"), win->GetTitle().c_str() );
153 // MR: wxRequestUserAttention related block
154 switch( win
->m_urgency_hint
)
157 g_source_remove( win
->m_urgency_hint
);
158 // no break, fallthrough to remove hint too
160 gtk_window_set_urgency_hint(GTK_WINDOW(widget
), false);
161 win
->m_urgency_hint
= -2;
167 wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame
);
168 wxActivateEvent
event(wxEVT_ACTIVATE
, true, g_activeFrame
->GetId());
169 event
.SetEventObject(g_activeFrame
);
170 g_activeFrame
->HandleWindowEvent(event
);
176 //-----------------------------------------------------------------------------
178 //-----------------------------------------------------------------------------
182 gboolean
gtk_frame_focus_out_callback(GtkWidget
* WXUNUSED(widget
),
183 GdkEventFocus
*WXUNUSED(gdk_event
),
184 wxTopLevelWindowGTK
* WXUNUSED(win
))
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;
191 // wxASSERT_MSG( (g_activeFrame == win), wxT("TLW deactivatd although it wasn't active") );
193 // wxPrintf( wxT("inactive: %s\n"), win->GetTitle().c_str() );
197 wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame
);
198 wxActivateEvent
event(wxEVT_ACTIVATE
, false, g_activeFrame
->GetId());
199 event
.SetEventObject(g_activeFrame
);
200 g_activeFrame
->HandleWindowEvent(event
);
202 g_activeFrame
= NULL
;
209 //-----------------------------------------------------------------------------
210 // "size_allocate" from m_wxwindow
211 //-----------------------------------------------------------------------------
215 size_allocate(GtkWidget
*, GtkAllocation
* alloc
, wxTopLevelWindowGTK
* win
)
217 if (win
->m_oldClientWidth
!= alloc
->width
||
218 win
->m_oldClientHeight
!= alloc
->height
)
220 win
->m_oldClientWidth
= alloc
->width
;
221 win
->m_oldClientHeight
= alloc
->height
;
224 gtk_widget_get_allocation(win
->m_widget
, &a
);
225 wxSize
size(a
.width
, a
.height
);
226 size
+= win
->m_decorSize
;
227 win
->m_width
= size
.x
;
228 win
->m_height
= size
.y
;
230 if (!win
->IsIconized())
232 wxSizeEvent
event(size
, win
->GetId());
233 event
.SetEventObject(win
);
234 win
->HandleWindowEvent(event
);
236 // else the window is currently unmapped, don't generate size events
241 // ----------------------------------------------------------------------------
243 // ----------------------------------------------------------------------------
247 void wxgtk_tlw_size_request_callback(GtkWidget
* WXUNUSED(widget
),
248 GtkRequisition
*requisition
,
249 wxTopLevelWindowGTK
*win
)
251 // we must return the size of the window without WM decorations, otherwise
252 // GTK+ gets confused, so don't call just GetSize() here
253 win
->GTKDoGetSize(&requisition
->width
, &requisition
->height
);
257 //-----------------------------------------------------------------------------
259 //-----------------------------------------------------------------------------
263 gtk_frame_delete_callback( GtkWidget
*WXUNUSED(widget
),
264 GdkEvent
*WXUNUSED(event
),
265 wxTopLevelWindowGTK
*win
)
267 if (win
->IsEnabled() &&
268 (wxOpenModalDialogsCount
== 0 || (win
->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) ||
276 //-----------------------------------------------------------------------------
278 //-----------------------------------------------------------------------------
282 gtk_frame_configure_callback( GtkWidget
* widget
,
283 GdkEventConfigure
*WXUNUSED(event
),
284 wxTopLevelWindowGTK
*win
)
286 if (!win
->m_hasVMT
|| !win
->IsShown())
290 gtk_window_get_position((GtkWindow
*)widget
, &point
.x
, &point
.y
);
294 wxMoveEvent
mevent(point
, win
->GetId());
295 mevent
.SetEventObject( win
);
296 win
->HandleWindowEvent( mevent
);
302 //-----------------------------------------------------------------------------
303 // "realize" from m_widget
304 //-----------------------------------------------------------------------------
306 // we cannot the WM hints and icons before the widget has been realized,
307 // so we do this directly after realization
309 void wxTopLevelWindowGTK::GTKHandleRealized()
311 wxNonOwnedWindow::GTKHandleRealized();
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
);
318 // GTK's shrinking/growing policy
319 if ( !(m_gdkFunc
& GDK_FUNC_RESIZE
) )
320 gtk_window_set_resizable(GTK_WINDOW(m_widget
), FALSE
);
321 #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
323 gtk_window_set_policy(GTK_WINDOW(m_widget
), 1, 1, 1);
326 const wxIconBundle
& icons
= GetIcons();
327 if (icons
.GetIconCount())
331 //-----------------------------------------------------------------------------
332 // "map_event" from m_widget
333 //-----------------------------------------------------------------------------
337 gtk_frame_map_callback( GtkWidget
*,
338 GdkEvent
* WXUNUSED(event
),
339 wxTopLevelWindow
*win
)
341 const bool wasIconized
= win
->IsIconized();
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
);
353 // it is possible for m_isShown to be false here, see bug #9909
354 if (win
->wxWindowBase::Show(true))
356 wxShowEvent
eventShow(win
->GetId(), true);
357 eventShow
.SetEventObject(win
);
358 win
->GetEventHandler()->ProcessEvent(eventShow
);
361 #if GTK_CHECK_VERSION(2,6,0)
362 if (!gtk_check_version(2,6,0))
364 // restore focus-on-map setting in case ShowWithoutActivating() was called
365 gtk_window_set_focus_on_map(GTK_WINDOW(win
->m_widget
), true);
373 //-----------------------------------------------------------------------------
374 // "window-state-event" from m_widget
375 //-----------------------------------------------------------------------------
379 gtk_frame_window_state_callback( GtkWidget
* WXUNUSED(widget
),
380 GdkEventWindowState
*event
,
381 wxTopLevelWindow
*win
)
383 if (event
->changed_mask
& GDK_WINDOW_STATE_ICONIFIED
)
384 win
->SetIconizeState((event
->new_window_state
& GDK_WINDOW_STATE_ICONIFIED
) != 0);
386 // if maximized bit changed and it is now set
387 if (event
->changed_mask
& event
->new_window_state
& GDK_WINDOW_STATE_MAXIMIZED
)
389 wxMaximizeEvent
event(win
->GetId());
390 event
.SetEventObject(win
);
391 win
->HandleWindowEvent(event
);
398 //-----------------------------------------------------------------------------
400 bool wxGetFrameExtents(GdkWindow
* window
, int* left
, int* right
, int* top
, int* bottom
)
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
);
407 gulong nitems
, bytes_after
;
409 Status status
= XGetWindowProperty(
410 gdk_x11_drawable_get_xdisplay(window
),
411 gdk_x11_drawable_get_xid(window
),
413 0, 4, false, XA_CARDINAL
,
414 &type
, &format
, &nitems
, &bytes_after
, &data
);
415 const bool success
= status
== Success
&& data
&& nitems
== 4;
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]);
429 //-----------------------------------------------------------------------------
430 // "property_notify_event" from m_widget
431 //-----------------------------------------------------------------------------
434 static gboolean
property_notify_event(
435 GtkWidget
*, GdkEventProperty
* event
, wxTopLevelWindowGTK
* win
)
437 // Watch for changes to _NET_FRAME_EXTENTS property
438 static GdkAtom property
= gdk_atom_intern("_NET_FRAME_EXTENTS", false);
439 if (event
->state
== GDK_PROPERTY_NEW_VALUE
&& event
->atom
== property
)
441 if (win
->m_netFrameExtentsTimerId
)
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;
449 wxSize decorSize
= win
->m_decorSize
;
450 int left
, right
, top
, bottom
;
451 if (wxGetFrameExtents(event
->window
, &left
, &right
, &top
, &bottom
))
452 decorSize
.Set(left
+ right
, top
+ bottom
);
454 win
->GTKUpdateDecorSize(decorSize
);
461 static gboolean
request_frame_extents_timeout(void* data
)
463 // WM support for _NET_REQUEST_FRAME_EXTENTS is broken
464 gs_requestFrameExtentsStatus
= 2;
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
);
478 // ----------------------------------------------------------------------------
479 // wxTopLevelWindowGTK creation
480 // ----------------------------------------------------------------------------
482 void wxTopLevelWindowGTK::Init()
485 m_isIconized
= false;
486 m_fsIsShowing
= false;
487 m_themeEnabled
= true;
492 m_deferShowAllowed
= true;
493 m_updateDecorSize
= true;
494 m_netFrameExtentsTimerId
= 0;
499 bool wxTopLevelWindowGTK::Create( wxWindow
*parent
,
501 const wxString
& title
,
503 const wxSize
& sizeOrig
,
505 const wxString
&name
)
507 // always create a frame of some reasonable, even if arbitrary, size (at
508 // least for MSW compatibility)
509 wxSize size
= sizeOrig
;
510 size
.x
= WidthDefault(size
.x
);
511 size
.y
= HeightDefault(size
.y
);
513 wxTopLevelWindows
.Append( this );
515 if (!PreCreation( parent
, pos
, size
) ||
516 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
518 wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") );
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
)
528 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
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
));
535 #else // !wxUSE_LIBHILDON || !wxUSE_LIBHILDON2
536 m_widget
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
537 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
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
);
548 if (style
& wxFRAME_TOOL_WINDOW
)
550 gtk_window_set_type_hint(GTK_WINDOW(m_widget
),
551 GDK_WINDOW_TYPE_HINT_UTILITY
);
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
;
562 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2
564 g_object_ref(m_widget
);
567 wxWindow
*topParent
= wxGetTopLevelParent(m_parent
);
568 if (topParent
&& (((GTK_IS_WINDOW(topParent
->m_widget
)) &&
569 (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)) ||
570 (style
& wxFRAME_FLOAT_ON_PARENT
)))
572 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
573 GTK_WINDOW(topParent
->m_widget
) );
576 if (style
& wxFRAME_NO_TASKBAR
)
578 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget
), TRUE
);
581 if (style
& wxSTAY_ON_TOP
)
583 gtk_window_set_keep_above(GTK_WINDOW(m_widget
), TRUE
);
585 if (style
& wxMAXIMIZE
)
586 gtk_window_maximize(GTK_WINDOW(m_widget
));
590 gtk_window_set_role( GTK_WINDOW(m_widget
), wxGTK_CONV( name
) );
593 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( title
) );
594 gtk_widget_set_can_focus(m_widget
, false);
596 g_signal_connect (m_widget
, "delete_event",
597 G_CALLBACK (gtk_frame_delete_callback
), this);
599 // m_mainWidget is a GtkVBox, holding the bars and client area (m_wxwindow)
600 m_mainWidget
= gtk_vbox_new(false, 0);
601 gtk_widget_show( m_mainWidget
);
602 gtk_widget_set_can_focus(m_mainWidget
, false);
603 gtk_container_add( GTK_CONTAINER(m_widget
), m_mainWidget
);
605 // m_wxwindow is the client area
606 m_wxwindow
= wxPizza::New();
607 gtk_widget_show( m_wxwindow
);
608 gtk_container_add( GTK_CONTAINER(m_mainWidget
), m_wxwindow
);
610 // we donm't allow the frame to get the focus as otherwise
611 // the frame will grab it at arbitrary focus changes
612 gtk_widget_set_can_focus(m_wxwindow
, false);
614 if (m_parent
) m_parent
->AddChild( this );
616 g_signal_connect(m_wxwindow
, "size_allocate",
617 G_CALLBACK(size_allocate
), this);
619 g_signal_connect (m_widget
, "size_request",
620 G_CALLBACK (wxgtk_tlw_size_request_callback
), this);
623 #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
624 if ((m_x
!= -1) || (m_y
!= -1))
625 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
628 // for some reported size corrections
629 g_signal_connect (m_widget
, "map_event",
630 G_CALLBACK (gtk_frame_map_callback
), this);
632 // for iconized state
633 g_signal_connect (m_widget
, "window_state_event",
634 G_CALLBACK (gtk_frame_window_state_callback
), this);
638 g_signal_connect (m_widget
, "configure_event",
639 G_CALLBACK (gtk_frame_configure_callback
), this);
642 g_signal_connect_after (m_widget
, "focus_in_event",
643 G_CALLBACK (gtk_frame_focus_in_callback
), this);
644 g_signal_connect_after (m_widget
, "focus_out_event",
645 G_CALLBACK (gtk_frame_focus_out_callback
), this);
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);
651 // translate wx decorations styles into Motif WM hints (they are recognized
652 // by other WMs as well)
654 // always enable moving the window as we have no separate flag for enabling
656 m_gdkFunc
= GDK_FUNC_MOVE
;
658 if ( style
& wxCLOSE_BOX
)
659 m_gdkFunc
|= GDK_FUNC_CLOSE
;
661 if ( style
& wxMINIMIZE_BOX
)
662 m_gdkFunc
|= GDK_FUNC_MINIMIZE
;
664 if ( style
& wxMAXIMIZE_BOX
)
665 m_gdkFunc
|= GDK_FUNC_MAXIMIZE
;
667 if ( (style
& wxSIMPLE_BORDER
) || (style
& wxNO_BORDER
) )
673 m_gdkDecor
= GDK_DECOR_BORDER
;
675 if ( style
& wxCAPTION
)
676 m_gdkDecor
|= GDK_DECOR_TITLE
;
678 if ( style
& wxSYSTEM_MENU
)
679 m_gdkDecor
|= GDK_DECOR_MENU
;
681 if ( style
& wxMINIMIZE_BOX
)
682 m_gdkDecor
|= GDK_DECOR_MINIMIZE
;
684 if ( style
& wxMAXIMIZE_BOX
)
685 m_gdkDecor
|= GDK_DECOR_MAXIMIZE
;
687 if ( style
& wxRESIZE_BORDER
)
689 m_gdkFunc
|= GDK_FUNC_RESIZE
;
690 m_gdkDecor
|= GDK_DECOR_RESIZEH
;
694 m_decorSize
= GetCachedDecorSize();
696 GTKDoGetSize(&w
, &h
);
697 gtk_window_set_default_size(GTK_WINDOW(m_widget
), w
, h
);
702 wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
704 if ( m_netFrameExtentsTimerId
)
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
);
711 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
712 // it can also be a (standard) dialog
713 if ( HILDON_IS_WINDOW(m_widget
) )
715 hildon_program_remove_window(wxTheApp
->GetHildonProgram(),
716 HILDON_WINDOW(m_widget
));
718 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2
722 wxFAIL_MSG(wxT("Window still grabbed"));
728 // it may also be GtkScrolledWindow in the case of an MDI child
729 if (GTK_IS_WINDOW(m_widget
))
731 gtk_window_set_focus( GTK_WINDOW(m_widget
), NULL
);
734 if (g_activeFrame
== this)
735 g_activeFrame
= NULL
;
736 if (g_lastActiveFrame
== this)
737 g_lastActiveFrame
= NULL
;
740 bool wxTopLevelWindowGTK::EnableCloseButton( bool enable
)
743 m_gdkFunc
|= GDK_FUNC_CLOSE
;
745 m_gdkFunc
&= ~GDK_FUNC_CLOSE
;
747 GdkWindow
* window
= gtk_widget_get_window(m_widget
);
749 gdk_window_set_functions(window
, (GdkWMFunction
)m_gdkFunc
);
754 bool wxTopLevelWindowGTK::ShowFullScreen(bool show
, long)
756 if (show
== m_fsIsShowing
)
757 return false; // return what?
759 m_fsIsShowing
= show
;
761 wxX11FullScreenMethod method
=
762 wxGetFullScreenMethodX11((WXDisplay
*)GDK_DISPLAY(),
763 (WXWindow
)GDK_ROOT_WINDOW());
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
769 if ( method
== wxX11_FS_WMSPEC
)
772 gtk_window_fullscreen( GTK_WINDOW( m_widget
) );
774 gtk_window_unfullscreen( GTK_WINDOW( m_widget
) );
778 GdkWindow
* window
= gtk_widget_get_window(m_widget
);
782 GetPosition( &m_fsSaveFrame
.x
, &m_fsSaveFrame
.y
);
783 GetSize( &m_fsSaveFrame
.width
, &m_fsSaveFrame
.height
);
785 int screen_width
,screen_height
;
786 wxDisplaySize( &screen_width
, &screen_height
);
788 gint client_x
, client_y
, root_x
, root_y
;
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);
797 gdk_window_get_origin(window
, &root_x
, &root_y
);
798 gdk_window_get_geometry(window
, &client_x
, &client_y
, &width
, &height
, NULL
);
800 gdk_window_move_resize(
801 window
, -client_x
, -client_y
, screen_width
+ 1, screen_height
+ 1);
803 wxSetFullScreenStateX11((WXDisplay
*)GDK_DISPLAY(),
804 (WXWindow
)GDK_ROOT_WINDOW(),
805 (WXWindow
)GDK_WINDOW_XWINDOW(window
),
806 show
, &m_fsSaveFrame
, method
);
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
);
815 wxSetFullScreenStateX11((WXDisplay
*)GDK_DISPLAY(),
816 (WXWindow
)GDK_ROOT_WINDOW(),
817 (WXWindow
)GDK_WINDOW_XWINDOW(window
),
818 show
, &m_fsSaveFrame
, method
);
820 SetSize(m_fsSaveFrame
.x
, m_fsSaveFrame
.y
,
821 m_fsSaveFrame
.width
, m_fsSaveFrame
.height
);
825 // documented behaviour is to show the window if it's still hidden when
826 // showing it full screen
833 // ----------------------------------------------------------------------------
834 // overridden wxWindow methods
835 // ----------------------------------------------------------------------------
837 void wxTopLevelWindowGTK::Refresh( bool WXUNUSED(eraseBackground
), const wxRect
*WXUNUSED(rect
) )
839 wxCHECK_RET( m_widget
, wxT("invalid frame") );
841 gtk_widget_queue_draw( m_widget
);
843 GdkWindow
* window
= NULL
;
845 window
= gtk_widget_get_window(m_wxwindow
);
847 gdk_window_invalidate_rect(window
, NULL
, true);
850 bool wxTopLevelWindowGTK::Show( bool show
)
852 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
854 bool deferShow
= show
&& !m_isShown
&& m_deferShow
;
857 deferShow
= gs_requestFrameExtentsStatus
!= 2 &&
858 m_deferShowAllowed
&& !gtk_widget_get_realized(m_widget
);
861 deferShow
= g_signal_handler_find(m_widget
,
862 GSignalMatchType(G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_DATA
),
863 g_signal_lookup("property_notify_event", GTK_TYPE_WIDGET
),
864 0, NULL
, NULL
, this) != 0;
866 GdkScreen
* screen
= NULL
;
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;
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
876 m_updateDecorSize
= deferShow
;
879 m_deferShow
= deferShow
;
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.
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).
895 gtk_widget_get_allocation(m_widget
, &alloc
);
896 const int alloc_width
= alloc
.width
;
897 if (alloc_width
== 1)
900 gtk_widget_set_allocation(m_widget
, &alloc
);
902 gtk_widget_realize(m_widget
);
903 if (alloc_width
== 1)
906 gtk_widget_set_allocation(m_widget
, &alloc
);
909 // send _NET_REQUEST_FRAME_EXTENTS
910 XClientMessageEvent xevent
;
911 memset(&xevent
, 0, sizeof(xevent
));
912 xevent
.type
= ClientMessage
;
913 GdkWindow
* window
= gtk_widget_get_window(m_widget
);
914 xevent
.window
= gdk_x11_drawable_get_xid(window
);
915 xevent
.message_type
= gdk_x11_atom_to_xatom_for_display(
916 gdk_drawable_get_display(window
),
917 gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false));
919 Display
* display
= gdk_x11_drawable_get_xdisplay(window
);
920 XSendEvent(display
, DefaultRootWindow(display
), false,
921 SubstructureNotifyMask
| SubstructureRedirectMask
,
924 if (gs_requestFrameExtentsStatus
== 0)
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);
932 // defer calling gtk_widget_show()
937 if (show
&& !gtk_widget_get_realized(m_widget
))
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);
944 HandleWindowEvent(event
);
947 bool change
= base_type::Show(show
);
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
);
960 void wxTopLevelWindowGTK::ShowWithoutActivating()
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);
973 void wxTopLevelWindowGTK::Raise()
975 gtk_window_present( GTK_WINDOW( m_widget
) );
978 void wxTopLevelWindowGTK::DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
) )
980 wxFAIL_MSG( wxT("DoMoveWindow called for wxTopLevelWindowGTK") );
983 // ----------------------------------------------------------------------------
985 // ----------------------------------------------------------------------------
987 void wxTopLevelWindowGTK::GTKDoGetSize(int *width
, int *height
) const
989 wxSize
size(m_width
, m_height
);
991 if (size
.x
< 0) size
.x
= 0;
992 if (size
.y
< 0) size
.y
= 0;
1003 else if (size
.y
== 270)
1008 #else // wxUSE_LIBHILDON2
1009 if (width
) *width
= size
.x
;
1010 if (height
) *height
= size
.y
;
1011 #endif // wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON2
1014 void wxTopLevelWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1016 wxCHECK_RET( m_widget
, wxT("invalid frame") );
1018 m_deferShowAllowed
= true;
1020 // deal with the position first
1024 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1026 // -1 means "use existing" unless the flag above is specified
1032 else // wxSIZE_ALLOW_MINUS_ONE
1038 if ( m_x
!= old_x
|| m_y
!= old_y
)
1040 gtk_window_move( GTK_WINDOW(m_widget
), m_x
, m_y
);
1043 const wxSize
oldSize(m_width
, m_height
);
1049 if (m_width
!= oldSize
.x
|| m_height
!= oldSize
.y
)
1052 GTKDoGetSize(&w
, &h
);
1053 gtk_window_resize(GTK_WINDOW(m_widget
), w
, h
);
1055 GetClientSize(&m_oldClientWidth
, &m_oldClientHeight
);
1056 wxSizeEvent
event(GetSize(), GetId());
1057 event
.SetEventObject(this);
1058 HandleWindowEvent(event
);
1062 void wxTopLevelWindowGTK::DoSetClientSize(int width
, int height
)
1064 base_type::DoSetClientSize(width
, height
);
1066 // Since client size is being explicitly set, don't change it later
1067 // Has to be done after calling base because it calls SetSize,
1068 // which sets this true
1069 m_deferShowAllowed
= false;
1072 void wxTopLevelWindowGTK::DoGetClientSize( int *width
, int *height
) const
1074 wxASSERT_MSG(m_widget
, wxT("invalid frame"));
1078 // for consistency with wxMSW, client area is supposed to be empty for
1079 // the iconized windows
1087 GTKDoGetSize(width
, height
);
1091 void wxTopLevelWindowGTK::DoSetSizeHints( int minW
, int minH
,
1093 int incW
, int incH
)
1095 base_type::DoSetSizeHints(minW
, minH
, maxW
, maxH
, incW
, incH
);
1097 const wxSize minSize
= GetMinSize();
1098 const wxSize maxSize
= GetMaxSize();
1101 if (minSize
.x
> 0 || minSize
.y
> 0)
1103 hints_mask
|= GDK_HINT_MIN_SIZE
;
1104 hints
.min_width
= minSize
.x
- m_decorSize
.x
;
1105 if (hints
.min_width
< 0)
1106 hints
.min_width
= 0;
1107 hints
.min_height
= minSize
.y
- m_decorSize
.y
;
1108 if (hints
.min_height
< 0)
1109 hints
.min_height
= 0;
1111 if (maxSize
.x
> 0 || maxSize
.y
> 0)
1113 hints_mask
|= GDK_HINT_MAX_SIZE
;
1114 hints
.max_width
= maxSize
.x
- m_decorSize
.x
;
1115 if (hints
.max_width
< 0)
1116 hints
.max_width
= INT_MAX
;
1117 hints
.max_height
= maxSize
.y
- m_decorSize
.y
;
1118 if (hints
.max_height
< 0)
1119 hints
.max_height
= INT_MAX
;
1121 if (incW
> 0 || incH
> 0)
1123 hints_mask
|= GDK_HINT_RESIZE_INC
;
1124 hints
.width_inc
= incW
> 0 ? incW
: 1;
1125 hints
.height_inc
= incH
> 0 ? incH
: 1;
1127 gtk_window_set_geometry_hints(
1128 (GtkWindow
*)m_widget
, NULL
, &hints
, (GdkWindowHints
)hints_mask
);
1131 void wxTopLevelWindowGTK::GTKUpdateDecorSize(const wxSize
& decorSize
)
1133 if (!IsMaximized() && !IsFullScreen())
1134 GetCachedDecorSize() = decorSize
;
1135 if (m_updateDecorSize
&& m_decorSize
!= decorSize
)
1137 const wxSize diff
= decorSize
- m_decorSize
;
1138 m_decorSize
= decorSize
;
1139 bool resized
= false;
1142 // keep overall size unchanged by shrinking m_widget
1144 GTKDoGetSize(&w
, &h
);
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
)
1149 gtk_window_resize(GTK_WINDOW(m_widget
), w
, h
);
1155 // adjust overall size to match change in frame extents
1158 if (m_width
< 0) m_width
= 0;
1159 if (m_height
< 0) m_height
= 0;
1160 m_oldClientWidth
= 0;
1161 gtk_widget_queue_resize(m_wxwindow
);
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
);
1173 gtk_widget_show(m_widget
);
1175 wxShowEvent
showEvent(GetId(), true);
1176 showEvent
.SetEventObject(this);
1177 HandleWindowEvent(showEvent
);
1181 wxSize
& wxTopLevelWindowGTK::GetCachedDecorSize()
1183 static wxSize size
[8];
1187 if (m_gdkDecor
& (GDK_DECOR_MENU
| GDK_DECOR_MINIMIZE
| GDK_DECOR_MAXIMIZE
| GDK_DECOR_TITLE
))
1190 if (m_gdkDecor
& GDK_DECOR_BORDER
)
1192 // utility window decor can be different
1193 if (m_windowStyle
& wxFRAME_TOOL_WINDOW
)
1198 void wxTopLevelWindowGTK::OnInternalIdle()
1200 wxTopLevelWindowBase::OnInternalIdle();
1202 // Synthetize activate events.
1203 if ( g_sendActivateEvent
!= -1 )
1205 bool activate
= g_sendActivateEvent
!= 0;
1207 // if (!activate) wxPrintf( wxT("de") );
1208 // wxPrintf( wxT("activate\n") );
1211 g_sendActivateEvent
= -1;
1213 wxTheApp
->SetActive(activate
, (wxWindow
*)g_lastActiveFrame
);
1217 // ----------------------------------------------------------------------------
1219 // ----------------------------------------------------------------------------
1221 void wxTopLevelWindowGTK::SetTitle( const wxString
&title
)
1223 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
1225 if ( title
== m_title
)
1230 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( title
) );
1233 void wxTopLevelWindowGTK::SetIcons( const wxIconBundle
&icons
)
1235 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
1237 base_type::SetIcons(icons
);
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.
1242 if (gtk_widget_get_realized(m_widget
))
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
);
1252 // ----------------------------------------------------------------------------
1253 // frame state: maximized/iconized/normal
1254 // ----------------------------------------------------------------------------
1256 void wxTopLevelWindowGTK::Maximize(bool maximize
)
1259 gtk_window_maximize( GTK_WINDOW( m_widget
) );
1261 gtk_window_unmaximize( GTK_WINDOW( m_widget
) );
1264 bool wxTopLevelWindowGTK::IsMaximized() const
1266 GdkWindow
* window
= gtk_widget_get_window(m_widget
);
1267 return window
&& (gdk_window_get_state(window
) & GDK_WINDOW_STATE_MAXIMIZED
);
1270 void wxTopLevelWindowGTK::Restore()
1272 // "Present" seems similar enough to "restore"
1273 gtk_window_present( GTK_WINDOW( m_widget
) );
1276 void wxTopLevelWindowGTK::Iconize( bool iconize
)
1279 gtk_window_iconify( GTK_WINDOW( m_widget
) );
1281 gtk_window_deiconify( GTK_WINDOW( m_widget
) );
1284 bool wxTopLevelWindowGTK::IsIconized() const
1286 return m_isIconized
;
1289 void wxTopLevelWindowGTK::SetIconizeState(bool iconize
)
1291 if ( iconize
!= m_isIconized
)
1293 m_isIconized
= iconize
;
1294 (void)SendIconizeEvent(iconize
);
1298 void wxTopLevelWindowGTK::AddGrab()
1303 gtk_grab_add( m_widget
);
1304 wxGUIEventLoop().Run();
1305 gtk_grab_remove( m_widget
);
1309 void wxTopLevelWindowGTK::RemoveGrab()
1318 bool wxTopLevelWindowGTK::IsActive()
1320 return (this == (wxTopLevelWindowGTK
*)g_activeFrame
);
1323 void wxTopLevelWindowGTK::RequestUserAttention(int flags
)
1325 bool new_hint_value
= false;
1327 // FIXME: This is a workaround to focus handling problem
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
);
1334 if(m_urgency_hint
>= 0)
1335 g_source_remove(m_urgency_hint
);
1337 m_urgency_hint
= -2;
1339 if( gtk_widget_get_realized(m_widget
) && !IsActive() )
1341 new_hint_value
= true;
1343 if (flags
& wxUSER_ATTENTION_INFO
)
1345 m_urgency_hint
= g_timeout_add(5000, (GSourceFunc
)gtk_frame_urgency_timer_callback
, this);
1347 m_urgency_hint
= -1;
1351 gtk_window_set_urgency_hint(GTK_WINDOW(m_widget
), new_hint_value
);
1354 void wxTopLevelWindowGTK::SetWindowStyleFlag( long style
)
1356 // Store which styles were changed
1357 long styleChanges
= style
^ m_windowStyle
;
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
);
1363 // just return for now if widget does not exist yet
1367 if ( styleChanges
& wxSTAY_ON_TOP
)
1369 gtk_window_set_keep_above(GTK_WINDOW(m_widget
),
1370 m_windowStyle
& wxSTAY_ON_TOP
);
1373 if ( styleChanges
& wxFRAME_NO_TASKBAR
)
1375 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget
),
1376 m_windowStyle
& wxFRAME_NO_TASKBAR
);
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
)
1384 Window root
, parent
;
1386 unsigned int nchildren
;
1388 XQueryTree(dpy
, child
, &root
, &parent
, &children
, &nchildren
);
1391 while (parent
!= root
) {
1393 XQueryTree(dpy
, child
, &root
, &parent
, &children
, &nchildren
);
1400 bool wxTopLevelWindowGTK::SetTransparent(wxByte alpha
)
1402 GdkWindow
* window
= NULL
;
1404 window
= gtk_widget_get_window(m_widget
);
1408 Display
* dpy
= GDK_WINDOW_XDISPLAY(window
);
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.
1412 Window win
= wxGetTopmostWindowX11(dpy
, GDK_WINDOW_XID(window
));
1415 // Using pure Xlib to not have a GTK version check mess due to gtk2.0 not having GdkDisplay
1417 XDeleteProperty(dpy
, win
, XInternAtom(dpy
, "_NET_WM_WINDOW_OPACITY", False
));
1420 long opacity
= alpha
* 0x1010101L
;
1421 XChangeProperty(dpy
, win
, XInternAtom(dpy
, "_NET_WM_WINDOW_OPACITY", False
),
1422 XA_CARDINAL
, 32, PropModeReplace
,
1423 (unsigned char *) &opacity
, 1L);
1429 bool wxTopLevelWindowGTK::CanSetTransparent()
1431 // allow to override automatic detection as it's far from perfect
1432 const wxString SYSOPT_TRANSPARENT
= "gtk.tlw.can-set-transparent";
1433 if ( wxSystemOptions::HasOption(SYSOPT_TRANSPARENT
) )
1435 return wxSystemOptions::GetOptionInt(SYSOPT_TRANSPARENT
) != 0;
1438 #if GTK_CHECK_VERSION(2,10,0)
1439 if (!gtk_check_version(2,10,0))
1441 return (gtk_widget_is_composited (m_widget
));
1444 #endif // In case of lower versions than gtk+-2.10.0 we could look for _NET_WM_CM_Sn ourselves
1449 #if 0 // Don't be optimistic here for the sake of wxAUI
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
);