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