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_xid_table_insert (screen_x11->display,
317 &screen_x11->xroot_window,
318 screen_x11->root_window);
322 set_wm_protocols (GdkWindow *window)
324 GdkDisplay *display = gdk_drawable_get_display (window);
327 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
328 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
329 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
331 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
336 * @parent: a #GdkWindow, or %NULL to create the window as a child of
337 * the default root window for the default display.
338 * @attributes: attributes of the new window
339 * @attributes_mask: mask indicating which fields in @attributes are valid
341 * Creates a new #GdkWindow using the attributes from
342 * @attributes. Seep #GdkWindowAttr and #GdkWindowAttributesType for
343 * more details. Note: to use this on displays other than the default
344 * display, @parent must be specified.
346 * Return value: the new #GdkWindow
349 gdk_window_new (GdkWindow *parent,
350 GdkWindowAttr *attributes,
351 gint attributes_mask)
354 GdkWindowObject *private;
355 GdkWindowImplX11 *impl;
356 GdkDrawableImplX11 *draw_impl;
357 GdkScreenX11 *screen_x11;
366 XSetWindowAttributes xattributes;
367 long xattributes_mask;
368 XSizeHints size_hints;
370 XClassHint *class_hint;
378 g_return_val_if_fail (attributes != NULL, NULL);
383 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
385 screen = gdk_screen_get_default ();
386 parent = gdk_screen_get_root_window (screen);
389 screen = gdk_drawable_get_screen (parent);
391 screen_x11 = GDK_SCREEN_X11 (screen);
393 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
395 if (GDK_WINDOW_DESTROYED (parent))
398 xparent = GDK_WINDOW_XID (parent);
400 window = g_object_new (GDK_TYPE_WINDOW, NULL);
401 private = (GdkWindowObject *)window;
402 impl = GDK_WINDOW_IMPL_X11 (private->impl);
403 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
404 draw_impl->wrapper = GDK_DRAWABLE (window);
406 draw_impl->screen = screen;
407 xdisplay = screen_x11->xdisplay;
409 /* Windows with a foreign parent are treated as if they are children
410 * of the root window, except for actual creation.
412 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
413 parent = gdk_screen_get_root_window (screen);
415 private->parent = (GdkWindowObject *)parent;
417 xattributes_mask = 0;
419 if (attributes_mask & GDK_WA_X)
424 if (attributes_mask & GDK_WA_Y)
431 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
432 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
434 if (attributes->wclass == GDK_INPUT_ONLY)
436 /* Backwards compatiblity - we've always ignored
437 * attributes->window_type for input-only windows
440 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
441 private->window_type = GDK_WINDOW_TEMP;
443 private->window_type = GDK_WINDOW_CHILD;
446 private->window_type = attributes->window_type;
448 _gdk_window_init_position (GDK_WINDOW (private));
449 if (impl->position_info.big)
450 private->guffaw_gravity = TRUE;
452 if (attributes_mask & GDK_WA_VISUAL)
453 visual = attributes->visual;
455 visual = gdk_screen_get_system_visual (screen);
456 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
458 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
459 for (i = 0; i < _gdk_nenvent_masks; i++)
461 if (attributes->event_mask & (1 << (i + 1)))
462 xattributes.event_mask |= _gdk_event_mask_table[i];
464 private->event_mask = attributes->event_mask;
466 if (xattributes.event_mask)
467 xattributes_mask |= CWEventMask;
469 if (attributes_mask & GDK_WA_NOREDIR)
471 xattributes.override_redirect =
472 (attributes->override_redirect == FALSE)?False:True;
473 xattributes_mask |= CWOverrideRedirect;
476 xattributes.override_redirect = False;
478 if (private->parent && private->parent->guffaw_gravity)
480 xattributes.win_gravity = StaticGravity;
481 xattributes_mask |= CWWinGravity;
485 switch (private->window_type)
487 case GDK_WINDOW_TOPLEVEL:
488 case GDK_WINDOW_DIALOG:
489 case GDK_WINDOW_TEMP:
490 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
492 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
493 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
494 xparent = GDK_SCREEN_XROOTWIN (screen);
496 case GDK_WINDOW_CHILD:
499 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
503 if (attributes->wclass == GDK_INPUT_OUTPUT)
506 depth = visual->depth;
508 private->input_only = FALSE;
509 private->depth = depth;
511 if (attributes_mask & GDK_WA_COLORMAP)
513 draw_impl->colormap = attributes->colormap;
514 g_object_ref (attributes->colormap);
518 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
520 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
521 g_object_ref (draw_impl->colormap);
525 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
529 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
530 xattributes.background_pixel = private->bg_color.pixel;
532 private->bg_pixmap = NULL;
534 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
535 xattributes_mask |= CWBorderPixel | CWBackPixel;
537 if (private->guffaw_gravity)
538 xattributes.bit_gravity = StaticGravity;
540 xattributes.bit_gravity = NorthWestGravity;
542 xattributes_mask |= CWBitGravity;
544 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
545 xattributes_mask |= CWColormap;
547 if (private->window_type == GDK_WINDOW_TEMP)
549 xattributes.save_under = True;
550 xattributes.override_redirect = True;
551 xattributes.cursor = None;
552 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
560 private->input_only = TRUE;
561 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
562 g_object_ref (draw_impl->colormap);
565 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
566 impl->position_info.x, impl->position_info.y,
567 impl->position_info.width, impl->position_info.height,
568 0, depth, class, xvisual,
569 xattributes_mask, &xattributes);
571 g_object_ref (window);
572 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
574 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
575 (attributes->cursor) :
579 private->parent->children = g_list_prepend (private->parent->children, window);
581 switch (GDK_WINDOW_TYPE (private))
583 case GDK_WINDOW_DIALOG:
584 XSetTransientForHint (xdisplay, xid, xparent);
585 case GDK_WINDOW_TOPLEVEL:
586 case GDK_WINDOW_TEMP:
587 set_wm_protocols (window);
589 case GDK_WINDOW_CHILD:
590 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
591 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
592 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
594 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
595 gdk_window_add_colormap_windows (window);
604 if (class != InputOnly)
606 /* The focus window is off the visible area, and serves to receive key
607 * press events so they don't get sent to child windows.
609 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
611 xattributes.background_pixel,
612 xattributes.background_pixel);
613 /* FIXME: probably better to actually track the requested event mask for the toplevel
615 XSelectInput (xdisplay, impl->focus_window,
616 KeyPressMask | KeyReleaseMask | FocusChangeMask);
618 XMapWindow (xdisplay, impl->focus_window);
619 _gdk_xid_table_insert (screen_x11->display, &impl->focus_window, window);
622 size_hints.flags = PSize;
623 size_hints.width = impl->width;
624 size_hints.height = impl->height;
626 wm_hints.flags = StateHint | WindowGroupHint;
627 wm_hints.window_group = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
628 wm_hints.input = True;
629 wm_hints.initial_state = NormalState;
631 /* FIXME: Is there any point in doing this? Do any WM's pay
632 * attention to PSize, and even if they do, is this the
635 XSetWMNormalHints (xdisplay, xid, &size_hints);
637 XSetWMHints (xdisplay, xid, &wm_hints);
639 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
640 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
643 XChangeProperty (xdisplay, xid,
644 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
649 XChangeProperty (xdisplay, xid,
650 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
651 XA_WINDOW, 32, PropModeReplace,
652 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
654 if (attributes_mask & GDK_WA_TITLE)
655 title = attributes->title;
657 title = g_get_prgname ();
659 gdk_window_set_title (window, title);
661 if (attributes_mask & GDK_WA_WMCLASS)
663 class_hint = XAllocClassHint ();
664 class_hint->res_name = attributes->wmclass_name;
665 class_hint->res_class = attributes->wmclass_class;
666 XSetClassHint (xdisplay, xid, class_hint);
674 x_event_mask_to_gdk_event_mask (long mask)
676 GdkEventMask event_mask = 0;
679 for (i = 0; i < _gdk_nenvent_masks; i++)
681 if (mask & _gdk_event_mask_table[i])
682 event_mask |= 1 << (i + 1);
689 * gdk_window_foreign_new_for_display:
690 * @display: the #GdkDisplay where the window handle comes from.
691 * @anid: a native window handle.
693 * Wraps a native window in a #GdkWindow.
694 * This may fail if the window has been destroyed.
696 * For example in the X backend, a native window handle is an Xlib
699 * Return value: the newly-created #GdkWindow wrapper for the
700 * native window or %NULL if the window has been destroyed.
703 gdk_window_foreign_new_for_display (GdkDisplay *display,
704 GdkNativeWindow anid)
707 GdkWindowObject *private;
708 GdkWindowImplX11 *impl;
709 GdkDrawableImplX11 *draw_impl;
710 GdkDisplayX11 *display_x11;
711 XWindowAttributes attrs;
713 Window *children = NULL;
717 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
719 display_x11 = GDK_DISPLAY_X11 (display);
721 gdk_error_trap_push ();
722 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
723 if (gdk_error_trap_pop () || !result)
726 /* FIXME: This is pretty expensive. Maybe the caller should supply
728 gdk_error_trap_push ();
729 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
730 if (gdk_error_trap_pop () || !result)
736 window = g_object_new (GDK_TYPE_WINDOW, NULL);
737 private = (GdkWindowObject *)window;
738 impl = GDK_WINDOW_IMPL_X11 (private->impl);
739 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
740 draw_impl->wrapper = GDK_DRAWABLE (window);
741 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
743 private->parent = gdk_xid_table_lookup_for_display (display, parent);
745 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
746 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
748 private->parent->children = g_list_prepend (private->parent->children, window);
750 draw_impl->xid = anid;
752 private->x = attrs.x;
753 private->y = attrs.y;
754 impl->width = attrs.width;
755 impl->height = attrs.height;
756 private->window_type = GDK_WINDOW_FOREIGN;
757 private->destroyed = FALSE;
759 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
761 if (attrs.map_state == IsUnmapped)
762 private->state = GDK_WINDOW_STATE_WITHDRAWN;
766 private->depth = attrs.depth;
768 _gdk_window_init_position (GDK_WINDOW (private));
770 g_object_ref (window);
771 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
776 * gdk_window_lookup_for_display:
777 * @display: the #GdkDisplay corresponding to the window handle
778 * @anid: a native window handle.
780 * Looks up the #GdkWindow that wraps the given native window handle.
782 * For example in the X backend, a native window handle is an Xlib
785 * Return value: the #GdkWindow wrapper for the native window,
786 * or %NULL if there is none.
789 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
791 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
796 * @anid: a native window handle.
798 * Looks up the #GdkWindow that wraps the given native window handle.
800 * For example in the X backend, a native window handle is an Xlib
803 * Return value: the #GdkWindow wrapper for the native window,
804 * or %NULL if there is none.
807 gdk_window_lookup (GdkNativeWindow anid)
809 return (GdkWindow*) gdk_xid_table_lookup (anid);
813 _gdk_windowing_window_destroy (GdkWindow *window,
815 gboolean foreign_destroy)
817 GdkWindowObject *private = (GdkWindowObject *)window;
819 g_return_if_fail (GDK_IS_WINDOW (window));
821 _gdk_selection_window_destroyed (window);
823 if (private->extension_events != 0)
824 _gdk_input_window_destroy (window);
828 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
830 if (draw_impl->xft_draw)
831 XftDrawDestroy (draw_impl->xft_draw);
833 #endif /* HAVE_XFT */
835 if (private->window_type == GDK_WINDOW_FOREIGN)
837 if (!foreign_destroy && (private->parent != NULL))
839 /* It's somebody else's window, but in our heirarchy,
840 * so reparent it to the root window, and then send
841 * it a delete event, as if we were a WM
843 XClientMessageEvent xevent;
845 gdk_error_trap_push ();
846 gdk_window_hide (window);
847 gdk_window_reparent (window, NULL, 0, 0);
849 xevent.type = ClientMessage;
850 xevent.window = GDK_WINDOW_XID (window);
851 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
854 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
856 xevent.data.l[1] = CurrentTime;
858 XSendEvent (GDK_WINDOW_XDISPLAY (window),
859 GDK_WINDOW_XID (window),
860 False, 0, (XEvent *)&xevent);
861 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
862 gdk_error_trap_pop ();
865 else if (!recursing && !foreign_destroy)
867 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
871 /* This function is called when the XWindow is really gone.
874 gdk_window_destroy_notify (GdkWindow *window)
876 GdkWindowImplX11 *window_impl;
878 g_return_if_fail (window != NULL);
880 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
882 if (!GDK_WINDOW_DESTROYED (window))
884 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
885 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
887 _gdk_window_destroy (window, TRUE);
890 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
891 if (window_impl->focus_window)
892 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->focus_window);
894 _gdk_xgrab_check_destroy (window);
896 g_object_unref (window);
900 set_initial_hints (GdkWindow *window)
902 GdkWindowObject *private;
906 private = (GdkWindowObject*) window;
908 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
912 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
913 GDK_WINDOW_XID (window));
915 wm_hints = XAllocWMHints ();
917 wm_hints->flags |= StateHint;
918 wm_hints->initial_state = IconicState;
920 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
921 GDK_WINDOW_XID (window), wm_hints);
925 /* We set the spec hints regardless of whether the spec is supported,
926 * since it can't hurt and it's kind of expensive to check whether
932 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
934 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
935 "_NET_WM_STATE_MAXIMIZED_VERT");
937 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
938 "_NET_WM_STATE_MAXIMIZED_HORZ");
942 if (private->state & GDK_WINDOW_STATE_STICKY)
944 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
945 "_NET_WM_STATE_STICKY");
949 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
951 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
952 "_NET_WM_STATE_FULLSCREEN");
956 if (private->modal_hint)
958 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
959 "_NET_WM_STATE_MODAL");
965 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
966 GDK_WINDOW_XID (window),
967 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_STATE"),
968 XA_ATOM, 32, PropModeReplace,
972 if (private->state & GDK_WINDOW_STATE_STICKY)
974 atoms[0] = 0xFFFFFFFF;
975 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
976 GDK_WINDOW_XID (window),
977 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_DESKTOP"),
978 XA_CARDINAL, 32, PropModeReplace,
984 show_window_internal (GdkWindow *window,
987 GdkWindowObject *private;
989 g_return_if_fail (GDK_IS_WINDOW (window));
991 private = (GdkWindowObject*) window;
992 if (!private->destroyed)
995 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
996 GDK_WINDOW_XID (window));
998 if (!GDK_WINDOW_IS_MAPPED (window))
1000 set_initial_hints (window);
1002 gdk_synthesize_window_state (window,
1003 GDK_WINDOW_STATE_WITHDRAWN,
1007 g_assert (GDK_WINDOW_IS_MAPPED (window));
1009 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
1010 XMapWindow (GDK_WINDOW_XDISPLAY (window),
1011 GDK_WINDOW_XID (window));
1016 * gdk_window_show_unraised:
1017 * @window: a #GdkWindow
1019 * Shows a #GdkWindow onscreen, but does not modify its stacking
1020 * order. In contrast, gdk_window_show() will raise the window
1021 * to the top of the window stack.
1023 * On the X11 platform, in Xlib terms, this function calls
1024 * XMapWindow() (it also updates some internal GDK state, which means
1025 * that you can't really use XMapWindow() directly on a GDK window).
1029 gdk_window_show_unraised (GdkWindow *window)
1031 g_return_if_fail (GDK_IS_WINDOW (window));
1033 show_window_internal (window, FALSE);
1038 * @window: a #GdkWindow
1040 * Like gdk_window_show_unraised(), but also raises the window to the
1041 * top of the window stack (moves the window to the front of the
1044 * This function maps a window so it's visible onscreen. Its opposite
1045 * is gdk_window_hide().
1047 * When implementing a #GtkWidget, you should call this function on the widget's
1048 * #GdkWindow as part of the "map" method.
1052 gdk_window_show (GdkWindow *window)
1054 g_return_if_fail (GDK_IS_WINDOW (window));
1056 show_window_internal (window, TRUE);
1061 * @window: a #GdkWindow
1063 * For toplevel windows, withdraws them, so they will no longer be
1064 * known to the window manager; for all windows, unmaps them, so
1065 * they won't be displayed. Normally done automatically as
1066 * part of gtk_widget_hide().
1070 gdk_window_hide (GdkWindow *window)
1072 GdkWindowObject *private;
1074 g_return_if_fail (window != NULL);
1076 private = (GdkWindowObject*) window;
1078 /* We'll get the unmap notify eventually, and handle it then,
1079 * but checking here makes things more consistent if we are
1080 * just doing stuff ourself.
1082 _gdk_xgrab_check_unmap (window,
1083 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1085 /* You can't simply unmap toplevel windows. */
1086 switch (private->window_type)
1088 case GDK_WINDOW_TOPLEVEL:
1089 case GDK_WINDOW_DIALOG:
1090 case GDK_WINDOW_TEMP: /* ? */
1091 gdk_window_withdraw (window);
1095 case GDK_WINDOW_FOREIGN:
1096 case GDK_WINDOW_ROOT:
1097 case GDK_WINDOW_CHILD:
1101 if (!private->destroyed)
1103 if (GDK_WINDOW_IS_MAPPED (window))
1104 gdk_synthesize_window_state (window,
1106 GDK_WINDOW_STATE_WITHDRAWN);
1108 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1110 _gdk_window_clear_update_area (window);
1112 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1113 GDK_WINDOW_XID (window));
1118 * gdk_window_withdraw:
1119 * @window: a toplevel #GdkWindow
1121 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1122 * Normally done automatically by gtk_widget_hide() called on a #GtkWindow.
1126 gdk_window_withdraw (GdkWindow *window)
1128 GdkWindowObject *private;
1130 g_return_if_fail (window != NULL);
1132 private = (GdkWindowObject*) window;
1133 if (!private->destroyed)
1135 if (GDK_WINDOW_IS_MAPPED (window))
1136 gdk_synthesize_window_state (window,
1138 GDK_WINDOW_STATE_WITHDRAWN);
1140 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1142 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1143 GDK_WINDOW_XID (window), 0);
1149 * @window: a #GdkWindow
1150 * @x: X coordinate relative to window's parent
1151 * @y: Y coordinate relative to window's parent
1153 * Repositions a window relative to its parent window.
1154 * For toplevel windows, window managers may ignore or modify the move;
1155 * you should probably use gtk_window_move() on a #GtkWindow widget
1156 * anyway, instead of using GDK functions. For child windows,
1157 * the move will reliably succeed.
1159 * If you're also planning to resize the window, use gdk_window_move_resize()
1160 * to both move and resize simultaneously, for a nicer visual effect.
1164 gdk_window_move (GdkWindow *window,
1168 GdkWindowObject *private = (GdkWindowObject *)window;
1169 GdkWindowImplX11 *impl;
1171 g_return_if_fail (window != NULL);
1172 g_return_if_fail (GDK_IS_WINDOW (window));
1174 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1176 if (!GDK_WINDOW_DESTROYED (window))
1178 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1179 _gdk_window_move_resize_child (window, x, y,
1180 impl->width, impl->height);
1183 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1184 GDK_WINDOW_XID (window),
1191 * gdk_window_resize:
1192 * @window: a #GdkWindow
1193 * @width: new width of the window
1194 * @height: new height of the window
1196 * Resizes @window; for toplevel windows, asks the window manager to resize
1197 * the window. The window manager may not allow the resize. When using GTK+,
1198 * use gtk_window_resize() instead of this low-level GDK function.
1200 * Windows may not be resized below 1x1.
1202 * If you're also planning to move the window, use gdk_window_move_resize()
1203 * to both move and resize simultaneously, for a nicer visual effect.
1207 gdk_window_resize (GdkWindow *window,
1211 GdkWindowObject *private;
1213 g_return_if_fail (window != NULL);
1214 g_return_if_fail (GDK_IS_WINDOW (window));
1221 private = (GdkWindowObject*) window;
1223 if (!GDK_WINDOW_DESTROYED (window))
1225 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1226 _gdk_window_move_resize_child (window, private->x, private->y,
1230 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1232 if (width != impl->width || height != impl->height)
1233 private->resize_count += 1;
1235 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1236 GDK_WINDOW_XID (window),
1243 * gdk_window_move_resize:
1244 * @window: a #GdkWindow
1245 * @x: new X position relative to window's parent
1246 * @y: new Y position relative to window's parent
1248 * @height: new height
1250 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1251 * except that both operations are performed at once, avoiding strange
1252 * visual effects. (i.e. the user may be able to see the window first
1253 * move, then resize, if you don't use gdk_window_move_resize().)
1257 gdk_window_move_resize (GdkWindow *window,
1263 GdkWindowObject *private;
1265 g_return_if_fail (window != NULL);
1266 g_return_if_fail (GDK_IS_WINDOW (window));
1273 private = (GdkWindowObject*) window;
1275 if (!GDK_WINDOW_DESTROYED (window))
1277 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1278 _gdk_window_move_resize_child (window, x, y, width, height);
1281 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1283 if (width != impl->width || height != impl->height)
1284 private->resize_count += 1;
1286 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1287 GDK_WINDOW_XID (window),
1288 x, y, width, height);
1294 * gdk_window_reparent:
1295 * @window: a #GdkWindow
1296 * @new_parent: new parent to move @window into
1297 * @x: X location inside the new parent
1298 * @y: Y location inside the new parent
1300 * Reparents @window into the given @new_parent. The window being
1301 * reparented will be unmapped as a side effect.
1305 gdk_window_reparent (GdkWindow *window,
1306 GdkWindow *new_parent,
1310 GdkDisplay *display;
1311 GdkWindowObject *window_private;
1312 GdkWindowObject *parent_private;
1313 GdkWindowObject *old_parent_private;
1315 g_return_if_fail (window != NULL);
1316 g_return_if_fail (GDK_IS_WINDOW (window));
1317 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1318 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1321 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1323 display = GDK_WINDOW_DISPLAY (window);
1325 window_private = (GdkWindowObject*) window;
1326 old_parent_private = (GdkWindowObject*)window_private->parent;
1327 parent_private = (GdkWindowObject*) new_parent;
1329 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1330 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1331 GDK_WINDOW_XID (window),
1332 GDK_WINDOW_XID (new_parent),
1335 window_private->x = x;
1336 window_private->y = y;
1338 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1341 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1342 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1344 window_private->parent = (GdkWindowObject *)new_parent;
1346 /* Switch the window type as appropriate */
1348 switch (GDK_WINDOW_TYPE (new_parent))
1350 case GDK_WINDOW_ROOT:
1351 case GDK_WINDOW_FOREIGN:
1352 /* Now a toplevel */
1353 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1354 set_wm_protocols (window);
1356 case GDK_WINDOW_TOPLEVEL:
1357 case GDK_WINDOW_CHILD:
1358 case GDK_WINDOW_DIALOG:
1359 case GDK_WINDOW_TEMP:
1360 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1361 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1363 /* If we were being sophisticated, we'd save the old window type
1364 * here, and restore it if we were reparented back to the
1365 * toplevel. However, the difference between different types
1366 * of toplevels only really matters on creation anyways.
1368 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1372 if (old_parent_private)
1373 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1375 if ((old_parent_private &&
1376 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1377 (!old_parent_private && parent_private->guffaw_gravity))
1378 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1380 parent_private->children = g_list_prepend (parent_private->children, window);
1381 _gdk_window_init_position (GDK_WINDOW (window_private));
1385 _gdk_windowing_window_clear_area (GdkWindow *window,
1391 g_return_if_fail (window != NULL);
1392 g_return_if_fail (GDK_IS_WINDOW (window));
1394 if (!GDK_WINDOW_DESTROYED (window))
1395 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1396 x, y, width, height, False);
1400 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1406 g_return_if_fail (window != NULL);
1407 g_return_if_fail (GDK_IS_WINDOW (window));
1409 if (!GDK_WINDOW_DESTROYED (window))
1410 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1411 x, y, width, height, True);
1417 * @window: a #GdkWindow
1419 * Raises @window to the top of the Z-order (stacking order), so that
1420 * other windows with the same parent window appear below @window.
1421 * If @window is a toplevel, the window manager may choose to deny the
1422 * request to move the window in the Z-order, gdk_window_raise() only
1423 * requests the restack, does not guarantee it.
1427 gdk_window_raise (GdkWindow *window)
1429 g_return_if_fail (window != NULL);
1430 g_return_if_fail (GDK_IS_WINDOW (window));
1432 if (!GDK_WINDOW_DESTROYED (window))
1433 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1438 * @window: a #GdkWindow
1440 * Lowers @window to the bottom of the Z-order (stacking order), so that
1441 * other windows with the same parent window appear above @window.
1442 * If @window is a toplevel, the window manager may choose to deny the
1443 * request to move the window in the Z-order, gdk_window_lower() only
1444 * requests the restack, does not guarantee it.
1446 * Note that gdk_window_show() raises the window again, so don't call this
1447 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1451 gdk_window_lower (GdkWindow *window)
1453 g_return_if_fail (window != NULL);
1454 g_return_if_fail (GDK_IS_WINDOW (window));
1456 if (!GDK_WINDOW_DESTROYED (window))
1457 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1462 * @window: a #GdkWindow
1463 * @timestamp: timestamp of the event triggering the window focus
1465 * Sets keyboard focus to @window. If @window is not onscreen this
1466 * will not work. In most cases, gtk_window_present() should be used on
1467 * a #GtkWindow, rather than calling this function.
1471 gdk_window_focus (GdkWindow *window,
1474 g_return_if_fail (GDK_IS_WINDOW (window));
1476 if (GDK_WINDOW_DESTROYED (window))
1479 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1480 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1484 xev.xclient.type = ClientMessage;
1485 xev.xclient.serial = 0;
1486 xev.xclient.send_event = True;
1487 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1488 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1489 "_NET_ACTIVE_WINDOW");
1490 xev.xclient.format = 32;
1491 xev.xclient.data.l[0] = 0;
1493 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1494 SubstructureRedirectMask | SubstructureNotifyMask,
1499 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1501 /* There is no way of knowing reliably whether we are viewable so we need
1502 * to trap errors so we don't cause a BadMatch.
1504 gdk_error_trap_push ();
1505 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1506 GDK_WINDOW_XWINDOW (window),
1509 XSync (GDK_WINDOW_XDISPLAY (window), False);
1510 gdk_error_trap_pop ();
1515 * gdk_window_set_hints:
1516 * @window: a #GdkWindow
1517 * @x: ignored field, does not matter
1518 * @y: ignored field, does not matter
1519 * @min_width: minimum width hint
1520 * @min_height: minimum height hint
1521 * @max_width: max width hint
1522 * @max_height: max height hint
1523 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1525 * This function is broken and useless and you should ignore it.
1526 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1527 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1528 * depending on what you're trying to do.
1530 * If using GDK directly, use gdk_window_set_geometry_hints().
1534 gdk_window_set_hints (GdkWindow *window,
1543 XSizeHints size_hints;
1545 g_return_if_fail (window != NULL);
1546 g_return_if_fail (GDK_IS_WINDOW (window));
1548 if (GDK_WINDOW_DESTROYED (window))
1551 size_hints.flags = 0;
1553 if (flags & GDK_HINT_POS)
1555 size_hints.flags |= PPosition;
1560 if (flags & GDK_HINT_MIN_SIZE)
1562 size_hints.flags |= PMinSize;
1563 size_hints.min_width = min_width;
1564 size_hints.min_height = min_height;
1567 if (flags & GDK_HINT_MAX_SIZE)
1569 size_hints.flags |= PMaxSize;
1570 size_hints.max_width = max_width;
1571 size_hints.max_height = max_height;
1574 /* FIXME: Would it be better to delete this property if
1575 * flags == 0? It would save space on the server
1577 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1578 GDK_WINDOW_XID (window),
1583 * gdk_window_set_type_hint:
1584 * @window: A #GdkWindow
1585 * @hint: A hint of the function this window will have
1587 * The application can use this call to provide a hint to the window
1588 * manager about the functionality of a window. The window manager
1589 * can use this information when determining the decoration and behaviour
1592 * The hint must be set before the window is mapped.
1595 gdk_window_set_type_hint (GdkWindow *window,
1596 GdkWindowTypeHint hint)
1598 GdkDisplay *display;
1601 g_return_if_fail (window != NULL);
1602 g_return_if_fail (GDK_IS_WINDOW (window));
1604 if (GDK_WINDOW_DESTROYED (window))
1607 display = gdk_drawable_get_display (window);
1611 case GDK_WINDOW_TYPE_HINT_DIALOG:
1612 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1614 case GDK_WINDOW_TYPE_HINT_MENU:
1615 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1617 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1618 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1620 case GDK_WINDOW_TYPE_HINT_UTILITY:
1621 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1623 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1624 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASHSCREEN");
1626 case GDK_WINDOW_TYPE_HINT_DOCK:
1627 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1629 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1630 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1633 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1635 case GDK_WINDOW_TYPE_HINT_NORMAL:
1636 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1640 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1641 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1642 XA_ATOM, 32, PropModeReplace,
1643 (guchar *)&atom, 1);
1648 gdk_wmspec_change_state (gboolean add,
1653 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1656 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1657 #define _NET_WM_STATE_ADD 1 /* add/set property */
1658 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1660 xev.xclient.type = ClientMessage;
1661 xev.xclient.serial = 0;
1662 xev.xclient.send_event = True;
1663 xev.xclient.window = GDK_WINDOW_XID (window);
1664 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1665 xev.xclient.format = 32;
1666 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1667 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1668 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1670 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1671 SubstructureRedirectMask | SubstructureNotifyMask,
1676 * gdk_window_set_modal_hint:
1677 * @window: A #GdkWindow
1678 * @modal: TRUE if the window is modal, FALSE otherwise.
1680 * The application can use this hint to tell the window manager
1681 * that a certain window has modal behaviour. The window manager
1682 * can use this information to handle modal windows in a special
1685 * You should only use this on windows for which you have
1686 * previously called #gdk_window_set_transient_for()
1689 gdk_window_set_modal_hint (GdkWindow *window,
1692 GdkWindowObject *private;
1694 g_return_if_fail (window != NULL);
1695 g_return_if_fail (GDK_IS_WINDOW (window));
1697 if (GDK_WINDOW_DESTROYED (window))
1700 private = (GdkWindowObject*) window;
1702 private->modal_hint = modal;
1704 if (GDK_WINDOW_IS_MAPPED (window))
1705 gdk_wmspec_change_state (modal, window,
1706 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1711 * gdk_window_set_skip_taskbar_hint:
1712 * @window: a #GdkWindow
1713 * @skips_taskbar: %TRUE to skip the taskbar
1715 * Toggles whether a window should appear in a task list or window
1716 * list. If a window's semantic type as specified with
1717 * gdk_window_set_type_hint() already fully describes the window, this
1718 * function should NOT be called in addition, instead you should allow
1719 * the window to be treated according to standard policy for its
1723 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
1724 gboolean skips_taskbar)
1726 GdkWindowObject *private;
1727 GdkWindowImplX11 *impl;
1729 g_return_if_fail (window != NULL);
1730 g_return_if_fail (GDK_IS_WINDOW (window));
1732 if (GDK_WINDOW_DESTROYED (window))
1735 private = (GdkWindowObject*) window;
1736 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1738 impl->skip_taskbar_hint = skips_taskbar;
1740 if (GDK_WINDOW_IS_MAPPED (window))
1741 gdk_wmspec_change_state (skips_taskbar, window,
1742 gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE),
1747 * gdk_window_set_skip_pager_hint:
1748 * @window: a #GdkWindow
1749 * @skips_taskbar: %TRUE to skip the pager
1751 * Toggles whether a window should appear in a pager (workspace
1752 * switcher, or other desktop utility program that displays a small
1753 * thumbnail representation of the windows on the desktop). If a
1754 * window's semantic type as specified with gdk_window_set_type_hint()
1755 * already fully describes the window, this function should NOT be
1756 * called in addition, instead you should allow the window to be
1757 * treated according to standard policy for its semantic type.
1760 gdk_window_set_skip_pager_hint (GdkWindow *window,
1761 gboolean skips_pager)
1763 GdkWindowObject *private;
1764 GdkWindowImplX11 *impl;
1766 g_return_if_fail (window != NULL);
1767 g_return_if_fail (GDK_IS_WINDOW (window));
1769 if (GDK_WINDOW_DESTROYED (window))
1772 private = (GdkWindowObject*) window;
1773 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1775 impl->skip_pager_hint = skips_pager;
1777 if (GDK_WINDOW_IS_MAPPED (window))
1778 gdk_wmspec_change_state (skips_pager, window,
1779 gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE),
1784 * gdk_window_set_geometry_hints:
1785 * @window: a #GdkWindow
1786 * @geometry: geometry hints
1787 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1789 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1790 * are set, hints not flagged in @geom_mask are unset.
1791 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1795 gdk_window_set_geometry_hints (GdkWindow *window,
1796 GdkGeometry *geometry,
1797 GdkWindowHints geom_mask)
1799 XSizeHints size_hints;
1801 g_return_if_fail (window != NULL);
1802 g_return_if_fail (GDK_IS_WINDOW (window));
1804 if (GDK_WINDOW_DESTROYED (window))
1807 size_hints.flags = 0;
1809 if (geom_mask & GDK_HINT_POS)
1811 size_hints.flags |= PPosition;
1812 /* We need to initialize the following obsolete fields because KWM
1813 * apparently uses these fields if they are non-zero.
1820 if (geom_mask & GDK_HINT_USER_POS)
1822 size_hints.flags |= USPosition;
1825 if (geom_mask & GDK_HINT_USER_SIZE)
1827 size_hints.flags |= USSize;
1830 if (geom_mask & GDK_HINT_MIN_SIZE)
1832 size_hints.flags |= PMinSize;
1833 size_hints.min_width = geometry->min_width;
1834 size_hints.min_height = geometry->min_height;
1837 if (geom_mask & GDK_HINT_MAX_SIZE)
1839 size_hints.flags |= PMaxSize;
1840 size_hints.max_width = MAX (geometry->max_width, 1);
1841 size_hints.max_height = MAX (geometry->max_height, 1);
1844 if (geom_mask & GDK_HINT_BASE_SIZE)
1846 size_hints.flags |= PBaseSize;
1847 size_hints.base_width = geometry->base_width;
1848 size_hints.base_height = geometry->base_height;
1851 if (geom_mask & GDK_HINT_RESIZE_INC)
1853 size_hints.flags |= PResizeInc;
1854 size_hints.width_inc = geometry->width_inc;
1855 size_hints.height_inc = geometry->height_inc;
1858 if (geom_mask & GDK_HINT_ASPECT)
1860 size_hints.flags |= PAspect;
1861 if (geometry->min_aspect <= 1)
1863 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1864 size_hints.min_aspect.y = 65536;
1868 size_hints.min_aspect.x = 65536;
1869 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1871 if (geometry->max_aspect <= 1)
1873 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1874 size_hints.max_aspect.y = 65536;
1878 size_hints.max_aspect.x = 65536;
1879 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1883 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1885 size_hints.flags |= PWinGravity;
1886 size_hints.win_gravity = geometry->win_gravity;
1889 /* FIXME: Would it be better to delete this property if
1890 * geom_mask == 0? It would save space on the server
1892 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1893 GDK_WINDOW_XID (window),
1898 gdk_window_get_geometry_hints (GdkWindow *window,
1899 GdkGeometry *geometry,
1900 GdkWindowHints *geom_mask)
1902 XSizeHints size_hints;
1903 glong junk_size_mask = 0;
1905 g_return_if_fail (GDK_IS_WINDOW (window));
1906 g_return_if_fail (geometry != NULL);
1907 g_return_if_fail (geom_mask != NULL);
1911 if (GDK_WINDOW_DESTROYED (window))
1914 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1915 GDK_WINDOW_XID (window),
1920 if (size_hints.flags & PMinSize)
1922 *geom_mask |= GDK_HINT_MIN_SIZE;
1923 geometry->min_width = size_hints.min_width;
1924 geometry->min_height = size_hints.min_height;
1927 if (size_hints.flags & PMaxSize)
1929 *geom_mask |= GDK_HINT_MAX_SIZE;
1930 geometry->max_width = MAX (size_hints.max_width, 1);
1931 geometry->max_height = MAX (size_hints.max_height, 1);
1934 if (size_hints.flags & PResizeInc)
1936 *geom_mask |= GDK_HINT_RESIZE_INC;
1937 geometry->width_inc = size_hints.width_inc;
1938 geometry->height_inc = size_hints.height_inc;
1941 if (size_hints.flags & PAspect)
1943 *geom_mask |= GDK_HINT_ASPECT;
1945 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1946 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1949 if (size_hints.flags & PWinGravity)
1951 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1952 geometry->win_gravity = size_hints.win_gravity;
1957 utf8_is_latin1 (const gchar *str)
1959 const char *p = str;
1963 gunichar ch = g_utf8_get_char (p);
1968 p = g_utf8_next_char (p);
1974 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
1975 * convertable to STRING, otherwise, set it as compound text
1978 set_text_property (GdkWindow *window,
1980 const gchar *utf8_str)
1982 guchar *prop_text = NULL;
1987 if (utf8_is_latin1 (utf8_str))
1989 prop_type = XA_STRING;
1990 prop_text = gdk_utf8_to_string_target (utf8_str);
1991 prop_length = prop_text ? strlen (prop_text) : 0;
1998 gdk_utf8_to_compound_text_for_display (gdk_drawable_get_display (window),
1999 utf8_str, &gdk_type, &prop_format,
2000 &prop_text, &prop_length);
2001 prop_type = gdk_x11_atom_to_xatom_for_display
2002 (GDK_WINDOW_DISPLAY (window), gdk_type);
2007 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2008 GDK_WINDOW_XID (window),
2010 prop_type, prop_format,
2011 PropModeReplace, prop_text,
2019 * gdk_window_set_title:
2020 * @window: a #GdkWindow
2021 * @title: title of @window
2023 * Sets the title of a toplevel window, to be displayed in the titlebar.
2024 * If you haven't explicitly set the icon name for the window
2025 * (using gdk_window_set_icon_name()), the icon name will be set to
2026 * @title as well. @title must be in UTF-8 encoding (as with all
2027 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2030 gdk_window_set_title (GdkWindow *window,
2033 GdkDisplay *display;
2035 g_return_if_fail (window != NULL);
2036 g_return_if_fail (GDK_IS_WINDOW (window));
2037 g_return_if_fail (title != NULL);
2039 if (GDK_WINDOW_DESTROYED (window))
2042 display = gdk_drawable_get_display (window);
2044 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2045 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2046 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2047 PropModeReplace, title, strlen (title));
2049 set_text_property (window,
2050 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2053 if (!gdk_window_icon_name_set (window))
2055 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2056 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2057 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2058 PropModeReplace, title, strlen (title));
2060 set_text_property (window,
2061 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2067 * gdk_window_set_role:
2068 * @window: a #GdkWindow
2069 * @role: a string indicating its role
2071 * When using GTK+, typically you should use gtk_window_set_role() instead
2072 * of this low-level function.
2074 * The window manager and session manager use a window's role to
2075 * distinguish it from other kinds of window in the same application.
2076 * When an application is restarted after being saved in a previous
2077 * session, all windows with the same title and role are treated as
2078 * interchangeable. So if you have two windows with the same title
2079 * that should be distinguished for session management purposes, you
2080 * should set the role on those windows. It doesn't matter what string
2081 * you use for the role, as long as you have a different role for each
2082 * non-interchangeable kind of window.
2086 gdk_window_set_role (GdkWindow *window,
2089 GdkDisplay *display;
2091 g_return_if_fail (window != NULL);
2092 g_return_if_fail (GDK_IS_WINDOW (window));
2094 display = gdk_drawable_get_display (window);
2096 if (!GDK_WINDOW_DESTROYED (window))
2099 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2100 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2101 XA_STRING, 8, PropModeReplace, role, strlen (role));
2103 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2104 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2109 * gdk_window_set_transient_for:
2110 * @window: a toplevel #GdkWindow
2111 * @parent: another toplevel #GdkWindow
2113 * Indicates to the window manager that @window is a transient dialog
2114 * associated with the application window @parent. This allows the
2115 * window manager to do things like center @window on @parent and
2116 * keep @window above @parent.
2118 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2123 gdk_window_set_transient_for (GdkWindow *window,
2126 GdkWindowObject *private;
2127 GdkWindowObject *parent_private;
2129 g_return_if_fail (window != NULL);
2130 g_return_if_fail (GDK_IS_WINDOW (window));
2132 private = (GdkWindowObject*) window;
2133 parent_private = (GdkWindowObject*) parent;
2135 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2136 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2137 GDK_WINDOW_XID (window),
2138 GDK_WINDOW_XID (parent));
2142 * gdk_window_set_background:
2143 * @window: a #GdkWindow
2144 * @color: an allocated #GdkColor
2146 * Sets the background color of @window. (However, when using GTK+,
2147 * set the background of a widget with gtk_widget_modify_bg() - if
2148 * you're an application - or gtk_style_set_background() - if you're
2149 * implementing a custom widget.)
2151 * The @color must be allocated; gdk_rgb_find_color() is the best way
2152 * to allocate a color.
2154 * See also gdk_window_set_back_pixmap().
2158 gdk_window_set_background (GdkWindow *window,
2161 GdkWindowObject *private = (GdkWindowObject *)window;
2163 g_return_if_fail (window != NULL);
2164 g_return_if_fail (GDK_IS_WINDOW (window));
2166 if (!GDK_WINDOW_DESTROYED (window))
2167 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2168 GDK_WINDOW_XID (window), color->pixel);
2170 private->bg_color = *color;
2172 if (private->bg_pixmap &&
2173 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2174 private->bg_pixmap != GDK_NO_BG)
2175 g_object_unref (private->bg_pixmap);
2177 private->bg_pixmap = NULL;
2181 * gdk_window_set_back_pixmap:
2182 * @window: a #GdkWindow
2183 * @pixmap: a #GdkPixmap, or %NULL
2184 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2186 * Sets the background pixmap of @window. May also be used to set a background of
2187 * "None" on @window, by setting a background pixmap of %NULL.
2188 * A background pixmap will be tiled, positioning the first tile at the origin of
2189 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2190 * origin of the parent window (useful to align tiles in a parent with tiles
2193 * A background pixmap of %NULL means that the window will have no
2194 * background. A window with no background will never have its
2195 * background filled by the windowing system, instead the window will
2196 * contain whatever pixels were already in the corresponding area of
2199 * The windowing system will normally fill a window with its background
2200 * when the window is obscured then exposed, and when you call
2201 * gdk_window_clear().
2205 gdk_window_set_back_pixmap (GdkWindow *window,
2207 gboolean parent_relative)
2209 GdkWindowObject *private = (GdkWindowObject *)window;
2212 g_return_if_fail (window != NULL);
2213 g_return_if_fail (GDK_IS_WINDOW (window));
2214 g_return_if_fail (pixmap == NULL || !parent_relative);
2215 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2217 if (private->bg_pixmap &&
2218 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2219 private->bg_pixmap != GDK_NO_BG)
2220 g_object_unref (private->bg_pixmap);
2222 if (parent_relative)
2224 xpixmap = ParentRelative;
2225 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2231 g_object_ref (pixmap);
2232 private->bg_pixmap = pixmap;
2233 xpixmap = GDK_PIXMAP_XID (pixmap);
2238 private->bg_pixmap = GDK_NO_BG;
2242 if (!GDK_WINDOW_DESTROYED (window))
2243 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2244 GDK_WINDOW_XID (window), xpixmap);
2248 * gdk_window_set_cursor:
2249 * @window: a #GdkWindow
2252 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2253 * gdk_cursor_new_from_pixmap() to create the cursor.
2254 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2255 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2256 * to gdk_window_set_cursor() means that @window will use the cursor of
2257 * its parent window. Most windows should use this default.
2261 gdk_window_set_cursor (GdkWindow *window,
2264 GdkCursorPrivate *cursor_private;
2267 g_return_if_fail (window != NULL);
2268 g_return_if_fail (GDK_IS_WINDOW (window));
2270 cursor_private = (GdkCursorPrivate*) cursor;
2275 xcursor = cursor_private->xcursor;
2277 if (!GDK_WINDOW_DESTROYED (window))
2278 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2279 GDK_WINDOW_XID (window),
2284 * gdk_window_get_geometry:
2285 * @window: a #GdkWindow
2286 * @x: return location for X coordinate of window (relative to its parent)
2287 * @y: return location for Y coordinate of window (relative to its parent)
2288 * @width: return location for width of window
2289 * @height: return location for height of window
2290 * @depth: return location for bit depth of window
2292 * Any of the return location arguments to this function may be %NULL,
2293 * if you aren't interested in getting the value of that field.
2295 * The X and Y coordinates returned are relative to the parent window
2296 * of @window, which for toplevels usually means relative to the
2297 * window decorations (titlebar, etc.) rather than relative to the
2298 * root window (screen-size background window).
2300 * On the X11 platform, the geometry is obtained from the X server,
2301 * so reflects the latest position of @window; this may be out-of-sync
2302 * with the position of @window delivered in the most-recently-processed
2303 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2304 * position from the most recent configure event.
2308 gdk_window_get_geometry (GdkWindow *window,
2320 guint tborder_width;
2323 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2327 GDK_NOTE (MULTIHEAD,
2328 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2329 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
2332 if (!GDK_WINDOW_DESTROYED (window))
2334 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2335 GDK_WINDOW_XID (window),
2336 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2352 * gdk_window_get_origin:
2353 * @window: a #GdkWindow
2354 * @x: return location for X coordinate
2355 * @y: return location for Y coordinate
2357 * Obtains the position of a window in root window coordinates.
2358 * (Compare with gdk_window_get_position() and
2359 * gdk_window_get_geometry() which return the position of a window
2360 * relative to its parent window.)
2362 * Return value: not meaningful, ignore
2365 gdk_window_get_origin (GdkWindow *window,
2374 g_return_val_if_fail (window != NULL, 0);
2376 if (!GDK_WINDOW_DESTROYED (window))
2378 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2379 GDK_WINDOW_XID (window),
2380 GDK_WINDOW_XROOTWIN (window),
2396 * gdk_window_get_deskrelative_origin:
2397 * @window: a #GdkWindow
2398 * @x: return location for X coordinate
2399 * @y: return location for Y coordinate
2401 * This gets the origin of a #GdkWindow relative to
2402 * an Enlightenment-window-manager desktop. As long as you don't
2403 * assume that the user's desktop/workspace covers the entire
2404 * root window (i.e. you don't assume that the desktop begins
2405 * at root window coordinate 0,0) this function is not necessary.
2406 * It's deprecated for that reason.
2408 * Return value: not meaningful
2411 gdk_window_get_deskrelative_origin (GdkWindow *window,
2415 gboolean return_val = FALSE;
2416 gint num_children, format_return;
2417 Window win, *child, parent, root;
2422 gulong number_return, bytes_after_return;
2423 guchar *data_return;
2425 g_return_val_if_fail (window != NULL, 0);
2426 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2428 if (!GDK_WINDOW_DESTROYED (window))
2430 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2431 "ENLIGHTENMENT_DESKTOP");
2432 win = GDK_WINDOW_XID (window);
2434 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2435 &child, (unsigned int *)&num_children))
2437 if ((child) && (num_children > 0))
2449 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2450 False, XA_CARDINAL, &type_return, &format_return,
2451 &number_return, &bytes_after_return, &data_return);
2453 if (type_return == XA_CARDINAL)
2455 XFree (data_return);
2460 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2461 GDK_WINDOW_XID (window),
2476 * gdk_window_get_root_origin:
2477 * @window: a #GdkWindow
2478 * @x: return location for X position of window frame
2479 * @y: return location for Y position of window frame
2481 * Obtains the top-left corner of the window manager frame in root
2482 * window coordinates.
2486 gdk_window_get_root_origin (GdkWindow *window,
2492 g_return_if_fail (GDK_IS_WINDOW (window));
2494 gdk_window_get_frame_extents (window, &rect);
2504 * gdk_window_get_frame_extents:
2505 * @window: a #GdkWindow
2506 * @rect: rectangle to fill with bounding box of the window frame
2508 * Obtains the bounding box of the window, including window manager
2509 * titlebar/borders if any. The frame position is given in root window
2510 * coordinates. To get the position of the window itself (rather than
2511 * the frame) in root window coordinates, use gdk_window_get_origin().
2515 gdk_window_get_frame_extents (GdkWindow *window,
2518 GdkWindowObject *private;
2523 unsigned int nchildren;
2525 g_return_if_fail (GDK_IS_WINDOW (window));
2526 g_return_if_fail (rect != NULL);
2528 private = (GdkWindowObject*) window;
2535 if (GDK_WINDOW_DESTROYED (window))
2538 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2539 private = (GdkWindowObject*) private->parent;
2540 if (GDK_WINDOW_DESTROYED (window))
2543 xparent = GDK_WINDOW_XID (window);
2547 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2549 &children, &nchildren))
2555 while (xparent != root);
2557 if (xparent == root)
2559 unsigned int ww, wh, wb, wd;
2562 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2573 _gdk_windowing_window_get_pointer (GdkWindow *window,
2576 GdkModifierType *mask)
2578 GdkWindow *return_val;
2584 unsigned int xmask = 0;
2585 gint xoffset, yoffset;
2587 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2591 GDK_NOTE (MULTIHEAD,
2592 g_message ("_gdk_windowing_window_get_pointer(): window arg is need for multihead safe operation"));
2593 window = gdk_screen_get_root_window (gdk_screen_get_default ());
2596 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2599 if (!GDK_WINDOW_DESTROYED (window) &&
2600 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2601 GDK_WINDOW_XID (window),
2602 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2605 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
2609 *x = winx + xoffset;
2611 *y = winy + yoffset;
2619 _gdk_windowing_window_at_pointer (GdkScreen *screen,
2626 Window xwindow_last = 0;
2628 int rootx = -1, rooty = -1;
2632 xwindow = GDK_SCREEN_XROOTWIN (screen);
2633 xdisplay = GDK_SCREEN_XDISPLAY (screen);
2635 XGrabServer (xdisplay);
2638 xwindow_last = xwindow;
2639 XQueryPointer (xdisplay, xwindow,
2640 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
2642 XUngrabServer (xdisplay);
2644 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
2647 *win_x = window ? winx : -1;
2649 *win_y = window ? winy : -1;
2655 * gdk_window_get_events:
2656 * @window: a #GdkWindow
2658 * Gets the event mask for @window. See gdk_window_set_events().
2660 * Return value: event mask for @window
2663 gdk_window_get_events (GdkWindow *window)
2665 XWindowAttributes attrs;
2666 GdkEventMask event_mask;
2668 g_return_val_if_fail (window != NULL, 0);
2669 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2671 if (GDK_WINDOW_DESTROYED (window))
2675 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2676 GDK_WINDOW_XID (window),
2679 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2680 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2687 * gdk_window_set_events:
2688 * @window: a #GdkWindow
2689 * @event_mask: event mask for @window
2691 * The event mask for a window determines which events will be reported
2692 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2693 * means the window should report button press events. The event mask
2694 * is the bitwise OR of values from the #GdkEventMask enumeration.
2698 gdk_window_set_events (GdkWindow *window,
2699 GdkEventMask event_mask)
2704 g_return_if_fail (window != NULL);
2705 g_return_if_fail (GDK_IS_WINDOW (window));
2707 if (!GDK_WINDOW_DESTROYED (window))
2709 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2710 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2711 for (i = 0; i < _gdk_nenvent_masks; i++)
2713 if (event_mask & (1 << (i + 1)))
2714 xevent_mask |= _gdk_event_mask_table[i];
2717 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2718 GDK_WINDOW_XID (window),
2724 gdk_window_add_colormap_windows (GdkWindow *window)
2726 GdkWindow *toplevel;
2727 Window *old_windows;
2728 Window *new_windows;
2731 g_return_if_fail (window != NULL);
2732 g_return_if_fail (GDK_IS_WINDOW (window));
2734 if (GDK_WINDOW_DESTROYED (window))
2736 toplevel = gdk_window_get_toplevel (window);
2739 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2740 GDK_WINDOW_XID (toplevel),
2741 &old_windows, &count))
2746 for (i = 0; i < count; i++)
2747 if (old_windows[i] == GDK_WINDOW_XID (window))
2749 XFree (old_windows);
2753 new_windows = g_new (Window, count + 1);
2755 for (i = 0; i < count; i++)
2756 new_windows[i] = old_windows[i];
2757 new_windows[count] = GDK_WINDOW_XID (window);
2759 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2760 GDK_WINDOW_XID (toplevel),
2761 new_windows, count + 1);
2763 g_free (new_windows);
2765 XFree (old_windows);
2769 gdk_window_have_shape_ext (GdkDisplay *display)
2771 GdkDisplayX11 *display_x11;
2773 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2775 display_x11 = GDK_DISPLAY_X11 (display);
2777 if (display_x11->have_shape == GDK_UNKNOWN)
2780 if (XQueryExtension (display_x11->xdisplay, "SHAPE", &ignore, &ignore, &ignore))
2781 display_x11->have_shape = GDK_YES;
2783 display_x11->have_shape = GDK_NO;
2786 return (display_x11->have_shape == GDK_YES);
2789 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2792 * This needs the X11 shape extension.
2793 * If not available, shaped windows will look
2794 * ugly, but programs still work. Stefan Wille
2797 * gdk_window_shape_combine_mask:
2798 * @window: a #GdkWindow
2800 * @x: X position of shape mask with respect to @window
2801 * @y: Y position of shape mask with respect to @window
2803 * Applies a shape mask to @window. Pixels in @window corresponding to
2804 * set bits in the @mask will be visible; pixels in @window
2805 * corresponding to unset bits in the @mask will be transparent. This
2806 * gives a non-rectangular window.
2808 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2809 * parameters are not used.
2811 * On the X11 platform, this uses an X server extension which is
2812 * widely available on most common platforms, but not available on
2813 * very old X servers, and occasionally the implementation will be
2814 * buggy. On servers without the shape extension, this function
2819 gdk_window_shape_combine_mask (GdkWindow *window,
2824 gint xoffset, yoffset;
2826 g_return_if_fail (window != NULL);
2827 g_return_if_fail (GDK_IS_WINDOW (window));
2829 #ifdef HAVE_SHAPE_EXT
2830 if (GDK_WINDOW_DESTROYED (window))
2833 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2835 if (xoffset != 0 || yoffset != 0)
2837 WARN_SHAPE_TOO_BIG ();
2841 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2845 pixmap = GDK_PIXMAP_XID (mask);
2854 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2855 GDK_WINDOW_XID (window),
2861 #endif /* HAVE_SHAPE_EXT */
2865 * gdk_window_shape_combine_region:
2866 * @window: a #GdkWindow
2867 * @shape_region: region of window to be non-transparent
2868 * @offset_x: X position of @shape_region in @window coordinates
2869 * @offset_y: Y position of @shape_region in @window coordinates
2871 * Makes pixels in @window outside @shape_region be transparent,
2872 * so that the window may be nonrectangular. See also
2873 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2875 * If @shape_region is %NULL, the shape will be unset, so the whole
2876 * window will be opaque again. @offset_x and @offset_y are ignored
2877 * if @shape_region is %NULL.
2879 * On the X11 platform, this uses an X server extension which is
2880 * widely available on most common platforms, but not available on
2881 * very old X servers, and occasionally the implementation will be
2882 * buggy. On servers without the shape extension, this function
2887 gdk_window_shape_combine_region (GdkWindow *window,
2888 GdkRegion *shape_region,
2892 gint xoffset, yoffset;
2894 g_return_if_fail (GDK_IS_WINDOW (window));
2896 #ifdef HAVE_SHAPE_EXT
2897 if (GDK_WINDOW_DESTROYED (window))
2900 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2902 if (xoffset != 0 || yoffset != 0)
2904 WARN_SHAPE_TOO_BIG ();
2908 if (shape_region == NULL)
2910 /* Use NULL mask to unset the shape */
2911 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2915 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2918 XRectangle *xrects = NULL;
2920 _gdk_region_get_xrectangles (shape_region,
2924 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2925 GDK_WINDOW_XID (window),
2934 #endif /* HAVE_SHAPE_EXT */
2939 * gdk_window_set_override_redirect:
2940 * @window: a #GdkWindow
2941 * @override_redirect: %TRUE if window should be override redirect
2943 * An override redirect window is not under the control of the window manager.
2944 * This means it won't have a titlebar, won't be minimizable, etc. - it will
2945 * be entirely under the control of the application. The window manager
2946 * can't see the override redirect window at all.
2948 * Override redirect should only be used for short-lived temporary
2949 * windows, such as popup menus. #GtkMenu uses an override redirect
2950 * window in its implementation, for example.
2954 gdk_window_set_override_redirect (GdkWindow *window,
2955 gboolean override_redirect)
2957 XSetWindowAttributes attr;
2959 g_return_if_fail (window != NULL);
2960 g_return_if_fail (GDK_IS_WINDOW (window));
2962 if (!GDK_WINDOW_DESTROYED (window))
2964 attr.override_redirect = (override_redirect == FALSE)?False:True;
2965 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2966 GDK_WINDOW_XID (window),
2974 * gdk_window_set_icon_list:
2975 * @window: The #GdkWindow toplevel window to set the icon of.
2976 * @pixbufs: A list of pixbufs, of different sizes.
2978 * Sets a list of icons for the window. One of these will be used
2979 * to represent the window when it has been iconified. The icon is
2980 * usually shown in an icon box or some sort of task bar. Which icon
2981 * size is shown depends on the window manager. The window manager
2982 * can scale the icon but setting several size icons can give better
2983 * image quality since the window manager may only need to scale the
2984 * icon by a small amount or not at all.
2988 gdk_window_set_icon_list (GdkWindow *window,
2997 gint width, height, stride;
3000 GdkDisplay *display;
3002 g_return_if_fail (GDK_IS_WINDOW (window));
3004 if (GDK_WINDOW_DESTROYED (window))
3007 display = gdk_drawable_get_display (window);
3015 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3017 width = gdk_pixbuf_get_width (pixbuf);
3018 height = gdk_pixbuf_get_height (pixbuf);
3020 size += 2 + width * height;
3022 l = g_list_next (l);
3025 data = g_malloc (size * sizeof (gulong));
3033 width = gdk_pixbuf_get_width (pixbuf);
3034 height = gdk_pixbuf_get_height (pixbuf);
3035 stride = gdk_pixbuf_get_rowstride (pixbuf);
3036 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3041 pixels = gdk_pixbuf_get_pixels (pixbuf);
3043 for (y = 0; y < height; y++)
3045 for (x = 0; x < width; x++)
3049 r = pixels[y*stride + x*n_channels + 0];
3050 g = pixels[y*stride + x*n_channels + 1];
3051 b = pixels[y*stride + x*n_channels + 2];
3052 if (n_channels >= 4)
3053 a = pixels[y*stride + x*n_channels + 3];
3057 *p++ = a << 24 | r << 16 | g << 8 | b ;
3061 l = g_list_next (l);
3066 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3067 GDK_WINDOW_XID (window),
3068 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3071 (guchar*) data, size);
3075 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3076 GDK_WINDOW_XID (window),
3077 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3084 * gdk_window_set_icon:
3085 * @window: a #GdkWindow
3086 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3087 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3088 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3090 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3091 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3092 * and gtk_window_set_icon(). If those don't meet your needs, look at
3093 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3094 * want to fall back to gdk_window_set_icon().
3098 gdk_window_set_icon (GdkWindow *window,
3099 GdkWindow *icon_window,
3105 g_return_if_fail (window != NULL);
3106 g_return_if_fail (GDK_IS_WINDOW (window));
3108 if (GDK_WINDOW_DESTROYED (window))
3111 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3112 GDK_WINDOW_XID (window));
3114 wm_hints = XAllocWMHints ();
3116 if (icon_window != NULL)
3118 wm_hints->flags |= IconWindowHint;
3119 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
3124 wm_hints->flags |= IconPixmapHint;
3125 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
3130 wm_hints->flags |= IconMaskHint;
3131 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
3134 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3135 GDK_WINDOW_XID (window), wm_hints);
3140 gdk_window_icon_name_set (GdkWindow *window)
3142 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3143 g_quark_from_static_string ("gdk-icon-name-set")));
3147 * gdk_window_set_icon_name:
3148 * @window: a #GdkWindow
3149 * @name: name of window while iconified (minimized)
3151 * Windows may have a name used while minimized, distinct from the
3152 * name they display in their titlebar. Most of the time this is a bad
3153 * idea from a user interface standpoint. But you can set such a name
3154 * with this function, if you like.
3158 gdk_window_set_icon_name (GdkWindow *window,
3161 GdkDisplay *display;
3163 g_return_if_fail (window != NULL);
3164 g_return_if_fail (GDK_IS_WINDOW (window));
3166 if (GDK_WINDOW_DESTROYED (window))
3169 display = gdk_drawable_get_display (window);
3171 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3172 GUINT_TO_POINTER (TRUE));
3174 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
3175 GDK_WINDOW_XID (window),
3176 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3177 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3178 PropModeReplace, name, strlen (name));
3180 set_text_property (window,
3181 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3186 * gdk_window_iconify:
3187 * @window: a #GdkWindow
3189 * Asks to iconify (minimize) @window. The window manager may choose
3190 * to ignore the request, but normally will honor it. Using
3191 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3195 gdk_window_iconify (GdkWindow *window)
3197 GdkWindowObject *private;
3199 g_return_if_fail (window != NULL);
3200 g_return_if_fail (GDK_IS_WINDOW (window));
3202 if (GDK_WINDOW_DESTROYED (window))
3205 private = (GdkWindowObject*) window;
3207 if (GDK_WINDOW_IS_MAPPED (window))
3209 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3210 GDK_WINDOW_XWINDOW (window),
3211 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3215 /* Flip our client side flag, the real work happens on map. */
3216 gdk_synthesize_window_state (window,
3218 GDK_WINDOW_STATE_ICONIFIED);
3223 * gdk_window_deiconify:
3224 * @window: a #GdkWindow
3226 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3227 * choose to ignore the request to deiconify. When using GTK+,
3228 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3229 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3230 * unminimizes it, and puts it on the current desktop.
3234 gdk_window_deiconify (GdkWindow *window)
3236 GdkWindowObject *private;
3238 g_return_if_fail (window != NULL);
3239 g_return_if_fail (GDK_IS_WINDOW (window));
3241 if (GDK_WINDOW_DESTROYED (window))
3244 private = (GdkWindowObject*) window;
3246 if (GDK_WINDOW_IS_MAPPED (window))
3248 gdk_window_show (window);
3252 /* Flip our client side flag, the real work happens on map. */
3253 gdk_synthesize_window_state (window,
3254 GDK_WINDOW_STATE_ICONIFIED,
3261 * @window: a toplevel #GdkWindow
3263 * "Pins" a window such that it's on all workspaces and does not scroll
3264 * with viewports, for window managers that have scrollable viewports.
3265 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3267 * On the X11 platform, this function depends on window manager
3268 * support, so may have no effect with many window managers. However,
3269 * GDK will do the best it can to convince the window manager to stick
3270 * the window. For window managers that don't support this operation,
3271 * there's nothing you can do to force it to happen.
3275 gdk_window_stick (GdkWindow *window)
3277 g_return_if_fail (GDK_IS_WINDOW (window));
3279 if (GDK_WINDOW_DESTROYED (window))
3282 if (GDK_WINDOW_IS_MAPPED (window))
3284 /* "stick" means stick to all desktops _and_ do not scroll with the
3285 * viewport. i.e. glue to the monitor glass in all cases.
3290 /* Request stick during viewport scroll */
3291 gdk_wmspec_change_state (TRUE, window,
3292 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3295 /* Request desktop 0xFFFFFFFF */
3296 xev.xclient.type = ClientMessage;
3297 xev.xclient.serial = 0;
3298 xev.xclient.send_event = True;
3299 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3300 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3301 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3303 xev.xclient.format = 32;
3305 xev.xclient.data.l[0] = 0xFFFFFFFF;
3307 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3308 SubstructureRedirectMask | SubstructureNotifyMask,
3313 /* Flip our client side flag, the real work happens on map. */
3314 gdk_synthesize_window_state (window,
3316 GDK_WINDOW_STATE_STICKY);
3321 * gdk_window_unstick:
3322 * @window: a toplevel #GdkWindow
3324 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3325 * and gtk_window_unstick().
3329 gdk_window_unstick (GdkWindow *window)
3331 g_return_if_fail (GDK_IS_WINDOW (window));
3333 if (GDK_WINDOW_DESTROYED (window))
3336 if (GDK_WINDOW_IS_MAPPED (window))
3343 gulong *current_desktop;
3344 GdkDisplay *display = gdk_drawable_get_display (window);
3346 /* Request unstick from viewport */
3347 gdk_wmspec_change_state (FALSE, window,
3348 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3351 /* Get current desktop, then set it; this is a race, but not
3352 * one that matters much in practice.
3354 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
3355 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
3357 False, XA_CARDINAL, &type, &format, &nitems,
3358 &bytes_after, (guchar **)¤t_desktop);
3360 if (type == XA_CARDINAL)
3362 xev.xclient.type = ClientMessage;
3363 xev.xclient.serial = 0;
3364 xev.xclient.send_event = True;
3365 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3366 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
3367 xev.xclient.format = 32;
3369 xev.xclient.data.l[0] = *current_desktop;
3371 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3372 SubstructureRedirectMask | SubstructureNotifyMask,
3375 XFree (current_desktop);
3380 /* Flip our client side flag, the real work happens on map. */
3381 gdk_synthesize_window_state (window,
3382 GDK_WINDOW_STATE_STICKY,
3389 * gdk_window_maximize:
3390 * @window: a #GdkWindow
3392 * Maximizes the window. If the window was already maximized, then
3393 * this function does nothing.
3395 * On X11, asks the window manager to maximize @window, if the window
3396 * manager supports this operation. Not all window managers support
3397 * this, and some deliberately ignore it or don't have a concept of
3398 * "maximized"; so you can't rely on the maximization actually
3399 * happening. But it will happen with most standard window managers,
3400 * and GDK makes a best effort to get it to happen.
3402 * On Windows, reliably maximizes the window.
3406 gdk_window_maximize (GdkWindow *window)
3408 g_return_if_fail (GDK_IS_WINDOW (window));
3410 if (GDK_WINDOW_DESTROYED (window))
3413 if (GDK_WINDOW_IS_MAPPED (window))
3414 gdk_wmspec_change_state (TRUE, window,
3415 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3416 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3418 gdk_synthesize_window_state (window,
3420 GDK_WINDOW_STATE_MAXIMIZED);
3424 * gdk_window_unmaximize:
3425 * @window: a #GdkWindow
3427 * Unmaximizes the window. If the window wasn't maximized, then this
3428 * function does nothing.
3430 * On X11, asks the window manager to unmaximize @window, if the
3431 * window manager supports this operation. Not all window managers
3432 * support this, and some deliberately ignore it or don't have a
3433 * concept of "maximized"; so you can't rely on the unmaximization
3434 * actually happening. But it will happen with most standard window
3435 * managers, and GDK makes a best effort to get it to happen.
3437 * On Windows, reliably unmaximizes the window.
3441 gdk_window_unmaximize (GdkWindow *window)
3443 g_return_if_fail (GDK_IS_WINDOW (window));
3445 if (GDK_WINDOW_DESTROYED (window))
3448 if (GDK_WINDOW_IS_MAPPED (window))
3449 gdk_wmspec_change_state (FALSE, window,
3450 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3451 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3453 gdk_synthesize_window_state (window,
3454 GDK_WINDOW_STATE_MAXIMIZED,
3459 * gdk_window_fullscreen:
3460 * @window: a #GdkWindow
3462 * Moves the window into fullscreen mode. This means the
3463 * window covers the entire screen and is above any panels
3466 * If the window was already fullscreen, then this function does nothing.
3468 * On X11, asks the window manager to put @window in a fullscreen
3469 * state, if the window manager supports this operation. Not all
3470 * window managers support this, and some deliberately ignore it or
3471 * don't have a concept of "fullscreen"; so you can't rely on the
3472 * fullscreenification actually happening. But it will happen with
3473 * most standard window managers, and GDK makes a best effort to get
3478 gdk_window_fullscreen (GdkWindow *window)
3480 g_return_if_fail (GDK_IS_WINDOW (window));
3482 if (GDK_WINDOW_DESTROYED (window))
3485 if (GDK_WINDOW_IS_MAPPED (window))
3486 gdk_wmspec_change_state (TRUE, window,
3487 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3491 gdk_synthesize_window_state (window,
3493 GDK_WINDOW_STATE_FULLSCREEN);
3497 * gdk_window_unfullscreen:
3498 * @window: a #GdkWindow
3500 * Moves the window out of fullscreen mode. If the window was not
3501 * fullscreen, does nothing.
3503 * On X11, asks the window manager to move @window out of the fullscreen
3504 * state, if the window manager supports this operation. Not all
3505 * window managers support this, and some deliberately ignore it or
3506 * don't have a concept of "fullscreen"; so you can't rely on the
3507 * unfullscreenification actually happening. But it will happen with
3508 * most standard window managers, and GDK makes a best effort to get
3513 gdk_window_unfullscreen (GdkWindow *window)
3515 g_return_if_fail (GDK_IS_WINDOW (window));
3517 if (GDK_WINDOW_DESTROYED (window))
3520 if (GDK_WINDOW_IS_MAPPED (window))
3521 gdk_wmspec_change_state (FALSE, window,
3522 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3526 gdk_synthesize_window_state (window,
3527 GDK_WINDOW_STATE_FULLSCREEN,
3533 * gdk_window_set_group:
3534 * @window: a #GdkWindow
3535 * @leader: group leader window
3537 * Sets the group leader window for @window. By default,
3538 * GDK sets the group leader for all toplevel windows
3539 * to a global window implicitly created by GDK. With this function
3540 * you can override this default.
3542 * The group leader window allows the window manager to distinguish
3543 * all windows that belong to a single application. It may for example
3544 * allow users to minimize/unminimize all windows belonging to an
3545 * application at once. You should only set a non-default group window
3546 * if your application pretends to be multiple applications.
3547 * The group leader window may not be changed after a window has been
3548 * mapped (with gdk_window_show() for example).
3552 gdk_window_set_group (GdkWindow *window,
3557 g_return_if_fail (window != NULL);
3558 g_return_if_fail (GDK_IS_WINDOW (window));
3559 g_return_if_fail (leader != NULL);
3560 g_return_if_fail (GDK_IS_WINDOW (leader));
3562 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3565 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3566 GDK_WINDOW_XID (window));
3568 wm_hints = XAllocWMHints ();
3570 wm_hints->flags |= WindowGroupHint;
3571 wm_hints->window_group = GDK_WINDOW_XID (leader);
3573 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3574 GDK_WINDOW_XID (window), wm_hints);
3578 static MotifWmHints *
3579 gdk_window_get_mwm_hints (GdkWindow *window)
3581 GdkDisplay *display;
3582 Atom hints_atom = None;
3583 MotifWmHints *hints;
3589 if (GDK_WINDOW_DESTROYED (window))
3592 display = gdk_drawable_get_display (window);
3594 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3596 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3597 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3598 False, AnyPropertyType, &type, &format, &nitems,
3599 &bytes_after, (guchar **)&hints);
3608 gdk_window_set_mwm_hints (GdkWindow *window,
3609 MotifWmHints *new_hints)
3611 GdkDisplay *display;
3612 Atom hints_atom = None;
3613 MotifWmHints *hints;
3619 if (GDK_WINDOW_DESTROYED (window))
3622 display = gdk_drawable_get_display (window);
3624 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3626 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3627 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3628 False, AnyPropertyType, &type, &format, &nitems,
3629 &bytes_after, (guchar **)&hints);
3635 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3637 hints->flags |= MWM_HINTS_FUNCTIONS;
3638 hints->functions = new_hints->functions;
3640 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3642 hints->flags |= MWM_HINTS_DECORATIONS;
3643 hints->decorations = new_hints->decorations;
3647 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3648 hints_atom, hints_atom, 32, PropModeReplace,
3649 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3651 if (hints != new_hints)
3656 * gdk_window_set_decorations:
3657 * @window: a #GdkWindow
3658 * @decorations: decoration hint mask
3660 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3661 * This function sets the traditional Motif window manager hints that tell the
3662 * window manager which decorations you would like your window to have.
3663 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3664 * using the GDK function directly.
3666 * The @decorations argument is the logical OR of the fields in
3667 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3668 * mask, the other bits indicate which decorations should be turned off.
3669 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3670 * which decorations should be turned on.
3672 * Most window managers honor a decorations hint of 0 to disable all decorations,
3673 * but very few honor all possible combinations of bits.
3677 gdk_window_set_decorations (GdkWindow *window,
3678 GdkWMDecoration decorations)
3682 g_return_if_fail (window != NULL);
3683 g_return_if_fail (GDK_IS_WINDOW (window));
3685 hints.flags = MWM_HINTS_DECORATIONS;
3686 hints.decorations = decorations;
3688 gdk_window_set_mwm_hints (window, &hints);
3692 * gdk_window_get_decorations:
3693 * @window: The #GdkWindow to get the decorations from
3694 * @decorations: The window decorations will be written here
3696 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3697 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3700 gdk_window_get_decorations(GdkWindow *window,
3701 GdkWMDecoration *decorations)
3703 MotifWmHints *hints;
3704 gboolean result = FALSE;
3706 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3708 hints = gdk_window_get_mwm_hints (window);
3712 if (hints->flags & MWM_HINTS_DECORATIONS)
3715 *decorations = hints->decorations;
3726 * gdk_window_set_functions:
3727 * @window: a #GdkWindow
3728 * @functions: bitmask of operations to allow on @window
3730 * This function isn't really good for much. It sets the traditional
3731 * Motif window manager hint for which operations the window manager
3732 * should allow on a toplevel window. However, few window managers do
3733 * anything reliable or interesting with this hint. Many ignore it
3736 * The @functions argument is the logical OR of values from the
3737 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3738 * then the other bits indicate which functions to disable; if
3739 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3744 gdk_window_set_functions (GdkWindow *window,
3745 GdkWMFunction functions)
3749 g_return_if_fail (window != NULL);
3750 g_return_if_fail (GDK_IS_WINDOW (window));
3752 hints.flags = MWM_HINTS_FUNCTIONS;
3753 hints.functions = functions;
3755 gdk_window_set_mwm_hints (window, &hints);
3758 #ifdef HAVE_SHAPE_EXT
3761 * propagate the shapes from all child windows of a GDK window to the parent
3762 * window. Shamelessly ripped from Enlightenment's code
3770 struct _gdk_span *next;
3774 gdk_add_to_span (struct _gdk_span **s,
3778 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3785 /* scan the spans for this line */
3788 /* -- -> new span */
3789 /* == -> existing span */
3790 /* ## -> spans intersect */
3791 /* if we are in the middle of spanning the span into the line */
3794 /* case: ---- ==== */
3795 if (xx < ptr1->start - 1)
3797 /* ends before next span - extend to here */
3801 /* case: ----##=== */
3802 else if (xx <= ptr1->end)
3804 /* crosses into next span - delete next span and append */
3805 ss->end = ptr1->end;
3806 ss->next = ptr1->next;
3810 /* case: ---###--- */
3813 /* overlaps next span - delete and keep checking */
3814 ss->next = ptr1->next;
3819 /* otherwise havent started spanning it in yet */
3822 /* case: ---- ==== */
3823 if (xx < ptr1->start - 1)
3825 /* insert span here in list */
3826 noo = g_malloc (sizeof (struct _gdk_span));
3840 /* case: ----##=== */
3841 else if ((x < ptr1->start) && (xx <= ptr1->end))
3843 /* expand this span to the left point of the new one */
3847 /* case: ===###=== */
3848 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3850 /* throw the span away */
3853 /* case: ---###--- */
3854 else if ((x < ptr1->start) && (xx > ptr1->end))
3861 /* case: ===##---- */
3862 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3868 /* case: ==== ---- */
3869 /* case handled by next loop iteration - first case */
3874 /* it started in the middle but spans beyond your current list */
3880 /* it does not start inside a span or in the middle, so add it to the end */
3881 noo = g_malloc (sizeof (struct _gdk_span));
3889 noo->next = ptr2->next;
3902 gdk_add_rectangles (Display *disp,
3904 struct _gdk_span **spans,
3911 gint x1, y1, x2, y2;
3915 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
3918 /* go through all clip rects in this window's shape */
3919 for (k = 0; k < rn; k++)
3921 /* for each clip rect, add it to each line's spans */
3923 x2 = x + rl[k].x + (rl[k].width - 1);
3925 y2 = y + rl[k].y + (rl[k].height - 1);
3934 for (a = y1; a <= y2; a++)
3937 gdk_add_to_span (&spans[a], x1, x2);
3945 gdk_propagate_shapes (Display *disp,
3949 Window rt, par, *list = NULL;
3950 gint i, j, num = 0, num_rects = 0;
3954 XRectangle *rects = NULL;
3955 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
3956 XWindowAttributes xatt;
3958 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
3963 spans = g_malloc (sizeof (struct _gdk_span *) * h);
3965 for (i = 0; i < h; i++)
3967 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
3970 /* go through all child windows and create/insert spans */
3971 for (i = 0; i < num; i++)
3973 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
3974 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
3975 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
3978 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
3980 /* go through the spans list and build a list of rects */
3981 rects = g_malloc (sizeof (XRectangle) * 256);
3983 for (i = 0; i < baseh; i++)
3986 /* go through the line for all spans */
3989 rects[num_rects].x = ptr1->start;
3990 rects[num_rects].y = i;
3991 rects[num_rects].width = ptr1->end - ptr1->start + 1;
3992 rects[num_rects].height = 1;
3994 /* if there are more lines */
3996 /* while contigous rects (same start/end coords) exist */
3997 while ((contig) && (j < baseh))
3999 /* search next line for spans matching this one */
4005 /* if we have an exact span match set contig */
4006 if ((ptr2->start == ptr1->start) &&
4007 (ptr2->end == ptr1->end))
4010 /* remove the span - not needed */
4013 ptr3->next = ptr2->next;
4019 spans[j] = ptr2->next;
4025 /* gone past the span point no point looking */
4026 else if (ptr2->start < ptr1->start)
4034 /* if a contiguous span was found increase the rect h */
4037 rects[num_rects].height++;
4041 /* up the rect count */
4043 /* every 256 new rects increase the rect array */
4044 if ((num_rects % 256) == 0)
4045 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
4049 /* set the rects as the shape mask */
4052 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
4053 ShapeSet, YXSorted);
4058 /* free up all the spans we made */
4059 for (i = 0; i < baseh; i++)
4072 #endif /* HAVE_SHAPE_EXT */
4075 * gdk_window_set_child_shapes:
4076 * @window: a #GdkWindow
4078 * Sets the shape mask of @window to the union of shape masks
4079 * for all children of @window, ignoring the shape mask of @window
4080 * itself. Contrast with gdk_window_merge_child_shapes() which includes
4081 * the shape mask of @window in the masks to be merged.
4084 gdk_window_set_child_shapes (GdkWindow *window)
4086 g_return_if_fail (window != NULL);
4087 g_return_if_fail (GDK_IS_WINDOW (window));
4089 #ifdef HAVE_SHAPE_EXT
4090 if (!GDK_WINDOW_DESTROYED (window) &&
4091 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4092 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4093 GDK_WINDOW_XID (window), FALSE);
4098 * gdk_window_merge_child_shapes:
4099 * @window: a #GdkWindow
4101 * Merges the shape masks for any child windows into the
4102 * shape mask for @window. i.e. the union of all masks
4103 * for @window and its children will become the new mask
4104 * for @window. See gdk_window_shape_combine_mask().
4106 * This function is distinct from gdk_window_set_child_shapes()
4107 * because it includes @window's shape mask in the set of shapes to
4112 gdk_window_merge_child_shapes (GdkWindow *window)
4114 g_return_if_fail (window != NULL);
4115 g_return_if_fail (GDK_IS_WINDOW (window));
4117 #ifdef HAVE_SHAPE_EXT
4118 if (!GDK_WINDOW_DESTROYED (window) &&
4119 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4120 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4121 GDK_WINDOW_XID (window), TRUE);
4125 /* Support for windows that can be guffaw-scrolled
4126 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
4130 gdk_window_gravity_works (GdkWindow *window)
4132 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (window));
4134 if (display_x11->gravity_works == GDK_UNKNOWN)
4141 /* This particular server apparently has a bug so that the test
4142 * works but the actual code crashes it
4144 if ((!strcmp (XServerVendor (display_x11->xdisplay),
4145 "Sun Microsystems, Inc.")) &&
4146 (VendorRelease (display_x11->xdisplay) == 3400))
4148 display_x11->gravity_works = GDK_NO;
4152 attr.window_type = GDK_WINDOW_TEMP;
4153 attr.wclass = GDK_INPUT_OUTPUT;
4158 attr.event_mask = 0;
4160 parent = gdk_window_new (gdk_screen_get_root_window (GDK_DRAWABLE_SCREEN (window)),
4161 &attr, GDK_WA_X | GDK_WA_Y);
4163 attr.window_type = GDK_WINDOW_CHILD;
4164 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
4166 gdk_window_set_static_win_gravity (child, TRUE);
4168 gdk_window_resize (parent, 100, 110);
4170 gdk_window_move (parent, 0, -10);
4171 gdk_window_move_resize (parent, 0, 0, 100, 100);
4173 gdk_window_resize (parent, 100, 110);
4174 gdk_window_move (parent, 0, -10);
4175 gdk_window_move_resize (parent, 0, 0, 100, 100);
4177 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
4179 gdk_window_destroy (parent);
4180 gdk_window_destroy (child);
4182 display_x11->gravity_works = ((y == -20) ? GDK_YES : GDK_NO);
4185 return (display_x11->gravity_works == GDK_YES);
4189 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
4191 XSetWindowAttributes xattributes;
4192 GdkWindowObject *private;
4193 guint xattributes_mask = 0;
4195 g_return_if_fail (window != NULL);
4197 private = GDK_WINDOW_OBJECT (window);
4198 if (private->input_only)
4201 xattributes.bit_gravity = StaticGravity;
4202 xattributes_mask |= CWBitGravity;
4203 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4204 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4205 GDK_WINDOW_XID (window),
4206 CWBitGravity, &xattributes);
4210 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4212 XSetWindowAttributes xattributes;
4214 g_return_if_fail (window != NULL);
4216 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4218 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4219 GDK_WINDOW_XID (window),
4220 CWWinGravity, &xattributes);
4224 * gdk_window_set_static_gravities:
4225 * @window: a #GdkWindow
4226 * @use_static: %TRUE to turn on static gravity
4228 * Set the bit gravity of the given window to static, and flag it so
4229 * all children get static subwindow gravity. This is used if you are
4230 * implementing scary features that involve deep knowledge of the
4231 * windowing system. Don't worry about it unless you have to.
4233 * Return value: %TRUE if the server supports static gravity
4236 gdk_window_set_static_gravities (GdkWindow *window,
4237 gboolean use_static)
4239 GdkWindowObject *private = (GdkWindowObject *)window;
4242 g_return_val_if_fail (window != NULL, FALSE);
4243 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4245 if (!use_static == !private->guffaw_gravity)
4248 if (use_static && !gdk_window_gravity_works (window))
4251 private->guffaw_gravity = use_static;
4253 if (!GDK_WINDOW_DESTROYED (window))
4255 gdk_window_set_static_bit_gravity (window, use_static);
4257 tmp_list = private->children;
4260 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4262 tmp_list = tmp_list->next;
4270 wmspec_moveresize (GdkWindow *window,
4276 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4280 /* Release passive grab */
4281 gdk_display_pointer_ungrab (display, timestamp);
4283 xev.xclient.type = ClientMessage;
4284 xev.xclient.serial = 0;
4285 xev.xclient.send_event = True;
4286 xev.xclient.window = GDK_WINDOW_XID (window);
4287 xev.xclient.message_type =
4288 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4289 xev.xclient.format = 32;
4290 xev.xclient.data.l[0] = root_x;
4291 xev.xclient.data.l[1] = root_y;
4292 xev.xclient.data.l[2] = direction;
4293 xev.xclient.data.l[3] = 0;
4294 xev.xclient.data.l[4] = 0;
4296 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4297 SubstructureRedirectMask | SubstructureNotifyMask,
4301 typedef struct _MoveResizeData MoveResizeData;
4303 struct _MoveResizeData
4305 GdkDisplay *display;
4307 GdkWindow *moveresize_window;
4308 GdkWindow *moveresize_emulation_window;
4310 GdkWindowEdge resize_edge;
4311 gint moveresize_button;
4314 gint moveresize_orig_x;
4315 gint moveresize_orig_y;
4316 gint moveresize_orig_width;
4317 gint moveresize_orig_height;
4318 GdkWindowHints moveresize_geom_mask;
4319 GdkGeometry moveresize_geometry;
4320 Time moveresize_process_time;
4321 XEvent *moveresize_pending_event;
4324 /* From the WM spec */
4325 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4326 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4327 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4328 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4329 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4330 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4331 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4332 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4333 #define _NET_WM_MOVERESIZE_MOVE 8
4336 wmspec_resize_drag (GdkWindow *window,
4345 /* Let the compiler turn a switch into a table, instead
4346 * of doing the table manually, this way is easier to verify.
4350 case GDK_WINDOW_EDGE_NORTH_WEST:
4351 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4354 case GDK_WINDOW_EDGE_NORTH:
4355 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4358 case GDK_WINDOW_EDGE_NORTH_EAST:
4359 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4362 case GDK_WINDOW_EDGE_WEST:
4363 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4366 case GDK_WINDOW_EDGE_EAST:
4367 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4370 case GDK_WINDOW_EDGE_SOUTH_WEST:
4371 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4374 case GDK_WINDOW_EDGE_SOUTH:
4375 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4378 case GDK_WINDOW_EDGE_SOUTH_EAST:
4379 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4383 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4389 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4392 static MoveResizeData *
4393 get_move_resize_data (GdkDisplay *display,
4396 MoveResizeData *mv_resize;
4397 static GQuark move_resize_quark = 0;
4399 if (!move_resize_quark)
4400 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4402 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4404 if (!mv_resize && create)
4406 mv_resize = g_new0 (MoveResizeData, 1);
4407 mv_resize->display = display;
4409 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4416 update_pos (MoveResizeData *mv_resize,
4422 dx = new_root_x - mv_resize->moveresize_x;
4423 dy = new_root_y - mv_resize->moveresize_y;
4425 if (mv_resize->is_resize)
4429 w = mv_resize->moveresize_orig_width;
4430 h = mv_resize->moveresize_orig_height;
4432 switch (mv_resize->resize_edge)
4434 case GDK_WINDOW_EDGE_SOUTH_EAST:
4443 if (mv_resize->moveresize_geom_mask)
4445 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4446 mv_resize->moveresize_geom_mask,
4450 gdk_window_resize (mv_resize->moveresize_window, w, h);
4456 x = mv_resize->moveresize_orig_x + dx;
4457 y = mv_resize->moveresize_orig_y + dy;
4459 gdk_window_move (mv_resize->moveresize_window, x, y);
4464 finish_drag (MoveResizeData *mv_resize)
4466 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4467 mv_resize->moveresize_emulation_window = NULL;
4468 mv_resize->moveresize_window = NULL;
4470 if (mv_resize->moveresize_pending_event)
4472 g_free (mv_resize->moveresize_pending_event);
4473 mv_resize->moveresize_pending_event = NULL;
4478 lookahead_motion_predicate (Display *xdisplay,
4482 gboolean *seen_release = (gboolean *)arg;
4483 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4484 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4489 switch (event->xany.type)
4492 *seen_release = TRUE;
4495 mv_resize->moveresize_process_time = event->xmotion.time;
4505 moveresize_lookahead (MoveResizeData *mv_resize,
4509 gboolean seen_release = FALSE;
4511 if (mv_resize->moveresize_process_time)
4513 if (event->xmotion.time == mv_resize->moveresize_process_time)
4515 mv_resize->moveresize_process_time = 0;
4522 XCheckIfEvent (event->xany.display, &tmp_event,
4523 lookahead_motion_predicate, (XPointer) & seen_release);
4525 return mv_resize->moveresize_process_time == 0;
4529 _gdk_moveresize_handle_event (XEvent *event)
4531 guint button_mask = 0;
4532 GdkWindowObject *window_private;
4533 GdkDisplay *display= gdk_x11_lookup_xdisplay (event->xany.display);
4534 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4536 if (!mv_resize || mv_resize->moveresize_window)
4539 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
4541 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4543 switch (event->xany.type)
4546 if (window_private->resize_count > 0)
4548 if (mv_resize->moveresize_pending_event)
4549 *mv_resize->moveresize_pending_event = *event;
4551 mv_resize->moveresize_pending_event =
4552 g_memdup (event, sizeof (XEvent));
4556 if (!moveresize_lookahead (mv_resize, event))
4559 update_pos (mv_resize,
4560 event->xmotion.x_root,
4561 event->xmotion.y_root);
4563 /* This should never be triggered in normal cases, but in the
4564 * case where the drag started without an implicit grab being
4565 * in effect, we could miss the release if it occurs before
4566 * we grab the pointer; this ensures that we will never
4567 * get a permanently stuck grab.
4569 if ((event->xmotion.state & button_mask) == 0)
4570 finish_drag (mv_resize);
4574 update_pos (mv_resize,
4575 event->xbutton.x_root,
4576 event->xbutton.y_root);
4578 if (event->xbutton.button == mv_resize->moveresize_button)
4579 finish_drag (mv_resize);
4586 _gdk_moveresize_configure_done (GdkDisplay *display,
4590 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4592 if (!mv_resize || window != mv_resize->moveresize_window)
4595 if (mv_resize->moveresize_pending_event)
4597 tmp_event = mv_resize->moveresize_pending_event;
4598 mv_resize->moveresize_pending_event = NULL;
4599 _gdk_moveresize_handle_event (tmp_event);
4607 create_moveresize_window (MoveResizeData *mv_resize,
4610 GdkWindowAttr attributes;
4611 gint attributes_mask;
4612 GdkGrabStatus status;
4614 g_assert (mv_resize->moveresize_emulation_window == NULL);
4616 attributes.x = -100;
4617 attributes.y = -100;
4618 attributes.width = 10;
4619 attributes.height = 10;
4620 attributes.window_type = GDK_WINDOW_TEMP;
4621 attributes.wclass = GDK_INPUT_ONLY;
4622 attributes.override_redirect = TRUE;
4623 attributes.event_mask = 0;
4625 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4627 mv_resize->moveresize_emulation_window =
4628 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4632 gdk_window_show (mv_resize->moveresize_emulation_window);
4634 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4636 GDK_BUTTON_RELEASE_MASK |
4637 GDK_POINTER_MOTION_MASK,
4642 if (status != GDK_GRAB_SUCCESS)
4644 /* If this fails, some other client has grabbed the window
4647 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4648 mv_resize->moveresize_emulation_window = NULL;
4651 mv_resize->moveresize_process_time = 0;
4655 emulate_resize_drag (GdkWindow *window,
4662 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4664 mv_resize->is_resize = TRUE;
4665 mv_resize->moveresize_button = button;
4666 mv_resize->resize_edge = edge;
4667 mv_resize->moveresize_x = root_x;
4668 mv_resize->moveresize_y = root_y;
4669 mv_resize->moveresize_window = g_object_ref (window);
4671 gdk_drawable_get_size (window,
4672 &mv_resize->moveresize_orig_width,
4673 &mv_resize->moveresize_orig_height);
4675 mv_resize->moveresize_geom_mask = 0;
4676 gdk_window_get_geometry_hints (window,
4677 &mv_resize->moveresize_geometry,
4678 &mv_resize->moveresize_geom_mask);
4680 create_moveresize_window (mv_resize, timestamp);
4684 emulate_move_drag (GdkWindow *window,
4690 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4692 mv_resize->is_resize = FALSE;
4693 mv_resize->moveresize_button = button;
4694 mv_resize->moveresize_x = root_x;
4695 mv_resize->moveresize_y = root_y;
4697 mv_resize->moveresize_window = g_object_ref (window);
4699 gdk_window_get_deskrelative_origin (mv_resize->moveresize_window,
4700 &mv_resize->moveresize_orig_x,
4701 &mv_resize->moveresize_orig_y);
4703 create_moveresize_window (mv_resize, timestamp);
4707 * gdk_window_begin_resize_drag:
4708 * @window: a #GdkWindow
4709 * @edge: the edge or corner from which the drag is started
4710 * @button: the button being used to drag
4711 * @root_x: root window X coordinate of mouse click that began the drag
4712 * @root_y: root window Y coordinate of mouse click that began the drag
4713 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4715 * Begins a window resize operation (for a toplevel window).
4716 * You might use this function to implement a "window resize grip," for
4717 * example; in fact #GtkStatusbar uses it. The function works best
4718 * with window managers that support the Extended Window Manager Hints spec
4719 * (see http://www.freedesktop.org), but has a fallback implementation
4720 * for other window managers.
4724 gdk_window_begin_resize_drag (GdkWindow *window,
4731 g_return_if_fail (GDK_IS_WINDOW (window));
4733 if (GDK_WINDOW_DESTROYED (window))
4736 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4737 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4738 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4740 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4744 * gdk_window_begin_move_drag:
4745 * @window: a #GdkWindow
4746 * @button: the button being used to drag
4747 * @root_x: root window X coordinate of mouse click that began the drag
4748 * @root_y: root window Y coordinate of mouse click that began the drag
4749 * @timestamp: timestamp of mouse click that began the drag
4751 * Begins a window move operation (for a toplevel window). You might
4752 * use this function to implement a "window move grip," for
4753 * example. The function works best with window managers that support
4754 * the Extended Window Manager Hints spec (see
4755 * http://www.freedesktop.org), but has a fallback implementation for
4756 * other window managers.
4760 gdk_window_begin_move_drag (GdkWindow *window,
4766 g_return_if_fail (GDK_IS_WINDOW (window));
4768 if (GDK_WINDOW_DESTROYED (window))
4771 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4772 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4773 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
4776 emulate_move_drag (window, button, root_x, root_y, timestamp);