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/.
30 #include <X11/Xutil.h>
31 #include <X11/Xatom.h>
32 #include <netinet/in.h>
36 #include "gdkwindow.h"
38 #include "gdkinputprivate.h"
39 #include "gdkdisplay-x11.h"
40 #include "gdkprivate-x11.h"
41 #include "gdkregion.h"
42 #include "gdkinternals.h"
44 #include "gdkwindow-x11.h"
52 #include <X11/extensions/shape.h>
55 const int _gdk_event_mask_table[21] =
59 PointerMotionHintMask,
76 SubstructureNotifyMask,
77 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
79 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
81 /* Forward declarations */
82 static void gdk_window_set_static_win_gravity (GdkWindow *window,
84 static gboolean gdk_window_have_shape_ext (GdkDisplay *display);
85 static gboolean gdk_window_icon_name_set (GdkWindow *window);
86 static void gdk_window_add_colormap_windows (GdkWindow *window);
87 static void set_wm_name (GdkDisplay *display,
91 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
92 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
94 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
97 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
98 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
99 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
100 static void gdk_window_impl_x11_finalize (GObject *object);
102 static gpointer parent_class = NULL;
104 #define WINDOW_IS_TOPLEVEL(window) \
105 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
106 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
109 gdk_window_impl_x11_get_type (void)
111 static GType object_type = 0;
115 static const GTypeInfo object_info =
117 sizeof (GdkWindowImplX11Class),
118 (GBaseInitFunc) NULL,
119 (GBaseFinalizeFunc) NULL,
120 (GClassInitFunc) gdk_window_impl_x11_class_init,
121 NULL, /* class_finalize */
122 NULL, /* class_data */
123 sizeof (GdkWindowImplX11),
125 (GInstanceInitFunc) gdk_window_impl_x11_init,
128 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
137 _gdk_window_impl_get_type (void)
139 return gdk_window_impl_x11_get_type ();
143 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
147 impl->toplevel_window_type = -1;
151 _gdk_x11_window_get_toplevel (GdkWindow *window)
153 GdkWindowObject *private;
154 GdkWindowImplX11 *impl;
156 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
158 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
161 private = (GdkWindowObject *)window;
162 impl = GDK_WINDOW_IMPL_X11 (private->impl);
165 impl->toplevel = g_new0 (GdkToplevelX11, 1);
167 return impl->toplevel;
171 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
173 GObjectClass *object_class = G_OBJECT_CLASS (klass);
174 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
176 parent_class = g_type_class_peek_parent (klass);
178 object_class->finalize = gdk_window_impl_x11_finalize;
180 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
181 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
182 drawable_class->get_size = gdk_window_impl_x11_get_size;
184 /* Visible and clip regions are the same */
185 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
186 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
190 gdk_window_impl_x11_finalize (GObject *object)
192 GdkWindowObject *wrapper;
193 GdkDrawableImplX11 *draw_impl;
194 GdkWindowImplX11 *window_impl;
196 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
198 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
199 window_impl = GDK_WINDOW_IMPL_X11 (object);
201 wrapper = (GdkWindowObject*) draw_impl->wrapper;
203 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
205 if (!GDK_WINDOW_DESTROYED (wrapper))
207 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
209 _gdk_xid_table_remove (display, draw_impl->xid);
210 if (window_impl->toplevel && window_impl->toplevel->focus_window)
211 _gdk_xid_table_remove (display, window_impl->toplevel->focus_window);
214 if (window_impl->toplevel)
215 g_free (window_impl->toplevel);
217 G_OBJECT_CLASS (parent_class)->finalize (object);
221 tmp_unset_bg (GdkWindow *window)
223 GdkWindowImplX11 *impl;
224 GdkWindowObject *obj;
226 obj = (GdkWindowObject *) window;
227 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
229 impl->position_info.no_bg = TRUE;
231 if (obj->bg_pixmap != GDK_NO_BG)
232 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
233 GDK_DRAWABLE_XID (window), None);
237 tmp_reset_bg (GdkWindow *window)
239 GdkWindowImplX11 *impl;
240 GdkWindowObject *obj;
242 obj = (GdkWindowObject *) window;
243 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
245 impl->position_info.no_bg = FALSE;
247 if (obj->bg_pixmap == GDK_NO_BG)
254 if (obj->bg_pixmap == GDK_PARENT_RELATIVE_BG)
255 xpixmap = ParentRelative;
257 xpixmap = GDK_DRAWABLE_XID (obj->bg_pixmap);
259 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
260 GDK_DRAWABLE_XID (window), xpixmap);
264 XSetWindowBackground (GDK_DRAWABLE_XDISPLAY (window),
265 GDK_DRAWABLE_XID (window),
266 obj->bg_color.pixel);
271 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
274 GdkWindowObject *private;
276 g_return_if_fail (GDK_IS_WINDOW (window));
278 private = (GdkWindowObject *)window;
280 if (private->input_only || private->destroyed ||
281 (private->window_type != GDK_WINDOW_ROOT &&
282 !GDK_WINDOW_IS_MAPPED (window)))
287 /* Don't unset the background of windows that don't select for expose
288 * events. Such windows don't get drawn, so we need the X server
289 * drawing them to prevent them from containing garbage
291 if (private->window_type != GDK_WINDOW_ROOT &&
292 private->window_type != GDK_WINDOW_FOREIGN &&
293 (private->event_mask & GDK_EXPOSURE_MASK))
295 tmp_unset_bg (window);
302 for (l = private->children; l != NULL; l = l->next)
303 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
308 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
311 GdkWindowObject *private;
313 g_return_if_fail (GDK_IS_WINDOW (window));
315 private = (GdkWindowObject *)window;
317 if (private->input_only || private->destroyed ||
318 (private->window_type != GDK_WINDOW_ROOT &&
319 !GDK_WINDOW_IS_MAPPED (window)))
324 if (private->window_type != GDK_WINDOW_ROOT &&
325 private->window_type != GDK_WINDOW_FOREIGN &&
326 (private->event_mask & GDK_EXPOSURE_MASK))
328 tmp_reset_bg (window);
335 for (l = private->children; l != NULL; l = l->next)
336 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
341 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
343 GdkDrawableImplX11 *drawable_impl;
344 GdkWindowImplX11 *window_impl;
346 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
348 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
349 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
351 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
352 drawable_impl->colormap == NULL)
354 XWindowAttributes window_attributes;
357 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
361 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
362 window_attributes.visual->visualid);
363 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
364 window_attributes.colormap);
367 return drawable_impl->colormap;
371 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
374 GdkWindowImplX11 *impl;
375 GdkDrawableImplX11 *draw_impl;
377 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
379 impl = GDK_WINDOW_IMPL_X11 (drawable);
380 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
382 if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper))
386 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
390 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
392 GDK_COLORMAP_XCOLORMAP (cmap));
394 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
396 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
402 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
406 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
409 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
411 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
415 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
417 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
418 GdkRectangle result_rect;
422 result_rect.width = impl->width;
423 result_rect.height = impl->height;
425 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
427 return gdk_region_rectangle (&result_rect);
431 _gdk_windowing_window_init (GdkScreen * screen)
433 GdkWindowObject *private;
434 GdkWindowImplX11 *impl;
435 GdkDrawableImplX11 *draw_impl;
436 GdkScreenX11 *screen_x11;
438 screen_x11 = GDK_SCREEN_X11 (screen);
440 g_assert (screen_x11->root_window == NULL);
442 gdk_screen_set_default_colormap (screen,
443 gdk_screen_get_system_colormap (screen));
445 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
446 private = (GdkWindowObject *)screen_x11->root_window;
447 impl = GDK_WINDOW_IMPL_X11 (private->impl);
448 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
450 draw_impl->screen = screen;
451 draw_impl->xid = screen_x11->xroot_window;
452 draw_impl->wrapper = GDK_DRAWABLE (private);
453 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
454 g_object_ref (draw_impl->colormap);
456 private->window_type = GDK_WINDOW_ROOT;
457 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
459 impl->width = WidthOfScreen (screen_x11->xscreen);
460 impl->height = HeightOfScreen (screen_x11->xscreen);
462 _gdk_window_init_position (GDK_WINDOW (private));
464 _gdk_xid_table_insert (screen_x11->display,
465 &screen_x11->xroot_window,
466 screen_x11->root_window);
470 set_wm_protocols (GdkWindow *window)
472 GdkDisplay *display = gdk_drawable_get_display (window);
475 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
476 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
477 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
479 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
483 get_default_title (void)
487 title = g_get_application_name ();
489 title = g_get_prgname ();
495 check_leader_window_title (GdkDisplay *display)
497 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
499 if (display_x11->leader_window && !display_x11->leader_window_title_set)
501 set_wm_name (display,
502 display_x11->leader_window,
503 get_default_title ());
505 display_x11->leader_window_title_set = TRUE;
510 create_focus_window (Display *xdisplay,
513 Window focus_window = XCreateSimpleWindow (xdisplay, parent,
517 /* FIXME: probably better to actually track the requested event mask for the toplevel
519 XSelectInput (xdisplay, focus_window,
520 KeyPressMask | KeyReleaseMask | FocusChangeMask);
522 XMapWindow (xdisplay, focus_window);
528 setup_toplevel_window (GdkWindow *window, GdkWindow *parent)
530 GdkWindowObject *obj = (GdkWindowObject *)window;
531 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
532 GdkWindowImplX11 *impl = (GdkWindowImplX11 *)obj->impl;
533 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
534 XID xid = GDK_WINDOW_XID (window);
535 XID xparent = GDK_WINDOW_XID (parent);
536 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
537 XSizeHints size_hints;
540 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_DIALOG)
541 XSetTransientForHint (xdisplay, xid, xparent);
543 set_wm_protocols (window);
545 if (!obj->input_only)
547 /* The focus window is off the visible area, and serves to receive key
548 * press events so they don't get sent to child windows.
550 toplevel->focus_window = create_focus_window (xdisplay, xid);
551 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
554 check_leader_window_title (screen_x11->display);
556 /* FIXME: Is there any point in doing this? Do any WM's pay
557 * attention to PSize, and even if they do, is this the
560 size_hints.flags = PSize;
561 size_hints.width = impl->width;
562 size_hints.height = impl->height;
564 XSetWMNormalHints (xdisplay, xid, &size_hints);
566 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
567 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
570 XChangeProperty (xdisplay, xid,
571 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
576 XChangeProperty (xdisplay, xid,
577 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
578 XA_WINDOW, 32, PropModeReplace,
579 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
581 if (!obj->focus_on_map)
582 gdk_x11_window_set_user_time (window, 0);
583 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
584 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
589 * @parent: a #GdkWindow, or %NULL to create the window as a child of
590 * the default root window for the default display.
591 * @attributes: attributes of the new window
592 * @attributes_mask: mask indicating which fields in @attributes are valid
594 * Creates a new #GdkWindow using the attributes from
595 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
596 * more details. Note: to use this on displays other than the default
597 * display, @parent must be specified.
599 * Return value: the new #GdkWindow
602 gdk_window_new (GdkWindow *parent,
603 GdkWindowAttr *attributes,
604 gint attributes_mask)
607 GdkWindowObject *private;
608 GdkWindowImplX11 *impl;
609 GdkDrawableImplX11 *draw_impl;
610 GdkScreenX11 *screen_x11;
619 XSetWindowAttributes xattributes;
620 long xattributes_mask;
621 XClassHint *class_hint;
628 g_return_val_if_fail (attributes != NULL, NULL);
633 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
635 screen = gdk_screen_get_default ();
636 parent = gdk_screen_get_root_window (screen);
639 screen = gdk_drawable_get_screen (parent);
641 screen_x11 = GDK_SCREEN_X11 (screen);
643 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
645 if (GDK_WINDOW_DESTROYED (parent))
648 xparent = GDK_WINDOW_XID (parent);
650 window = g_object_new (GDK_TYPE_WINDOW, NULL);
651 private = (GdkWindowObject *)window;
652 impl = GDK_WINDOW_IMPL_X11 (private->impl);
653 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
654 draw_impl->wrapper = GDK_DRAWABLE (window);
656 draw_impl->screen = screen;
657 xdisplay = screen_x11->xdisplay;
659 /* Windows with a foreign parent are treated as if they are children
660 * of the root window, except for actual creation.
662 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
663 parent = gdk_screen_get_root_window (screen);
665 private->parent = (GdkWindowObject *)parent;
667 private->accept_focus = TRUE;
668 private->focus_on_map = TRUE;
670 xattributes_mask = 0;
672 if (attributes_mask & GDK_WA_X)
677 if (attributes_mask & GDK_WA_Y)
684 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
685 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
687 if (attributes->wclass == GDK_INPUT_ONLY)
689 /* Backwards compatiblity - we've always ignored
690 * attributes->window_type for input-only windows
693 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
694 private->window_type = GDK_WINDOW_TEMP;
696 private->window_type = GDK_WINDOW_CHILD;
699 private->window_type = attributes->window_type;
701 _gdk_window_init_position (GDK_WINDOW (private));
702 if (impl->position_info.big)
703 private->guffaw_gravity = TRUE;
705 if (attributes_mask & GDK_WA_VISUAL)
706 visual = attributes->visual;
708 visual = gdk_screen_get_system_visual (screen);
709 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
711 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
712 for (i = 0; i < _gdk_nenvent_masks; i++)
714 if (attributes->event_mask & (1 << (i + 1)))
715 xattributes.event_mask |= _gdk_event_mask_table[i];
717 private->event_mask = attributes->event_mask;
719 if (xattributes.event_mask)
720 xattributes_mask |= CWEventMask;
722 if (attributes_mask & GDK_WA_NOREDIR)
724 xattributes.override_redirect =
725 (attributes->override_redirect == FALSE)?False:True;
726 xattributes_mask |= CWOverrideRedirect;
729 xattributes.override_redirect = False;
731 impl->override_redirect = xattributes.override_redirect;
733 if (private->parent && private->parent->guffaw_gravity)
735 xattributes.win_gravity = StaticGravity;
736 xattributes_mask |= CWWinGravity;
740 switch (private->window_type)
742 case GDK_WINDOW_TOPLEVEL:
743 case GDK_WINDOW_DIALOG:
744 case GDK_WINDOW_TEMP:
745 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
747 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
748 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
749 xparent = GDK_SCREEN_XROOTWIN (screen);
751 case GDK_WINDOW_CHILD:
754 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
758 if (attributes->wclass == GDK_INPUT_OUTPUT)
761 depth = visual->depth;
763 private->input_only = FALSE;
764 private->depth = depth;
766 if (attributes_mask & GDK_WA_COLORMAP)
768 draw_impl->colormap = attributes->colormap;
769 g_object_ref (attributes->colormap);
773 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
775 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
776 g_object_ref (draw_impl->colormap);
780 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
784 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
785 xattributes.background_pixel = private->bg_color.pixel;
787 private->bg_pixmap = NULL;
789 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
790 xattributes_mask |= CWBorderPixel | CWBackPixel;
792 if (private->guffaw_gravity)
793 xattributes.bit_gravity = StaticGravity;
795 xattributes.bit_gravity = NorthWestGravity;
797 xattributes_mask |= CWBitGravity;
799 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
800 xattributes_mask |= CWColormap;
802 if (private->window_type == GDK_WINDOW_TEMP)
804 xattributes.save_under = True;
805 xattributes.override_redirect = True;
806 xattributes.cursor = None;
807 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
809 impl->override_redirect = TRUE;
817 private->input_only = TRUE;
818 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
819 g_object_ref (draw_impl->colormap);
822 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
823 impl->position_info.x, impl->position_info.y,
824 impl->position_info.width, impl->position_info.height,
825 0, depth, class, xvisual,
826 xattributes_mask, &xattributes);
828 g_object_ref (window);
829 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
831 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
832 (attributes->cursor) :
836 private->parent->children = g_list_prepend (private->parent->children, window);
838 switch (GDK_WINDOW_TYPE (private))
840 case GDK_WINDOW_DIALOG:
841 case GDK_WINDOW_TOPLEVEL:
842 case GDK_WINDOW_TEMP:
843 if (attributes_mask & GDK_WA_TITLE)
844 title = attributes->title;
846 title = get_default_title ();
848 gdk_window_set_title (window, title);
850 if (attributes_mask & GDK_WA_WMCLASS)
852 class_hint = XAllocClassHint ();
853 class_hint->res_name = attributes->wmclass_name;
854 class_hint->res_class = attributes->wmclass_class;
855 XSetClassHint (xdisplay, xid, class_hint);
859 setup_toplevel_window (window, parent);
862 case GDK_WINDOW_CHILD:
863 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
864 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
865 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
867 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
868 gdk_window_add_colormap_windows (window);
880 x_event_mask_to_gdk_event_mask (long mask)
882 GdkEventMask event_mask = 0;
885 for (i = 0; i < _gdk_nenvent_masks; i++)
887 if (mask & _gdk_event_mask_table[i])
888 event_mask |= 1 << (i + 1);
895 * gdk_window_foreign_new_for_display:
896 * @display: the #GdkDisplay where the window handle comes from.
897 * @anid: a native window handle.
899 * Wraps a native window in a #GdkWindow.
900 * This may fail if the window has been destroyed.
902 * For example in the X backend, a native window handle is an Xlib
905 * Return value: the newly-created #GdkWindow wrapper for the
906 * native window or %NULL if the window has been destroyed.
911 gdk_window_foreign_new_for_display (GdkDisplay *display,
912 GdkNativeWindow anid)
915 GdkWindowObject *private;
916 GdkWindowImplX11 *impl;
917 GdkDrawableImplX11 *draw_impl;
918 GdkDisplayX11 *display_x11;
919 XWindowAttributes attrs;
921 Window *children = NULL;
925 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
927 display_x11 = GDK_DISPLAY_X11 (display);
929 gdk_error_trap_push ();
930 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
931 if (gdk_error_trap_pop () || !result)
934 /* FIXME: This is pretty expensive. Maybe the caller should supply
936 gdk_error_trap_push ();
937 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
938 if (gdk_error_trap_pop () || !result)
944 window = g_object_new (GDK_TYPE_WINDOW, NULL);
945 private = (GdkWindowObject *)window;
946 impl = GDK_WINDOW_IMPL_X11 (private->impl);
947 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
948 draw_impl->wrapper = GDK_DRAWABLE (window);
949 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
951 private->parent = gdk_xid_table_lookup_for_display (display, parent);
953 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
954 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
956 private->parent->children = g_list_prepend (private->parent->children, window);
958 draw_impl->xid = anid;
960 private->x = attrs.x;
961 private->y = attrs.y;
962 impl->width = attrs.width;
963 impl->height = attrs.height;
964 private->window_type = GDK_WINDOW_FOREIGN;
965 private->destroyed = FALSE;
967 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
969 if (attrs.map_state == IsUnmapped)
970 private->state = GDK_WINDOW_STATE_WITHDRAWN;
974 private->depth = attrs.depth;
976 _gdk_window_init_position (GDK_WINDOW (private));
978 g_object_ref (window);
979 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
984 * gdk_window_lookup_for_display:
985 * @display: the #GdkDisplay corresponding to the window handle
986 * @anid: a native window handle.
988 * Looks up the #GdkWindow that wraps the given native window handle.
990 * For example in the X backend, a native window handle is an Xlib
993 * Return value: the #GdkWindow wrapper for the native window,
994 * or %NULL if there is none.
999 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
1001 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
1005 * gdk_window_lookup:
1006 * @anid: a native window handle.
1008 * Looks up the #GdkWindow that wraps the given native window handle.
1010 * For example in the X backend, a native window handle is an Xlib
1013 * Return value: the #GdkWindow wrapper for the native window,
1014 * or %NULL if there is none.
1017 gdk_window_lookup (GdkNativeWindow anid)
1019 return (GdkWindow*) gdk_xid_table_lookup (anid);
1023 gdk_toplevel_x11_free_contents (GdkToplevelX11 *toplevel)
1025 if (toplevel->icon_window)
1027 g_object_unref (toplevel->icon_window);
1028 toplevel->icon_window = NULL;
1030 if (toplevel->icon_pixmap)
1032 g_object_unref (toplevel->icon_pixmap);
1033 toplevel->icon_pixmap = NULL;
1035 if (toplevel->icon_mask)
1037 g_object_unref (toplevel->icon_mask);
1038 toplevel->icon_mask = NULL;
1040 if (toplevel->group_leader)
1042 g_object_unref (toplevel->group_leader);
1043 toplevel->group_leader = NULL;
1048 _gdk_windowing_window_destroy (GdkWindow *window,
1050 gboolean foreign_destroy)
1052 GdkWindowObject *private = (GdkWindowObject *)window;
1053 GdkToplevelX11 *toplevel;
1054 GdkDrawableImplX11 *draw_impl;
1056 g_return_if_fail (GDK_IS_WINDOW (window));
1058 _gdk_selection_window_destroyed (window);
1060 if (private->extension_events != 0)
1061 _gdk_input_window_destroy (window);
1063 toplevel = _gdk_x11_window_get_toplevel (window);
1065 gdk_toplevel_x11_free_contents (toplevel);
1067 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
1069 if (draw_impl->xft_draw)
1070 XftDrawDestroy (draw_impl->xft_draw);
1072 if (!recursing && !foreign_destroy)
1074 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1079 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1081 /* It's somebody else's window, but in our heirarchy,
1082 * so reparent it to the root window, and then send
1083 * it a delete event, as if we were a WM
1085 XClientMessageEvent xevent;
1087 gdk_error_trap_push ();
1088 gdk_window_hide (window);
1089 gdk_window_reparent (window, NULL, 0, 0);
1091 xevent.type = ClientMessage;
1092 xevent.window = GDK_WINDOW_XID (window);
1093 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1096 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1097 "WM_DELETE_WINDOW");
1098 xevent.data.l[1] = CurrentTime;
1099 xevent.data.l[2] = 0;
1100 xevent.data.l[3] = 0;
1101 xevent.data.l[4] = 0;
1103 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1104 GDK_WINDOW_XID (window),
1105 False, 0, (XEvent *)&xevent);
1106 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
1107 gdk_error_trap_pop ();
1111 get_root (GdkWindow *window)
1113 GdkScreen *screen = gdk_drawable_get_screen (window);
1115 return gdk_screen_get_root_window (screen);
1118 /* This function is called when the XWindow is really gone.
1121 gdk_window_destroy_notify (GdkWindow *window)
1123 GdkWindowImplX11 *window_impl;
1125 g_return_if_fail (window != NULL);
1127 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
1129 if (!GDK_WINDOW_DESTROYED (window))
1131 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1132 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1134 _gdk_window_destroy (window, TRUE);
1137 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1138 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1139 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1141 _gdk_xgrab_check_destroy (window);
1143 g_object_unref (window);
1147 update_wm_hints (GdkWindow *window,
1150 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1151 GdkWindowObject *private = (GdkWindowObject *)window;
1152 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1156 private->state & GDK_WINDOW_STATE_WITHDRAWN)
1159 wm_hints.flags = StateHint | InputHint;
1160 wm_hints.input = private->accept_focus ? True : False;
1161 wm_hints.initial_state = NormalState;
1163 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1165 wm_hints.flags |= StateHint;
1166 wm_hints.initial_state = IconicState;
1169 if (toplevel->icon_window && !GDK_WINDOW_DESTROYED (toplevel->icon_window))
1171 wm_hints.flags |= IconWindowHint;
1172 wm_hints.icon_window = GDK_WINDOW_XID (toplevel->icon_window);
1175 if (toplevel->icon_pixmap)
1177 wm_hints.flags |= IconPixmapHint;
1178 wm_hints.icon_pixmap = GDK_PIXMAP_XID (toplevel->icon_pixmap);
1181 if (toplevel->icon_mask)
1183 wm_hints.flags |= IconMaskHint;
1184 wm_hints.icon_mask = GDK_PIXMAP_XID (toplevel->icon_mask);
1187 wm_hints.flags |= WindowGroupHint;
1188 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1190 wm_hints.flags |= WindowGroupHint;
1191 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1194 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1196 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1197 GDK_WINDOW_XID (window),
1202 set_initial_hints (GdkWindow *window)
1204 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1205 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1206 Window xwindow = GDK_WINDOW_XID (window);
1207 GdkWindowObject *private;
1208 GdkToplevelX11 *toplevel;
1212 private = (GdkWindowObject*) window;
1213 toplevel = _gdk_x11_window_get_toplevel (window);
1218 update_wm_hints (window, TRUE);
1220 /* We set the spec hints regardless of whether the spec is supported,
1221 * since it can't hurt and it's kind of expensive to check whether
1227 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1229 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1230 "_NET_WM_STATE_MAXIMIZED_VERT");
1232 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1233 "_NET_WM_STATE_MAXIMIZED_HORZ");
1237 if (private->state & GDK_WINDOW_STATE_ABOVE)
1239 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1240 "_NET_WM_STATE_ABOVE");
1244 if (private->state & GDK_WINDOW_STATE_BELOW)
1246 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1247 "_NET_WM_STATE_BELOW");
1251 if (private->state & GDK_WINDOW_STATE_STICKY)
1253 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1254 "_NET_WM_STATE_STICKY");
1258 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1260 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1261 "_NET_WM_STATE_FULLSCREEN");
1265 if (private->modal_hint)
1267 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1268 "_NET_WM_STATE_MODAL");
1272 if (toplevel->skip_taskbar_hint)
1274 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1275 "_NET_WM_STATE_SKIP_TASKBAR");
1279 if (toplevel->skip_pager_hint)
1281 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1282 "_NET_WM_STATE_SKIP_PAGER");
1288 XChangeProperty (xdisplay,
1290 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1291 XA_ATOM, 32, PropModeReplace,
1292 (guchar*) atoms, i);
1296 XDeleteProperty (xdisplay,
1298 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1301 if (private->state & GDK_WINDOW_STATE_STICKY)
1303 atoms[0] = 0xFFFFFFFF;
1304 XChangeProperty (xdisplay,
1306 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1307 XA_CARDINAL, 32, PropModeReplace,
1308 (guchar*) atoms, 1);
1312 XDeleteProperty (xdisplay,
1314 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1317 toplevel->map_serial = NextRequest (xdisplay);
1321 show_window_internal (GdkWindow *window,
1324 GdkWindowObject *private;
1326 g_return_if_fail (GDK_IS_WINDOW (window));
1328 private = (GdkWindowObject*) window;
1329 if (!private->destroyed)
1331 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1332 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1333 Window xwindow = GDK_WINDOW_XID (window);
1336 XRaiseWindow (xdisplay, xwindow);
1338 if (!GDK_WINDOW_IS_MAPPED (window))
1340 set_initial_hints (window);
1342 gdk_synthesize_window_state (window,
1343 GDK_WINDOW_STATE_WITHDRAWN,
1347 g_assert (GDK_WINDOW_IS_MAPPED (window));
1349 if (impl->position_info.mapped)
1351 gboolean unset_bg = !private->input_only &&
1352 (private->window_type == GDK_WINDOW_CHILD ||
1353 impl->override_redirect) &&
1354 gdk_window_is_viewable (window);
1357 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1359 XMapWindow (xdisplay, xwindow);
1363 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1364 gdk_window_invalidate_rect (window, NULL, TRUE);
1371 * gdk_window_show_unraised:
1372 * @window: a #GdkWindow
1374 * Shows a #GdkWindow onscreen, but does not modify its stacking
1375 * order. In contrast, gdk_window_show() will raise the window
1376 * to the top of the window stack.
1378 * On the X11 platform, in Xlib terms, this function calls
1379 * XMapWindow() (it also updates some internal GDK state, which means
1380 * that you can't really use XMapWindow() directly on a GDK window).
1384 gdk_window_show_unraised (GdkWindow *window)
1386 g_return_if_fail (GDK_IS_WINDOW (window));
1388 show_window_internal (window, FALSE);
1393 * @window: a #GdkWindow
1395 * Like gdk_window_show_unraised(), but also raises the window to the
1396 * top of the window stack (moves the window to the front of the
1399 * This function maps a window so it's visible onscreen. Its opposite
1400 * is gdk_window_hide().
1402 * When implementing a #GtkWidget, you should call this function on the widget's
1403 * #GdkWindow as part of the "map" method.
1407 gdk_window_show (GdkWindow *window)
1409 g_return_if_fail (GDK_IS_WINDOW (window));
1411 show_window_internal (window, TRUE);
1415 pre_unmap (GdkWindow *window)
1417 GdkWindow *start_window = NULL;
1418 GdkWindowObject *private = (GdkWindowObject *)window;
1420 if (private->input_only)
1423 if (private->window_type == GDK_WINDOW_CHILD)
1424 start_window = (GdkWindow *)private->parent;
1425 else if (private->window_type == GDK_WINDOW_TEMP)
1426 start_window = get_root (window);
1429 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1433 post_unmap (GdkWindow *window)
1435 GdkWindow *start_window = NULL;
1436 GdkWindowObject *private = (GdkWindowObject *)window;
1438 if (private->input_only)
1441 if (private->window_type == GDK_WINDOW_CHILD)
1442 start_window = (GdkWindow *)private->parent;
1443 else if (private->window_type == GDK_WINDOW_TEMP)
1444 start_window = get_root (window);
1448 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1450 if (private->window_type == GDK_WINDOW_CHILD && private->parent)
1452 GdkRectangle invalid_rect;
1454 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1455 gdk_drawable_get_size (GDK_DRAWABLE (window),
1456 &invalid_rect.width, &invalid_rect.height);
1457 gdk_window_invalidate_rect ((GdkWindow *)private->parent,
1458 &invalid_rect, TRUE);
1465 * @window: a #GdkWindow
1467 * For toplevel windows, withdraws them, so they will no longer be
1468 * known to the window manager; for all windows, unmaps them, so
1469 * they won't be displayed. Normally done automatically as
1470 * part of gtk_widget_hide().
1474 gdk_window_hide (GdkWindow *window)
1476 GdkWindowObject *private;
1478 g_return_if_fail (window != NULL);
1480 private = (GdkWindowObject*) window;
1482 /* We'll get the unmap notify eventually, and handle it then,
1483 * but checking here makes things more consistent if we are
1484 * just doing stuff ourself.
1486 _gdk_xgrab_check_unmap (window,
1487 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1489 /* You can't simply unmap toplevel windows. */
1490 switch (private->window_type)
1492 case GDK_WINDOW_TOPLEVEL:
1493 case GDK_WINDOW_DIALOG:
1494 case GDK_WINDOW_TEMP: /* ? */
1495 gdk_window_withdraw (window);
1499 case GDK_WINDOW_FOREIGN:
1500 case GDK_WINDOW_ROOT:
1501 case GDK_WINDOW_CHILD:
1505 if (!private->destroyed)
1507 if (GDK_WINDOW_IS_MAPPED (window))
1508 gdk_synthesize_window_state (window,
1510 GDK_WINDOW_STATE_WITHDRAWN);
1512 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1514 _gdk_window_clear_update_area (window);
1518 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1519 GDK_WINDOW_XID (window));
1521 post_unmap (window);
1526 * gdk_window_withdraw:
1527 * @window: a toplevel #GdkWindow
1529 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1530 * This function is not really useful as gdk_window_hide() automatically
1531 * withdraws toplevel windows before hiding them.
1535 gdk_window_withdraw (GdkWindow *window)
1537 GdkWindowObject *private;
1539 g_return_if_fail (window != NULL);
1541 private = (GdkWindowObject*) window;
1542 if (!private->destroyed)
1544 if (GDK_WINDOW_IS_MAPPED (window))
1545 gdk_synthesize_window_state (window,
1547 GDK_WINDOW_STATE_WITHDRAWN);
1549 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1553 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1554 GDK_WINDOW_XID (window), 0);
1556 post_unmap (window);
1562 * @window: a #GdkWindow
1563 * @x: X coordinate relative to window's parent
1564 * @y: Y coordinate relative to window's parent
1566 * Repositions a window relative to its parent window.
1567 * For toplevel windows, window managers may ignore or modify the move;
1568 * you should probably use gtk_window_move() on a #GtkWindow widget
1569 * anyway, instead of using GDK functions. For child windows,
1570 * the move will reliably succeed.
1572 * If you're also planning to resize the window, use gdk_window_move_resize()
1573 * to both move and resize simultaneously, for a nicer visual effect.
1576 gdk_window_move (GdkWindow *window,
1580 GdkWindowObject *private = (GdkWindowObject *)window;
1581 GdkWindowImplX11 *impl;
1583 g_return_if_fail (window != NULL);
1584 g_return_if_fail (GDK_IS_WINDOW (window));
1586 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1588 if (!GDK_WINDOW_DESTROYED (window))
1590 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1592 _gdk_window_move_resize_child (window, x, y,
1593 impl->width, impl->height);
1597 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1598 GDK_WINDOW_XID (window),
1601 if (impl->override_redirect)
1611 * gdk_window_resize:
1612 * @window: a #GdkWindow
1613 * @width: new width of the window
1614 * @height: new height of the window
1616 * Resizes @window; for toplevel windows, asks the window manager to resize
1617 * the window. The window manager may not allow the resize. When using GTK+,
1618 * use gtk_window_resize() instead of this low-level GDK function.
1620 * Windows may not be resized below 1x1.
1622 * If you're also planning to move the window, use gdk_window_move_resize()
1623 * to both move and resize simultaneously, for a nicer visual effect.
1626 gdk_window_resize (GdkWindow *window,
1630 GdkWindowObject *private;
1632 g_return_if_fail (window != NULL);
1633 g_return_if_fail (GDK_IS_WINDOW (window));
1640 private = (GdkWindowObject*) window;
1642 if (!GDK_WINDOW_DESTROYED (window))
1644 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1646 _gdk_window_move_resize_child (window, private->x, private->y,
1651 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1653 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1654 GDK_WINDOW_XID (window),
1657 if (impl->override_redirect)
1659 impl->width = width;
1660 impl->height = height;
1664 if (width != impl->width || height != impl->height)
1665 private->resize_count += 1;
1672 * gdk_window_move_resize:
1673 * @window: a #GdkWindow
1674 * @x: new X position relative to window's parent
1675 * @y: new Y position relative to window's parent
1677 * @height: new height
1679 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1680 * except that both operations are performed at once, avoiding strange
1681 * visual effects. (i.e. the user may be able to see the window first
1682 * move, then resize, if you don't use gdk_window_move_resize().)
1685 gdk_window_move_resize (GdkWindow *window,
1691 GdkWindowObject *private;
1693 g_return_if_fail (window != NULL);
1694 g_return_if_fail (GDK_IS_WINDOW (window));
1701 private = (GdkWindowObject*) window;
1703 if (!GDK_WINDOW_DESTROYED (window))
1705 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1707 _gdk_window_move_resize_child (window, x, y, width, height);
1711 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1713 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1714 GDK_WINDOW_XID (window),
1715 x, y, width, height);
1716 if (impl->override_redirect)
1720 impl->width = width;
1721 impl->height = height;
1725 if (width != impl->width || height != impl->height)
1726 private->resize_count += 1;
1733 * gdk_window_reparent:
1734 * @window: a #GdkWindow
1735 * @new_parent: new parent to move @window into
1736 * @x: X location inside the new parent
1737 * @y: Y location inside the new parent
1739 * Reparents @window into the given @new_parent. The window being
1740 * reparented will be unmapped as a side effect.
1744 gdk_window_reparent (GdkWindow *window,
1745 GdkWindow *new_parent,
1749 GdkDisplay *display;
1750 GdkWindowObject *window_private;
1751 GdkWindowObject *parent_private;
1752 GdkWindowObject *old_parent_private;
1753 GdkWindowImplX11 *impl;
1754 gboolean was_toplevel;
1756 g_return_if_fail (window != NULL);
1757 g_return_if_fail (GDK_IS_WINDOW (window));
1758 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1759 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1761 if (GDK_WINDOW_DESTROYED (window) ||
1762 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1768 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1770 display = GDK_WINDOW_DISPLAY (window);
1772 window_private = (GdkWindowObject*) window;
1773 old_parent_private = (GdkWindowObject*)window_private->parent;
1774 parent_private = (GdkWindowObject*) new_parent;
1775 impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1777 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1778 GDK_WINDOW_XID (window),
1779 GDK_WINDOW_XID (new_parent),
1782 window_private->x = x;
1783 window_private->y = y;
1785 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1788 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1789 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1791 window_private->parent = (GdkWindowObject *)new_parent;
1793 /* Switch the window type as appropriate */
1795 switch (GDK_WINDOW_TYPE (new_parent))
1797 case GDK_WINDOW_ROOT:
1798 case GDK_WINDOW_FOREIGN:
1799 was_toplevel = WINDOW_IS_TOPLEVEL (window);
1801 if (impl->toplevel_window_type != -1)
1802 GDK_WINDOW_TYPE (window) = impl->toplevel_window_type;
1803 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1804 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1806 if (WINDOW_IS_TOPLEVEL (window) && !was_toplevel)
1807 setup_toplevel_window (window, new_parent);
1809 case GDK_WINDOW_TOPLEVEL:
1810 case GDK_WINDOW_CHILD:
1811 case GDK_WINDOW_DIALOG:
1812 case GDK_WINDOW_TEMP:
1813 if (WINDOW_IS_TOPLEVEL (window))
1815 /* Save the original window type so we can restore it if the
1816 * window is reparented back to be a toplevel
1818 impl->toplevel_window_type = GDK_WINDOW_TYPE (window);
1819 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1822 if (impl->toplevel->focus_window)
1824 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1825 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1828 gdk_toplevel_x11_free_contents (impl->toplevel);
1829 g_free (impl->toplevel);
1830 impl->toplevel = NULL;
1835 if (old_parent_private)
1836 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1838 if ((old_parent_private &&
1839 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1840 (!old_parent_private && parent_private->guffaw_gravity))
1841 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1843 parent_private->children = g_list_prepend (parent_private->children, window);
1844 _gdk_window_init_position (GDK_WINDOW (window_private));
1848 _gdk_windowing_window_clear_area (GdkWindow *window,
1854 g_return_if_fail (window != NULL);
1855 g_return_if_fail (GDK_IS_WINDOW (window));
1857 if (!GDK_WINDOW_DESTROYED (window))
1858 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1859 x, y, width, height, False);
1863 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1869 g_return_if_fail (window != NULL);
1870 g_return_if_fail (GDK_IS_WINDOW (window));
1872 if (!GDK_WINDOW_DESTROYED (window))
1873 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1874 x, y, width, height, True);
1880 * @window: a #GdkWindow
1882 * Raises @window to the top of the Z-order (stacking order), so that
1883 * other windows with the same parent window appear below @window.
1884 * This is true whether or not the windows are visible.
1886 * If @window is a toplevel, the window manager may choose to deny the
1887 * request to move the window in the Z-order, gdk_window_raise() only
1888 * requests the restack, does not guarantee it.
1892 gdk_window_raise (GdkWindow *window)
1894 g_return_if_fail (window != NULL);
1895 g_return_if_fail (GDK_IS_WINDOW (window));
1897 if (!GDK_WINDOW_DESTROYED (window))
1898 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1903 * @window: a #GdkWindow
1905 * Lowers @window to the bottom of the Z-order (stacking order), so that
1906 * other windows with the same parent window appear above @window.
1907 * This is true whether or not the other windows are visible.
1909 * If @window is a toplevel, the window manager may choose to deny the
1910 * request to move the window in the Z-order, gdk_window_lower() only
1911 * requests the restack, does not guarantee it.
1913 * Note that gdk_window_show() raises the window again, so don't call this
1914 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1918 gdk_window_lower (GdkWindow *window)
1920 g_return_if_fail (window != NULL);
1921 g_return_if_fail (GDK_IS_WINDOW (window));
1923 if (!GDK_WINDOW_DESTROYED (window))
1924 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1929 * @window: a #GdkWindow
1930 * @timestamp: timestamp of the event triggering the window focus
1932 * Sets keyboard focus to @window. If @window is not onscreen this
1933 * will not work. In most cases, gtk_window_present() should be used on
1934 * a #GtkWindow, rather than calling this function.
1938 gdk_window_focus (GdkWindow *window,
1941 GdkDisplay *display;
1943 g_return_if_fail (GDK_IS_WINDOW (window));
1945 if (GDK_WINDOW_DESTROYED (window))
1948 display = GDK_WINDOW_DISPLAY (window);
1950 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1951 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1955 xev.xclient.type = ClientMessage;
1956 xev.xclient.serial = 0;
1957 xev.xclient.send_event = True;
1958 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1959 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1960 "_NET_ACTIVE_WINDOW");
1961 xev.xclient.format = 32;
1962 xev.xclient.data.l[0] = 0;
1963 xev.xclient.data.l[1] = 0;
1964 xev.xclient.data.l[2] = 0;
1965 xev.xclient.data.l[3] = 0;
1966 xev.xclient.data.l[4] = 0;
1968 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1969 SubstructureRedirectMask | SubstructureNotifyMask,
1974 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1976 /* There is no way of knowing reliably whether we are viewable;
1977 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1979 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1986 * gdk_window_set_hints:
1987 * @window: a #GdkWindow
1988 * @x: ignored field, does not matter
1989 * @y: ignored field, does not matter
1990 * @min_width: minimum width hint
1991 * @min_height: minimum height hint
1992 * @max_width: max width hint
1993 * @max_height: max height hint
1994 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1996 * This function is broken and useless and you should ignore it.
1997 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1998 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1999 * depending on what you're trying to do.
2001 * If using GDK directly, use gdk_window_set_geometry_hints().
2005 gdk_window_set_hints (GdkWindow *window,
2014 XSizeHints size_hints;
2016 g_return_if_fail (window != NULL);
2017 g_return_if_fail (GDK_IS_WINDOW (window));
2019 if (GDK_WINDOW_DESTROYED (window))
2022 size_hints.flags = 0;
2024 if (flags & GDK_HINT_POS)
2026 size_hints.flags |= PPosition;
2031 if (flags & GDK_HINT_MIN_SIZE)
2033 size_hints.flags |= PMinSize;
2034 size_hints.min_width = min_width;
2035 size_hints.min_height = min_height;
2038 if (flags & GDK_HINT_MAX_SIZE)
2040 size_hints.flags |= PMaxSize;
2041 size_hints.max_width = max_width;
2042 size_hints.max_height = max_height;
2045 /* FIXME: Would it be better to delete this property if
2046 * flags == 0? It would save space on the server
2048 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2049 GDK_WINDOW_XID (window),
2054 * gdk_window_set_type_hint:
2055 * @window: A toplevel #GdkWindow
2056 * @hint: A hint of the function this window will have
2058 * The application can use this call to provide a hint to the window
2059 * manager about the functionality of a window. The window manager
2060 * can use this information when determining the decoration and behaviour
2063 * The hint must be set before the window is mapped.
2066 gdk_window_set_type_hint (GdkWindow *window,
2067 GdkWindowTypeHint hint)
2069 GdkDisplay *display;
2072 g_return_if_fail (window != NULL);
2073 g_return_if_fail (GDK_IS_WINDOW (window));
2075 if (GDK_WINDOW_DESTROYED (window))
2078 display = gdk_drawable_get_display (window);
2082 case GDK_WINDOW_TYPE_HINT_DIALOG:
2083 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
2085 case GDK_WINDOW_TYPE_HINT_MENU:
2086 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
2088 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
2089 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
2091 case GDK_WINDOW_TYPE_HINT_UTILITY:
2092 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
2094 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
2095 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
2097 case GDK_WINDOW_TYPE_HINT_DOCK:
2098 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
2100 case GDK_WINDOW_TYPE_HINT_DESKTOP:
2101 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
2104 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
2106 case GDK_WINDOW_TYPE_HINT_NORMAL:
2107 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
2111 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2112 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
2113 XA_ATOM, 32, PropModeReplace,
2114 (guchar *)&atom, 1);
2119 gdk_wmspec_change_state (gboolean add,
2124 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
2127 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
2128 #define _NET_WM_STATE_ADD 1 /* add/set property */
2129 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
2131 xev.xclient.type = ClientMessage;
2132 xev.xclient.serial = 0;
2133 xev.xclient.send_event = True;
2134 xev.xclient.window = GDK_WINDOW_XID (window);
2135 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
2136 xev.xclient.format = 32;
2137 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
2138 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
2139 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
2140 xev.xclient.data.l[3] = 0;
2141 xev.xclient.data.l[4] = 0;
2143 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
2144 SubstructureRedirectMask | SubstructureNotifyMask,
2149 * gdk_window_set_modal_hint:
2150 * @window: A toplevel #GdkWindow
2151 * @modal: TRUE if the window is modal, FALSE otherwise.
2153 * The application can use this hint to tell the window manager
2154 * that a certain window has modal behaviour. The window manager
2155 * can use this information to handle modal windows in a special
2158 * You should only use this on windows for which you have
2159 * previously called #gdk_window_set_transient_for()
2162 gdk_window_set_modal_hint (GdkWindow *window,
2165 GdkWindowObject *private;
2167 g_return_if_fail (window != NULL);
2168 g_return_if_fail (GDK_IS_WINDOW (window));
2170 if (GDK_WINDOW_DESTROYED (window))
2173 private = (GdkWindowObject*) window;
2175 private->modal_hint = modal;
2177 if (GDK_WINDOW_IS_MAPPED (window))
2178 gdk_wmspec_change_state (modal, window,
2179 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
2184 * gdk_window_set_skip_taskbar_hint:
2185 * @window: a toplevel #GdkWindow
2186 * @skips_taskbar: %TRUE to skip the taskbar
2188 * Toggles whether a window should appear in a task list or window
2189 * list. If a window's semantic type as specified with
2190 * gdk_window_set_type_hint() already fully describes the window, this
2191 * function should NOT be called in addition, instead you should allow
2192 * the window to be treated according to standard policy for its
2198 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2199 gboolean skips_taskbar)
2201 GdkToplevelX11 *toplevel;
2203 g_return_if_fail (window != NULL);
2204 g_return_if_fail (GDK_IS_WINDOW (window));
2205 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2207 if (GDK_WINDOW_DESTROYED (window))
2210 toplevel = _gdk_x11_window_get_toplevel (window);
2211 toplevel->skip_taskbar_hint = skips_taskbar;
2213 if (GDK_WINDOW_IS_MAPPED (window))
2214 gdk_wmspec_change_state (skips_taskbar, window,
2215 gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE),
2220 * gdk_window_set_skip_pager_hint:
2221 * @window: a toplevel #GdkWindow
2222 * @skips_pager: %TRUE to skip the pager
2224 * Toggles whether a window should appear in a pager (workspace
2225 * switcher, or other desktop utility program that displays a small
2226 * thumbnail representation of the windows on the desktop). If a
2227 * window's semantic type as specified with gdk_window_set_type_hint()
2228 * already fully describes the window, this function should NOT be
2229 * called in addition, instead you should allow the window to be
2230 * treated according to standard policy for its semantic type.
2235 gdk_window_set_skip_pager_hint (GdkWindow *window,
2236 gboolean skips_pager)
2238 GdkToplevelX11 *toplevel;
2240 g_return_if_fail (window != NULL);
2241 g_return_if_fail (GDK_IS_WINDOW (window));
2242 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2244 if (GDK_WINDOW_DESTROYED (window))
2247 toplevel = _gdk_x11_window_get_toplevel (window);
2248 toplevel->skip_pager_hint = skips_pager;
2250 if (GDK_WINDOW_IS_MAPPED (window))
2251 gdk_wmspec_change_state (skips_pager, window,
2252 gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE),
2257 * gdk_window_set_geometry_hints:
2258 * @window: a toplevel #GdkWindow
2259 * @geometry: geometry hints
2260 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2262 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2263 * are set, hints not flagged in @geom_mask are unset.
2264 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2266 * This function provides hints to the windowing system about
2267 * acceptable sizes for a toplevel window. The purpose of
2268 * this is to constrain user resizing, but the windowing system
2269 * will typically (but is not required to) also constrain the
2270 * current size of the window to the provided values and
2271 * constrain programatic resizing via gdk_window_resize() or
2272 * gdk_window_move_resize().
2274 * Note that on X11, this effect has no effect on windows
2275 * of type GDK_WINDOW_TEMP or windows where override_redirect
2276 * has been turned on via gdk_window_set_override_redirect()
2277 * since these windows are not resizable by the user.
2279 * Since you can't count on the windowing system doing the
2280 * constraints for programmatic resizes, you should generally
2281 * call gdk_window_constrain_size() yourself to determine
2282 * appropriate sizes.
2286 gdk_window_set_geometry_hints (GdkWindow *window,
2287 GdkGeometry *geometry,
2288 GdkWindowHints geom_mask)
2290 XSizeHints size_hints;
2292 g_return_if_fail (window != NULL);
2293 g_return_if_fail (GDK_IS_WINDOW (window));
2295 if (GDK_WINDOW_DESTROYED (window))
2298 size_hints.flags = 0;
2300 if (geom_mask & GDK_HINT_POS)
2302 size_hints.flags |= PPosition;
2303 /* We need to initialize the following obsolete fields because KWM
2304 * apparently uses these fields if they are non-zero.
2311 if (geom_mask & GDK_HINT_USER_POS)
2313 size_hints.flags |= USPosition;
2316 if (geom_mask & GDK_HINT_USER_SIZE)
2318 size_hints.flags |= USSize;
2321 if (geom_mask & GDK_HINT_MIN_SIZE)
2323 size_hints.flags |= PMinSize;
2324 size_hints.min_width = geometry->min_width;
2325 size_hints.min_height = geometry->min_height;
2328 if (geom_mask & GDK_HINT_MAX_SIZE)
2330 size_hints.flags |= PMaxSize;
2331 size_hints.max_width = MAX (geometry->max_width, 1);
2332 size_hints.max_height = MAX (geometry->max_height, 1);
2335 if (geom_mask & GDK_HINT_BASE_SIZE)
2337 size_hints.flags |= PBaseSize;
2338 size_hints.base_width = geometry->base_width;
2339 size_hints.base_height = geometry->base_height;
2342 if (geom_mask & GDK_HINT_RESIZE_INC)
2344 size_hints.flags |= PResizeInc;
2345 size_hints.width_inc = geometry->width_inc;
2346 size_hints.height_inc = geometry->height_inc;
2349 if (geom_mask & GDK_HINT_ASPECT)
2351 size_hints.flags |= PAspect;
2352 if (geometry->min_aspect <= 1)
2354 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2355 size_hints.min_aspect.y = 65536;
2359 size_hints.min_aspect.x = 65536;
2360 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2362 if (geometry->max_aspect <= 1)
2364 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2365 size_hints.max_aspect.y = 65536;
2369 size_hints.max_aspect.x = 65536;
2370 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2374 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2376 size_hints.flags |= PWinGravity;
2377 size_hints.win_gravity = geometry->win_gravity;
2380 /* FIXME: Would it be better to delete this property if
2381 * geom_mask == 0? It would save space on the server
2383 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2384 GDK_WINDOW_XID (window),
2389 gdk_window_get_geometry_hints (GdkWindow *window,
2390 GdkGeometry *geometry,
2391 GdkWindowHints *geom_mask)
2393 XSizeHints size_hints;
2394 glong junk_size_mask = 0;
2396 g_return_if_fail (GDK_IS_WINDOW (window));
2397 g_return_if_fail (geometry != NULL);
2398 g_return_if_fail (geom_mask != NULL);
2402 if (GDK_WINDOW_DESTROYED (window))
2405 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2406 GDK_WINDOW_XID (window),
2411 if (size_hints.flags & PMinSize)
2413 *geom_mask |= GDK_HINT_MIN_SIZE;
2414 geometry->min_width = size_hints.min_width;
2415 geometry->min_height = size_hints.min_height;
2418 if (size_hints.flags & PMaxSize)
2420 *geom_mask |= GDK_HINT_MAX_SIZE;
2421 geometry->max_width = MAX (size_hints.max_width, 1);
2422 geometry->max_height = MAX (size_hints.max_height, 1);
2425 if (size_hints.flags & PResizeInc)
2427 *geom_mask |= GDK_HINT_RESIZE_INC;
2428 geometry->width_inc = size_hints.width_inc;
2429 geometry->height_inc = size_hints.height_inc;
2432 if (size_hints.flags & PAspect)
2434 *geom_mask |= GDK_HINT_ASPECT;
2436 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
2437 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
2440 if (size_hints.flags & PWinGravity)
2442 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2443 geometry->win_gravity = size_hints.win_gravity;
2448 utf8_is_latin1 (const gchar *str)
2450 const char *p = str;
2454 gunichar ch = g_utf8_get_char (p);
2459 p = g_utf8_next_char (p);
2465 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2466 * convertable to STRING, otherwise, set it as compound text
2469 set_text_property (GdkDisplay *display,
2472 const gchar *utf8_str)
2474 guchar *prop_text = NULL;
2478 gboolean is_compound_text;
2480 if (utf8_is_latin1 (utf8_str))
2482 prop_type = XA_STRING;
2483 prop_text = gdk_utf8_to_string_target (utf8_str);
2484 prop_length = prop_text ? strlen (prop_text) : 0;
2486 is_compound_text = FALSE;
2492 gdk_utf8_to_compound_text_for_display (display,
2493 utf8_str, &gdk_type, &prop_format,
2494 &prop_text, &prop_length);
2495 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2496 is_compound_text = TRUE;
2501 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2504 prop_type, prop_format,
2505 PropModeReplace, prop_text,
2508 if (is_compound_text)
2509 gdk_free_compound_text (prop_text);
2515 /* Set WM_NAME and _NET_WM_NAME
2518 set_wm_name (GdkDisplay *display,
2522 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2523 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2524 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2525 PropModeReplace, name, strlen (name));
2527 set_text_property (display, xwindow,
2528 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2533 * gdk_window_set_title:
2534 * @window: a toplevel #GdkWindow
2535 * @title: title of @window
2537 * Sets the title of a toplevel window, to be displayed in the titlebar.
2538 * If you haven't explicitly set the icon name for the window
2539 * (using gdk_window_set_icon_name()), the icon name will be set to
2540 * @title as well. @title must be in UTF-8 encoding (as with all
2541 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2544 gdk_window_set_title (GdkWindow *window,
2547 GdkDisplay *display;
2551 g_return_if_fail (window != NULL);
2552 g_return_if_fail (GDK_IS_WINDOW (window));
2553 g_return_if_fail (title != NULL);
2555 if (GDK_WINDOW_DESTROYED (window))
2558 display = gdk_drawable_get_display (window);
2559 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2560 xwindow = GDK_WINDOW_XID (window);
2562 set_wm_name (display, xwindow, title);
2564 if (!gdk_window_icon_name_set (window))
2566 XChangeProperty (xdisplay, xwindow,
2567 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2568 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2569 PropModeReplace, title, strlen (title));
2571 set_text_property (display, xwindow,
2572 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2578 * gdk_window_set_role:
2579 * @window: a toplevel #GdkWindow
2580 * @role: a string indicating its role
2582 * When using GTK+, typically you should use gtk_window_set_role() instead
2583 * of this low-level function.
2585 * The window manager and session manager use a window's role to
2586 * distinguish it from other kinds of window in the same application.
2587 * When an application is restarted after being saved in a previous
2588 * session, all windows with the same title and role are treated as
2589 * interchangeable. So if you have two windows with the same title
2590 * that should be distinguished for session management purposes, you
2591 * should set the role on those windows. It doesn't matter what string
2592 * you use for the role, as long as you have a different role for each
2593 * non-interchangeable kind of window.
2597 gdk_window_set_role (GdkWindow *window,
2600 GdkDisplay *display;
2602 g_return_if_fail (window != NULL);
2603 g_return_if_fail (GDK_IS_WINDOW (window));
2605 display = gdk_drawable_get_display (window);
2607 if (!GDK_WINDOW_DESTROYED (window))
2610 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2611 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2612 XA_STRING, 8, PropModeReplace, role, strlen (role));
2614 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2615 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2620 * gdk_window_set_transient_for:
2621 * @window: a toplevel #GdkWindow
2622 * @parent: another toplevel #GdkWindow
2624 * Indicates to the window manager that @window is a transient dialog
2625 * associated with the application window @parent. This allows the
2626 * window manager to do things like center @window on @parent and
2627 * keep @window above @parent.
2629 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2634 gdk_window_set_transient_for (GdkWindow *window,
2637 GdkWindowObject *private;
2638 GdkWindowObject *parent_private;
2640 g_return_if_fail (window != NULL);
2641 g_return_if_fail (GDK_IS_WINDOW (window));
2643 private = (GdkWindowObject*) window;
2644 parent_private = (GdkWindowObject*) parent;
2646 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2647 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2648 GDK_WINDOW_XID (window),
2649 GDK_WINDOW_XID (parent));
2653 * gdk_window_set_background:
2654 * @window: a #GdkWindow
2655 * @color: an allocated #GdkColor
2657 * Sets the background color of @window. (However, when using GTK+,
2658 * set the background of a widget with gtk_widget_modify_bg() - if
2659 * you're an application - or gtk_style_set_background() - if you're
2660 * implementing a custom widget.)
2662 * The @color must be allocated; gdk_rgb_find_color() is the best way
2663 * to allocate a color.
2665 * See also gdk_window_set_back_pixmap().
2669 gdk_window_set_background (GdkWindow *window,
2670 const GdkColor *color)
2672 GdkWindowObject *private = (GdkWindowObject *)window;
2674 g_return_if_fail (window != NULL);
2675 g_return_if_fail (GDK_IS_WINDOW (window));
2677 if (!GDK_WINDOW_DESTROYED (window))
2678 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2679 GDK_WINDOW_XID (window), color->pixel);
2681 private->bg_color = *color;
2683 if (private->bg_pixmap &&
2684 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2685 private->bg_pixmap != GDK_NO_BG)
2686 g_object_unref (private->bg_pixmap);
2688 private->bg_pixmap = NULL;
2692 * gdk_window_set_back_pixmap:
2693 * @window: a #GdkWindow
2694 * @pixmap: a #GdkPixmap, or %NULL
2695 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2697 * Sets the background pixmap of @window. May also be used to set a background of
2698 * "None" on @window, by setting a background pixmap of %NULL.
2699 * A background pixmap will be tiled, positioning the first tile at the origin of
2700 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2701 * origin of the parent window (useful to align tiles in a parent with tiles
2704 * A background pixmap of %NULL means that the window will have no
2705 * background. A window with no background will never have its
2706 * background filled by the windowing system, instead the window will
2707 * contain whatever pixels were already in the corresponding area of
2710 * The windowing system will normally fill a window with its background
2711 * when the window is obscured then exposed, and when you call
2712 * gdk_window_clear().
2716 gdk_window_set_back_pixmap (GdkWindow *window,
2718 gboolean parent_relative)
2720 GdkWindowObject *private = (GdkWindowObject *)window;
2723 g_return_if_fail (window != NULL);
2724 g_return_if_fail (GDK_IS_WINDOW (window));
2725 g_return_if_fail (pixmap == NULL || !parent_relative);
2726 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2728 if (private->bg_pixmap &&
2729 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2730 private->bg_pixmap != GDK_NO_BG)
2731 g_object_unref (private->bg_pixmap);
2733 if (parent_relative)
2735 xpixmap = ParentRelative;
2736 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2742 g_object_ref (pixmap);
2743 private->bg_pixmap = pixmap;
2744 xpixmap = GDK_PIXMAP_XID (pixmap);
2749 private->bg_pixmap = GDK_NO_BG;
2753 if (!GDK_WINDOW_DESTROYED (window))
2754 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2755 GDK_WINDOW_XID (window), xpixmap);
2759 * gdk_window_set_cursor:
2760 * @window: a #GdkWindow
2763 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2764 * gdk_cursor_new_from_pixmap() to create the cursor.
2765 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2766 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2767 * to gdk_window_set_cursor() means that @window will use the cursor of
2768 * its parent window. Most windows should use this default.
2772 gdk_window_set_cursor (GdkWindow *window,
2775 GdkCursorPrivate *cursor_private;
2778 g_return_if_fail (window != NULL);
2779 g_return_if_fail (GDK_IS_WINDOW (window));
2781 cursor_private = (GdkCursorPrivate*) cursor;
2786 xcursor = cursor_private->xcursor;
2788 if (!GDK_WINDOW_DESTROYED (window))
2789 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2790 GDK_WINDOW_XID (window),
2795 * gdk_window_get_geometry:
2796 * @window: a #GdkWindow
2797 * @x: return location for X coordinate of window (relative to its parent)
2798 * @y: return location for Y coordinate of window (relative to its parent)
2799 * @width: return location for width of window
2800 * @height: return location for height of window
2801 * @depth: return location for bit depth of window
2803 * Any of the return location arguments to this function may be %NULL,
2804 * if you aren't interested in getting the value of that field.
2806 * The X and Y coordinates returned are relative to the parent window
2807 * of @window, which for toplevels usually means relative to the
2808 * window decorations (titlebar, etc.) rather than relative to the
2809 * root window (screen-size background window).
2811 * On the X11 platform, the geometry is obtained from the X server,
2812 * so reflects the latest position of @window; this may be out-of-sync
2813 * with the position of @window delivered in the most-recently-processed
2814 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2815 * position from the most recent configure event.
2819 gdk_window_get_geometry (GdkWindow *window,
2831 guint tborder_width;
2834 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2838 GDK_NOTE (MULTIHEAD,
2839 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2840 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
2843 if (!GDK_WINDOW_DESTROYED (window))
2845 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2846 GDK_WINDOW_XID (window),
2847 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2863 * gdk_window_get_origin:
2864 * @window: a #GdkWindow
2865 * @x: return location for X coordinate
2866 * @y: return location for Y coordinate
2868 * Obtains the position of a window in root window coordinates.
2869 * (Compare with gdk_window_get_position() and
2870 * gdk_window_get_geometry() which return the position of a window
2871 * relative to its parent window.)
2873 * Return value: not meaningful, ignore
2876 gdk_window_get_origin (GdkWindow *window,
2885 g_return_val_if_fail (window != NULL, 0);
2887 if (!GDK_WINDOW_DESTROYED (window))
2889 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2890 GDK_WINDOW_XID (window),
2891 GDK_WINDOW_XROOTWIN (window),
2907 * gdk_window_get_deskrelative_origin:
2908 * @window: a toplevel #GdkWindow
2909 * @x: return location for X coordinate
2910 * @y: return location for Y coordinate
2912 * This gets the origin of a #GdkWindow relative to
2913 * an Enlightenment-window-manager desktop. As long as you don't
2914 * assume that the user's desktop/workspace covers the entire
2915 * root window (i.e. you don't assume that the desktop begins
2916 * at root window coordinate 0,0) this function is not necessary.
2917 * It's deprecated for that reason.
2919 * Return value: not meaningful
2922 gdk_window_get_deskrelative_origin (GdkWindow *window,
2926 gboolean return_val = FALSE;
2927 gint num_children, format_return;
2928 Window win, *child, parent, root;
2933 gulong number_return, bytes_after_return;
2934 guchar *data_return;
2936 g_return_val_if_fail (window != NULL, FALSE);
2937 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2939 if (!GDK_WINDOW_DESTROYED (window))
2941 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2942 "ENLIGHTENMENT_DESKTOP");
2943 win = GDK_WINDOW_XID (window);
2945 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2946 &child, (unsigned int *)&num_children))
2948 if ((child) && (num_children > 0))
2960 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2961 False, XA_CARDINAL, &type_return, &format_return,
2962 &number_return, &bytes_after_return, &data_return);
2964 if (type_return == XA_CARDINAL)
2966 XFree (data_return);
2971 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2972 GDK_WINDOW_XID (window),
2987 * gdk_window_get_root_origin:
2988 * @window: a toplevel #GdkWindow
2989 * @x: return location for X position of window frame
2990 * @y: return location for Y position of window frame
2992 * Obtains the top-left corner of the window manager frame in root
2993 * window coordinates.
2997 gdk_window_get_root_origin (GdkWindow *window,
3003 g_return_if_fail (GDK_IS_WINDOW (window));
3005 gdk_window_get_frame_extents (window, &rect);
3015 * gdk_window_get_frame_extents:
3016 * @window: a toplevel #GdkWindow
3017 * @rect: rectangle to fill with bounding box of the window frame
3019 * Obtains the bounding box of the window, including window manager
3020 * titlebar/borders if any. The frame position is given in root window
3021 * coordinates. To get the position of the window itself (rather than
3022 * the frame) in root window coordinates, use gdk_window_get_origin().
3026 gdk_window_get_frame_extents (GdkWindow *window,
3029 GdkWindowObject *private;
3034 unsigned int nchildren;
3036 g_return_if_fail (GDK_IS_WINDOW (window));
3037 g_return_if_fail (rect != NULL);
3039 private = (GdkWindowObject*) window;
3046 if (GDK_WINDOW_DESTROYED (window))
3049 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
3050 private = (GdkWindowObject*) private->parent;
3052 /* Refine our fallback answer a bit using local information */
3053 rect->x = private->x;
3054 rect->y = private->y;
3055 gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height);
3057 if (GDK_WINDOW_DESTROYED (private))
3060 gdk_error_trap_push();
3062 xparent = GDK_WINDOW_XID (window);
3066 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
3068 &children, &nchildren))
3074 while (xparent != root);
3076 if (xparent == root)
3078 unsigned int ww, wh, wb, wd;
3081 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
3091 gdk_error_trap_pop ();
3095 _gdk_windowing_get_pointer (GdkDisplay *display,
3099 GdkModifierType *mask)
3101 GdkScreen *default_screen;
3109 if (display->closed)
3112 default_screen = gdk_display_get_default_screen (display);
3114 XQueryPointer (GDK_SCREEN_XDISPLAY (default_screen),
3115 GDK_SCREEN_XROOTWIN (default_screen),
3116 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3120 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
3121 *screen = gdk_drawable_get_screen (gdk_root);
3130 _gdk_windowing_window_get_pointer (GdkDisplay *display,
3134 GdkModifierType *mask)
3136 GdkWindow *return_val;
3142 unsigned int xmask = 0;
3143 gint xoffset, yoffset;
3145 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
3147 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3150 if (!GDK_WINDOW_DESTROYED (window) &&
3151 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
3152 GDK_WINDOW_XID (window),
3153 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
3156 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
3159 *x = winx + xoffset;
3160 *y = winy + yoffset;
3167 _gdk_windowing_window_at_pointer (GdkDisplay *display,
3176 Window xwindow_last = 0;
3178 int rootx = -1, rooty = -1;
3182 screen = gdk_display_get_default_screen (display);
3184 xwindow = GDK_SCREEN_XROOTWIN (screen);
3185 xdisplay = GDK_SCREEN_XDISPLAY (screen);
3187 /* This function really only works if the mouse pointer is held still
3188 * during its operation. If it moves from one leaf window to another
3189 * than we'll end up with inaccurate values for win_x, win_y
3192 gdk_x11_display_grab (display);
3193 XQueryPointer (xdisplay, xwindow,
3194 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3196 if (root == xwindow)
3203 xwindow_last = xwindow;
3204 XQueryPointer (xdisplay, xwindow,
3205 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3207 gdk_x11_display_ungrab (display);
3209 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
3211 *win_x = window ? winx : -1;
3212 *win_y = window ? winy : -1;
3218 * gdk_window_get_events:
3219 * @window: a #GdkWindow
3221 * Gets the event mask for @window. See gdk_window_set_events().
3223 * Return value: event mask for @window
3226 gdk_window_get_events (GdkWindow *window)
3228 XWindowAttributes attrs;
3229 GdkEventMask event_mask;
3231 g_return_val_if_fail (window != NULL, 0);
3232 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
3234 if (GDK_WINDOW_DESTROYED (window))
3238 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3239 GDK_WINDOW_XID (window),
3242 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
3243 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3250 * gdk_window_set_events:
3251 * @window: a #GdkWindow
3252 * @event_mask: event mask for @window
3254 * The event mask for a window determines which events will be reported
3255 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
3256 * means the window should report button press events. The event mask
3257 * is the bitwise OR of values from the #GdkEventMask enumeration.
3261 gdk_window_set_events (GdkWindow *window,
3262 GdkEventMask event_mask)
3267 g_return_if_fail (window != NULL);
3268 g_return_if_fail (GDK_IS_WINDOW (window));
3270 if (!GDK_WINDOW_DESTROYED (window))
3272 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3273 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3274 for (i = 0; i < _gdk_nenvent_masks; i++)
3276 if (event_mask & (1 << (i + 1)))
3277 xevent_mask |= _gdk_event_mask_table[i];
3280 XSelectInput (GDK_WINDOW_XDISPLAY (window),
3281 GDK_WINDOW_XID (window),
3287 gdk_window_add_colormap_windows (GdkWindow *window)
3289 GdkWindow *toplevel;
3290 Window *old_windows;
3291 Window *new_windows;
3294 g_return_if_fail (window != NULL);
3295 g_return_if_fail (GDK_IS_WINDOW (window));
3297 if (GDK_WINDOW_DESTROYED (window))
3299 toplevel = gdk_window_get_toplevel (window);
3302 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3303 GDK_WINDOW_XID (toplevel),
3304 &old_windows, &count))
3309 for (i = 0; i < count; i++)
3310 if (old_windows[i] == GDK_WINDOW_XID (window))
3312 XFree (old_windows);
3316 new_windows = g_new (Window, count + 1);
3318 for (i = 0; i < count; i++)
3319 new_windows[i] = old_windows[i];
3320 new_windows[count] = GDK_WINDOW_XID (window);
3322 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3323 GDK_WINDOW_XID (toplevel),
3324 new_windows, count + 1);
3326 g_free (new_windows);
3328 XFree (old_windows);
3332 gdk_window_have_shape_ext (GdkDisplay *display)
3334 #ifdef HAVE_SHAPE_EXT
3337 return XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display),
3344 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
3347 * This needs the X11 shape extension.
3348 * If not available, shaped windows will look
3349 * ugly, but programs still work. Stefan Wille
3352 * gdk_window_shape_combine_mask:
3353 * @window: a #GdkWindow
3355 * @x: X position of shape mask with respect to @window
3356 * @y: Y position of shape mask with respect to @window
3358 * Applies a shape mask to @window. Pixels in @window corresponding to
3359 * set bits in the @mask will be visible; pixels in @window
3360 * corresponding to unset bits in the @mask will be transparent. This
3361 * gives a non-rectangular window.
3363 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
3364 * parameters are not used.
3366 * On the X11 platform, this uses an X server extension which is
3367 * widely available on most common platforms, but not available on
3368 * very old X servers, and occasionally the implementation will be
3369 * buggy. On servers without the shape extension, this function
3372 * This function works on both toplevel and child windows.
3376 gdk_window_shape_combine_mask (GdkWindow *window,
3381 gint xoffset, yoffset;
3383 g_return_if_fail (window != NULL);
3384 g_return_if_fail (GDK_IS_WINDOW (window));
3386 #ifdef HAVE_SHAPE_EXT
3387 if (GDK_WINDOW_DESTROYED (window))
3390 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3392 if (xoffset != 0 || yoffset != 0)
3394 WARN_SHAPE_TOO_BIG ();
3398 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3402 pixmap = GDK_PIXMAP_XID (mask);
3411 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3412 GDK_WINDOW_XID (window),
3418 #endif /* HAVE_SHAPE_EXT */
3422 * gdk_window_shape_combine_region:
3423 * @window: a #GdkWindow
3424 * @shape_region: region of window to be non-transparent
3425 * @offset_x: X position of @shape_region in @window coordinates
3426 * @offset_y: Y position of @shape_region in @window coordinates
3428 * Makes pixels in @window outside @shape_region be transparent,
3429 * so that the window may be nonrectangular. See also
3430 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
3432 * If @shape_region is %NULL, the shape will be unset, so the whole
3433 * window will be opaque again. @offset_x and @offset_y are ignored
3434 * if @shape_region is %NULL.
3436 * On the X11 platform, this uses an X server extension which is
3437 * widely available on most common platforms, but not available on
3438 * very old X servers, and occasionally the implementation will be
3439 * buggy. On servers without the shape extension, this function
3442 * This function works on both toplevel and child windows.
3446 gdk_window_shape_combine_region (GdkWindow *window,
3447 GdkRegion *shape_region,
3451 gint xoffset, yoffset;
3453 g_return_if_fail (GDK_IS_WINDOW (window));
3455 #ifdef HAVE_SHAPE_EXT
3456 if (GDK_WINDOW_DESTROYED (window))
3459 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3461 if (xoffset != 0 || yoffset != 0)
3463 WARN_SHAPE_TOO_BIG ();
3467 if (shape_region == NULL)
3469 /* Use NULL mask to unset the shape */
3470 gdk_window_shape_combine_mask (window, NULL, 0, 0);
3474 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3477 XRectangle *xrects = NULL;
3479 _gdk_region_get_xrectangles (shape_region,
3483 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3484 GDK_WINDOW_XID (window),
3493 #endif /* HAVE_SHAPE_EXT */
3498 * gdk_window_set_override_redirect:
3499 * @window: a toplevel #GdkWindow
3500 * @override_redirect: %TRUE if window should be override redirect
3502 * An override redirect window is not under the control of the window manager.
3503 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3504 * be entirely under the control of the application. The window manager
3505 * can't see the override redirect window at all.
3507 * Override redirect should only be used for short-lived temporary
3508 * windows, such as popup menus. #GtkMenu uses an override redirect
3509 * window in its implementation, for example.
3513 gdk_window_set_override_redirect (GdkWindow *window,
3514 gboolean override_redirect)
3516 XSetWindowAttributes attr;
3518 g_return_if_fail (window != NULL);
3519 g_return_if_fail (GDK_IS_WINDOW (window));
3521 if (!GDK_WINDOW_DESTROYED (window))
3523 GdkWindowObject *private = (GdkWindowObject *)window;
3524 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
3526 attr.override_redirect = (override_redirect? True : False);
3527 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3528 GDK_WINDOW_XID (window),
3532 impl->override_redirect = attr.override_redirect;
3537 * gdk_window_set_accept_focus:
3538 * @window: a toplevel #GdkWindow
3539 * @accept_focus: %TRUE if the window should receive input focus
3541 * Setting @accept_focus to %FALSE hints the desktop environment that the
3542 * window doesn't want to receive input focus.
3544 * On X, it is the responsibility of the window manager to interpret this
3545 * hint. ICCCM-compliant window manager usually respect it.
3550 gdk_window_set_accept_focus (GdkWindow *window,
3551 gboolean accept_focus)
3553 GdkWindowObject *private;
3554 g_return_if_fail (window != NULL);
3555 g_return_if_fail (GDK_IS_WINDOW (window));
3557 private = (GdkWindowObject *)window;
3559 accept_focus = accept_focus != FALSE;
3561 if (private->accept_focus != accept_focus)
3563 private->accept_focus = accept_focus;
3565 if (!GDK_WINDOW_DESTROYED (window))
3566 update_wm_hints (window, FALSE);
3571 * gdk_window_set_focus_on_map:
3572 * @window: a toplevel #GdkWindow
3573 * @focus_on_map: %TRUE if the window should receive input focus when mapped
3575 * Setting @focus_on_map to %FALSE hints the desktop environment that the
3576 * window doesn't want to receive input focus when it is mapped.
3577 * focus_on_map should be turned off for windows that aren't triggered
3578 * interactively (such as popups from network activity).
3580 * On X, it is the responsibility of the window manager to interpret
3581 * this hint. Window managers following the freedesktop.org window
3582 * manager extension specification should respect it.
3587 gdk_window_set_focus_on_map (GdkWindow *window,
3588 gboolean focus_on_map)
3590 GdkWindowObject *private;
3591 g_return_if_fail (window != NULL);
3592 g_return_if_fail (GDK_IS_WINDOW (window));
3594 private = (GdkWindowObject *)window;
3596 focus_on_map = focus_on_map != FALSE;
3598 if (private->focus_on_map != focus_on_map)
3600 private->focus_on_map = focus_on_map;
3602 if ((!GDK_WINDOW_DESTROYED (window)) && (!private->focus_on_map))
3603 gdk_x11_window_set_user_time (window, 0);
3608 * gdk_x11_window_set_user_time:
3609 * @window: A toplevel #GdkWindow
3610 * @timestamp: An XServer timestamp to which the property should be set
3612 * The application can use this call to update the _NET_WM_USER_TIME
3613 * property on a toplevel window. This property stores an Xserver
3614 * time which represents the time of the last user input event
3615 * received for this window. This property may be used by the window
3616 * manager to alter the focus, stacking, and/or placement behavior of
3617 * windows when they are mapped depending on whether the new window
3618 * was created by a user action or is a "pop-up" window activated by a
3619 * timer or some other event.
3621 * Note that this property is automatically updated by GDK, so this
3622 * function should only be used by applications which handle input
3623 * events bypassing GDK.
3628 gdk_x11_window_set_user_time (GdkWindow *window,
3631 GdkDisplay *display;
3632 GdkDisplayX11 *display_x11;
3633 glong timestamp_long = (glong)timestamp;
3635 g_return_if_fail (window != NULL);
3636 g_return_if_fail (GDK_IS_WINDOW (window));
3638 if (GDK_WINDOW_DESTROYED (window))
3641 display = gdk_drawable_get_display (window);
3642 display_x11 = GDK_DISPLAY_X11 (display);
3644 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3645 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3646 XA_CARDINAL, 32, PropModeReplace,
3647 (guchar *)×tamp_long, 1);
3649 if (timestamp_long != GDK_CURRENT_TIME)
3650 display_x11->user_time = timestamp_long;
3654 * gdk_window_set_icon_list:
3655 * @window: The #GdkWindow toplevel window to set the icon of.
3656 * @pixbufs: A list of pixbufs, of different sizes.
3658 * Sets a list of icons for the window. One of these will be used
3659 * to represent the window when it has been iconified. The icon is
3660 * usually shown in an icon box or some sort of task bar. Which icon
3661 * size is shown depends on the window manager. The window manager
3662 * can scale the icon but setting several size icons can give better
3663 * image quality since the window manager may only need to scale the
3664 * icon by a small amount or not at all.
3668 gdk_window_set_icon_list (GdkWindow *window,
3677 gint width, height, stride;
3680 GdkDisplay *display;
3682 g_return_if_fail (GDK_IS_WINDOW (window));
3684 if (GDK_WINDOW_DESTROYED (window))
3687 display = gdk_drawable_get_display (window);
3695 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3697 width = gdk_pixbuf_get_width (pixbuf);
3698 height = gdk_pixbuf_get_height (pixbuf);
3700 size += 2 + width * height;
3702 l = g_list_next (l);
3705 data = g_malloc (size * sizeof (gulong));
3713 width = gdk_pixbuf_get_width (pixbuf);
3714 height = gdk_pixbuf_get_height (pixbuf);
3715 stride = gdk_pixbuf_get_rowstride (pixbuf);
3716 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3721 pixels = gdk_pixbuf_get_pixels (pixbuf);
3723 for (y = 0; y < height; y++)
3725 for (x = 0; x < width; x++)
3729 r = pixels[y*stride + x*n_channels + 0];
3730 g = pixels[y*stride + x*n_channels + 1];
3731 b = pixels[y*stride + x*n_channels + 2];
3732 if (n_channels >= 4)
3733 a = pixels[y*stride + x*n_channels + 3];
3737 *p++ = a << 24 | r << 16 | g << 8 | b ;
3741 l = g_list_next (l);
3746 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3747 GDK_WINDOW_XID (window),
3748 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3751 (guchar*) data, size);
3755 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3756 GDK_WINDOW_XID (window),
3757 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3764 * gdk_window_set_icon:
3765 * @window: a toplevel #GdkWindow
3766 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3767 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3768 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3770 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3771 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3772 * and gtk_window_set_icon(). If those don't meet your needs, look at
3773 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3774 * want to fall back to gdk_window_set_icon().
3778 gdk_window_set_icon (GdkWindow *window,
3779 GdkWindow *icon_window,
3783 GdkToplevelX11 *toplevel;
3785 g_return_if_fail (window != NULL);
3786 g_return_if_fail (GDK_IS_WINDOW (window));
3787 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3789 if (GDK_WINDOW_DESTROYED (window))
3792 toplevel = _gdk_x11_window_get_toplevel (window);
3794 if (toplevel->icon_window != icon_window)
3796 if (toplevel->icon_window)
3797 g_object_unref (toplevel->icon_window);
3798 toplevel->icon_window = g_object_ref (icon_window);
3801 if (toplevel->icon_pixmap != pixmap)
3804 g_object_ref (pixmap);
3805 if (toplevel->icon_pixmap)
3806 g_object_unref (toplevel->icon_pixmap);
3807 toplevel->icon_pixmap = pixmap;
3810 if (toplevel->icon_mask != mask)
3813 g_object_ref (mask);
3814 if (toplevel->icon_mask)
3815 g_object_unref (toplevel->icon_mask);
3816 toplevel->icon_mask = mask;
3819 update_wm_hints (window, FALSE);
3823 gdk_window_icon_name_set (GdkWindow *window)
3825 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3826 g_quark_from_static_string ("gdk-icon-name-set")));
3830 * gdk_window_set_icon_name:
3831 * @window: a toplevel #GdkWindow
3832 * @name: name of window while iconified (minimized)
3834 * Windows may have a name used while minimized, distinct from the
3835 * name they display in their titlebar. Most of the time this is a bad
3836 * idea from a user interface standpoint. But you can set such a name
3837 * with this function, if you like.
3841 gdk_window_set_icon_name (GdkWindow *window,
3844 GdkDisplay *display;
3846 g_return_if_fail (window != NULL);
3847 g_return_if_fail (GDK_IS_WINDOW (window));
3849 if (GDK_WINDOW_DESTROYED (window))
3852 display = gdk_drawable_get_display (window);
3854 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3855 GUINT_TO_POINTER (TRUE));
3857 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3858 GDK_WINDOW_XID (window),
3859 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3860 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3861 PropModeReplace, name, strlen (name));
3863 set_text_property (display, GDK_WINDOW_XID (window),
3864 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3869 * gdk_window_iconify:
3870 * @window: a toplevel #GdkWindow
3872 * Asks to iconify (minimize) @window. The window manager may choose
3873 * to ignore the request, but normally will honor it. Using
3874 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3876 * This function only makes sense when @window is a toplevel window.
3880 gdk_window_iconify (GdkWindow *window)
3882 GdkWindowObject *private;
3884 g_return_if_fail (window != NULL);
3885 g_return_if_fail (GDK_IS_WINDOW (window));
3887 if (GDK_WINDOW_DESTROYED (window))
3890 private = (GdkWindowObject*) window;
3892 if (GDK_WINDOW_IS_MAPPED (window))
3894 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3895 GDK_WINDOW_XWINDOW (window),
3896 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3900 /* Flip our client side flag, the real work happens on map. */
3901 gdk_synthesize_window_state (window,
3903 GDK_WINDOW_STATE_ICONIFIED);
3908 * gdk_window_deiconify:
3909 * @window: a toplevel #GdkWindow
3911 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3912 * choose to ignore the request to deiconify. When using GTK+,
3913 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3914 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3915 * unminimizes it, and puts it on the current desktop.
3919 gdk_window_deiconify (GdkWindow *window)
3921 GdkWindowObject *private;
3923 g_return_if_fail (window != NULL);
3924 g_return_if_fail (GDK_IS_WINDOW (window));
3926 if (GDK_WINDOW_DESTROYED (window))
3929 private = (GdkWindowObject*) window;
3931 if (GDK_WINDOW_IS_MAPPED (window))
3933 gdk_window_show (window);
3937 /* Flip our client side flag, the real work happens on map. */
3938 gdk_synthesize_window_state (window,
3939 GDK_WINDOW_STATE_ICONIFIED,
3946 * @window: a toplevel #GdkWindow
3948 * "Pins" a window such that it's on all workspaces and does not scroll
3949 * with viewports, for window managers that have scrollable viewports.
3950 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3952 * On the X11 platform, this function depends on window manager
3953 * support, so may have no effect with many window managers. However,
3954 * GDK will do the best it can to convince the window manager to stick
3955 * the window. For window managers that don't support this operation,
3956 * there's nothing you can do to force it to happen.
3960 gdk_window_stick (GdkWindow *window)
3962 g_return_if_fail (GDK_IS_WINDOW (window));
3964 if (GDK_WINDOW_DESTROYED (window))
3967 if (GDK_WINDOW_IS_MAPPED (window))
3969 /* "stick" means stick to all desktops _and_ do not scroll with the
3970 * viewport. i.e. glue to the monitor glass in all cases.
3975 /* Request stick during viewport scroll */
3976 gdk_wmspec_change_state (TRUE, window,
3977 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3980 /* Request desktop 0xFFFFFFFF */
3981 xev.xclient.type = ClientMessage;
3982 xev.xclient.serial = 0;
3983 xev.xclient.send_event = True;
3984 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3985 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3986 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3988 xev.xclient.format = 32;
3990 xev.xclient.data.l[0] = 0xFFFFFFFF;
3991 xev.xclient.data.l[1] = 0;
3992 xev.xclient.data.l[2] = 0;
3993 xev.xclient.data.l[3] = 0;
3994 xev.xclient.data.l[4] = 0;
3996 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3997 SubstructureRedirectMask | SubstructureNotifyMask,
4002 /* Flip our client side flag, the real work happens on map. */
4003 gdk_synthesize_window_state (window,
4005 GDK_WINDOW_STATE_STICKY);
4010 * gdk_window_unstick:
4011 * @window: a toplevel #GdkWindow
4013 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
4014 * and gtk_window_unstick().
4018 gdk_window_unstick (GdkWindow *window)
4020 g_return_if_fail (GDK_IS_WINDOW (window));
4022 if (GDK_WINDOW_DESTROYED (window))
4025 if (GDK_WINDOW_IS_MAPPED (window))
4032 gulong *current_desktop;
4033 GdkDisplay *display = gdk_drawable_get_display (window);
4035 /* Request unstick from viewport */
4036 gdk_wmspec_change_state (FALSE, window,
4037 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
4040 /* Get current desktop, then set it; this is a race, but not
4041 * one that matters much in practice.
4043 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
4044 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
4046 False, XA_CARDINAL, &type, &format, &nitems,
4047 &bytes_after, (guchar **)¤t_desktop);
4049 if (type == XA_CARDINAL)
4051 xev.xclient.type = ClientMessage;
4052 xev.xclient.serial = 0;
4053 xev.xclient.send_event = True;
4054 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
4055 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
4056 xev.xclient.format = 32;
4058 xev.xclient.data.l[0] = *current_desktop;
4059 xev.xclient.data.l[1] = 0;
4060 xev.xclient.data.l[2] = 0;
4061 xev.xclient.data.l[3] = 0;
4062 xev.xclient.data.l[4] = 0;
4064 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4065 SubstructureRedirectMask | SubstructureNotifyMask,
4068 XFree (current_desktop);
4073 /* Flip our client side flag, the real work happens on map. */
4074 gdk_synthesize_window_state (window,
4075 GDK_WINDOW_STATE_STICKY,
4082 * gdk_window_maximize:
4083 * @window: a toplevel #GdkWindow
4085 * Maximizes the window. If the window was already maximized, then
4086 * this function does nothing.
4088 * On X11, asks the window manager to maximize @window, if the window
4089 * manager supports this operation. Not all window managers support
4090 * this, and some deliberately ignore it or don't have a concept of
4091 * "maximized"; so you can't rely on the maximization actually
4092 * happening. But it will happen with most standard window managers,
4093 * and GDK makes a best effort to get it to happen.
4095 * On Windows, reliably maximizes the window.
4099 gdk_window_maximize (GdkWindow *window)
4101 g_return_if_fail (GDK_IS_WINDOW (window));
4103 if (GDK_WINDOW_DESTROYED (window))
4106 if (GDK_WINDOW_IS_MAPPED (window))
4107 gdk_wmspec_change_state (TRUE, window,
4108 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
4109 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
4111 gdk_synthesize_window_state (window,
4113 GDK_WINDOW_STATE_MAXIMIZED);
4117 * gdk_window_unmaximize:
4118 * @window: a toplevel #GdkWindow
4120 * Unmaximizes the window. If the window wasn't maximized, then this
4121 * function does nothing.
4123 * On X11, asks the window manager to unmaximize @window, if the
4124 * window manager supports this operation. Not all window managers
4125 * support this, and some deliberately ignore it or don't have a
4126 * concept of "maximized"; so you can't rely on the unmaximization
4127 * actually happening. But it will happen with most standard window
4128 * managers, and GDK makes a best effort to get it to happen.
4130 * On Windows, reliably unmaximizes the window.
4134 gdk_window_unmaximize (GdkWindow *window)
4136 g_return_if_fail (GDK_IS_WINDOW (window));
4138 if (GDK_WINDOW_DESTROYED (window))
4141 if (GDK_WINDOW_IS_MAPPED (window))
4142 gdk_wmspec_change_state (FALSE, window,
4143 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
4144 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
4146 gdk_synthesize_window_state (window,
4147 GDK_WINDOW_STATE_MAXIMIZED,
4152 * gdk_window_fullscreen:
4153 * @window: a toplevel #GdkWindow
4155 * Moves the window into fullscreen mode. This means the
4156 * window covers the entire screen and is above any panels
4159 * If the window was already fullscreen, then this function does nothing.
4161 * On X11, asks the window manager to put @window in a fullscreen
4162 * state, if the window manager supports this operation. Not all
4163 * window managers support this, and some deliberately ignore it or
4164 * don't have a concept of "fullscreen"; so you can't rely on the
4165 * fullscreenification actually happening. But it will happen with
4166 * most standard window managers, and GDK makes a best effort to get
4172 gdk_window_fullscreen (GdkWindow *window)
4174 g_return_if_fail (GDK_IS_WINDOW (window));
4176 if (GDK_WINDOW_DESTROYED (window))
4179 if (GDK_WINDOW_IS_MAPPED (window))
4180 gdk_wmspec_change_state (TRUE, window,
4181 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
4185 gdk_synthesize_window_state (window,
4187 GDK_WINDOW_STATE_FULLSCREEN);
4191 * gdk_window_unfullscreen:
4192 * @window: a toplevel #GdkWindow
4194 * Moves the window out of fullscreen mode. If the window was not
4195 * fullscreen, does nothing.
4197 * On X11, asks the window manager to move @window out of the fullscreen
4198 * state, if the window manager supports this operation. Not all
4199 * window managers support this, and some deliberately ignore it or
4200 * don't have a concept of "fullscreen"; so you can't rely on the
4201 * unfullscreenification actually happening. But it will happen with
4202 * most standard window managers, and GDK makes a best effort to get
4208 gdk_window_unfullscreen (GdkWindow *window)
4210 g_return_if_fail (GDK_IS_WINDOW (window));
4212 if (GDK_WINDOW_DESTROYED (window))
4215 if (GDK_WINDOW_IS_MAPPED (window))
4216 gdk_wmspec_change_state (FALSE, window,
4217 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
4221 gdk_synthesize_window_state (window,
4222 GDK_WINDOW_STATE_FULLSCREEN,
4227 * gdk_window_set_keep_above:
4228 * @window: a toplevel #GdkWindow
4229 * @setting: whether to keep @window above other windows
4231 * Set if @window must be kept above other windows. If the
4232 * window was already above, then this function does nothing.
4234 * On X11, asks the window manager to keep @window above, if the window
4235 * manager supports this operation. Not all window managers support
4236 * this, and some deliberately ignore it or don't have a concept of
4237 * "keep above"; so you can't rely on the window being kept above.
4238 * But it will happen with most standard window managers,
4239 * and GDK makes a best effort to get it to happen.
4244 gdk_window_set_keep_above (GdkWindow *window, gboolean setting)
4246 g_return_if_fail (GDK_IS_WINDOW (window));
4248 if (GDK_WINDOW_DESTROYED (window))
4251 if (GDK_WINDOW_IS_MAPPED (window))
4252 gdk_wmspec_change_state (setting, window,
4253 gdk_atom_intern ("_NET_WM_STATE_ABOVE", setting),
4254 setting ? gdk_atom_intern ("_NET_WM_STATE_BELOW", FALSE)
4257 gdk_synthesize_window_state (window,
4258 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4259 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4263 * gdk_window_set_keep_below:
4264 * @window: a toplevel #GdkWindow
4265 * @setting: whether to keep @window below other windows
4267 * Set if @window must be kept below other windows. If the
4268 * window was already below, then this function does nothing.
4270 * On X11, asks the window manager to keep @window below, if the window
4271 * manager supports this operation. Not all window managers support
4272 * this, and some deliberately ignore it or don't have a concept of
4273 * "keep below"; so you can't rely on the window being kept below.
4274 * But it will happen with most standard window managers,
4275 * and GDK makes a best effort to get it to happen.
4280 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4282 g_return_if_fail (GDK_IS_WINDOW (window));
4284 if (GDK_WINDOW_DESTROYED (window))
4287 if (GDK_WINDOW_IS_MAPPED (window))
4288 gdk_wmspec_change_state (setting, window,
4289 gdk_atom_intern ("_NET_WM_STATE_BELOW", setting),
4290 setting ? gdk_atom_intern ("_NET_WM_STATE_ABOVE", FALSE)
4293 gdk_synthesize_window_state (window,
4294 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4295 setting ? GDK_WINDOW_STATE_BELOW : 0);
4299 * gdk_window_get_group:
4300 * @window: a toplevel #GdkWindow
4302 * Returns the group leader window for @window. See gdk_window_set_group().
4304 * Return value: the group leader window for @window
4309 gdk_window_get_group (GdkWindow *window)
4311 GdkToplevelX11 *toplevel;
4313 g_return_val_if_fail (window != NULL, NULL);
4314 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4315 g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);
4317 if (GDK_WINDOW_DESTROYED (window))
4320 toplevel = _gdk_x11_window_get_toplevel (window);
4322 return toplevel->group_leader;
4326 * gdk_window_set_group:
4327 * @window: a toplevel #GdkWindow
4328 * @leader: group leader window, or %NULL to restore the default group leader window
4330 * Sets the group leader window for @window. By default,
4331 * GDK sets the group leader for all toplevel windows
4332 * to a global window implicitly created by GDK. With this function
4333 * you can override this default.
4335 * The group leader window allows the window manager to distinguish
4336 * all windows that belong to a single application. It may for example
4337 * allow users to minimize/unminimize all windows belonging to an
4338 * application at once. You should only set a non-default group window
4339 * if your application pretends to be multiple applications.
4342 gdk_window_set_group (GdkWindow *window,
4345 GdkToplevelX11 *toplevel;
4347 g_return_if_fail (window != NULL);
4348 g_return_if_fail (GDK_IS_WINDOW (window));
4349 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4350 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4352 if (GDK_WINDOW_DESTROYED (window) || (leader != NULL && GDK_WINDOW_DESTROYED (leader)))
4355 toplevel = _gdk_x11_window_get_toplevel (window);
4358 leader = gdk_display_get_default_group (gdk_drawable_get_display (window));
4360 if (toplevel->group_leader != leader)
4362 if (toplevel->group_leader)
4363 g_object_unref (toplevel->group_leader);
4364 toplevel->group_leader = g_object_ref (leader);
4367 update_wm_hints (window, FALSE);
4370 static MotifWmHints *
4371 gdk_window_get_mwm_hints (GdkWindow *window)
4373 GdkDisplay *display;
4374 Atom hints_atom = None;
4375 MotifWmHints *hints;
4381 if (GDK_WINDOW_DESTROYED (window))
4384 display = gdk_drawable_get_display (window);
4386 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4388 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4389 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4390 False, AnyPropertyType, &type, &format, &nitems,
4391 &bytes_after, (guchar **)&hints);
4400 gdk_window_set_mwm_hints (GdkWindow *window,
4401 MotifWmHints *new_hints)
4403 GdkDisplay *display;
4404 Atom hints_atom = None;
4405 MotifWmHints *hints;
4411 if (GDK_WINDOW_DESTROYED (window))
4414 display = gdk_drawable_get_display (window);
4416 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4418 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4419 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4420 False, AnyPropertyType, &type, &format, &nitems,
4421 &bytes_after, (guchar **)&hints);
4427 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4429 hints->flags |= MWM_HINTS_FUNCTIONS;
4430 hints->functions = new_hints->functions;
4432 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4434 hints->flags |= MWM_HINTS_DECORATIONS;
4435 hints->decorations = new_hints->decorations;
4439 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4440 hints_atom, hints_atom, 32, PropModeReplace,
4441 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4443 if (hints != new_hints)
4448 * gdk_window_set_decorations:
4449 * @window: a toplevel #GdkWindow
4450 * @decorations: decoration hint mask
4452 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
4453 * This function sets the traditional Motif window manager hints that tell the
4454 * window manager which decorations you would like your window to have.
4455 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
4456 * using the GDK function directly.
4458 * The @decorations argument is the logical OR of the fields in
4459 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
4460 * mask, the other bits indicate which decorations should be turned off.
4461 * If #GDK_DECOR_ALL is not included, then the other bits indicate
4462 * which decorations should be turned on.
4464 * Most window managers honor a decorations hint of 0 to disable all decorations,
4465 * but very few honor all possible combinations of bits.
4469 gdk_window_set_decorations (GdkWindow *window,
4470 GdkWMDecoration decorations)
4474 g_return_if_fail (window != NULL);
4475 g_return_if_fail (GDK_IS_WINDOW (window));
4477 hints.flags = MWM_HINTS_DECORATIONS;
4478 hints.decorations = decorations;
4480 gdk_window_set_mwm_hints (window, &hints);
4484 * gdk_window_get_decorations:
4485 * @window: The toplevel #GdkWindow to get the decorations from
4486 * @decorations: The window decorations will be written here
4488 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
4489 * Returns: TRUE if the window has decorations set, FALSE otherwise.
4492 gdk_window_get_decorations(GdkWindow *window,
4493 GdkWMDecoration *decorations)
4495 MotifWmHints *hints;
4496 gboolean result = FALSE;
4498 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4500 hints = gdk_window_get_mwm_hints (window);
4504 if (hints->flags & MWM_HINTS_DECORATIONS)
4507 *decorations = hints->decorations;
4518 * gdk_window_set_functions:
4519 * @window: a toplevel #GdkWindow
4520 * @functions: bitmask of operations to allow on @window
4522 * This function isn't really good for much. It sets the traditional
4523 * Motif window manager hint for which operations the window manager
4524 * should allow on a toplevel window. However, few window managers do
4525 * anything reliable or interesting with this hint. Many ignore it
4528 * The @functions argument is the logical OR of values from the
4529 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
4530 * then the other bits indicate which functions to disable; if
4531 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4536 gdk_window_set_functions (GdkWindow *window,
4537 GdkWMFunction functions)
4541 g_return_if_fail (window != NULL);
4542 g_return_if_fail (GDK_IS_WINDOW (window));
4544 hints.flags = MWM_HINTS_FUNCTIONS;
4545 hints.functions = functions;
4547 gdk_window_set_mwm_hints (window, &hints);
4550 #ifdef HAVE_SHAPE_EXT
4553 * propagate the shapes from all child windows of a GDK window to the parent
4554 * window. Shamelessly ripped from Enlightenment's code
4562 struct _gdk_span *next;
4566 gdk_add_to_span (struct _gdk_span **s,
4570 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
4577 /* scan the spans for this line */
4580 /* -- -> new span */
4581 /* == -> existing span */
4582 /* ## -> spans intersect */
4583 /* if we are in the middle of spanning the span into the line */
4586 /* case: ---- ==== */
4587 if (xx < ptr1->start - 1)
4589 /* ends before next span - extend to here */
4593 /* case: ----##=== */
4594 else if (xx <= ptr1->end)
4596 /* crosses into next span - delete next span and append */
4597 ss->end = ptr1->end;
4598 ss->next = ptr1->next;
4602 /* case: ---###--- */
4605 /* overlaps next span - delete and keep checking */
4606 ss->next = ptr1->next;
4611 /* otherwise havent started spanning it in yet */
4614 /* case: ---- ==== */
4615 if (xx < ptr1->start - 1)
4617 /* insert span here in list */
4618 noo = g_malloc (sizeof (struct _gdk_span));
4632 /* case: ----##=== */
4633 else if ((x < ptr1->start) && (xx <= ptr1->end))
4635 /* expand this span to the left point of the new one */
4639 /* case: ===###=== */
4640 else if ((x >= ptr1->start) && (xx <= ptr1->end))
4642 /* throw the span away */
4645 /* case: ---###--- */
4646 else if ((x < ptr1->start) && (xx > ptr1->end))
4653 /* case: ===##---- */
4654 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
4660 /* case: ==== ---- */
4661 /* case handled by next loop iteration - first case */
4666 /* it started in the middle but spans beyond your current list */
4672 /* it does not start inside a span or in the middle, so add it to the end */
4673 noo = g_malloc (sizeof (struct _gdk_span));
4681 noo->next = ptr2->next;
4694 gdk_add_rectangles (Display *disp,
4696 struct _gdk_span **spans,
4703 gint x1, y1, x2, y2;
4707 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
4710 /* go through all clip rects in this window's shape */
4711 for (k = 0; k < rn; k++)
4713 /* for each clip rect, add it to each line's spans */
4715 x2 = x + rl[k].x + (rl[k].width - 1);
4717 y2 = y + rl[k].y + (rl[k].height - 1);
4726 for (a = y1; a <= y2; a++)
4729 gdk_add_to_span (&spans[a], x1, x2);
4737 gdk_propagate_shapes (Display *disp,
4741 Window rt, par, *list = NULL;
4742 gint i, j, num = 0, num_rects = 0;
4746 XRectangle *rects = NULL;
4747 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
4748 XWindowAttributes xatt;
4750 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
4755 spans = g_malloc (sizeof (struct _gdk_span *) * h);
4757 for (i = 0; i < h; i++)
4759 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
4762 /* go through all child windows and create/insert spans */
4763 for (i = 0; i < num; i++)
4765 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
4766 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
4767 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
4770 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
4772 /* go through the spans list and build a list of rects */
4773 rects = g_malloc (sizeof (XRectangle) * 256);
4775 for (i = 0; i < baseh; i++)
4778 /* go through the line for all spans */
4781 rects[num_rects].x = ptr1->start;
4782 rects[num_rects].y = i;
4783 rects[num_rects].width = ptr1->end - ptr1->start + 1;
4784 rects[num_rects].height = 1;
4786 /* if there are more lines */
4788 /* while contigous rects (same start/end coords) exist */
4789 while ((contig) && (j < baseh))
4791 /* search next line for spans matching this one */
4797 /* if we have an exact span match set contig */
4798 if ((ptr2->start == ptr1->start) &&
4799 (ptr2->end == ptr1->end))
4802 /* remove the span - not needed */
4805 ptr3->next = ptr2->next;
4811 spans[j] = ptr2->next;
4817 /* gone past the span point no point looking */
4818 else if (ptr2->start < ptr1->start)
4826 /* if a contiguous span was found increase the rect h */
4829 rects[num_rects].height++;
4833 /* up the rect count */
4835 /* every 256 new rects increase the rect array */
4836 if ((num_rects % 256) == 0)
4837 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
4841 /* set the rects as the shape mask */
4844 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
4845 ShapeSet, YXSorted);
4850 /* free up all the spans we made */
4851 for (i = 0; i < baseh; i++)
4864 #endif /* HAVE_SHAPE_EXT */
4867 * gdk_window_set_child_shapes:
4868 * @window: a #GdkWindow
4870 * Sets the shape mask of @window to the union of shape masks
4871 * for all children of @window, ignoring the shape mask of @window
4872 * itself. Contrast with gdk_window_merge_child_shapes() which includes
4873 * the shape mask of @window in the masks to be merged.
4876 gdk_window_set_child_shapes (GdkWindow *window)
4878 g_return_if_fail (window != NULL);
4879 g_return_if_fail (GDK_IS_WINDOW (window));
4881 #ifdef HAVE_SHAPE_EXT
4882 if (!GDK_WINDOW_DESTROYED (window) &&
4883 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4884 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4885 GDK_WINDOW_XID (window), FALSE);
4890 * gdk_window_merge_child_shapes:
4891 * @window: a #GdkWindow
4893 * Merges the shape masks for any child windows into the
4894 * shape mask for @window. i.e. the union of all masks
4895 * for @window and its children will become the new mask
4896 * for @window. See gdk_window_shape_combine_mask().
4898 * This function is distinct from gdk_window_set_child_shapes()
4899 * because it includes @window's shape mask in the set of shapes to
4904 gdk_window_merge_child_shapes (GdkWindow *window)
4906 g_return_if_fail (window != NULL);
4907 g_return_if_fail (GDK_IS_WINDOW (window));
4909 #ifdef HAVE_SHAPE_EXT
4910 if (!GDK_WINDOW_DESTROYED (window) &&
4911 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4912 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4913 GDK_WINDOW_XID (window), TRUE);
4918 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
4920 XSetWindowAttributes xattributes;
4921 GdkWindowObject *private;
4922 guint xattributes_mask = 0;
4924 g_return_if_fail (window != NULL);
4926 private = GDK_WINDOW_OBJECT (window);
4927 if (private->input_only)
4930 xattributes.bit_gravity = StaticGravity;
4931 xattributes_mask |= CWBitGravity;
4932 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4933 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4934 GDK_WINDOW_XID (window),
4935 CWBitGravity, &xattributes);
4939 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4941 XSetWindowAttributes xattributes;
4943 g_return_if_fail (window != NULL);
4945 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4947 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4948 GDK_WINDOW_XID (window),
4949 CWWinGravity, &xattributes);
4953 * gdk_window_set_static_gravities:
4954 * @window: a #GdkWindow
4955 * @use_static: %TRUE to turn on static gravity
4957 * Set the bit gravity of the given window to static, and flag it so
4958 * all children get static subwindow gravity. This is used if you are
4959 * implementing scary features that involve deep knowledge of the
4960 * windowing system. Don't worry about it unless you have to.
4962 * Return value: %TRUE if the server supports static gravity
4965 gdk_window_set_static_gravities (GdkWindow *window,
4966 gboolean use_static)
4968 GdkWindowObject *private = (GdkWindowObject *)window;
4971 g_return_val_if_fail (window != NULL, FALSE);
4972 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4974 if (!use_static == !private->guffaw_gravity)
4977 private->guffaw_gravity = use_static;
4979 if (!GDK_WINDOW_DESTROYED (window))
4981 gdk_window_set_static_bit_gravity (window, use_static);
4983 tmp_list = private->children;
4986 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4988 tmp_list = tmp_list->next;
4996 wmspec_moveresize (GdkWindow *window,
5002 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5006 /* Release passive grab */
5007 gdk_display_pointer_ungrab (display, timestamp);
5009 xev.xclient.type = ClientMessage;
5010 xev.xclient.serial = 0;
5011 xev.xclient.send_event = True;
5012 xev.xclient.window = GDK_WINDOW_XID (window);
5013 xev.xclient.message_type =
5014 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
5015 xev.xclient.format = 32;
5016 xev.xclient.data.l[0] = root_x;
5017 xev.xclient.data.l[1] = root_y;
5018 xev.xclient.data.l[2] = direction;
5019 xev.xclient.data.l[3] = 0;
5020 xev.xclient.data.l[4] = 0;
5022 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
5023 SubstructureRedirectMask | SubstructureNotifyMask,
5027 typedef struct _MoveResizeData MoveResizeData;
5029 struct _MoveResizeData
5031 GdkDisplay *display;
5033 GdkWindow *moveresize_window;
5034 GdkWindow *moveresize_emulation_window;
5036 GdkWindowEdge resize_edge;
5037 gint moveresize_button;
5040 gint moveresize_orig_x;
5041 gint moveresize_orig_y;
5042 gint moveresize_orig_width;
5043 gint moveresize_orig_height;
5044 GdkWindowHints moveresize_geom_mask;
5045 GdkGeometry moveresize_geometry;
5046 Time moveresize_process_time;
5047 XEvent *moveresize_pending_event;
5050 /* From the WM spec */
5051 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
5052 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
5053 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
5054 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
5055 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
5056 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
5057 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
5058 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
5059 #define _NET_WM_MOVERESIZE_MOVE 8
5062 wmspec_resize_drag (GdkWindow *window,
5071 /* Let the compiler turn a switch into a table, instead
5072 * of doing the table manually, this way is easier to verify.
5076 case GDK_WINDOW_EDGE_NORTH_WEST:
5077 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
5080 case GDK_WINDOW_EDGE_NORTH:
5081 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
5084 case GDK_WINDOW_EDGE_NORTH_EAST:
5085 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
5088 case GDK_WINDOW_EDGE_WEST:
5089 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
5092 case GDK_WINDOW_EDGE_EAST:
5093 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
5096 case GDK_WINDOW_EDGE_SOUTH_WEST:
5097 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
5100 case GDK_WINDOW_EDGE_SOUTH:
5101 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
5104 case GDK_WINDOW_EDGE_SOUTH_EAST:
5105 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
5109 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
5115 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
5118 static MoveResizeData *
5119 get_move_resize_data (GdkDisplay *display,
5122 MoveResizeData *mv_resize;
5123 static GQuark move_resize_quark = 0;
5125 if (!move_resize_quark)
5126 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
5128 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
5130 if (!mv_resize && create)
5132 mv_resize = g_new0 (MoveResizeData, 1);
5133 mv_resize->display = display;
5135 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
5142 update_pos (MoveResizeData *mv_resize,
5148 dx = new_root_x - mv_resize->moveresize_x;
5149 dy = new_root_y - mv_resize->moveresize_y;
5151 if (mv_resize->is_resize)
5155 x = mv_resize->moveresize_orig_x;
5156 y = mv_resize->moveresize_orig_y;
5158 w = mv_resize->moveresize_orig_width;
5159 h = mv_resize->moveresize_orig_height;
5161 switch (mv_resize->resize_edge)
5163 case GDK_WINDOW_EDGE_NORTH_WEST:
5169 case GDK_WINDOW_EDGE_NORTH:
5173 case GDK_WINDOW_EDGE_NORTH_EAST:
5178 case GDK_WINDOW_EDGE_SOUTH_WEST:
5183 case GDK_WINDOW_EDGE_SOUTH_EAST:
5187 case GDK_WINDOW_EDGE_SOUTH:
5190 case GDK_WINDOW_EDGE_EAST:
5193 case GDK_WINDOW_EDGE_WEST:
5204 if (mv_resize->moveresize_geom_mask)
5206 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
5207 mv_resize->moveresize_geom_mask,
5211 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
5217 x = mv_resize->moveresize_orig_x + dx;
5218 y = mv_resize->moveresize_orig_y + dy;
5220 gdk_window_move (mv_resize->moveresize_window, x, y);
5225 finish_drag (MoveResizeData *mv_resize)
5227 gdk_window_destroy (mv_resize->moveresize_emulation_window);
5228 mv_resize->moveresize_emulation_window = NULL;
5229 mv_resize->moveresize_window = NULL;
5231 if (mv_resize->moveresize_pending_event)
5233 g_free (mv_resize->moveresize_pending_event);
5234 mv_resize->moveresize_pending_event = NULL;
5239 lookahead_motion_predicate (Display *xdisplay,
5243 gboolean *seen_release = (gboolean *)arg;
5244 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
5245 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5250 switch (event->xany.type)
5253 *seen_release = TRUE;
5256 mv_resize->moveresize_process_time = event->xmotion.time;
5266 moveresize_lookahead (MoveResizeData *mv_resize,
5270 gboolean seen_release = FALSE;
5272 if (mv_resize->moveresize_process_time)
5274 if (event->xmotion.time == mv_resize->moveresize_process_time)
5276 mv_resize->moveresize_process_time = 0;
5283 XCheckIfEvent (event->xany.display, &tmp_event,
5284 lookahead_motion_predicate, (XPointer) & seen_release);
5286 return mv_resize->moveresize_process_time == 0;
5290 _gdk_moveresize_handle_event (XEvent *event)
5292 guint button_mask = 0;
5293 GdkWindowObject *window_private;
5294 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
5295 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5297 if (!mv_resize || !mv_resize->moveresize_window)
5300 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
5302 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
5304 switch (event->xany.type)
5307 if (window_private->resize_count > 0)
5309 if (mv_resize->moveresize_pending_event)
5310 *mv_resize->moveresize_pending_event = *event;
5312 mv_resize->moveresize_pending_event =
5313 g_memdup (event, sizeof (XEvent));
5317 if (!moveresize_lookahead (mv_resize, event))
5320 update_pos (mv_resize,
5321 event->xmotion.x_root,
5322 event->xmotion.y_root);
5324 /* This should never be triggered in normal cases, but in the
5325 * case where the drag started without an implicit grab being
5326 * in effect, we could miss the release if it occurs before
5327 * we grab the pointer; this ensures that we will never
5328 * get a permanently stuck grab.
5330 if ((event->xmotion.state & button_mask) == 0)
5331 finish_drag (mv_resize);
5335 update_pos (mv_resize,
5336 event->xbutton.x_root,
5337 event->xbutton.y_root);
5339 if (event->xbutton.button == mv_resize->moveresize_button)
5340 finish_drag (mv_resize);
5347 _gdk_moveresize_configure_done (GdkDisplay *display,
5351 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5353 if (!mv_resize || window != mv_resize->moveresize_window)
5356 if (mv_resize->moveresize_pending_event)
5358 tmp_event = mv_resize->moveresize_pending_event;
5359 mv_resize->moveresize_pending_event = NULL;
5360 _gdk_moveresize_handle_event (tmp_event);
5368 create_moveresize_window (MoveResizeData *mv_resize,
5371 GdkWindowAttr attributes;
5372 gint attributes_mask;
5373 GdkGrabStatus status;
5375 g_assert (mv_resize->moveresize_emulation_window == NULL);
5377 attributes.x = -100;
5378 attributes.y = -100;
5379 attributes.width = 10;
5380 attributes.height = 10;
5381 attributes.window_type = GDK_WINDOW_TEMP;
5382 attributes.wclass = GDK_INPUT_ONLY;
5383 attributes.override_redirect = TRUE;
5384 attributes.event_mask = 0;
5386 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5388 mv_resize->moveresize_emulation_window =
5389 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
5393 gdk_window_show (mv_resize->moveresize_emulation_window);
5395 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
5397 GDK_BUTTON_RELEASE_MASK |
5398 GDK_POINTER_MOTION_MASK,
5403 if (status != GDK_GRAB_SUCCESS)
5405 /* If this fails, some other client has grabbed the window
5408 gdk_window_destroy (mv_resize->moveresize_emulation_window);
5409 mv_resize->moveresize_emulation_window = NULL;
5412 mv_resize->moveresize_process_time = 0;
5416 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
5417 so that calling XMoveWindow with these coordinates will not move the
5419 Note that this depends on the WM to implement ICCCM-compliant reference
5423 calculate_unmoving_origin (MoveResizeData *mv_resize)
5428 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
5429 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
5431 gdk_window_get_origin (mv_resize->moveresize_window,
5432 &mv_resize->moveresize_orig_x,
5433 &mv_resize->moveresize_orig_y);
5437 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
5438 gdk_window_get_geometry (mv_resize->moveresize_window,
5439 NULL, NULL, &width, &height, NULL);
5441 switch (mv_resize->moveresize_geometry.win_gravity)
5443 case GDK_GRAVITY_NORTH_WEST:
5444 mv_resize->moveresize_orig_x = rect.x;
5445 mv_resize->moveresize_orig_y = rect.y;
5447 case GDK_GRAVITY_NORTH:
5448 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5449 mv_resize->moveresize_orig_y = rect.y;
5451 case GDK_GRAVITY_NORTH_EAST:
5452 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5453 mv_resize->moveresize_orig_y = rect.y;
5455 case GDK_GRAVITY_WEST:
5456 mv_resize->moveresize_orig_x = rect.x;
5457 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5459 case GDK_GRAVITY_CENTER:
5460 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5461 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5463 case GDK_GRAVITY_EAST:
5464 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5465 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5467 case GDK_GRAVITY_SOUTH_WEST:
5468 mv_resize->moveresize_orig_x = rect.x;
5469 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5471 case GDK_GRAVITY_SOUTH:
5472 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5473 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5475 case GDK_GRAVITY_SOUTH_EAST:
5476 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5477 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5480 mv_resize->moveresize_orig_x = rect.x;
5481 mv_resize->moveresize_orig_y = rect.y;
5488 emulate_resize_drag (GdkWindow *window,
5495 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5497 mv_resize->is_resize = TRUE;
5498 mv_resize->moveresize_button = button;
5499 mv_resize->resize_edge = edge;
5500 mv_resize->moveresize_x = root_x;
5501 mv_resize->moveresize_y = root_y;
5502 mv_resize->moveresize_window = g_object_ref (window);
5504 gdk_drawable_get_size (window,
5505 &mv_resize->moveresize_orig_width,
5506 &mv_resize->moveresize_orig_height);
5508 mv_resize->moveresize_geom_mask = 0;
5509 gdk_window_get_geometry_hints (window,
5510 &mv_resize->moveresize_geometry,
5511 &mv_resize->moveresize_geom_mask);
5513 calculate_unmoving_origin (mv_resize);
5515 create_moveresize_window (mv_resize, timestamp);
5519 emulate_move_drag (GdkWindow *window,
5525 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5527 mv_resize->is_resize = FALSE;
5528 mv_resize->moveresize_button = button;
5529 mv_resize->moveresize_x = root_x;
5530 mv_resize->moveresize_y = root_y;
5532 mv_resize->moveresize_window = g_object_ref (window);
5534 calculate_unmoving_origin (mv_resize);
5536 create_moveresize_window (mv_resize, timestamp);
5540 * gdk_window_begin_resize_drag:
5541 * @window: a toplevel #GdkWindow
5542 * @edge: the edge or corner from which the drag is started
5543 * @button: the button being used to drag
5544 * @root_x: root window X coordinate of mouse click that began the drag
5545 * @root_y: root window Y coordinate of mouse click that began the drag
5546 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5548 * Begins a window resize operation (for a toplevel window).
5549 * You might use this function to implement a "window resize grip," for
5550 * example; in fact #GtkStatusbar uses it. The function works best
5551 * with window managers that support the Extended Window Manager Hints spec
5552 * (see http://www.freedesktop.org), but has a fallback implementation
5553 * for other window managers.
5557 gdk_window_begin_resize_drag (GdkWindow *window,
5564 g_return_if_fail (GDK_IS_WINDOW (window));
5566 if (GDK_WINDOW_DESTROYED (window))
5569 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5570 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5571 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5573 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5577 * gdk_window_begin_move_drag:
5578 * @window: a toplevel #GdkWindow
5579 * @button: the button being used to drag
5580 * @root_x: root window X coordinate of mouse click that began the drag
5581 * @root_y: root window Y coordinate of mouse click that began the drag
5582 * @timestamp: timestamp of mouse click that began the drag
5584 * Begins a window move operation (for a toplevel window). You might
5585 * use this function to implement a "window move grip," for
5586 * example. The function works best with window managers that support
5587 * the Extended Window Manager Hints spec (see
5588 * http://www.freedesktop.org), but has a fallback implementation for
5589 * other window managers.
5593 gdk_window_begin_move_drag (GdkWindow *window,
5599 g_return_if_fail (GDK_IS_WINDOW (window));
5601 if (GDK_WINDOW_DESTROYED (window))
5604 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5605 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5606 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5609 emulate_move_drag (window, button, root_x, root_y, timestamp);