1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
30 #include <netinet/in.h>
35 #include "gdkwindow.h"
36 #include "gdkinputprivate.h"
37 #include "gdkprivate-x11.h"
38 #include "gdkregion.h"
39 #include "gdkinternals.h"
41 #include "gdkwindow-x11.h"
49 #include <X11/extensions/shape.h>
52 const int _gdk_event_mask_table[21] =
56 PointerMotionHintMask,
73 SubstructureNotifyMask,
74 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
76 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
78 /* Forward declarations */
79 static gboolean gdk_window_gravity_works (void);
80 static void gdk_window_set_static_win_gravity (GdkWindow *window,
82 static gboolean gdk_window_have_shape_ext (void);
83 static gboolean gdk_window_icon_name_set (GdkWindow *window);
85 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
86 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
88 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
91 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
92 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
93 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
94 static void gdk_window_impl_x11_finalize (GObject *object);
96 static gpointer parent_class = NULL;
99 gdk_window_impl_x11_get_type (void)
101 static GType object_type = 0;
105 static const GTypeInfo object_info =
107 sizeof (GdkWindowImplX11Class),
108 (GBaseInitFunc) NULL,
109 (GBaseFinalizeFunc) NULL,
110 (GClassInitFunc) gdk_window_impl_x11_class_init,
111 NULL, /* class_finalize */
112 NULL, /* class_data */
113 sizeof (GdkWindowImplX11),
115 (GInstanceInitFunc) gdk_window_impl_x11_init,
118 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
127 _gdk_window_impl_get_type (void)
129 return gdk_window_impl_x11_get_type ();
133 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
140 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
142 GObjectClass *object_class = G_OBJECT_CLASS (klass);
143 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
145 parent_class = g_type_class_peek_parent (klass);
147 object_class->finalize = gdk_window_impl_x11_finalize;
149 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
150 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
151 drawable_class->get_size = gdk_window_impl_x11_get_size;
153 /* Visible and clip regions are the same */
154 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
155 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
159 gdk_window_impl_x11_finalize (GObject *object)
161 GdkWindowObject *wrapper;
162 GdkDrawableImplX11 *draw_impl;
163 GdkWindowImplX11 *window_impl;
165 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
167 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
168 window_impl = GDK_WINDOW_IMPL_X11 (object);
170 wrapper = (GdkWindowObject*) draw_impl->wrapper;
172 if (!GDK_WINDOW_DESTROYED (wrapper))
174 gdk_xid_table_remove (draw_impl->xid);
175 if (window_impl->focus_window)
176 gdk_xid_table_remove (window_impl->focus_window);
179 G_OBJECT_CLASS (parent_class)->finalize (object);
183 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
185 GdkDrawableImplX11 *drawable_impl;
186 GdkWindowImplX11 *window_impl;
188 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
190 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
191 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
193 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
194 drawable_impl->colormap == NULL)
196 XWindowAttributes window_attributes;
198 XGetWindowAttributes (drawable_impl->xdisplay,
201 drawable_impl->colormap =
202 gdk_colormap_lookup (window_attributes.colormap);
205 return drawable_impl->colormap;
209 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
212 GdkWindowImplX11 *impl;
213 GdkDrawableImplX11 *draw_impl;
215 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
217 impl = GDK_WINDOW_IMPL_X11 (drawable);
218 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
221 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
225 XSetWindowColormap (draw_impl->xdisplay,
227 GDK_COLORMAP_XCOLORMAP (cmap));
229 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
231 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
237 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
241 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
244 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
246 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
250 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
252 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
253 GdkRectangle result_rect;
257 result_rect.width = impl->width;
258 result_rect.height = impl->height;
260 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
262 return gdk_region_rectangle (&result_rect);
266 _gdk_windowing_window_init (void)
268 GdkWindowObject *private;
269 GdkWindowImplX11 *impl;
270 GdkDrawableImplX11 *draw_impl;
271 XWindowAttributes xattributes;
274 unsigned int border_width;
278 g_assert (_gdk_parent_root == NULL);
280 XGetGeometry (gdk_display, _gdk_root_window, &_gdk_root_window,
281 &x, &y, &width, &height, &border_width, &depth);
282 XGetWindowAttributes (gdk_display, _gdk_root_window, &xattributes);
284 _gdk_parent_root = g_object_new (GDK_TYPE_WINDOW, NULL);
285 private = (GdkWindowObject *)_gdk_parent_root;
286 impl = GDK_WINDOW_IMPL_X11 (private->impl);
287 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
289 draw_impl->xdisplay = gdk_display;
290 draw_impl->xid = _gdk_root_window;
291 draw_impl->wrapper = GDK_DRAWABLE (private);
293 private->window_type = GDK_WINDOW_ROOT;
294 private->depth = depth;
296 impl->height = height;
298 gdk_xid_table_insert (&_gdk_root_window, _gdk_parent_root);
301 static Atom wm_client_leader_atom = None;
305 * @parent: a #GdkWindow
306 * @attributes: attributes of the new window
307 * @attributes_mask: mask indicating which fields in @attributes are valid
309 * Creates a new #GdkWindow using the attributes from @attributes. See
310 * #GdkWindowAttr and #GdkWindowAttributesType for more details.
312 * Return value: the new #GdkWindow
315 gdk_window_new (GdkWindow *parent,
316 GdkWindowAttr *attributes,
317 gint attributes_mask)
320 GdkWindowObject *private;
321 GdkWindowImplX11 *impl;
322 GdkDrawableImplX11 *draw_impl;
330 XSetWindowAttributes xattributes;
331 long xattributes_mask;
332 XSizeHints size_hints;
334 XClassHint *class_hint;
342 g_return_val_if_fail (attributes != NULL, NULL);
345 parent = _gdk_parent_root;
347 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
349 if (GDK_WINDOW_DESTROYED (parent))
352 xparent = GDK_WINDOW_XID (parent);
354 window = g_object_new (GDK_TYPE_WINDOW, NULL);
355 private = (GdkWindowObject *)window;
356 impl = GDK_WINDOW_IMPL_X11 (private->impl);
357 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
358 draw_impl->wrapper = GDK_DRAWABLE (window);
360 xdisplay = draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (parent);
362 /* Windows with a foreign parent are treated as if they are children
363 * of the root window, except for actual creation.
365 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
366 parent = _gdk_parent_root;
368 private->parent = (GdkWindowObject *)parent;
370 xattributes_mask = 0;
372 if (attributes_mask & GDK_WA_X)
377 if (attributes_mask & GDK_WA_Y)
384 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
385 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
387 if (attributes->wclass == GDK_INPUT_ONLY)
389 /* Backwards compatiblity - we've always ignored
390 * attributes->window_type for input-only windows
393 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
394 private->window_type = GDK_WINDOW_TEMP;
396 private->window_type = GDK_WINDOW_CHILD;
399 private->window_type = attributes->window_type;
401 _gdk_window_init_position (GDK_WINDOW (private));
402 if (impl->position_info.big)
403 private->guffaw_gravity = TRUE;
405 if (attributes_mask & GDK_WA_VISUAL)
406 visual = attributes->visual;
408 visual = gdk_visual_get_system ();
409 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
411 xattributes.event_mask = StructureNotifyMask;
412 for (i = 0; i < _gdk_nenvent_masks; i++)
414 if (attributes->event_mask & (1 << (i + 1)))
415 xattributes.event_mask |= _gdk_event_mask_table[i];
418 if (xattributes.event_mask)
419 xattributes_mask |= CWEventMask;
421 if (attributes_mask & GDK_WA_NOREDIR)
423 xattributes.override_redirect =
424 (attributes->override_redirect == FALSE)?False:True;
425 xattributes_mask |= CWOverrideRedirect;
428 xattributes.override_redirect = False;
430 if (private->parent && private->parent->guffaw_gravity)
432 xattributes.win_gravity = StaticGravity;
433 xattributes_mask |= CWWinGravity;
437 switch (private->window_type)
439 case GDK_WINDOW_TOPLEVEL:
440 case GDK_WINDOW_DIALOG:
441 case GDK_WINDOW_TEMP:
442 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
444 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
445 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
446 xparent = _gdk_root_window;
448 case GDK_WINDOW_CHILD:
451 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
455 if (attributes->wclass == GDK_INPUT_OUTPUT)
458 depth = visual->depth;
460 private->input_only = FALSE;
461 private->depth = depth;
463 if (attributes_mask & GDK_WA_COLORMAP)
465 draw_impl->colormap = attributes->colormap;
466 gdk_colormap_ref (attributes->colormap);
470 if ((((GdkVisualPrivate*)gdk_visual_get_system ())->xvisual) == xvisual)
472 draw_impl->colormap =
473 gdk_colormap_get_system ();
474 gdk_colormap_ref (draw_impl->colormap);
478 draw_impl->colormap =
479 gdk_colormap_new (visual, FALSE);
483 private->bg_color.pixel = BlackPixel (gdk_display, _gdk_screen);
484 xattributes.background_pixel = private->bg_color.pixel;
486 private->bg_pixmap = NULL;
488 xattributes.border_pixel = BlackPixel (gdk_display, _gdk_screen);
489 xattributes_mask |= CWBorderPixel | CWBackPixel;
491 if (private->guffaw_gravity)
492 xattributes.bit_gravity = StaticGravity;
494 xattributes.bit_gravity = NorthWestGravity;
496 xattributes_mask |= CWBitGravity;
498 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
499 xattributes_mask |= CWColormap;
501 if (private->window_type == GDK_WINDOW_TEMP)
503 xattributes.save_under = True;
504 xattributes.override_redirect = True;
505 xattributes.cursor = None;
506 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
514 private->input_only = TRUE;
515 draw_impl->colormap = gdk_colormap_get_system ();
516 gdk_colormap_ref (draw_impl->colormap);
519 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
520 impl->position_info.x, impl->position_info.y,
521 impl->position_info.width, impl->position_info.height,
522 0, depth, class, xvisual,
523 xattributes_mask, &xattributes);
525 gdk_drawable_ref (window);
526 gdk_xid_table_insert (&draw_impl->xid, window);
528 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
529 (attributes->cursor) :
533 private->parent->children = g_list_prepend (private->parent->children, window);
535 switch (GDK_WINDOW_TYPE (private))
537 case GDK_WINDOW_DIALOG:
538 XSetTransientForHint (xdisplay, xid, xparent);
539 case GDK_WINDOW_TOPLEVEL:
540 case GDK_WINDOW_TEMP:
541 XSetWMProtocols (xdisplay, xid,
542 _gdk_wm_window_protocols, 3);
544 case GDK_WINDOW_CHILD:
545 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
546 (draw_impl->colormap != gdk_colormap_get_system ()) &&
547 (draw_impl->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window))))
549 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
550 gdk_window_add_colormap_windows (window);
559 if (class != InputOnly)
561 /* The focus window is off the visible area, and serves to receive key
562 * press events so they don't get sent to child windows.
564 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
566 xattributes.background_pixel,
567 xattributes.background_pixel);
568 /* FIXME: probably better to actually track the requested event mask for the toplevel
570 XSelectInput (xdisplay, impl->focus_window,
571 KeyPressMask | KeyReleaseMask | FocusChangeMask);
573 XMapWindow (xdisplay, impl->focus_window);
574 gdk_xid_table_insert (&impl->focus_window, window);
577 size_hints.flags = PSize;
578 size_hints.width = impl->width;
579 size_hints.height = impl->height;
581 wm_hints.flags = StateHint | WindowGroupHint;
582 wm_hints.window_group = _gdk_leader_window;
583 wm_hints.input = True;
584 wm_hints.initial_state = NormalState;
586 /* FIXME: Is there any point in doing this? Do any WM's pay
587 * attention to PSize, and even if they do, is this the
590 XSetWMNormalHints (xdisplay, xid, &size_hints);
592 XSetWMHints (xdisplay, xid, &wm_hints);
594 if (!wm_client_leader_atom)
595 wm_client_leader_atom = gdk_x11_get_xatom_by_name ("WM_CLIENT_LEADER");
597 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
598 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
601 XChangeProperty (xdisplay, xid,
602 gdk_x11_get_xatom_by_name ("_NET_WM_PID"),
607 XChangeProperty (xdisplay, xid,
608 wm_client_leader_atom,
609 XA_WINDOW, 32, PropModeReplace,
610 (guchar*) &_gdk_leader_window, 1);
612 if (attributes_mask & GDK_WA_TITLE)
613 title = attributes->title;
615 title = g_get_prgname ();
617 gdk_window_set_title (window, title);
619 if (attributes_mask & GDK_WA_WMCLASS)
621 class_hint = XAllocClassHint ();
622 class_hint->res_name = attributes->wmclass_name;
623 class_hint->res_class = attributes->wmclass_class;
624 XSetClassHint (xdisplay, xid, class_hint);
632 * gdk_window_foreign_new:
633 * @anid: a native window handle.
635 * Wraps a native window in a #GdkWindow.
636 * This may fail if the window has been destroyed.
638 * For example in the X backend, a native window handle is an Xlib
641 * Return value: the newly-created #GdkWindow wrapper for the
642 * native window or %NULL if the window has been destroyed.
645 gdk_window_foreign_new (GdkNativeWindow anid)
648 GdkWindowObject *private;
649 GdkWindowImplX11 *impl;
650 GdkDrawableImplX11 *draw_impl;
651 XWindowAttributes attrs;
653 Window *children = NULL;
657 gdk_error_trap_push ();
658 result = XGetWindowAttributes (gdk_display, anid, &attrs);
659 if (gdk_error_trap_pop () || !result)
662 /* FIXME: This is pretty expensive. Maybe the caller should supply
664 gdk_error_trap_push ();
665 result = XQueryTree (gdk_display, anid, &root, &parent, &children, &nchildren);
666 if (gdk_error_trap_pop () || !result)
672 window = g_object_new (GDK_TYPE_WINDOW, NULL);
673 private = (GdkWindowObject *)window;
674 impl = GDK_WINDOW_IMPL_X11 (private->impl);
675 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
676 draw_impl->wrapper = GDK_DRAWABLE (window);
678 private->parent = gdk_xid_table_lookup (parent);
679 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
680 private->parent = (GdkWindowObject *)_gdk_parent_root;
682 private->parent->children = g_list_prepend (private->parent->children, window);
684 draw_impl->xid = anid;
685 draw_impl->xdisplay = gdk_display;
687 private->x = attrs.x;
688 private->y = attrs.y;
689 impl->width = attrs.width;
690 impl->height = attrs.height;
691 private->window_type = GDK_WINDOW_FOREIGN;
692 private->destroyed = FALSE;
694 if (attrs.map_state == IsUnmapped)
695 private->state = GDK_WINDOW_STATE_WITHDRAWN;
699 private->depth = attrs.depth;
701 _gdk_window_init_position (GDK_WINDOW (private));
703 gdk_drawable_ref (window);
704 gdk_xid_table_insert (&GDK_WINDOW_XID (window), window);
711 * @anid: a native window handle.
713 * Looks up the #GdkWindow that wraps the given native window handle.
715 * For example in the X backend, a native window handle is an Xlib
718 * Return value: the #GdkWindow wrapper for the native window,
719 * or %NULL if there is none.
722 gdk_window_lookup (GdkNativeWindow anid)
724 return (GdkWindow*) gdk_xid_table_lookup (anid);
728 _gdk_windowing_window_destroy (GdkWindow *window,
730 gboolean foreign_destroy)
732 GdkWindowObject *private = (GdkWindowObject *)window;
734 g_return_if_fail (GDK_IS_WINDOW (window));
736 _gdk_selection_window_destroyed (window);
738 if (private->extension_events != 0)
739 gdk_input_window_destroy (window);
743 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
745 if (draw_impl->picture)
746 XRenderFreePicture (draw_impl->xdisplay, draw_impl->picture);
748 #endif /* HAVE_XFT */
750 if (private->window_type == GDK_WINDOW_FOREIGN)
752 if (!foreign_destroy && (private->parent != NULL))
754 /* It's somebody else's window, but in our heirarchy,
755 * so reparent it to the root window, and then send
756 * it a delete event, as if we were a WM
758 XClientMessageEvent xevent;
760 gdk_error_trap_push ();
761 gdk_window_hide (window);
762 gdk_window_reparent (window, NULL, 0, 0);
764 xevent.type = ClientMessage;
765 xevent.window = GDK_WINDOW_XID (window);
766 xevent.message_type = gdk_x11_get_xatom_by_name ("WM_PROTOCOLS");
768 xevent.data.l[0] = gdk_x11_get_xatom_by_name ("WM_DELETE_WINDOW");
769 xevent.data.l[1] = CurrentTime;
771 XSendEvent (GDK_WINDOW_XDISPLAY (window),
772 GDK_WINDOW_XID (window),
773 False, 0, (XEvent *)&xevent);
775 gdk_error_trap_pop ();
778 else if (!recursing && !foreign_destroy)
779 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
782 /* This function is called when the XWindow is really gone.
785 gdk_window_destroy_notify (GdkWindow *window)
787 GdkWindowImplX11 *window_impl;
789 g_return_if_fail (window != NULL);
791 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
793 if (!GDK_WINDOW_DESTROYED (window))
795 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
796 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
798 _gdk_window_destroy (window, TRUE);
801 gdk_xid_table_remove (GDK_WINDOW_XID (window));
802 if (window_impl->focus_window)
803 gdk_xid_table_remove (window_impl->focus_window);
805 gdk_drawable_unref (window);
809 set_initial_hints (GdkWindow *window)
811 GdkWindowObject *private;
815 private = (GdkWindowObject*) window;
817 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
821 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
822 GDK_WINDOW_XID (window));
824 wm_hints = XAllocWMHints ();
826 wm_hints->flags |= StateHint;
827 wm_hints->initial_state = IconicState;
829 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
830 GDK_WINDOW_XID (window), wm_hints);
834 /* We set the spec hints regardless of whether the spec is supported,
835 * since it can't hurt and it's kind of expensive to check whether
841 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
843 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_VERT");
845 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_HORZ");
849 if (private->state & GDK_WINDOW_STATE_STICKY)
851 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_STICKY");
855 if (private->modal_hint)
857 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MODAL");
863 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
864 GDK_WINDOW_XID (window),
865 gdk_x11_get_xatom_by_name ("_NET_WM_STATE"),
866 XA_ATOM, 32, PropModeReplace,
870 if (private->state & GDK_WINDOW_STATE_STICKY)
872 atoms[0] = 0xFFFFFFFF;
873 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
874 GDK_WINDOW_XID (window),
875 gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP"),
876 XA_CARDINAL, 32, PropModeReplace,
882 show_window_internal (GdkWindow *window,
885 GdkWindowObject *private;
887 g_return_if_fail (GDK_IS_WINDOW (window));
889 private = (GdkWindowObject*) window;
890 if (!private->destroyed)
893 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
894 GDK_WINDOW_XID (window));
896 if (!GDK_WINDOW_IS_MAPPED (window))
898 set_initial_hints (window);
900 gdk_synthesize_window_state (window,
901 GDK_WINDOW_STATE_WITHDRAWN,
905 g_assert (GDK_WINDOW_IS_MAPPED (window));
907 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
908 XMapWindow (GDK_WINDOW_XDISPLAY (window),
909 GDK_WINDOW_XID (window));
914 * gdk_window_show_unraised:
915 * @window: a #GdkWindow
917 * Shows a #GdkWindow onscreen, but does not modify its stacking
918 * order. In contrast, gdk_window_show() will raise the window
919 * to the top of the window stack.
921 * On the X11 platform, in Xlib terms, this function calls
922 * XMapWindow() (it also updates some internal GDK state, which means
923 * that you can't really use XMapWindow() directly on a GDK window).
927 gdk_window_show_unraised (GdkWindow *window)
929 g_return_if_fail (GDK_IS_WINDOW (window));
931 show_window_internal (window, FALSE);
936 * @window: a #GdkWindow
938 * Like gdk_window_show_unraised(), but also raises the window to the
939 * top of the window stack (moves the window to the front of the
942 * This function maps a window so it's visible onscreen. Its opposite
943 * is gdk_window_hide().
945 * When implementing a #GtkWidget, you should call this function on the widget's
946 * #GdkWindow as part of the "map" method.
950 gdk_window_show (GdkWindow *window)
952 g_return_if_fail (GDK_IS_WINDOW (window));
954 show_window_internal (window, TRUE);
959 * @window: a #GdkWindow
961 * For toplevel windows, withdraws them, so they will no longer be
962 * known to the window manager; for all windows, unmaps them, so
963 * they won't be displayed. Normally done automatically as
964 * part of gtk_widget_hide().
968 gdk_window_hide (GdkWindow *window)
970 GdkWindowObject *private;
972 g_return_if_fail (window != NULL);
974 private = (GdkWindowObject*) window;
976 /* You can't simply unmap toplevel windows. */
977 switch (private->window_type)
979 case GDK_WINDOW_TOPLEVEL:
980 case GDK_WINDOW_DIALOG:
981 case GDK_WINDOW_TEMP: /* ? */
982 gdk_window_withdraw (window);
986 case GDK_WINDOW_FOREIGN:
987 case GDK_WINDOW_ROOT:
988 case GDK_WINDOW_CHILD:
992 if (!private->destroyed)
994 if (GDK_WINDOW_IS_MAPPED (window))
995 gdk_synthesize_window_state (window,
997 GDK_WINDOW_STATE_WITHDRAWN);
999 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1001 _gdk_window_clear_update_area (window);
1003 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1004 GDK_WINDOW_XID (window));
1009 * gdk_window_withdraw:
1010 * @window: a toplevel #GdkWindow
1012 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1013 * Normally done automatically by gtk_widget_hide() called on a #GtkWindow.
1017 gdk_window_withdraw (GdkWindow *window)
1019 GdkWindowObject *private;
1021 g_return_if_fail (window != NULL);
1023 private = (GdkWindowObject*) window;
1024 if (!private->destroyed)
1026 if (GDK_WINDOW_IS_MAPPED (window))
1027 gdk_synthesize_window_state (window,
1029 GDK_WINDOW_STATE_WITHDRAWN);
1031 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1033 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1034 GDK_WINDOW_XID (window), 0);
1040 * @window: a #GdkWindow
1041 * @x: X coordinate relative to window's parent
1042 * @y: Y coordinate relative to window's parent
1044 * Repositions a window relative to its parent window.
1045 * For toplevel windows, window managers may ignore or modify the move;
1046 * you should probably use gtk_window_move() on a #GtkWindow widget
1047 * anyway, instead of using GDK functions. For child windows,
1048 * the move will reliably succeed.
1050 * If you're also planning to resize the window, use gdk_window_move_resize()
1051 * to both move and resize simultaneously, for a nicer visual effect.
1055 gdk_window_move (GdkWindow *window,
1059 GdkWindowObject *private = (GdkWindowObject *)window;
1060 GdkWindowImplX11 *impl;
1062 g_return_if_fail (window != NULL);
1063 g_return_if_fail (GDK_IS_WINDOW (window));
1065 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1067 if (!GDK_WINDOW_DESTROYED (window))
1069 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1070 _gdk_window_move_resize_child (window, x, y,
1071 impl->width, impl->height);
1074 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1075 GDK_WINDOW_XID (window),
1082 * gdk_window_resize:
1083 * @window: a #GdkWindow
1084 * @width: new width of the window
1085 * @height: new height of the window
1087 * Resizes @window; for toplevel windows, asks the window manager to resize
1088 * the window. The window manager may not allow the resize. When using GTK+,
1089 * use gtk_window_resize() instead of this low-level GDK function.
1091 * Windows may not be resized below 1x1.
1093 * If you're also planning to move the window, use gdk_window_move_resize()
1094 * to both move and resize simultaneously, for a nicer visual effect.
1098 gdk_window_resize (GdkWindow *window,
1102 GdkWindowObject *private;
1104 g_return_if_fail (window != NULL);
1105 g_return_if_fail (GDK_IS_WINDOW (window));
1112 private = (GdkWindowObject*) window;
1114 if (!GDK_WINDOW_DESTROYED (window))
1116 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1117 _gdk_window_move_resize_child (window, private->x, private->y,
1121 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1123 if (width != impl->width || height != impl->height)
1124 private->resize_count += 1;
1126 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1127 GDK_WINDOW_XID (window),
1134 * gdk_window_move_resize:
1135 * @window: a #GdkWindow
1136 * @x: new X position relative to window's parent
1137 * @y: new Y position relative to window's parent
1139 * @height: new height
1141 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1142 * except that both operations are performed at once, avoiding strange
1143 * visual effects. (i.e. the user may be able to see the window first
1144 * move, then resize, if youu don't use gdk_window_move_resize().)
1148 gdk_window_move_resize (GdkWindow *window,
1154 GdkWindowObject *private;
1156 g_return_if_fail (window != NULL);
1157 g_return_if_fail (GDK_IS_WINDOW (window));
1164 private = (GdkWindowObject*) window;
1166 if (!GDK_WINDOW_DESTROYED (window))
1168 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1169 _gdk_window_move_resize_child (window, x, y, width, height);
1172 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1174 if (width != impl->width || height != impl->height)
1175 private->resize_count += 1;
1177 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1178 GDK_WINDOW_XID (window),
1179 x, y, width, height);
1185 * gdk_window_reparent:
1186 * @window: a #GdkWindow
1187 * @new_parent: new parent to move @window into
1188 * @x: X location inside the new parent
1189 * @y: Y location inside the new parent
1191 * Reparents @window into the given @new_parent. The window being
1192 * reparented will be unmapped as a side effect.
1196 gdk_window_reparent (GdkWindow *window,
1197 GdkWindow *new_parent,
1201 GdkWindowObject *window_private;
1202 GdkWindowObject *parent_private;
1203 GdkWindowObject *old_parent_private;
1205 g_return_if_fail (window != NULL);
1206 g_return_if_fail (GDK_IS_WINDOW (window));
1207 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1208 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1211 new_parent = _gdk_parent_root;
1213 window_private = (GdkWindowObject*) window;
1214 old_parent_private = (GdkWindowObject*)window_private->parent;
1215 parent_private = (GdkWindowObject*) new_parent;
1217 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1218 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1219 GDK_WINDOW_XID (window),
1220 GDK_WINDOW_XID (new_parent),
1223 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1226 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1227 new_parent = _gdk_parent_root;
1229 window_private->parent = (GdkWindowObject *)new_parent;
1231 /* Switch the window type as appropriate */
1233 switch (GDK_WINDOW_TYPE (new_parent))
1235 case GDK_WINDOW_ROOT:
1236 case GDK_WINDOW_FOREIGN:
1237 /* Now a toplevel */
1238 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1240 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1241 XSetWMProtocols (GDK_WINDOW_XDISPLAY (window),
1242 GDK_WINDOW_XID (window),
1243 _gdk_wm_window_protocols, 3);
1245 case GDK_WINDOW_TOPLEVEL:
1246 case GDK_WINDOW_CHILD:
1247 case GDK_WINDOW_DIALOG:
1248 case GDK_WINDOW_TEMP:
1249 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1250 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1252 /* If we were being sophisticated, we'd save the old window type
1253 * here, and restore it if we were reparented back to the
1254 * toplevel. However, the difference between different types
1255 * of toplevels only really matters on creation anyways.
1257 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1261 if (old_parent_private)
1262 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1264 if ((old_parent_private &&
1265 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1266 (!old_parent_private && parent_private->guffaw_gravity))
1267 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1269 parent_private->children = g_list_prepend (parent_private->children, window);
1270 _gdk_window_init_position (GDK_WINDOW (window_private));
1274 _gdk_windowing_window_clear_area (GdkWindow *window,
1280 g_return_if_fail (window != NULL);
1281 g_return_if_fail (GDK_IS_WINDOW (window));
1283 if (!GDK_WINDOW_DESTROYED (window))
1284 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1285 x, y, width, height, False);
1289 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1295 g_return_if_fail (window != NULL);
1296 g_return_if_fail (GDK_IS_WINDOW (window));
1298 if (!GDK_WINDOW_DESTROYED (window))
1299 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1300 x, y, width, height, True);
1306 * @window: a #GdkWindow
1308 * Raises @window to the top of the Z-order (stacking order), so that
1309 * other windows with the same parent window appear below @window.
1310 * If @window is a toplevel, the window manager may choose to deny the
1311 * request to move the window in the Z-order, gdk_window_raise() only
1312 * requests the restack, does not guarantee it.
1316 gdk_window_raise (GdkWindow *window)
1318 g_return_if_fail (window != NULL);
1319 g_return_if_fail (GDK_IS_WINDOW (window));
1321 if (!GDK_WINDOW_DESTROYED (window))
1322 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1327 * @window: a #GdkWindow
1329 * Lowers @window to the bottom of the Z-order (stacking order), so that
1330 * other windows with the same parent window appear above @window.
1331 * If @window is a toplevel, the window manager may choose to deny the
1332 * request to move the window in the Z-order, gdk_window_lower() only
1333 * requests the restack, does not guarantee it.
1335 * Note that gdk_window_show() raises the window again, so don't call this
1336 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1340 gdk_window_lower (GdkWindow *window)
1342 g_return_if_fail (window != NULL);
1343 g_return_if_fail (GDK_IS_WINDOW (window));
1345 if (!GDK_WINDOW_DESTROYED (window))
1346 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1351 * @window: a #GdkWindow
1352 * @timestamp: timestamp of the event triggering the window focus
1354 * Sets keyboard focus to @window. If @window is not onscreen this
1355 * will not work. In most cases, gtk_window_present() should be used on
1356 * a #GtkWindow, rather than calling this function.
1360 gdk_window_focus (GdkWindow *window,
1363 g_return_if_fail (GDK_IS_WINDOW (window));
1365 if (GDK_WINDOW_DESTROYED (window))
1368 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1372 xev.xclient.type = ClientMessage;
1373 xev.xclient.serial = 0;
1374 xev.xclient.send_event = True;
1375 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1376 xev.xclient.display = gdk_display;
1377 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW");
1378 xev.xclient.format = 32;
1379 xev.xclient.data.l[0] = 0;
1381 XSendEvent (gdk_display, _gdk_root_window, False,
1382 SubstructureRedirectMask | SubstructureNotifyMask,
1387 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1389 /* There is no way of knowing reliably whether we are viewable so we need
1390 * to trap errors so we don't cause a BadMatch.
1392 gdk_error_trap_push ();
1393 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1394 GDK_WINDOW_XWINDOW (window),
1397 XSync (GDK_WINDOW_XDISPLAY (window), False);
1398 gdk_error_trap_pop ();
1403 * gdk_window_set_hints:
1404 * @window: a #GdkWindow
1405 * @x: ignored field, does not matter
1406 * @y: ignored field, does not matter
1407 * @min_width: minimum width hint
1408 * @min_height: minimum height hint
1409 * @max_width: max width hint
1410 * @max_height: max height hint
1411 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1413 * This function is broken and useless and you should ignore it.
1414 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1415 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1416 * depending on what you're trying to do.
1418 * If using GDK directly, use gdk_window_set_geometry_hints().
1422 gdk_window_set_hints (GdkWindow *window,
1431 XSizeHints size_hints;
1433 g_return_if_fail (window != NULL);
1434 g_return_if_fail (GDK_IS_WINDOW (window));
1436 if (GDK_WINDOW_DESTROYED (window))
1439 size_hints.flags = 0;
1441 if (flags & GDK_HINT_POS)
1443 size_hints.flags |= PPosition;
1448 if (flags & GDK_HINT_MIN_SIZE)
1450 size_hints.flags |= PMinSize;
1451 size_hints.min_width = min_width;
1452 size_hints.min_height = min_height;
1455 if (flags & GDK_HINT_MAX_SIZE)
1457 size_hints.flags |= PMaxSize;
1458 size_hints.max_width = max_width;
1459 size_hints.max_height = max_height;
1462 /* FIXME: Would it be better to delete this property if
1463 * flags == 0? It would save space on the server
1465 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1466 GDK_WINDOW_XID (window),
1471 * gdk_window_set_type_hint:
1472 * @window: A #GdkWindow
1473 * @hint: A hint of the function this window will have
1475 * The application can use this call to provide a hint to the window
1476 * manager about the functionality of a window. The window manager
1477 * can use this information when determining the decoration and behaviour
1480 * The hint must be set before the window is mapped.
1483 gdk_window_set_type_hint (GdkWindow *window,
1484 GdkWindowTypeHint hint)
1488 g_return_if_fail (window != NULL);
1489 g_return_if_fail (GDK_IS_WINDOW (window));
1491 if (GDK_WINDOW_DESTROYED (window))
1496 case GDK_WINDOW_TYPE_HINT_DIALOG:
1497 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_DIALOG");
1499 case GDK_WINDOW_TYPE_HINT_MENU:
1500 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_MENU");
1502 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1503 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_TOOLBAR");
1506 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1508 case GDK_WINDOW_TYPE_HINT_NORMAL:
1509 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_NORMAL");
1513 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1514 GDK_WINDOW_XID (window),
1515 gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE"),
1516 XA_ATOM, 32, PropModeReplace,
1517 (guchar *)&atom, 1);
1522 gdk_wmspec_change_state (gboolean add,
1529 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1530 #define _NET_WM_STATE_ADD 1 /* add/set property */
1531 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1533 xev.xclient.type = ClientMessage;
1534 xev.xclient.serial = 0;
1535 xev.xclient.send_event = True;
1536 xev.xclient.display = gdk_display;
1537 xev.xclient.window = GDK_WINDOW_XID (window);
1538 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_STATE");
1539 xev.xclient.format = 32;
1540 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1541 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom (state1);
1542 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom (state2);
1544 XSendEvent (gdk_display, _gdk_root_window, False,
1545 SubstructureRedirectMask | SubstructureNotifyMask,
1549 * gdk_window_set_modal_hint:
1550 * @window: A #GdkWindow
1551 * @modal: TRUE if the window is modal, FALSE otherwise.
1553 * The application can use this hint to tell the window manager
1554 * that a certain window has modal behaviour. The window manager
1555 * can use this information to handle modal windows in a special
1558 * You should only use this on windows for which you have
1559 * previously called #gdk_window_set_transient_for()
1562 gdk_window_set_modal_hint (GdkWindow *window,
1565 GdkWindowObject *private;
1567 g_return_if_fail (window != NULL);
1568 g_return_if_fail (GDK_IS_WINDOW (window));
1570 if (GDK_WINDOW_DESTROYED (window))
1573 private = (GdkWindowObject*) window;
1575 private->modal_hint = modal;
1577 if (GDK_WINDOW_IS_MAPPED (window))
1578 gdk_wmspec_change_state (modal, window,
1579 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1584 * gdk_window_set_geometry_hints:
1585 * @window: a #GdkWindow
1586 * @geometry: geometry hints
1587 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1589 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1590 * are set, hints not flagged in @geom_mask are unset.
1591 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1595 gdk_window_set_geometry_hints (GdkWindow *window,
1596 GdkGeometry *geometry,
1597 GdkWindowHints geom_mask)
1599 XSizeHints size_hints;
1601 g_return_if_fail (window != NULL);
1602 g_return_if_fail (GDK_IS_WINDOW (window));
1604 if (GDK_WINDOW_DESTROYED (window))
1607 size_hints.flags = 0;
1609 if (geom_mask & GDK_HINT_POS)
1611 size_hints.flags |= PPosition;
1612 /* We need to initialize the following obsolete fields because KWM
1613 * apparently uses these fields if they are non-zero.
1620 if (geom_mask & GDK_HINT_USER_POS)
1622 size_hints.flags |= USPosition;
1625 if (geom_mask & GDK_HINT_USER_SIZE)
1627 size_hints.flags |= USSize;
1630 if (geom_mask & GDK_HINT_MIN_SIZE)
1632 size_hints.flags |= PMinSize;
1633 size_hints.min_width = geometry->min_width;
1634 size_hints.min_height = geometry->min_height;
1637 if (geom_mask & GDK_HINT_MAX_SIZE)
1639 size_hints.flags |= PMaxSize;
1640 size_hints.max_width = MAX (geometry->max_width, 1);
1641 size_hints.max_height = MAX (geometry->max_height, 1);
1644 if (geom_mask & GDK_HINT_BASE_SIZE)
1646 size_hints.flags |= PBaseSize;
1647 size_hints.base_width = geometry->base_width;
1648 size_hints.base_height = geometry->base_height;
1651 if (geom_mask & GDK_HINT_RESIZE_INC)
1653 size_hints.flags |= PResizeInc;
1654 size_hints.width_inc = geometry->width_inc;
1655 size_hints.height_inc = geometry->height_inc;
1658 if (geom_mask & GDK_HINT_ASPECT)
1660 size_hints.flags |= PAspect;
1661 if (geometry->min_aspect <= 1)
1663 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1664 size_hints.min_aspect.y = 65536;
1668 size_hints.min_aspect.x = 65536;
1669 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1671 if (geometry->max_aspect <= 1)
1673 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1674 size_hints.max_aspect.y = 65536;
1678 size_hints.max_aspect.x = 65536;
1679 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1683 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1685 size_hints.flags |= PWinGravity;
1686 size_hints.win_gravity = geometry->win_gravity;
1689 /* FIXME: Would it be better to delete this property if
1690 * geom_mask == 0? It would save space on the server
1692 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1693 GDK_WINDOW_XID (window),
1698 gdk_window_get_geometry_hints (GdkWindow *window,
1699 GdkGeometry *geometry,
1700 GdkWindowHints *geom_mask)
1702 XSizeHints size_hints;
1703 glong junk_size_mask = 0;
1705 g_return_if_fail (GDK_IS_WINDOW (window));
1706 g_return_if_fail (geometry != NULL);
1707 g_return_if_fail (geom_mask != NULL);
1711 if (GDK_WINDOW_DESTROYED (window))
1714 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1715 GDK_WINDOW_XID (window),
1720 if (size_hints.flags & PMinSize)
1722 *geom_mask |= GDK_HINT_MIN_SIZE;
1723 geometry->min_width = size_hints.min_width;
1724 geometry->min_height = size_hints.min_height;
1727 if (size_hints.flags & PMaxSize)
1729 *geom_mask |= GDK_HINT_MAX_SIZE;
1730 geometry->max_width = MAX (size_hints.max_width, 1);
1731 geometry->max_height = MAX (size_hints.max_height, 1);
1734 if (size_hints.flags & PResizeInc)
1736 *geom_mask |= GDK_HINT_RESIZE_INC;
1737 geometry->width_inc = size_hints.width_inc;
1738 geometry->height_inc = size_hints.height_inc;
1741 if (size_hints.flags & PAspect)
1743 *geom_mask |= GDK_HINT_ASPECT;
1745 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1746 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1749 if (size_hints.flags & PWinGravity)
1751 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1752 geometry->win_gravity = size_hints.win_gravity;
1757 utf8_is_latin1 (const gchar *str)
1759 const char *p = str;
1763 gunichar ch = g_utf8_get_char (p);
1768 p = g_utf8_next_char (p);
1774 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
1775 * convertable to STRING, otherwise, set it as compound text
1778 set_text_property (GdkWindow *window,
1780 const gchar *utf8_str)
1782 guchar *prop_text = NULL;
1787 if (utf8_is_latin1 (utf8_str))
1789 prop_type = XA_STRING;
1790 prop_text = gdk_utf8_to_string_target (utf8_str);
1791 prop_length = strlen (prop_text);
1798 gdk_utf8_to_compound_text (utf8_str, &gdk_type, &prop_format,
1799 &prop_text, &prop_length);
1800 prop_type = gdk_x11_atom_to_xatom (gdk_type);
1805 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1806 GDK_WINDOW_XID (window),
1808 prop_type, prop_format,
1809 PropModeReplace, prop_text,
1817 * gdk_window_set_title:
1818 * @window: a #GdkWindow
1819 * @title: title of @window
1821 * Sets the title of a toplevel window, to be displayed in the titlebar.
1822 * If you haven't explicitly set the icon name for the window
1823 * (using gdk_window_set_icon_name()), the icon name will be set to
1824 * @title as well. @title must be in UTF-8 encoding (as with all
1825 * user-readable strings in GDK/GTK+). @title may not be %NULL.
1829 gdk_window_set_title (GdkWindow *window,
1832 g_return_if_fail (window != NULL);
1833 g_return_if_fail (GDK_IS_WINDOW (window));
1834 g_return_if_fail (title != NULL);
1836 if (GDK_WINDOW_DESTROYED (window))
1839 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1840 GDK_WINDOW_XID (window),
1841 gdk_x11_get_xatom_by_name ("_NET_WM_NAME"),
1842 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
1843 PropModeReplace, title,
1846 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_NAME"), title);
1847 if (!gdk_window_icon_name_set (window))
1849 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1850 GDK_WINDOW_XID (window),
1851 gdk_x11_get_xatom_by_name ("_NET_WM_ICON_NAME"),
1852 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
1853 PropModeReplace, title,
1855 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_ICON_NAME"), title);
1860 * gdk_window_set_role:
1861 * @window: a #GdkWindow
1862 * @role: a string indicating its role
1864 * When using GTK+, typically you should use gtk_window_set_role() instead
1865 * of this low-level function.
1867 * The window manager and session manager use a window's role to
1868 * distinguish it from other kinds of window in the same application.
1869 * When an application is restarted after being saved in a previous
1870 * session, all windows with the same title and role are treated as
1871 * interchangeable. So if you have two windows with the same title
1872 * that should be distinguished for session management purposes, you
1873 * should set the role on those windows. It doesn't matter what string
1874 * you use for the role, as long as you have a different role for each
1875 * non-interchangeable kind of window.
1879 gdk_window_set_role (GdkWindow *window,
1882 g_return_if_fail (window != NULL);
1883 g_return_if_fail (GDK_IS_WINDOW (window));
1885 if (!GDK_WINDOW_DESTROYED (window))
1888 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1889 gdk_x11_get_xatom_by_name ("WM_WINDOW_ROLE"), XA_STRING,
1890 8, PropModeReplace, role, strlen (role));
1892 XDeleteProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1893 gdk_x11_get_xatom_by_name ("WM_WINDOW_ROLE"));
1898 * gdk_window_set_transient_for:
1899 * @window: a toplevel #GdkWindow
1900 * @parent: another toplevel #GdkWindow
1902 * Indicates to the window manager that @window is a transient dialog
1903 * associated with the application window @parent. This allows the
1904 * window manager to do things like center @window on @parent and
1905 * keep @window above @parent.
1907 * See gtk_window_set_transient_for() if you're using #GtkWindow or
1912 gdk_window_set_transient_for (GdkWindow *window,
1915 GdkWindowObject *private;
1916 GdkWindowObject *parent_private;
1918 g_return_if_fail (window != NULL);
1919 g_return_if_fail (GDK_IS_WINDOW (window));
1921 private = (GdkWindowObject*) window;
1922 parent_private = (GdkWindowObject*) parent;
1924 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
1925 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
1926 GDK_WINDOW_XID (window),
1927 GDK_WINDOW_XID (parent));
1931 * gdk_window_set_background:
1932 * @window: a #GdkWindow
1933 * @color: an allocated #GdkColor
1935 * Sets the background color of @window. (However, when using GTK+,
1936 * set the background of a widget with gtk_widget_modify_bg() - if
1937 * you're an application - or gtk_style_set_background() - if you're
1938 * implementing a custom widget.)
1940 * The @color must be allocated; gdk_rgb_find_color() is the best way
1941 * to allocate a color.
1943 * See also gdk_window_set_back_pixmap().
1947 gdk_window_set_background (GdkWindow *window,
1950 GdkWindowObject *private = (GdkWindowObject *)window;
1952 g_return_if_fail (window != NULL);
1953 g_return_if_fail (GDK_IS_WINDOW (window));
1955 if (!GDK_WINDOW_DESTROYED (window))
1956 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
1957 GDK_WINDOW_XID (window), color->pixel);
1959 private->bg_color = *color;
1961 if (private->bg_pixmap &&
1962 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1963 private->bg_pixmap != GDK_NO_BG)
1965 gdk_pixmap_unref (private->bg_pixmap);
1966 private->bg_pixmap = NULL;
1971 * gdk_window_set_back_pixmap:
1972 * @window: a #GdkWindow
1973 * @pixmap: a #GdkPixmap, or %NULL
1974 * @parent_relative: whether the tiling origin is at the origin of @window's parent
1976 * Sets the background pixmap of @window. May also be used to set a background of
1977 * "None" on @window, by setting a background pixmap of %NULL.
1978 * A background pixmap will be tiled, positioning the first tile at the origin of
1979 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
1980 * origin of the parent window (useful to align tiles in a parent with tiles
1983 * A background pixmap of %NULL means that the window will have no
1984 * background. A window with no background will never have its
1985 * background filled by the windowing system, instead the window will
1986 * contain whatever pixels were already in the corresponding area of
1989 * The windowing system will normally fill a window with its background
1990 * when the window is obscured then exposed, and when you call
1991 * gdk_window_clear().
1995 gdk_window_set_back_pixmap (GdkWindow *window,
1997 gboolean parent_relative)
1999 GdkWindowObject *private = (GdkWindowObject *)window;
2002 g_return_if_fail (window != NULL);
2003 g_return_if_fail (GDK_IS_WINDOW (window));
2004 g_return_if_fail (pixmap == NULL || !parent_relative);
2006 if (private->bg_pixmap &&
2007 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2008 private->bg_pixmap != GDK_NO_BG)
2009 gdk_pixmap_unref (private->bg_pixmap);
2011 if (parent_relative)
2013 xpixmap = ParentRelative;
2014 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2020 gdk_pixmap_ref (pixmap);
2021 private->bg_pixmap = pixmap;
2022 xpixmap = GDK_PIXMAP_XID (pixmap);
2027 private->bg_pixmap = GDK_NO_BG;
2031 if (!GDK_WINDOW_DESTROYED (window))
2032 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2033 GDK_WINDOW_XID (window), xpixmap);
2037 * gdk_window_set_cursor:
2038 * @window: a #GdkWindow
2041 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2042 * gdk_cursor_new_from_pixmap() to create the cursor.
2043 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2044 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2045 * to gdk_window_set_cursor() means that @window will use the cursor of
2046 * its parent window. Most windows should use this default.
2050 gdk_window_set_cursor (GdkWindow *window,
2053 GdkCursorPrivate *cursor_private;
2056 g_return_if_fail (window != NULL);
2057 g_return_if_fail (GDK_IS_WINDOW (window));
2059 cursor_private = (GdkCursorPrivate*) cursor;
2064 xcursor = cursor_private->xcursor;
2066 if (!GDK_WINDOW_DESTROYED (window))
2067 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2068 GDK_WINDOW_XID (window),
2073 * gdk_window_get_geometry:
2074 * @window: a #GdkWindow
2075 * @x: return location for X coordinate of window (relative to its parent)
2076 * @y: return location for Y coordinate of window (relative to its parent)
2077 * @width: return location for width of window
2078 * @height: return location for height of window
2079 * @depth: return location for bit depth of window
2081 * Any of the return location arguments to this function may be %NULL,
2082 * if you aren't interested in getting the value of that field.
2084 * The X and Y coordinates returned are relative to the parent window
2085 * of @window, which for toplevels usually means relative to the
2086 * window decorations (titlebar, etc.) rather than relative to the
2087 * root window (screen-size background window).
2089 * On the X11 platform, the geometry is obtained from the X server,
2090 * so reflects the latest position of @window; this may be out-of-sync
2091 * with the position of @window delivered in the most-recently-processed
2092 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2093 * position from the most recent configure event.
2097 gdk_window_get_geometry (GdkWindow *window,
2109 guint tborder_width;
2112 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2115 window = _gdk_parent_root;
2117 if (!GDK_WINDOW_DESTROYED (window))
2119 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2120 GDK_WINDOW_XID (window),
2121 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2137 * gdk_window_get_origin:
2138 * @window: a #GdkWindow
2139 * @x: return location for X coordinate
2140 * @y: return location for Y coordinate
2142 * Obtains the position of a window in root window coordinates.
2143 * (Compare with gdk_window_get_position() and
2144 * gdk_window_get_geometry() which return the position of a window
2145 * relative to its parent window.)
2147 * Return value: not meaningful, ignore
2150 gdk_window_get_origin (GdkWindow *window,
2159 g_return_val_if_fail (window != NULL, 0);
2161 if (!GDK_WINDOW_DESTROYED (window))
2163 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2164 GDK_WINDOW_XID (window),
2182 * gdk_window_get_deskrelative_origin:
2183 * @window: a #GdkWindow
2184 * @x: return location for X coordinate
2185 * @y: return location for Y coordinate
2187 * This gets the origin of a #GdkWindow relative to
2188 * an Enlightenment-window-manager desktop. As long as you don't
2189 * assume that the user's desktop/workspace covers the entire
2190 * root window (i.e. you don't assume that the desktop begins
2191 * at root window coordinate 0,0) this function is not necessary.
2192 * It's deprecated for that reason.
2194 * Return value: not meaningful
2197 gdk_window_get_deskrelative_origin (GdkWindow *window,
2201 gboolean return_val = FALSE;
2202 gint num_children, format_return;
2203 Window win, *child, parent, root;
2207 static Atom atom = 0;
2208 gulong number_return, bytes_after_return;
2209 guchar *data_return;
2211 g_return_val_if_fail (window != NULL, 0);
2212 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2214 if (!GDK_WINDOW_DESTROYED (window))
2217 atom = gdk_x11_get_xatom_by_name ("ENLIGHTENMENT_DESKTOP");
2218 win = GDK_WINDOW_XID (window);
2220 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2221 &child, (unsigned int *)&num_children))
2223 if ((child) && (num_children > 0))
2235 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2236 False, XA_CARDINAL, &type_return, &format_return,
2237 &number_return, &bytes_after_return, &data_return);
2238 if (type_return == XA_CARDINAL)
2240 XFree (data_return);
2245 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2246 GDK_WINDOW_XID (window),
2261 * gdk_window_get_root_origin:
2262 * @window: a #GdkWindow
2263 * @x: return location for X position of window frame
2264 * @y: return location for Y position of window frame
2266 * Obtains the top-left corner of the window manager frame in root
2267 * window coordinates.
2271 gdk_window_get_root_origin (GdkWindow *window,
2277 g_return_if_fail (GDK_IS_WINDOW (window));
2279 gdk_window_get_frame_extents (window, &rect);
2289 * gdk_window_get_frame_extents:
2290 * @window: a #GdkWindow
2291 * @rect: rectangle to fill with bounding box of the window frame
2293 * Obtains the bounding box of the window, including window manager
2294 * titlebar/borders if any. The frame position is given in root window
2295 * coordinates. To get the position of the window itself (rather than
2296 * the frame) in root window coordinates, use gdk_window_get_origin().
2300 gdk_window_get_frame_extents (GdkWindow *window,
2303 GdkWindowObject *private;
2308 unsigned int nchildren;
2310 g_return_if_fail (GDK_IS_WINDOW (window));
2311 g_return_if_fail (rect != NULL);
2313 private = (GdkWindowObject*) window;
2320 if (GDK_WINDOW_DESTROYED (window))
2323 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2324 private = (GdkWindowObject*) private->parent;
2325 if (GDK_WINDOW_DESTROYED (window))
2328 xparent = GDK_WINDOW_XID (window);
2332 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2334 &children, &nchildren))
2340 while (xparent != root);
2342 if (xparent == root)
2344 unsigned int ww, wh, wb, wd;
2347 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2358 _gdk_windowing_window_get_pointer (GdkWindow *window,
2361 GdkModifierType *mask)
2363 GdkWindow *return_val;
2369 unsigned int xmask = 0;
2370 gint xoffset, yoffset;
2372 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2375 window = _gdk_parent_root;
2377 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2380 if (!GDK_WINDOW_DESTROYED (window) &&
2381 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2382 GDK_WINDOW_XID (window),
2383 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2386 return_val = gdk_window_lookup (child);
2390 *x = winx + xoffset;
2392 *y = winy + yoffset;
2400 _gdk_windowing_window_at_pointer (GdkScreen *screen,
2407 Window xwindow_last = 0;
2409 int rootx = -1, rooty = -1;
2413 xwindow = GDK_ROOT_WINDOW ();
2414 xdisplay = GDK_DISPLAY ();
2416 gdk_x11_grab_server ();
2419 xwindow_last = xwindow;
2420 XQueryPointer (xdisplay, xwindow,
2426 gdk_x11_ungrab_server ();
2428 window = gdk_window_lookup (xwindow_last);
2431 *win_x = window ? winx : -1;
2433 *win_y = window ? winy : -1;
2439 * gdk_window_get_events:
2440 * @window: a #GdkWindow
2442 * Gets the event mask for @window. See gdk_window_set_events().
2444 * Return value: event mask for @window
2447 gdk_window_get_events (GdkWindow *window)
2449 XWindowAttributes attrs;
2450 GdkEventMask event_mask;
2453 g_return_val_if_fail (window != NULL, 0);
2454 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2456 if (GDK_WINDOW_DESTROYED (window))
2460 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2461 GDK_WINDOW_XID (window),
2465 for (i = 0; i < _gdk_nenvent_masks; i++)
2467 if (attrs.your_event_mask & _gdk_event_mask_table[i])
2468 event_mask |= 1 << (i + 1);
2476 * gdk_window_set_events:
2477 * @window: a #GdkWindow
2478 * @event_mask: event mask for @window
2480 * The event mask for a window determines which events will be reported
2481 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2482 * means the window should report button press events. The event mask
2483 * is the bitwise OR of values from the #GdkEventMask enumeration.
2487 gdk_window_set_events (GdkWindow *window,
2488 GdkEventMask event_mask)
2493 g_return_if_fail (window != NULL);
2494 g_return_if_fail (GDK_IS_WINDOW (window));
2496 if (!GDK_WINDOW_DESTROYED (window))
2498 xevent_mask = StructureNotifyMask;
2499 for (i = 0; i < _gdk_nenvent_masks; i++)
2501 if (event_mask & (1 << (i + 1)))
2502 xevent_mask |= _gdk_event_mask_table[i];
2505 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2506 GDK_WINDOW_XID (window),
2512 gdk_window_add_colormap_windows (GdkWindow *window)
2514 GdkWindow *toplevel;
2515 Window *old_windows;
2516 Window *new_windows;
2519 g_return_if_fail (window != NULL);
2520 g_return_if_fail (GDK_IS_WINDOW (window));
2522 toplevel = gdk_window_get_toplevel (window);
2523 if (GDK_WINDOW_DESTROYED (toplevel))
2527 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2528 GDK_WINDOW_XID (toplevel),
2529 &old_windows, &count))
2534 for (i = 0; i < count; i++)
2535 if (old_windows[i] == GDK_WINDOW_XID (window))
2537 XFree (old_windows);
2541 new_windows = g_new (Window, count + 1);
2543 for (i = 0; i < count; i++)
2544 new_windows[i] = old_windows[i];
2545 new_windows[count] = GDK_WINDOW_XID (window);
2547 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2548 GDK_WINDOW_XID (toplevel),
2549 new_windows, count + 1);
2551 g_free (new_windows);
2553 XFree (old_windows);
2557 gdk_window_have_shape_ext (void)
2559 enum { UNKNOWN, NO, YES };
2560 static gint have_shape = UNKNOWN;
2562 if (have_shape == UNKNOWN)
2565 if (XQueryExtension (gdk_display, "SHAPE", &ignore, &ignore, &ignore))
2571 return (have_shape == YES);
2574 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2577 * This needs the X11 shape extension.
2578 * If not available, shaped windows will look
2579 * ugly, but programs still work. Stefan Wille
2582 * gdk_window_shape_combine_mask:
2583 * @window: a #GdkWindow
2585 * @x: X position of shape mask with respect to @window
2586 * @y: Y position of shape mask with respect to @window
2588 * Applies a shape mask to @window. Pixels in @window corresponding to
2589 * set bits in the @mask will be visible; pixels in @window
2590 * corresponding to unset bits in the @mask will be transparent. This
2591 * gives a non-rectangular window.
2593 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2594 * parameters are not used.
2596 * On the X11 platform, this uses an X server extension which is
2597 * widely available on most common platforms, but not available on
2598 * very old X servers, and occasionally the implementation will be
2599 * buggy. On servers without the shape extension, this function
2604 gdk_window_shape_combine_mask (GdkWindow *window,
2609 gint xoffset, yoffset;
2611 g_return_if_fail (window != NULL);
2612 g_return_if_fail (GDK_IS_WINDOW (window));
2614 #ifdef HAVE_SHAPE_EXT
2615 if (GDK_WINDOW_DESTROYED (window))
2618 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2620 if (xoffset != 0 || yoffset != 0)
2622 WARN_SHAPE_TOO_BIG ();
2626 if (gdk_window_have_shape_ext ())
2630 pixmap = GDK_PIXMAP_XID (mask);
2639 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2640 GDK_WINDOW_XID (window),
2646 #endif /* HAVE_SHAPE_EXT */
2650 * gdk_window_shape_combine_region:
2651 * @window: a #GdkWindow
2652 * @shape_region: region of window to be non-transparent
2653 * @offset_x: X position of @shape_region in @window coordinates
2654 * @offset_y: Y position of @shape_region in @window coordinates
2656 * Makes pixels in @window outside @shape_region be transparent,
2657 * so that the window may be nonrectangular. See also
2658 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2660 * If @shape_region is %NULL, the shape will be unset, so the whole
2661 * window will be opaque again. @offset_x and @offset_y are ignored
2662 * if @shape_region is %NULL.
2664 * On the X11 platform, this uses an X server extension which is
2665 * widely available on most common platforms, but not available on
2666 * very old X servers, and occasionally the implementation will be
2667 * buggy. On servers without the shape extension, this function
2672 gdk_window_shape_combine_region (GdkWindow *window,
2673 GdkRegion *shape_region,
2677 gint xoffset, yoffset;
2679 g_return_if_fail (GDK_IS_WINDOW (window));
2681 #ifdef HAVE_SHAPE_EXT
2682 if (GDK_WINDOW_DESTROYED (window))
2685 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2687 if (xoffset != 0 || yoffset != 0)
2689 WARN_SHAPE_TOO_BIG ();
2693 if (shape_region == NULL)
2695 /* Use NULL mask to unset the shape */
2696 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2700 if (gdk_window_have_shape_ext ())
2703 XRectangle *xrects = NULL;
2705 _gdk_region_get_xrectangles (shape_region,
2709 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2710 GDK_WINDOW_XID (window),
2719 #endif /* HAVE_SHAPE_EXT */
2724 * gdk_window_set_override_redirect:
2725 * @window: a #GdkWindow
2726 * @override_redirect: %TRUE if window should be override redirect
2728 * An override redirect window is not under the control of the window manager.
2729 * This means it won't have a titlebar, won't be minimizable, etc. - it will
2730 * be entirely under the control of the application. The window manager
2731 * can't see the override redirect window at all.
2733 * Override redirect should only be used for short-lived temporary
2734 * windows, such as popup menus. #GtkMenu uses an override redirect
2735 * window in its implementation, for example.
2739 gdk_window_set_override_redirect (GdkWindow *window,
2740 gboolean override_redirect)
2742 XSetWindowAttributes attr;
2744 g_return_if_fail (window != NULL);
2745 g_return_if_fail (GDK_IS_WINDOW (window));
2747 if (GDK_WINDOW_DESTROYED (window))
2749 attr.override_redirect = (override_redirect == FALSE)?False:True;
2750 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2751 GDK_WINDOW_XID (window),
2759 * gdk_window_set_icon_list:
2760 * @window: The #GdkWindow toplevel window to set the icon of.
2761 * @pixbufs: A list of pixbufs, of different sizes.
2763 * Sets a list of icons for the window. One of these will be used
2764 * to represent the window when it has been iconified. The icon is
2765 * usually shown in an icon box or some sort of task bar. Which icon
2766 * size is shown depends on the window manager. The window manager
2767 * can scale the icon but setting several size icons can give better
2768 * image quality since the window manager may only need to scale the
2769 * icon by a small amount or not at all.
2773 gdk_window_set_icon_list (GdkWindow *window,
2782 gint width, height, stride;
2786 g_return_if_fail (GDK_IS_WINDOW (window));
2788 if (GDK_WINDOW_DESTROYED (window))
2797 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
2799 width = gdk_pixbuf_get_width (pixbuf);
2800 height = gdk_pixbuf_get_height (pixbuf);
2802 size += 2 + width * height;
2804 l = g_list_next (l);
2807 data = g_malloc (size * sizeof (gulong));
2815 width = gdk_pixbuf_get_width (pixbuf);
2816 height = gdk_pixbuf_get_height (pixbuf);
2817 stride = gdk_pixbuf_get_rowstride (pixbuf);
2818 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
2823 pixels = gdk_pixbuf_get_pixels (pixbuf);
2825 for (y = 0; y < height; y++)
2827 for (x = 0; x < width; x++)
2831 r = pixels[y*stride + x*n_channels + 0];
2832 g = pixels[y*stride + x*n_channels + 1];
2833 b = pixels[y*stride + x*n_channels + 2];
2834 if (n_channels >= 4)
2835 a = pixels[y*stride + x*n_channels + 3];
2839 *p++ = a << 24 | r << 16 | g << 8 | b ;
2843 l = g_list_next (l);
2848 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2849 GDK_WINDOW_XID (window),
2850 gdk_x11_get_xatom_by_name ("_NET_WM_ICON"),
2853 (guchar*) data, size);
2857 XDeleteProperty (GDK_WINDOW_XDISPLAY (window),
2858 GDK_WINDOW_XID (window),
2859 gdk_x11_get_xatom_by_name ("_NET_WM_ICON"));
2866 * gdk_window_set_icon:
2867 * @window: a #GdkWindow
2868 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
2869 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
2870 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
2872 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
2873 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
2874 * and gtk_window_set_icon(). If those don't meet your needs, look at
2875 * gdk_window_set_icon_list(). Only if all those are too high-level do you
2876 * want to fall back to gdk_window_set_icon().
2880 gdk_window_set_icon (GdkWindow *window,
2881 GdkWindow *icon_window,
2887 g_return_if_fail (window != NULL);
2888 g_return_if_fail (GDK_IS_WINDOW (window));
2890 if (GDK_WINDOW_DESTROYED (window))
2893 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
2894 GDK_WINDOW_XID (window));
2896 wm_hints = XAllocWMHints ();
2898 if (icon_window != NULL)
2900 wm_hints->flags |= IconWindowHint;
2901 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
2906 wm_hints->flags |= IconPixmapHint;
2907 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
2912 wm_hints->flags |= IconMaskHint;
2913 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
2916 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
2917 GDK_WINDOW_XID (window), wm_hints);
2922 gdk_window_icon_name_set (GdkWindow *window)
2924 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
2925 g_quark_from_static_string ("gdk-icon-name-set")));
2929 * gdk_window_set_icon_name:
2930 * @window: a #GdkWindow
2931 * @name: name of window while iconified (minimized)
2933 * Windows may have a name used while minimized, distinct from the
2934 * name they display in their titlebar. Most of the time this is a bad
2935 * idea from a user interface standpoint. But you can set such a name
2936 * with this function, if you like.
2940 gdk_window_set_icon_name (GdkWindow *window,
2943 g_return_if_fail (window != NULL);
2944 g_return_if_fail (GDK_IS_WINDOW (window));
2946 if (GDK_WINDOW_DESTROYED (window))
2949 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
2950 GUINT_TO_POINTER (TRUE));
2952 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2953 GDK_WINDOW_XID (window),
2954 gdk_x11_get_xatom_by_name ("_NET_WM_ICON_NAME"),
2955 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
2956 PropModeReplace, name,
2958 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_ICON_NAME"), name);
2962 * gdk_window_iconify:
2963 * @window: a #GdkWindow
2965 * Asks to iconify (minimize) @window. The window manager may choose
2966 * to ignore the request, but normally will honor it. Using
2967 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
2971 gdk_window_iconify (GdkWindow *window)
2974 GdkWindowObject *private;
2976 g_return_if_fail (window != NULL);
2977 g_return_if_fail (GDK_IS_WINDOW (window));
2979 if (GDK_WINDOW_DESTROYED (window))
2982 display = GDK_WINDOW_XDISPLAY (window);
2984 private = (GdkWindowObject*) window;
2986 if (GDK_WINDOW_IS_MAPPED (window))
2988 XIconifyWindow (display, GDK_WINDOW_XWINDOW (window), DefaultScreen (display));
2993 /* Flip our client side flag, the real work happens on map. */
2994 gdk_synthesize_window_state (window,
2996 GDK_WINDOW_STATE_ICONIFIED);
3001 * gdk_window_deiconify:
3002 * @window: a #GdkWindow
3004 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3005 * choose to ignore the request to deiconify. When using GTK+,
3006 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3007 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3008 * unminimizes it, and puts it on the current desktop.
3012 gdk_window_deiconify (GdkWindow *window)
3015 GdkWindowObject *private;
3017 g_return_if_fail (window != NULL);
3018 g_return_if_fail (GDK_IS_WINDOW (window));
3020 if (GDK_WINDOW_DESTROYED (window))
3023 display = GDK_WINDOW_XDISPLAY (window);
3025 private = (GdkWindowObject*) window;
3027 if (GDK_WINDOW_IS_MAPPED (window))
3029 gdk_window_show (window);
3033 /* Flip our client side flag, the real work happens on map. */
3034 gdk_synthesize_window_state (window,
3035 GDK_WINDOW_STATE_ICONIFIED,
3042 * @window: a toplevel #GdkWindow
3044 * "Pins" a window such that it's on all workspaces and does not scroll
3045 * with viewports, for window managers that have scrollable viewports.
3046 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3048 * On the X11 platform, this function depends on window manager
3049 * support, so may have no effect with many window managers. However,
3050 * GDK will do the best it can to convince the window manager to stick
3051 * the window. For window managers that don't support this operation,
3052 * there's nothing you can do to force it to happen.
3056 gdk_window_stick (GdkWindow *window)
3058 g_return_if_fail (GDK_IS_WINDOW (window));
3060 if (GDK_WINDOW_DESTROYED (window))
3063 if (GDK_WINDOW_IS_MAPPED (window))
3065 /* "stick" means stick to all desktops _and_ do not scroll with the
3066 * viewport. i.e. glue to the monitor glass in all cases.
3071 /* Request stick during viewport scroll */
3072 gdk_wmspec_change_state (TRUE, window,
3073 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3076 /* Request desktop 0xFFFFFFFF */
3077 xev.xclient.type = ClientMessage;
3078 xev.xclient.serial = 0;
3079 xev.xclient.send_event = True;
3080 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3081 xev.xclient.display = gdk_display;
3082 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
3083 xev.xclient.format = 32;
3085 xev.xclient.data.l[0] = 0xFFFFFFFF;
3087 XSendEvent (gdk_display, _gdk_root_window, False,
3088 SubstructureRedirectMask | SubstructureNotifyMask,
3093 /* Flip our client side flag, the real work happens on map. */
3094 gdk_synthesize_window_state (window,
3096 GDK_WINDOW_STATE_STICKY);
3101 * gdk_window_unstick:
3102 * @window: a toplevel #GdkWindow
3104 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3105 * and gtk_window_unstick().
3109 gdk_window_unstick (GdkWindow *window)
3111 g_return_if_fail (GDK_IS_WINDOW (window));
3113 if (GDK_WINDOW_DESTROYED (window))
3116 if (GDK_WINDOW_IS_MAPPED (window))
3123 gulong *current_desktop;
3125 /* Request unstick from viewport */
3126 gdk_wmspec_change_state (FALSE, window,
3127 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3130 /* Get current desktop, then set it; this is a race, but not
3131 * one that matters much in practice.
3133 XGetWindowProperty (gdk_display, _gdk_root_window,
3134 gdk_x11_get_xatom_by_name ("_NET_CURRENT_DESKTOP"),
3136 False, XA_CARDINAL, &type, &format, &nitems,
3137 &bytes_after, (guchar **)¤t_desktop);
3139 if (type == XA_CARDINAL)
3141 xev.xclient.type = ClientMessage;
3142 xev.xclient.serial = 0;
3143 xev.xclient.send_event = True;
3144 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3145 xev.xclient.display = gdk_display;
3146 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
3147 xev.xclient.format = 32;
3149 xev.xclient.data.l[0] = *current_desktop;
3151 XSendEvent (gdk_display, _gdk_root_window, False,
3152 SubstructureRedirectMask | SubstructureNotifyMask,
3155 XFree (current_desktop);
3160 /* Flip our client side flag, the real work happens on map. */
3161 gdk_synthesize_window_state (window,
3162 GDK_WINDOW_STATE_STICKY,
3169 * gdk_window_maximize:
3170 * @window: a #GdkWindow
3172 * Asks the window manager to maximize @window, if the window manager supports
3173 * this operation. Not all window managers support this, and some deliberately
3174 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3175 * maximization actually happening. But it will happen with most standard
3176 * window managers, and GDK makes a best effort to get it to happen.
3178 * If the window was already maximized, then this function does nothing.
3182 gdk_window_maximize (GdkWindow *window)
3184 g_return_if_fail (GDK_IS_WINDOW (window));
3186 if (GDK_WINDOW_DESTROYED (window))
3189 if (GDK_WINDOW_IS_MAPPED (window))
3190 gdk_wmspec_change_state (TRUE, window,
3191 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3192 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3194 gdk_synthesize_window_state (window,
3196 GDK_WINDOW_STATE_MAXIMIZED);
3200 * gdk_window_unmaximize:
3201 * @window: a #GdkWindow
3203 * Asks the window manager to unmaximize @window, if the window manager supports
3204 * this operation. Not all window managers support this, and some deliberately
3205 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3206 * unmaximization actually happening. But it will happen with most standard
3207 * window managers, and GDK makes a best effort to get it to happen.
3209 * If the window wasn't maximized, then this function does nothing.
3213 gdk_window_unmaximize (GdkWindow *window)
3215 g_return_if_fail (GDK_IS_WINDOW (window));
3217 if (GDK_WINDOW_DESTROYED (window))
3220 if (GDK_WINDOW_IS_MAPPED (window))
3221 gdk_wmspec_change_state (FALSE, window,
3222 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3223 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3225 gdk_synthesize_window_state (window,
3226 GDK_WINDOW_STATE_MAXIMIZED,
3231 * gdk_window_set_group:
3232 * @window: a #GdkWindow
3233 * @leader: group leader window
3235 * Sets the group leader window for @window. By default,
3236 * GDK sets the group leader for all toplevel windows
3237 * to a global window implicitly created by GDK. With this function
3238 * you can override this default.
3240 * The group leader window allows the window manager to distinguish
3241 * all windows that belong to a single application. It may for example
3242 * allow users to minimize/unminimize all windows belonging to an
3243 * application at once. You should only set a non-default group window
3244 * if your application pretends to be multiple applications.
3245 * The group leader window may not be changed after a window has been
3246 * mapped (with gdk_window_show() for example).
3250 gdk_window_set_group (GdkWindow *window,
3255 g_return_if_fail (window != NULL);
3256 g_return_if_fail (GDK_IS_WINDOW (window));
3257 g_return_if_fail (leader != NULL);
3258 g_return_if_fail (GDK_IS_WINDOW (leader));
3260 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3263 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3264 GDK_WINDOW_XID (window));
3266 wm_hints = XAllocWMHints ();
3268 wm_hints->flags |= WindowGroupHint;
3269 wm_hints->window_group = GDK_WINDOW_XID (leader);
3271 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3272 GDK_WINDOW_XID (window), wm_hints);
3276 static MotifWmHints *
3277 gdk_window_get_mwm_hints (GdkWindow *window)
3279 static Atom hints_atom = None;
3280 MotifWmHints *hints;
3286 if (GDK_WINDOW_DESTROYED (window))
3290 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
3291 _XA_MOTIF_WM_HINTS, FALSE);
3293 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3294 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3295 False, AnyPropertyType, &type, &format, &nitems,
3296 &bytes_after, (guchar **)&hints);
3305 gdk_window_set_mwm_hints (GdkWindow *window,
3306 MotifWmHints *new_hints)
3308 static Atom hints_atom = None;
3309 MotifWmHints *hints;
3315 if (GDK_WINDOW_DESTROYED (window))
3319 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
3320 _XA_MOTIF_WM_HINTS, FALSE);
3322 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3323 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3324 False, AnyPropertyType, &type, &format, &nitems,
3325 &bytes_after, (guchar **)&hints);
3331 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3333 hints->flags |= MWM_HINTS_FUNCTIONS;
3334 hints->functions = new_hints->functions;
3336 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3338 hints->flags |= MWM_HINTS_DECORATIONS;
3339 hints->decorations = new_hints->decorations;
3343 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3344 hints_atom, hints_atom, 32, PropModeReplace,
3345 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3347 if (hints != new_hints)
3352 * gdk_window_set_decorations:
3353 * @window: a #GdkWindow
3354 * @decorations: decoration hint mask
3356 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3357 * This function sets the traditional Motif window manager hints that tell the
3358 * window manager which decorations you would like your window to have.
3359 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3360 * using the GDK function directly.
3362 * The @decorations argument is the logical OR of the fields in
3363 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3364 * mask, the other bits indicate which decorations should be turned off.
3365 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3366 * which decorations should be turned on.
3368 * Most window managers honor a decorations hint of 0 to disable all decorations,
3369 * but very few honor all possible combinations of bits.
3373 gdk_window_set_decorations (GdkWindow *window,
3374 GdkWMDecoration decorations)
3378 g_return_if_fail (window != NULL);
3379 g_return_if_fail (GDK_IS_WINDOW (window));
3381 hints.flags = MWM_HINTS_DECORATIONS;
3382 hints.decorations = decorations;
3384 gdk_window_set_mwm_hints (window, &hints);
3388 * gdk_window_get_decorations:
3389 * @window: The #GdkWindow to get the decorations from
3390 * @decorations: The window decorations will be written here
3392 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3393 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3396 gdk_window_get_decorations(GdkWindow *window,
3397 GdkWMDecoration *decorations)
3399 MotifWmHints *hints;
3400 gboolean result = FALSE;
3402 hints = gdk_window_get_mwm_hints (window);
3406 if (hints->flags & MWM_HINTS_DECORATIONS)
3408 *decorations = hints->decorations;
3419 * gdk_window_set_functions:
3420 * @window: a #GdkWindow
3421 * @functions: bitmask of operations to allow on @window
3423 * This function isn't really good for much. It sets the traditional
3424 * Motif window manager hint for which operations the window manager
3425 * should allow on a toplevel window. However, few window managers do
3426 * anything reliable or interesting with this hint. Many ignore it
3429 * The @functions argument is the logical OR of values from the
3430 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3431 * then the other bits indicate which functions to disable; if
3432 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3437 gdk_window_set_functions (GdkWindow *window,
3438 GdkWMFunction functions)
3442 g_return_if_fail (window != NULL);
3443 g_return_if_fail (GDK_IS_WINDOW (window));
3445 hints.flags = MWM_HINTS_FUNCTIONS;
3446 hints.functions = functions;
3448 gdk_window_set_mwm_hints (window, &hints);
3451 #ifdef HAVE_SHAPE_EXT
3454 * propagate the shapes from all child windows of a GDK window to the parent
3455 * window. Shamelessly ripped from Enlightenment's code
3463 struct _gdk_span *next;
3467 gdk_add_to_span (struct _gdk_span **s,
3471 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3478 /* scan the spans for this line */
3481 /* -- -> new span */
3482 /* == -> existing span */
3483 /* ## -> spans intersect */
3484 /* if we are in the middle of spanning the span into the line */
3487 /* case: ---- ==== */
3488 if (xx < ptr1->start - 1)
3490 /* ends before next span - extend to here */
3494 /* case: ----##=== */
3495 else if (xx <= ptr1->end)
3497 /* crosses into next span - delete next span and append */
3498 ss->end = ptr1->end;
3499 ss->next = ptr1->next;
3503 /* case: ---###--- */
3506 /* overlaps next span - delete and keep checking */
3507 ss->next = ptr1->next;
3512 /* otherwise havent started spanning it in yet */
3515 /* case: ---- ==== */
3516 if (xx < ptr1->start - 1)
3518 /* insert span here in list */
3519 noo = g_malloc (sizeof (struct _gdk_span));
3533 /* case: ----##=== */
3534 else if ((x < ptr1->start) && (xx <= ptr1->end))
3536 /* expand this span to the left point of the new one */
3540 /* case: ===###=== */
3541 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3543 /* throw the span away */
3546 /* case: ---###--- */
3547 else if ((x < ptr1->start) && (xx > ptr1->end))
3554 /* case: ===##---- */
3555 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3561 /* case: ==== ---- */
3562 /* case handled by next loop iteration - first case */
3567 /* it started in the middle but spans beyond your current list */
3573 /* it does not start inside a span or in the middle, so add it to the end */
3574 noo = g_malloc (sizeof (struct _gdk_span));
3582 noo->next = ptr2->next;
3595 gdk_add_rectangles (Display *disp,
3597 struct _gdk_span **spans,
3604 gint x1, y1, x2, y2;
3608 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
3611 /* go through all clip rects in this window's shape */
3612 for (k = 0; k < rn; k++)
3614 /* for each clip rect, add it to each line's spans */
3616 x2 = x + rl[k].x + (rl[k].width - 1);
3618 y2 = y + rl[k].y + (rl[k].height - 1);
3627 for (a = y1; a <= y2; a++)
3630 gdk_add_to_span (&spans[a], x1, x2);
3638 gdk_propagate_shapes (Display *disp,
3642 Window rt, par, *list = NULL;
3643 gint i, j, num = 0, num_rects = 0;
3647 XRectangle *rects = NULL;
3648 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
3649 XWindowAttributes xatt;
3651 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
3656 spans = g_malloc (sizeof (struct _gdk_span *) * h);
3658 for (i = 0; i < h; i++)
3660 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
3663 /* go through all child windows and create/insert spans */
3664 for (i = 0; i < num; i++)
3666 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
3667 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
3668 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
3671 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
3673 /* go through the spans list and build a list of rects */
3674 rects = g_malloc (sizeof (XRectangle) * 256);
3676 for (i = 0; i < baseh; i++)
3679 /* go through the line for all spans */
3682 rects[num_rects].x = ptr1->start;
3683 rects[num_rects].y = i;
3684 rects[num_rects].width = ptr1->end - ptr1->start + 1;
3685 rects[num_rects].height = 1;
3687 /* if there are more lines */
3689 /* while contigous rects (same start/end coords) exist */
3690 while ((contig) && (j < baseh))
3692 /* search next line for spans matching this one */
3698 /* if we have an exact span match set contig */
3699 if ((ptr2->start == ptr1->start) &&
3700 (ptr2->end == ptr1->end))
3703 /* remove the span - not needed */
3706 ptr3->next = ptr2->next;
3712 spans[j] = ptr2->next;
3718 /* gone past the span point no point looking */
3719 else if (ptr2->start < ptr1->start)
3727 /* if a contiguous span was found increase the rect h */
3730 rects[num_rects].height++;
3734 /* up the rect count */
3736 /* every 256 new rects increase the rect array */
3737 if ((num_rects % 256) == 0)
3738 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
3742 /* set the rects as the shape mask */
3745 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
3746 ShapeSet, YXSorted);
3751 /* free up all the spans we made */
3752 for (i = 0; i < baseh; i++)
3765 #endif /* HAVE_SHAPE_EXT */
3768 * gdk_window_set_child_shapes:
3769 * @window: a #GdkWindow
3771 * Sets the shape mask of @window to the union of shape masks
3772 * for all children of @window, ignoring the shape mask of @window
3773 * itself. Contrast with gdk_window_merge_child_shapes() which includes
3774 * the shape mask of @window in the masks to be merged.
3777 gdk_window_set_child_shapes (GdkWindow *window)
3779 g_return_if_fail (window != NULL);
3780 g_return_if_fail (GDK_IS_WINDOW (window));
3782 #ifdef HAVE_SHAPE_EXT
3783 if (!GDK_WINDOW_DESTROYED (window) &&
3784 gdk_window_have_shape_ext ())
3785 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3786 GDK_WINDOW_XID (window), FALSE);
3791 * gdk_window_merge_child_shapes:
3792 * @window: a #GdkWindow
3794 * Merges the shape masks for any child windows into the
3795 * shape mask for @window. i.e. the union of all masks
3796 * for @window and its children will become the new mask
3797 * for @window. See gdk_window_shape_combine_mask().
3799 * This function is distinct from gdk_window_set_child_shapes()
3800 * because it includes @window's shape mask in the set of shapes to
3805 gdk_window_merge_child_shapes (GdkWindow *window)
3807 g_return_if_fail (window != NULL);
3808 g_return_if_fail (GDK_IS_WINDOW (window));
3810 #ifdef HAVE_SHAPE_EXT
3811 if (!GDK_WINDOW_DESTROYED (window) &&
3812 gdk_window_have_shape_ext ())
3813 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3814 GDK_WINDOW_XID (window), TRUE);
3818 /* Support for windows that can be guffaw-scrolled
3819 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
3823 gdk_window_gravity_works (void)
3825 enum { UNKNOWN, NO, YES };
3826 static gint gravity_works = UNKNOWN;
3828 if (gravity_works == UNKNOWN)
3835 /* This particular server apparently has a bug so that the test
3836 * works but the actual code crashes it
3838 if ((!strcmp (XServerVendor (gdk_display), "Sun Microsystems, Inc.")) &&
3839 (VendorRelease (gdk_display) == 3400))
3845 attr.window_type = GDK_WINDOW_TEMP;
3846 attr.wclass = GDK_INPUT_OUTPUT;
3851 attr.event_mask = 0;
3853 parent = gdk_window_new (NULL, &attr, GDK_WA_X | GDK_WA_Y);
3855 attr.window_type = GDK_WINDOW_CHILD;
3856 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
3858 gdk_window_set_static_win_gravity (child, TRUE);
3860 gdk_window_resize (parent, 100, 110);
3861 gdk_window_move (parent, 0, -10);
3862 gdk_window_move_resize (parent, 0, 0, 100, 100);
3864 gdk_window_resize (parent, 100, 110);
3865 gdk_window_move (parent, 0, -10);
3866 gdk_window_move_resize (parent, 0, 0, 100, 100);
3868 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
3870 gdk_window_destroy (parent);
3871 gdk_window_destroy (child);
3873 gravity_works = ((y == -20) ? YES : NO);
3876 return (gravity_works == YES);
3880 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
3882 XSetWindowAttributes xattributes;
3883 guint xattributes_mask = 0;
3885 g_return_if_fail (window != NULL);
3887 xattributes.bit_gravity = StaticGravity;
3888 xattributes_mask |= CWBitGravity;
3889 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
3890 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3891 GDK_WINDOW_XID (window),
3892 CWBitGravity, &xattributes);
3896 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
3898 XSetWindowAttributes xattributes;
3900 g_return_if_fail (window != NULL);
3902 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
3904 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3905 GDK_WINDOW_XID (window),
3906 CWWinGravity, &xattributes);
3910 * gdk_window_set_static_gravities:
3911 * @window: a #GdkWindow
3912 * @use_static: %TRUE to turn on static gravity
3914 * Set the bit gravity of the given window to static, and flag it so
3915 * all children get static subwindow gravity. This is used if you are
3916 * implementing scary features that involve deep knowledge of the
3917 * windowing system. Don't worry about it unless you have to.
3919 * Return value: %TRUE if the server supports static gravity
3922 gdk_window_set_static_gravities (GdkWindow *window,
3923 gboolean use_static)
3925 GdkWindowObject *private = (GdkWindowObject *)window;
3928 g_return_val_if_fail (window != NULL, FALSE);
3929 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3931 if (!use_static == !private->guffaw_gravity)
3934 if (use_static && !gdk_window_gravity_works ())
3937 private->guffaw_gravity = use_static;
3939 if (!GDK_WINDOW_DESTROYED (window))
3941 gdk_window_set_static_bit_gravity (window, use_static);
3943 tmp_list = private->children;
3946 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
3948 tmp_list = tmp_list->next;
3955 /* internal function created for and used by gdk_window_xid_at_coords */
3957 gdk_window_xid_at (Window base,
3963 gboolean excl_child)
3966 Window *list = NULL;
3967 Window child = 0, parent_win = 0, root_win = 0;
3969 unsigned int ww, wh, wb, wd, num;
3972 xdisplay = GDK_DISPLAY ();
3973 if (!XGetGeometry (xdisplay, base, &root_win, &wx, &wy, &ww, &wh, &wb, &wd))
3980 (x < (int) (wx + ww)) &&
3981 (y < (int) (wy + wh))))
3984 if (!XQueryTree (xdisplay, base, &root_win, &parent_win, &list, &num))
3989 for (i = num - 1; ; i--)
3991 if ((!excl_child) || (!g_list_find (excludes, (gpointer *) list[i])))
3993 if ((child = gdk_window_xid_at (list[i], wx, wy, x, y, excludes, excl_child)) != 0)
4008 * The following fucntion by The Rasterman <raster@redhat.com>
4009 * This function returns the X Window ID in which the x y location is in
4010 * (x and y being relative to the root window), excluding any windows listed
4011 * in the GList excludes (this is a list of X Window ID's - gpointer being
4014 * This is primarily designed for internal gdk use - for DND for example
4015 * when using a shaped icon window as the drag object - you exclude the
4016 * X Window ID of the "icon" (perhaps more if excludes may be needed) and
4017 * You can get back an X Window ID as to what X Window ID is infact under
4018 * those X,Y co-ordinates.
4021 gdk_window_xid_at_coords (gint x,
4024 gboolean excl_child)
4028 Window *list = NULL;
4029 Window root, child = 0, parent_win = 0, root_win = 0;
4033 window = _gdk_parent_root;
4034 xdisplay = GDK_WINDOW_XDISPLAY (window);
4035 root = GDK_WINDOW_XID (window);
4036 num = g_list_length (excludes);
4038 gdk_x11_grab_server ();
4039 if (!XQueryTree (xdisplay, root, &root_win, &parent_win, &list, &num))
4041 gdk_x11_ungrab_server ();
4049 XWindowAttributes xwa;
4051 XGetWindowAttributes (xdisplay, list [i], &xwa);
4053 if (xwa.map_state != IsViewable)
4056 if (excl_child && g_list_find (excludes, (gpointer *) list[i]))
4059 if ((child = gdk_window_xid_at (list[i], 0, 0, x, y, excludes, excl_child)) == 0)
4064 if (!g_list_find (excludes, (gpointer *) child))
4067 gdk_x11_ungrab_server ();
4074 gdk_x11_ungrab_server ();
4080 gdk_x11_ungrab_server ();
4085 wmspec_moveresize (GdkWindow *window,
4093 /* Release passive grab */
4094 gdk_pointer_ungrab (timestamp);
4096 xev.xclient.type = ClientMessage;
4097 xev.xclient.serial = 0;
4098 xev.xclient.send_event = True;
4099 xev.xclient.display = gdk_display;
4100 xev.xclient.window = GDK_WINDOW_XID (window);
4101 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_MOVERESIZE");
4102 xev.xclient.format = 32;
4103 xev.xclient.data.l[0] = root_x;
4104 xev.xclient.data.l[1] = root_y;
4105 xev.xclient.data.l[2] = direction;
4106 xev.xclient.data.l[3] = 0;
4107 xev.xclient.data.l[4] = 0;
4109 XSendEvent (gdk_display, _gdk_root_window, False,
4110 SubstructureRedirectMask | SubstructureNotifyMask,
4114 /* From the WM spec */
4115 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4116 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4117 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4118 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4119 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4120 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4121 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4122 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4123 #define _NET_WM_MOVERESIZE_MOVE 8
4126 wmspec_resize_drag (GdkWindow *window,
4135 /* Let the compiler turn a switch into a table, instead
4136 * of doing the table manually, this way is easier to verify.
4140 case GDK_WINDOW_EDGE_NORTH_WEST:
4141 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4144 case GDK_WINDOW_EDGE_NORTH:
4145 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4148 case GDK_WINDOW_EDGE_NORTH_EAST:
4149 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4152 case GDK_WINDOW_EDGE_WEST:
4153 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4156 case GDK_WINDOW_EDGE_EAST:
4157 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4160 case GDK_WINDOW_EDGE_SOUTH_WEST:
4161 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4164 case GDK_WINDOW_EDGE_SOUTH:
4165 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4168 case GDK_WINDOW_EDGE_SOUTH_EAST:
4169 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4173 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4179 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4182 /* This is global for use in gdkevents-x11.c */
4183 GdkWindow *_gdk_moveresize_window;
4185 static GdkWindow *moveresize_emulation_window = NULL;
4186 static gboolean is_resize = FALSE;
4187 static GdkWindowEdge resize_edge;
4188 static gint moveresize_button;
4189 static gint moveresize_x;
4190 static gint moveresize_y;
4191 static gint moveresize_orig_x;
4192 static gint moveresize_orig_y;
4193 static gint moveresize_orig_width;
4194 static gint moveresize_orig_height;
4195 static GdkWindowHints moveresize_geom_mask = 0;
4196 static GdkGeometry moveresize_geometry;
4197 static Time moveresize_process_time;
4199 static XEvent *moveresize_pending_event;
4202 update_pos (gint new_root_x,
4207 dx = new_root_x - moveresize_x;
4208 dy = new_root_y - moveresize_y;
4214 w = moveresize_orig_width;
4215 h = moveresize_orig_height;
4217 switch (resize_edge)
4219 case GDK_WINDOW_EDGE_SOUTH_EAST:
4228 if (moveresize_geom_mask)
4230 gdk_window_constrain_size (&moveresize_geometry,
4231 moveresize_geom_mask,
4236 gdk_window_resize (_gdk_moveresize_window, w, h);
4242 x = moveresize_orig_x + dx;
4243 y = moveresize_orig_y + dy;
4245 gdk_window_move (_gdk_moveresize_window, x, y);
4252 gdk_window_destroy (moveresize_emulation_window);
4253 moveresize_emulation_window = NULL;
4254 _gdk_moveresize_window = NULL;
4256 if (moveresize_pending_event)
4258 g_free (moveresize_pending_event);
4259 moveresize_pending_event = NULL;
4264 lookahead_motion_predicate (Display *display,
4268 gboolean *seen_release = (gboolean *)arg;
4273 switch (event->xany.type)
4276 *seen_release = TRUE;
4279 moveresize_process_time = event->xmotion.time;
4289 moveresize_lookahead (XEvent *event)
4292 gboolean seen_release = FALSE;
4294 if (moveresize_process_time)
4296 if (event->xmotion.time == moveresize_process_time)
4298 moveresize_process_time = 0;
4305 XCheckIfEvent (gdk_display, &tmp_event,
4306 lookahead_motion_predicate, (XPointer)&seen_release);
4308 return moveresize_process_time == 0;
4312 _gdk_moveresize_handle_event (XEvent *event)
4314 guint button_mask = 0;
4315 GdkWindowObject *window_private = (GdkWindowObject *) _gdk_moveresize_window;
4317 button_mask = GDK_BUTTON1_MASK << (moveresize_button - 1);
4319 switch (event->xany.type)
4322 if (window_private->resize_count > 0)
4324 if (moveresize_pending_event)
4325 *moveresize_pending_event = *event;
4327 moveresize_pending_event = g_memdup (event, sizeof (XEvent));
4331 if (!moveresize_lookahead (event))
4334 update_pos (event->xmotion.x_root,
4335 event->xmotion.y_root);
4337 /* This should never be triggered in normal cases, but in the
4338 * case where the drag started without an implicit grab being
4339 * in effect, we could miss the release if it occurs before
4340 * we grab the pointer; this ensures that we will never
4341 * get a permanently stuck grab.
4343 if ((event->xmotion.state & button_mask) == 0)
4348 update_pos (event->xbutton.x_root,
4349 event->xbutton.y_root);
4351 if (event->xbutton.button == moveresize_button)
4358 _gdk_moveresize_configure_done (void)
4362 if (moveresize_pending_event)
4364 tmp_event = moveresize_pending_event;
4365 moveresize_pending_event = NULL;
4366 _gdk_moveresize_handle_event (tmp_event);
4372 create_moveresize_window (guint32 timestamp)
4374 GdkWindowAttr attributes;
4375 gint attributes_mask;
4376 GdkGrabStatus status;
4378 g_assert (moveresize_emulation_window == NULL);
4380 attributes.x = -100;
4381 attributes.y = -100;
4382 attributes.width = 10;
4383 attributes.height = 10;
4384 attributes.window_type = GDK_WINDOW_TEMP;
4385 attributes.wclass = GDK_INPUT_ONLY;
4386 attributes.override_redirect = TRUE;
4387 attributes.event_mask = 0;
4389 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4391 moveresize_emulation_window =
4392 gdk_window_new (NULL, &attributes, attributes_mask);
4394 gdk_window_show (moveresize_emulation_window);
4396 status = gdk_pointer_grab (moveresize_emulation_window,
4398 GDK_BUTTON_RELEASE_MASK |
4399 GDK_POINTER_MOTION_MASK,
4404 if (status != GDK_GRAB_SUCCESS)
4406 /* If this fails, some other client has grabbed the window
4409 gdk_window_destroy (moveresize_emulation_window);
4410 moveresize_emulation_window = NULL;
4413 moveresize_process_time = 0;
4417 emulate_resize_drag (GdkWindow *window,
4425 moveresize_button = button;
4427 moveresize_x = root_x;
4428 moveresize_y = root_y;
4429 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4431 gdk_window_get_size (window, &moveresize_orig_width, &moveresize_orig_height);
4433 moveresize_geom_mask = 0;
4434 gdk_window_get_geometry_hints (window,
4435 &moveresize_geometry,
4436 &moveresize_geom_mask);
4438 create_moveresize_window (timestamp);
4442 emulate_move_drag (GdkWindow *window,
4449 moveresize_button = button;
4450 moveresize_x = root_x;
4451 moveresize_y = root_y;
4452 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4454 gdk_window_get_deskrelative_origin (_gdk_moveresize_window,
4456 &moveresize_orig_y);
4458 create_moveresize_window (timestamp);
4462 * gdk_window_begin_resize_drag:
4463 * @window: a #GdkWindow
4464 * @edge: the edge or corner from which the drag is started
4465 * @button: the button being used to drag
4466 * @root_x: root window X coordinate of mouse click that began the drag
4467 * @root_y: root window Y coordinate of mouse click that began the drag
4468 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4470 * Begins a window resize operation (for a toplevel window).
4471 * You might use this function to implement a "window resize grip," for
4472 * example; in fact #GtkStatusbar uses it. The function works best
4473 * with window managers that support the Extended Window Manager Hints spec
4474 * (see http://www.freedesktop.org), but has a fallback implementation
4475 * for other window managers.
4479 gdk_window_begin_resize_drag (GdkWindow *window,
4486 g_return_if_fail (GDK_IS_WINDOW (window));
4487 g_return_if_fail (moveresize_emulation_window == NULL);
4489 if (GDK_WINDOW_DESTROYED (window))
4492 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4493 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4495 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4499 * gdk_window_begin_move_drag:
4500 * @window: a #GdkWindow
4501 * @button: the button being used to drag
4502 * @root_x: root window X coordinate of mouse click that began the drag
4503 * @root_y: root window Y coordinate of mouse click that began the drag
4504 * @timestamp: timestamp of mouse click that began the drag
4506 * Begins a window move operation (for a toplevel window). You might
4507 * use this function to implement a "window move grip," for
4508 * example. The function works best with window managers that support
4509 * the Extended Window Manager Hints spec (see
4510 * http://www.freedesktop.org), but has a fallback implementation for
4511 * other window managers.
4515 gdk_window_begin_move_drag (GdkWindow *window,
4521 g_return_if_fail (GDK_IS_WINDOW (window));
4522 g_return_if_fail (moveresize_emulation_window == NULL);
4524 if (GDK_WINDOW_DESTROYED (window))
4527 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4528 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE,
4529 root_x, root_y, timestamp);
4531 emulate_move_drag (window, button, root_x, root_y, timestamp);