1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
30 #include <netinet/in.h>
35 #include "gdkwindow.h"
36 #include "gdkinputprivate.h"
37 #include "gdkdisplay-x11.h"
38 #include "gdkprivate-x11.h"
39 #include "gdkregion.h"
40 #include "gdkinternals.h"
42 #include "gdkwindow-x11.h"
50 #include <X11/extensions/shape.h>
53 const int _gdk_event_mask_table[21] =
57 PointerMotionHintMask,
74 SubstructureNotifyMask,
75 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
77 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
79 /* Forward declarations */
80 static gboolean gdk_window_gravity_works (GdkWindow *window);
81 static void gdk_window_set_static_win_gravity (GdkWindow *window,
83 static gboolean gdk_window_have_shape_ext (GdkDisplay *display);
84 static gboolean gdk_window_icon_name_set (GdkWindow *window);
86 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
87 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
89 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
92 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
93 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
94 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
95 static void gdk_window_impl_x11_finalize (GObject *object);
97 static gpointer parent_class = NULL;
100 gdk_window_impl_x11_get_type (void)
102 static GType object_type = 0;
106 static const GTypeInfo object_info =
108 sizeof (GdkWindowImplX11Class),
109 (GBaseInitFunc) NULL,
110 (GBaseFinalizeFunc) NULL,
111 (GClassInitFunc) gdk_window_impl_x11_class_init,
112 NULL, /* class_finalize */
113 NULL, /* class_data */
114 sizeof (GdkWindowImplX11),
116 (GInstanceInitFunc) gdk_window_impl_x11_init,
119 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
128 _gdk_window_impl_get_type (void)
130 return gdk_window_impl_x11_get_type ();
134 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
141 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
143 GObjectClass *object_class = G_OBJECT_CLASS (klass);
144 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
146 parent_class = g_type_class_peek_parent (klass);
148 object_class->finalize = gdk_window_impl_x11_finalize;
150 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
151 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
152 drawable_class->get_size = gdk_window_impl_x11_get_size;
154 /* Visible and clip regions are the same */
155 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
156 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
160 gdk_window_impl_x11_finalize (GObject *object)
162 GdkWindowObject *wrapper;
163 GdkDrawableImplX11 *draw_impl;
164 GdkWindowImplX11 *window_impl;
166 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
168 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
169 window_impl = GDK_WINDOW_IMPL_X11 (object);
171 wrapper = (GdkWindowObject*) draw_impl->wrapper;
173 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
175 if (!GDK_WINDOW_DESTROYED (wrapper))
177 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), draw_impl->xid);
178 if (window_impl->focus_window)
179 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), window_impl->focus_window);
182 G_OBJECT_CLASS (parent_class)->finalize (object);
186 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
188 GdkDrawableImplX11 *drawable_impl;
189 GdkWindowImplX11 *window_impl;
191 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
193 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
194 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
196 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
197 drawable_impl->colormap == NULL)
199 XWindowAttributes window_attributes;
201 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
204 drawable_impl->colormap =
205 gdk_colormap_lookup (window_attributes.colormap);
208 return drawable_impl->colormap;
212 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
215 GdkWindowImplX11 *impl;
216 GdkDrawableImplX11 *draw_impl;
218 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
220 impl = GDK_WINDOW_IMPL_X11 (drawable);
221 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
224 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
228 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
230 GDK_COLORMAP_XCOLORMAP (cmap));
232 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
234 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
240 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
244 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
247 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
249 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
253 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
255 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
256 GdkRectangle result_rect;
260 result_rect.width = impl->width;
261 result_rect.height = impl->height;
263 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
265 return gdk_region_rectangle (&result_rect);
269 _gdk_windowing_window_init (GdkScreen * screen)
271 GdkWindowObject *private;
272 GdkWindowImplX11 *impl;
273 GdkDrawableImplX11 *draw_impl;
274 GdkScreenX11 *screen_x11;
275 XWindowAttributes xattributes;
278 unsigned int border_width;
282 screen_x11 = GDK_SCREEN_X11 (screen);
284 g_assert (screen_x11->root_window == NULL);
286 screen_x11->default_colormap = gdk_screen_get_system_colormap (screen);
288 XGetGeometry (screen_x11->xdisplay, screen_x11->xroot_window,
289 &screen_x11->xroot_window, &x, &y, &width, &height, &border_width, &depth);
290 XGetWindowAttributes (screen_x11->xdisplay, screen_x11->xroot_window, &xattributes);
292 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
293 private = (GdkWindowObject *)screen_x11->root_window;
294 impl = GDK_WINDOW_IMPL_X11 (private->impl);
295 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
297 draw_impl->screen = screen;
298 draw_impl->xid = screen_x11->xroot_window;
299 draw_impl->wrapper = GDK_DRAWABLE (private);
301 private->window_type = GDK_WINDOW_ROOT;
302 private->depth = depth;
304 impl->height = height;
305 screen_x11->colormap_initialised = TRUE;
307 _gdk_xid_table_insert (screen_x11->display,
308 &screen_x11->xroot_window,
309 screen_x11->root_window);
313 set_wm_protocols (GdkWindow *window)
315 GdkDisplay *display = gdk_drawable_get_display (window);
318 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
319 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
320 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
322 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
327 * @parent: a #GdkWindow, or %NULL to create the window as a child of
328 * the default root window for the default display.
329 * @attributes: attributes of the new window
330 * @attributes_mask: mask indicating which fields in @attributes are valid
332 * Creates a new #GdkWindow using the attributes from
333 * @attributes. Seep #GdkWindowAttr and #GdkWindowAttributesType for
334 * more details. Note: to use this on displays other than the default
335 * display, @parent must be specified.
337 * Return value: the new #GdkWindow
340 gdk_window_new (GdkWindow *parent,
341 GdkWindowAttr *attributes,
342 gint attributes_mask)
345 GdkWindowObject *private;
346 GdkWindowImplX11 *impl;
347 GdkDrawableImplX11 *draw_impl;
348 GdkScreenX11 *screen_x11;
357 XSetWindowAttributes xattributes;
358 long xattributes_mask;
359 XSizeHints size_hints;
361 XClassHint *class_hint;
369 g_return_val_if_fail (attributes != NULL, NULL);
374 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
376 screen = gdk_get_default_screen ();
377 parent = gdk_screen_get_root_window (screen);
380 screen = gdk_drawable_get_screen (parent);
382 screen_x11 = GDK_SCREEN_X11 (screen);
384 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
386 if (GDK_WINDOW_DESTROYED (parent))
389 xparent = GDK_WINDOW_XID (parent);
391 window = g_object_new (GDK_TYPE_WINDOW, NULL);
392 private = (GdkWindowObject *)window;
393 impl = GDK_WINDOW_IMPL_X11 (private->impl);
394 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
395 draw_impl->wrapper = GDK_DRAWABLE (window);
397 draw_impl->screen = screen;
398 xdisplay = screen_x11->xdisplay;
400 /* Windows with a foreign parent are treated as if they are children
401 * of the root window, except for actual creation.
403 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
404 parent = gdk_screen_get_root_window (screen);
406 private->parent = (GdkWindowObject *)parent;
408 xattributes_mask = 0;
410 if (attributes_mask & GDK_WA_X)
415 if (attributes_mask & GDK_WA_Y)
422 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
423 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
425 if (attributes->wclass == GDK_INPUT_ONLY)
427 /* Backwards compatiblity - we've always ignored
428 * attributes->window_type for input-only windows
431 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
432 private->window_type = GDK_WINDOW_TEMP;
434 private->window_type = GDK_WINDOW_CHILD;
437 private->window_type = attributes->window_type;
439 _gdk_window_init_position (GDK_WINDOW (private));
440 if (impl->position_info.big)
441 private->guffaw_gravity = TRUE;
443 if (attributes_mask & GDK_WA_VISUAL)
444 visual = attributes->visual;
446 visual = gdk_screen_get_system_visual (screen);
447 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
449 xattributes.event_mask = StructureNotifyMask;
450 for (i = 0; i < _gdk_nenvent_masks; i++)
452 if (attributes->event_mask & (1 << (i + 1)))
453 xattributes.event_mask |= _gdk_event_mask_table[i];
455 private->event_mask = attributes->event_mask;
457 if (xattributes.event_mask)
458 xattributes_mask |= CWEventMask;
460 if (attributes_mask & GDK_WA_NOREDIR)
462 xattributes.override_redirect =
463 (attributes->override_redirect == FALSE)?False:True;
464 xattributes_mask |= CWOverrideRedirect;
467 xattributes.override_redirect = False;
469 if (private->parent && private->parent->guffaw_gravity)
471 xattributes.win_gravity = StaticGravity;
472 xattributes_mask |= CWWinGravity;
476 switch (private->window_type)
478 case GDK_WINDOW_TOPLEVEL:
479 case GDK_WINDOW_DIALOG:
480 case GDK_WINDOW_TEMP:
481 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
483 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
484 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
485 xparent = GDK_SCREEN_XROOTWIN (screen);
487 case GDK_WINDOW_CHILD:
490 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
494 if (attributes->wclass == GDK_INPUT_OUTPUT)
497 depth = visual->depth;
499 private->input_only = FALSE;
500 private->depth = depth;
502 if (attributes_mask & GDK_WA_COLORMAP)
504 draw_impl->colormap = attributes->colormap;
505 gdk_colormap_ref (attributes->colormap);
509 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
511 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
512 gdk_colormap_ref (draw_impl->colormap);
516 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
520 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
521 xattributes.background_pixel = private->bg_color.pixel;
523 private->bg_pixmap = NULL;
525 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
526 xattributes_mask |= CWBorderPixel | CWBackPixel;
528 if (private->guffaw_gravity)
529 xattributes.bit_gravity = StaticGravity;
531 xattributes.bit_gravity = NorthWestGravity;
533 xattributes_mask |= CWBitGravity;
535 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
536 xattributes_mask |= CWColormap;
538 if (private->window_type == GDK_WINDOW_TEMP)
540 xattributes.save_under = True;
541 xattributes.override_redirect = True;
542 xattributes.cursor = None;
543 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
551 private->input_only = TRUE;
552 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
553 gdk_colormap_ref (draw_impl->colormap);
556 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
557 impl->position_info.x, impl->position_info.y,
558 impl->position_info.width, impl->position_info.height,
559 0, depth, class, xvisual,
560 xattributes_mask, &xattributes);
562 gdk_drawable_ref (window);
563 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
565 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
566 (attributes->cursor) :
570 private->parent->children = g_list_prepend (private->parent->children, window);
572 switch (GDK_WINDOW_TYPE (private))
574 case GDK_WINDOW_DIALOG:
575 XSetTransientForHint (xdisplay, xid, xparent);
576 case GDK_WINDOW_TOPLEVEL:
577 case GDK_WINDOW_TEMP:
578 set_wm_protocols (window);
580 case GDK_WINDOW_CHILD:
581 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
582 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
583 (draw_impl->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window))))
585 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
586 gdk_window_add_colormap_windows (window);
595 if (class != InputOnly)
597 /* The focus window is off the visible area, and serves to receive key
598 * press events so they don't get sent to child windows.
600 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
602 xattributes.background_pixel,
603 xattributes.background_pixel);
604 /* FIXME: probably better to actually track the requested event mask for the toplevel
606 XSelectInput (xdisplay, impl->focus_window,
607 KeyPressMask | KeyReleaseMask | FocusChangeMask);
609 XMapWindow (xdisplay, impl->focus_window);
610 _gdk_xid_table_insert (screen_x11->display, &impl->focus_window, window);
613 size_hints.flags = PSize;
614 size_hints.width = impl->width;
615 size_hints.height = impl->height;
617 wm_hints.flags = StateHint | WindowGroupHint;
618 wm_hints.window_group = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
619 wm_hints.input = True;
620 wm_hints.initial_state = NormalState;
622 /* FIXME: Is there any point in doing this? Do any WM's pay
623 * attention to PSize, and even if they do, is this the
626 XSetWMNormalHints (xdisplay, xid, &size_hints);
628 XSetWMHints (xdisplay, xid, &wm_hints);
630 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
631 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
634 XChangeProperty (xdisplay, xid,
635 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
640 XChangeProperty (xdisplay, xid,
641 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
642 XA_WINDOW, 32, PropModeReplace,
643 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
645 if (attributes_mask & GDK_WA_TITLE)
646 title = attributes->title;
648 title = g_get_prgname ();
650 gdk_window_set_title (window, title);
652 if (attributes_mask & GDK_WA_WMCLASS)
654 class_hint = XAllocClassHint ();
655 class_hint->res_name = attributes->wmclass_name;
656 class_hint->res_class = attributes->wmclass_class;
657 XSetClassHint (xdisplay, xid, class_hint);
665 x_event_mask_to_gdk_event_mask (long mask)
667 GdkEventMask event_mask = 0;
670 for (i = 0; i < _gdk_nenvent_masks; i++)
672 if (mask & _gdk_event_mask_table[i])
673 event_mask |= 1 << (i + 1);
680 * gdk_window_foreign_new_for_display:
681 * @display: the #GdkDisplay where the window handle comes from.
682 * @anid: a native window handle.
684 * Wraps a native window in a #GdkWindow.
685 * This may fail if the window has been destroyed.
687 * For example in the X backend, a native window handle is an Xlib
690 * Return value: the newly-created #GdkWindow wrapper for the
691 * native window or %NULL if the window has been destroyed.
694 gdk_window_foreign_new_for_display (GdkDisplay *display,
695 GdkNativeWindow anid)
698 GdkWindowObject *private;
699 GdkWindowImplX11 *impl;
700 GdkDrawableImplX11 *draw_impl;
701 GdkDisplayX11 *display_x11;
702 XWindowAttributes attrs;
704 Window *children = NULL;
708 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
710 display_x11 = GDK_DISPLAY_X11 (display);
712 gdk_error_trap_push ();
713 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
714 if (gdk_error_trap_pop () || !result)
717 /* FIXME: This is pretty expensive. Maybe the caller should supply
719 gdk_error_trap_push ();
720 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
721 if (gdk_error_trap_pop () || !result)
727 window = g_object_new (GDK_TYPE_WINDOW, NULL);
728 private = (GdkWindowObject *)window;
729 impl = GDK_WINDOW_IMPL_X11 (private->impl);
730 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
731 draw_impl->wrapper = GDK_DRAWABLE (window);
732 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
734 private->parent = gdk_xid_table_lookup_for_display (display, parent);
736 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
737 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
739 private->parent->children = g_list_prepend (private->parent->children, window);
741 draw_impl->xid = anid;
743 private->x = attrs.x;
744 private->y = attrs.y;
745 impl->width = attrs.width;
746 impl->height = attrs.height;
747 private->window_type = GDK_WINDOW_FOREIGN;
748 private->destroyed = FALSE;
750 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
752 if (attrs.map_state == IsUnmapped)
753 private->state = GDK_WINDOW_STATE_WITHDRAWN;
757 private->depth = attrs.depth;
759 _gdk_window_init_position (GDK_WINDOW (private));
761 gdk_drawable_ref (window);
762 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
767 * gdk_window_foreign_new:
768 * @anid: a native window handle.
770 * Wraps a native window for the default display in a #GdkWindow.
771 * This may fail if the window has been destroyed.
773 * For example in the X backend, a native window handle is an Xlib
776 * Return value: the newly-created #GdkWindow wrapper for the
777 * native window or %NULL if the window has been destroyed.
780 gdk_window_foreign_new (GdkNativeWindow anid)
782 return gdk_window_foreign_new_for_display (gdk_get_default_display (), anid);
786 * gdk_window_lookup_for_display:
787 * @display: the #GdkDisplay corresponding to the window handle
788 * @anid: a native window handle.
790 * Looks up the #GdkWindow that wraps the given native window handle.
792 * For example in the X backend, a native window handle is an Xlib
795 * Return value: the #GdkWindow wrapper for the native window,
796 * or %NULL if there is none.
799 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
801 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
806 * @anid: a native window handle.
808 * Looks up the #GdkWindow that wraps the given native window handle.
810 * For example in the X backend, a native window handle is an Xlib
813 * Return value: the #GdkWindow wrapper for the native window,
814 * or %NULL if there is none.
817 gdk_window_lookup (GdkNativeWindow anid)
819 return (GdkWindow*) gdk_xid_table_lookup (anid);
823 _gdk_windowing_window_destroy (GdkWindow *window,
825 gboolean foreign_destroy)
827 GdkWindowObject *private = (GdkWindowObject *)window;
829 g_return_if_fail (GDK_IS_WINDOW (window));
831 _gdk_selection_window_destroyed (window);
833 if (private->extension_events != 0)
834 gdk_input_window_destroy (window);
838 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
840 if (draw_impl->picture)
841 XRenderFreePicture (GDK_WINDOW_XDISPLAY (window), draw_impl->picture);
843 #endif /* HAVE_XFT */
845 if (private->window_type == GDK_WINDOW_FOREIGN)
847 if (!foreign_destroy && (private->parent != NULL))
849 /* It's somebody else's window, but in our heirarchy,
850 * so reparent it to the root window, and then send
851 * it a delete event, as if we were a WM
853 XClientMessageEvent xevent;
855 gdk_error_trap_push ();
856 gdk_window_hide (window);
857 gdk_window_reparent (window, NULL, 0, 0);
859 xevent.type = ClientMessage;
860 xevent.window = GDK_WINDOW_XID (window);
861 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
864 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
866 xevent.data.l[1] = CurrentTime;
868 XSendEvent (GDK_WINDOW_XDISPLAY (window),
869 GDK_WINDOW_XID (window),
870 False, 0, (XEvent *)&xevent);
871 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
872 gdk_error_trap_pop ();
875 else if (!recursing && !foreign_destroy)
877 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
881 /* This function is called when the XWindow is really gone.
884 gdk_window_destroy_notify (GdkWindow *window)
886 GdkWindowImplX11 *window_impl;
888 g_return_if_fail (window != NULL);
890 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
892 if (!GDK_WINDOW_DESTROYED (window))
894 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
895 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
897 _gdk_window_destroy (window, TRUE);
900 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
901 if (window_impl->focus_window)
902 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->focus_window);
904 _gdk_xgrab_check_destroy (window);
906 gdk_drawable_unref (window);
910 set_initial_hints (GdkWindow *window)
912 GdkWindowObject *private;
916 private = (GdkWindowObject*) window;
918 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
922 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
923 GDK_WINDOW_XID (window));
925 wm_hints = XAllocWMHints ();
927 wm_hints->flags |= StateHint;
928 wm_hints->initial_state = IconicState;
930 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
931 GDK_WINDOW_XID (window), wm_hints);
935 /* We set the spec hints regardless of whether the spec is supported,
936 * since it can't hurt and it's kind of expensive to check whether
942 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
944 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
945 "_NET_WM_STATE_MAXIMIZED_VERT");
947 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
948 "_NET_WM_STATE_MAXIMIZED_HORZ");
952 if (private->state & GDK_WINDOW_STATE_STICKY)
954 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
955 "_NET_WM_STATE_STICKY");
959 if (private->modal_hint)
961 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
962 "_NET_WM_STATE_MODAL");
968 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
969 GDK_WINDOW_XID (window),
970 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_STATE"),
971 XA_ATOM, 32, PropModeReplace,
975 if (private->state & GDK_WINDOW_STATE_STICKY)
977 atoms[0] = 0xFFFFFFFF;
978 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
979 GDK_WINDOW_XID (window),
980 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_DESKTOP"),
981 XA_CARDINAL, 32, PropModeReplace,
987 show_window_internal (GdkWindow *window,
990 GdkWindowObject *private;
992 g_return_if_fail (GDK_IS_WINDOW (window));
994 private = (GdkWindowObject*) window;
995 if (!private->destroyed)
998 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
999 GDK_WINDOW_XID (window));
1001 if (!GDK_WINDOW_IS_MAPPED (window))
1003 set_initial_hints (window);
1005 gdk_synthesize_window_state (window,
1006 GDK_WINDOW_STATE_WITHDRAWN,
1010 g_assert (GDK_WINDOW_IS_MAPPED (window));
1012 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
1013 XMapWindow (GDK_WINDOW_XDISPLAY (window),
1014 GDK_WINDOW_XID (window));
1019 * gdk_window_show_unraised:
1020 * @window: a #GdkWindow
1022 * Shows a #GdkWindow onscreen, but does not modify its stacking
1023 * order. In contrast, gdk_window_show() will raise the window
1024 * to the top of the window stack.
1026 * On the X11 platform, in Xlib terms, this function calls
1027 * XMapWindow() (it also updates some internal GDK state, which means
1028 * that you can't really use XMapWindow() directly on a GDK window).
1032 gdk_window_show_unraised (GdkWindow *window)
1034 g_return_if_fail (GDK_IS_WINDOW (window));
1036 show_window_internal (window, FALSE);
1041 * @window: a #GdkWindow
1043 * Like gdk_window_show_unraised(), but also raises the window to the
1044 * top of the window stack (moves the window to the front of the
1047 * This function maps a window so it's visible onscreen. Its opposite
1048 * is gdk_window_hide().
1050 * When implementing a #GtkWidget, you should call this function on the widget's
1051 * #GdkWindow as part of the "map" method.
1055 gdk_window_show (GdkWindow *window)
1057 g_return_if_fail (GDK_IS_WINDOW (window));
1059 show_window_internal (window, TRUE);
1064 * @window: a #GdkWindow
1066 * For toplevel windows, withdraws them, so they will no longer be
1067 * known to the window manager; for all windows, unmaps them, so
1068 * they won't be displayed. Normally done automatically as
1069 * part of gtk_widget_hide().
1073 gdk_window_hide (GdkWindow *window)
1075 GdkWindowObject *private;
1077 g_return_if_fail (window != NULL);
1079 private = (GdkWindowObject*) window;
1081 /* We'll get the unmap notify eventually, and handle it then,
1082 * but checking here makes things more consistent if we are
1083 * just doing stuff ourself.
1085 _gdk_xgrab_check_unmap (window,
1086 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1088 /* You can't simply unmap toplevel windows. */
1089 switch (private->window_type)
1091 case GDK_WINDOW_TOPLEVEL:
1092 case GDK_WINDOW_DIALOG:
1093 case GDK_WINDOW_TEMP: /* ? */
1094 gdk_window_withdraw (window);
1098 case GDK_WINDOW_FOREIGN:
1099 case GDK_WINDOW_ROOT:
1100 case GDK_WINDOW_CHILD:
1104 if (!private->destroyed)
1106 if (GDK_WINDOW_IS_MAPPED (window))
1107 gdk_synthesize_window_state (window,
1109 GDK_WINDOW_STATE_WITHDRAWN);
1111 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1113 _gdk_window_clear_update_area (window);
1115 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1116 GDK_WINDOW_XID (window));
1121 * gdk_window_withdraw:
1122 * @window: a toplevel #GdkWindow
1124 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1125 * Normally done automatically by gtk_widget_hide() called on a #GtkWindow.
1129 gdk_window_withdraw (GdkWindow *window)
1131 GdkWindowObject *private;
1133 g_return_if_fail (window != NULL);
1135 private = (GdkWindowObject*) window;
1136 if (!private->destroyed)
1138 if (GDK_WINDOW_IS_MAPPED (window))
1139 gdk_synthesize_window_state (window,
1141 GDK_WINDOW_STATE_WITHDRAWN);
1143 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1145 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1146 GDK_WINDOW_XID (window), 0);
1152 * @window: a #GdkWindow
1153 * @x: X coordinate relative to window's parent
1154 * @y: Y coordinate relative to window's parent
1156 * Repositions a window relative to its parent window.
1157 * For toplevel windows, window managers may ignore or modify the move;
1158 * you should probably use gtk_window_move() on a #GtkWindow widget
1159 * anyway, instead of using GDK functions. For child windows,
1160 * the move will reliably succeed.
1162 * If you're also planning to resize the window, use gdk_window_move_resize()
1163 * to both move and resize simultaneously, for a nicer visual effect.
1167 gdk_window_move (GdkWindow *window,
1171 GdkWindowObject *private = (GdkWindowObject *)window;
1172 GdkWindowImplX11 *impl;
1174 g_return_if_fail (window != NULL);
1175 g_return_if_fail (GDK_IS_WINDOW (window));
1177 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1179 if (!GDK_WINDOW_DESTROYED (window))
1181 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1182 _gdk_window_move_resize_child (window, x, y,
1183 impl->width, impl->height);
1186 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1187 GDK_WINDOW_XID (window),
1194 * gdk_window_resize:
1195 * @window: a #GdkWindow
1196 * @width: new width of the window
1197 * @height: new height of the window
1199 * Resizes @window; for toplevel windows, asks the window manager to resize
1200 * the window. The window manager may not allow the resize. When using GTK+,
1201 * use gtk_window_resize() instead of this low-level GDK function.
1203 * Windows may not be resized below 1x1.
1205 * If you're also planning to move the window, use gdk_window_move_resize()
1206 * to both move and resize simultaneously, for a nicer visual effect.
1210 gdk_window_resize (GdkWindow *window,
1214 GdkWindowObject *private;
1216 g_return_if_fail (window != NULL);
1217 g_return_if_fail (GDK_IS_WINDOW (window));
1224 private = (GdkWindowObject*) window;
1226 if (!GDK_WINDOW_DESTROYED (window))
1228 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1229 _gdk_window_move_resize_child (window, private->x, private->y,
1233 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1235 if (width != impl->width || height != impl->height)
1236 private->resize_count += 1;
1238 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1239 GDK_WINDOW_XID (window),
1246 * gdk_window_move_resize:
1247 * @window: a #GdkWindow
1248 * @x: new X position relative to window's parent
1249 * @y: new Y position relative to window's parent
1251 * @height: new height
1253 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1254 * except that both operations are performed at once, avoiding strange
1255 * visual effects. (i.e. the user may be able to see the window first
1256 * move, then resize, if you don't use gdk_window_move_resize().)
1260 gdk_window_move_resize (GdkWindow *window,
1266 GdkWindowObject *private;
1268 g_return_if_fail (window != NULL);
1269 g_return_if_fail (GDK_IS_WINDOW (window));
1276 private = (GdkWindowObject*) window;
1278 if (!GDK_WINDOW_DESTROYED (window))
1280 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1281 _gdk_window_move_resize_child (window, x, y, width, height);
1284 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1286 if (width != impl->width || height != impl->height)
1287 private->resize_count += 1;
1289 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1290 GDK_WINDOW_XID (window),
1291 x, y, width, height);
1297 * gdk_window_reparent:
1298 * @window: a #GdkWindow
1299 * @new_parent: new parent to move @window into
1300 * @x: X location inside the new parent
1301 * @y: Y location inside the new parent
1303 * Reparents @window into the given @new_parent. The window being
1304 * reparented will be unmapped as a side effect.
1308 gdk_window_reparent (GdkWindow *window,
1309 GdkWindow *new_parent,
1313 GdkDisplay *display;
1314 GdkWindowObject *window_private;
1315 GdkWindowObject *parent_private;
1316 GdkWindowObject *old_parent_private;
1318 g_return_if_fail (window != NULL);
1319 g_return_if_fail (GDK_IS_WINDOW (window));
1320 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1321 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1324 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1326 display = GDK_WINDOW_DISPLAY (window);
1328 window_private = (GdkWindowObject*) window;
1329 old_parent_private = (GdkWindowObject*)window_private->parent;
1330 parent_private = (GdkWindowObject*) new_parent;
1332 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1333 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1334 GDK_WINDOW_XID (window),
1335 GDK_WINDOW_XID (new_parent),
1338 window_private->x = x;
1339 window_private->y = y;
1341 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1344 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1345 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1347 window_private->parent = (GdkWindowObject *)new_parent;
1349 /* Switch the window type as appropriate */
1351 switch (GDK_WINDOW_TYPE (new_parent))
1353 case GDK_WINDOW_ROOT:
1354 case GDK_WINDOW_FOREIGN:
1355 /* Now a toplevel */
1356 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1357 set_wm_protocols (window);
1359 case GDK_WINDOW_TOPLEVEL:
1360 case GDK_WINDOW_CHILD:
1361 case GDK_WINDOW_DIALOG:
1362 case GDK_WINDOW_TEMP:
1363 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1364 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1366 /* If we were being sophisticated, we'd save the old window type
1367 * here, and restore it if we were reparented back to the
1368 * toplevel. However, the difference between different types
1369 * of toplevels only really matters on creation anyways.
1371 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1375 if (old_parent_private)
1376 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1378 if ((old_parent_private &&
1379 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1380 (!old_parent_private && parent_private->guffaw_gravity))
1381 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1383 parent_private->children = g_list_prepend (parent_private->children, window);
1384 _gdk_window_init_position (GDK_WINDOW (window_private));
1388 _gdk_windowing_window_clear_area (GdkWindow *window,
1394 g_return_if_fail (window != NULL);
1395 g_return_if_fail (GDK_IS_WINDOW (window));
1397 if (!GDK_WINDOW_DESTROYED (window))
1398 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1399 x, y, width, height, False);
1403 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1409 g_return_if_fail (window != NULL);
1410 g_return_if_fail (GDK_IS_WINDOW (window));
1412 if (!GDK_WINDOW_DESTROYED (window))
1413 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1414 x, y, width, height, True);
1420 * @window: a #GdkWindow
1422 * Raises @window to the top of the Z-order (stacking order), so that
1423 * other windows with the same parent window appear below @window.
1424 * If @window is a toplevel, the window manager may choose to deny the
1425 * request to move the window in the Z-order, gdk_window_raise() only
1426 * requests the restack, does not guarantee it.
1430 gdk_window_raise (GdkWindow *window)
1432 g_return_if_fail (window != NULL);
1433 g_return_if_fail (GDK_IS_WINDOW (window));
1435 if (!GDK_WINDOW_DESTROYED (window))
1436 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1441 * @window: a #GdkWindow
1443 * Lowers @window to the bottom of the Z-order (stacking order), so that
1444 * other windows with the same parent window appear above @window.
1445 * If @window is a toplevel, the window manager may choose to deny the
1446 * request to move the window in the Z-order, gdk_window_lower() only
1447 * requests the restack, does not guarantee it.
1449 * Note that gdk_window_show() raises the window again, so don't call this
1450 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1454 gdk_window_lower (GdkWindow *window)
1456 g_return_if_fail (window != NULL);
1457 g_return_if_fail (GDK_IS_WINDOW (window));
1459 if (!GDK_WINDOW_DESTROYED (window))
1460 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1465 * @window: a #GdkWindow
1466 * @timestamp: timestamp of the event triggering the window focus
1468 * Sets keyboard focus to @window. If @window is not onscreen this
1469 * will not work. In most cases, gtk_window_present() should be used on
1470 * a #GtkWindow, rather than calling this function.
1474 gdk_window_focus (GdkWindow *window,
1477 g_return_if_fail (GDK_IS_WINDOW (window));
1479 if (GDK_WINDOW_DESTROYED (window))
1482 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1483 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1487 xev.xclient.type = ClientMessage;
1488 xev.xclient.serial = 0;
1489 xev.xclient.send_event = True;
1490 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1491 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1492 "_NET_ACTIVE_WINDOW");
1493 xev.xclient.format = 32;
1494 xev.xclient.data.l[0] = 0;
1496 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1497 SubstructureRedirectMask | SubstructureNotifyMask,
1502 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1504 /* There is no way of knowing reliably whether we are viewable so we need
1505 * to trap errors so we don't cause a BadMatch.
1507 gdk_error_trap_push ();
1508 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1509 GDK_WINDOW_XWINDOW (window),
1512 XSync (GDK_WINDOW_XDISPLAY (window), False);
1513 gdk_error_trap_pop ();
1518 * gdk_window_set_hints:
1519 * @window: a #GdkWindow
1520 * @x: ignored field, does not matter
1521 * @y: ignored field, does not matter
1522 * @min_width: minimum width hint
1523 * @min_height: minimum height hint
1524 * @max_width: max width hint
1525 * @max_height: max height hint
1526 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1528 * This function is broken and useless and you should ignore it.
1529 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1530 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1531 * depending on what you're trying to do.
1533 * If using GDK directly, use gdk_window_set_geometry_hints().
1537 gdk_window_set_hints (GdkWindow *window,
1546 XSizeHints size_hints;
1548 g_return_if_fail (window != NULL);
1549 g_return_if_fail (GDK_IS_WINDOW (window));
1551 if (GDK_WINDOW_DESTROYED (window))
1554 size_hints.flags = 0;
1556 if (flags & GDK_HINT_POS)
1558 size_hints.flags |= PPosition;
1563 if (flags & GDK_HINT_MIN_SIZE)
1565 size_hints.flags |= PMinSize;
1566 size_hints.min_width = min_width;
1567 size_hints.min_height = min_height;
1570 if (flags & GDK_HINT_MAX_SIZE)
1572 size_hints.flags |= PMaxSize;
1573 size_hints.max_width = max_width;
1574 size_hints.max_height = max_height;
1577 /* FIXME: Would it be better to delete this property if
1578 * flags == 0? It would save space on the server
1580 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1581 GDK_WINDOW_XID (window),
1586 * gdk_window_set_type_hint:
1587 * @window: A #GdkWindow
1588 * @hint: A hint of the function this window will have
1590 * The application can use this call to provide a hint to the window
1591 * manager about the functionality of a window. The window manager
1592 * can use this information when determining the decoration and behaviour
1595 * The hint must be set before the window is mapped.
1598 gdk_window_set_type_hint (GdkWindow *window,
1599 GdkWindowTypeHint hint)
1601 GdkDisplay *display;
1604 g_return_if_fail (window != NULL);
1605 g_return_if_fail (GDK_IS_WINDOW (window));
1607 if (GDK_WINDOW_DESTROYED (window))
1610 display = gdk_drawable_get_display (window);
1614 case GDK_WINDOW_TYPE_HINT_DIALOG:
1615 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1617 case GDK_WINDOW_TYPE_HINT_MENU:
1618 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1620 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1621 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1624 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1626 case GDK_WINDOW_TYPE_HINT_NORMAL:
1627 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1631 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1632 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1633 XA_ATOM, 32, PropModeReplace,
1634 (guchar *)&atom, 1);
1639 gdk_wmspec_change_state (gboolean add,
1644 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1647 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1648 #define _NET_WM_STATE_ADD 1 /* add/set property */
1649 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1651 xev.xclient.type = ClientMessage;
1652 xev.xclient.serial = 0;
1653 xev.xclient.send_event = True;
1654 xev.xclient.window = GDK_WINDOW_XID (window);
1655 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1656 xev.xclient.format = 32;
1657 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1658 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1659 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1661 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1662 SubstructureRedirectMask | SubstructureNotifyMask,
1667 * gdk_window_set_modal_hint:
1668 * @window: A #GdkWindow
1669 * @modal: TRUE if the window is modal, FALSE otherwise.
1671 * The application can use this hint to tell the window manager
1672 * that a certain window has modal behaviour. The window manager
1673 * can use this information to handle modal windows in a special
1676 * You should only use this on windows for which you have
1677 * previously called #gdk_window_set_transient_for()
1680 gdk_window_set_modal_hint (GdkWindow *window,
1683 GdkWindowObject *private;
1685 g_return_if_fail (window != NULL);
1686 g_return_if_fail (GDK_IS_WINDOW (window));
1688 if (GDK_WINDOW_DESTROYED (window))
1691 private = (GdkWindowObject*) window;
1693 private->modal_hint = modal;
1695 if (GDK_WINDOW_IS_MAPPED (window))
1696 gdk_wmspec_change_state (modal, window,
1697 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1702 * gdk_window_set_geometry_hints:
1703 * @window: a #GdkWindow
1704 * @geometry: geometry hints
1705 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1707 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1708 * are set, hints not flagged in @geom_mask are unset.
1709 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1713 gdk_window_set_geometry_hints (GdkWindow *window,
1714 GdkGeometry *geometry,
1715 GdkWindowHints geom_mask)
1717 XSizeHints size_hints;
1719 g_return_if_fail (window != NULL);
1720 g_return_if_fail (GDK_IS_WINDOW (window));
1722 if (GDK_WINDOW_DESTROYED (window))
1725 size_hints.flags = 0;
1727 if (geom_mask & GDK_HINT_POS)
1729 size_hints.flags |= PPosition;
1730 /* We need to initialize the following obsolete fields because KWM
1731 * apparently uses these fields if they are non-zero.
1738 if (geom_mask & GDK_HINT_USER_POS)
1740 size_hints.flags |= USPosition;
1743 if (geom_mask & GDK_HINT_USER_SIZE)
1745 size_hints.flags |= USSize;
1748 if (geom_mask & GDK_HINT_MIN_SIZE)
1750 size_hints.flags |= PMinSize;
1751 size_hints.min_width = geometry->min_width;
1752 size_hints.min_height = geometry->min_height;
1755 if (geom_mask & GDK_HINT_MAX_SIZE)
1757 size_hints.flags |= PMaxSize;
1758 size_hints.max_width = MAX (geometry->max_width, 1);
1759 size_hints.max_height = MAX (geometry->max_height, 1);
1762 if (geom_mask & GDK_HINT_BASE_SIZE)
1764 size_hints.flags |= PBaseSize;
1765 size_hints.base_width = geometry->base_width;
1766 size_hints.base_height = geometry->base_height;
1769 if (geom_mask & GDK_HINT_RESIZE_INC)
1771 size_hints.flags |= PResizeInc;
1772 size_hints.width_inc = geometry->width_inc;
1773 size_hints.height_inc = geometry->height_inc;
1776 if (geom_mask & GDK_HINT_ASPECT)
1778 size_hints.flags |= PAspect;
1779 if (geometry->min_aspect <= 1)
1781 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1782 size_hints.min_aspect.y = 65536;
1786 size_hints.min_aspect.x = 65536;
1787 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1789 if (geometry->max_aspect <= 1)
1791 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1792 size_hints.max_aspect.y = 65536;
1796 size_hints.max_aspect.x = 65536;
1797 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1801 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1803 size_hints.flags |= PWinGravity;
1804 size_hints.win_gravity = geometry->win_gravity;
1807 /* FIXME: Would it be better to delete this property if
1808 * geom_mask == 0? It would save space on the server
1810 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1811 GDK_WINDOW_XID (window),
1816 gdk_window_get_geometry_hints (GdkWindow *window,
1817 GdkGeometry *geometry,
1818 GdkWindowHints *geom_mask)
1820 XSizeHints size_hints;
1821 glong junk_size_mask = 0;
1823 g_return_if_fail (GDK_IS_WINDOW (window));
1824 g_return_if_fail (geometry != NULL);
1825 g_return_if_fail (geom_mask != NULL);
1829 if (GDK_WINDOW_DESTROYED (window))
1832 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1833 GDK_WINDOW_XID (window),
1838 if (size_hints.flags & PMinSize)
1840 *geom_mask |= GDK_HINT_MIN_SIZE;
1841 geometry->min_width = size_hints.min_width;
1842 geometry->min_height = size_hints.min_height;
1845 if (size_hints.flags & PMaxSize)
1847 *geom_mask |= GDK_HINT_MAX_SIZE;
1848 geometry->max_width = MAX (size_hints.max_width, 1);
1849 geometry->max_height = MAX (size_hints.max_height, 1);
1852 if (size_hints.flags & PResizeInc)
1854 *geom_mask |= GDK_HINT_RESIZE_INC;
1855 geometry->width_inc = size_hints.width_inc;
1856 geometry->height_inc = size_hints.height_inc;
1859 if (size_hints.flags & PAspect)
1861 *geom_mask |= GDK_HINT_ASPECT;
1863 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1864 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1867 if (size_hints.flags & PWinGravity)
1869 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1870 geometry->win_gravity = size_hints.win_gravity;
1875 utf8_is_latin1 (const gchar *str)
1877 const char *p = str;
1881 gunichar ch = g_utf8_get_char (p);
1886 p = g_utf8_next_char (p);
1892 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
1893 * convertable to STRING, otherwise, set it as compound text
1896 set_text_property (GdkWindow *window,
1898 const gchar *utf8_str)
1900 guchar *prop_text = NULL;
1905 if (utf8_is_latin1 (utf8_str))
1907 prop_type = XA_STRING;
1908 prop_text = gdk_utf8_to_string_target (utf8_str);
1909 prop_length = prop_text ? strlen (prop_text) : 0;
1916 gdk_utf8_to_compound_text_for_display (gdk_drawable_get_display (window),
1917 utf8_str, &gdk_type, &prop_format,
1918 &prop_text, &prop_length);
1919 prop_type = gdk_x11_atom_to_xatom_for_display
1920 (GDK_WINDOW_DISPLAY (window), gdk_type);
1925 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1926 GDK_WINDOW_XID (window),
1928 prop_type, prop_format,
1929 PropModeReplace, prop_text,
1937 * gdk_window_set_title:
1938 * @window: a #GdkWindow
1939 * @title: title of @window
1941 * Sets the title of a toplevel window, to be displayed in the titlebar.
1942 * If you haven't explicitly set the icon name for the window
1943 * (using gdk_window_set_icon_name()), the icon name will be set to
1944 * @title as well. @title must be in UTF-8 encoding (as with all
1945 * user-readable strings in GDK/GTK+). @title may not be %NULL.
1948 gdk_window_set_title (GdkWindow *window,
1951 GdkDisplay *display;
1953 g_return_if_fail (window != NULL);
1954 g_return_if_fail (GDK_IS_WINDOW (window));
1955 g_return_if_fail (title != NULL);
1957 if (GDK_WINDOW_DESTROYED (window))
1960 display = gdk_drawable_get_display (window);
1962 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1963 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
1964 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
1965 PropModeReplace, title, strlen (title));
1967 set_text_property (window,
1968 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
1971 if (!gdk_window_icon_name_set (window))
1973 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1974 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
1975 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
1976 PropModeReplace, title, strlen (title));
1978 set_text_property (window,
1979 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
1985 * gdk_window_set_role:
1986 * @window: a #GdkWindow
1987 * @role: a string indicating its role
1989 * When using GTK+, typically you should use gtk_window_set_role() instead
1990 * of this low-level function.
1992 * The window manager and session manager use a window's role to
1993 * distinguish it from other kinds of window in the same application.
1994 * When an application is restarted after being saved in a previous
1995 * session, all windows with the same title and role are treated as
1996 * interchangeable. So if you have two windows with the same title
1997 * that should be distinguished for session management purposes, you
1998 * should set the role on those windows. It doesn't matter what string
1999 * you use for the role, as long as you have a different role for each
2000 * non-interchangeable kind of window.
2004 gdk_window_set_role (GdkWindow *window,
2007 GdkDisplay *display;
2009 g_return_if_fail (window != NULL);
2010 g_return_if_fail (GDK_IS_WINDOW (window));
2012 display = gdk_drawable_get_display (window);
2014 if (!GDK_WINDOW_DESTROYED (window))
2017 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2018 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2019 XA_STRING, 8, PropModeReplace, role, strlen (role));
2021 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2022 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2027 * gdk_window_set_transient_for:
2028 * @window: a toplevel #GdkWindow
2029 * @parent: another toplevel #GdkWindow
2031 * Indicates to the window manager that @window is a transient dialog
2032 * associated with the application window @parent. This allows the
2033 * window manager to do things like center @window on @parent and
2034 * keep @window above @parent.
2036 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2041 gdk_window_set_transient_for (GdkWindow *window,
2044 GdkWindowObject *private;
2045 GdkWindowObject *parent_private;
2047 g_return_if_fail (window != NULL);
2048 g_return_if_fail (GDK_IS_WINDOW (window));
2050 private = (GdkWindowObject*) window;
2051 parent_private = (GdkWindowObject*) parent;
2053 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2054 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2055 GDK_WINDOW_XID (window),
2056 GDK_WINDOW_XID (parent));
2060 * gdk_window_set_background:
2061 * @window: a #GdkWindow
2062 * @color: an allocated #GdkColor
2064 * Sets the background color of @window. (However, when using GTK+,
2065 * set the background of a widget with gtk_widget_modify_bg() - if
2066 * you're an application - or gtk_style_set_background() - if you're
2067 * implementing a custom widget.)
2069 * The @color must be allocated; gdk_rgb_find_color() is the best way
2070 * to allocate a color.
2072 * See also gdk_window_set_back_pixmap().
2076 gdk_window_set_background (GdkWindow *window,
2079 GdkWindowObject *private = (GdkWindowObject *)window;
2081 g_return_if_fail (window != NULL);
2082 g_return_if_fail (GDK_IS_WINDOW (window));
2084 if (!GDK_WINDOW_DESTROYED (window))
2085 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2086 GDK_WINDOW_XID (window), color->pixel);
2088 private->bg_color = *color;
2090 if (private->bg_pixmap &&
2091 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2092 private->bg_pixmap != GDK_NO_BG)
2093 gdk_pixmap_unref (private->bg_pixmap);
2095 private->bg_pixmap = NULL;
2099 * gdk_window_set_back_pixmap:
2100 * @window: a #GdkWindow
2101 * @pixmap: a #GdkPixmap, or %NULL
2102 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2104 * Sets the background pixmap of @window. May also be used to set a background of
2105 * "None" on @window, by setting a background pixmap of %NULL.
2106 * A background pixmap will be tiled, positioning the first tile at the origin of
2107 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2108 * origin of the parent window (useful to align tiles in a parent with tiles
2111 * A background pixmap of %NULL means that the window will have no
2112 * background. A window with no background will never have its
2113 * background filled by the windowing system, instead the window will
2114 * contain whatever pixels were already in the corresponding area of
2117 * The windowing system will normally fill a window with its background
2118 * when the window is obscured then exposed, and when you call
2119 * gdk_window_clear().
2123 gdk_window_set_back_pixmap (GdkWindow *window,
2125 gboolean parent_relative)
2127 GdkWindowObject *private = (GdkWindowObject *)window;
2130 g_return_if_fail (window != NULL);
2131 g_return_if_fail (GDK_IS_WINDOW (window));
2132 g_return_if_fail (pixmap == NULL || !parent_relative);
2134 if (private->bg_pixmap &&
2135 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2136 private->bg_pixmap != GDK_NO_BG)
2137 gdk_pixmap_unref (private->bg_pixmap);
2139 if (parent_relative)
2141 xpixmap = ParentRelative;
2142 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2148 gdk_pixmap_ref (pixmap);
2149 private->bg_pixmap = pixmap;
2150 xpixmap = GDK_PIXMAP_XID (pixmap);
2155 private->bg_pixmap = GDK_NO_BG;
2159 if (!GDK_WINDOW_DESTROYED (window))
2160 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2161 GDK_WINDOW_XID (window), xpixmap);
2165 * gdk_window_set_cursor:
2166 * @window: a #GdkWindow
2169 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2170 * gdk_cursor_new_from_pixmap() to create the cursor.
2171 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2172 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2173 * to gdk_window_set_cursor() means that @window will use the cursor of
2174 * its parent window. Most windows should use this default.
2178 gdk_window_set_cursor (GdkWindow *window,
2181 GdkCursorPrivate *cursor_private;
2184 g_return_if_fail (window != NULL);
2185 g_return_if_fail (GDK_IS_WINDOW (window));
2187 cursor_private = (GdkCursorPrivate*) cursor;
2192 xcursor = cursor_private->xcursor;
2194 if (!GDK_WINDOW_DESTROYED (window))
2195 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2196 GDK_WINDOW_XID (window),
2201 * gdk_window_get_geometry:
2202 * @window: a #GdkWindow
2203 * @x: return location for X coordinate of window (relative to its parent)
2204 * @y: return location for Y coordinate of window (relative to its parent)
2205 * @width: return location for width of window
2206 * @height: return location for height of window
2207 * @depth: return location for bit depth of window
2209 * Any of the return location arguments to this function may be %NULL,
2210 * if you aren't interested in getting the value of that field.
2212 * The X and Y coordinates returned are relative to the parent window
2213 * of @window, which for toplevels usually means relative to the
2214 * window decorations (titlebar, etc.) rather than relative to the
2215 * root window (screen-size background window).
2217 * On the X11 platform, the geometry is obtained from the X server,
2218 * so reflects the latest position of @window; this may be out-of-sync
2219 * with the position of @window delivered in the most-recently-processed
2220 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2221 * position from the most recent configure event.
2225 gdk_window_get_geometry (GdkWindow *window,
2237 guint tborder_width;
2240 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2244 GDK_NOTE (MULTIHEAD,
2245 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2246 window = gdk_screen_get_root_window ((gdk_get_default_screen ()));
2249 if (!GDK_WINDOW_DESTROYED (window))
2251 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2252 GDK_WINDOW_XID (window),
2253 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2269 * gdk_window_get_origin:
2270 * @window: a #GdkWindow
2271 * @x: return location for X coordinate
2272 * @y: return location for Y coordinate
2274 * Obtains the position of a window in root window coordinates.
2275 * (Compare with gdk_window_get_position() and
2276 * gdk_window_get_geometry() which return the position of a window
2277 * relative to its parent window.)
2279 * Return value: not meaningful, ignore
2282 gdk_window_get_origin (GdkWindow *window,
2291 g_return_val_if_fail (window != NULL, 0);
2293 if (!GDK_WINDOW_DESTROYED (window))
2295 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2296 GDK_WINDOW_XID (window),
2297 GDK_WINDOW_XROOTWIN (window),
2313 * gdk_window_get_deskrelative_origin:
2314 * @window: a #GdkWindow
2315 * @x: return location for X coordinate
2316 * @y: return location for Y coordinate
2318 * This gets the origin of a #GdkWindow relative to
2319 * an Enlightenment-window-manager desktop. As long as you don't
2320 * assume that the user's desktop/workspace covers the entire
2321 * root window (i.e. you don't assume that the desktop begins
2322 * at root window coordinate 0,0) this function is not necessary.
2323 * It's deprecated for that reason.
2325 * Return value: not meaningful
2328 gdk_window_get_deskrelative_origin (GdkWindow *window,
2332 gboolean return_val = FALSE;
2333 gint num_children, format_return;
2334 Window win, *child, parent, root;
2339 gulong number_return, bytes_after_return;
2340 guchar *data_return;
2342 g_return_val_if_fail (window != NULL, 0);
2343 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2345 if (!GDK_WINDOW_DESTROYED (window))
2347 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2348 "ENLIGHTENMENT_DESKTOP");
2349 win = GDK_WINDOW_XID (window);
2351 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2352 &child, (unsigned int *)&num_children))
2354 if ((child) && (num_children > 0))
2366 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2367 False, XA_CARDINAL, &type_return, &format_return,
2368 &number_return, &bytes_after_return, &data_return);
2370 if (type_return == XA_CARDINAL)
2372 XFree (data_return);
2377 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2378 GDK_WINDOW_XID (window),
2393 * gdk_window_get_root_origin:
2394 * @window: a #GdkWindow
2395 * @x: return location for X position of window frame
2396 * @y: return location for Y position of window frame
2398 * Obtains the top-left corner of the window manager frame in root
2399 * window coordinates.
2403 gdk_window_get_root_origin (GdkWindow *window,
2409 g_return_if_fail (GDK_IS_WINDOW (window));
2411 gdk_window_get_frame_extents (window, &rect);
2421 * gdk_window_get_frame_extents:
2422 * @window: a #GdkWindow
2423 * @rect: rectangle to fill with bounding box of the window frame
2425 * Obtains the bounding box of the window, including window manager
2426 * titlebar/borders if any. The frame position is given in root window
2427 * coordinates. To get the position of the window itself (rather than
2428 * the frame) in root window coordinates, use gdk_window_get_origin().
2432 gdk_window_get_frame_extents (GdkWindow *window,
2435 GdkWindowObject *private;
2440 unsigned int nchildren;
2442 g_return_if_fail (GDK_IS_WINDOW (window));
2443 g_return_if_fail (rect != NULL);
2445 private = (GdkWindowObject*) window;
2452 if (GDK_WINDOW_DESTROYED (window))
2455 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2456 private = (GdkWindowObject*) private->parent;
2457 if (GDK_WINDOW_DESTROYED (window))
2460 xparent = GDK_WINDOW_XID (window);
2464 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2466 &children, &nchildren))
2472 while (xparent != root);
2474 if (xparent == root)
2476 unsigned int ww, wh, wb, wd;
2479 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2490 _gdk_windowing_window_get_pointer (GdkWindow *window,
2493 GdkModifierType *mask)
2495 GdkWindow *return_val;
2501 unsigned int xmask = 0;
2502 gint xoffset, yoffset;
2504 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2508 GDK_NOTE (MULTIHEAD,
2509 g_message ("_gdk_windowing_window_get_pointer(): window arg is need for multihead safe operation"));
2510 window = gdk_screen_get_root_window (gdk_get_default_screen ());
2513 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2516 if (!GDK_WINDOW_DESTROYED (window) &&
2517 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2518 GDK_WINDOW_XID (window),
2519 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2522 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
2526 *x = winx + xoffset;
2528 *y = winy + yoffset;
2536 _gdk_windowing_window_at_pointer (GdkScreen *screen,
2540 return gdk_screen_get_window_at_pointer (screen, win_x, win_y);
2544 * gdk_window_get_events:
2545 * @window: a #GdkWindow
2547 * Gets the event mask for @window. See gdk_window_set_events().
2549 * Return value: event mask for @window
2552 gdk_window_get_events (GdkWindow *window)
2554 XWindowAttributes attrs;
2555 GdkEventMask event_mask;
2557 g_return_val_if_fail (window != NULL, 0);
2558 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2560 if (GDK_WINDOW_DESTROYED (window))
2564 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2565 GDK_WINDOW_XID (window),
2568 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2569 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2576 * gdk_window_set_events:
2577 * @window: a #GdkWindow
2578 * @event_mask: event mask for @window
2580 * The event mask for a window determines which events will be reported
2581 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2582 * means the window should report button press events. The event mask
2583 * is the bitwise OR of values from the #GdkEventMask enumeration.
2587 gdk_window_set_events (GdkWindow *window,
2588 GdkEventMask event_mask)
2593 g_return_if_fail (window != NULL);
2594 g_return_if_fail (GDK_IS_WINDOW (window));
2596 if (!GDK_WINDOW_DESTROYED (window))
2598 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2599 xevent_mask = StructureNotifyMask;
2600 for (i = 0; i < _gdk_nenvent_masks; i++)
2602 if (event_mask & (1 << (i + 1)))
2603 xevent_mask |= _gdk_event_mask_table[i];
2606 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2607 GDK_WINDOW_XID (window),
2613 gdk_window_add_colormap_windows (GdkWindow *window)
2615 GdkWindow *toplevel;
2616 Window *old_windows;
2617 Window *new_windows;
2620 g_return_if_fail (window != NULL);
2621 g_return_if_fail (GDK_IS_WINDOW (window));
2623 toplevel = gdk_window_get_toplevel (window);
2624 if (GDK_WINDOW_DESTROYED (toplevel))
2628 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2629 GDK_WINDOW_XID (toplevel),
2630 &old_windows, &count))
2635 for (i = 0; i < count; i++)
2636 if (old_windows[i] == GDK_WINDOW_XID (window))
2638 XFree (old_windows);
2642 new_windows = g_new (Window, count + 1);
2644 for (i = 0; i < count; i++)
2645 new_windows[i] = old_windows[i];
2646 new_windows[count] = GDK_WINDOW_XID (window);
2648 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2649 GDK_WINDOW_XID (toplevel),
2650 new_windows, count + 1);
2652 g_free (new_windows);
2654 XFree (old_windows);
2658 gdk_window_have_shape_ext (GdkDisplay *display)
2660 enum { UNKNOWN, NO, YES };
2661 GdkDisplayX11 *display_x11;
2663 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2665 display_x11 = GDK_DISPLAY_X11 (display);
2667 if (display_x11->have_shape == UNKNOWN)
2670 if (XQueryExtension (display_x11->xdisplay, "SHAPE", &ignore, &ignore, &ignore))
2671 display_x11->have_shape = YES;
2673 display_x11->have_shape = NO;
2676 return (display_x11->have_shape == YES);
2679 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2682 * This needs the X11 shape extension.
2683 * If not available, shaped windows will look
2684 * ugly, but programs still work. Stefan Wille
2687 * gdk_window_shape_combine_mask:
2688 * @window: a #GdkWindow
2690 * @x: X position of shape mask with respect to @window
2691 * @y: Y position of shape mask with respect to @window
2693 * Applies a shape mask to @window. Pixels in @window corresponding to
2694 * set bits in the @mask will be visible; pixels in @window
2695 * corresponding to unset bits in the @mask will be transparent. This
2696 * gives a non-rectangular window.
2698 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2699 * parameters are not used.
2701 * On the X11 platform, this uses an X server extension which is
2702 * widely available on most common platforms, but not available on
2703 * very old X servers, and occasionally the implementation will be
2704 * buggy. On servers without the shape extension, this function
2709 gdk_window_shape_combine_mask (GdkWindow *window,
2714 gint xoffset, yoffset;
2716 g_return_if_fail (window != NULL);
2717 g_return_if_fail (GDK_IS_WINDOW (window));
2719 #ifdef HAVE_SHAPE_EXT
2720 if (GDK_WINDOW_DESTROYED (window))
2723 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2725 if (xoffset != 0 || yoffset != 0)
2727 WARN_SHAPE_TOO_BIG ();
2731 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2735 pixmap = GDK_PIXMAP_XID (mask);
2744 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2745 GDK_WINDOW_XID (window),
2751 #endif /* HAVE_SHAPE_EXT */
2755 * gdk_window_shape_combine_region:
2756 * @window: a #GdkWindow
2757 * @shape_region: region of window to be non-transparent
2758 * @offset_x: X position of @shape_region in @window coordinates
2759 * @offset_y: Y position of @shape_region in @window coordinates
2761 * Makes pixels in @window outside @shape_region be transparent,
2762 * so that the window may be nonrectangular. See also
2763 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2765 * If @shape_region is %NULL, the shape will be unset, so the whole
2766 * window will be opaque again. @offset_x and @offset_y are ignored
2767 * if @shape_region is %NULL.
2769 * On the X11 platform, this uses an X server extension which is
2770 * widely available on most common platforms, but not available on
2771 * very old X servers, and occasionally the implementation will be
2772 * buggy. On servers without the shape extension, this function
2777 gdk_window_shape_combine_region (GdkWindow *window,
2778 GdkRegion *shape_region,
2782 gint xoffset, yoffset;
2784 g_return_if_fail (GDK_IS_WINDOW (window));
2786 #ifdef HAVE_SHAPE_EXT
2787 if (GDK_WINDOW_DESTROYED (window))
2790 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2792 if (xoffset != 0 || yoffset != 0)
2794 WARN_SHAPE_TOO_BIG ();
2798 if (shape_region == NULL)
2800 /* Use NULL mask to unset the shape */
2801 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2805 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2808 XRectangle *xrects = NULL;
2810 _gdk_region_get_xrectangles (shape_region,
2814 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2815 GDK_WINDOW_XID (window),
2824 #endif /* HAVE_SHAPE_EXT */
2829 * gdk_window_set_override_redirect:
2830 * @window: a #GdkWindow
2831 * @override_redirect: %TRUE if window should be override redirect
2833 * An override redirect window is not under the control of the window manager.
2834 * This means it won't have a titlebar, won't be minimizable, etc. - it will
2835 * be entirely under the control of the application. The window manager
2836 * can't see the override redirect window at all.
2838 * Override redirect should only be used for short-lived temporary
2839 * windows, such as popup menus. #GtkMenu uses an override redirect
2840 * window in its implementation, for example.
2844 gdk_window_set_override_redirect (GdkWindow *window,
2845 gboolean override_redirect)
2847 XSetWindowAttributes attr;
2849 g_return_if_fail (window != NULL);
2850 g_return_if_fail (GDK_IS_WINDOW (window));
2852 if (!GDK_WINDOW_DESTROYED (window))
2854 attr.override_redirect = (override_redirect == FALSE)?False:True;
2855 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2856 GDK_WINDOW_XID (window),
2864 * gdk_window_set_icon_list:
2865 * @window: The #GdkWindow toplevel window to set the icon of.
2866 * @pixbufs: A list of pixbufs, of different sizes.
2868 * Sets a list of icons for the window. One of these will be used
2869 * to represent the window when it has been iconified. The icon is
2870 * usually shown in an icon box or some sort of task bar. Which icon
2871 * size is shown depends on the window manager. The window manager
2872 * can scale the icon but setting several size icons can give better
2873 * image quality since the window manager may only need to scale the
2874 * icon by a small amount or not at all.
2878 gdk_window_set_icon_list (GdkWindow *window,
2887 gint width, height, stride;
2890 GdkDisplay *display;
2892 g_return_if_fail (GDK_IS_WINDOW (window));
2894 if (GDK_WINDOW_DESTROYED (window))
2897 display = gdk_drawable_get_display (window);
2905 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
2907 width = gdk_pixbuf_get_width (pixbuf);
2908 height = gdk_pixbuf_get_height (pixbuf);
2910 size += 2 + width * height;
2912 l = g_list_next (l);
2915 data = g_malloc (size * sizeof (gulong));
2923 width = gdk_pixbuf_get_width (pixbuf);
2924 height = gdk_pixbuf_get_height (pixbuf);
2925 stride = gdk_pixbuf_get_rowstride (pixbuf);
2926 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
2931 pixels = gdk_pixbuf_get_pixels (pixbuf);
2933 for (y = 0; y < height; y++)
2935 for (x = 0; x < width; x++)
2939 r = pixels[y*stride + x*n_channels + 0];
2940 g = pixels[y*stride + x*n_channels + 1];
2941 b = pixels[y*stride + x*n_channels + 2];
2942 if (n_channels >= 4)
2943 a = pixels[y*stride + x*n_channels + 3];
2947 *p++ = a << 24 | r << 16 | g << 8 | b ;
2951 l = g_list_next (l);
2956 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2957 GDK_WINDOW_XID (window),
2958 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
2961 (guchar*) data, size);
2965 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
2966 GDK_WINDOW_XID (window),
2967 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
2974 * gdk_window_set_icon:
2975 * @window: a #GdkWindow
2976 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
2977 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
2978 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
2980 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
2981 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
2982 * and gtk_window_set_icon(). If those don't meet your needs, look at
2983 * gdk_window_set_icon_list(). Only if all those are too high-level do you
2984 * want to fall back to gdk_window_set_icon().
2988 gdk_window_set_icon (GdkWindow *window,
2989 GdkWindow *icon_window,
2995 g_return_if_fail (window != NULL);
2996 g_return_if_fail (GDK_IS_WINDOW (window));
2998 if (GDK_WINDOW_DESTROYED (window))
3001 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3002 GDK_WINDOW_XID (window));
3004 wm_hints = XAllocWMHints ();
3006 if (icon_window != NULL)
3008 wm_hints->flags |= IconWindowHint;
3009 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
3014 wm_hints->flags |= IconPixmapHint;
3015 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
3020 wm_hints->flags |= IconMaskHint;
3021 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
3024 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3025 GDK_WINDOW_XID (window), wm_hints);
3030 gdk_window_icon_name_set (GdkWindow *window)
3032 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3033 g_quark_from_static_string ("gdk-icon-name-set")));
3037 * gdk_window_set_icon_name:
3038 * @window: a #GdkWindow
3039 * @name: name of window while iconified (minimized)
3041 * Windows may have a name used while minimized, distinct from the
3042 * name they display in their titlebar. Most of the time this is a bad
3043 * idea from a user interface standpoint. But you can set such a name
3044 * with this function, if you like.
3048 gdk_window_set_icon_name (GdkWindow *window,
3051 GdkDisplay *display;
3053 g_return_if_fail (window != NULL);
3054 g_return_if_fail (GDK_IS_WINDOW (window));
3056 if (GDK_WINDOW_DESTROYED (window))
3059 display = gdk_drawable_get_display (window);
3061 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3062 GUINT_TO_POINTER (TRUE));
3064 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
3065 GDK_WINDOW_XID (window),
3066 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3067 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3068 PropModeReplace, name, strlen (name));
3070 set_text_property (window,
3071 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3076 * gdk_window_iconify:
3077 * @window: a #GdkWindow
3079 * Asks to iconify (minimize) @window. The window manager may choose
3080 * to ignore the request, but normally will honor it. Using
3081 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3085 gdk_window_iconify (GdkWindow *window)
3087 GdkWindowObject *private;
3089 g_return_if_fail (window != NULL);
3090 g_return_if_fail (GDK_IS_WINDOW (window));
3092 if (GDK_WINDOW_DESTROYED (window))
3095 private = (GdkWindowObject*) window;
3097 if (GDK_WINDOW_IS_MAPPED (window))
3099 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3100 GDK_WINDOW_XWINDOW (window),
3101 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3105 /* Flip our client side flag, the real work happens on map. */
3106 gdk_synthesize_window_state (window,
3108 GDK_WINDOW_STATE_ICONIFIED);
3113 * gdk_window_deiconify:
3114 * @window: a #GdkWindow
3116 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3117 * choose to ignore the request to deiconify. When using GTK+,
3118 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3119 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3120 * unminimizes it, and puts it on the current desktop.
3124 gdk_window_deiconify (GdkWindow *window)
3126 GdkWindowObject *private;
3128 g_return_if_fail (window != NULL);
3129 g_return_if_fail (GDK_IS_WINDOW (window));
3131 if (GDK_WINDOW_DESTROYED (window))
3134 private = (GdkWindowObject*) window;
3136 if (GDK_WINDOW_IS_MAPPED (window))
3138 gdk_window_show (window);
3142 /* Flip our client side flag, the real work happens on map. */
3143 gdk_synthesize_window_state (window,
3144 GDK_WINDOW_STATE_ICONIFIED,
3151 * @window: a toplevel #GdkWindow
3153 * "Pins" a window such that it's on all workspaces and does not scroll
3154 * with viewports, for window managers that have scrollable viewports.
3155 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3157 * On the X11 platform, this function depends on window manager
3158 * support, so may have no effect with many window managers. However,
3159 * GDK will do the best it can to convince the window manager to stick
3160 * the window. For window managers that don't support this operation,
3161 * there's nothing you can do to force it to happen.
3165 gdk_window_stick (GdkWindow *window)
3167 g_return_if_fail (GDK_IS_WINDOW (window));
3169 if (GDK_WINDOW_DESTROYED (window))
3172 if (GDK_WINDOW_IS_MAPPED (window))
3174 /* "stick" means stick to all desktops _and_ do not scroll with the
3175 * viewport. i.e. glue to the monitor glass in all cases.
3180 /* Request stick during viewport scroll */
3181 gdk_wmspec_change_state (TRUE, window,
3182 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3185 /* Request desktop 0xFFFFFFFF */
3186 xev.xclient.type = ClientMessage;
3187 xev.xclient.serial = 0;
3188 xev.xclient.send_event = True;
3189 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3190 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3191 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3193 xev.xclient.format = 32;
3195 xev.xclient.data.l[0] = 0xFFFFFFFF;
3197 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3198 SubstructureRedirectMask | SubstructureNotifyMask,
3203 /* Flip our client side flag, the real work happens on map. */
3204 gdk_synthesize_window_state (window,
3206 GDK_WINDOW_STATE_STICKY);
3211 * gdk_window_unstick:
3212 * @window: a toplevel #GdkWindow
3214 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3215 * and gtk_window_unstick().
3219 gdk_window_unstick (GdkWindow *window)
3221 g_return_if_fail (GDK_IS_WINDOW (window));
3223 if (GDK_WINDOW_DESTROYED (window))
3226 if (GDK_WINDOW_IS_MAPPED (window))
3233 gulong *current_desktop;
3234 GdkDisplay *display = gdk_drawable_get_display (window);
3236 /* Request unstick from viewport */
3237 gdk_wmspec_change_state (FALSE, window,
3238 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3241 /* Get current desktop, then set it; this is a race, but not
3242 * one that matters much in practice.
3244 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
3245 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
3247 False, XA_CARDINAL, &type, &format, &nitems,
3248 &bytes_after, (guchar **)¤t_desktop);
3250 if (type == XA_CARDINAL)
3252 xev.xclient.type = ClientMessage;
3253 xev.xclient.serial = 0;
3254 xev.xclient.send_event = True;
3255 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3256 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
3257 xev.xclient.format = 32;
3259 xev.xclient.data.l[0] = *current_desktop;
3261 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3262 SubstructureRedirectMask | SubstructureNotifyMask,
3265 XFree (current_desktop);
3270 /* Flip our client side flag, the real work happens on map. */
3271 gdk_synthesize_window_state (window,
3272 GDK_WINDOW_STATE_STICKY,
3279 * gdk_window_maximize:
3280 * @window: a #GdkWindow
3282 * Asks the window manager to maximize @window, if the window manager supports
3283 * this operation. Not all window managers support this, and some deliberately
3284 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3285 * maximization actually happening. But it will happen with most standard
3286 * window managers, and GDK makes a best effort to get it to happen.
3288 * If the window was already maximized, then this function does nothing.
3292 gdk_window_maximize (GdkWindow *window)
3294 g_return_if_fail (GDK_IS_WINDOW (window));
3296 if (GDK_WINDOW_DESTROYED (window))
3299 if (GDK_WINDOW_IS_MAPPED (window))
3300 gdk_wmspec_change_state (TRUE, window,
3301 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3302 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3304 gdk_synthesize_window_state (window,
3306 GDK_WINDOW_STATE_MAXIMIZED);
3310 * gdk_window_unmaximize:
3311 * @window: a #GdkWindow
3313 * Asks the window manager to unmaximize @window, if the window manager supports
3314 * this operation. Not all window managers support this, and some deliberately
3315 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3316 * unmaximization actually happening. But it will happen with most standard
3317 * window managers, and GDK makes a best effort to get it to happen.
3319 * If the window wasn't maximized, then this function does nothing.
3323 gdk_window_unmaximize (GdkWindow *window)
3325 g_return_if_fail (GDK_IS_WINDOW (window));
3327 if (GDK_WINDOW_DESTROYED (window))
3330 if (GDK_WINDOW_IS_MAPPED (window))
3331 gdk_wmspec_change_state (FALSE, window,
3332 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3333 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3335 gdk_synthesize_window_state (window,
3336 GDK_WINDOW_STATE_MAXIMIZED,
3341 * gdk_window_set_group:
3342 * @window: a #GdkWindow
3343 * @leader: group leader window
3345 * Sets the group leader window for @window. By default,
3346 * GDK sets the group leader for all toplevel windows
3347 * to a global window implicitly created by GDK. With this function
3348 * you can override this default.
3350 * The group leader window allows the window manager to distinguish
3351 * all windows that belong to a single application. It may for example
3352 * allow users to minimize/unminimize all windows belonging to an
3353 * application at once. You should only set a non-default group window
3354 * if your application pretends to be multiple applications.
3355 * The group leader window may not be changed after a window has been
3356 * mapped (with gdk_window_show() for example).
3360 gdk_window_set_group (GdkWindow *window,
3365 g_return_if_fail (window != NULL);
3366 g_return_if_fail (GDK_IS_WINDOW (window));
3367 g_return_if_fail (leader != NULL);
3368 g_return_if_fail (GDK_IS_WINDOW (leader));
3370 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3373 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3374 GDK_WINDOW_XID (window));
3376 wm_hints = XAllocWMHints ();
3378 wm_hints->flags |= WindowGroupHint;
3379 wm_hints->window_group = GDK_WINDOW_XID (leader);
3381 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3382 GDK_WINDOW_XID (window), wm_hints);
3386 static MotifWmHints *
3387 gdk_window_get_mwm_hints (GdkWindow *window)
3389 GdkDisplay *display;
3390 Atom hints_atom = None;
3391 MotifWmHints *hints;
3397 if (GDK_WINDOW_DESTROYED (window))
3400 display = gdk_drawable_get_display (window);
3402 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3404 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3405 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3406 False, AnyPropertyType, &type, &format, &nitems,
3407 &bytes_after, (guchar **)&hints);
3416 gdk_window_set_mwm_hints (GdkWindow *window,
3417 MotifWmHints *new_hints)
3419 GdkDisplay *display;
3420 Atom hints_atom = None;
3421 MotifWmHints *hints;
3427 if (GDK_WINDOW_DESTROYED (window))
3430 display = gdk_drawable_get_display (window);
3432 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3434 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3435 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3436 False, AnyPropertyType, &type, &format, &nitems,
3437 &bytes_after, (guchar **)&hints);
3443 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3445 hints->flags |= MWM_HINTS_FUNCTIONS;
3446 hints->functions = new_hints->functions;
3448 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3450 hints->flags |= MWM_HINTS_DECORATIONS;
3451 hints->decorations = new_hints->decorations;
3455 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3456 hints_atom, hints_atom, 32, PropModeReplace,
3457 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3459 if (hints != new_hints)
3464 * gdk_window_set_decorations:
3465 * @window: a #GdkWindow
3466 * @decorations: decoration hint mask
3468 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3469 * This function sets the traditional Motif window manager hints that tell the
3470 * window manager which decorations you would like your window to have.
3471 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3472 * using the GDK function directly.
3474 * The @decorations argument is the logical OR of the fields in
3475 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3476 * mask, the other bits indicate which decorations should be turned off.
3477 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3478 * which decorations should be turned on.
3480 * Most window managers honor a decorations hint of 0 to disable all decorations,
3481 * but very few honor all possible combinations of bits.
3485 gdk_window_set_decorations (GdkWindow *window,
3486 GdkWMDecoration decorations)
3490 g_return_if_fail (window != NULL);
3491 g_return_if_fail (GDK_IS_WINDOW (window));
3493 hints.flags = MWM_HINTS_DECORATIONS;
3494 hints.decorations = decorations;
3496 gdk_window_set_mwm_hints (window, &hints);
3500 * gdk_window_get_decorations:
3501 * @window: The #GdkWindow to get the decorations from
3502 * @decorations: The window decorations will be written here
3504 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3505 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3508 gdk_window_get_decorations(GdkWindow *window,
3509 GdkWMDecoration *decorations)
3511 MotifWmHints *hints;
3512 gboolean result = FALSE;
3514 hints = gdk_window_get_mwm_hints (window);
3518 if (hints->flags & MWM_HINTS_DECORATIONS)
3520 *decorations = hints->decorations;
3531 * gdk_window_set_functions:
3532 * @window: a #GdkWindow
3533 * @functions: bitmask of operations to allow on @window
3535 * This function isn't really good for much. It sets the traditional
3536 * Motif window manager hint for which operations the window manager
3537 * should allow on a toplevel window. However, few window managers do
3538 * anything reliable or interesting with this hint. Many ignore it
3541 * The @functions argument is the logical OR of values from the
3542 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3543 * then the other bits indicate which functions to disable; if
3544 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3549 gdk_window_set_functions (GdkWindow *window,
3550 GdkWMFunction functions)
3554 g_return_if_fail (window != NULL);
3555 g_return_if_fail (GDK_IS_WINDOW (window));
3557 hints.flags = MWM_HINTS_FUNCTIONS;
3558 hints.functions = functions;
3560 gdk_window_set_mwm_hints (window, &hints);
3563 #ifdef HAVE_SHAPE_EXT
3566 * propagate the shapes from all child windows of a GDK window to the parent
3567 * window. Shamelessly ripped from Enlightenment's code
3575 struct _gdk_span *next;
3579 gdk_add_to_span (struct _gdk_span **s,
3583 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3590 /* scan the spans for this line */
3593 /* -- -> new span */
3594 /* == -> existing span */
3595 /* ## -> spans intersect */
3596 /* if we are in the middle of spanning the span into the line */
3599 /* case: ---- ==== */
3600 if (xx < ptr1->start - 1)
3602 /* ends before next span - extend to here */
3606 /* case: ----##=== */
3607 else if (xx <= ptr1->end)
3609 /* crosses into next span - delete next span and append */
3610 ss->end = ptr1->end;
3611 ss->next = ptr1->next;
3615 /* case: ---###--- */
3618 /* overlaps next span - delete and keep checking */
3619 ss->next = ptr1->next;
3624 /* otherwise havent started spanning it in yet */
3627 /* case: ---- ==== */
3628 if (xx < ptr1->start - 1)
3630 /* insert span here in list */
3631 noo = g_malloc (sizeof (struct _gdk_span));
3645 /* case: ----##=== */
3646 else if ((x < ptr1->start) && (xx <= ptr1->end))
3648 /* expand this span to the left point of the new one */
3652 /* case: ===###=== */
3653 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3655 /* throw the span away */
3658 /* case: ---###--- */
3659 else if ((x < ptr1->start) && (xx > ptr1->end))
3666 /* case: ===##---- */
3667 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3673 /* case: ==== ---- */
3674 /* case handled by next loop iteration - first case */
3679 /* it started in the middle but spans beyond your current list */
3685 /* it does not start inside a span or in the middle, so add it to the end */
3686 noo = g_malloc (sizeof (struct _gdk_span));
3694 noo->next = ptr2->next;
3707 gdk_add_rectangles (Display *disp,
3709 struct _gdk_span **spans,
3716 gint x1, y1, x2, y2;
3720 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
3723 /* go through all clip rects in this window's shape */
3724 for (k = 0; k < rn; k++)
3726 /* for each clip rect, add it to each line's spans */
3728 x2 = x + rl[k].x + (rl[k].width - 1);
3730 y2 = y + rl[k].y + (rl[k].height - 1);
3739 for (a = y1; a <= y2; a++)
3742 gdk_add_to_span (&spans[a], x1, x2);
3750 gdk_propagate_shapes (Display *disp,
3754 Window rt, par, *list = NULL;
3755 gint i, j, num = 0, num_rects = 0;
3759 XRectangle *rects = NULL;
3760 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
3761 XWindowAttributes xatt;
3763 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
3768 spans = g_malloc (sizeof (struct _gdk_span *) * h);
3770 for (i = 0; i < h; i++)
3772 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
3775 /* go through all child windows and create/insert spans */
3776 for (i = 0; i < num; i++)
3778 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
3779 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
3780 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
3783 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
3785 /* go through the spans list and build a list of rects */
3786 rects = g_malloc (sizeof (XRectangle) * 256);
3788 for (i = 0; i < baseh; i++)
3791 /* go through the line for all spans */
3794 rects[num_rects].x = ptr1->start;
3795 rects[num_rects].y = i;
3796 rects[num_rects].width = ptr1->end - ptr1->start + 1;
3797 rects[num_rects].height = 1;
3799 /* if there are more lines */
3801 /* while contigous rects (same start/end coords) exist */
3802 while ((contig) && (j < baseh))
3804 /* search next line for spans matching this one */
3810 /* if we have an exact span match set contig */
3811 if ((ptr2->start == ptr1->start) &&
3812 (ptr2->end == ptr1->end))
3815 /* remove the span - not needed */
3818 ptr3->next = ptr2->next;
3824 spans[j] = ptr2->next;
3830 /* gone past the span point no point looking */
3831 else if (ptr2->start < ptr1->start)
3839 /* if a contiguous span was found increase the rect h */
3842 rects[num_rects].height++;
3846 /* up the rect count */
3848 /* every 256 new rects increase the rect array */
3849 if ((num_rects % 256) == 0)
3850 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
3854 /* set the rects as the shape mask */
3857 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
3858 ShapeSet, YXSorted);
3863 /* free up all the spans we made */
3864 for (i = 0; i < baseh; i++)
3877 #endif /* HAVE_SHAPE_EXT */
3880 * gdk_window_set_child_shapes:
3881 * @window: a #GdkWindow
3883 * Sets the shape mask of @window to the union of shape masks
3884 * for all children of @window, ignoring the shape mask of @window
3885 * itself. Contrast with gdk_window_merge_child_shapes() which includes
3886 * the shape mask of @window in the masks to be merged.
3889 gdk_window_set_child_shapes (GdkWindow *window)
3891 g_return_if_fail (window != NULL);
3892 g_return_if_fail (GDK_IS_WINDOW (window));
3894 #ifdef HAVE_SHAPE_EXT
3895 if (!GDK_WINDOW_DESTROYED (window) &&
3896 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3897 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3898 GDK_WINDOW_XID (window), FALSE);
3903 * gdk_window_merge_child_shapes:
3904 * @window: a #GdkWindow
3906 * Merges the shape masks for any child windows into the
3907 * shape mask for @window. i.e. the union of all masks
3908 * for @window and its children will become the new mask
3909 * for @window. See gdk_window_shape_combine_mask().
3911 * This function is distinct from gdk_window_set_child_shapes()
3912 * because it includes @window's shape mask in the set of shapes to
3917 gdk_window_merge_child_shapes (GdkWindow *window)
3919 g_return_if_fail (window != NULL);
3920 g_return_if_fail (GDK_IS_WINDOW (window));
3922 #ifdef HAVE_SHAPE_EXT
3923 if (!GDK_WINDOW_DESTROYED (window) &&
3924 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3925 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3926 GDK_WINDOW_XID (window), TRUE);
3930 /* Support for windows that can be guffaw-scrolled
3931 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
3935 gdk_window_gravity_works (GdkWindow *window)
3937 enum { UNKNOWN, NO, YES };
3938 static gint gravity_works = UNKNOWN;
3939 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (window);
3941 if (gravity_works == UNKNOWN)
3948 /* This particular server apparently has a bug so that the test
3949 * works but the actual code crashes it
3951 if ((!strcmp (XServerVendor (GDK_DISPLAY_XDISPLAY (display)),
3952 "Sun Microsystems, Inc.")) &&
3953 (VendorRelease (GDK_DISPLAY_XDISPLAY (display)) == 3400))
3959 attr.window_type = GDK_WINDOW_TEMP;
3960 attr.wclass = GDK_INPUT_OUTPUT;
3965 attr.event_mask = 0;
3967 parent = gdk_window_new (gdk_screen_get_root_window (GDK_DRAWABLE_SCREEN (window)),
3968 &attr, GDK_WA_X | GDK_WA_Y);
3970 attr.window_type = GDK_WINDOW_CHILD;
3971 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
3973 gdk_window_set_static_win_gravity (child, TRUE);
3975 gdk_window_resize (parent, 100, 110);
3977 gdk_window_move (parent, 0, -10);
3978 gdk_window_move_resize (parent, 0, 0, 100, 100);
3980 gdk_window_resize (parent, 100, 110);
3981 gdk_window_move (parent, 0, -10);
3982 gdk_window_move_resize (parent, 0, 0, 100, 100);
3984 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
3986 gdk_window_destroy (parent);
3987 gdk_window_destroy (child);
3989 gravity_works = ((y == -20) ? YES : NO);
3992 return (gravity_works == YES);
3996 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
3998 XSetWindowAttributes xattributes;
3999 GdkWindowObject *private;
4000 guint xattributes_mask = 0;
4002 g_return_if_fail (window != NULL);
4004 private = GDK_WINDOW_OBJECT (window);
4005 if (private->input_only)
4008 xattributes.bit_gravity = StaticGravity;
4009 xattributes_mask |= CWBitGravity;
4010 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4011 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4012 GDK_WINDOW_XID (window),
4013 CWBitGravity, &xattributes);
4017 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4019 XSetWindowAttributes xattributes;
4021 g_return_if_fail (window != NULL);
4023 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4025 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4026 GDK_WINDOW_XID (window),
4027 CWWinGravity, &xattributes);
4031 * gdk_window_set_static_gravities:
4032 * @window: a #GdkWindow
4033 * @use_static: %TRUE to turn on static gravity
4035 * Set the bit gravity of the given window to static, and flag it so
4036 * all children get static subwindow gravity. This is used if you are
4037 * implementing scary features that involve deep knowledge of the
4038 * windowing system. Don't worry about it unless you have to.
4040 * Return value: %TRUE if the server supports static gravity
4043 gdk_window_set_static_gravities (GdkWindow *window,
4044 gboolean use_static)
4046 GdkWindowObject *private = (GdkWindowObject *)window;
4049 g_return_val_if_fail (window != NULL, FALSE);
4050 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4052 if (!use_static == !private->guffaw_gravity)
4055 if (use_static && !gdk_window_gravity_works (window))
4058 private->guffaw_gravity = use_static;
4060 if (!GDK_WINDOW_DESTROYED (window))
4062 gdk_window_set_static_bit_gravity (window, use_static);
4064 tmp_list = private->children;
4067 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4069 tmp_list = tmp_list->next;
4077 wmspec_moveresize (GdkWindow *window,
4083 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4087 /* Release passive grab */
4088 gdk_display_pointer_ungrab (display, timestamp);
4090 xev.xclient.type = ClientMessage;
4091 xev.xclient.serial = 0;
4092 xev.xclient.send_event = True;
4093 xev.xclient.window = GDK_WINDOW_XID (window);
4094 xev.xclient.message_type =
4095 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4096 xev.xclient.format = 32;
4097 xev.xclient.data.l[0] = root_x;
4098 xev.xclient.data.l[1] = root_y;
4099 xev.xclient.data.l[2] = direction;
4100 xev.xclient.data.l[3] = 0;
4101 xev.xclient.data.l[4] = 0;
4103 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4104 SubstructureRedirectMask | SubstructureNotifyMask,
4108 typedef struct _MoveResizeData MoveResizeData;
4110 struct _MoveResizeData
4112 GdkDisplay *display;
4114 GdkWindow *moveresize_window;
4115 GdkWindow *moveresize_emulation_window;
4117 GdkWindowEdge resize_edge;
4118 gint moveresize_button;
4121 gint moveresize_orig_x;
4122 gint moveresize_orig_y;
4123 gint moveresize_orig_width;
4124 gint moveresize_orig_height;
4125 GdkWindowHints moveresize_geom_mask;
4126 GdkGeometry moveresize_geometry;
4127 Time moveresize_process_time;
4128 XEvent *moveresize_pending_event;
4131 /* From the WM spec */
4132 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4133 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4134 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4135 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4136 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4137 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4138 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4139 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4140 #define _NET_WM_MOVERESIZE_MOVE 8
4143 wmspec_resize_drag (GdkWindow *window,
4152 /* Let the compiler turn a switch into a table, instead
4153 * of doing the table manually, this way is easier to verify.
4157 case GDK_WINDOW_EDGE_NORTH_WEST:
4158 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4161 case GDK_WINDOW_EDGE_NORTH:
4162 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4165 case GDK_WINDOW_EDGE_NORTH_EAST:
4166 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4169 case GDK_WINDOW_EDGE_WEST:
4170 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4173 case GDK_WINDOW_EDGE_EAST:
4174 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4177 case GDK_WINDOW_EDGE_SOUTH_WEST:
4178 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4181 case GDK_WINDOW_EDGE_SOUTH:
4182 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4185 case GDK_WINDOW_EDGE_SOUTH_EAST:
4186 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4190 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4196 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4199 static MoveResizeData *
4200 get_move_resize_data (GdkDisplay *display)
4202 MoveResizeData *mv_resize;
4203 static GQuark move_resize_quark = 0;
4205 if (!move_resize_quark)
4206 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4208 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4212 mv_resize = g_new0 (MoveResizeData, 1);
4213 mv_resize->display = display;
4215 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4222 update_pos (MoveResizeData *mv_resize,
4228 dx = new_root_x - mv_resize->moveresize_x;
4229 dy = new_root_y - mv_resize->moveresize_y;
4231 if (mv_resize->is_resize)
4235 w = mv_resize->moveresize_orig_width;
4236 h = mv_resize->moveresize_orig_height;
4238 switch (mv_resize->resize_edge)
4240 case GDK_WINDOW_EDGE_SOUTH_EAST:
4249 if (mv_resize->moveresize_geom_mask)
4251 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4252 mv_resize->moveresize_geom_mask,
4256 gdk_window_resize (mv_resize->moveresize_window, w, h);
4262 x = mv_resize->moveresize_orig_x + dx;
4263 y = mv_resize->moveresize_orig_y + dy;
4265 gdk_window_move (mv_resize->moveresize_window, x, y);
4270 finish_drag (MoveResizeData *mv_resize)
4272 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4273 mv_resize->moveresize_emulation_window = NULL;
4274 mv_resize->moveresize_window = NULL;
4276 if (mv_resize->moveresize_pending_event)
4278 g_free (mv_resize->moveresize_pending_event);
4279 mv_resize->moveresize_pending_event = NULL;
4284 lookahead_motion_predicate (Display *xdisplay,
4288 gboolean *seen_release = (gboolean *)arg;
4289 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4290 MoveResizeData *mv_resize = get_move_resize_data (display);
4295 switch (event->xany.type)
4298 *seen_release = TRUE;
4301 mv_resize->moveresize_process_time = event->xmotion.time;
4311 moveresize_lookahead (MoveResizeData *mv_resize,
4315 gboolean seen_release = FALSE;
4317 if (mv_resize->moveresize_process_time)
4319 if (event->xmotion.time == mv_resize->moveresize_process_time)
4321 mv_resize->moveresize_process_time = 0;
4328 XCheckIfEvent (event->xany.display, &tmp_event,
4329 lookahead_motion_predicate, (XPointer) & seen_release);
4331 return mv_resize->moveresize_process_time == 0;
4335 _gdk_moveresize_handle_event (XEvent *event)
4337 guint button_mask = 0;
4338 GdkWindowObject *window_private;
4339 GdkDisplay *display= gdk_x11_lookup_xdisplay (event->xany.display);
4340 MoveResizeData *mv_resize = get_move_resize_data (display);
4342 if (!mv_resize->moveresize_window)
4345 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
4347 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4349 switch (event->xany.type)
4352 if (window_private->resize_count > 0)
4354 if (mv_resize->moveresize_pending_event)
4355 *mv_resize->moveresize_pending_event = *event;
4357 mv_resize->moveresize_pending_event =
4358 g_memdup (event, sizeof (XEvent));
4362 if (!moveresize_lookahead (mv_resize, event))
4365 update_pos (mv_resize,
4366 event->xmotion.x_root,
4367 event->xmotion.y_root);
4369 /* This should never be triggered in normal cases, but in the
4370 * case where the drag started without an implicit grab being
4371 * in effect, we could miss the release if it occurs before
4372 * we grab the pointer; this ensures that we will never
4373 * get a permanently stuck grab.
4375 if ((event->xmotion.state & button_mask) == 0)
4376 finish_drag (mv_resize);
4380 update_pos (mv_resize,
4381 event->xbutton.x_root,
4382 event->xbutton.y_root);
4384 if (event->xbutton.button == mv_resize->moveresize_button)
4385 finish_drag (mv_resize);
4392 _gdk_moveresize_configure_done (GdkDisplay *display,
4396 MoveResizeData *mv_resize = get_move_resize_data (display);
4398 if (window != mv_resize->moveresize_window)
4401 g_assert (mv_resize != NULL);
4403 if (mv_resize->moveresize_pending_event)
4405 tmp_event = mv_resize->moveresize_pending_event;
4406 mv_resize->moveresize_pending_event = NULL;
4407 _gdk_moveresize_handle_event (tmp_event);
4415 create_moveresize_window (MoveResizeData *mv_resize,
4418 GdkWindowAttr attributes;
4419 gint attributes_mask;
4420 GdkGrabStatus status;
4422 g_assert (mv_resize->moveresize_emulation_window == NULL);
4424 attributes.x = -100;
4425 attributes.y = -100;
4426 attributes.width = 10;
4427 attributes.height = 10;
4428 attributes.window_type = GDK_WINDOW_TEMP;
4429 attributes.wclass = GDK_INPUT_ONLY;
4430 attributes.override_redirect = TRUE;
4431 attributes.event_mask = 0;
4433 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4435 mv_resize->moveresize_emulation_window =
4436 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4440 gdk_window_show (mv_resize->moveresize_emulation_window);
4442 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4444 GDK_BUTTON_RELEASE_MASK |
4445 GDK_POINTER_MOTION_MASK,
4450 if (status != GDK_GRAB_SUCCESS)
4452 /* If this fails, some other client has grabbed the window
4455 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4456 mv_resize->moveresize_emulation_window = NULL;
4459 mv_resize->moveresize_process_time = 0;
4463 emulate_resize_drag (GdkWindow *window,
4470 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window));
4472 mv_resize->is_resize = TRUE;
4473 mv_resize->moveresize_button = button;
4474 mv_resize->resize_edge = edge;
4475 mv_resize->moveresize_x = root_x;
4476 mv_resize->moveresize_y = root_y;
4477 mv_resize->moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4479 gdk_window_get_size (window,
4480 &mv_resize->moveresize_orig_width,
4481 &mv_resize->moveresize_orig_height);
4483 mv_resize->moveresize_geom_mask = 0;
4484 gdk_window_get_geometry_hints (window,
4485 &mv_resize->moveresize_geometry,
4486 &mv_resize->moveresize_geom_mask);
4488 create_moveresize_window (mv_resize, timestamp);
4492 emulate_move_drag (GdkWindow *window,
4498 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window));
4500 mv_resize->is_resize = FALSE;
4501 mv_resize->moveresize_button = button;
4502 mv_resize->moveresize_x = root_x;
4503 mv_resize->moveresize_y = root_y;
4505 mv_resize->moveresize_window =
4506 GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4508 gdk_window_get_deskrelative_origin (mv_resize->moveresize_window,
4509 &mv_resize->moveresize_orig_x,
4510 &mv_resize->moveresize_orig_y);
4512 create_moveresize_window (mv_resize, timestamp);
4516 * gdk_window_begin_resize_drag:
4517 * @window: a #GdkWindow
4518 * @edge: the edge or corner from which the drag is started
4519 * @button: the button being used to drag
4520 * @root_x: root window X coordinate of mouse click that began the drag
4521 * @root_y: root window Y coordinate of mouse click that began the drag
4522 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4524 * Begins a window resize operation (for a toplevel window).
4525 * You might use this function to implement a "window resize grip," for
4526 * example; in fact #GtkStatusbar uses it. The function works best
4527 * with window managers that support the Extended Window Manager Hints spec
4528 * (see http://www.freedesktop.org), but has a fallback implementation
4529 * for other window managers.
4533 gdk_window_begin_resize_drag (GdkWindow *window,
4540 g_return_if_fail (GDK_IS_WINDOW (window));
4542 if (GDK_WINDOW_DESTROYED (window))
4545 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4546 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4547 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4549 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4553 * gdk_window_begin_move_drag:
4554 * @window: a #GdkWindow
4555 * @button: the button being used to drag
4556 * @root_x: root window X coordinate of mouse click that began the drag
4557 * @root_y: root window Y coordinate of mouse click that began the drag
4558 * @timestamp: timestamp of mouse click that began the drag
4560 * Begins a window move operation (for a toplevel window). You might
4561 * use this function to implement a "window move grip," for
4562 * example. The function works best with window managers that support
4563 * the Extended Window Manager Hints spec (see
4564 * http://www.freedesktop.org), but has a fallback implementation for
4565 * other window managers.
4569 gdk_window_begin_move_drag (GdkWindow *window,
4575 g_return_if_fail (GDK_IS_WINDOW (window));
4577 if (GDK_WINDOW_DESTROYED (window))
4580 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4581 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4582 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
4585 emulate_move_drag (window, button, root_x, root_y, timestamp);