2 /* GDK - The GIMP Drawing Kit
3 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include <X11/Xutil.h>
30 #include <X11/Xatom.h>
31 #include <netinet/in.h>
36 #include "gdkwindow.h"
38 #include "gdkinputprivate.h"
39 #include "gdkdisplay-x11.h"
40 #include "gdkprivate-x11.h"
41 #include "gdkregion.h"
42 #include "gdkinternals.h"
44 #include "gdkwindow-x11.h"
52 #include <X11/extensions/shape.h>
55 const int _gdk_event_mask_table[21] =
59 PointerMotionHintMask,
76 SubstructureNotifyMask,
77 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
79 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
81 /* Forward declarations */
82 static gboolean gdk_window_gravity_works (GdkWindow *window);
83 static void gdk_window_set_static_win_gravity (GdkWindow *window,
85 static gboolean gdk_window_have_shape_ext (GdkDisplay *display);
86 static gboolean gdk_window_icon_name_set (GdkWindow *window);
87 static void gdk_window_add_colormap_windows (GdkWindow *window);
88 static void set_wm_name (GdkDisplay *display,
92 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
93 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
95 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
98 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
99 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
100 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
101 static void gdk_window_impl_x11_finalize (GObject *object);
103 static gpointer parent_class = NULL;
106 gdk_window_impl_x11_get_type (void)
108 static GType object_type = 0;
112 static const GTypeInfo object_info =
114 sizeof (GdkWindowImplX11Class),
115 (GBaseInitFunc) NULL,
116 (GBaseFinalizeFunc) NULL,
117 (GClassInitFunc) gdk_window_impl_x11_class_init,
118 NULL, /* class_finalize */
119 NULL, /* class_data */
120 sizeof (GdkWindowImplX11),
122 (GInstanceInitFunc) gdk_window_impl_x11_init,
125 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
134 _gdk_window_impl_get_type (void)
136 return gdk_window_impl_x11_get_type ();
140 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
147 _gdk_x11_window_get_toplevel (GdkWindow *window)
149 GdkWindowObject *private;
150 GdkWindowImplX11 *impl;
152 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
154 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
157 private = (GdkWindowObject *)window;
158 impl = GDK_WINDOW_IMPL_X11 (private->impl);
161 impl->toplevel = g_new0 (GdkToplevelX11, 1);
163 return impl->toplevel;
167 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
169 GObjectClass *object_class = G_OBJECT_CLASS (klass);
170 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
172 parent_class = g_type_class_peek_parent (klass);
174 object_class->finalize = gdk_window_impl_x11_finalize;
176 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
177 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
178 drawable_class->get_size = gdk_window_impl_x11_get_size;
180 /* Visible and clip regions are the same */
181 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
182 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
186 gdk_window_impl_x11_finalize (GObject *object)
188 GdkWindowObject *wrapper;
189 GdkDrawableImplX11 *draw_impl;
190 GdkWindowImplX11 *window_impl;
192 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
194 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
195 window_impl = GDK_WINDOW_IMPL_X11 (object);
197 wrapper = (GdkWindowObject*) draw_impl->wrapper;
199 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
201 if (!GDK_WINDOW_DESTROYED (wrapper))
203 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), draw_impl->xid);
204 if (window_impl->toplevel && window_impl->toplevel->focus_window)
205 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (object), window_impl->toplevel->focus_window);
208 if (window_impl->toplevel)
209 g_free (window_impl->toplevel);
211 G_OBJECT_CLASS (parent_class)->finalize (object);
215 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
217 GdkDrawableImplX11 *drawable_impl;
218 GdkWindowImplX11 *window_impl;
220 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
222 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
223 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
225 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
226 drawable_impl->colormap == NULL)
228 XWindowAttributes window_attributes;
231 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
235 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
236 window_attributes.visual->visualid);
237 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
238 window_attributes.colormap);
241 return drawable_impl->colormap;
245 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
248 GdkWindowImplX11 *impl;
249 GdkDrawableImplX11 *draw_impl;
251 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
253 impl = GDK_WINDOW_IMPL_X11 (drawable);
254 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
256 if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper))
260 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
264 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
266 GDK_COLORMAP_XCOLORMAP (cmap));
268 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
270 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
276 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
280 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
283 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
285 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
289 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
291 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
292 GdkRectangle result_rect;
296 result_rect.width = impl->width;
297 result_rect.height = impl->height;
299 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
301 return gdk_region_rectangle (&result_rect);
305 _gdk_windowing_window_init (GdkScreen * screen)
307 GdkWindowObject *private;
308 GdkWindowImplX11 *impl;
309 GdkDrawableImplX11 *draw_impl;
310 GdkScreenX11 *screen_x11;
312 screen_x11 = GDK_SCREEN_X11 (screen);
314 g_assert (screen_x11->root_window == NULL);
316 gdk_screen_set_default_colormap (screen,
317 gdk_screen_get_system_colormap (screen));
319 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
320 private = (GdkWindowObject *)screen_x11->root_window;
321 impl = GDK_WINDOW_IMPL_X11 (private->impl);
322 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
324 draw_impl->screen = screen;
325 draw_impl->xid = screen_x11->xroot_window;
326 draw_impl->wrapper = GDK_DRAWABLE (private);
327 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
328 g_object_ref (draw_impl->colormap);
330 private->window_type = GDK_WINDOW_ROOT;
331 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
333 impl->width = WidthOfScreen (screen_x11->xscreen);
334 impl->height = HeightOfScreen (screen_x11->xscreen);
336 _gdk_window_init_position (GDK_WINDOW (private));
338 _gdk_xid_table_insert (screen_x11->display,
339 &screen_x11->xroot_window,
340 screen_x11->root_window);
344 set_wm_protocols (GdkWindow *window)
346 GdkWindowObject *private = (GdkWindowObject *)window;
347 GdkDisplay *display = gdk_drawable_get_display (window);
350 protocols[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
351 protocols[1] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
352 protocols[2] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
354 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, 3);
358 get_default_title (void)
362 title = g_get_application_name ();
364 title = g_get_prgname ();
370 check_leader_window_title (GdkDisplay *display)
372 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
374 if (display_x11->leader_window && !display_x11->leader_window_title_set)
376 set_wm_name (display,
377 display_x11->leader_window,
378 get_default_title ());
380 display_x11->leader_window_title_set = TRUE;
386 * @parent: a #GdkWindow, or %NULL to create the window as a child of
387 * the default root window for the default display.
388 * @attributes: attributes of the new window
389 * @attributes_mask: mask indicating which fields in @attributes are valid
391 * Creates a new #GdkWindow using the attributes from
392 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
393 * more details. Note: to use this on displays other than the default
394 * display, @parent must be specified.
396 * Return value: the new #GdkWindow
399 gdk_window_new (GdkWindow *parent,
400 GdkWindowAttr *attributes,
401 gint attributes_mask)
404 GdkWindowObject *private;
405 GdkWindowImplX11 *impl;
406 GdkDrawableImplX11 *draw_impl;
407 GdkToplevelX11 *toplevel;
408 GdkScreenX11 *screen_x11;
417 XSetWindowAttributes xattributes;
418 long xattributes_mask;
419 XSizeHints size_hints;
420 XClassHint *class_hint;
428 g_return_val_if_fail (attributes != NULL, NULL);
433 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
435 screen = gdk_screen_get_default ();
436 parent = gdk_screen_get_root_window (screen);
439 screen = gdk_drawable_get_screen (parent);
441 screen_x11 = GDK_SCREEN_X11 (screen);
443 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
445 if (GDK_WINDOW_DESTROYED (parent))
448 xparent = GDK_WINDOW_XID (parent);
450 window = g_object_new (GDK_TYPE_WINDOW, NULL);
451 private = (GdkWindowObject *)window;
452 impl = GDK_WINDOW_IMPL_X11 (private->impl);
453 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
454 draw_impl->wrapper = GDK_DRAWABLE (window);
456 draw_impl->screen = screen;
457 xdisplay = screen_x11->xdisplay;
459 /* Windows with a foreign parent are treated as if they are children
460 * of the root window, except for actual creation.
462 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
463 parent = gdk_screen_get_root_window (screen);
465 private->parent = (GdkWindowObject *)parent;
467 private->accept_focus = TRUE;
469 xattributes_mask = 0;
471 if (attributes_mask & GDK_WA_X)
476 if (attributes_mask & GDK_WA_Y)
483 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
484 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
486 if (attributes->wclass == GDK_INPUT_ONLY)
488 /* Backwards compatiblity - we've always ignored
489 * attributes->window_type for input-only windows
492 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
493 private->window_type = GDK_WINDOW_TEMP;
495 private->window_type = GDK_WINDOW_CHILD;
498 private->window_type = attributes->window_type;
500 _gdk_window_init_position (GDK_WINDOW (private));
501 if (impl->position_info.big)
502 private->guffaw_gravity = TRUE;
504 if (attributes_mask & GDK_WA_VISUAL)
505 visual = attributes->visual;
507 visual = gdk_screen_get_system_visual (screen);
508 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
510 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
511 for (i = 0; i < _gdk_nenvent_masks; i++)
513 if (attributes->event_mask & (1 << (i + 1)))
514 xattributes.event_mask |= _gdk_event_mask_table[i];
516 private->event_mask = attributes->event_mask;
518 if (xattributes.event_mask)
519 xattributes_mask |= CWEventMask;
521 if (attributes_mask & GDK_WA_NOREDIR)
523 xattributes.override_redirect =
524 (attributes->override_redirect == FALSE)?False:True;
525 xattributes_mask |= CWOverrideRedirect;
528 xattributes.override_redirect = False;
530 if (private->parent && private->parent->guffaw_gravity)
532 xattributes.win_gravity = StaticGravity;
533 xattributes_mask |= CWWinGravity;
537 switch (private->window_type)
539 case GDK_WINDOW_TOPLEVEL:
540 case GDK_WINDOW_DIALOG:
541 case GDK_WINDOW_TEMP:
542 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
544 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
545 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
546 xparent = GDK_SCREEN_XROOTWIN (screen);
548 case GDK_WINDOW_CHILD:
551 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
555 if (attributes->wclass == GDK_INPUT_OUTPUT)
558 depth = visual->depth;
560 private->input_only = FALSE;
561 private->depth = depth;
563 if (attributes_mask & GDK_WA_COLORMAP)
565 draw_impl->colormap = attributes->colormap;
566 g_object_ref (attributes->colormap);
570 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
572 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
573 g_object_ref (draw_impl->colormap);
577 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
581 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
582 xattributes.background_pixel = private->bg_color.pixel;
584 private->bg_pixmap = NULL;
586 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
587 xattributes_mask |= CWBorderPixel | CWBackPixel;
589 if (private->guffaw_gravity)
590 xattributes.bit_gravity = StaticGravity;
592 xattributes.bit_gravity = NorthWestGravity;
594 xattributes_mask |= CWBitGravity;
596 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
597 xattributes_mask |= CWColormap;
599 if (private->window_type == GDK_WINDOW_TEMP)
601 xattributes.save_under = True;
602 xattributes.override_redirect = True;
603 xattributes.cursor = None;
604 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
612 private->input_only = TRUE;
613 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
614 g_object_ref (draw_impl->colormap);
617 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
618 impl->position_info.x, impl->position_info.y,
619 impl->position_info.width, impl->position_info.height,
620 0, depth, class, xvisual,
621 xattributes_mask, &xattributes);
623 g_object_ref (window);
624 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
626 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
627 (attributes->cursor) :
631 private->parent->children = g_list_prepend (private->parent->children, window);
633 switch (GDK_WINDOW_TYPE (private))
635 case GDK_WINDOW_DIALOG:
636 XSetTransientForHint (xdisplay, xid, xparent);
637 case GDK_WINDOW_TOPLEVEL:
638 case GDK_WINDOW_TEMP:
639 set_wm_protocols (window);
641 case GDK_WINDOW_CHILD:
642 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
643 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
644 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
646 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
647 gdk_window_add_colormap_windows (window);
656 toplevel = _gdk_x11_window_get_toplevel (window);
658 if (class != InputOnly)
660 /* The focus window is off the visible area, and serves to receive key
661 * press events so they don't get sent to child windows.
663 toplevel->focus_window = XCreateSimpleWindow (xdisplay, xid,
665 xattributes.background_pixel,
666 xattributes.background_pixel);
667 /* FIXME: probably better to actually track the requested event mask for the toplevel
669 XSelectInput (xdisplay, toplevel->focus_window,
670 KeyPressMask | KeyReleaseMask | FocusChangeMask);
672 XMapWindow (xdisplay, toplevel->focus_window);
673 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
676 size_hints.flags = PSize;
677 size_hints.width = impl->width;
678 size_hints.height = impl->height;
680 check_leader_window_title (screen_x11->display);
682 /* FIXME: Is there any point in doing this? Do any WM's pay
683 * attention to PSize, and even if they do, is this the
686 XSetWMNormalHints (xdisplay, xid, &size_hints);
688 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
689 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
692 XChangeProperty (xdisplay, xid,
693 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
698 XChangeProperty (xdisplay, xid,
699 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
700 XA_WINDOW, 32, PropModeReplace,
701 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
703 if (attributes_mask & GDK_WA_TITLE)
704 title = attributes->title;
706 title = get_default_title ();
708 gdk_window_set_title (window, title);
710 if (attributes_mask & GDK_WA_WMCLASS)
712 class_hint = XAllocClassHint ();
713 class_hint->res_name = attributes->wmclass_name;
714 class_hint->res_class = attributes->wmclass_class;
715 XSetClassHint (xdisplay, xid, class_hint);
723 x_event_mask_to_gdk_event_mask (long mask)
725 GdkEventMask event_mask = 0;
728 for (i = 0; i < _gdk_nenvent_masks; i++)
730 if (mask & _gdk_event_mask_table[i])
731 event_mask |= 1 << (i + 1);
738 * gdk_window_foreign_new_for_display:
739 * @display: the #GdkDisplay where the window handle comes from.
740 * @anid: a native window handle.
742 * Wraps a native window in a #GdkWindow.
743 * This may fail if the window has been destroyed.
745 * For example in the X backend, a native window handle is an Xlib
748 * Return value: the newly-created #GdkWindow wrapper for the
749 * native window or %NULL if the window has been destroyed.
754 gdk_window_foreign_new_for_display (GdkDisplay *display,
755 GdkNativeWindow anid)
758 GdkWindowObject *private;
759 GdkWindowImplX11 *impl;
760 GdkDrawableImplX11 *draw_impl;
761 GdkDisplayX11 *display_x11;
762 XWindowAttributes attrs;
764 Window *children = NULL;
768 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
770 display_x11 = GDK_DISPLAY_X11 (display);
772 gdk_error_trap_push ();
773 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
774 if (gdk_error_trap_pop () || !result)
777 /* FIXME: This is pretty expensive. Maybe the caller should supply
779 gdk_error_trap_push ();
780 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
781 if (gdk_error_trap_pop () || !result)
787 window = g_object_new (GDK_TYPE_WINDOW, NULL);
788 private = (GdkWindowObject *)window;
789 impl = GDK_WINDOW_IMPL_X11 (private->impl);
790 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
791 draw_impl->wrapper = GDK_DRAWABLE (window);
792 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
794 private->parent = gdk_xid_table_lookup_for_display (display, parent);
796 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
797 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
799 private->parent->children = g_list_prepend (private->parent->children, window);
801 draw_impl->xid = anid;
803 private->x = attrs.x;
804 private->y = attrs.y;
805 impl->width = attrs.width;
806 impl->height = attrs.height;
807 private->window_type = GDK_WINDOW_FOREIGN;
808 private->destroyed = FALSE;
810 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
812 if (attrs.map_state == IsUnmapped)
813 private->state = GDK_WINDOW_STATE_WITHDRAWN;
817 private->depth = attrs.depth;
819 _gdk_window_init_position (GDK_WINDOW (private));
821 g_object_ref (window);
822 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
827 * gdk_window_lookup_for_display:
828 * @display: the #GdkDisplay corresponding to the window handle
829 * @anid: a native window handle.
831 * Looks up the #GdkWindow that wraps the given native window handle.
833 * For example in the X backend, a native window handle is an Xlib
836 * Return value: the #GdkWindow wrapper for the native window,
837 * or %NULL if there is none.
842 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
844 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
849 * @anid: a native window handle.
851 * Looks up the #GdkWindow that wraps the given native window handle.
853 * For example in the X backend, a native window handle is an Xlib
856 * Return value: the #GdkWindow wrapper for the native window,
857 * or %NULL if there is none.
860 gdk_window_lookup (GdkNativeWindow anid)
862 return (GdkWindow*) gdk_xid_table_lookup (anid);
866 gdk_toplevel_x11_free_contents (GdkToplevelX11 *toplevel)
868 if (toplevel->icon_window)
870 g_object_unref (toplevel->icon_window);
871 toplevel->icon_window = NULL;
873 if (toplevel->icon_pixmap)
875 g_object_unref (toplevel->icon_pixmap);
876 toplevel->icon_pixmap = NULL;
878 if (toplevel->icon_mask)
880 g_object_unref (toplevel->icon_mask);
881 toplevel->icon_mask = NULL;
883 if (toplevel->group_leader)
885 g_object_unref (toplevel->group_leader);
886 toplevel->group_leader = NULL;
891 _gdk_windowing_window_destroy (GdkWindow *window,
893 gboolean foreign_destroy)
895 GdkWindowObject *private = (GdkWindowObject *)window;
896 GdkToplevelX11 *toplevel;
897 GdkDrawableImplX11 *draw_impl;
899 g_return_if_fail (GDK_IS_WINDOW (window));
901 _gdk_selection_window_destroyed (window);
903 if (private->extension_events != 0)
904 _gdk_input_window_destroy (window);
906 toplevel = _gdk_x11_window_get_toplevel (window);
908 gdk_toplevel_x11_free_contents (toplevel);
910 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
912 if (draw_impl->xft_draw)
913 XftDrawDestroy (draw_impl->xft_draw);
915 if (private->window_type == GDK_WINDOW_FOREIGN)
917 if (!foreign_destroy && (private->parent != NULL))
919 /* It's somebody else's window, but in our heirarchy,
920 * so reparent it to the root window, and then send
921 * it a delete event, as if we were a WM
923 XClientMessageEvent xevent;
925 gdk_error_trap_push ();
926 gdk_window_hide (window);
927 gdk_window_reparent (window, NULL, 0, 0);
929 xevent.type = ClientMessage;
930 xevent.window = GDK_WINDOW_XID (window);
931 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
934 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
936 xevent.data.l[1] = CurrentTime;
937 xevent.data.l[2] = 0;
938 xevent.data.l[3] = 0;
939 xevent.data.l[4] = 0;
941 XSendEvent (GDK_WINDOW_XDISPLAY (window),
942 GDK_WINDOW_XID (window),
943 False, 0, (XEvent *)&xevent);
944 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
945 gdk_error_trap_pop ();
948 else if (!recursing && !foreign_destroy)
950 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
954 /* This function is called when the XWindow is really gone.
957 gdk_window_destroy_notify (GdkWindow *window)
959 GdkWindowImplX11 *window_impl;
961 g_return_if_fail (window != NULL);
963 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
965 if (!GDK_WINDOW_DESTROYED (window))
967 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
968 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
970 _gdk_window_destroy (window, TRUE);
973 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
974 if (window_impl->toplevel && window_impl->toplevel->focus_window)
975 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
977 _gdk_xgrab_check_destroy (window);
979 g_object_unref (window);
983 update_wm_hints (GdkWindow *window,
986 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
987 GdkWindowObject *private = (GdkWindowObject *)window;
988 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
992 private->state & GDK_WINDOW_STATE_WITHDRAWN)
995 wm_hints.flags = StateHint | InputHint;
996 wm_hints.input = private->accept_focus ? True : False;
997 wm_hints.initial_state = NormalState;
999 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1001 wm_hints.flags |= StateHint;
1002 wm_hints.initial_state = IconicState;
1005 if (toplevel->icon_window && !GDK_WINDOW_DESTROYED (toplevel->icon_window))
1007 wm_hints.flags |= IconWindowHint;
1008 wm_hints.icon_window = GDK_WINDOW_XID (toplevel->icon_window);
1011 if (toplevel->icon_pixmap)
1013 wm_hints.flags |= IconPixmapHint;
1014 wm_hints.icon_pixmap = GDK_PIXMAP_XID (toplevel->icon_pixmap);
1017 if (toplevel->icon_mask)
1019 wm_hints.flags |= IconMaskHint;
1020 wm_hints.icon_mask = GDK_PIXMAP_XID (toplevel->icon_mask);
1023 wm_hints.flags |= WindowGroupHint;
1024 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1026 wm_hints.flags |= WindowGroupHint;
1027 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1030 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1032 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1033 GDK_WINDOW_XID (window),
1038 set_initial_hints (GdkWindow *window)
1040 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1041 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1042 Window xwindow = GDK_WINDOW_XID (window);
1043 GdkWindowObject *private;
1044 GdkToplevelX11 *toplevel;
1048 private = (GdkWindowObject*) window;
1049 toplevel = _gdk_x11_window_get_toplevel (window);
1054 update_wm_hints (window, TRUE);
1056 /* We set the spec hints regardless of whether the spec is supported,
1057 * since it can't hurt and it's kind of expensive to check whether
1063 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1065 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1066 "_NET_WM_STATE_MAXIMIZED_VERT");
1068 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1069 "_NET_WM_STATE_MAXIMIZED_HORZ");
1073 if (private->state & GDK_WINDOW_STATE_STICKY)
1075 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1076 "_NET_WM_STATE_STICKY");
1080 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1082 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1083 "_NET_WM_STATE_FULLSCREEN");
1087 if (private->modal_hint)
1089 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1090 "_NET_WM_STATE_MODAL");
1094 if (toplevel->skip_taskbar_hint)
1096 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1097 "_NET_WM_STATE_SKIP_TASKBAR");
1101 if (toplevel->skip_pager_hint)
1103 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1104 "_NET_WM_STATE_SKIP_PAGER");
1110 XChangeProperty (xdisplay,
1112 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1113 XA_ATOM, 32, PropModeReplace,
1114 (guchar*) atoms, i);
1118 XDeleteProperty (xdisplay,
1120 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1123 if (private->state & GDK_WINDOW_STATE_STICKY)
1125 atoms[0] = 0xFFFFFFFF;
1126 XChangeProperty (xdisplay,
1128 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1129 XA_CARDINAL, 32, PropModeReplace,
1130 (guchar*) atoms, 1);
1134 XDeleteProperty (xdisplay,
1136 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1139 toplevel->map_serial = NextRequest (xdisplay);
1143 show_window_internal (GdkWindow *window,
1146 GdkWindowObject *private;
1148 g_return_if_fail (GDK_IS_WINDOW (window));
1150 private = (GdkWindowObject*) window;
1151 if (!private->destroyed)
1153 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1154 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1155 Window xwindow = GDK_WINDOW_XID (window);
1158 XRaiseWindow (xdisplay, xwindow);
1160 if (!GDK_WINDOW_IS_MAPPED (window))
1162 set_initial_hints (window);
1164 gdk_synthesize_window_state (window,
1165 GDK_WINDOW_STATE_WITHDRAWN,
1169 g_assert (GDK_WINDOW_IS_MAPPED (window));
1171 if (impl->position_info.mapped)
1172 XMapWindow (xdisplay, xwindow);
1177 * gdk_window_show_unraised:
1178 * @window: a #GdkWindow
1180 * Shows a #GdkWindow onscreen, but does not modify its stacking
1181 * order. In contrast, gdk_window_show() will raise the window
1182 * to the top of the window stack.
1184 * On the X11 platform, in Xlib terms, this function calls
1185 * XMapWindow() (it also updates some internal GDK state, which means
1186 * that you can't really use XMapWindow() directly on a GDK window).
1190 gdk_window_show_unraised (GdkWindow *window)
1192 g_return_if_fail (GDK_IS_WINDOW (window));
1194 show_window_internal (window, FALSE);
1199 * @window: a #GdkWindow
1201 * Like gdk_window_show_unraised(), but also raises the window to the
1202 * top of the window stack (moves the window to the front of the
1205 * This function maps a window so it's visible onscreen. Its opposite
1206 * is gdk_window_hide().
1208 * When implementing a #GtkWidget, you should call this function on the widget's
1209 * #GdkWindow as part of the "map" method.
1213 gdk_window_show (GdkWindow *window)
1215 g_return_if_fail (GDK_IS_WINDOW (window));
1217 show_window_internal (window, TRUE);
1222 * @window: a #GdkWindow
1224 * For toplevel windows, withdraws them, so they will no longer be
1225 * known to the window manager; for all windows, unmaps them, so
1226 * they won't be displayed. Normally done automatically as
1227 * part of gtk_widget_hide().
1231 gdk_window_hide (GdkWindow *window)
1233 GdkWindowObject *private;
1235 g_return_if_fail (window != NULL);
1237 private = (GdkWindowObject*) window;
1239 /* We'll get the unmap notify eventually, and handle it then,
1240 * but checking here makes things more consistent if we are
1241 * just doing stuff ourself.
1243 _gdk_xgrab_check_unmap (window,
1244 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1246 /* You can't simply unmap toplevel windows. */
1247 switch (private->window_type)
1249 case GDK_WINDOW_TOPLEVEL:
1250 case GDK_WINDOW_DIALOG:
1251 case GDK_WINDOW_TEMP: /* ? */
1252 gdk_window_withdraw (window);
1256 case GDK_WINDOW_FOREIGN:
1257 case GDK_WINDOW_ROOT:
1258 case GDK_WINDOW_CHILD:
1262 if (!private->destroyed)
1264 if (GDK_WINDOW_IS_MAPPED (window))
1265 gdk_synthesize_window_state (window,
1267 GDK_WINDOW_STATE_WITHDRAWN);
1269 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1271 _gdk_window_clear_update_area (window);
1273 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1274 GDK_WINDOW_XID (window));
1279 * gdk_window_withdraw:
1280 * @window: a toplevel #GdkWindow
1282 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1283 * This function is not really useful as gdk_window_hide() automatically
1284 * withdraws toplevel windows before hiding them.
1288 gdk_window_withdraw (GdkWindow *window)
1290 GdkWindowObject *private;
1292 g_return_if_fail (window != NULL);
1294 private = (GdkWindowObject*) window;
1295 if (!private->destroyed)
1297 if (GDK_WINDOW_IS_MAPPED (window))
1298 gdk_synthesize_window_state (window,
1300 GDK_WINDOW_STATE_WITHDRAWN);
1302 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1304 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1305 GDK_WINDOW_XID (window), 0);
1311 * @window: a #GdkWindow
1312 * @x: X coordinate relative to window's parent
1313 * @y: Y coordinate relative to window's parent
1315 * Repositions a window relative to its parent window.
1316 * For toplevel windows, window managers may ignore or modify the move;
1317 * you should probably use gtk_window_move() on a #GtkWindow widget
1318 * anyway, instead of using GDK functions. For child windows,
1319 * the move will reliably succeed.
1321 * If you're also planning to resize the window, use gdk_window_move_resize()
1322 * to both move and resize simultaneously, for a nicer visual effect.
1325 gdk_window_move (GdkWindow *window,
1329 GdkWindowObject *private = (GdkWindowObject *)window;
1330 GdkWindowImplX11 *impl;
1332 g_return_if_fail (window != NULL);
1333 g_return_if_fail (GDK_IS_WINDOW (window));
1335 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1337 if (!GDK_WINDOW_DESTROYED (window))
1339 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1340 _gdk_window_move_resize_child (window, x, y,
1341 impl->width, impl->height);
1344 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1345 GDK_WINDOW_XID (window),
1352 * gdk_window_resize:
1353 * @window: a #GdkWindow
1354 * @width: new width of the window
1355 * @height: new height of the window
1357 * Resizes @window; for toplevel windows, asks the window manager to resize
1358 * the window. The window manager may not allow the resize. When using GTK+,
1359 * use gtk_window_resize() instead of this low-level GDK function.
1361 * Windows may not be resized below 1x1.
1363 * If you're also planning to move the window, use gdk_window_move_resize()
1364 * to both move and resize simultaneously, for a nicer visual effect.
1367 gdk_window_resize (GdkWindow *window,
1371 GdkWindowObject *private;
1373 g_return_if_fail (window != NULL);
1374 g_return_if_fail (GDK_IS_WINDOW (window));
1381 private = (GdkWindowObject*) window;
1383 if (!GDK_WINDOW_DESTROYED (window))
1385 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1386 _gdk_window_move_resize_child (window, private->x, private->y,
1390 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1392 if (width != impl->width || height != impl->height)
1393 private->resize_count += 1;
1395 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1396 GDK_WINDOW_XID (window),
1403 * gdk_window_move_resize:
1404 * @window: a #GdkWindow
1405 * @x: new X position relative to window's parent
1406 * @y: new Y position relative to window's parent
1408 * @height: new height
1410 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1411 * except that both operations are performed at once, avoiding strange
1412 * visual effects. (i.e. the user may be able to see the window first
1413 * move, then resize, if you don't use gdk_window_move_resize().)
1416 gdk_window_move_resize (GdkWindow *window,
1422 GdkWindowObject *private;
1424 g_return_if_fail (window != NULL);
1425 g_return_if_fail (GDK_IS_WINDOW (window));
1432 private = (GdkWindowObject*) window;
1434 if (!GDK_WINDOW_DESTROYED (window))
1436 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1437 _gdk_window_move_resize_child (window, x, y, width, height);
1440 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1442 if (width != impl->width || height != impl->height)
1443 private->resize_count += 1;
1445 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1446 GDK_WINDOW_XID (window),
1447 x, y, width, height);
1453 * gdk_window_reparent:
1454 * @window: a #GdkWindow
1455 * @new_parent: new parent to move @window into
1456 * @x: X location inside the new parent
1457 * @y: Y location inside the new parent
1459 * Reparents @window into the given @new_parent. The window being
1460 * reparented will be unmapped as a side effect.
1464 gdk_window_reparent (GdkWindow *window,
1465 GdkWindow *new_parent,
1469 GdkDisplay *display;
1470 GdkWindowObject *window_private;
1471 GdkWindowObject *parent_private;
1472 GdkWindowObject *old_parent_private;
1474 g_return_if_fail (window != NULL);
1475 g_return_if_fail (GDK_IS_WINDOW (window));
1476 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1477 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1480 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1482 display = GDK_WINDOW_DISPLAY (window);
1484 window_private = (GdkWindowObject*) window;
1485 old_parent_private = (GdkWindowObject*)window_private->parent;
1486 parent_private = (GdkWindowObject*) new_parent;
1488 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1489 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1490 GDK_WINDOW_XID (window),
1491 GDK_WINDOW_XID (new_parent),
1494 window_private->x = x;
1495 window_private->y = y;
1497 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1500 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1501 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1503 window_private->parent = (GdkWindowObject *)new_parent;
1505 /* Switch the window type as appropriate */
1507 switch (GDK_WINDOW_TYPE (new_parent))
1509 case GDK_WINDOW_ROOT:
1510 case GDK_WINDOW_FOREIGN:
1511 /* Now a toplevel */
1512 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1513 set_wm_protocols (window);
1515 case GDK_WINDOW_TOPLEVEL:
1516 case GDK_WINDOW_CHILD:
1517 case GDK_WINDOW_DIALOG:
1518 case GDK_WINDOW_TEMP:
1519 if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1520 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
1522 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1524 /* If we were being sophisticated, we'd save the old window type
1525 * here, and restore it if we were reparented back to the
1526 * toplevel. However, the difference between different types
1527 * of toplevels only really matters on creation anyways.
1529 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1532 gdk_toplevel_x11_free_contents (impl->toplevel);
1533 g_free (impl->toplevel);
1534 impl->toplevel = NULL;
1539 if (old_parent_private)
1540 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1542 if ((old_parent_private &&
1543 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1544 (!old_parent_private && parent_private->guffaw_gravity))
1545 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1547 parent_private->children = g_list_prepend (parent_private->children, window);
1548 _gdk_window_init_position (GDK_WINDOW (window_private));
1552 _gdk_windowing_window_clear_area (GdkWindow *window,
1558 g_return_if_fail (window != NULL);
1559 g_return_if_fail (GDK_IS_WINDOW (window));
1561 if (!GDK_WINDOW_DESTROYED (window))
1562 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1563 x, y, width, height, False);
1567 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1573 g_return_if_fail (window != NULL);
1574 g_return_if_fail (GDK_IS_WINDOW (window));
1576 if (!GDK_WINDOW_DESTROYED (window))
1577 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1578 x, y, width, height, True);
1584 * @window: a #GdkWindow
1586 * Raises @window to the top of the Z-order (stacking order), so that
1587 * other windows with the same parent window appear below @window.
1588 * This is true whether or not the windows are visible.
1590 * If @window is a toplevel, the window manager may choose to deny the
1591 * request to move the window in the Z-order, gdk_window_raise() only
1592 * requests the restack, does not guarantee it.
1596 gdk_window_raise (GdkWindow *window)
1598 g_return_if_fail (window != NULL);
1599 g_return_if_fail (GDK_IS_WINDOW (window));
1601 if (!GDK_WINDOW_DESTROYED (window))
1602 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1607 * @window: a #GdkWindow
1609 * Lowers @window to the bottom of the Z-order (stacking order), so that
1610 * other windows with the same parent window appear above @window.
1611 * This is true whether or not the other windows are visible.
1613 * If @window is a toplevel, the window manager may choose to deny the
1614 * request to move the window in the Z-order, gdk_window_lower() only
1615 * requests the restack, does not guarantee it.
1617 * Note that gdk_window_show() raises the window again, so don't call this
1618 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1622 gdk_window_lower (GdkWindow *window)
1624 g_return_if_fail (window != NULL);
1625 g_return_if_fail (GDK_IS_WINDOW (window));
1627 if (!GDK_WINDOW_DESTROYED (window))
1628 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1633 * @window: a #GdkWindow
1634 * @timestamp: timestamp of the event triggering the window focus
1636 * Sets keyboard focus to @window. If @window is not onscreen this
1637 * will not work. In most cases, gtk_window_present() should be used on
1638 * a #GtkWindow, rather than calling this function.
1642 gdk_window_focus (GdkWindow *window,
1645 GdkDisplay *display;
1647 g_return_if_fail (GDK_IS_WINDOW (window));
1649 if (GDK_WINDOW_DESTROYED (window))
1652 display = GDK_WINDOW_DISPLAY (window);
1654 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1655 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1659 xev.xclient.type = ClientMessage;
1660 xev.xclient.serial = 0;
1661 xev.xclient.send_event = True;
1662 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1663 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1664 "_NET_ACTIVE_WINDOW");
1665 xev.xclient.format = 32;
1666 xev.xclient.data.l[0] = 0;
1667 xev.xclient.data.l[1] = 0;
1668 xev.xclient.data.l[2] = 0;
1669 xev.xclient.data.l[3] = 0;
1670 xev.xclient.data.l[4] = 0;
1672 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1673 SubstructureRedirectMask | SubstructureNotifyMask,
1678 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1680 /* There is no way of knowing reliably whether we are viewable;
1681 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1683 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1690 * gdk_window_set_hints:
1691 * @window: a #GdkWindow
1692 * @x: ignored field, does not matter
1693 * @y: ignored field, does not matter
1694 * @min_width: minimum width hint
1695 * @min_height: minimum height hint
1696 * @max_width: max width hint
1697 * @max_height: max height hint
1698 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
1700 * This function is broken and useless and you should ignore it.
1701 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
1702 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
1703 * depending on what you're trying to do.
1705 * If using GDK directly, use gdk_window_set_geometry_hints().
1709 gdk_window_set_hints (GdkWindow *window,
1718 XSizeHints size_hints;
1720 g_return_if_fail (window != NULL);
1721 g_return_if_fail (GDK_IS_WINDOW (window));
1723 if (GDK_WINDOW_DESTROYED (window))
1726 size_hints.flags = 0;
1728 if (flags & GDK_HINT_POS)
1730 size_hints.flags |= PPosition;
1735 if (flags & GDK_HINT_MIN_SIZE)
1737 size_hints.flags |= PMinSize;
1738 size_hints.min_width = min_width;
1739 size_hints.min_height = min_height;
1742 if (flags & GDK_HINT_MAX_SIZE)
1744 size_hints.flags |= PMaxSize;
1745 size_hints.max_width = max_width;
1746 size_hints.max_height = max_height;
1749 /* FIXME: Would it be better to delete this property if
1750 * flags == 0? It would save space on the server
1752 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1753 GDK_WINDOW_XID (window),
1758 * gdk_window_set_type_hint:
1759 * @window: A toplevel #GdkWindow
1760 * @hint: A hint of the function this window will have
1762 * The application can use this call to provide a hint to the window
1763 * manager about the functionality of a window. The window manager
1764 * can use this information when determining the decoration and behaviour
1767 * The hint must be set before the window is mapped.
1770 gdk_window_set_type_hint (GdkWindow *window,
1771 GdkWindowTypeHint hint)
1773 GdkDisplay *display;
1776 g_return_if_fail (window != NULL);
1777 g_return_if_fail (GDK_IS_WINDOW (window));
1779 if (GDK_WINDOW_DESTROYED (window))
1782 display = gdk_drawable_get_display (window);
1786 case GDK_WINDOW_TYPE_HINT_DIALOG:
1787 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1789 case GDK_WINDOW_TYPE_HINT_MENU:
1790 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1792 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1793 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1795 case GDK_WINDOW_TYPE_HINT_UTILITY:
1796 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1798 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1799 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1801 case GDK_WINDOW_TYPE_HINT_DOCK:
1802 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1804 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1805 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1808 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1810 case GDK_WINDOW_TYPE_HINT_NORMAL:
1811 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1815 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1816 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1817 XA_ATOM, 32, PropModeReplace,
1818 (guchar *)&atom, 1);
1823 gdk_wmspec_change_state (gboolean add,
1828 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1831 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1832 #define _NET_WM_STATE_ADD 1 /* add/set property */
1833 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1835 xev.xclient.type = ClientMessage;
1836 xev.xclient.serial = 0;
1837 xev.xclient.send_event = True;
1838 xev.xclient.window = GDK_WINDOW_XID (window);
1839 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1840 xev.xclient.format = 32;
1841 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1842 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1843 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1844 xev.xclient.data.l[3] = 0;
1845 xev.xclient.data.l[4] = 0;
1847 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1848 SubstructureRedirectMask | SubstructureNotifyMask,
1853 * gdk_window_set_modal_hint:
1854 * @window: A toplevel #GdkWindow
1855 * @modal: TRUE if the window is modal, FALSE otherwise.
1857 * The application can use this hint to tell the window manager
1858 * that a certain window has modal behaviour. The window manager
1859 * can use this information to handle modal windows in a special
1862 * You should only use this on windows for which you have
1863 * previously called #gdk_window_set_transient_for()
1866 gdk_window_set_modal_hint (GdkWindow *window,
1869 GdkWindowObject *private;
1871 g_return_if_fail (window != NULL);
1872 g_return_if_fail (GDK_IS_WINDOW (window));
1874 if (GDK_WINDOW_DESTROYED (window))
1877 private = (GdkWindowObject*) window;
1879 private->modal_hint = modal;
1881 if (GDK_WINDOW_IS_MAPPED (window))
1882 gdk_wmspec_change_state (modal, window,
1883 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1888 * gdk_window_set_skip_taskbar_hint:
1889 * @window: a toplevel #GdkWindow
1890 * @skips_taskbar: %TRUE to skip the taskbar
1892 * Toggles whether a window should appear in a task list or window
1893 * list. If a window's semantic type as specified with
1894 * gdk_window_set_type_hint() already fully describes the window, this
1895 * function should NOT be called in addition, instead you should allow
1896 * the window to be treated according to standard policy for its
1902 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
1903 gboolean skips_taskbar)
1905 GdkToplevelX11 *toplevel;
1907 g_return_if_fail (window != NULL);
1908 g_return_if_fail (GDK_IS_WINDOW (window));
1909 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1911 if (GDK_WINDOW_DESTROYED (window))
1914 toplevel = _gdk_x11_window_get_toplevel (window);
1915 toplevel->skip_taskbar_hint = skips_taskbar;
1917 if (GDK_WINDOW_IS_MAPPED (window))
1918 gdk_wmspec_change_state (skips_taskbar, window,
1919 gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE),
1924 * gdk_window_set_skip_pager_hint:
1925 * @window: a toplevel #GdkWindow
1926 * @skips_pager: %TRUE to skip the pager
1928 * Toggles whether a window should appear in a pager (workspace
1929 * switcher, or other desktop utility program that displays a small
1930 * thumbnail representation of the windows on the desktop). If a
1931 * window's semantic type as specified with gdk_window_set_type_hint()
1932 * already fully describes the window, this function should NOT be
1933 * called in addition, instead you should allow the window to be
1934 * treated according to standard policy for its semantic type.
1939 gdk_window_set_skip_pager_hint (GdkWindow *window,
1940 gboolean skips_pager)
1942 GdkToplevelX11 *toplevel;
1944 g_return_if_fail (window != NULL);
1945 g_return_if_fail (GDK_IS_WINDOW (window));
1946 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1948 if (GDK_WINDOW_DESTROYED (window))
1951 toplevel = _gdk_x11_window_get_toplevel (window);
1952 toplevel->skip_pager_hint = skips_pager;
1954 if (GDK_WINDOW_IS_MAPPED (window))
1955 gdk_wmspec_change_state (skips_pager, window,
1956 gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE),
1961 * gdk_window_set_geometry_hints:
1962 * @window: a toplevel #GdkWindow
1963 * @geometry: geometry hints
1964 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
1966 * Sets the geometry hints for @window. Hints flagged in @geom_mask
1967 * are set, hints not flagged in @geom_mask are unset.
1968 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
1970 * This function provides hints to the windowing system about
1971 * acceptable sizes for a toplevel window. The purpose of
1972 * this is to constrain user resizing, but the windowing system
1973 * will typically (but is not required to) also constrain the
1974 * current size of the window to the provided values and
1975 * constrain programatic resizing via gdk_window_resize() or
1976 * gdk_window_move_resize().
1978 * Note that on X11, this effect has no effect on windows
1979 * of type GDK_WINDOW_TEMP or windows where override_redirect
1980 * has been turned on via gdk_window_set_override_redirect()
1981 * since these windows are not resizable by the user.
1983 * Since you can't count on the windowing system doing the
1984 * constraints for programmatic resizes, you should generally
1985 * call gdk_window_constrain_size() yourself to determine
1986 * appropriate sizes.
1990 gdk_window_set_geometry_hints (GdkWindow *window,
1991 GdkGeometry *geometry,
1992 GdkWindowHints geom_mask)
1994 XSizeHints size_hints;
1996 g_return_if_fail (window != NULL);
1997 g_return_if_fail (GDK_IS_WINDOW (window));
1999 if (GDK_WINDOW_DESTROYED (window))
2002 size_hints.flags = 0;
2004 if (geom_mask & GDK_HINT_POS)
2006 size_hints.flags |= PPosition;
2007 /* We need to initialize the following obsolete fields because KWM
2008 * apparently uses these fields if they are non-zero.
2015 if (geom_mask & GDK_HINT_USER_POS)
2017 size_hints.flags |= USPosition;
2020 if (geom_mask & GDK_HINT_USER_SIZE)
2022 size_hints.flags |= USSize;
2025 if (geom_mask & GDK_HINT_MIN_SIZE)
2027 size_hints.flags |= PMinSize;
2028 size_hints.min_width = geometry->min_width;
2029 size_hints.min_height = geometry->min_height;
2032 if (geom_mask & GDK_HINT_MAX_SIZE)
2034 size_hints.flags |= PMaxSize;
2035 size_hints.max_width = MAX (geometry->max_width, 1);
2036 size_hints.max_height = MAX (geometry->max_height, 1);
2039 if (geom_mask & GDK_HINT_BASE_SIZE)
2041 size_hints.flags |= PBaseSize;
2042 size_hints.base_width = geometry->base_width;
2043 size_hints.base_height = geometry->base_height;
2046 if (geom_mask & GDK_HINT_RESIZE_INC)
2048 size_hints.flags |= PResizeInc;
2049 size_hints.width_inc = geometry->width_inc;
2050 size_hints.height_inc = geometry->height_inc;
2053 if (geom_mask & GDK_HINT_ASPECT)
2055 size_hints.flags |= PAspect;
2056 if (geometry->min_aspect <= 1)
2058 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2059 size_hints.min_aspect.y = 65536;
2063 size_hints.min_aspect.x = 65536;
2064 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2066 if (geometry->max_aspect <= 1)
2068 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2069 size_hints.max_aspect.y = 65536;
2073 size_hints.max_aspect.x = 65536;
2074 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2078 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2080 size_hints.flags |= PWinGravity;
2081 size_hints.win_gravity = geometry->win_gravity;
2084 /* FIXME: Would it be better to delete this property if
2085 * geom_mask == 0? It would save space on the server
2087 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2088 GDK_WINDOW_XID (window),
2093 gdk_window_get_geometry_hints (GdkWindow *window,
2094 GdkGeometry *geometry,
2095 GdkWindowHints *geom_mask)
2097 XSizeHints size_hints;
2098 glong junk_size_mask = 0;
2100 g_return_if_fail (GDK_IS_WINDOW (window));
2101 g_return_if_fail (geometry != NULL);
2102 g_return_if_fail (geom_mask != NULL);
2106 if (GDK_WINDOW_DESTROYED (window))
2109 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2110 GDK_WINDOW_XID (window),
2115 if (size_hints.flags & PMinSize)
2117 *geom_mask |= GDK_HINT_MIN_SIZE;
2118 geometry->min_width = size_hints.min_width;
2119 geometry->min_height = size_hints.min_height;
2122 if (size_hints.flags & PMaxSize)
2124 *geom_mask |= GDK_HINT_MAX_SIZE;
2125 geometry->max_width = MAX (size_hints.max_width, 1);
2126 geometry->max_height = MAX (size_hints.max_height, 1);
2129 if (size_hints.flags & PResizeInc)
2131 *geom_mask |= GDK_HINT_RESIZE_INC;
2132 geometry->width_inc = size_hints.width_inc;
2133 geometry->height_inc = size_hints.height_inc;
2136 if (size_hints.flags & PAspect)
2138 *geom_mask |= GDK_HINT_ASPECT;
2140 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
2141 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
2144 if (size_hints.flags & PWinGravity)
2146 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2147 geometry->win_gravity = size_hints.win_gravity;
2152 utf8_is_latin1 (const gchar *str)
2154 const char *p = str;
2158 gunichar ch = g_utf8_get_char (p);
2163 p = g_utf8_next_char (p);
2169 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2170 * convertable to STRING, otherwise, set it as compound text
2173 set_text_property (GdkDisplay *display,
2176 const gchar *utf8_str)
2178 guchar *prop_text = NULL;
2183 if (utf8_is_latin1 (utf8_str))
2185 prop_type = XA_STRING;
2186 prop_text = gdk_utf8_to_string_target (utf8_str);
2187 prop_length = prop_text ? strlen (prop_text) : 0;
2194 gdk_utf8_to_compound_text_for_display (display,
2195 utf8_str, &gdk_type, &prop_format,
2196 &prop_text, &prop_length);
2197 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2202 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2205 prop_type, prop_format,
2206 PropModeReplace, prop_text,
2209 gdk_free_compound_text (prop_text);
2213 /* Set WM_NAME and _NET_WM_NAME
2216 set_wm_name (GdkDisplay *display,
2220 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2221 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2222 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2223 PropModeReplace, name, strlen (name));
2225 set_text_property (display, xwindow,
2226 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2231 * gdk_window_set_title:
2232 * @window: a toplevel #GdkWindow
2233 * @title: title of @window
2235 * Sets the title of a toplevel window, to be displayed in the titlebar.
2236 * If you haven't explicitly set the icon name for the window
2237 * (using gdk_window_set_icon_name()), the icon name will be set to
2238 * @title as well. @title must be in UTF-8 encoding (as with all
2239 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2242 gdk_window_set_title (GdkWindow *window,
2245 GdkDisplay *display;
2249 g_return_if_fail (window != NULL);
2250 g_return_if_fail (GDK_IS_WINDOW (window));
2251 g_return_if_fail (title != NULL);
2253 if (GDK_WINDOW_DESTROYED (window))
2256 display = gdk_drawable_get_display (window);
2257 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2258 xwindow = GDK_WINDOW_XID (window);
2260 set_wm_name (display, xwindow, title);
2262 if (!gdk_window_icon_name_set (window))
2264 XChangeProperty (xdisplay, xwindow,
2265 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2266 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2267 PropModeReplace, title, strlen (title));
2269 set_text_property (display, xwindow,
2270 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2276 * gdk_window_set_role:
2277 * @window: a toplevel #GdkWindow
2278 * @role: a string indicating its role
2280 * When using GTK+, typically you should use gtk_window_set_role() instead
2281 * of this low-level function.
2283 * The window manager and session manager use a window's role to
2284 * distinguish it from other kinds of window in the same application.
2285 * When an application is restarted after being saved in a previous
2286 * session, all windows with the same title and role are treated as
2287 * interchangeable. So if you have two windows with the same title
2288 * that should be distinguished for session management purposes, you
2289 * should set the role on those windows. It doesn't matter what string
2290 * you use for the role, as long as you have a different role for each
2291 * non-interchangeable kind of window.
2295 gdk_window_set_role (GdkWindow *window,
2298 GdkDisplay *display;
2300 g_return_if_fail (window != NULL);
2301 g_return_if_fail (GDK_IS_WINDOW (window));
2303 display = gdk_drawable_get_display (window);
2305 if (!GDK_WINDOW_DESTROYED (window))
2308 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2309 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2310 XA_STRING, 8, PropModeReplace, role, strlen (role));
2312 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2313 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2318 * gdk_window_set_transient_for:
2319 * @window: a toplevel #GdkWindow
2320 * @parent: another toplevel #GdkWindow
2322 * Indicates to the window manager that @window is a transient dialog
2323 * associated with the application window @parent. This allows the
2324 * window manager to do things like center @window on @parent and
2325 * keep @window above @parent.
2327 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2332 gdk_window_set_transient_for (GdkWindow *window,
2335 GdkWindowObject *private;
2336 GdkWindowObject *parent_private;
2338 g_return_if_fail (window != NULL);
2339 g_return_if_fail (GDK_IS_WINDOW (window));
2341 private = (GdkWindowObject*) window;
2342 parent_private = (GdkWindowObject*) parent;
2344 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2345 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2346 GDK_WINDOW_XID (window),
2347 GDK_WINDOW_XID (parent));
2351 * gdk_window_set_background:
2352 * @window: a #GdkWindow
2353 * @color: an allocated #GdkColor
2355 * Sets the background color of @window. (However, when using GTK+,
2356 * set the background of a widget with gtk_widget_modify_bg() - if
2357 * you're an application - or gtk_style_set_background() - if you're
2358 * implementing a custom widget.)
2360 * The @color must be allocated; gdk_rgb_find_color() is the best way
2361 * to allocate a color.
2363 * See also gdk_window_set_back_pixmap().
2367 gdk_window_set_background (GdkWindow *window,
2370 GdkWindowObject *private = (GdkWindowObject *)window;
2372 g_return_if_fail (window != NULL);
2373 g_return_if_fail (GDK_IS_WINDOW (window));
2375 if (!GDK_WINDOW_DESTROYED (window))
2376 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2377 GDK_WINDOW_XID (window), color->pixel);
2379 private->bg_color = *color;
2381 if (private->bg_pixmap &&
2382 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2383 private->bg_pixmap != GDK_NO_BG)
2384 g_object_unref (private->bg_pixmap);
2386 private->bg_pixmap = NULL;
2390 * gdk_window_set_back_pixmap:
2391 * @window: a #GdkWindow
2392 * @pixmap: a #GdkPixmap, or %NULL
2393 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2395 * Sets the background pixmap of @window. May also be used to set a background of
2396 * "None" on @window, by setting a background pixmap of %NULL.
2397 * A background pixmap will be tiled, positioning the first tile at the origin of
2398 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2399 * origin of the parent window (useful to align tiles in a parent with tiles
2402 * A background pixmap of %NULL means that the window will have no
2403 * background. A window with no background will never have its
2404 * background filled by the windowing system, instead the window will
2405 * contain whatever pixels were already in the corresponding area of
2408 * The windowing system will normally fill a window with its background
2409 * when the window is obscured then exposed, and when you call
2410 * gdk_window_clear().
2414 gdk_window_set_back_pixmap (GdkWindow *window,
2416 gboolean parent_relative)
2418 GdkWindowObject *private = (GdkWindowObject *)window;
2421 g_return_if_fail (window != NULL);
2422 g_return_if_fail (GDK_IS_WINDOW (window));
2423 g_return_if_fail (pixmap == NULL || !parent_relative);
2424 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2426 if (private->bg_pixmap &&
2427 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2428 private->bg_pixmap != GDK_NO_BG)
2429 g_object_unref (private->bg_pixmap);
2431 if (parent_relative)
2433 xpixmap = ParentRelative;
2434 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2440 g_object_ref (pixmap);
2441 private->bg_pixmap = pixmap;
2442 xpixmap = GDK_PIXMAP_XID (pixmap);
2447 private->bg_pixmap = GDK_NO_BG;
2451 if (!GDK_WINDOW_DESTROYED (window))
2452 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2453 GDK_WINDOW_XID (window), xpixmap);
2457 * gdk_window_set_cursor:
2458 * @window: a #GdkWindow
2461 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2462 * gdk_cursor_new_from_pixmap() to create the cursor.
2463 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2464 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2465 * to gdk_window_set_cursor() means that @window will use the cursor of
2466 * its parent window. Most windows should use this default.
2470 gdk_window_set_cursor (GdkWindow *window,
2473 GdkCursorPrivate *cursor_private;
2476 g_return_if_fail (window != NULL);
2477 g_return_if_fail (GDK_IS_WINDOW (window));
2479 cursor_private = (GdkCursorPrivate*) cursor;
2484 xcursor = cursor_private->xcursor;
2486 if (!GDK_WINDOW_DESTROYED (window))
2487 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2488 GDK_WINDOW_XID (window),
2493 * gdk_window_get_geometry:
2494 * @window: a #GdkWindow
2495 * @x: return location for X coordinate of window (relative to its parent)
2496 * @y: return location for Y coordinate of window (relative to its parent)
2497 * @width: return location for width of window
2498 * @height: return location for height of window
2499 * @depth: return location for bit depth of window
2501 * Any of the return location arguments to this function may be %NULL,
2502 * if you aren't interested in getting the value of that field.
2504 * The X and Y coordinates returned are relative to the parent window
2505 * of @window, which for toplevels usually means relative to the
2506 * window decorations (titlebar, etc.) rather than relative to the
2507 * root window (screen-size background window).
2509 * On the X11 platform, the geometry is obtained from the X server,
2510 * so reflects the latest position of @window; this may be out-of-sync
2511 * with the position of @window delivered in the most-recently-processed
2512 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2513 * position from the most recent configure event.
2517 gdk_window_get_geometry (GdkWindow *window,
2529 guint tborder_width;
2532 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2536 GDK_NOTE (MULTIHEAD,
2537 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2538 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
2541 if (!GDK_WINDOW_DESTROYED (window))
2543 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2544 GDK_WINDOW_XID (window),
2545 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2561 * gdk_window_get_origin:
2562 * @window: a #GdkWindow
2563 * @x: return location for X coordinate
2564 * @y: return location for Y coordinate
2566 * Obtains the position of a window in root window coordinates.
2567 * (Compare with gdk_window_get_position() and
2568 * gdk_window_get_geometry() which return the position of a window
2569 * relative to its parent window.)
2571 * Return value: not meaningful, ignore
2574 gdk_window_get_origin (GdkWindow *window,
2583 g_return_val_if_fail (window != NULL, 0);
2585 if (!GDK_WINDOW_DESTROYED (window))
2587 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2588 GDK_WINDOW_XID (window),
2589 GDK_WINDOW_XROOTWIN (window),
2605 * gdk_window_get_deskrelative_origin:
2606 * @window: a toplevel #GdkWindow
2607 * @x: return location for X coordinate
2608 * @y: return location for Y coordinate
2610 * This gets the origin of a #GdkWindow relative to
2611 * an Enlightenment-window-manager desktop. As long as you don't
2612 * assume that the user's desktop/workspace covers the entire
2613 * root window (i.e. you don't assume that the desktop begins
2614 * at root window coordinate 0,0) this function is not necessary.
2615 * It's deprecated for that reason.
2617 * Return value: not meaningful
2620 gdk_window_get_deskrelative_origin (GdkWindow *window,
2624 gboolean return_val = FALSE;
2625 gint num_children, format_return;
2626 Window win, *child, parent, root;
2631 gulong number_return, bytes_after_return;
2632 guchar *data_return;
2634 g_return_val_if_fail (window != NULL, FALSE);
2635 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2637 if (!GDK_WINDOW_DESTROYED (window))
2639 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2640 "ENLIGHTENMENT_DESKTOP");
2641 win = GDK_WINDOW_XID (window);
2643 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
2644 &child, (unsigned int *)&num_children))
2646 if ((child) && (num_children > 0))
2658 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
2659 False, XA_CARDINAL, &type_return, &format_return,
2660 &number_return, &bytes_after_return, &data_return);
2662 if (type_return == XA_CARDINAL)
2664 XFree (data_return);
2669 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2670 GDK_WINDOW_XID (window),
2685 * gdk_window_get_root_origin:
2686 * @window: a toplevel #GdkWindow
2687 * @x: return location for X position of window frame
2688 * @y: return location for Y position of window frame
2690 * Obtains the top-left corner of the window manager frame in root
2691 * window coordinates.
2695 gdk_window_get_root_origin (GdkWindow *window,
2701 g_return_if_fail (GDK_IS_WINDOW (window));
2703 gdk_window_get_frame_extents (window, &rect);
2713 * gdk_window_get_frame_extents:
2714 * @window: a toplevel #GdkWindow
2715 * @rect: rectangle to fill with bounding box of the window frame
2717 * Obtains the bounding box of the window, including window manager
2718 * titlebar/borders if any. The frame position is given in root window
2719 * coordinates. To get the position of the window itself (rather than
2720 * the frame) in root window coordinates, use gdk_window_get_origin().
2724 gdk_window_get_frame_extents (GdkWindow *window,
2727 GdkWindowObject *private;
2732 unsigned int nchildren;
2734 g_return_if_fail (GDK_IS_WINDOW (window));
2735 g_return_if_fail (rect != NULL);
2737 private = (GdkWindowObject*) window;
2744 if (GDK_WINDOW_DESTROYED (window))
2747 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2748 private = (GdkWindowObject*) private->parent;
2750 /* Refine our fallback answer a bit using local information */
2751 rect->x = private->x;
2752 rect->y = private->y;
2753 gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height);
2755 if (GDK_WINDOW_DESTROYED (private))
2758 gdk_error_trap_push();
2760 xparent = GDK_WINDOW_XID (window);
2764 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
2766 &children, &nchildren))
2772 while (xparent != root);
2774 if (xparent == root)
2776 unsigned int ww, wh, wb, wd;
2779 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
2789 gdk_error_trap_pop ();
2793 _gdk_windowing_get_pointer (GdkDisplay *display,
2797 GdkModifierType *mask)
2799 GdkScreen *default_screen;
2807 if (display->closed)
2810 default_screen = gdk_display_get_default_screen (display);
2812 XQueryPointer (GDK_SCREEN_XDISPLAY (default_screen),
2813 GDK_SCREEN_XROOTWIN (default_screen),
2814 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2818 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
2819 *screen = gdk_drawable_get_screen (gdk_root);
2828 _gdk_windowing_window_get_pointer (GdkDisplay *display,
2832 GdkModifierType *mask)
2834 GdkWindow *return_val;
2840 unsigned int xmask = 0;
2841 gint xoffset, yoffset;
2843 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2845 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2848 if (!GDK_WINDOW_DESTROYED (window) &&
2849 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
2850 GDK_WINDOW_XID (window),
2851 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
2854 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
2857 *x = winx + xoffset;
2858 *y = winy + yoffset;
2865 _gdk_windowing_window_at_pointer (GdkDisplay *display,
2874 Window xwindow_last = 0;
2876 int rootx = -1, rooty = -1;
2880 screen = gdk_display_get_default_screen (display);
2882 xwindow = GDK_SCREEN_XROOTWIN (screen);
2883 xdisplay = GDK_SCREEN_XDISPLAY (screen);
2885 /* This function really only works if the mouse pointer is held still
2886 * during its operation. If it moves from one leaf window to another
2887 * than we'll end up with inaccurate values for win_x, win_y
2890 gdk_x11_display_grab (display);
2891 XQueryPointer (xdisplay, xwindow,
2892 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
2894 if (root == xwindow)
2901 xwindow_last = xwindow;
2902 XQueryPointer (xdisplay, xwindow,
2903 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
2905 gdk_x11_display_ungrab (display);
2907 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
2909 *win_x = window ? winx : -1;
2910 *win_y = window ? winy : -1;
2916 * gdk_window_get_events:
2917 * @window: a #GdkWindow
2919 * Gets the event mask for @window. See gdk_window_set_events().
2921 * Return value: event mask for @window
2924 gdk_window_get_events (GdkWindow *window)
2926 XWindowAttributes attrs;
2927 GdkEventMask event_mask;
2929 g_return_val_if_fail (window != NULL, 0);
2930 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2932 if (GDK_WINDOW_DESTROYED (window))
2936 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2937 GDK_WINDOW_XID (window),
2940 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2941 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2948 * gdk_window_set_events:
2949 * @window: a #GdkWindow
2950 * @event_mask: event mask for @window
2952 * The event mask for a window determines which events will be reported
2953 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
2954 * means the window should report button press events. The event mask
2955 * is the bitwise OR of values from the #GdkEventMask enumeration.
2959 gdk_window_set_events (GdkWindow *window,
2960 GdkEventMask event_mask)
2965 g_return_if_fail (window != NULL);
2966 g_return_if_fail (GDK_IS_WINDOW (window));
2968 if (!GDK_WINDOW_DESTROYED (window))
2970 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2971 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2972 for (i = 0; i < _gdk_nenvent_masks; i++)
2974 if (event_mask & (1 << (i + 1)))
2975 xevent_mask |= _gdk_event_mask_table[i];
2978 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2979 GDK_WINDOW_XID (window),
2985 gdk_window_add_colormap_windows (GdkWindow *window)
2987 GdkWindow *toplevel;
2988 Window *old_windows;
2989 Window *new_windows;
2992 g_return_if_fail (window != NULL);
2993 g_return_if_fail (GDK_IS_WINDOW (window));
2995 if (GDK_WINDOW_DESTROYED (window))
2997 toplevel = gdk_window_get_toplevel (window);
3000 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3001 GDK_WINDOW_XID (toplevel),
3002 &old_windows, &count))
3007 for (i = 0; i < count; i++)
3008 if (old_windows[i] == GDK_WINDOW_XID (window))
3010 XFree (old_windows);
3014 new_windows = g_new (Window, count + 1);
3016 for (i = 0; i < count; i++)
3017 new_windows[i] = old_windows[i];
3018 new_windows[count] = GDK_WINDOW_XID (window);
3020 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3021 GDK_WINDOW_XID (toplevel),
3022 new_windows, count + 1);
3024 g_free (new_windows);
3026 XFree (old_windows);
3030 gdk_window_have_shape_ext (GdkDisplay *display)
3032 #ifdef HAVE_SHAPE_EXT
3035 return XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display),
3042 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
3045 * This needs the X11 shape extension.
3046 * If not available, shaped windows will look
3047 * ugly, but programs still work. Stefan Wille
3050 * gdk_window_shape_combine_mask:
3051 * @window: a #GdkWindow
3053 * @x: X position of shape mask with respect to @window
3054 * @y: Y position of shape mask with respect to @window
3056 * Applies a shape mask to @window. Pixels in @window corresponding to
3057 * set bits in the @mask will be visible; pixels in @window
3058 * corresponding to unset bits in the @mask will be transparent. This
3059 * gives a non-rectangular window.
3061 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
3062 * parameters are not used.
3064 * On the X11 platform, this uses an X server extension which is
3065 * widely available on most common platforms, but not available on
3066 * very old X servers, and occasionally the implementation will be
3067 * buggy. On servers without the shape extension, this function
3070 * This function works on both toplevel and child windows.
3074 gdk_window_shape_combine_mask (GdkWindow *window,
3079 gint xoffset, yoffset;
3081 g_return_if_fail (window != NULL);
3082 g_return_if_fail (GDK_IS_WINDOW (window));
3084 #ifdef HAVE_SHAPE_EXT
3085 if (GDK_WINDOW_DESTROYED (window))
3088 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3090 if (xoffset != 0 || yoffset != 0)
3092 WARN_SHAPE_TOO_BIG ();
3096 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3100 pixmap = GDK_PIXMAP_XID (mask);
3109 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3110 GDK_WINDOW_XID (window),
3116 #endif /* HAVE_SHAPE_EXT */
3120 * gdk_window_shape_combine_region:
3121 * @window: a #GdkWindow
3122 * @shape_region: region of window to be non-transparent
3123 * @offset_x: X position of @shape_region in @window coordinates
3124 * @offset_y: Y position of @shape_region in @window coordinates
3126 * Makes pixels in @window outside @shape_region be transparent,
3127 * so that the window may be nonrectangular. See also
3128 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
3130 * If @shape_region is %NULL, the shape will be unset, so the whole
3131 * window will be opaque again. @offset_x and @offset_y are ignored
3132 * if @shape_region is %NULL.
3134 * On the X11 platform, this uses an X server extension which is
3135 * widely available on most common platforms, but not available on
3136 * very old X servers, and occasionally the implementation will be
3137 * buggy. On servers without the shape extension, this function
3140 * This function works on both toplevel and child windows.
3144 gdk_window_shape_combine_region (GdkWindow *window,
3145 GdkRegion *shape_region,
3149 gint xoffset, yoffset;
3151 g_return_if_fail (GDK_IS_WINDOW (window));
3153 #ifdef HAVE_SHAPE_EXT
3154 if (GDK_WINDOW_DESTROYED (window))
3157 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3159 if (xoffset != 0 || yoffset != 0)
3161 WARN_SHAPE_TOO_BIG ();
3165 if (shape_region == NULL)
3167 /* Use NULL mask to unset the shape */
3168 gdk_window_shape_combine_mask (window, NULL, 0, 0);
3172 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3175 XRectangle *xrects = NULL;
3177 _gdk_region_get_xrectangles (shape_region,
3181 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3182 GDK_WINDOW_XID (window),
3191 #endif /* HAVE_SHAPE_EXT */
3196 * gdk_window_set_override_redirect:
3197 * @window: a toplevel #GdkWindow
3198 * @override_redirect: %TRUE if window should be override redirect
3200 * An override redirect window is not under the control of the window manager.
3201 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3202 * be entirely under the control of the application. The window manager
3203 * can't see the override redirect window at all.
3205 * Override redirect should only be used for short-lived temporary
3206 * windows, such as popup menus. #GtkMenu uses an override redirect
3207 * window in its implementation, for example.
3211 gdk_window_set_override_redirect (GdkWindow *window,
3212 gboolean override_redirect)
3214 XSetWindowAttributes attr;
3216 g_return_if_fail (window != NULL);
3217 g_return_if_fail (GDK_IS_WINDOW (window));
3219 if (!GDK_WINDOW_DESTROYED (window))
3221 attr.override_redirect = (override_redirect == FALSE)?False:True;
3222 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3223 GDK_WINDOW_XID (window),
3230 * gdk_window_set_accept_focus:
3231 * @window: a toplevel #GdkWindow
3232 * @accept_focus: %TRUE if the window should receive input focus
3234 * Setting @accept_focus to %FALSE hints the desktop environment that the
3235 * window doesn't want to receive input focus.
3237 * On X, it is the responsibility of the window manager to interpret this
3238 * hint. ICCCM-compliant window manager usually respect it.
3243 gdk_window_set_accept_focus (GdkWindow *window,
3244 gboolean accept_focus)
3246 GdkWindowObject *private;
3247 g_return_if_fail (window != NULL);
3248 g_return_if_fail (GDK_IS_WINDOW (window));
3250 private = (GdkWindowObject *)window;
3252 accept_focus = accept_focus != FALSE;
3254 if (private->accept_focus != accept_focus)
3256 private->accept_focus = accept_focus;
3258 if (!GDK_WINDOW_DESTROYED (window))
3259 update_wm_hints (window, FALSE);
3265 * gdk_window_set_icon_list:
3266 * @window: The #GdkWindow toplevel window to set the icon of.
3267 * @pixbufs: A list of pixbufs, of different sizes.
3269 * Sets a list of icons for the window. One of these will be used
3270 * to represent the window when it has been iconified. The icon is
3271 * usually shown in an icon box or some sort of task bar. Which icon
3272 * size is shown depends on the window manager. The window manager
3273 * can scale the icon but setting several size icons can give better
3274 * image quality since the window manager may only need to scale the
3275 * icon by a small amount or not at all.
3279 gdk_window_set_icon_list (GdkWindow *window,
3288 gint width, height, stride;
3291 GdkDisplay *display;
3293 g_return_if_fail (GDK_IS_WINDOW (window));
3295 if (GDK_WINDOW_DESTROYED (window))
3298 display = gdk_drawable_get_display (window);
3306 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3308 width = gdk_pixbuf_get_width (pixbuf);
3309 height = gdk_pixbuf_get_height (pixbuf);
3311 size += 2 + width * height;
3313 l = g_list_next (l);
3316 data = g_malloc (size * sizeof (gulong));
3324 width = gdk_pixbuf_get_width (pixbuf);
3325 height = gdk_pixbuf_get_height (pixbuf);
3326 stride = gdk_pixbuf_get_rowstride (pixbuf);
3327 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3332 pixels = gdk_pixbuf_get_pixels (pixbuf);
3334 for (y = 0; y < height; y++)
3336 for (x = 0; x < width; x++)
3340 r = pixels[y*stride + x*n_channels + 0];
3341 g = pixels[y*stride + x*n_channels + 1];
3342 b = pixels[y*stride + x*n_channels + 2];
3343 if (n_channels >= 4)
3344 a = pixels[y*stride + x*n_channels + 3];
3348 *p++ = a << 24 | r << 16 | g << 8 | b ;
3352 l = g_list_next (l);
3357 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3358 GDK_WINDOW_XID (window),
3359 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3362 (guchar*) data, size);
3366 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3367 GDK_WINDOW_XID (window),
3368 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3375 * gdk_window_set_icon:
3376 * @window: a toplevel #GdkWindow
3377 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3378 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3379 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3381 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3382 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3383 * and gtk_window_set_icon(). If those don't meet your needs, look at
3384 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3385 * want to fall back to gdk_window_set_icon().
3389 gdk_window_set_icon (GdkWindow *window,
3390 GdkWindow *icon_window,
3394 GdkToplevelX11 *toplevel;
3396 g_return_if_fail (window != NULL);
3397 g_return_if_fail (GDK_IS_WINDOW (window));
3398 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3400 if (GDK_WINDOW_DESTROYED (window))
3403 toplevel = _gdk_x11_window_get_toplevel (window);
3405 if (toplevel->icon_window != icon_window)
3407 if (toplevel->icon_window)
3408 g_object_unref (toplevel->icon_window);
3409 toplevel->icon_window = g_object_ref (icon_window);
3412 if (toplevel->icon_pixmap != pixmap)
3415 g_object_ref (pixmap);
3416 if (toplevel->icon_pixmap)
3417 g_object_unref (toplevel->icon_pixmap);
3418 toplevel->icon_pixmap = pixmap;
3421 if (toplevel->icon_mask != mask)
3424 g_object_ref (mask);
3425 if (toplevel->icon_mask)
3426 g_object_unref (toplevel->icon_mask);
3427 toplevel->icon_mask = mask;
3430 update_wm_hints (window, FALSE);
3434 gdk_window_icon_name_set (GdkWindow *window)
3436 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3437 g_quark_from_static_string ("gdk-icon-name-set")));
3441 * gdk_window_set_icon_name:
3442 * @window: a toplevel #GdkWindow
3443 * @name: name of window while iconified (minimized)
3445 * Windows may have a name used while minimized, distinct from the
3446 * name they display in their titlebar. Most of the time this is a bad
3447 * idea from a user interface standpoint. But you can set such a name
3448 * with this function, if you like.
3452 gdk_window_set_icon_name (GdkWindow *window,
3455 GdkDisplay *display;
3457 g_return_if_fail (window != NULL);
3458 g_return_if_fail (GDK_IS_WINDOW (window));
3460 if (GDK_WINDOW_DESTROYED (window))
3463 display = gdk_drawable_get_display (window);
3465 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3466 GUINT_TO_POINTER (TRUE));
3468 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3469 GDK_WINDOW_XID (window),
3470 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3471 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3472 PropModeReplace, name, strlen (name));
3474 set_text_property (display, GDK_WINDOW_XID (window),
3475 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3480 * gdk_window_iconify:
3481 * @window: a toplevel #GdkWindow
3483 * Asks to iconify (minimize) @window. The window manager may choose
3484 * to ignore the request, but normally will honor it. Using
3485 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
3487 * This function only makes sense when @window is a toplevel window.
3491 gdk_window_iconify (GdkWindow *window)
3493 GdkWindowObject *private;
3495 g_return_if_fail (window != NULL);
3496 g_return_if_fail (GDK_IS_WINDOW (window));
3498 if (GDK_WINDOW_DESTROYED (window))
3501 private = (GdkWindowObject*) window;
3503 if (GDK_WINDOW_IS_MAPPED (window))
3505 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3506 GDK_WINDOW_XWINDOW (window),
3507 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3511 /* Flip our client side flag, the real work happens on map. */
3512 gdk_synthesize_window_state (window,
3514 GDK_WINDOW_STATE_ICONIFIED);
3519 * gdk_window_deiconify:
3520 * @window: a toplevel #GdkWindow
3522 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
3523 * choose to ignore the request to deiconify. When using GTK+,
3524 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
3525 * you probably want to use gtk_window_present(), which raises the window, focuses it,
3526 * unminimizes it, and puts it on the current desktop.
3530 gdk_window_deiconify (GdkWindow *window)
3532 GdkWindowObject *private;
3534 g_return_if_fail (window != NULL);
3535 g_return_if_fail (GDK_IS_WINDOW (window));
3537 if (GDK_WINDOW_DESTROYED (window))
3540 private = (GdkWindowObject*) window;
3542 if (GDK_WINDOW_IS_MAPPED (window))
3544 gdk_window_show (window);
3548 /* Flip our client side flag, the real work happens on map. */
3549 gdk_synthesize_window_state (window,
3550 GDK_WINDOW_STATE_ICONIFIED,
3557 * @window: a toplevel #GdkWindow
3559 * "Pins" a window such that it's on all workspaces and does not scroll
3560 * with viewports, for window managers that have scrollable viewports.
3561 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
3563 * On the X11 platform, this function depends on window manager
3564 * support, so may have no effect with many window managers. However,
3565 * GDK will do the best it can to convince the window manager to stick
3566 * the window. For window managers that don't support this operation,
3567 * there's nothing you can do to force it to happen.
3571 gdk_window_stick (GdkWindow *window)
3573 g_return_if_fail (GDK_IS_WINDOW (window));
3575 if (GDK_WINDOW_DESTROYED (window))
3578 if (GDK_WINDOW_IS_MAPPED (window))
3580 /* "stick" means stick to all desktops _and_ do not scroll with the
3581 * viewport. i.e. glue to the monitor glass in all cases.
3586 /* Request stick during viewport scroll */
3587 gdk_wmspec_change_state (TRUE, window,
3588 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3591 /* Request desktop 0xFFFFFFFF */
3592 xev.xclient.type = ClientMessage;
3593 xev.xclient.serial = 0;
3594 xev.xclient.send_event = True;
3595 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3596 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
3597 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3599 xev.xclient.format = 32;
3601 xev.xclient.data.l[0] = 0xFFFFFFFF;
3602 xev.xclient.data.l[1] = 0;
3603 xev.xclient.data.l[2] = 0;
3604 xev.xclient.data.l[3] = 0;
3605 xev.xclient.data.l[4] = 0;
3607 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3608 SubstructureRedirectMask | SubstructureNotifyMask,
3613 /* Flip our client side flag, the real work happens on map. */
3614 gdk_synthesize_window_state (window,
3616 GDK_WINDOW_STATE_STICKY);
3621 * gdk_window_unstick:
3622 * @window: a toplevel #GdkWindow
3624 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
3625 * and gtk_window_unstick().
3629 gdk_window_unstick (GdkWindow *window)
3631 g_return_if_fail (GDK_IS_WINDOW (window));
3633 if (GDK_WINDOW_DESTROYED (window))
3636 if (GDK_WINDOW_IS_MAPPED (window))
3643 gulong *current_desktop;
3644 GdkDisplay *display = gdk_drawable_get_display (window);
3646 /* Request unstick from viewport */
3647 gdk_wmspec_change_state (FALSE, window,
3648 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
3651 /* Get current desktop, then set it; this is a race, but not
3652 * one that matters much in practice.
3654 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
3655 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
3657 False, XA_CARDINAL, &type, &format, &nitems,
3658 &bytes_after, (guchar **)¤t_desktop);
3660 if (type == XA_CARDINAL)
3662 xev.xclient.type = ClientMessage;
3663 xev.xclient.serial = 0;
3664 xev.xclient.send_event = True;
3665 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
3666 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
3667 xev.xclient.format = 32;
3669 xev.xclient.data.l[0] = *current_desktop;
3670 xev.xclient.data.l[1] = 0;
3671 xev.xclient.data.l[2] = 0;
3672 xev.xclient.data.l[3] = 0;
3673 xev.xclient.data.l[4] = 0;
3675 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3676 SubstructureRedirectMask | SubstructureNotifyMask,
3679 XFree (current_desktop);
3684 /* Flip our client side flag, the real work happens on map. */
3685 gdk_synthesize_window_state (window,
3686 GDK_WINDOW_STATE_STICKY,
3693 * gdk_window_maximize:
3694 * @window: a toplevel #GdkWindow
3696 * Maximizes the window. If the window was already maximized, then
3697 * this function does nothing.
3699 * On X11, asks the window manager to maximize @window, if the window
3700 * manager supports this operation. Not all window managers support
3701 * this, and some deliberately ignore it or don't have a concept of
3702 * "maximized"; so you can't rely on the maximization actually
3703 * happening. But it will happen with most standard window managers,
3704 * and GDK makes a best effort to get it to happen.
3706 * On Windows, reliably maximizes the window.
3710 gdk_window_maximize (GdkWindow *window)
3712 g_return_if_fail (GDK_IS_WINDOW (window));
3714 if (GDK_WINDOW_DESTROYED (window))
3717 if (GDK_WINDOW_IS_MAPPED (window))
3718 gdk_wmspec_change_state (TRUE, window,
3719 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3720 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3722 gdk_synthesize_window_state (window,
3724 GDK_WINDOW_STATE_MAXIMIZED);
3728 * gdk_window_unmaximize:
3729 * @window: a toplevel #GdkWindow
3731 * Unmaximizes the window. If the window wasn't maximized, then this
3732 * function does nothing.
3734 * On X11, asks the window manager to unmaximize @window, if the
3735 * window manager supports this operation. Not all window managers
3736 * support this, and some deliberately ignore it or don't have a
3737 * concept of "maximized"; so you can't rely on the unmaximization
3738 * actually happening. But it will happen with most standard window
3739 * managers, and GDK makes a best effort to get it to happen.
3741 * On Windows, reliably unmaximizes the window.
3745 gdk_window_unmaximize (GdkWindow *window)
3747 g_return_if_fail (GDK_IS_WINDOW (window));
3749 if (GDK_WINDOW_DESTROYED (window))
3752 if (GDK_WINDOW_IS_MAPPED (window))
3753 gdk_wmspec_change_state (FALSE, window,
3754 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
3755 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
3757 gdk_synthesize_window_state (window,
3758 GDK_WINDOW_STATE_MAXIMIZED,
3763 * gdk_window_fullscreen:
3764 * @window: a toplevel #GdkWindow
3766 * Moves the window into fullscreen mode. This means the
3767 * window covers the entire screen and is above any panels
3770 * If the window was already fullscreen, then this function does nothing.
3772 * On X11, asks the window manager to put @window in a fullscreen
3773 * state, if the window manager supports this operation. Not all
3774 * window managers support this, and some deliberately ignore it or
3775 * don't have a concept of "fullscreen"; so you can't rely on the
3776 * fullscreenification actually happening. But it will happen with
3777 * most standard window managers, and GDK makes a best effort to get
3783 gdk_window_fullscreen (GdkWindow *window)
3785 g_return_if_fail (GDK_IS_WINDOW (window));
3787 if (GDK_WINDOW_DESTROYED (window))
3790 if (GDK_WINDOW_IS_MAPPED (window))
3791 gdk_wmspec_change_state (TRUE, window,
3792 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3796 gdk_synthesize_window_state (window,
3798 GDK_WINDOW_STATE_FULLSCREEN);
3802 * gdk_window_unfullscreen:
3803 * @window: a toplevel #GdkWindow
3805 * Moves the window out of fullscreen mode. If the window was not
3806 * fullscreen, does nothing.
3808 * On X11, asks the window manager to move @window out of the fullscreen
3809 * state, if the window manager supports this operation. Not all
3810 * window managers support this, and some deliberately ignore it or
3811 * don't have a concept of "fullscreen"; so you can't rely on the
3812 * unfullscreenification actually happening. But it will happen with
3813 * most standard window managers, and GDK makes a best effort to get
3819 gdk_window_unfullscreen (GdkWindow *window)
3821 g_return_if_fail (GDK_IS_WINDOW (window));
3823 if (GDK_WINDOW_DESTROYED (window))
3826 if (GDK_WINDOW_IS_MAPPED (window))
3827 gdk_wmspec_change_state (FALSE, window,
3828 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
3832 gdk_synthesize_window_state (window,
3833 GDK_WINDOW_STATE_FULLSCREEN,
3838 * gdk_window_set_keep_above:
3839 * @window: a toplevel #GdkWindow
3840 * @setting: whether to keep @window above other windows
3842 * Set if @window must be kept above other windows. If the
3843 * window was already above, then this function does nothing.
3845 * On X11, asks the window manager to keep @window above, if the window
3846 * manager supports this operation. Not all window managers support
3847 * this, and some deliberately ignore it or don't have a concept of
3848 * "keep above"; so you can't rely on the window being kept above.
3849 * But it will happen with most standard window managers,
3850 * and GDK makes a best effort to get it to happen.
3855 gdk_window_set_keep_above (GdkWindow *window, gboolean setting)
3857 g_return_if_fail (GDK_IS_WINDOW (window));
3859 if (GDK_WINDOW_DESTROYED (window))
3862 if (GDK_WINDOW_IS_MAPPED (window))
3863 gdk_wmspec_change_state (setting, window,
3864 gdk_atom_intern ("_NET_WM_STATE_ABOVE", setting),
3865 setting ? gdk_atom_intern ("_NET_WM_STATE_BELOW", FALSE)
3868 gdk_synthesize_window_state (window,
3869 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
3870 setting ? GDK_WINDOW_STATE_ABOVE : 0);
3874 * gdk_window_set_keep_below:
3875 * @window: a toplevel #GdkWindow
3876 * @setting: whether to keep @window below other windows
3878 * Set if @window must be kept below other windows. If the
3879 * window was already below, then this function does nothing.
3881 * On X11, asks the window manager to keep @window below, if the window
3882 * manager supports this operation. Not all window managers support
3883 * this, and some deliberately ignore it or don't have a concept of
3884 * "keep below"; so you can't rely on the window being kept below.
3885 * But it will happen with most standard window managers,
3886 * and GDK makes a best effort to get it to happen.
3891 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
3893 g_return_if_fail (GDK_IS_WINDOW (window));
3895 if (GDK_WINDOW_DESTROYED (window))
3898 if (GDK_WINDOW_IS_MAPPED (window))
3899 gdk_wmspec_change_state (setting, window,
3900 gdk_atom_intern ("_NET_WM_STATE_BELOW", setting),
3901 setting ? gdk_atom_intern ("_NET_WM_STATE_ABOVE", FALSE)
3904 gdk_synthesize_window_state (window,
3905 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
3906 setting ? GDK_WINDOW_STATE_BELOW : 0);
3910 * gdk_window_get_group:
3911 * @window: a toplevel #GdkWindow
3913 * Returns the group leader window for @window. See gdk_window_set_group().
3915 * Return value: the group leader window for @window
3920 gdk_window_get_group (GdkWindow *window)
3922 GdkToplevelX11 *toplevel;
3924 g_return_val_if_fail (window != NULL, NULL);
3925 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3926 g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);
3928 if (GDK_WINDOW_DESTROYED (window))
3931 toplevel = _gdk_x11_window_get_toplevel (window);
3933 return toplevel->group_leader;
3937 * gdk_window_set_group:
3938 * @window: a toplevel #GdkWindow
3939 * @leader: group leader window, or %NULL to restore the default group leader window
3941 * Sets the group leader window for @window. By default,
3942 * GDK sets the group leader for all toplevel windows
3943 * to a global window implicitly created by GDK. With this function
3944 * you can override this default.
3946 * The group leader window allows the window manager to distinguish
3947 * all windows that belong to a single application. It may for example
3948 * allow users to minimize/unminimize all windows belonging to an
3949 * application at once. You should only set a non-default group window
3950 * if your application pretends to be multiple applications.
3953 gdk_window_set_group (GdkWindow *window,
3956 GdkToplevelX11 *toplevel;
3958 g_return_if_fail (window != NULL);
3959 g_return_if_fail (GDK_IS_WINDOW (window));
3960 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3961 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
3963 if (GDK_WINDOW_DESTROYED (window) || (leader != NULL && GDK_WINDOW_DESTROYED (leader)))
3966 toplevel = _gdk_x11_window_get_toplevel (window);
3969 leader = gdk_display_get_default_group (gdk_drawable_get_display (window));
3971 if (toplevel->group_leader != leader)
3973 if (toplevel->group_leader)
3974 g_object_unref (toplevel->group_leader);
3975 toplevel->group_leader = g_object_ref (leader);
3978 update_wm_hints (window, FALSE);
3981 static MotifWmHints *
3982 gdk_window_get_mwm_hints (GdkWindow *window)
3984 GdkDisplay *display;
3985 Atom hints_atom = None;
3986 MotifWmHints *hints;
3992 if (GDK_WINDOW_DESTROYED (window))
3995 display = gdk_drawable_get_display (window);
3997 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3999 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4000 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4001 False, AnyPropertyType, &type, &format, &nitems,
4002 &bytes_after, (guchar **)&hints);
4011 gdk_window_set_mwm_hints (GdkWindow *window,
4012 MotifWmHints *new_hints)
4014 GdkDisplay *display;
4015 Atom hints_atom = None;
4016 MotifWmHints *hints;
4022 if (GDK_WINDOW_DESTROYED (window))
4025 display = gdk_drawable_get_display (window);
4027 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4029 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4030 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4031 False, AnyPropertyType, &type, &format, &nitems,
4032 &bytes_after, (guchar **)&hints);
4038 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4040 hints->flags |= MWM_HINTS_FUNCTIONS;
4041 hints->functions = new_hints->functions;
4043 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4045 hints->flags |= MWM_HINTS_DECORATIONS;
4046 hints->decorations = new_hints->decorations;
4050 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4051 hints_atom, hints_atom, 32, PropModeReplace,
4052 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4054 if (hints != new_hints)
4059 * gdk_window_set_decorations:
4060 * @window: a toplevel #GdkWindow
4061 * @decorations: decoration hint mask
4063 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
4064 * This function sets the traditional Motif window manager hints that tell the
4065 * window manager which decorations you would like your window to have.
4066 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
4067 * using the GDK function directly.
4069 * The @decorations argument is the logical OR of the fields in
4070 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
4071 * mask, the other bits indicate which decorations should be turned off.
4072 * If #GDK_DECOR_ALL is not included, then the other bits indicate
4073 * which decorations should be turned on.
4075 * Most window managers honor a decorations hint of 0 to disable all decorations,
4076 * but very few honor all possible combinations of bits.
4080 gdk_window_set_decorations (GdkWindow *window,
4081 GdkWMDecoration decorations)
4085 g_return_if_fail (window != NULL);
4086 g_return_if_fail (GDK_IS_WINDOW (window));
4088 hints.flags = MWM_HINTS_DECORATIONS;
4089 hints.decorations = decorations;
4091 gdk_window_set_mwm_hints (window, &hints);
4095 * gdk_window_get_decorations:
4096 * @window: The toplevel #GdkWindow to get the decorations from
4097 * @decorations: The window decorations will be written here
4099 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
4100 * Returns: TRUE if the window has decorations set, FALSE otherwise.
4103 gdk_window_get_decorations(GdkWindow *window,
4104 GdkWMDecoration *decorations)
4106 MotifWmHints *hints;
4107 gboolean result = FALSE;
4109 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4111 hints = gdk_window_get_mwm_hints (window);
4115 if (hints->flags & MWM_HINTS_DECORATIONS)
4118 *decorations = hints->decorations;
4129 * gdk_window_set_functions:
4130 * @window: a toplevel #GdkWindow
4131 * @functions: bitmask of operations to allow on @window
4133 * This function isn't really good for much. It sets the traditional
4134 * Motif window manager hint for which operations the window manager
4135 * should allow on a toplevel window. However, few window managers do
4136 * anything reliable or interesting with this hint. Many ignore it
4139 * The @functions argument is the logical OR of values from the
4140 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
4141 * then the other bits indicate which functions to disable; if
4142 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4147 gdk_window_set_functions (GdkWindow *window,
4148 GdkWMFunction functions)
4152 g_return_if_fail (window != NULL);
4153 g_return_if_fail (GDK_IS_WINDOW (window));
4155 hints.flags = MWM_HINTS_FUNCTIONS;
4156 hints.functions = functions;
4158 gdk_window_set_mwm_hints (window, &hints);
4161 #ifdef HAVE_SHAPE_EXT
4164 * propagate the shapes from all child windows of a GDK window to the parent
4165 * window. Shamelessly ripped from Enlightenment's code
4173 struct _gdk_span *next;
4177 gdk_add_to_span (struct _gdk_span **s,
4181 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
4188 /* scan the spans for this line */
4191 /* -- -> new span */
4192 /* == -> existing span */
4193 /* ## -> spans intersect */
4194 /* if we are in the middle of spanning the span into the line */
4197 /* case: ---- ==== */
4198 if (xx < ptr1->start - 1)
4200 /* ends before next span - extend to here */
4204 /* case: ----##=== */
4205 else if (xx <= ptr1->end)
4207 /* crosses into next span - delete next span and append */
4208 ss->end = ptr1->end;
4209 ss->next = ptr1->next;
4213 /* case: ---###--- */
4216 /* overlaps next span - delete and keep checking */
4217 ss->next = ptr1->next;
4222 /* otherwise havent started spanning it in yet */
4225 /* case: ---- ==== */
4226 if (xx < ptr1->start - 1)
4228 /* insert span here in list */
4229 noo = g_malloc (sizeof (struct _gdk_span));
4243 /* case: ----##=== */
4244 else if ((x < ptr1->start) && (xx <= ptr1->end))
4246 /* expand this span to the left point of the new one */
4250 /* case: ===###=== */
4251 else if ((x >= ptr1->start) && (xx <= ptr1->end))
4253 /* throw the span away */
4256 /* case: ---###--- */
4257 else if ((x < ptr1->start) && (xx > ptr1->end))
4264 /* case: ===##---- */
4265 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
4271 /* case: ==== ---- */
4272 /* case handled by next loop iteration - first case */
4277 /* it started in the middle but spans beyond your current list */
4283 /* it does not start inside a span or in the middle, so add it to the end */
4284 noo = g_malloc (sizeof (struct _gdk_span));
4292 noo->next = ptr2->next;
4305 gdk_add_rectangles (Display *disp,
4307 struct _gdk_span **spans,
4314 gint x1, y1, x2, y2;
4318 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
4321 /* go through all clip rects in this window's shape */
4322 for (k = 0; k < rn; k++)
4324 /* for each clip rect, add it to each line's spans */
4326 x2 = x + rl[k].x + (rl[k].width - 1);
4328 y2 = y + rl[k].y + (rl[k].height - 1);
4337 for (a = y1; a <= y2; a++)
4340 gdk_add_to_span (&spans[a], x1, x2);
4348 gdk_propagate_shapes (Display *disp,
4352 Window rt, par, *list = NULL;
4353 gint i, j, num = 0, num_rects = 0;
4357 XRectangle *rects = NULL;
4358 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
4359 XWindowAttributes xatt;
4361 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
4366 spans = g_malloc (sizeof (struct _gdk_span *) * h);
4368 for (i = 0; i < h; i++)
4370 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
4373 /* go through all child windows and create/insert spans */
4374 for (i = 0; i < num; i++)
4376 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
4377 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
4378 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
4381 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
4383 /* go through the spans list and build a list of rects */
4384 rects = g_malloc (sizeof (XRectangle) * 256);
4386 for (i = 0; i < baseh; i++)
4389 /* go through the line for all spans */
4392 rects[num_rects].x = ptr1->start;
4393 rects[num_rects].y = i;
4394 rects[num_rects].width = ptr1->end - ptr1->start + 1;
4395 rects[num_rects].height = 1;
4397 /* if there are more lines */
4399 /* while contigous rects (same start/end coords) exist */
4400 while ((contig) && (j < baseh))
4402 /* search next line for spans matching this one */
4408 /* if we have an exact span match set contig */
4409 if ((ptr2->start == ptr1->start) &&
4410 (ptr2->end == ptr1->end))
4413 /* remove the span - not needed */
4416 ptr3->next = ptr2->next;
4422 spans[j] = ptr2->next;
4428 /* gone past the span point no point looking */
4429 else if (ptr2->start < ptr1->start)
4437 /* if a contiguous span was found increase the rect h */
4440 rects[num_rects].height++;
4444 /* up the rect count */
4446 /* every 256 new rects increase the rect array */
4447 if ((num_rects % 256) == 0)
4448 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
4452 /* set the rects as the shape mask */
4455 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
4456 ShapeSet, YXSorted);
4461 /* free up all the spans we made */
4462 for (i = 0; i < baseh; i++)
4475 #endif /* HAVE_SHAPE_EXT */
4478 * gdk_window_set_child_shapes:
4479 * @window: a #GdkWindow
4481 * Sets the shape mask of @window to the union of shape masks
4482 * for all children of @window, ignoring the shape mask of @window
4483 * itself. Contrast with gdk_window_merge_child_shapes() which includes
4484 * the shape mask of @window in the masks to be merged.
4487 gdk_window_set_child_shapes (GdkWindow *window)
4489 g_return_if_fail (window != NULL);
4490 g_return_if_fail (GDK_IS_WINDOW (window));
4492 #ifdef HAVE_SHAPE_EXT
4493 if (!GDK_WINDOW_DESTROYED (window) &&
4494 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4495 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4496 GDK_WINDOW_XID (window), FALSE);
4501 * gdk_window_merge_child_shapes:
4502 * @window: a #GdkWindow
4504 * Merges the shape masks for any child windows into the
4505 * shape mask for @window. i.e. the union of all masks
4506 * for @window and its children will become the new mask
4507 * for @window. See gdk_window_shape_combine_mask().
4509 * This function is distinct from gdk_window_set_child_shapes()
4510 * because it includes @window's shape mask in the set of shapes to
4515 gdk_window_merge_child_shapes (GdkWindow *window)
4517 g_return_if_fail (window != NULL);
4518 g_return_if_fail (GDK_IS_WINDOW (window));
4520 #ifdef HAVE_SHAPE_EXT
4521 if (!GDK_WINDOW_DESTROYED (window) &&
4522 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
4523 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
4524 GDK_WINDOW_XID (window), TRUE);
4528 /* Support for windows that can be guffaw-scrolled
4529 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
4533 gdk_window_gravity_works (GdkWindow *window)
4535 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (window));
4537 if (display_x11->gravity_works == GDK_UNKNOWN)
4544 /* This particular server apparently has a bug so that the test
4545 * works but the actual code crashes it
4547 if ((!strcmp (XServerVendor (display_x11->xdisplay),
4548 "Sun Microsystems, Inc.")) &&
4549 (VendorRelease (display_x11->xdisplay) == 3400))
4551 display_x11->gravity_works = GDK_NO;
4555 attr.window_type = GDK_WINDOW_TEMP;
4556 attr.wclass = GDK_INPUT_OUTPUT;
4561 attr.event_mask = 0;
4563 parent = gdk_window_new (gdk_screen_get_root_window (GDK_DRAWABLE_SCREEN (window)),
4564 &attr, GDK_WA_X | GDK_WA_Y);
4566 attr.window_type = GDK_WINDOW_CHILD;
4567 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
4569 gdk_window_set_static_win_gravity (child, TRUE);
4571 gdk_window_resize (parent, 100, 110);
4573 gdk_window_move (parent, 0, -10);
4574 gdk_window_move_resize (parent, 0, 0, 100, 100);
4576 gdk_window_resize (parent, 100, 110);
4577 gdk_window_move (parent, 0, -10);
4578 gdk_window_move_resize (parent, 0, 0, 100, 100);
4580 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
4582 gdk_window_destroy (parent);
4583 gdk_window_destroy (child);
4585 display_x11->gravity_works = ((y == -20) ? GDK_YES : GDK_NO);
4588 return (display_x11->gravity_works == GDK_YES);
4592 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
4594 XSetWindowAttributes xattributes;
4595 GdkWindowObject *private;
4596 guint xattributes_mask = 0;
4598 g_return_if_fail (window != NULL);
4600 private = GDK_WINDOW_OBJECT (window);
4601 if (private->input_only)
4604 xattributes.bit_gravity = StaticGravity;
4605 xattributes_mask |= CWBitGravity;
4606 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
4607 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4608 GDK_WINDOW_XID (window),
4609 CWBitGravity, &xattributes);
4613 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
4615 XSetWindowAttributes xattributes;
4617 g_return_if_fail (window != NULL);
4619 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
4621 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4622 GDK_WINDOW_XID (window),
4623 CWWinGravity, &xattributes);
4627 * gdk_window_set_static_gravities:
4628 * @window: a #GdkWindow
4629 * @use_static: %TRUE to turn on static gravity
4631 * Set the bit gravity of the given window to static, and flag it so
4632 * all children get static subwindow gravity. This is used if you are
4633 * implementing scary features that involve deep knowledge of the
4634 * windowing system. Don't worry about it unless you have to.
4636 * Return value: %TRUE if the server supports static gravity
4639 gdk_window_set_static_gravities (GdkWindow *window,
4640 gboolean use_static)
4642 GdkWindowObject *private = (GdkWindowObject *)window;
4645 g_return_val_if_fail (window != NULL, FALSE);
4646 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4648 if (!use_static == !private->guffaw_gravity)
4651 if (use_static && !gdk_window_gravity_works (window))
4654 private->guffaw_gravity = use_static;
4656 if (!GDK_WINDOW_DESTROYED (window))
4658 gdk_window_set_static_bit_gravity (window, use_static);
4660 tmp_list = private->children;
4663 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
4665 tmp_list = tmp_list->next;
4673 wmspec_moveresize (GdkWindow *window,
4679 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4683 /* Release passive grab */
4684 gdk_display_pointer_ungrab (display, timestamp);
4686 xev.xclient.type = ClientMessage;
4687 xev.xclient.serial = 0;
4688 xev.xclient.send_event = True;
4689 xev.xclient.window = GDK_WINDOW_XID (window);
4690 xev.xclient.message_type =
4691 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
4692 xev.xclient.format = 32;
4693 xev.xclient.data.l[0] = root_x;
4694 xev.xclient.data.l[1] = root_y;
4695 xev.xclient.data.l[2] = direction;
4696 xev.xclient.data.l[3] = 0;
4697 xev.xclient.data.l[4] = 0;
4699 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4700 SubstructureRedirectMask | SubstructureNotifyMask,
4704 typedef struct _MoveResizeData MoveResizeData;
4706 struct _MoveResizeData
4708 GdkDisplay *display;
4710 GdkWindow *moveresize_window;
4711 GdkWindow *moveresize_emulation_window;
4713 GdkWindowEdge resize_edge;
4714 gint moveresize_button;
4717 gint moveresize_orig_x;
4718 gint moveresize_orig_y;
4719 gint moveresize_orig_width;
4720 gint moveresize_orig_height;
4721 GdkWindowHints moveresize_geom_mask;
4722 GdkGeometry moveresize_geometry;
4723 Time moveresize_process_time;
4724 XEvent *moveresize_pending_event;
4727 /* From the WM spec */
4728 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
4729 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
4730 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
4731 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
4732 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
4733 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
4734 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
4735 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
4736 #define _NET_WM_MOVERESIZE_MOVE 8
4739 wmspec_resize_drag (GdkWindow *window,
4748 /* Let the compiler turn a switch into a table, instead
4749 * of doing the table manually, this way is easier to verify.
4753 case GDK_WINDOW_EDGE_NORTH_WEST:
4754 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
4757 case GDK_WINDOW_EDGE_NORTH:
4758 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
4761 case GDK_WINDOW_EDGE_NORTH_EAST:
4762 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
4765 case GDK_WINDOW_EDGE_WEST:
4766 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
4769 case GDK_WINDOW_EDGE_EAST:
4770 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
4773 case GDK_WINDOW_EDGE_SOUTH_WEST:
4774 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
4777 case GDK_WINDOW_EDGE_SOUTH:
4778 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
4781 case GDK_WINDOW_EDGE_SOUTH_EAST:
4782 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
4786 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
4792 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
4795 static MoveResizeData *
4796 get_move_resize_data (GdkDisplay *display,
4799 MoveResizeData *mv_resize;
4800 static GQuark move_resize_quark = 0;
4802 if (!move_resize_quark)
4803 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4805 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4807 if (!mv_resize && create)
4809 mv_resize = g_new0 (MoveResizeData, 1);
4810 mv_resize->display = display;
4812 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4819 update_pos (MoveResizeData *mv_resize,
4825 dx = new_root_x - mv_resize->moveresize_x;
4826 dy = new_root_y - mv_resize->moveresize_y;
4828 if (mv_resize->is_resize)
4832 x = mv_resize->moveresize_orig_x;
4833 y = mv_resize->moveresize_orig_y;
4835 w = mv_resize->moveresize_orig_width;
4836 h = mv_resize->moveresize_orig_height;
4838 switch (mv_resize->resize_edge)
4840 case GDK_WINDOW_EDGE_NORTH_WEST:
4846 case GDK_WINDOW_EDGE_NORTH:
4850 case GDK_WINDOW_EDGE_NORTH_EAST:
4855 case GDK_WINDOW_EDGE_SOUTH_WEST:
4860 case GDK_WINDOW_EDGE_SOUTH_EAST:
4864 case GDK_WINDOW_EDGE_SOUTH:
4867 case GDK_WINDOW_EDGE_EAST:
4870 case GDK_WINDOW_EDGE_WEST:
4881 if (mv_resize->moveresize_geom_mask)
4883 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4884 mv_resize->moveresize_geom_mask,
4888 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4894 x = mv_resize->moveresize_orig_x + dx;
4895 y = mv_resize->moveresize_orig_y + dy;
4897 gdk_window_move (mv_resize->moveresize_window, x, y);
4902 finish_drag (MoveResizeData *mv_resize)
4904 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4905 mv_resize->moveresize_emulation_window = NULL;
4906 mv_resize->moveresize_window = NULL;
4908 if (mv_resize->moveresize_pending_event)
4910 g_free (mv_resize->moveresize_pending_event);
4911 mv_resize->moveresize_pending_event = NULL;
4916 lookahead_motion_predicate (Display *xdisplay,
4920 gboolean *seen_release = (gboolean *)arg;
4921 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4922 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4927 switch (event->xany.type)
4930 *seen_release = TRUE;
4933 mv_resize->moveresize_process_time = event->xmotion.time;
4943 moveresize_lookahead (MoveResizeData *mv_resize,
4947 gboolean seen_release = FALSE;
4949 if (mv_resize->moveresize_process_time)
4951 if (event->xmotion.time == mv_resize->moveresize_process_time)
4953 mv_resize->moveresize_process_time = 0;
4960 XCheckIfEvent (event->xany.display, &tmp_event,
4961 lookahead_motion_predicate, (XPointer) & seen_release);
4963 return mv_resize->moveresize_process_time == 0;
4967 _gdk_moveresize_handle_event (XEvent *event)
4969 guint button_mask = 0;
4970 GdkWindowObject *window_private;
4971 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
4972 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4974 if (!mv_resize || !mv_resize->moveresize_window)
4977 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
4979 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4981 switch (event->xany.type)
4984 if (window_private->resize_count > 0)
4986 if (mv_resize->moveresize_pending_event)
4987 *mv_resize->moveresize_pending_event = *event;
4989 mv_resize->moveresize_pending_event =
4990 g_memdup (event, sizeof (XEvent));
4994 if (!moveresize_lookahead (mv_resize, event))
4997 update_pos (mv_resize,
4998 event->xmotion.x_root,
4999 event->xmotion.y_root);
5001 /* This should never be triggered in normal cases, but in the
5002 * case where the drag started without an implicit grab being
5003 * in effect, we could miss the release if it occurs before
5004 * we grab the pointer; this ensures that we will never
5005 * get a permanently stuck grab.
5007 if ((event->xmotion.state & button_mask) == 0)
5008 finish_drag (mv_resize);
5012 update_pos (mv_resize,
5013 event->xbutton.x_root,
5014 event->xbutton.y_root);
5016 if (event->xbutton.button == mv_resize->moveresize_button)
5017 finish_drag (mv_resize);
5024 _gdk_moveresize_configure_done (GdkDisplay *display,
5028 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5030 if (!mv_resize || window != mv_resize->moveresize_window)
5033 if (mv_resize->moveresize_pending_event)
5035 tmp_event = mv_resize->moveresize_pending_event;
5036 mv_resize->moveresize_pending_event = NULL;
5037 _gdk_moveresize_handle_event (tmp_event);
5045 create_moveresize_window (MoveResizeData *mv_resize,
5048 GdkWindowAttr attributes;
5049 gint attributes_mask;
5050 GdkGrabStatus status;
5052 g_assert (mv_resize->moveresize_emulation_window == NULL);
5054 attributes.x = -100;
5055 attributes.y = -100;
5056 attributes.width = 10;
5057 attributes.height = 10;
5058 attributes.window_type = GDK_WINDOW_TEMP;
5059 attributes.wclass = GDK_INPUT_ONLY;
5060 attributes.override_redirect = TRUE;
5061 attributes.event_mask = 0;
5063 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5065 mv_resize->moveresize_emulation_window =
5066 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
5070 gdk_window_show (mv_resize->moveresize_emulation_window);
5072 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
5074 GDK_BUTTON_RELEASE_MASK |
5075 GDK_POINTER_MOTION_MASK,
5080 if (status != GDK_GRAB_SUCCESS)
5082 /* If this fails, some other client has grabbed the window
5085 gdk_window_destroy (mv_resize->moveresize_emulation_window);
5086 mv_resize->moveresize_emulation_window = NULL;
5089 mv_resize->moveresize_process_time = 0;
5093 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
5094 so that calling XMoveWindow with these coordinates will not move the
5096 Note that this depends on the WM to implement ICCCM-compliant reference
5100 calculate_unmoving_origin (MoveResizeData *mv_resize)
5105 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
5106 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
5108 gdk_window_get_origin (mv_resize->moveresize_window,
5109 &mv_resize->moveresize_orig_x,
5110 &mv_resize->moveresize_orig_y);
5114 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
5115 gdk_window_get_geometry (mv_resize->moveresize_window,
5116 NULL, NULL, &width, &height, NULL);
5118 switch (mv_resize->moveresize_geometry.win_gravity)
5120 case GDK_GRAVITY_NORTH_WEST:
5121 mv_resize->moveresize_orig_x = rect.x;
5122 mv_resize->moveresize_orig_y = rect.y;
5124 case GDK_GRAVITY_NORTH:
5125 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5126 mv_resize->moveresize_orig_y = rect.y;
5128 case GDK_GRAVITY_NORTH_EAST:
5129 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5130 mv_resize->moveresize_orig_y = rect.y;
5132 case GDK_GRAVITY_WEST:
5133 mv_resize->moveresize_orig_x = rect.x;
5134 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5136 case GDK_GRAVITY_CENTER:
5137 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5138 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5140 case GDK_GRAVITY_EAST:
5141 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5142 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5144 case GDK_GRAVITY_SOUTH_WEST:
5145 mv_resize->moveresize_orig_x = rect.x;
5146 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5148 case GDK_GRAVITY_SOUTH:
5149 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5150 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5152 case GDK_GRAVITY_SOUTH_EAST:
5153 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5154 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5157 mv_resize->moveresize_orig_x = rect.x;
5158 mv_resize->moveresize_orig_y = rect.y;
5165 emulate_resize_drag (GdkWindow *window,
5172 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5174 mv_resize->is_resize = TRUE;
5175 mv_resize->moveresize_button = button;
5176 mv_resize->resize_edge = edge;
5177 mv_resize->moveresize_x = root_x;
5178 mv_resize->moveresize_y = root_y;
5179 mv_resize->moveresize_window = g_object_ref (window);
5181 gdk_drawable_get_size (window,
5182 &mv_resize->moveresize_orig_width,
5183 &mv_resize->moveresize_orig_height);
5185 mv_resize->moveresize_geom_mask = 0;
5186 gdk_window_get_geometry_hints (window,
5187 &mv_resize->moveresize_geometry,
5188 &mv_resize->moveresize_geom_mask);
5190 calculate_unmoving_origin (mv_resize);
5192 create_moveresize_window (mv_resize, timestamp);
5196 emulate_move_drag (GdkWindow *window,
5202 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5204 mv_resize->is_resize = FALSE;
5205 mv_resize->moveresize_button = button;
5206 mv_resize->moveresize_x = root_x;
5207 mv_resize->moveresize_y = root_y;
5209 mv_resize->moveresize_window = g_object_ref (window);
5211 calculate_unmoving_origin (mv_resize);
5213 create_moveresize_window (mv_resize, timestamp);
5217 * gdk_window_begin_resize_drag:
5218 * @window: a toplevel #GdkWindow
5219 * @edge: the edge or corner from which the drag is started
5220 * @button: the button being used to drag
5221 * @root_x: root window X coordinate of mouse click that began the drag
5222 * @root_y: root window Y coordinate of mouse click that began the drag
5223 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5225 * Begins a window resize operation (for a toplevel window).
5226 * You might use this function to implement a "window resize grip," for
5227 * example; in fact #GtkStatusbar uses it. The function works best
5228 * with window managers that support the Extended Window Manager Hints spec
5229 * (see http://www.freedesktop.org), but has a fallback implementation
5230 * for other window managers.
5234 gdk_window_begin_resize_drag (GdkWindow *window,
5241 g_return_if_fail (GDK_IS_WINDOW (window));
5243 if (GDK_WINDOW_DESTROYED (window))
5246 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5247 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5248 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5250 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5254 * gdk_window_begin_move_drag:
5255 * @window: a toplevel #GdkWindow
5256 * @button: the button being used to drag
5257 * @root_x: root window X coordinate of mouse click that began the drag
5258 * @root_y: root window Y coordinate of mouse click that began the drag
5259 * @timestamp: timestamp of mouse click that began the drag
5261 * Begins a window move operation (for a toplevel window). You might
5262 * use this function to implement a "window move grip," for
5263 * example. The function works best with window managers that support
5264 * the Extended Window Manager Hints spec (see
5265 * http://www.freedesktop.org), but has a fallback implementation for
5266 * other window managers.
5270 gdk_window_begin_move_drag (GdkWindow *window,
5276 g_return_if_fail (GDK_IS_WINDOW (window));
5278 if (GDK_WINDOW_DESTROYED (window))
5281 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5282 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5283 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5286 emulate_move_drag (window, button, root_x, root_y, timestamp);