1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
30 #include <netinet/in.h>
35 #include "gdkwindow.h"
36 #include "gdkinputprivate.h"
37 #include "gdkdisplay-x11.h"
38 #include "gdkprivate-x11.h"
39 #include "gdkregion.h"
40 #include "gdkinternals.h"
42 #include "gdkwindow-x11.h"
50 #include <X11/extensions/shape.h>
53 const int _gdk_event_mask_table[21] =
57 PointerMotionHintMask,
74 SubstructureNotifyMask,
75 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
77 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
79 /* Forward declarations */
80 static gboolean gdk_window_gravity_works (GdkWindow *window);
81 static void gdk_window_set_static_win_gravity (GdkWindow *window,
83 static gboolean gdk_window_have_shape_ext (GdkDisplay *display);
84 static gboolean gdk_window_icon_name_set (GdkWindow *window);
85 static void gdk_window_add_colormap_windows (GdkWindow *window);
87 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
88 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
90 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
93 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
94 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
95 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
96 static void gdk_window_impl_x11_finalize (GObject *object);
98 static gpointer parent_class = NULL;
101 gdk_window_impl_x11_get_type (void)
103 static GType object_type = 0;
107 static const GTypeInfo object_info =
109 sizeof (GdkWindowImplX11Class),
110 (GBaseInitFunc) NULL,
111 (GBaseFinalizeFunc) NULL,
112 (GClassInitFunc) gdk_window_impl_x11_class_init,
113 NULL, /* class_finalize */
114 NULL, /* class_data */
115 sizeof (GdkWindowImplX11),
117 (GInstanceInitFunc) gdk_window_impl_x11_init,
120 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
129 _gdk_window_impl_get_type (void)
131 return gdk_window_impl_x11_get_type ();
135 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
142 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
144 GObjectClass *object_class = G_OBJECT_CLASS (klass);
145 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
147 parent_class = g_type_class_peek_parent (klass);
149 object_class->finalize = gdk_window_impl_x11_finalize;
151 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
152 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
153 drawable_class->get_size = gdk_window_impl_x11_get_size;
155 /* Visible and clip regions are the same */
156 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
157 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
161 gdk_window_impl_x11_finalize (GObject *object)
163 GdkWindowObject *wrapper;
164 GdkDrawableImplX11 *draw_impl;
165 GdkWindowImplX11 *window_impl;
167 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
169 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
170 window_impl = GDK_WINDOW_IMPL_X11 (object);
172 wrapper = (GdkWindowObject*) draw_impl->wrapper;
174 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
176 if (!GDK_WINDOW_DESTROYED (wrapper))
178 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), draw_impl->xid);
179 if (window_impl->focus_window)
180 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), window_impl->focus_window);
183 G_OBJECT_CLASS (parent_class)->finalize (object);
187 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
189 GdkDrawableImplX11 *drawable_impl;
190 GdkWindowImplX11 *window_impl;
192 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
194 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
195 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
197 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
198 drawable_impl->colormap == NULL)
200 XWindowAttributes window_attributes;
203 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
207 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
208 window_attributes.visual->visualid);
209 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
210 window_attributes.colormap);
213 return drawable_impl->colormap;
217 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
220 GdkWindowImplX11 *impl;
221 GdkDrawableImplX11 *draw_impl;
223 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
225 impl = GDK_WINDOW_IMPL_X11 (drawable);
226 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
228 if (GDK_WINDOW_DESTROYED (draw_impl->wrapper))
232 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
236 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
238 GDK_COLORMAP_XCOLORMAP (cmap));
240 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
242 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
248 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
252 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
255 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
257 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
261 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
263 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
264 GdkRectangle result_rect;
268 result_rect.width = impl->width;
269 result_rect.height = impl->height;
271 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
273 return gdk_region_rectangle (&result_rect);
277 _gdk_windowing_window_init (GdkScreen * screen)
279 GdkWindowObject *private;
280 GdkWindowImplX11 *impl;
281 GdkDrawableImplX11 *draw_impl;
282 GdkScreenX11 *screen_x11;
283 XWindowAttributes xattributes;
286 unsigned int border_width;
290 screen_x11 = GDK_SCREEN_X11 (screen);
292 g_assert (screen_x11->root_window == NULL);
294 screen_x11->default_colormap = gdk_screen_get_system_colormap (screen);
296 XGetGeometry (screen_x11->xdisplay, screen_x11->xroot_window,
297 &screen_x11->xroot_window, &x, &y, &width, &height, &border_width, &depth);
298 XGetWindowAttributes (screen_x11->xdisplay, screen_x11->xroot_window, &xattributes);
300 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
301 private = (GdkWindowObject *)screen_x11->root_window;
302 impl = GDK_WINDOW_IMPL_X11 (private->impl);
303 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
305 draw_impl->screen = screen;
306 draw_impl->xid = screen_x11->xroot_window;
307 draw_impl->wrapper = GDK_DRAWABLE (private);
308 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
310 private->window_type = GDK_WINDOW_ROOT;
311 private->depth = depth;
314 impl->height = height;
316 _gdk_window_init_position (GDK_WINDOW (private));
318 _gdk_xid_table_insert (screen_x11->display,
319 &screen_x11->xroot_window,
320 screen_x11->root_window);
324 set_wm_protocols (GdkWindow *window)
326 GdkDisplay *display = gdk_drawable_get_display (window);
329 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
330 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
331 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
333 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
338 * @parent: a #GdkWindow, or %NULL to create the window as a child of
339 * the default root window for the default display.
340 * @attributes: attributes of the new window
341 * @attributes_mask: mask indicating which fields in @attributes are valid
343 * Creates a new #GdkWindow using the attributes from
344 * @attributes. Seep #GdkWindowAttr and #GdkWindowAttributesType for
345 * more details. Note: to use this on displays other than the default
346 * display, @parent must be specified.
348 * Return value: the new #GdkWindow
351 gdk_window_new (GdkWindow *parent,
352 GdkWindowAttr *attributes,
353 gint attributes_mask)
356 GdkWindowObject *private;
357 GdkWindowImplX11 *impl;
358 GdkDrawableImplX11 *draw_impl;
359 GdkScreenX11 *screen_x11;
368 XSetWindowAttributes xattributes;
369 long xattributes_mask;
370 XSizeHints size_hints;
372 XClassHint *class_hint;
380 g_return_val_if_fail (attributes != NULL, NULL);
385 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
387 screen = gdk_screen_get_default ();
388 parent = gdk_screen_get_root_window (screen);
391 screen = gdk_drawable_get_screen (parent);
393 screen_x11 = GDK_SCREEN_X11 (screen);
395 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
397 if (GDK_WINDOW_DESTROYED (parent))
400 xparent = GDK_WINDOW_XID (parent);
402 window = g_object_new (GDK_TYPE_WINDOW, NULL);
403 private = (GdkWindowObject *)window;
404 impl = GDK_WINDOW_IMPL_X11 (private->impl);
405 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
406 draw_impl->wrapper = GDK_DRAWABLE (window);
408 draw_impl->screen = screen;
409 xdisplay = screen_x11->xdisplay;
411 /* Windows with a foreign parent are treated as if they are children
412 * of the root window, except for actual creation.
414 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
415 parent = gdk_screen_get_root_window (screen);
417 private->parent = (GdkWindowObject *)parent;
419 xattributes_mask = 0;
421 if (attributes_mask & GDK_WA_X)
426 if (attributes_mask & GDK_WA_Y)
433 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
434 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
436 if (attributes->wclass == GDK_INPUT_ONLY)
438 /* Backwards compatiblity - we've always ignored
439 * attributes->window_type for input-only windows
442 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
443 private->window_type = GDK_WINDOW_TEMP;
445 private->window_type = GDK_WINDOW_CHILD;
448 private->window_type = attributes->window_type;
450 _gdk_window_init_position (GDK_WINDOW (private));
451 if (impl->position_info.big)
452 private->guffaw_gravity = TRUE;
454 if (attributes_mask & GDK_WA_VISUAL)
455 visual = attributes->visual;
457 visual = gdk_screen_get_system_visual (screen);
458 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
460 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
461 for (i = 0; i < _gdk_nenvent_masks; i++)
463 if (attributes->event_mask & (1 << (i + 1)))
464 xattributes.event_mask |= _gdk_event_mask_table[i];
466 private->event_mask = attributes->event_mask;
468 if (xattributes.event_mask)
469 xattributes_mask |= CWEventMask;
471 if (attributes_mask & GDK_WA_NOREDIR)
473 xattributes.override_redirect =
474 (attributes->override_redirect == FALSE)?False:True;
475 xattributes_mask |= CWOverrideRedirect;
478 xattributes.override_redirect = False;
480 if (private->parent && private->parent->guffaw_gravity)
482 xattributes.win_gravity = StaticGravity;
483 xattributes_mask |= CWWinGravity;
487 switch (private->window_type)
489 case GDK_WINDOW_TOPLEVEL:
490 case GDK_WINDOW_DIALOG:
491 case GDK_WINDOW_TEMP:
492 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
494 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
495 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
496 xparent = GDK_SCREEN_XROOTWIN (screen);
498 case GDK_WINDOW_CHILD:
501 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
505 if (attributes->wclass == GDK_INPUT_OUTPUT)
508 depth = visual->depth;
510 private->input_only = FALSE;
511 private->depth = depth;
513 if (attributes_mask & GDK_WA_COLORMAP)
515 draw_impl->colormap = attributes->colormap;
516 g_object_ref (attributes->colormap);
520 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
522 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
523 g_object_ref (draw_impl->colormap);
527 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
531 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
532 xattributes.background_pixel = private->bg_color.pixel;
534 private->bg_pixmap = NULL;
536 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
537 xattributes_mask |= CWBorderPixel | CWBackPixel;
539 if (private->guffaw_gravity)
540 xattributes.bit_gravity = StaticGravity;
542 xattributes.bit_gravity = NorthWestGravity;
544 xattributes_mask |= CWBitGravity;
546 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
547 xattributes_mask |= CWColormap;
549 if (private->window_type == GDK_WINDOW_TEMP)
551 xattributes.save_under = True;
552 xattributes.override_redirect = True;
553 xattributes.cursor = None;
554 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
562 private->input_only = TRUE;
563 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
564 g_object_ref (draw_impl->colormap);
567 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
568 impl->position_info.x, impl->position_info.y,
569 impl->position_info.width, impl->position_info.height,
570 0, depth, class, xvisual,
571 xattributes_mask, &xattributes);
573 g_object_ref (window);
574 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
576 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
577 (attributes->cursor) :
581 private->parent->children = g_list_prepend (private->parent->children, window);
583 switch (GDK_WINDOW_TYPE (private))
585 case GDK_WINDOW_DIALOG:
586 XSetTransientForHint (xdisplay, xid, xparent);
587 case GDK_WINDOW_TOPLEVEL:
588 case GDK_WINDOW_TEMP:
589 set_wm_protocols (window);
591 case GDK_WINDOW_CHILD:
592 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
593 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
594 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
596 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
597 gdk_window_add_colormap_windows (window);
606 if (class != InputOnly)
608 /* The focus window is off the visible area, and serves to receive key
609 * press events so they don't get sent to child windows.
611 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
613 xattributes.background_pixel,
614 xattributes.background_pixel);
615 /* FIXME: probably better to actually track the requested event mask for the toplevel
617 XSelectInput (xdisplay, impl->focus_window,
618 KeyPressMask | KeyReleaseMask | FocusChangeMask);
620 XMapWindow (xdisplay, impl->focus_window);
621 _gdk_xid_table_insert (screen_x11->display, &impl->focus_window, window);
624 size_hints.flags = PSize;
625 size_hints.width = impl->width;
626 size_hints.height = impl->height;
628 wm_hints.flags = StateHint | WindowGroupHint;
629 wm_hints.window_group = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
630 wm_hints.input = True;
631 wm_hints.initial_state = NormalState;
633 /* FIXME: Is there any point in doing this? Do any WM's pay
634 * attention to PSize, and even if they do, is this the
637 XSetWMNormalHints (xdisplay, xid, &size_hints);
639 XSetWMHints (xdisplay, xid, &wm_hints);
641 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
642 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
645 XChangeProperty (xdisplay, xid,
646 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
651 XChangeProperty (xdisplay, xid,
652 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
653 XA_WINDOW, 32, PropModeReplace,
654 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
656 if (attributes_mask & GDK_WA_TITLE)
657 title = attributes->title;
659 title = g_get_prgname ();
661 gdk_window_set_title (window, title);
663 if (attributes_mask & GDK_WA_WMCLASS)
665 class_hint = XAllocClassHint ();
666 class_hint->res_name = attributes->wmclass_name;
667 class_hint->res_class = attributes->wmclass_class;
668 XSetClassHint (xdisplay, xid, class_hint);
676 x_event_mask_to_gdk_event_mask (long mask)
678 GdkEventMask event_mask = 0;
681 for (i = 0; i < _gdk_nenvent_masks; i++)
683 if (mask & _gdk_event_mask_table[i])
684 event_mask |= 1 << (i + 1);
691 * gdk_window_foreign_new_for_display:
692 * @display: the #GdkDisplay where the window handle comes from.
693 * @anid: a native window handle.
695 * Wraps a native window in a #GdkWindow.
696 * This may fail if the window has been destroyed.
698 * For example in the X backend, a native window handle is an Xlib
701 * Return value: the newly-created #GdkWindow wrapper for the
702 * native window or %NULL if the window has been destroyed.
705 gdk_window_foreign_new_for_display (GdkDisplay *display,
706 GdkNativeWindow anid)
709 GdkWindowObject *private;
710 GdkWindowImplX11 *impl;
711 GdkDrawableImplX11 *draw_impl;
712 GdkDisplayX11 *display_x11;
713 XWindowAttributes attrs;
715 Window *children = NULL;
719 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
721 display_x11 = GDK_DISPLAY_X11 (display);
723 gdk_error_trap_push ();
724 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
725 if (gdk_error_trap_pop () || !result)
728 /* FIXME: This is pretty expensive. Maybe the caller should supply
730 gdk_error_trap_push ();
731 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
732 if (gdk_error_trap_pop () || !result)
738 window = g_object_new (GDK_TYPE_WINDOW, NULL);
739 private = (GdkWindowObject *)window;
740 impl = GDK_WINDOW_IMPL_X11 (private->impl);
741 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
742 draw_impl->wrapper = GDK_DRAWABLE (window);
743 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
745 private->parent = gdk_xid_table_lookup_for_display (display, parent);
747 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
748 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
750 private->parent->children = g_list_prepend (private->parent->children, window);
752 draw_impl->xid = anid;
754 private->x = attrs.x;
755 private->y = attrs.y;
756 impl->width = attrs.width;
757 impl->height = attrs.height;
758 private->window_type = GDK_WINDOW_FOREIGN;
759 private->destroyed = FALSE;
761 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
763 if (attrs.map_state == IsUnmapped)
764 private->state = GDK_WINDOW_STATE_WITHDRAWN;
768 private->depth = attrs.depth;
770 _gdk_window_init_position (GDK_WINDOW (private));
772 g_object_ref (window);
773 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
778 * gdk_window_lookup_for_display:
779 * @display: the #GdkDisplay corresponding to the window handle
780 * @anid: a native window handle.
782 * Looks up the #GdkWindow that wraps the given native window handle.
784 * For example in the X backend, a native window handle is an Xlib
787 * Return value: the #GdkWindow wrapper for the native window,
788 * or %NULL if there is none.
791 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
793 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
798 * @anid: a native window handle.
800 * Looks up the #GdkWindow that wraps the given native window handle.
802 * For example in the X backend, a native window handle is an Xlib
805 * Return value: the #GdkWindow wrapper for the native window,
806 * or %NULL if there is none.
809 gdk_window_lookup (GdkNativeWindow anid)
811 return (GdkWindow*) gdk_xid_table_lookup (anid);
815 _gdk_windowing_window_destroy (GdkWindow *window,
817 gboolean foreign_destroy)
819 GdkWindowObject *private = (GdkWindowObject *)window;
821 g_return_if_fail (GDK_IS_WINDOW (window));
823 _gdk_selection_window_destroyed (window);
825 if (private->extension_events != 0)
826 _gdk_input_window_destroy (window);
830 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
833 if (draw_impl->xft_draw)
834 XftDrawDestroy (draw_impl->xft_draw);
835 #else /* !HAVE_XFT2 */
836 if (draw_impl->picture)
837 XRenderFreePicture (GDK_DRAWABLE_XDISPLAY (window), draw_impl->picture);
838 #endif /* HAVE_XFT2 */
840 #endif /* HAVE_XFT */
842 if (private->window_type == GDK_WINDOW_FOREIGN)
844 if (!foreign_destroy && (private->parent != NULL))
846 /* It's somebody else's window, but in our heirarchy,
847 * so reparent it to the root window, and then send
848 * it a delete event, as if we were a WM
850 XClientMessageEvent xevent;
852 gdk_error_trap_push ();
853 gdk_window_hide (window);
854 gdk_window_reparent (window, NULL, 0, 0);
856 xevent.type = ClientMessage;
857 xevent.window = GDK_WINDOW_XID (window);
858 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
861 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
863 xevent.data.l[1] = CurrentTime;
865 XSendEvent (GDK_WINDOW_XDISPLAY (window),
866 GDK_WINDOW_XID (window),
867 False, 0, (XEvent *)&xevent);
868 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
869 gdk_error_trap_pop ();
872 else if (!recursing && !foreign_destroy)
874 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
878 /* This function is called when the XWindow is really gone.
881 gdk_window_destroy_notify (GdkWindow *window)
883 GdkWindowImplX11 *window_impl;
885 g_return_if_fail (window != NULL);
887 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
889 if (!GDK_WINDOW_DESTROYED (window))
891 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
892 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
894 _gdk_window_destroy (window, TRUE);
897 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
898 if (window_impl->focus_window)
899 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->focus_window);
901 _gdk_xgrab_check_destroy (window);
903 g_object_unref (window);
907 set_initial_hints (GdkWindow *window)
909 GdkWindowObject *private;
913 private = (GdkWindowObject*) window;
915 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
919 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
920 GDK_WINDOW_XID (window));
922 wm_hints = XAllocWMHints ();
924 wm_hints->flags |= StateHint;
925 wm_hints->initial_state = IconicState;
927 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
928 GDK_WINDOW_XID (window), wm_hints);
932 /* We set the spec hints regardless of whether the spec is supported,
933 * since it can't hurt and it's kind of expensive to check whether
939 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
941 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
942 "_NET_WM_STATE_MAXIMIZED_VERT");
944 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
945 "_NET_WM_STATE_MAXIMIZED_HORZ");
949 if (private->state & GDK_WINDOW_STATE_STICKY)
951 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
952 "_NET_WM_STATE_STICKY");
956 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
958 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
959 "_NET_WM_STATE_FULLSCREEN");
963 if (private->modal_hint)
965 atoms[i] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
966 "_NET_WM_STATE_MODAL");
972 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
973 GDK_WINDOW_XID (window),
974 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_STATE"),
975 XA_ATOM, 32, PropModeReplace,
979 if (private->state & GDK_WINDOW_STATE_STICKY)
981 atoms[0] = 0xFFFFFFFF;
982 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
983 GDK_WINDOW_XID (window),
984 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), "_NET_WM_DESKTOP"),
985 XA_CARDINAL, 32, PropModeReplace,
991 show_window_internal (GdkWindow *window,
994 GdkWindowObject *private;
996 g_return_if_fail (GDK_IS_WINDOW (window));
998 private = (GdkWindowObject*) window;
999 if (!private->destroyed)
1002 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
1003 GDK_WINDOW_XID (window));
1005 if (!GDK_WINDOW_IS_MAPPED (window))
1007 set_initial_hints (window);
1009 gdk_synthesize_window_state (window,
1010 GDK_WINDOW_STATE_WITHDRAWN,
1014 g_assert (GDK_WINDOW_IS_MAPPED (window));
1016 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
1017 XMapWindow (GDK_WINDOW_XDISPLAY (window),
1018 GDK_WINDOW_XID (window));
1023 * gdk_window_show_unraised:
1024 * @window: a #GdkWindow
1026 * Shows a #GdkWindow onscreen, but does not modify its stacking
1027 * order. In contrast, gdk_window_show() will raise the window
1028 * to the top of the window stack.
1030 * On the X11 platform, in Xlib terms, this function calls
1031 * XMapWindow() (it also updates some internal GDK state, which means
1032 * that you can't really use XMapWindow() directly on a GDK window).
1036 gdk_window_show_unraised (GdkWindow *window)
1038 g_return_if_fail (GDK_IS_WINDOW (window));
1040 show_window_internal (window, FALSE);
1045 * @window: a #GdkWindow
1047 * Like gdk_window_show_unraised(), but also raises the window to the
1048 * top of the window stack (moves the window to the front of the
1051 * This function maps a window so it's visible onscreen. Its opposite
1052 * is gdk_window_hide().
1054 * When implementing a #GtkWidget, you should call this function on the widget's
1055 * #GdkWindow as part of the "map" method.
1059 gdk_window_show (GdkWindow *window)
1061 g_return_if_fail (GDK_IS_WINDOW (window));
1063 show_window_internal (window, TRUE);
1068 * @window: a #GdkWindow
1070 * For toplevel windows, withdraws them, so they will no longer be
1071 * known to the window manager; for all windows, unmaps them, so
1072 * they won't be displayed. Normally done automatically as
1073 * part of gtk_widget_hide().
1077 gdk_window_hide (GdkWindow *window)
1079 GdkWindowObject *private;
1081 g_return_if_fail (window != NULL);
1083 private = (GdkWindowObject*) window;
1085 /* We'll get the unmap notify eventually, and handle it then,
1086 * but checking here makes things more consistent if we are
1087 * just doing stuff ourself.
1089 _gdk_xgrab_check_unmap (window,
1090 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1092 /* You can't simply unmap toplevel windows. */
1093 switch (private->window_type)
1095 case GDK_WINDOW_TOPLEVEL:
1096 case GDK_WINDOW_DIALOG:
1097 case GDK_WINDOW_TEMP: /* ? */
1098 gdk_window_withdraw (window);
1102 case GDK_WINDOW_FOREIGN:
1103 case GDK_WINDOW_ROOT:
1104 case GDK_WINDOW_CHILD:
1108 if (!private->destroyed)
1110 if (GDK_WINDOW_IS_MAPPED (window))
1111 gdk_synthesize_window_state (window,
1113 GDK_WINDOW_STATE_WITHDRAWN);
1115 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1117 _gdk_window_clear_update_area (window);
1119 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1120 GDK_WINDOW_XID (window));
1125 * gdk_window_withdraw:
1126 * @window: a toplevel #GdkWindow
1128 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1129 * This function is not really useful as gdk_window_hide() automatically
1130 * withdraws toplevel windows before hiding them.
1134 gdk_window_withdraw (GdkWindow *window)
1136 GdkWindowObject *private;
1138 g_return_if_fail (window != NULL);
1140 private = (GdkWindowObject*) window;
1141 if (!private->destroyed)
1143 if (GDK_WINDOW_IS_MAPPED (window))
1144 gdk_synthesize_window_state (window,
1146 GDK_WINDOW_STATE_WITHDRAWN);
1148 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1150 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1151 GDK_WINDOW_XID (window), 0);
1157 * @window: a #GdkWindow
1158 * @x: X coordinate relative to window's parent
1159 * @y: Y coordinate relative to window's parent
1161 * Repositions a window relative to its parent window.
1162 * For toplevel windows, window managers may ignore or modify the move;
1163 * you should probably use gtk_window_move() on a #GtkWindow widget
1164 * anyway, instead of using GDK functions. For child windows,
1165 * the move will reliably succeed.
1167 * If you're also planning to resize the window, use gdk_window_move_resize()
1168 * to both move and resize simultaneously, for a nicer visual effect.
1171 gdk_window_move (GdkWindow *window,
1175 GdkWindowObject *private = (GdkWindowObject *)window;
1176 GdkWindowImplX11 *impl;
1178 g_return_if_fail (window != NULL);
1179 g_return_if_fail (GDK_IS_WINDOW (window));
1181 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1183 if (!GDK_WINDOW_DESTROYED (window))
1185 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1186 _gdk_window_move_resize_child (window, x, y,
1187 impl->width, impl->height);
1190 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1191 GDK_WINDOW_XID (window),
1198 * gdk_window_resize:
1199 * @window: a #GdkWindow
1200 * @width: new width of the window
1201 * @height: new height of the window
1203 * Resizes @window; for toplevel windows, asks the window manager to resize
1204 * the window. The window manager may not allow the resize. When using GTK+,
1205 * use gtk_window_resize() instead of this low-level GDK function.
1207 * Windows may not be resized below 1x1.
1209 * If you're also planning to move the window, use gdk_window_move_resize()
1210 * to both move and resize simultaneously, for a nicer visual effect.
1213 gdk_window_resize (GdkWindow *window,
1217 GdkWindowObject *private;
1219 g_return_if_fail (window != NULL);
1220 g_return_if_fail (GDK_IS_WINDOW (window));
1227 private = (GdkWindowObject*) window;
1229 if (!GDK_WINDOW_DESTROYED (window))
1231 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1232 _gdk_window_move_resize_child (window, private->x, private->y,
1236 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1238 if (width != impl->width || height != impl->height)
1239 private->resize_count += 1;
1241 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1242 GDK_WINDOW_XID (window),
1249 * gdk_window_move_resize:
1250 * @window: a #GdkWindow
1251 * @x: new X position relative to window's parent
1252 * @y: new Y position relative to window's parent
1254 * @height: new height
1256 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1257 * except that both operations are performed at once, avoiding strange
1258 * visual effects. (i.e. the user may be able to see the window first
1259 * move, then resize, if you don't use gdk_window_move_resize().)
1262 gdk_window_move_resize (GdkWindow *window,
1268 GdkWindowObject *private;
1270 g_return_if_fail (window != NULL);
1271 g_return_if_fail (GDK_IS_WINDOW (window));
1278 private = (GdkWindowObject*) window;
1280 if (!GDK_WINDOW_DESTROYED (window))
1282 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1283 _gdk_window_move_resize_child (window, x, y, width, height);
1286 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1288 if (width != impl->width || height != impl->height)
1289 private->resize_count += 1;
1291 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1292 GDK_WINDOW_XID (window),
1293 x, y, width, height);
1299 * gdk_window_reparent:
1300 * @window: a #GdkWindow
1301 * @new_parent: new parent to move @window into
1302 * @x: X location inside the new parent
1303 * @y: Y location inside the new parent
1305 * Reparents @window into the given @new_parent. The window being
1306 * reparented will be unmapped as a side effect.
1310 gdk_window_reparent (GdkWindow *window,
1311 GdkWindow *new_parent,
1315 GdkDisplay *display;
1316 GdkWindowObject *window_private;
1317 GdkWindowObject *parent_private;
1318 GdkWindowObject *old_parent_private;
1320 g_return_if_fail (window != NULL);
1321 g_return_if_fail (GDK_IS_WINDOW (window));
1322 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1323 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1326 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1328 display = GDK_WINDOW_DISPLAY (window);
1330 window_private = (GdkWindowObject*) window;
1331 old_parent_private = (GdkWindowObject*)window_private->parent;
1332 parent_private = (GdkWindowObject*) new_parent;
1334 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1335 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1336 GDK_WINDOW_XID (window),
1337 GDK_WINDOW_XID (new_parent),
1340 window_private->x = x;
1341 window_private->y = y;
1343 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1346 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1347 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1349 window_private->parent = (GdkWindowObject *)new_parent;
1351 /* Switch the window type as appropriate */
1353 switch (GDK_WINDOW_TYPE (new_parent))
1355 case GDK_WINDOW_ROOT:
1356 case GDK_WINDOW_FOREIGN:
1357 /* Now a toplevel */
1358 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1359 set_wm_protocols (window);
1361 case GDK_WINDOW_TOPLEVEL:
1362 case GDK_WINDOW_CHILD:
1363 case GDK_WINDOW_DIALOG:
1364 case GDK_WINDOW_TEMP:
1365 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1366 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1368 /* If we were being sophisticated, we'd save the old window type
1369 * here, and restore it if we were reparented back to the
1370 * toplevel. However, the difference between different types
1371 * of toplevels only really matters on creation anyways.
1373 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1377 if (old_parent_private)
1378 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1380 if ((old_parent_private &&
1381 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1382 (!old_parent_private && parent_private->guffaw_gravity))
1383 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1385 parent_private->children = g_list_prepend (parent_private->children, window);
1386 _gdk_window_init_position (GDK_WINDOW (window_private));
1390 _gdk_windowing_window_clear_area (GdkWindow *window,
1396 g_return_if_fail (window != NULL);
1397 g_return_if_fail (GDK_IS_WINDOW (window));
1399 if (!GDK_WINDOW_DESTROYED (window))
1400 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1401 x, y, width, height, False);
1405 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1411 g_return_if_fail (window != NULL);
1412 g_return_if_fail (GDK_IS_WINDOW (window));
1414 if (!GDK_WINDOW_DESTROYED (window))
1415 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1416 x, y, width, height, True);
1422 * @window: a #GdkWindow
1424 * Raises @window to the top of the Z-order (stacking order), so that
1425 * other windows with the same parent window appear below @window.
1426 * This is true whether or not the windows are visible.
1428 * If @window is a toplevel, the window manager may choose to deny the
1429 * request to move the window in the Z-order, gdk_window_raise() only
1430 * requests the restack, does not guarantee it.
1434 gdk_window_raise (GdkWindow *window)
1436 g_return_if_fail (window != NULL);
1437 g_return_if_fail (GDK_IS_WINDOW (window));
1439 if (!GDK_WINDOW_DESTROYED (window))
1440 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1445 * @window: a #GdkWindow
1447 * Lowers @window to the bottom of the Z-order (stacking order), so that
1448 * other windows with the same parent window appear above @window.
1449 * This is true whether or not the other windows are visible.
1451 * If @window is a toplevel, the window manager may choose to deny the
1452 * request to move the window in the Z-order, gdk_window_lower() only
1453 * requests the restack, does not guarantee it.
1455 * Note that gdk_window_show() raises the window again, so don't call this
1456 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1460 gdk_window_lower (GdkWindow *window)
1462 g_return_if_fail (window != NULL);
1463 g_return_if_fail (GDK_IS_WINDOW (window));
1465 if (!GDK_WINDOW_DESTROYED (window))
1466 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1471 * @window: a #GdkWindow
1472 * @timestamp: timestamp of the event triggering the window focus
1474 * Sets keyboard focus to @window. If @window is not onscreen this
1475 * will not work. In most cases, gtk_window_present() should be used on
1476 * a #GtkWindow, rather than calling this function.
1480 gdk_window_focus (GdkWindow *window,
1483 g_return_if_fail (GDK_IS_WINDOW (window));
1485 if (GDK_WINDOW_DESTROYED (window))
1488 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1489 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1493 xev.xclient.type = ClientMessage;
1494 xev.xclient.serial = 0;
1495 xev.xclient.send_event = True;
1496 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1497 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1498 "_NET_ACTIVE_WINDOW");
1499 xev.xclient.format = 32;
1500 xev.xclient.data.l[0] = 0;
1502 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1503 SubstructureRedirectMask | SubstructureNotifyMask,
1508 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1510 /* There is no way of knowing reliably whether we are viewable so we need
1511 * to trap errors so we don't cause a BadMatch.
1513 gdk_error_trap_push ();
1514 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1515 GDK_WINDOW_XWINDOW (window),
1518 XSync (GDK_WINDOW_XDISPLAY (window), False);
1519 gdk_error_trap_pop ();
1524 * gdk_window_set_hints:
1525 * @window: a #GdkWindow
1526 * @x: ignored field, does not matter
1527 * @y: ignored field, does not matter
1528 * @min_width: minimum width hint
1529 * @min_height: minimum height hint
1530 * @max_width: max width hint
1531 * @max_height: max height hint
1532 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1534 * This function is broken and useless and you should ignore it.
1535 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1536 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1537 * depending on what you're trying to do.
1539 * If using GDK directly, use gdk_window_set_geometry_hints().
1543 gdk_window_set_hints (GdkWindow *window,
1552 XSizeHints size_hints;
1554 g_return_if_fail (window != NULL);
1555 g_return_if_fail (GDK_IS_WINDOW (window));
1557 if (GDK_WINDOW_DESTROYED (window))
1560 size_hints.flags = 0;
1562 if (flags & GDK_HINT_POS)
1564 size_hints.flags |= PPosition;
1569 if (flags & GDK_HINT_MIN_SIZE)
1571 size_hints.flags |= PMinSize;
1572 size_hints.min_width = min_width;
1573 size_hints.min_height = min_height;
1576 if (flags & GDK_HINT_MAX_SIZE)
1578 size_hints.flags |= PMaxSize;
1579 size_hints.max_width = max_width;
1580 size_hints.max_height = max_height;
1583 /* FIXME: Would it be better to delete this property if
1584 * flags == 0? It would save space on the server
1586 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1587 GDK_WINDOW_XID (window),
1592 * gdk_window_set_type_hint:
1593 * @window: A toplevel #GdkWindow
1594 * @hint: A hint of the function this window will have
1596 * The application can use this call to provide a hint to the window
1597 * manager about the functionality of a window. The window manager
1598 * can use this information when determining the decoration and behaviour
1601 * The hint must be set before the window is mapped.
1604 gdk_window_set_type_hint (GdkWindow *window,
1605 GdkWindowTypeHint hint)
1607 GdkDisplay *display;
1610 g_return_if_fail (window != NULL);
1611 g_return_if_fail (GDK_IS_WINDOW (window));
1613 if (GDK_WINDOW_DESTROYED (window))
1616 display = gdk_drawable_get_display (window);
1620 case GDK_WINDOW_TYPE_HINT_DIALOG:
1621 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1623 case GDK_WINDOW_TYPE_HINT_MENU:
1624 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1626 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1627 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1629 case GDK_WINDOW_TYPE_HINT_UTILITY:
1630 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1632 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1633 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASHSCREEN");
1635 case GDK_WINDOW_TYPE_HINT_DOCK:
1636 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1638 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1639 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1642 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1644 case GDK_WINDOW_TYPE_HINT_NORMAL:
1645 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1649 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1650 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1651 XA_ATOM, 32, PropModeReplace,
1652 (guchar *)&atom, 1);
1657 gdk_wmspec_change_state (gboolean add,
1662 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1665 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1666 #define _NET_WM_STATE_ADD 1 /* add/set property */
1667 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1669 xev.xclient.type = ClientMessage;
1670 xev.xclient.serial = 0;
1671 xev.xclient.send_event = True;
1672 xev.xclient.window = GDK_WINDOW_XID (window);
1673 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1674 xev.xclient.format = 32;
1675 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1676 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1677 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1679 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1680 SubstructureRedirectMask | SubstructureNotifyMask,
1685 * gdk_window_set_modal_hint:
1686 * @window: A toplevel #GdkWindow
1687 * @modal: TRUE if the window is modal, FALSE otherwise.
1689 * The application can use this hint to tell the window manager
1690 * that a certain window has modal behaviour. The window manager
1691 * can use this information to handle modal windows in a special
1694 * You should only use this on windows for which you have
1695 * previously called #gdk_window_set_transient_for()
1698 gdk_window_set_modal_hint (GdkWindow *window,
1701 GdkWindowObject *private;
1703 g_return_if_fail (window != NULL);
1704 g_return_if_fail (GDK_IS_WINDOW (window));
1706 if (GDK_WINDOW_DESTROYED (window))
1709 private = (GdkWindowObject*) window;
1711 private->modal_hint = modal;
1713 if (GDK_WINDOW_IS_MAPPED (window))
1714 gdk_wmspec_change_state (modal, window,
1715 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1720 * gdk_window_set_skip_taskbar_hint:
1721 * @window: a toplevel #GdkWindow
1722 * @skips_taskbar: %TRUE to skip the taskbar
1724 * Toggles whether a window should appear in a task list or window
1725 * list. If a window's semantic type as specified with
1726 * gdk_window_set_type_hint() already fully describes the window, this
1727 * function should NOT be called in addition, instead you should allow
1728 * the window to be treated according to standard policy for its
1732 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
1733 gboolean skips_taskbar)
1735 GdkWindowObject *private;
1736 GdkWindowImplX11 *impl;
1738 g_return_if_fail (window != NULL);
1739 g_return_if_fail (GDK_IS_WINDOW (window));
1741 if (GDK_WINDOW_DESTROYED (window))
1744 private = (GdkWindowObject*) window;
1745 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1747 impl->skip_taskbar_hint = skips_taskbar;
1749 if (GDK_WINDOW_IS_MAPPED (window))
1750 gdk_wmspec_change_state (skips_taskbar, window,
1751 gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE),
1756 * gdk_window_set_skip_pager_hint:
1757 * @window: a toplevel #GdkWindow
1758 * @skips_taskbar: %TRUE to skip the pager
1760 * Toggles whether a window should appear in a pager (workspace
1761 * switcher, or other desktop utility program that displays a small
1762 * thumbnail representation of the windows on the desktop). If a
1763 * window's semantic type as specified with gdk_window_set_type_hint()
1764 * already fully describes the window, this function should NOT be
1765 * called in addition, instead you should allow the window to be
1766 * treated according to standard policy for its semantic type.
1769 gdk_window_set_skip_pager_hint (GdkWindow *window,
1770 gboolean skips_pager)
1772 GdkWindowObject *private;
1773 GdkWindowImplX11 *impl;
1775 g_return_if_fail (window != NULL);
1776 g_return_if_fail (GDK_IS_WINDOW (window));
1778 if (GDK_WINDOW_DESTROYED (window))
1781 private = (GdkWindowObject*) window;
1782 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1784 impl->skip_pager_hint = skips_pager;
1786 if (GDK_WINDOW_IS_MAPPED (window))
1787 gdk_wmspec_change_state (skips_pager, window,
1788 gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE),
1793 * gdk_window_set_geometry_hints:
1794 * @window: a toplevel #GdkWindow
1795 * @geometry: geometry hints
1796 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1798 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1799 * are set, hints not flagged in @geom_mask are unset.
1800 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1802 * This function provides hints to the windowing system about
1803 * acceptable sizes for a toplevel window. The purpose of
1804 * this is to constrain user resizing, but the windowing system
1805 * will typically (but is not required to) also constrain the
1806 * current size of the window to the provided values and
1807 * constrain programatic resizing via gdk_window_resize() or
1808 * gdk_window_move_resize().
1810 * Note that on X11, this effect has no effect on windows
1811 * of type GDK_WINDOW_TEMP or windows where override_redirect
1812 * has been turned on via gdk_window_set_override_redirect()
1813 * since these windows are not resizable by the user.
1815 * Since you can't count on the windowing system doing the
1816 * constraints for programmatic resizes, you should generally
1817 * call gdk_window_constrain_size() yourself to determine
1818 * appropriate sizes.
1822 gdk_window_set_geometry_hints (GdkWindow *window,
1823 GdkGeometry *geometry,
1824 GdkWindowHints geom_mask)
1826 XSizeHints size_hints;
1828 g_return_if_fail (window != NULL);
1829 g_return_if_fail (GDK_IS_WINDOW (window));
1831 if (GDK_WINDOW_DESTROYED (window))
1834 size_hints.flags = 0;
1836 if (geom_mask & GDK_HINT_POS)
1838 size_hints.flags |= PPosition;
1839 /* We need to initialize the following obsolete fields because KWM
1840 * apparently uses these fields if they are non-zero.
1847 if (geom_mask & GDK_HINT_USER_POS)
1849 size_hints.flags |= USPosition;
1852 if (geom_mask & GDK_HINT_USER_SIZE)
1854 size_hints.flags |= USSize;
1857 if (geom_mask & GDK_HINT_MIN_SIZE)
1859 size_hints.flags |= PMinSize;
1860 size_hints.min_width = geometry->min_width;
1861 size_hints.min_height = geometry->min_height;
1864 if (geom_mask & GDK_HINT_MAX_SIZE)
1866 size_hints.flags |= PMaxSize;
1867 size_hints.max_width = MAX (geometry->max_width, 1);
1868 size_hints.max_height = MAX (geometry->max_height, 1);
1871 if (geom_mask & GDK_HINT_BASE_SIZE)
1873 size_hints.flags |= PBaseSize;
1874 size_hints.base_width = geometry->base_width;
1875 size_hints.base_height = geometry->base_height;
1878 if (geom_mask & GDK_HINT_RESIZE_INC)
1880 size_hints.flags |= PResizeInc;
1881 size_hints.width_inc = geometry->width_inc;
1882 size_hints.height_inc = geometry->height_inc;
1885 if (geom_mask & GDK_HINT_ASPECT)
1887 size_hints.flags |= PAspect;
1888 if (geometry->min_aspect <= 1)
1890 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1891 size_hints.min_aspect.y = 65536;
1895 size_hints.min_aspect.x = 65536;
1896 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1898 if (geometry->max_aspect <= 1)
1900 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1901 size_hints.max_aspect.y = 65536;
1905 size_hints.max_aspect.x = 65536;
1906 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1910 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1912 size_hints.flags |= PWinGravity;
1913 size_hints.win_gravity = geometry->win_gravity;
1916 /* FIXME: Would it be better to delete this property if
1917 * geom_mask == 0? It would save space on the server
1919 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1920 GDK_WINDOW_XID (window),
1925 gdk_window_get_geometry_hints (GdkWindow *window,
1926 GdkGeometry *geometry,
1927 GdkWindowHints *geom_mask)
1929 XSizeHints size_hints;
1930 glong junk_size_mask = 0;
1932 g_return_if_fail (GDK_IS_WINDOW (window));
1933 g_return_if_fail (geometry != NULL);
1934 g_return_if_fail (geom_mask != NULL);
1938 if (GDK_WINDOW_DESTROYED (window))
1941 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1942 GDK_WINDOW_XID (window),
1947 if (size_hints.flags & PMinSize)
1949 *geom_mask |= GDK_HINT_MIN_SIZE;
1950 geometry->min_width = size_hints.min_width;
1951 geometry->min_height = size_hints.min_height;
1954 if (size_hints.flags & PMaxSize)
1956 *geom_mask |= GDK_HINT_MAX_SIZE;
1957 geometry->max_width = MAX (size_hints.max_width, 1);
1958 geometry->max_height = MAX (size_hints.max_height, 1);
1961 if (size_hints.flags & PResizeInc)
1963 *geom_mask |= GDK_HINT_RESIZE_INC;
1964 geometry->width_inc = size_hints.width_inc;
1965 geometry->height_inc = size_hints.height_inc;
1968 if (size_hints.flags & PAspect)
1970 *geom_mask |= GDK_HINT_ASPECT;
1972 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1973 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1976 if (size_hints.flags & PWinGravity)
1978 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1979 geometry->win_gravity = size_hints.win_gravity;
1984 utf8_is_latin1 (const gchar *str)
1986 const char *p = str;
1990 gunichar ch = g_utf8_get_char (p);
1995 p = g_utf8_next_char (p);
2001 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2002 * convertable to STRING, otherwise, set it as compound text
2005 set_text_property (GdkWindow *window,
2007 const gchar *utf8_str)
2009 guchar *prop_text = NULL;
2014 if (utf8_is_latin1 (utf8_str))
2016 prop_type = XA_STRING;
2017 prop_text = gdk_utf8_to_string_target (utf8_str);
2018 prop_length = prop_text ? strlen (prop_text) : 0;
2025 gdk_utf8_to_compound_text_for_display (gdk_drawable_get_display (window),
2026 utf8_str, &gdk_type, &prop_format,
2027 &prop_text, &prop_length);
2028 prop_type = gdk_x11_atom_to_xatom_for_display
2029 (GDK_WINDOW_DISPLAY (window), gdk_type);
2034 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2035 GDK_WINDOW_XID (window),
2037 prop_type, prop_format,
2038 PropModeReplace, prop_text,
2046 * gdk_window_set_title:
2047 * @window: a toplevel #GdkWindow
2048 * @title: title of @window
2050 * Sets the title of a toplevel window, to be displayed in the titlebar.
2051 * If you haven't explicitly set the icon name for the window
2052 * (using gdk_window_set_icon_name()), the icon name will be set to
2053 * @title as well. @title must be in UTF-8 encoding (as with all
2054 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2057 gdk_window_set_title (GdkWindow *window,
2060 GdkDisplay *display;
2062 g_return_if_fail (window != NULL);
2063 g_return_if_fail (GDK_IS_WINDOW (window));
2064 g_return_if_fail (title != NULL);
2066 if (GDK_WINDOW_DESTROYED (window))
2069 display = gdk_drawable_get_display (window);
2071 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2072 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2073 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2074 PropModeReplace, title, strlen (title));
2076 set_text_property (window,
2077 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2080 if (!gdk_window_icon_name_set (window))
2082 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2083 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2084 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2085 PropModeReplace, title, strlen (title));
2087 set_text_property (window,
2088 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2094 * gdk_window_set_role:
2095 * @window: a toplevel #GdkWindow
2096 * @role: a string indicating its role
2098 * When using GTK+, typically you should use gtk_window_set_role() instead
2099 * of this low-level function.
2101 * The window manager and session manager use a window's role to
2102 * distinguish it from other kinds of window in the same application.
2103 * When an application is restarted after being saved in a previous
2104 * session, all windows with the same title and role are treated as
2105 * interchangeable. So if you have two windows with the same title
2106 * that should be distinguished for session management purposes, you
2107 * should set the role on those windows. It doesn't matter what string
2108 * you use for the role, as long as you have a different role for each
2109 * non-interchangeable kind of window.
2113 gdk_window_set_role (GdkWindow *window,
2116 GdkDisplay *display;
2118 g_return_if_fail (window != NULL);
2119 g_return_if_fail (GDK_IS_WINDOW (window));
2121 display = gdk_drawable_get_display (window);
2123 if (!GDK_WINDOW_DESTROYED (window))
2126 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2127 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2128 XA_STRING, 8, PropModeReplace, role, strlen (role));
2130 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2131 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2136 * gdk_window_set_transient_for:
2137 * @window: a toplevel #GdkWindow
2138 * @parent: another toplevel #GdkWindow
2140 * Indicates to the window manager that @window is a transient dialog
2141 * associated with the application window @parent. This allows the
2142 * window manager to do things like center @window on @parent and
2143 * keep @window above @parent.
2145 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2150 gdk_window_set_transient_for (GdkWindow *window,
2153 GdkWindowObject *private;
2154 GdkWindowObject *parent_private;
2156 g_return_if_fail (window != NULL);
2157 g_return_if_fail (GDK_IS_WINDOW (window));
2159 private = (GdkWindowObject*) window;
2160 parent_private = (GdkWindowObject*) parent;
2162 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2163 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2164 GDK_WINDOW_XID (window),
2165 GDK_WINDOW_XID (parent));
2169 * gdk_window_set_background:
2170 * @window: a #GdkWindow
2171 * @color: an allocated #GdkColor
2173 * Sets the background color of @window. (However, when using GTK+,
2174 * set the background of a widget with gtk_widget_modify_bg() - if
2175 * you're an application - or gtk_style_set_background() - if you're
2176 * implementing a custom widget.)
2178 * The @color must be allocated; gdk_rgb_find_color() is the best way
2179 * to allocate a color.
2181 * See also gdk_window_set_back_pixmap().
2185 gdk_window_set_background (GdkWindow *window,
2188 GdkWindowObject *private = (GdkWindowObject *)window;
2190 g_return_if_fail (window != NULL);
2191 g_return_if_fail (GDK_IS_WINDOW (window));
2193 if (!GDK_WINDOW_DESTROYED (window))
2194 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2195 GDK_WINDOW_XID (window), color->pixel);
2197 private->bg_color = *color;
2199 if (private->bg_pixmap &&
2200 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2201 private->bg_pixmap != GDK_NO_BG)
2202 g_object_unref (private->bg_pixmap);
2204 private->bg_pixmap = NULL;
2208 * gdk_window_set_back_pixmap:
2209 * @window: a #GdkWindow
2210 * @pixmap: a #GdkPixmap, or %NULL
2211 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2213 * Sets the background pixmap of @window. May also be used to set a background of
2214 * "None" on @window, by setting a background pixmap of %NULL.
2215 * A background pixmap will be tiled, positioning the first tile at the origin of
2216 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2217 * origin of the parent window (useful to align tiles in a parent with tiles
2220 * A background pixmap of %NULL means that the window will have no
2221 * background. A window with no background will never have its
2222 * background filled by the windowing system, instead the window will
2223 * contain whatever pixels were already in the corresponding area of
2226 * The windowing system will normally fill a window with its background
2227 * when the window is obscured then exposed, and when you call
2228 * gdk_window_clear().
2232 gdk_window_set_back_pixmap (GdkWindow *window,
2234 gboolean parent_relative)
2236 GdkWindowObject *private = (GdkWindowObject *)window;
2239 g_return_if_fail (window != NULL);
2240 g_return_if_fail (GDK_IS_WINDOW (window));
2241 g_return_if_fail (pixmap == NULL || !parent_relative);
2242 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2244 if (private->bg_pixmap &&
2245 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2246 private->bg_pixmap != GDK_NO_BG)
2247 g_object_unref (private->bg_pixmap);
2249 if (parent_relative)
2251 xpixmap = ParentRelative;
2252 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2258 g_object_ref (pixmap);
2259 private->bg_pixmap = pixmap;
2260 xpixmap = GDK_PIXMAP_XID (pixmap);
2265 private->bg_pixmap = GDK_NO_BG;
2269 if (!GDK_WINDOW_DESTROYED (window))
2270 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2271 GDK_WINDOW_XID (window), xpixmap);
2275 * gdk_window_set_cursor:
2276 * @window: a #GdkWindow
2279 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2280 * gdk_cursor_new_from_pixmap() to create the cursor.
2281 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2282 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2283 * to gdk_window_set_cursor() means that @window will use the cursor of
2284 * its parent window. Most windows should use this default.
2288 gdk_window_set_cursor (GdkWindow *window,
2291 GdkCursorPrivate *cursor_private;
2294 g_return_if_fail (window != NULL);
2295 g_return_if_fail (GDK_IS_WINDOW (window));
2297 cursor_private = (GdkCursorPrivate*) cursor;
2302 xcursor = cursor_private->xcursor;
2304 if (!GDK_WINDOW_DESTROYED (window))
2305 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2306 GDK_WINDOW_XID (window),
2311 * gdk_window_get_geometry:
2312 * @window: a #GdkWindow
2313 * @x: return location for X coordinate of window (relative to its parent)
2314 * @y: return location for Y coordinate of window (relative to its parent)
2315 * @width: return location for width of window
2316 * @height: return location for height of window
2317 * @depth: return location for bit depth of window
2319 * Any of the return location arguments to this function may be %NULL,
2320 * if you aren't interested in getting the value of that field.
2322 * The X and Y coordinates returned are relative to the parent window
2323 * of @window, which for toplevels usually means relative to the
2324 * window decorations (titlebar, etc.) rather than relative to the
2325 * root window (screen-size background window).
2327 * On the X11 platform, the geometry is obtained from the X server,
2328 * so reflects the latest position of @window; this may be out-of-sync
2329 * with the position of @window delivered in the most-recently-processed
2330 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2331 * position from the most recent configure event.
2335 gdk_window_get_geometry (GdkWindow *window,
2347 guint tborder_width;
2350 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2354 GDK_NOTE (MULTIHEAD,
2355 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2356 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
2359 if (!GDK_WINDOW_DESTROYED (window))
2361 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2362 GDK_WINDOW_XID (window),
2363 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2379 * gdk_window_get_origin:
2380 * @window: a #GdkWindow
2381 * @x: return location for X coordinate
2382 * @y: return location for Y coordinate
2384 * Obtains the position of a window in root window coordinates.
2385 * (Compare with gdk_window_get_position() and
2386 * gdk_window_get_geometry() which return the position of a window
2387 * relative to its parent window.)
2389 * Return value: not meaningful, ignore
2392 gdk_window_get_origin (GdkWindow *window,
2401 g_return_val_if_fail (window != NULL, 0);
2403 if (!GDK_WINDOW_DESTROYED (window))
2405 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2406 GDK_WINDOW_XID (window),
2407 GDK_WINDOW_XROOTWIN (window),
2423 * gdk_window_get_deskrelative_origin:
2424 * @window: a toplevel #GdkWindow
2425 * @x: return location for X coordinate
2426 * @y: return location for Y coordinate
2428 * This gets the origin of a #GdkWindow relative to
2429 * an Enlightenment-window-manager desktop. As long as you don't
2430 * assume that the user's desktop/workspace covers the entire
2431 * root window (i.e. you don't assume that the desktop begins
2432 * at root window coordinate 0,0) this function is not necessary.
2433 * It's deprecated for that reason.
2435 * Return value: not meaningful
2438 gdk_window_get_deskrelative_origin (GdkWindow *window,
2442 gboolean return_val = FALSE;
2443 gint num_children, format_return;
2444 Window win, *child, parent, root;
2449 gulong number_return, bytes_after_return;
2450 guchar *data_return;
2452 g_return_val_if_fail (window != NULL, 0);
2453 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2455 if (!GDK_WINDOW_DESTROYED (window))
2457 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2458 "ENLIGHTENMENT_DESKTOP");
2459 win = GDK_WINDOW_XID (window);
2461 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2462 &child, (unsigned int *)&num_children))
2464 if ((child) && (num_children > 0))
2476 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2477 False, XA_CARDINAL, &type_return, &format_return,
2478 &number_return, &bytes_after_return, &data_return);
2480 if (type_return == XA_CARDINAL)
2482 XFree (data_return);
2487 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2488 GDK_WINDOW_XID (window),
2503 * gdk_window_get_root_origin:
2504 * @window: a toplevel #GdkWindow
2505 * @x: return location for X position of window frame
2506 * @y: return location for Y position of window frame
2508 * Obtains the top-left corner of the window manager frame in root
2509 * window coordinates.
2513 gdk_window_get_root_origin (GdkWindow *window,
2519 g_return_if_fail (GDK_IS_WINDOW (window));
2521 gdk_window_get_frame_extents (window, &rect);
2531 * gdk_window_get_frame_extents:
2532 * @window: a toplevel #GdkWindow
2533 * @rect: rectangle to fill with bounding box of the window frame
2535 * Obtains the bounding box of the window, including window manager
2536 * titlebar/borders if any. The frame position is given in root window
2537 * coordinates. To get the position of the window itself (rather than
2538 * the frame) in root window coordinates, use gdk_window_get_origin().
2542 gdk_window_get_frame_extents (GdkWindow *window,
2545 GdkWindowObject *private;
2550 unsigned int nchildren;
2552 g_return_if_fail (GDK_IS_WINDOW (window));
2553 g_return_if_fail (rect != NULL);
2555 private = (GdkWindowObject*) window;
2562 if (GDK_WINDOW_DESTROYED (window))
2565 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2566 private = (GdkWindowObject*) private->parent;
2567 if (GDK_WINDOW_DESTROYED (window))
2570 xparent = GDK_WINDOW_XID (window);
2574 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2576 &children, &nchildren))
2582 while (xparent != root);
2584 if (xparent == root)
2586 unsigned int ww, wh, wb, wd;
2589 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2600 _gdk_windowing_get_pointer (GdkDisplay *display,
2604 GdkModifierType *mask)
2606 GdkScreen *default_screen;
2614 if (display->closed)
2617 default_screen = gdk_display_get_default_screen (display);
2619 XQueryPointer (GDK_SCREEN_XDISPLAY (default_screen),
2620 GDK_SCREEN_XROOTWIN (default_screen),
2621 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2625 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
2626 *screen = gdk_drawable_get_screen (gdk_root);
2635 _gdk_windowing_window_get_pointer (GdkDisplay *display,
2639 GdkModifierType *mask)
2641 GdkWindow *return_val;
2647 unsigned int xmask = 0;
2648 gint xoffset, yoffset;
2650 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2652 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2655 if (!GDK_WINDOW_DESTROYED (window) &&
2656 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2657 GDK_WINDOW_XID (window),
2658 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2661 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
2664 *x = winx + xoffset;
2665 *y = winy + yoffset;
2672 _gdk_windowing_window_at_pointer (GdkDisplay *display,
2681 Window xwindow_last = 0;
2683 int rootx = -1, rooty = -1;
2687 screen = gdk_display_get_default_screen (display);
2689 xwindow = GDK_SCREEN_XROOTWIN (screen);
2690 xdisplay = GDK_SCREEN_XDISPLAY (screen);
2692 /* This function really only works if the mouse pointer is held still
2693 * during its operation. If it moves from one leaf window to another
2694 * than we'll end up with inaccurate values for win_x, win_y
2697 XGrabServer (xdisplay);
2698 XQueryPointer (xdisplay, xwindow,
2699 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2701 if (root == xwindow)
2708 xwindow_last = xwindow;
2709 XQueryPointer (xdisplay, xwindow,
2710 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
2712 XUngrabServer (xdisplay);
2714 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
2716 *win_x = window ? winx : -1;
2717 *win_y = window ? winy : -1;
2723 * gdk_window_get_events:
2724 * @window: a #GdkWindow
2726 * Gets the event mask for @window. See gdk_window_set_events().
2728 * Return value: event mask for @window
2731 gdk_window_get_events (GdkWindow *window)
2733 XWindowAttributes attrs;
2734 GdkEventMask event_mask;
2736 g_return_val_if_fail (window != NULL, 0);
2737 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2739 if (GDK_WINDOW_DESTROYED (window))
2743 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2744 GDK_WINDOW_XID (window),
2747 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2748 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2755 * gdk_window_set_events:
2756 * @window: a #GdkWindow
2757 * @event_mask: event mask for @window
2759 * The event mask for a window determines which events will be reported
2760 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2761 * means the window should report button press events. The event mask
2762 * is the bitwise OR of values from the #GdkEventMask enumeration.
2766 gdk_window_set_events (GdkWindow *window,
2767 GdkEventMask event_mask)
2772 g_return_if_fail (window != NULL);
2773 g_return_if_fail (GDK_IS_WINDOW (window));
2775 if (!GDK_WINDOW_DESTROYED (window))
2777 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2778 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2779 for (i = 0; i < _gdk_nenvent_masks; i++)
2781 if (event_mask & (1 << (i + 1)))
2782 xevent_mask |= _gdk_event_mask_table[i];
2785 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2786 GDK_WINDOW_XID (window),
2792 gdk_window_add_colormap_windows (GdkWindow *window)
2794 GdkWindow *toplevel;
2795 Window *old_windows;
2796 Window *new_windows;
2799 g_return_if_fail (window != NULL);
2800 g_return_if_fail (GDK_IS_WINDOW (window));
2802 if (GDK_WINDOW_DESTROYED (window))
2804 toplevel = gdk_window_get_toplevel (window);
2807 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2808 GDK_WINDOW_XID (toplevel),
2809 &old_windows, &count))
2814 for (i = 0; i < count; i++)
2815 if (old_windows[i] == GDK_WINDOW_XID (window))
2817 XFree (old_windows);
2821 new_windows = g_new (Window, count + 1);
2823 for (i = 0; i < count; i++)
2824 new_windows[i] = old_windows[i];
2825 new_windows[count] = GDK_WINDOW_XID (window);
2827 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2828 GDK_WINDOW_XID (toplevel),
2829 new_windows, count + 1);
2831 g_free (new_windows);
2833 XFree (old_windows);
2837 gdk_window_have_shape_ext (GdkDisplay *display)
2839 GdkDisplayX11 *display_x11;
2841 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2843 display_x11 = GDK_DISPLAY_X11 (display);
2845 if (display_x11->have_shape == GDK_UNKNOWN)
2848 if (XQueryExtension (display_x11->xdisplay, "SHAPE", &ignore, &ignore, &ignore))
2849 display_x11->have_shape = GDK_YES;
2851 display_x11->have_shape = GDK_NO;
2854 return (display_x11->have_shape == GDK_YES);
2857 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2860 * This needs the X11 shape extension.
2861 * If not available, shaped windows will look
2862 * ugly, but programs still work. Stefan Wille
2865 * gdk_window_shape_combine_mask:
2866 * @window: a #GdkWindow
2868 * @x: X position of shape mask with respect to @window
2869 * @y: Y position of shape mask with respect to @window
2871 * Applies a shape mask to @window. Pixels in @window corresponding to
2872 * set bits in the @mask will be visible; pixels in @window
2873 * corresponding to unset bits in the @mask will be transparent. This
2874 * gives a non-rectangular window.
2876 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2877 * parameters are not used.
2879 * On the X11 platform, this uses an X server extension which is
2880 * widely available on most common platforms, but not available on
2881 * very old X servers, and occasionally the implementation will be
2882 * buggy. On servers without the shape extension, this function
2885 * This function works on both toplevel and child windows.
2889 gdk_window_shape_combine_mask (GdkWindow *window,
2894 gint xoffset, yoffset;
2896 g_return_if_fail (window != NULL);
2897 g_return_if_fail (GDK_IS_WINDOW (window));
2899 #ifdef HAVE_SHAPE_EXT
2900 if (GDK_WINDOW_DESTROYED (window))
2903 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2905 if (xoffset != 0 || yoffset != 0)
2907 WARN_SHAPE_TOO_BIG ();
2911 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2915 pixmap = GDK_PIXMAP_XID (mask);
2924 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2925 GDK_WINDOW_XID (window),
2931 #endif /* HAVE_SHAPE_EXT */
2935 * gdk_window_shape_combine_region:
2936 * @window: a #GdkWindow
2937 * @shape_region: region of window to be non-transparent
2938 * @offset_x: X position of @shape_region in @window coordinates
2939 * @offset_y: Y position of @shape_region in @window coordinates
2941 * Makes pixels in @window outside @shape_region be transparent,
2942 * so that the window may be nonrectangular. See also
2943 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2945 * If @shape_region is %NULL, the shape will be unset, so the whole
2946 * window will be opaque again. @offset_x and @offset_y are ignored
2947 * if @shape_region is %NULL.
2949 * On the X11 platform, this uses an X server extension which is
2950 * widely available on most common platforms, but not available on
2951 * very old X servers, and occasionally the implementation will be
2952 * buggy. On servers without the shape extension, this function
2955 * This function works on both toplevel and child windows.
2959 gdk_window_shape_combine_region (GdkWindow *window,
2960 GdkRegion *shape_region,
2964 gint xoffset, yoffset;
2966 g_return_if_fail (GDK_IS_WINDOW (window));
2968 #ifdef HAVE_SHAPE_EXT
2969 if (GDK_WINDOW_DESTROYED (window))
2972 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2974 if (xoffset != 0 || yoffset != 0)
2976 WARN_SHAPE_TOO_BIG ();
2980 if (shape_region == NULL)
2982 /* Use NULL mask to unset the shape */
2983 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2987 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
2990 XRectangle *xrects = NULL;
2992 _gdk_region_get_xrectangles (shape_region,
2996 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2997 GDK_WINDOW_XID (window),
3006 #endif /* HAVE_SHAPE_EXT */
3011 * gdk_window_set_override_redirect:
3012 * @window: a toplevel #GdkWindow
3013 * @override_redirect: %TRUE if window should be override redirect
3015 * An override redirect window is not under the control of the window manager.
3016 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3017 * be entirely under the control of the application. The window manager
3018 * can't see the override redirect window at all.
3020 * Override redirect should only be used for short-lived temporary
3021 * windows, such as popup menus. #GtkMenu uses an override redirect
3022 * window in its implementation, for example.
3026 gdk_window_set_override_redirect (GdkWindow *window,
3027 gboolean override_redirect)
3029 XSetWindowAttributes attr;
3031 g_return_if_fail (window != NULL);
3032 g_return_if_fail (GDK_IS_WINDOW (window));
3034 if (!GDK_WINDOW_DESTROYED (window))
3036 attr.override_redirect = (override_redirect == FALSE)?False:True;
3037 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3038 GDK_WINDOW_XID (window),
3046 * gdk_window_set_icon_list:
3047 * @window: The #GdkWindow toplevel window to set the icon of.
3048 * @pixbufs: A list of pixbufs, of different sizes.
3050 * Sets a list of icons for the window. One of these will be used
3051 * to represent the window when it has been iconified. The icon is
3052 * usually shown in an icon box or some sort of task bar. Which icon
3053 * size is shown depends on the window manager. The window manager
3054 * can scale the icon but setting several size icons can give better
3055 * image quality since the window manager may only need to scale the
3056 * icon by a small amount or not at all.
3060 gdk_window_set_icon_list (GdkWindow *window,
3069 gint width, height, stride;
3072 GdkDisplay *display;
3074 g_return_if_fail (GDK_IS_WINDOW (window));
3076 if (GDK_WINDOW_DESTROYED (window))
3079 display = gdk_drawable_get_display (window);
3087 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3089 width = gdk_pixbuf_get_width (pixbuf);
3090 height = gdk_pixbuf_get_height (pixbuf);
3092 size += 2 + width * height;
3094 l = g_list_next (l);
3097 data = g_malloc (size * sizeof (gulong));
3105 width = gdk_pixbuf_get_width (pixbuf);
3106 height = gdk_pixbuf_get_height (pixbuf);
3107 stride = gdk_pixbuf_get_rowstride (pixbuf);
3108 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3113 pixels = gdk_pixbuf_get_pixels (pixbuf);
3115 for (y = 0; y < height; y++)
3117 for (x = 0; x < width; x++)
3121 r = pixels[y*stride + x*n_channels + 0];
3122 g = pixels[y*stride + x*n_channels + 1];
3123 b = pixels[y*stride + x*n_channels + 2];
3124 if (n_channels >= 4)
3125 a = pixels[y*stride + x*n_channels + 3];
3129 *p++ = a << 24 | r << 16 | g << 8 | b ;
3133 l = g_list_next (l);
3138 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3139 GDK_WINDOW_XID (window),
3140 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3143 (guchar*) data, size);
3147 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3148 GDK_WINDOW_XID (window),
3149 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3156 * gdk_window_set_icon:
3157 * @window: a toplevel #GdkWindow
3158 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3159 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3160 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3162 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3163 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3164 * and gtk_window_set_icon(). If those don't meet your needs, look at
3165 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3166 * want to fall back to gdk_window_set_icon().
3170 gdk_window_set_icon (GdkWindow *window,
3171 GdkWindow *icon_window,
3177 g_return_if_fail (window != NULL);
3178 g_return_if_fail (GDK_IS_WINDOW (window));
3180 if (GDK_WINDOW_DESTROYED (window))
3183 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3184 GDK_WINDOW_XID (window));
3186 wm_hints = XAllocWMHints ();
3188 if (icon_window != NULL)
3190 wm_hints->flags |= IconWindowHint;
3191 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
3196 wm_hints->flags |= IconPixmapHint;
3197 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
3202 wm_hints->flags |= IconMaskHint;
3203 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
3206 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3207 GDK_WINDOW_XID (window), wm_hints);
3212 gdk_window_icon_name_set (GdkWindow *window)
3214 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3215 g_quark_from_static_string ("gdk-icon-name-set")));
3219 * gdk_window_set_icon_name:
3220 * @window: a toplevel #GdkWindow
3221 * @name: name of window while iconified (minimized)
3223 * Windows may have a name used while minimized, distinct from the
3224 * name they display in their titlebar. Most of the time this is a bad
3225 * idea from a user interface standpoint. But you can set such a name
3226 * with this function, if you like.
3230 gdk_window_set_icon_name (GdkWindow *window,
3233 GdkDisplay *display;
3235 g_return_if_fail (window != NULL);
3236 g_return_if_fail (GDK_IS_WINDOW (window));
3238 if (GDK_WINDOW_DESTROYED (window))
3241 display = gdk_drawable_get_display (window);
3243 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3244 GUINT_TO_POINTER (TRUE));
3246 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
3247 GDK_WINDOW_XID (window),
3248 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3249 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3250 PropModeReplace, name, strlen (name));
3252 set_text_property (window,
3253 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3258 * gdk_window_iconify:
3259 * @window: a toplevel #GdkWindow
3261 * Asks to iconify (minimize) @window. The window manager may choose
3262 * to ignore the request, but normally will honor it. Using
3263 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3265 * This function only makes sense when @window is a toplevel window.
3269 gdk_window_iconify (GdkWindow *window)
3271 GdkWindowObject *private;
3273 g_return_if_fail (window != NULL);
3274 g_return_if_fail (GDK_IS_WINDOW (window));
3276 if (GDK_WINDOW_DESTROYED (window))
3279 private = (GdkWindowObject*) window;
3281 if (GDK_WINDOW_IS_MAPPED (window))
3283 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3284 GDK_WINDOW_XWINDOW (window),
3285 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3289 /* Flip our client side flag, the real work happens on map. */
3290 gdk_synthesize_window_state (window,
3292 GDK_WINDOW_STATE_ICONIFIED);
3297 * gdk_window_deiconify:
3298 * @window: a toplevel #GdkWindow
3300 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3301 * choose to ignore the request to deiconify. When using GTK+,
3302 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3303 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3304 * unminimizes it, and puts it on the current desktop.
3308 gdk_window_deiconify (GdkWindow *window)
3310 GdkWindowObject *private;
3312 g_return_if_fail (window != NULL);
3313 g_return_if_fail (GDK_IS_WINDOW (window));
3315 if (GDK_WINDOW_DESTROYED (window))
3318 private = (GdkWindowObject*) window;
3320 if (GDK_WINDOW_IS_MAPPED (window))
3322 gdk_window_show (window);
3326 /* Flip our client side flag, the real work happens on map. */
3327 gdk_synthesize_window_state (window,
3328 GDK_WINDOW_STATE_ICONIFIED,
3335 * @window: a toplevel #GdkWindow
3337 * "Pins" a window such that it's on all workspaces and does not scroll
3338 * with viewports, for window managers that have scrollable viewports.
3339 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3341 * On the X11 platform, this function depends on window manager
3342 * support, so may have no effect with many window managers. However,
3343 * GDK will do the best it can to convince the window manager to stick
3344 * the window. For window managers that don't support this operation,
3345 * there's nothing you can do to force it to happen.
3349 gdk_window_stick (GdkWindow *window)
3351 g_return_if_fail (GDK_IS_WINDOW (window));
3353 if (GDK_WINDOW_DESTROYED (window))
3356 if (GDK_WINDOW_IS_MAPPED (window))
3358 /* "stick" means stick to all desktops _and_ do not scroll with the
3359 * viewport. i.e. glue to the monitor glass in all cases.
3364 /* Request stick during viewport scroll */
3365 gdk_wmspec_change_state (TRUE, window,
3366 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3369 /* Request desktop 0xFFFFFFFF */
3370 xev.xclient.type = ClientMessage;
3371 xev.xclient.serial = 0;
3372 xev.xclient.send_event = True;
3373 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3374 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3375 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3377 xev.xclient.format = 32;
3379 xev.xclient.data.l[0] = 0xFFFFFFFF;
3381 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3382 SubstructureRedirectMask | SubstructureNotifyMask,
3387 /* Flip our client side flag, the real work happens on map. */
3388 gdk_synthesize_window_state (window,
3390 GDK_WINDOW_STATE_STICKY);
3395 * gdk_window_unstick:
3396 * @window: a toplevel #GdkWindow
3398 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3399 * and gtk_window_unstick().
3403 gdk_window_unstick (GdkWindow *window)
3405 g_return_if_fail (GDK_IS_WINDOW (window));
3407 if (GDK_WINDOW_DESTROYED (window))
3410 if (GDK_WINDOW_IS_MAPPED (window))
3417 gulong *current_desktop;
3418 GdkDisplay *display = gdk_drawable_get_display (window);
3420 /* Request unstick from viewport */
3421 gdk_wmspec_change_state (FALSE, window,
3422 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3425 /* Get current desktop, then set it; this is a race, but not
3426 * one that matters much in practice.
3428 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
3429 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
3431 False, XA_CARDINAL, &type, &format, &nitems,
3432 &bytes_after, (guchar **)¤t_desktop);
3434 if (type == XA_CARDINAL)
3436 xev.xclient.type = ClientMessage;
3437 xev.xclient.serial = 0;
3438 xev.xclient.send_event = True;
3439 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3440 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
3441 xev.xclient.format = 32;
3443 xev.xclient.data.l[0] = *current_desktop;
3445 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3446 SubstructureRedirectMask | SubstructureNotifyMask,
3449 XFree (current_desktop);
3454 /* Flip our client side flag, the real work happens on map. */
3455 gdk_synthesize_window_state (window,
3456 GDK_WINDOW_STATE_STICKY,
3463 * gdk_window_maximize:
3464 * @window: a toplevel #GdkWindow
3466 * Maximizes the window. If the window was already maximized, then
3467 * this function does nothing.
3469 * On X11, asks the window manager to maximize @window, if the window
3470 * manager supports this operation. Not all window managers support
3471 * this, and some deliberately ignore it or don't have a concept of
3472 * "maximized"; so you can't rely on the maximization actually
3473 * happening. But it will happen with most standard window managers,
3474 * and GDK makes a best effort to get it to happen.
3476 * On Windows, reliably maximizes the window.
3480 gdk_window_maximize (GdkWindow *window)
3482 g_return_if_fail (GDK_IS_WINDOW (window));
3484 if (GDK_WINDOW_DESTROYED (window))
3487 if (GDK_WINDOW_IS_MAPPED (window))
3488 gdk_wmspec_change_state (TRUE, window,
3489 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3490 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3492 gdk_synthesize_window_state (window,
3494 GDK_WINDOW_STATE_MAXIMIZED);
3498 * gdk_window_unmaximize:
3499 * @window: a toplevel #GdkWindow
3501 * Unmaximizes the window. If the window wasn't maximized, then this
3502 * function does nothing.
3504 * On X11, asks the window manager to unmaximize @window, if the
3505 * window manager supports this operation. Not all window managers
3506 * support this, and some deliberately ignore it or don't have a
3507 * concept of "maximized"; so you can't rely on the unmaximization
3508 * actually happening. But it will happen with most standard window
3509 * managers, and GDK makes a best effort to get it to happen.
3511 * On Windows, reliably unmaximizes the window.
3515 gdk_window_unmaximize (GdkWindow *window)
3517 g_return_if_fail (GDK_IS_WINDOW (window));
3519 if (GDK_WINDOW_DESTROYED (window))
3522 if (GDK_WINDOW_IS_MAPPED (window))
3523 gdk_wmspec_change_state (FALSE, window,
3524 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3525 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3527 gdk_synthesize_window_state (window,
3528 GDK_WINDOW_STATE_MAXIMIZED,
3533 * gdk_window_fullscreen:
3534 * @window: a toplevel #GdkWindow
3536 * Moves the window into fullscreen mode. This means the
3537 * window covers the entire screen and is above any panels
3540 * If the window was already fullscreen, then this function does nothing.
3542 * On X11, asks the window manager to put @window in a fullscreen
3543 * state, if the window manager supports this operation. Not all
3544 * window managers support this, and some deliberately ignore it or
3545 * don't have a concept of "fullscreen"; so you can't rely on the
3546 * fullscreenification actually happening. But it will happen with
3547 * most standard window managers, and GDK makes a best effort to get
3552 gdk_window_fullscreen (GdkWindow *window)
3554 g_return_if_fail (GDK_IS_WINDOW (window));
3556 if (GDK_WINDOW_DESTROYED (window))
3559 if (GDK_WINDOW_IS_MAPPED (window))
3560 gdk_wmspec_change_state (TRUE, window,
3561 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3565 gdk_synthesize_window_state (window,
3567 GDK_WINDOW_STATE_FULLSCREEN);
3571 * gdk_window_unfullscreen:
3572 * @window: a toplevel #GdkWindow
3574 * Moves the window out of fullscreen mode. If the window was not
3575 * fullscreen, does nothing.
3577 * On X11, asks the window manager to move @window out of the fullscreen
3578 * state, if the window manager supports this operation. Not all
3579 * window managers support this, and some deliberately ignore it or
3580 * don't have a concept of "fullscreen"; so you can't rely on the
3581 * unfullscreenification actually happening. But it will happen with
3582 * most standard window managers, and GDK makes a best effort to get
3587 gdk_window_unfullscreen (GdkWindow *window)
3589 g_return_if_fail (GDK_IS_WINDOW (window));
3591 if (GDK_WINDOW_DESTROYED (window))
3594 if (GDK_WINDOW_IS_MAPPED (window))
3595 gdk_wmspec_change_state (FALSE, window,
3596 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3600 gdk_synthesize_window_state (window,
3601 GDK_WINDOW_STATE_FULLSCREEN,
3607 * gdk_window_set_group:
3608 * @window: a toplevel #GdkWindow
3609 * @leader: group leader window
3611 * Sets the group leader window for @window. By default,
3612 * GDK sets the group leader for all toplevel windows
3613 * to a global window implicitly created by GDK. With this function
3614 * you can override this default.
3616 * The group leader window allows the window manager to distinguish
3617 * all windows that belong to a single application. It may for example
3618 * allow users to minimize/unminimize all windows belonging to an
3619 * application at once. You should only set a non-default group window
3620 * if your application pretends to be multiple applications.
3621 * The group leader window may not be changed after a window has been
3622 * mapped (with gdk_window_show() for example).
3626 gdk_window_set_group (GdkWindow *window,
3631 g_return_if_fail (window != NULL);
3632 g_return_if_fail (GDK_IS_WINDOW (window));
3633 g_return_if_fail (leader != NULL);
3634 g_return_if_fail (GDK_IS_WINDOW (leader));
3636 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3639 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3640 GDK_WINDOW_XID (window));
3642 wm_hints = XAllocWMHints ();
3644 wm_hints->flags |= WindowGroupHint;
3645 wm_hints->window_group = GDK_WINDOW_XID (leader);
3647 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3648 GDK_WINDOW_XID (window), wm_hints);
3652 static MotifWmHints *
3653 gdk_window_get_mwm_hints (GdkWindow *window)
3655 GdkDisplay *display;
3656 Atom hints_atom = None;
3657 MotifWmHints *hints;
3663 if (GDK_WINDOW_DESTROYED (window))
3666 display = gdk_drawable_get_display (window);
3668 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3670 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3671 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3672 False, AnyPropertyType, &type, &format, &nitems,
3673 &bytes_after, (guchar **)&hints);
3682 gdk_window_set_mwm_hints (GdkWindow *window,
3683 MotifWmHints *new_hints)
3685 GdkDisplay *display;
3686 Atom hints_atom = None;
3687 MotifWmHints *hints;
3693 if (GDK_WINDOW_DESTROYED (window))
3696 display = gdk_drawable_get_display (window);
3698 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3700 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3701 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3702 False, AnyPropertyType, &type, &format, &nitems,
3703 &bytes_after, (guchar **)&hints);
3709 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3711 hints->flags |= MWM_HINTS_FUNCTIONS;
3712 hints->functions = new_hints->functions;
3714 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3716 hints->flags |= MWM_HINTS_DECORATIONS;
3717 hints->decorations = new_hints->decorations;
3721 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3722 hints_atom, hints_atom, 32, PropModeReplace,
3723 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3725 if (hints != new_hints)
3730 * gdk_window_set_decorations:
3731 * @window: a toplevel #GdkWindow
3732 * @decorations: decoration hint mask
3734 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3735 * This function sets the traditional Motif window manager hints that tell the
3736 * window manager which decorations you would like your window to have.
3737 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3738 * using the GDK function directly.
3740 * The @decorations argument is the logical OR of the fields in
3741 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3742 * mask, the other bits indicate which decorations should be turned off.
3743 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3744 * which decorations should be turned on.
3746 * Most window managers honor a decorations hint of 0 to disable all decorations,
3747 * but very few honor all possible combinations of bits.
3751 gdk_window_set_decorations (GdkWindow *window,
3752 GdkWMDecoration decorations)
3756 g_return_if_fail (window != NULL);
3757 g_return_if_fail (GDK_IS_WINDOW (window));
3759 hints.flags = MWM_HINTS_DECORATIONS;
3760 hints.decorations = decorations;
3762 gdk_window_set_mwm_hints (window, &hints);
3766 * gdk_window_get_decorations:
3767 * @window: The toplevel #GdkWindow to get the decorations from
3768 * @decorations: The window decorations will be written here
3770 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3771 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3774 gdk_window_get_decorations(GdkWindow *window,
3775 GdkWMDecoration *decorations)
3777 MotifWmHints *hints;
3778 gboolean result = FALSE;
3780 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3782 hints = gdk_window_get_mwm_hints (window);
3786 if (hints->flags & MWM_HINTS_DECORATIONS)
3789 *decorations = hints->decorations;
3800 * gdk_window_set_functions:
3801 * @window: a toplevel #GdkWindow
3802 * @functions: bitmask of operations to allow on @window
3804 * This function isn't really good for much. It sets the traditional
3805 * Motif window manager hint for which operations the window manager
3806 * should allow on a toplevel window. However, few window managers do
3807 * anything reliable or interesting with this hint. Many ignore it
3810 * The @functions argument is the logical OR of values from the
3811 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3812 * then the other bits indicate which functions to disable; if
3813 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3818 gdk_window_set_functions (GdkWindow *window,
3819 GdkWMFunction functions)
3823 g_return_if_fail (window != NULL);
3824 g_return_if_fail (GDK_IS_WINDOW (window));
3826 hints.flags = MWM_HINTS_FUNCTIONS;
3827 hints.functions = functions;
3829 gdk_window_set_mwm_hints (window, &hints);
3832 #ifdef HAVE_SHAPE_EXT
3835 * propagate the shapes from all child windows of a GDK window to the parent
3836 * window. Shamelessly ripped from Enlightenment's code
3844 struct _gdk_span *next;
3848 gdk_add_to_span (struct _gdk_span **s,
3852 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3859 /* scan the spans for this line */
3862 /* -- -> new span */
3863 /* == -> existing span */
3864 /* ## -> spans intersect */
3865 /* if we are in the middle of spanning the span into the line */
3868 /* case: ---- ==== */
3869 if (xx < ptr1->start - 1)
3871 /* ends before next span - extend to here */
3875 /* case: ----##=== */
3876 else if (xx <= ptr1->end)
3878 /* crosses into next span - delete next span and append */
3879 ss->end = ptr1->end;
3880 ss->next = ptr1->next;
3884 /* case: ---###--- */
3887 /* overlaps next span - delete and keep checking */
3888 ss->next = ptr1->next;
3893 /* otherwise havent started spanning it in yet */
3896 /* case: ---- ==== */
3897 if (xx < ptr1->start - 1)
3899 /* insert span here in list */
3900 noo = g_malloc (sizeof (struct _gdk_span));
3914 /* case: ----##=== */
3915 else if ((x < ptr1->start) && (xx <= ptr1->end))
3917 /* expand this span to the left point of the new one */
3921 /* case: ===###=== */
3922 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3924 /* throw the span away */
3927 /* case: ---###--- */
3928 else if ((x < ptr1->start) && (xx > ptr1->end))
3935 /* case: ===##---- */
3936 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3942 /* case: ==== ---- */
3943 /* case handled by next loop iteration - first case */
3948 /* it started in the middle but spans beyond your current list */
3954 /* it does not start inside a span or in the middle, so add it to the end */
3955 noo = g_malloc (sizeof (struct _gdk_span));
3963 noo->next = ptr2->next;
3976 gdk_add_rectangles (Display *disp,
3978 struct _gdk_span **spans,
3985 gint x1, y1, x2, y2;
3989 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
3992 /* go through all clip rects in this window's shape */
3993 for (k = 0; k < rn; k++)
3995 /* for each clip rect, add it to each line's spans */
3997 x2 = x + rl[k].x + (rl[k].width - 1);
3999 y2 = y + rl[k].y + (rl[k].height - 1);
4008 for (a = y1; a <= y2; a++)
4011 gdk_add_to_span (&spans[a], x1, x2);
4019 gdk_propagate_shapes (Display *disp,
4023 Window rt, par, *list = NULL;
4024 gint i, j, num = 0, num_rects = 0;
4028 XRectangle *rects = NULL;
4029 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
4030 XWindowAttributes xatt;
4032 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
4037 spans = g_malloc (sizeof (struct _gdk_span *) * h);
4039 for (i = 0; i < h; i++)
4041 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
4044 /* go through all child windows and create/insert spans */
4045 for (i = 0; i < num; i++)
4047 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
4048 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
4049 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
4052 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
4054 /* go through the spans list and build a list of rects */
4055 rects = g_malloc (sizeof (XRectangle) * 256);
4057 for (i = 0; i < baseh; i++)
4060 /* go through the line for all spans */
4063 rects[num_rects].x = ptr1->start;
4064 rects[num_rects].y = i;
4065 rects[num_rects].width = ptr1->end - ptr1->start + 1;
4066 rects[num_rects].height = 1;
4068 /* if there are more lines */
4070 /* while contigous rects (same start/end coords) exist */
4071 while ((contig) && (j < baseh))
4073 /* search next line for spans matching this one */
4079 /* if we have an exact span match set contig */
4080 if ((ptr2->start == ptr1->start) &&
4081 (ptr2->end == ptr1->end))
4084 /* remove the span - not needed */
4087 ptr3->next = ptr2->next;
4093 spans[j] = ptr2->next;
4099 /* gone past the span point no point looking */
4100 else if (ptr2->start < ptr1->start)
4108 /* if a contiguous span was found increase the rect h */
4111 rects[num_rects].height++;
4115 /* up the rect count */
4117 /* every 256 new rects increase the rect array */
4118 if ((num_rects % 256) == 0)
4119 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
4123 /* set the rects as the shape mask */
4126 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
4127 ShapeSet, YXSorted);
4132 /* free up all the spans we made */
4133 for (i = 0; i < baseh; i++)
4146 #endif /* HAVE_SHAPE_EXT */
4149 * gdk_window_set_child_shapes:
4150 * @window: a #GdkWindow
4152 * Sets the shape mask of @window to the union of shape masks
4153 * for all children of @window, ignoring the shape mask of @window
4154 * itself. Contrast with gdk_window_merge_child_shapes() which includes
4155 * the shape mask of @window in the masks to be merged.
4158 gdk_window_set_child_shapes (GdkWindow *window)
4160 g_return_if_fail (window != NULL);
4161 g_return_if_fail (GDK_IS_WINDOW (window));
4163 #ifdef HAVE_SHAPE_EXT
4164 if (!GDK_WINDOW_DESTROYED (window) &&
4165 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4166 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4167 GDK_WINDOW_XID (window), FALSE);
4172 * gdk_window_merge_child_shapes:
4173 * @window: a #GdkWindow
4175 * Merges the shape masks for any child windows into the
4176 * shape mask for @window. i.e. the union of all masks
4177 * for @window and its children will become the new mask
4178 * for @window. See gdk_window_shape_combine_mask().
4180 * This function is distinct from gdk_window_set_child_shapes()
4181 * because it includes @window's shape mask in the set of shapes to
4186 gdk_window_merge_child_shapes (GdkWindow *window)
4188 g_return_if_fail (window != NULL);
4189 g_return_if_fail (GDK_IS_WINDOW (window));
4191 #ifdef HAVE_SHAPE_EXT
4192 if (!GDK_WINDOW_DESTROYED (window) &&
4193 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4194 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4195 GDK_WINDOW_XID (window), TRUE);
4199 /* Support for windows that can be guffaw-scrolled
4200 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
4204 gdk_window_gravity_works (GdkWindow *window)
4206 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (window));
4208 if (display_x11->gravity_works == GDK_UNKNOWN)
4215 /* This particular server apparently has a bug so that the test
4216 * works but the actual code crashes it
4218 if ((!strcmp (XServerVendor (display_x11->xdisplay),
4219 "Sun Microsystems, Inc.")) &&
4220 (VendorRelease (display_x11->xdisplay) == 3400))
4222 display_x11->gravity_works = GDK_NO;
4226 attr.window_type = GDK_WINDOW_TEMP;
4227 attr.wclass = GDK_INPUT_OUTPUT;
4232 attr.event_mask = 0;
4234 parent = gdk_window_new (gdk_screen_get_root_window (GDK_DRAWABLE_SCREEN (window)),
4235 &attr, GDK_WA_X | GDK_WA_Y);
4237 attr.window_type = GDK_WINDOW_CHILD;
4238 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
4240 gdk_window_set_static_win_gravity (child, TRUE);
4242 gdk_window_resize (parent, 100, 110);
4244 gdk_window_move (parent, 0, -10);
4245 gdk_window_move_resize (parent, 0, 0, 100, 100);
4247 gdk_window_resize (parent, 100, 110);
4248 gdk_window_move (parent, 0, -10);
4249 gdk_window_move_resize (parent, 0, 0, 100, 100);
4251 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
4253 gdk_window_destroy (parent);
4254 gdk_window_destroy (child);
4256 display_x11->gravity_works = ((y == -20) ? GDK_YES : GDK_NO);
4259 return (display_x11->gravity_works == GDK_YES);
4263 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
4265 XSetWindowAttributes xattributes;
4266 GdkWindowObject *private;
4267 guint xattributes_mask = 0;
4269 g_return_if_fail (window != NULL);
4271 private = GDK_WINDOW_OBJECT (window);
4272 if (private->input_only)
4275 xattributes.bit_gravity = StaticGravity;
4276 xattributes_mask |= CWBitGravity;
4277 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4278 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4279 GDK_WINDOW_XID (window),
4280 CWBitGravity, &xattributes);
4284 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4286 XSetWindowAttributes xattributes;
4288 g_return_if_fail (window != NULL);
4290 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4292 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4293 GDK_WINDOW_XID (window),
4294 CWWinGravity, &xattributes);
4298 * gdk_window_set_static_gravities:
4299 * @window: a #GdkWindow
4300 * @use_static: %TRUE to turn on static gravity
4302 * Set the bit gravity of the given window to static, and flag it so
4303 * all children get static subwindow gravity. This is used if you are
4304 * implementing scary features that involve deep knowledge of the
4305 * windowing system. Don't worry about it unless you have to.
4307 * Return value: %TRUE if the server supports static gravity
4310 gdk_window_set_static_gravities (GdkWindow *window,
4311 gboolean use_static)
4313 GdkWindowObject *private = (GdkWindowObject *)window;
4316 g_return_val_if_fail (window != NULL, FALSE);
4317 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4319 if (!use_static == !private->guffaw_gravity)
4322 if (use_static && !gdk_window_gravity_works (window))
4325 private->guffaw_gravity = use_static;
4327 if (!GDK_WINDOW_DESTROYED (window))
4329 gdk_window_set_static_bit_gravity (window, use_static);
4331 tmp_list = private->children;
4334 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4336 tmp_list = tmp_list->next;
4344 wmspec_moveresize (GdkWindow *window,
4350 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4354 /* Release passive grab */
4355 gdk_display_pointer_ungrab (display, timestamp);
4357 xev.xclient.type = ClientMessage;
4358 xev.xclient.serial = 0;
4359 xev.xclient.send_event = True;
4360 xev.xclient.window = GDK_WINDOW_XID (window);
4361 xev.xclient.message_type =
4362 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4363 xev.xclient.format = 32;
4364 xev.xclient.data.l[0] = root_x;
4365 xev.xclient.data.l[1] = root_y;
4366 xev.xclient.data.l[2] = direction;
4367 xev.xclient.data.l[3] = 0;
4368 xev.xclient.data.l[4] = 0;
4370 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4371 SubstructureRedirectMask | SubstructureNotifyMask,
4375 typedef struct _MoveResizeData MoveResizeData;
4377 struct _MoveResizeData
4379 GdkDisplay *display;
4381 GdkWindow *moveresize_window;
4382 GdkWindow *moveresize_emulation_window;
4384 GdkWindowEdge resize_edge;
4385 gint moveresize_button;
4388 gint moveresize_orig_x;
4389 gint moveresize_orig_y;
4390 gint moveresize_orig_width;
4391 gint moveresize_orig_height;
4392 GdkWindowHints moveresize_geom_mask;
4393 GdkGeometry moveresize_geometry;
4394 Time moveresize_process_time;
4395 XEvent *moveresize_pending_event;
4398 /* From the WM spec */
4399 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4400 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4401 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4402 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4403 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4404 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4405 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4406 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4407 #define _NET_WM_MOVERESIZE_MOVE 8
4410 wmspec_resize_drag (GdkWindow *window,
4419 /* Let the compiler turn a switch into a table, instead
4420 * of doing the table manually, this way is easier to verify.
4424 case GDK_WINDOW_EDGE_NORTH_WEST:
4425 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4428 case GDK_WINDOW_EDGE_NORTH:
4429 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4432 case GDK_WINDOW_EDGE_NORTH_EAST:
4433 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4436 case GDK_WINDOW_EDGE_WEST:
4437 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4440 case GDK_WINDOW_EDGE_EAST:
4441 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4444 case GDK_WINDOW_EDGE_SOUTH_WEST:
4445 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4448 case GDK_WINDOW_EDGE_SOUTH:
4449 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4452 case GDK_WINDOW_EDGE_SOUTH_EAST:
4453 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4457 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4463 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4466 static MoveResizeData *
4467 get_move_resize_data (GdkDisplay *display,
4470 MoveResizeData *mv_resize;
4471 static GQuark move_resize_quark = 0;
4473 if (!move_resize_quark)
4474 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4476 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4478 if (!mv_resize && create)
4480 mv_resize = g_new0 (MoveResizeData, 1);
4481 mv_resize->display = display;
4483 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4490 update_pos (MoveResizeData *mv_resize,
4496 dx = new_root_x - mv_resize->moveresize_x;
4497 dy = new_root_y - mv_resize->moveresize_y;
4499 if (mv_resize->is_resize)
4503 w = mv_resize->moveresize_orig_width;
4504 h = mv_resize->moveresize_orig_height;
4506 switch (mv_resize->resize_edge)
4508 case GDK_WINDOW_EDGE_SOUTH_EAST:
4517 if (mv_resize->moveresize_geom_mask)
4519 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4520 mv_resize->moveresize_geom_mask,
4524 gdk_window_resize (mv_resize->moveresize_window, w, h);
4530 x = mv_resize->moveresize_orig_x + dx;
4531 y = mv_resize->moveresize_orig_y + dy;
4533 gdk_window_move (mv_resize->moveresize_window, x, y);
4538 finish_drag (MoveResizeData *mv_resize)
4540 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4541 mv_resize->moveresize_emulation_window = NULL;
4542 mv_resize->moveresize_window = NULL;
4544 if (mv_resize->moveresize_pending_event)
4546 g_free (mv_resize->moveresize_pending_event);
4547 mv_resize->moveresize_pending_event = NULL;
4552 lookahead_motion_predicate (Display *xdisplay,
4556 gboolean *seen_release = (gboolean *)arg;
4557 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4558 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4563 switch (event->xany.type)
4566 *seen_release = TRUE;
4569 mv_resize->moveresize_process_time = event->xmotion.time;
4579 moveresize_lookahead (MoveResizeData *mv_resize,
4583 gboolean seen_release = FALSE;
4585 if (mv_resize->moveresize_process_time)
4587 if (event->xmotion.time == mv_resize->moveresize_process_time)
4589 mv_resize->moveresize_process_time = 0;
4596 XCheckIfEvent (event->xany.display, &tmp_event,
4597 lookahead_motion_predicate, (XPointer) & seen_release);
4599 return mv_resize->moveresize_process_time == 0;
4603 _gdk_moveresize_handle_event (XEvent *event)
4605 guint button_mask = 0;
4606 GdkWindowObject *window_private;
4607 GdkDisplay *display= gdk_x11_lookup_xdisplay (event->xany.display);
4608 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4610 if (!mv_resize || mv_resize->moveresize_window)
4613 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
4615 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4617 switch (event->xany.type)
4620 if (window_private->resize_count > 0)
4622 if (mv_resize->moveresize_pending_event)
4623 *mv_resize->moveresize_pending_event = *event;
4625 mv_resize->moveresize_pending_event =
4626 g_memdup (event, sizeof (XEvent));
4630 if (!moveresize_lookahead (mv_resize, event))
4633 update_pos (mv_resize,
4634 event->xmotion.x_root,
4635 event->xmotion.y_root);
4637 /* This should never be triggered in normal cases, but in the
4638 * case where the drag started without an implicit grab being
4639 * in effect, we could miss the release if it occurs before
4640 * we grab the pointer; this ensures that we will never
4641 * get a permanently stuck grab.
4643 if ((event->xmotion.state & button_mask) == 0)
4644 finish_drag (mv_resize);
4648 update_pos (mv_resize,
4649 event->xbutton.x_root,
4650 event->xbutton.y_root);
4652 if (event->xbutton.button == mv_resize->moveresize_button)
4653 finish_drag (mv_resize);
4660 _gdk_moveresize_configure_done (GdkDisplay *display,
4664 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4666 if (!mv_resize || window != mv_resize->moveresize_window)
4669 if (mv_resize->moveresize_pending_event)
4671 tmp_event = mv_resize->moveresize_pending_event;
4672 mv_resize->moveresize_pending_event = NULL;
4673 _gdk_moveresize_handle_event (tmp_event);
4681 create_moveresize_window (MoveResizeData *mv_resize,
4684 GdkWindowAttr attributes;
4685 gint attributes_mask;
4686 GdkGrabStatus status;
4688 g_assert (mv_resize->moveresize_emulation_window == NULL);
4690 attributes.x = -100;
4691 attributes.y = -100;
4692 attributes.width = 10;
4693 attributes.height = 10;
4694 attributes.window_type = GDK_WINDOW_TEMP;
4695 attributes.wclass = GDK_INPUT_ONLY;
4696 attributes.override_redirect = TRUE;
4697 attributes.event_mask = 0;
4699 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4701 mv_resize->moveresize_emulation_window =
4702 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4706 gdk_window_show (mv_resize->moveresize_emulation_window);
4708 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4710 GDK_BUTTON_RELEASE_MASK |
4711 GDK_POINTER_MOTION_MASK,
4716 if (status != GDK_GRAB_SUCCESS)
4718 /* If this fails, some other client has grabbed the window
4721 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4722 mv_resize->moveresize_emulation_window = NULL;
4725 mv_resize->moveresize_process_time = 0;
4729 emulate_resize_drag (GdkWindow *window,
4736 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4738 mv_resize->is_resize = TRUE;
4739 mv_resize->moveresize_button = button;
4740 mv_resize->resize_edge = edge;
4741 mv_resize->moveresize_x = root_x;
4742 mv_resize->moveresize_y = root_y;
4743 mv_resize->moveresize_window = g_object_ref (window);
4745 gdk_drawable_get_size (window,
4746 &mv_resize->moveresize_orig_width,
4747 &mv_resize->moveresize_orig_height);
4749 mv_resize->moveresize_geom_mask = 0;
4750 gdk_window_get_geometry_hints (window,
4751 &mv_resize->moveresize_geometry,
4752 &mv_resize->moveresize_geom_mask);
4754 create_moveresize_window (mv_resize, timestamp);
4758 emulate_move_drag (GdkWindow *window,
4764 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4766 mv_resize->is_resize = FALSE;
4767 mv_resize->moveresize_button = button;
4768 mv_resize->moveresize_x = root_x;
4769 mv_resize->moveresize_y = root_y;
4771 mv_resize->moveresize_window = g_object_ref (window);
4773 gdk_window_get_deskrelative_origin (mv_resize->moveresize_window,
4774 &mv_resize->moveresize_orig_x,
4775 &mv_resize->moveresize_orig_y);
4777 create_moveresize_window (mv_resize, timestamp);
4781 * gdk_window_begin_resize_drag:
4782 * @window: a toplevel #GdkWindow
4783 * @edge: the edge or corner from which the drag is started
4784 * @button: the button being used to drag
4785 * @root_x: root window X coordinate of mouse click that began the drag
4786 * @root_y: root window Y coordinate of mouse click that began the drag
4787 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4789 * Begins a window resize operation (for a toplevel window).
4790 * You might use this function to implement a "window resize grip," for
4791 * example; in fact #GtkStatusbar uses it. The function works best
4792 * with window managers that support the Extended Window Manager Hints spec
4793 * (see http://www.freedesktop.org), but has a fallback implementation
4794 * for other window managers.
4798 gdk_window_begin_resize_drag (GdkWindow *window,
4805 g_return_if_fail (GDK_IS_WINDOW (window));
4807 if (GDK_WINDOW_DESTROYED (window))
4810 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4811 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4812 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4814 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4818 * gdk_window_begin_move_drag:
4819 * @window: a toplevel #GdkWindow
4820 * @button: the button being used to drag
4821 * @root_x: root window X coordinate of mouse click that began the drag
4822 * @root_y: root window Y coordinate of mouse click that began the drag
4823 * @timestamp: timestamp of mouse click that began the drag
4825 * Begins a window move operation (for a toplevel window). You might
4826 * use this function to implement a "window move grip," for
4827 * example. The function works best with window managers that support
4828 * the Extended Window Manager Hints spec (see
4829 * http://www.freedesktop.org), but has a fallback implementation for
4830 * other window managers.
4834 gdk_window_begin_move_drag (GdkWindow *window,
4840 g_return_if_fail (GDK_IS_WINDOW (window));
4842 if (GDK_WINDOW_DESTROYED (window))
4845 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4846 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4847 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
4850 emulate_move_drag (window, button, root_x, root_y, timestamp);