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 "gdkprivate-x11.h"
38 #include "gdkregion.h"
39 #include "gdkinternals.h"
41 #include "gdkwindow-x11.h"
49 #include <X11/extensions/shape.h>
52 const int _gdk_event_mask_table[21] =
56 PointerMotionHintMask,
73 SubstructureNotifyMask,
74 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
76 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
78 /* Forward declarations */
79 static gboolean gdk_window_gravity_works (void);
80 static void gdk_window_set_static_win_gravity (GdkWindow *window,
82 static gboolean gdk_window_have_shape_ext (void);
83 static gboolean gdk_window_icon_name_set (GdkWindow *window);
85 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
86 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
88 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
91 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
92 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
93 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
94 static void gdk_window_impl_x11_finalize (GObject *object);
96 static gpointer parent_class = NULL;
99 gdk_window_impl_x11_get_type (void)
101 static GType object_type = 0;
105 static const GTypeInfo object_info =
107 sizeof (GdkWindowImplX11Class),
108 (GBaseInitFunc) NULL,
109 (GBaseFinalizeFunc) NULL,
110 (GClassInitFunc) gdk_window_impl_x11_class_init,
111 NULL, /* class_finalize */
112 NULL, /* class_data */
113 sizeof (GdkWindowImplX11),
115 (GInstanceInitFunc) gdk_window_impl_x11_init,
118 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
127 _gdk_window_impl_get_type (void)
129 return gdk_window_impl_x11_get_type ();
133 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
140 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
142 GObjectClass *object_class = G_OBJECT_CLASS (klass);
143 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
145 parent_class = g_type_class_peek_parent (klass);
147 object_class->finalize = gdk_window_impl_x11_finalize;
149 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
150 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
151 drawable_class->get_size = gdk_window_impl_x11_get_size;
153 /* Visible and clip regions are the same */
154 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
155 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
159 gdk_window_impl_x11_finalize (GObject *object)
161 GdkWindowObject *wrapper;
162 GdkDrawableImplX11 *draw_impl;
163 GdkWindowImplX11 *window_impl;
165 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
167 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
168 window_impl = GDK_WINDOW_IMPL_X11 (object);
170 wrapper = (GdkWindowObject*) draw_impl->wrapper;
172 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
174 if (!GDK_WINDOW_DESTROYED (wrapper))
176 gdk_xid_table_remove (draw_impl->xid);
177 if (window_impl->focus_window)
178 gdk_xid_table_remove (window_impl->focus_window);
181 G_OBJECT_CLASS (parent_class)->finalize (object);
185 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
187 GdkDrawableImplX11 *drawable_impl;
188 GdkWindowImplX11 *window_impl;
190 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
192 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
193 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
195 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
196 drawable_impl->colormap == NULL)
198 XWindowAttributes window_attributes;
200 XGetWindowAttributes (drawable_impl->xdisplay,
203 drawable_impl->colormap =
204 gdk_colormap_lookup (window_attributes.colormap);
207 return drawable_impl->colormap;
211 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
214 GdkWindowImplX11 *impl;
215 GdkDrawableImplX11 *draw_impl;
217 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
219 impl = GDK_WINDOW_IMPL_X11 (drawable);
220 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
223 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
227 XSetWindowColormap (draw_impl->xdisplay,
229 GDK_COLORMAP_XCOLORMAP (cmap));
231 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
233 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
239 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
243 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
246 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
248 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
252 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
254 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
255 GdkRectangle result_rect;
259 result_rect.width = impl->width;
260 result_rect.height = impl->height;
262 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
264 return gdk_region_rectangle (&result_rect);
268 _gdk_windowing_window_init (void)
270 GdkWindowObject *private;
271 GdkWindowImplX11 *impl;
272 GdkDrawableImplX11 *draw_impl;
273 XWindowAttributes xattributes;
276 unsigned int border_width;
280 g_assert (_gdk_parent_root == NULL);
282 XGetGeometry (gdk_display, _gdk_root_window, &_gdk_root_window,
283 &x, &y, &width, &height, &border_width, &depth);
284 XGetWindowAttributes (gdk_display, _gdk_root_window, &xattributes);
286 _gdk_parent_root = g_object_new (GDK_TYPE_WINDOW, NULL);
287 private = (GdkWindowObject *)_gdk_parent_root;
288 impl = GDK_WINDOW_IMPL_X11 (private->impl);
289 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
291 draw_impl->xdisplay = gdk_display;
292 draw_impl->xid = _gdk_root_window;
293 draw_impl->wrapper = GDK_DRAWABLE (private);
295 private->window_type = GDK_WINDOW_ROOT;
296 private->depth = depth;
298 impl->height = height;
300 gdk_xid_table_insert (&_gdk_root_window, _gdk_parent_root);
303 static Atom wm_client_leader_atom = None;
307 * @parent: a #GdkWindow
308 * @attributes: attributes of the new window
309 * @attributes_mask: mask indicating which fields in @attributes are valid
311 * Creates a new #GdkWindow using the attributes from @attributes. See
312 * #GdkWindowAttr and #GdkWindowAttributesType for more details.
314 * Return value: the new #GdkWindow
317 gdk_window_new (GdkWindow *parent,
318 GdkWindowAttr *attributes,
319 gint attributes_mask)
322 GdkWindowObject *private;
323 GdkWindowImplX11 *impl;
324 GdkDrawableImplX11 *draw_impl;
332 XSetWindowAttributes xattributes;
333 long xattributes_mask;
334 XSizeHints size_hints;
336 XClassHint *class_hint;
344 g_return_val_if_fail (attributes != NULL, NULL);
347 parent = _gdk_parent_root;
349 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
351 if (GDK_WINDOW_DESTROYED (parent))
354 xparent = GDK_WINDOW_XID (parent);
356 window = g_object_new (GDK_TYPE_WINDOW, NULL);
357 private = (GdkWindowObject *)window;
358 impl = GDK_WINDOW_IMPL_X11 (private->impl);
359 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
360 draw_impl->wrapper = GDK_DRAWABLE (window);
362 xdisplay = draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (parent);
364 /* Windows with a foreign parent are treated as if they are children
365 * of the root window, except for actual creation.
367 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
368 parent = _gdk_parent_root;
370 private->parent = (GdkWindowObject *)parent;
372 xattributes_mask = 0;
374 if (attributes_mask & GDK_WA_X)
379 if (attributes_mask & GDK_WA_Y)
386 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
387 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
389 if (attributes->wclass == GDK_INPUT_ONLY)
391 /* Backwards compatiblity - we've always ignored
392 * attributes->window_type for input-only windows
395 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
396 private->window_type = GDK_WINDOW_TEMP;
398 private->window_type = GDK_WINDOW_CHILD;
401 private->window_type = attributes->window_type;
403 _gdk_window_init_position (GDK_WINDOW (private));
404 if (impl->position_info.big)
405 private->guffaw_gravity = TRUE;
407 if (attributes_mask & GDK_WA_VISUAL)
408 visual = attributes->visual;
410 visual = gdk_visual_get_system ();
411 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
413 xattributes.event_mask = StructureNotifyMask;
414 for (i = 0; i < _gdk_nenvent_masks; i++)
416 if (attributes->event_mask & (1 << (i + 1)))
417 xattributes.event_mask |= _gdk_event_mask_table[i];
419 private->event_mask = attributes->event_mask;
421 if (xattributes.event_mask)
422 xattributes_mask |= CWEventMask;
424 if (attributes_mask & GDK_WA_NOREDIR)
426 xattributes.override_redirect =
427 (attributes->override_redirect == FALSE)?False:True;
428 xattributes_mask |= CWOverrideRedirect;
431 xattributes.override_redirect = False;
433 if (private->parent && private->parent->guffaw_gravity)
435 xattributes.win_gravity = StaticGravity;
436 xattributes_mask |= CWWinGravity;
440 switch (private->window_type)
442 case GDK_WINDOW_TOPLEVEL:
443 case GDK_WINDOW_DIALOG:
444 case GDK_WINDOW_TEMP:
445 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
447 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
448 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
449 xparent = _gdk_root_window;
451 case GDK_WINDOW_CHILD:
454 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
458 if (attributes->wclass == GDK_INPUT_OUTPUT)
461 depth = visual->depth;
463 private->input_only = FALSE;
464 private->depth = depth;
466 if (attributes_mask & GDK_WA_COLORMAP)
468 draw_impl->colormap = attributes->colormap;
469 gdk_colormap_ref (attributes->colormap);
473 if ((((GdkVisualPrivate*)gdk_visual_get_system ())->xvisual) == xvisual)
475 draw_impl->colormap =
476 gdk_colormap_get_system ();
477 gdk_colormap_ref (draw_impl->colormap);
481 draw_impl->colormap =
482 gdk_colormap_new (visual, FALSE);
486 private->bg_color.pixel = BlackPixel (gdk_display, _gdk_screen);
487 xattributes.background_pixel = private->bg_color.pixel;
489 private->bg_pixmap = NULL;
491 xattributes.border_pixel = BlackPixel (gdk_display, _gdk_screen);
492 xattributes_mask |= CWBorderPixel | CWBackPixel;
494 if (private->guffaw_gravity)
495 xattributes.bit_gravity = StaticGravity;
497 xattributes.bit_gravity = NorthWestGravity;
499 xattributes_mask |= CWBitGravity;
501 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
502 xattributes_mask |= CWColormap;
504 if (private->window_type == GDK_WINDOW_TEMP)
506 xattributes.save_under = True;
507 xattributes.override_redirect = True;
508 xattributes.cursor = None;
509 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
517 private->input_only = TRUE;
518 draw_impl->colormap = gdk_colormap_get_system ();
519 gdk_colormap_ref (draw_impl->colormap);
522 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
523 impl->position_info.x, impl->position_info.y,
524 impl->position_info.width, impl->position_info.height,
525 0, depth, class, xvisual,
526 xattributes_mask, &xattributes);
528 gdk_drawable_ref (window);
529 gdk_xid_table_insert (&draw_impl->xid, window);
531 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
532 (attributes->cursor) :
536 private->parent->children = g_list_prepend (private->parent->children, window);
538 switch (GDK_WINDOW_TYPE (private))
540 case GDK_WINDOW_DIALOG:
541 XSetTransientForHint (xdisplay, xid, xparent);
542 case GDK_WINDOW_TOPLEVEL:
543 case GDK_WINDOW_TEMP:
544 XSetWMProtocols (xdisplay, xid,
545 _gdk_wm_window_protocols, 3);
547 case GDK_WINDOW_CHILD:
548 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
549 (draw_impl->colormap != gdk_colormap_get_system ()) &&
550 (draw_impl->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window))))
552 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
553 gdk_window_add_colormap_windows (window);
562 if (class != InputOnly)
564 /* The focus window is off the visible area, and serves to receive key
565 * press events so they don't get sent to child windows.
567 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
569 xattributes.background_pixel,
570 xattributes.background_pixel);
571 /* FIXME: probably better to actually track the requested event mask for the toplevel
573 XSelectInput (xdisplay, impl->focus_window,
574 KeyPressMask | KeyReleaseMask | FocusChangeMask);
576 XMapWindow (xdisplay, impl->focus_window);
577 gdk_xid_table_insert (&impl->focus_window, window);
580 size_hints.flags = PSize;
581 size_hints.width = impl->width;
582 size_hints.height = impl->height;
584 wm_hints.flags = StateHint | WindowGroupHint;
585 wm_hints.window_group = _gdk_leader_window;
586 wm_hints.input = True;
587 wm_hints.initial_state = NormalState;
589 /* FIXME: Is there any point in doing this? Do any WM's pay
590 * attention to PSize, and even if they do, is this the
593 XSetWMNormalHints (xdisplay, xid, &size_hints);
595 XSetWMHints (xdisplay, xid, &wm_hints);
597 if (!wm_client_leader_atom)
598 wm_client_leader_atom = gdk_x11_get_xatom_by_name ("WM_CLIENT_LEADER");
600 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
601 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
604 XChangeProperty (xdisplay, xid,
605 gdk_x11_get_xatom_by_name ("_NET_WM_PID"),
610 XChangeProperty (xdisplay, xid,
611 wm_client_leader_atom,
612 XA_WINDOW, 32, PropModeReplace,
613 (guchar*) &_gdk_leader_window, 1);
615 if (attributes_mask & GDK_WA_TITLE)
616 title = attributes->title;
618 title = g_get_prgname ();
620 gdk_window_set_title (window, title);
622 if (attributes_mask & GDK_WA_WMCLASS)
624 class_hint = XAllocClassHint ();
625 class_hint->res_name = attributes->wmclass_name;
626 class_hint->res_class = attributes->wmclass_class;
627 XSetClassHint (xdisplay, xid, class_hint);
635 x_event_mask_to_gdk_event_mask (long mask)
637 GdkEventMask event_mask = 0;
640 for (i = 0; i < _gdk_nenvent_masks; i++)
642 if (mask & _gdk_event_mask_table[i])
643 event_mask |= 1 << (i + 1);
650 * gdk_window_foreign_new:
651 * @anid: a native window handle.
653 * Wraps a native window in a #GdkWindow.
654 * This may fail if the window has been destroyed.
656 * For example in the X backend, a native window handle is an Xlib
659 * Return value: the newly-created #GdkWindow wrapper for the
660 * native window or %NULL if the window has been destroyed.
663 gdk_window_foreign_new (GdkNativeWindow anid)
666 GdkWindowObject *private;
667 GdkWindowImplX11 *impl;
668 GdkDrawableImplX11 *draw_impl;
669 XWindowAttributes attrs;
671 Window *children = NULL;
675 gdk_error_trap_push ();
676 result = XGetWindowAttributes (gdk_display, anid, &attrs);
677 if (gdk_error_trap_pop () || !result)
680 /* FIXME: This is pretty expensive. Maybe the caller should supply
682 gdk_error_trap_push ();
683 result = XQueryTree (gdk_display, anid, &root, &parent, &children, &nchildren);
684 if (gdk_error_trap_pop () || !result)
690 window = g_object_new (GDK_TYPE_WINDOW, NULL);
691 private = (GdkWindowObject *)window;
692 impl = GDK_WINDOW_IMPL_X11 (private->impl);
693 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
694 draw_impl->wrapper = GDK_DRAWABLE (window);
696 private->parent = gdk_xid_table_lookup (parent);
697 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
698 private->parent = (GdkWindowObject *)_gdk_parent_root;
700 private->parent->children = g_list_prepend (private->parent->children, window);
702 draw_impl->xid = anid;
703 draw_impl->xdisplay = gdk_display;
705 private->x = attrs.x;
706 private->y = attrs.y;
707 impl->width = attrs.width;
708 impl->height = attrs.height;
709 private->window_type = GDK_WINDOW_FOREIGN;
710 private->destroyed = FALSE;
712 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
714 if (attrs.map_state == IsUnmapped)
715 private->state = GDK_WINDOW_STATE_WITHDRAWN;
719 private->depth = attrs.depth;
721 _gdk_window_init_position (GDK_WINDOW (private));
723 gdk_drawable_ref (window);
724 gdk_xid_table_insert (&GDK_WINDOW_XID (window), window);
731 * @anid: a native window handle.
733 * Looks up the #GdkWindow that wraps the given native window handle.
735 * For example in the X backend, a native window handle is an Xlib
738 * Return value: the #GdkWindow wrapper for the native window,
739 * or %NULL if there is none.
742 gdk_window_lookup (GdkNativeWindow anid)
744 return (GdkWindow*) gdk_xid_table_lookup (anid);
748 _gdk_windowing_window_destroy (GdkWindow *window,
750 gboolean foreign_destroy)
752 GdkWindowObject *private = (GdkWindowObject *)window;
754 g_return_if_fail (GDK_IS_WINDOW (window));
756 _gdk_selection_window_destroyed (window);
758 if (private->extension_events != 0)
759 gdk_input_window_destroy (window);
763 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
765 if (draw_impl->picture)
766 XRenderFreePicture (draw_impl->xdisplay, draw_impl->picture);
768 #endif /* HAVE_XFT */
770 if (private->window_type == GDK_WINDOW_FOREIGN)
772 if (!foreign_destroy && (private->parent != NULL))
774 /* It's somebody else's window, but in our heirarchy,
775 * so reparent it to the root window, and then send
776 * it a delete event, as if we were a WM
778 XClientMessageEvent xevent;
780 gdk_error_trap_push ();
781 gdk_window_hide (window);
782 gdk_window_reparent (window, NULL, 0, 0);
784 xevent.type = ClientMessage;
785 xevent.window = GDK_WINDOW_XID (window);
786 xevent.message_type = gdk_x11_get_xatom_by_name ("WM_PROTOCOLS");
788 xevent.data.l[0] = gdk_x11_get_xatom_by_name ("WM_DELETE_WINDOW");
789 xevent.data.l[1] = CurrentTime;
791 XSendEvent (GDK_WINDOW_XDISPLAY (window),
792 GDK_WINDOW_XID (window),
793 False, 0, (XEvent *)&xevent);
795 gdk_error_trap_pop ();
798 else if (!recursing && !foreign_destroy)
800 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
804 /* This function is called when the XWindow is really gone.
807 gdk_window_destroy_notify (GdkWindow *window)
809 GdkWindowImplX11 *window_impl;
811 g_return_if_fail (window != NULL);
813 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
815 if (!GDK_WINDOW_DESTROYED (window))
817 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
818 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
820 _gdk_window_destroy (window, TRUE);
823 gdk_xid_table_remove (GDK_WINDOW_XID (window));
824 if (window_impl->focus_window)
825 gdk_xid_table_remove (window_impl->focus_window);
827 _gdk_xgrab_check_destroy (window);
829 gdk_drawable_unref (window);
833 set_initial_hints (GdkWindow *window)
835 GdkWindowObject *private;
839 private = (GdkWindowObject*) window;
841 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
845 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
846 GDK_WINDOW_XID (window));
848 wm_hints = XAllocWMHints ();
850 wm_hints->flags |= StateHint;
851 wm_hints->initial_state = IconicState;
853 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
854 GDK_WINDOW_XID (window), wm_hints);
858 /* We set the spec hints regardless of whether the spec is supported,
859 * since it can't hurt and it's kind of expensive to check whether
865 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
867 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_VERT");
869 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_HORZ");
873 if (private->state & GDK_WINDOW_STATE_STICKY)
875 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_STICKY");
879 if (private->modal_hint)
881 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MODAL");
887 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
888 GDK_WINDOW_XID (window),
889 gdk_x11_get_xatom_by_name ("_NET_WM_STATE"),
890 XA_ATOM, 32, PropModeReplace,
894 if (private->state & GDK_WINDOW_STATE_STICKY)
896 atoms[0] = 0xFFFFFFFF;
897 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
898 GDK_WINDOW_XID (window),
899 gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP"),
900 XA_CARDINAL, 32, PropModeReplace,
906 show_window_internal (GdkWindow *window,
909 GdkWindowObject *private;
911 g_return_if_fail (GDK_IS_WINDOW (window));
913 private = (GdkWindowObject*) window;
914 if (!private->destroyed)
917 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
918 GDK_WINDOW_XID (window));
920 if (!GDK_WINDOW_IS_MAPPED (window))
922 set_initial_hints (window);
924 gdk_synthesize_window_state (window,
925 GDK_WINDOW_STATE_WITHDRAWN,
929 g_assert (GDK_WINDOW_IS_MAPPED (window));
931 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
932 XMapWindow (GDK_WINDOW_XDISPLAY (window),
933 GDK_WINDOW_XID (window));
938 * gdk_window_show_unraised:
939 * @window: a #GdkWindow
941 * Shows a #GdkWindow onscreen, but does not modify its stacking
942 * order. In contrast, gdk_window_show() will raise the window
943 * to the top of the window stack.
945 * On the X11 platform, in Xlib terms, this function calls
946 * XMapWindow() (it also updates some internal GDK state, which means
947 * that you can't really use XMapWindow() directly on a GDK window).
951 gdk_window_show_unraised (GdkWindow *window)
953 g_return_if_fail (GDK_IS_WINDOW (window));
955 show_window_internal (window, FALSE);
960 * @window: a #GdkWindow
962 * Like gdk_window_show_unraised(), but also raises the window to the
963 * top of the window stack (moves the window to the front of the
966 * This function maps a window so it's visible onscreen. Its opposite
967 * is gdk_window_hide().
969 * When implementing a #GtkWidget, you should call this function on the widget's
970 * #GdkWindow as part of the "map" method.
974 gdk_window_show (GdkWindow *window)
976 g_return_if_fail (GDK_IS_WINDOW (window));
978 show_window_internal (window, TRUE);
983 * @window: a #GdkWindow
985 * For toplevel windows, withdraws them, so they will no longer be
986 * known to the window manager; for all windows, unmaps them, so
987 * they won't be displayed. Normally done automatically as
988 * part of gtk_widget_hide().
992 gdk_window_hide (GdkWindow *window)
994 GdkWindowObject *private;
996 g_return_if_fail (window != NULL);
998 private = (GdkWindowObject*) window;
1000 /* We'll get the unmap notify eventually, and handle it then,
1001 * but checking here makes things more consistent if we are
1002 * just doing stuff ourself.
1004 _gdk_xgrab_check_unmap (window,
1005 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1007 /* You can't simply unmap toplevel windows. */
1008 switch (private->window_type)
1010 case GDK_WINDOW_TOPLEVEL:
1011 case GDK_WINDOW_DIALOG:
1012 case GDK_WINDOW_TEMP: /* ? */
1013 gdk_window_withdraw (window);
1017 case GDK_WINDOW_FOREIGN:
1018 case GDK_WINDOW_ROOT:
1019 case GDK_WINDOW_CHILD:
1023 if (!private->destroyed)
1025 if (GDK_WINDOW_IS_MAPPED (window))
1026 gdk_synthesize_window_state (window,
1028 GDK_WINDOW_STATE_WITHDRAWN);
1030 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1032 _gdk_window_clear_update_area (window);
1034 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1035 GDK_WINDOW_XID (window));
1040 * gdk_window_withdraw:
1041 * @window: a toplevel #GdkWindow
1043 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1044 * Normally done automatically by gtk_widget_hide() called on a #GtkWindow.
1048 gdk_window_withdraw (GdkWindow *window)
1050 GdkWindowObject *private;
1052 g_return_if_fail (window != NULL);
1054 private = (GdkWindowObject*) window;
1055 if (!private->destroyed)
1057 if (GDK_WINDOW_IS_MAPPED (window))
1058 gdk_synthesize_window_state (window,
1060 GDK_WINDOW_STATE_WITHDRAWN);
1062 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1064 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1065 GDK_WINDOW_XID (window), 0);
1071 * @window: a #GdkWindow
1072 * @x: X coordinate relative to window's parent
1073 * @y: Y coordinate relative to window's parent
1075 * Repositions a window relative to its parent window.
1076 * For toplevel windows, window managers may ignore or modify the move;
1077 * you should probably use gtk_window_move() on a #GtkWindow widget
1078 * anyway, instead of using GDK functions. For child windows,
1079 * the move will reliably succeed.
1081 * If you're also planning to resize the window, use gdk_window_move_resize()
1082 * to both move and resize simultaneously, for a nicer visual effect.
1086 gdk_window_move (GdkWindow *window,
1090 GdkWindowObject *private = (GdkWindowObject *)window;
1091 GdkWindowImplX11 *impl;
1093 g_return_if_fail (window != NULL);
1094 g_return_if_fail (GDK_IS_WINDOW (window));
1096 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1098 if (!GDK_WINDOW_DESTROYED (window))
1100 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1101 _gdk_window_move_resize_child (window, x, y,
1102 impl->width, impl->height);
1105 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1106 GDK_WINDOW_XID (window),
1113 * gdk_window_resize:
1114 * @window: a #GdkWindow
1115 * @width: new width of the window
1116 * @height: new height of the window
1118 * Resizes @window; for toplevel windows, asks the window manager to resize
1119 * the window. The window manager may not allow the resize. When using GTK+,
1120 * use gtk_window_resize() instead of this low-level GDK function.
1122 * Windows may not be resized below 1x1.
1124 * If you're also planning to move the window, use gdk_window_move_resize()
1125 * to both move and resize simultaneously, for a nicer visual effect.
1129 gdk_window_resize (GdkWindow *window,
1133 GdkWindowObject *private;
1135 g_return_if_fail (window != NULL);
1136 g_return_if_fail (GDK_IS_WINDOW (window));
1143 private = (GdkWindowObject*) window;
1145 if (!GDK_WINDOW_DESTROYED (window))
1147 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1148 _gdk_window_move_resize_child (window, private->x, private->y,
1152 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1154 if (width != impl->width || height != impl->height)
1155 private->resize_count += 1;
1157 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1158 GDK_WINDOW_XID (window),
1165 * gdk_window_move_resize:
1166 * @window: a #GdkWindow
1167 * @x: new X position relative to window's parent
1168 * @y: new Y position relative to window's parent
1170 * @height: new height
1172 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1173 * except that both operations are performed at once, avoiding strange
1174 * visual effects. (i.e. the user may be able to see the window first
1175 * move, then resize, if youu don't use gdk_window_move_resize().)
1179 gdk_window_move_resize (GdkWindow *window,
1185 GdkWindowObject *private;
1187 g_return_if_fail (window != NULL);
1188 g_return_if_fail (GDK_IS_WINDOW (window));
1195 private = (GdkWindowObject*) window;
1197 if (!GDK_WINDOW_DESTROYED (window))
1199 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1200 _gdk_window_move_resize_child (window, x, y, width, height);
1203 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1205 if (width != impl->width || height != impl->height)
1206 private->resize_count += 1;
1208 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1209 GDK_WINDOW_XID (window),
1210 x, y, width, height);
1216 * gdk_window_reparent:
1217 * @window: a #GdkWindow
1218 * @new_parent: new parent to move @window into
1219 * @x: X location inside the new parent
1220 * @y: Y location inside the new parent
1222 * Reparents @window into the given @new_parent. The window being
1223 * reparented will be unmapped as a side effect.
1227 gdk_window_reparent (GdkWindow *window,
1228 GdkWindow *new_parent,
1232 GdkWindowObject *window_private;
1233 GdkWindowObject *parent_private;
1234 GdkWindowObject *old_parent_private;
1236 g_return_if_fail (window != NULL);
1237 g_return_if_fail (GDK_IS_WINDOW (window));
1238 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1239 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1242 new_parent = _gdk_parent_root;
1244 window_private = (GdkWindowObject*) window;
1245 old_parent_private = (GdkWindowObject*)window_private->parent;
1246 parent_private = (GdkWindowObject*) new_parent;
1248 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1249 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1250 GDK_WINDOW_XID (window),
1251 GDK_WINDOW_XID (new_parent),
1254 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1257 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1258 new_parent = _gdk_parent_root;
1260 window_private->parent = (GdkWindowObject *)new_parent;
1262 /* Switch the window type as appropriate */
1264 switch (GDK_WINDOW_TYPE (new_parent))
1266 case GDK_WINDOW_ROOT:
1267 case GDK_WINDOW_FOREIGN:
1268 /* Now a toplevel */
1269 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1271 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1272 XSetWMProtocols (GDK_WINDOW_XDISPLAY (window),
1273 GDK_WINDOW_XID (window),
1274 _gdk_wm_window_protocols, 3);
1276 case GDK_WINDOW_TOPLEVEL:
1277 case GDK_WINDOW_CHILD:
1278 case GDK_WINDOW_DIALOG:
1279 case GDK_WINDOW_TEMP:
1280 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1281 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1283 /* If we were being sophisticated, we'd save the old window type
1284 * here, and restore it if we were reparented back to the
1285 * toplevel. However, the difference between different types
1286 * of toplevels only really matters on creation anyways.
1288 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1292 if (old_parent_private)
1293 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1295 if ((old_parent_private &&
1296 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1297 (!old_parent_private && parent_private->guffaw_gravity))
1298 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1300 parent_private->children = g_list_prepend (parent_private->children, window);
1301 _gdk_window_init_position (GDK_WINDOW (window_private));
1305 _gdk_windowing_window_clear_area (GdkWindow *window,
1311 g_return_if_fail (window != NULL);
1312 g_return_if_fail (GDK_IS_WINDOW (window));
1314 if (!GDK_WINDOW_DESTROYED (window))
1315 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1316 x, y, width, height, False);
1320 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1326 g_return_if_fail (window != NULL);
1327 g_return_if_fail (GDK_IS_WINDOW (window));
1329 if (!GDK_WINDOW_DESTROYED (window))
1330 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1331 x, y, width, height, True);
1337 * @window: a #GdkWindow
1339 * Raises @window to the top of the Z-order (stacking order), so that
1340 * other windows with the same parent window appear below @window.
1341 * If @window is a toplevel, the window manager may choose to deny the
1342 * request to move the window in the Z-order, gdk_window_raise() only
1343 * requests the restack, does not guarantee it.
1347 gdk_window_raise (GdkWindow *window)
1349 g_return_if_fail (window != NULL);
1350 g_return_if_fail (GDK_IS_WINDOW (window));
1352 if (!GDK_WINDOW_DESTROYED (window))
1353 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1358 * @window: a #GdkWindow
1360 * Lowers @window to the bottom of the Z-order (stacking order), so that
1361 * other windows with the same parent window appear above @window.
1362 * If @window is a toplevel, the window manager may choose to deny the
1363 * request to move the window in the Z-order, gdk_window_lower() only
1364 * requests the restack, does not guarantee it.
1366 * Note that gdk_window_show() raises the window again, so don't call this
1367 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1371 gdk_window_lower (GdkWindow *window)
1373 g_return_if_fail (window != NULL);
1374 g_return_if_fail (GDK_IS_WINDOW (window));
1376 if (!GDK_WINDOW_DESTROYED (window))
1377 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1382 * @window: a #GdkWindow
1383 * @timestamp: timestamp of the event triggering the window focus
1385 * Sets keyboard focus to @window. If @window is not onscreen this
1386 * will not work. In most cases, gtk_window_present() should be used on
1387 * a #GtkWindow, rather than calling this function.
1391 gdk_window_focus (GdkWindow *window,
1394 g_return_if_fail (GDK_IS_WINDOW (window));
1396 if (GDK_WINDOW_DESTROYED (window))
1399 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1403 xev.xclient.type = ClientMessage;
1404 xev.xclient.serial = 0;
1405 xev.xclient.send_event = True;
1406 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1407 xev.xclient.display = gdk_display;
1408 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW");
1409 xev.xclient.format = 32;
1410 xev.xclient.data.l[0] = 0;
1412 XSendEvent (gdk_display, _gdk_root_window, False,
1413 SubstructureRedirectMask | SubstructureNotifyMask,
1418 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1420 /* There is no way of knowing reliably whether we are viewable so we need
1421 * to trap errors so we don't cause a BadMatch.
1423 gdk_error_trap_push ();
1424 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1425 GDK_WINDOW_XWINDOW (window),
1428 XSync (GDK_WINDOW_XDISPLAY (window), False);
1429 gdk_error_trap_pop ();
1434 * gdk_window_set_hints:
1435 * @window: a #GdkWindow
1436 * @x: ignored field, does not matter
1437 * @y: ignored field, does not matter
1438 * @min_width: minimum width hint
1439 * @min_height: minimum height hint
1440 * @max_width: max width hint
1441 * @max_height: max height hint
1442 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1444 * This function is broken and useless and you should ignore it.
1445 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1446 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1447 * depending on what you're trying to do.
1449 * If using GDK directly, use gdk_window_set_geometry_hints().
1453 gdk_window_set_hints (GdkWindow *window,
1462 XSizeHints size_hints;
1464 g_return_if_fail (window != NULL);
1465 g_return_if_fail (GDK_IS_WINDOW (window));
1467 if (GDK_WINDOW_DESTROYED (window))
1470 size_hints.flags = 0;
1472 if (flags & GDK_HINT_POS)
1474 size_hints.flags |= PPosition;
1479 if (flags & GDK_HINT_MIN_SIZE)
1481 size_hints.flags |= PMinSize;
1482 size_hints.min_width = min_width;
1483 size_hints.min_height = min_height;
1486 if (flags & GDK_HINT_MAX_SIZE)
1488 size_hints.flags |= PMaxSize;
1489 size_hints.max_width = max_width;
1490 size_hints.max_height = max_height;
1493 /* FIXME: Would it be better to delete this property if
1494 * flags == 0? It would save space on the server
1496 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1497 GDK_WINDOW_XID (window),
1502 * gdk_window_set_type_hint:
1503 * @window: A #GdkWindow
1504 * @hint: A hint of the function this window will have
1506 * The application can use this call to provide a hint to the window
1507 * manager about the functionality of a window. The window manager
1508 * can use this information when determining the decoration and behaviour
1511 * The hint must be set before the window is mapped.
1514 gdk_window_set_type_hint (GdkWindow *window,
1515 GdkWindowTypeHint hint)
1519 g_return_if_fail (window != NULL);
1520 g_return_if_fail (GDK_IS_WINDOW (window));
1522 if (GDK_WINDOW_DESTROYED (window))
1527 case GDK_WINDOW_TYPE_HINT_DIALOG:
1528 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_DIALOG");
1530 case GDK_WINDOW_TYPE_HINT_MENU:
1531 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_MENU");
1533 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1534 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_TOOLBAR");
1537 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1539 case GDK_WINDOW_TYPE_HINT_NORMAL:
1540 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_NORMAL");
1544 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1545 GDK_WINDOW_XID (window),
1546 gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE"),
1547 XA_ATOM, 32, PropModeReplace,
1548 (guchar *)&atom, 1);
1553 gdk_wmspec_change_state (gboolean add,
1560 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1561 #define _NET_WM_STATE_ADD 1 /* add/set property */
1562 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1564 xev.xclient.type = ClientMessage;
1565 xev.xclient.serial = 0;
1566 xev.xclient.send_event = True;
1567 xev.xclient.display = gdk_display;
1568 xev.xclient.window = GDK_WINDOW_XID (window);
1569 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_STATE");
1570 xev.xclient.format = 32;
1571 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1572 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom (state1);
1573 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom (state2);
1575 XSendEvent (gdk_display, _gdk_root_window, False,
1576 SubstructureRedirectMask | SubstructureNotifyMask,
1580 * gdk_window_set_modal_hint:
1581 * @window: A #GdkWindow
1582 * @modal: TRUE if the window is modal, FALSE otherwise.
1584 * The application can use this hint to tell the window manager
1585 * that a certain window has modal behaviour. The window manager
1586 * can use this information to handle modal windows in a special
1589 * You should only use this on windows for which you have
1590 * previously called #gdk_window_set_transient_for()
1593 gdk_window_set_modal_hint (GdkWindow *window,
1596 GdkWindowObject *private;
1598 g_return_if_fail (window != NULL);
1599 g_return_if_fail (GDK_IS_WINDOW (window));
1601 if (GDK_WINDOW_DESTROYED (window))
1604 private = (GdkWindowObject*) window;
1606 private->modal_hint = modal;
1608 if (GDK_WINDOW_IS_MAPPED (window))
1609 gdk_wmspec_change_state (modal, window,
1610 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1615 * gdk_window_set_geometry_hints:
1616 * @window: a #GdkWindow
1617 * @geometry: geometry hints
1618 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1620 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1621 * are set, hints not flagged in @geom_mask are unset.
1622 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1626 gdk_window_set_geometry_hints (GdkWindow *window,
1627 GdkGeometry *geometry,
1628 GdkWindowHints geom_mask)
1630 XSizeHints size_hints;
1632 g_return_if_fail (window != NULL);
1633 g_return_if_fail (GDK_IS_WINDOW (window));
1635 if (GDK_WINDOW_DESTROYED (window))
1638 size_hints.flags = 0;
1640 if (geom_mask & GDK_HINT_POS)
1642 size_hints.flags |= PPosition;
1643 /* We need to initialize the following obsolete fields because KWM
1644 * apparently uses these fields if they are non-zero.
1651 if (geom_mask & GDK_HINT_USER_POS)
1653 size_hints.flags |= USPosition;
1656 if (geom_mask & GDK_HINT_USER_SIZE)
1658 size_hints.flags |= USSize;
1661 if (geom_mask & GDK_HINT_MIN_SIZE)
1663 size_hints.flags |= PMinSize;
1664 size_hints.min_width = geometry->min_width;
1665 size_hints.min_height = geometry->min_height;
1668 if (geom_mask & GDK_HINT_MAX_SIZE)
1670 size_hints.flags |= PMaxSize;
1671 size_hints.max_width = MAX (geometry->max_width, 1);
1672 size_hints.max_height = MAX (geometry->max_height, 1);
1675 if (geom_mask & GDK_HINT_BASE_SIZE)
1677 size_hints.flags |= PBaseSize;
1678 size_hints.base_width = geometry->base_width;
1679 size_hints.base_height = geometry->base_height;
1682 if (geom_mask & GDK_HINT_RESIZE_INC)
1684 size_hints.flags |= PResizeInc;
1685 size_hints.width_inc = geometry->width_inc;
1686 size_hints.height_inc = geometry->height_inc;
1689 if (geom_mask & GDK_HINT_ASPECT)
1691 size_hints.flags |= PAspect;
1692 if (geometry->min_aspect <= 1)
1694 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1695 size_hints.min_aspect.y = 65536;
1699 size_hints.min_aspect.x = 65536;
1700 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1702 if (geometry->max_aspect <= 1)
1704 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1705 size_hints.max_aspect.y = 65536;
1709 size_hints.max_aspect.x = 65536;
1710 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1714 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1716 size_hints.flags |= PWinGravity;
1717 size_hints.win_gravity = geometry->win_gravity;
1720 /* FIXME: Would it be better to delete this property if
1721 * geom_mask == 0? It would save space on the server
1723 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1724 GDK_WINDOW_XID (window),
1729 gdk_window_get_geometry_hints (GdkWindow *window,
1730 GdkGeometry *geometry,
1731 GdkWindowHints *geom_mask)
1733 XSizeHints size_hints;
1734 glong junk_size_mask = 0;
1736 g_return_if_fail (GDK_IS_WINDOW (window));
1737 g_return_if_fail (geometry != NULL);
1738 g_return_if_fail (geom_mask != NULL);
1742 if (GDK_WINDOW_DESTROYED (window))
1745 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1746 GDK_WINDOW_XID (window),
1751 if (size_hints.flags & PMinSize)
1753 *geom_mask |= GDK_HINT_MIN_SIZE;
1754 geometry->min_width = size_hints.min_width;
1755 geometry->min_height = size_hints.min_height;
1758 if (size_hints.flags & PMaxSize)
1760 *geom_mask |= GDK_HINT_MAX_SIZE;
1761 geometry->max_width = MAX (size_hints.max_width, 1);
1762 geometry->max_height = MAX (size_hints.max_height, 1);
1765 if (size_hints.flags & PResizeInc)
1767 *geom_mask |= GDK_HINT_RESIZE_INC;
1768 geometry->width_inc = size_hints.width_inc;
1769 geometry->height_inc = size_hints.height_inc;
1772 if (size_hints.flags & PAspect)
1774 *geom_mask |= GDK_HINT_ASPECT;
1776 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1777 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1780 if (size_hints.flags & PWinGravity)
1782 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1783 geometry->win_gravity = size_hints.win_gravity;
1788 utf8_is_latin1 (const gchar *str)
1790 const char *p = str;
1794 gunichar ch = g_utf8_get_char (p);
1799 p = g_utf8_next_char (p);
1805 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
1806 * convertable to STRING, otherwise, set it as compound text
1809 set_text_property (GdkWindow *window,
1811 const gchar *utf8_str)
1813 guchar *prop_text = NULL;
1818 if (utf8_is_latin1 (utf8_str))
1820 prop_type = XA_STRING;
1821 prop_text = gdk_utf8_to_string_target (utf8_str);
1822 prop_length = strlen (prop_text);
1829 gdk_utf8_to_compound_text (utf8_str, &gdk_type, &prop_format,
1830 &prop_text, &prop_length);
1831 prop_type = gdk_x11_atom_to_xatom (gdk_type);
1836 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1837 GDK_WINDOW_XID (window),
1839 prop_type, prop_format,
1840 PropModeReplace, prop_text,
1848 * gdk_window_set_title:
1849 * @window: a #GdkWindow
1850 * @title: title of @window
1852 * Sets the title of a toplevel window, to be displayed in the titlebar.
1853 * If you haven't explicitly set the icon name for the window
1854 * (using gdk_window_set_icon_name()), the icon name will be set to
1855 * @title as well. @title must be in UTF-8 encoding (as with all
1856 * user-readable strings in GDK/GTK+). @title may not be %NULL.
1860 gdk_window_set_title (GdkWindow *window,
1863 g_return_if_fail (window != NULL);
1864 g_return_if_fail (GDK_IS_WINDOW (window));
1865 g_return_if_fail (title != NULL);
1867 if (GDK_WINDOW_DESTROYED (window))
1870 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1871 GDK_WINDOW_XID (window),
1872 gdk_x11_get_xatom_by_name ("_NET_WM_NAME"),
1873 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
1874 PropModeReplace, title,
1877 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_NAME"), title);
1878 if (!gdk_window_icon_name_set (window))
1880 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1881 GDK_WINDOW_XID (window),
1882 gdk_x11_get_xatom_by_name ("_NET_WM_ICON_NAME"),
1883 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
1884 PropModeReplace, title,
1886 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_ICON_NAME"), title);
1891 * gdk_window_set_role:
1892 * @window: a #GdkWindow
1893 * @role: a string indicating its role
1895 * When using GTK+, typically you should use gtk_window_set_role() instead
1896 * of this low-level function.
1898 * The window manager and session manager use a window's role to
1899 * distinguish it from other kinds of window in the same application.
1900 * When an application is restarted after being saved in a previous
1901 * session, all windows with the same title and role are treated as
1902 * interchangeable. So if you have two windows with the same title
1903 * that should be distinguished for session management purposes, you
1904 * should set the role on those windows. It doesn't matter what string
1905 * you use for the role, as long as you have a different role for each
1906 * non-interchangeable kind of window.
1910 gdk_window_set_role (GdkWindow *window,
1913 g_return_if_fail (window != NULL);
1914 g_return_if_fail (GDK_IS_WINDOW (window));
1916 if (!GDK_WINDOW_DESTROYED (window))
1919 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1920 gdk_x11_get_xatom_by_name ("WM_WINDOW_ROLE"), XA_STRING,
1921 8, PropModeReplace, role, strlen (role));
1923 XDeleteProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1924 gdk_x11_get_xatom_by_name ("WM_WINDOW_ROLE"));
1929 * gdk_window_set_transient_for:
1930 * @window: a toplevel #GdkWindow
1931 * @parent: another toplevel #GdkWindow
1933 * Indicates to the window manager that @window is a transient dialog
1934 * associated with the application window @parent. This allows the
1935 * window manager to do things like center @window on @parent and
1936 * keep @window above @parent.
1938 * See gtk_window_set_transient_for() if you're using #GtkWindow or
1943 gdk_window_set_transient_for (GdkWindow *window,
1946 GdkWindowObject *private;
1947 GdkWindowObject *parent_private;
1949 g_return_if_fail (window != NULL);
1950 g_return_if_fail (GDK_IS_WINDOW (window));
1952 private = (GdkWindowObject*) window;
1953 parent_private = (GdkWindowObject*) parent;
1955 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
1956 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
1957 GDK_WINDOW_XID (window),
1958 GDK_WINDOW_XID (parent));
1962 * gdk_window_set_background:
1963 * @window: a #GdkWindow
1964 * @color: an allocated #GdkColor
1966 * Sets the background color of @window. (However, when using GTK+,
1967 * set the background of a widget with gtk_widget_modify_bg() - if
1968 * you're an application - or gtk_style_set_background() - if you're
1969 * implementing a custom widget.)
1971 * The @color must be allocated; gdk_rgb_find_color() is the best way
1972 * to allocate a color.
1974 * See also gdk_window_set_back_pixmap().
1978 gdk_window_set_background (GdkWindow *window,
1981 GdkWindowObject *private = (GdkWindowObject *)window;
1983 g_return_if_fail (window != NULL);
1984 g_return_if_fail (GDK_IS_WINDOW (window));
1986 if (!GDK_WINDOW_DESTROYED (window))
1987 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
1988 GDK_WINDOW_XID (window), color->pixel);
1990 private->bg_color = *color;
1992 if (private->bg_pixmap &&
1993 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1994 private->bg_pixmap != GDK_NO_BG)
1995 gdk_pixmap_unref (private->bg_pixmap);
1997 private->bg_pixmap = NULL;
2001 * gdk_window_set_back_pixmap:
2002 * @window: a #GdkWindow
2003 * @pixmap: a #GdkPixmap, or %NULL
2004 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2006 * Sets the background pixmap of @window. May also be used to set a background of
2007 * "None" on @window, by setting a background pixmap of %NULL.
2008 * A background pixmap will be tiled, positioning the first tile at the origin of
2009 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2010 * origin of the parent window (useful to align tiles in a parent with tiles
2013 * A background pixmap of %NULL means that the window will have no
2014 * background. A window with no background will never have its
2015 * background filled by the windowing system, instead the window will
2016 * contain whatever pixels were already in the corresponding area of
2019 * The windowing system will normally fill a window with its background
2020 * when the window is obscured then exposed, and when you call
2021 * gdk_window_clear().
2025 gdk_window_set_back_pixmap (GdkWindow *window,
2027 gboolean parent_relative)
2029 GdkWindowObject *private = (GdkWindowObject *)window;
2032 g_return_if_fail (window != NULL);
2033 g_return_if_fail (GDK_IS_WINDOW (window));
2034 g_return_if_fail (pixmap == NULL || !parent_relative);
2036 if (private->bg_pixmap &&
2037 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2038 private->bg_pixmap != GDK_NO_BG)
2039 gdk_pixmap_unref (private->bg_pixmap);
2041 if (parent_relative)
2043 xpixmap = ParentRelative;
2044 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2050 gdk_pixmap_ref (pixmap);
2051 private->bg_pixmap = pixmap;
2052 xpixmap = GDK_PIXMAP_XID (pixmap);
2057 private->bg_pixmap = GDK_NO_BG;
2061 if (!GDK_WINDOW_DESTROYED (window))
2062 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2063 GDK_WINDOW_XID (window), xpixmap);
2067 * gdk_window_set_cursor:
2068 * @window: a #GdkWindow
2071 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2072 * gdk_cursor_new_from_pixmap() to create the cursor.
2073 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2074 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2075 * to gdk_window_set_cursor() means that @window will use the cursor of
2076 * its parent window. Most windows should use this default.
2080 gdk_window_set_cursor (GdkWindow *window,
2083 GdkCursorPrivate *cursor_private;
2086 g_return_if_fail (window != NULL);
2087 g_return_if_fail (GDK_IS_WINDOW (window));
2089 cursor_private = (GdkCursorPrivate*) cursor;
2094 xcursor = cursor_private->xcursor;
2096 if (!GDK_WINDOW_DESTROYED (window))
2097 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2098 GDK_WINDOW_XID (window),
2103 * gdk_window_get_geometry:
2104 * @window: a #GdkWindow
2105 * @x: return location for X coordinate of window (relative to its parent)
2106 * @y: return location for Y coordinate of window (relative to its parent)
2107 * @width: return location for width of window
2108 * @height: return location for height of window
2109 * @depth: return location for bit depth of window
2111 * Any of the return location arguments to this function may be %NULL,
2112 * if you aren't interested in getting the value of that field.
2114 * The X and Y coordinates returned are relative to the parent window
2115 * of @window, which for toplevels usually means relative to the
2116 * window decorations (titlebar, etc.) rather than relative to the
2117 * root window (screen-size background window).
2119 * On the X11 platform, the geometry is obtained from the X server,
2120 * so reflects the latest position of @window; this may be out-of-sync
2121 * with the position of @window delivered in the most-recently-processed
2122 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2123 * position from the most recent configure event.
2127 gdk_window_get_geometry (GdkWindow *window,
2139 guint tborder_width;
2142 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2145 window = _gdk_parent_root;
2147 if (!GDK_WINDOW_DESTROYED (window))
2149 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2150 GDK_WINDOW_XID (window),
2151 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2167 * gdk_window_get_origin:
2168 * @window: a #GdkWindow
2169 * @x: return location for X coordinate
2170 * @y: return location for Y coordinate
2172 * Obtains the position of a window in root window coordinates.
2173 * (Compare with gdk_window_get_position() and
2174 * gdk_window_get_geometry() which return the position of a window
2175 * relative to its parent window.)
2177 * Return value: not meaningful, ignore
2180 gdk_window_get_origin (GdkWindow *window,
2189 g_return_val_if_fail (window != NULL, 0);
2191 if (!GDK_WINDOW_DESTROYED (window))
2193 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2194 GDK_WINDOW_XID (window),
2212 * gdk_window_get_deskrelative_origin:
2213 * @window: a #GdkWindow
2214 * @x: return location for X coordinate
2215 * @y: return location for Y coordinate
2217 * This gets the origin of a #GdkWindow relative to
2218 * an Enlightenment-window-manager desktop. As long as you don't
2219 * assume that the user's desktop/workspace covers the entire
2220 * root window (i.e. you don't assume that the desktop begins
2221 * at root window coordinate 0,0) this function is not necessary.
2222 * It's deprecated for that reason.
2224 * Return value: not meaningful
2227 gdk_window_get_deskrelative_origin (GdkWindow *window,
2231 gboolean return_val = FALSE;
2232 gint num_children, format_return;
2233 Window win, *child, parent, root;
2237 static Atom atom = 0;
2238 gulong number_return, bytes_after_return;
2239 guchar *data_return;
2241 g_return_val_if_fail (window != NULL, 0);
2242 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2244 if (!GDK_WINDOW_DESTROYED (window))
2247 atom = gdk_x11_get_xatom_by_name ("ENLIGHTENMENT_DESKTOP");
2248 win = GDK_WINDOW_XID (window);
2250 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2251 &child, (unsigned int *)&num_children))
2253 if ((child) && (num_children > 0))
2265 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2266 False, XA_CARDINAL, &type_return, &format_return,
2267 &number_return, &bytes_after_return, &data_return);
2268 if (type_return == XA_CARDINAL)
2270 XFree (data_return);
2275 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2276 GDK_WINDOW_XID (window),
2291 * gdk_window_get_root_origin:
2292 * @window: a #GdkWindow
2293 * @x: return location for X position of window frame
2294 * @y: return location for Y position of window frame
2296 * Obtains the top-left corner of the window manager frame in root
2297 * window coordinates.
2301 gdk_window_get_root_origin (GdkWindow *window,
2307 g_return_if_fail (GDK_IS_WINDOW (window));
2309 gdk_window_get_frame_extents (window, &rect);
2319 * gdk_window_get_frame_extents:
2320 * @window: a #GdkWindow
2321 * @rect: rectangle to fill with bounding box of the window frame
2323 * Obtains the bounding box of the window, including window manager
2324 * titlebar/borders if any. The frame position is given in root window
2325 * coordinates. To get the position of the window itself (rather than
2326 * the frame) in root window coordinates, use gdk_window_get_origin().
2330 gdk_window_get_frame_extents (GdkWindow *window,
2333 GdkWindowObject *private;
2338 unsigned int nchildren;
2340 g_return_if_fail (GDK_IS_WINDOW (window));
2341 g_return_if_fail (rect != NULL);
2343 private = (GdkWindowObject*) window;
2350 if (GDK_WINDOW_DESTROYED (window))
2353 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2354 private = (GdkWindowObject*) private->parent;
2355 if (GDK_WINDOW_DESTROYED (window))
2358 xparent = GDK_WINDOW_XID (window);
2362 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2364 &children, &nchildren))
2370 while (xparent != root);
2372 if (xparent == root)
2374 unsigned int ww, wh, wb, wd;
2377 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2388 _gdk_windowing_window_get_pointer (GdkWindow *window,
2391 GdkModifierType *mask)
2393 GdkWindow *return_val;
2399 unsigned int xmask = 0;
2400 gint xoffset, yoffset;
2402 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2405 window = _gdk_parent_root;
2407 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2410 if (!GDK_WINDOW_DESTROYED (window) &&
2411 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2412 GDK_WINDOW_XID (window),
2413 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2416 return_val = gdk_window_lookup (child);
2420 *x = winx + xoffset;
2422 *y = winy + yoffset;
2430 _gdk_windowing_window_at_pointer (GdkScreen *screen,
2437 Window xwindow_last = 0;
2439 int rootx = -1, rooty = -1;
2443 xwindow = GDK_ROOT_WINDOW ();
2444 xdisplay = GDK_DISPLAY ();
2446 gdk_x11_grab_server ();
2449 xwindow_last = xwindow;
2450 XQueryPointer (xdisplay, xwindow,
2456 gdk_x11_ungrab_server ();
2458 window = gdk_window_lookup (xwindow_last);
2461 *win_x = window ? winx : -1;
2463 *win_y = window ? winy : -1;
2469 * gdk_window_get_events:
2470 * @window: a #GdkWindow
2472 * Gets the event mask for @window. See gdk_window_set_events().
2474 * Return value: event mask for @window
2477 gdk_window_get_events (GdkWindow *window)
2479 XWindowAttributes attrs;
2480 GdkEventMask event_mask;
2482 g_return_val_if_fail (window != NULL, 0);
2483 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2485 if (GDK_WINDOW_DESTROYED (window))
2489 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2490 GDK_WINDOW_XID (window),
2493 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2494 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2501 * gdk_window_set_events:
2502 * @window: a #GdkWindow
2503 * @event_mask: event mask for @window
2505 * The event mask for a window determines which events will be reported
2506 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2507 * means the window should report button press events. The event mask
2508 * is the bitwise OR of values from the #GdkEventMask enumeration.
2512 gdk_window_set_events (GdkWindow *window,
2513 GdkEventMask event_mask)
2518 g_return_if_fail (window != NULL);
2519 g_return_if_fail (GDK_IS_WINDOW (window));
2521 if (!GDK_WINDOW_DESTROYED (window))
2523 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2524 xevent_mask = StructureNotifyMask;
2525 for (i = 0; i < _gdk_nenvent_masks; i++)
2527 if (event_mask & (1 << (i + 1)))
2528 xevent_mask |= _gdk_event_mask_table[i];
2531 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2532 GDK_WINDOW_XID (window),
2538 gdk_window_add_colormap_windows (GdkWindow *window)
2540 GdkWindow *toplevel;
2541 Window *old_windows;
2542 Window *new_windows;
2545 g_return_if_fail (window != NULL);
2546 g_return_if_fail (GDK_IS_WINDOW (window));
2548 toplevel = gdk_window_get_toplevel (window);
2549 if (GDK_WINDOW_DESTROYED (toplevel))
2553 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2554 GDK_WINDOW_XID (toplevel),
2555 &old_windows, &count))
2560 for (i = 0; i < count; i++)
2561 if (old_windows[i] == GDK_WINDOW_XID (window))
2563 XFree (old_windows);
2567 new_windows = g_new (Window, count + 1);
2569 for (i = 0; i < count; i++)
2570 new_windows[i] = old_windows[i];
2571 new_windows[count] = GDK_WINDOW_XID (window);
2573 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2574 GDK_WINDOW_XID (toplevel),
2575 new_windows, count + 1);
2577 g_free (new_windows);
2579 XFree (old_windows);
2583 gdk_window_have_shape_ext (void)
2585 enum { UNKNOWN, NO, YES };
2586 static gint have_shape = UNKNOWN;
2588 if (have_shape == UNKNOWN)
2591 if (XQueryExtension (gdk_display, "SHAPE", &ignore, &ignore, &ignore))
2597 return (have_shape == YES);
2600 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2603 * This needs the X11 shape extension.
2604 * If not available, shaped windows will look
2605 * ugly, but programs still work. Stefan Wille
2608 * gdk_window_shape_combine_mask:
2609 * @window: a #GdkWindow
2611 * @x: X position of shape mask with respect to @window
2612 * @y: Y position of shape mask with respect to @window
2614 * Applies a shape mask to @window. Pixels in @window corresponding to
2615 * set bits in the @mask will be visible; pixels in @window
2616 * corresponding to unset bits in the @mask will be transparent. This
2617 * gives a non-rectangular window.
2619 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2620 * parameters are not used.
2622 * On the X11 platform, this uses an X server extension which is
2623 * widely available on most common platforms, but not available on
2624 * very old X servers, and occasionally the implementation will be
2625 * buggy. On servers without the shape extension, this function
2630 gdk_window_shape_combine_mask (GdkWindow *window,
2635 gint xoffset, yoffset;
2637 g_return_if_fail (window != NULL);
2638 g_return_if_fail (GDK_IS_WINDOW (window));
2640 #ifdef HAVE_SHAPE_EXT
2641 if (GDK_WINDOW_DESTROYED (window))
2644 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2646 if (xoffset != 0 || yoffset != 0)
2648 WARN_SHAPE_TOO_BIG ();
2652 if (gdk_window_have_shape_ext ())
2656 pixmap = GDK_PIXMAP_XID (mask);
2665 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2666 GDK_WINDOW_XID (window),
2672 #endif /* HAVE_SHAPE_EXT */
2676 * gdk_window_shape_combine_region:
2677 * @window: a #GdkWindow
2678 * @shape_region: region of window to be non-transparent
2679 * @offset_x: X position of @shape_region in @window coordinates
2680 * @offset_y: Y position of @shape_region in @window coordinates
2682 * Makes pixels in @window outside @shape_region be transparent,
2683 * so that the window may be nonrectangular. See also
2684 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2686 * If @shape_region is %NULL, the shape will be unset, so the whole
2687 * window will be opaque again. @offset_x and @offset_y are ignored
2688 * if @shape_region is %NULL.
2690 * On the X11 platform, this uses an X server extension which is
2691 * widely available on most common platforms, but not available on
2692 * very old X servers, and occasionally the implementation will be
2693 * buggy. On servers without the shape extension, this function
2698 gdk_window_shape_combine_region (GdkWindow *window,
2699 GdkRegion *shape_region,
2703 gint xoffset, yoffset;
2705 g_return_if_fail (GDK_IS_WINDOW (window));
2707 #ifdef HAVE_SHAPE_EXT
2708 if (GDK_WINDOW_DESTROYED (window))
2711 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2713 if (xoffset != 0 || yoffset != 0)
2715 WARN_SHAPE_TOO_BIG ();
2719 if (shape_region == NULL)
2721 /* Use NULL mask to unset the shape */
2722 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2726 if (gdk_window_have_shape_ext ())
2729 XRectangle *xrects = NULL;
2731 _gdk_region_get_xrectangles (shape_region,
2735 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2736 GDK_WINDOW_XID (window),
2745 #endif /* HAVE_SHAPE_EXT */
2750 * gdk_window_set_override_redirect:
2751 * @window: a #GdkWindow
2752 * @override_redirect: %TRUE if window should be override redirect
2754 * An override redirect window is not under the control of the window manager.
2755 * This means it won't have a titlebar, won't be minimizable, etc. - it will
2756 * be entirely under the control of the application. The window manager
2757 * can't see the override redirect window at all.
2759 * Override redirect should only be used for short-lived temporary
2760 * windows, such as popup menus. #GtkMenu uses an override redirect
2761 * window in its implementation, for example.
2765 gdk_window_set_override_redirect (GdkWindow *window,
2766 gboolean override_redirect)
2768 XSetWindowAttributes attr;
2770 g_return_if_fail (window != NULL);
2771 g_return_if_fail (GDK_IS_WINDOW (window));
2773 if (GDK_WINDOW_DESTROYED (window))
2775 attr.override_redirect = (override_redirect == FALSE)?False:True;
2776 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2777 GDK_WINDOW_XID (window),
2785 * gdk_window_set_icon_list:
2786 * @window: The #GdkWindow toplevel window to set the icon of.
2787 * @pixbufs: A list of pixbufs, of different sizes.
2789 * Sets a list of icons for the window. One of these will be used
2790 * to represent the window when it has been iconified. The icon is
2791 * usually shown in an icon box or some sort of task bar. Which icon
2792 * size is shown depends on the window manager. The window manager
2793 * can scale the icon but setting several size icons can give better
2794 * image quality since the window manager may only need to scale the
2795 * icon by a small amount or not at all.
2799 gdk_window_set_icon_list (GdkWindow *window,
2808 gint width, height, stride;
2812 g_return_if_fail (GDK_IS_WINDOW (window));
2814 if (GDK_WINDOW_DESTROYED (window))
2823 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
2825 width = gdk_pixbuf_get_width (pixbuf);
2826 height = gdk_pixbuf_get_height (pixbuf);
2828 size += 2 + width * height;
2830 l = g_list_next (l);
2833 data = g_malloc (size * sizeof (gulong));
2841 width = gdk_pixbuf_get_width (pixbuf);
2842 height = gdk_pixbuf_get_height (pixbuf);
2843 stride = gdk_pixbuf_get_rowstride (pixbuf);
2844 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
2849 pixels = gdk_pixbuf_get_pixels (pixbuf);
2851 for (y = 0; y < height; y++)
2853 for (x = 0; x < width; x++)
2857 r = pixels[y*stride + x*n_channels + 0];
2858 g = pixels[y*stride + x*n_channels + 1];
2859 b = pixels[y*stride + x*n_channels + 2];
2860 if (n_channels >= 4)
2861 a = pixels[y*stride + x*n_channels + 3];
2865 *p++ = a << 24 | r << 16 | g << 8 | b ;
2869 l = g_list_next (l);
2874 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2875 GDK_WINDOW_XID (window),
2876 gdk_x11_get_xatom_by_name ("_NET_WM_ICON"),
2879 (guchar*) data, size);
2883 XDeleteProperty (GDK_WINDOW_XDISPLAY (window),
2884 GDK_WINDOW_XID (window),
2885 gdk_x11_get_xatom_by_name ("_NET_WM_ICON"));
2892 * gdk_window_set_icon:
2893 * @window: a #GdkWindow
2894 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
2895 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
2896 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
2898 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
2899 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
2900 * and gtk_window_set_icon(). If those don't meet your needs, look at
2901 * gdk_window_set_icon_list(). Only if all those are too high-level do you
2902 * want to fall back to gdk_window_set_icon().
2906 gdk_window_set_icon (GdkWindow *window,
2907 GdkWindow *icon_window,
2913 g_return_if_fail (window != NULL);
2914 g_return_if_fail (GDK_IS_WINDOW (window));
2916 if (GDK_WINDOW_DESTROYED (window))
2919 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
2920 GDK_WINDOW_XID (window));
2922 wm_hints = XAllocWMHints ();
2924 if (icon_window != NULL)
2926 wm_hints->flags |= IconWindowHint;
2927 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
2932 wm_hints->flags |= IconPixmapHint;
2933 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
2938 wm_hints->flags |= IconMaskHint;
2939 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
2942 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
2943 GDK_WINDOW_XID (window), wm_hints);
2948 gdk_window_icon_name_set (GdkWindow *window)
2950 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
2951 g_quark_from_static_string ("gdk-icon-name-set")));
2955 * gdk_window_set_icon_name:
2956 * @window: a #GdkWindow
2957 * @name: name of window while iconified (minimized)
2959 * Windows may have a name used while minimized, distinct from the
2960 * name they display in their titlebar. Most of the time this is a bad
2961 * idea from a user interface standpoint. But you can set such a name
2962 * with this function, if you like.
2966 gdk_window_set_icon_name (GdkWindow *window,
2969 g_return_if_fail (window != NULL);
2970 g_return_if_fail (GDK_IS_WINDOW (window));
2972 if (GDK_WINDOW_DESTROYED (window))
2975 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
2976 GUINT_TO_POINTER (TRUE));
2978 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2979 GDK_WINDOW_XID (window),
2980 gdk_x11_get_xatom_by_name ("_NET_WM_ICON_NAME"),
2981 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
2982 PropModeReplace, name,
2984 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_ICON_NAME"), name);
2988 * gdk_window_iconify:
2989 * @window: a #GdkWindow
2991 * Asks to iconify (minimize) @window. The window manager may choose
2992 * to ignore the request, but normally will honor it. Using
2993 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
2997 gdk_window_iconify (GdkWindow *window)
3000 GdkWindowObject *private;
3002 g_return_if_fail (window != NULL);
3003 g_return_if_fail (GDK_IS_WINDOW (window));
3005 if (GDK_WINDOW_DESTROYED (window))
3008 display = GDK_WINDOW_XDISPLAY (window);
3010 private = (GdkWindowObject*) window;
3012 if (GDK_WINDOW_IS_MAPPED (window))
3014 XIconifyWindow (display, GDK_WINDOW_XWINDOW (window), DefaultScreen (display));
3019 /* Flip our client side flag, the real work happens on map. */
3020 gdk_synthesize_window_state (window,
3022 GDK_WINDOW_STATE_ICONIFIED);
3027 * gdk_window_deiconify:
3028 * @window: a #GdkWindow
3030 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3031 * choose to ignore the request to deiconify. When using GTK+,
3032 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3033 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3034 * unminimizes it, and puts it on the current desktop.
3038 gdk_window_deiconify (GdkWindow *window)
3041 GdkWindowObject *private;
3043 g_return_if_fail (window != NULL);
3044 g_return_if_fail (GDK_IS_WINDOW (window));
3046 if (GDK_WINDOW_DESTROYED (window))
3049 display = GDK_WINDOW_XDISPLAY (window);
3051 private = (GdkWindowObject*) window;
3053 if (GDK_WINDOW_IS_MAPPED (window))
3055 gdk_window_show (window);
3059 /* Flip our client side flag, the real work happens on map. */
3060 gdk_synthesize_window_state (window,
3061 GDK_WINDOW_STATE_ICONIFIED,
3068 * @window: a toplevel #GdkWindow
3070 * "Pins" a window such that it's on all workspaces and does not scroll
3071 * with viewports, for window managers that have scrollable viewports.
3072 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3074 * On the X11 platform, this function depends on window manager
3075 * support, so may have no effect with many window managers. However,
3076 * GDK will do the best it can to convince the window manager to stick
3077 * the window. For window managers that don't support this operation,
3078 * there's nothing you can do to force it to happen.
3082 gdk_window_stick (GdkWindow *window)
3084 g_return_if_fail (GDK_IS_WINDOW (window));
3086 if (GDK_WINDOW_DESTROYED (window))
3089 if (GDK_WINDOW_IS_MAPPED (window))
3091 /* "stick" means stick to all desktops _and_ do not scroll with the
3092 * viewport. i.e. glue to the monitor glass in all cases.
3097 /* Request stick during viewport scroll */
3098 gdk_wmspec_change_state (TRUE, window,
3099 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3102 /* Request desktop 0xFFFFFFFF */
3103 xev.xclient.type = ClientMessage;
3104 xev.xclient.serial = 0;
3105 xev.xclient.send_event = True;
3106 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3107 xev.xclient.display = gdk_display;
3108 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
3109 xev.xclient.format = 32;
3111 xev.xclient.data.l[0] = 0xFFFFFFFF;
3113 XSendEvent (gdk_display, _gdk_root_window, False,
3114 SubstructureRedirectMask | SubstructureNotifyMask,
3119 /* Flip our client side flag, the real work happens on map. */
3120 gdk_synthesize_window_state (window,
3122 GDK_WINDOW_STATE_STICKY);
3127 * gdk_window_unstick:
3128 * @window: a toplevel #GdkWindow
3130 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3131 * and gtk_window_unstick().
3135 gdk_window_unstick (GdkWindow *window)
3137 g_return_if_fail (GDK_IS_WINDOW (window));
3139 if (GDK_WINDOW_DESTROYED (window))
3142 if (GDK_WINDOW_IS_MAPPED (window))
3149 gulong *current_desktop;
3151 /* Request unstick from viewport */
3152 gdk_wmspec_change_state (FALSE, window,
3153 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3156 /* Get current desktop, then set it; this is a race, but not
3157 * one that matters much in practice.
3159 XGetWindowProperty (gdk_display, _gdk_root_window,
3160 gdk_x11_get_xatom_by_name ("_NET_CURRENT_DESKTOP"),
3162 False, XA_CARDINAL, &type, &format, &nitems,
3163 &bytes_after, (guchar **)¤t_desktop);
3165 if (type == XA_CARDINAL)
3167 xev.xclient.type = ClientMessage;
3168 xev.xclient.serial = 0;
3169 xev.xclient.send_event = True;
3170 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3171 xev.xclient.display = gdk_display;
3172 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
3173 xev.xclient.format = 32;
3175 xev.xclient.data.l[0] = *current_desktop;
3177 XSendEvent (gdk_display, _gdk_root_window, False,
3178 SubstructureRedirectMask | SubstructureNotifyMask,
3181 XFree (current_desktop);
3186 /* Flip our client side flag, the real work happens on map. */
3187 gdk_synthesize_window_state (window,
3188 GDK_WINDOW_STATE_STICKY,
3195 * gdk_window_maximize:
3196 * @window: a #GdkWindow
3198 * Asks the window manager to maximize @window, if the window manager supports
3199 * this operation. Not all window managers support this, and some deliberately
3200 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3201 * maximization actually happening. But it will happen with most standard
3202 * window managers, and GDK makes a best effort to get it to happen.
3204 * If the window was already maximized, then this function does nothing.
3208 gdk_window_maximize (GdkWindow *window)
3210 g_return_if_fail (GDK_IS_WINDOW (window));
3212 if (GDK_WINDOW_DESTROYED (window))
3215 if (GDK_WINDOW_IS_MAPPED (window))
3216 gdk_wmspec_change_state (TRUE, window,
3217 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3218 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3220 gdk_synthesize_window_state (window,
3222 GDK_WINDOW_STATE_MAXIMIZED);
3226 * gdk_window_unmaximize:
3227 * @window: a #GdkWindow
3229 * Asks the window manager to unmaximize @window, if the window manager supports
3230 * this operation. Not all window managers support this, and some deliberately
3231 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3232 * unmaximization actually happening. But it will happen with most standard
3233 * window managers, and GDK makes a best effort to get it to happen.
3235 * If the window wasn't maximized, then this function does nothing.
3239 gdk_window_unmaximize (GdkWindow *window)
3241 g_return_if_fail (GDK_IS_WINDOW (window));
3243 if (GDK_WINDOW_DESTROYED (window))
3246 if (GDK_WINDOW_IS_MAPPED (window))
3247 gdk_wmspec_change_state (FALSE, window,
3248 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3249 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3251 gdk_synthesize_window_state (window,
3252 GDK_WINDOW_STATE_MAXIMIZED,
3257 * gdk_window_set_group:
3258 * @window: a #GdkWindow
3259 * @leader: group leader window
3261 * Sets the group leader window for @window. By default,
3262 * GDK sets the group leader for all toplevel windows
3263 * to a global window implicitly created by GDK. With this function
3264 * you can override this default.
3266 * The group leader window allows the window manager to distinguish
3267 * all windows that belong to a single application. It may for example
3268 * allow users to minimize/unminimize all windows belonging to an
3269 * application at once. You should only set a non-default group window
3270 * if your application pretends to be multiple applications.
3271 * The group leader window may not be changed after a window has been
3272 * mapped (with gdk_window_show() for example).
3276 gdk_window_set_group (GdkWindow *window,
3281 g_return_if_fail (window != NULL);
3282 g_return_if_fail (GDK_IS_WINDOW (window));
3283 g_return_if_fail (leader != NULL);
3284 g_return_if_fail (GDK_IS_WINDOW (leader));
3286 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3289 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3290 GDK_WINDOW_XID (window));
3292 wm_hints = XAllocWMHints ();
3294 wm_hints->flags |= WindowGroupHint;
3295 wm_hints->window_group = GDK_WINDOW_XID (leader);
3297 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3298 GDK_WINDOW_XID (window), wm_hints);
3302 static MotifWmHints *
3303 gdk_window_get_mwm_hints (GdkWindow *window)
3305 static Atom hints_atom = None;
3306 MotifWmHints *hints;
3312 if (GDK_WINDOW_DESTROYED (window))
3316 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
3317 _XA_MOTIF_WM_HINTS, FALSE);
3319 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3320 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3321 False, AnyPropertyType, &type, &format, &nitems,
3322 &bytes_after, (guchar **)&hints);
3331 gdk_window_set_mwm_hints (GdkWindow *window,
3332 MotifWmHints *new_hints)
3334 static Atom hints_atom = None;
3335 MotifWmHints *hints;
3341 if (GDK_WINDOW_DESTROYED (window))
3345 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
3346 _XA_MOTIF_WM_HINTS, FALSE);
3348 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3349 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3350 False, AnyPropertyType, &type, &format, &nitems,
3351 &bytes_after, (guchar **)&hints);
3357 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3359 hints->flags |= MWM_HINTS_FUNCTIONS;
3360 hints->functions = new_hints->functions;
3362 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3364 hints->flags |= MWM_HINTS_DECORATIONS;
3365 hints->decorations = new_hints->decorations;
3369 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3370 hints_atom, hints_atom, 32, PropModeReplace,
3371 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3373 if (hints != new_hints)
3378 * gdk_window_set_decorations:
3379 * @window: a #GdkWindow
3380 * @decorations: decoration hint mask
3382 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3383 * This function sets the traditional Motif window manager hints that tell the
3384 * window manager which decorations you would like your window to have.
3385 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3386 * using the GDK function directly.
3388 * The @decorations argument is the logical OR of the fields in
3389 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3390 * mask, the other bits indicate which decorations should be turned off.
3391 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3392 * which decorations should be turned on.
3394 * Most window managers honor a decorations hint of 0 to disable all decorations,
3395 * but very few honor all possible combinations of bits.
3399 gdk_window_set_decorations (GdkWindow *window,
3400 GdkWMDecoration decorations)
3404 g_return_if_fail (window != NULL);
3405 g_return_if_fail (GDK_IS_WINDOW (window));
3407 hints.flags = MWM_HINTS_DECORATIONS;
3408 hints.decorations = decorations;
3410 gdk_window_set_mwm_hints (window, &hints);
3414 * gdk_window_get_decorations:
3415 * @window: The #GdkWindow to get the decorations from
3416 * @decorations: The window decorations will be written here
3418 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3419 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3422 gdk_window_get_decorations(GdkWindow *window,
3423 GdkWMDecoration *decorations)
3425 MotifWmHints *hints;
3426 gboolean result = FALSE;
3428 hints = gdk_window_get_mwm_hints (window);
3432 if (hints->flags & MWM_HINTS_DECORATIONS)
3434 *decorations = hints->decorations;
3445 * gdk_window_set_functions:
3446 * @window: a #GdkWindow
3447 * @functions: bitmask of operations to allow on @window
3449 * This function isn't really good for much. It sets the traditional
3450 * Motif window manager hint for which operations the window manager
3451 * should allow on a toplevel window. However, few window managers do
3452 * anything reliable or interesting with this hint. Many ignore it
3455 * The @functions argument is the logical OR of values from the
3456 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3457 * then the other bits indicate which functions to disable; if
3458 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3463 gdk_window_set_functions (GdkWindow *window,
3464 GdkWMFunction functions)
3468 g_return_if_fail (window != NULL);
3469 g_return_if_fail (GDK_IS_WINDOW (window));
3471 hints.flags = MWM_HINTS_FUNCTIONS;
3472 hints.functions = functions;
3474 gdk_window_set_mwm_hints (window, &hints);
3477 #ifdef HAVE_SHAPE_EXT
3480 * propagate the shapes from all child windows of a GDK window to the parent
3481 * window. Shamelessly ripped from Enlightenment's code
3489 struct _gdk_span *next;
3493 gdk_add_to_span (struct _gdk_span **s,
3497 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3504 /* scan the spans for this line */
3507 /* -- -> new span */
3508 /* == -> existing span */
3509 /* ## -> spans intersect */
3510 /* if we are in the middle of spanning the span into the line */
3513 /* case: ---- ==== */
3514 if (xx < ptr1->start - 1)
3516 /* ends before next span - extend to here */
3520 /* case: ----##=== */
3521 else if (xx <= ptr1->end)
3523 /* crosses into next span - delete next span and append */
3524 ss->end = ptr1->end;
3525 ss->next = ptr1->next;
3529 /* case: ---###--- */
3532 /* overlaps next span - delete and keep checking */
3533 ss->next = ptr1->next;
3538 /* otherwise havent started spanning it in yet */
3541 /* case: ---- ==== */
3542 if (xx < ptr1->start - 1)
3544 /* insert span here in list */
3545 noo = g_malloc (sizeof (struct _gdk_span));
3559 /* case: ----##=== */
3560 else if ((x < ptr1->start) && (xx <= ptr1->end))
3562 /* expand this span to the left point of the new one */
3566 /* case: ===###=== */
3567 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3569 /* throw the span away */
3572 /* case: ---###--- */
3573 else if ((x < ptr1->start) && (xx > ptr1->end))
3580 /* case: ===##---- */
3581 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3587 /* case: ==== ---- */
3588 /* case handled by next loop iteration - first case */
3593 /* it started in the middle but spans beyond your current list */
3599 /* it does not start inside a span or in the middle, so add it to the end */
3600 noo = g_malloc (sizeof (struct _gdk_span));
3608 noo->next = ptr2->next;
3621 gdk_add_rectangles (Display *disp,
3623 struct _gdk_span **spans,
3630 gint x1, y1, x2, y2;
3634 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
3637 /* go through all clip rects in this window's shape */
3638 for (k = 0; k < rn; k++)
3640 /* for each clip rect, add it to each line's spans */
3642 x2 = x + rl[k].x + (rl[k].width - 1);
3644 y2 = y + rl[k].y + (rl[k].height - 1);
3653 for (a = y1; a <= y2; a++)
3656 gdk_add_to_span (&spans[a], x1, x2);
3664 gdk_propagate_shapes (Display *disp,
3668 Window rt, par, *list = NULL;
3669 gint i, j, num = 0, num_rects = 0;
3673 XRectangle *rects = NULL;
3674 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
3675 XWindowAttributes xatt;
3677 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
3682 spans = g_malloc (sizeof (struct _gdk_span *) * h);
3684 for (i = 0; i < h; i++)
3686 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
3689 /* go through all child windows and create/insert spans */
3690 for (i = 0; i < num; i++)
3692 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
3693 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
3694 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
3697 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
3699 /* go through the spans list and build a list of rects */
3700 rects = g_malloc (sizeof (XRectangle) * 256);
3702 for (i = 0; i < baseh; i++)
3705 /* go through the line for all spans */
3708 rects[num_rects].x = ptr1->start;
3709 rects[num_rects].y = i;
3710 rects[num_rects].width = ptr1->end - ptr1->start + 1;
3711 rects[num_rects].height = 1;
3713 /* if there are more lines */
3715 /* while contigous rects (same start/end coords) exist */
3716 while ((contig) && (j < baseh))
3718 /* search next line for spans matching this one */
3724 /* if we have an exact span match set contig */
3725 if ((ptr2->start == ptr1->start) &&
3726 (ptr2->end == ptr1->end))
3729 /* remove the span - not needed */
3732 ptr3->next = ptr2->next;
3738 spans[j] = ptr2->next;
3744 /* gone past the span point no point looking */
3745 else if (ptr2->start < ptr1->start)
3753 /* if a contiguous span was found increase the rect h */
3756 rects[num_rects].height++;
3760 /* up the rect count */
3762 /* every 256 new rects increase the rect array */
3763 if ((num_rects % 256) == 0)
3764 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
3768 /* set the rects as the shape mask */
3771 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
3772 ShapeSet, YXSorted);
3777 /* free up all the spans we made */
3778 for (i = 0; i < baseh; i++)
3791 #endif /* HAVE_SHAPE_EXT */
3794 * gdk_window_set_child_shapes:
3795 * @window: a #GdkWindow
3797 * Sets the shape mask of @window to the union of shape masks
3798 * for all children of @window, ignoring the shape mask of @window
3799 * itself. Contrast with gdk_window_merge_child_shapes() which includes
3800 * the shape mask of @window in the masks to be merged.
3803 gdk_window_set_child_shapes (GdkWindow *window)
3805 g_return_if_fail (window != NULL);
3806 g_return_if_fail (GDK_IS_WINDOW (window));
3808 #ifdef HAVE_SHAPE_EXT
3809 if (!GDK_WINDOW_DESTROYED (window) &&
3810 gdk_window_have_shape_ext ())
3811 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3812 GDK_WINDOW_XID (window), FALSE);
3817 * gdk_window_merge_child_shapes:
3818 * @window: a #GdkWindow
3820 * Merges the shape masks for any child windows into the
3821 * shape mask for @window. i.e. the union of all masks
3822 * for @window and its children will become the new mask
3823 * for @window. See gdk_window_shape_combine_mask().
3825 * This function is distinct from gdk_window_set_child_shapes()
3826 * because it includes @window's shape mask in the set of shapes to
3831 gdk_window_merge_child_shapes (GdkWindow *window)
3833 g_return_if_fail (window != NULL);
3834 g_return_if_fail (GDK_IS_WINDOW (window));
3836 #ifdef HAVE_SHAPE_EXT
3837 if (!GDK_WINDOW_DESTROYED (window) &&
3838 gdk_window_have_shape_ext ())
3839 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3840 GDK_WINDOW_XID (window), TRUE);
3844 /* Support for windows that can be guffaw-scrolled
3845 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
3849 gdk_window_gravity_works (void)
3851 enum { UNKNOWN, NO, YES };
3852 static gint gravity_works = UNKNOWN;
3854 if (gravity_works == UNKNOWN)
3861 /* This particular server apparently has a bug so that the test
3862 * works but the actual code crashes it
3864 if ((!strcmp (XServerVendor (gdk_display), "Sun Microsystems, Inc.")) &&
3865 (VendorRelease (gdk_display) == 3400))
3871 attr.window_type = GDK_WINDOW_TEMP;
3872 attr.wclass = GDK_INPUT_OUTPUT;
3877 attr.event_mask = 0;
3879 parent = gdk_window_new (NULL, &attr, GDK_WA_X | GDK_WA_Y);
3881 attr.window_type = GDK_WINDOW_CHILD;
3882 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
3884 gdk_window_set_static_win_gravity (child, TRUE);
3886 gdk_window_resize (parent, 100, 110);
3887 gdk_window_move (parent, 0, -10);
3888 gdk_window_move_resize (parent, 0, 0, 100, 100);
3890 gdk_window_resize (parent, 100, 110);
3891 gdk_window_move (parent, 0, -10);
3892 gdk_window_move_resize (parent, 0, 0, 100, 100);
3894 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
3896 gdk_window_destroy (parent);
3897 gdk_window_destroy (child);
3899 gravity_works = ((y == -20) ? YES : NO);
3902 return (gravity_works == YES);
3906 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
3908 XSetWindowAttributes xattributes;
3909 guint xattributes_mask = 0;
3911 g_return_if_fail (window != NULL);
3913 xattributes.bit_gravity = StaticGravity;
3914 xattributes_mask |= CWBitGravity;
3915 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
3916 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3917 GDK_WINDOW_XID (window),
3918 CWBitGravity, &xattributes);
3922 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
3924 XSetWindowAttributes xattributes;
3926 g_return_if_fail (window != NULL);
3928 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
3930 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3931 GDK_WINDOW_XID (window),
3932 CWWinGravity, &xattributes);
3936 * gdk_window_set_static_gravities:
3937 * @window: a #GdkWindow
3938 * @use_static: %TRUE to turn on static gravity
3940 * Set the bit gravity of the given window to static, and flag it so
3941 * all children get static subwindow gravity. This is used if you are
3942 * implementing scary features that involve deep knowledge of the
3943 * windowing system. Don't worry about it unless you have to.
3945 * Return value: %TRUE if the server supports static gravity
3948 gdk_window_set_static_gravities (GdkWindow *window,
3949 gboolean use_static)
3951 GdkWindowObject *private = (GdkWindowObject *)window;
3954 g_return_val_if_fail (window != NULL, FALSE);
3955 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3957 if (!use_static == !private->guffaw_gravity)
3960 if (use_static && !gdk_window_gravity_works ())
3963 private->guffaw_gravity = use_static;
3965 if (!GDK_WINDOW_DESTROYED (window))
3967 gdk_window_set_static_bit_gravity (window, use_static);
3969 tmp_list = private->children;
3972 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
3974 tmp_list = tmp_list->next;
3981 /* internal function created for and used by gdk_window_xid_at_coords */
3983 gdk_window_xid_at (Window base,
3989 gboolean excl_child)
3992 Window *list = NULL;
3993 Window child = 0, parent_win = 0, root_win = 0;
3995 unsigned int ww, wh, wb, wd, num;
3998 xdisplay = GDK_DISPLAY ();
3999 if (!XGetGeometry (xdisplay, base, &root_win, &wx, &wy, &ww, &wh, &wb, &wd))
4006 (x < (int) (wx + ww)) &&
4007 (y < (int) (wy + wh))))
4010 if (!XQueryTree (xdisplay, base, &root_win, &parent_win, &list, &num))
4015 for (i = num - 1; ; i--)
4017 if ((!excl_child) || (!g_list_find (excludes, (gpointer *) list[i])))
4019 if ((child = gdk_window_xid_at (list[i], wx, wy, x, y, excludes, excl_child)) != 0)
4034 * The following fucntion by The Rasterman <raster@redhat.com>
4035 * This function returns the X Window ID in which the x y location is in
4036 * (x and y being relative to the root window), excluding any windows listed
4037 * in the GList excludes (this is a list of X Window ID's - gpointer being
4040 * This is primarily designed for internal gdk use - for DND for example
4041 * when using a shaped icon window as the drag object - you exclude the
4042 * X Window ID of the "icon" (perhaps more if excludes may be needed) and
4043 * You can get back an X Window ID as to what X Window ID is infact under
4044 * those X,Y co-ordinates.
4047 gdk_window_xid_at_coords (gint x,
4050 gboolean excl_child)
4054 Window *list = NULL;
4055 Window root, child = 0, parent_win = 0, root_win = 0;
4059 window = _gdk_parent_root;
4060 xdisplay = GDK_WINDOW_XDISPLAY (window);
4061 root = GDK_WINDOW_XID (window);
4062 num = g_list_length (excludes);
4064 gdk_x11_grab_server ();
4065 if (!XQueryTree (xdisplay, root, &root_win, &parent_win, &list, &num))
4067 gdk_x11_ungrab_server ();
4075 XWindowAttributes xwa;
4077 XGetWindowAttributes (xdisplay, list [i], &xwa);
4079 if (xwa.map_state != IsViewable)
4082 if (excl_child && g_list_find (excludes, (gpointer *) list[i]))
4085 if ((child = gdk_window_xid_at (list[i], 0, 0, x, y, excludes, excl_child)) == 0)
4090 if (!g_list_find (excludes, (gpointer *) child))
4093 gdk_x11_ungrab_server ();
4100 gdk_x11_ungrab_server ();
4106 gdk_x11_ungrab_server ();
4111 wmspec_moveresize (GdkWindow *window,
4119 /* Release passive grab */
4120 gdk_pointer_ungrab (timestamp);
4122 xev.xclient.type = ClientMessage;
4123 xev.xclient.serial = 0;
4124 xev.xclient.send_event = True;
4125 xev.xclient.display = gdk_display;
4126 xev.xclient.window = GDK_WINDOW_XID (window);
4127 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_MOVERESIZE");
4128 xev.xclient.format = 32;
4129 xev.xclient.data.l[0] = root_x;
4130 xev.xclient.data.l[1] = root_y;
4131 xev.xclient.data.l[2] = direction;
4132 xev.xclient.data.l[3] = 0;
4133 xev.xclient.data.l[4] = 0;
4135 XSendEvent (gdk_display, _gdk_root_window, False,
4136 SubstructureRedirectMask | SubstructureNotifyMask,
4140 /* From the WM spec */
4141 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4142 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4143 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4144 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4145 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4146 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4147 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4148 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4149 #define _NET_WM_MOVERESIZE_MOVE 8
4152 wmspec_resize_drag (GdkWindow *window,
4161 /* Let the compiler turn a switch into a table, instead
4162 * of doing the table manually, this way is easier to verify.
4166 case GDK_WINDOW_EDGE_NORTH_WEST:
4167 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4170 case GDK_WINDOW_EDGE_NORTH:
4171 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4174 case GDK_WINDOW_EDGE_NORTH_EAST:
4175 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4178 case GDK_WINDOW_EDGE_WEST:
4179 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4182 case GDK_WINDOW_EDGE_EAST:
4183 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4186 case GDK_WINDOW_EDGE_SOUTH_WEST:
4187 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4190 case GDK_WINDOW_EDGE_SOUTH:
4191 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4194 case GDK_WINDOW_EDGE_SOUTH_EAST:
4195 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4199 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4205 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4208 /* This is global for use in gdkevents-x11.c */
4209 GdkWindow *_gdk_moveresize_window;
4211 static GdkWindow *moveresize_emulation_window = NULL;
4212 static gboolean is_resize = FALSE;
4213 static GdkWindowEdge resize_edge;
4214 static gint moveresize_button;
4215 static gint moveresize_x;
4216 static gint moveresize_y;
4217 static gint moveresize_orig_x;
4218 static gint moveresize_orig_y;
4219 static gint moveresize_orig_width;
4220 static gint moveresize_orig_height;
4221 static GdkWindowHints moveresize_geom_mask = 0;
4222 static GdkGeometry moveresize_geometry;
4223 static Time moveresize_process_time;
4225 static XEvent *moveresize_pending_event;
4228 update_pos (gint new_root_x,
4233 dx = new_root_x - moveresize_x;
4234 dy = new_root_y - moveresize_y;
4240 w = moveresize_orig_width;
4241 h = moveresize_orig_height;
4243 switch (resize_edge)
4245 case GDK_WINDOW_EDGE_SOUTH_EAST:
4254 if (moveresize_geom_mask)
4256 gdk_window_constrain_size (&moveresize_geometry,
4257 moveresize_geom_mask,
4262 gdk_window_resize (_gdk_moveresize_window, w, h);
4268 x = moveresize_orig_x + dx;
4269 y = moveresize_orig_y + dy;
4271 gdk_window_move (_gdk_moveresize_window, x, y);
4278 gdk_window_destroy (moveresize_emulation_window);
4279 moveresize_emulation_window = NULL;
4280 _gdk_moveresize_window = NULL;
4282 if (moveresize_pending_event)
4284 g_free (moveresize_pending_event);
4285 moveresize_pending_event = NULL;
4290 lookahead_motion_predicate (Display *display,
4294 gboolean *seen_release = (gboolean *)arg;
4299 switch (event->xany.type)
4302 *seen_release = TRUE;
4305 moveresize_process_time = event->xmotion.time;
4315 moveresize_lookahead (XEvent *event)
4318 gboolean seen_release = FALSE;
4320 if (moveresize_process_time)
4322 if (event->xmotion.time == moveresize_process_time)
4324 moveresize_process_time = 0;
4331 XCheckIfEvent (gdk_display, &tmp_event,
4332 lookahead_motion_predicate, (XPointer)&seen_release);
4334 return moveresize_process_time == 0;
4338 _gdk_moveresize_handle_event (XEvent *event)
4340 guint button_mask = 0;
4341 GdkWindowObject *window_private = (GdkWindowObject *) _gdk_moveresize_window;
4343 button_mask = GDK_BUTTON1_MASK << (moveresize_button - 1);
4345 switch (event->xany.type)
4348 if (window_private->resize_count > 0)
4350 if (moveresize_pending_event)
4351 *moveresize_pending_event = *event;
4353 moveresize_pending_event = g_memdup (event, sizeof (XEvent));
4357 if (!moveresize_lookahead (event))
4360 update_pos (event->xmotion.x_root,
4361 event->xmotion.y_root);
4363 /* This should never be triggered in normal cases, but in the
4364 * case where the drag started without an implicit grab being
4365 * in effect, we could miss the release if it occurs before
4366 * we grab the pointer; this ensures that we will never
4367 * get a permanently stuck grab.
4369 if ((event->xmotion.state & button_mask) == 0)
4374 update_pos (event->xbutton.x_root,
4375 event->xbutton.y_root);
4377 if (event->xbutton.button == moveresize_button)
4384 _gdk_moveresize_configure_done (void)
4388 if (moveresize_pending_event)
4390 tmp_event = moveresize_pending_event;
4391 moveresize_pending_event = NULL;
4392 _gdk_moveresize_handle_event (tmp_event);
4398 create_moveresize_window (guint32 timestamp)
4400 GdkWindowAttr attributes;
4401 gint attributes_mask;
4402 GdkGrabStatus status;
4404 g_assert (moveresize_emulation_window == NULL);
4406 attributes.x = -100;
4407 attributes.y = -100;
4408 attributes.width = 10;
4409 attributes.height = 10;
4410 attributes.window_type = GDK_WINDOW_TEMP;
4411 attributes.wclass = GDK_INPUT_ONLY;
4412 attributes.override_redirect = TRUE;
4413 attributes.event_mask = 0;
4415 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4417 moveresize_emulation_window =
4418 gdk_window_new (NULL, &attributes, attributes_mask);
4420 gdk_window_show (moveresize_emulation_window);
4422 status = gdk_pointer_grab (moveresize_emulation_window,
4424 GDK_BUTTON_RELEASE_MASK |
4425 GDK_POINTER_MOTION_MASK,
4430 if (status != GDK_GRAB_SUCCESS)
4432 /* If this fails, some other client has grabbed the window
4435 gdk_window_destroy (moveresize_emulation_window);
4436 moveresize_emulation_window = NULL;
4439 moveresize_process_time = 0;
4443 emulate_resize_drag (GdkWindow *window,
4451 moveresize_button = button;
4453 moveresize_x = root_x;
4454 moveresize_y = root_y;
4455 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4457 gdk_window_get_size (window, &moveresize_orig_width, &moveresize_orig_height);
4459 moveresize_geom_mask = 0;
4460 gdk_window_get_geometry_hints (window,
4461 &moveresize_geometry,
4462 &moveresize_geom_mask);
4464 create_moveresize_window (timestamp);
4468 emulate_move_drag (GdkWindow *window,
4475 moveresize_button = button;
4476 moveresize_x = root_x;
4477 moveresize_y = root_y;
4478 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4480 gdk_window_get_deskrelative_origin (_gdk_moveresize_window,
4482 &moveresize_orig_y);
4484 create_moveresize_window (timestamp);
4488 * gdk_window_begin_resize_drag:
4489 * @window: a #GdkWindow
4490 * @edge: the edge or corner from which the drag is started
4491 * @button: the button being used to drag
4492 * @root_x: root window X coordinate of mouse click that began the drag
4493 * @root_y: root window Y coordinate of mouse click that began the drag
4494 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4496 * Begins a window resize operation (for a toplevel window).
4497 * You might use this function to implement a "window resize grip," for
4498 * example; in fact #GtkStatusbar uses it. The function works best
4499 * with window managers that support the Extended Window Manager Hints spec
4500 * (see http://www.freedesktop.org), but has a fallback implementation
4501 * for other window managers.
4505 gdk_window_begin_resize_drag (GdkWindow *window,
4512 g_return_if_fail (GDK_IS_WINDOW (window));
4513 g_return_if_fail (moveresize_emulation_window == NULL);
4515 if (GDK_WINDOW_DESTROYED (window))
4518 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4519 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4521 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4525 * gdk_window_begin_move_drag:
4526 * @window: a #GdkWindow
4527 * @button: the button being used to drag
4528 * @root_x: root window X coordinate of mouse click that began the drag
4529 * @root_y: root window Y coordinate of mouse click that began the drag
4530 * @timestamp: timestamp of mouse click that began the drag
4532 * Begins a window move operation (for a toplevel window). You might
4533 * use this function to implement a "window move grip," for
4534 * example. The function works best with window managers that support
4535 * the Extended Window Manager Hints spec (see
4536 * http://www.freedesktop.org), but has a fallback implementation for
4537 * other window managers.
4541 gdk_window_begin_move_drag (GdkWindow *window,
4547 g_return_if_fail (GDK_IS_WINDOW (window));
4548 g_return_if_fail (moveresize_emulation_window == NULL);
4550 if (GDK_WINDOW_DESTROYED (window))
4553 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4554 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE,
4555 root_x, root_y, timestamp);
4557 emulate_move_drag (window, button, root_x, root_y, timestamp);