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