1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include <X11/Xutil.h>
31 #include <X11/Xatom.h>
32 #include <netinet/in.h>
38 #include "gdkwindow.h"
40 #include "gdkinputprivate.h"
41 #include "gdkdisplay-x11.h"
42 #include "gdkprivate-x11.h"
43 #include "gdkregion.h"
44 #include "gdkinternals.h"
46 #include "gdkwindow-x11.h"
54 #include <X11/extensions/shape.h>
57 const int _gdk_event_mask_table[21] =
61 PointerMotionHintMask,
78 SubstructureNotifyMask,
79 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
81 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
83 /* Forward declarations */
84 static void gdk_window_set_static_win_gravity (GdkWindow *window,
86 static gboolean gdk_window_have_shape_ext (GdkDisplay *display);
87 static gboolean gdk_window_icon_name_set (GdkWindow *window);
88 static void gdk_window_add_colormap_windows (GdkWindow *window);
89 static void set_wm_name (GdkDisplay *display,
93 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
94 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
96 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
99 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
100 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
101 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
102 static void gdk_window_impl_x11_finalize (GObject *object);
104 static gpointer parent_class = NULL;
106 #define WINDOW_IS_TOPLEVEL(window) \
107 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
108 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
110 /* Return whether time1 is considered later than time2 as far as xserver
111 * time is concerned. Accounts for wraparound.
113 #define XSERVER_TIME_IS_LATER(time1, time2) \
114 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
115 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
119 gdk_window_impl_x11_get_type (void)
121 static GType object_type = 0;
125 static const GTypeInfo object_info =
127 sizeof (GdkWindowImplX11Class),
128 (GBaseInitFunc) NULL,
129 (GBaseFinalizeFunc) NULL,
130 (GClassInitFunc) gdk_window_impl_x11_class_init,
131 NULL, /* class_finalize */
132 NULL, /* class_data */
133 sizeof (GdkWindowImplX11),
135 (GInstanceInitFunc) gdk_window_impl_x11_init,
138 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
147 _gdk_window_impl_get_type (void)
149 return gdk_window_impl_x11_get_type ();
153 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
157 impl->toplevel_window_type = -1;
161 _gdk_x11_window_get_toplevel (GdkWindow *window)
163 GdkWindowObject *private;
164 GdkWindowImplX11 *impl;
166 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
168 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
171 private = (GdkWindowObject *)window;
172 impl = GDK_WINDOW_IMPL_X11 (private->impl);
175 impl->toplevel = g_new0 (GdkToplevelX11, 1);
177 return impl->toplevel;
181 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
183 GObjectClass *object_class = G_OBJECT_CLASS (klass);
184 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
186 parent_class = g_type_class_peek_parent (klass);
188 object_class->finalize = gdk_window_impl_x11_finalize;
190 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
191 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
192 drawable_class->get_size = gdk_window_impl_x11_get_size;
194 /* Visible and clip regions are the same */
195 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
196 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
200 gdk_window_impl_x11_finalize (GObject *object)
202 GdkWindowObject *wrapper;
203 GdkDrawableImplX11 *draw_impl;
204 GdkWindowImplX11 *window_impl;
206 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
208 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
209 window_impl = GDK_WINDOW_IMPL_X11 (object);
211 wrapper = (GdkWindowObject*) draw_impl->wrapper;
213 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
215 if (!GDK_WINDOW_DESTROYED (wrapper))
217 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
219 _gdk_xid_table_remove (display, draw_impl->xid);
220 if (window_impl->toplevel && window_impl->toplevel->focus_window)
221 _gdk_xid_table_remove (display, window_impl->toplevel->focus_window);
224 if (window_impl->toplevel)
225 g_free (window_impl->toplevel);
227 G_OBJECT_CLASS (parent_class)->finalize (object);
231 tmp_unset_bg (GdkWindow *window)
233 GdkWindowImplX11 *impl;
234 GdkWindowObject *obj;
236 obj = (GdkWindowObject *) window;
237 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
239 /* For windows without EXPOSURE_MASK, we can't do this
240 * unsetting because such windows depend on the drawing
241 * that the X server is going to do
243 if (!(obj->event_mask & GDK_EXPOSURE_MASK))
246 impl->position_info.no_bg = TRUE;
248 if (obj->bg_pixmap != GDK_NO_BG)
249 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
250 GDK_DRAWABLE_XID (window), None);
254 tmp_reset_bg (GdkWindow *window)
256 GdkWindowImplX11 *impl;
257 GdkWindowObject *obj;
259 obj = (GdkWindowObject *) window;
260 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
262 if (!(obj->event_mask & GDK_EXPOSURE_MASK))
265 impl->position_info.no_bg = FALSE;
267 if (obj->bg_pixmap == GDK_NO_BG)
274 if (obj->bg_pixmap == GDK_PARENT_RELATIVE_BG)
275 xpixmap = ParentRelative;
277 xpixmap = GDK_DRAWABLE_XID (obj->bg_pixmap);
279 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
280 GDK_DRAWABLE_XID (window), xpixmap);
284 XSetWindowBackground (GDK_DRAWABLE_XDISPLAY (window),
285 GDK_DRAWABLE_XID (window),
286 obj->bg_color.pixel);
291 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
294 GdkWindowObject *private;
296 g_return_if_fail (GDK_IS_WINDOW (window));
298 private = (GdkWindowObject *)window;
300 if (private->input_only || private->destroyed ||
301 (private->window_type != GDK_WINDOW_ROOT &&
302 !GDK_WINDOW_IS_MAPPED (window)))
307 if (private->window_type != GDK_WINDOW_ROOT &&
308 private->window_type != GDK_WINDOW_FOREIGN)
310 tmp_unset_bg (window);
317 for (l = private->children; l != NULL; l = l->next)
318 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
323 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
326 GdkWindowObject *private;
328 g_return_if_fail (GDK_IS_WINDOW (window));
330 private = (GdkWindowObject *)window;
332 if (private->input_only || private->destroyed ||
333 (private->window_type != GDK_WINDOW_ROOT &&
334 !GDK_WINDOW_IS_MAPPED (window)))
339 if (private->window_type != GDK_WINDOW_ROOT &&
340 private->window_type != GDK_WINDOW_FOREIGN)
342 tmp_reset_bg (window);
349 for (l = private->children; l != NULL; l = l->next)
350 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
355 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
357 GdkDrawableImplX11 *drawable_impl;
358 GdkWindowImplX11 *window_impl;
360 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
362 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
363 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
365 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
366 drawable_impl->colormap == NULL)
368 XWindowAttributes window_attributes;
371 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
375 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
376 window_attributes.visual->visualid);
377 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
378 window_attributes.colormap);
381 return drawable_impl->colormap;
385 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
388 GdkWindowImplX11 *impl;
389 GdkDrawableImplX11 *draw_impl;
391 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
393 impl = GDK_WINDOW_IMPL_X11 (drawable);
394 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
396 if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper))
400 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
404 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
406 GDK_COLORMAP_XCOLORMAP (cmap));
408 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
410 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
416 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
420 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
423 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
425 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
429 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
431 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
432 GdkRectangle result_rect;
436 result_rect.width = impl->width;
437 result_rect.height = impl->height;
439 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
441 return gdk_region_rectangle (&result_rect);
445 _gdk_windowing_window_init (GdkScreen * screen)
447 GdkWindowObject *private;
448 GdkWindowImplX11 *impl;
449 GdkDrawableImplX11 *draw_impl;
450 GdkScreenX11 *screen_x11;
452 screen_x11 = GDK_SCREEN_X11 (screen);
454 g_assert (screen_x11->root_window == NULL);
456 gdk_screen_set_default_colormap (screen,
457 gdk_screen_get_system_colormap (screen));
459 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
460 private = (GdkWindowObject *)screen_x11->root_window;
461 impl = GDK_WINDOW_IMPL_X11 (private->impl);
462 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
464 draw_impl->screen = screen;
465 draw_impl->xid = screen_x11->xroot_window;
466 draw_impl->wrapper = GDK_DRAWABLE (private);
467 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
468 g_object_ref (draw_impl->colormap);
470 private->window_type = GDK_WINDOW_ROOT;
471 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
473 impl->width = WidthOfScreen (screen_x11->xscreen);
474 impl->height = HeightOfScreen (screen_x11->xscreen);
476 _gdk_window_init_position (GDK_WINDOW (private));
478 _gdk_xid_table_insert (screen_x11->display,
479 &screen_x11->xroot_window,
480 screen_x11->root_window);
484 set_wm_protocols (GdkWindow *window)
486 GdkDisplay *display = gdk_drawable_get_display (window);
490 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
491 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
492 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
495 if (GDK_DISPLAY_X11 (display)->use_sync)
496 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
499 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
503 get_default_title (void)
507 title = g_get_application_name ();
509 title = g_get_prgname ();
515 check_leader_window_title (GdkDisplay *display)
517 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
519 if (display_x11->leader_window && !display_x11->leader_window_title_set)
521 set_wm_name (display,
522 display_x11->leader_window,
523 get_default_title ());
525 display_x11->leader_window_title_set = TRUE;
530 create_focus_window (Display *xdisplay,
533 Window focus_window = XCreateSimpleWindow (xdisplay, parent,
537 /* FIXME: probably better to actually track the requested event mask for the toplevel
539 XSelectInput (xdisplay, focus_window,
540 KeyPressMask | KeyReleaseMask | FocusChangeMask);
542 XMapWindow (xdisplay, focus_window);
548 ensure_sync_counter (GdkWindow *window)
551 if (!GDK_WINDOW_DESTROYED (window))
553 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
554 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
555 GdkWindowObject *private = (GdkWindowObject *)window;
556 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
558 if (toplevel && impl->use_synchronized_configure &&
559 toplevel->update_counter == None &&
560 GDK_DISPLAY_X11 (display)->use_sync)
562 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
566 XSyncIntToValue (&value, 0);
568 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
570 atom = gdk_x11_get_xatom_by_name_for_display (display,
571 "_NET_WM_SYNC_REQUEST_COUNTER");
573 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
576 (guchar *)&toplevel->update_counter, 1);
578 XSyncIntToValue (&toplevel->current_counter_value, 0);
585 setup_toplevel_window (GdkWindow *window,
588 GdkWindowObject *obj = (GdkWindowObject *)window;
589 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
590 GdkWindowImplX11 *impl = (GdkWindowImplX11 *)obj->impl;
591 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
592 XID xid = GDK_WINDOW_XID (window);
593 XID xparent = GDK_WINDOW_XID (parent);
594 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
595 XSizeHints size_hints;
598 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_DIALOG)
599 XSetTransientForHint (xdisplay, xid, xparent);
601 set_wm_protocols (window);
603 if (!obj->input_only)
605 /* The focus window is off the visible area, and serves to receive key
606 * press events so they don't get sent to child windows.
608 toplevel->focus_window = create_focus_window (xdisplay, xid);
609 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
612 check_leader_window_title (screen_x11->display);
614 /* FIXME: Is there any point in doing this? Do any WM's pay
615 * attention to PSize, and even if they do, is this the
618 size_hints.flags = PSize;
619 size_hints.width = impl->width;
620 size_hints.height = impl->height;
622 XSetWMNormalHints (xdisplay, xid, &size_hints);
624 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
625 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
628 XChangeProperty (xdisplay, xid,
629 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
634 XChangeProperty (xdisplay, xid,
635 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
636 XA_WINDOW, 32, PropModeReplace,
637 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
639 if (!obj->focus_on_map)
640 gdk_x11_window_set_user_time (window, 0);
641 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
642 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
644 ensure_sync_counter (window);
649 * @parent: a #GdkWindow, or %NULL to create the window as a child of
650 * the default root window for the default display.
651 * @attributes: attributes of the new window
652 * @attributes_mask: mask indicating which fields in @attributes are valid
654 * Creates a new #GdkWindow using the attributes from
655 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
656 * more details. Note: to use this on displays other than the default
657 * display, @parent must be specified.
659 * Return value: the new #GdkWindow
662 gdk_window_new (GdkWindow *parent,
663 GdkWindowAttr *attributes,
664 gint attributes_mask)
667 GdkWindowObject *private;
668 GdkWindowImplX11 *impl;
669 GdkDrawableImplX11 *draw_impl;
670 GdkScreenX11 *screen_x11;
679 XSetWindowAttributes xattributes;
680 long xattributes_mask;
681 XClassHint *class_hint;
688 g_return_val_if_fail (attributes != NULL, NULL);
693 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
695 screen = gdk_screen_get_default ();
696 parent = gdk_screen_get_root_window (screen);
699 screen = gdk_drawable_get_screen (parent);
701 screen_x11 = GDK_SCREEN_X11 (screen);
703 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
705 if (GDK_WINDOW_DESTROYED (parent))
708 xparent = GDK_WINDOW_XID (parent);
710 window = g_object_new (GDK_TYPE_WINDOW, NULL);
711 private = (GdkWindowObject *)window;
712 impl = GDK_WINDOW_IMPL_X11 (private->impl);
713 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
714 draw_impl->wrapper = GDK_DRAWABLE (window);
716 draw_impl->screen = screen;
717 xdisplay = screen_x11->xdisplay;
719 /* Windows with a foreign parent are treated as if they are children
720 * of the root window, except for actual creation.
722 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
723 parent = gdk_screen_get_root_window (screen);
725 private->parent = (GdkWindowObject *)parent;
727 private->accept_focus = TRUE;
728 private->focus_on_map = TRUE;
730 xattributes_mask = 0;
732 if (attributes_mask & GDK_WA_X)
737 if (attributes_mask & GDK_WA_Y)
744 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
745 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
747 if (attributes->wclass == GDK_INPUT_ONLY)
749 /* Backwards compatiblity - we've always ignored
750 * attributes->window_type for input-only windows
753 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
754 private->window_type = GDK_WINDOW_TEMP;
756 private->window_type = GDK_WINDOW_CHILD;
759 private->window_type = attributes->window_type;
761 _gdk_window_init_position (GDK_WINDOW (private));
762 if (impl->position_info.big)
763 private->guffaw_gravity = TRUE;
765 if (attributes_mask & GDK_WA_VISUAL)
766 visual = attributes->visual;
768 visual = gdk_screen_get_system_visual (screen);
769 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
771 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
772 for (i = 0; i < _gdk_nenvent_masks; i++)
774 if (attributes->event_mask & (1 << (i + 1)))
775 xattributes.event_mask |= _gdk_event_mask_table[i];
777 private->event_mask = attributes->event_mask;
779 if (xattributes.event_mask)
780 xattributes_mask |= CWEventMask;
782 if (attributes_mask & GDK_WA_NOREDIR)
784 xattributes.override_redirect =
785 (attributes->override_redirect == FALSE)?False:True;
786 xattributes_mask |= CWOverrideRedirect;
789 xattributes.override_redirect = False;
791 impl->override_redirect = xattributes.override_redirect;
793 if (private->parent && private->parent->guffaw_gravity)
795 xattributes.win_gravity = StaticGravity;
796 xattributes_mask |= CWWinGravity;
800 switch (private->window_type)
802 case GDK_WINDOW_TOPLEVEL:
803 case GDK_WINDOW_DIALOG:
804 case GDK_WINDOW_TEMP:
805 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
807 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
808 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
809 xparent = GDK_SCREEN_XROOTWIN (screen);
811 case GDK_WINDOW_CHILD:
814 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
818 if (attributes->wclass == GDK_INPUT_OUTPUT)
821 depth = visual->depth;
823 private->input_only = FALSE;
824 private->depth = depth;
826 if (attributes_mask & GDK_WA_COLORMAP)
828 draw_impl->colormap = attributes->colormap;
829 g_object_ref (attributes->colormap);
833 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
835 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
836 g_object_ref (draw_impl->colormap);
840 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
844 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
845 xattributes.background_pixel = private->bg_color.pixel;
847 private->bg_pixmap = NULL;
849 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
850 xattributes_mask |= CWBorderPixel | CWBackPixel;
852 if (private->guffaw_gravity)
853 xattributes.bit_gravity = StaticGravity;
855 xattributes.bit_gravity = NorthWestGravity;
857 xattributes_mask |= CWBitGravity;
859 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
860 xattributes_mask |= CWColormap;
862 if (private->window_type == GDK_WINDOW_TEMP)
864 xattributes.save_under = True;
865 xattributes.override_redirect = True;
866 xattributes.cursor = None;
867 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
869 impl->override_redirect = TRUE;
877 private->input_only = TRUE;
878 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
879 g_object_ref (draw_impl->colormap);
882 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
883 impl->position_info.x, impl->position_info.y,
884 impl->position_info.width, impl->position_info.height,
885 0, depth, class, xvisual,
886 xattributes_mask, &xattributes);
888 g_object_ref (window);
889 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
891 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
892 (attributes->cursor) :
896 private->parent->children = g_list_prepend (private->parent->children, window);
898 switch (GDK_WINDOW_TYPE (private))
900 case GDK_WINDOW_DIALOG:
901 case GDK_WINDOW_TOPLEVEL:
902 case GDK_WINDOW_TEMP:
903 if (attributes_mask & GDK_WA_TITLE)
904 title = attributes->title;
906 title = get_default_title ();
908 gdk_window_set_title (window, title);
910 if (attributes_mask & GDK_WA_WMCLASS)
912 class_hint = XAllocClassHint ();
913 class_hint->res_name = attributes->wmclass_name;
914 class_hint->res_class = attributes->wmclass_class;
915 XSetClassHint (xdisplay, xid, class_hint);
919 setup_toplevel_window (window, parent);
922 case GDK_WINDOW_CHILD:
923 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
924 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
925 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
927 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
928 gdk_window_add_colormap_windows (window);
940 x_event_mask_to_gdk_event_mask (long mask)
942 GdkEventMask event_mask = 0;
945 for (i = 0; i < _gdk_nenvent_masks; i++)
947 if (mask & _gdk_event_mask_table[i])
948 event_mask |= 1 << (i + 1);
955 * gdk_window_foreign_new_for_display:
956 * @display: the #GdkDisplay where the window handle comes from.
957 * @anid: a native window handle.
959 * Wraps a native window in a #GdkWindow.
960 * This may fail if the window has been destroyed. If the window
961 * was already known to GDK, a new reference to the existing
962 * #GdkWindow is returned.
964 * For example in the X backend, a native window handle is an Xlib
967 * Return value: a #GdkWindow wrapper for the native window or
968 * %NULL if the window has been destroyed. The wrapper will be
969 * newly created, if one doesn't exist already.
974 gdk_window_foreign_new_for_display (GdkDisplay *display,
975 GdkNativeWindow anid)
978 GdkWindowObject *private;
979 GdkWindowImplX11 *impl;
980 GdkDrawableImplX11 *draw_impl;
981 GdkDisplayX11 *display_x11;
982 XWindowAttributes attrs;
984 Window *children = NULL;
988 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
990 display_x11 = GDK_DISPLAY_X11 (display);
992 if ((window = gdk_xid_table_lookup_for_display (display, anid)) != NULL)
993 return g_object_ref (window);
995 gdk_error_trap_push ();
996 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
997 if (gdk_error_trap_pop () || !result)
1000 /* FIXME: This is pretty expensive. Maybe the caller should supply
1002 gdk_error_trap_push ();
1003 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
1004 if (gdk_error_trap_pop () || !result)
1010 window = g_object_new (GDK_TYPE_WINDOW, NULL);
1011 private = (GdkWindowObject *)window;
1012 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1013 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
1014 draw_impl->wrapper = GDK_DRAWABLE (window);
1015 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
1017 private->parent = gdk_xid_table_lookup_for_display (display, parent);
1019 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
1020 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
1022 private->parent->children = g_list_prepend (private->parent->children, window);
1024 draw_impl->xid = anid;
1026 private->x = attrs.x;
1027 private->y = attrs.y;
1028 impl->width = attrs.width;
1029 impl->height = attrs.height;
1030 private->window_type = GDK_WINDOW_FOREIGN;
1031 private->destroyed = FALSE;
1033 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
1035 if (attrs.map_state == IsUnmapped)
1036 private->state = GDK_WINDOW_STATE_WITHDRAWN;
1040 private->depth = attrs.depth;
1042 _gdk_window_init_position (GDK_WINDOW (private));
1044 g_object_ref (window);
1045 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
1050 * gdk_window_lookup_for_display:
1051 * @display: the #GdkDisplay corresponding to the window handle
1052 * @anid: a native window handle.
1054 * Looks up the #GdkWindow that wraps the given native window handle.
1056 * For example in the X backend, a native window handle is an Xlib
1059 * Return value: the #GdkWindow wrapper for the native window,
1060 * or %NULL if there is none.
1065 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
1067 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
1071 * gdk_window_lookup:
1072 * @anid: a native window handle.
1074 * Looks up the #GdkWindow that wraps the given native window handle.
1076 * For example in the X backend, a native window handle is an Xlib
1079 * Return value: the #GdkWindow wrapper for the native window,
1080 * or %NULL if there is none.
1083 gdk_window_lookup (GdkNativeWindow anid)
1085 return (GdkWindow*) gdk_xid_table_lookup (anid);
1089 gdk_toplevel_x11_free_contents (GdkDisplay *display,
1090 GdkToplevelX11 *toplevel)
1092 if (toplevel->icon_window)
1094 g_object_unref (toplevel->icon_window);
1095 toplevel->icon_window = NULL;
1097 if (toplevel->icon_pixmap)
1099 g_object_unref (toplevel->icon_pixmap);
1100 toplevel->icon_pixmap = NULL;
1102 if (toplevel->icon_mask)
1104 g_object_unref (toplevel->icon_mask);
1105 toplevel->icon_mask = NULL;
1107 if (toplevel->group_leader)
1109 g_object_unref (toplevel->group_leader);
1110 toplevel->group_leader = NULL;
1113 if (toplevel->update_counter != None)
1115 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
1116 toplevel->update_counter);
1117 toplevel->update_counter = None;
1119 XSyncIntToValue (&toplevel->current_counter_value, 0);
1125 _gdk_windowing_window_destroy (GdkWindow *window,
1127 gboolean foreign_destroy)
1129 GdkWindowObject *private = (GdkWindowObject *)window;
1130 GdkToplevelX11 *toplevel;
1131 GdkDrawableImplX11 *draw_impl;
1133 g_return_if_fail (GDK_IS_WINDOW (window));
1135 _gdk_selection_window_destroyed (window);
1137 if (private->extension_events != 0)
1138 _gdk_input_window_destroy (window);
1140 toplevel = _gdk_x11_window_get_toplevel (window);
1142 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1144 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
1146 if (draw_impl->xft_draw)
1147 XftDrawDestroy (draw_impl->xft_draw);
1149 if (!recursing && !foreign_destroy)
1151 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1156 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1158 /* It's somebody else's window, but in our heirarchy,
1159 * so reparent it to the root window, and then send
1160 * it a delete event, as if we were a WM
1162 XClientMessageEvent xevent;
1164 gdk_error_trap_push ();
1165 gdk_window_hide (window);
1166 gdk_window_reparent (window, NULL, 0, 0);
1168 xevent.type = ClientMessage;
1169 xevent.window = GDK_WINDOW_XID (window);
1170 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1173 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1174 "WM_DELETE_WINDOW");
1175 xevent.data.l[1] = CurrentTime;
1176 xevent.data.l[2] = 0;
1177 xevent.data.l[3] = 0;
1178 xevent.data.l[4] = 0;
1180 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1181 GDK_WINDOW_XID (window),
1182 False, 0, (XEvent *)&xevent);
1183 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
1184 gdk_error_trap_pop ();
1188 get_root (GdkWindow *window)
1190 GdkScreen *screen = gdk_drawable_get_screen (window);
1192 return gdk_screen_get_root_window (screen);
1195 /* This function is called when the XWindow is really gone.
1198 gdk_window_destroy_notify (GdkWindow *window)
1200 GdkWindowImplX11 *window_impl;
1202 g_return_if_fail (window != NULL);
1204 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
1206 if (!GDK_WINDOW_DESTROYED (window))
1208 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1209 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1211 _gdk_window_destroy (window, TRUE);
1214 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1215 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1216 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1218 _gdk_xgrab_check_destroy (window);
1220 g_object_unref (window);
1224 update_wm_hints (GdkWindow *window,
1227 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1228 GdkWindowObject *private = (GdkWindowObject *)window;
1229 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1233 !toplevel->is_leader &&
1234 private->state & GDK_WINDOW_STATE_WITHDRAWN)
1237 wm_hints.flags = StateHint | InputHint;
1238 wm_hints.input = private->accept_focus ? True : False;
1239 wm_hints.initial_state = NormalState;
1241 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1243 wm_hints.flags |= StateHint;
1244 wm_hints.initial_state = IconicState;
1247 if (toplevel->icon_window && !GDK_WINDOW_DESTROYED (toplevel->icon_window))
1249 wm_hints.flags |= IconWindowHint;
1250 wm_hints.icon_window = GDK_WINDOW_XID (toplevel->icon_window);
1253 if (toplevel->icon_pixmap)
1255 wm_hints.flags |= IconPixmapHint;
1256 wm_hints.icon_pixmap = GDK_PIXMAP_XID (toplevel->icon_pixmap);
1259 if (toplevel->icon_mask)
1261 wm_hints.flags |= IconMaskHint;
1262 wm_hints.icon_mask = GDK_PIXMAP_XID (toplevel->icon_mask);
1265 wm_hints.flags |= WindowGroupHint;
1266 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1268 wm_hints.flags |= WindowGroupHint;
1269 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1272 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1274 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1275 GDK_WINDOW_XID (window),
1280 set_initial_hints (GdkWindow *window)
1282 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1283 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1284 Window xwindow = GDK_WINDOW_XID (window);
1285 GdkWindowObject *private;
1286 GdkToplevelX11 *toplevel;
1290 private = (GdkWindowObject*) window;
1291 toplevel = _gdk_x11_window_get_toplevel (window);
1296 update_wm_hints (window, TRUE);
1298 /* We set the spec hints regardless of whether the spec is supported,
1299 * since it can't hurt and it's kind of expensive to check whether
1305 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1307 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1308 "_NET_WM_STATE_MAXIMIZED_VERT");
1310 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1311 "_NET_WM_STATE_MAXIMIZED_HORZ");
1315 if (private->state & GDK_WINDOW_STATE_ABOVE)
1317 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1318 "_NET_WM_STATE_ABOVE");
1322 if (private->state & GDK_WINDOW_STATE_BELOW)
1324 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1325 "_NET_WM_STATE_BELOW");
1329 if (private->state & GDK_WINDOW_STATE_STICKY)
1331 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1332 "_NET_WM_STATE_STICKY");
1336 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1338 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1339 "_NET_WM_STATE_FULLSCREEN");
1343 if (private->modal_hint)
1345 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1346 "_NET_WM_STATE_MODAL");
1350 if (toplevel->skip_taskbar_hint)
1352 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1353 "_NET_WM_STATE_SKIP_TASKBAR");
1357 if (toplevel->skip_pager_hint)
1359 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1360 "_NET_WM_STATE_SKIP_PAGER");
1366 XChangeProperty (xdisplay,
1368 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1369 XA_ATOM, 32, PropModeReplace,
1370 (guchar*) atoms, i);
1374 XDeleteProperty (xdisplay,
1376 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1379 if (private->state & GDK_WINDOW_STATE_STICKY)
1381 atoms[0] = 0xFFFFFFFF;
1382 XChangeProperty (xdisplay,
1384 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1385 XA_CARDINAL, 32, PropModeReplace,
1386 (guchar*) atoms, 1);
1390 XDeleteProperty (xdisplay,
1392 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1395 toplevel->map_serial = NextRequest (xdisplay);
1399 show_window_internal (GdkWindow *window,
1402 GdkWindowObject *private;
1403 GdkDisplay *display;
1404 GdkDisplayX11 *display_x11;
1405 GdkToplevelX11 *toplevel;
1407 g_return_if_fail (GDK_IS_WINDOW (window));
1409 private = (GdkWindowObject*) window;
1410 if (!private->destroyed)
1412 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1413 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1414 Window xwindow = GDK_WINDOW_XID (window);
1417 XRaiseWindow (xdisplay, xwindow);
1419 if (!GDK_WINDOW_IS_MAPPED (window))
1421 set_initial_hints (window);
1423 gdk_synthesize_window_state (window,
1424 GDK_WINDOW_STATE_WITHDRAWN,
1428 g_assert (GDK_WINDOW_IS_MAPPED (window));
1430 if (WINDOW_IS_TOPLEVEL (window))
1432 display = gdk_drawable_get_display (window);
1433 display_x11 = GDK_DISPLAY_X11 (display);
1434 toplevel = _gdk_x11_window_get_toplevel (window);
1436 if (toplevel->user_time != 0 &&
1437 display_x11->user_time != 0 &&
1438 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1439 gdk_x11_window_set_user_time (window, display_x11->user_time);
1442 if (impl->position_info.mapped)
1444 gboolean unset_bg = !private->input_only &&
1445 (private->window_type == GDK_WINDOW_CHILD ||
1446 impl->override_redirect) &&
1447 gdk_window_is_viewable (window);
1450 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1452 XMapWindow (xdisplay, xwindow);
1456 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1457 gdk_window_invalidate_rect (window, NULL, TRUE);
1464 * gdk_window_show_unraised:
1465 * @window: a #GdkWindow
1467 * Shows a #GdkWindow onscreen, but does not modify its stacking
1468 * order. In contrast, gdk_window_show() will raise the window
1469 * to the top of the window stack.
1471 * On the X11 platform, in Xlib terms, this function calls
1472 * XMapWindow() (it also updates some internal GDK state, which means
1473 * that you can't really use XMapWindow() directly on a GDK window).
1477 gdk_window_show_unraised (GdkWindow *window)
1479 g_return_if_fail (GDK_IS_WINDOW (window));
1481 show_window_internal (window, FALSE);
1486 * @window: a #GdkWindow
1488 * Like gdk_window_show_unraised(), but also raises the window to the
1489 * top of the window stack (moves the window to the front of the
1492 * This function maps a window so it's visible onscreen. Its opposite
1493 * is gdk_window_hide().
1495 * When implementing a #GtkWidget, you should call this function on the widget's
1496 * #GdkWindow as part of the "map" method.
1500 gdk_window_show (GdkWindow *window)
1502 g_return_if_fail (GDK_IS_WINDOW (window));
1504 show_window_internal (window, TRUE);
1508 pre_unmap (GdkWindow *window)
1510 GdkWindow *start_window = NULL;
1511 GdkWindowObject *private = (GdkWindowObject *)window;
1513 if (private->input_only)
1516 if (private->window_type == GDK_WINDOW_CHILD)
1517 start_window = (GdkWindow *)private->parent;
1518 else if (private->window_type == GDK_WINDOW_TEMP)
1519 start_window = get_root (window);
1522 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1526 post_unmap (GdkWindow *window)
1528 GdkWindow *start_window = NULL;
1529 GdkWindowObject *private = (GdkWindowObject *)window;
1531 if (private->input_only)
1534 if (private->window_type == GDK_WINDOW_CHILD)
1535 start_window = (GdkWindow *)private->parent;
1536 else if (private->window_type == GDK_WINDOW_TEMP)
1537 start_window = get_root (window);
1541 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1543 if (private->window_type == GDK_WINDOW_CHILD && private->parent)
1545 GdkRectangle invalid_rect;
1547 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1548 gdk_drawable_get_size (GDK_DRAWABLE (window),
1549 &invalid_rect.width, &invalid_rect.height);
1550 gdk_window_invalidate_rect ((GdkWindow *)private->parent,
1551 &invalid_rect, TRUE);
1558 * @window: a #GdkWindow
1560 * For toplevel windows, withdraws them, so they will no longer be
1561 * known to the window manager; for all windows, unmaps them, so
1562 * they won't be displayed. Normally done automatically as
1563 * part of gtk_widget_hide().
1567 gdk_window_hide (GdkWindow *window)
1569 GdkWindowObject *private;
1571 g_return_if_fail (window != NULL);
1573 private = (GdkWindowObject*) window;
1575 /* We'll get the unmap notify eventually, and handle it then,
1576 * but checking here makes things more consistent if we are
1577 * just doing stuff ourself.
1579 _gdk_xgrab_check_unmap (window,
1580 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1582 /* You can't simply unmap toplevel windows. */
1583 switch (private->window_type)
1585 case GDK_WINDOW_TOPLEVEL:
1586 case GDK_WINDOW_DIALOG:
1587 case GDK_WINDOW_TEMP: /* ? */
1588 gdk_window_withdraw (window);
1592 case GDK_WINDOW_FOREIGN:
1593 case GDK_WINDOW_ROOT:
1594 case GDK_WINDOW_CHILD:
1598 if (!private->destroyed)
1600 if (GDK_WINDOW_IS_MAPPED (window))
1601 gdk_synthesize_window_state (window,
1603 GDK_WINDOW_STATE_WITHDRAWN);
1605 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1607 _gdk_window_clear_update_area (window);
1611 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1612 GDK_WINDOW_XID (window));
1614 post_unmap (window);
1619 * gdk_window_withdraw:
1620 * @window: a toplevel #GdkWindow
1622 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1623 * This function is not really useful as gdk_window_hide() automatically
1624 * withdraws toplevel windows before hiding them.
1628 gdk_window_withdraw (GdkWindow *window)
1630 GdkWindowObject *private;
1632 g_return_if_fail (window != NULL);
1634 private = (GdkWindowObject*) window;
1635 if (!private->destroyed)
1637 if (GDK_WINDOW_IS_MAPPED (window))
1638 gdk_synthesize_window_state (window,
1640 GDK_WINDOW_STATE_WITHDRAWN);
1642 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1646 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1647 GDK_WINDOW_XID (window), 0);
1649 post_unmap (window);
1655 * @window: a #GdkWindow
1656 * @x: X coordinate relative to window's parent
1657 * @y: Y coordinate relative to window's parent
1659 * Repositions a window relative to its parent window.
1660 * For toplevel windows, window managers may ignore or modify the move;
1661 * you should probably use gtk_window_move() on a #GtkWindow widget
1662 * anyway, instead of using GDK functions. For child windows,
1663 * the move will reliably succeed.
1665 * If you're also planning to resize the window, use gdk_window_move_resize()
1666 * to both move and resize simultaneously, for a nicer visual effect.
1669 gdk_window_move (GdkWindow *window,
1673 GdkWindowObject *private = (GdkWindowObject *)window;
1674 GdkWindowImplX11 *impl;
1676 g_return_if_fail (window != NULL);
1677 g_return_if_fail (GDK_IS_WINDOW (window));
1679 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1681 if (!GDK_WINDOW_DESTROYED (window))
1683 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1685 _gdk_window_move_resize_child (window, x, y,
1686 impl->width, impl->height);
1690 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1691 GDK_WINDOW_XID (window),
1694 if (impl->override_redirect)
1704 * gdk_window_resize:
1705 * @window: a #GdkWindow
1706 * @width: new width of the window
1707 * @height: new height of the window
1709 * Resizes @window; for toplevel windows, asks the window manager to resize
1710 * the window. The window manager may not allow the resize. When using GTK+,
1711 * use gtk_window_resize() instead of this low-level GDK function.
1713 * Windows may not be resized below 1x1.
1715 * If you're also planning to move the window, use gdk_window_move_resize()
1716 * to both move and resize simultaneously, for a nicer visual effect.
1719 gdk_window_resize (GdkWindow *window,
1723 GdkWindowObject *private;
1725 g_return_if_fail (window != NULL);
1726 g_return_if_fail (GDK_IS_WINDOW (window));
1733 private = (GdkWindowObject*) window;
1735 if (!GDK_WINDOW_DESTROYED (window))
1737 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1739 _gdk_window_move_resize_child (window, private->x, private->y,
1744 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1746 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1747 GDK_WINDOW_XID (window),
1750 if (impl->override_redirect)
1752 impl->width = width;
1753 impl->height = height;
1757 if (width != impl->width || height != impl->height)
1758 private->resize_count += 1;
1765 * gdk_window_move_resize:
1766 * @window: a #GdkWindow
1767 * @x: new X position relative to window's parent
1768 * @y: new Y position relative to window's parent
1770 * @height: new height
1772 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1773 * except that both operations are performed at once, avoiding strange
1774 * visual effects. (i.e. the user may be able to see the window first
1775 * move, then resize, if you don't use gdk_window_move_resize().)
1778 gdk_window_move_resize (GdkWindow *window,
1784 GdkWindowObject *private;
1786 g_return_if_fail (window != NULL);
1787 g_return_if_fail (GDK_IS_WINDOW (window));
1794 private = (GdkWindowObject*) window;
1796 if (!GDK_WINDOW_DESTROYED (window))
1798 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1800 _gdk_window_move_resize_child (window, x, y, width, height);
1804 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1806 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1807 GDK_WINDOW_XID (window),
1808 x, y, width, height);
1809 if (impl->override_redirect)
1813 impl->width = width;
1814 impl->height = height;
1818 if (width != impl->width || height != impl->height)
1819 private->resize_count += 1;
1826 * gdk_window_reparent:
1827 * @window: a #GdkWindow
1828 * @new_parent: new parent to move @window into
1829 * @x: X location inside the new parent
1830 * @y: Y location inside the new parent
1832 * Reparents @window into the given @new_parent. The window being
1833 * reparented will be unmapped as a side effect.
1837 gdk_window_reparent (GdkWindow *window,
1838 GdkWindow *new_parent,
1842 GdkDisplay *display;
1843 GdkWindowObject *window_private;
1844 GdkWindowObject *parent_private;
1845 GdkWindowObject *old_parent_private;
1846 GdkWindowImplX11 *impl;
1847 gboolean was_toplevel;
1849 g_return_if_fail (window != NULL);
1850 g_return_if_fail (GDK_IS_WINDOW (window));
1851 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1852 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1854 if (GDK_WINDOW_DESTROYED (window) ||
1855 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1861 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1863 display = GDK_WINDOW_DISPLAY (window);
1865 window_private = (GdkWindowObject*) window;
1866 old_parent_private = (GdkWindowObject*)window_private->parent;
1867 parent_private = (GdkWindowObject*) new_parent;
1868 impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1870 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1871 GDK_WINDOW_XID (window),
1872 GDK_WINDOW_XID (new_parent),
1875 window_private->x = x;
1876 window_private->y = y;
1878 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1881 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1882 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1884 window_private->parent = (GdkWindowObject *)new_parent;
1886 /* Switch the window type as appropriate */
1888 switch (GDK_WINDOW_TYPE (new_parent))
1890 case GDK_WINDOW_ROOT:
1891 case GDK_WINDOW_FOREIGN:
1892 was_toplevel = WINDOW_IS_TOPLEVEL (window);
1894 if (impl->toplevel_window_type != -1)
1895 GDK_WINDOW_TYPE (window) = impl->toplevel_window_type;
1896 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1897 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1899 if (WINDOW_IS_TOPLEVEL (window) && !was_toplevel)
1900 setup_toplevel_window (window, new_parent);
1902 case GDK_WINDOW_TOPLEVEL:
1903 case GDK_WINDOW_CHILD:
1904 case GDK_WINDOW_DIALOG:
1905 case GDK_WINDOW_TEMP:
1906 if (WINDOW_IS_TOPLEVEL (window))
1908 /* Save the original window type so we can restore it if the
1909 * window is reparented back to be a toplevel
1911 impl->toplevel_window_type = GDK_WINDOW_TYPE (window);
1912 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1915 if (impl->toplevel->focus_window)
1917 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1918 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1921 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1923 g_free (impl->toplevel);
1924 impl->toplevel = NULL;
1929 if (old_parent_private)
1930 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1932 if ((old_parent_private &&
1933 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1934 (!old_parent_private && parent_private->guffaw_gravity))
1935 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1937 parent_private->children = g_list_prepend (parent_private->children, window);
1938 _gdk_window_init_position (GDK_WINDOW (window_private));
1942 _gdk_windowing_window_clear_area (GdkWindow *window,
1948 g_return_if_fail (window != NULL);
1949 g_return_if_fail (GDK_IS_WINDOW (window));
1951 if (!GDK_WINDOW_DESTROYED (window))
1952 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1953 x, y, width, height, False);
1957 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1963 g_return_if_fail (window != NULL);
1964 g_return_if_fail (GDK_IS_WINDOW (window));
1966 if (!GDK_WINDOW_DESTROYED (window))
1967 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1968 x, y, width, height, True);
1974 * @window: a #GdkWindow
1976 * Raises @window to the top of the Z-order (stacking order), so that
1977 * other windows with the same parent window appear below @window.
1978 * This is true whether or not the windows are visible.
1980 * If @window is a toplevel, the window manager may choose to deny the
1981 * request to move the window in the Z-order, gdk_window_raise() only
1982 * requests the restack, does not guarantee it.
1986 gdk_window_raise (GdkWindow *window)
1988 g_return_if_fail (window != NULL);
1989 g_return_if_fail (GDK_IS_WINDOW (window));
1991 if (!GDK_WINDOW_DESTROYED (window))
1992 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1997 * @window: a #GdkWindow
1999 * Lowers @window to the bottom of the Z-order (stacking order), so that
2000 * other windows with the same parent window appear above @window.
2001 * This is true whether or not the other windows are visible.
2003 * If @window is a toplevel, the window manager may choose to deny the
2004 * request to move the window in the Z-order, gdk_window_lower() only
2005 * requests the restack, does not guarantee it.
2007 * Note that gdk_window_show() raises the window again, so don't call this
2008 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
2012 gdk_window_lower (GdkWindow *window)
2014 g_return_if_fail (window != NULL);
2015 g_return_if_fail (GDK_IS_WINDOW (window));
2017 if (!GDK_WINDOW_DESTROYED (window))
2018 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
2023 * @window: a #GdkWindow
2024 * @timestamp: timestamp of the event triggering the window focus
2026 * Sets keyboard focus to @window. If @window is not onscreen this
2027 * will not work. In most cases, gtk_window_present() should be used on
2028 * a #GtkWindow, rather than calling this function.
2032 gdk_window_focus (GdkWindow *window,
2035 GdkDisplay *display;
2037 g_return_if_fail (GDK_IS_WINDOW (window));
2039 if (GDK_WINDOW_DESTROYED (window))
2042 display = GDK_WINDOW_DISPLAY (window);
2044 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
2045 gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
2049 xev.xclient.type = ClientMessage;
2050 xev.xclient.serial = 0;
2051 xev.xclient.send_event = True;
2052 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
2053 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
2054 "_NET_ACTIVE_WINDOW");
2055 xev.xclient.format = 32;
2056 xev.xclient.data.l[0] = 1; /* requestor type; we're an app */
2057 xev.xclient.data.l[1] = timestamp;
2058 xev.xclient.data.l[2] = None; /* currently active window */
2059 xev.xclient.data.l[3] = 0;
2060 xev.xclient.data.l[4] = 0;
2062 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
2063 SubstructureRedirectMask | SubstructureNotifyMask,
2068 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
2070 /* There is no way of knowing reliably whether we are viewable;
2071 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
2073 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
2080 * gdk_window_set_hints:
2081 * @window: a #GdkWindow
2082 * @x: ignored field, does not matter
2083 * @y: ignored field, does not matter
2084 * @min_width: minimum width hint
2085 * @min_height: minimum height hint
2086 * @max_width: max width hint
2087 * @max_height: max height hint
2088 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
2090 * This function is broken and useless and you should ignore it.
2091 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
2092 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
2093 * depending on what you're trying to do.
2095 * If using GDK directly, use gdk_window_set_geometry_hints().
2099 gdk_window_set_hints (GdkWindow *window,
2108 XSizeHints size_hints;
2110 g_return_if_fail (window != NULL);
2111 g_return_if_fail (GDK_IS_WINDOW (window));
2113 if (GDK_WINDOW_DESTROYED (window))
2116 size_hints.flags = 0;
2118 if (flags & GDK_HINT_POS)
2120 size_hints.flags |= PPosition;
2125 if (flags & GDK_HINT_MIN_SIZE)
2127 size_hints.flags |= PMinSize;
2128 size_hints.min_width = min_width;
2129 size_hints.min_height = min_height;
2132 if (flags & GDK_HINT_MAX_SIZE)
2134 size_hints.flags |= PMaxSize;
2135 size_hints.max_width = max_width;
2136 size_hints.max_height = max_height;
2139 /* FIXME: Would it be better to delete this property if
2140 * flags == 0? It would save space on the server
2142 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2143 GDK_WINDOW_XID (window),
2148 * gdk_window_set_type_hint:
2149 * @window: A toplevel #GdkWindow
2150 * @hint: A hint of the function this window will have
2152 * The application can use this call to provide a hint to the window
2153 * manager about the functionality of a window. The window manager
2154 * can use this information when determining the decoration and behaviour
2157 * The hint must be set before the window is mapped.
2160 gdk_window_set_type_hint (GdkWindow *window,
2161 GdkWindowTypeHint hint)
2163 GdkDisplay *display;
2166 g_return_if_fail (window != NULL);
2167 g_return_if_fail (GDK_IS_WINDOW (window));
2169 if (GDK_WINDOW_DESTROYED (window))
2172 display = gdk_drawable_get_display (window);
2176 case GDK_WINDOW_TYPE_HINT_DIALOG:
2177 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
2179 case GDK_WINDOW_TYPE_HINT_MENU:
2180 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
2182 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
2183 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
2185 case GDK_WINDOW_TYPE_HINT_UTILITY:
2186 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
2188 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
2189 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
2191 case GDK_WINDOW_TYPE_HINT_DOCK:
2192 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
2194 case GDK_WINDOW_TYPE_HINT_DESKTOP:
2195 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
2198 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
2200 case GDK_WINDOW_TYPE_HINT_NORMAL:
2201 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
2205 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2206 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
2207 XA_ATOM, 32, PropModeReplace,
2208 (guchar *)&atom, 1);
2213 gdk_wmspec_change_state (gboolean add,
2218 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
2221 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
2222 #define _NET_WM_STATE_ADD 1 /* add/set property */
2223 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
2225 xev.xclient.type = ClientMessage;
2226 xev.xclient.serial = 0;
2227 xev.xclient.send_event = True;
2228 xev.xclient.window = GDK_WINDOW_XID (window);
2229 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
2230 xev.xclient.format = 32;
2231 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
2232 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
2233 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
2234 xev.xclient.data.l[3] = 0;
2235 xev.xclient.data.l[4] = 0;
2237 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
2238 SubstructureRedirectMask | SubstructureNotifyMask,
2243 * gdk_window_set_modal_hint:
2244 * @window: A toplevel #GdkWindow
2245 * @modal: TRUE if the window is modal, FALSE otherwise.
2247 * The application can use this hint to tell the window manager
2248 * that a certain window has modal behaviour. The window manager
2249 * can use this information to handle modal windows in a special
2252 * You should only use this on windows for which you have
2253 * previously called #gdk_window_set_transient_for()
2256 gdk_window_set_modal_hint (GdkWindow *window,
2259 GdkWindowObject *private;
2261 g_return_if_fail (window != NULL);
2262 g_return_if_fail (GDK_IS_WINDOW (window));
2264 if (GDK_WINDOW_DESTROYED (window))
2267 private = (GdkWindowObject*) window;
2269 private->modal_hint = modal;
2271 if (GDK_WINDOW_IS_MAPPED (window))
2272 gdk_wmspec_change_state (modal, window,
2273 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
2278 * gdk_window_set_skip_taskbar_hint:
2279 * @window: a toplevel #GdkWindow
2280 * @skips_taskbar: %TRUE to skip the taskbar
2282 * Toggles whether a window should appear in a task list or window
2283 * list. If a window's semantic type as specified with
2284 * gdk_window_set_type_hint() already fully describes the window, this
2285 * function should NOT be called in addition, instead you should allow
2286 * the window to be treated according to standard policy for its
2292 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2293 gboolean skips_taskbar)
2295 GdkToplevelX11 *toplevel;
2297 g_return_if_fail (window != NULL);
2298 g_return_if_fail (GDK_IS_WINDOW (window));
2299 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2301 if (GDK_WINDOW_DESTROYED (window))
2304 toplevel = _gdk_x11_window_get_toplevel (window);
2305 toplevel->skip_taskbar_hint = skips_taskbar;
2307 if (GDK_WINDOW_IS_MAPPED (window))
2308 gdk_wmspec_change_state (skips_taskbar, window,
2309 gdk_atom_intern ("_NET_WM_STATE_SKIP_TASKBAR", FALSE),
2314 * gdk_window_set_skip_pager_hint:
2315 * @window: a toplevel #GdkWindow
2316 * @skips_pager: %TRUE to skip the pager
2318 * Toggles whether a window should appear in a pager (workspace
2319 * switcher, or other desktop utility program that displays a small
2320 * thumbnail representation of the windows on the desktop). If a
2321 * window's semantic type as specified with gdk_window_set_type_hint()
2322 * already fully describes the window, this function should NOT be
2323 * called in addition, instead you should allow the window to be
2324 * treated according to standard policy for its semantic type.
2329 gdk_window_set_skip_pager_hint (GdkWindow *window,
2330 gboolean skips_pager)
2332 GdkToplevelX11 *toplevel;
2334 g_return_if_fail (window != NULL);
2335 g_return_if_fail (GDK_IS_WINDOW (window));
2336 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2338 if (GDK_WINDOW_DESTROYED (window))
2341 toplevel = _gdk_x11_window_get_toplevel (window);
2342 toplevel->skip_pager_hint = skips_pager;
2344 if (GDK_WINDOW_IS_MAPPED (window))
2345 gdk_wmspec_change_state (skips_pager, window,
2346 gdk_atom_intern ("_NET_WM_STATE_SKIP_PAGER", FALSE),
2351 * gdk_window_set_geometry_hints:
2352 * @window: a toplevel #GdkWindow
2353 * @geometry: geometry hints
2354 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2356 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2357 * are set, hints not flagged in @geom_mask are unset.
2358 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2360 * This function provides hints to the windowing system about
2361 * acceptable sizes for a toplevel window. The purpose of
2362 * this is to constrain user resizing, but the windowing system
2363 * will typically (but is not required to) also constrain the
2364 * current size of the window to the provided values and
2365 * constrain programatic resizing via gdk_window_resize() or
2366 * gdk_window_move_resize().
2368 * Note that on X11, this effect has no effect on windows
2369 * of type GDK_WINDOW_TEMP or windows where override_redirect
2370 * has been turned on via gdk_window_set_override_redirect()
2371 * since these windows are not resizable by the user.
2373 * Since you can't count on the windowing system doing the
2374 * constraints for programmatic resizes, you should generally
2375 * call gdk_window_constrain_size() yourself to determine
2376 * appropriate sizes.
2380 gdk_window_set_geometry_hints (GdkWindow *window,
2381 GdkGeometry *geometry,
2382 GdkWindowHints geom_mask)
2384 XSizeHints size_hints;
2386 g_return_if_fail (window != NULL);
2387 g_return_if_fail (GDK_IS_WINDOW (window));
2389 if (GDK_WINDOW_DESTROYED (window))
2392 size_hints.flags = 0;
2394 if (geom_mask & GDK_HINT_POS)
2396 size_hints.flags |= PPosition;
2397 /* We need to initialize the following obsolete fields because KWM
2398 * apparently uses these fields if they are non-zero.
2405 if (geom_mask & GDK_HINT_USER_POS)
2407 size_hints.flags |= USPosition;
2410 if (geom_mask & GDK_HINT_USER_SIZE)
2412 size_hints.flags |= USSize;
2415 if (geom_mask & GDK_HINT_MIN_SIZE)
2417 size_hints.flags |= PMinSize;
2418 size_hints.min_width = geometry->min_width;
2419 size_hints.min_height = geometry->min_height;
2422 if (geom_mask & GDK_HINT_MAX_SIZE)
2424 size_hints.flags |= PMaxSize;
2425 size_hints.max_width = MAX (geometry->max_width, 1);
2426 size_hints.max_height = MAX (geometry->max_height, 1);
2429 if (geom_mask & GDK_HINT_BASE_SIZE)
2431 size_hints.flags |= PBaseSize;
2432 size_hints.base_width = geometry->base_width;
2433 size_hints.base_height = geometry->base_height;
2436 if (geom_mask & GDK_HINT_RESIZE_INC)
2438 size_hints.flags |= PResizeInc;
2439 size_hints.width_inc = geometry->width_inc;
2440 size_hints.height_inc = geometry->height_inc;
2443 if (geom_mask & GDK_HINT_ASPECT)
2445 size_hints.flags |= PAspect;
2446 if (geometry->min_aspect <= 1)
2448 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2449 size_hints.min_aspect.y = 65536;
2453 size_hints.min_aspect.x = 65536;
2454 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2456 if (geometry->max_aspect <= 1)
2458 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2459 size_hints.max_aspect.y = 65536;
2463 size_hints.max_aspect.x = 65536;
2464 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2468 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2470 size_hints.flags |= PWinGravity;
2471 size_hints.win_gravity = geometry->win_gravity;
2474 /* FIXME: Would it be better to delete this property if
2475 * geom_mask == 0? It would save space on the server
2477 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2478 GDK_WINDOW_XID (window),
2483 gdk_window_get_geometry_hints (GdkWindow *window,
2484 GdkGeometry *geometry,
2485 GdkWindowHints *geom_mask)
2487 XSizeHints size_hints;
2488 glong junk_size_mask = 0;
2490 g_return_if_fail (GDK_IS_WINDOW (window));
2491 g_return_if_fail (geometry != NULL);
2492 g_return_if_fail (geom_mask != NULL);
2496 if (GDK_WINDOW_DESTROYED (window))
2499 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2500 GDK_WINDOW_XID (window),
2505 if (size_hints.flags & PMinSize)
2507 *geom_mask |= GDK_HINT_MIN_SIZE;
2508 geometry->min_width = size_hints.min_width;
2509 geometry->min_height = size_hints.min_height;
2512 if (size_hints.flags & PMaxSize)
2514 *geom_mask |= GDK_HINT_MAX_SIZE;
2515 geometry->max_width = MAX (size_hints.max_width, 1);
2516 geometry->max_height = MAX (size_hints.max_height, 1);
2519 if (size_hints.flags & PResizeInc)
2521 *geom_mask |= GDK_HINT_RESIZE_INC;
2522 geometry->width_inc = size_hints.width_inc;
2523 geometry->height_inc = size_hints.height_inc;
2526 if (size_hints.flags & PAspect)
2528 *geom_mask |= GDK_HINT_ASPECT;
2530 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
2531 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
2534 if (size_hints.flags & PWinGravity)
2536 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2537 geometry->win_gravity = size_hints.win_gravity;
2542 utf8_is_latin1 (const gchar *str)
2544 const char *p = str;
2548 gunichar ch = g_utf8_get_char (p);
2553 p = g_utf8_next_char (p);
2559 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2560 * convertable to STRING, otherwise, set it as compound text
2563 set_text_property (GdkDisplay *display,
2566 const gchar *utf8_str)
2568 guchar *prop_text = NULL;
2572 gboolean is_compound_text;
2574 if (utf8_is_latin1 (utf8_str))
2576 prop_type = XA_STRING;
2577 prop_text = gdk_utf8_to_string_target (utf8_str);
2578 prop_length = prop_text ? strlen (prop_text) : 0;
2580 is_compound_text = FALSE;
2586 gdk_utf8_to_compound_text_for_display (display,
2587 utf8_str, &gdk_type, &prop_format,
2588 &prop_text, &prop_length);
2589 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2590 is_compound_text = TRUE;
2595 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2598 prop_type, prop_format,
2599 PropModeReplace, prop_text,
2602 if (is_compound_text)
2603 gdk_free_compound_text (prop_text);
2609 /* Set WM_NAME and _NET_WM_NAME
2612 set_wm_name (GdkDisplay *display,
2616 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2617 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2618 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2619 PropModeReplace, name, strlen (name));
2621 set_text_property (display, xwindow,
2622 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2627 * gdk_window_set_title:
2628 * @window: a toplevel #GdkWindow
2629 * @title: title of @window
2631 * Sets the title of a toplevel window, to be displayed in the titlebar.
2632 * If you haven't explicitly set the icon name for the window
2633 * (using gdk_window_set_icon_name()), the icon name will be set to
2634 * @title as well. @title must be in UTF-8 encoding (as with all
2635 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2638 gdk_window_set_title (GdkWindow *window,
2641 GdkDisplay *display;
2645 g_return_if_fail (window != NULL);
2646 g_return_if_fail (GDK_IS_WINDOW (window));
2647 g_return_if_fail (title != NULL);
2649 if (GDK_WINDOW_DESTROYED (window))
2652 display = gdk_drawable_get_display (window);
2653 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2654 xwindow = GDK_WINDOW_XID (window);
2656 set_wm_name (display, xwindow, title);
2658 if (!gdk_window_icon_name_set (window))
2660 XChangeProperty (xdisplay, xwindow,
2661 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2662 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2663 PropModeReplace, title, strlen (title));
2665 set_text_property (display, xwindow,
2666 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2672 * gdk_window_set_role:
2673 * @window: a toplevel #GdkWindow
2674 * @role: a string indicating its role
2676 * When using GTK+, typically you should use gtk_window_set_role() instead
2677 * of this low-level function.
2679 * The window manager and session manager use a window's role to
2680 * distinguish it from other kinds of window in the same application.
2681 * When an application is restarted after being saved in a previous
2682 * session, all windows with the same title and role are treated as
2683 * interchangeable. So if you have two windows with the same title
2684 * that should be distinguished for session management purposes, you
2685 * should set the role on those windows. It doesn't matter what string
2686 * you use for the role, as long as you have a different role for each
2687 * non-interchangeable kind of window.
2691 gdk_window_set_role (GdkWindow *window,
2694 GdkDisplay *display;
2696 g_return_if_fail (window != NULL);
2697 g_return_if_fail (GDK_IS_WINDOW (window));
2699 display = gdk_drawable_get_display (window);
2701 if (!GDK_WINDOW_DESTROYED (window))
2704 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2705 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2706 XA_STRING, 8, PropModeReplace, role, strlen (role));
2708 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2709 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2714 * gdk_window_set_transient_for:
2715 * @window: a toplevel #GdkWindow
2716 * @parent: another toplevel #GdkWindow
2718 * Indicates to the window manager that @window is a transient dialog
2719 * associated with the application window @parent. This allows the
2720 * window manager to do things like center @window on @parent and
2721 * keep @window above @parent.
2723 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2728 gdk_window_set_transient_for (GdkWindow *window,
2731 GdkWindowObject *private;
2732 GdkWindowObject *parent_private;
2734 g_return_if_fail (window != NULL);
2735 g_return_if_fail (GDK_IS_WINDOW (window));
2737 private = (GdkWindowObject*) window;
2738 parent_private = (GdkWindowObject*) parent;
2740 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2741 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2742 GDK_WINDOW_XID (window),
2743 GDK_WINDOW_XID (parent));
2747 * gdk_window_set_background:
2748 * @window: a #GdkWindow
2749 * @color: an allocated #GdkColor
2751 * Sets the background color of @window. (However, when using GTK+,
2752 * set the background of a widget with gtk_widget_modify_bg() - if
2753 * you're an application - or gtk_style_set_background() - if you're
2754 * implementing a custom widget.)
2756 * The @color must be allocated; gdk_rgb_find_color() is the best way
2757 * to allocate a color.
2759 * See also gdk_window_set_back_pixmap().
2763 gdk_window_set_background (GdkWindow *window,
2764 const GdkColor *color)
2766 GdkWindowObject *private = (GdkWindowObject *)window;
2768 g_return_if_fail (window != NULL);
2769 g_return_if_fail (GDK_IS_WINDOW (window));
2771 if (!GDK_WINDOW_DESTROYED (window))
2772 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2773 GDK_WINDOW_XID (window), color->pixel);
2775 private->bg_color = *color;
2777 if (private->bg_pixmap &&
2778 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2779 private->bg_pixmap != GDK_NO_BG)
2780 g_object_unref (private->bg_pixmap);
2782 private->bg_pixmap = NULL;
2786 * gdk_window_set_back_pixmap:
2787 * @window: a #GdkWindow
2788 * @pixmap: a #GdkPixmap, or %NULL
2789 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2791 * Sets the background pixmap of @window. May also be used to set a background of
2792 * "None" on @window, by setting a background pixmap of %NULL.
2793 * A background pixmap will be tiled, positioning the first tile at the origin of
2794 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2795 * origin of the parent window (useful to align tiles in a parent with tiles
2798 * A background pixmap of %NULL means that the window will have no
2799 * background. A window with no background will never have its
2800 * background filled by the windowing system, instead the window will
2801 * contain whatever pixels were already in the corresponding area of
2804 * The windowing system will normally fill a window with its background
2805 * when the window is obscured then exposed, and when you call
2806 * gdk_window_clear().
2810 gdk_window_set_back_pixmap (GdkWindow *window,
2812 gboolean parent_relative)
2814 GdkWindowObject *private = (GdkWindowObject *)window;
2817 g_return_if_fail (window != NULL);
2818 g_return_if_fail (GDK_IS_WINDOW (window));
2819 g_return_if_fail (pixmap == NULL || !parent_relative);
2820 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2822 if (private->bg_pixmap &&
2823 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2824 private->bg_pixmap != GDK_NO_BG)
2825 g_object_unref (private->bg_pixmap);
2827 if (parent_relative)
2829 xpixmap = ParentRelative;
2830 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
2836 g_object_ref (pixmap);
2837 private->bg_pixmap = pixmap;
2838 xpixmap = GDK_PIXMAP_XID (pixmap);
2843 private->bg_pixmap = GDK_NO_BG;
2847 if (!GDK_WINDOW_DESTROYED (window))
2848 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2849 GDK_WINDOW_XID (window), xpixmap);
2853 * gdk_window_set_cursor:
2854 * @window: a #GdkWindow
2857 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
2858 * gdk_cursor_new_from_pixmap() to create the cursor.
2859 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
2860 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
2861 * to gdk_window_set_cursor() means that @window will use the cursor of
2862 * its parent window. Most windows should use this default.
2866 gdk_window_set_cursor (GdkWindow *window,
2869 GdkCursorPrivate *cursor_private;
2872 g_return_if_fail (window != NULL);
2873 g_return_if_fail (GDK_IS_WINDOW (window));
2875 cursor_private = (GdkCursorPrivate*) cursor;
2880 xcursor = cursor_private->xcursor;
2882 if (!GDK_WINDOW_DESTROYED (window))
2883 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
2884 GDK_WINDOW_XID (window),
2889 * gdk_window_get_geometry:
2890 * @window: a #GdkWindow
2891 * @x: return location for X coordinate of window (relative to its parent)
2892 * @y: return location for Y coordinate of window (relative to its parent)
2893 * @width: return location for width of window
2894 * @height: return location for height of window
2895 * @depth: return location for bit depth of window
2897 * Any of the return location arguments to this function may be %NULL,
2898 * if you aren't interested in getting the value of that field.
2900 * The X and Y coordinates returned are relative to the parent window
2901 * of @window, which for toplevels usually means relative to the
2902 * window decorations (titlebar, etc.) rather than relative to the
2903 * root window (screen-size background window).
2905 * On the X11 platform, the geometry is obtained from the X server,
2906 * so reflects the latest position of @window; this may be out-of-sync
2907 * with the position of @window delivered in the most-recently-processed
2908 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
2909 * position from the most recent configure event.
2912 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
2913 * to call gdk_window_get_position() and gdk_drawable_get_size() instead,
2914 * because it avoids the roundtrip to the X server and because
2915 * gdk_drawable_get_size() supports the full 32-bit coordinate space,
2916 * whereas gdk_window_get_geometry() is restricted to the 16-bit
2917 * coordinates of X11.
2921 gdk_window_get_geometry (GdkWindow *window,
2933 guint tborder_width;
2936 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
2940 GDK_NOTE (MULTIHEAD,
2941 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
2942 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
2945 if (!GDK_WINDOW_DESTROYED (window))
2947 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2948 GDK_WINDOW_XID (window),
2949 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2965 * gdk_window_get_origin:
2966 * @window: a #GdkWindow
2967 * @x: return location for X coordinate
2968 * @y: return location for Y coordinate
2970 * Obtains the position of a window in root window coordinates.
2971 * (Compare with gdk_window_get_position() and
2972 * gdk_window_get_geometry() which return the position of a window
2973 * relative to its parent window.)
2975 * Return value: not meaningful, ignore
2978 gdk_window_get_origin (GdkWindow *window,
2987 g_return_val_if_fail (window != NULL, 0);
2989 if (!GDK_WINDOW_DESTROYED (window))
2991 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2992 GDK_WINDOW_XID (window),
2993 GDK_WINDOW_XROOTWIN (window),
3009 * gdk_window_get_deskrelative_origin:
3010 * @window: a toplevel #GdkWindow
3011 * @x: return location for X coordinate
3012 * @y: return location for Y coordinate
3014 * This gets the origin of a #GdkWindow relative to
3015 * an Enlightenment-window-manager desktop. As long as you don't
3016 * assume that the user's desktop/workspace covers the entire
3017 * root window (i.e. you don't assume that the desktop begins
3018 * at root window coordinate 0,0) this function is not necessary.
3019 * It's deprecated for that reason.
3021 * Return value: not meaningful
3024 gdk_window_get_deskrelative_origin (GdkWindow *window,
3028 gboolean return_val = FALSE;
3029 gint num_children, format_return;
3030 Window win, *child, parent, root;
3035 gulong number_return, bytes_after_return;
3036 guchar *data_return;
3038 g_return_val_if_fail (window != NULL, FALSE);
3039 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3041 if (!GDK_WINDOW_DESTROYED (window))
3043 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3044 "ENLIGHTENMENT_DESKTOP");
3045 win = GDK_WINDOW_XID (window);
3047 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
3048 &child, (unsigned int *)&num_children))
3050 if ((child) && (num_children > 0))
3062 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
3063 False, XA_CARDINAL, &type_return, &format_return,
3064 &number_return, &bytes_after_return, &data_return);
3066 if (type_return == XA_CARDINAL)
3068 XFree (data_return);
3073 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
3074 GDK_WINDOW_XID (window),
3089 * gdk_window_get_root_origin:
3090 * @window: a toplevel #GdkWindow
3091 * @x: return location for X position of window frame
3092 * @y: return location for Y position of window frame
3094 * Obtains the top-left corner of the window manager frame in root
3095 * window coordinates.
3099 gdk_window_get_root_origin (GdkWindow *window,
3105 g_return_if_fail (GDK_IS_WINDOW (window));
3107 gdk_window_get_frame_extents (window, &rect);
3117 * gdk_window_get_frame_extents:
3118 * @window: a toplevel #GdkWindow
3119 * @rect: rectangle to fill with bounding box of the window frame
3121 * Obtains the bounding box of the window, including window manager
3122 * titlebar/borders if any. The frame position is given in root window
3123 * coordinates. To get the position of the window itself (rather than
3124 * the frame) in root window coordinates, use gdk_window_get_origin().
3128 gdk_window_get_frame_extents (GdkWindow *window,
3131 GdkDisplay *display;
3132 GdkWindowObject *private;
3142 gulong nitems_return;
3143 gulong bytes_after_return;
3146 guint ww, wh, wb, wd;
3149 g_return_if_fail (GDK_IS_WINDOW (window));
3150 g_return_if_fail (rect != NULL);
3152 private = (GdkWindowObject*) window;
3159 if (GDK_WINDOW_DESTROYED (window))
3162 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
3163 private = (GdkWindowObject*) private->parent;
3165 /* Refine our fallback answer a bit using local information */
3166 rect->x = private->x;
3167 rect->y = private->y;
3168 gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height);
3170 if (GDK_WINDOW_DESTROYED (private))
3173 gdk_error_trap_push();
3175 /* use NETWM_VIRTUAL_ROOTS if available */
3176 display = gdk_drawable_get_display (window);
3177 root = GDK_WINDOW_XROOTWIN (window);
3182 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
3183 gdk_x11_get_xatom_by_name_for_display (display,
3184 "_NET_VIRTUAL_ROOTS"),
3185 0, G_MAXLONG, False, XA_WINDOW, &type_return,
3186 &format_return, &nitems_return, &bytes_after_return,
3190 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
3192 nvroots = nitems_return;
3193 vroots = (Window *)data;
3197 xparent = GDK_WINDOW_XID (window);
3203 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
3205 &children, &nchildren))
3211 /* check virtual roots */
3212 for (i = 0; i < nvroots; i++)
3214 if (xparent == vroots[i])
3221 while (xparent != root);
3223 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
3224 &root, &wx, &wy, &ww, &wh, &wb, &wd))
3236 gdk_error_trap_pop ();
3240 _gdk_windowing_get_pointer (GdkDisplay *display,
3244 GdkModifierType *mask)
3246 GdkScreen *default_screen;
3254 if (display->closed)
3257 default_screen = gdk_display_get_default_screen (display);
3259 XQueryPointer (GDK_SCREEN_XDISPLAY (default_screen),
3260 GDK_SCREEN_XROOTWIN (default_screen),
3261 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3265 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
3266 *screen = gdk_drawable_get_screen (gdk_root);
3275 _gdk_windowing_window_get_pointer (GdkDisplay *display,
3279 GdkModifierType *mask)
3281 GdkWindow *return_val;
3287 unsigned int xmask = 0;
3288 gint xoffset, yoffset;
3290 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
3292 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3295 if (!GDK_WINDOW_DESTROYED (window) &&
3296 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
3297 GDK_WINDOW_XID (window),
3298 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
3301 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
3304 *x = winx + xoffset;
3305 *y = winy + yoffset;
3312 * gdk_display_warp_pointer:
3313 * @display: a #GdkDisplay
3314 * @screen: the screen of @display to warp the pointer to
3315 * @x: the x coordinate of the destination
3316 * @y: the y coordinate of the destination
3318 * Warps the pointer of @display to the point @x,@y on
3319 * the screen @screen, unless the pointer is confined
3320 * to a window by a grab, in which case it will be moved
3321 * as far as allowed by the grab. Warping the pointer
3322 * creates events as if the user had moved the mouse
3323 * instantaneously to the destination.
3325 * Note that the pointer should normally be under the
3326 * control of the user. This function was added to cover
3327 * some rare use cases like keyboard navigation support
3328 * for the color picker in the #GtkColorSelectionDialog.
3333 gdk_display_warp_pointer (GdkDisplay *display,
3341 xdisplay = GDK_DISPLAY_XDISPLAY (display);
3342 dest = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen));
3344 XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, x, y);
3348 _gdk_windowing_window_at_pointer (GdkDisplay *display,
3357 Window xwindow_last = 0;
3359 int rootx = -1, rooty = -1;
3363 screen = gdk_display_get_default_screen (display);
3365 xwindow = GDK_SCREEN_XROOTWIN (screen);
3366 xdisplay = GDK_SCREEN_XDISPLAY (screen);
3368 /* This function really only works if the mouse pointer is held still
3369 * during its operation. If it moves from one leaf window to another
3370 * than we'll end up with inaccurate values for win_x, win_y
3373 gdk_x11_display_grab (display);
3374 XQueryPointer (xdisplay, xwindow,
3375 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3377 if (root == xwindow)
3384 xwindow_last = xwindow;
3385 XQueryPointer (xdisplay, xwindow,
3386 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3388 gdk_x11_display_ungrab (display);
3390 window = gdk_window_lookup_for_display (GDK_SCREEN_DISPLAY(screen),
3392 *win_x = window ? winx : -1;
3393 *win_y = window ? winy : -1;
3399 * gdk_window_get_events:
3400 * @window: a #GdkWindow
3402 * Gets the event mask for @window. See gdk_window_set_events().
3404 * Return value: event mask for @window
3407 gdk_window_get_events (GdkWindow *window)
3409 XWindowAttributes attrs;
3410 GdkEventMask event_mask;
3412 g_return_val_if_fail (window != NULL, 0);
3413 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
3415 if (GDK_WINDOW_DESTROYED (window))
3419 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3420 GDK_WINDOW_XID (window),
3423 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
3424 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3431 * gdk_window_set_events:
3432 * @window: a #GdkWindow
3433 * @event_mask: event mask for @window
3435 * The event mask for a window determines which events will be reported
3436 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
3437 * means the window should report button press events. The event mask
3438 * is the bitwise OR of values from the #GdkEventMask enumeration.
3442 gdk_window_set_events (GdkWindow *window,
3443 GdkEventMask event_mask)
3448 g_return_if_fail (window != NULL);
3449 g_return_if_fail (GDK_IS_WINDOW (window));
3451 if (!GDK_WINDOW_DESTROYED (window))
3453 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3454 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3455 for (i = 0; i < _gdk_nenvent_masks; i++)
3457 if (event_mask & (1 << (i + 1)))
3458 xevent_mask |= _gdk_event_mask_table[i];
3461 XSelectInput (GDK_WINDOW_XDISPLAY (window),
3462 GDK_WINDOW_XID (window),
3468 gdk_window_add_colormap_windows (GdkWindow *window)
3470 GdkWindow *toplevel;
3471 Window *old_windows;
3472 Window *new_windows;
3475 g_return_if_fail (window != NULL);
3476 g_return_if_fail (GDK_IS_WINDOW (window));
3478 if (GDK_WINDOW_DESTROYED (window))
3480 toplevel = gdk_window_get_toplevel (window);
3483 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3484 GDK_WINDOW_XID (toplevel),
3485 &old_windows, &count))
3490 for (i = 0; i < count; i++)
3491 if (old_windows[i] == GDK_WINDOW_XID (window))
3493 XFree (old_windows);
3497 new_windows = g_new (Window, count + 1);
3499 for (i = 0; i < count; i++)
3500 new_windows[i] = old_windows[i];
3501 new_windows[count] = GDK_WINDOW_XID (window);
3503 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3504 GDK_WINDOW_XID (toplevel),
3505 new_windows, count + 1);
3507 g_free (new_windows);
3509 XFree (old_windows);
3513 gdk_window_have_shape_ext (GdkDisplay *display)
3515 #ifdef HAVE_SHAPE_EXT
3518 return XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display),
3525 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
3528 * This needs the X11 shape extension.
3529 * If not available, shaped windows will look
3530 * ugly, but programs still work. Stefan Wille
3533 * gdk_window_shape_combine_mask:
3534 * @window: a #GdkWindow
3536 * @x: X position of shape mask with respect to @window
3537 * @y: Y position of shape mask with respect to @window
3539 * Applies a shape mask to @window. Pixels in @window corresponding to
3540 * set bits in the @mask will be visible; pixels in @window
3541 * corresponding to unset bits in the @mask will be transparent. This
3542 * gives a non-rectangular window.
3544 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
3545 * parameters are not used.
3547 * On the X11 platform, this uses an X server extension which is
3548 * widely available on most common platforms, but not available on
3549 * very old X servers, and occasionally the implementation will be
3550 * buggy. On servers without the shape extension, this function
3553 * This function works on both toplevel and child windows.
3557 gdk_window_shape_combine_mask (GdkWindow *window,
3562 gint xoffset, yoffset;
3564 g_return_if_fail (window != NULL);
3565 g_return_if_fail (GDK_IS_WINDOW (window));
3567 #ifdef HAVE_SHAPE_EXT
3568 if (GDK_WINDOW_DESTROYED (window))
3571 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3573 if (xoffset != 0 || yoffset != 0)
3575 WARN_SHAPE_TOO_BIG ();
3579 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3583 pixmap = GDK_PIXMAP_XID (mask);
3592 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3593 GDK_WINDOW_XID (window),
3599 #endif /* HAVE_SHAPE_EXT */
3603 * gdk_window_shape_combine_region:
3604 * @window: a #GdkWindow
3605 * @shape_region: region of window to be non-transparent
3606 * @offset_x: X position of @shape_region in @window coordinates
3607 * @offset_y: Y position of @shape_region in @window coordinates
3609 * Makes pixels in @window outside @shape_region be transparent,
3610 * so that the window may be nonrectangular. See also
3611 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
3613 * If @shape_region is %NULL, the shape will be unset, so the whole
3614 * window will be opaque again. @offset_x and @offset_y are ignored
3615 * if @shape_region is %NULL.
3617 * On the X11 platform, this uses an X server extension which is
3618 * widely available on most common platforms, but not available on
3619 * very old X servers, and occasionally the implementation will be
3620 * buggy. On servers without the shape extension, this function
3623 * This function works on both toplevel and child windows.
3627 gdk_window_shape_combine_region (GdkWindow *window,
3628 GdkRegion *shape_region,
3632 gint xoffset, yoffset;
3634 g_return_if_fail (GDK_IS_WINDOW (window));
3636 #ifdef HAVE_SHAPE_EXT
3637 if (GDK_WINDOW_DESTROYED (window))
3640 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3642 if (xoffset != 0 || yoffset != 0)
3644 WARN_SHAPE_TOO_BIG ();
3648 if (shape_region == NULL)
3650 /* Use NULL mask to unset the shape */
3651 gdk_window_shape_combine_mask (window, NULL, 0, 0);
3655 if (gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
3658 XRectangle *xrects = NULL;
3660 _gdk_region_get_xrectangles (shape_region,
3664 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
3665 GDK_WINDOW_XID (window),
3674 #endif /* HAVE_SHAPE_EXT */
3679 * gdk_window_set_override_redirect:
3680 * @window: a toplevel #GdkWindow
3681 * @override_redirect: %TRUE if window should be override redirect
3683 * An override redirect window is not under the control of the window manager.
3684 * This means it won't have a titlebar, won't be minimizable, etc. - it will
3685 * be entirely under the control of the application. The window manager
3686 * can't see the override redirect window at all.
3688 * Override redirect should only be used for short-lived temporary
3689 * windows, such as popup menus. #GtkMenu uses an override redirect
3690 * window in its implementation, for example.
3694 gdk_window_set_override_redirect (GdkWindow *window,
3695 gboolean override_redirect)
3697 XSetWindowAttributes attr;
3699 g_return_if_fail (window != NULL);
3700 g_return_if_fail (GDK_IS_WINDOW (window));
3702 if (!GDK_WINDOW_DESTROYED (window))
3704 GdkWindowObject *private = (GdkWindowObject *)window;
3705 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
3707 attr.override_redirect = (override_redirect? True : False);
3708 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3709 GDK_WINDOW_XID (window),
3713 impl->override_redirect = attr.override_redirect;
3718 * gdk_window_set_accept_focus:
3719 * @window: a toplevel #GdkWindow
3720 * @accept_focus: %TRUE if the window should receive input focus
3722 * Setting @accept_focus to %FALSE hints the desktop environment that the
3723 * window doesn't want to receive input focus.
3725 * On X, it is the responsibility of the window manager to interpret this
3726 * hint. ICCCM-compliant window manager usually respect it.
3731 gdk_window_set_accept_focus (GdkWindow *window,
3732 gboolean accept_focus)
3734 GdkWindowObject *private;
3735 g_return_if_fail (window != NULL);
3736 g_return_if_fail (GDK_IS_WINDOW (window));
3738 private = (GdkWindowObject *)window;
3740 accept_focus = accept_focus != FALSE;
3742 if (private->accept_focus != accept_focus)
3744 private->accept_focus = accept_focus;
3746 if (!GDK_WINDOW_DESTROYED (window))
3747 update_wm_hints (window, FALSE);
3752 * gdk_window_set_focus_on_map:
3753 * @window: a toplevel #GdkWindow
3754 * @focus_on_map: %TRUE if the window should receive input focus when mapped
3756 * Setting @focus_on_map to %FALSE hints the desktop environment that the
3757 * window doesn't want to receive input focus when it is mapped.
3758 * focus_on_map should be turned off for windows that aren't triggered
3759 * interactively (such as popups from network activity).
3761 * On X, it is the responsibility of the window manager to interpret
3762 * this hint. Window managers following the freedesktop.org window
3763 * manager extension specification should respect it.
3768 gdk_window_set_focus_on_map (GdkWindow *window,
3769 gboolean focus_on_map)
3771 GdkWindowObject *private;
3772 g_return_if_fail (window != NULL);
3773 g_return_if_fail (GDK_IS_WINDOW (window));
3775 private = (GdkWindowObject *)window;
3777 focus_on_map = focus_on_map != FALSE;
3779 if (private->focus_on_map != focus_on_map)
3781 private->focus_on_map = focus_on_map;
3783 if ((!GDK_WINDOW_DESTROYED (window)) && (!private->focus_on_map))
3784 gdk_x11_window_set_user_time (window, 0);
3789 * gdk_x11_window_set_user_time:
3790 * @window: A toplevel #GdkWindow
3791 * @timestamp: An XServer timestamp to which the property should be set
3793 * The application can use this call to update the _NET_WM_USER_TIME
3794 * property on a toplevel window. This property stores an Xserver
3795 * time which represents the time of the last user input event
3796 * received for this window. This property may be used by the window
3797 * manager to alter the focus, stacking, and/or placement behavior of
3798 * windows when they are mapped depending on whether the new window
3799 * was created by a user action or is a "pop-up" window activated by a
3800 * timer or some other event.
3802 * Note that this property is automatically updated by GDK, so this
3803 * function should only be used by applications which handle input
3804 * events bypassing GDK.
3809 gdk_x11_window_set_user_time (GdkWindow *window,
3812 GdkDisplay *display;
3813 GdkDisplayX11 *display_x11;
3814 GdkToplevelX11 *toplevel;
3815 glong timestamp_long = (glong)timestamp;
3817 g_return_if_fail (window != NULL);
3818 g_return_if_fail (GDK_IS_WINDOW (window));
3820 if (GDK_WINDOW_DESTROYED (window))
3823 display = gdk_drawable_get_display (window);
3824 display_x11 = GDK_DISPLAY_X11 (display);
3825 toplevel = _gdk_x11_window_get_toplevel (window);
3827 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3828 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3829 XA_CARDINAL, 32, PropModeReplace,
3830 (guchar *)×tamp_long, 1);
3832 if (timestamp_long != GDK_CURRENT_TIME)
3833 display_x11->user_time = timestamp_long;
3835 toplevel->user_time = timestamp_long;
3839 * gdk_window_set_icon_list:
3840 * @window: The #GdkWindow toplevel window to set the icon of.
3841 * @pixbufs: A list of pixbufs, of different sizes.
3843 * Sets a list of icons for the window. One of these will be used
3844 * to represent the window when it has been iconified. The icon is
3845 * usually shown in an icon box or some sort of task bar. Which icon
3846 * size is shown depends on the window manager. The window manager
3847 * can scale the icon but setting several size icons can give better
3848 * image quality since the window manager may only need to scale the
3849 * icon by a small amount or not at all.
3853 gdk_window_set_icon_list (GdkWindow *window,
3862 gint width, height, stride;
3865 GdkDisplay *display;
3867 g_return_if_fail (GDK_IS_WINDOW (window));
3869 if (GDK_WINDOW_DESTROYED (window))
3872 display = gdk_drawable_get_display (window);
3880 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3882 width = gdk_pixbuf_get_width (pixbuf);
3883 height = gdk_pixbuf_get_height (pixbuf);
3885 size += 2 + width * height;
3887 l = g_list_next (l);
3890 data = g_malloc (size * sizeof (gulong));
3898 width = gdk_pixbuf_get_width (pixbuf);
3899 height = gdk_pixbuf_get_height (pixbuf);
3900 stride = gdk_pixbuf_get_rowstride (pixbuf);
3901 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3906 pixels = gdk_pixbuf_get_pixels (pixbuf);
3908 for (y = 0; y < height; y++)
3910 for (x = 0; x < width; x++)
3914 r = pixels[y*stride + x*n_channels + 0];
3915 g = pixels[y*stride + x*n_channels + 1];
3916 b = pixels[y*stride + x*n_channels + 2];
3917 if (n_channels >= 4)
3918 a = pixels[y*stride + x*n_channels + 3];
3922 *p++ = a << 24 | r << 16 | g << 8 | b ;
3926 l = g_list_next (l);
3931 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3932 GDK_WINDOW_XID (window),
3933 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3936 (guchar*) data, size);
3940 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3941 GDK_WINDOW_XID (window),
3942 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3949 * gdk_window_set_icon:
3950 * @window: a toplevel #GdkWindow
3951 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
3952 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
3953 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
3955 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
3956 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
3957 * and gtk_window_set_icon(). If those don't meet your needs, look at
3958 * gdk_window_set_icon_list(). Only if all those are too high-level do you
3959 * want to fall back to gdk_window_set_icon().
3963 gdk_window_set_icon (GdkWindow *window,
3964 GdkWindow *icon_window,
3968 GdkToplevelX11 *toplevel;
3970 g_return_if_fail (window != NULL);
3971 g_return_if_fail (GDK_IS_WINDOW (window));
3972 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3974 if (GDK_WINDOW_DESTROYED (window))
3977 toplevel = _gdk_x11_window_get_toplevel (window);
3979 if (toplevel->icon_window != icon_window)
3981 if (toplevel->icon_window)
3982 g_object_unref (toplevel->icon_window);
3983 toplevel->icon_window = g_object_ref (icon_window);
3986 if (toplevel->icon_pixmap != pixmap)
3989 g_object_ref (pixmap);
3990 if (toplevel->icon_pixmap)
3991 g_object_unref (toplevel->icon_pixmap);
3992 toplevel->icon_pixmap = pixmap;
3995 if (toplevel->icon_mask != mask)
3998 g_object_ref (mask);
3999 if (toplevel->icon_mask)
4000 g_object_unref (toplevel->icon_mask);
4001 toplevel->icon_mask = mask;
4004 update_wm_hints (window, FALSE);
4008 gdk_window_icon_name_set (GdkWindow *window)
4010 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
4011 g_quark_from_static_string ("gdk-icon-name-set")));
4015 * gdk_window_set_icon_name:
4016 * @window: a toplevel #GdkWindow
4017 * @name: name of window while iconified (minimized)
4019 * Windows may have a name used while minimized, distinct from the
4020 * name they display in their titlebar. Most of the time this is a bad
4021 * idea from a user interface standpoint. But you can set such a name
4022 * with this function, if you like.
4026 gdk_window_set_icon_name (GdkWindow *window,
4029 GdkDisplay *display;
4031 g_return_if_fail (window != NULL);
4032 g_return_if_fail (GDK_IS_WINDOW (window));
4034 if (GDK_WINDOW_DESTROYED (window))
4037 display = gdk_drawable_get_display (window);
4039 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
4040 GUINT_TO_POINTER (TRUE));
4042 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
4043 GDK_WINDOW_XID (window),
4044 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
4045 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
4046 PropModeReplace, name, strlen (name));
4048 set_text_property (display, GDK_WINDOW_XID (window),
4049 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
4054 * gdk_window_iconify:
4055 * @window: a toplevel #GdkWindow
4057 * Asks to iconify (minimize) @window. The window manager may choose
4058 * to ignore the request, but normally will honor it. Using
4059 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
4061 * This function only makes sense when @window is a toplevel window.
4065 gdk_window_iconify (GdkWindow *window)
4067 GdkWindowObject *private;
4069 g_return_if_fail (window != NULL);
4070 g_return_if_fail (GDK_IS_WINDOW (window));
4072 if (GDK_WINDOW_DESTROYED (window))
4075 private = (GdkWindowObject*) window;
4077 if (GDK_WINDOW_IS_MAPPED (window))
4079 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
4080 GDK_WINDOW_XWINDOW (window),
4081 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
4085 /* Flip our client side flag, the real work happens on map. */
4086 gdk_synthesize_window_state (window,
4088 GDK_WINDOW_STATE_ICONIFIED);
4093 * gdk_window_deiconify:
4094 * @window: a toplevel #GdkWindow
4096 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
4097 * choose to ignore the request to deiconify. When using GTK+,
4098 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
4099 * you probably want to use gtk_window_present(), which raises the window, focuses it,
4100 * unminimizes it, and puts it on the current desktop.
4104 gdk_window_deiconify (GdkWindow *window)
4106 GdkWindowObject *private;
4108 g_return_if_fail (window != NULL);
4109 g_return_if_fail (GDK_IS_WINDOW (window));
4111 if (GDK_WINDOW_DESTROYED (window))
4114 private = (GdkWindowObject*) window;
4116 if (GDK_WINDOW_IS_MAPPED (window))
4118 gdk_window_show (window);
4122 /* Flip our client side flag, the real work happens on map. */
4123 gdk_synthesize_window_state (window,
4124 GDK_WINDOW_STATE_ICONIFIED,
4131 * @window: a toplevel #GdkWindow
4133 * "Pins" a window such that it's on all workspaces and does not scroll
4134 * with viewports, for window managers that have scrollable viewports.
4135 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
4137 * On the X11 platform, this function depends on window manager
4138 * support, so may have no effect with many window managers. However,
4139 * GDK will do the best it can to convince the window manager to stick
4140 * the window. For window managers that don't support this operation,
4141 * there's nothing you can do to force it to happen.
4145 gdk_window_stick (GdkWindow *window)
4147 g_return_if_fail (GDK_IS_WINDOW (window));
4149 if (GDK_WINDOW_DESTROYED (window))
4152 if (GDK_WINDOW_IS_MAPPED (window))
4154 /* "stick" means stick to all desktops _and_ do not scroll with the
4155 * viewport. i.e. glue to the monitor glass in all cases.
4160 /* Request stick during viewport scroll */
4161 gdk_wmspec_change_state (TRUE, window,
4162 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
4165 /* Request desktop 0xFFFFFFFF */
4166 xev.xclient.type = ClientMessage;
4167 xev.xclient.serial = 0;
4168 xev.xclient.send_event = True;
4169 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
4170 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
4171 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
4173 xev.xclient.format = 32;
4175 xev.xclient.data.l[0] = 0xFFFFFFFF;
4176 xev.xclient.data.l[1] = 0;
4177 xev.xclient.data.l[2] = 0;
4178 xev.xclient.data.l[3] = 0;
4179 xev.xclient.data.l[4] = 0;
4181 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
4182 SubstructureRedirectMask | SubstructureNotifyMask,
4187 /* Flip our client side flag, the real work happens on map. */
4188 gdk_synthesize_window_state (window,
4190 GDK_WINDOW_STATE_STICKY);
4195 * gdk_window_unstick:
4196 * @window: a toplevel #GdkWindow
4198 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
4199 * and gtk_window_unstick().
4203 gdk_window_unstick (GdkWindow *window)
4205 g_return_if_fail (GDK_IS_WINDOW (window));
4207 if (GDK_WINDOW_DESTROYED (window))
4210 if (GDK_WINDOW_IS_MAPPED (window))
4218 gulong *current_desktop;
4219 GdkDisplay *display = gdk_drawable_get_display (window);
4221 /* Request unstick from viewport */
4222 gdk_wmspec_change_state (FALSE, window,
4223 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
4226 /* Get current desktop, then set it; this is a race, but not
4227 * one that matters much in practice.
4229 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window),
4230 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
4232 False, XA_CARDINAL, &type, &format, &nitems,
4233 &bytes_after, &data);
4235 if (type == XA_CARDINAL)
4237 current_desktop = (gulong *)data;
4239 xev.xclient.type = ClientMessage;
4240 xev.xclient.serial = 0;
4241 xev.xclient.send_event = True;
4242 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
4243 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
4244 xev.xclient.format = 32;
4246 xev.xclient.data.l[0] = *current_desktop;
4247 xev.xclient.data.l[1] = 0;
4248 xev.xclient.data.l[2] = 0;
4249 xev.xclient.data.l[3] = 0;
4250 xev.xclient.data.l[4] = 0;
4252 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
4253 SubstructureRedirectMask | SubstructureNotifyMask,
4256 XFree (current_desktop);
4261 /* Flip our client side flag, the real work happens on map. */
4262 gdk_synthesize_window_state (window,
4263 GDK_WINDOW_STATE_STICKY,
4270 * gdk_window_maximize:
4271 * @window: a toplevel #GdkWindow
4273 * Maximizes the window. If the window was already maximized, then
4274 * this function does nothing.
4276 * On X11, asks the window manager to maximize @window, if the window
4277 * manager supports this operation. Not all window managers support
4278 * this, and some deliberately ignore it or don't have a concept of
4279 * "maximized"; so you can't rely on the maximization actually
4280 * happening. But it will happen with most standard window managers,
4281 * and GDK makes a best effort to get it to happen.
4283 * On Windows, reliably maximizes the window.
4287 gdk_window_maximize (GdkWindow *window)
4289 g_return_if_fail (GDK_IS_WINDOW (window));
4291 if (GDK_WINDOW_DESTROYED (window))
4294 if (GDK_WINDOW_IS_MAPPED (window))
4295 gdk_wmspec_change_state (TRUE, window,
4296 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
4297 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
4299 gdk_synthesize_window_state (window,
4301 GDK_WINDOW_STATE_MAXIMIZED);
4305 * gdk_window_unmaximize:
4306 * @window: a toplevel #GdkWindow
4308 * Unmaximizes the window. If the window wasn't maximized, then this
4309 * function does nothing.
4311 * On X11, asks the window manager to unmaximize @window, if the
4312 * window manager supports this operation. Not all window managers
4313 * support this, and some deliberately ignore it or don't have a
4314 * concept of "maximized"; so you can't rely on the unmaximization
4315 * actually happening. But it will happen with most standard window
4316 * managers, and GDK makes a best effort to get it to happen.
4318 * On Windows, reliably unmaximizes the window.
4322 gdk_window_unmaximize (GdkWindow *window)
4324 g_return_if_fail (GDK_IS_WINDOW (window));
4326 if (GDK_WINDOW_DESTROYED (window))
4329 if (GDK_WINDOW_IS_MAPPED (window))
4330 gdk_wmspec_change_state (FALSE, window,
4331 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
4332 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
4334 gdk_synthesize_window_state (window,
4335 GDK_WINDOW_STATE_MAXIMIZED,
4340 * gdk_window_fullscreen:
4341 * @window: a toplevel #GdkWindow
4343 * Moves the window into fullscreen mode. This means the
4344 * window covers the entire screen and is above any panels
4347 * If the window was already fullscreen, then this function does nothing.
4349 * On X11, asks the window manager to put @window in a fullscreen
4350 * state, if the window manager supports this operation. Not all
4351 * window managers support this, and some deliberately ignore it or
4352 * don't have a concept of "fullscreen"; so you can't rely on the
4353 * fullscreenification actually happening. But it will happen with
4354 * most standard window managers, and GDK makes a best effort to get
4360 gdk_window_fullscreen (GdkWindow *window)
4362 g_return_if_fail (GDK_IS_WINDOW (window));
4364 if (GDK_WINDOW_DESTROYED (window))
4367 if (GDK_WINDOW_IS_MAPPED (window))
4368 gdk_wmspec_change_state (TRUE, window,
4369 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
4373 gdk_synthesize_window_state (window,
4375 GDK_WINDOW_STATE_FULLSCREEN);
4379 * gdk_window_unfullscreen:
4380 * @window: a toplevel #GdkWindow
4382 * Moves the window out of fullscreen mode. If the window was not
4383 * fullscreen, does nothing.
4385 * On X11, asks the window manager to move @window out of the fullscreen
4386 * state, if the window manager supports this operation. Not all
4387 * window managers support this, and some deliberately ignore it or
4388 * don't have a concept of "fullscreen"; so you can't rely on the
4389 * unfullscreenification actually happening. But it will happen with
4390 * most standard window managers, and GDK makes a best effort to get
4396 gdk_window_unfullscreen (GdkWindow *window)
4398 g_return_if_fail (GDK_IS_WINDOW (window));
4400 if (GDK_WINDOW_DESTROYED (window))
4403 if (GDK_WINDOW_IS_MAPPED (window))
4404 gdk_wmspec_change_state (FALSE, window,
4405 gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", FALSE),
4409 gdk_synthesize_window_state (window,
4410 GDK_WINDOW_STATE_FULLSCREEN,
4415 * gdk_window_set_keep_above:
4416 * @window: a toplevel #GdkWindow
4417 * @setting: whether to keep @window above other windows
4419 * Set if @window must be kept above other windows. If the
4420 * window was already above, then this function does nothing.
4422 * On X11, asks the window manager to keep @window above, if the window
4423 * manager supports this operation. Not all window managers support
4424 * this, and some deliberately ignore it or don't have a concept of
4425 * "keep above"; so you can't rely on the window being kept above.
4426 * But it will happen with most standard window managers,
4427 * and GDK makes a best effort to get it to happen.
4432 gdk_window_set_keep_above (GdkWindow *window, gboolean setting)
4434 g_return_if_fail (GDK_IS_WINDOW (window));
4436 if (GDK_WINDOW_DESTROYED (window))
4439 if (GDK_WINDOW_IS_MAPPED (window))
4442 gdk_wmspec_change_state (FALSE, window,
4443 gdk_atom_intern ("_NET_WM_STATE_BELOW", FALSE),
4445 gdk_wmspec_change_state (setting, window,
4446 gdk_atom_intern ("_NET_WM_STATE_ABOVE", FALSE),
4450 gdk_synthesize_window_state (window,
4451 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4452 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4456 * gdk_window_set_keep_below:
4457 * @window: a toplevel #GdkWindow
4458 * @setting: whether to keep @window below other windows
4460 * Set if @window must be kept below other windows. If the
4461 * window was already below, then this function does nothing.
4463 * On X11, asks the window manager to keep @window below, if the window
4464 * manager supports this operation. Not all window managers support
4465 * this, and some deliberately ignore it or don't have a concept of
4466 * "keep below"; so you can't rely on the window being kept below.
4467 * But it will happen with most standard window managers,
4468 * and GDK makes a best effort to get it to happen.
4473 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4475 g_return_if_fail (GDK_IS_WINDOW (window));
4477 if (GDK_WINDOW_DESTROYED (window))
4480 if (GDK_WINDOW_IS_MAPPED (window))
4483 gdk_wmspec_change_state (FALSE, window,
4484 gdk_atom_intern ("_NET_WM_STATE_ABOVE", FALSE),
4486 gdk_wmspec_change_state (setting, window,
4487 gdk_atom_intern ("_NET_WM_STATE_BELOW", FALSE),
4491 gdk_synthesize_window_state (window,
4492 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4493 setting ? GDK_WINDOW_STATE_BELOW : 0);
4497 * gdk_window_get_group:
4498 * @window: a toplevel #GdkWindow
4500 * Returns the group leader window for @window. See gdk_window_set_group().
4502 * Return value: the group leader window for @window
4507 gdk_window_get_group (GdkWindow *window)
4509 GdkToplevelX11 *toplevel;
4511 g_return_val_if_fail (window != NULL, NULL);
4512 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4513 g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);
4515 if (GDK_WINDOW_DESTROYED (window))
4518 toplevel = _gdk_x11_window_get_toplevel (window);
4520 return toplevel->group_leader;
4524 * gdk_window_set_group:
4525 * @window: a toplevel #GdkWindow
4526 * @leader: group leader window, or %NULL to restore the default group leader window
4528 * Sets the group leader window for @window. By default,
4529 * GDK sets the group leader for all toplevel windows
4530 * to a global window implicitly created by GDK. With this function
4531 * you can override this default.
4533 * The group leader window allows the window manager to distinguish
4534 * all windows that belong to a single application. It may for example
4535 * allow users to minimize/unminimize all windows belonging to an
4536 * application at once. You should only set a non-default group window
4537 * if your application pretends to be multiple applications.
4540 gdk_window_set_group (GdkWindow *window,
4543 GdkToplevelX11 *toplevel;
4545 g_return_if_fail (window != NULL);
4546 g_return_if_fail (GDK_IS_WINDOW (window));
4547 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4548 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4550 if (GDK_WINDOW_DESTROYED (window) || (leader != NULL && GDK_WINDOW_DESTROYED (leader)))
4553 toplevel = _gdk_x11_window_get_toplevel (window);
4556 leader = gdk_display_get_default_group (gdk_drawable_get_display (window));
4558 if (toplevel->group_leader != leader)
4560 if (toplevel->group_leader)
4561 g_object_unref (toplevel->group_leader);
4562 toplevel->group_leader = g_object_ref (leader);
4563 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
4566 update_wm_hints (window, FALSE);
4569 static MotifWmHints *
4570 gdk_window_get_mwm_hints (GdkWindow *window)
4572 GdkDisplay *display;
4573 Atom hints_atom = None;
4580 if (GDK_WINDOW_DESTROYED (window))
4583 display = gdk_drawable_get_display (window);
4585 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4587 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4588 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4589 False, AnyPropertyType, &type, &format, &nitems,
4590 &bytes_after, &data);
4595 return (MotifWmHints *)data;
4599 gdk_window_set_mwm_hints (GdkWindow *window,
4600 MotifWmHints *new_hints)
4602 GdkDisplay *display;
4603 Atom hints_atom = None;
4605 MotifWmHints *hints;
4611 if (GDK_WINDOW_DESTROYED (window))
4614 display = gdk_drawable_get_display (window);
4616 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4618 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4619 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4620 False, AnyPropertyType, &type, &format, &nitems,
4621 &bytes_after, &data);
4627 hints = (MotifWmHints *)data;
4629 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4631 hints->flags |= MWM_HINTS_FUNCTIONS;
4632 hints->functions = new_hints->functions;
4634 if (new_hints->flags & MWM_HINTS_DECORATIONS)
4636 hints->flags |= MWM_HINTS_DECORATIONS;
4637 hints->decorations = new_hints->decorations;
4641 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4642 hints_atom, hints_atom, 32, PropModeReplace,
4643 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
4645 if (hints != new_hints)
4650 * gdk_window_set_decorations:
4651 * @window: a toplevel #GdkWindow
4652 * @decorations: decoration hint mask
4654 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
4655 * This function sets the traditional Motif window manager hints that tell the
4656 * window manager which decorations you would like your window to have.
4657 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
4658 * using the GDK function directly.
4660 * The @decorations argument is the logical OR of the fields in
4661 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
4662 * mask, the other bits indicate which decorations should be turned off.
4663 * If #GDK_DECOR_ALL is not included, then the other bits indicate
4664 * which decorations should be turned on.
4666 * Most window managers honor a decorations hint of 0 to disable all decorations,
4667 * but very few honor all possible combinations of bits.
4671 gdk_window_set_decorations (GdkWindow *window,
4672 GdkWMDecoration decorations)
4676 g_return_if_fail (window != NULL);
4677 g_return_if_fail (GDK_IS_WINDOW (window));
4679 hints.flags = MWM_HINTS_DECORATIONS;
4680 hints.decorations = decorations;
4682 gdk_window_set_mwm_hints (window, &hints);
4686 * gdk_window_get_decorations:
4687 * @window: The toplevel #GdkWindow to get the decorations from
4688 * @decorations: The window decorations will be written here
4690 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
4691 * Returns: TRUE if the window has decorations set, FALSE otherwise.
4694 gdk_window_get_decorations(GdkWindow *window,
4695 GdkWMDecoration *decorations)
4697 MotifWmHints *hints;
4698 gboolean result = FALSE;
4700 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
4702 hints = gdk_window_get_mwm_hints (window);
4706 if (hints->flags & MWM_HINTS_DECORATIONS)
4709 *decorations = hints->decorations;
4720 * gdk_window_set_functions:
4721 * @window: a toplevel #GdkWindow
4722 * @functions: bitmask of operations to allow on @window
4724 * This function isn't really good for much. It sets the traditional
4725 * Motif window manager hint for which operations the window manager
4726 * should allow on a toplevel window. However, few window managers do
4727 * anything reliable or interesting with this hint. Many ignore it
4730 * The @functions argument is the logical OR of values from the
4731 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
4732 * then the other bits indicate which functions to disable; if
4733 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
4738 gdk_window_set_functions (GdkWindow *window,
4739 GdkWMFunction functions)
4743 g_return_if_fail (window != NULL);
4744 g_return_if_fail (GDK_IS_WINDOW (window));
4746 hints.flags = MWM_HINTS_FUNCTIONS;
4747 hints.functions = functions;
4749 gdk_window_set_mwm_hints (window, &hints);
4752 #ifdef HAVE_SHAPE_EXT
4755 * propagate the shapes from all child windows of a GDK window to the parent
4756 * window. Shamelessly ripped from Enlightenment's code
4764 struct _gdk_span *next;
4768 gdk_add_to_span (struct _gdk_span **s,
4772 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
4779 /* scan the spans for this line */
4782 /* -- -> new span */
4783 /* == -> existing span */
4784 /* ## -> spans intersect */
4785 /* if we are in the middle of spanning the span into the line */
4788 /* case: ---- ==== */
4789 if (xx < ptr1->start - 1)
4791 /* ends before next span - extend to here */
4795 /* case: ----##=== */
4796 else if (xx <= ptr1->end)
4798 /* crosses into next span - delete next span and append */
4799 ss->end = ptr1->end;
4800 ss->next = ptr1->next;
4804 /* case: ---###--- */
4807 /* overlaps next span - delete and keep checking */
4808 ss->next = ptr1->next;
4813 /* otherwise havent started spanning it in yet */
4816 /* case: ---- ==== */
4817 if (xx < ptr1->start - 1)
4819 /* insert span here in list */
4820 noo = g_malloc (sizeof (struct _gdk_span));
4834 /* case: ----##=== */
4835 else if ((x < ptr1->start) && (xx <= ptr1->end))
4837 /* expand this span to the left point of the new one */
4841 /* case: ===###=== */
4842 else if ((x >= ptr1->start) && (xx <= ptr1->end))
4844 /* throw the span away */
4847 /* case: ---###--- */
4848 else if ((x < ptr1->start) && (xx > ptr1->end))
4855 /* case: ===##---- */
4856 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
4862 /* case: ==== ---- */
4863 /* case handled by next loop iteration - first case */
4868 /* it started in the middle but spans beyond your current list */
4874 /* it does not start inside a span or in the middle, so add it to the end */
4875 noo = g_malloc (sizeof (struct _gdk_span));
4883 noo->next = ptr2->next;
4896 gdk_add_rectangles (Display *disp,
4898 struct _gdk_span **spans,
4905 gint x1, y1, x2, y2;
4909 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
4912 /* go through all clip rects in this window's shape */
4913 for (k = 0; k < rn; k++)
4915 /* for each clip rect, add it to each line's spans */
4917 x2 = x + rl[k].x + (rl[k].width - 1);
4919 y2 = y + rl[k].y + (rl[k].height - 1);
4928 for (a = y1; a <= y2; a++)
4931 gdk_add_to_span (&spans[a], x1, x2);
4939 gdk_propagate_shapes (Display *disp,
4943 Window rt, par, *list = NULL;
4944 gint i, j, num = 0, num_rects = 0;
4948 XRectangle *rects = NULL;
4949 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
4950 XWindowAttributes xatt;
4952 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
4957 spans = g_malloc (sizeof (struct _gdk_span *) * h);
4959 for (i = 0; i < h; i++)
4961 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
4964 /* go through all child windows and create/insert spans */
4965 for (i = 0; i < num; i++)
4967 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
4968 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
4969 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
4972 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
4974 /* go through the spans list and build a list of rects */
4975 rects = g_malloc (sizeof (XRectangle) * 256);
4977 for (i = 0; i < baseh; i++)
4980 /* go through the line for all spans */
4983 rects[num_rects].x = ptr1->start;
4984 rects[num_rects].y = i;
4985 rects[num_rects].width = ptr1->end - ptr1->start + 1;
4986 rects[num_rects].height = 1;
4988 /* if there are more lines */
4990 /* while contigous rects (same start/end coords) exist */
4991 while ((contig) && (j < baseh))
4993 /* search next line for spans matching this one */
4999 /* if we have an exact span match set contig */
5000 if ((ptr2->start == ptr1->start) &&
5001 (ptr2->end == ptr1->end))
5004 /* remove the span - not needed */
5007 ptr3->next = ptr2->next;
5013 spans[j] = ptr2->next;
5019 /* gone past the span point no point looking */
5020 else if (ptr2->start < ptr1->start)
5028 /* if a contiguous span was found increase the rect h */
5031 rects[num_rects].height++;
5035 /* up the rect count */
5037 /* every 256 new rects increase the rect array */
5038 if ((num_rects % 256) == 0)
5039 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
5043 /* set the rects as the shape mask */
5046 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
5047 ShapeSet, YXSorted);
5052 /* free up all the spans we made */
5053 for (i = 0; i < baseh; i++)
5066 #endif /* HAVE_SHAPE_EXT */
5069 * gdk_window_set_child_shapes:
5070 * @window: a #GdkWindow
5072 * Sets the shape mask of @window to the union of shape masks
5073 * for all children of @window, ignoring the shape mask of @window
5074 * itself. Contrast with gdk_window_merge_child_shapes() which includes
5075 * the shape mask of @window in the masks to be merged.
5078 gdk_window_set_child_shapes (GdkWindow *window)
5080 g_return_if_fail (window != NULL);
5081 g_return_if_fail (GDK_IS_WINDOW (window));
5083 #ifdef HAVE_SHAPE_EXT
5084 if (!GDK_WINDOW_DESTROYED (window) &&
5085 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
5086 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5087 GDK_WINDOW_XID (window), FALSE);
5092 * gdk_window_merge_child_shapes:
5093 * @window: a #GdkWindow
5095 * Merges the shape masks for any child windows into the
5096 * shape mask for @window. i.e. the union of all masks
5097 * for @window and its children will become the new mask
5098 * for @window. See gdk_window_shape_combine_mask().
5100 * This function is distinct from gdk_window_set_child_shapes()
5101 * because it includes @window's shape mask in the set of shapes to
5106 gdk_window_merge_child_shapes (GdkWindow *window)
5108 g_return_if_fail (window != NULL);
5109 g_return_if_fail (GDK_IS_WINDOW (window));
5111 #ifdef HAVE_SHAPE_EXT
5112 if (!GDK_WINDOW_DESTROYED (window) &&
5113 gdk_window_have_shape_ext (GDK_WINDOW_DISPLAY (window)))
5114 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5115 GDK_WINDOW_XID (window), TRUE);
5120 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
5122 XSetWindowAttributes xattributes;
5123 GdkWindowObject *private;
5124 guint xattributes_mask = 0;
5126 g_return_if_fail (window != NULL);
5128 private = GDK_WINDOW_OBJECT (window);
5129 if (private->input_only)
5132 xattributes.bit_gravity = StaticGravity;
5133 xattributes_mask |= CWBitGravity;
5134 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
5135 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
5136 GDK_WINDOW_XID (window),
5137 CWBitGravity, &xattributes);
5141 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
5143 XSetWindowAttributes xattributes;
5145 g_return_if_fail (window != NULL);
5147 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
5149 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
5150 GDK_WINDOW_XID (window),
5151 CWWinGravity, &xattributes);
5155 * gdk_window_set_static_gravities:
5156 * @window: a #GdkWindow
5157 * @use_static: %TRUE to turn on static gravity
5159 * Set the bit gravity of the given window to static, and flag it so
5160 * all children get static subwindow gravity. This is used if you are
5161 * implementing scary features that involve deep knowledge of the
5162 * windowing system. Don't worry about it unless you have to.
5164 * Return value: %TRUE if the server supports static gravity
5167 gdk_window_set_static_gravities (GdkWindow *window,
5168 gboolean use_static)
5170 GdkWindowObject *private = (GdkWindowObject *)window;
5173 g_return_val_if_fail (window != NULL, FALSE);
5174 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5176 if (!use_static == !private->guffaw_gravity)
5179 private->guffaw_gravity = use_static;
5181 if (!GDK_WINDOW_DESTROYED (window))
5183 gdk_window_set_static_bit_gravity (window, use_static);
5185 tmp_list = private->children;
5188 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
5190 tmp_list = tmp_list->next;
5198 wmspec_moveresize (GdkWindow *window,
5204 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5208 /* Release passive grab */
5209 gdk_display_pointer_ungrab (display, timestamp);
5211 xev.xclient.type = ClientMessage;
5212 xev.xclient.serial = 0;
5213 xev.xclient.send_event = True;
5214 xev.xclient.window = GDK_WINDOW_XID (window);
5215 xev.xclient.message_type =
5216 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
5217 xev.xclient.format = 32;
5218 xev.xclient.data.l[0] = root_x;
5219 xev.xclient.data.l[1] = root_y;
5220 xev.xclient.data.l[2] = direction;
5221 xev.xclient.data.l[3] = 0;
5222 xev.xclient.data.l[4] = 0;
5224 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
5225 SubstructureRedirectMask | SubstructureNotifyMask,
5229 typedef struct _MoveResizeData MoveResizeData;
5231 struct _MoveResizeData
5233 GdkDisplay *display;
5235 GdkWindow *moveresize_window;
5236 GdkWindow *moveresize_emulation_window;
5238 GdkWindowEdge resize_edge;
5239 gint moveresize_button;
5242 gint moveresize_orig_x;
5243 gint moveresize_orig_y;
5244 gint moveresize_orig_width;
5245 gint moveresize_orig_height;
5246 GdkWindowHints moveresize_geom_mask;
5247 GdkGeometry moveresize_geometry;
5248 Time moveresize_process_time;
5249 XEvent *moveresize_pending_event;
5252 /* From the WM spec */
5253 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
5254 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
5255 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
5256 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
5257 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
5258 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
5259 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
5260 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
5261 #define _NET_WM_MOVERESIZE_MOVE 8
5264 wmspec_resize_drag (GdkWindow *window,
5273 /* Let the compiler turn a switch into a table, instead
5274 * of doing the table manually, this way is easier to verify.
5278 case GDK_WINDOW_EDGE_NORTH_WEST:
5279 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
5282 case GDK_WINDOW_EDGE_NORTH:
5283 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
5286 case GDK_WINDOW_EDGE_NORTH_EAST:
5287 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
5290 case GDK_WINDOW_EDGE_WEST:
5291 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
5294 case GDK_WINDOW_EDGE_EAST:
5295 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
5298 case GDK_WINDOW_EDGE_SOUTH_WEST:
5299 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
5302 case GDK_WINDOW_EDGE_SOUTH:
5303 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
5306 case GDK_WINDOW_EDGE_SOUTH_EAST:
5307 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
5311 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
5317 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
5320 static MoveResizeData *
5321 get_move_resize_data (GdkDisplay *display,
5324 MoveResizeData *mv_resize;
5325 static GQuark move_resize_quark = 0;
5327 if (!move_resize_quark)
5328 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
5330 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
5332 if (!mv_resize && create)
5334 mv_resize = g_new0 (MoveResizeData, 1);
5335 mv_resize->display = display;
5337 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
5344 update_pos (MoveResizeData *mv_resize,
5350 dx = new_root_x - mv_resize->moveresize_x;
5351 dy = new_root_y - mv_resize->moveresize_y;
5353 if (mv_resize->is_resize)
5357 x = mv_resize->moveresize_orig_x;
5358 y = mv_resize->moveresize_orig_y;
5360 w = mv_resize->moveresize_orig_width;
5361 h = mv_resize->moveresize_orig_height;
5363 switch (mv_resize->resize_edge)
5365 case GDK_WINDOW_EDGE_NORTH_WEST:
5371 case GDK_WINDOW_EDGE_NORTH:
5375 case GDK_WINDOW_EDGE_NORTH_EAST:
5380 case GDK_WINDOW_EDGE_SOUTH_WEST:
5385 case GDK_WINDOW_EDGE_SOUTH_EAST:
5389 case GDK_WINDOW_EDGE_SOUTH:
5392 case GDK_WINDOW_EDGE_EAST:
5395 case GDK_WINDOW_EDGE_WEST:
5406 if (mv_resize->moveresize_geom_mask)
5408 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
5409 mv_resize->moveresize_geom_mask,
5413 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
5419 x = mv_resize->moveresize_orig_x + dx;
5420 y = mv_resize->moveresize_orig_y + dy;
5422 gdk_window_move (mv_resize->moveresize_window, x, y);
5427 finish_drag (MoveResizeData *mv_resize)
5429 gdk_window_destroy (mv_resize->moveresize_emulation_window);
5430 mv_resize->moveresize_emulation_window = NULL;
5431 mv_resize->moveresize_window = NULL;
5433 if (mv_resize->moveresize_pending_event)
5435 g_free (mv_resize->moveresize_pending_event);
5436 mv_resize->moveresize_pending_event = NULL;
5441 lookahead_motion_predicate (Display *xdisplay,
5445 gboolean *seen_release = (gboolean *)arg;
5446 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
5447 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5452 switch (event->xany.type)
5455 *seen_release = TRUE;
5458 mv_resize->moveresize_process_time = event->xmotion.time;
5468 moveresize_lookahead (MoveResizeData *mv_resize,
5472 gboolean seen_release = FALSE;
5474 if (mv_resize->moveresize_process_time)
5476 if (event->xmotion.time == mv_resize->moveresize_process_time)
5478 mv_resize->moveresize_process_time = 0;
5485 XCheckIfEvent (event->xany.display, &tmp_event,
5486 lookahead_motion_predicate, (XPointer) & seen_release);
5488 return mv_resize->moveresize_process_time == 0;
5492 _gdk_moveresize_handle_event (XEvent *event)
5494 guint button_mask = 0;
5495 GdkWindowObject *window_private;
5496 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
5497 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5499 if (!mv_resize || !mv_resize->moveresize_window)
5502 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
5504 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
5506 switch (event->xany.type)
5509 if (window_private->resize_count > 0)
5511 if (mv_resize->moveresize_pending_event)
5512 *mv_resize->moveresize_pending_event = *event;
5514 mv_resize->moveresize_pending_event =
5515 g_memdup (event, sizeof (XEvent));
5519 if (!moveresize_lookahead (mv_resize, event))
5522 update_pos (mv_resize,
5523 event->xmotion.x_root,
5524 event->xmotion.y_root);
5526 /* This should never be triggered in normal cases, but in the
5527 * case where the drag started without an implicit grab being
5528 * in effect, we could miss the release if it occurs before
5529 * we grab the pointer; this ensures that we will never
5530 * get a permanently stuck grab.
5532 if ((event->xmotion.state & button_mask) == 0)
5533 finish_drag (mv_resize);
5537 update_pos (mv_resize,
5538 event->xbutton.x_root,
5539 event->xbutton.y_root);
5541 if (event->xbutton.button == mv_resize->moveresize_button)
5542 finish_drag (mv_resize);
5549 _gdk_moveresize_configure_done (GdkDisplay *display,
5553 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5555 if (!mv_resize || window != mv_resize->moveresize_window)
5558 if (mv_resize->moveresize_pending_event)
5560 tmp_event = mv_resize->moveresize_pending_event;
5561 mv_resize->moveresize_pending_event = NULL;
5562 _gdk_moveresize_handle_event (tmp_event);
5570 create_moveresize_window (MoveResizeData *mv_resize,
5573 GdkWindowAttr attributes;
5574 gint attributes_mask;
5575 GdkGrabStatus status;
5577 g_assert (mv_resize->moveresize_emulation_window == NULL);
5579 attributes.x = -100;
5580 attributes.y = -100;
5581 attributes.width = 10;
5582 attributes.height = 10;
5583 attributes.window_type = GDK_WINDOW_TEMP;
5584 attributes.wclass = GDK_INPUT_ONLY;
5585 attributes.override_redirect = TRUE;
5586 attributes.event_mask = 0;
5588 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
5590 mv_resize->moveresize_emulation_window =
5591 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
5595 gdk_window_show (mv_resize->moveresize_emulation_window);
5597 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
5599 GDK_BUTTON_RELEASE_MASK |
5600 GDK_POINTER_MOTION_MASK,
5605 if (status != GDK_GRAB_SUCCESS)
5607 /* If this fails, some other client has grabbed the window
5610 gdk_window_destroy (mv_resize->moveresize_emulation_window);
5611 mv_resize->moveresize_emulation_window = NULL;
5614 mv_resize->moveresize_process_time = 0;
5618 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
5619 so that calling XMoveWindow with these coordinates will not move the
5621 Note that this depends on the WM to implement ICCCM-compliant reference
5625 calculate_unmoving_origin (MoveResizeData *mv_resize)
5630 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
5631 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
5633 gdk_window_get_origin (mv_resize->moveresize_window,
5634 &mv_resize->moveresize_orig_x,
5635 &mv_resize->moveresize_orig_y);
5639 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
5640 gdk_window_get_geometry (mv_resize->moveresize_window,
5641 NULL, NULL, &width, &height, NULL);
5643 switch (mv_resize->moveresize_geometry.win_gravity)
5645 case GDK_GRAVITY_NORTH_WEST:
5646 mv_resize->moveresize_orig_x = rect.x;
5647 mv_resize->moveresize_orig_y = rect.y;
5649 case GDK_GRAVITY_NORTH:
5650 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5651 mv_resize->moveresize_orig_y = rect.y;
5653 case GDK_GRAVITY_NORTH_EAST:
5654 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5655 mv_resize->moveresize_orig_y = rect.y;
5657 case GDK_GRAVITY_WEST:
5658 mv_resize->moveresize_orig_x = rect.x;
5659 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5661 case GDK_GRAVITY_CENTER:
5662 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5663 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5665 case GDK_GRAVITY_EAST:
5666 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5667 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
5669 case GDK_GRAVITY_SOUTH_WEST:
5670 mv_resize->moveresize_orig_x = rect.x;
5671 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5673 case GDK_GRAVITY_SOUTH:
5674 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
5675 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5677 case GDK_GRAVITY_SOUTH_EAST:
5678 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
5679 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
5682 mv_resize->moveresize_orig_x = rect.x;
5683 mv_resize->moveresize_orig_y = rect.y;
5690 emulate_resize_drag (GdkWindow *window,
5697 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5699 mv_resize->is_resize = TRUE;
5700 mv_resize->moveresize_button = button;
5701 mv_resize->resize_edge = edge;
5702 mv_resize->moveresize_x = root_x;
5703 mv_resize->moveresize_y = root_y;
5704 mv_resize->moveresize_window = g_object_ref (window);
5706 gdk_drawable_get_size (window,
5707 &mv_resize->moveresize_orig_width,
5708 &mv_resize->moveresize_orig_height);
5710 mv_resize->moveresize_geom_mask = 0;
5711 gdk_window_get_geometry_hints (window,
5712 &mv_resize->moveresize_geometry,
5713 &mv_resize->moveresize_geom_mask);
5715 calculate_unmoving_origin (mv_resize);
5717 create_moveresize_window (mv_resize, timestamp);
5721 emulate_move_drag (GdkWindow *window,
5727 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
5729 mv_resize->is_resize = FALSE;
5730 mv_resize->moveresize_button = button;
5731 mv_resize->moveresize_x = root_x;
5732 mv_resize->moveresize_y = root_y;
5734 mv_resize->moveresize_window = g_object_ref (window);
5736 calculate_unmoving_origin (mv_resize);
5738 create_moveresize_window (mv_resize, timestamp);
5742 * gdk_window_begin_resize_drag:
5743 * @window: a toplevel #GdkWindow
5744 * @edge: the edge or corner from which the drag is started
5745 * @button: the button being used to drag
5746 * @root_x: root window X coordinate of mouse click that began the drag
5747 * @root_y: root window Y coordinate of mouse click that began the drag
5748 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
5750 * Begins a window resize operation (for a toplevel window).
5751 * You might use this function to implement a "window resize grip," for
5752 * example; in fact #GtkStatusbar uses it. The function works best
5753 * with window managers that support the Extended Window Manager Hints spec
5754 * (see http://www.freedesktop.org), but has a fallback implementation
5755 * for other window managers.
5759 gdk_window_begin_resize_drag (GdkWindow *window,
5766 g_return_if_fail (GDK_IS_WINDOW (window));
5768 if (GDK_WINDOW_DESTROYED (window))
5771 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5772 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5773 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
5775 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
5779 * gdk_window_begin_move_drag:
5780 * @window: a toplevel #GdkWindow
5781 * @button: the button being used to drag
5782 * @root_x: root window X coordinate of mouse click that began the drag
5783 * @root_y: root window Y coordinate of mouse click that began the drag
5784 * @timestamp: timestamp of mouse click that began the drag
5786 * Begins a window move operation (for a toplevel window). You might
5787 * use this function to implement a "window move grip," for
5788 * example. The function works best with window managers that support
5789 * the Extended Window Manager Hints spec (see
5790 * http://www.freedesktop.org), but has a fallback implementation for
5791 * other window managers.
5795 gdk_window_begin_move_drag (GdkWindow *window,
5801 g_return_if_fail (GDK_IS_WINDOW (window));
5803 if (GDK_WINDOW_DESTROYED (window))
5806 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
5807 gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
5808 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
5811 emulate_move_drag (window, button, root_x, root_y, timestamp);
5815 * gdk_window_enable_synchronized_configure:
5816 * @window: a toplevel #GdkWindow
5818 * Indicates that the application will cooperate with the window
5819 * system in synchronizing the window repaint with the window
5820 * manager during resizing operations. After an application calls
5821 * this function, it must call gdk_window_configure_finished() every
5822 * time it has finished all processing associated with a set of
5823 * Configure events. Toplevel GTK+ windows automatically use this
5826 * On X, calling this function makes @window participate in the
5827 * _NET_WM_SYNC_REQUEST window manager protocol.
5832 gdk_window_enable_synchronized_configure (GdkWindow *window)
5834 GdkWindowObject *private = (GdkWindowObject *)window;
5835 GdkWindowImplX11 *impl;
5837 g_return_if_fail (GDK_IS_WINDOW (window));
5839 impl = GDK_WINDOW_IMPL_X11 (private->impl);
5841 if (!impl->use_synchronized_configure)
5843 impl->use_synchronized_configure = TRUE;
5844 ensure_sync_counter (window);
5849 * gdk_window_configure_finished:
5850 * @window: a toplevel #GdkWindow
5852 * Signal to the window system that the application has finished
5853 * handling Configure events it has received. Window Managers can
5854 * use this to better synchronize the frame repaint with the
5855 * application. GTK+ applications will automatically call this
5856 * function when appropriate.
5858 * This function can only be called if gdk_window_use_configure()
5859 * was called previously.
5864 gdk_window_configure_finished (GdkWindow *window)
5866 GdkWindowImplX11 *impl;
5868 g_return_if_fail (GDK_IS_WINDOW (window));
5870 impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
5871 if (!impl->use_synchronized_configure)
5875 if (!GDK_WINDOW_DESTROYED (window))
5877 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5878 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
5880 if (toplevel && toplevel->update_counter != None &&
5881 GDK_DISPLAY_X11 (display)->use_sync &&
5882 !XSyncValueIsZero (toplevel->current_counter_value))
5884 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
5885 toplevel->update_counter,
5886 toplevel->current_counter_value);
5888 XSyncIntToValue (&toplevel->current_counter_value, 0);