1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
30 #include <netinet/in.h>
35 #include "gdkwindow.h"
36 #include "gdkinputprivate.h"
37 #include "gdkdisplay-x11.h"
38 #include "gdkprivate-x11.h"
39 #include "gdkregion.h"
40 #include "gdkinternals.h"
42 #include "gdkwindow-x11.h"
50 #include <X11/extensions/shape.h>
53 const int _gdk_event_mask_table[21] =
57 PointerMotionHintMask,
74 SubstructureNotifyMask,
75 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
77 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
79 /* Forward declarations */
80 static gboolean gdk_window_gravity_works (GdkWindow *window);
81 static void gdk_window_set_static_win_gravity (GdkWindow *window,
83 static gboolean gdk_window_have_shape_ext (GdkDisplay *display);
84 static gboolean gdk_window_icon_name_set (GdkWindow *window);
85 static void gdk_window_add_colormap_windows (GdkWindow *window);
87 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
88 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
90 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
93 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
94 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
95 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
96 static void gdk_window_impl_x11_finalize (GObject *object);
98 static gpointer parent_class = NULL;
101 gdk_window_impl_x11_get_type (void)
103 static GType object_type = 0;
107 static const GTypeInfo object_info =
109 sizeof (GdkWindowImplX11Class),
110 (GBaseInitFunc) NULL,
111 (GBaseFinalizeFunc) NULL,
112 (GClassInitFunc) gdk_window_impl_x11_class_init,
113 NULL, /* class_finalize */
114 NULL, /* class_data */
115 sizeof (GdkWindowImplX11),
117 (GInstanceInitFunc) gdk_window_impl_x11_init,
120 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
129 _gdk_window_impl_get_type (void)
131 return gdk_window_impl_x11_get_type ();
135 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
142 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
144 GObjectClass *object_class = G_OBJECT_CLASS (klass);
145 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
147 parent_class = g_type_class_peek_parent (klass);
149 object_class->finalize = gdk_window_impl_x11_finalize;
151 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
152 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
153 drawable_class->get_size = gdk_window_impl_x11_get_size;
155 /* Visible and clip regions are the same */
156 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
157 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
161 gdk_window_impl_x11_finalize (GObject *object)
163 GdkWindowObject *wrapper;
164 GdkDrawableImplX11 *draw_impl;
165 GdkWindowImplX11 *window_impl;
167 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
169 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
170 window_impl = GDK_WINDOW_IMPL_X11 (object);
172 wrapper = (GdkWindowObject*) draw_impl->wrapper;
174 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
176 if (!GDK_WINDOW_DESTROYED (wrapper))
178 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), draw_impl->xid);
179 if (window_impl->focus_window)
180 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), window_impl->focus_window);
183 G_OBJECT_CLASS (parent_class)->finalize (object);
187 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
189 GdkDrawableImplX11 *drawable_impl;
190 GdkWindowImplX11 *window_impl;
192 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
194 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
195 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
197 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
198 drawable_impl->colormap == NULL)
200 XWindowAttributes window_attributes;
203 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
207 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
208 window_attributes.visual->visualid);
209 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
210 window_attributes.colormap);
213 return drawable_impl->colormap;
217 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
220 GdkWindowImplX11 *impl;
221 GdkDrawableImplX11 *draw_impl;
223 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
225 impl = GDK_WINDOW_IMPL_X11 (drawable);
226 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
228 if (GDK_WINDOW_DESTROYED (draw_impl->wrapper))
232 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
236 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
238 GDK_COLORMAP_XCOLORMAP (cmap));
240 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
242 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
248 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
252 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
255 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
257 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
261 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
263 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
264 GdkRectangle result_rect;
268 result_rect.width = impl->width;
269 result_rect.height = impl->height;
271 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
273 return gdk_region_rectangle (&result_rect);
277 _gdk_windowing_window_init (GdkScreen * screen)
279 GdkWindowObject *private;
280 GdkWindowImplX11 *impl;
281 GdkDrawableImplX11 *draw_impl;
282 GdkScreenX11 *screen_x11;
283 XWindowAttributes xattributes;
286 unsigned int border_width;
290 screen_x11 = GDK_SCREEN_X11 (screen);
292 g_assert (screen_x11->root_window == NULL);
294 screen_x11->default_colormap = gdk_screen_get_system_colormap (screen);
296 XGetGeometry (screen_x11->xdisplay, screen_x11->xroot_window,
297 &screen_x11->xroot_window, &x, &y, &width, &height, &border_width, &depth);
298 XGetWindowAttributes (screen_x11->xdisplay, screen_x11->xroot_window, &xattributes);
300 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
301 private = (GdkWindowObject *)screen_x11->root_window;
302 impl = GDK_WINDOW_IMPL_X11 (private->impl);
303 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
305 draw_impl->screen = screen;
306 draw_impl->xid = screen_x11->xroot_window;
307 draw_impl->wrapper = GDK_DRAWABLE (private);
308 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
310 private->window_type = GDK_WINDOW_ROOT;
311 private->depth = depth;
314 impl->height = height;
316 _gdk_window_init_position (GDK_WINDOW (private));
318 _gdk_xid_table_insert (screen_x11->display,
319 &screen_x11->xroot_window,
320 screen_x11->root_window);
324 set_wm_protocols (GdkWindow *window)
326 GdkDisplay *display = gdk_drawable_get_display (window);
329 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
330 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
331 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
333 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
338 * @parent: a #GdkWindow, or %NULL to create the window as a child of
339 * the default root window for the default display.
340 * @attributes: attributes of the new window
341 * @attributes_mask: mask indicating which fields in @attributes are valid
343 * Creates a new #GdkWindow using the attributes from
344 * @attributes. Seep #GdkWindowAttr and #GdkWindowAttributesType for
345 * more details. Note: to use this on displays other than the default
346 * display, @parent must be specified.
348 * Return value: the new #GdkWindow
351 gdk_window_new (GdkWindow *parent,
352 GdkWindowAttr *attributes,
353 gint attributes_mask)
356 GdkWindowObject *private;
357 GdkWindowImplX11 *impl;
358 GdkDrawableImplX11 *draw_impl;
359 GdkScreenX11 *screen_x11;
368 XSetWindowAttributes xattributes;
369 long xattributes_mask;
370 XSizeHints size_hints;
372 XClassHint *class_hint;
380 g_return_val_if_fail (attributes != NULL, NULL);
385 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
387 screen = gdk_screen_get_default ();
388 parent = gdk_screen_get_root_window (screen);
391 screen = gdk_drawable_get_screen (parent);
393 screen_x11 = GDK_SCREEN_X11 (screen);
395 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
397 if (GDK_WINDOW_DESTROYED (parent))
400 xparent = GDK_WINDOW_XID (parent);
402 window = g_object_new (GDK_TYPE_WINDOW, NULL);
403 private = (GdkWindowObject *)window;
404 impl = GDK_WINDOW_IMPL_X11 (private->impl);
405 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
406 draw_impl->wrapper = GDK_DRAWABLE (window);
408 draw_impl->screen = screen;
409 xdisplay = screen_x11->xdisplay;
411 /* Windows with a foreign parent are treated as if they are children
412 * of the root window, except for actual creation.
414 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
415 parent = gdk_screen_get_root_window (screen);
417 private->parent = (GdkWindowObject *)parent;
419 xattributes_mask = 0;
421 if (attributes_mask & GDK_WA_X)
426 if (attributes_mask & GDK_WA_Y)
433 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
434 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
436 if (attributes->wclass == GDK_INPUT_ONLY)
438 /* Backwards compatiblity - we've always ignored
439 * attributes->window_type for input-only windows
442 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
443 private->window_type = GDK_WINDOW_TEMP;
445 private->window_type = GDK_WINDOW_CHILD;
448 private->window_type = attributes->window_type;
450 _gdk_window_init_position (GDK_WINDOW (private));
451 if (impl->position_info.big)
452 private->guffaw_gravity = TRUE;
454 if (attributes_mask & GDK_WA_VISUAL)
455 visual = attributes->visual;
457 visual = gdk_screen_get_system_visual (screen);
458 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
460 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
461 for (i = 0; i < _gdk_nenvent_masks; i++)
463 if (attributes->event_mask & (1 << (i + 1)))
464 xattributes.event_mask |= _gdk_event_mask_table[i];
466 private->event_mask = attributes->event_mask;
468 if (xattributes.event_mask)
469 xattributes_mask |= CWEventMask;
471 if (attributes_mask & GDK_WA_NOREDIR)
473 xattributes.override_redirect =
474 (attributes->override_redirect == FALSE)?False:True;
475 xattributes_mask |= CWOverrideRedirect;
478 xattributes.override_redirect = False;
480 if (private->parent && private->parent->guffaw_gravity)
482 xattributes.win_gravity = StaticGravity;
483 xattributes_mask |= CWWinGravity;
487 switch (private->window_type)
489 case GDK_WINDOW_TOPLEVEL:
490 case GDK_WINDOW_DIALOG:
491 case GDK_WINDOW_TEMP:
492 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
494 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
495 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
496 xparent = GDK_SCREEN_XROOTWIN (screen);
498 case GDK_WINDOW_CHILD:
501 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
505 if (attributes->wclass == GDK_INPUT_OUTPUT)
508 depth = visual->depth;
510 private->input_only = FALSE;
511 private->depth = depth;
513 if (attributes_mask & GDK_WA_COLORMAP)
515 draw_impl->colormap = attributes->colormap;
516 g_object_ref (attributes->colormap);
520 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
522 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
523 g_object_ref (draw_impl->colormap);
527 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
531 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
532 xattributes.background_pixel = private->bg_color.pixel;
534 private->bg_pixmap = NULL;
536 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
537 xattributes_mask |= CWBorderPixel | CWBackPixel;
539 if (private->guffaw_gravity)
540 xattributes.bit_gravity = StaticGravity;
542 xattributes.bit_gravity = NorthWestGravity;
544 xattributes_mask |= CWBitGravity;
546 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
547 xattributes_mask |= CWColormap;
549 if (private->window_type == GDK_WINDOW_TEMP)
551 xattributes.save_under = True;
552 xattributes.override_redirect = True;
553 xattributes.cursor = None;
554 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
562 private->input_only = TRUE;
563 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
564 g_object_ref (draw_impl->colormap);
567 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
568 impl->position_info.x, impl->position_info.y,
569 impl->position_info.width, impl->position_info.height,
570 0, depth, class, xvisual,
571 xattributes_mask, &xattributes);
573 g_object_ref (window);
574 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
576 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
577 (attributes->cursor) :
581 private->parent->children = g_list_prepend (private->parent->children, window);
583 switch (GDK_WINDOW_TYPE (private))
585 case GDK_WINDOW_DIALOG:
586 XSetTransientForHint (xdisplay, xid, xparent);
587 case GDK_WINDOW_TOPLEVEL:
588 case GDK_WINDOW_TEMP:
589 set_wm_protocols (window);
591 case GDK_WINDOW_CHILD:
592 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
593 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
594 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
596 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
597 gdk_window_add_colormap_windows (window);
606 if (class != InputOnly)
608 /* The focus window is off the visible area, and serves to receive key
609 * press events so they don't get sent to child windows.
611 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
613 xattributes.background_pixel,
614 xattributes.background_pixel);
615 /* FIXME: probably better to actually track the requested event mask for the toplevel
617 XSelectInput (xdisplay, impl->focus_window,
618 KeyPressMask | KeyReleaseMask | FocusChangeMask);
620 XMapWindow (xdisplay, impl->focus_window);
621 _gdk_xid_table_insert (screen_x11->display, &impl->focus_window, window);
624 size_hints.flags = PSize;
625 size_hints.width = impl->width;
626 size_hints.height = impl->height;
628 wm_hints.flags = StateHint | WindowGroupHint;
629 wm_hints.window_group = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
630 wm_hints.input = True;
631 wm_hints.initial_state = NormalState;
633 /* FIXME: Is there any point in doing this? Do any WM's pay
634 * attention to PSize, and even if they do, is this the
637 XSetWMNormalHints (xdisplay, xid, &size_hints);
639 XSetWMHints (xdisplay, xid, &wm_hints);
641 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
642 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
645 XChangeProperty (xdisplay, xid,
646 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
651 XChangeProperty (xdisplay, xid,
652 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
653 XA_WINDOW, 32, PropModeReplace,
654 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
656 if (attributes_mask & GDK_WA_TITLE)
657 title = attributes->title;
659 title = g_get_prgname ();
661 gdk_window_set_title (window, title);
663 if (attributes_mask & GDK_WA_WMCLASS)
665 class_hint = XAllocClassHint ();
666 class_hint->res_name = attributes->wmclass_name;
667 class_hint->res_class = attributes->wmclass_class;
668 XSetClassHint (xdisplay, xid, class_hint);
676 x_event_mask_to_gdk_event_mask (long mask)
678 GdkEventMask event_mask = 0;
681 for (i = 0; i < _gdk_nenvent_masks; i++)
683 if (mask & _gdk_event_mask_table[i])
684 event_mask |= 1 << (i + 1);
691 * gdk_window_foreign_new_for_display:
692 * @display: the #GdkDisplay where the window handle comes from.
693 * @anid: a native window handle.
695 * Wraps a native window in a #GdkWindow.
696 * This may fail if the window has been destroyed.
698 * For example in the X backend, a native window handle is an Xlib
701 * Return value: the newly-created #GdkWindow wrapper for the
702 * native window or %NULL if the window has been destroyed.
705 gdk_window_foreign_new_for_display (GdkDisplay *display,
706 GdkNativeWindow anid)
709 GdkWindowObject *private;
710 GdkWindowImplX11 *impl;
711 GdkDrawableImplX11 *draw_impl;
712 GdkDisplayX11 *display_x11;
713 XWindowAttributes attrs;
715 Window *children = NULL;
719 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
721 display_x11 = GDK_DISPLAY_X11 (display);
723 gdk_error_trap_push ();
724 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
725 if (gdk_error_trap_pop () || !result)
728 /* FIXME: This is pretty expensive. Maybe the caller should supply
730 gdk_error_trap_push ();
731 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
732 if (gdk_error_trap_pop () || !result)
738 window = g_object_new (GDK_TYPE_WINDOW, NULL);
739 private = (GdkWindowObject *)window;
740 impl = GDK_WINDOW_IMPL_X11 (private->impl);
741 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
742 draw_impl->wrapper = GDK_DRAWABLE (window);
743 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
745 private->parent = gdk_xid_table_lookup_for_display (display, parent);
747 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
748 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
750 private->parent->children = g_list_prepend (private->parent->children, window);
752 draw_impl->xid = anid;
754 private->x = attrs.x;
755 private->y = attrs.y;
756 impl->width = attrs.width;
757 impl->height = attrs.height;
758 private->window_type = GDK_WINDOW_FOREIGN;
759 private->destroyed = FALSE;
761 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
763 if (attrs.map_state == IsUnmapped)
764 private->state = GDK_WINDOW_STATE_WITHDRAWN;
768 private->depth = attrs.depth;
770 _gdk_window_init_position (GDK_WINDOW (private));
772 g_object_ref (window);
773 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
778 * gdk_window_lookup_for_display:
779 * @display: the #GdkDisplay corresponding to the window handle
780 * @anid: a native window handle.
782 * Looks up the #GdkWindow that wraps the given native window handle.
784 * For example in the X backend, a native window handle is an Xlib
787 * Return value: the #GdkWindow wrapper for the native window,
788 * or %NULL if there is none.
791 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
793 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
798 * @anid: a native window handle.
800 * Looks up the #GdkWindow that wraps the given native window handle.
802 * For example in the X backend, a native window handle is an Xlib
805 * Return value: the #GdkWindow wrapper for the native window,
806 * or %NULL if there is none.
809 gdk_window_lookup (GdkNativeWindow anid)
811 return (GdkWindow*) gdk_xid_table_lookup (anid);
815 _gdk_windowing_window_destroy (GdkWindow *window,
817 gboolean foreign_destroy)
819 GdkWindowObject *private = (GdkWindowObject *)window;
821 g_return_if_fail (GDK_IS_WINDOW (window));
823 _gdk_selection_window_destroyed (window);
825 if (private->extension_events != 0)
826 _gdk_input_window_destroy (window);
830 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
833 if (draw_impl->xft_draw)
834 XftDrawDestroy (draw_impl->xft_draw);
835 #else /* !HAVE_XFT2 */
836 if (draw_impl->picture)
837 XRenderFreePicture (GDK_DRAWABLE_XDISPLAY (window), draw_impl->picture);
838 #endif /* HAVE_XFT2 */
840 #endif /* HAVE_XFT */
842 if (private->window_type == GDK_WINDOW_FOREIGN)
844 if (!foreign_destroy && (private->parent != NULL))
846 /* It's somebody else's window, but in our heirarchy,
847 * so reparent it to the root window, and then send
848 * it a delete event, as if we were a WM
850 XClientMessageEvent xevent;
852 gdk_error_trap_push ();
853 gdk_window_hide (window);
854 gdk_window_reparent (window, NULL, 0, 0);
856 xevent.type = ClientMessage;
857 xevent.window = GDK_WINDOW_XID (window);
858 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
861 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
863 xevent.data.l[1] = CurrentTime;
865 XSendEvent (GDK_WINDOW_XDISPLAY (window),
866 GDK_WINDOW_XID (window),
867 False, 0, (XEvent *)&xevent);
868 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
869 gdk_error_trap_pop ();
872 else if (!recursing && !foreign_destroy)
874 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
878 /* This function is called when the XWindow is really gone.
881 gdk_window_destroy_notify (GdkWindow *window)
883 GdkWindowImplX11 *window_impl;
885 g_return_if_fail (window != NULL);
887 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
889 if (!GDK_WINDOW_DESTROYED (window))
891 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
892 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
894 _gdk_window_destroy (window, TRUE);
897 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
898 if (window_impl->focus_window)
899 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->focus_window);
901 _gdk_xgrab_check_destroy (window);
903 g_object_unref (window);
907 set_initial_hints (GdkWindow *window)
909 GdkWindowObject *private;
913 private = (GdkWindowObject*) window;
915 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
919 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
920 GDK_WINDOW_XID (window));
922 wm_hints = XAllocWMHints ();
924 wm_hints->flags |= StateHint;
925 wm_hints->initial_state = IconicState;
927 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
928 GDK_WINDOW_XID (window), wm_hints);
932 /* We set the spec hints regardless of whether the spec is supported,
933 * since it can't hurt and it's kind of expensive to check whether
939 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
941 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
942 "_NET_WM_STATE_MAXIMIZED_VERT");
944 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
945 "_NET_WM_STATE_MAXIMIZED_HORZ");
949 if (private->state & GDK_WINDOW_STATE_STICKY)
951 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
952 "_NET_WM_STATE_STICKY");
956 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
958 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
959 "_NET_WM_STATE_FULLSCREEN");
963 if (private->modal_hint)
965 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
966 "_NET_WM_STATE_MODAL");
972 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
973 GDK_WINDOW_XID (window),
974 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_STATE"),
975 XA_ATOM, 32, PropModeReplace,
979 if (private->state & GDK_WINDOW_STATE_STICKY)
981 atoms[0] = 0xFFFFFFFF;
982 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
983 GDK_WINDOW_XID (window),
984 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_DESKTOP"),
985 XA_CARDINAL, 32, PropModeReplace,
991 show_window_internal (GdkWindow *window,
994 GdkWindowObject *private;
996 g_return_if_fail (GDK_IS_WINDOW (window));
998 private = (GdkWindowObject*) window;
999 if (!private->destroyed)
1002 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
1003 GDK_WINDOW_XID (window));
1005 if (!GDK_WINDOW_IS_MAPPED (window))
1007 set_initial_hints (window);
1009 gdk_synthesize_window_state (window,
1010 GDK_WINDOW_STATE_WITHDRAWN,
1014 g_assert (GDK_WINDOW_IS_MAPPED (window));
1016 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
1017 XMapWindow (GDK_WINDOW_XDISPLAY (window),
1018 GDK_WINDOW_XID (window));
1023 * gdk_window_show_unraised:
1024 * @window: a #GdkWindow
1026 * Shows a #GdkWindow onscreen, but does not modify its stacking
1027 * order. In contrast, gdk_window_show() will raise the window
1028 * to the top of the window stack.
1030 * On the X11 platform, in Xlib terms, this function calls
1031 * XMapWindow() (it also updates some internal GDK state, which means
1032 * that you can't really use XMapWindow() directly on a GDK window).
1036 gdk_window_show_unraised (GdkWindow *window)
1038 g_return_if_fail (GDK_IS_WINDOW (window));
1040 show_window_internal (window, FALSE);
1045 * @window: a #GdkWindow
1047 * Like gdk_window_show_unraised(), but also raises the window to the
1048 * top of the window stack (moves the window to the front of the
1051 * This function maps a window so it's visible onscreen. Its opposite
1052 * is gdk_window_hide().
1054 * When implementing a #GtkWidget, you should call this function on the widget's
1055 * #GdkWindow as part of the "map" method.
1059 gdk_window_show (GdkWindow *window)
1061 g_return_if_fail (GDK_IS_WINDOW (window));
1063 show_window_internal (window, TRUE);
1068 * @window: a #GdkWindow
1070 * For toplevel windows, withdraws them, so they will no longer be
1071 * known to the window manager; for all windows, unmaps them, so
1072 * they won't be displayed. Normally done automatically as
1073 * part of gtk_widget_hide().
1077 gdk_window_hide (GdkWindow *window)
1079 GdkWindowObject *private;
1081 g_return_if_fail (window != NULL);
1083 private = (GdkWindowObject*) window;
1085 /* We'll get the unmap notify eventually, and handle it then,
1086 * but checking here makes things more consistent if we are
1087 * just doing stuff ourself.
1089 _gdk_xgrab_check_unmap (window,
1090 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1092 /* You can't simply unmap toplevel windows. */
1093 switch (private->window_type)
1095 case GDK_WINDOW_TOPLEVEL:
1096 case GDK_WINDOW_DIALOG:
1097 case GDK_WINDOW_TEMP: /* ? */
1098 gdk_window_withdraw (window);
1102 case GDK_WINDOW_FOREIGN:
1103 case GDK_WINDOW_ROOT:
1104 case GDK_WINDOW_CHILD:
1108 if (!private->destroyed)
1110 if (GDK_WINDOW_IS_MAPPED (window))
1111 gdk_synthesize_window_state (window,
1113 GDK_WINDOW_STATE_WITHDRAWN);
1115 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1117 _gdk_window_clear_update_area (window);
1119 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1120 GDK_WINDOW_XID (window));
1125 * gdk_window_withdraw:
1126 * @window: a toplevel #GdkWindow
1128 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1129 * Normally done automatically by gtk_widget_hide() called on a #GtkWindow.
1133 gdk_window_withdraw (GdkWindow *window)
1135 GdkWindowObject *private;
1137 g_return_if_fail (window != NULL);
1139 private = (GdkWindowObject*) window;
1140 if (!private->destroyed)
1142 if (GDK_WINDOW_IS_MAPPED (window))
1143 gdk_synthesize_window_state (window,
1145 GDK_WINDOW_STATE_WITHDRAWN);
1147 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1149 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1150 GDK_WINDOW_XID (window), 0);
1156 * @window: a #GdkWindow
1157 * @x: X coordinate relative to window's parent
1158 * @y: Y coordinate relative to window's parent
1160 * Repositions a window relative to its parent window.
1161 * For toplevel windows, window managers may ignore or modify the move;
1162 * you should probably use gtk_window_move() on a #GtkWindow widget
1163 * anyway, instead of using GDK functions. For child windows,
1164 * the move will reliably succeed.
1166 * If you're also planning to resize the window, use gdk_window_move_resize()
1167 * to both move and resize simultaneously, for a nicer visual effect.
1171 gdk_window_move (GdkWindow *window,
1175 GdkWindowObject *private = (GdkWindowObject *)window;
1176 GdkWindowImplX11 *impl;
1178 g_return_if_fail (window != NULL);
1179 g_return_if_fail (GDK_IS_WINDOW (window));
1181 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1183 if (!GDK_WINDOW_DESTROYED (window))
1185 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1186 _gdk_window_move_resize_child (window, x, y,
1187 impl->width, impl->height);
1190 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1191 GDK_WINDOW_XID (window),
1198 * gdk_window_resize:
1199 * @window: a #GdkWindow
1200 * @width: new width of the window
1201 * @height: new height of the window
1203 * Resizes @window; for toplevel windows, asks the window manager to resize
1204 * the window. The window manager may not allow the resize. When using GTK+,
1205 * use gtk_window_resize() instead of this low-level GDK function.
1207 * Windows may not be resized below 1x1.
1209 * If you're also planning to move the window, use gdk_window_move_resize()
1210 * to both move and resize simultaneously, for a nicer visual effect.
1214 gdk_window_resize (GdkWindow *window,
1218 GdkWindowObject *private;
1220 g_return_if_fail (window != NULL);
1221 g_return_if_fail (GDK_IS_WINDOW (window));
1228 private = (GdkWindowObject*) window;
1230 if (!GDK_WINDOW_DESTROYED (window))
1232 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1233 _gdk_window_move_resize_child (window, private->x, private->y,
1237 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1239 if (width != impl->width || height != impl->height)
1240 private->resize_count += 1;
1242 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1243 GDK_WINDOW_XID (window),
1250 * gdk_window_move_resize:
1251 * @window: a #GdkWindow
1252 * @x: new X position relative to window's parent
1253 * @y: new Y position relative to window's parent
1255 * @height: new height
1257 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1258 * except that both operations are performed at once, avoiding strange
1259 * visual effects. (i.e. the user may be able to see the window first
1260 * move, then resize, if you don't use gdk_window_move_resize().)
1264 gdk_window_move_resize (GdkWindow *window,
1270 GdkWindowObject *private;
1272 g_return_if_fail (window != NULL);
1273 g_return_if_fail (GDK_IS_WINDOW (window));
1280 private = (GdkWindowObject*) window;
1282 if (!GDK_WINDOW_DESTROYED (window))
1284 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1285 _gdk_window_move_resize_child (window, x, y, width, height);
1288 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1290 if (width != impl->width || height != impl->height)
1291 private->resize_count += 1;
1293 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1294 GDK_WINDOW_XID (window),
1295 x, y, width, height);
1301 * gdk_window_reparent:
1302 * @window: a #GdkWindow
1303 * @new_parent: new parent to move @window into
1304 * @x: X location inside the new parent
1305 * @y: Y location inside the new parent
1307 * Reparents @window into the given @new_parent. The window being
1308 * reparented will be unmapped as a side effect.
1312 gdk_window_reparent (GdkWindow *window,
1313 GdkWindow *new_parent,
1317 GdkDisplay *display;
1318 GdkWindowObject *window_private;
1319 GdkWindowObject *parent_private;
1320 GdkWindowObject *old_parent_private;
1322 g_return_if_fail (window != NULL);
1323 g_return_if_fail (GDK_IS_WINDOW (window));
1324 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1325 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1328 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1330 display = GDK_WINDOW_DISPLAY (window);
1332 window_private = (GdkWindowObject*) window;
1333 old_parent_private = (GdkWindowObject*)window_private->parent;
1334 parent_private = (GdkWindowObject*) new_parent;
1336 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1337 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1338 GDK_WINDOW_XID (window),
1339 GDK_WINDOW_XID (new_parent),
1342 window_private->x = x;
1343 window_private->y = y;
1345 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1348 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1349 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1351 window_private->parent = (GdkWindowObject *)new_parent;
1353 /* Switch the window type as appropriate */
1355 switch (GDK_WINDOW_TYPE (new_parent))
1357 case GDK_WINDOW_ROOT:
1358 case GDK_WINDOW_FOREIGN:
1359 /* Now a toplevel */
1360 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1361 set_wm_protocols (window);
1363 case GDK_WINDOW_TOPLEVEL:
1364 case GDK_WINDOW_CHILD:
1365 case GDK_WINDOW_DIALOG:
1366 case GDK_WINDOW_TEMP:
1367 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1368 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1370 /* If we were being sophisticated, we'd save the old window type
1371 * here, and restore it if we were reparented back to the
1372 * toplevel. However, the difference between different types
1373 * of toplevels only really matters on creation anyways.
1375 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1379 if (old_parent_private)
1380 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1382 if ((old_parent_private &&
1383 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1384 (!old_parent_private && parent_private->guffaw_gravity))
1385 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1387 parent_private->children = g_list_prepend (parent_private->children, window);
1388 _gdk_window_init_position (GDK_WINDOW (window_private));
1392 _gdk_windowing_window_clear_area (GdkWindow *window,
1398 g_return_if_fail (window != NULL);
1399 g_return_if_fail (GDK_IS_WINDOW (window));
1401 if (!GDK_WINDOW_DESTROYED (window))
1402 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1403 x, y, width, height, False);
1407 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1413 g_return_if_fail (window != NULL);
1414 g_return_if_fail (GDK_IS_WINDOW (window));
1416 if (!GDK_WINDOW_DESTROYED (window))
1417 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1418 x, y, width, height, True);
1424 * @window: a #GdkWindow
1426 * Raises @window to the top of the Z-order (stacking order), so that
1427 * other windows with the same parent window appear below @window.
1428 * If @window is a toplevel, the window manager may choose to deny the
1429 * request to move the window in the Z-order, gdk_window_raise() only
1430 * requests the restack, does not guarantee it.
1434 gdk_window_raise (GdkWindow *window)
1436 g_return_if_fail (window != NULL);
1437 g_return_if_fail (GDK_IS_WINDOW (window));
1439 if (!GDK_WINDOW_DESTROYED (window))
1440 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1445 * @window: a #GdkWindow
1447 * Lowers @window to the bottom of the Z-order (stacking order), so that
1448 * other windows with the same parent window appear above @window.
1449 * If @window is a toplevel, the window manager may choose to deny the
1450 * request to move the window in the Z-order, gdk_window_lower() only
1451 * requests the restack, does not guarantee it.
1453 * Note that gdk_window_show() raises the window again, so don't call this
1454 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1458 gdk_window_lower (GdkWindow *window)
1460 g_return_if_fail (window != NULL);
1461 g_return_if_fail (GDK_IS_WINDOW (window));
1463 if (!GDK_WINDOW_DESTROYED (window))
1464 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1469 * @window: a #GdkWindow
1470 * @timestamp: timestamp of the event triggering the window focus
1472 * Sets keyboard focus to @window. If @window is not onscreen this
1473 * will not work. In most cases, gtk_window_present() should be used on
1474 * a #GtkWindow, rather than calling this function.
1478 gdk_window_focus (GdkWindow *window,
1481 g_return_if_fail (GDK_IS_WINDOW (window));
1483 if (GDK_WINDOW_DESTROYED (window))
1486 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1487 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1491 xev.xclient.type = ClientMessage;
1492 xev.xclient.serial = 0;
1493 xev.xclient.send_event = True;
1494 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1495 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1496 "_NET_ACTIVE_WINDOW");
1497 xev.xclient.format = 32;
1498 xev.xclient.data.l[0] = 0;
1500 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1501 SubstructureRedirectMask | SubstructureNotifyMask,
1506 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1508 /* There is no way of knowing reliably whether we are viewable so we need
1509 * to trap errors so we don't cause a BadMatch.
1511 gdk_error_trap_push ();
1512 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1513 GDK_WINDOW_XWINDOW (window),
1516 XSync (GDK_WINDOW_XDISPLAY (window), False);
1517 gdk_error_trap_pop ();
1522 * gdk_window_set_hints:
1523 * @window: a #GdkWindow
1524 * @x: ignored field, does not matter
1525 * @y: ignored field, does not matter
1526 * @min_width: minimum width hint
1527 * @min_height: minimum height hint
1528 * @max_width: max width hint
1529 * @max_height: max height hint
1530 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1532 * This function is broken and useless and you should ignore it.
1533 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1534 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1535 * depending on what you're trying to do.
1537 * If using GDK directly, use gdk_window_set_geometry_hints().
1541 gdk_window_set_hints (GdkWindow *window,
1550 XSizeHints size_hints;
1552 g_return_if_fail (window != NULL);
1553 g_return_if_fail (GDK_IS_WINDOW (window));
1555 if (GDK_WINDOW_DESTROYED (window))
1558 size_hints.flags = 0;
1560 if (flags & GDK_HINT_POS)
1562 size_hints.flags |= PPosition;
1567 if (flags & GDK_HINT_MIN_SIZE)
1569 size_hints.flags |= PMinSize;
1570 size_hints.min_width = min_width;
1571 size_hints.min_height = min_height;
1574 if (flags & GDK_HINT_MAX_SIZE)
1576 size_hints.flags |= PMaxSize;
1577 size_hints.max_width = max_width;
1578 size_hints.max_height = max_height;
1581 /* FIXME: Would it be better to delete this property if
1582 * flags == 0? It would save space on the server
1584 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1585 GDK_WINDOW_XID (window),
1590 * gdk_window_set_type_hint:
1591 * @window: A #GdkWindow
1592 * @hint: A hint of the function this window will have
1594 * The application can use this call to provide a hint to the window
1595 * manager about the functionality of a window. The window manager
1596 * can use this information when determining the decoration and behaviour
1599 * The hint must be set before the window is mapped.
1602 gdk_window_set_type_hint (GdkWindow *window,
1603 GdkWindowTypeHint hint)
1605 GdkDisplay *display;
1608 g_return_if_fail (window != NULL);
1609 g_return_if_fail (GDK_IS_WINDOW (window));
1611 if (GDK_WINDOW_DESTROYED (window))
1614 display = gdk_drawable_get_display (window);
1618 case GDK_WINDOW_TYPE_HINT_DIALOG:
1619 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1621 case GDK_WINDOW_TYPE_HINT_MENU:
1622 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1624 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1625 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1627 case GDK_WINDOW_TYPE_HINT_UTILITY:
1628 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1630 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1631 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASHSCREEN");
1633 case GDK_WINDOW_TYPE_HINT_DOCK:
1634 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1636 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1637 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1640 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1642 case GDK_WINDOW_TYPE_HINT_NORMAL:
1643 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1647 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1648 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1649 XA_ATOM, 32, PropModeReplace,
1650 (guchar *)&atom, 1);
1655 gdk_wmspec_change_state (gboolean add,
1660 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1663 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1664 #define _NET_WM_STATE_ADD 1 /* add/set property */
1665 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1667 xev.xclient.type = ClientMessage;
1668 xev.xclient.serial = 0;
1669 xev.xclient.send_event = True;
1670 xev.xclient.window = GDK_WINDOW_XID (window);
1671 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1672 xev.xclient.format = 32;
1673 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1674 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1675 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1677 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1678 SubstructureRedirectMask | SubstructureNotifyMask,
1683 * gdk_window_set_modal_hint:
1684 * @window: A #GdkWindow
1685 * @modal: TRUE if the window is modal, FALSE otherwise.
1687 * The application can use this hint to tell the window manager
1688 * that a certain window has modal behaviour. The window manager
1689 * can use this information to handle modal windows in a special
1692 * You should only use this on windows for which you have
1693 * previously called #gdk_window_set_transient_for()
1696 gdk_window_set_modal_hint (GdkWindow *window,
1699 GdkWindowObject *private;
1701 g_return_if_fail (window != NULL);
1702 g_return_if_fail (GDK_IS_WINDOW (window));
1704 if (GDK_WINDOW_DESTROYED (window))
1707 private = (GdkWindowObject*) window;
1709 private->modal_hint = modal;
1711 if (GDK_WINDOW_IS_MAPPED (window))
1712 gdk_wmspec_change_state (modal, window,
1713 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1718 * gdk_window_set_skip_taskbar_hint:
1719 * @window: a #GdkWindow
1720 * @skips_taskbar: %TRUE to skip the taskbar
1722 * Toggles whether a window should appear in a task list or window
1723 * list. If a window's semantic type as specified with
1724 * gdk_window_set_type_hint() already fully describes the window, this
1725 * function should NOT be called in addition, instead you should allow
1726 * the window to be treated according to standard policy for its
1730 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
1731 gboolean skips_taskbar)
1733 GdkWindowObject *private;
1734 GdkWindowImplX11 *impl;
1736 g_return_if_fail (window != NULL);
1737 g_return_if_fail (GDK_IS_WINDOW (window));
1739 if (GDK_WINDOW_DESTROYED (window))
1742 private = (GdkWindowObject*) window;
1743 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1745 impl->skip_taskbar_hint = skips_taskbar;
1747 if (GDK_WINDOW_IS_MAPPED (window))
1748 gdk_wmspec_change_state (skips_taskbar, window,
1749 gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE),
1754 * gdk_window_set_skip_pager_hint:
1755 * @window: a #GdkWindow
1756 * @skips_taskbar: %TRUE to skip the pager
1758 * Toggles whether a window should appear in a pager (workspace
1759 * switcher, or other desktop utility program that displays a small
1760 * thumbnail representation of the windows on the desktop). If a
1761 * window's semantic type as specified with gdk_window_set_type_hint()
1762 * already fully describes the window, this function should NOT be
1763 * called in addition, instead you should allow the window to be
1764 * treated according to standard policy for its semantic type.
1767 gdk_window_set_skip_pager_hint (GdkWindow *window,
1768 gboolean skips_pager)
1770 GdkWindowObject *private;
1771 GdkWindowImplX11 *impl;
1773 g_return_if_fail (window != NULL);
1774 g_return_if_fail (GDK_IS_WINDOW (window));
1776 if (GDK_WINDOW_DESTROYED (window))
1779 private = (GdkWindowObject*) window;
1780 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1782 impl->skip_pager_hint = skips_pager;
1784 if (GDK_WINDOW_IS_MAPPED (window))
1785 gdk_wmspec_change_state (skips_pager, window,
1786 gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE),
1791 * gdk_window_set_geometry_hints:
1792 * @window: a #GdkWindow
1793 * @geometry: geometry hints
1794 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1796 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1797 * are set, hints not flagged in @geom_mask are unset.
1798 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1802 gdk_window_set_geometry_hints (GdkWindow *window,
1803 GdkGeometry *geometry,
1804 GdkWindowHints geom_mask)
1806 XSizeHints size_hints;
1808 g_return_if_fail (window != NULL);
1809 g_return_if_fail (GDK_IS_WINDOW (window));
1811 if (GDK_WINDOW_DESTROYED (window))
1814 size_hints.flags = 0;
1816 if (geom_mask & GDK_HINT_POS)
1818 size_hints.flags |= PPosition;
1819 /* We need to initialize the following obsolete fields because KWM
1820 * apparently uses these fields if they are non-zero.
1827 if (geom_mask & GDK_HINT_USER_POS)
1829 size_hints.flags |= USPosition;
1832 if (geom_mask & GDK_HINT_USER_SIZE)
1834 size_hints.flags |= USSize;
1837 if (geom_mask & GDK_HINT_MIN_SIZE)
1839 size_hints.flags |= PMinSize;
1840 size_hints.min_width = geometry->min_width;
1841 size_hints.min_height = geometry->min_height;
1844 if (geom_mask & GDK_HINT_MAX_SIZE)
1846 size_hints.flags |= PMaxSize;
1847 size_hints.max_width = MAX (geometry->max_width, 1);
1848 size_hints.max_height = MAX (geometry->max_height, 1);
1851 if (geom_mask & GDK_HINT_BASE_SIZE)
1853 size_hints.flags |= PBaseSize;
1854 size_hints.base_width = geometry->base_width;
1855 size_hints.base_height = geometry->base_height;
1858 if (geom_mask & GDK_HINT_RESIZE_INC)
1860 size_hints.flags |= PResizeInc;
1861 size_hints.width_inc = geometry->width_inc;
1862 size_hints.height_inc = geometry->height_inc;
1865 if (geom_mask & GDK_HINT_ASPECT)
1867 size_hints.flags |= PAspect;
1868 if (geometry->min_aspect <= 1)
1870 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1871 size_hints.min_aspect.y = 65536;
1875 size_hints.min_aspect.x = 65536;
1876 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1878 if (geometry->max_aspect <= 1)
1880 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1881 size_hints.max_aspect.y = 65536;
1885 size_hints.max_aspect.x = 65536;
1886 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1890 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1892 size_hints.flags |= PWinGravity;
1893 size_hints.win_gravity = geometry->win_gravity;
1896 /* FIXME: Would it be better to delete this property if
1897 * geom_mask == 0? It would save space on the server
1899 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1900 GDK_WINDOW_XID (window),
1905 gdk_window_get_geometry_hints (GdkWindow *window,
1906 GdkGeometry *geometry,
1907 GdkWindowHints *geom_mask)
1909 XSizeHints size_hints;
1910 glong junk_size_mask = 0;
1912 g_return_if_fail (GDK_IS_WINDOW (window));
1913 g_return_if_fail (geometry != NULL);
1914 g_return_if_fail (geom_mask != NULL);
1918 if (GDK_WINDOW_DESTROYED (window))
1921 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1922 GDK_WINDOW_XID (window),
1927 if (size_hints.flags & PMinSize)
1929 *geom_mask |= GDK_HINT_MIN_SIZE;
1930 geometry->min_width = size_hints.min_width;
1931 geometry->min_height = size_hints.min_height;
1934 if (size_hints.flags & PMaxSize)
1936 *geom_mask |= GDK_HINT_MAX_SIZE;
1937 geometry->max_width = MAX (size_hints.max_width, 1);
1938 geometry->max_height = MAX (size_hints.max_height, 1);
1941 if (size_hints.flags & PResizeInc)
1943 *geom_mask |= GDK_HINT_RESIZE_INC;
1944 geometry->width_inc = size_hints.width_inc;
1945 geometry->height_inc = size_hints.height_inc;
1948 if (size_hints.flags & PAspect)
1950 *geom_mask |= GDK_HINT_ASPECT;
1952 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1953 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1956 if (size_hints.flags & PWinGravity)
1958 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1959 geometry->win_gravity = size_hints.win_gravity;
1964 utf8_is_latin1 (const gchar *str)
1966 const char *p = str;
1970 gunichar ch = g_utf8_get_char (p);
1975 p = g_utf8_next_char (p);
1981 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
1982 * convertable to STRING, otherwise, set it as compound text
1985 set_text_property (GdkWindow *window,
1987 const gchar *utf8_str)
1989 guchar *prop_text = NULL;
1994 if (utf8_is_latin1 (utf8_str))
1996 prop_type = XA_STRING;
1997 prop_text = gdk_utf8_to_string_target (utf8_str);
1998 prop_length = prop_text ? strlen (prop_text) : 0;
2005 gdk_utf8_to_compound_text_for_display (gdk_drawable_get_display (window),
2006 utf8_str, &gdk_type, &prop_format,
2007 &prop_text, &prop_length);
2008 prop_type = gdk_x11_atom_to_xatom_for_display
2009 (GDK_WINDOW_DISPLAY (window), gdk_type);
2014 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2015 GDK_WINDOW_XID (window),
2017 prop_type, prop_format,
2018 PropModeReplace, prop_text,
2026 * gdk_window_set_title:
2027 * @window: a #GdkWindow
2028 * @title: title of @window
2030 * Sets the title of a toplevel window, to be displayed in the titlebar.
2031 * If you haven't explicitly set the icon name for the window
2032 * (using gdk_window_set_icon_name()), the icon name will be set to
2033 * @title as well. @title must be in UTF-8 encoding (as with all
2034 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2037 gdk_window_set_title (GdkWindow *window,
2040 GdkDisplay *display;
2042 g_return_if_fail (window != NULL);
2043 g_return_if_fail (GDK_IS_WINDOW (window));
2044 g_return_if_fail (title != NULL);
2046 if (GDK_WINDOW_DESTROYED (window))
2049 display = gdk_drawable_get_display (window);
2051 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2052 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2053 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2054 PropModeReplace, title, strlen (title));
2056 set_text_property (window,
2057 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2060 if (!gdk_window_icon_name_set (window))
2062 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2063 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2064 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2065 PropModeReplace, title, strlen (title));
2067 set_text_property (window,
2068 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2074 * gdk_window_set_role:
2075 * @window: a #GdkWindow
2076 * @role: a string indicating its role
2078 * When using GTK+, typically you should use gtk_window_set_role() instead
2079 * of this low-level function.
2081 * The window manager and session manager use a window's role to
2082 * distinguish it from other kinds of window in the same application.
2083 * When an application is restarted after being saved in a previous
2084 * session, all windows with the same title and role are treated as
2085 * interchangeable. So if you have two windows with the same title
2086 * that should be distinguished for session management purposes, you
2087 * should set the role on those windows. It doesn't matter what string
2088 * you use for the role, as long as you have a different role for each
2089 * non-interchangeable kind of window.
2093 gdk_window_set_role (GdkWindow *window,
2096 GdkDisplay *display;
2098 g_return_if_fail (window != NULL);
2099 g_return_if_fail (GDK_IS_WINDOW (window));
2101 display = gdk_drawable_get_display (window);
2103 if (!GDK_WINDOW_DESTROYED (window))
2106 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2107 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2108 XA_STRING, 8, PropModeReplace, role, strlen (role));
2110 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2111 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2116 * gdk_window_set_transient_for:
2117 * @window: a toplevel #GdkWindow
2118 * @parent: another toplevel #GdkWindow
2120 * Indicates to the window manager that @window is a transient dialog
2121 * associated with the application window @parent. This allows the
2122 * window manager to do things like center @window on @parent and
2123 * keep @window above @parent.
2125 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2130 gdk_window_set_transient_for (GdkWindow *window,
2133 GdkWindowObject *private;
2134 GdkWindowObject *parent_private;
2136 g_return_if_fail (window != NULL);
2137 g_return_if_fail (GDK_IS_WINDOW (window));
2139 private = (GdkWindowObject*) window;
2140 parent_private = (GdkWindowObject*) parent;
2142 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2143 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2144 GDK_WINDOW_XID (window),
2145 GDK_WINDOW_XID (parent));
2149 * gdk_window_set_background:
2150 * @window: a #GdkWindow
2151 * @color: an allocated #GdkColor
2153 * Sets the background color of @window. (However, when using GTK+,
2154 * set the background of a widget with gtk_widget_modify_bg() - if
2155 * you're an application - or gtk_style_set_background() - if you're
2156 * implementing a custom widget.)
2158 * The @color must be allocated; gdk_rgb_find_color() is the best way
2159 * to allocate a color.
2161 * See also gdk_window_set_back_pixmap().
2165 gdk_window_set_background (GdkWindow *window,
2168 GdkWindowObject *private = (GdkWindowObject *)window;
2170 g_return_if_fail (window != NULL);
2171 g_return_if_fail (GDK_IS_WINDOW (window));
2173 if (!GDK_WINDOW_DESTROYED (window))
2174 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2175 GDK_WINDOW_XID (window), color->pixel);
2177 private->bg_color = *color;
2179 if (private->bg_pixmap &&
2180 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2181 private->bg_pixmap != GDK_NO_BG)
2182 g_object_unref (private->bg_pixmap);
2184 private->bg_pixmap = NULL;
2188 * gdk_window_set_back_pixmap:
2189 * @window: a #GdkWindow
2190 * @pixmap: a #GdkPixmap, or %NULL
2191 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2193 * Sets the background pixmap of @window. May also be used to set a background of
2194 * "None" on @window, by setting a background pixmap of %NULL.
2195 * A background pixmap will be tiled, positioning the first tile at the origin of
2196 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2197 * origin of the parent window (useful to align tiles in a parent with tiles
2200 * A background pixmap of %NULL means that the window will have no
2201 * background. A window with no background will never have its
2202 * background filled by the windowing system, instead the window will
2203 * contain whatever pixels were already in the corresponding area of
2206 * The windowing system will normally fill a window with its background
2207 * when the window is obscured then exposed, and when you call
2208 * gdk_window_clear().
2212 gdk_window_set_back_pixmap (GdkWindow *window,
2214 gboolean parent_relative)
2216 GdkWindowObject *private = (GdkWindowObject *)window;
2219 g_return_if_fail (window != NULL);
2220 g_return_if_fail (GDK_IS_WINDOW (window));
2221 g_return_if_fail (pixmap == NULL || !parent_relative);
2222 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2224 if (private->bg_pixmap &&
2225 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2226 private->bg_pixmap != GDK_NO_BG)
2227 g_object_unref (private->bg_pixmap);
2229 if (parent_relative)
2231 xpixmap = ParentRelative;
2232 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2238 g_object_ref (pixmap);
2239 private->bg_pixmap = pixmap;
2240 xpixmap = GDK_PIXMAP_XID (pixmap);
2245 private->bg_pixmap = GDK_NO_BG;
2249 if (!GDK_WINDOW_DESTROYED (window))
2250 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2251 GDK_WINDOW_XID (window), xpixmap);
2255 * gdk_window_set_cursor:
2256 * @window: a #GdkWindow
2259 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2260 * gdk_cursor_new_from_pixmap() to create the cursor.
2261 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2262 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2263 * to gdk_window_set_cursor() means that @window will use the cursor of
2264 * its parent window. Most windows should use this default.
2268 gdk_window_set_cursor (GdkWindow *window,
2271 GdkCursorPrivate *cursor_private;
2274 g_return_if_fail (window != NULL);
2275 g_return_if_fail (GDK_IS_WINDOW (window));
2277 cursor_private = (GdkCursorPrivate*) cursor;
2282 xcursor = cursor_private->xcursor;
2284 if (!GDK_WINDOW_DESTROYED (window))
2285 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2286 GDK_WINDOW_XID (window),
2291 * gdk_window_get_geometry:
2292 * @window: a #GdkWindow
2293 * @x: return location for X coordinate of window (relative to its parent)
2294 * @y: return location for Y coordinate of window (relative to its parent)
2295 * @width: return location for width of window
2296 * @height: return location for height of window
2297 * @depth: return location for bit depth of window
2299 * Any of the return location arguments to this function may be %NULL,
2300 * if you aren't interested in getting the value of that field.
2302 * The X and Y coordinates returned are relative to the parent window
2303 * of @window, which for toplevels usually means relative to the
2304 * window decorations (titlebar, etc.) rather than relative to the
2305 * root window (screen-size background window).
2307 * On the X11 platform, the geometry is obtained from the X server,
2308 * so reflects the latest position of @window; this may be out-of-sync
2309 * with the position of @window delivered in the most-recently-processed
2310 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2311 * position from the most recent configure event.
2315 gdk_window_get_geometry (GdkWindow *window,
2327 guint tborder_width;
2330 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2334 GDK_NOTE (MULTIHEAD,
2335 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2336 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
2339 if (!GDK_WINDOW_DESTROYED (window))
2341 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2342 GDK_WINDOW_XID (window),
2343 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2359 * gdk_window_get_origin:
2360 * @window: a #GdkWindow
2361 * @x: return location for X coordinate
2362 * @y: return location for Y coordinate
2364 * Obtains the position of a window in root window coordinates.
2365 * (Compare with gdk_window_get_position() and
2366 * gdk_window_get_geometry() which return the position of a window
2367 * relative to its parent window.)
2369 * Return value: not meaningful, ignore
2372 gdk_window_get_origin (GdkWindow *window,
2381 g_return_val_if_fail (window != NULL, 0);
2383 if (!GDK_WINDOW_DESTROYED (window))
2385 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2386 GDK_WINDOW_XID (window),
2387 GDK_WINDOW_XROOTWIN (window),
2403 * gdk_window_get_deskrelative_origin:
2404 * @window: a #GdkWindow
2405 * @x: return location for X coordinate
2406 * @y: return location for Y coordinate
2408 * This gets the origin of a #GdkWindow relative to
2409 * an Enlightenment-window-manager desktop. As long as you don't
2410 * assume that the user's desktop/workspace covers the entire
2411 * root window (i.e. you don't assume that the desktop begins
2412 * at root window coordinate 0,0) this function is not necessary.
2413 * It's deprecated for that reason.
2415 * Return value: not meaningful
2418 gdk_window_get_deskrelative_origin (GdkWindow *window,
2422 gboolean return_val = FALSE;
2423 gint num_children, format_return;
2424 Window win, *child, parent, root;
2429 gulong number_return, bytes_after_return;
2430 guchar *data_return;
2432 g_return_val_if_fail (window != NULL, 0);
2433 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2435 if (!GDK_WINDOW_DESTROYED (window))
2437 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2438 "ENLIGHTENMENT_DESKTOP");
2439 win = GDK_WINDOW_XID (window);
2441 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2442 &child, (unsigned int *)&num_children))
2444 if ((child) && (num_children > 0))
2456 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2457 False, XA_CARDINAL, &type_return, &format_return,
2458 &number_return, &bytes_after_return, &data_return);
2460 if (type_return == XA_CARDINAL)
2462 XFree (data_return);
2467 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2468 GDK_WINDOW_XID (window),
2483 * gdk_window_get_root_origin:
2484 * @window: a #GdkWindow
2485 * @x: return location for X position of window frame
2486 * @y: return location for Y position of window frame
2488 * Obtains the top-left corner of the window manager frame in root
2489 * window coordinates.
2493 gdk_window_get_root_origin (GdkWindow *window,
2499 g_return_if_fail (GDK_IS_WINDOW (window));
2501 gdk_window_get_frame_extents (window, &rect);
2511 * gdk_window_get_frame_extents:
2512 * @window: a #GdkWindow
2513 * @rect: rectangle to fill with bounding box of the window frame
2515 * Obtains the bounding box of the window, including window manager
2516 * titlebar/borders if any. The frame position is given in root window
2517 * coordinates. To get the position of the window itself (rather than
2518 * the frame) in root window coordinates, use gdk_window_get_origin().
2522 gdk_window_get_frame_extents (GdkWindow *window,
2525 GdkWindowObject *private;
2530 unsigned int nchildren;
2532 g_return_if_fail (GDK_IS_WINDOW (window));
2533 g_return_if_fail (rect != NULL);
2535 private = (GdkWindowObject*) window;
2542 if (GDK_WINDOW_DESTROYED (window))
2545 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2546 private = (GdkWindowObject*) private->parent;
2547 if (GDK_WINDOW_DESTROYED (window))
2550 xparent = GDK_WINDOW_XID (window);
2554 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2556 &children, &nchildren))
2562 while (xparent != root);
2564 if (xparent == root)
2566 unsigned int ww, wh, wb, wd;
2569 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2580 _gdk_windowing_window_get_pointer (GdkWindow *window,
2583 GdkModifierType *mask)
2585 GdkWindow *return_val;
2591 unsigned int xmask = 0;
2592 gint xoffset, yoffset;
2594 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2598 GDK_NOTE (MULTIHEAD,
2599 g_message ("_gdk_windowing_window_get_pointer(): window arg is need for multihead safe operation"));
2600 window = gdk_screen_get_root_window (gdk_screen_get_default ());
2603 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2606 if (!GDK_WINDOW_DESTROYED (window) &&
2607 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2608 GDK_WINDOW_XID (window),
2609 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2612 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
2616 *x = winx + xoffset;
2618 *y = winy + yoffset;
2626 _gdk_windowing_window_at_pointer (GdkScreen *screen,
2633 Window xwindow_last = 0;
2635 int rootx = -1, rooty = -1;
2639 xwindow = GDK_SCREEN_XROOTWIN (screen);
2640 xdisplay = GDK_SCREEN_XDISPLAY (screen);
2642 XGrabServer (xdisplay);
2645 xwindow_last = xwindow;
2646 XQueryPointer (xdisplay, xwindow,
2647 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
2649 XUngrabServer (xdisplay);
2651 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
2654 *win_x = window ? winx : -1;
2656 *win_y = window ? winy : -1;
2662 * gdk_window_get_events:
2663 * @window: a #GdkWindow
2665 * Gets the event mask for @window. See gdk_window_set_events().
2667 * Return value: event mask for @window
2670 gdk_window_get_events (GdkWindow *window)
2672 XWindowAttributes attrs;
2673 GdkEventMask event_mask;
2675 g_return_val_if_fail (window != NULL, 0);
2676 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2678 if (GDK_WINDOW_DESTROYED (window))
2682 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2683 GDK_WINDOW_XID (window),
2686 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2687 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2694 * gdk_window_set_events:
2695 * @window: a #GdkWindow
2696 * @event_mask: event mask for @window
2698 * The event mask for a window determines which events will be reported
2699 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2700 * means the window should report button press events. The event mask
2701 * is the bitwise OR of values from the #GdkEventMask enumeration.
2705 gdk_window_set_events (GdkWindow *window,
2706 GdkEventMask event_mask)
2711 g_return_if_fail (window != NULL);
2712 g_return_if_fail (GDK_IS_WINDOW (window));
2714 if (!GDK_WINDOW_DESTROYED (window))
2716 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2717 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2718 for (i = 0; i < _gdk_nenvent_masks; i++)
2720 if (event_mask & (1 << (i + 1)))
2721 xevent_mask |= _gdk_event_mask_table[i];
2724 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2725 GDK_WINDOW_XID (window),
2731 gdk_window_add_colormap_windows (GdkWindow *window)
2733 GdkWindow *toplevel;
2734 Window *old_windows;
2735 Window *new_windows;
2738 g_return_if_fail (window != NULL);
2739 g_return_if_fail (GDK_IS_WINDOW (window));
2741 if (GDK_WINDOW_DESTROYED (window))
2743 toplevel = gdk_window_get_toplevel (window);
2746 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2747 GDK_WINDOW_XID (toplevel),
2748 &old_windows, &count))
2753 for (i = 0; i < count; i++)
2754 if (old_windows[i] == GDK_WINDOW_XID (window))
2756 XFree (old_windows);
2760 new_windows = g_new (Window, count + 1);
2762 for (i = 0; i < count; i++)
2763 new_windows[i] = old_windows[i];
2764 new_windows[count] = GDK_WINDOW_XID (window);
2766 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2767 GDK_WINDOW_XID (toplevel),
2768 new_windows, count + 1);
2770 g_free (new_windows);
2772 XFree (old_windows);
2776 gdk_window_have_shape_ext (GdkDisplay *display)
2778 GdkDisplayX11 *display_x11;
2780 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2782 display_x11 = GDK_DISPLAY_X11 (display);
2784 if (display_x11->have_shape == GDK_UNKNOWN)
2787 if (XQueryExtension (display_x11->xdisplay, "SHAPE", &ignore, &ignore, &ignore))
2788 display_x11->have_shape = GDK_YES;
2790 display_x11->have_shape = GDK_NO;
2793 return (display_x11->have_shape == GDK_YES);
2796 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2799 * This needs the X11 shape extension.
2800 * If not available, shaped windows will look
2801 * ugly, but programs still work. Stefan Wille
2804 * gdk_window_shape_combine_mask:
2805 * @window: a #GdkWindow
2807 * @x: X position of shape mask with respect to @window
2808 * @y: Y position of shape mask with respect to @window
2810 * Applies a shape mask to @window. Pixels in @window corresponding to
2811 * set bits in the @mask will be visible; pixels in @window
2812 * corresponding to unset bits in the @mask will be transparent. This
2813 * gives a non-rectangular window.
2815 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2816 * parameters are not used.
2818 * On the X11 platform, this uses an X server extension which is
2819 * widely available on most common platforms, but not available on
2820 * very old X servers, and occasionally the implementation will be
2821 * buggy. On servers without the shape extension, this function
2826 gdk_window_shape_combine_mask (GdkWindow *window,
2831 gint xoffset, yoffset;
2833 g_return_if_fail (window != NULL);
2834 g_return_if_fail (GDK_IS_WINDOW (window));
2836 #ifdef HAVE_SHAPE_EXT
2837 if (GDK_WINDOW_DESTROYED (window))
2840 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2842 if (xoffset != 0 || yoffset != 0)
2844 WARN_SHAPE_TOO_BIG ();
2848 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2852 pixmap = GDK_PIXMAP_XID (mask);
2861 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2862 GDK_WINDOW_XID (window),
2868 #endif /* HAVE_SHAPE_EXT */
2872 * gdk_window_shape_combine_region:
2873 * @window: a #GdkWindow
2874 * @shape_region: region of window to be non-transparent
2875 * @offset_x: X position of @shape_region in @window coordinates
2876 * @offset_y: Y position of @shape_region in @window coordinates
2878 * Makes pixels in @window outside @shape_region be transparent,
2879 * so that the window may be nonrectangular. See also
2880 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2882 * If @shape_region is %NULL, the shape will be unset, so the whole
2883 * window will be opaque again. @offset_x and @offset_y are ignored
2884 * if @shape_region is %NULL.
2886 * On the X11 platform, this uses an X server extension which is
2887 * widely available on most common platforms, but not available on
2888 * very old X servers, and occasionally the implementation will be
2889 * buggy. On servers without the shape extension, this function
2894 gdk_window_shape_combine_region (GdkWindow *window,
2895 GdkRegion *shape_region,
2899 gint xoffset, yoffset;
2901 g_return_if_fail (GDK_IS_WINDOW (window));
2903 #ifdef HAVE_SHAPE_EXT
2904 if (GDK_WINDOW_DESTROYED (window))
2907 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2909 if (xoffset != 0 || yoffset != 0)
2911 WARN_SHAPE_TOO_BIG ();
2915 if (shape_region == NULL)
2917 /* Use NULL mask to unset the shape */
2918 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2922 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2925 XRectangle *xrects = NULL;
2927 _gdk_region_get_xrectangles (shape_region,
2931 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2932 GDK_WINDOW_XID (window),
2941 #endif /* HAVE_SHAPE_EXT */
2946 * gdk_window_set_override_redirect:
2947 * @window: a #GdkWindow
2948 * @override_redirect: %TRUE if window should be override redirect
2950 * An override redirect window is not under the control of the window manager.
2951 * This means it won't have a titlebar, won't be minimizable, etc. - it will
2952 * be entirely under the control of the application. The window manager
2953 * can't see the override redirect window at all.
2955 * Override redirect should only be used for short-lived temporary
2956 * windows, such as popup menus. #GtkMenu uses an override redirect
2957 * window in its implementation, for example.
2961 gdk_window_set_override_redirect (GdkWindow *window,
2962 gboolean override_redirect)
2964 XSetWindowAttributes attr;
2966 g_return_if_fail (window != NULL);
2967 g_return_if_fail (GDK_IS_WINDOW (window));
2969 if (!GDK_WINDOW_DESTROYED (window))
2971 attr.override_redirect = (override_redirect == FALSE)?False:True;
2972 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2973 GDK_WINDOW_XID (window),
2981 * gdk_window_set_icon_list:
2982 * @window: The #GdkWindow toplevel window to set the icon of.
2983 * @pixbufs: A list of pixbufs, of different sizes.
2985 * Sets a list of icons for the window. One of these will be used
2986 * to represent the window when it has been iconified. The icon is
2987 * usually shown in an icon box or some sort of task bar. Which icon
2988 * size is shown depends on the window manager. The window manager
2989 * can scale the icon but setting several size icons can give better
2990 * image quality since the window manager may only need to scale the
2991 * icon by a small amount or not at all.
2995 gdk_window_set_icon_list (GdkWindow *window,
3004 gint width, height, stride;
3007 GdkDisplay *display;
3009 g_return_if_fail (GDK_IS_WINDOW (window));
3011 if (GDK_WINDOW_DESTROYED (window))
3014 display = gdk_drawable_get_display (window);
3022 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3024 width = gdk_pixbuf_get_width (pixbuf);
3025 height = gdk_pixbuf_get_height (pixbuf);
3027 size += 2 + width * height;
3029 l = g_list_next (l);
3032 data = g_malloc (size * sizeof (gulong));
3040 width = gdk_pixbuf_get_width (pixbuf);
3041 height = gdk_pixbuf_get_height (pixbuf);
3042 stride = gdk_pixbuf_get_rowstride (pixbuf);
3043 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3048 pixels = gdk_pixbuf_get_pixels (pixbuf);
3050 for (y = 0; y < height; y++)
3052 for (x = 0; x < width; x++)
3056 r = pixels[y*stride + x*n_channels + 0];
3057 g = pixels[y*stride + x*n_channels + 1];
3058 b = pixels[y*stride + x*n_channels + 2];
3059 if (n_channels >= 4)
3060 a = pixels[y*stride + x*n_channels + 3];
3064 *p++ = a << 24 | r << 16 | g << 8 | b ;
3068 l = g_list_next (l);
3073 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3074 GDK_WINDOW_XID (window),
3075 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3078 (guchar*) data, size);
3082 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3083 GDK_WINDOW_XID (window),
3084 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3091 * gdk_window_set_icon:
3092 * @window: a #GdkWindow
3093 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3094 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3095 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3097 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3098 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3099 * and gtk_window_set_icon(). If those don't meet your needs, look at
3100 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3101 * want to fall back to gdk_window_set_icon().
3105 gdk_window_set_icon (GdkWindow *window,
3106 GdkWindow *icon_window,
3112 g_return_if_fail (window != NULL);
3113 g_return_if_fail (GDK_IS_WINDOW (window));
3115 if (GDK_WINDOW_DESTROYED (window))
3118 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3119 GDK_WINDOW_XID (window));
3121 wm_hints = XAllocWMHints ();
3123 if (icon_window != NULL)
3125 wm_hints->flags |= IconWindowHint;
3126 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
3131 wm_hints->flags |= IconPixmapHint;
3132 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
3137 wm_hints->flags |= IconMaskHint;
3138 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
3141 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3142 GDK_WINDOW_XID (window), wm_hints);
3147 gdk_window_icon_name_set (GdkWindow *window)
3149 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3150 g_quark_from_static_string ("gdk-icon-name-set")));
3154 * gdk_window_set_icon_name:
3155 * @window: a #GdkWindow
3156 * @name: name of window while iconified (minimized)
3158 * Windows may have a name used while minimized, distinct from the
3159 * name they display in their titlebar. Most of the time this is a bad
3160 * idea from a user interface standpoint. But you can set such a name
3161 * with this function, if you like.
3165 gdk_window_set_icon_name (GdkWindow *window,
3168 GdkDisplay *display;
3170 g_return_if_fail (window != NULL);
3171 g_return_if_fail (GDK_IS_WINDOW (window));
3173 if (GDK_WINDOW_DESTROYED (window))
3176 display = gdk_drawable_get_display (window);
3178 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3179 GUINT_TO_POINTER (TRUE));
3181 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
3182 GDK_WINDOW_XID (window),
3183 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3184 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3185 PropModeReplace, name, strlen (name));
3187 set_text_property (window,
3188 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3193 * gdk_window_iconify:
3194 * @window: a #GdkWindow
3196 * Asks to iconify (minimize) @window. The window manager may choose
3197 * to ignore the request, but normally will honor it. Using
3198 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3202 gdk_window_iconify (GdkWindow *window)
3204 GdkWindowObject *private;
3206 g_return_if_fail (window != NULL);
3207 g_return_if_fail (GDK_IS_WINDOW (window));
3209 if (GDK_WINDOW_DESTROYED (window))
3212 private = (GdkWindowObject*) window;
3214 if (GDK_WINDOW_IS_MAPPED (window))
3216 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3217 GDK_WINDOW_XWINDOW (window),
3218 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3222 /* Flip our client side flag, the real work happens on map. */
3223 gdk_synthesize_window_state (window,
3225 GDK_WINDOW_STATE_ICONIFIED);
3230 * gdk_window_deiconify:
3231 * @window: a #GdkWindow
3233 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3234 * choose to ignore the request to deiconify. When using GTK+,
3235 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3236 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3237 * unminimizes it, and puts it on the current desktop.
3241 gdk_window_deiconify (GdkWindow *window)
3243 GdkWindowObject *private;
3245 g_return_if_fail (window != NULL);
3246 g_return_if_fail (GDK_IS_WINDOW (window));
3248 if (GDK_WINDOW_DESTROYED (window))
3251 private = (GdkWindowObject*) window;
3253 if (GDK_WINDOW_IS_MAPPED (window))
3255 gdk_window_show (window);
3259 /* Flip our client side flag, the real work happens on map. */
3260 gdk_synthesize_window_state (window,
3261 GDK_WINDOW_STATE_ICONIFIED,
3268 * @window: a toplevel #GdkWindow
3270 * "Pins" a window such that it's on all workspaces and does not scroll
3271 * with viewports, for window managers that have scrollable viewports.
3272 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3274 * On the X11 platform, this function depends on window manager
3275 * support, so may have no effect with many window managers. However,
3276 * GDK will do the best it can to convince the window manager to stick
3277 * the window. For window managers that don't support this operation,
3278 * there's nothing you can do to force it to happen.
3282 gdk_window_stick (GdkWindow *window)
3284 g_return_if_fail (GDK_IS_WINDOW (window));
3286 if (GDK_WINDOW_DESTROYED (window))
3289 if (GDK_WINDOW_IS_MAPPED (window))
3291 /* "stick" means stick to all desktops _and_ do not scroll with the
3292 * viewport. i.e. glue to the monitor glass in all cases.
3297 /* Request stick during viewport scroll */
3298 gdk_wmspec_change_state (TRUE, window,
3299 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3302 /* Request desktop 0xFFFFFFFF */
3303 xev.xclient.type = ClientMessage;
3304 xev.xclient.serial = 0;
3305 xev.xclient.send_event = True;
3306 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3307 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3308 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3310 xev.xclient.format = 32;
3312 xev.xclient.data.l[0] = 0xFFFFFFFF;
3314 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3315 SubstructureRedirectMask | SubstructureNotifyMask,
3320 /* Flip our client side flag, the real work happens on map. */
3321 gdk_synthesize_window_state (window,
3323 GDK_WINDOW_STATE_STICKY);
3328 * gdk_window_unstick:
3329 * @window: a toplevel #GdkWindow
3331 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3332 * and gtk_window_unstick().
3336 gdk_window_unstick (GdkWindow *window)
3338 g_return_if_fail (GDK_IS_WINDOW (window));
3340 if (GDK_WINDOW_DESTROYED (window))
3343 if (GDK_WINDOW_IS_MAPPED (window))
3350 gulong *current_desktop;
3351 GdkDisplay *display = gdk_drawable_get_display (window);
3353 /* Request unstick from viewport */
3354 gdk_wmspec_change_state (FALSE, window,
3355 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3358 /* Get current desktop, then set it; this is a race, but not
3359 * one that matters much in practice.
3361 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
3362 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
3364 False, XA_CARDINAL, &type, &format, &nitems,
3365 &bytes_after, (guchar **)¤t_desktop);
3367 if (type == XA_CARDINAL)
3369 xev.xclient.type = ClientMessage;
3370 xev.xclient.serial = 0;
3371 xev.xclient.send_event = True;
3372 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3373 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
3374 xev.xclient.format = 32;
3376 xev.xclient.data.l[0] = *current_desktop;
3378 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3379 SubstructureRedirectMask | SubstructureNotifyMask,
3382 XFree (current_desktop);
3387 /* Flip our client side flag, the real work happens on map. */
3388 gdk_synthesize_window_state (window,
3389 GDK_WINDOW_STATE_STICKY,
3396 * gdk_window_maximize:
3397 * @window: a #GdkWindow
3399 * Maximizes the window. If the window was already maximized, then
3400 * this function does nothing.
3402 * On X11, asks the window manager to maximize @window, if the window
3403 * manager supports this operation. Not all window managers support
3404 * this, and some deliberately ignore it or don't have a concept of
3405 * "maximized"; so you can't rely on the maximization actually
3406 * happening. But it will happen with most standard window managers,
3407 * and GDK makes a best effort to get it to happen.
3409 * On Windows, reliably maximizes the window.
3413 gdk_window_maximize (GdkWindow *window)
3415 g_return_if_fail (GDK_IS_WINDOW (window));
3417 if (GDK_WINDOW_DESTROYED (window))
3420 if (GDK_WINDOW_IS_MAPPED (window))
3421 gdk_wmspec_change_state (TRUE, window,
3422 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3423 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3425 gdk_synthesize_window_state (window,
3427 GDK_WINDOW_STATE_MAXIMIZED);
3431 * gdk_window_unmaximize:
3432 * @window: a #GdkWindow
3434 * Unmaximizes the window. If the window wasn't maximized, then this
3435 * function does nothing.
3437 * On X11, asks the window manager to unmaximize @window, if the
3438 * window manager supports this operation. Not all window managers
3439 * support this, and some deliberately ignore it or don't have a
3440 * concept of "maximized"; so you can't rely on the unmaximization
3441 * actually happening. But it will happen with most standard window
3442 * managers, and GDK makes a best effort to get it to happen.
3444 * On Windows, reliably unmaximizes the window.
3448 gdk_window_unmaximize (GdkWindow *window)
3450 g_return_if_fail (GDK_IS_WINDOW (window));
3452 if (GDK_WINDOW_DESTROYED (window))
3455 if (GDK_WINDOW_IS_MAPPED (window))
3456 gdk_wmspec_change_state (FALSE, window,
3457 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3458 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3460 gdk_synthesize_window_state (window,
3461 GDK_WINDOW_STATE_MAXIMIZED,
3466 * gdk_window_fullscreen:
3467 * @window: a #GdkWindow
3469 * Moves the window into fullscreen mode. This means the
3470 * window covers the entire screen and is above any panels
3473 * If the window was already fullscreen, then this function does nothing.
3475 * On X11, asks the window manager to put @window in a fullscreen
3476 * state, if the window manager supports this operation. Not all
3477 * window managers support this, and some deliberately ignore it or
3478 * don't have a concept of "fullscreen"; so you can't rely on the
3479 * fullscreenification actually happening. But it will happen with
3480 * most standard window managers, and GDK makes a best effort to get
3485 gdk_window_fullscreen (GdkWindow *window)
3487 g_return_if_fail (GDK_IS_WINDOW (window));
3489 if (GDK_WINDOW_DESTROYED (window))
3492 if (GDK_WINDOW_IS_MAPPED (window))
3493 gdk_wmspec_change_state (TRUE, window,
3494 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3498 gdk_synthesize_window_state (window,
3500 GDK_WINDOW_STATE_FULLSCREEN);
3504 * gdk_window_unfullscreen:
3505 * @window: a #GdkWindow
3507 * Moves the window out of fullscreen mode. If the window was not
3508 * fullscreen, does nothing.
3510 * On X11, asks the window manager to move @window out of the fullscreen
3511 * state, if the window manager supports this operation. Not all
3512 * window managers support this, and some deliberately ignore it or
3513 * don't have a concept of "fullscreen"; so you can't rely on the
3514 * unfullscreenification actually happening. But it will happen with
3515 * most standard window managers, and GDK makes a best effort to get
3520 gdk_window_unfullscreen (GdkWindow *window)
3522 g_return_if_fail (GDK_IS_WINDOW (window));
3524 if (GDK_WINDOW_DESTROYED (window))
3527 if (GDK_WINDOW_IS_MAPPED (window))
3528 gdk_wmspec_change_state (FALSE, window,
3529 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3533 gdk_synthesize_window_state (window,
3534 GDK_WINDOW_STATE_FULLSCREEN,
3540 * gdk_window_set_group:
3541 * @window: a #GdkWindow
3542 * @leader: group leader window
3544 * Sets the group leader window for @window. By default,
3545 * GDK sets the group leader for all toplevel windows
3546 * to a global window implicitly created by GDK. With this function
3547 * you can override this default.
3549 * The group leader window allows the window manager to distinguish
3550 * all windows that belong to a single application. It may for example
3551 * allow users to minimize/unminimize all windows belonging to an
3552 * application at once. You should only set a non-default group window
3553 * if your application pretends to be multiple applications.
3554 * The group leader window may not be changed after a window has been
3555 * mapped (with gdk_window_show() for example).
3559 gdk_window_set_group (GdkWindow *window,
3564 g_return_if_fail (window != NULL);
3565 g_return_if_fail (GDK_IS_WINDOW (window));
3566 g_return_if_fail (leader != NULL);
3567 g_return_if_fail (GDK_IS_WINDOW (leader));
3569 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3572 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3573 GDK_WINDOW_XID (window));
3575 wm_hints = XAllocWMHints ();
3577 wm_hints->flags |= WindowGroupHint;
3578 wm_hints->window_group = GDK_WINDOW_XID (leader);
3580 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3581 GDK_WINDOW_XID (window), wm_hints);
3585 static MotifWmHints *
3586 gdk_window_get_mwm_hints (GdkWindow *window)
3588 GdkDisplay *display;
3589 Atom hints_atom = None;
3590 MotifWmHints *hints;
3596 if (GDK_WINDOW_DESTROYED (window))
3599 display = gdk_drawable_get_display (window);
3601 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3603 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3604 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3605 False, AnyPropertyType, &type, &format, &nitems,
3606 &bytes_after, (guchar **)&hints);
3615 gdk_window_set_mwm_hints (GdkWindow *window,
3616 MotifWmHints *new_hints)
3618 GdkDisplay *display;
3619 Atom hints_atom = None;
3620 MotifWmHints *hints;
3626 if (GDK_WINDOW_DESTROYED (window))
3629 display = gdk_drawable_get_display (window);
3631 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3633 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3634 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3635 False, AnyPropertyType, &type, &format, &nitems,
3636 &bytes_after, (guchar **)&hints);
3642 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3644 hints->flags |= MWM_HINTS_FUNCTIONS;
3645 hints->functions = new_hints->functions;
3647 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3649 hints->flags |= MWM_HINTS_DECORATIONS;
3650 hints->decorations = new_hints->decorations;
3654 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3655 hints_atom, hints_atom, 32, PropModeReplace,
3656 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3658 if (hints != new_hints)
3663 * gdk_window_set_decorations:
3664 * @window: a #GdkWindow
3665 * @decorations: decoration hint mask
3667 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3668 * This function sets the traditional Motif window manager hints that tell the
3669 * window manager which decorations you would like your window to have.
3670 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3671 * using the GDK function directly.
3673 * The @decorations argument is the logical OR of the fields in
3674 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3675 * mask, the other bits indicate which decorations should be turned off.
3676 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3677 * which decorations should be turned on.
3679 * Most window managers honor a decorations hint of 0 to disable all decorations,
3680 * but very few honor all possible combinations of bits.
3684 gdk_window_set_decorations (GdkWindow *window,
3685 GdkWMDecoration decorations)
3689 g_return_if_fail (window != NULL);
3690 g_return_if_fail (GDK_IS_WINDOW (window));
3692 hints.flags = MWM_HINTS_DECORATIONS;
3693 hints.decorations = decorations;
3695 gdk_window_set_mwm_hints (window, &hints);
3699 * gdk_window_get_decorations:
3700 * @window: The #GdkWindow to get the decorations from
3701 * @decorations: The window decorations will be written here
3703 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3704 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3707 gdk_window_get_decorations(GdkWindow *window,
3708 GdkWMDecoration *decorations)
3710 MotifWmHints *hints;
3711 gboolean result = FALSE;
3713 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3715 hints = gdk_window_get_mwm_hints (window);
3719 if (hints->flags & MWM_HINTS_DECORATIONS)
3722 *decorations = hints->decorations;
3733 * gdk_window_set_functions:
3734 * @window: a #GdkWindow
3735 * @functions: bitmask of operations to allow on @window
3737 * This function isn't really good for much. It sets the traditional
3738 * Motif window manager hint for which operations the window manager
3739 * should allow on a toplevel window. However, few window managers do
3740 * anything reliable or interesting with this hint. Many ignore it
3743 * The @functions argument is the logical OR of values from the
3744 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3745 * then the other bits indicate which functions to disable; if
3746 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3751 gdk_window_set_functions (GdkWindow *window,
3752 GdkWMFunction functions)
3756 g_return_if_fail (window != NULL);
3757 g_return_if_fail (GDK_IS_WINDOW (window));
3759 hints.flags = MWM_HINTS_FUNCTIONS;
3760 hints.functions = functions;
3762 gdk_window_set_mwm_hints (window, &hints);
3765 #ifdef HAVE_SHAPE_EXT
3768 * propagate the shapes from all child windows of a GDK window to the parent
3769 * window. Shamelessly ripped from Enlightenment's code
3777 struct _gdk_span *next;
3781 gdk_add_to_span (struct _gdk_span **s,
3785 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3792 /* scan the spans for this line */
3795 /* -- -> new span */
3796 /* == -> existing span */
3797 /* ## -> spans intersect */
3798 /* if we are in the middle of spanning the span into the line */
3801 /* case: ---- ==== */
3802 if (xx < ptr1->start - 1)
3804 /* ends before next span - extend to here */
3808 /* case: ----##=== */
3809 else if (xx <= ptr1->end)
3811 /* crosses into next span - delete next span and append */
3812 ss->end = ptr1->end;
3813 ss->next = ptr1->next;
3817 /* case: ---###--- */
3820 /* overlaps next span - delete and keep checking */
3821 ss->next = ptr1->next;
3826 /* otherwise havent started spanning it in yet */
3829 /* case: ---- ==== */
3830 if (xx < ptr1->start - 1)
3832 /* insert span here in list */
3833 noo = g_malloc (sizeof (struct _gdk_span));
3847 /* case: ----##=== */
3848 else if ((x < ptr1->start) && (xx <= ptr1->end))
3850 /* expand this span to the left point of the new one */
3854 /* case: ===###=== */
3855 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3857 /* throw the span away */
3860 /* case: ---###--- */
3861 else if ((x < ptr1->start) && (xx > ptr1->end))
3868 /* case: ===##---- */
3869 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3875 /* case: ==== ---- */
3876 /* case handled by next loop iteration - first case */
3881 /* it started in the middle but spans beyond your current list */
3887 /* it does not start inside a span or in the middle, so add it to the end */
3888 noo = g_malloc (sizeof (struct _gdk_span));
3896 noo->next = ptr2->next;
3909 gdk_add_rectangles (Display *disp,
3911 struct _gdk_span **spans,
3918 gint x1, y1, x2, y2;
3922 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
3925 /* go through all clip rects in this window's shape */
3926 for (k = 0; k < rn; k++)
3928 /* for each clip rect, add it to each line's spans */
3930 x2 = x + rl[k].x + (rl[k].width - 1);
3932 y2 = y + rl[k].y + (rl[k].height - 1);
3941 for (a = y1; a <= y2; a++)
3944 gdk_add_to_span (&spans[a], x1, x2);
3952 gdk_propagate_shapes (Display *disp,
3956 Window rt, par, *list = NULL;
3957 gint i, j, num = 0, num_rects = 0;
3961 XRectangle *rects = NULL;
3962 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
3963 XWindowAttributes xatt;
3965 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
3970 spans = g_malloc (sizeof (struct _gdk_span *) * h);
3972 for (i = 0; i < h; i++)
3974 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
3977 /* go through all child windows and create/insert spans */
3978 for (i = 0; i < num; i++)
3980 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
3981 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
3982 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
3985 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
3987 /* go through the spans list and build a list of rects */
3988 rects = g_malloc (sizeof (XRectangle) * 256);
3990 for (i = 0; i < baseh; i++)
3993 /* go through the line for all spans */
3996 rects[num_rects].x = ptr1->start;
3997 rects[num_rects].y = i;
3998 rects[num_rects].width = ptr1->end - ptr1->start + 1;
3999 rects[num_rects].height = 1;
4001 /* if there are more lines */
4003 /* while contigous rects (same start/end coords) exist */
4004 while ((contig) && (j < baseh))
4006 /* search next line for spans matching this one */
4012 /* if we have an exact span match set contig */
4013 if ((ptr2->start == ptr1->start) &&
4014 (ptr2->end == ptr1->end))
4017 /* remove the span - not needed */
4020 ptr3->next = ptr2->next;
4026 spans[j] = ptr2->next;
4032 /* gone past the span point no point looking */
4033 else if (ptr2->start < ptr1->start)
4041 /* if a contiguous span was found increase the rect h */
4044 rects[num_rects].height++;
4048 /* up the rect count */
4050 /* every 256 new rects increase the rect array */
4051 if ((num_rects % 256) == 0)
4052 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
4056 /* set the rects as the shape mask */
4059 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
4060 ShapeSet, YXSorted);
4065 /* free up all the spans we made */
4066 for (i = 0; i < baseh; i++)
4079 #endif /* HAVE_SHAPE_EXT */
4082 * gdk_window_set_child_shapes:
4083 * @window: a #GdkWindow
4085 * Sets the shape mask of @window to the union of shape masks
4086 * for all children of @window, ignoring the shape mask of @window
4087 * itself. Contrast with gdk_window_merge_child_shapes() which includes
4088 * the shape mask of @window in the masks to be merged.
4091 gdk_window_set_child_shapes (GdkWindow *window)
4093 g_return_if_fail (window != NULL);
4094 g_return_if_fail (GDK_IS_WINDOW (window));
4096 #ifdef HAVE_SHAPE_EXT
4097 if (!GDK_WINDOW_DESTROYED (window) &&
4098 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4099 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4100 GDK_WINDOW_XID (window), FALSE);
4105 * gdk_window_merge_child_shapes:
4106 * @window: a #GdkWindow
4108 * Merges the shape masks for any child windows into the
4109 * shape mask for @window. i.e. the union of all masks
4110 * for @window and its children will become the new mask
4111 * for @window. See gdk_window_shape_combine_mask().
4113 * This function is distinct from gdk_window_set_child_shapes()
4114 * because it includes @window's shape mask in the set of shapes to
4119 gdk_window_merge_child_shapes (GdkWindow *window)
4121 g_return_if_fail (window != NULL);
4122 g_return_if_fail (GDK_IS_WINDOW (window));
4124 #ifdef HAVE_SHAPE_EXT
4125 if (!GDK_WINDOW_DESTROYED (window) &&
4126 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4127 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4128 GDK_WINDOW_XID (window), TRUE);
4132 /* Support for windows that can be guffaw-scrolled
4133 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
4137 gdk_window_gravity_works (GdkWindow *window)
4139 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (window));
4141 if (display_x11->gravity_works == GDK_UNKNOWN)
4148 /* This particular server apparently has a bug so that the test
4149 * works but the actual code crashes it
4151 if ((!strcmp (XServerVendor (display_x11->xdisplay),
4152 "Sun Microsystems, Inc.")) &&
4153 (VendorRelease (display_x11->xdisplay) == 3400))
4155 display_x11->gravity_works = GDK_NO;
4159 attr.window_type = GDK_WINDOW_TEMP;
4160 attr.wclass = GDK_INPUT_OUTPUT;
4165 attr.event_mask = 0;
4167 parent = gdk_window_new (gdk_screen_get_root_window (GDK_DRAWABLE_SCREEN (window)),
4168 &attr, GDK_WA_X | GDK_WA_Y);
4170 attr.window_type = GDK_WINDOW_CHILD;
4171 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
4173 gdk_window_set_static_win_gravity (child, TRUE);
4175 gdk_window_resize (parent, 100, 110);
4177 gdk_window_move (parent, 0, -10);
4178 gdk_window_move_resize (parent, 0, 0, 100, 100);
4180 gdk_window_resize (parent, 100, 110);
4181 gdk_window_move (parent, 0, -10);
4182 gdk_window_move_resize (parent, 0, 0, 100, 100);
4184 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
4186 gdk_window_destroy (parent);
4187 gdk_window_destroy (child);
4189 display_x11->gravity_works = ((y == -20) ? GDK_YES : GDK_NO);
4192 return (display_x11->gravity_works == GDK_YES);
4196 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
4198 XSetWindowAttributes xattributes;
4199 GdkWindowObject *private;
4200 guint xattributes_mask = 0;
4202 g_return_if_fail (window != NULL);
4204 private = GDK_WINDOW_OBJECT (window);
4205 if (private->input_only)
4208 xattributes.bit_gravity = StaticGravity;
4209 xattributes_mask |= CWBitGravity;
4210 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4211 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4212 GDK_WINDOW_XID (window),
4213 CWBitGravity, &xattributes);
4217 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4219 XSetWindowAttributes xattributes;
4221 g_return_if_fail (window != NULL);
4223 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4225 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4226 GDK_WINDOW_XID (window),
4227 CWWinGravity, &xattributes);
4231 * gdk_window_set_static_gravities:
4232 * @window: a #GdkWindow
4233 * @use_static: %TRUE to turn on static gravity
4235 * Set the bit gravity of the given window to static, and flag it so
4236 * all children get static subwindow gravity. This is used if you are
4237 * implementing scary features that involve deep knowledge of the
4238 * windowing system. Don't worry about it unless you have to.
4240 * Return value: %TRUE if the server supports static gravity
4243 gdk_window_set_static_gravities (GdkWindow *window,
4244 gboolean use_static)
4246 GdkWindowObject *private = (GdkWindowObject *)window;
4249 g_return_val_if_fail (window != NULL, FALSE);
4250 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4252 if (!use_static == !private->guffaw_gravity)
4255 if (use_static && !gdk_window_gravity_works (window))
4258 private->guffaw_gravity = use_static;
4260 if (!GDK_WINDOW_DESTROYED (window))
4262 gdk_window_set_static_bit_gravity (window, use_static);
4264 tmp_list = private->children;
4267 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4269 tmp_list = tmp_list->next;
4277 wmspec_moveresize (GdkWindow *window,
4283 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4287 /* Release passive grab */
4288 gdk_display_pointer_ungrab (display, timestamp);
4290 xev.xclient.type = ClientMessage;
4291 xev.xclient.serial = 0;
4292 xev.xclient.send_event = True;
4293 xev.xclient.window = GDK_WINDOW_XID (window);
4294 xev.xclient.message_type =
4295 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4296 xev.xclient.format = 32;
4297 xev.xclient.data.l[0] = root_x;
4298 xev.xclient.data.l[1] = root_y;
4299 xev.xclient.data.l[2] = direction;
4300 xev.xclient.data.l[3] = 0;
4301 xev.xclient.data.l[4] = 0;
4303 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4304 SubstructureRedirectMask | SubstructureNotifyMask,
4308 typedef struct _MoveResizeData MoveResizeData;
4310 struct _MoveResizeData
4312 GdkDisplay *display;
4314 GdkWindow *moveresize_window;
4315 GdkWindow *moveresize_emulation_window;
4317 GdkWindowEdge resize_edge;
4318 gint moveresize_button;
4321 gint moveresize_orig_x;
4322 gint moveresize_orig_y;
4323 gint moveresize_orig_width;
4324 gint moveresize_orig_height;
4325 GdkWindowHints moveresize_geom_mask;
4326 GdkGeometry moveresize_geometry;
4327 Time moveresize_process_time;
4328 XEvent *moveresize_pending_event;
4331 /* From the WM spec */
4332 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4333 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4334 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4335 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4336 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4337 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4338 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4339 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4340 #define _NET_WM_MOVERESIZE_MOVE 8
4343 wmspec_resize_drag (GdkWindow *window,
4352 /* Let the compiler turn a switch into a table, instead
4353 * of doing the table manually, this way is easier to verify.
4357 case GDK_WINDOW_EDGE_NORTH_WEST:
4358 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4361 case GDK_WINDOW_EDGE_NORTH:
4362 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4365 case GDK_WINDOW_EDGE_NORTH_EAST:
4366 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4369 case GDK_WINDOW_EDGE_WEST:
4370 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4373 case GDK_WINDOW_EDGE_EAST:
4374 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4377 case GDK_WINDOW_EDGE_SOUTH_WEST:
4378 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4381 case GDK_WINDOW_EDGE_SOUTH:
4382 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4385 case GDK_WINDOW_EDGE_SOUTH_EAST:
4386 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4390 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4396 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4399 static MoveResizeData *
4400 get_move_resize_data (GdkDisplay *display,
4403 MoveResizeData *mv_resize;
4404 static GQuark move_resize_quark = 0;
4406 if (!move_resize_quark)
4407 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4409 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4411 if (!mv_resize && create)
4413 mv_resize = g_new0 (MoveResizeData, 1);
4414 mv_resize->display = display;
4416 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4423 update_pos (MoveResizeData *mv_resize,
4429 dx = new_root_x - mv_resize->moveresize_x;
4430 dy = new_root_y - mv_resize->moveresize_y;
4432 if (mv_resize->is_resize)
4436 w = mv_resize->moveresize_orig_width;
4437 h = mv_resize->moveresize_orig_height;
4439 switch (mv_resize->resize_edge)
4441 case GDK_WINDOW_EDGE_SOUTH_EAST:
4450 if (mv_resize->moveresize_geom_mask)
4452 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4453 mv_resize->moveresize_geom_mask,
4457 gdk_window_resize (mv_resize->moveresize_window, w, h);
4463 x = mv_resize->moveresize_orig_x + dx;
4464 y = mv_resize->moveresize_orig_y + dy;
4466 gdk_window_move (mv_resize->moveresize_window, x, y);
4471 finish_drag (MoveResizeData *mv_resize)
4473 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4474 mv_resize->moveresize_emulation_window = NULL;
4475 mv_resize->moveresize_window = NULL;
4477 if (mv_resize->moveresize_pending_event)
4479 g_free (mv_resize->moveresize_pending_event);
4480 mv_resize->moveresize_pending_event = NULL;
4485 lookahead_motion_predicate (Display *xdisplay,
4489 gboolean *seen_release = (gboolean *)arg;
4490 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4491 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4496 switch (event->xany.type)
4499 *seen_release = TRUE;
4502 mv_resize->moveresize_process_time = event->xmotion.time;
4512 moveresize_lookahead (MoveResizeData *mv_resize,
4516 gboolean seen_release = FALSE;
4518 if (mv_resize->moveresize_process_time)
4520 if (event->xmotion.time == mv_resize->moveresize_process_time)
4522 mv_resize->moveresize_process_time = 0;
4529 XCheckIfEvent (event->xany.display, &tmp_event,
4530 lookahead_motion_predicate, (XPointer) & seen_release);
4532 return mv_resize->moveresize_process_time == 0;
4536 _gdk_moveresize_handle_event (XEvent *event)
4538 guint button_mask = 0;
4539 GdkWindowObject *window_private;
4540 GdkDisplay *display= gdk_x11_lookup_xdisplay (event->xany.display);
4541 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4543 if (!mv_resize || mv_resize->moveresize_window)
4546 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
4548 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4550 switch (event->xany.type)
4553 if (window_private->resize_count > 0)
4555 if (mv_resize->moveresize_pending_event)
4556 *mv_resize->moveresize_pending_event = *event;
4558 mv_resize->moveresize_pending_event =
4559 g_memdup (event, sizeof (XEvent));
4563 if (!moveresize_lookahead (mv_resize, event))
4566 update_pos (mv_resize,
4567 event->xmotion.x_root,
4568 event->xmotion.y_root);
4570 /* This should never be triggered in normal cases, but in the
4571 * case where the drag started without an implicit grab being
4572 * in effect, we could miss the release if it occurs before
4573 * we grab the pointer; this ensures that we will never
4574 * get a permanently stuck grab.
4576 if ((event->xmotion.state & button_mask) == 0)
4577 finish_drag (mv_resize);
4581 update_pos (mv_resize,
4582 event->xbutton.x_root,
4583 event->xbutton.y_root);
4585 if (event->xbutton.button == mv_resize->moveresize_button)
4586 finish_drag (mv_resize);
4593 _gdk_moveresize_configure_done (GdkDisplay *display,
4597 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4599 if (!mv_resize || window != mv_resize->moveresize_window)
4602 if (mv_resize->moveresize_pending_event)
4604 tmp_event = mv_resize->moveresize_pending_event;
4605 mv_resize->moveresize_pending_event = NULL;
4606 _gdk_moveresize_handle_event (tmp_event);
4614 create_moveresize_window (MoveResizeData *mv_resize,
4617 GdkWindowAttr attributes;
4618 gint attributes_mask;
4619 GdkGrabStatus status;
4621 g_assert (mv_resize->moveresize_emulation_window == NULL);
4623 attributes.x = -100;
4624 attributes.y = -100;
4625 attributes.width = 10;
4626 attributes.height = 10;
4627 attributes.window_type = GDK_WINDOW_TEMP;
4628 attributes.wclass = GDK_INPUT_ONLY;
4629 attributes.override_redirect = TRUE;
4630 attributes.event_mask = 0;
4632 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4634 mv_resize->moveresize_emulation_window =
4635 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4639 gdk_window_show (mv_resize->moveresize_emulation_window);
4641 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4643 GDK_BUTTON_RELEASE_MASK |
4644 GDK_POINTER_MOTION_MASK,
4649 if (status != GDK_GRAB_SUCCESS)
4651 /* If this fails, some other client has grabbed the window
4654 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4655 mv_resize->moveresize_emulation_window = NULL;
4658 mv_resize->moveresize_process_time = 0;
4662 emulate_resize_drag (GdkWindow *window,
4669 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4671 mv_resize->is_resize = TRUE;
4672 mv_resize->moveresize_button = button;
4673 mv_resize->resize_edge = edge;
4674 mv_resize->moveresize_x = root_x;
4675 mv_resize->moveresize_y = root_y;
4676 mv_resize->moveresize_window = g_object_ref (window);
4678 gdk_drawable_get_size (window,
4679 &mv_resize->moveresize_orig_width,
4680 &mv_resize->moveresize_orig_height);
4682 mv_resize->moveresize_geom_mask = 0;
4683 gdk_window_get_geometry_hints (window,
4684 &mv_resize->moveresize_geometry,
4685 &mv_resize->moveresize_geom_mask);
4687 create_moveresize_window (mv_resize, timestamp);
4691 emulate_move_drag (GdkWindow *window,
4697 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4699 mv_resize->is_resize = FALSE;
4700 mv_resize->moveresize_button = button;
4701 mv_resize->moveresize_x = root_x;
4702 mv_resize->moveresize_y = root_y;
4704 mv_resize->moveresize_window = g_object_ref (window);
4706 gdk_window_get_deskrelative_origin (mv_resize->moveresize_window,
4707 &mv_resize->moveresize_orig_x,
4708 &mv_resize->moveresize_orig_y);
4710 create_moveresize_window (mv_resize, timestamp);
4714 * gdk_window_begin_resize_drag:
4715 * @window: a #GdkWindow
4716 * @edge: the edge or corner from which the drag is started
4717 * @button: the button being used to drag
4718 * @root_x: root window X coordinate of mouse click that began the drag
4719 * @root_y: root window Y coordinate of mouse click that began the drag
4720 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4722 * Begins a window resize operation (for a toplevel window).
4723 * You might use this function to implement a "window resize grip," for
4724 * example; in fact #GtkStatusbar uses it. The function works best
4725 * with window managers that support the Extended Window Manager Hints spec
4726 * (see http://www.freedesktop.org), but has a fallback implementation
4727 * for other window managers.
4731 gdk_window_begin_resize_drag (GdkWindow *window,
4738 g_return_if_fail (GDK_IS_WINDOW (window));
4740 if (GDK_WINDOW_DESTROYED (window))
4743 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4744 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4745 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4747 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4751 * gdk_window_begin_move_drag:
4752 * @window: a #GdkWindow
4753 * @button: the button being used to drag
4754 * @root_x: root window X coordinate of mouse click that began the drag
4755 * @root_y: root window Y coordinate of mouse click that began the drag
4756 * @timestamp: timestamp of mouse click that began the drag
4758 * Begins a window move operation (for a toplevel window). You might
4759 * use this function to implement a "window move grip," for
4760 * example. The function works best with window managers that support
4761 * the Extended Window Manager Hints spec (see
4762 * http://www.freedesktop.org), but has a fallback implementation for
4763 * other window managers.
4767 gdk_window_begin_move_drag (GdkWindow *window,
4773 g_return_if_fail (GDK_IS_WINDOW (window));
4775 if (GDK_WINDOW_DESTROYED (window))
4778 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4779 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4780 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
4783 emulate_move_drag (window, button, root_x, root_y, timestamp);