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