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;
306 _gdk_xid_table_insert (screen_x11->display,
307 &screen_x11->xroot_window,
308 screen_x11->root_window);
312 set_wm_protocols (GdkWindow *window)
314 GdkDisplay *display = gdk_drawable_get_display (window);
317 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
318 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
319 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
321 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
326 * @parent: a #GdkWindow, or %NULL to create the window as a child of
327 * the default root window for the default display.
328 * @attributes: attributes of the new window
329 * @attributes_mask: mask indicating which fields in @attributes are valid
331 * Creates a new #GdkWindow using the attributes from
332 * @attributes. Seep #GdkWindowAttr and #GdkWindowAttributesType for
333 * more details. Note: to use this on displays other than the default
334 * display, @parent must be specified.
336 * Return value: the new #GdkWindow
339 gdk_window_new (GdkWindow *parent,
340 GdkWindowAttr *attributes,
341 gint attributes_mask)
344 GdkWindowObject *private;
345 GdkWindowImplX11 *impl;
346 GdkDrawableImplX11 *draw_impl;
347 GdkScreenX11 *screen_x11;
356 XSetWindowAttributes xattributes;
357 long xattributes_mask;
358 XSizeHints size_hints;
360 XClassHint *class_hint;
368 g_return_val_if_fail (attributes != NULL, NULL);
373 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
375 screen = gdk_get_default_screen ();
376 parent = gdk_screen_get_root_window (screen);
379 screen = gdk_drawable_get_screen (parent);
381 screen_x11 = GDK_SCREEN_X11 (screen);
383 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
385 if (GDK_WINDOW_DESTROYED (parent))
388 xparent = GDK_WINDOW_XID (parent);
390 window = g_object_new (GDK_TYPE_WINDOW, NULL);
391 private = (GdkWindowObject *)window;
392 impl = GDK_WINDOW_IMPL_X11 (private->impl);
393 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
394 draw_impl->wrapper = GDK_DRAWABLE (window);
396 draw_impl->screen = screen;
397 xdisplay = screen_x11->xdisplay;
399 /* Windows with a foreign parent are treated as if they are children
400 * of the root window, except for actual creation.
402 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
403 parent = gdk_screen_get_root_window (screen);
405 private->parent = (GdkWindowObject *)parent;
407 xattributes_mask = 0;
409 if (attributes_mask & GDK_WA_X)
414 if (attributes_mask & GDK_WA_Y)
421 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
422 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
424 if (attributes->wclass == GDK_INPUT_ONLY)
426 /* Backwards compatiblity - we've always ignored
427 * attributes->window_type for input-only windows
430 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
431 private->window_type = GDK_WINDOW_TEMP;
433 private->window_type = GDK_WINDOW_CHILD;
436 private->window_type = attributes->window_type;
438 _gdk_window_init_position (GDK_WINDOW (private));
439 if (impl->position_info.big)
440 private->guffaw_gravity = TRUE;
442 if (attributes_mask & GDK_WA_VISUAL)
443 visual = attributes->visual;
445 visual = gdk_screen_get_system_visual (screen);
446 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
448 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
449 for (i = 0; i < _gdk_nenvent_masks; i++)
451 if (attributes->event_mask & (1 << (i + 1)))
452 xattributes.event_mask |= _gdk_event_mask_table[i];
454 private->event_mask = attributes->event_mask;
456 if (xattributes.event_mask)
457 xattributes_mask |= CWEventMask;
459 if (attributes_mask & GDK_WA_NOREDIR)
461 xattributes.override_redirect =
462 (attributes->override_redirect == FALSE)?False:True;
463 xattributes_mask |= CWOverrideRedirect;
466 xattributes.override_redirect = False;
468 if (private->parent && private->parent->guffaw_gravity)
470 xattributes.win_gravity = StaticGravity;
471 xattributes_mask |= CWWinGravity;
475 switch (private->window_type)
477 case GDK_WINDOW_TOPLEVEL:
478 case GDK_WINDOW_DIALOG:
479 case GDK_WINDOW_TEMP:
480 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
482 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
483 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
484 xparent = GDK_SCREEN_XROOTWIN (screen);
486 case GDK_WINDOW_CHILD:
489 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
493 if (attributes->wclass == GDK_INPUT_OUTPUT)
496 depth = visual->depth;
498 private->input_only = FALSE;
499 private->depth = depth;
501 if (attributes_mask & GDK_WA_COLORMAP)
503 draw_impl->colormap = attributes->colormap;
504 gdk_colormap_ref (attributes->colormap);
508 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
510 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
511 gdk_colormap_ref (draw_impl->colormap);
515 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
519 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
520 xattributes.background_pixel = private->bg_color.pixel;
522 private->bg_pixmap = NULL;
524 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
525 xattributes_mask |= CWBorderPixel | CWBackPixel;
527 if (private->guffaw_gravity)
528 xattributes.bit_gravity = StaticGravity;
530 xattributes.bit_gravity = NorthWestGravity;
532 xattributes_mask |= CWBitGravity;
534 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
535 xattributes_mask |= CWColormap;
537 if (private->window_type == GDK_WINDOW_TEMP)
539 xattributes.save_under = True;
540 xattributes.override_redirect = True;
541 xattributes.cursor = None;
542 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
550 private->input_only = TRUE;
551 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
552 gdk_colormap_ref (draw_impl->colormap);
555 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
556 impl->position_info.x, impl->position_info.y,
557 impl->position_info.width, impl->position_info.height,
558 0, depth, class, xvisual,
559 xattributes_mask, &xattributes);
561 gdk_drawable_ref (window);
562 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
564 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
565 (attributes->cursor) :
569 private->parent->children = g_list_prepend (private->parent->children, window);
571 switch (GDK_WINDOW_TYPE (private))
573 case GDK_WINDOW_DIALOG:
574 XSetTransientForHint (xdisplay, xid, xparent);
575 case GDK_WINDOW_TOPLEVEL:
576 case GDK_WINDOW_TEMP:
577 set_wm_protocols (window);
579 case GDK_WINDOW_CHILD:
580 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
581 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
582 (draw_impl->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window))))
584 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
585 gdk_window_add_colormap_windows (window);
594 if (class != InputOnly)
596 /* The focus window is off the visible area, and serves to receive key
597 * press events so they don't get sent to child windows.
599 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
601 xattributes.background_pixel,
602 xattributes.background_pixel);
603 /* FIXME: probably better to actually track the requested event mask for the toplevel
605 XSelectInput (xdisplay, impl->focus_window,
606 KeyPressMask | KeyReleaseMask | FocusChangeMask);
608 XMapWindow (xdisplay, impl->focus_window);
609 _gdk_xid_table_insert (screen_x11->display, &impl->focus_window, window);
612 size_hints.flags = PSize;
613 size_hints.width = impl->width;
614 size_hints.height = impl->height;
616 wm_hints.flags = StateHint | WindowGroupHint;
617 wm_hints.window_group = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
618 wm_hints.input = True;
619 wm_hints.initial_state = NormalState;
621 /* FIXME: Is there any point in doing this? Do any WM's pay
622 * attention to PSize, and even if they do, is this the
625 XSetWMNormalHints (xdisplay, xid, &size_hints);
627 XSetWMHints (xdisplay, xid, &wm_hints);
629 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
630 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
633 XChangeProperty (xdisplay, xid,
634 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
639 XChangeProperty (xdisplay, xid,
640 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
641 XA_WINDOW, 32, PropModeReplace,
642 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
644 if (attributes_mask & GDK_WA_TITLE)
645 title = attributes->title;
647 title = g_get_prgname ();
649 gdk_window_set_title (window, title);
651 if (attributes_mask & GDK_WA_WMCLASS)
653 class_hint = XAllocClassHint ();
654 class_hint->res_name = attributes->wmclass_name;
655 class_hint->res_class = attributes->wmclass_class;
656 XSetClassHint (xdisplay, xid, class_hint);
664 x_event_mask_to_gdk_event_mask (long mask)
666 GdkEventMask event_mask = 0;
669 for (i = 0; i < _gdk_nenvent_masks; i++)
671 if (mask & _gdk_event_mask_table[i])
672 event_mask |= 1 << (i + 1);
679 * gdk_window_foreign_new_for_display:
680 * @display: the #GdkDisplay where the window handle comes from.
681 * @anid: a native window handle.
683 * Wraps a native window in a #GdkWindow.
684 * This may fail if the window has been destroyed.
686 * For example in the X backend, a native window handle is an Xlib
689 * Return value: the newly-created #GdkWindow wrapper for the
690 * native window or %NULL if the window has been destroyed.
693 gdk_window_foreign_new_for_display (GdkDisplay *display,
694 GdkNativeWindow anid)
697 GdkWindowObject *private;
698 GdkWindowImplX11 *impl;
699 GdkDrawableImplX11 *draw_impl;
700 GdkDisplayX11 *display_x11;
701 XWindowAttributes attrs;
703 Window *children = NULL;
707 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
709 display_x11 = GDK_DISPLAY_X11 (display);
711 gdk_error_trap_push ();
712 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
713 if (gdk_error_trap_pop () || !result)
716 /* FIXME: This is pretty expensive. Maybe the caller should supply
718 gdk_error_trap_push ();
719 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
720 if (gdk_error_trap_pop () || !result)
726 window = g_object_new (GDK_TYPE_WINDOW, NULL);
727 private = (GdkWindowObject *)window;
728 impl = GDK_WINDOW_IMPL_X11 (private->impl);
729 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
730 draw_impl->wrapper = GDK_DRAWABLE (window);
731 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
733 private->parent = gdk_xid_table_lookup_for_display (display, parent);
735 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
736 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
738 private->parent->children = g_list_prepend (private->parent->children, window);
740 draw_impl->xid = anid;
742 private->x = attrs.x;
743 private->y = attrs.y;
744 impl->width = attrs.width;
745 impl->height = attrs.height;
746 private->window_type = GDK_WINDOW_FOREIGN;
747 private->destroyed = FALSE;
749 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
751 if (attrs.map_state == IsUnmapped)
752 private->state = GDK_WINDOW_STATE_WITHDRAWN;
756 private->depth = attrs.depth;
758 _gdk_window_init_position (GDK_WINDOW (private));
760 gdk_drawable_ref (window);
761 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
766 * gdk_window_lookup_for_display:
767 * @display: the #GdkDisplay corresponding to the window handle
768 * @anid: a native window handle.
770 * Looks up the #GdkWindow that wraps the given native window handle.
772 * For example in the X backend, a native window handle is an Xlib
775 * Return value: the #GdkWindow wrapper for the native window,
776 * or %NULL if there is none.
779 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
781 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
786 * @anid: a native window handle.
788 * Looks up the #GdkWindow that wraps the given native window handle.
790 * For example in the X backend, a native window handle is an Xlib
793 * Return value: the #GdkWindow wrapper for the native window,
794 * or %NULL if there is none.
797 gdk_window_lookup (GdkNativeWindow anid)
799 return (GdkWindow*) gdk_xid_table_lookup (anid);
803 _gdk_windowing_window_destroy (GdkWindow *window,
805 gboolean foreign_destroy)
807 GdkWindowObject *private = (GdkWindowObject *)window;
809 g_return_if_fail (GDK_IS_WINDOW (window));
811 _gdk_selection_window_destroyed (window);
813 if (private->extension_events != 0)
814 gdk_input_window_destroy (window);
818 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
820 if (draw_impl->picture)
821 XRenderFreePicture (GDK_WINDOW_XDISPLAY (window), draw_impl->picture);
823 #endif /* HAVE_XFT */
825 if (private->window_type == GDK_WINDOW_FOREIGN)
827 if (!foreign_destroy && (private->parent != NULL))
829 /* It's somebody else's window, but in our heirarchy,
830 * so reparent it to the root window, and then send
831 * it a delete event, as if we were a WM
833 XClientMessageEvent xevent;
835 gdk_error_trap_push ();
836 gdk_window_hide (window);
837 gdk_window_reparent (window, NULL, 0, 0);
839 xevent.type = ClientMessage;
840 xevent.window = GDK_WINDOW_XID (window);
841 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
844 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
846 xevent.data.l[1] = CurrentTime;
848 XSendEvent (GDK_WINDOW_XDISPLAY (window),
849 GDK_WINDOW_XID (window),
850 False, 0, (XEvent *)&xevent);
851 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
852 gdk_error_trap_pop ();
855 else if (!recursing && !foreign_destroy)
857 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
861 /* This function is called when the XWindow is really gone.
864 gdk_window_destroy_notify (GdkWindow *window)
866 GdkWindowImplX11 *window_impl;
868 g_return_if_fail (window != NULL);
870 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
872 if (!GDK_WINDOW_DESTROYED (window))
874 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
875 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
877 _gdk_window_destroy (window, TRUE);
880 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
881 if (window_impl->focus_window)
882 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->focus_window);
884 _gdk_xgrab_check_destroy (window);
886 gdk_drawable_unref (window);
890 set_initial_hints (GdkWindow *window)
892 GdkWindowObject *private;
896 private = (GdkWindowObject*) window;
898 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
902 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
903 GDK_WINDOW_XID (window));
905 wm_hints = XAllocWMHints ();
907 wm_hints->flags |= StateHint;
908 wm_hints->initial_state = IconicState;
910 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
911 GDK_WINDOW_XID (window), wm_hints);
915 /* We set the spec hints regardless of whether the spec is supported,
916 * since it can't hurt and it's kind of expensive to check whether
922 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
924 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
925 "_NET_WM_STATE_MAXIMIZED_VERT");
927 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
928 "_NET_WM_STATE_MAXIMIZED_HORZ");
932 if (private->state & GDK_WINDOW_STATE_STICKY)
934 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
935 "_NET_WM_STATE_STICKY");
939 if (private->modal_hint)
941 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
942 "_NET_WM_STATE_MODAL");
948 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
949 GDK_WINDOW_XID (window),
950 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_STATE"),
951 XA_ATOM, 32, PropModeReplace,
955 if (private->state & GDK_WINDOW_STATE_STICKY)
957 atoms[0] = 0xFFFFFFFF;
958 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
959 GDK_WINDOW_XID (window),
960 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_DESKTOP"),
961 XA_CARDINAL, 32, PropModeReplace,
967 show_window_internal (GdkWindow *window,
970 GdkWindowObject *private;
972 g_return_if_fail (GDK_IS_WINDOW (window));
974 private = (GdkWindowObject*) window;
975 if (!private->destroyed)
978 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
979 GDK_WINDOW_XID (window));
981 if (!GDK_WINDOW_IS_MAPPED (window))
983 set_initial_hints (window);
985 gdk_synthesize_window_state (window,
986 GDK_WINDOW_STATE_WITHDRAWN,
990 g_assert (GDK_WINDOW_IS_MAPPED (window));
992 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
993 XMapWindow (GDK_WINDOW_XDISPLAY (window),
994 GDK_WINDOW_XID (window));
999 * gdk_window_show_unraised:
1000 * @window: a #GdkWindow
1002 * Shows a #GdkWindow onscreen, but does not modify its stacking
1003 * order. In contrast, gdk_window_show() will raise the window
1004 * to the top of the window stack.
1006 * On the X11 platform, in Xlib terms, this function calls
1007 * XMapWindow() (it also updates some internal GDK state, which means
1008 * that you can't really use XMapWindow() directly on a GDK window).
1012 gdk_window_show_unraised (GdkWindow *window)
1014 g_return_if_fail (GDK_IS_WINDOW (window));
1016 show_window_internal (window, FALSE);
1021 * @window: a #GdkWindow
1023 * Like gdk_window_show_unraised(), but also raises the window to the
1024 * top of the window stack (moves the window to the front of the
1027 * This function maps a window so it's visible onscreen. Its opposite
1028 * is gdk_window_hide().
1030 * When implementing a #GtkWidget, you should call this function on the widget's
1031 * #GdkWindow as part of the "map" method.
1035 gdk_window_show (GdkWindow *window)
1037 g_return_if_fail (GDK_IS_WINDOW (window));
1039 show_window_internal (window, TRUE);
1044 * @window: a #GdkWindow
1046 * For toplevel windows, withdraws them, so they will no longer be
1047 * known to the window manager; for all windows, unmaps them, so
1048 * they won't be displayed. Normally done automatically as
1049 * part of gtk_widget_hide().
1053 gdk_window_hide (GdkWindow *window)
1055 GdkWindowObject *private;
1057 g_return_if_fail (window != NULL);
1059 private = (GdkWindowObject*) window;
1061 /* We'll get the unmap notify eventually, and handle it then,
1062 * but checking here makes things more consistent if we are
1063 * just doing stuff ourself.
1065 _gdk_xgrab_check_unmap (window,
1066 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1068 /* You can't simply unmap toplevel windows. */
1069 switch (private->window_type)
1071 case GDK_WINDOW_TOPLEVEL:
1072 case GDK_WINDOW_DIALOG:
1073 case GDK_WINDOW_TEMP: /* ? */
1074 gdk_window_withdraw (window);
1078 case GDK_WINDOW_FOREIGN:
1079 case GDK_WINDOW_ROOT:
1080 case GDK_WINDOW_CHILD:
1084 if (!private->destroyed)
1086 if (GDK_WINDOW_IS_MAPPED (window))
1087 gdk_synthesize_window_state (window,
1089 GDK_WINDOW_STATE_WITHDRAWN);
1091 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1093 _gdk_window_clear_update_area (window);
1095 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1096 GDK_WINDOW_XID (window));
1101 * gdk_window_withdraw:
1102 * @window: a toplevel #GdkWindow
1104 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1105 * Normally done automatically by gtk_widget_hide() called on a #GtkWindow.
1109 gdk_window_withdraw (GdkWindow *window)
1111 GdkWindowObject *private;
1113 g_return_if_fail (window != NULL);
1115 private = (GdkWindowObject*) window;
1116 if (!private->destroyed)
1118 if (GDK_WINDOW_IS_MAPPED (window))
1119 gdk_synthesize_window_state (window,
1121 GDK_WINDOW_STATE_WITHDRAWN);
1123 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1125 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1126 GDK_WINDOW_XID (window), 0);
1132 * @window: a #GdkWindow
1133 * @x: X coordinate relative to window's parent
1134 * @y: Y coordinate relative to window's parent
1136 * Repositions a window relative to its parent window.
1137 * For toplevel windows, window managers may ignore or modify the move;
1138 * you should probably use gtk_window_move() on a #GtkWindow widget
1139 * anyway, instead of using GDK functions. For child windows,
1140 * the move will reliably succeed.
1142 * If you're also planning to resize the window, use gdk_window_move_resize()
1143 * to both move and resize simultaneously, for a nicer visual effect.
1147 gdk_window_move (GdkWindow *window,
1151 GdkWindowObject *private = (GdkWindowObject *)window;
1152 GdkWindowImplX11 *impl;
1154 g_return_if_fail (window != NULL);
1155 g_return_if_fail (GDK_IS_WINDOW (window));
1157 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1159 if (!GDK_WINDOW_DESTROYED (window))
1161 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1162 _gdk_window_move_resize_child (window, x, y,
1163 impl->width, impl->height);
1166 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1167 GDK_WINDOW_XID (window),
1174 * gdk_window_resize:
1175 * @window: a #GdkWindow
1176 * @width: new width of the window
1177 * @height: new height of the window
1179 * Resizes @window; for toplevel windows, asks the window manager to resize
1180 * the window. The window manager may not allow the resize. When using GTK+,
1181 * use gtk_window_resize() instead of this low-level GDK function.
1183 * Windows may not be resized below 1x1.
1185 * If you're also planning to move the window, use gdk_window_move_resize()
1186 * to both move and resize simultaneously, for a nicer visual effect.
1190 gdk_window_resize (GdkWindow *window,
1194 GdkWindowObject *private;
1196 g_return_if_fail (window != NULL);
1197 g_return_if_fail (GDK_IS_WINDOW (window));
1204 private = (GdkWindowObject*) window;
1206 if (!GDK_WINDOW_DESTROYED (window))
1208 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1209 _gdk_window_move_resize_child (window, private->x, private->y,
1213 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1215 if (width != impl->width || height != impl->height)
1216 private->resize_count += 1;
1218 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1219 GDK_WINDOW_XID (window),
1226 * gdk_window_move_resize:
1227 * @window: a #GdkWindow
1228 * @x: new X position relative to window's parent
1229 * @y: new Y position relative to window's parent
1231 * @height: new height
1233 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1234 * except that both operations are performed at once, avoiding strange
1235 * visual effects. (i.e. the user may be able to see the window first
1236 * move, then resize, if you don't use gdk_window_move_resize().)
1240 gdk_window_move_resize (GdkWindow *window,
1246 GdkWindowObject *private;
1248 g_return_if_fail (window != NULL);
1249 g_return_if_fail (GDK_IS_WINDOW (window));
1256 private = (GdkWindowObject*) window;
1258 if (!GDK_WINDOW_DESTROYED (window))
1260 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1261 _gdk_window_move_resize_child (window, x, y, width, height);
1264 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1266 if (width != impl->width || height != impl->height)
1267 private->resize_count += 1;
1269 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1270 GDK_WINDOW_XID (window),
1271 x, y, width, height);
1277 * gdk_window_reparent:
1278 * @window: a #GdkWindow
1279 * @new_parent: new parent to move @window into
1280 * @x: X location inside the new parent
1281 * @y: Y location inside the new parent
1283 * Reparents @window into the given @new_parent. The window being
1284 * reparented will be unmapped as a side effect.
1288 gdk_window_reparent (GdkWindow *window,
1289 GdkWindow *new_parent,
1293 GdkDisplay *display;
1294 GdkWindowObject *window_private;
1295 GdkWindowObject *parent_private;
1296 GdkWindowObject *old_parent_private;
1298 g_return_if_fail (window != NULL);
1299 g_return_if_fail (GDK_IS_WINDOW (window));
1300 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1301 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1304 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1306 display = GDK_WINDOW_DISPLAY (window);
1308 window_private = (GdkWindowObject*) window;
1309 old_parent_private = (GdkWindowObject*)window_private->parent;
1310 parent_private = (GdkWindowObject*) new_parent;
1312 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1313 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1314 GDK_WINDOW_XID (window),
1315 GDK_WINDOW_XID (new_parent),
1318 window_private->x = x;
1319 window_private->y = y;
1321 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1324 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1325 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1327 window_private->parent = (GdkWindowObject *)new_parent;
1329 /* Switch the window type as appropriate */
1331 switch (GDK_WINDOW_TYPE (new_parent))
1333 case GDK_WINDOW_ROOT:
1334 case GDK_WINDOW_FOREIGN:
1335 /* Now a toplevel */
1336 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1337 set_wm_protocols (window);
1339 case GDK_WINDOW_TOPLEVEL:
1340 case GDK_WINDOW_CHILD:
1341 case GDK_WINDOW_DIALOG:
1342 case GDK_WINDOW_TEMP:
1343 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1344 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1346 /* If we were being sophisticated, we'd save the old window type
1347 * here, and restore it if we were reparented back to the
1348 * toplevel. However, the difference between different types
1349 * of toplevels only really matters on creation anyways.
1351 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1355 if (old_parent_private)
1356 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1358 if ((old_parent_private &&
1359 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1360 (!old_parent_private && parent_private->guffaw_gravity))
1361 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1363 parent_private->children = g_list_prepend (parent_private->children, window);
1364 _gdk_window_init_position (GDK_WINDOW (window_private));
1368 _gdk_windowing_window_clear_area (GdkWindow *window,
1374 g_return_if_fail (window != NULL);
1375 g_return_if_fail (GDK_IS_WINDOW (window));
1377 if (!GDK_WINDOW_DESTROYED (window))
1378 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1379 x, y, width, height, False);
1383 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1389 g_return_if_fail (window != NULL);
1390 g_return_if_fail (GDK_IS_WINDOW (window));
1392 if (!GDK_WINDOW_DESTROYED (window))
1393 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1394 x, y, width, height, True);
1400 * @window: a #GdkWindow
1402 * Raises @window to the top of the Z-order (stacking order), so that
1403 * other windows with the same parent window appear below @window.
1404 * If @window is a toplevel, the window manager may choose to deny the
1405 * request to move the window in the Z-order, gdk_window_raise() only
1406 * requests the restack, does not guarantee it.
1410 gdk_window_raise (GdkWindow *window)
1412 g_return_if_fail (window != NULL);
1413 g_return_if_fail (GDK_IS_WINDOW (window));
1415 if (!GDK_WINDOW_DESTROYED (window))
1416 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1421 * @window: a #GdkWindow
1423 * Lowers @window to the bottom of the Z-order (stacking order), so that
1424 * other windows with the same parent window appear above @window.
1425 * If @window is a toplevel, the window manager may choose to deny the
1426 * request to move the window in the Z-order, gdk_window_lower() only
1427 * requests the restack, does not guarantee it.
1429 * Note that gdk_window_show() raises the window again, so don't call this
1430 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1434 gdk_window_lower (GdkWindow *window)
1436 g_return_if_fail (window != NULL);
1437 g_return_if_fail (GDK_IS_WINDOW (window));
1439 if (!GDK_WINDOW_DESTROYED (window))
1440 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1445 * @window: a #GdkWindow
1446 * @timestamp: timestamp of the event triggering the window focus
1448 * Sets keyboard focus to @window. If @window is not onscreen this
1449 * will not work. In most cases, gtk_window_present() should be used on
1450 * a #GtkWindow, rather than calling this function.
1454 gdk_window_focus (GdkWindow *window,
1457 g_return_if_fail (GDK_IS_WINDOW (window));
1459 if (GDK_WINDOW_DESTROYED (window))
1462 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1463 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1467 xev.xclient.type = ClientMessage;
1468 xev.xclient.serial = 0;
1469 xev.xclient.send_event = True;
1470 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1471 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1472 "_NET_ACTIVE_WINDOW");
1473 xev.xclient.format = 32;
1474 xev.xclient.data.l[0] = 0;
1476 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1477 SubstructureRedirectMask | SubstructureNotifyMask,
1482 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1484 /* There is no way of knowing reliably whether we are viewable so we need
1485 * to trap errors so we don't cause a BadMatch.
1487 gdk_error_trap_push ();
1488 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1489 GDK_WINDOW_XWINDOW (window),
1492 XSync (GDK_WINDOW_XDISPLAY (window), False);
1493 gdk_error_trap_pop ();
1498 * gdk_window_set_hints:
1499 * @window: a #GdkWindow
1500 * @x: ignored field, does not matter
1501 * @y: ignored field, does not matter
1502 * @min_width: minimum width hint
1503 * @min_height: minimum height hint
1504 * @max_width: max width hint
1505 * @max_height: max height hint
1506 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1508 * This function is broken and useless and you should ignore it.
1509 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1510 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1511 * depending on what you're trying to do.
1513 * If using GDK directly, use gdk_window_set_geometry_hints().
1517 gdk_window_set_hints (GdkWindow *window,
1526 XSizeHints size_hints;
1528 g_return_if_fail (window != NULL);
1529 g_return_if_fail (GDK_IS_WINDOW (window));
1531 if (GDK_WINDOW_DESTROYED (window))
1534 size_hints.flags = 0;
1536 if (flags & GDK_HINT_POS)
1538 size_hints.flags |= PPosition;
1543 if (flags & GDK_HINT_MIN_SIZE)
1545 size_hints.flags |= PMinSize;
1546 size_hints.min_width = min_width;
1547 size_hints.min_height = min_height;
1550 if (flags & GDK_HINT_MAX_SIZE)
1552 size_hints.flags |= PMaxSize;
1553 size_hints.max_width = max_width;
1554 size_hints.max_height = max_height;
1557 /* FIXME: Would it be better to delete this property if
1558 * flags == 0? It would save space on the server
1560 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1561 GDK_WINDOW_XID (window),
1566 * gdk_window_set_type_hint:
1567 * @window: A #GdkWindow
1568 * @hint: A hint of the function this window will have
1570 * The application can use this call to provide a hint to the window
1571 * manager about the functionality of a window. The window manager
1572 * can use this information when determining the decoration and behaviour
1575 * The hint must be set before the window is mapped.
1578 gdk_window_set_type_hint (GdkWindow *window,
1579 GdkWindowTypeHint hint)
1581 GdkDisplay *display;
1584 g_return_if_fail (window != NULL);
1585 g_return_if_fail (GDK_IS_WINDOW (window));
1587 if (GDK_WINDOW_DESTROYED (window))
1590 display = gdk_drawable_get_display (window);
1594 case GDK_WINDOW_TYPE_HINT_DIALOG:
1595 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1597 case GDK_WINDOW_TYPE_HINT_MENU:
1598 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1600 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1601 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1604 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1606 case GDK_WINDOW_TYPE_HINT_NORMAL:
1607 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1611 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1612 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1613 XA_ATOM, 32, PropModeReplace,
1614 (guchar *)&atom, 1);
1619 gdk_wmspec_change_state (gboolean add,
1624 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1627 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1628 #define _NET_WM_STATE_ADD 1 /* add/set property */
1629 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1631 xev.xclient.type = ClientMessage;
1632 xev.xclient.serial = 0;
1633 xev.xclient.send_event = True;
1634 xev.xclient.window = GDK_WINDOW_XID (window);
1635 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1636 xev.xclient.format = 32;
1637 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1638 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1639 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1641 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1642 SubstructureRedirectMask | SubstructureNotifyMask,
1647 * gdk_window_set_modal_hint:
1648 * @window: A #GdkWindow
1649 * @modal: TRUE if the window is modal, FALSE otherwise.
1651 * The application can use this hint to tell the window manager
1652 * that a certain window has modal behaviour. The window manager
1653 * can use this information to handle modal windows in a special
1656 * You should only use this on windows for which you have
1657 * previously called #gdk_window_set_transient_for()
1660 gdk_window_set_modal_hint (GdkWindow *window,
1663 GdkWindowObject *private;
1665 g_return_if_fail (window != NULL);
1666 g_return_if_fail (GDK_IS_WINDOW (window));
1668 if (GDK_WINDOW_DESTROYED (window))
1671 private = (GdkWindowObject*) window;
1673 private->modal_hint = modal;
1675 if (GDK_WINDOW_IS_MAPPED (window))
1676 gdk_wmspec_change_state (modal, window,
1677 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1682 * gdk_window_set_geometry_hints:
1683 * @window: a #GdkWindow
1684 * @geometry: geometry hints
1685 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1687 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1688 * are set, hints not flagged in @geom_mask are unset.
1689 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1693 gdk_window_set_geometry_hints (GdkWindow *window,
1694 GdkGeometry *geometry,
1695 GdkWindowHints geom_mask)
1697 XSizeHints size_hints;
1699 g_return_if_fail (window != NULL);
1700 g_return_if_fail (GDK_IS_WINDOW (window));
1702 if (GDK_WINDOW_DESTROYED (window))
1705 size_hints.flags = 0;
1707 if (geom_mask & GDK_HINT_POS)
1709 size_hints.flags |= PPosition;
1710 /* We need to initialize the following obsolete fields because KWM
1711 * apparently uses these fields if they are non-zero.
1718 if (geom_mask & GDK_HINT_USER_POS)
1720 size_hints.flags |= USPosition;
1723 if (geom_mask & GDK_HINT_USER_SIZE)
1725 size_hints.flags |= USSize;
1728 if (geom_mask & GDK_HINT_MIN_SIZE)
1730 size_hints.flags |= PMinSize;
1731 size_hints.min_width = geometry->min_width;
1732 size_hints.min_height = geometry->min_height;
1735 if (geom_mask & GDK_HINT_MAX_SIZE)
1737 size_hints.flags |= PMaxSize;
1738 size_hints.max_width = MAX (geometry->max_width, 1);
1739 size_hints.max_height = MAX (geometry->max_height, 1);
1742 if (geom_mask & GDK_HINT_BASE_SIZE)
1744 size_hints.flags |= PBaseSize;
1745 size_hints.base_width = geometry->base_width;
1746 size_hints.base_height = geometry->base_height;
1749 if (geom_mask & GDK_HINT_RESIZE_INC)
1751 size_hints.flags |= PResizeInc;
1752 size_hints.width_inc = geometry->width_inc;
1753 size_hints.height_inc = geometry->height_inc;
1756 if (geom_mask & GDK_HINT_ASPECT)
1758 size_hints.flags |= PAspect;
1759 if (geometry->min_aspect <= 1)
1761 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1762 size_hints.min_aspect.y = 65536;
1766 size_hints.min_aspect.x = 65536;
1767 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1769 if (geometry->max_aspect <= 1)
1771 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1772 size_hints.max_aspect.y = 65536;
1776 size_hints.max_aspect.x = 65536;
1777 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1781 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1783 size_hints.flags |= PWinGravity;
1784 size_hints.win_gravity = geometry->win_gravity;
1787 /* FIXME: Would it be better to delete this property if
1788 * geom_mask == 0? It would save space on the server
1790 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1791 GDK_WINDOW_XID (window),
1796 gdk_window_get_geometry_hints (GdkWindow *window,
1797 GdkGeometry *geometry,
1798 GdkWindowHints *geom_mask)
1800 XSizeHints size_hints;
1801 glong junk_size_mask = 0;
1803 g_return_if_fail (GDK_IS_WINDOW (window));
1804 g_return_if_fail (geometry != NULL);
1805 g_return_if_fail (geom_mask != NULL);
1809 if (GDK_WINDOW_DESTROYED (window))
1812 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1813 GDK_WINDOW_XID (window),
1818 if (size_hints.flags & PMinSize)
1820 *geom_mask |= GDK_HINT_MIN_SIZE;
1821 geometry->min_width = size_hints.min_width;
1822 geometry->min_height = size_hints.min_height;
1825 if (size_hints.flags & PMaxSize)
1827 *geom_mask |= GDK_HINT_MAX_SIZE;
1828 geometry->max_width = MAX (size_hints.max_width, 1);
1829 geometry->max_height = MAX (size_hints.max_height, 1);
1832 if (size_hints.flags & PResizeInc)
1834 *geom_mask |= GDK_HINT_RESIZE_INC;
1835 geometry->width_inc = size_hints.width_inc;
1836 geometry->height_inc = size_hints.height_inc;
1839 if (size_hints.flags & PAspect)
1841 *geom_mask |= GDK_HINT_ASPECT;
1843 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1844 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1847 if (size_hints.flags & PWinGravity)
1849 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1850 geometry->win_gravity = size_hints.win_gravity;
1855 utf8_is_latin1 (const gchar *str)
1857 const char *p = str;
1861 gunichar ch = g_utf8_get_char (p);
1866 p = g_utf8_next_char (p);
1872 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
1873 * convertable to STRING, otherwise, set it as compound text
1876 set_text_property (GdkWindow *window,
1878 const gchar *utf8_str)
1880 guchar *prop_text = NULL;
1885 if (utf8_is_latin1 (utf8_str))
1887 prop_type = XA_STRING;
1888 prop_text = gdk_utf8_to_string_target (utf8_str);
1889 prop_length = prop_text ? strlen (prop_text) : 0;
1896 gdk_utf8_to_compound_text_for_display (gdk_drawable_get_display (window),
1897 utf8_str, &gdk_type, &prop_format,
1898 &prop_text, &prop_length);
1899 prop_type = gdk_x11_atom_to_xatom_for_display
1900 (GDK_WINDOW_DISPLAY (window), gdk_type);
1905 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1906 GDK_WINDOW_XID (window),
1908 prop_type, prop_format,
1909 PropModeReplace, prop_text,
1917 * gdk_window_set_title:
1918 * @window: a #GdkWindow
1919 * @title: title of @window
1921 * Sets the title of a toplevel window, to be displayed in the titlebar.
1922 * If you haven't explicitly set the icon name for the window
1923 * (using gdk_window_set_icon_name()), the icon name will be set to
1924 * @title as well. @title must be in UTF-8 encoding (as with all
1925 * user-readable strings in GDK/GTK+). @title may not be %NULL.
1928 gdk_window_set_title (GdkWindow *window,
1931 GdkDisplay *display;
1933 g_return_if_fail (window != NULL);
1934 g_return_if_fail (GDK_IS_WINDOW (window));
1935 g_return_if_fail (title != NULL);
1937 if (GDK_WINDOW_DESTROYED (window))
1940 display = gdk_drawable_get_display (window);
1942 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1943 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
1944 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
1945 PropModeReplace, title, strlen (title));
1947 set_text_property (window,
1948 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
1951 if (!gdk_window_icon_name_set (window))
1953 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1954 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
1955 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
1956 PropModeReplace, title, strlen (title));
1958 set_text_property (window,
1959 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
1965 * gdk_window_set_role:
1966 * @window: a #GdkWindow
1967 * @role: a string indicating its role
1969 * When using GTK+, typically you should use gtk_window_set_role() instead
1970 * of this low-level function.
1972 * The window manager and session manager use a window's role to
1973 * distinguish it from other kinds of window in the same application.
1974 * When an application is restarted after being saved in a previous
1975 * session, all windows with the same title and role are treated as
1976 * interchangeable. So if you have two windows with the same title
1977 * that should be distinguished for session management purposes, you
1978 * should set the role on those windows. It doesn't matter what string
1979 * you use for the role, as long as you have a different role for each
1980 * non-interchangeable kind of window.
1984 gdk_window_set_role (GdkWindow *window,
1987 GdkDisplay *display;
1989 g_return_if_fail (window != NULL);
1990 g_return_if_fail (GDK_IS_WINDOW (window));
1992 display = gdk_drawable_get_display (window);
1994 if (!GDK_WINDOW_DESTROYED (window))
1997 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1998 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
1999 XA_STRING, 8, PropModeReplace, role, strlen (role));
2001 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2002 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2007 * gdk_window_set_transient_for:
2008 * @window: a toplevel #GdkWindow
2009 * @parent: another toplevel #GdkWindow
2011 * Indicates to the window manager that @window is a transient dialog
2012 * associated with the application window @parent. This allows the
2013 * window manager to do things like center @window on @parent and
2014 * keep @window above @parent.
2016 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2021 gdk_window_set_transient_for (GdkWindow *window,
2024 GdkWindowObject *private;
2025 GdkWindowObject *parent_private;
2027 g_return_if_fail (window != NULL);
2028 g_return_if_fail (GDK_IS_WINDOW (window));
2030 private = (GdkWindowObject*) window;
2031 parent_private = (GdkWindowObject*) parent;
2033 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2034 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2035 GDK_WINDOW_XID (window),
2036 GDK_WINDOW_XID (parent));
2040 * gdk_window_set_background:
2041 * @window: a #GdkWindow
2042 * @color: an allocated #GdkColor
2044 * Sets the background color of @window. (However, when using GTK+,
2045 * set the background of a widget with gtk_widget_modify_bg() - if
2046 * you're an application - or gtk_style_set_background() - if you're
2047 * implementing a custom widget.)
2049 * The @color must be allocated; gdk_rgb_find_color() is the best way
2050 * to allocate a color.
2052 * See also gdk_window_set_back_pixmap().
2056 gdk_window_set_background (GdkWindow *window,
2059 GdkWindowObject *private = (GdkWindowObject *)window;
2061 g_return_if_fail (window != NULL);
2062 g_return_if_fail (GDK_IS_WINDOW (window));
2064 if (!GDK_WINDOW_DESTROYED (window))
2065 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2066 GDK_WINDOW_XID (window), color->pixel);
2068 private->bg_color = *color;
2070 if (private->bg_pixmap &&
2071 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2072 private->bg_pixmap != GDK_NO_BG)
2073 gdk_pixmap_unref (private->bg_pixmap);
2075 private->bg_pixmap = NULL;
2079 * gdk_window_set_back_pixmap:
2080 * @window: a #GdkWindow
2081 * @pixmap: a #GdkPixmap, or %NULL
2082 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2084 * Sets the background pixmap of @window. May also be used to set a background of
2085 * "None" on @window, by setting a background pixmap of %NULL.
2086 * A background pixmap will be tiled, positioning the first tile at the origin of
2087 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2088 * origin of the parent window (useful to align tiles in a parent with tiles
2091 * A background pixmap of %NULL means that the window will have no
2092 * background. A window with no background will never have its
2093 * background filled by the windowing system, instead the window will
2094 * contain whatever pixels were already in the corresponding area of
2097 * The windowing system will normally fill a window with its background
2098 * when the window is obscured then exposed, and when you call
2099 * gdk_window_clear().
2103 gdk_window_set_back_pixmap (GdkWindow *window,
2105 gboolean parent_relative)
2107 GdkWindowObject *private = (GdkWindowObject *)window;
2110 g_return_if_fail (window != NULL);
2111 g_return_if_fail (GDK_IS_WINDOW (window));
2112 g_return_if_fail (pixmap == NULL || !parent_relative);
2113 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2115 if (private->bg_pixmap &&
2116 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2117 private->bg_pixmap != GDK_NO_BG)
2118 gdk_pixmap_unref (private->bg_pixmap);
2120 if (parent_relative)
2122 xpixmap = ParentRelative;
2123 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2129 gdk_pixmap_ref (pixmap);
2130 private->bg_pixmap = pixmap;
2131 xpixmap = GDK_PIXMAP_XID (pixmap);
2136 private->bg_pixmap = GDK_NO_BG;
2140 if (!GDK_WINDOW_DESTROYED (window))
2141 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2142 GDK_WINDOW_XID (window), xpixmap);
2146 * gdk_window_set_cursor:
2147 * @window: a #GdkWindow
2150 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2151 * gdk_cursor_new_from_pixmap() to create the cursor.
2152 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2153 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2154 * to gdk_window_set_cursor() means that @window will use the cursor of
2155 * its parent window. Most windows should use this default.
2159 gdk_window_set_cursor (GdkWindow *window,
2162 GdkCursorPrivate *cursor_private;
2165 g_return_if_fail (window != NULL);
2166 g_return_if_fail (GDK_IS_WINDOW (window));
2168 cursor_private = (GdkCursorPrivate*) cursor;
2173 xcursor = cursor_private->xcursor;
2175 if (!GDK_WINDOW_DESTROYED (window))
2176 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2177 GDK_WINDOW_XID (window),
2182 * gdk_window_get_geometry:
2183 * @window: a #GdkWindow
2184 * @x: return location for X coordinate of window (relative to its parent)
2185 * @y: return location for Y coordinate of window (relative to its parent)
2186 * @width: return location for width of window
2187 * @height: return location for height of window
2188 * @depth: return location for bit depth of window
2190 * Any of the return location arguments to this function may be %NULL,
2191 * if you aren't interested in getting the value of that field.
2193 * The X and Y coordinates returned are relative to the parent window
2194 * of @window, which for toplevels usually means relative to the
2195 * window decorations (titlebar, etc.) rather than relative to the
2196 * root window (screen-size background window).
2198 * On the X11 platform, the geometry is obtained from the X server,
2199 * so reflects the latest position of @window; this may be out-of-sync
2200 * with the position of @window delivered in the most-recently-processed
2201 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2202 * position from the most recent configure event.
2206 gdk_window_get_geometry (GdkWindow *window,
2218 guint tborder_width;
2221 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2225 GDK_NOTE (MULTIHEAD,
2226 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2227 window = gdk_screen_get_root_window ((gdk_get_default_screen ()));
2230 if (!GDK_WINDOW_DESTROYED (window))
2232 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2233 GDK_WINDOW_XID (window),
2234 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2250 * gdk_window_get_origin:
2251 * @window: a #GdkWindow
2252 * @x: return location for X coordinate
2253 * @y: return location for Y coordinate
2255 * Obtains the position of a window in root window coordinates.
2256 * (Compare with gdk_window_get_position() and
2257 * gdk_window_get_geometry() which return the position of a window
2258 * relative to its parent window.)
2260 * Return value: not meaningful, ignore
2263 gdk_window_get_origin (GdkWindow *window,
2272 g_return_val_if_fail (window != NULL, 0);
2274 if (!GDK_WINDOW_DESTROYED (window))
2276 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2277 GDK_WINDOW_XID (window),
2278 GDK_WINDOW_XROOTWIN (window),
2294 * gdk_window_get_deskrelative_origin:
2295 * @window: a #GdkWindow
2296 * @x: return location for X coordinate
2297 * @y: return location for Y coordinate
2299 * This gets the origin of a #GdkWindow relative to
2300 * an Enlightenment-window-manager desktop. As long as you don't
2301 * assume that the user's desktop/workspace covers the entire
2302 * root window (i.e. you don't assume that the desktop begins
2303 * at root window coordinate 0,0) this function is not necessary.
2304 * It's deprecated for that reason.
2306 * Return value: not meaningful
2309 gdk_window_get_deskrelative_origin (GdkWindow *window,
2313 gboolean return_val = FALSE;
2314 gint num_children, format_return;
2315 Window win, *child, parent, root;
2320 gulong number_return, bytes_after_return;
2321 guchar *data_return;
2323 g_return_val_if_fail (window != NULL, 0);
2324 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2326 if (!GDK_WINDOW_DESTROYED (window))
2328 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2329 "ENLIGHTENMENT_DESKTOP");
2330 win = GDK_WINDOW_XID (window);
2332 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2333 &child, (unsigned int *)&num_children))
2335 if ((child) && (num_children > 0))
2347 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2348 False, XA_CARDINAL, &type_return, &format_return,
2349 &number_return, &bytes_after_return, &data_return);
2351 if (type_return == XA_CARDINAL)
2353 XFree (data_return);
2358 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2359 GDK_WINDOW_XID (window),
2374 * gdk_window_get_root_origin:
2375 * @window: a #GdkWindow
2376 * @x: return location for X position of window frame
2377 * @y: return location for Y position of window frame
2379 * Obtains the top-left corner of the window manager frame in root
2380 * window coordinates.
2384 gdk_window_get_root_origin (GdkWindow *window,
2390 g_return_if_fail (GDK_IS_WINDOW (window));
2392 gdk_window_get_frame_extents (window, &rect);
2402 * gdk_window_get_frame_extents:
2403 * @window: a #GdkWindow
2404 * @rect: rectangle to fill with bounding box of the window frame
2406 * Obtains the bounding box of the window, including window manager
2407 * titlebar/borders if any. The frame position is given in root window
2408 * coordinates. To get the position of the window itself (rather than
2409 * the frame) in root window coordinates, use gdk_window_get_origin().
2413 gdk_window_get_frame_extents (GdkWindow *window,
2416 GdkWindowObject *private;
2421 unsigned int nchildren;
2423 g_return_if_fail (GDK_IS_WINDOW (window));
2424 g_return_if_fail (rect != NULL);
2426 private = (GdkWindowObject*) window;
2433 if (GDK_WINDOW_DESTROYED (window))
2436 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2437 private = (GdkWindowObject*) private->parent;
2438 if (GDK_WINDOW_DESTROYED (window))
2441 xparent = GDK_WINDOW_XID (window);
2445 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2447 &children, &nchildren))
2453 while (xparent != root);
2455 if (xparent == root)
2457 unsigned int ww, wh, wb, wd;
2460 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2471 _gdk_windowing_window_get_pointer (GdkWindow *window,
2474 GdkModifierType *mask)
2476 GdkWindow *return_val;
2482 unsigned int xmask = 0;
2483 gint xoffset, yoffset;
2485 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2489 GDK_NOTE (MULTIHEAD,
2490 g_message ("_gdk_windowing_window_get_pointer(): window arg is need for multihead safe operation"));
2491 window = gdk_screen_get_root_window (gdk_get_default_screen ());
2494 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2497 if (!GDK_WINDOW_DESTROYED (window) &&
2498 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2499 GDK_WINDOW_XID (window),
2500 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2503 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
2507 *x = winx + xoffset;
2509 *y = winy + yoffset;
2517 _gdk_windowing_window_at_pointer (GdkScreen *screen,
2524 Window xwindow_last = 0;
2526 int rootx = -1, rooty = -1;
2530 xwindow = GDK_SCREEN_XROOTWIN (screen);
2531 xdisplay = GDK_SCREEN_XDISPLAY (screen);
2533 XGrabServer (xdisplay);
2536 xwindow_last = xwindow;
2537 XQueryPointer (xdisplay, xwindow,
2538 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
2540 XUngrabServer (xdisplay);
2542 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
2545 *win_x = window ? winx : -1;
2547 *win_y = window ? winy : -1;
2553 * gdk_window_get_events:
2554 * @window: a #GdkWindow
2556 * Gets the event mask for @window. See gdk_window_set_events().
2558 * Return value: event mask for @window
2561 gdk_window_get_events (GdkWindow *window)
2563 XWindowAttributes attrs;
2564 GdkEventMask event_mask;
2566 g_return_val_if_fail (window != NULL, 0);
2567 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2569 if (GDK_WINDOW_DESTROYED (window))
2573 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2574 GDK_WINDOW_XID (window),
2577 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2578 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2585 * gdk_window_set_events:
2586 * @window: a #GdkWindow
2587 * @event_mask: event mask for @window
2589 * The event mask for a window determines which events will be reported
2590 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2591 * means the window should report button press events. The event mask
2592 * is the bitwise OR of values from the #GdkEventMask enumeration.
2596 gdk_window_set_events (GdkWindow *window,
2597 GdkEventMask event_mask)
2602 g_return_if_fail (window != NULL);
2603 g_return_if_fail (GDK_IS_WINDOW (window));
2605 if (!GDK_WINDOW_DESTROYED (window))
2607 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2608 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2609 for (i = 0; i < _gdk_nenvent_masks; i++)
2611 if (event_mask & (1 << (i + 1)))
2612 xevent_mask |= _gdk_event_mask_table[i];
2615 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2616 GDK_WINDOW_XID (window),
2622 gdk_window_add_colormap_windows (GdkWindow *window)
2624 GdkWindow *toplevel;
2625 Window *old_windows;
2626 Window *new_windows;
2629 g_return_if_fail (window != NULL);
2630 g_return_if_fail (GDK_IS_WINDOW (window));
2632 toplevel = gdk_window_get_toplevel (window);
2633 if (GDK_WINDOW_DESTROYED (toplevel))
2637 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2638 GDK_WINDOW_XID (toplevel),
2639 &old_windows, &count))
2644 for (i = 0; i < count; i++)
2645 if (old_windows[i] == GDK_WINDOW_XID (window))
2647 XFree (old_windows);
2651 new_windows = g_new (Window, count + 1);
2653 for (i = 0; i < count; i++)
2654 new_windows[i] = old_windows[i];
2655 new_windows[count] = GDK_WINDOW_XID (window);
2657 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2658 GDK_WINDOW_XID (toplevel),
2659 new_windows, count + 1);
2661 g_free (new_windows);
2663 XFree (old_windows);
2667 gdk_window_have_shape_ext (GdkDisplay *display)
2669 enum { UNKNOWN, NO, YES };
2670 GdkDisplayX11 *display_x11;
2672 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2674 display_x11 = GDK_DISPLAY_X11 (display);
2676 if (display_x11->have_shape == UNKNOWN)
2679 if (XQueryExtension (display_x11->xdisplay, "SHAPE", &ignore, &ignore, &ignore))
2680 display_x11->have_shape = YES;
2682 display_x11->have_shape = NO;
2685 return (display_x11->have_shape == YES);
2688 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2691 * This needs the X11 shape extension.
2692 * If not available, shaped windows will look
2693 * ugly, but programs still work. Stefan Wille
2696 * gdk_window_shape_combine_mask:
2697 * @window: a #GdkWindow
2699 * @x: X position of shape mask with respect to @window
2700 * @y: Y position of shape mask with respect to @window
2702 * Applies a shape mask to @window. Pixels in @window corresponding to
2703 * set bits in the @mask will be visible; pixels in @window
2704 * corresponding to unset bits in the @mask will be transparent. This
2705 * gives a non-rectangular window.
2707 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2708 * parameters are not used.
2710 * On the X11 platform, this uses an X server extension which is
2711 * widely available on most common platforms, but not available on
2712 * very old X servers, and occasionally the implementation will be
2713 * buggy. On servers without the shape extension, this function
2718 gdk_window_shape_combine_mask (GdkWindow *window,
2723 gint xoffset, yoffset;
2725 g_return_if_fail (window != NULL);
2726 g_return_if_fail (GDK_IS_WINDOW (window));
2728 #ifdef HAVE_SHAPE_EXT
2729 if (GDK_WINDOW_DESTROYED (window))
2732 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2734 if (xoffset != 0 || yoffset != 0)
2736 WARN_SHAPE_TOO_BIG ();
2740 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2744 pixmap = GDK_PIXMAP_XID (mask);
2753 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2754 GDK_WINDOW_XID (window),
2760 #endif /* HAVE_SHAPE_EXT */
2764 * gdk_window_shape_combine_region:
2765 * @window: a #GdkWindow
2766 * @shape_region: region of window to be non-transparent
2767 * @offset_x: X position of @shape_region in @window coordinates
2768 * @offset_y: Y position of @shape_region in @window coordinates
2770 * Makes pixels in @window outside @shape_region be transparent,
2771 * so that the window may be nonrectangular. See also
2772 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2774 * If @shape_region is %NULL, the shape will be unset, so the whole
2775 * window will be opaque again. @offset_x and @offset_y are ignored
2776 * if @shape_region is %NULL.
2778 * On the X11 platform, this uses an X server extension which is
2779 * widely available on most common platforms, but not available on
2780 * very old X servers, and occasionally the implementation will be
2781 * buggy. On servers without the shape extension, this function
2786 gdk_window_shape_combine_region (GdkWindow *window,
2787 GdkRegion *shape_region,
2791 gint xoffset, yoffset;
2793 g_return_if_fail (GDK_IS_WINDOW (window));
2795 #ifdef HAVE_SHAPE_EXT
2796 if (GDK_WINDOW_DESTROYED (window))
2799 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2801 if (xoffset != 0 || yoffset != 0)
2803 WARN_SHAPE_TOO_BIG ();
2807 if (shape_region == NULL)
2809 /* Use NULL mask to unset the shape */
2810 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2814 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2817 XRectangle *xrects = NULL;
2819 _gdk_region_get_xrectangles (shape_region,
2823 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2824 GDK_WINDOW_XID (window),
2833 #endif /* HAVE_SHAPE_EXT */
2838 * gdk_window_set_override_redirect:
2839 * @window: a #GdkWindow
2840 * @override_redirect: %TRUE if window should be override redirect
2842 * An override redirect window is not under the control of the window manager.
2843 * This means it won't have a titlebar, won't be minimizable, etc. - it will
2844 * be entirely under the control of the application. The window manager
2845 * can't see the override redirect window at all.
2847 * Override redirect should only be used for short-lived temporary
2848 * windows, such as popup menus. #GtkMenu uses an override redirect
2849 * window in its implementation, for example.
2853 gdk_window_set_override_redirect (GdkWindow *window,
2854 gboolean override_redirect)
2856 XSetWindowAttributes attr;
2858 g_return_if_fail (window != NULL);
2859 g_return_if_fail (GDK_IS_WINDOW (window));
2861 if (!GDK_WINDOW_DESTROYED (window))
2863 attr.override_redirect = (override_redirect == FALSE)?False:True;
2864 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2865 GDK_WINDOW_XID (window),
2873 * gdk_window_set_icon_list:
2874 * @window: The #GdkWindow toplevel window to set the icon of.
2875 * @pixbufs: A list of pixbufs, of different sizes.
2877 * Sets a list of icons for the window. One of these will be used
2878 * to represent the window when it has been iconified. The icon is
2879 * usually shown in an icon box or some sort of task bar. Which icon
2880 * size is shown depends on the window manager. The window manager
2881 * can scale the icon but setting several size icons can give better
2882 * image quality since the window manager may only need to scale the
2883 * icon by a small amount or not at all.
2887 gdk_window_set_icon_list (GdkWindow *window,
2896 gint width, height, stride;
2899 GdkDisplay *display;
2901 g_return_if_fail (GDK_IS_WINDOW (window));
2903 if (GDK_WINDOW_DESTROYED (window))
2906 display = gdk_drawable_get_display (window);
2914 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
2916 width = gdk_pixbuf_get_width (pixbuf);
2917 height = gdk_pixbuf_get_height (pixbuf);
2919 size += 2 + width * height;
2921 l = g_list_next (l);
2924 data = g_malloc (size * sizeof (gulong));
2932 width = gdk_pixbuf_get_width (pixbuf);
2933 height = gdk_pixbuf_get_height (pixbuf);
2934 stride = gdk_pixbuf_get_rowstride (pixbuf);
2935 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
2940 pixels = gdk_pixbuf_get_pixels (pixbuf);
2942 for (y = 0; y < height; y++)
2944 for (x = 0; x < width; x++)
2948 r = pixels[y*stride + x*n_channels + 0];
2949 g = pixels[y*stride + x*n_channels + 1];
2950 b = pixels[y*stride + x*n_channels + 2];
2951 if (n_channels >= 4)
2952 a = pixels[y*stride + x*n_channels + 3];
2956 *p++ = a << 24 | r << 16 | g << 8 | b ;
2960 l = g_list_next (l);
2965 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2966 GDK_WINDOW_XID (window),
2967 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
2970 (guchar*) data, size);
2974 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
2975 GDK_WINDOW_XID (window),
2976 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
2983 * gdk_window_set_icon:
2984 * @window: a #GdkWindow
2985 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
2986 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
2987 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
2989 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
2990 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
2991 * and gtk_window_set_icon(). If those don't meet your needs, look at
2992 * gdk_window_set_icon_list(). Only if all those are too high-level do you
2993 * want to fall back to gdk_window_set_icon().
2997 gdk_window_set_icon (GdkWindow *window,
2998 GdkWindow *icon_window,
3004 g_return_if_fail (window != NULL);
3005 g_return_if_fail (GDK_IS_WINDOW (window));
3007 if (GDK_WINDOW_DESTROYED (window))
3010 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3011 GDK_WINDOW_XID (window));
3013 wm_hints = XAllocWMHints ();
3015 if (icon_window != NULL)
3017 wm_hints->flags |= IconWindowHint;
3018 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
3023 wm_hints->flags |= IconPixmapHint;
3024 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
3029 wm_hints->flags |= IconMaskHint;
3030 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
3033 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3034 GDK_WINDOW_XID (window), wm_hints);
3039 gdk_window_icon_name_set (GdkWindow *window)
3041 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3042 g_quark_from_static_string ("gdk-icon-name-set")));
3046 * gdk_window_set_icon_name:
3047 * @window: a #GdkWindow
3048 * @name: name of window while iconified (minimized)
3050 * Windows may have a name used while minimized, distinct from the
3051 * name they display in their titlebar. Most of the time this is a bad
3052 * idea from a user interface standpoint. But you can set such a name
3053 * with this function, if you like.
3057 gdk_window_set_icon_name (GdkWindow *window,
3060 GdkDisplay *display;
3062 g_return_if_fail (window != NULL);
3063 g_return_if_fail (GDK_IS_WINDOW (window));
3065 if (GDK_WINDOW_DESTROYED (window))
3068 display = gdk_drawable_get_display (window);
3070 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3071 GUINT_TO_POINTER (TRUE));
3073 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
3074 GDK_WINDOW_XID (window),
3075 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3076 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3077 PropModeReplace, name, strlen (name));
3079 set_text_property (window,
3080 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3085 * gdk_window_iconify:
3086 * @window: a #GdkWindow
3088 * Asks to iconify (minimize) @window. The window manager may choose
3089 * to ignore the request, but normally will honor it. Using
3090 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3094 gdk_window_iconify (GdkWindow *window)
3096 GdkWindowObject *private;
3098 g_return_if_fail (window != NULL);
3099 g_return_if_fail (GDK_IS_WINDOW (window));
3101 if (GDK_WINDOW_DESTROYED (window))
3104 private = (GdkWindowObject*) window;
3106 if (GDK_WINDOW_IS_MAPPED (window))
3108 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3109 GDK_WINDOW_XWINDOW (window),
3110 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3114 /* Flip our client side flag, the real work happens on map. */
3115 gdk_synthesize_window_state (window,
3117 GDK_WINDOW_STATE_ICONIFIED);
3122 * gdk_window_deiconify:
3123 * @window: a #GdkWindow
3125 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3126 * choose to ignore the request to deiconify. When using GTK+,
3127 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3128 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3129 * unminimizes it, and puts it on the current desktop.
3133 gdk_window_deiconify (GdkWindow *window)
3135 GdkWindowObject *private;
3137 g_return_if_fail (window != NULL);
3138 g_return_if_fail (GDK_IS_WINDOW (window));
3140 if (GDK_WINDOW_DESTROYED (window))
3143 private = (GdkWindowObject*) window;
3145 if (GDK_WINDOW_IS_MAPPED (window))
3147 gdk_window_show (window);
3151 /* Flip our client side flag, the real work happens on map. */
3152 gdk_synthesize_window_state (window,
3153 GDK_WINDOW_STATE_ICONIFIED,
3160 * @window: a toplevel #GdkWindow
3162 * "Pins" a window such that it's on all workspaces and does not scroll
3163 * with viewports, for window managers that have scrollable viewports.
3164 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3166 * On the X11 platform, this function depends on window manager
3167 * support, so may have no effect with many window managers. However,
3168 * GDK will do the best it can to convince the window manager to stick
3169 * the window. For window managers that don't support this operation,
3170 * there's nothing you can do to force it to happen.
3174 gdk_window_stick (GdkWindow *window)
3176 g_return_if_fail (GDK_IS_WINDOW (window));
3178 if (GDK_WINDOW_DESTROYED (window))
3181 if (GDK_WINDOW_IS_MAPPED (window))
3183 /* "stick" means stick to all desktops _and_ do not scroll with the
3184 * viewport. i.e. glue to the monitor glass in all cases.
3189 /* Request stick during viewport scroll */
3190 gdk_wmspec_change_state (TRUE, window,
3191 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3194 /* Request desktop 0xFFFFFFFF */
3195 xev.xclient.type = ClientMessage;
3196 xev.xclient.serial = 0;
3197 xev.xclient.send_event = True;
3198 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3199 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3200 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3202 xev.xclient.format = 32;
3204 xev.xclient.data.l[0] = 0xFFFFFFFF;
3206 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3207 SubstructureRedirectMask | SubstructureNotifyMask,
3212 /* Flip our client side flag, the real work happens on map. */
3213 gdk_synthesize_window_state (window,
3215 GDK_WINDOW_STATE_STICKY);
3220 * gdk_window_unstick:
3221 * @window: a toplevel #GdkWindow
3223 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3224 * and gtk_window_unstick().
3228 gdk_window_unstick (GdkWindow *window)
3230 g_return_if_fail (GDK_IS_WINDOW (window));
3232 if (GDK_WINDOW_DESTROYED (window))
3235 if (GDK_WINDOW_IS_MAPPED (window))
3242 gulong *current_desktop;
3243 GdkDisplay *display = gdk_drawable_get_display (window);
3245 /* Request unstick from viewport */
3246 gdk_wmspec_change_state (FALSE, window,
3247 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3250 /* Get current desktop, then set it; this is a race, but not
3251 * one that matters much in practice.
3253 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
3254 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
3256 False, XA_CARDINAL, &type, &format, &nitems,
3257 &bytes_after, (guchar **)¤t_desktop);
3259 if (type == XA_CARDINAL)
3261 xev.xclient.type = ClientMessage;
3262 xev.xclient.serial = 0;
3263 xev.xclient.send_event = True;
3264 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3265 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
3266 xev.xclient.format = 32;
3268 xev.xclient.data.l[0] = *current_desktop;
3270 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3271 SubstructureRedirectMask | SubstructureNotifyMask,
3274 XFree (current_desktop);
3279 /* Flip our client side flag, the real work happens on map. */
3280 gdk_synthesize_window_state (window,
3281 GDK_WINDOW_STATE_STICKY,
3288 * gdk_window_maximize:
3289 * @window: a #GdkWindow
3291 * Asks the window manager to maximize @window, if the window manager supports
3292 * this operation. Not all window managers support this, and some deliberately
3293 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3294 * maximization actually happening. But it will happen with most standard
3295 * window managers, and GDK makes a best effort to get it to happen.
3297 * If the window was already maximized, then this function does nothing.
3301 gdk_window_maximize (GdkWindow *window)
3303 g_return_if_fail (GDK_IS_WINDOW (window));
3305 if (GDK_WINDOW_DESTROYED (window))
3308 if (GDK_WINDOW_IS_MAPPED (window))
3309 gdk_wmspec_change_state (TRUE, window,
3310 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3311 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3313 gdk_synthesize_window_state (window,
3315 GDK_WINDOW_STATE_MAXIMIZED);
3319 * gdk_window_unmaximize:
3320 * @window: a #GdkWindow
3322 * Asks the window manager to unmaximize @window, if the window manager supports
3323 * this operation. Not all window managers support this, and some deliberately
3324 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3325 * unmaximization actually happening. But it will happen with most standard
3326 * window managers, and GDK makes a best effort to get it to happen.
3328 * If the window wasn't maximized, then this function does nothing.
3332 gdk_window_unmaximize (GdkWindow *window)
3334 g_return_if_fail (GDK_IS_WINDOW (window));
3336 if (GDK_WINDOW_DESTROYED (window))
3339 if (GDK_WINDOW_IS_MAPPED (window))
3340 gdk_wmspec_change_state (FALSE, window,
3341 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3342 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3344 gdk_synthesize_window_state (window,
3345 GDK_WINDOW_STATE_MAXIMIZED,
3350 * gdk_window_set_group:
3351 * @window: a #GdkWindow
3352 * @leader: group leader window
3354 * Sets the group leader window for @window. By default,
3355 * GDK sets the group leader for all toplevel windows
3356 * to a global window implicitly created by GDK. With this function
3357 * you can override this default.
3359 * The group leader window allows the window manager to distinguish
3360 * all windows that belong to a single application. It may for example
3361 * allow users to minimize/unminimize all windows belonging to an
3362 * application at once. You should only set a non-default group window
3363 * if your application pretends to be multiple applications.
3364 * The group leader window may not be changed after a window has been
3365 * mapped (with gdk_window_show() for example).
3369 gdk_window_set_group (GdkWindow *window,
3374 g_return_if_fail (window != NULL);
3375 g_return_if_fail (GDK_IS_WINDOW (window));
3376 g_return_if_fail (leader != NULL);
3377 g_return_if_fail (GDK_IS_WINDOW (leader));
3379 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3382 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3383 GDK_WINDOW_XID (window));
3385 wm_hints = XAllocWMHints ();
3387 wm_hints->flags |= WindowGroupHint;
3388 wm_hints->window_group = GDK_WINDOW_XID (leader);
3390 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3391 GDK_WINDOW_XID (window), wm_hints);
3395 static MotifWmHints *
3396 gdk_window_get_mwm_hints (GdkWindow *window)
3398 GdkDisplay *display;
3399 Atom hints_atom = None;
3400 MotifWmHints *hints;
3406 if (GDK_WINDOW_DESTROYED (window))
3409 display = gdk_drawable_get_display (window);
3411 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3413 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3414 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3415 False, AnyPropertyType, &type, &format, &nitems,
3416 &bytes_after, (guchar **)&hints);
3425 gdk_window_set_mwm_hints (GdkWindow *window,
3426 MotifWmHints *new_hints)
3428 GdkDisplay *display;
3429 Atom hints_atom = None;
3430 MotifWmHints *hints;
3436 if (GDK_WINDOW_DESTROYED (window))
3439 display = gdk_drawable_get_display (window);
3441 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3443 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3444 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3445 False, AnyPropertyType, &type, &format, &nitems,
3446 &bytes_after, (guchar **)&hints);
3452 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3454 hints->flags |= MWM_HINTS_FUNCTIONS;
3455 hints->functions = new_hints->functions;
3457 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3459 hints->flags |= MWM_HINTS_DECORATIONS;
3460 hints->decorations = new_hints->decorations;
3464 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3465 hints_atom, hints_atom, 32, PropModeReplace,
3466 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3468 if (hints != new_hints)
3473 * gdk_window_set_decorations:
3474 * @window: a #GdkWindow
3475 * @decorations: decoration hint mask
3477 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3478 * This function sets the traditional Motif window manager hints that tell the
3479 * window manager which decorations you would like your window to have.
3480 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3481 * using the GDK function directly.
3483 * The @decorations argument is the logical OR of the fields in
3484 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3485 * mask, the other bits indicate which decorations should be turned off.
3486 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3487 * which decorations should be turned on.
3489 * Most window managers honor a decorations hint of 0 to disable all decorations,
3490 * but very few honor all possible combinations of bits.
3494 gdk_window_set_decorations (GdkWindow *window,
3495 GdkWMDecoration decorations)
3499 g_return_if_fail (window != NULL);
3500 g_return_if_fail (GDK_IS_WINDOW (window));
3502 hints.flags = MWM_HINTS_DECORATIONS;
3503 hints.decorations = decorations;
3505 gdk_window_set_mwm_hints (window, &hints);
3509 * gdk_window_get_decorations:
3510 * @window: The #GdkWindow to get the decorations from
3511 * @decorations: The window decorations will be written here
3513 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3514 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3517 gdk_window_get_decorations(GdkWindow *window,
3518 GdkWMDecoration *decorations)
3520 MotifWmHints *hints;
3521 gboolean result = FALSE;
3523 hints = gdk_window_get_mwm_hints (window);
3527 if (hints->flags & MWM_HINTS_DECORATIONS)
3529 *decorations = hints->decorations;
3540 * gdk_window_set_functions:
3541 * @window: a #GdkWindow
3542 * @functions: bitmask of operations to allow on @window
3544 * This function isn't really good for much. It sets the traditional
3545 * Motif window manager hint for which operations the window manager
3546 * should allow on a toplevel window. However, few window managers do
3547 * anything reliable or interesting with this hint. Many ignore it
3550 * The @functions argument is the logical OR of values from the
3551 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3552 * then the other bits indicate which functions to disable; if
3553 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3558 gdk_window_set_functions (GdkWindow *window,
3559 GdkWMFunction functions)
3563 g_return_if_fail (window != NULL);
3564 g_return_if_fail (GDK_IS_WINDOW (window));
3566 hints.flags = MWM_HINTS_FUNCTIONS;
3567 hints.functions = functions;
3569 gdk_window_set_mwm_hints (window, &hints);
3572 #ifdef HAVE_SHAPE_EXT
3575 * propagate the shapes from all child windows of a GDK window to the parent
3576 * window. Shamelessly ripped from Enlightenment's code
3584 struct _gdk_span *next;
3588 gdk_add_to_span (struct _gdk_span **s,
3592 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3599 /* scan the spans for this line */
3602 /* -- -> new span */
3603 /* == -> existing span */
3604 /* ## -> spans intersect */
3605 /* if we are in the middle of spanning the span into the line */
3608 /* case: ---- ==== */
3609 if (xx < ptr1->start - 1)
3611 /* ends before next span - extend to here */
3615 /* case: ----##=== */
3616 else if (xx <= ptr1->end)
3618 /* crosses into next span - delete next span and append */
3619 ss->end = ptr1->end;
3620 ss->next = ptr1->next;
3624 /* case: ---###--- */
3627 /* overlaps next span - delete and keep checking */
3628 ss->next = ptr1->next;
3633 /* otherwise havent started spanning it in yet */
3636 /* case: ---- ==== */
3637 if (xx < ptr1->start - 1)
3639 /* insert span here in list */
3640 noo = g_malloc (sizeof (struct _gdk_span));
3654 /* case: ----##=== */
3655 else if ((x < ptr1->start) && (xx <= ptr1->end))
3657 /* expand this span to the left point of the new one */
3661 /* case: ===###=== */
3662 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3664 /* throw the span away */
3667 /* case: ---###--- */
3668 else if ((x < ptr1->start) && (xx > ptr1->end))
3675 /* case: ===##---- */
3676 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3682 /* case: ==== ---- */
3683 /* case handled by next loop iteration - first case */
3688 /* it started in the middle but spans beyond your current list */
3694 /* it does not start inside a span or in the middle, so add it to the end */
3695 noo = g_malloc (sizeof (struct _gdk_span));
3703 noo->next = ptr2->next;
3716 gdk_add_rectangles (Display *disp,
3718 struct _gdk_span **spans,
3725 gint x1, y1, x2, y2;
3729 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
3732 /* go through all clip rects in this window's shape */
3733 for (k = 0; k < rn; k++)
3735 /* for each clip rect, add it to each line's spans */
3737 x2 = x + rl[k].x + (rl[k].width - 1);
3739 y2 = y + rl[k].y + (rl[k].height - 1);
3748 for (a = y1; a <= y2; a++)
3751 gdk_add_to_span (&spans[a], x1, x2);
3759 gdk_propagate_shapes (Display *disp,
3763 Window rt, par, *list = NULL;
3764 gint i, j, num = 0, num_rects = 0;
3768 XRectangle *rects = NULL;
3769 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
3770 XWindowAttributes xatt;
3772 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
3777 spans = g_malloc (sizeof (struct _gdk_span *) * h);
3779 for (i = 0; i < h; i++)
3781 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
3784 /* go through all child windows and create/insert spans */
3785 for (i = 0; i < num; i++)
3787 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
3788 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
3789 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
3792 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
3794 /* go through the spans list and build a list of rects */
3795 rects = g_malloc (sizeof (XRectangle) * 256);
3797 for (i = 0; i < baseh; i++)
3800 /* go through the line for all spans */
3803 rects[num_rects].x = ptr1->start;
3804 rects[num_rects].y = i;
3805 rects[num_rects].width = ptr1->end - ptr1->start + 1;
3806 rects[num_rects].height = 1;
3808 /* if there are more lines */
3810 /* while contigous rects (same start/end coords) exist */
3811 while ((contig) && (j < baseh))
3813 /* search next line for spans matching this one */
3819 /* if we have an exact span match set contig */
3820 if ((ptr2->start == ptr1->start) &&
3821 (ptr2->end == ptr1->end))
3824 /* remove the span - not needed */
3827 ptr3->next = ptr2->next;
3833 spans[j] = ptr2->next;
3839 /* gone past the span point no point looking */
3840 else if (ptr2->start < ptr1->start)
3848 /* if a contiguous span was found increase the rect h */
3851 rects[num_rects].height++;
3855 /* up the rect count */
3857 /* every 256 new rects increase the rect array */
3858 if ((num_rects % 256) == 0)
3859 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
3863 /* set the rects as the shape mask */
3866 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
3867 ShapeSet, YXSorted);
3872 /* free up all the spans we made */
3873 for (i = 0; i < baseh; i++)
3886 #endif /* HAVE_SHAPE_EXT */
3889 * gdk_window_set_child_shapes:
3890 * @window: a #GdkWindow
3892 * Sets the shape mask of @window to the union of shape masks
3893 * for all children of @window, ignoring the shape mask of @window
3894 * itself. Contrast with gdk_window_merge_child_shapes() which includes
3895 * the shape mask of @window in the masks to be merged.
3898 gdk_window_set_child_shapes (GdkWindow *window)
3900 g_return_if_fail (window != NULL);
3901 g_return_if_fail (GDK_IS_WINDOW (window));
3903 #ifdef HAVE_SHAPE_EXT
3904 if (!GDK_WINDOW_DESTROYED (window) &&
3905 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3906 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3907 GDK_WINDOW_XID (window), FALSE);
3912 * gdk_window_merge_child_shapes:
3913 * @window: a #GdkWindow
3915 * Merges the shape masks for any child windows into the
3916 * shape mask for @window. i.e. the union of all masks
3917 * for @window and its children will become the new mask
3918 * for @window. See gdk_window_shape_combine_mask().
3920 * This function is distinct from gdk_window_set_child_shapes()
3921 * because it includes @window's shape mask in the set of shapes to
3926 gdk_window_merge_child_shapes (GdkWindow *window)
3928 g_return_if_fail (window != NULL);
3929 g_return_if_fail (GDK_IS_WINDOW (window));
3931 #ifdef HAVE_SHAPE_EXT
3932 if (!GDK_WINDOW_DESTROYED (window) &&
3933 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3934 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3935 GDK_WINDOW_XID (window), TRUE);
3939 /* Support for windows that can be guffaw-scrolled
3940 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
3944 gdk_window_gravity_works (GdkWindow *window)
3946 enum { UNKNOWN, NO, YES };
3947 static gint gravity_works = UNKNOWN;
3948 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (window);
3950 if (gravity_works == UNKNOWN)
3957 /* This particular server apparently has a bug so that the test
3958 * works but the actual code crashes it
3960 if ((!strcmp (XServerVendor (GDK_DISPLAY_XDISPLAY (display)),
3961 "Sun Microsystems, Inc.")) &&
3962 (VendorRelease (GDK_DISPLAY_XDISPLAY (display)) == 3400))
3968 attr.window_type = GDK_WINDOW_TEMP;
3969 attr.wclass = GDK_INPUT_OUTPUT;
3974 attr.event_mask = 0;
3976 parent = gdk_window_new (gdk_screen_get_root_window (GDK_DRAWABLE_SCREEN (window)),
3977 &attr, GDK_WA_X | GDK_WA_Y);
3979 attr.window_type = GDK_WINDOW_CHILD;
3980 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
3982 gdk_window_set_static_win_gravity (child, TRUE);
3984 gdk_window_resize (parent, 100, 110);
3986 gdk_window_move (parent, 0, -10);
3987 gdk_window_move_resize (parent, 0, 0, 100, 100);
3989 gdk_window_resize (parent, 100, 110);
3990 gdk_window_move (parent, 0, -10);
3991 gdk_window_move_resize (parent, 0, 0, 100, 100);
3993 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
3995 gdk_window_destroy (parent);
3996 gdk_window_destroy (child);
3998 gravity_works = ((y == -20) ? YES : NO);
4001 return (gravity_works == YES);
4005 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
4007 XSetWindowAttributes xattributes;
4008 GdkWindowObject *private;
4009 guint xattributes_mask = 0;
4011 g_return_if_fail (window != NULL);
4013 private = GDK_WINDOW_OBJECT (window);
4014 if (private->input_only)
4017 xattributes.bit_gravity = StaticGravity;
4018 xattributes_mask |= CWBitGravity;
4019 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4020 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4021 GDK_WINDOW_XID (window),
4022 CWBitGravity, &xattributes);
4026 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4028 XSetWindowAttributes xattributes;
4030 g_return_if_fail (window != NULL);
4032 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4034 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4035 GDK_WINDOW_XID (window),
4036 CWWinGravity, &xattributes);
4040 * gdk_window_set_static_gravities:
4041 * @window: a #GdkWindow
4042 * @use_static: %TRUE to turn on static gravity
4044 * Set the bit gravity of the given window to static, and flag it so
4045 * all children get static subwindow gravity. This is used if you are
4046 * implementing scary features that involve deep knowledge of the
4047 * windowing system. Don't worry about it unless you have to.
4049 * Return value: %TRUE if the server supports static gravity
4052 gdk_window_set_static_gravities (GdkWindow *window,
4053 gboolean use_static)
4055 GdkWindowObject *private = (GdkWindowObject *)window;
4058 g_return_val_if_fail (window != NULL, FALSE);
4059 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4061 if (!use_static == !private->guffaw_gravity)
4064 if (use_static && !gdk_window_gravity_works (window))
4067 private->guffaw_gravity = use_static;
4069 if (!GDK_WINDOW_DESTROYED (window))
4071 gdk_window_set_static_bit_gravity (window, use_static);
4073 tmp_list = private->children;
4076 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4078 tmp_list = tmp_list->next;
4086 wmspec_moveresize (GdkWindow *window,
4092 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4096 /* Release passive grab */
4097 gdk_display_pointer_ungrab (display, timestamp);
4099 xev.xclient.type = ClientMessage;
4100 xev.xclient.serial = 0;
4101 xev.xclient.send_event = True;
4102 xev.xclient.window = GDK_WINDOW_XID (window);
4103 xev.xclient.message_type =
4104 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4105 xev.xclient.format = 32;
4106 xev.xclient.data.l[0] = root_x;
4107 xev.xclient.data.l[1] = root_y;
4108 xev.xclient.data.l[2] = direction;
4109 xev.xclient.data.l[3] = 0;
4110 xev.xclient.data.l[4] = 0;
4112 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4113 SubstructureRedirectMask | SubstructureNotifyMask,
4117 typedef struct _MoveResizeData MoveResizeData;
4119 struct _MoveResizeData
4121 GdkDisplay *display;
4123 GdkWindow *moveresize_window;
4124 GdkWindow *moveresize_emulation_window;
4126 GdkWindowEdge resize_edge;
4127 gint moveresize_button;
4130 gint moveresize_orig_x;
4131 gint moveresize_orig_y;
4132 gint moveresize_orig_width;
4133 gint moveresize_orig_height;
4134 GdkWindowHints moveresize_geom_mask;
4135 GdkGeometry moveresize_geometry;
4136 Time moveresize_process_time;
4137 XEvent *moveresize_pending_event;
4140 /* From the WM spec */
4141 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4142 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4143 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4144 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4145 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4146 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4147 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4148 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4149 #define _NET_WM_MOVERESIZE_MOVE 8
4152 wmspec_resize_drag (GdkWindow *window,
4161 /* Let the compiler turn a switch into a table, instead
4162 * of doing the table manually, this way is easier to verify.
4166 case GDK_WINDOW_EDGE_NORTH_WEST:
4167 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4170 case GDK_WINDOW_EDGE_NORTH:
4171 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4174 case GDK_WINDOW_EDGE_NORTH_EAST:
4175 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4178 case GDK_WINDOW_EDGE_WEST:
4179 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4182 case GDK_WINDOW_EDGE_EAST:
4183 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4186 case GDK_WINDOW_EDGE_SOUTH_WEST:
4187 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4190 case GDK_WINDOW_EDGE_SOUTH:
4191 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4194 case GDK_WINDOW_EDGE_SOUTH_EAST:
4195 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4199 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4205 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4208 static MoveResizeData *
4209 get_move_resize_data (GdkDisplay *display,
4212 MoveResizeData *mv_resize;
4213 static GQuark move_resize_quark = 0;
4215 if (!move_resize_quark)
4216 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4218 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4220 if (!mv_resize && create)
4222 mv_resize = g_new0 (MoveResizeData, 1);
4223 mv_resize->display = display;
4225 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4232 update_pos (MoveResizeData *mv_resize,
4238 dx = new_root_x - mv_resize->moveresize_x;
4239 dy = new_root_y - mv_resize->moveresize_y;
4241 if (mv_resize->is_resize)
4245 w = mv_resize->moveresize_orig_width;
4246 h = mv_resize->moveresize_orig_height;
4248 switch (mv_resize->resize_edge)
4250 case GDK_WINDOW_EDGE_SOUTH_EAST:
4259 if (mv_resize->moveresize_geom_mask)
4261 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4262 mv_resize->moveresize_geom_mask,
4266 gdk_window_resize (mv_resize->moveresize_window, w, h);
4272 x = mv_resize->moveresize_orig_x + dx;
4273 y = mv_resize->moveresize_orig_y + dy;
4275 gdk_window_move (mv_resize->moveresize_window, x, y);
4280 finish_drag (MoveResizeData *mv_resize)
4282 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4283 mv_resize->moveresize_emulation_window = NULL;
4284 mv_resize->moveresize_window = NULL;
4286 if (mv_resize->moveresize_pending_event)
4288 g_free (mv_resize->moveresize_pending_event);
4289 mv_resize->moveresize_pending_event = NULL;
4294 lookahead_motion_predicate (Display *xdisplay,
4298 gboolean *seen_release = (gboolean *)arg;
4299 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4300 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4305 switch (event->xany.type)
4308 *seen_release = TRUE;
4311 mv_resize->moveresize_process_time = event->xmotion.time;
4321 moveresize_lookahead (MoveResizeData *mv_resize,
4325 gboolean seen_release = FALSE;
4327 if (mv_resize->moveresize_process_time)
4329 if (event->xmotion.time == mv_resize->moveresize_process_time)
4331 mv_resize->moveresize_process_time = 0;
4338 XCheckIfEvent (event->xany.display, &tmp_event,
4339 lookahead_motion_predicate, (XPointer) & seen_release);
4341 return mv_resize->moveresize_process_time == 0;
4345 _gdk_moveresize_handle_event (XEvent *event)
4347 guint button_mask = 0;
4348 GdkWindowObject *window_private;
4349 GdkDisplay *display= gdk_x11_lookup_xdisplay (event->xany.display);
4350 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4352 if (!mv_resize || mv_resize->moveresize_window)
4355 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
4357 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4359 switch (event->xany.type)
4362 if (window_private->resize_count > 0)
4364 if (mv_resize->moveresize_pending_event)
4365 *mv_resize->moveresize_pending_event = *event;
4367 mv_resize->moveresize_pending_event =
4368 g_memdup (event, sizeof (XEvent));
4372 if (!moveresize_lookahead (mv_resize, event))
4375 update_pos (mv_resize,
4376 event->xmotion.x_root,
4377 event->xmotion.y_root);
4379 /* This should never be triggered in normal cases, but in the
4380 * case where the drag started without an implicit grab being
4381 * in effect, we could miss the release if it occurs before
4382 * we grab the pointer; this ensures that we will never
4383 * get a permanently stuck grab.
4385 if ((event->xmotion.state & button_mask) == 0)
4386 finish_drag (mv_resize);
4390 update_pos (mv_resize,
4391 event->xbutton.x_root,
4392 event->xbutton.y_root);
4394 if (event->xbutton.button == mv_resize->moveresize_button)
4395 finish_drag (mv_resize);
4402 _gdk_moveresize_configure_done (GdkDisplay *display,
4406 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4408 if (!mv_resize || window != mv_resize->moveresize_window)
4411 if (mv_resize->moveresize_pending_event)
4413 tmp_event = mv_resize->moveresize_pending_event;
4414 mv_resize->moveresize_pending_event = NULL;
4415 _gdk_moveresize_handle_event (tmp_event);
4423 create_moveresize_window (MoveResizeData *mv_resize,
4426 GdkWindowAttr attributes;
4427 gint attributes_mask;
4428 GdkGrabStatus status;
4430 g_assert (mv_resize->moveresize_emulation_window == NULL);
4432 attributes.x = -100;
4433 attributes.y = -100;
4434 attributes.width = 10;
4435 attributes.height = 10;
4436 attributes.window_type = GDK_WINDOW_TEMP;
4437 attributes.wclass = GDK_INPUT_ONLY;
4438 attributes.override_redirect = TRUE;
4439 attributes.event_mask = 0;
4441 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4443 mv_resize->moveresize_emulation_window =
4444 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4448 gdk_window_show (mv_resize->moveresize_emulation_window);
4450 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4452 GDK_BUTTON_RELEASE_MASK |
4453 GDK_POINTER_MOTION_MASK,
4458 if (status != GDK_GRAB_SUCCESS)
4460 /* If this fails, some other client has grabbed the window
4463 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4464 mv_resize->moveresize_emulation_window = NULL;
4467 mv_resize->moveresize_process_time = 0;
4471 emulate_resize_drag (GdkWindow *window,
4478 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4480 mv_resize->is_resize = TRUE;
4481 mv_resize->moveresize_button = button;
4482 mv_resize->resize_edge = edge;
4483 mv_resize->moveresize_x = root_x;
4484 mv_resize->moveresize_y = root_y;
4485 mv_resize->moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4487 gdk_window_get_size (window,
4488 &mv_resize->moveresize_orig_width,
4489 &mv_resize->moveresize_orig_height);
4491 mv_resize->moveresize_geom_mask = 0;
4492 gdk_window_get_geometry_hints (window,
4493 &mv_resize->moveresize_geometry,
4494 &mv_resize->moveresize_geom_mask);
4496 create_moveresize_window (mv_resize, timestamp);
4500 emulate_move_drag (GdkWindow *window,
4506 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4508 mv_resize->is_resize = FALSE;
4509 mv_resize->moveresize_button = button;
4510 mv_resize->moveresize_x = root_x;
4511 mv_resize->moveresize_y = root_y;
4513 mv_resize->moveresize_window =
4514 GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4516 gdk_window_get_deskrelative_origin (mv_resize->moveresize_window,
4517 &mv_resize->moveresize_orig_x,
4518 &mv_resize->moveresize_orig_y);
4520 create_moveresize_window (mv_resize, timestamp);
4524 * gdk_window_begin_resize_drag:
4525 * @window: a #GdkWindow
4526 * @edge: the edge or corner from which the drag is started
4527 * @button: the button being used to drag
4528 * @root_x: root window X coordinate of mouse click that began the drag
4529 * @root_y: root window Y coordinate of mouse click that began the drag
4530 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4532 * Begins a window resize operation (for a toplevel window).
4533 * You might use this function to implement a "window resize grip," for
4534 * example; in fact #GtkStatusbar uses it. The function works best
4535 * with window managers that support the Extended Window Manager Hints spec
4536 * (see http://www.freedesktop.org), but has a fallback implementation
4537 * for other window managers.
4541 gdk_window_begin_resize_drag (GdkWindow *window,
4548 g_return_if_fail (GDK_IS_WINDOW (window));
4550 if (GDK_WINDOW_DESTROYED (window))
4553 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4554 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4555 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4557 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4561 * gdk_window_begin_move_drag:
4562 * @window: a #GdkWindow
4563 * @button: the button being used to drag
4564 * @root_x: root window X coordinate of mouse click that began the drag
4565 * @root_y: root window Y coordinate of mouse click that began the drag
4566 * @timestamp: timestamp of mouse click that began the drag
4568 * Begins a window move operation (for a toplevel window). You might
4569 * use this function to implement a "window move grip," for
4570 * example. The function works best with window managers that support
4571 * the Extended Window Manager Hints spec (see
4572 * http://www.freedesktop.org), but has a fallback implementation for
4573 * other window managers.
4577 gdk_window_begin_move_drag (GdkWindow *window,
4583 g_return_if_fail (GDK_IS_WINDOW (window));
4585 if (GDK_WINDOW_DESTROYED (window))
4588 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4589 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4590 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
4593 emulate_move_drag (window, button, root_x, root_y, timestamp);