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 if (!GDK_WINDOW_DESTROYED (wrapper))
174 gdk_xid_table_remove (draw_impl->xid);
175 if (window_impl->focus_window)
176 gdk_xid_table_remove (window_impl->focus_window);
179 G_OBJECT_CLASS (parent_class)->finalize (object);
183 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
185 GdkDrawableImplX11 *drawable_impl;
186 GdkWindowImplX11 *window_impl;
188 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
190 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
191 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
193 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
194 drawable_impl->colormap == NULL)
196 XWindowAttributes window_attributes;
198 XGetWindowAttributes (drawable_impl->xdisplay,
201 drawable_impl->colormap =
202 gdk_colormap_lookup (window_attributes.colormap);
205 return drawable_impl->colormap;
209 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
212 GdkWindowImplX11 *impl;
213 GdkDrawableImplX11 *draw_impl;
215 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
217 impl = GDK_WINDOW_IMPL_X11 (drawable);
218 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
221 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
225 XSetWindowColormap (draw_impl->xdisplay,
227 GDK_COLORMAP_XCOLORMAP (cmap));
229 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
231 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
237 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
241 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
244 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
246 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
250 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
252 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
253 GdkRectangle result_rect;
257 result_rect.width = impl->width;
258 result_rect.height = impl->height;
260 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
262 return gdk_region_rectangle (&result_rect);
266 _gdk_windowing_window_init (void)
268 GdkWindowObject *private;
269 GdkWindowImplX11 *impl;
270 GdkDrawableImplX11 *draw_impl;
271 XWindowAttributes xattributes;
274 unsigned int border_width;
278 g_assert (_gdk_parent_root == NULL);
280 XGetGeometry (gdk_display, _gdk_root_window, &_gdk_root_window,
281 &x, &y, &width, &height, &border_width, &depth);
282 XGetWindowAttributes (gdk_display, _gdk_root_window, &xattributes);
284 _gdk_parent_root = g_object_new (GDK_TYPE_WINDOW, NULL);
285 private = (GdkWindowObject *)_gdk_parent_root;
286 impl = GDK_WINDOW_IMPL_X11 (private->impl);
287 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
289 draw_impl->xdisplay = gdk_display;
290 draw_impl->xid = _gdk_root_window;
291 draw_impl->wrapper = GDK_DRAWABLE (private);
293 private->window_type = GDK_WINDOW_ROOT;
294 private->depth = depth;
296 impl->height = height;
298 gdk_xid_table_insert (&_gdk_root_window, _gdk_parent_root);
301 static Atom wm_client_leader_atom = None;
305 * @parent: a #GdkWindow
306 * @attributes: attributes of the new window
307 * @attributes_mask: mask indicating which fields in @attributes are valid
309 * Creates a new #GdkWindow using the attributes from @attributes. See
310 * #GdkWindowAttr and #GdkWindowAttributesType for more details.
312 * Return value: the new #GdkWindow
315 gdk_window_new (GdkWindow *parent,
316 GdkWindowAttr *attributes,
317 gint attributes_mask)
320 GdkWindowObject *private;
321 GdkWindowImplX11 *impl;
322 GdkDrawableImplX11 *draw_impl;
330 XSetWindowAttributes xattributes;
331 long xattributes_mask;
332 XSizeHints size_hints;
334 XClassHint *class_hint;
342 g_return_val_if_fail (attributes != NULL, NULL);
345 parent = _gdk_parent_root;
347 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
349 if (GDK_WINDOW_DESTROYED (parent))
352 xparent = GDK_WINDOW_XID (parent);
354 window = g_object_new (GDK_TYPE_WINDOW, NULL);
355 private = (GdkWindowObject *)window;
356 impl = GDK_WINDOW_IMPL_X11 (private->impl);
357 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
358 draw_impl->wrapper = GDK_DRAWABLE (window);
360 xdisplay = draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (parent);
362 /* Windows with a foreign parent are treated as if they are children
363 * of the root window, except for actual creation.
365 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
366 parent = _gdk_parent_root;
368 private->parent = (GdkWindowObject *)parent;
370 xattributes_mask = 0;
372 if (attributes_mask & GDK_WA_X)
377 if (attributes_mask & GDK_WA_Y)
384 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
385 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
387 if (attributes->wclass == GDK_INPUT_ONLY)
389 /* Backwards compatiblity - we've always ignored
390 * attributes->window_type for input-only windows
393 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
394 private->window_type = GDK_WINDOW_TEMP;
396 private->window_type = GDK_WINDOW_CHILD;
399 private->window_type = attributes->window_type;
401 _gdk_window_init_position (GDK_WINDOW (private));
402 if (impl->position_info.big)
403 private->guffaw_gravity = TRUE;
405 if (attributes_mask & GDK_WA_VISUAL)
406 visual = attributes->visual;
408 visual = gdk_visual_get_system ();
409 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
411 xattributes.event_mask = StructureNotifyMask;
412 for (i = 0; i < _gdk_nenvent_masks; i++)
414 if (attributes->event_mask & (1 << (i + 1)))
415 xattributes.event_mask |= _gdk_event_mask_table[i];
417 private->event_mask = attributes->event_mask;
419 if (xattributes.event_mask)
420 xattributes_mask |= CWEventMask;
422 if (attributes_mask & GDK_WA_NOREDIR)
424 xattributes.override_redirect =
425 (attributes->override_redirect == FALSE)?False:True;
426 xattributes_mask |= CWOverrideRedirect;
429 xattributes.override_redirect = False;
431 if (private->parent && private->parent->guffaw_gravity)
433 xattributes.win_gravity = StaticGravity;
434 xattributes_mask |= CWWinGravity;
438 switch (private->window_type)
440 case GDK_WINDOW_TOPLEVEL:
441 case GDK_WINDOW_DIALOG:
442 case GDK_WINDOW_TEMP:
443 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
445 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
446 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
447 xparent = _gdk_root_window;
449 case GDK_WINDOW_CHILD:
452 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
456 if (attributes->wclass == GDK_INPUT_OUTPUT)
459 depth = visual->depth;
461 private->input_only = FALSE;
462 private->depth = depth;
464 if (attributes_mask & GDK_WA_COLORMAP)
466 draw_impl->colormap = attributes->colormap;
467 gdk_colormap_ref (attributes->colormap);
471 if ((((GdkVisualPrivate*)gdk_visual_get_system ())->xvisual) == xvisual)
473 draw_impl->colormap =
474 gdk_colormap_get_system ();
475 gdk_colormap_ref (draw_impl->colormap);
479 draw_impl->colormap =
480 gdk_colormap_new (visual, FALSE);
484 private->bg_color.pixel = BlackPixel (gdk_display, _gdk_screen);
485 xattributes.background_pixel = private->bg_color.pixel;
487 private->bg_pixmap = NULL;
489 xattributes.border_pixel = BlackPixel (gdk_display, _gdk_screen);
490 xattributes_mask |= CWBorderPixel | CWBackPixel;
492 if (private->guffaw_gravity)
493 xattributes.bit_gravity = StaticGravity;
495 xattributes.bit_gravity = NorthWestGravity;
497 xattributes_mask |= CWBitGravity;
499 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
500 xattributes_mask |= CWColormap;
502 if (private->window_type == GDK_WINDOW_TEMP)
504 xattributes.save_under = True;
505 xattributes.override_redirect = True;
506 xattributes.cursor = None;
507 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
515 private->input_only = TRUE;
516 draw_impl->colormap = gdk_colormap_get_system ();
517 gdk_colormap_ref (draw_impl->colormap);
520 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
521 impl->position_info.x, impl->position_info.y,
522 impl->position_info.width, impl->position_info.height,
523 0, depth, class, xvisual,
524 xattributes_mask, &xattributes);
526 gdk_drawable_ref (window);
527 gdk_xid_table_insert (&draw_impl->xid, window);
529 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
530 (attributes->cursor) :
534 private->parent->children = g_list_prepend (private->parent->children, window);
536 switch (GDK_WINDOW_TYPE (private))
538 case GDK_WINDOW_DIALOG:
539 XSetTransientForHint (xdisplay, xid, xparent);
540 case GDK_WINDOW_TOPLEVEL:
541 case GDK_WINDOW_TEMP:
542 XSetWMProtocols (xdisplay, xid,
543 _gdk_wm_window_protocols, 3);
545 case GDK_WINDOW_CHILD:
546 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
547 (draw_impl->colormap != gdk_colormap_get_system ()) &&
548 (draw_impl->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window))))
550 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
551 gdk_window_add_colormap_windows (window);
560 if (class != InputOnly)
562 /* The focus window is off the visible area, and serves to receive key
563 * press events so they don't get sent to child windows.
565 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
567 xattributes.background_pixel,
568 xattributes.background_pixel);
569 /* FIXME: probably better to actually track the requested event mask for the toplevel
571 XSelectInput (xdisplay, impl->focus_window,
572 KeyPressMask | KeyReleaseMask | FocusChangeMask);
574 XMapWindow (xdisplay, impl->focus_window);
575 gdk_xid_table_insert (&impl->focus_window, window);
578 size_hints.flags = PSize;
579 size_hints.width = impl->width;
580 size_hints.height = impl->height;
582 wm_hints.flags = StateHint | WindowGroupHint;
583 wm_hints.window_group = _gdk_leader_window;
584 wm_hints.input = True;
585 wm_hints.initial_state = NormalState;
587 /* FIXME: Is there any point in doing this? Do any WM's pay
588 * attention to PSize, and even if they do, is this the
591 XSetWMNormalHints (xdisplay, xid, &size_hints);
593 XSetWMHints (xdisplay, xid, &wm_hints);
595 if (!wm_client_leader_atom)
596 wm_client_leader_atom = gdk_x11_get_xatom_by_name ("WM_CLIENT_LEADER");
598 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
599 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
602 XChangeProperty (xdisplay, xid,
603 gdk_x11_get_xatom_by_name ("_NET_WM_PID"),
608 XChangeProperty (xdisplay, xid,
609 wm_client_leader_atom,
610 XA_WINDOW, 32, PropModeReplace,
611 (guchar*) &_gdk_leader_window, 1);
613 if (attributes_mask & GDK_WA_TITLE)
614 title = attributes->title;
616 title = g_get_prgname ();
618 gdk_window_set_title (window, title);
620 if (attributes_mask & GDK_WA_WMCLASS)
622 class_hint = XAllocClassHint ();
623 class_hint->res_name = attributes->wmclass_name;
624 class_hint->res_class = attributes->wmclass_class;
625 XSetClassHint (xdisplay, xid, class_hint);
633 x_event_mask_to_gdk_event_mask (long mask)
635 GdkEventMask event_mask = 0;
638 for (i = 0; i < _gdk_nenvent_masks; i++)
640 if (mask & _gdk_event_mask_table[i])
641 event_mask |= 1 << (i + 1);
648 * gdk_window_foreign_new:
649 * @anid: a native window handle.
651 * Wraps a native window in a #GdkWindow.
652 * This may fail if the window has been destroyed.
654 * For example in the X backend, a native window handle is an Xlib
657 * Return value: the newly-created #GdkWindow wrapper for the
658 * native window or %NULL if the window has been destroyed.
661 gdk_window_foreign_new (GdkNativeWindow anid)
664 GdkWindowObject *private;
665 GdkWindowImplX11 *impl;
666 GdkDrawableImplX11 *draw_impl;
667 XWindowAttributes attrs;
669 Window *children = NULL;
673 gdk_error_trap_push ();
674 result = XGetWindowAttributes (gdk_display, anid, &attrs);
675 if (gdk_error_trap_pop () || !result)
678 /* FIXME: This is pretty expensive. Maybe the caller should supply
680 gdk_error_trap_push ();
681 result = XQueryTree (gdk_display, anid, &root, &parent, &children, &nchildren);
682 if (gdk_error_trap_pop () || !result)
688 window = g_object_new (GDK_TYPE_WINDOW, NULL);
689 private = (GdkWindowObject *)window;
690 impl = GDK_WINDOW_IMPL_X11 (private->impl);
691 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
692 draw_impl->wrapper = GDK_DRAWABLE (window);
694 private->parent = gdk_xid_table_lookup (parent);
695 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
696 private->parent = (GdkWindowObject *)_gdk_parent_root;
698 private->parent->children = g_list_prepend (private->parent->children, window);
700 draw_impl->xid = anid;
701 draw_impl->xdisplay = gdk_display;
703 private->x = attrs.x;
704 private->y = attrs.y;
705 impl->width = attrs.width;
706 impl->height = attrs.height;
707 private->window_type = GDK_WINDOW_FOREIGN;
708 private->destroyed = FALSE;
710 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
712 if (attrs.map_state == IsUnmapped)
713 private->state = GDK_WINDOW_STATE_WITHDRAWN;
717 private->depth = attrs.depth;
719 _gdk_window_init_position (GDK_WINDOW (private));
721 gdk_drawable_ref (window);
722 gdk_xid_table_insert (&GDK_WINDOW_XID (window), window);
729 * @anid: a native window handle.
731 * Looks up the #GdkWindow that wraps the given native window handle.
733 * For example in the X backend, a native window handle is an Xlib
736 * Return value: the #GdkWindow wrapper for the native window,
737 * or %NULL if there is none.
740 gdk_window_lookup (GdkNativeWindow anid)
742 return (GdkWindow*) gdk_xid_table_lookup (anid);
746 _gdk_windowing_window_destroy (GdkWindow *window,
748 gboolean foreign_destroy)
750 GdkWindowObject *private = (GdkWindowObject *)window;
752 g_return_if_fail (GDK_IS_WINDOW (window));
754 _gdk_selection_window_destroyed (window);
756 if (private->extension_events != 0)
757 gdk_input_window_destroy (window);
761 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
763 if (draw_impl->picture)
764 XRenderFreePicture (draw_impl->xdisplay, draw_impl->picture);
766 #endif /* HAVE_XFT */
768 if (private->window_type == GDK_WINDOW_FOREIGN)
770 if (!foreign_destroy && (private->parent != NULL))
772 /* It's somebody else's window, but in our heirarchy,
773 * so reparent it to the root window, and then send
774 * it a delete event, as if we were a WM
776 XClientMessageEvent xevent;
778 gdk_error_trap_push ();
779 gdk_window_hide (window);
780 gdk_window_reparent (window, NULL, 0, 0);
782 xevent.type = ClientMessage;
783 xevent.window = GDK_WINDOW_XID (window);
784 xevent.message_type = gdk_x11_get_xatom_by_name ("WM_PROTOCOLS");
786 xevent.data.l[0] = gdk_x11_get_xatom_by_name ("WM_DELETE_WINDOW");
787 xevent.data.l[1] = CurrentTime;
789 XSendEvent (GDK_WINDOW_XDISPLAY (window),
790 GDK_WINDOW_XID (window),
791 False, 0, (XEvent *)&xevent);
793 gdk_error_trap_pop ();
796 else if (!recursing && !foreign_destroy)
797 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
800 /* This function is called when the XWindow is really gone.
803 gdk_window_destroy_notify (GdkWindow *window)
805 GdkWindowImplX11 *window_impl;
807 g_return_if_fail (window != NULL);
809 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
811 if (!GDK_WINDOW_DESTROYED (window))
813 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
814 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
816 _gdk_window_destroy (window, TRUE);
819 gdk_xid_table_remove (GDK_WINDOW_XID (window));
820 if (window_impl->focus_window)
821 gdk_xid_table_remove (window_impl->focus_window);
823 gdk_drawable_unref (window);
827 set_initial_hints (GdkWindow *window)
829 GdkWindowObject *private;
833 private = (GdkWindowObject*) window;
835 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
839 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
840 GDK_WINDOW_XID (window));
842 wm_hints = XAllocWMHints ();
844 wm_hints->flags |= StateHint;
845 wm_hints->initial_state = IconicState;
847 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
848 GDK_WINDOW_XID (window), wm_hints);
852 /* We set the spec hints regardless of whether the spec is supported,
853 * since it can't hurt and it's kind of expensive to check whether
859 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
861 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_VERT");
863 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_HORZ");
867 if (private->state & GDK_WINDOW_STATE_STICKY)
869 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_STICKY");
873 if (private->modal_hint)
875 atoms[i] = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MODAL");
881 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
882 GDK_WINDOW_XID (window),
883 gdk_x11_get_xatom_by_name ("_NET_WM_STATE"),
884 XA_ATOM, 32, PropModeReplace,
888 if (private->state & GDK_WINDOW_STATE_STICKY)
890 atoms[0] = 0xFFFFFFFF;
891 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
892 GDK_WINDOW_XID (window),
893 gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP"),
894 XA_CARDINAL, 32, PropModeReplace,
900 show_window_internal (GdkWindow *window,
903 GdkWindowObject *private;
905 g_return_if_fail (GDK_IS_WINDOW (window));
907 private = (GdkWindowObject*) window;
908 if (!private->destroyed)
911 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
912 GDK_WINDOW_XID (window));
914 if (!GDK_WINDOW_IS_MAPPED (window))
916 set_initial_hints (window);
918 gdk_synthesize_window_state (window,
919 GDK_WINDOW_STATE_WITHDRAWN,
923 g_assert (GDK_WINDOW_IS_MAPPED (window));
925 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
926 XMapWindow (GDK_WINDOW_XDISPLAY (window),
927 GDK_WINDOW_XID (window));
932 * gdk_window_show_unraised:
933 * @window: a #GdkWindow
935 * Shows a #GdkWindow onscreen, but does not modify its stacking
936 * order. In contrast, gdk_window_show() will raise the window
937 * to the top of the window stack.
939 * On the X11 platform, in Xlib terms, this function calls
940 * XMapWindow() (it also updates some internal GDK state, which means
941 * that you can't really use XMapWindow() directly on a GDK window).
945 gdk_window_show_unraised (GdkWindow *window)
947 g_return_if_fail (GDK_IS_WINDOW (window));
949 show_window_internal (window, FALSE);
954 * @window: a #GdkWindow
956 * Like gdk_window_show_unraised(), but also raises the window to the
957 * top of the window stack (moves the window to the front of the
960 * This function maps a window so it's visible onscreen. Its opposite
961 * is gdk_window_hide().
963 * When implementing a #GtkWidget, you should call this function on the widget's
964 * #GdkWindow as part of the "map" method.
968 gdk_window_show (GdkWindow *window)
970 g_return_if_fail (GDK_IS_WINDOW (window));
972 show_window_internal (window, TRUE);
977 * @window: a #GdkWindow
979 * For toplevel windows, withdraws them, so they will no longer be
980 * known to the window manager; for all windows, unmaps them, so
981 * they won't be displayed. Normally done automatically as
982 * part of gtk_widget_hide().
986 gdk_window_hide (GdkWindow *window)
988 GdkWindowObject *private;
990 g_return_if_fail (window != NULL);
992 private = (GdkWindowObject*) window;
994 /* You can't simply unmap toplevel windows. */
995 switch (private->window_type)
997 case GDK_WINDOW_TOPLEVEL:
998 case GDK_WINDOW_DIALOG:
999 case GDK_WINDOW_TEMP: /* ? */
1000 gdk_window_withdraw (window);
1004 case GDK_WINDOW_FOREIGN:
1005 case GDK_WINDOW_ROOT:
1006 case GDK_WINDOW_CHILD:
1010 if (!private->destroyed)
1012 if (GDK_WINDOW_IS_MAPPED (window))
1013 gdk_synthesize_window_state (window,
1015 GDK_WINDOW_STATE_WITHDRAWN);
1017 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1019 _gdk_window_clear_update_area (window);
1021 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1022 GDK_WINDOW_XID (window));
1027 * gdk_window_withdraw:
1028 * @window: a toplevel #GdkWindow
1030 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1031 * Normally done automatically by gtk_widget_hide() called on a #GtkWindow.
1035 gdk_window_withdraw (GdkWindow *window)
1037 GdkWindowObject *private;
1039 g_return_if_fail (window != NULL);
1041 private = (GdkWindowObject*) window;
1042 if (!private->destroyed)
1044 if (GDK_WINDOW_IS_MAPPED (window))
1045 gdk_synthesize_window_state (window,
1047 GDK_WINDOW_STATE_WITHDRAWN);
1049 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1051 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1052 GDK_WINDOW_XID (window), 0);
1058 * @window: a #GdkWindow
1059 * @x: X coordinate relative to window's parent
1060 * @y: Y coordinate relative to window's parent
1062 * Repositions a window relative to its parent window.
1063 * For toplevel windows, window managers may ignore or modify the move;
1064 * you should probably use gtk_window_move() on a #GtkWindow widget
1065 * anyway, instead of using GDK functions. For child windows,
1066 * the move will reliably succeed.
1068 * If you're also planning to resize the window, use gdk_window_move_resize()
1069 * to both move and resize simultaneously, for a nicer visual effect.
1073 gdk_window_move (GdkWindow *window,
1077 GdkWindowObject *private = (GdkWindowObject *)window;
1078 GdkWindowImplX11 *impl;
1080 g_return_if_fail (window != NULL);
1081 g_return_if_fail (GDK_IS_WINDOW (window));
1083 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1085 if (!GDK_WINDOW_DESTROYED (window))
1087 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1088 _gdk_window_move_resize_child (window, x, y,
1089 impl->width, impl->height);
1092 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1093 GDK_WINDOW_XID (window),
1100 * gdk_window_resize:
1101 * @window: a #GdkWindow
1102 * @width: new width of the window
1103 * @height: new height of the window
1105 * Resizes @window; for toplevel windows, asks the window manager to resize
1106 * the window. The window manager may not allow the resize. When using GTK+,
1107 * use gtk_window_resize() instead of this low-level GDK function.
1109 * Windows may not be resized below 1x1.
1111 * If you're also planning to move the window, use gdk_window_move_resize()
1112 * to both move and resize simultaneously, for a nicer visual effect.
1116 gdk_window_resize (GdkWindow *window,
1120 GdkWindowObject *private;
1122 g_return_if_fail (window != NULL);
1123 g_return_if_fail (GDK_IS_WINDOW (window));
1130 private = (GdkWindowObject*) window;
1132 if (!GDK_WINDOW_DESTROYED (window))
1134 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1135 _gdk_window_move_resize_child (window, private->x, private->y,
1139 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1141 if (width != impl->width || height != impl->height)
1142 private->resize_count += 1;
1144 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1145 GDK_WINDOW_XID (window),
1152 * gdk_window_move_resize:
1153 * @window: a #GdkWindow
1154 * @x: new X position relative to window's parent
1155 * @y: new Y position relative to window's parent
1157 * @height: new height
1159 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1160 * except that both operations are performed at once, avoiding strange
1161 * visual effects. (i.e. the user may be able to see the window first
1162 * move, then resize, if youu don't use gdk_window_move_resize().)
1166 gdk_window_move_resize (GdkWindow *window,
1172 GdkWindowObject *private;
1174 g_return_if_fail (window != NULL);
1175 g_return_if_fail (GDK_IS_WINDOW (window));
1182 private = (GdkWindowObject*) window;
1184 if (!GDK_WINDOW_DESTROYED (window))
1186 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1187 _gdk_window_move_resize_child (window, x, y, width, height);
1190 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1192 if (width != impl->width || height != impl->height)
1193 private->resize_count += 1;
1195 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1196 GDK_WINDOW_XID (window),
1197 x, y, width, height);
1203 * gdk_window_reparent:
1204 * @window: a #GdkWindow
1205 * @new_parent: new parent to move @window into
1206 * @x: X location inside the new parent
1207 * @y: Y location inside the new parent
1209 * Reparents @window into the given @new_parent. The window being
1210 * reparented will be unmapped as a side effect.
1214 gdk_window_reparent (GdkWindow *window,
1215 GdkWindow *new_parent,
1219 GdkWindowObject *window_private;
1220 GdkWindowObject *parent_private;
1221 GdkWindowObject *old_parent_private;
1223 g_return_if_fail (window != NULL);
1224 g_return_if_fail (GDK_IS_WINDOW (window));
1225 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1226 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1229 new_parent = _gdk_parent_root;
1231 window_private = (GdkWindowObject*) window;
1232 old_parent_private = (GdkWindowObject*)window_private->parent;
1233 parent_private = (GdkWindowObject*) new_parent;
1235 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1236 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1237 GDK_WINDOW_XID (window),
1238 GDK_WINDOW_XID (new_parent),
1241 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1244 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1245 new_parent = _gdk_parent_root;
1247 window_private->parent = (GdkWindowObject *)new_parent;
1249 /* Switch the window type as appropriate */
1251 switch (GDK_WINDOW_TYPE (new_parent))
1253 case GDK_WINDOW_ROOT:
1254 case GDK_WINDOW_FOREIGN:
1255 /* Now a toplevel */
1256 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1258 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1259 XSetWMProtocols (GDK_WINDOW_XDISPLAY (window),
1260 GDK_WINDOW_XID (window),
1261 _gdk_wm_window_protocols, 3);
1263 case GDK_WINDOW_TOPLEVEL:
1264 case GDK_WINDOW_CHILD:
1265 case GDK_WINDOW_DIALOG:
1266 case GDK_WINDOW_TEMP:
1267 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1268 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1270 /* If we were being sophisticated, we'd save the old window type
1271 * here, and restore it if we were reparented back to the
1272 * toplevel. However, the difference between different types
1273 * of toplevels only really matters on creation anyways.
1275 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1279 if (old_parent_private)
1280 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1282 if ((old_parent_private &&
1283 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1284 (!old_parent_private && parent_private->guffaw_gravity))
1285 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1287 parent_private->children = g_list_prepend (parent_private->children, window);
1288 _gdk_window_init_position (GDK_WINDOW (window_private));
1292 _gdk_windowing_window_clear_area (GdkWindow *window,
1298 g_return_if_fail (window != NULL);
1299 g_return_if_fail (GDK_IS_WINDOW (window));
1301 if (!GDK_WINDOW_DESTROYED (window))
1302 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1303 x, y, width, height, False);
1307 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1313 g_return_if_fail (window != NULL);
1314 g_return_if_fail (GDK_IS_WINDOW (window));
1316 if (!GDK_WINDOW_DESTROYED (window))
1317 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1318 x, y, width, height, True);
1324 * @window: a #GdkWindow
1326 * Raises @window to the top of the Z-order (stacking order), so that
1327 * other windows with the same parent window appear below @window.
1328 * If @window is a toplevel, the window manager may choose to deny the
1329 * request to move the window in the Z-order, gdk_window_raise() only
1330 * requests the restack, does not guarantee it.
1334 gdk_window_raise (GdkWindow *window)
1336 g_return_if_fail (window != NULL);
1337 g_return_if_fail (GDK_IS_WINDOW (window));
1339 if (!GDK_WINDOW_DESTROYED (window))
1340 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1345 * @window: a #GdkWindow
1347 * Lowers @window to the bottom of the Z-order (stacking order), so that
1348 * other windows with the same parent window appear above @window.
1349 * If @window is a toplevel, the window manager may choose to deny the
1350 * request to move the window in the Z-order, gdk_window_lower() only
1351 * requests the restack, does not guarantee it.
1353 * Note that gdk_window_show() raises the window again, so don't call this
1354 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1358 gdk_window_lower (GdkWindow *window)
1360 g_return_if_fail (window != NULL);
1361 g_return_if_fail (GDK_IS_WINDOW (window));
1363 if (!GDK_WINDOW_DESTROYED (window))
1364 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1369 * @window: a #GdkWindow
1370 * @timestamp: timestamp of the event triggering the window focus
1372 * Sets keyboard focus to @window. If @window is not onscreen this
1373 * will not work. In most cases, gtk_window_present() should be used on
1374 * a #GtkWindow, rather than calling this function.
1378 gdk_window_focus (GdkWindow *window,
1381 g_return_if_fail (GDK_IS_WINDOW (window));
1383 if (GDK_WINDOW_DESTROYED (window))
1386 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1390 xev.xclient.type = ClientMessage;
1391 xev.xclient.serial = 0;
1392 xev.xclient.send_event = True;
1393 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1394 xev.xclient.display = gdk_display;
1395 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW");
1396 xev.xclient.format = 32;
1397 xev.xclient.data.l[0] = 0;
1399 XSendEvent (gdk_display, _gdk_root_window, False,
1400 SubstructureRedirectMask | SubstructureNotifyMask,
1405 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1407 /* There is no way of knowing reliably whether we are viewable so we need
1408 * to trap errors so we don't cause a BadMatch.
1410 gdk_error_trap_push ();
1411 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1412 GDK_WINDOW_XWINDOW (window),
1415 XSync (GDK_WINDOW_XDISPLAY (window), False);
1416 gdk_error_trap_pop ();
1421 * gdk_window_set_hints:
1422 * @window: a #GdkWindow
1423 * @x: ignored field, does not matter
1424 * @y: ignored field, does not matter
1425 * @min_width: minimum width hint
1426 * @min_height: minimum height hint
1427 * @max_width: max width hint
1428 * @max_height: max height hint
1429 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1431 * This function is broken and useless and you should ignore it.
1432 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1433 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1434 * depending on what you're trying to do.
1436 * If using GDK directly, use gdk_window_set_geometry_hints().
1440 gdk_window_set_hints (GdkWindow *window,
1449 XSizeHints size_hints;
1451 g_return_if_fail (window != NULL);
1452 g_return_if_fail (GDK_IS_WINDOW (window));
1454 if (GDK_WINDOW_DESTROYED (window))
1457 size_hints.flags = 0;
1459 if (flags & GDK_HINT_POS)
1461 size_hints.flags |= PPosition;
1466 if (flags & GDK_HINT_MIN_SIZE)
1468 size_hints.flags |= PMinSize;
1469 size_hints.min_width = min_width;
1470 size_hints.min_height = min_height;
1473 if (flags & GDK_HINT_MAX_SIZE)
1475 size_hints.flags |= PMaxSize;
1476 size_hints.max_width = max_width;
1477 size_hints.max_height = max_height;
1480 /* FIXME: Would it be better to delete this property if
1481 * flags == 0? It would save space on the server
1483 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1484 GDK_WINDOW_XID (window),
1489 * gdk_window_set_type_hint:
1490 * @window: A #GdkWindow
1491 * @hint: A hint of the function this window will have
1493 * The application can use this call to provide a hint to the window
1494 * manager about the functionality of a window. The window manager
1495 * can use this information when determining the decoration and behaviour
1498 * The hint must be set before the window is mapped.
1501 gdk_window_set_type_hint (GdkWindow *window,
1502 GdkWindowTypeHint hint)
1506 g_return_if_fail (window != NULL);
1507 g_return_if_fail (GDK_IS_WINDOW (window));
1509 if (GDK_WINDOW_DESTROYED (window))
1514 case GDK_WINDOW_TYPE_HINT_DIALOG:
1515 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_DIALOG");
1517 case GDK_WINDOW_TYPE_HINT_MENU:
1518 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_MENU");
1520 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1521 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_TOOLBAR");
1524 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1526 case GDK_WINDOW_TYPE_HINT_NORMAL:
1527 atom = gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE_NORMAL");
1531 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1532 GDK_WINDOW_XID (window),
1533 gdk_x11_get_xatom_by_name ("_NET_WM_WINDOW_TYPE"),
1534 XA_ATOM, 32, PropModeReplace,
1535 (guchar *)&atom, 1);
1540 gdk_wmspec_change_state (gboolean add,
1547 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1548 #define _NET_WM_STATE_ADD 1 /* add/set property */
1549 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1551 xev.xclient.type = ClientMessage;
1552 xev.xclient.serial = 0;
1553 xev.xclient.send_event = True;
1554 xev.xclient.display = gdk_display;
1555 xev.xclient.window = GDK_WINDOW_XID (window);
1556 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_STATE");
1557 xev.xclient.format = 32;
1558 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1559 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom (state1);
1560 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom (state2);
1562 XSendEvent (gdk_display, _gdk_root_window, False,
1563 SubstructureRedirectMask | SubstructureNotifyMask,
1567 * gdk_window_set_modal_hint:
1568 * @window: A #GdkWindow
1569 * @modal: TRUE if the window is modal, FALSE otherwise.
1571 * The application can use this hint to tell the window manager
1572 * that a certain window has modal behaviour. The window manager
1573 * can use this information to handle modal windows in a special
1576 * You should only use this on windows for which you have
1577 * previously called #gdk_window_set_transient_for()
1580 gdk_window_set_modal_hint (GdkWindow *window,
1583 GdkWindowObject *private;
1585 g_return_if_fail (window != NULL);
1586 g_return_if_fail (GDK_IS_WINDOW (window));
1588 if (GDK_WINDOW_DESTROYED (window))
1591 private = (GdkWindowObject*) window;
1593 private->modal_hint = modal;
1595 if (GDK_WINDOW_IS_MAPPED (window))
1596 gdk_wmspec_change_state (modal, window,
1597 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1602 * gdk_window_set_geometry_hints:
1603 * @window: a #GdkWindow
1604 * @geometry: geometry hints
1605 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1607 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1608 * are set, hints not flagged in @geom_mask are unset.
1609 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1613 gdk_window_set_geometry_hints (GdkWindow *window,
1614 GdkGeometry *geometry,
1615 GdkWindowHints geom_mask)
1617 XSizeHints size_hints;
1619 g_return_if_fail (window != NULL);
1620 g_return_if_fail (GDK_IS_WINDOW (window));
1622 if (GDK_WINDOW_DESTROYED (window))
1625 size_hints.flags = 0;
1627 if (geom_mask & GDK_HINT_POS)
1629 size_hints.flags |= PPosition;
1630 /* We need to initialize the following obsolete fields because KWM
1631 * apparently uses these fields if they are non-zero.
1638 if (geom_mask & GDK_HINT_USER_POS)
1640 size_hints.flags |= USPosition;
1643 if (geom_mask & GDK_HINT_USER_SIZE)
1645 size_hints.flags |= USSize;
1648 if (geom_mask & GDK_HINT_MIN_SIZE)
1650 size_hints.flags |= PMinSize;
1651 size_hints.min_width = geometry->min_width;
1652 size_hints.min_height = geometry->min_height;
1655 if (geom_mask & GDK_HINT_MAX_SIZE)
1657 size_hints.flags |= PMaxSize;
1658 size_hints.max_width = MAX (geometry->max_width, 1);
1659 size_hints.max_height = MAX (geometry->max_height, 1);
1662 if (geom_mask & GDK_HINT_BASE_SIZE)
1664 size_hints.flags |= PBaseSize;
1665 size_hints.base_width = geometry->base_width;
1666 size_hints.base_height = geometry->base_height;
1669 if (geom_mask & GDK_HINT_RESIZE_INC)
1671 size_hints.flags |= PResizeInc;
1672 size_hints.width_inc = geometry->width_inc;
1673 size_hints.height_inc = geometry->height_inc;
1676 if (geom_mask & GDK_HINT_ASPECT)
1678 size_hints.flags |= PAspect;
1679 if (geometry->min_aspect <= 1)
1681 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1682 size_hints.min_aspect.y = 65536;
1686 size_hints.min_aspect.x = 65536;
1687 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1689 if (geometry->max_aspect <= 1)
1691 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1692 size_hints.max_aspect.y = 65536;
1696 size_hints.max_aspect.x = 65536;
1697 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1701 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1703 size_hints.flags |= PWinGravity;
1704 size_hints.win_gravity = geometry->win_gravity;
1707 /* FIXME: Would it be better to delete this property if
1708 * geom_mask == 0? It would save space on the server
1710 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1711 GDK_WINDOW_XID (window),
1716 gdk_window_get_geometry_hints (GdkWindow *window,
1717 GdkGeometry *geometry,
1718 GdkWindowHints *geom_mask)
1720 XSizeHints size_hints;
1721 glong junk_size_mask = 0;
1723 g_return_if_fail (GDK_IS_WINDOW (window));
1724 g_return_if_fail (geometry != NULL);
1725 g_return_if_fail (geom_mask != NULL);
1729 if (GDK_WINDOW_DESTROYED (window))
1732 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1733 GDK_WINDOW_XID (window),
1738 if (size_hints.flags & PMinSize)
1740 *geom_mask |= GDK_HINT_MIN_SIZE;
1741 geometry->min_width = size_hints.min_width;
1742 geometry->min_height = size_hints.min_height;
1745 if (size_hints.flags & PMaxSize)
1747 *geom_mask |= GDK_HINT_MAX_SIZE;
1748 geometry->max_width = MAX (size_hints.max_width, 1);
1749 geometry->max_height = MAX (size_hints.max_height, 1);
1752 if (size_hints.flags & PResizeInc)
1754 *geom_mask |= GDK_HINT_RESIZE_INC;
1755 geometry->width_inc = size_hints.width_inc;
1756 geometry->height_inc = size_hints.height_inc;
1759 if (size_hints.flags & PAspect)
1761 *geom_mask |= GDK_HINT_ASPECT;
1763 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1764 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1767 if (size_hints.flags & PWinGravity)
1769 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1770 geometry->win_gravity = size_hints.win_gravity;
1775 utf8_is_latin1 (const gchar *str)
1777 const char *p = str;
1781 gunichar ch = g_utf8_get_char (p);
1786 p = g_utf8_next_char (p);
1792 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
1793 * convertable to STRING, otherwise, set it as compound text
1796 set_text_property (GdkWindow *window,
1798 const gchar *utf8_str)
1800 guchar *prop_text = NULL;
1805 if (utf8_is_latin1 (utf8_str))
1807 prop_type = XA_STRING;
1808 prop_text = gdk_utf8_to_string_target (utf8_str);
1809 prop_length = strlen (prop_text);
1816 gdk_utf8_to_compound_text (utf8_str, &gdk_type, &prop_format,
1817 &prop_text, &prop_length);
1818 prop_type = gdk_x11_atom_to_xatom (gdk_type);
1823 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1824 GDK_WINDOW_XID (window),
1826 prop_type, prop_format,
1827 PropModeReplace, prop_text,
1835 * gdk_window_set_title:
1836 * @window: a #GdkWindow
1837 * @title: title of @window
1839 * Sets the title of a toplevel window, to be displayed in the titlebar.
1840 * If you haven't explicitly set the icon name for the window
1841 * (using gdk_window_set_icon_name()), the icon name will be set to
1842 * @title as well. @title must be in UTF-8 encoding (as with all
1843 * user-readable strings in GDK/GTK+). @title may not be %NULL.
1847 gdk_window_set_title (GdkWindow *window,
1850 g_return_if_fail (window != NULL);
1851 g_return_if_fail (GDK_IS_WINDOW (window));
1852 g_return_if_fail (title != NULL);
1854 if (GDK_WINDOW_DESTROYED (window))
1857 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1858 GDK_WINDOW_XID (window),
1859 gdk_x11_get_xatom_by_name ("_NET_WM_NAME"),
1860 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
1861 PropModeReplace, title,
1864 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_NAME"), title);
1865 if (!gdk_window_icon_name_set (window))
1867 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1868 GDK_WINDOW_XID (window),
1869 gdk_x11_get_xatom_by_name ("_NET_WM_ICON_NAME"),
1870 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
1871 PropModeReplace, title,
1873 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_ICON_NAME"), title);
1878 * gdk_window_set_role:
1879 * @window: a #GdkWindow
1880 * @role: a string indicating its role
1882 * When using GTK+, typically you should use gtk_window_set_role() instead
1883 * of this low-level function.
1885 * The window manager and session manager use a window's role to
1886 * distinguish it from other kinds of window in the same application.
1887 * When an application is restarted after being saved in a previous
1888 * session, all windows with the same title and role are treated as
1889 * interchangeable. So if you have two windows with the same title
1890 * that should be distinguished for session management purposes, you
1891 * should set the role on those windows. It doesn't matter what string
1892 * you use for the role, as long as you have a different role for each
1893 * non-interchangeable kind of window.
1897 gdk_window_set_role (GdkWindow *window,
1900 g_return_if_fail (window != NULL);
1901 g_return_if_fail (GDK_IS_WINDOW (window));
1903 if (!GDK_WINDOW_DESTROYED (window))
1906 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1907 gdk_x11_get_xatom_by_name ("WM_WINDOW_ROLE"), XA_STRING,
1908 8, PropModeReplace, role, strlen (role));
1910 XDeleteProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1911 gdk_x11_get_xatom_by_name ("WM_WINDOW_ROLE"));
1916 * gdk_window_set_transient_for:
1917 * @window: a toplevel #GdkWindow
1918 * @parent: another toplevel #GdkWindow
1920 * Indicates to the window manager that @window is a transient dialog
1921 * associated with the application window @parent. This allows the
1922 * window manager to do things like center @window on @parent and
1923 * keep @window above @parent.
1925 * See gtk_window_set_transient_for() if you're using #GtkWindow or
1930 gdk_window_set_transient_for (GdkWindow *window,
1933 GdkWindowObject *private;
1934 GdkWindowObject *parent_private;
1936 g_return_if_fail (window != NULL);
1937 g_return_if_fail (GDK_IS_WINDOW (window));
1939 private = (GdkWindowObject*) window;
1940 parent_private = (GdkWindowObject*) parent;
1942 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
1943 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
1944 GDK_WINDOW_XID (window),
1945 GDK_WINDOW_XID (parent));
1949 * gdk_window_set_background:
1950 * @window: a #GdkWindow
1951 * @color: an allocated #GdkColor
1953 * Sets the background color of @window. (However, when using GTK+,
1954 * set the background of a widget with gtk_widget_modify_bg() - if
1955 * you're an application - or gtk_style_set_background() - if you're
1956 * implementing a custom widget.)
1958 * The @color must be allocated; gdk_rgb_find_color() is the best way
1959 * to allocate a color.
1961 * See also gdk_window_set_back_pixmap().
1965 gdk_window_set_background (GdkWindow *window,
1968 GdkWindowObject *private = (GdkWindowObject *)window;
1970 g_return_if_fail (window != NULL);
1971 g_return_if_fail (GDK_IS_WINDOW (window));
1973 if (!GDK_WINDOW_DESTROYED (window))
1974 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
1975 GDK_WINDOW_XID (window), color->pixel);
1977 private->bg_color = *color;
1979 if (private->bg_pixmap &&
1980 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1981 private->bg_pixmap != GDK_NO_BG)
1982 gdk_pixmap_unref (private->bg_pixmap);
1984 private->bg_pixmap = NULL;
1988 * gdk_window_set_back_pixmap:
1989 * @window: a #GdkWindow
1990 * @pixmap: a #GdkPixmap, or %NULL
1991 * @parent_relative: whether the tiling origin is at the origin of @window's parent
1993 * Sets the background pixmap of @window. May also be used to set a background of
1994 * "None" on @window, by setting a background pixmap of %NULL.
1995 * A background pixmap will be tiled, positioning the first tile at the origin of
1996 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
1997 * origin of the parent window (useful to align tiles in a parent with tiles
2000 * A background pixmap of %NULL means that the window will have no
2001 * background. A window with no background will never have its
2002 * background filled by the windowing system, instead the window will
2003 * contain whatever pixels were already in the corresponding area of
2006 * The windowing system will normally fill a window with its background
2007 * when the window is obscured then exposed, and when you call
2008 * gdk_window_clear().
2012 gdk_window_set_back_pixmap (GdkWindow *window,
2014 gboolean parent_relative)
2016 GdkWindowObject *private = (GdkWindowObject *)window;
2019 g_return_if_fail (window != NULL);
2020 g_return_if_fail (GDK_IS_WINDOW (window));
2021 g_return_if_fail (pixmap == NULL || !parent_relative);
2023 if (private->bg_pixmap &&
2024 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2025 private->bg_pixmap != GDK_NO_BG)
2026 gdk_pixmap_unref (private->bg_pixmap);
2028 if (parent_relative)
2030 xpixmap = ParentRelative;
2031 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2037 gdk_pixmap_ref (pixmap);
2038 private->bg_pixmap = pixmap;
2039 xpixmap = GDK_PIXMAP_XID (pixmap);
2044 private->bg_pixmap = GDK_NO_BG;
2048 if (!GDK_WINDOW_DESTROYED (window))
2049 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2050 GDK_WINDOW_XID (window), xpixmap);
2054 * gdk_window_set_cursor:
2055 * @window: a #GdkWindow
2058 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2059 * gdk_cursor_new_from_pixmap() to create the cursor.
2060 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2061 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2062 * to gdk_window_set_cursor() means that @window will use the cursor of
2063 * its parent window. Most windows should use this default.
2067 gdk_window_set_cursor (GdkWindow *window,
2070 GdkCursorPrivate *cursor_private;
2073 g_return_if_fail (window != NULL);
2074 g_return_if_fail (GDK_IS_WINDOW (window));
2076 cursor_private = (GdkCursorPrivate*) cursor;
2081 xcursor = cursor_private->xcursor;
2083 if (!GDK_WINDOW_DESTROYED (window))
2084 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2085 GDK_WINDOW_XID (window),
2090 * gdk_window_get_geometry:
2091 * @window: a #GdkWindow
2092 * @x: return location for X coordinate of window (relative to its parent)
2093 * @y: return location for Y coordinate of window (relative to its parent)
2094 * @width: return location for width of window
2095 * @height: return location for height of window
2096 * @depth: return location for bit depth of window
2098 * Any of the return location arguments to this function may be %NULL,
2099 * if you aren't interested in getting the value of that field.
2101 * The X and Y coordinates returned are relative to the parent window
2102 * of @window, which for toplevels usually means relative to the
2103 * window decorations (titlebar, etc.) rather than relative to the
2104 * root window (screen-size background window).
2106 * On the X11 platform, the geometry is obtained from the X server,
2107 * so reflects the latest position of @window; this may be out-of-sync
2108 * with the position of @window delivered in the most-recently-processed
2109 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2110 * position from the most recent configure event.
2114 gdk_window_get_geometry (GdkWindow *window,
2126 guint tborder_width;
2129 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2132 window = _gdk_parent_root;
2134 if (!GDK_WINDOW_DESTROYED (window))
2136 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2137 GDK_WINDOW_XID (window),
2138 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2154 * gdk_window_get_origin:
2155 * @window: a #GdkWindow
2156 * @x: return location for X coordinate
2157 * @y: return location for Y coordinate
2159 * Obtains the position of a window in root window coordinates.
2160 * (Compare with gdk_window_get_position() and
2161 * gdk_window_get_geometry() which return the position of a window
2162 * relative to its parent window.)
2164 * Return value: not meaningful, ignore
2167 gdk_window_get_origin (GdkWindow *window,
2176 g_return_val_if_fail (window != NULL, 0);
2178 if (!GDK_WINDOW_DESTROYED (window))
2180 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2181 GDK_WINDOW_XID (window),
2199 * gdk_window_get_deskrelative_origin:
2200 * @window: a #GdkWindow
2201 * @x: return location for X coordinate
2202 * @y: return location for Y coordinate
2204 * This gets the origin of a #GdkWindow relative to
2205 * an Enlightenment-window-manager desktop. As long as you don't
2206 * assume that the user's desktop/workspace covers the entire
2207 * root window (i.e. you don't assume that the desktop begins
2208 * at root window coordinate 0,0) this function is not necessary.
2209 * It's deprecated for that reason.
2211 * Return value: not meaningful
2214 gdk_window_get_deskrelative_origin (GdkWindow *window,
2218 gboolean return_val = FALSE;
2219 gint num_children, format_return;
2220 Window win, *child, parent, root;
2224 static Atom atom = 0;
2225 gulong number_return, bytes_after_return;
2226 guchar *data_return;
2228 g_return_val_if_fail (window != NULL, 0);
2229 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2231 if (!GDK_WINDOW_DESTROYED (window))
2234 atom = gdk_x11_get_xatom_by_name ("ENLIGHTENMENT_DESKTOP");
2235 win = GDK_WINDOW_XID (window);
2237 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2238 &child, (unsigned int *)&num_children))
2240 if ((child) && (num_children > 0))
2252 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2253 False, XA_CARDINAL, &type_return, &format_return,
2254 &number_return, &bytes_after_return, &data_return);
2255 if (type_return == XA_CARDINAL)
2257 XFree (data_return);
2262 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2263 GDK_WINDOW_XID (window),
2278 * gdk_window_get_root_origin:
2279 * @window: a #GdkWindow
2280 * @x: return location for X position of window frame
2281 * @y: return location for Y position of window frame
2283 * Obtains the top-left corner of the window manager frame in root
2284 * window coordinates.
2288 gdk_window_get_root_origin (GdkWindow *window,
2294 g_return_if_fail (GDK_IS_WINDOW (window));
2296 gdk_window_get_frame_extents (window, &rect);
2306 * gdk_window_get_frame_extents:
2307 * @window: a #GdkWindow
2308 * @rect: rectangle to fill with bounding box of the window frame
2310 * Obtains the bounding box of the window, including window manager
2311 * titlebar/borders if any. The frame position is given in root window
2312 * coordinates. To get the position of the window itself (rather than
2313 * the frame) in root window coordinates, use gdk_window_get_origin().
2317 gdk_window_get_frame_extents (GdkWindow *window,
2320 GdkWindowObject *private;
2325 unsigned int nchildren;
2327 g_return_if_fail (GDK_IS_WINDOW (window));
2328 g_return_if_fail (rect != NULL);
2330 private = (GdkWindowObject*) window;
2337 if (GDK_WINDOW_DESTROYED (window))
2340 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2341 private = (GdkWindowObject*) private->parent;
2342 if (GDK_WINDOW_DESTROYED (window))
2345 xparent = GDK_WINDOW_XID (window);
2349 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2351 &children, &nchildren))
2357 while (xparent != root);
2359 if (xparent == root)
2361 unsigned int ww, wh, wb, wd;
2364 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2375 _gdk_windowing_window_get_pointer (GdkWindow *window,
2378 GdkModifierType *mask)
2380 GdkWindow *return_val;
2386 unsigned int xmask = 0;
2387 gint xoffset, yoffset;
2389 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2392 window = _gdk_parent_root;
2394 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2397 if (!GDK_WINDOW_DESTROYED (window) &&
2398 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2399 GDK_WINDOW_XID (window),
2400 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2403 return_val = gdk_window_lookup (child);
2407 *x = winx + xoffset;
2409 *y = winy + yoffset;
2417 _gdk_windowing_window_at_pointer (GdkScreen *screen,
2424 Window xwindow_last = 0;
2426 int rootx = -1, rooty = -1;
2430 xwindow = GDK_ROOT_WINDOW ();
2431 xdisplay = GDK_DISPLAY ();
2433 gdk_x11_grab_server ();
2436 xwindow_last = xwindow;
2437 XQueryPointer (xdisplay, xwindow,
2443 gdk_x11_ungrab_server ();
2445 window = gdk_window_lookup (xwindow_last);
2448 *win_x = window ? winx : -1;
2450 *win_y = window ? winy : -1;
2456 * gdk_window_get_events:
2457 * @window: a #GdkWindow
2459 * Gets the event mask for @window. See gdk_window_set_events().
2461 * Return value: event mask for @window
2464 gdk_window_get_events (GdkWindow *window)
2466 XWindowAttributes attrs;
2467 GdkEventMask event_mask;
2469 g_return_val_if_fail (window != NULL, 0);
2470 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2472 if (GDK_WINDOW_DESTROYED (window))
2476 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2477 GDK_WINDOW_XID (window),
2480 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2481 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2488 * gdk_window_set_events:
2489 * @window: a #GdkWindow
2490 * @event_mask: event mask for @window
2492 * The event mask for a window determines which events will be reported
2493 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2494 * means the window should report button press events. The event mask
2495 * is the bitwise OR of values from the #GdkEventMask enumeration.
2499 gdk_window_set_events (GdkWindow *window,
2500 GdkEventMask event_mask)
2505 g_return_if_fail (window != NULL);
2506 g_return_if_fail (GDK_IS_WINDOW (window));
2508 if (!GDK_WINDOW_DESTROYED (window))
2510 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2511 xevent_mask = StructureNotifyMask;
2512 for (i = 0; i < _gdk_nenvent_masks; i++)
2514 if (event_mask & (1 << (i + 1)))
2515 xevent_mask |= _gdk_event_mask_table[i];
2518 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2519 GDK_WINDOW_XID (window),
2525 gdk_window_add_colormap_windows (GdkWindow *window)
2527 GdkWindow *toplevel;
2528 Window *old_windows;
2529 Window *new_windows;
2532 g_return_if_fail (window != NULL);
2533 g_return_if_fail (GDK_IS_WINDOW (window));
2535 toplevel = gdk_window_get_toplevel (window);
2536 if (GDK_WINDOW_DESTROYED (toplevel))
2540 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2541 GDK_WINDOW_XID (toplevel),
2542 &old_windows, &count))
2547 for (i = 0; i < count; i++)
2548 if (old_windows[i] == GDK_WINDOW_XID (window))
2550 XFree (old_windows);
2554 new_windows = g_new (Window, count + 1);
2556 for (i = 0; i < count; i++)
2557 new_windows[i] = old_windows[i];
2558 new_windows[count] = GDK_WINDOW_XID (window);
2560 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2561 GDK_WINDOW_XID (toplevel),
2562 new_windows, count + 1);
2564 g_free (new_windows);
2566 XFree (old_windows);
2570 gdk_window_have_shape_ext (void)
2572 enum { UNKNOWN, NO, YES };
2573 static gint have_shape = UNKNOWN;
2575 if (have_shape == UNKNOWN)
2578 if (XQueryExtension (gdk_display, "SHAPE", &ignore, &ignore, &ignore))
2584 return (have_shape == YES);
2587 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2590 * This needs the X11 shape extension.
2591 * If not available, shaped windows will look
2592 * ugly, but programs still work. Stefan Wille
2595 * gdk_window_shape_combine_mask:
2596 * @window: a #GdkWindow
2598 * @x: X position of shape mask with respect to @window
2599 * @y: Y position of shape mask with respect to @window
2601 * Applies a shape mask to @window. Pixels in @window corresponding to
2602 * set bits in the @mask will be visible; pixels in @window
2603 * corresponding to unset bits in the @mask will be transparent. This
2604 * gives a non-rectangular window.
2606 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
2607 * parameters are not used.
2609 * On the X11 platform, this uses an X server extension which is
2610 * widely available on most common platforms, but not available on
2611 * very old X servers, and occasionally the implementation will be
2612 * buggy. On servers without the shape extension, this function
2617 gdk_window_shape_combine_mask (GdkWindow *window,
2622 gint xoffset, yoffset;
2624 g_return_if_fail (window != NULL);
2625 g_return_if_fail (GDK_IS_WINDOW (window));
2627 #ifdef HAVE_SHAPE_EXT
2628 if (GDK_WINDOW_DESTROYED (window))
2631 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2633 if (xoffset != 0 || yoffset != 0)
2635 WARN_SHAPE_TOO_BIG ();
2639 if (gdk_window_have_shape_ext ())
2643 pixmap = GDK_PIXMAP_XID (mask);
2652 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2653 GDK_WINDOW_XID (window),
2659 #endif /* HAVE_SHAPE_EXT */
2663 * gdk_window_shape_combine_region:
2664 * @window: a #GdkWindow
2665 * @shape_region: region of window to be non-transparent
2666 * @offset_x: X position of @shape_region in @window coordinates
2667 * @offset_y: Y position of @shape_region in @window coordinates
2669 * Makes pixels in @window outside @shape_region be transparent,
2670 * so that the window may be nonrectangular. See also
2671 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
2673 * If @shape_region is %NULL, the shape will be unset, so the whole
2674 * window will be opaque again. @offset_x and @offset_y are ignored
2675 * if @shape_region is %NULL.
2677 * On the X11 platform, this uses an X server extension which is
2678 * widely available on most common platforms, but not available on
2679 * very old X servers, and occasionally the implementation will be
2680 * buggy. On servers without the shape extension, this function
2685 gdk_window_shape_combine_region (GdkWindow *window,
2686 GdkRegion *shape_region,
2690 gint xoffset, yoffset;
2692 g_return_if_fail (GDK_IS_WINDOW (window));
2694 #ifdef HAVE_SHAPE_EXT
2695 if (GDK_WINDOW_DESTROYED (window))
2698 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2700 if (xoffset != 0 || yoffset != 0)
2702 WARN_SHAPE_TOO_BIG ();
2706 if (shape_region == NULL)
2708 /* Use NULL mask to unset the shape */
2709 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2713 if (gdk_window_have_shape_ext ())
2716 XRectangle *xrects = NULL;
2718 _gdk_region_get_xrectangles (shape_region,
2722 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2723 GDK_WINDOW_XID (window),
2732 #endif /* HAVE_SHAPE_EXT */
2737 * gdk_window_set_override_redirect:
2738 * @window: a #GdkWindow
2739 * @override_redirect: %TRUE if window should be override redirect
2741 * An override redirect window is not under the control of the window manager.
2742 * This means it won't have a titlebar, won't be minimizable, etc. - it will
2743 * be entirely under the control of the application. The window manager
2744 * can't see the override redirect window at all.
2746 * Override redirect should only be used for short-lived temporary
2747 * windows, such as popup menus. #GtkMenu uses an override redirect
2748 * window in its implementation, for example.
2752 gdk_window_set_override_redirect (GdkWindow *window,
2753 gboolean override_redirect)
2755 XSetWindowAttributes attr;
2757 g_return_if_fail (window != NULL);
2758 g_return_if_fail (GDK_IS_WINDOW (window));
2760 if (GDK_WINDOW_DESTROYED (window))
2762 attr.override_redirect = (override_redirect == FALSE)?False:True;
2763 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2764 GDK_WINDOW_XID (window),
2772 * gdk_window_set_icon_list:
2773 * @window: The #GdkWindow toplevel window to set the icon of.
2774 * @pixbufs: A list of pixbufs, of different sizes.
2776 * Sets a list of icons for the window. One of these will be used
2777 * to represent the window when it has been iconified. The icon is
2778 * usually shown in an icon box or some sort of task bar. Which icon
2779 * size is shown depends on the window manager. The window manager
2780 * can scale the icon but setting several size icons can give better
2781 * image quality since the window manager may only need to scale the
2782 * icon by a small amount or not at all.
2786 gdk_window_set_icon_list (GdkWindow *window,
2795 gint width, height, stride;
2799 g_return_if_fail (GDK_IS_WINDOW (window));
2801 if (GDK_WINDOW_DESTROYED (window))
2810 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
2812 width = gdk_pixbuf_get_width (pixbuf);
2813 height = gdk_pixbuf_get_height (pixbuf);
2815 size += 2 + width * height;
2817 l = g_list_next (l);
2820 data = g_malloc (size * sizeof (gulong));
2828 width = gdk_pixbuf_get_width (pixbuf);
2829 height = gdk_pixbuf_get_height (pixbuf);
2830 stride = gdk_pixbuf_get_rowstride (pixbuf);
2831 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
2836 pixels = gdk_pixbuf_get_pixels (pixbuf);
2838 for (y = 0; y < height; y++)
2840 for (x = 0; x < width; x++)
2844 r = pixels[y*stride + x*n_channels + 0];
2845 g = pixels[y*stride + x*n_channels + 1];
2846 b = pixels[y*stride + x*n_channels + 2];
2847 if (n_channels >= 4)
2848 a = pixels[y*stride + x*n_channels + 3];
2852 *p++ = a << 24 | r << 16 | g << 8 | b ;
2856 l = g_list_next (l);
2861 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2862 GDK_WINDOW_XID (window),
2863 gdk_x11_get_xatom_by_name ("_NET_WM_ICON"),
2866 (guchar*) data, size);
2870 XDeleteProperty (GDK_WINDOW_XDISPLAY (window),
2871 GDK_WINDOW_XID (window),
2872 gdk_x11_get_xatom_by_name ("_NET_WM_ICON"));
2879 * gdk_window_set_icon:
2880 * @window: a #GdkWindow
2881 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
2882 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
2883 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
2885 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
2886 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
2887 * and gtk_window_set_icon(). If those don't meet your needs, look at
2888 * gdk_window_set_icon_list(). Only if all those are too high-level do you
2889 * want to fall back to gdk_window_set_icon().
2893 gdk_window_set_icon (GdkWindow *window,
2894 GdkWindow *icon_window,
2900 g_return_if_fail (window != NULL);
2901 g_return_if_fail (GDK_IS_WINDOW (window));
2903 if (GDK_WINDOW_DESTROYED (window))
2906 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
2907 GDK_WINDOW_XID (window));
2909 wm_hints = XAllocWMHints ();
2911 if (icon_window != NULL)
2913 wm_hints->flags |= IconWindowHint;
2914 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
2919 wm_hints->flags |= IconPixmapHint;
2920 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
2925 wm_hints->flags |= IconMaskHint;
2926 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
2929 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
2930 GDK_WINDOW_XID (window), wm_hints);
2935 gdk_window_icon_name_set (GdkWindow *window)
2937 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
2938 g_quark_from_static_string ("gdk-icon-name-set")));
2942 * gdk_window_set_icon_name:
2943 * @window: a #GdkWindow
2944 * @name: name of window while iconified (minimized)
2946 * Windows may have a name used while minimized, distinct from the
2947 * name they display in their titlebar. Most of the time this is a bad
2948 * idea from a user interface standpoint. But you can set such a name
2949 * with this function, if you like.
2953 gdk_window_set_icon_name (GdkWindow *window,
2956 g_return_if_fail (window != NULL);
2957 g_return_if_fail (GDK_IS_WINDOW (window));
2959 if (GDK_WINDOW_DESTROYED (window))
2962 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
2963 GUINT_TO_POINTER (TRUE));
2965 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2966 GDK_WINDOW_XID (window),
2967 gdk_x11_get_xatom_by_name ("_NET_WM_ICON_NAME"),
2968 gdk_x11_get_xatom_by_name ("UTF8_STRING"), 8,
2969 PropModeReplace, name,
2971 set_text_property (window, gdk_x11_get_xatom_by_name ("WM_ICON_NAME"), name);
2975 * gdk_window_iconify:
2976 * @window: a #GdkWindow
2978 * Asks to iconify (minimize) @window. The window manager may choose
2979 * to ignore the request, but normally will honor it. Using
2980 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
2984 gdk_window_iconify (GdkWindow *window)
2987 GdkWindowObject *private;
2989 g_return_if_fail (window != NULL);
2990 g_return_if_fail (GDK_IS_WINDOW (window));
2992 if (GDK_WINDOW_DESTROYED (window))
2995 display = GDK_WINDOW_XDISPLAY (window);
2997 private = (GdkWindowObject*) window;
2999 if (GDK_WINDOW_IS_MAPPED (window))
3001 XIconifyWindow (display, GDK_WINDOW_XWINDOW (window), DefaultScreen (display));
3006 /* Flip our client side flag, the real work happens on map. */
3007 gdk_synthesize_window_state (window,
3009 GDK_WINDOW_STATE_ICONIFIED);
3014 * gdk_window_deiconify:
3015 * @window: a #GdkWindow
3017 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3018 * choose to ignore the request to deiconify. When using GTK+,
3019 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3020 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3021 * unminimizes it, and puts it on the current desktop.
3025 gdk_window_deiconify (GdkWindow *window)
3028 GdkWindowObject *private;
3030 g_return_if_fail (window != NULL);
3031 g_return_if_fail (GDK_IS_WINDOW (window));
3033 if (GDK_WINDOW_DESTROYED (window))
3036 display = GDK_WINDOW_XDISPLAY (window);
3038 private = (GdkWindowObject*) window;
3040 if (GDK_WINDOW_IS_MAPPED (window))
3042 gdk_window_show (window);
3046 /* Flip our client side flag, the real work happens on map. */
3047 gdk_synthesize_window_state (window,
3048 GDK_WINDOW_STATE_ICONIFIED,
3055 * @window: a toplevel #GdkWindow
3057 * "Pins" a window such that it's on all workspaces and does not scroll
3058 * with viewports, for window managers that have scrollable viewports.
3059 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3061 * On the X11 platform, this function depends on window manager
3062 * support, so may have no effect with many window managers. However,
3063 * GDK will do the best it can to convince the window manager to stick
3064 * the window. For window managers that don't support this operation,
3065 * there's nothing you can do to force it to happen.
3069 gdk_window_stick (GdkWindow *window)
3071 g_return_if_fail (GDK_IS_WINDOW (window));
3073 if (GDK_WINDOW_DESTROYED (window))
3076 if (GDK_WINDOW_IS_MAPPED (window))
3078 /* "stick" means stick to all desktops _and_ do not scroll with the
3079 * viewport. i.e. glue to the monitor glass in all cases.
3084 /* Request stick during viewport scroll */
3085 gdk_wmspec_change_state (TRUE, window,
3086 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3089 /* Request desktop 0xFFFFFFFF */
3090 xev.xclient.type = ClientMessage;
3091 xev.xclient.serial = 0;
3092 xev.xclient.send_event = True;
3093 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3094 xev.xclient.display = gdk_display;
3095 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
3096 xev.xclient.format = 32;
3098 xev.xclient.data.l[0] = 0xFFFFFFFF;
3100 XSendEvent (gdk_display, _gdk_root_window, False,
3101 SubstructureRedirectMask | SubstructureNotifyMask,
3106 /* Flip our client side flag, the real work happens on map. */
3107 gdk_synthesize_window_state (window,
3109 GDK_WINDOW_STATE_STICKY);
3114 * gdk_window_unstick:
3115 * @window: a toplevel #GdkWindow
3117 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3118 * and gtk_window_unstick().
3122 gdk_window_unstick (GdkWindow *window)
3124 g_return_if_fail (GDK_IS_WINDOW (window));
3126 if (GDK_WINDOW_DESTROYED (window))
3129 if (GDK_WINDOW_IS_MAPPED (window))
3136 gulong *current_desktop;
3138 /* Request unstick from viewport */
3139 gdk_wmspec_change_state (FALSE, window,
3140 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3143 /* Get current desktop, then set it; this is a race, but not
3144 * one that matters much in practice.
3146 XGetWindowProperty (gdk_display, _gdk_root_window,
3147 gdk_x11_get_xatom_by_name ("_NET_CURRENT_DESKTOP"),
3149 False, XA_CARDINAL, &type, &format, &nitems,
3150 &bytes_after, (guchar **)¤t_desktop);
3152 if (type == XA_CARDINAL)
3154 xev.xclient.type = ClientMessage;
3155 xev.xclient.serial = 0;
3156 xev.xclient.send_event = True;
3157 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3158 xev.xclient.display = gdk_display;
3159 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
3160 xev.xclient.format = 32;
3162 xev.xclient.data.l[0] = *current_desktop;
3164 XSendEvent (gdk_display, _gdk_root_window, False,
3165 SubstructureRedirectMask | SubstructureNotifyMask,
3168 XFree (current_desktop);
3173 /* Flip our client side flag, the real work happens on map. */
3174 gdk_synthesize_window_state (window,
3175 GDK_WINDOW_STATE_STICKY,
3182 * gdk_window_maximize:
3183 * @window: a #GdkWindow
3185 * Asks the window manager to maximize @window, if the window manager supports
3186 * this operation. Not all window managers support this, and some deliberately
3187 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3188 * maximization actually happening. But it will happen with most standard
3189 * window managers, and GDK makes a best effort to get it to happen.
3191 * If the window was already maximized, then this function does nothing.
3195 gdk_window_maximize (GdkWindow *window)
3197 g_return_if_fail (GDK_IS_WINDOW (window));
3199 if (GDK_WINDOW_DESTROYED (window))
3202 if (GDK_WINDOW_IS_MAPPED (window))
3203 gdk_wmspec_change_state (TRUE, window,
3204 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3205 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3207 gdk_synthesize_window_state (window,
3209 GDK_WINDOW_STATE_MAXIMIZED);
3213 * gdk_window_unmaximize:
3214 * @window: a #GdkWindow
3216 * Asks the window manager to unmaximize @window, if the window manager supports
3217 * this operation. Not all window managers support this, and some deliberately
3218 * ignore it or don't have a concept of "maximized"; so you can't rely on the
3219 * unmaximization actually happening. But it will happen with most standard
3220 * window managers, and GDK makes a best effort to get it to happen.
3222 * If the window wasn't maximized, then this function does nothing.
3226 gdk_window_unmaximize (GdkWindow *window)
3228 g_return_if_fail (GDK_IS_WINDOW (window));
3230 if (GDK_WINDOW_DESTROYED (window))
3233 if (GDK_WINDOW_IS_MAPPED (window))
3234 gdk_wmspec_change_state (FALSE, window,
3235 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3236 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3238 gdk_synthesize_window_state (window,
3239 GDK_WINDOW_STATE_MAXIMIZED,
3244 * gdk_window_set_group:
3245 * @window: a #GdkWindow
3246 * @leader: group leader window
3248 * Sets the group leader window for @window. By default,
3249 * GDK sets the group leader for all toplevel windows
3250 * to a global window implicitly created by GDK. With this function
3251 * you can override this default.
3253 * The group leader window allows the window manager to distinguish
3254 * all windows that belong to a single application. It may for example
3255 * allow users to minimize/unminimize all windows belonging to an
3256 * application at once. You should only set a non-default group window
3257 * if your application pretends to be multiple applications.
3258 * The group leader window may not be changed after a window has been
3259 * mapped (with gdk_window_show() for example).
3263 gdk_window_set_group (GdkWindow *window,
3268 g_return_if_fail (window != NULL);
3269 g_return_if_fail (GDK_IS_WINDOW (window));
3270 g_return_if_fail (leader != NULL);
3271 g_return_if_fail (GDK_IS_WINDOW (leader));
3273 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
3276 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
3277 GDK_WINDOW_XID (window));
3279 wm_hints = XAllocWMHints ();
3281 wm_hints->flags |= WindowGroupHint;
3282 wm_hints->window_group = GDK_WINDOW_XID (leader);
3284 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
3285 GDK_WINDOW_XID (window), wm_hints);
3289 static MotifWmHints *
3290 gdk_window_get_mwm_hints (GdkWindow *window)
3292 static Atom hints_atom = None;
3293 MotifWmHints *hints;
3299 if (GDK_WINDOW_DESTROYED (window))
3303 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
3304 _XA_MOTIF_WM_HINTS, FALSE);
3306 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3307 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3308 False, AnyPropertyType, &type, &format, &nitems,
3309 &bytes_after, (guchar **)&hints);
3318 gdk_window_set_mwm_hints (GdkWindow *window,
3319 MotifWmHints *new_hints)
3321 static Atom hints_atom = None;
3322 MotifWmHints *hints;
3328 if (GDK_WINDOW_DESTROYED (window))
3332 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
3333 _XA_MOTIF_WM_HINTS, FALSE);
3335 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3336 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3337 False, AnyPropertyType, &type, &format, &nitems,
3338 &bytes_after, (guchar **)&hints);
3344 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3346 hints->flags |= MWM_HINTS_FUNCTIONS;
3347 hints->functions = new_hints->functions;
3349 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3351 hints->flags |= MWM_HINTS_DECORATIONS;
3352 hints->decorations = new_hints->decorations;
3356 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3357 hints_atom, hints_atom, 32, PropModeReplace,
3358 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3360 if (hints != new_hints)
3365 * gdk_window_set_decorations:
3366 * @window: a #GdkWindow
3367 * @decorations: decoration hint mask
3369 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
3370 * This function sets the traditional Motif window manager hints that tell the
3371 * window manager which decorations you would like your window to have.
3372 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
3373 * using the GDK function directly.
3375 * The @decorations argument is the logical OR of the fields in
3376 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
3377 * mask, the other bits indicate which decorations should be turned off.
3378 * If #GDK_DECOR_ALL is not included, then the other bits indicate
3379 * which decorations should be turned on.
3381 * Most window managers honor a decorations hint of 0 to disable all decorations,
3382 * but very few honor all possible combinations of bits.
3386 gdk_window_set_decorations (GdkWindow *window,
3387 GdkWMDecoration decorations)
3391 g_return_if_fail (window != NULL);
3392 g_return_if_fail (GDK_IS_WINDOW (window));
3394 hints.flags = MWM_HINTS_DECORATIONS;
3395 hints.decorations = decorations;
3397 gdk_window_set_mwm_hints (window, &hints);
3401 * gdk_window_get_decorations:
3402 * @window: The #GdkWindow to get the decorations from
3403 * @decorations: The window decorations will be written here
3405 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
3406 * Returns: TRUE if the window has decorations set, FALSE otherwise.
3409 gdk_window_get_decorations(GdkWindow *window,
3410 GdkWMDecoration *decorations)
3412 MotifWmHints *hints;
3413 gboolean result = FALSE;
3415 hints = gdk_window_get_mwm_hints (window);
3419 if (hints->flags & MWM_HINTS_DECORATIONS)
3421 *decorations = hints->decorations;
3432 * gdk_window_set_functions:
3433 * @window: a #GdkWindow
3434 * @functions: bitmask of operations to allow on @window
3436 * This function isn't really good for much. It sets the traditional
3437 * Motif window manager hint for which operations the window manager
3438 * should allow on a toplevel window. However, few window managers do
3439 * anything reliable or interesting with this hint. Many ignore it
3442 * The @functions argument is the logical OR of values from the
3443 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
3444 * then the other bits indicate which functions to disable; if
3445 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
3450 gdk_window_set_functions (GdkWindow *window,
3451 GdkWMFunction functions)
3455 g_return_if_fail (window != NULL);
3456 g_return_if_fail (GDK_IS_WINDOW (window));
3458 hints.flags = MWM_HINTS_FUNCTIONS;
3459 hints.functions = functions;
3461 gdk_window_set_mwm_hints (window, &hints);
3464 #ifdef HAVE_SHAPE_EXT
3467 * propagate the shapes from all child windows of a GDK window to the parent
3468 * window. Shamelessly ripped from Enlightenment's code
3476 struct _gdk_span *next;
3480 gdk_add_to_span (struct _gdk_span **s,
3484 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
3491 /* scan the spans for this line */
3494 /* -- -> new span */
3495 /* == -> existing span */
3496 /* ## -> spans intersect */
3497 /* if we are in the middle of spanning the span into the line */
3500 /* case: ---- ==== */
3501 if (xx < ptr1->start - 1)
3503 /* ends before next span - extend to here */
3507 /* case: ----##=== */
3508 else if (xx <= ptr1->end)
3510 /* crosses into next span - delete next span and append */
3511 ss->end = ptr1->end;
3512 ss->next = ptr1->next;
3516 /* case: ---###--- */
3519 /* overlaps next span - delete and keep checking */
3520 ss->next = ptr1->next;
3525 /* otherwise havent started spanning it in yet */
3528 /* case: ---- ==== */
3529 if (xx < ptr1->start - 1)
3531 /* insert span here in list */
3532 noo = g_malloc (sizeof (struct _gdk_span));
3546 /* case: ----##=== */
3547 else if ((x < ptr1->start) && (xx <= ptr1->end))
3549 /* expand this span to the left point of the new one */
3553 /* case: ===###=== */
3554 else if ((x >= ptr1->start) && (xx <= ptr1->end))
3556 /* throw the span away */
3559 /* case: ---###--- */
3560 else if ((x < ptr1->start) && (xx > ptr1->end))
3567 /* case: ===##---- */
3568 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
3574 /* case: ==== ---- */
3575 /* case handled by next loop iteration - first case */
3580 /* it started in the middle but spans beyond your current list */
3586 /* it does not start inside a span or in the middle, so add it to the end */
3587 noo = g_malloc (sizeof (struct _gdk_span));
3595 noo->next = ptr2->next;
3608 gdk_add_rectangles (Display *disp,
3610 struct _gdk_span **spans,
3617 gint x1, y1, x2, y2;
3621 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
3624 /* go through all clip rects in this window's shape */
3625 for (k = 0; k < rn; k++)
3627 /* for each clip rect, add it to each line's spans */
3629 x2 = x + rl[k].x + (rl[k].width - 1);
3631 y2 = y + rl[k].y + (rl[k].height - 1);
3640 for (a = y1; a <= y2; a++)
3643 gdk_add_to_span (&spans[a], x1, x2);
3651 gdk_propagate_shapes (Display *disp,
3655 Window rt, par, *list = NULL;
3656 gint i, j, num = 0, num_rects = 0;
3660 XRectangle *rects = NULL;
3661 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
3662 XWindowAttributes xatt;
3664 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
3669 spans = g_malloc (sizeof (struct _gdk_span *) * h);
3671 for (i = 0; i < h; i++)
3673 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
3676 /* go through all child windows and create/insert spans */
3677 for (i = 0; i < num; i++)
3679 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
3680 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
3681 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
3684 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
3686 /* go through the spans list and build a list of rects */
3687 rects = g_malloc (sizeof (XRectangle) * 256);
3689 for (i = 0; i < baseh; i++)
3692 /* go through the line for all spans */
3695 rects[num_rects].x = ptr1->start;
3696 rects[num_rects].y = i;
3697 rects[num_rects].width = ptr1->end - ptr1->start + 1;
3698 rects[num_rects].height = 1;
3700 /* if there are more lines */
3702 /* while contigous rects (same start/end coords) exist */
3703 while ((contig) && (j < baseh))
3705 /* search next line for spans matching this one */
3711 /* if we have an exact span match set contig */
3712 if ((ptr2->start == ptr1->start) &&
3713 (ptr2->end == ptr1->end))
3716 /* remove the span - not needed */
3719 ptr3->next = ptr2->next;
3725 spans[j] = ptr2->next;
3731 /* gone past the span point no point looking */
3732 else if (ptr2->start < ptr1->start)
3740 /* if a contiguous span was found increase the rect h */
3743 rects[num_rects].height++;
3747 /* up the rect count */
3749 /* every 256 new rects increase the rect array */
3750 if ((num_rects % 256) == 0)
3751 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
3755 /* set the rects as the shape mask */
3758 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
3759 ShapeSet, YXSorted);
3764 /* free up all the spans we made */
3765 for (i = 0; i < baseh; i++)
3778 #endif /* HAVE_SHAPE_EXT */
3781 * gdk_window_set_child_shapes:
3782 * @window: a #GdkWindow
3784 * Sets the shape mask of @window to the union of shape masks
3785 * for all children of @window, ignoring the shape mask of @window
3786 * itself. Contrast with gdk_window_merge_child_shapes() which includes
3787 * the shape mask of @window in the masks to be merged.
3790 gdk_window_set_child_shapes (GdkWindow *window)
3792 g_return_if_fail (window != NULL);
3793 g_return_if_fail (GDK_IS_WINDOW (window));
3795 #ifdef HAVE_SHAPE_EXT
3796 if (!GDK_WINDOW_DESTROYED (window) &&
3797 gdk_window_have_shape_ext ())
3798 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3799 GDK_WINDOW_XID (window), FALSE);
3804 * gdk_window_merge_child_shapes:
3805 * @window: a #GdkWindow
3807 * Merges the shape masks for any child windows into the
3808 * shape mask for @window. i.e. the union of all masks
3809 * for @window and its children will become the new mask
3810 * for @window. See gdk_window_shape_combine_mask().
3812 * This function is distinct from gdk_window_set_child_shapes()
3813 * because it includes @window's shape mask in the set of shapes to
3818 gdk_window_merge_child_shapes (GdkWindow *window)
3820 g_return_if_fail (window != NULL);
3821 g_return_if_fail (GDK_IS_WINDOW (window));
3823 #ifdef HAVE_SHAPE_EXT
3824 if (!GDK_WINDOW_DESTROYED (window) &&
3825 gdk_window_have_shape_ext ())
3826 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3827 GDK_WINDOW_XID (window), TRUE);
3831 /* Support for windows that can be guffaw-scrolled
3832 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
3836 gdk_window_gravity_works (void)
3838 enum { UNKNOWN, NO, YES };
3839 static gint gravity_works = UNKNOWN;
3841 if (gravity_works == UNKNOWN)
3848 /* This particular server apparently has a bug so that the test
3849 * works but the actual code crashes it
3851 if ((!strcmp (XServerVendor (gdk_display), "Sun Microsystems, Inc.")) &&
3852 (VendorRelease (gdk_display) == 3400))
3858 attr.window_type = GDK_WINDOW_TEMP;
3859 attr.wclass = GDK_INPUT_OUTPUT;
3864 attr.event_mask = 0;
3866 parent = gdk_window_new (NULL, &attr, GDK_WA_X | GDK_WA_Y);
3868 attr.window_type = GDK_WINDOW_CHILD;
3869 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
3871 gdk_window_set_static_win_gravity (child, TRUE);
3873 gdk_window_resize (parent, 100, 110);
3874 gdk_window_move (parent, 0, -10);
3875 gdk_window_move_resize (parent, 0, 0, 100, 100);
3877 gdk_window_resize (parent, 100, 110);
3878 gdk_window_move (parent, 0, -10);
3879 gdk_window_move_resize (parent, 0, 0, 100, 100);
3881 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
3883 gdk_window_destroy (parent);
3884 gdk_window_destroy (child);
3886 gravity_works = ((y == -20) ? YES : NO);
3889 return (gravity_works == YES);
3893 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
3895 XSetWindowAttributes xattributes;
3896 guint xattributes_mask = 0;
3898 g_return_if_fail (window != NULL);
3900 xattributes.bit_gravity = StaticGravity;
3901 xattributes_mask |= CWBitGravity;
3902 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
3903 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3904 GDK_WINDOW_XID (window),
3905 CWBitGravity, &xattributes);
3909 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
3911 XSetWindowAttributes xattributes;
3913 g_return_if_fail (window != NULL);
3915 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
3917 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3918 GDK_WINDOW_XID (window),
3919 CWWinGravity, &xattributes);
3923 * gdk_window_set_static_gravities:
3924 * @window: a #GdkWindow
3925 * @use_static: %TRUE to turn on static gravity
3927 * Set the bit gravity of the given window to static, and flag it so
3928 * all children get static subwindow gravity. This is used if you are
3929 * implementing scary features that involve deep knowledge of the
3930 * windowing system. Don't worry about it unless you have to.
3932 * Return value: %TRUE if the server supports static gravity
3935 gdk_window_set_static_gravities (GdkWindow *window,
3936 gboolean use_static)
3938 GdkWindowObject *private = (GdkWindowObject *)window;
3941 g_return_val_if_fail (window != NULL, FALSE);
3942 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3944 if (!use_static == !private->guffaw_gravity)
3947 if (use_static && !gdk_window_gravity_works ())
3950 private->guffaw_gravity = use_static;
3952 if (!GDK_WINDOW_DESTROYED (window))
3954 gdk_window_set_static_bit_gravity (window, use_static);
3956 tmp_list = private->children;
3959 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
3961 tmp_list = tmp_list->next;
3968 /* internal function created for and used by gdk_window_xid_at_coords */
3970 gdk_window_xid_at (Window base,
3976 gboolean excl_child)
3979 Window *list = NULL;
3980 Window child = 0, parent_win = 0, root_win = 0;
3982 unsigned int ww, wh, wb, wd, num;
3985 xdisplay = GDK_DISPLAY ();
3986 if (!XGetGeometry (xdisplay, base, &root_win, &wx, &wy, &ww, &wh, &wb, &wd))
3993 (x < (int) (wx + ww)) &&
3994 (y < (int) (wy + wh))))
3997 if (!XQueryTree (xdisplay, base, &root_win, &parent_win, &list, &num))
4002 for (i = num - 1; ; i--)
4004 if ((!excl_child) || (!g_list_find (excludes, (gpointer *) list[i])))
4006 if ((child = gdk_window_xid_at (list[i], wx, wy, x, y, excludes, excl_child)) != 0)
4021 * The following fucntion by The Rasterman <raster@redhat.com>
4022 * This function returns the X Window ID in which the x y location is in
4023 * (x and y being relative to the root window), excluding any windows listed
4024 * in the GList excludes (this is a list of X Window ID's - gpointer being
4027 * This is primarily designed for internal gdk use - for DND for example
4028 * when using a shaped icon window as the drag object - you exclude the
4029 * X Window ID of the "icon" (perhaps more if excludes may be needed) and
4030 * You can get back an X Window ID as to what X Window ID is infact under
4031 * those X,Y co-ordinates.
4034 gdk_window_xid_at_coords (gint x,
4037 gboolean excl_child)
4041 Window *list = NULL;
4042 Window root, child = 0, parent_win = 0, root_win = 0;
4046 window = _gdk_parent_root;
4047 xdisplay = GDK_WINDOW_XDISPLAY (window);
4048 root = GDK_WINDOW_XID (window);
4049 num = g_list_length (excludes);
4051 gdk_x11_grab_server ();
4052 if (!XQueryTree (xdisplay, root, &root_win, &parent_win, &list, &num))
4054 gdk_x11_ungrab_server ();
4062 XWindowAttributes xwa;
4064 XGetWindowAttributes (xdisplay, list [i], &xwa);
4066 if (xwa.map_state != IsViewable)
4069 if (excl_child && g_list_find (excludes, (gpointer *) list[i]))
4072 if ((child = gdk_window_xid_at (list[i], 0, 0, x, y, excludes, excl_child)) == 0)
4077 if (!g_list_find (excludes, (gpointer *) child))
4080 gdk_x11_ungrab_server ();
4087 gdk_x11_ungrab_server ();
4093 gdk_x11_ungrab_server ();
4098 wmspec_moveresize (GdkWindow *window,
4106 /* Release passive grab */
4107 gdk_pointer_ungrab (timestamp);
4109 xev.xclient.type = ClientMessage;
4110 xev.xclient.serial = 0;
4111 xev.xclient.send_event = True;
4112 xev.xclient.display = gdk_display;
4113 xev.xclient.window = GDK_WINDOW_XID (window);
4114 xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_MOVERESIZE");
4115 xev.xclient.format = 32;
4116 xev.xclient.data.l[0] = root_x;
4117 xev.xclient.data.l[1] = root_y;
4118 xev.xclient.data.l[2] = direction;
4119 xev.xclient.data.l[3] = 0;
4120 xev.xclient.data.l[4] = 0;
4122 XSendEvent (gdk_display, _gdk_root_window, False,
4123 SubstructureRedirectMask | SubstructureNotifyMask,
4127 /* From the WM spec */
4128 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4129 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4130 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4131 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4132 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4133 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4134 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4135 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4136 #define _NET_WM_MOVERESIZE_MOVE 8
4139 wmspec_resize_drag (GdkWindow *window,
4148 /* Let the compiler turn a switch into a table, instead
4149 * of doing the table manually, this way is easier to verify.
4153 case GDK_WINDOW_EDGE_NORTH_WEST:
4154 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4157 case GDK_WINDOW_EDGE_NORTH:
4158 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4161 case GDK_WINDOW_EDGE_NORTH_EAST:
4162 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4165 case GDK_WINDOW_EDGE_WEST:
4166 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4169 case GDK_WINDOW_EDGE_EAST:
4170 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4173 case GDK_WINDOW_EDGE_SOUTH_WEST:
4174 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4177 case GDK_WINDOW_EDGE_SOUTH:
4178 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4181 case GDK_WINDOW_EDGE_SOUTH_EAST:
4182 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4186 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4192 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4195 /* This is global for use in gdkevents-x11.c */
4196 GdkWindow *_gdk_moveresize_window;
4198 static GdkWindow *moveresize_emulation_window = NULL;
4199 static gboolean is_resize = FALSE;
4200 static GdkWindowEdge resize_edge;
4201 static gint moveresize_button;
4202 static gint moveresize_x;
4203 static gint moveresize_y;
4204 static gint moveresize_orig_x;
4205 static gint moveresize_orig_y;
4206 static gint moveresize_orig_width;
4207 static gint moveresize_orig_height;
4208 static GdkWindowHints moveresize_geom_mask = 0;
4209 static GdkGeometry moveresize_geometry;
4210 static Time moveresize_process_time;
4212 static XEvent *moveresize_pending_event;
4215 update_pos (gint new_root_x,
4220 dx = new_root_x - moveresize_x;
4221 dy = new_root_y - moveresize_y;
4227 w = moveresize_orig_width;
4228 h = moveresize_orig_height;
4230 switch (resize_edge)
4232 case GDK_WINDOW_EDGE_SOUTH_EAST:
4241 if (moveresize_geom_mask)
4243 gdk_window_constrain_size (&moveresize_geometry,
4244 moveresize_geom_mask,
4249 gdk_window_resize (_gdk_moveresize_window, w, h);
4255 x = moveresize_orig_x + dx;
4256 y = moveresize_orig_y + dy;
4258 gdk_window_move (_gdk_moveresize_window, x, y);
4265 gdk_window_destroy (moveresize_emulation_window);
4266 moveresize_emulation_window = NULL;
4267 _gdk_moveresize_window = NULL;
4269 if (moveresize_pending_event)
4271 g_free (moveresize_pending_event);
4272 moveresize_pending_event = NULL;
4277 lookahead_motion_predicate (Display *display,
4281 gboolean *seen_release = (gboolean *)arg;
4286 switch (event->xany.type)
4289 *seen_release = TRUE;
4292 moveresize_process_time = event->xmotion.time;
4302 moveresize_lookahead (XEvent *event)
4305 gboolean seen_release = FALSE;
4307 if (moveresize_process_time)
4309 if (event->xmotion.time == moveresize_process_time)
4311 moveresize_process_time = 0;
4318 XCheckIfEvent (gdk_display, &tmp_event,
4319 lookahead_motion_predicate, (XPointer)&seen_release);
4321 return moveresize_process_time == 0;
4325 _gdk_moveresize_handle_event (XEvent *event)
4327 guint button_mask = 0;
4328 GdkWindowObject *window_private = (GdkWindowObject *) _gdk_moveresize_window;
4330 button_mask = GDK_BUTTON1_MASK << (moveresize_button - 1);
4332 switch (event->xany.type)
4335 if (window_private->resize_count > 0)
4337 if (moveresize_pending_event)
4338 *moveresize_pending_event = *event;
4340 moveresize_pending_event = g_memdup (event, sizeof (XEvent));
4344 if (!moveresize_lookahead (event))
4347 update_pos (event->xmotion.x_root,
4348 event->xmotion.y_root);
4350 /* This should never be triggered in normal cases, but in the
4351 * case where the drag started without an implicit grab being
4352 * in effect, we could miss the release if it occurs before
4353 * we grab the pointer; this ensures that we will never
4354 * get a permanently stuck grab.
4356 if ((event->xmotion.state & button_mask) == 0)
4361 update_pos (event->xbutton.x_root,
4362 event->xbutton.y_root);
4364 if (event->xbutton.button == moveresize_button)
4371 _gdk_moveresize_configure_done (void)
4375 if (moveresize_pending_event)
4377 tmp_event = moveresize_pending_event;
4378 moveresize_pending_event = NULL;
4379 _gdk_moveresize_handle_event (tmp_event);
4385 create_moveresize_window (guint32 timestamp)
4387 GdkWindowAttr attributes;
4388 gint attributes_mask;
4389 GdkGrabStatus status;
4391 g_assert (moveresize_emulation_window == NULL);
4393 attributes.x = -100;
4394 attributes.y = -100;
4395 attributes.width = 10;
4396 attributes.height = 10;
4397 attributes.window_type = GDK_WINDOW_TEMP;
4398 attributes.wclass = GDK_INPUT_ONLY;
4399 attributes.override_redirect = TRUE;
4400 attributes.event_mask = 0;
4402 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4404 moveresize_emulation_window =
4405 gdk_window_new (NULL, &attributes, attributes_mask);
4407 gdk_window_show (moveresize_emulation_window);
4409 status = gdk_pointer_grab (moveresize_emulation_window,
4411 GDK_BUTTON_RELEASE_MASK |
4412 GDK_POINTER_MOTION_MASK,
4417 if (status != GDK_GRAB_SUCCESS)
4419 /* If this fails, some other client has grabbed the window
4422 gdk_window_destroy (moveresize_emulation_window);
4423 moveresize_emulation_window = NULL;
4426 moveresize_process_time = 0;
4430 emulate_resize_drag (GdkWindow *window,
4438 moveresize_button = button;
4440 moveresize_x = root_x;
4441 moveresize_y = root_y;
4442 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4444 gdk_window_get_size (window, &moveresize_orig_width, &moveresize_orig_height);
4446 moveresize_geom_mask = 0;
4447 gdk_window_get_geometry_hints (window,
4448 &moveresize_geometry,
4449 &moveresize_geom_mask);
4451 create_moveresize_window (timestamp);
4455 emulate_move_drag (GdkWindow *window,
4462 moveresize_button = button;
4463 moveresize_x = root_x;
4464 moveresize_y = root_y;
4465 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
4467 gdk_window_get_deskrelative_origin (_gdk_moveresize_window,
4469 &moveresize_orig_y);
4471 create_moveresize_window (timestamp);
4475 * gdk_window_begin_resize_drag:
4476 * @window: a #GdkWindow
4477 * @edge: the edge or corner from which the drag is started
4478 * @button: the button being used to drag
4479 * @root_x: root window X coordinate of mouse click that began the drag
4480 * @root_y: root window Y coordinate of mouse click that began the drag
4481 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
4483 * Begins a window resize operation (for a toplevel window).
4484 * You might use this function to implement a "window resize grip," for
4485 * example; in fact #GtkStatusbar uses it. The function works best
4486 * with window managers that support the Extended Window Manager Hints spec
4487 * (see http://www.freedesktop.org), but has a fallback implementation
4488 * for other window managers.
4492 gdk_window_begin_resize_drag (GdkWindow *window,
4499 g_return_if_fail (GDK_IS_WINDOW (window));
4500 g_return_if_fail (moveresize_emulation_window == NULL);
4502 if (GDK_WINDOW_DESTROYED (window))
4505 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4506 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4508 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4512 * gdk_window_begin_move_drag:
4513 * @window: a #GdkWindow
4514 * @button: the button being used to drag
4515 * @root_x: root window X coordinate of mouse click that began the drag
4516 * @root_y: root window Y coordinate of mouse click that began the drag
4517 * @timestamp: timestamp of mouse click that began the drag
4519 * Begins a window move operation (for a toplevel window). You might
4520 * use this function to implement a "window move grip," for
4521 * example. The function works best with window managers that support
4522 * the Extended Window Manager Hints spec (see
4523 * http://www.freedesktop.org), but has a fallback implementation for
4524 * other window managers.
4528 gdk_window_begin_move_drag (GdkWindow *window,
4534 g_return_if_fail (GDK_IS_WINDOW (window));
4535 g_return_if_fail (moveresize_emulation_window == NULL);
4537 if (GDK_WINDOW_DESTROYED (window))
4540 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
4541 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE,
4542 root_x, root_y, timestamp);
4544 emulate_move_drag (window, button, root_x, root_y, timestamp);