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