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"
37 #include "gdkinputprivate.h"
38 #include "gdkdisplay-x11.h"
39 #include "gdkprivate-x11.h"
40 #include "gdkregion.h"
41 #include "gdkinternals.h"
43 #include "gdkwindow-x11.h"
51 #include <X11/extensions/shape.h>
54 const int _gdk_event_mask_table[21] =
58 PointerMotionHintMask,
75 SubstructureNotifyMask,
76 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
78 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
80 /* Forward declarations */
81 static gboolean gdk_window_gravity_works (GdkWindow *window);
82 static void gdk_window_set_static_win_gravity (GdkWindow *window,
84 static gboolean gdk_window_have_shape_ext (GdkDisplay *display);
85 static gboolean gdk_window_icon_name_set (GdkWindow *window);
86 static void gdk_window_add_colormap_windows (GdkWindow *window);
87 static void set_wm_name (GdkDisplay *display,
91 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
92 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
94 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
97 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
98 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
99 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
100 static void gdk_window_impl_x11_finalize (GObject *object);
102 static gpointer parent_class = NULL;
105 gdk_window_impl_x11_get_type (void)
107 static GType object_type = 0;
111 static const GTypeInfo object_info =
113 sizeof (GdkWindowImplX11Class),
114 (GBaseInitFunc) NULL,
115 (GBaseFinalizeFunc) NULL,
116 (GClassInitFunc) gdk_window_impl_x11_class_init,
117 NULL, /* class_finalize */
118 NULL, /* class_data */
119 sizeof (GdkWindowImplX11),
121 (GInstanceInitFunc) gdk_window_impl_x11_init,
124 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
133 _gdk_window_impl_get_type (void)
135 return gdk_window_impl_x11_get_type ();
139 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
146 _gdk_x11_window_get_toplevel (GdkWindow *window)
148 GdkWindowObject *private;
149 GdkWindowImplX11 *impl;
151 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
153 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
156 private = (GdkWindowObject *)window;
157 impl = GDK_WINDOW_IMPL_X11 (private->impl);
160 impl->toplevel = g_new0 (GdkToplevelX11, 1);
162 return impl->toplevel;
166 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
168 GObjectClass *object_class = G_OBJECT_CLASS (klass);
169 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
171 parent_class = g_type_class_peek_parent (klass);
173 object_class->finalize = gdk_window_impl_x11_finalize;
175 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
176 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
177 drawable_class->get_size = gdk_window_impl_x11_get_size;
179 /* Visible and clip regions are the same */
180 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
181 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
185 gdk_window_impl_x11_finalize (GObject *object)
187 GdkWindowObject *wrapper;
188 GdkDrawableImplX11 *draw_impl;
189 GdkWindowImplX11 *window_impl;
191 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
193 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
194 window_impl = GDK_WINDOW_IMPL_X11 (object);
196 wrapper = (GdkWindowObject*) draw_impl->wrapper;
198 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
200 if (!GDK_WINDOW_DESTROYED (wrapper))
202 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), draw_impl->xid);
203 if (window_impl->toplevel && window_impl->toplevel->focus_window)
204 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), window_impl->toplevel->focus_window);
207 if (window_impl->toplevel)
208 g_free (window_impl->toplevel);
210 G_OBJECT_CLASS (parent_class)->finalize (object);
214 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
216 GdkDrawableImplX11 *drawable_impl;
217 GdkWindowImplX11 *window_impl;
219 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
221 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
222 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
224 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
225 drawable_impl->colormap == NULL)
227 XWindowAttributes window_attributes;
230 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
234 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
235 window_attributes.visual->visualid);
236 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
237 window_attributes.colormap);
240 return drawable_impl->colormap;
244 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
247 GdkWindowImplX11 *impl;
248 GdkDrawableImplX11 *draw_impl;
250 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
252 impl = GDK_WINDOW_IMPL_X11 (drawable);
253 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
255 if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper))
259 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
263 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
265 GDK_COLORMAP_XCOLORMAP (cmap));
267 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
269 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
275 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
279 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
282 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
284 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
288 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
290 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
291 GdkRectangle result_rect;
295 result_rect.width = impl->width;
296 result_rect.height = impl->height;
298 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
300 return gdk_region_rectangle (&result_rect);
304 _gdk_windowing_window_init (GdkScreen * screen)
306 GdkWindowObject *private;
307 GdkWindowImplX11 *impl;
308 GdkDrawableImplX11 *draw_impl;
309 GdkScreenX11 *screen_x11;
311 screen_x11 = GDK_SCREEN_X11 (screen);
313 g_assert (screen_x11->root_window == NULL);
315 gdk_screen_set_default_colormap (screen,
316 gdk_screen_get_system_colormap (screen));
318 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
319 private = (GdkWindowObject *)screen_x11->root_window;
320 impl = GDK_WINDOW_IMPL_X11 (private->impl);
321 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
323 draw_impl->screen = screen;
324 draw_impl->xid = screen_x11->xroot_window;
325 draw_impl->wrapper = GDK_DRAWABLE (private);
326 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
327 g_object_ref (draw_impl->colormap);
329 private->window_type = GDK_WINDOW_ROOT;
330 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
332 impl->width = WidthOfScreen (screen_x11->xscreen);
333 impl->height = HeightOfScreen (screen_x11->xscreen);
335 _gdk_window_init_position (GDK_WINDOW (private));
337 _gdk_xid_table_insert (screen_x11->display,
338 &screen_x11->xroot_window,
339 screen_x11->root_window);
343 set_wm_protocols (GdkWindow *window)
345 GdkDisplay *display = gdk_drawable_get_display (window);
348 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
349 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
350 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
352 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
356 get_default_title (void)
360 title = g_get_application_name ();
362 title = g_get_prgname ();
368 check_leader_window_title (GdkDisplay *display)
370 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
372 if (!display_x11->leader_window_title_set)
374 set_wm_name (display,
375 display_x11->leader_window,
376 get_default_title ());
378 display_x11->leader_window_title_set = TRUE;
384 * @parent: a #GdkWindow, or %NULL to create the window as a child of
385 * the default root window for the default display.
386 * @attributes: attributes of the new window
387 * @attributes_mask: mask indicating which fields in @attributes are valid
389 * Creates a new #GdkWindow using the attributes from
390 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
391 * more details. Note: to use this on displays other than the default
392 * display, @parent must be specified.
394 * Return value: the new #GdkWindow
397 gdk_window_new (GdkWindow *parent,
398 GdkWindowAttr *attributes,
399 gint attributes_mask)
402 GdkWindowObject *private;
403 GdkWindowImplX11 *impl;
404 GdkDrawableImplX11 *draw_impl;
405 GdkToplevelX11 *toplevel;
406 GdkScreenX11 *screen_x11;
415 XSetWindowAttributes xattributes;
416 long xattributes_mask;
417 XSizeHints size_hints;
418 XClassHint *class_hint;
426 g_return_val_if_fail (attributes != NULL, NULL);
431 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
433 screen = gdk_screen_get_default ();
434 parent = gdk_screen_get_root_window (screen);
437 screen = gdk_drawable_get_screen (parent);
439 screen_x11 = GDK_SCREEN_X11 (screen);
441 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
443 if (GDK_WINDOW_DESTROYED (parent))
446 xparent = GDK_WINDOW_XID (parent);
448 window = g_object_new (GDK_TYPE_WINDOW, NULL);
449 private = (GdkWindowObject *)window;
450 impl = GDK_WINDOW_IMPL_X11 (private->impl);
451 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
452 draw_impl->wrapper = GDK_DRAWABLE (window);
454 draw_impl->screen = screen;
455 xdisplay = screen_x11->xdisplay;
457 /* Windows with a foreign parent are treated as if they are children
458 * of the root window, except for actual creation.
460 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
461 parent = gdk_screen_get_root_window (screen);
463 private->parent = (GdkWindowObject *)parent;
465 xattributes_mask = 0;
467 if (attributes_mask & GDK_WA_X)
472 if (attributes_mask & GDK_WA_Y)
479 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
480 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
482 if (attributes->wclass == GDK_INPUT_ONLY)
484 /* Backwards compatiblity - we've always ignored
485 * attributes->window_type for input-only windows
488 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
489 private->window_type = GDK_WINDOW_TEMP;
491 private->window_type = GDK_WINDOW_CHILD;
494 private->window_type = attributes->window_type;
496 _gdk_window_init_position (GDK_WINDOW (private));
497 if (impl->position_info.big)
498 private->guffaw_gravity = TRUE;
500 if (attributes_mask & GDK_WA_VISUAL)
501 visual = attributes->visual;
503 visual = gdk_screen_get_system_visual (screen);
504 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
506 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
507 for (i = 0; i < _gdk_nenvent_masks; i++)
509 if (attributes->event_mask & (1 << (i + 1)))
510 xattributes.event_mask |= _gdk_event_mask_table[i];
512 private->event_mask = attributes->event_mask;
514 if (xattributes.event_mask)
515 xattributes_mask |= CWEventMask;
517 if (attributes_mask & GDK_WA_NOREDIR)
519 xattributes.override_redirect =
520 (attributes->override_redirect == FALSE)?False:True;
521 xattributes_mask |= CWOverrideRedirect;
524 xattributes.override_redirect = False;
526 if (private->parent && private->parent->guffaw_gravity)
528 xattributes.win_gravity = StaticGravity;
529 xattributes_mask |= CWWinGravity;
533 switch (private->window_type)
535 case GDK_WINDOW_TOPLEVEL:
536 case GDK_WINDOW_DIALOG:
537 case GDK_WINDOW_TEMP:
538 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
540 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
541 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
542 xparent = GDK_SCREEN_XROOTWIN (screen);
544 case GDK_WINDOW_CHILD:
547 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
551 if (attributes->wclass == GDK_INPUT_OUTPUT)
554 depth = visual->depth;
556 private->input_only = FALSE;
557 private->depth = depth;
559 if (attributes_mask & GDK_WA_COLORMAP)
561 draw_impl->colormap = attributes->colormap;
562 g_object_ref (attributes->colormap);
566 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
568 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
569 g_object_ref (draw_impl->colormap);
573 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
577 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
578 xattributes.background_pixel = private->bg_color.pixel;
580 private->bg_pixmap = NULL;
582 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
583 xattributes_mask |= CWBorderPixel | CWBackPixel;
585 if (private->guffaw_gravity)
586 xattributes.bit_gravity = StaticGravity;
588 xattributes.bit_gravity = NorthWestGravity;
590 xattributes_mask |= CWBitGravity;
592 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
593 xattributes_mask |= CWColormap;
595 if (private->window_type == GDK_WINDOW_TEMP)
597 xattributes.save_under = True;
598 xattributes.override_redirect = True;
599 xattributes.cursor = None;
600 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
608 private->input_only = TRUE;
609 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
610 g_object_ref (draw_impl->colormap);
613 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
614 impl->position_info.x, impl->position_info.y,
615 impl->position_info.width, impl->position_info.height,
616 0, depth, class, xvisual,
617 xattributes_mask, &xattributes);
619 g_object_ref (window);
620 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
622 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
623 (attributes->cursor) :
627 private->parent->children = g_list_prepend (private->parent->children, window);
629 switch (GDK_WINDOW_TYPE (private))
631 case GDK_WINDOW_DIALOG:
632 XSetTransientForHint (xdisplay, xid, xparent);
633 case GDK_WINDOW_TOPLEVEL:
634 case GDK_WINDOW_TEMP:
635 set_wm_protocols (window);
637 case GDK_WINDOW_CHILD:
638 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
639 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
640 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
642 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
643 gdk_window_add_colormap_windows (window);
652 toplevel = _gdk_x11_window_get_toplevel (window);
654 if (class != InputOnly)
656 /* The focus window is off the visible area, and serves to receive key
657 * press events so they don't get sent to child windows.
659 toplevel->focus_window = XCreateSimpleWindow (xdisplay, xid,
661 xattributes.background_pixel,
662 xattributes.background_pixel);
663 /* FIXME: probably better to actually track the requested event mask for the toplevel
665 XSelectInput (xdisplay, toplevel->focus_window,
666 KeyPressMask | KeyReleaseMask | FocusChangeMask);
668 XMapWindow (xdisplay, toplevel->focus_window);
669 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
672 size_hints.flags = PSize;
673 size_hints.width = impl->width;
674 size_hints.height = impl->height;
676 check_leader_window_title (screen_x11->display);
678 /* FIXME: Is there any point in doing this? Do any WM's pay
679 * attention to PSize, and even if they do, is this the
682 XSetWMNormalHints (xdisplay, xid, &size_hints);
684 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
685 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
688 XChangeProperty (xdisplay, xid,
689 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
694 XChangeProperty (xdisplay, xid,
695 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
696 XA_WINDOW, 32, PropModeReplace,
697 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
699 if (attributes_mask & GDK_WA_TITLE)
700 title = attributes->title;
702 title = get_default_title ();
704 gdk_window_set_title (window, title);
706 if (attributes_mask & GDK_WA_WMCLASS)
708 class_hint = XAllocClassHint ();
709 class_hint->res_name = attributes->wmclass_name;
710 class_hint->res_class = attributes->wmclass_class;
711 XSetClassHint (xdisplay, xid, class_hint);
719 x_event_mask_to_gdk_event_mask (long mask)
721 GdkEventMask event_mask = 0;
724 for (i = 0; i < _gdk_nenvent_masks; i++)
726 if (mask & _gdk_event_mask_table[i])
727 event_mask |= 1 << (i + 1);
734 * gdk_window_foreign_new_for_display:
735 * @display: the #GdkDisplay where the window handle comes from.
736 * @anid: a native window handle.
738 * Wraps a native window in a #GdkWindow.
739 * This may fail if the window has been destroyed.
741 * For example in the X backend, a native window handle is an Xlib
744 * Return value: the newly-created #GdkWindow wrapper for the
745 * native window or %NULL if the window has been destroyed.
750 gdk_window_foreign_new_for_display (GdkDisplay *display,
751 GdkNativeWindow anid)
754 GdkWindowObject *private;
755 GdkWindowImplX11 *impl;
756 GdkDrawableImplX11 *draw_impl;
757 GdkDisplayX11 *display_x11;
758 XWindowAttributes attrs;
760 Window *children = NULL;
764 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
766 display_x11 = GDK_DISPLAY_X11 (display);
768 gdk_error_trap_push ();
769 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
770 if (gdk_error_trap_pop () || !result)
773 /* FIXME: This is pretty expensive. Maybe the caller should supply
775 gdk_error_trap_push ();
776 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
777 if (gdk_error_trap_pop () || !result)
783 window = g_object_new (GDK_TYPE_WINDOW, NULL);
784 private = (GdkWindowObject *)window;
785 impl = GDK_WINDOW_IMPL_X11 (private->impl);
786 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
787 draw_impl->wrapper = GDK_DRAWABLE (window);
788 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
790 private->parent = gdk_xid_table_lookup_for_display (display, parent);
792 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
793 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
795 private->parent->children = g_list_prepend (private->parent->children, window);
797 draw_impl->xid = anid;
799 private->x = attrs.x;
800 private->y = attrs.y;
801 impl->width = attrs.width;
802 impl->height = attrs.height;
803 private->window_type = GDK_WINDOW_FOREIGN;
804 private->destroyed = FALSE;
806 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
808 if (attrs.map_state == IsUnmapped)
809 private->state = GDK_WINDOW_STATE_WITHDRAWN;
813 private->depth = attrs.depth;
815 _gdk_window_init_position (GDK_WINDOW (private));
817 g_object_ref (window);
818 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
823 * gdk_window_lookup_for_display:
824 * @display: the #GdkDisplay corresponding to the window handle
825 * @anid: a native window handle.
827 * Looks up the #GdkWindow that wraps the given native window handle.
829 * For example in the X backend, a native window handle is an Xlib
832 * Return value: the #GdkWindow wrapper for the native window,
833 * or %NULL if there is none.
838 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
840 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
845 * @anid: a native window handle.
847 * Looks up the #GdkWindow that wraps the given native window handle.
849 * For example in the X backend, a native window handle is an Xlib
852 * Return value: the #GdkWindow wrapper for the native window,
853 * or %NULL if there is none.
856 gdk_window_lookup (GdkNativeWindow anid)
858 return (GdkWindow*) gdk_xid_table_lookup (anid);
862 gdk_toplevel_x11_free_contents (GdkToplevelX11 *toplevel)
864 if (toplevel->icon_window)
866 g_object_unref (toplevel->icon_window);
867 toplevel->icon_window = NULL;
869 if (toplevel->icon_pixmap)
871 g_object_unref (toplevel->icon_pixmap);
872 toplevel->icon_pixmap = NULL;
874 if (toplevel->icon_mask)
876 g_object_unref (toplevel->icon_mask);
877 toplevel->icon_mask = NULL;
879 if (toplevel->group_leader)
881 g_object_unref (toplevel->group_leader);
882 toplevel->group_leader = NULL;
887 _gdk_windowing_window_destroy (GdkWindow *window,
889 gboolean foreign_destroy)
891 GdkWindowObject *private = (GdkWindowObject *)window;
892 GdkToplevelX11 *toplevel;
893 GdkDrawableImplX11 *draw_impl;
895 g_return_if_fail (GDK_IS_WINDOW (window));
897 _gdk_selection_window_destroyed (window);
899 if (private->extension_events != 0)
900 _gdk_input_window_destroy (window);
902 toplevel = _gdk_x11_window_get_toplevel (window);
904 gdk_toplevel_x11_free_contents (toplevel);
906 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
908 if (draw_impl->xft_draw)
909 XftDrawDestroy (draw_impl->xft_draw);
911 if (private->window_type == GDK_WINDOW_FOREIGN)
913 if (!foreign_destroy && (private->parent != NULL))
915 /* It's somebody else's window, but in our heirarchy,
916 * so reparent it to the root window, and then send
917 * it a delete event, as if we were a WM
919 XClientMessageEvent xevent;
921 gdk_error_trap_push ();
922 gdk_window_hide (window);
923 gdk_window_reparent (window, NULL, 0, 0);
925 xevent.type = ClientMessage;
926 xevent.window = GDK_WINDOW_XID (window);
927 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
930 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
932 xevent.data.l[1] = CurrentTime;
933 xevent.data.l[2] = 0;
934 xevent.data.l[3] = 0;
935 xevent.data.l[4] = 0;
937 XSendEvent (GDK_WINDOW_XDISPLAY (window),
938 GDK_WINDOW_XID (window),
939 False, 0, (XEvent *)&xevent);
940 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
941 gdk_error_trap_pop ();
944 else if (!recursing && !foreign_destroy)
946 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
950 /* This function is called when the XWindow is really gone.
953 gdk_window_destroy_notify (GdkWindow *window)
955 GdkWindowImplX11 *window_impl;
957 g_return_if_fail (window != NULL);
959 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
961 if (!GDK_WINDOW_DESTROYED (window))
963 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
964 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
966 _gdk_window_destroy (window, TRUE);
969 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
970 if (window_impl->toplevel && window_impl->toplevel->focus_window)
971 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
973 _gdk_xgrab_check_destroy (window);
975 g_object_unref (window);
979 update_wm_hints (GdkWindow *window,
982 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
983 GdkWindowObject *private = (GdkWindowObject *)window;
984 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
988 private->state & GDK_WINDOW_STATE_WITHDRAWN)
991 wm_hints.flags = StateHint;
992 wm_hints.input = True;
993 wm_hints.initial_state = NormalState;
995 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
997 wm_hints.flags |= StateHint;
998 wm_hints.initial_state = IconicState;
1001 if (toplevel->icon_window && !GDK_WINDOW_DESTROYED (toplevel->icon_window))
1003 wm_hints.flags |= IconWindowHint;
1004 wm_hints.icon_window = GDK_WINDOW_XID (toplevel->icon_window);
1007 if (toplevel->icon_pixmap)
1009 wm_hints.flags |= IconPixmapHint;
1010 wm_hints.icon_pixmap = GDK_PIXMAP_XID (toplevel->icon_pixmap);
1013 if (toplevel->icon_mask)
1015 wm_hints.flags |= IconMaskHint;
1016 wm_hints.icon_mask = GDK_PIXMAP_XID (toplevel->icon_mask);
1019 wm_hints.flags |= WindowGroupHint;
1020 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1022 wm_hints.flags |= WindowGroupHint;
1023 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1026 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1028 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1029 GDK_WINDOW_XID (window),
1034 set_initial_hints (GdkWindow *window)
1036 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1037 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1038 Window xwindow = GDK_WINDOW_XID (window);
1039 GdkWindowObject *private;
1040 GdkToplevelX11 *toplevel;
1044 private = (GdkWindowObject*) window;
1045 toplevel = _gdk_x11_window_get_toplevel (window);
1050 update_wm_hints (window, TRUE);
1052 /* We set the spec hints regardless of whether the spec is supported,
1053 * since it can't hurt and it's kind of expensive to check whether
1059 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1061 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1062 "_NET_WM_STATE_MAXIMIZED_VERT");
1064 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1065 "_NET_WM_STATE_MAXIMIZED_HORZ");
1069 if (private->state & GDK_WINDOW_STATE_STICKY)
1071 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1072 "_NET_WM_STATE_STICKY");
1076 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1078 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1079 "_NET_WM_STATE_FULLSCREEN");
1083 if (private->modal_hint)
1085 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1086 "_NET_WM_STATE_MODAL");
1090 if (toplevel->skip_taskbar_hint)
1092 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1093 "_NET_WM_STATE_SKIP_TASKBAR");
1097 if (toplevel->skip_pager_hint)
1099 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1100 "_NET_WM_STATE_SKIP_PAGER");
1106 XChangeProperty (xdisplay,
1108 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1109 XA_ATOM, 32, PropModeReplace,
1110 (guchar*) atoms, i);
1114 XDeleteProperty (xdisplay,
1116 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1119 if (private->state & GDK_WINDOW_STATE_STICKY)
1121 atoms[0] = 0xFFFFFFFF;
1122 XChangeProperty (xdisplay,
1124 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1125 XA_CARDINAL, 32, PropModeReplace,
1126 (guchar*) atoms, 1);
1130 XDeleteProperty (xdisplay,
1132 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1135 toplevel->map_serial = NextRequest (xdisplay);
1139 show_window_internal (GdkWindow *window,
1142 GdkWindowObject *private;
1144 g_return_if_fail (GDK_IS_WINDOW (window));
1146 private = (GdkWindowObject*) window;
1147 if (!private->destroyed)
1149 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1150 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1151 Window xwindow = GDK_WINDOW_XID (window);
1154 XRaiseWindow (xdisplay, xwindow);
1156 if (!GDK_WINDOW_IS_MAPPED (window))
1158 set_initial_hints (window);
1160 gdk_synthesize_window_state (window,
1161 GDK_WINDOW_STATE_WITHDRAWN,
1165 g_assert (GDK_WINDOW_IS_MAPPED (window));
1167 if (impl->position_info.mapped)
1168 XMapWindow (xdisplay, xwindow);
1173 * gdk_window_show_unraised:
1174 * @window: a #GdkWindow
1176 * Shows a #GdkWindow onscreen, but does not modify its stacking
1177 * order. In contrast, gdk_window_show() will raise the window
1178 * to the top of the window stack.
1180 * On the X11 platform, in Xlib terms, this function calls
1181 * XMapWindow() (it also updates some internal GDK state, which means
1182 * that you can't really use XMapWindow() directly on a GDK window).
1186 gdk_window_show_unraised (GdkWindow *window)
1188 g_return_if_fail (GDK_IS_WINDOW (window));
1190 show_window_internal (window, FALSE);
1195 * @window: a #GdkWindow
1197 * Like gdk_window_show_unraised(), but also raises the window to the
1198 * top of the window stack (moves the window to the front of the
1201 * This function maps a window so it's visible onscreen. Its opposite
1202 * is gdk_window_hide().
1204 * When implementing a #GtkWidget, you should call this function on the widget's
1205 * #GdkWindow as part of the "map" method.
1209 gdk_window_show (GdkWindow *window)
1211 g_return_if_fail (GDK_IS_WINDOW (window));
1213 show_window_internal (window, TRUE);
1218 * @window: a #GdkWindow
1220 * For toplevel windows, withdraws them, so they will no longer be
1221 * known to the window manager; for all windows, unmaps them, so
1222 * they won't be displayed. Normally done automatically as
1223 * part of gtk_widget_hide().
1227 gdk_window_hide (GdkWindow *window)
1229 GdkWindowObject *private;
1231 g_return_if_fail (window != NULL);
1233 private = (GdkWindowObject*) window;
1235 /* We'll get the unmap notify eventually, and handle it then,
1236 * but checking here makes things more consistent if we are
1237 * just doing stuff ourself.
1239 _gdk_xgrab_check_unmap (window,
1240 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1242 /* You can't simply unmap toplevel windows. */
1243 switch (private->window_type)
1245 case GDK_WINDOW_TOPLEVEL:
1246 case GDK_WINDOW_DIALOG:
1247 case GDK_WINDOW_TEMP: /* ? */
1248 gdk_window_withdraw (window);
1252 case GDK_WINDOW_FOREIGN:
1253 case GDK_WINDOW_ROOT:
1254 case GDK_WINDOW_CHILD:
1258 if (!private->destroyed)
1260 if (GDK_WINDOW_IS_MAPPED (window))
1261 gdk_synthesize_window_state (window,
1263 GDK_WINDOW_STATE_WITHDRAWN);
1265 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1267 _gdk_window_clear_update_area (window);
1269 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1270 GDK_WINDOW_XID (window));
1275 * gdk_window_withdraw:
1276 * @window: a toplevel #GdkWindow
1278 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1279 * This function is not really useful as gdk_window_hide() automatically
1280 * withdraws toplevel windows before hiding them.
1284 gdk_window_withdraw (GdkWindow *window)
1286 GdkWindowObject *private;
1288 g_return_if_fail (window != NULL);
1290 private = (GdkWindowObject*) window;
1291 if (!private->destroyed)
1293 if (GDK_WINDOW_IS_MAPPED (window))
1294 gdk_synthesize_window_state (window,
1296 GDK_WINDOW_STATE_WITHDRAWN);
1298 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1300 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1301 GDK_WINDOW_XID (window), 0);
1307 * @window: a #GdkWindow
1308 * @x: X coordinate relative to window's parent
1309 * @y: Y coordinate relative to window's parent
1311 * Repositions a window relative to its parent window.
1312 * For toplevel windows, window managers may ignore or modify the move;
1313 * you should probably use gtk_window_move() on a #GtkWindow widget
1314 * anyway, instead of using GDK functions. For child windows,
1315 * the move will reliably succeed.
1317 * If you're also planning to resize the window, use gdk_window_move_resize()
1318 * to both move and resize simultaneously, for a nicer visual effect.
1321 gdk_window_move (GdkWindow *window,
1325 GdkWindowObject *private = (GdkWindowObject *)window;
1326 GdkWindowImplX11 *impl;
1328 g_return_if_fail (window != NULL);
1329 g_return_if_fail (GDK_IS_WINDOW (window));
1331 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1333 if (!GDK_WINDOW_DESTROYED (window))
1335 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1336 _gdk_window_move_resize_child (window, x, y,
1337 impl->width, impl->height);
1340 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1341 GDK_WINDOW_XID (window),
1348 * gdk_window_resize:
1349 * @window: a #GdkWindow
1350 * @width: new width of the window
1351 * @height: new height of the window
1353 * Resizes @window; for toplevel windows, asks the window manager to resize
1354 * the window. The window manager may not allow the resize. When using GTK+,
1355 * use gtk_window_resize() instead of this low-level GDK function.
1357 * Windows may not be resized below 1x1.
1359 * If you're also planning to move the window, use gdk_window_move_resize()
1360 * to both move and resize simultaneously, for a nicer visual effect.
1363 gdk_window_resize (GdkWindow *window,
1367 GdkWindowObject *private;
1369 g_return_if_fail (window != NULL);
1370 g_return_if_fail (GDK_IS_WINDOW (window));
1377 private = (GdkWindowObject*) window;
1379 if (!GDK_WINDOW_DESTROYED (window))
1381 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1382 _gdk_window_move_resize_child (window, private->x, private->y,
1386 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1388 if (width != impl->width || height != impl->height)
1389 private->resize_count += 1;
1391 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1392 GDK_WINDOW_XID (window),
1399 * gdk_window_move_resize:
1400 * @window: a #GdkWindow
1401 * @x: new X position relative to window's parent
1402 * @y: new Y position relative to window's parent
1404 * @height: new height
1406 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1407 * except that both operations are performed at once, avoiding strange
1408 * visual effects. (i.e. the user may be able to see the window first
1409 * move, then resize, if you don't use gdk_window_move_resize().)
1412 gdk_window_move_resize (GdkWindow *window,
1418 GdkWindowObject *private;
1420 g_return_if_fail (window != NULL);
1421 g_return_if_fail (GDK_IS_WINDOW (window));
1428 private = (GdkWindowObject*) window;
1430 if (!GDK_WINDOW_DESTROYED (window))
1432 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1433 _gdk_window_move_resize_child (window, x, y, width, height);
1436 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1438 if (width != impl->width || height != impl->height)
1439 private->resize_count += 1;
1441 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1442 GDK_WINDOW_XID (window),
1443 x, y, width, height);
1449 * gdk_window_reparent:
1450 * @window: a #GdkWindow
1451 * @new_parent: new parent to move @window into
1452 * @x: X location inside the new parent
1453 * @y: Y location inside the new parent
1455 * Reparents @window into the given @new_parent. The window being
1456 * reparented will be unmapped as a side effect.
1460 gdk_window_reparent (GdkWindow *window,
1461 GdkWindow *new_parent,
1465 GdkDisplay *display;
1466 GdkWindowObject *window_private;
1467 GdkWindowObject *parent_private;
1468 GdkWindowObject *old_parent_private;
1470 g_return_if_fail (window != NULL);
1471 g_return_if_fail (GDK_IS_WINDOW (window));
1472 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1473 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1476 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1478 display = GDK_WINDOW_DISPLAY (window);
1480 window_private = (GdkWindowObject*) window;
1481 old_parent_private = (GdkWindowObject*)window_private->parent;
1482 parent_private = (GdkWindowObject*) new_parent;
1484 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1485 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1486 GDK_WINDOW_XID (window),
1487 GDK_WINDOW_XID (new_parent),
1490 window_private->x = x;
1491 window_private->y = y;
1493 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1496 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1497 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1499 window_private->parent = (GdkWindowObject *)new_parent;
1501 /* Switch the window type as appropriate */
1503 switch (GDK_WINDOW_TYPE (new_parent))
1505 case GDK_WINDOW_ROOT:
1506 case GDK_WINDOW_FOREIGN:
1507 /* Now a toplevel */
1508 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1509 set_wm_protocols (window);
1511 case GDK_WINDOW_TOPLEVEL:
1512 case GDK_WINDOW_CHILD:
1513 case GDK_WINDOW_DIALOG:
1514 case GDK_WINDOW_TEMP:
1515 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1516 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1518 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1520 /* If we were being sophisticated, we'd save the old window type
1521 * here, and restore it if we were reparented back to the
1522 * toplevel. However, the difference between different types
1523 * of toplevels only really matters on creation anyways.
1525 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1528 gdk_toplevel_x11_free_contents (impl->toplevel);
1529 g_free (impl->toplevel);
1530 impl->toplevel = NULL;
1535 if (old_parent_private)
1536 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1538 if ((old_parent_private &&
1539 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1540 (!old_parent_private && parent_private->guffaw_gravity))
1541 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1543 parent_private->children = g_list_prepend (parent_private->children, window);
1544 _gdk_window_init_position (GDK_WINDOW (window_private));
1548 _gdk_windowing_window_clear_area (GdkWindow *window,
1554 g_return_if_fail (window != NULL);
1555 g_return_if_fail (GDK_IS_WINDOW (window));
1557 if (!GDK_WINDOW_DESTROYED (window))
1558 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1559 x, y, width, height, False);
1563 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1569 g_return_if_fail (window != NULL);
1570 g_return_if_fail (GDK_IS_WINDOW (window));
1572 if (!GDK_WINDOW_DESTROYED (window))
1573 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1574 x, y, width, height, True);
1580 * @window: a #GdkWindow
1582 * Raises @window to the top of the Z-order (stacking order), so that
1583 * other windows with the same parent window appear below @window.
1584 * This is true whether or not the windows are visible.
1586 * If @window is a toplevel, the window manager may choose to deny the
1587 * request to move the window in the Z-order, gdk_window_raise() only
1588 * requests the restack, does not guarantee it.
1592 gdk_window_raise (GdkWindow *window)
1594 g_return_if_fail (window != NULL);
1595 g_return_if_fail (GDK_IS_WINDOW (window));
1597 if (!GDK_WINDOW_DESTROYED (window))
1598 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1603 * @window: a #GdkWindow
1605 * Lowers @window to the bottom of the Z-order (stacking order), so that
1606 * other windows with the same parent window appear above @window.
1607 * This is true whether or not the other windows are visible.
1609 * If @window is a toplevel, the window manager may choose to deny the
1610 * request to move the window in the Z-order, gdk_window_lower() only
1611 * requests the restack, does not guarantee it.
1613 * Note that gdk_window_show() raises the window again, so don't call this
1614 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1618 gdk_window_lower (GdkWindow *window)
1620 g_return_if_fail (window != NULL);
1621 g_return_if_fail (GDK_IS_WINDOW (window));
1623 if (!GDK_WINDOW_DESTROYED (window))
1624 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1629 * @window: a #GdkWindow
1630 * @timestamp: timestamp of the event triggering the window focus
1632 * Sets keyboard focus to @window. If @window is not onscreen this
1633 * will not work. In most cases, gtk_window_present() should be used on
1634 * a #GtkWindow, rather than calling this function.
1638 gdk_window_focus (GdkWindow *window,
1641 GdkDisplay *display;
1643 g_return_if_fail (GDK_IS_WINDOW (window));
1645 if (GDK_WINDOW_DESTROYED (window))
1648 display = GDK_WINDOW_DISPLAY (window);
1650 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1651 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1655 xev.xclient.type = ClientMessage;
1656 xev.xclient.serial = 0;
1657 xev.xclient.send_event = True;
1658 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1659 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1660 "_NET_ACTIVE_WINDOW");
1661 xev.xclient.format = 32;
1662 xev.xclient.data.l[0] = 0;
1663 xev.xclient.data.l[1] = 0;
1664 xev.xclient.data.l[2] = 0;
1665 xev.xclient.data.l[3] = 0;
1666 xev.xclient.data.l[4] = 0;
1668 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1669 SubstructureRedirectMask | SubstructureNotifyMask,
1674 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1676 /* There is no way of knowing reliably whether we are viewable;
1677 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1679 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1686 * gdk_window_set_hints:
1687 * @window: a #GdkWindow
1688 * @x: ignored field, does not matter
1689 * @y: ignored field, does not matter
1690 * @min_width: minimum width hint
1691 * @min_height: minimum height hint
1692 * @max_width: max width hint
1693 * @max_height: max height hint
1694 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1696 * This function is broken and useless and you should ignore it.
1697 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1698 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1699 * depending on what you're trying to do.
1701 * If using GDK directly, use gdk_window_set_geometry_hints().
1705 gdk_window_set_hints (GdkWindow *window,
1714 XSizeHints size_hints;
1716 g_return_if_fail (window != NULL);
1717 g_return_if_fail (GDK_IS_WINDOW (window));
1719 if (GDK_WINDOW_DESTROYED (window))
1722 size_hints.flags = 0;
1724 if (flags & GDK_HINT_POS)
1726 size_hints.flags |= PPosition;
1731 if (flags & GDK_HINT_MIN_SIZE)
1733 size_hints.flags |= PMinSize;
1734 size_hints.min_width = min_width;
1735 size_hints.min_height = min_height;
1738 if (flags & GDK_HINT_MAX_SIZE)
1740 size_hints.flags |= PMaxSize;
1741 size_hints.max_width = max_width;
1742 size_hints.max_height = max_height;
1745 /* FIXME: Would it be better to delete this property if
1746 * flags == 0? It would save space on the server
1748 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1749 GDK_WINDOW_XID (window),
1754 * gdk_window_set_type_hint:
1755 * @window: A toplevel #GdkWindow
1756 * @hint: A hint of the function this window will have
1758 * The application can use this call to provide a hint to the window
1759 * manager about the functionality of a window. The window manager
1760 * can use this information when determining the decoration and behaviour
1763 * The hint must be set before the window is mapped.
1766 gdk_window_set_type_hint (GdkWindow *window,
1767 GdkWindowTypeHint hint)
1769 GdkDisplay *display;
1772 g_return_if_fail (window != NULL);
1773 g_return_if_fail (GDK_IS_WINDOW (window));
1775 if (GDK_WINDOW_DESTROYED (window))
1778 display = gdk_drawable_get_display (window);
1782 case GDK_WINDOW_TYPE_HINT_DIALOG:
1783 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1785 case GDK_WINDOW_TYPE_HINT_MENU:
1786 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1788 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1789 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1791 case GDK_WINDOW_TYPE_HINT_UTILITY:
1792 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1794 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1795 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1797 case GDK_WINDOW_TYPE_HINT_DOCK:
1798 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1800 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1801 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1804 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1806 case GDK_WINDOW_TYPE_HINT_NORMAL:
1807 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1811 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1812 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1813 XA_ATOM, 32, PropModeReplace,
1814 (guchar *)&atom, 1);
1819 gdk_wmspec_change_state (gboolean add,
1824 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1827 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1828 #define _NET_WM_STATE_ADD 1 /* add/set property */
1829 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1831 xev.xclient.type = ClientMessage;
1832 xev.xclient.serial = 0;
1833 xev.xclient.send_event = True;
1834 xev.xclient.window = GDK_WINDOW_XID (window);
1835 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1836 xev.xclient.format = 32;
1837 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1838 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1839 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1840 xev.xclient.data.l[3] = 0;
1841 xev.xclient.data.l[4] = 0;
1843 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1844 SubstructureRedirectMask | SubstructureNotifyMask,
1849 * gdk_window_set_modal_hint:
1850 * @window: A toplevel #GdkWindow
1851 * @modal: TRUE if the window is modal, FALSE otherwise.
1853 * The application can use this hint to tell the window manager
1854 * that a certain window has modal behaviour. The window manager
1855 * can use this information to handle modal windows in a special
1858 * You should only use this on windows for which you have
1859 * previously called #gdk_window_set_transient_for()
1862 gdk_window_set_modal_hint (GdkWindow *window,
1865 GdkWindowObject *private;
1867 g_return_if_fail (window != NULL);
1868 g_return_if_fail (GDK_IS_WINDOW (window));
1870 if (GDK_WINDOW_DESTROYED (window))
1873 private = (GdkWindowObject*) window;
1875 private->modal_hint = modal;
1877 if (GDK_WINDOW_IS_MAPPED (window))
1878 gdk_wmspec_change_state (modal, window,
1879 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1884 * gdk_window_set_skip_taskbar_hint:
1885 * @window: a toplevel #GdkWindow
1886 * @skips_taskbar: %TRUE to skip the taskbar
1888 * Toggles whether a window should appear in a task list or window
1889 * list. If a window's semantic type as specified with
1890 * gdk_window_set_type_hint() already fully describes the window, this
1891 * function should NOT be called in addition, instead you should allow
1892 * the window to be treated according to standard policy for its
1898 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
1899 gboolean skips_taskbar)
1901 GdkToplevelX11 *toplevel;
1903 g_return_if_fail (window != NULL);
1904 g_return_if_fail (GDK_IS_WINDOW (window));
1905 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1907 if (GDK_WINDOW_DESTROYED (window))
1910 toplevel = _gdk_x11_window_get_toplevel (window);
1911 toplevel->skip_taskbar_hint = skips_taskbar;
1913 if (GDK_WINDOW_IS_MAPPED (window))
1914 gdk_wmspec_change_state (skips_taskbar, window,
1915 gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE),
1920 * gdk_window_set_skip_pager_hint:
1921 * @window: a toplevel #GdkWindow
1922 * @skips_pager: %TRUE to skip the pager
1924 * Toggles whether a window should appear in a pager (workspace
1925 * switcher, or other desktop utility program that displays a small
1926 * thumbnail representation of the windows on the desktop). If a
1927 * window's semantic type as specified with gdk_window_set_type_hint()
1928 * already fully describes the window, this function should NOT be
1929 * called in addition, instead you should allow the window to be
1930 * treated according to standard policy for its semantic type.
1935 gdk_window_set_skip_pager_hint (GdkWindow *window,
1936 gboolean skips_pager)
1938 GdkToplevelX11 *toplevel;
1940 g_return_if_fail (window != NULL);
1941 g_return_if_fail (GDK_IS_WINDOW (window));
1942 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1944 if (GDK_WINDOW_DESTROYED (window))
1947 toplevel = _gdk_x11_window_get_toplevel (window);
1948 toplevel->skip_pager_hint = skips_pager;
1950 if (GDK_WINDOW_IS_MAPPED (window))
1951 gdk_wmspec_change_state (skips_pager, window,
1952 gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE),
1957 * gdk_window_set_geometry_hints:
1958 * @window: a toplevel #GdkWindow
1959 * @geometry: geometry hints
1960 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1962 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1963 * are set, hints not flagged in @geom_mask are unset.
1964 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1966 * This function provides hints to the windowing system about
1967 * acceptable sizes for a toplevel window. The purpose of
1968 * this is to constrain user resizing, but the windowing system
1969 * will typically (but is not required to) also constrain the
1970 * current size of the window to the provided values and
1971 * constrain programatic resizing via gdk_window_resize() or
1972 * gdk_window_move_resize().
1974 * Note that on X11, this effect has no effect on windows
1975 * of type GDK_WINDOW_TEMP or windows where override_redirect
1976 * has been turned on via gdk_window_set_override_redirect()
1977 * since these windows are not resizable by the user.
1979 * Since you can't count on the windowing system doing the
1980 * constraints for programmatic resizes, you should generally
1981 * call gdk_window_constrain_size() yourself to determine
1982 * appropriate sizes.
1986 gdk_window_set_geometry_hints (GdkWindow *window,
1987 GdkGeometry *geometry,
1988 GdkWindowHints geom_mask)
1990 XSizeHints size_hints;
1992 g_return_if_fail (window != NULL);
1993 g_return_if_fail (GDK_IS_WINDOW (window));
1995 if (GDK_WINDOW_DESTROYED (window))
1998 size_hints.flags = 0;
2000 if (geom_mask & GDK_HINT_POS)
2002 size_hints.flags |= PPosition;
2003 /* We need to initialize the following obsolete fields because KWM
2004 * apparently uses these fields if they are non-zero.
2011 if (geom_mask & GDK_HINT_USER_POS)
2013 size_hints.flags |= USPosition;
2016 if (geom_mask & GDK_HINT_USER_SIZE)
2018 size_hints.flags |= USSize;
2021 if (geom_mask & GDK_HINT_MIN_SIZE)
2023 size_hints.flags |= PMinSize;
2024 size_hints.min_width = geometry->min_width;
2025 size_hints.min_height = geometry->min_height;
2028 if (geom_mask & GDK_HINT_MAX_SIZE)
2030 size_hints.flags |= PMaxSize;
2031 size_hints.max_width = MAX (geometry->max_width, 1);
2032 size_hints.max_height = MAX (geometry->max_height, 1);
2035 if (geom_mask & GDK_HINT_BASE_SIZE)
2037 size_hints.flags |= PBaseSize;
2038 size_hints.base_width = geometry->base_width;
2039 size_hints.base_height = geometry->base_height;
2042 if (geom_mask & GDK_HINT_RESIZE_INC)
2044 size_hints.flags |= PResizeInc;
2045 size_hints.width_inc = geometry->width_inc;
2046 size_hints.height_inc = geometry->height_inc;
2049 if (geom_mask & GDK_HINT_ASPECT)
2051 size_hints.flags |= PAspect;
2052 if (geometry->min_aspect <= 1)
2054 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2055 size_hints.min_aspect.y = 65536;
2059 size_hints.min_aspect.x = 65536;
2060 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2062 if (geometry->max_aspect <= 1)
2064 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2065 size_hints.max_aspect.y = 65536;
2069 size_hints.max_aspect.x = 65536;
2070 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2074 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2076 size_hints.flags |= PWinGravity;
2077 size_hints.win_gravity = geometry->win_gravity;
2080 /* FIXME: Would it be better to delete this property if
2081 * geom_mask == 0? It would save space on the server
2083 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2084 GDK_WINDOW_XID (window),
2089 gdk_window_get_geometry_hints (GdkWindow *window,
2090 GdkGeometry *geometry,
2091 GdkWindowHints *geom_mask)
2093 XSizeHints size_hints;
2094 glong junk_size_mask = 0;
2096 g_return_if_fail (GDK_IS_WINDOW (window));
2097 g_return_if_fail (geometry != NULL);
2098 g_return_if_fail (geom_mask != NULL);
2102 if (GDK_WINDOW_DESTROYED (window))
2105 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2106 GDK_WINDOW_XID (window),
2111 if (size_hints.flags & PMinSize)
2113 *geom_mask |= GDK_HINT_MIN_SIZE;
2114 geometry->min_width = size_hints.min_width;
2115 geometry->min_height = size_hints.min_height;
2118 if (size_hints.flags & PMaxSize)
2120 *geom_mask |= GDK_HINT_MAX_SIZE;
2121 geometry->max_width = MAX (size_hints.max_width, 1);
2122 geometry->max_height = MAX (size_hints.max_height, 1);
2125 if (size_hints.flags & PResizeInc)
2127 *geom_mask |= GDK_HINT_RESIZE_INC;
2128 geometry->width_inc = size_hints.width_inc;
2129 geometry->height_inc = size_hints.height_inc;
2132 if (size_hints.flags & PAspect)
2134 *geom_mask |= GDK_HINT_ASPECT;
2136 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
2137 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
2140 if (size_hints.flags & PWinGravity)
2142 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2143 geometry->win_gravity = size_hints.win_gravity;
2148 utf8_is_latin1 (const gchar *str)
2150 const char *p = str;
2154 gunichar ch = g_utf8_get_char (p);
2159 p = g_utf8_next_char (p);
2165 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2166 * convertable to STRING, otherwise, set it as compound text
2169 set_text_property (GdkDisplay *display,
2172 const gchar *utf8_str)
2174 guchar *prop_text = NULL;
2179 if (utf8_is_latin1 (utf8_str))
2181 prop_type = XA_STRING;
2182 prop_text = gdk_utf8_to_string_target (utf8_str);
2183 prop_length = prop_text ? strlen (prop_text) : 0;
2190 gdk_utf8_to_compound_text_for_display (display,
2191 utf8_str, &gdk_type, &prop_format,
2192 &prop_text, &prop_length);
2193 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2198 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2201 prop_type, prop_format,
2202 PropModeReplace, prop_text,
2205 gdk_free_compound_text (prop_text);
2209 /* Set WM_NAME and _NET_WM_NAME
2212 set_wm_name (GdkDisplay *display,
2216 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2217 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2218 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2219 PropModeReplace, name, strlen (name));
2221 set_text_property (display, xwindow,
2222 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2227 * gdk_window_set_title:
2228 * @window: a toplevel #GdkWindow
2229 * @title: title of @window
2231 * Sets the title of a toplevel window, to be displayed in the titlebar.
2232 * If you haven't explicitly set the icon name for the window
2233 * (using gdk_window_set_icon_name()), the icon name will be set to
2234 * @title as well. @title must be in UTF-8 encoding (as with all
2235 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2238 gdk_window_set_title (GdkWindow *window,
2241 GdkDisplay *display;
2245 g_return_if_fail (window != NULL);
2246 g_return_if_fail (GDK_IS_WINDOW (window));
2247 g_return_if_fail (title != NULL);
2249 if (GDK_WINDOW_DESTROYED (window))
2252 display = gdk_drawable_get_display (window);
2253 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2254 xwindow = GDK_WINDOW_XID (window);
2256 set_wm_name (display, xwindow, title);
2258 if (!gdk_window_icon_name_set (window))
2260 XChangeProperty (xdisplay, xwindow,
2261 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2262 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2263 PropModeReplace, title, strlen (title));
2265 set_text_property (display, xwindow,
2266 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2272 * gdk_window_set_role:
2273 * @window: a toplevel #GdkWindow
2274 * @role: a string indicating its role
2276 * When using GTK+, typically you should use gtk_window_set_role() instead
2277 * of this low-level function.
2279 * The window manager and session manager use a window's role to
2280 * distinguish it from other kinds of window in the same application.
2281 * When an application is restarted after being saved in a previous
2282 * session, all windows with the same title and role are treated as
2283 * interchangeable. So if you have two windows with the same title
2284 * that should be distinguished for session management purposes, you
2285 * should set the role on those windows. It doesn't matter what string
2286 * you use for the role, as long as you have a different role for each
2287 * non-interchangeable kind of window.
2291 gdk_window_set_role (GdkWindow *window,
2294 GdkDisplay *display;
2296 g_return_if_fail (window != NULL);
2297 g_return_if_fail (GDK_IS_WINDOW (window));
2299 display = gdk_drawable_get_display (window);
2301 if (!GDK_WINDOW_DESTROYED (window))
2304 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2305 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2306 XA_STRING, 8, PropModeReplace, role, strlen (role));
2308 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2309 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2314 * gdk_window_set_transient_for:
2315 * @window: a toplevel #GdkWindow
2316 * @parent: another toplevel #GdkWindow
2318 * Indicates to the window manager that @window is a transient dialog
2319 * associated with the application window @parent. This allows the
2320 * window manager to do things like center @window on @parent and
2321 * keep @window above @parent.
2323 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2328 gdk_window_set_transient_for (GdkWindow *window,
2331 GdkWindowObject *private;
2332 GdkWindowObject *parent_private;
2334 g_return_if_fail (window != NULL);
2335 g_return_if_fail (GDK_IS_WINDOW (window));
2337 private = (GdkWindowObject*) window;
2338 parent_private = (GdkWindowObject*) parent;
2340 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2341 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2342 GDK_WINDOW_XID (window),
2343 GDK_WINDOW_XID (parent));
2347 * gdk_window_set_background:
2348 * @window: a #GdkWindow
2349 * @color: an allocated #GdkColor
2351 * Sets the background color of @window. (However, when using GTK+,
2352 * set the background of a widget with gtk_widget_modify_bg() - if
2353 * you're an application - or gtk_style_set_background() - if you're
2354 * implementing a custom widget.)
2356 * The @color must be allocated; gdk_rgb_find_color() is the best way
2357 * to allocate a color.
2359 * See also gdk_window_set_back_pixmap().
2363 gdk_window_set_background (GdkWindow *window,
2366 GdkWindowObject *private = (GdkWindowObject *)window;
2368 g_return_if_fail (window != NULL);
2369 g_return_if_fail (GDK_IS_WINDOW (window));
2371 if (!GDK_WINDOW_DESTROYED (window))
2372 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2373 GDK_WINDOW_XID (window), color->pixel);
2375 private->bg_color = *color;
2377 if (private->bg_pixmap &&
2378 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2379 private->bg_pixmap != GDK_NO_BG)
2380 g_object_unref (private->bg_pixmap);
2382 private->bg_pixmap = NULL;
2386 * gdk_window_set_back_pixmap:
2387 * @window: a #GdkWindow
2388 * @pixmap: a #GdkPixmap, or %NULL
2389 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2391 * Sets the background pixmap of @window. May also be used to set a background of
2392 * "None" on @window, by setting a background pixmap of %NULL.
2393 * A background pixmap will be tiled, positioning the first tile at the origin of
2394 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2395 * origin of the parent window (useful to align tiles in a parent with tiles
2398 * A background pixmap of %NULL means that the window will have no
2399 * background. A window with no background will never have its
2400 * background filled by the windowing system, instead the window will
2401 * contain whatever pixels were already in the corresponding area of
2404 * The windowing system will normally fill a window with its background
2405 * when the window is obscured then exposed, and when you call
2406 * gdk_window_clear().
2410 gdk_window_set_back_pixmap (GdkWindow *window,
2412 gboolean parent_relative)
2414 GdkWindowObject *private = (GdkWindowObject *)window;
2417 g_return_if_fail (window != NULL);
2418 g_return_if_fail (GDK_IS_WINDOW (window));
2419 g_return_if_fail (pixmap == NULL || !parent_relative);
2420 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2422 if (private->bg_pixmap &&
2423 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2424 private->bg_pixmap != GDK_NO_BG)
2425 g_object_unref (private->bg_pixmap);
2427 if (parent_relative)
2429 xpixmap = ParentRelative;
2430 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2436 g_object_ref (pixmap);
2437 private->bg_pixmap = pixmap;
2438 xpixmap = GDK_PIXMAP_XID (pixmap);
2443 private->bg_pixmap = GDK_NO_BG;
2447 if (!GDK_WINDOW_DESTROYED (window))
2448 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2449 GDK_WINDOW_XID (window), xpixmap);
2453 * gdk_window_set_cursor:
2454 * @window: a #GdkWindow
2457 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2458 * gdk_cursor_new_from_pixmap() to create the cursor.
2459 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2460 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2461 * to gdk_window_set_cursor() means that @window will use the cursor of
2462 * its parent window. Most windows should use this default.
2466 gdk_window_set_cursor (GdkWindow *window,
2469 GdkCursorPrivate *cursor_private;
2472 g_return_if_fail (window != NULL);
2473 g_return_if_fail (GDK_IS_WINDOW (window));
2475 cursor_private = (GdkCursorPrivate*) cursor;
2480 xcursor = cursor_private->xcursor;
2482 if (!GDK_WINDOW_DESTROYED (window))
2483 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2484 GDK_WINDOW_XID (window),
2489 * gdk_window_get_geometry:
2490 * @window: a #GdkWindow
2491 * @x: return location for X coordinate of window (relative to its parent)
2492 * @y: return location for Y coordinate of window (relative to its parent)
2493 * @width: return location for width of window
2494 * @height: return location for height of window
2495 * @depth: return location for bit depth of window
2497 * Any of the return location arguments to this function may be %NULL,
2498 * if you aren't interested in getting the value of that field.
2500 * The X and Y coordinates returned are relative to the parent window
2501 * of @window, which for toplevels usually means relative to the
2502 * window decorations (titlebar, etc.) rather than relative to the
2503 * root window (screen-size background window).
2505 * On the X11 platform, the geometry is obtained from the X server,
2506 * so reflects the latest position of @window; this may be out-of-sync
2507 * with the position of @window delivered in the most-recently-processed
2508 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2509 * position from the most recent configure event.
2513 gdk_window_get_geometry (GdkWindow *window,
2525 guint tborder_width;
2528 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2532 GDK_NOTE (MULTIHEAD,
2533 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2534 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
2537 if (!GDK_WINDOW_DESTROYED (window))
2539 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2540 GDK_WINDOW_XID (window),
2541 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2557 * gdk_window_get_origin:
2558 * @window: a #GdkWindow
2559 * @x: return location for X coordinate
2560 * @y: return location for Y coordinate
2562 * Obtains the position of a window in root window coordinates.
2563 * (Compare with gdk_window_get_position() and
2564 * gdk_window_get_geometry() which return the position of a window
2565 * relative to its parent window.)
2567 * Return value: not meaningful, ignore
2570 gdk_window_get_origin (GdkWindow *window,
2579 g_return_val_if_fail (window != NULL, 0);
2581 if (!GDK_WINDOW_DESTROYED (window))
2583 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2584 GDK_WINDOW_XID (window),
2585 GDK_WINDOW_XROOTWIN (window),
2601 * gdk_window_get_deskrelative_origin:
2602 * @window: a toplevel #GdkWindow
2603 * @x: return location for X coordinate
2604 * @y: return location for Y coordinate
2606 * This gets the origin of a #GdkWindow relative to
2607 * an Enlightenment-window-manager desktop. As long as you don't
2608 * assume that the user's desktop/workspace covers the entire
2609 * root window (i.e. you don't assume that the desktop begins
2610 * at root window coordinate 0,0) this function is not necessary.
2611 * It's deprecated for that reason.
2613 * Return value: not meaningful
2616 gdk_window_get_deskrelative_origin (GdkWindow *window,
2620 gboolean return_val = FALSE;
2621 gint num_children, format_return;
2622 Window win, *child, parent, root;
2627 gulong number_return, bytes_after_return;
2628 guchar *data_return;
2630 g_return_val_if_fail (window != NULL, FALSE);
2631 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2633 if (!GDK_WINDOW_DESTROYED (window))
2635 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2636 "ENLIGHTENMENT_DESKTOP");
2637 win = GDK_WINDOW_XID (window);
2639 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2640 &child, (unsigned int *)&num_children))
2642 if ((child) && (num_children > 0))
2654 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2655 False, XA_CARDINAL, &type_return, &format_return,
2656 &number_return, &bytes_after_return, &data_return);
2658 if (type_return == XA_CARDINAL)
2660 XFree (data_return);
2665 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2666 GDK_WINDOW_XID (window),
2681 * gdk_window_get_root_origin:
2682 * @window: a toplevel #GdkWindow
2683 * @x: return location for X position of window frame
2684 * @y: return location for Y position of window frame
2686 * Obtains the top-left corner of the window manager frame in root
2687 * window coordinates.
2691 gdk_window_get_root_origin (GdkWindow *window,
2697 g_return_if_fail (GDK_IS_WINDOW (window));
2699 gdk_window_get_frame_extents (window, &rect);
2709 * gdk_window_get_frame_extents:
2710 * @window: a toplevel #GdkWindow
2711 * @rect: rectangle to fill with bounding box of the window frame
2713 * Obtains the bounding box of the window, including window manager
2714 * titlebar/borders if any. The frame position is given in root window
2715 * coordinates. To get the position of the window itself (rather than
2716 * the frame) in root window coordinates, use gdk_window_get_origin().
2720 gdk_window_get_frame_extents (GdkWindow *window,
2723 GdkWindowObject *private;
2728 unsigned int nchildren;
2730 g_return_if_fail (GDK_IS_WINDOW (window));
2731 g_return_if_fail (rect != NULL);
2733 private = (GdkWindowObject*) window;
2740 if (GDK_WINDOW_DESTROYED (window))
2743 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2744 private = (GdkWindowObject*) private->parent;
2746 /* Refine our fallback answer a bit using local information */
2747 rect->x = private->x;
2748 rect->y = private->y;
2749 gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height);
2751 if (GDK_WINDOW_DESTROYED (private))
2754 gdk_error_trap_push();
2756 xparent = GDK_WINDOW_XID (window);
2760 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2762 &children, &nchildren))
2768 while (xparent != root);
2770 if (xparent == root)
2772 unsigned int ww, wh, wb, wd;
2775 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2785 gdk_error_trap_pop ();
2789 _gdk_windowing_get_pointer (GdkDisplay *display,
2793 GdkModifierType *mask)
2795 GdkScreen *default_screen;
2803 if (display->closed)
2806 default_screen = gdk_display_get_default_screen (display);
2808 XQueryPointer (GDK_SCREEN_XDISPLAY (default_screen),
2809 GDK_SCREEN_XROOTWIN (default_screen),
2810 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2814 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
2815 *screen = gdk_drawable_get_screen (gdk_root);
2824 _gdk_windowing_window_get_pointer (GdkDisplay *display,
2828 GdkModifierType *mask)
2830 GdkWindow *return_val;
2836 unsigned int xmask = 0;
2837 gint xoffset, yoffset;
2839 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2841 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2844 if (!GDK_WINDOW_DESTROYED (window) &&
2845 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2846 GDK_WINDOW_XID (window),
2847 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2850 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
2853 *x = winx + xoffset;
2854 *y = winy + yoffset;
2861 _gdk_windowing_window_at_pointer (GdkDisplay *display,
2870 Window xwindow_last = 0;
2872 int rootx = -1, rooty = -1;
2876 screen = gdk_display_get_default_screen (display);
2878 xwindow = GDK_SCREEN_XROOTWIN (screen);
2879 xdisplay = GDK_SCREEN_XDISPLAY (screen);
2881 /* This function really only works if the mouse pointer is held still
2882 * during its operation. If it moves from one leaf window to another
2883 * than we'll end up with inaccurate values for win_x, win_y
2886 gdk_x11_display_grab (display);
2887 XQueryPointer (xdisplay, xwindow,
2888 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2890 if (root == xwindow)
2897 xwindow_last = xwindow;
2898 XQueryPointer (xdisplay, xwindow,
2899 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
2901 gdk_x11_display_ungrab (display);
2903 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
2905 *win_x = window ? winx : -1;
2906 *win_y = window ? winy : -1;
2912 * gdk_window_get_events:
2913 * @window: a #GdkWindow
2915 * Gets the event mask for @window. See gdk_window_set_events().
2917 * Return value: event mask for @window
2920 gdk_window_get_events (GdkWindow *window)
2922 XWindowAttributes attrs;
2923 GdkEventMask event_mask;
2925 g_return_val_if_fail (window != NULL, 0);
2926 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2928 if (GDK_WINDOW_DESTROYED (window))
2932 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2933 GDK_WINDOW_XID (window),
2936 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2937 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2944 * gdk_window_set_events:
2945 * @window: a #GdkWindow
2946 * @event_mask: event mask for @window
2948 * The event mask for a window determines which events will be reported
2949 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2950 * means the window should report button press events. The event mask
2951 * is the bitwise OR of values from the #GdkEventMask enumeration.
2955 gdk_window_set_events (GdkWindow *window,
2956 GdkEventMask event_mask)
2961 g_return_if_fail (window != NULL);
2962 g_return_if_fail (GDK_IS_WINDOW (window));
2964 if (!GDK_WINDOW_DESTROYED (window))
2966 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2967 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2968 for (i = 0; i < _gdk_nenvent_masks; i++)
2970 if (event_mask & (1 << (i + 1)))
2971 xevent_mask |= _gdk_event_mask_table[i];
2974 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2975 GDK_WINDOW_XID (window),
2981 gdk_window_add_colormap_windows (GdkWindow *window)
2983 GdkWindow *toplevel;
2984 Window *old_windows;
2985 Window *new_windows;
2988 g_return_if_fail (window != NULL);
2989 g_return_if_fail (GDK_IS_WINDOW (window));
2991 if (GDK_WINDOW_DESTROYED (window))
2993 toplevel = gdk_window_get_toplevel (window);
2996 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2997 GDK_WINDOW_XID (toplevel),
2998 &old_windows, &count))
3003 for (i = 0; i < count; i++)
3004 if (old_windows[i] == GDK_WINDOW_XID (window))
3006 XFree (old_windows);
3010 new_windows = g_new (Window, count + 1);
3012 for (i = 0; i < count; i++)
3013 new_windows[i] = old_windows[i];
3014 new_windows[count] = GDK_WINDOW_XID (window);
3016 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3017 GDK_WINDOW_XID (toplevel),
3018 new_windows, count + 1);
3020 g_free (new_windows);
3022 XFree (old_windows);
3026 gdk_window_have_shape_ext (GdkDisplay *display)
3028 #ifdef HAVE_SHAPE_EXT
3031 return XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display),
3038 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
3041 * This needs the X11 shape extension.
3042 * If not available, shaped windows will look
3043 * ugly, but programs still work. Stefan Wille
3046 * gdk_window_shape_combine_mask:
3047 * @window: a #GdkWindow
3049 * @x: X position of shape mask with respect to @window
3050 * @y: Y position of shape mask with respect to @window
3052 * Applies a shape mask to @window. Pixels in @window corresponding to
3053 * set bits in the @mask will be visible; pixels in @window
3054 * corresponding to unset bits in the @mask will be transparent. This
3055 * gives a non-rectangular window.
3057 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
3058 * parameters are not used.
3060 * On the X11 platform, this uses an X server extension which is
3061 * widely available on most common platforms, but not available on
3062 * very old X servers, and occasionally the implementation will be
3063 * buggy. On servers without the shape extension, this function
3066 * This function works on both toplevel and child windows.
3070 gdk_window_shape_combine_mask (GdkWindow *window,
3075 gint xoffset, yoffset;
3077 g_return_if_fail (window != NULL);
3078 g_return_if_fail (GDK_IS_WINDOW (window));
3080 #ifdef HAVE_SHAPE_EXT
3081 if (GDK_WINDOW_DESTROYED (window))
3084 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3086 if (xoffset != 0 || yoffset != 0)
3088 WARN_SHAPE_TOO_BIG ();
3092 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3096 pixmap = GDK_PIXMAP_XID (mask);
3105 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3106 GDK_WINDOW_XID (window),
3112 #endif /* HAVE_SHAPE_EXT */
3116 * gdk_window_shape_combine_region:
3117 * @window: a #GdkWindow
3118 * @shape_region: region of window to be non-transparent
3119 * @offset_x: X position of @shape_region in @window coordinates
3120 * @offset_y: Y position of @shape_region in @window coordinates
3122 * Makes pixels in @window outside @shape_region be transparent,
3123 * so that the window may be nonrectangular. See also
3124 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
3126 * If @shape_region is %NULL, the shape will be unset, so the whole
3127 * window will be opaque again. @offset_x and @offset_y are ignored
3128 * if @shape_region is %NULL.
3130 * On the X11 platform, this uses an X server extension which is
3131 * widely available on most common platforms, but not available on
3132 * very old X servers, and occasionally the implementation will be
3133 * buggy. On servers without the shape extension, this function
3136 * This function works on both toplevel and child windows.
3140 gdk_window_shape_combine_region (GdkWindow *window,
3141 GdkRegion *shape_region,
3145 gint xoffset, yoffset;
3147 g_return_if_fail (GDK_IS_WINDOW (window));
3149 #ifdef HAVE_SHAPE_EXT
3150 if (GDK_WINDOW_DESTROYED (window))
3153 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3155 if (xoffset != 0 || yoffset != 0)
3157 WARN_SHAPE_TOO_BIG ();
3161 if (shape_region == NULL)
3163 /* Use NULL mask to unset the shape */
3164 gdk_window_shape_combine_mask (window, NULL, 0, 0);
3168 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3171 XRectangle *xrects = NULL;
3173 _gdk_region_get_xrectangles (shape_region,
3177 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3178 GDK_WINDOW_XID (window),
3187 #endif /* HAVE_SHAPE_EXT */
3192 * gdk_window_set_override_redirect:
3193 * @window: a toplevel #GdkWindow
3194 * @override_redirect: %TRUE if window should be override redirect
3196 * An override redirect window is not under the control of the window manager.
3197 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3198 * be entirely under the control of the application. The window manager
3199 * can't see the override redirect window at all.
3201 * Override redirect should only be used for short-lived temporary
3202 * windows, such as popup menus. #GtkMenu uses an override redirect
3203 * window in its implementation, for example.
3207 gdk_window_set_override_redirect (GdkWindow *window,
3208 gboolean override_redirect)
3210 XSetWindowAttributes attr;
3212 g_return_if_fail (window != NULL);
3213 g_return_if_fail (GDK_IS_WINDOW (window));
3215 if (!GDK_WINDOW_DESTROYED (window))
3217 attr.override_redirect = (override_redirect == FALSE)?False:True;
3218 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3219 GDK_WINDOW_XID (window),
3227 * gdk_window_set_icon_list:
3228 * @window: The #GdkWindow toplevel window to set the icon of.
3229 * @pixbufs: A list of pixbufs, of different sizes.
3231 * Sets a list of icons for the window. One of these will be used
3232 * to represent the window when it has been iconified. The icon is
3233 * usually shown in an icon box or some sort of task bar. Which icon
3234 * size is shown depends on the window manager. The window manager
3235 * can scale the icon but setting several size icons can give better
3236 * image quality since the window manager may only need to scale the
3237 * icon by a small amount or not at all.
3241 gdk_window_set_icon_list (GdkWindow *window,
3250 gint width, height, stride;
3253 GdkDisplay *display;
3255 g_return_if_fail (GDK_IS_WINDOW (window));
3257 if (GDK_WINDOW_DESTROYED (window))
3260 display = gdk_drawable_get_display (window);
3268 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3270 width = gdk_pixbuf_get_width (pixbuf);
3271 height = gdk_pixbuf_get_height (pixbuf);
3273 size += 2 + width * height;
3275 l = g_list_next (l);
3278 data = g_malloc (size * sizeof (gulong));
3286 width = gdk_pixbuf_get_width (pixbuf);
3287 height = gdk_pixbuf_get_height (pixbuf);
3288 stride = gdk_pixbuf_get_rowstride (pixbuf);
3289 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3294 pixels = gdk_pixbuf_get_pixels (pixbuf);
3296 for (y = 0; y < height; y++)
3298 for (x = 0; x < width; x++)
3302 r = pixels[y*stride + x*n_channels + 0];
3303 g = pixels[y*stride + x*n_channels + 1];
3304 b = pixels[y*stride + x*n_channels + 2];
3305 if (n_channels >= 4)
3306 a = pixels[y*stride + x*n_channels + 3];
3310 *p++ = a << 24 | r << 16 | g << 8 | b ;
3314 l = g_list_next (l);
3319 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3320 GDK_WINDOW_XID (window),
3321 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3324 (guchar*) data, size);
3328 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3329 GDK_WINDOW_XID (window),
3330 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3337 * gdk_window_set_icon:
3338 * @window: a toplevel #GdkWindow
3339 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3340 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3341 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3343 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3344 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3345 * and gtk_window_set_icon(). If those don't meet your needs, look at
3346 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3347 * want to fall back to gdk_window_set_icon().
3351 gdk_window_set_icon (GdkWindow *window,
3352 GdkWindow *icon_window,
3356 GdkToplevelX11 *toplevel;
3358 g_return_if_fail (window != NULL);
3359 g_return_if_fail (GDK_IS_WINDOW (window));
3360 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3362 if (GDK_WINDOW_DESTROYED (window))
3365 toplevel = _gdk_x11_window_get_toplevel (window);
3367 if (toplevel->icon_window != icon_window)
3369 if (toplevel->icon_window)
3370 g_object_unref (toplevel->icon_window);
3371 toplevel->icon_window = g_object_ref (icon_window);
3374 if (toplevel->icon_pixmap != pixmap)
3376 if (toplevel->icon_pixmap)
3377 g_object_unref (toplevel->icon_pixmap);
3378 toplevel->icon_pixmap = g_object_ref (pixmap);
3381 if (toplevel->icon_mask != mask)
3383 if (toplevel->icon_mask)
3384 g_object_unref (toplevel->icon_mask);
3385 toplevel->icon_mask = g_object_ref (mask);
3388 update_wm_hints (window, FALSE);
3392 gdk_window_icon_name_set (GdkWindow *window)
3394 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3395 g_quark_from_static_string ("gdk-icon-name-set")));
3399 * gdk_window_set_icon_name:
3400 * @window: a toplevel #GdkWindow
3401 * @name: name of window while iconified (minimized)
3403 * Windows may have a name used while minimized, distinct from the
3404 * name they display in their titlebar. Most of the time this is a bad
3405 * idea from a user interface standpoint. But you can set such a name
3406 * with this function, if you like.
3410 gdk_window_set_icon_name (GdkWindow *window,
3413 GdkDisplay *display;
3415 g_return_if_fail (window != NULL);
3416 g_return_if_fail (GDK_IS_WINDOW (window));
3418 if (GDK_WINDOW_DESTROYED (window))
3421 display = gdk_drawable_get_display (window);
3423 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3424 GUINT_TO_POINTER (TRUE));
3426 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3427 GDK_WINDOW_XID (window),
3428 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3429 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3430 PropModeReplace, name, strlen (name));
3432 set_text_property (display, GDK_WINDOW_XID (window),
3433 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3438 * gdk_window_iconify:
3439 * @window: a toplevel #GdkWindow
3441 * Asks to iconify (minimize) @window. The window manager may choose
3442 * to ignore the request, but normally will honor it. Using
3443 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3445 * This function only makes sense when @window is a toplevel window.
3449 gdk_window_iconify (GdkWindow *window)
3451 GdkWindowObject *private;
3453 g_return_if_fail (window != NULL);
3454 g_return_if_fail (GDK_IS_WINDOW (window));
3456 if (GDK_WINDOW_DESTROYED (window))
3459 private = (GdkWindowObject*) window;
3461 if (GDK_WINDOW_IS_MAPPED (window))
3463 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3464 GDK_WINDOW_XWINDOW (window),
3465 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3469 /* Flip our client side flag, the real work happens on map. */
3470 gdk_synthesize_window_state (window,
3472 GDK_WINDOW_STATE_ICONIFIED);
3477 * gdk_window_deiconify:
3478 * @window: a toplevel #GdkWindow
3480 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3481 * choose to ignore the request to deiconify. When using GTK+,
3482 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3483 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3484 * unminimizes it, and puts it on the current desktop.
3488 gdk_window_deiconify (GdkWindow *window)
3490 GdkWindowObject *private;
3492 g_return_if_fail (window != NULL);
3493 g_return_if_fail (GDK_IS_WINDOW (window));
3495 if (GDK_WINDOW_DESTROYED (window))
3498 private = (GdkWindowObject*) window;
3500 if (GDK_WINDOW_IS_MAPPED (window))
3502 gdk_window_show (window);
3506 /* Flip our client side flag, the real work happens on map. */
3507 gdk_synthesize_window_state (window,
3508 GDK_WINDOW_STATE_ICONIFIED,
3515 * @window: a toplevel #GdkWindow
3517 * "Pins" a window such that it's on all workspaces and does not scroll
3518 * with viewports, for window managers that have scrollable viewports.
3519 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3521 * On the X11 platform, this function depends on window manager
3522 * support, so may have no effect with many window managers. However,
3523 * GDK will do the best it can to convince the window manager to stick
3524 * the window. For window managers that don't support this operation,
3525 * there's nothing you can do to force it to happen.
3529 gdk_window_stick (GdkWindow *window)
3531 g_return_if_fail (GDK_IS_WINDOW (window));
3533 if (GDK_WINDOW_DESTROYED (window))
3536 if (GDK_WINDOW_IS_MAPPED (window))
3538 /* "stick" means stick to all desktops _and_ do not scroll with the
3539 * viewport. i.e. glue to the monitor glass in all cases.
3544 /* Request stick during viewport scroll */
3545 gdk_wmspec_change_state (TRUE, window,
3546 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3549 /* Request desktop 0xFFFFFFFF */
3550 xev.xclient.type = ClientMessage;
3551 xev.xclient.serial = 0;
3552 xev.xclient.send_event = True;
3553 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3554 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3555 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3557 xev.xclient.format = 32;
3559 xev.xclient.data.l[0] = 0xFFFFFFFF;
3560 xev.xclient.data.l[1] = 0;
3561 xev.xclient.data.l[2] = 0;
3562 xev.xclient.data.l[3] = 0;
3563 xev.xclient.data.l[4] = 0;
3565 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3566 SubstructureRedirectMask | SubstructureNotifyMask,
3571 /* Flip our client side flag, the real work happens on map. */
3572 gdk_synthesize_window_state (window,
3574 GDK_WINDOW_STATE_STICKY);
3579 * gdk_window_unstick:
3580 * @window: a toplevel #GdkWindow
3582 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3583 * and gtk_window_unstick().
3587 gdk_window_unstick (GdkWindow *window)
3589 g_return_if_fail (GDK_IS_WINDOW (window));
3591 if (GDK_WINDOW_DESTROYED (window))
3594 if (GDK_WINDOW_IS_MAPPED (window))
3601 gulong *current_desktop;
3602 GdkDisplay *display = gdk_drawable_get_display (window);
3604 /* Request unstick from viewport */
3605 gdk_wmspec_change_state (FALSE, window,
3606 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3609 /* Get current desktop, then set it; this is a race, but not
3610 * one that matters much in practice.
3612 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
3613 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
3615 False, XA_CARDINAL, &type, &format, &nitems,
3616 &bytes_after, (guchar **)¤t_desktop);
3618 if (type == XA_CARDINAL)
3620 xev.xclient.type = ClientMessage;
3621 xev.xclient.serial = 0;
3622 xev.xclient.send_event = True;
3623 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3624 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
3625 xev.xclient.format = 32;
3627 xev.xclient.data.l[0] = *current_desktop;
3628 xev.xclient.data.l[1] = 0;
3629 xev.xclient.data.l[2] = 0;
3630 xev.xclient.data.l[3] = 0;
3631 xev.xclient.data.l[4] = 0;
3633 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3634 SubstructureRedirectMask | SubstructureNotifyMask,
3637 XFree (current_desktop);
3642 /* Flip our client side flag, the real work happens on map. */
3643 gdk_synthesize_window_state (window,
3644 GDK_WINDOW_STATE_STICKY,
3651 * gdk_window_maximize:
3652 * @window: a toplevel #GdkWindow
3654 * Maximizes the window. If the window was already maximized, then
3655 * this function does nothing.
3657 * On X11, asks the window manager to maximize @window, if the window
3658 * manager supports this operation. Not all window managers support
3659 * this, and some deliberately ignore it or don't have a concept of
3660 * "maximized"; so you can't rely on the maximization actually
3661 * happening. But it will happen with most standard window managers,
3662 * and GDK makes a best effort to get it to happen.
3664 * On Windows, reliably maximizes the window.
3668 gdk_window_maximize (GdkWindow *window)
3670 g_return_if_fail (GDK_IS_WINDOW (window));
3672 if (GDK_WINDOW_DESTROYED (window))
3675 if (GDK_WINDOW_IS_MAPPED (window))
3676 gdk_wmspec_change_state (TRUE, window,
3677 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3678 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3680 gdk_synthesize_window_state (window,
3682 GDK_WINDOW_STATE_MAXIMIZED);
3686 * gdk_window_unmaximize:
3687 * @window: a toplevel #GdkWindow
3689 * Unmaximizes the window. If the window wasn't maximized, then this
3690 * function does nothing.
3692 * On X11, asks the window manager to unmaximize @window, if the
3693 * window manager supports this operation. Not all window managers
3694 * support this, and some deliberately ignore it or don't have a
3695 * concept of "maximized"; so you can't rely on the unmaximization
3696 * actually happening. But it will happen with most standard window
3697 * managers, and GDK makes a best effort to get it to happen.
3699 * On Windows, reliably unmaximizes the window.
3703 gdk_window_unmaximize (GdkWindow *window)
3705 g_return_if_fail (GDK_IS_WINDOW (window));
3707 if (GDK_WINDOW_DESTROYED (window))
3710 if (GDK_WINDOW_IS_MAPPED (window))
3711 gdk_wmspec_change_state (FALSE, window,
3712 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3713 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3715 gdk_synthesize_window_state (window,
3716 GDK_WINDOW_STATE_MAXIMIZED,
3721 * gdk_window_fullscreen:
3722 * @window: a toplevel #GdkWindow
3724 * Moves the window into fullscreen mode. This means the
3725 * window covers the entire screen and is above any panels
3728 * If the window was already fullscreen, then this function does nothing.
3730 * On X11, asks the window manager to put @window in a fullscreen
3731 * state, if the window manager supports this operation. Not all
3732 * window managers support this, and some deliberately ignore it or
3733 * don't have a concept of "fullscreen"; so you can't rely on the
3734 * fullscreenification actually happening. But it will happen with
3735 * most standard window managers, and GDK makes a best effort to get
3741 gdk_window_fullscreen (GdkWindow *window)
3743 g_return_if_fail (GDK_IS_WINDOW (window));
3745 if (GDK_WINDOW_DESTROYED (window))
3748 if (GDK_WINDOW_IS_MAPPED (window))
3749 gdk_wmspec_change_state (TRUE, window,
3750 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3754 gdk_synthesize_window_state (window,
3756 GDK_WINDOW_STATE_FULLSCREEN);
3760 * gdk_window_unfullscreen:
3761 * @window: a toplevel #GdkWindow
3763 * Moves the window out of fullscreen mode. If the window was not
3764 * fullscreen, does nothing.
3766 * On X11, asks the window manager to move @window out of the fullscreen
3767 * state, if the window manager supports this operation. Not all
3768 * window managers support this, and some deliberately ignore it or
3769 * don't have a concept of "fullscreen"; so you can't rely on the
3770 * unfullscreenification actually happening. But it will happen with
3771 * most standard window managers, and GDK makes a best effort to get
3777 gdk_window_unfullscreen (GdkWindow *window)
3779 g_return_if_fail (GDK_IS_WINDOW (window));
3781 if (GDK_WINDOW_DESTROYED (window))
3784 if (GDK_WINDOW_IS_MAPPED (window))
3785 gdk_wmspec_change_state (FALSE, window,
3786 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3790 gdk_synthesize_window_state (window,
3791 GDK_WINDOW_STATE_FULLSCREEN,
3797 * gdk_window_set_group:
3798 * @window: a toplevel #GdkWindow
3799 * @leader: group leader window
3801 * Sets the group leader window for @window. By default,
3802 * GDK sets the group leader for all toplevel windows
3803 * to a global window implicitly created by GDK. With this function
3804 * you can override this default.
3806 * The group leader window allows the window manager to distinguish
3807 * all windows that belong to a single application. It may for example
3808 * allow users to minimize/unminimize all windows belonging to an
3809 * application at once. You should only set a non-default group window
3810 * if your application pretends to be multiple applications.
3813 gdk_window_set_group (GdkWindow *window,
3816 GdkToplevelX11 *toplevel;
3818 g_return_if_fail (window != NULL);
3819 g_return_if_fail (GDK_IS_WINDOW (window));
3820 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3821 g_return_if_fail (leader != NULL);
3822 g_return_if_fail (GDK_IS_WINDOW (leader));
3824 toplevel = _gdk_x11_window_get_toplevel (window);
3826 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3829 if (toplevel->group_leader != leader)
3831 if (toplevel->group_leader)
3832 g_object_unref (toplevel->group_leader);
3833 toplevel->group_leader = g_object_ref (toplevel->group_leader);
3836 update_wm_hints (window, FALSE);
3839 static MotifWmHints *
3840 gdk_window_get_mwm_hints (GdkWindow *window)
3842 GdkDisplay *display;
3843 Atom hints_atom = None;
3844 MotifWmHints *hints;
3850 if (GDK_WINDOW_DESTROYED (window))
3853 display = gdk_drawable_get_display (window);
3855 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3857 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3858 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3859 False, AnyPropertyType, &type, &format, &nitems,
3860 &bytes_after, (guchar **)&hints);
3869 gdk_window_set_mwm_hints (GdkWindow *window,
3870 MotifWmHints *new_hints)
3872 GdkDisplay *display;
3873 Atom hints_atom = None;
3874 MotifWmHints *hints;
3880 if (GDK_WINDOW_DESTROYED (window))
3883 display = gdk_drawable_get_display (window);
3885 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3887 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3888 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3889 False, AnyPropertyType, &type, &format, &nitems,
3890 &bytes_after, (guchar **)&hints);
3896 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3898 hints->flags |= MWM_HINTS_FUNCTIONS;
3899 hints->functions = new_hints->functions;
3901 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3903 hints->flags |= MWM_HINTS_DECORATIONS;
3904 hints->decorations = new_hints->decorations;
3908 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3909 hints_atom, hints_atom, 32, PropModeReplace,
3910 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3912 if (hints != new_hints)
3917 * gdk_window_set_decorations:
3918 * @window: a toplevel #GdkWindow
3919 * @decorations: decoration hint mask
3921 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3922 * This function sets the traditional Motif window manager hints that tell the
3923 * window manager which decorations you would like your window to have.
3924 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3925 * using the GDK function directly.
3927 * The @decorations argument is the logical OR of the fields in
3928 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3929 * mask, the other bits indicate which decorations should be turned off.
3930 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3931 * which decorations should be turned on.
3933 * Most window managers honor a decorations hint of 0 to disable all decorations,
3934 * but very few honor all possible combinations of bits.
3938 gdk_window_set_decorations (GdkWindow *window,
3939 GdkWMDecoration decorations)
3943 g_return_if_fail (window != NULL);
3944 g_return_if_fail (GDK_IS_WINDOW (window));
3946 hints.flags = MWM_HINTS_DECORATIONS;
3947 hints.decorations = decorations;
3949 gdk_window_set_mwm_hints (window, &hints);
3953 * gdk_window_get_decorations:
3954 * @window: The toplevel #GdkWindow to get the decorations from
3955 * @decorations: The window decorations will be written here
3957 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3958 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3961 gdk_window_get_decorations(GdkWindow *window,
3962 GdkWMDecoration *decorations)
3964 MotifWmHints *hints;
3965 gboolean result = FALSE;
3967 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3969 hints = gdk_window_get_mwm_hints (window);
3973 if (hints->flags & MWM_HINTS_DECORATIONS)
3976 *decorations = hints->decorations;
3987 * gdk_window_set_functions:
3988 * @window: a toplevel #GdkWindow
3989 * @functions: bitmask of operations to allow on @window
3991 * This function isn't really good for much. It sets the traditional
3992 * Motif window manager hint for which operations the window manager
3993 * should allow on a toplevel window. However, few window managers do
3994 * anything reliable or interesting with this hint. Many ignore it
3997 * The @functions argument is the logical OR of values from the
3998 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3999 * then the other bits indicate which functions to disable; if
4000 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4005 gdk_window_set_functions (GdkWindow *window,
4006 GdkWMFunction functions)
4010 g_return_if_fail (window != NULL);
4011 g_return_if_fail (GDK_IS_WINDOW (window));
4013 hints.flags = MWM_HINTS_FUNCTIONS;
4014 hints.functions = functions;
4016 gdk_window_set_mwm_hints (window, &hints);
4019 #ifdef HAVE_SHAPE_EXT
4022 * propagate the shapes from all child windows of a GDK window to the parent
4023 * window. Shamelessly ripped from Enlightenment's code
4031 struct _gdk_span *next;
4035 gdk_add_to_span (struct _gdk_span **s,
4039 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
4046 /* scan the spans for this line */
4049 /* -- -> new span */
4050 /* == -> existing span */
4051 /* ## -> spans intersect */
4052 /* if we are in the middle of spanning the span into the line */
4055 /* case: ---- ==== */
4056 if (xx < ptr1->start - 1)
4058 /* ends before next span - extend to here */
4062 /* case: ----##=== */
4063 else if (xx <= ptr1->end)
4065 /* crosses into next span - delete next span and append */
4066 ss->end = ptr1->end;
4067 ss->next = ptr1->next;
4071 /* case: ---###--- */
4074 /* overlaps next span - delete and keep checking */
4075 ss->next = ptr1->next;
4080 /* otherwise havent started spanning it in yet */
4083 /* case: ---- ==== */
4084 if (xx < ptr1->start - 1)
4086 /* insert span here in list */
4087 noo = g_malloc (sizeof (struct _gdk_span));
4101 /* case: ----##=== */
4102 else if ((x < ptr1->start) && (xx <= ptr1->end))
4104 /* expand this span to the left point of the new one */
4108 /* case: ===###=== */
4109 else if ((x >= ptr1->start) && (xx <= ptr1->end))
4111 /* throw the span away */
4114 /* case: ---###--- */
4115 else if ((x < ptr1->start) && (xx > ptr1->end))
4122 /* case: ===##---- */
4123 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
4129 /* case: ==== ---- */
4130 /* case handled by next loop iteration - first case */
4135 /* it started in the middle but spans beyond your current list */
4141 /* it does not start inside a span or in the middle, so add it to the end */
4142 noo = g_malloc (sizeof (struct _gdk_span));
4150 noo->next = ptr2->next;
4163 gdk_add_rectangles (Display *disp,
4165 struct _gdk_span **spans,
4172 gint x1, y1, x2, y2;
4176 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
4179 /* go through all clip rects in this window's shape */
4180 for (k = 0; k < rn; k++)
4182 /* for each clip rect, add it to each line's spans */
4184 x2 = x + rl[k].x + (rl[k].width - 1);
4186 y2 = y + rl[k].y + (rl[k].height - 1);
4195 for (a = y1; a <= y2; a++)
4198 gdk_add_to_span (&spans[a], x1, x2);
4206 gdk_propagate_shapes (Display *disp,
4210 Window rt, par, *list = NULL;
4211 gint i, j, num = 0, num_rects = 0;
4215 XRectangle *rects = NULL;
4216 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
4217 XWindowAttributes xatt;
4219 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
4224 spans = g_malloc (sizeof (struct _gdk_span *) * h);
4226 for (i = 0; i < h; i++)
4228 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
4231 /* go through all child windows and create/insert spans */
4232 for (i = 0; i < num; i++)
4234 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
4235 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
4236 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
4239 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
4241 /* go through the spans list and build a list of rects */
4242 rects = g_malloc (sizeof (XRectangle) * 256);
4244 for (i = 0; i < baseh; i++)
4247 /* go through the line for all spans */
4250 rects[num_rects].x = ptr1->start;
4251 rects[num_rects].y = i;
4252 rects[num_rects].width = ptr1->end - ptr1->start + 1;
4253 rects[num_rects].height = 1;
4255 /* if there are more lines */
4257 /* while contigous rects (same start/end coords) exist */
4258 while ((contig) && (j < baseh))
4260 /* search next line for spans matching this one */
4266 /* if we have an exact span match set contig */
4267 if ((ptr2->start == ptr1->start) &&
4268 (ptr2->end == ptr1->end))
4271 /* remove the span - not needed */
4274 ptr3->next = ptr2->next;
4280 spans[j] = ptr2->next;
4286 /* gone past the span point no point looking */
4287 else if (ptr2->start < ptr1->start)
4295 /* if a contiguous span was found increase the rect h */
4298 rects[num_rects].height++;
4302 /* up the rect count */
4304 /* every 256 new rects increase the rect array */
4305 if ((num_rects % 256) == 0)
4306 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
4310 /* set the rects as the shape mask */
4313 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
4314 ShapeSet, YXSorted);
4319 /* free up all the spans we made */
4320 for (i = 0; i < baseh; i++)
4333 #endif /* HAVE_SHAPE_EXT */
4336 * gdk_window_set_child_shapes:
4337 * @window: a #GdkWindow
4339 * Sets the shape mask of @window to the union of shape masks
4340 * for all children of @window, ignoring the shape mask of @window
4341 * itself. Contrast with gdk_window_merge_child_shapes() which includes
4342 * the shape mask of @window in the masks to be merged.
4345 gdk_window_set_child_shapes (GdkWindow *window)
4347 g_return_if_fail (window != NULL);
4348 g_return_if_fail (GDK_IS_WINDOW (window));
4350 #ifdef HAVE_SHAPE_EXT
4351 if (!GDK_WINDOW_DESTROYED (window) &&
4352 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4353 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4354 GDK_WINDOW_XID (window), FALSE);
4359 * gdk_window_merge_child_shapes:
4360 * @window: a #GdkWindow
4362 * Merges the shape masks for any child windows into the
4363 * shape mask for @window. i.e. the union of all masks
4364 * for @window and its children will become the new mask
4365 * for @window. See gdk_window_shape_combine_mask().
4367 * This function is distinct from gdk_window_set_child_shapes()
4368 * because it includes @window's shape mask in the set of shapes to
4373 gdk_window_merge_child_shapes (GdkWindow *window)
4375 g_return_if_fail (window != NULL);
4376 g_return_if_fail (GDK_IS_WINDOW (window));
4378 #ifdef HAVE_SHAPE_EXT
4379 if (!GDK_WINDOW_DESTROYED (window) &&
4380 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4381 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4382 GDK_WINDOW_XID (window), TRUE);
4386 /* Support for windows that can be guffaw-scrolled
4387 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
4391 gdk_window_gravity_works (GdkWindow *window)
4393 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (window));
4395 if (display_x11->gravity_works == GDK_UNKNOWN)
4402 /* This particular server apparently has a bug so that the test
4403 * works but the actual code crashes it
4405 if ((!strcmp (XServerVendor (display_x11->xdisplay),
4406 "Sun Microsystems, Inc.")) &&
4407 (VendorRelease (display_x11->xdisplay) == 3400))
4409 display_x11->gravity_works = GDK_NO;
4413 attr.window_type = GDK_WINDOW_TEMP;
4414 attr.wclass = GDK_INPUT_OUTPUT;
4419 attr.event_mask = 0;
4421 parent = gdk_window_new (gdk_screen_get_root_window (GDK_DRAWABLE_SCREEN (window)),
4422 &attr, GDK_WA_X | GDK_WA_Y);
4424 attr.window_type = GDK_WINDOW_CHILD;
4425 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
4427 gdk_window_set_static_win_gravity (child, TRUE);
4429 gdk_window_resize (parent, 100, 110);
4431 gdk_window_move (parent, 0, -10);
4432 gdk_window_move_resize (parent, 0, 0, 100, 100);
4434 gdk_window_resize (parent, 100, 110);
4435 gdk_window_move (parent, 0, -10);
4436 gdk_window_move_resize (parent, 0, 0, 100, 100);
4438 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
4440 gdk_window_destroy (parent);
4441 gdk_window_destroy (child);
4443 display_x11->gravity_works = ((y == -20) ? GDK_YES : GDK_NO);
4446 return (display_x11->gravity_works == GDK_YES);
4450 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
4452 XSetWindowAttributes xattributes;
4453 GdkWindowObject *private;
4454 guint xattributes_mask = 0;
4456 g_return_if_fail (window != NULL);
4458 private = GDK_WINDOW_OBJECT (window);
4459 if (private->input_only)
4462 xattributes.bit_gravity = StaticGravity;
4463 xattributes_mask |= CWBitGravity;
4464 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4465 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4466 GDK_WINDOW_XID (window),
4467 CWBitGravity, &xattributes);
4471 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4473 XSetWindowAttributes xattributes;
4475 g_return_if_fail (window != NULL);
4477 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4479 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4480 GDK_WINDOW_XID (window),
4481 CWWinGravity, &xattributes);
4485 * gdk_window_set_static_gravities:
4486 * @window: a #GdkWindow
4487 * @use_static: %TRUE to turn on static gravity
4489 * Set the bit gravity of the given window to static, and flag it so
4490 * all children get static subwindow gravity. This is used if you are
4491 * implementing scary features that involve deep knowledge of the
4492 * windowing system. Don't worry about it unless you have to.
4494 * Return value: %TRUE if the server supports static gravity
4497 gdk_window_set_static_gravities (GdkWindow *window,
4498 gboolean use_static)
4500 GdkWindowObject *private = (GdkWindowObject *)window;
4503 g_return_val_if_fail (window != NULL, FALSE);
4504 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4506 if (!use_static == !private->guffaw_gravity)
4509 if (use_static && !gdk_window_gravity_works (window))
4512 private->guffaw_gravity = use_static;
4514 if (!GDK_WINDOW_DESTROYED (window))
4516 gdk_window_set_static_bit_gravity (window, use_static);
4518 tmp_list = private->children;
4521 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4523 tmp_list = tmp_list->next;
4531 wmspec_moveresize (GdkWindow *window,
4537 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4541 /* Release passive grab */
4542 gdk_display_pointer_ungrab (display, timestamp);
4544 xev.xclient.type = ClientMessage;
4545 xev.xclient.serial = 0;
4546 xev.xclient.send_event = True;
4547 xev.xclient.window = GDK_WINDOW_XID (window);
4548 xev.xclient.message_type =
4549 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4550 xev.xclient.format = 32;
4551 xev.xclient.data.l[0] = root_x;
4552 xev.xclient.data.l[1] = root_y;
4553 xev.xclient.data.l[2] = direction;
4554 xev.xclient.data.l[3] = 0;
4555 xev.xclient.data.l[4] = 0;
4557 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4558 SubstructureRedirectMask | SubstructureNotifyMask,
4562 typedef struct _MoveResizeData MoveResizeData;
4564 struct _MoveResizeData
4566 GdkDisplay *display;
4568 GdkWindow *moveresize_window;
4569 GdkWindow *moveresize_emulation_window;
4571 GdkWindowEdge resize_edge;
4572 gint moveresize_button;
4575 gint moveresize_orig_x;
4576 gint moveresize_orig_y;
4577 gint moveresize_orig_width;
4578 gint moveresize_orig_height;
4579 GdkWindowHints moveresize_geom_mask;
4580 GdkGeometry moveresize_geometry;
4581 Time moveresize_process_time;
4582 XEvent *moveresize_pending_event;
4585 /* From the WM spec */
4586 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4587 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4588 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4589 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4590 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4591 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4592 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4593 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4594 #define _NET_WM_MOVERESIZE_MOVE 8
4597 wmspec_resize_drag (GdkWindow *window,
4606 /* Let the compiler turn a switch into a table, instead
4607 * of doing the table manually, this way is easier to verify.
4611 case GDK_WINDOW_EDGE_NORTH_WEST:
4612 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4615 case GDK_WINDOW_EDGE_NORTH:
4616 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4619 case GDK_WINDOW_EDGE_NORTH_EAST:
4620 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4623 case GDK_WINDOW_EDGE_WEST:
4624 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4627 case GDK_WINDOW_EDGE_EAST:
4628 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4631 case GDK_WINDOW_EDGE_SOUTH_WEST:
4632 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4635 case GDK_WINDOW_EDGE_SOUTH:
4636 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4639 case GDK_WINDOW_EDGE_SOUTH_EAST:
4640 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4644 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4650 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4653 static MoveResizeData *
4654 get_move_resize_data (GdkDisplay *display,
4657 MoveResizeData *mv_resize;
4658 static GQuark move_resize_quark = 0;
4660 if (!move_resize_quark)
4661 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4663 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4665 if (!mv_resize && create)
4667 mv_resize = g_new0 (MoveResizeData, 1);
4668 mv_resize->display = display;
4670 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4677 update_pos (MoveResizeData *mv_resize,
4683 dx = new_root_x - mv_resize->moveresize_x;
4684 dy = new_root_y - mv_resize->moveresize_y;
4686 if (mv_resize->is_resize)
4690 x = mv_resize->moveresize_orig_x;
4691 y = mv_resize->moveresize_orig_y;
4693 w = mv_resize->moveresize_orig_width;
4694 h = mv_resize->moveresize_orig_height;
4696 switch (mv_resize->resize_edge)
4698 case GDK_WINDOW_EDGE_NORTH_WEST:
4704 case GDK_WINDOW_EDGE_NORTH:
4708 case GDK_WINDOW_EDGE_NORTH_EAST:
4713 case GDK_WINDOW_EDGE_SOUTH_WEST:
4718 case GDK_WINDOW_EDGE_SOUTH_EAST:
4722 case GDK_WINDOW_EDGE_SOUTH:
4725 case GDK_WINDOW_EDGE_EAST:
4728 case GDK_WINDOW_EDGE_WEST:
4739 if (mv_resize->moveresize_geom_mask)
4741 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4742 mv_resize->moveresize_geom_mask,
4746 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4752 x = mv_resize->moveresize_orig_x + dx;
4753 y = mv_resize->moveresize_orig_y + dy;
4755 gdk_window_move (mv_resize->moveresize_window, x, y);
4760 finish_drag (MoveResizeData *mv_resize)
4762 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4763 mv_resize->moveresize_emulation_window = NULL;
4764 mv_resize->moveresize_window = NULL;
4766 if (mv_resize->moveresize_pending_event)
4768 g_free (mv_resize->moveresize_pending_event);
4769 mv_resize->moveresize_pending_event = NULL;
4774 lookahead_motion_predicate (Display *xdisplay,
4778 gboolean *seen_release = (gboolean *)arg;
4779 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4780 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4785 switch (event->xany.type)
4788 *seen_release = TRUE;
4791 mv_resize->moveresize_process_time = event->xmotion.time;
4801 moveresize_lookahead (MoveResizeData *mv_resize,
4805 gboolean seen_release = FALSE;
4807 if (mv_resize->moveresize_process_time)
4809 if (event->xmotion.time == mv_resize->moveresize_process_time)
4811 mv_resize->moveresize_process_time = 0;
4818 XCheckIfEvent (event->xany.display, &tmp_event,
4819 lookahead_motion_predicate, (XPointer) & seen_release);
4821 return mv_resize->moveresize_process_time == 0;
4825 _gdk_moveresize_handle_event (XEvent *event)
4827 guint button_mask = 0;
4828 GdkWindowObject *window_private;
4829 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
4830 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4832 if (!mv_resize || !mv_resize->moveresize_window)
4835 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
4837 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4839 switch (event->xany.type)
4842 if (window_private->resize_count > 0)
4844 if (mv_resize->moveresize_pending_event)
4845 *mv_resize->moveresize_pending_event = *event;
4847 mv_resize->moveresize_pending_event =
4848 g_memdup (event, sizeof (XEvent));
4852 if (!moveresize_lookahead (mv_resize, event))
4855 update_pos (mv_resize,
4856 event->xmotion.x_root,
4857 event->xmotion.y_root);
4859 /* This should never be triggered in normal cases, but in the
4860 * case where the drag started without an implicit grab being
4861 * in effect, we could miss the release if it occurs before
4862 * we grab the pointer; this ensures that we will never
4863 * get a permanently stuck grab.
4865 if ((event->xmotion.state & button_mask) == 0)
4866 finish_drag (mv_resize);
4870 update_pos (mv_resize,
4871 event->xbutton.x_root,
4872 event->xbutton.y_root);
4874 if (event->xbutton.button == mv_resize->moveresize_button)
4875 finish_drag (mv_resize);
4882 _gdk_moveresize_configure_done (GdkDisplay *display,
4886 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4888 if (!mv_resize || window != mv_resize->moveresize_window)
4891 if (mv_resize->moveresize_pending_event)
4893 tmp_event = mv_resize->moveresize_pending_event;
4894 mv_resize->moveresize_pending_event = NULL;
4895 _gdk_moveresize_handle_event (tmp_event);
4903 create_moveresize_window (MoveResizeData *mv_resize,
4906 GdkWindowAttr attributes;
4907 gint attributes_mask;
4908 GdkGrabStatus status;
4910 g_assert (mv_resize->moveresize_emulation_window == NULL);
4912 attributes.x = -100;
4913 attributes.y = -100;
4914 attributes.width = 10;
4915 attributes.height = 10;
4916 attributes.window_type = GDK_WINDOW_TEMP;
4917 attributes.wclass = GDK_INPUT_ONLY;
4918 attributes.override_redirect = TRUE;
4919 attributes.event_mask = 0;
4921 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4923 mv_resize->moveresize_emulation_window =
4924 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4928 gdk_window_show (mv_resize->moveresize_emulation_window);
4930 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4932 GDK_BUTTON_RELEASE_MASK |
4933 GDK_POINTER_MOTION_MASK,
4938 if (status != GDK_GRAB_SUCCESS)
4940 /* If this fails, some other client has grabbed the window
4943 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4944 mv_resize->moveresize_emulation_window = NULL;
4947 mv_resize->moveresize_process_time = 0;
4951 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
4952 so that calling XMoveWindow with these coordinates will not move the
4954 Note that this depends on the WM to implement ICCCM-compliant reference
4958 calculate_unmoving_origin (MoveResizeData *mv_resize)
4963 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
4964 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
4966 gdk_window_get_origin (mv_resize->moveresize_window,
4967 &mv_resize->moveresize_orig_x,
4968 &mv_resize->moveresize_orig_y);
4972 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
4973 gdk_window_get_geometry (mv_resize->moveresize_window,
4974 NULL, NULL, &width, &height, NULL);
4976 switch (mv_resize->moveresize_geometry.win_gravity)
4978 case GDK_GRAVITY_NORTH_WEST:
4979 mv_resize->moveresize_orig_x = rect.x;
4980 mv_resize->moveresize_orig_y = rect.y;
4982 case GDK_GRAVITY_NORTH:
4983 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4984 mv_resize->moveresize_orig_y = rect.y;
4986 case GDK_GRAVITY_NORTH_EAST:
4987 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4988 mv_resize->moveresize_orig_y = rect.y;
4990 case GDK_GRAVITY_WEST:
4991 mv_resize->moveresize_orig_x = rect.x;
4992 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4994 case GDK_GRAVITY_CENTER:
4995 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4996 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4998 case GDK_GRAVITY_EAST:
4999 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5000 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5002 case GDK_GRAVITY_SOUTH_WEST:
5003 mv_resize->moveresize_orig_x = rect.x;
5004 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5006 case GDK_GRAVITY_SOUTH:
5007 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5008 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5010 case GDK_GRAVITY_SOUTH_EAST:
5011 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5012 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5015 mv_resize->moveresize_orig_x = rect.x;
5016 mv_resize->moveresize_orig_y = rect.y;
5023 emulate_resize_drag (GdkWindow *window,
5030 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5032 mv_resize->is_resize = TRUE;
5033 mv_resize->moveresize_button = button;
5034 mv_resize->resize_edge = edge;
5035 mv_resize->moveresize_x = root_x;
5036 mv_resize->moveresize_y = root_y;
5037 mv_resize->moveresize_window = g_object_ref (window);
5039 gdk_drawable_get_size (window,
5040 &mv_resize->moveresize_orig_width,
5041 &mv_resize->moveresize_orig_height);
5043 mv_resize->moveresize_geom_mask = 0;
5044 gdk_window_get_geometry_hints (window,
5045 &mv_resize->moveresize_geometry,
5046 &mv_resize->moveresize_geom_mask);
5048 calculate_unmoving_origin (mv_resize);
5050 create_moveresize_window (mv_resize, timestamp);
5054 emulate_move_drag (GdkWindow *window,
5060 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5062 mv_resize->is_resize = FALSE;
5063 mv_resize->moveresize_button = button;
5064 mv_resize->moveresize_x = root_x;
5065 mv_resize->moveresize_y = root_y;
5067 mv_resize->moveresize_window = g_object_ref (window);
5069 calculate_unmoving_origin (mv_resize);
5071 create_moveresize_window (mv_resize, timestamp);
5075 * gdk_window_begin_resize_drag:
5076 * @window: a toplevel #GdkWindow
5077 * @edge: the edge or corner from which the drag is started
5078 * @button: the button being used to drag
5079 * @root_x: root window X coordinate of mouse click that began the drag
5080 * @root_y: root window Y coordinate of mouse click that began the drag
5081 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5083 * Begins a window resize operation (for a toplevel window).
5084 * You might use this function to implement a "window resize grip," for
5085 * example; in fact #GtkStatusbar uses it. The function works best
5086 * with window managers that support the Extended Window Manager Hints spec
5087 * (see http://www.freedesktop.org), but has a fallback implementation
5088 * for other window managers.
5092 gdk_window_begin_resize_drag (GdkWindow *window,
5099 g_return_if_fail (GDK_IS_WINDOW (window));
5101 if (GDK_WINDOW_DESTROYED (window))
5104 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5105 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5106 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5108 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5112 * gdk_window_begin_move_drag:
5113 * @window: a toplevel #GdkWindow
5114 * @button: the button being used to drag
5115 * @root_x: root window X coordinate of mouse click that began the drag
5116 * @root_y: root window Y coordinate of mouse click that began the drag
5117 * @timestamp: timestamp of mouse click that began the drag
5119 * Begins a window move operation (for a toplevel window). You might
5120 * use this function to implement a "window move grip," for
5121 * example. The function works best with window managers that support
5122 * the Extended Window Manager Hints spec (see
5123 * http://www.freedesktop.org), but has a fallback implementation for
5124 * other window managers.
5128 gdk_window_begin_move_drag (GdkWindow *window,
5134 g_return_if_fail (GDK_IS_WINDOW (window));
5136 if (GDK_WINDOW_DESTROYED (window))
5139 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5140 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5141 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5144 emulate_move_drag (window, button, root_x, root_y, timestamp);