New attempt to implement wxNO_FULL_REDRAW_ON_REPAINT.
[wxWidgets.git] / src / x11 / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: x11/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for X11
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 24.09.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2002 Julian Smart
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "toplevel.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/toplevel.h"
34 #include "wx/string.h"
35 #include "wx/log.h"
36 #include "wx/intl.h"
37 #include "wx/frame.h"
38 #include "wx/menu.h"
39 #include "wx/statusbr.h"
40 #endif //WX_PRECOMP
41
42 #include "wx/settings.h"
43 #include "wx/x11/private.h"
44 #include "X11/Xutil.h"
45
46 bool wxMWMIsRunning(Window w);
47
48 // ----------------------------------------------------------------------------
49 // wxTopLevelWindowX11 creation
50 // ----------------------------------------------------------------------------
51
52 void wxTopLevelWindowX11::Init()
53 {
54 m_iconized =
55 m_maximizeOnShow = FALSE;
56
57 // unlike (almost?) all other windows, frames are created hidden
58 m_isShown = FALSE;
59
60 // Data to save/restore when calling ShowFullScreen
61 m_fsStyle = 0;
62 m_fsIsMaximized = FALSE;
63 m_fsIsShowing = FALSE;
64
65 m_needResizeInIdle = FALSE;
66 }
67
68 bool wxTopLevelWindowX11::Create(wxWindow *parent,
69 wxWindowID id,
70 const wxString& title,
71 const wxPoint& pos,
72 const wxSize& size,
73 long style,
74 const wxString& name)
75 {
76 // init our fields
77 Init();
78
79 m_windowStyle = style;
80 m_parent = parent;
81
82 SetName(name);
83
84 m_windowId = id == -1 ? NewControlId() : id;
85
86 if (parent)
87 parent->AddChild(this);
88
89 wxTopLevelWindows.Append(this);
90
91 Display *xdisplay = wxGlobalDisplay();
92 int xscreen = DefaultScreen( xdisplay );
93 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
94 Window xparent = RootWindow( xdisplay, xscreen );
95 Colormap cm = DefaultColormap( xdisplay, xscreen );
96
97 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
98 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
99 else
100 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
101 m_backgroundColour.CalcPixel( (WXColormap) cm );
102 m_hasBgCol = TRUE;
103
104 wxSize size2(size);
105 if (size2.x == -1)
106 size2.x = 100;
107 if (size2.y == -1)
108 size2.y = 100;
109
110 wxPoint pos2(pos);
111 if (pos2.x == -1)
112 pos2.x = 100;
113 if (pos2.y == -1)
114 pos2.y = 100;
115
116 #if !wxUSE_NANOX
117 XSetWindowAttributes xattributes;
118 XSizeHints size_hints;
119
120 long xattributes_mask =
121 CWBorderPixel | CWBackPixel;
122
123 xattributes.background_pixel = m_backgroundColour.GetPixel();
124 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
125
126 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE ))
127 {
128 xattributes_mask |= CWBitGravity;
129 xattributes.bit_gravity = StaticGravity;
130 }
131
132 // TODO: if we want no border, caption etc.,
133 // I think we set this to True to remove decorations
134 // No. RR.
135 // Yes :-) JACS (because some WMs don't respect
136 // the hints)
137 // xattributes.override_redirect = (style & wxNO_BORDER) ? True : False;
138
139 xattributes_mask |= CWEventMask;
140 xattributes.event_mask =
141 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
142 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
143 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
144 PropertyChangeMask;
145
146 Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
147 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
148 #else
149 long backColor, foreColor;
150 backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
151 foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
152
153 Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
154 0, 0, InputOutput, xvisual, backColor, foreColor);
155 #endif
156
157 m_mainWidget = (WXWindow) xwindow;
158
159 #if wxUSE_NANOX
160 XSelectInput( xdisplay, xwindow,
161 GR_EVENT_MASK_CLOSE_REQ |
162 ExposureMask |
163 KeyPressMask |
164 KeyReleaseMask |
165 ButtonPressMask |
166 ButtonReleaseMask |
167 ButtonMotionMask |
168 EnterWindowMask |
169 LeaveWindowMask |
170 PointerMotionMask |
171 KeymapStateMask |
172 FocusChangeMask |
173 ColormapChangeMask |
174 StructureNotifyMask |
175 PropertyChangeMask
176 );
177 #endif
178
179 wxAddWindowToTable( xwindow, (wxWindow*) this );
180
181 // Set background to None which will prevent X11 from clearing the
182 // background completely.
183 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
184
185 #if !wxUSE_NANOX
186 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
187 {
188 if (GetParent() && GetParent()->GetMainWindow())
189 {
190 Window xparentwindow = (Window) GetParent()->GetMainWindow();
191 XSetTransientForHint( xdisplay, xwindow, xparentwindow );
192 }
193 }
194
195 size_hints.flags = PSize | PPosition;
196 size_hints.x = pos2.x;
197 size_hints.y = pos2.y;
198 size_hints.width = size2.x;
199 size_hints.height = size2.y;
200 XSetWMNormalHints( xdisplay, xwindow, &size_hints);
201
202 XWMHints wm_hints;
203 wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
204 wm_hints.input = True;
205 wm_hints.initial_state = NormalState;
206 XSetWMHints( xdisplay, xwindow, &wm_hints);
207
208 Atom wm_protocols[2];
209 wm_protocols[0] = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False );
210 wm_protocols[1] = XInternAtom( xdisplay, "WM_TAKE_FOCUS", False );
211 XSetWMProtocols( xdisplay, xwindow, wm_protocols, 2);
212
213 #if 0 // TODO
214 // You will need a compliant window manager for this to work
215 // (e.g. sawfish/enlightenment/kde/icewm/windowmaker)
216 if (style & wxSTAY_ON_TOP)
217 {
218 CARD32 data = 4; // or should this be 6? According to http://developer.gnome.org/doc/standards/wm/c44.html
219 XChangeProperty (xdisplay,
220 xwindow,
221 XInternAtom (xdisplay, "_WIN_LAYER", False),
222 XA_CARDINAL,
223 32,
224 PropModeReplace,
225 (unsigned char *)&data,
226 1);
227 }
228 #endif
229
230 #endif
231
232 wxSetWMDecorations( xwindow, style);
233
234 SetTitle(title);
235
236 return TRUE;
237 }
238
239 wxTopLevelWindowX11::~wxTopLevelWindowX11()
240 {
241 wxTopLevelWindows.DeleteObject(this);
242
243 // If this is the last top-level window, exit.
244 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
245 {
246 wxTheApp->SetTopWindow(NULL);
247
248 if (wxTheApp->GetExitOnFrameDelete())
249 {
250 // Signal to the app that we're going to close
251 wxTheApp->ExitMainLoop();
252 }
253 }
254 }
255
256 void wxTopLevelWindowX11::OnInternalIdle()
257 {
258 wxWindow::OnInternalIdle();
259
260 if (m_needResizeInIdle)
261 {
262 wxSizeEvent event( GetClientSize(), GetId() );
263 event.SetEventObject( this );
264 GetEventHandler()->ProcessEvent( event );
265
266 m_needResizeInIdle = FALSE;
267 }
268 }
269
270 // ----------------------------------------------------------------------------
271 // wxTopLevelWindowX11 showing
272 // ----------------------------------------------------------------------------
273
274 bool wxTopLevelWindowX11::Show(bool show)
275 {
276 // Nano-X has to force a size event,
277 // else there's no initial size.
278 #if wxUSE_NANOX
279 if (show)
280 #else
281 if (show && m_needResizeInIdle)
282 #endif
283 {
284 wxSizeEvent event(GetSize(), GetId());
285 event.SetEventObject(this);
286 GetEventHandler()->ProcessEvent(event);
287
288 m_needResizeInIdle = FALSE;
289 }
290
291 if (show)
292 {
293 // This does the layout _before_ the
294 // window is shown, else the items are
295 // drawn first at the wrong positions,
296 // then at the correct positions.
297 if (GetAutoLayout())
298 {
299 Layout();
300 }
301 }
302
303 return wxWindowX11::Show(show);
304 }
305
306 // ----------------------------------------------------------------------------
307 // wxTopLevelWindowX11 maximize/minimize
308 // ----------------------------------------------------------------------------
309
310 void wxTopLevelWindowX11::Maximize(bool maximize)
311 {
312 // TODO
313 }
314
315 bool wxTopLevelWindowX11::IsMaximized() const
316 {
317 // TODO
318 return TRUE;
319 }
320
321 void wxTopLevelWindowX11::Iconize(bool iconize)
322 {
323 if (!m_iconized && GetMainWindow())
324 {
325 if (XIconifyWindow(wxGlobalDisplay(),
326 (Window) GetMainWindow(), DefaultScreen(wxGlobalDisplay())) != 0)
327 m_iconized = TRUE;
328 }
329 }
330
331 bool wxTopLevelWindowX11::IsIconized() const
332 {
333 return m_iconized;
334 }
335
336 void wxTopLevelWindowX11::Restore()
337 {
338 // This is the way to deiconify the window, according to the X FAQ
339 if (m_iconized && GetMainWindow())
340 {
341 XMapWindow(wxGlobalDisplay(), (Window) GetMainWindow());
342 m_iconized = FALSE;
343 }
344 }
345
346 // ----------------------------------------------------------------------------
347 // wxTopLevelWindowX11 fullscreen
348 // ----------------------------------------------------------------------------
349
350 bool wxTopLevelWindowX11::ShowFullScreen(bool show, long style)
351 {
352 if (show)
353 {
354 if (IsFullScreen())
355 return FALSE;
356
357 m_fsIsShowing = TRUE;
358 m_fsStyle = style;
359
360 // TODO
361
362 return TRUE;
363 }
364 else
365 {
366 if (!IsFullScreen())
367 return FALSE;
368
369 m_fsIsShowing = FALSE;
370
371 // TODO
372 return TRUE;
373 }
374 }
375
376 // ----------------------------------------------------------------------------
377 // wxTopLevelWindowX11 misc
378 // ----------------------------------------------------------------------------
379
380 void wxTopLevelWindowX11::SetIcon(const wxIcon& icon)
381 {
382 // this sets m_icon
383 wxTopLevelWindowBase::SetIcon(icon);
384
385 if (icon.Ok() && GetMainWindow())
386 {
387 #if wxUSE_NANOX
388 #else
389 XWMHints *wmHints = XAllocWMHints();
390 wmHints->icon_pixmap = (Pixmap) icon.GetPixmap();
391
392 wmHints->flags = IconPixmapHint;
393
394 if (icon.GetMask())
395 {
396 wmHints->flags |= IconMaskHint;
397 wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap();
398 }
399
400 XSetWMHints(wxGlobalDisplay(), (Window) GetMainWindow(), wmHints);
401 XFree(wmHints);
402 #endif
403 }
404 }
405
406 void wxTopLevelWindowX11::SetTitle(const wxString& title)
407 {
408 m_title = title;
409 if (GetMainWindow())
410 {
411 XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(),
412 (const char*) title);
413 XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(),
414 (const char*) title);
415
416 // Use this if the platform doesn't supply the above functions.
417 #if 0
418 XTextProperty textProperty;
419 textProperty.value = (unsigned char*) title;
420 textProperty.encoding = XA_STRING;
421 textProperty.format = 8;
422 textProperty.nitems = 1;
423
424 XSetTextProperty(wxGlobalDisplay(), (Window) GetMainWindow(),
425 & textProperty, WM_NAME);
426 #endif
427 }
428 }
429
430 wxString wxTopLevelWindowX11::GetTitle() const
431 {
432 return m_title;
433 }
434
435 #ifndef MWM_DECOR_BORDER
436 /* bit definitions for MwmHints.flags */
437 #define MWM_HINTS_FUNCTIONS (1L << 0)
438 #define MWM_HINTS_DECORATIONS (1L << 1)
439 #define MWM_HINTS_INPUT_MODE (1L << 2)
440 #define MWM_HINTS_STATUS (1L << 3)
441
442 #define MWM_DECOR_ALL (1L << 0)
443 #define MWM_DECOR_BORDER (1L << 1)
444 #define MWM_DECOR_RESIZEH (1L << 2)
445 #define MWM_DECOR_TITLE (1L << 3)
446 #define MWM_DECOR_MENU (1L << 4)
447 #define MWM_DECOR_MINIMIZE (1L << 5)
448 #define MWM_DECOR_MAXIMIZE (1L << 6)
449 #endif
450
451 struct MwmHints {
452 long flags;
453 long functions;
454 long decorations;
455 long input_mode;
456 };
457
458 #define PROP_MOTIF_WM_HINTS_ELEMENTS 5
459
460 // Set the window manager decorations according to the
461 // given wxWindows style
462 bool wxSetWMDecorations(Window w, long style)
463 {
464 #if wxUSE_NANOX
465 GR_WM_PROPERTIES wmProp;
466
467 wmProp.flags = 0;
468 wmProp.props = 0;
469
470 if (style & wxRESIZE_BORDER)
471 {
472 wmProp.props |= GR_WM_PROPS_APPFRAME ;
473 wmProp.flags |= GR_WM_FLAGS_PROPS ;
474 }
475
476 if (style & wxSYSTEM_MENU)
477 {
478 wmProp.props |= GR_WM_PROPS_CLOSEBOX ;
479 wmProp.flags |= GR_WM_FLAGS_PROPS ;
480 }
481
482 if ((style & wxCAPTION) ||
483 (style & wxTINY_CAPTION_HORIZ) ||
484 (style & wxTINY_CAPTION_VERT))
485 {
486 wmProp.props |= GR_WM_PROPS_CAPTION ;
487 wmProp.flags |= GR_WM_FLAGS_PROPS ;
488
489 // The default dialog style doesn't include any kind
490 // of border, which is a bit odd. Anyway, inclusion
491 // of a caption surely implies a border.
492 style |= wxTHICK_FRAME;
493 }
494
495 if (style & wxTHICK_FRAME)
496 {
497 wmProp.props |= GR_WM_PROPS_APPFRAME ;
498 wmProp.flags |= GR_WM_FLAGS_PROPS ;
499 }
500
501 if (style & wxSIMPLE_BORDER)
502 {
503 wmProp.props |= GR_WM_PROPS_BORDER ;
504 wmProp.flags |= GR_WM_FLAGS_PROPS ;
505 }
506
507 if (style & wxMINIMIZE_BOX)
508 {
509 }
510
511 if (style & wxMAXIMIZE_BOX)
512 {
513 wmProp.props |= GR_WM_PROPS_MAXIMIZE ;
514 wmProp.flags |= GR_WM_FLAGS_PROPS ;
515 }
516
517 if (((style & wxBORDER) != wxBORDER) && ((style & wxTHICK_FRAME) != wxTHICK_FRAME)
518 && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER))
519 {
520 wmProp.props |= GR_WM_PROPS_NODECORATE ;
521 wmProp.flags |= GR_WM_FLAGS_PROPS ;
522 }
523
524 GrSetWMProperties(w, & wmProp);
525
526 #else
527 if (!wxMWMIsRunning(w))
528 return FALSE;
529
530 Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False);
531 MwmHints hints;
532 hints.flags = 0;
533 hints.decorations = 0;
534
535 if (style & wxRESIZE_BORDER)
536 {
537 // wxLogDebug("MWM_DECOR_RESIZEH");
538 hints.flags |= MWM_HINTS_DECORATIONS;
539 hints.decorations |= MWM_DECOR_RESIZEH;
540 }
541
542 if (style & wxSYSTEM_MENU)
543 {
544 // wxLogDebug("MWM_DECOR_MENU");
545 hints.flags |= MWM_HINTS_DECORATIONS;
546 hints.decorations |= MWM_DECOR_MENU;
547 }
548
549 if ((style & wxCAPTION) ||
550 (style & wxTINY_CAPTION_HORIZ) ||
551 (style & wxTINY_CAPTION_VERT))
552 {
553 // wxLogDebug("MWM_DECOR_TITLE");
554 hints.flags |= MWM_HINTS_DECORATIONS;
555 hints.decorations |= MWM_DECOR_TITLE;
556 }
557
558 if ((style & wxTHICK_FRAME) || (style & wxCAPTION))
559 {
560 // wxLogDebug("MWM_DECOR_BORDER");
561 hints.flags |= MWM_HINTS_DECORATIONS;
562 hints.decorations |= MWM_DECOR_BORDER;
563 }
564
565 if (style & wxMINIMIZE_BOX)
566 {
567 // wxLogDebug("MWM_DECOR_MINIMIZE");
568 hints.flags |= MWM_HINTS_DECORATIONS;
569 hints.decorations |= MWM_DECOR_MINIMIZE;
570 }
571
572 if (style & wxMAXIMIZE_BOX)
573 {
574 // wxLogDebug("MWM_DECOR_MAXIMIZE");
575 hints.flags |= MWM_HINTS_DECORATIONS;
576 hints.decorations |= MWM_DECOR_MAXIMIZE;
577 }
578
579 XChangeProperty(wxGlobalDisplay(),
580 w,
581 mwm_wm_hints, mwm_wm_hints,
582 32, PropModeReplace,
583 (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
584
585 #endif
586 return TRUE;
587 }
588
589 bool wxMWMIsRunning(Window w)
590 {
591 #if wxUSE_NANOX
592 return FALSE;
593 #else
594 Display *dpy = (Display*)wxGetDisplay();
595 Atom motifWmInfo = XInternAtom(dpy, "_MOTIF_WM_INFO", False);
596
597 unsigned long length, bytesafter;
598 unsigned char value[20];
599 unsigned char *ptr = &value[0];
600 int ret, format;
601 Atom type;
602
603 type = format = length = 0;
604 value[0] = 0;
605
606 ret = XGetWindowProperty(wxGlobalDisplay(), w, motifWmInfo,
607 0L, 2, False, motifWmInfo,
608 &type, &format, &length, &bytesafter, &ptr);
609
610 return (ret == Success);
611 #endif
612 }
613
614 // For implementation purposes - sometimes decorations make the client area
615 // smaller
616 wxPoint wxTopLevelWindowX11::GetClientAreaOrigin() const
617 {
618 // wxFrame::GetClientAreaOrigin
619 // does the required calculation already.
620 return wxPoint(0, 0);
621 }
622
623 void wxTopLevelWindowX11::DoGetClientSize( int *width, int *height ) const
624 {
625 XSync(wxGlobalDisplay(), False);
626 wxWindowX11::DoGetClientSize(width, height);
627 }
628
629 void wxTopLevelWindowX11::DoSetClientSize(int width, int height)
630 {
631 wxWindowX11::DoSetClientSize(width, height);
632
633 #if !wxUSE_NANOX
634 // Set the top-level window size
635 XSizeHints size_hints;
636 wxSize oldSize = GetSize();
637 wxSize oldClientSize = GetClientSize();
638
639 size_hints.flags = PSize;
640 size_hints.width = width + (oldSize.x - oldClientSize.x);
641 size_hints.height = height + (oldSize.y - oldClientSize.y);
642 XSetWMNormalHints( (Display*) GetXDisplay(), (Window) GetMainWindow(),
643 &size_hints);
644
645 // This seems to be necessary or resizes don't get performed
646 XSync(wxGlobalDisplay(), False);
647 XSync(wxGlobalDisplay(), False);
648
649 #if 0
650 wxLogDebug("DoSetClientSize: Tried to set size to %d, %d", (int) size_hints.width, (int) size_hints.height);
651
652 XSync(wxGlobalDisplay(), False);
653 wxSize newSize = GetSize();
654 wxLogDebug("New size is %d, %d", (int) newSize.x, (int) newSize.y);
655 #endif
656 #endif
657 }
658
659 void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
660 {
661 #if 0
662 // wxLogDebug( "Setting pos: %d, %d", x, y );
663 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
664 #endif
665 XSync(wxGlobalDisplay(), False);
666 Window window = (Window) m_mainWidget;
667 if (!window)
668 return ;
669
670 Display *display = (Display*) GetXDisplay();
671 Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display));
672 Window parent_window = window,
673 next_parent = window;
674
675 // search for the parent that is child of ROOT, because the WM may
676 // reparent twice and notify only the next parent (like FVWM)
677 while (next_parent != root) {
678 Window *theChildren;
679 #if wxUSE_NANOX
680 GR_COUNT n;
681 #else
682 unsigned int n;
683 #endif
684 parent_window = next_parent;
685 XQueryTree(display, parent_window, &root,
686 &next_parent, &theChildren, &n);
687 XFree(theChildren); // not needed
688 }
689
690 XWindowChanges windowChanges;
691 windowChanges.x = x;
692 windowChanges.y = y;
693 windowChanges.width = width;
694 windowChanges.height = height;
695 windowChanges.stack_mode = 0;
696 int valueMask = CWX | CWY | CWWidth | CWHeight;
697
698 if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
699 {
700 valueMask |= CWX;
701 }
702 if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
703 {
704 valueMask |= CWY;
705 }
706 if (width != -1)
707 {
708 windowChanges.width = wxMax(1, width);
709 valueMask |= CWWidth;
710 }
711 if (height != -1)
712 {
713 windowChanges.height = wxMax(1, height);
714 valueMask |= CWHeight;
715 }
716
717 XConfigureWindow( display, parent_window, valueMask, &windowChanges );
718
719 #if !wxUSE_NANOX
720 XSizeHints size_hints;
721 size_hints.flags = 0;
722 if (x > -1 && y > -1)
723 size_hints.flags |= PPosition;
724 if (width > -1 && height > -1)
725 size_hints.flags |= PSize;
726 size_hints.width = width;
727 size_hints.height = height;
728 size_hints.x = x;
729 size_hints.y = y;
730 XSetWMNormalHints( (Display*) GetXDisplay(), (Window) GetMainWindow(),
731 &size_hints);
732
733 // This seems to be necessary or resizes don't get performed.
734 // Take them out (or even just one of them), and the About
735 // box of the minimal sample probably won't be resized right.
736 XSync(wxGlobalDisplay(), False);
737 XSync(wxGlobalDisplay(), False);
738 #endif
739 }
740
741 void wxTopLevelWindowX11::DoGetPosition(int *x, int *y) const
742 {
743 XSync(wxGlobalDisplay(), False);
744 Window window = (Window) m_mainWidget;
745 if (!window)
746 return ;
747
748 Display *display = (Display*) GetXDisplay();
749 Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display));
750 Window parent_window = window,
751 next_parent = window;
752
753 // search for the parent that is child of ROOT, because the WM may
754 // reparent twice and notify only the next parent (like FVWM)
755 while (next_parent != root) {
756 Window *theChildren;
757 #if wxUSE_NANOX
758 GR_COUNT n;
759 #else
760 unsigned int n;
761 #endif
762 parent_window = next_parent;
763 XQueryTree(display, parent_window, &root,
764 &next_parent, &theChildren, &n);
765 XFree(theChildren); // not needed
766 }
767 #if 0
768 int xx, yy; unsigned int dummy;
769 XGetGeometry(display, parent_window, &root,
770 &xx, &yy, &dummy, &dummy, &dummy, &dummy);
771 if (x) *x = xx;
772 if (y) *y = yy;
773 #else
774 XWindowAttributes attr;
775 Status status = XGetWindowAttributes((Display*) GetXDisplay(), parent_window, & attr);
776 if (status)
777 {
778 if (x) *x = attr.x;
779 if (y) *y = attr.y;
780 }
781 else
782 {
783 if (x) *x = 0;
784 if (y) *y = 0;
785 }
786 #endif
787 }