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>
34 #include <X11/XKBlib.h>
37 #include <netinet/in.h>
42 #include "gdkwindow.h"
44 #include "gdkinputprivate.h"
45 #include "gdkdisplay-x11.h"
46 #include "gdkprivate-x11.h"
47 #include "gdkregion.h"
48 #include "gdkinternals.h"
50 #include "gdkwindow-x11.h"
59 #include <X11/extensions/shape.h>
62 const int _gdk_event_mask_table[21] =
66 PointerMotionHintMask,
83 SubstructureNotifyMask,
84 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
86 const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int);
88 /* Forward declarations */
89 static void gdk_window_set_static_win_gravity (GdkWindow *window,
91 static gboolean gdk_window_icon_name_set (GdkWindow *window);
92 static void gdk_window_add_colormap_windows (GdkWindow *window);
93 static void set_wm_name (GdkDisplay *display,
96 static void move_to_current_desktop (GdkWindow *window);
98 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
99 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
101 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
104 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
105 static void gdk_window_impl_x11_finalize (GObject *object);
107 #define WINDOW_IS_TOPLEVEL(window) \
108 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
109 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
111 /* Return whether time1 is considered later than time2 as far as xserver
112 * time is concerned. Accounts for wraparound.
114 #define XSERVER_TIME_IS_LATER(time1, time2) \
115 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
116 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
119 G_DEFINE_TYPE (GdkWindowImplX11, gdk_window_impl_x11, GDK_TYPE_DRAWABLE_IMPL_X11)
122 _gdk_window_impl_get_type (void)
124 return gdk_window_impl_x11_get_type ();
128 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
132 impl->toplevel_window_type = -1;
136 _gdk_x11_window_get_toplevel (GdkWindow *window)
138 GdkWindowObject *private;
139 GdkWindowImplX11 *impl;
141 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
143 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
146 private = (GdkWindowObject *)window;
147 impl = GDK_WINDOW_IMPL_X11 (private->impl);
150 impl->toplevel = g_new0 (GdkToplevelX11, 1);
152 return impl->toplevel;
156 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
158 GObjectClass *object_class = G_OBJECT_CLASS (klass);
159 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
161 object_class->finalize = gdk_window_impl_x11_finalize;
163 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
164 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
165 drawable_class->get_size = gdk_window_impl_x11_get_size;
167 /* Visible and clip regions are the same */
168 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
169 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
173 gdk_window_impl_x11_finalize (GObject *object)
175 GdkWindowObject *wrapper;
176 GdkDrawableImplX11 *draw_impl;
177 GdkWindowImplX11 *window_impl;
179 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
181 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
182 window_impl = GDK_WINDOW_IMPL_X11 (object);
184 wrapper = (GdkWindowObject*) draw_impl->wrapper;
186 _gdk_xgrab_check_destroy (GDK_WINDOW (wrapper));
188 if (!GDK_WINDOW_DESTROYED (wrapper))
190 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
192 _gdk_xid_table_remove (display, draw_impl->xid);
193 if (window_impl->toplevel && window_impl->toplevel->focus_window)
194 _gdk_xid_table_remove (display, window_impl->toplevel->focus_window);
197 if (window_impl->toplevel)
198 g_free (window_impl->toplevel);
200 if (window_impl->cursor)
201 gdk_cursor_unref (window_impl->cursor);
203 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
207 tmp_unset_bg (GdkWindow *window)
209 GdkWindowImplX11 *impl;
210 GdkWindowObject *obj;
212 obj = (GdkWindowObject *) window;
213 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
215 /* For windows without EXPOSURE_MASK, we can't do this
216 * unsetting because such windows depend on the drawing
217 * that the X server is going to do
219 if (!(obj->event_mask & GDK_EXPOSURE_MASK))
222 impl->position_info.no_bg = TRUE;
224 if (obj->bg_pixmap != GDK_NO_BG)
225 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
226 GDK_DRAWABLE_XID (window), None);
230 tmp_reset_bg (GdkWindow *window)
232 GdkWindowImplX11 *impl;
233 GdkWindowObject *obj;
235 obj = (GdkWindowObject *) window;
236 impl = GDK_WINDOW_IMPL_X11 (obj->impl);
238 if (!(obj->event_mask & GDK_EXPOSURE_MASK))
241 impl->position_info.no_bg = FALSE;
243 if (obj->bg_pixmap == GDK_NO_BG)
250 if (obj->bg_pixmap == GDK_PARENT_RELATIVE_BG)
251 xpixmap = ParentRelative;
253 xpixmap = GDK_DRAWABLE_XID (obj->bg_pixmap);
255 XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
256 GDK_DRAWABLE_XID (window), xpixmap);
260 XSetWindowBackground (GDK_DRAWABLE_XDISPLAY (window),
261 GDK_DRAWABLE_XID (window),
262 obj->bg_color.pixel);
266 /* Unsetting and resetting window backgrounds.
268 * In many cases it is possible to avoid flicker by unsetting the
269 * background of windows. For example if the background of the
270 * parent window is unset when a window is unmapped, a brief flicker
271 * of background painting is avoided.
274 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
277 GdkWindowObject *private;
279 g_return_if_fail (GDK_IS_WINDOW (window));
281 private = (GdkWindowObject *)window;
283 if (private->input_only || private->destroyed ||
284 (private->window_type != GDK_WINDOW_ROOT &&
285 !GDK_WINDOW_IS_MAPPED (window)))
290 if (private->window_type != GDK_WINDOW_ROOT &&
291 private->window_type != GDK_WINDOW_FOREIGN)
293 tmp_unset_bg (window);
300 for (l = private->children; l != NULL; l = l->next)
301 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
306 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
309 GdkWindowObject *private;
311 g_return_if_fail (GDK_IS_WINDOW (window));
313 private = (GdkWindowObject *)window;
315 if (private->input_only || private->destroyed ||
316 (private->window_type != GDK_WINDOW_ROOT &&
317 !GDK_WINDOW_IS_MAPPED (window)))
322 if (private->window_type != GDK_WINDOW_ROOT &&
323 private->window_type != GDK_WINDOW_FOREIGN)
325 tmp_reset_bg (window);
332 for (l = private->children; l != NULL; l = l->next)
333 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
338 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
340 GdkDrawableImplX11 *drawable_impl;
342 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
344 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
346 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
347 drawable_impl->colormap == NULL)
349 XWindowAttributes window_attributes;
352 XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen),
356 visual = gdk_x11_screen_lookup_visual (drawable_impl->screen,
357 window_attributes.visual->visualid);
358 drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual,
359 window_attributes.colormap);
362 return drawable_impl->colormap;
366 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
369 GdkDrawableImplX11 *draw_impl;
371 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
373 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
375 if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper))
379 GDK_DRAWABLE_CLASS (gdk_window_impl_x11_parent_class)->set_colormap (drawable, cmap);
383 XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen),
385 GDK_COLORMAP_XCOLORMAP (cmap));
387 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
389 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
395 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
399 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
402 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
404 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
408 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
410 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
411 GdkRectangle result_rect;
415 result_rect.width = impl->width;
416 result_rect.height = impl->height;
418 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
420 return gdk_region_rectangle (&result_rect);
424 _gdk_windowing_window_init (GdkScreen * screen)
426 GdkWindowObject *private;
427 GdkWindowImplX11 *impl;
428 GdkDrawableImplX11 *draw_impl;
429 GdkScreenX11 *screen_x11;
431 screen_x11 = GDK_SCREEN_X11 (screen);
433 g_assert (screen_x11->root_window == NULL);
435 gdk_screen_set_default_colormap (screen,
436 gdk_screen_get_system_colormap (screen));
438 screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
439 private = (GdkWindowObject *)screen_x11->root_window;
440 impl = GDK_WINDOW_IMPL_X11 (private->impl);
441 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
443 draw_impl->screen = screen;
444 draw_impl->xid = screen_x11->xroot_window;
445 draw_impl->wrapper = GDK_DRAWABLE (private);
446 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
447 g_object_ref (draw_impl->colormap);
449 private->window_type = GDK_WINDOW_ROOT;
450 private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
452 impl->width = WidthOfScreen (screen_x11->xscreen);
453 impl->height = HeightOfScreen (screen_x11->xscreen);
455 _gdk_window_init_position (GDK_WINDOW (private));
457 _gdk_xid_table_insert (screen_x11->display,
458 &screen_x11->xroot_window,
459 screen_x11->root_window);
463 set_wm_protocols (GdkWindow *window)
465 GdkDisplay *display = gdk_drawable_get_display (window);
469 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
470 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
471 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
474 if (GDK_DISPLAY_X11 (display)->use_sync)
475 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
478 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
482 get_default_title (void)
486 title = g_get_application_name ();
488 title = g_get_prgname ();
494 check_leader_window_title (GdkDisplay *display)
496 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
498 if (display_x11->leader_window && !display_x11->leader_window_title_set)
500 set_wm_name (display,
501 display_x11->leader_window,
502 get_default_title ());
504 display_x11->leader_window_title_set = TRUE;
509 create_focus_window (Display *xdisplay,
512 Window focus_window = XCreateSimpleWindow (xdisplay, parent,
516 /* FIXME: probably better to actually track the requested event mask for the toplevel
518 XSelectInput (xdisplay, focus_window,
519 KeyPressMask | KeyReleaseMask | FocusChangeMask);
521 XMapWindow (xdisplay, focus_window);
527 ensure_sync_counter (GdkWindow *window)
530 if (!GDK_WINDOW_DESTROYED (window))
532 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
533 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
534 GdkWindowObject *private = (GdkWindowObject *)window;
535 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
537 if (toplevel && impl->use_synchronized_configure &&
538 toplevel->update_counter == None &&
539 GDK_DISPLAY_X11 (display)->use_sync)
541 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
545 XSyncIntToValue (&value, 0);
547 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
549 atom = gdk_x11_get_xatom_by_name_for_display (display,
550 "_NET_WM_SYNC_REQUEST_COUNTER");
552 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
555 (guchar *)&toplevel->update_counter, 1);
557 XSyncIntToValue (&toplevel->current_counter_value, 0);
564 setup_toplevel_window (GdkWindow *window,
567 GdkWindowObject *obj = (GdkWindowObject *)window;
568 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
569 GdkWindowImplX11 *impl = (GdkWindowImplX11 *)obj->impl;
570 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
571 XID xid = GDK_WINDOW_XID (window);
572 XID xparent = GDK_WINDOW_XID (parent);
573 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
574 XSizeHints size_hints;
577 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_DIALOG)
578 XSetTransientForHint (xdisplay, xid, xparent);
580 set_wm_protocols (window);
582 if (!obj->input_only)
584 /* The focus window is off the visible area, and serves to receive key
585 * press events so they don't get sent to child windows.
587 toplevel->focus_window = create_focus_window (xdisplay, xid);
588 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
591 check_leader_window_title (screen_x11->display);
593 /* FIXME: Is there any point in doing this? Do any WM's pay
594 * attention to PSize, and even if they do, is this the
597 size_hints.flags = PSize;
598 size_hints.width = impl->width;
599 size_hints.height = impl->height;
601 XSetWMNormalHints (xdisplay, xid, &size_hints);
603 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
604 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
607 XChangeProperty (xdisplay, xid,
608 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
613 XChangeProperty (xdisplay, xid,
614 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
615 XA_WINDOW, 32, PropModeReplace,
616 (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
618 if (!obj->focus_on_map)
619 gdk_x11_window_set_user_time (window, 0);
620 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
621 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
623 ensure_sync_counter (window);
628 * @parent: a #GdkWindow, or %NULL to create the window as a child of
629 * the default root window for the default display.
630 * @attributes: attributes of the new window
631 * @attributes_mask: mask indicating which fields in @attributes are valid
633 * Creates a new #GdkWindow using the attributes from
634 * @attributes. See #GdkWindowAttr and #GdkWindowAttributesType for
635 * more details. Note: to use this on displays other than the default
636 * display, @parent must be specified.
638 * Return value: the new #GdkWindow
641 gdk_window_new (GdkWindow *parent,
642 GdkWindowAttr *attributes,
643 gint attributes_mask)
646 GdkWindowObject *private;
647 GdkWindowImplX11 *impl;
648 GdkDrawableImplX11 *draw_impl;
649 GdkScreenX11 *screen_x11;
658 XSetWindowAttributes xattributes;
659 long xattributes_mask;
660 XClassHint *class_hint;
667 g_return_val_if_fail (attributes != NULL, NULL);
672 g_warning ("gdk_window_new(): no parent specified reverting to parent = default root window"));
674 screen = gdk_screen_get_default ();
675 parent = gdk_screen_get_root_window (screen);
678 screen = gdk_drawable_get_screen (parent);
680 screen_x11 = GDK_SCREEN_X11 (screen);
682 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
684 if (GDK_WINDOW_DESTROYED (parent))
687 xparent = GDK_WINDOW_XID (parent);
689 window = g_object_new (GDK_TYPE_WINDOW, NULL);
690 private = (GdkWindowObject *)window;
691 impl = GDK_WINDOW_IMPL_X11 (private->impl);
692 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
693 draw_impl->wrapper = GDK_DRAWABLE (window);
695 draw_impl->screen = screen;
696 xdisplay = screen_x11->xdisplay;
698 /* Windows with a foreign parent are treated as if they are children
699 * of the root window, except for actual creation.
701 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_FOREIGN)
702 parent = gdk_screen_get_root_window (screen);
704 private->parent = (GdkWindowObject *)parent;
706 private->accept_focus = TRUE;
707 private->focus_on_map = TRUE;
709 xattributes_mask = 0;
711 if (attributes_mask & GDK_WA_X)
716 if (attributes_mask & GDK_WA_Y)
723 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
724 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
726 if (attributes->wclass == GDK_INPUT_ONLY)
728 /* Backwards compatiblity - we've always ignored
729 * attributes->window_type for input-only windows
732 if (GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT)
733 private->window_type = GDK_WINDOW_TEMP;
735 private->window_type = GDK_WINDOW_CHILD;
738 private->window_type = attributes->window_type;
740 /* Work around a bug where Xorg refuses to map toplevel InputOnly windows
741 * from an untrusted client: http://bugs.freedesktop.org/show_bug.cgi?id=6988
743 if (attributes->wclass == GDK_INPUT_ONLY &&
744 GDK_WINDOW_TYPE (parent) == GDK_WINDOW_ROOT &&
745 !G_LIKELY (GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (parent))->trusted_client))
747 g_warning ("Coercing GDK_INPUT_ONLY toplevel window to GDK_INPUT_OUTPUT to work around bug in Xorg server");
748 attributes->wclass = GDK_INPUT_OUTPUT;
751 _gdk_window_init_position (GDK_WINDOW (private));
752 if (impl->position_info.big)
753 private->guffaw_gravity = TRUE;
755 if (attributes_mask & GDK_WA_VISUAL)
756 visual = attributes->visual;
758 visual = gdk_screen_get_system_visual (screen);
759 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
761 xattributes.event_mask = StructureNotifyMask | PropertyChangeMask;
762 for (i = 0; i < _gdk_nenvent_masks; i++)
764 if (attributes->event_mask & (1 << (i + 1)))
765 xattributes.event_mask |= _gdk_event_mask_table[i];
767 private->event_mask = attributes->event_mask;
769 if (xattributes.event_mask)
770 xattributes_mask |= CWEventMask;
772 if (attributes_mask & GDK_WA_NOREDIR)
774 xattributes.override_redirect =
775 (attributes->override_redirect == FALSE)?False:True;
776 xattributes_mask |= CWOverrideRedirect;
779 xattributes.override_redirect = False;
781 impl->override_redirect = xattributes.override_redirect;
783 if (private->parent && private->parent->guffaw_gravity)
785 xattributes.win_gravity = StaticGravity;
786 xattributes_mask |= CWWinGravity;
790 switch (private->window_type)
792 case GDK_WINDOW_TOPLEVEL:
793 case GDK_WINDOW_DIALOG:
794 case GDK_WINDOW_TEMP:
795 if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
797 g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
798 "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
799 xparent = GDK_SCREEN_XROOTWIN (screen);
801 case GDK_WINDOW_CHILD:
804 g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
808 if (attributes->wclass == GDK_INPUT_OUTPUT)
811 depth = visual->depth;
813 private->input_only = FALSE;
814 private->depth = depth;
816 if (attributes_mask & GDK_WA_COLORMAP)
818 draw_impl->colormap = attributes->colormap;
819 g_object_ref (attributes->colormap);
823 if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
825 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
826 g_object_ref (draw_impl->colormap);
830 draw_impl->colormap = gdk_colormap_new (visual, FALSE);
834 private->bg_color.pixel = BlackPixel (xdisplay, screen_x11->screen_num);
835 private->bg_color.red = private->bg_color.green = private->bg_color.blue = 0;
836 xattributes.background_pixel = private->bg_color.pixel;
838 private->bg_pixmap = NULL;
840 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
841 xattributes_mask |= CWBorderPixel | CWBackPixel;
843 if (private->guffaw_gravity)
844 xattributes.bit_gravity = StaticGravity;
846 xattributes.bit_gravity = NorthWestGravity;
848 xattributes_mask |= CWBitGravity;
850 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
851 xattributes_mask |= CWColormap;
853 if (private->window_type == GDK_WINDOW_TEMP)
855 xattributes.save_under = True;
856 xattributes.override_redirect = True;
857 xattributes.cursor = None;
858 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
860 impl->override_redirect = TRUE;
868 private->input_only = TRUE;
869 draw_impl->colormap = gdk_screen_get_system_colormap (screen);
870 g_object_ref (draw_impl->colormap);
873 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
874 impl->position_info.x, impl->position_info.y,
875 impl->position_info.width, impl->position_info.height,
876 0, depth, class, xvisual,
877 xattributes_mask, &xattributes);
879 g_object_ref (window);
880 _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
882 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
883 (attributes->cursor) :
887 private->parent->children = g_list_prepend (private->parent->children, window);
889 switch (GDK_WINDOW_TYPE (private))
891 case GDK_WINDOW_DIALOG:
892 case GDK_WINDOW_TOPLEVEL:
893 case GDK_WINDOW_TEMP:
894 if (attributes_mask & GDK_WA_TITLE)
895 title = attributes->title;
897 title = get_default_title ();
899 gdk_window_set_title (window, title);
901 if (attributes_mask & GDK_WA_WMCLASS)
903 class_hint = XAllocClassHint ();
904 class_hint->res_name = attributes->wmclass_name;
905 class_hint->res_class = attributes->wmclass_class;
906 XSetClassHint (xdisplay, xid, class_hint);
910 setup_toplevel_window (window, parent);
913 case GDK_WINDOW_CHILD:
914 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
915 (draw_impl->colormap != gdk_screen_get_system_colormap (screen)) &&
916 (draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window))))
918 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
919 gdk_window_add_colormap_windows (window);
931 x_event_mask_to_gdk_event_mask (long mask)
933 GdkEventMask event_mask = 0;
936 for (i = 0; i < _gdk_nenvent_masks; i++)
938 if (mask & _gdk_event_mask_table[i])
939 event_mask |= 1 << (i + 1);
946 * gdk_window_foreign_new_for_display:
947 * @display: the #GdkDisplay where the window handle comes from.
948 * @anid: a native window handle.
950 * Wraps a native window in a #GdkWindow.
951 * This may fail if the window has been destroyed. If the window
952 * was already known to GDK, a new reference to the existing
953 * #GdkWindow is returned.
955 * For example in the X backend, a native window handle is an Xlib
958 * Return value: a #GdkWindow wrapper for the native window or
959 * %NULL if the window has been destroyed. The wrapper will be
960 * newly created, if one doesn't exist already.
965 gdk_window_foreign_new_for_display (GdkDisplay *display,
966 GdkNativeWindow anid)
969 GdkWindowObject *private;
970 GdkWindowImplX11 *impl;
971 GdkDrawableImplX11 *draw_impl;
972 GdkDisplayX11 *display_x11;
973 XWindowAttributes attrs;
975 Window *children = NULL;
979 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
981 display_x11 = GDK_DISPLAY_X11 (display);
983 if ((window = gdk_xid_table_lookup_for_display (display, anid)) != NULL)
984 return g_object_ref (window);
986 gdk_error_trap_push ();
987 result = XGetWindowAttributes (display_x11->xdisplay, anid, &attrs);
988 if (gdk_error_trap_pop () || !result)
991 /* FIXME: This is pretty expensive. Maybe the caller should supply
993 gdk_error_trap_push ();
994 result = XQueryTree (display_x11->xdisplay, anid, &root, &parent, &children, &nchildren);
995 if (gdk_error_trap_pop () || !result)
1001 window = g_object_new (GDK_TYPE_WINDOW, NULL);
1002 private = (GdkWindowObject *)window;
1003 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1004 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
1005 draw_impl->wrapper = GDK_DRAWABLE (window);
1006 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
1008 private->parent = gdk_xid_table_lookup_for_display (display, parent);
1010 if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN)
1011 private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen);
1013 private->parent->children = g_list_prepend (private->parent->children, window);
1015 draw_impl->xid = anid;
1017 private->x = attrs.x;
1018 private->y = attrs.y;
1019 impl->width = attrs.width;
1020 impl->height = attrs.height;
1021 private->window_type = GDK_WINDOW_FOREIGN;
1022 private->destroyed = FALSE;
1024 private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
1026 if (attrs.map_state == IsUnmapped)
1027 private->state = GDK_WINDOW_STATE_WITHDRAWN;
1031 private->depth = attrs.depth;
1033 _gdk_window_init_position (GDK_WINDOW (private));
1035 g_object_ref (window);
1036 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
1041 * gdk_window_lookup_for_display:
1042 * @display: the #GdkDisplay corresponding to the window handle
1043 * @anid: a native window handle.
1045 * Looks up the #GdkWindow that wraps the given native window handle.
1047 * For example in the X backend, a native window handle is an Xlib
1050 * Return value: the #GdkWindow wrapper for the native window,
1051 * or %NULL if there is none.
1056 gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
1058 return (GdkWindow*) gdk_xid_table_lookup_for_display (display, anid);
1062 * gdk_window_lookup:
1063 * @anid: a native window handle.
1065 * Looks up the #GdkWindow that wraps the given native window handle.
1067 * For example in the X backend, a native window handle is an Xlib
1070 * Return value: the #GdkWindow wrapper for the native window,
1071 * or %NULL if there is none.
1074 gdk_window_lookup (GdkNativeWindow anid)
1076 return (GdkWindow*) gdk_xid_table_lookup (anid);
1080 gdk_toplevel_x11_free_contents (GdkDisplay *display,
1081 GdkToplevelX11 *toplevel)
1083 if (toplevel->icon_window)
1085 g_object_unref (toplevel->icon_window);
1086 toplevel->icon_window = NULL;
1088 if (toplevel->icon_pixmap)
1090 g_object_unref (toplevel->icon_pixmap);
1091 toplevel->icon_pixmap = NULL;
1093 if (toplevel->icon_mask)
1095 g_object_unref (toplevel->icon_mask);
1096 toplevel->icon_mask = NULL;
1098 if (toplevel->group_leader)
1100 g_object_unref (toplevel->group_leader);
1101 toplevel->group_leader = NULL;
1104 if (toplevel->update_counter != None)
1106 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
1107 toplevel->update_counter);
1108 toplevel->update_counter = None;
1110 XSyncIntToValue (&toplevel->current_counter_value, 0);
1116 _gdk_windowing_window_destroy (GdkWindow *window,
1118 gboolean foreign_destroy)
1120 GdkWindowObject *private = (GdkWindowObject *)window;
1121 GdkToplevelX11 *toplevel;
1123 g_return_if_fail (GDK_IS_WINDOW (window));
1125 _gdk_selection_window_destroyed (window);
1127 if (private->extension_events != 0)
1128 _gdk_input_window_destroy (window);
1130 toplevel = _gdk_x11_window_get_toplevel (window);
1132 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1134 _gdk_x11_drawable_finish (private->impl);
1136 if (!recursing && !foreign_destroy)
1138 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1143 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
1145 /* It's somebody else's window, but in our heirarchy,
1146 * so reparent it to the root window, and then send
1147 * it a delete event, as if we were a WM
1149 XClientMessageEvent xevent;
1151 gdk_error_trap_push ();
1152 gdk_window_hide (window);
1153 gdk_window_reparent (window, NULL, 0, 0);
1155 xevent.type = ClientMessage;
1156 xevent.window = GDK_WINDOW_XID (window);
1157 xevent.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1160 xevent.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
1161 "WM_DELETE_WINDOW");
1162 xevent.data.l[1] = CurrentTime;
1163 xevent.data.l[2] = 0;
1164 xevent.data.l[3] = 0;
1165 xevent.data.l[4] = 0;
1167 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1168 GDK_WINDOW_XID (window),
1169 False, 0, (XEvent *)&xevent);
1170 gdk_display_sync (GDK_WINDOW_DISPLAY (window));
1171 gdk_error_trap_pop ();
1175 get_root (GdkWindow *window)
1177 GdkScreen *screen = gdk_drawable_get_screen (window);
1179 return gdk_screen_get_root_window (screen);
1182 /* This function is called when the XWindow is really gone.
1185 gdk_window_destroy_notify (GdkWindow *window)
1187 GdkWindowImplX11 *window_impl;
1189 g_return_if_fail (GDK_IS_WINDOW (window));
1191 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
1193 if (!GDK_WINDOW_DESTROYED (window))
1195 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1196 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1198 _gdk_window_destroy (window, TRUE);
1201 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1202 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1203 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1205 _gdk_xgrab_check_destroy (window);
1207 g_object_unref (window);
1211 update_wm_hints (GdkWindow *window,
1214 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1215 GdkWindowObject *private = (GdkWindowObject *)window;
1216 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1220 !toplevel->is_leader &&
1221 private->state & GDK_WINDOW_STATE_WITHDRAWN)
1224 wm_hints.flags = StateHint | InputHint;
1225 wm_hints.input = private->accept_focus ? True : False;
1226 wm_hints.initial_state = NormalState;
1228 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
1230 wm_hints.flags |= StateHint;
1231 wm_hints.initial_state = IconicState;
1234 if (toplevel->icon_window && !GDK_WINDOW_DESTROYED (toplevel->icon_window))
1236 wm_hints.flags |= IconWindowHint;
1237 wm_hints.icon_window = GDK_WINDOW_XID (toplevel->icon_window);
1240 if (toplevel->icon_pixmap)
1242 wm_hints.flags |= IconPixmapHint;
1243 wm_hints.icon_pixmap = GDK_PIXMAP_XID (toplevel->icon_pixmap);
1246 if (toplevel->icon_mask)
1248 wm_hints.flags |= IconMaskHint;
1249 wm_hints.icon_mask = GDK_PIXMAP_XID (toplevel->icon_mask);
1252 wm_hints.flags |= WindowGroupHint;
1253 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1255 wm_hints.flags |= WindowGroupHint;
1256 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1259 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1261 if (toplevel->urgency_hint)
1262 wm_hints.flags |= XUrgencyHint;
1264 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1265 GDK_WINDOW_XID (window),
1270 set_initial_hints (GdkWindow *window)
1272 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1273 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1274 Window xwindow = GDK_WINDOW_XID (window);
1275 GdkWindowObject *private;
1276 GdkToplevelX11 *toplevel;
1280 private = (GdkWindowObject*) window;
1281 toplevel = _gdk_x11_window_get_toplevel (window);
1286 update_wm_hints (window, TRUE);
1288 /* We set the spec hints regardless of whether the spec is supported,
1289 * since it can't hurt and it's kind of expensive to check whether
1295 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
1297 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1298 "_NET_WM_STATE_MAXIMIZED_VERT");
1300 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1301 "_NET_WM_STATE_MAXIMIZED_HORZ");
1305 if (private->state & GDK_WINDOW_STATE_ABOVE)
1307 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1308 "_NET_WM_STATE_ABOVE");
1312 if (private->state & GDK_WINDOW_STATE_BELOW)
1314 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1315 "_NET_WM_STATE_BELOW");
1319 if (private->state & GDK_WINDOW_STATE_STICKY)
1321 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1322 "_NET_WM_STATE_STICKY");
1326 if (private->state & GDK_WINDOW_STATE_FULLSCREEN)
1328 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1329 "_NET_WM_STATE_FULLSCREEN");
1333 if (private->modal_hint)
1335 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1336 "_NET_WM_STATE_MODAL");
1340 if (toplevel->skip_taskbar_hint)
1342 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1343 "_NET_WM_STATE_SKIP_TASKBAR");
1347 if (toplevel->skip_pager_hint)
1349 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1350 "_NET_WM_STATE_SKIP_PAGER");
1356 XChangeProperty (xdisplay,
1358 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1359 XA_ATOM, 32, PropModeReplace,
1360 (guchar*) atoms, i);
1364 XDeleteProperty (xdisplay,
1366 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1369 if (private->state & GDK_WINDOW_STATE_STICKY)
1371 atoms[0] = 0xFFFFFFFF;
1372 XChangeProperty (xdisplay,
1374 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1375 XA_CARDINAL, 32, PropModeReplace,
1376 (guchar*) atoms, 1);
1380 XDeleteProperty (xdisplay,
1382 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1385 toplevel->map_serial = NextRequest (xdisplay);
1389 show_window_internal (GdkWindow *window,
1392 GdkWindowObject *private;
1393 GdkDisplay *display;
1394 GdkDisplayX11 *display_x11;
1395 GdkToplevelX11 *toplevel;
1397 g_return_if_fail (GDK_IS_WINDOW (window));
1399 private = (GdkWindowObject*) window;
1400 if (!private->destroyed)
1402 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1403 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1404 Window xwindow = GDK_WINDOW_XID (window);
1407 XRaiseWindow (xdisplay, xwindow);
1409 if (!GDK_WINDOW_IS_MAPPED (window))
1411 set_initial_hints (window);
1413 gdk_synthesize_window_state (window,
1414 GDK_WINDOW_STATE_WITHDRAWN,
1418 g_assert (GDK_WINDOW_IS_MAPPED (window));
1420 if (WINDOW_IS_TOPLEVEL (window))
1422 display = gdk_drawable_get_display (window);
1423 display_x11 = GDK_DISPLAY_X11 (display);
1424 toplevel = _gdk_x11_window_get_toplevel (window);
1426 if (toplevel->user_time != 0 &&
1427 display_x11->user_time != 0 &&
1428 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1429 gdk_x11_window_set_user_time (window, display_x11->user_time);
1432 if (impl->position_info.mapped)
1434 gboolean unset_bg = !private->input_only &&
1435 (private->window_type == GDK_WINDOW_CHILD ||
1436 impl->override_redirect) &&
1437 gdk_window_is_viewable (window);
1440 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1442 XMapWindow (xdisplay, xwindow);
1446 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1447 gdk_window_invalidate_rect (window, NULL, TRUE);
1454 * gdk_window_show_unraised:
1455 * @window: a #GdkWindow
1457 * Shows a #GdkWindow onscreen, but does not modify its stacking
1458 * order. In contrast, gdk_window_show() will raise the window
1459 * to the top of the window stack.
1461 * On the X11 platform, in Xlib terms, this function calls
1462 * XMapWindow() (it also updates some internal GDK state, which means
1463 * that you can't really use XMapWindow() directly on a GDK window).
1467 gdk_window_show_unraised (GdkWindow *window)
1469 g_return_if_fail (GDK_IS_WINDOW (window));
1471 show_window_internal (window, FALSE);
1476 * @window: a #GdkWindow
1478 * Like gdk_window_show_unraised(), but also raises the window to the
1479 * top of the window stack (moves the window to the front of the
1482 * This function maps a window so it's visible onscreen. Its opposite
1483 * is gdk_window_hide().
1485 * When implementing a #GtkWidget, you should call this function on the widget's
1486 * #GdkWindow as part of the "map" method.
1490 gdk_window_show (GdkWindow *window)
1492 g_return_if_fail (GDK_IS_WINDOW (window));
1494 show_window_internal (window, TRUE);
1498 pre_unmap (GdkWindow *window)
1500 GdkWindow *start_window = NULL;
1501 GdkWindowObject *private = (GdkWindowObject *)window;
1503 if (private->input_only)
1506 if (private->window_type == GDK_WINDOW_CHILD)
1507 start_window = (GdkWindow *)private->parent;
1508 else if (private->window_type == GDK_WINDOW_TEMP)
1509 start_window = get_root (window);
1512 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1516 post_unmap (GdkWindow *window)
1518 GdkWindow *start_window = NULL;
1519 GdkWindowObject *private = (GdkWindowObject *)window;
1521 if (private->input_only)
1524 if (private->window_type == GDK_WINDOW_CHILD)
1525 start_window = (GdkWindow *)private->parent;
1526 else if (private->window_type == GDK_WINDOW_TEMP)
1527 start_window = get_root (window);
1531 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1533 if (private->window_type == GDK_WINDOW_CHILD && private->parent)
1535 GdkRectangle invalid_rect;
1537 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1538 gdk_drawable_get_size (GDK_DRAWABLE (window),
1539 &invalid_rect.width, &invalid_rect.height);
1540 gdk_window_invalidate_rect ((GdkWindow *)private->parent,
1541 &invalid_rect, TRUE);
1548 * @window: a #GdkWindow
1550 * For toplevel windows, withdraws them, so they will no longer be
1551 * known to the window manager; for all windows, unmaps them, so
1552 * they won't be displayed. Normally done automatically as
1553 * part of gtk_widget_hide().
1557 gdk_window_hide (GdkWindow *window)
1559 GdkWindowObject *private;
1561 g_return_if_fail (GDK_IS_WINDOW (window));
1563 private = (GdkWindowObject*) window;
1565 /* We'll get the unmap notify eventually, and handle it then,
1566 * but checking here makes things more consistent if we are
1567 * just doing stuff ourself.
1569 _gdk_xgrab_check_unmap (window,
1570 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1572 /* You can't simply unmap toplevel windows. */
1573 switch (private->window_type)
1575 case GDK_WINDOW_TOPLEVEL:
1576 case GDK_WINDOW_DIALOG:
1577 case GDK_WINDOW_TEMP: /* ? */
1578 gdk_window_withdraw (window);
1582 case GDK_WINDOW_FOREIGN:
1583 case GDK_WINDOW_ROOT:
1584 case GDK_WINDOW_CHILD:
1588 if (!private->destroyed)
1590 if (GDK_WINDOW_IS_MAPPED (window))
1591 gdk_synthesize_window_state (window,
1593 GDK_WINDOW_STATE_WITHDRAWN);
1595 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1597 _gdk_window_clear_update_area (window);
1601 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1602 GDK_WINDOW_XID (window));
1604 post_unmap (window);
1609 * gdk_window_withdraw:
1610 * @window: a toplevel #GdkWindow
1612 * Withdraws a window (unmaps it and asks the window manager to forget about it).
1613 * This function is not really useful as gdk_window_hide() automatically
1614 * withdraws toplevel windows before hiding them.
1618 gdk_window_withdraw (GdkWindow *window)
1620 GdkWindowObject *private;
1622 g_return_if_fail (GDK_IS_WINDOW (window));
1624 private = (GdkWindowObject*) window;
1625 if (!private->destroyed)
1627 if (GDK_WINDOW_IS_MAPPED (window))
1628 gdk_synthesize_window_state (window,
1630 GDK_WINDOW_STATE_WITHDRAWN);
1632 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1636 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1637 GDK_WINDOW_XID (window), 0);
1639 post_unmap (window);
1645 * @window: a #GdkWindow
1646 * @x: X coordinate relative to window's parent
1647 * @y: Y coordinate relative to window's parent
1649 * Repositions a window relative to its parent window.
1650 * For toplevel windows, window managers may ignore or modify the move;
1651 * you should probably use gtk_window_move() on a #GtkWindow widget
1652 * anyway, instead of using GDK functions. For child windows,
1653 * the move will reliably succeed.
1655 * If you're also planning to resize the window, use gdk_window_move_resize()
1656 * to both move and resize simultaneously, for a nicer visual effect.
1659 gdk_window_move (GdkWindow *window,
1663 GdkWindowObject *private = (GdkWindowObject *)window;
1664 GdkWindowImplX11 *impl;
1666 g_return_if_fail (GDK_IS_WINDOW (window));
1668 impl = GDK_WINDOW_IMPL_X11 (private->impl);
1670 if (!GDK_WINDOW_DESTROYED (window))
1672 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1674 _gdk_window_move_resize_child (window, x, y,
1675 impl->width, impl->height);
1679 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1680 GDK_WINDOW_XID (window),
1683 if (impl->override_redirect)
1693 * gdk_window_resize:
1694 * @window: a #GdkWindow
1695 * @width: new width of the window
1696 * @height: new height of the window
1698 * Resizes @window; for toplevel windows, asks the window manager to resize
1699 * the window. The window manager may not allow the resize. When using GTK+,
1700 * use gtk_window_resize() instead of this low-level GDK function.
1702 * Windows may not be resized below 1x1.
1704 * If you're also planning to move the window, use gdk_window_move_resize()
1705 * to both move and resize simultaneously, for a nicer visual effect.
1708 gdk_window_resize (GdkWindow *window,
1712 GdkWindowObject *private;
1714 g_return_if_fail (GDK_IS_WINDOW (window));
1721 private = (GdkWindowObject*) window;
1723 if (!GDK_WINDOW_DESTROYED (window))
1725 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1727 _gdk_window_move_resize_child (window, private->x, private->y,
1729 _gdk_x11_drawable_update_size (private->impl);
1733 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1735 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1736 GDK_WINDOW_XID (window),
1739 if (impl->override_redirect)
1741 impl->width = width;
1742 impl->height = height;
1743 _gdk_x11_drawable_update_size (private->impl);
1747 if (width != impl->width || height != impl->height)
1748 private->resize_count += 1;
1752 _gdk_x11_drawable_update_size (private->impl);
1757 * gdk_window_move_resize:
1758 * @window: a #GdkWindow
1759 * @x: new X position relative to window's parent
1760 * @y: new Y position relative to window's parent
1762 * @height: new height
1764 * Equivalent to calling gdk_window_move() and gdk_window_resize(),
1765 * except that both operations are performed at once, avoiding strange
1766 * visual effects. (i.e. the user may be able to see the window first
1767 * move, then resize, if you don't use gdk_window_move_resize().)
1770 gdk_window_move_resize (GdkWindow *window,
1776 GdkWindowObject *private;
1778 g_return_if_fail (GDK_IS_WINDOW (window));
1785 private = (GdkWindowObject*) window;
1787 if (!GDK_WINDOW_DESTROYED (window))
1789 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1791 _gdk_window_move_resize_child (window, x, y, width, height);
1792 _gdk_x11_drawable_update_size (private->impl);
1796 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1798 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1799 GDK_WINDOW_XID (window),
1800 x, y, width, height);
1801 if (impl->override_redirect)
1805 impl->width = width;
1806 impl->height = height;
1808 _gdk_x11_drawable_update_size (private->impl);
1812 if (width != impl->width || height != impl->height)
1813 private->resize_count += 1;
1820 * gdk_window_reparent:
1821 * @window: a #GdkWindow
1822 * @new_parent: new parent to move @window into
1823 * @x: X location inside the new parent
1824 * @y: Y location inside the new parent
1826 * Reparents @window into the given @new_parent. The window being
1827 * reparented will be unmapped as a side effect.
1831 gdk_window_reparent (GdkWindow *window,
1832 GdkWindow *new_parent,
1836 GdkWindowObject *window_private;
1837 GdkWindowObject *parent_private;
1838 GdkWindowObject *old_parent_private;
1839 GdkWindowImplX11 *impl;
1840 gboolean was_toplevel;
1842 g_return_if_fail (GDK_IS_WINDOW (window));
1843 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1844 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT);
1846 if (GDK_WINDOW_DESTROYED (window) ||
1847 (new_parent && GDK_WINDOW_DESTROYED (new_parent)))
1853 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1855 window_private = (GdkWindowObject*) window;
1856 old_parent_private = (GdkWindowObject*)window_private->parent;
1857 parent_private = (GdkWindowObject*) new_parent;
1858 impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
1860 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1861 GDK_WINDOW_XID (window),
1862 GDK_WINDOW_XID (new_parent),
1865 window_private->x = x;
1866 window_private->y = y;
1868 /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like
1871 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1872 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1874 window_private->parent = (GdkWindowObject *)new_parent;
1876 /* Switch the window type as appropriate */
1878 switch (GDK_WINDOW_TYPE (new_parent))
1880 case GDK_WINDOW_ROOT:
1881 case GDK_WINDOW_FOREIGN:
1882 was_toplevel = WINDOW_IS_TOPLEVEL (window);
1884 if (impl->toplevel_window_type != -1)
1885 GDK_WINDOW_TYPE (window) = impl->toplevel_window_type;
1886 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1887 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1889 if (WINDOW_IS_TOPLEVEL (window) && !was_toplevel)
1890 setup_toplevel_window (window, new_parent);
1892 case GDK_WINDOW_TOPLEVEL:
1893 case GDK_WINDOW_CHILD:
1894 case GDK_WINDOW_DIALOG:
1895 case GDK_WINDOW_TEMP:
1896 if (WINDOW_IS_TOPLEVEL (window))
1898 /* Save the original window type so we can restore it if the
1899 * window is reparented back to be a toplevel
1901 impl->toplevel_window_type = GDK_WINDOW_TYPE (window);
1902 GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD;
1905 if (impl->toplevel->focus_window)
1907 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1908 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1911 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1913 g_free (impl->toplevel);
1914 impl->toplevel = NULL;
1919 if (old_parent_private)
1920 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1922 if ((old_parent_private &&
1923 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1924 (!old_parent_private && parent_private->guffaw_gravity))
1925 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1927 parent_private->children = g_list_prepend (parent_private->children, window);
1928 _gdk_window_init_position (GDK_WINDOW (window_private));
1932 _gdk_windowing_window_clear_area (GdkWindow *window,
1938 g_return_if_fail (GDK_IS_WINDOW (window));
1940 if (!GDK_WINDOW_DESTROYED (window))
1941 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1942 x, y, width, height, False);
1946 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1952 g_return_if_fail (GDK_IS_WINDOW (window));
1954 if (!GDK_WINDOW_DESTROYED (window))
1955 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1956 x, y, width, height, True);
1962 * @window: a #GdkWindow
1964 * Raises @window to the top of the Z-order (stacking order), so that
1965 * other windows with the same parent window appear below @window.
1966 * This is true whether or not the windows are visible.
1968 * If @window is a toplevel, the window manager may choose to deny the
1969 * request to move the window in the Z-order, gdk_window_raise() only
1970 * requests the restack, does not guarantee it.
1974 gdk_window_raise (GdkWindow *window)
1976 g_return_if_fail (GDK_IS_WINDOW (window));
1978 if (!GDK_WINDOW_DESTROYED (window))
1979 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1984 * @window: a #GdkWindow
1986 * Lowers @window to the bottom of the Z-order (stacking order), so that
1987 * other windows with the same parent window appear above @window.
1988 * This is true whether or not the other windows are visible.
1990 * If @window is a toplevel, the window manager may choose to deny the
1991 * request to move the window in the Z-order, gdk_window_lower() only
1992 * requests the restack, does not guarantee it.
1994 * Note that gdk_window_show() raises the window again, so don't call this
1995 * function before gdk_window_show(). (Try gdk_window_show_unraised().)
1999 gdk_window_lower (GdkWindow *window)
2001 g_return_if_fail (GDK_IS_WINDOW (window));
2003 if (!GDK_WINDOW_DESTROYED (window))
2004 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
2008 * gdk_x11_window_move_to_current_desktop:
2009 * @window: a #GdkWindow
2011 * Moves the window to the correct workspace when running under a
2012 * window manager that supports multiple workspaces, as described
2013 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
2014 * Window Manager Hints</ulink>. Will not do anything if the
2015 * window is already on all workspaces.
2020 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
2022 GdkToplevelX11 *toplevel;
2023 toplevel = _gdk_x11_window_get_toplevel (window);
2025 if (toplevel->on_all_desktops)
2028 move_to_current_desktop (window);
2032 move_to_current_desktop (GdkWindow *window)
2034 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
2035 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
2043 gulong *current_desktop;
2044 GdkDisplay *display;
2046 display = gdk_drawable_get_display (window);
2048 /* Get current desktop, then set it; this is a race, but not
2049 * one that matters much in practice.
2051 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
2052 GDK_WINDOW_XROOTWIN (window),
2053 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
2055 False, XA_CARDINAL, &type, &format, &nitems,
2056 &bytes_after, &data);
2058 if (type == XA_CARDINAL)
2060 current_desktop = (gulong *)data;
2062 xev.xclient.type = ClientMessage;
2063 xev.xclient.serial = 0;
2064 xev.xclient.send_event = True;
2065 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
2066 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
2067 xev.xclient.format = 32;
2069 xev.xclient.data.l[0] = *current_desktop;
2070 xev.xclient.data.l[1] = 0;
2071 xev.xclient.data.l[2] = 0;
2072 xev.xclient.data.l[3] = 0;
2073 xev.xclient.data.l[4] = 0;
2075 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
2076 GDK_WINDOW_XROOTWIN (window),
2078 SubstructureRedirectMask | SubstructureNotifyMask,
2081 XFree (current_desktop);
2088 * @window: a #GdkWindow
2089 * @timestamp: timestamp of the event triggering the window focus
2091 * Sets keyboard focus to @window. In most cases, gtk_window_present()
2092 * should be used on a #GtkWindow, rather than calling this function.
2096 gdk_window_focus (GdkWindow *window,
2099 GdkDisplay *display;
2101 g_return_if_fail (GDK_IS_WINDOW (window));
2103 if (GDK_WINDOW_DESTROYED (window))
2106 display = GDK_WINDOW_DISPLAY (window);
2108 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
2109 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
2113 xev.xclient.type = ClientMessage;
2114 xev.xclient.serial = 0;
2115 xev.xclient.send_event = True;
2116 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
2117 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
2118 "_NET_ACTIVE_WINDOW");
2119 xev.xclient.format = 32;
2120 xev.xclient.data.l[0] = 1; /* requestor type; we're an app */
2121 xev.xclient.data.l[1] = timestamp;
2122 xev.xclient.data.l[2] = None; /* currently active window */
2123 xev.xclient.data.l[3] = 0;
2124 xev.xclient.data.l[4] = 0;
2126 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
2127 SubstructureRedirectMask | SubstructureNotifyMask,
2132 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
2134 /* There is no way of knowing reliably whether we are viewable;
2135 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
2137 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
2144 * gdk_window_set_hints:
2145 * @window: a #GdkWindow
2146 * @x: ignored field, does not matter
2147 * @y: ignored field, does not matter
2148 * @min_width: minimum width hint
2149 * @min_height: minimum height hint
2150 * @max_width: max width hint
2151 * @max_height: max height hint
2152 * @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE
2154 * This function is broken and useless and you should ignore it.
2155 * If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(),
2156 * gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(),
2157 * depending on what you're trying to do.
2159 * If using GDK directly, use gdk_window_set_geometry_hints().
2163 gdk_window_set_hints (GdkWindow *window,
2172 XSizeHints size_hints;
2174 g_return_if_fail (GDK_IS_WINDOW (window));
2176 if (GDK_WINDOW_DESTROYED (window))
2179 size_hints.flags = 0;
2181 if (flags & GDK_HINT_POS)
2183 size_hints.flags |= PPosition;
2188 if (flags & GDK_HINT_MIN_SIZE)
2190 size_hints.flags |= PMinSize;
2191 size_hints.min_width = min_width;
2192 size_hints.min_height = min_height;
2195 if (flags & GDK_HINT_MAX_SIZE)
2197 size_hints.flags |= PMaxSize;
2198 size_hints.max_width = max_width;
2199 size_hints.max_height = max_height;
2202 /* FIXME: Would it be better to delete this property if
2203 * flags == 0? It would save space on the server
2205 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2206 GDK_WINDOW_XID (window),
2211 * gdk_window_set_type_hint:
2212 * @window: A toplevel #GdkWindow
2213 * @hint: A hint of the function this window will have
2215 * The application can use this call to provide a hint to the window
2216 * manager about the functionality of a window. The window manager
2217 * can use this information when determining the decoration and behaviour
2220 * The hint must be set before the window is mapped.
2223 gdk_window_set_type_hint (GdkWindow *window,
2224 GdkWindowTypeHint hint)
2226 GdkDisplay *display;
2229 g_return_if_fail (GDK_IS_WINDOW (window));
2231 if (GDK_WINDOW_DESTROYED (window))
2234 display = gdk_drawable_get_display (window);
2238 case GDK_WINDOW_TYPE_HINT_DIALOG:
2239 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
2241 case GDK_WINDOW_TYPE_HINT_MENU:
2242 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
2244 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
2245 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
2247 case GDK_WINDOW_TYPE_HINT_UTILITY:
2248 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
2250 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
2251 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
2253 case GDK_WINDOW_TYPE_HINT_DOCK:
2254 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
2256 case GDK_WINDOW_TYPE_HINT_DESKTOP:
2257 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
2259 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
2260 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
2262 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
2263 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
2265 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
2266 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
2268 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
2269 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
2271 case GDK_WINDOW_TYPE_HINT_COMBO:
2272 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
2274 case GDK_WINDOW_TYPE_HINT_DND:
2275 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
2278 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
2280 case GDK_WINDOW_TYPE_HINT_NORMAL:
2281 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
2285 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2286 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
2287 XA_ATOM, 32, PropModeReplace,
2288 (guchar *)&atom, 1);
2292 * gdk_window_get_type_hint:
2293 * @window: A toplevel #GdkWindow
2295 * This function returns the type hint set for a window.
2297 * Return value: The type hint set for @window
2302 gdk_window_get_type_hint (GdkWindow *window)
2304 GdkDisplay *display;
2305 GdkWindowTypeHint type;
2308 gulong nitems_return;
2309 gulong bytes_after_return;
2310 guchar *data = NULL;
2312 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
2314 if (GDK_WINDOW_DESTROYED (window))
2315 return GDK_WINDOW_TYPE_HINT_NORMAL;
2317 type = GDK_WINDOW_TYPE_HINT_NORMAL;
2319 display = gdk_drawable_get_display (window);
2321 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2322 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
2323 0, G_MAXLONG, False, XA_ATOM, &type_return,
2324 &format_return, &nitems_return, &bytes_after_return,
2327 if ((type_return == XA_ATOM) && (format_return == 32) &&
2328 (data) && (nitems_return == 1))
2330 Atom atom = *(Atom*)data;
2332 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
2333 type = GDK_WINDOW_TYPE_HINT_DIALOG;
2334 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
2335 type = GDK_WINDOW_TYPE_HINT_MENU;
2336 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
2337 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
2338 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
2339 type = GDK_WINDOW_TYPE_HINT_UTILITY;
2340 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
2341 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
2342 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
2343 type = GDK_WINDOW_TYPE_HINT_DOCK;
2344 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
2345 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
2346 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
2347 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
2348 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
2349 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
2350 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
2351 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
2352 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
2353 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
2354 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
2355 type = GDK_WINDOW_TYPE_HINT_COMBO;
2356 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
2357 type = GDK_WINDOW_TYPE_HINT_DND;
2360 if (type_return != None && data != NULL)
2368 gdk_wmspec_change_state (gboolean add,
2373 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
2376 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
2377 #define _NET_WM_STATE_ADD 1 /* add/set property */
2378 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
2380 xev.xclient.type = ClientMessage;
2381 xev.xclient.serial = 0;
2382 xev.xclient.send_event = True;
2383 xev.xclient.window = GDK_WINDOW_XID (window);
2384 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
2385 xev.xclient.format = 32;
2386 xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
2387 xev.xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
2388 xev.xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
2389 xev.xclient.data.l[3] = 0;
2390 xev.xclient.data.l[4] = 0;
2392 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
2393 SubstructureRedirectMask | SubstructureNotifyMask,
2398 * gdk_window_set_modal_hint:
2399 * @window: A toplevel #GdkWindow
2400 * @modal: %TRUE if the window is modal, %FALSE otherwise.
2402 * The application can use this hint to tell the window manager
2403 * that a certain window has modal behaviour. The window manager
2404 * can use this information to handle modal windows in a special
2407 * You should only use this on windows for which you have
2408 * previously called gdk_window_set_transient_for()
2411 gdk_window_set_modal_hint (GdkWindow *window,
2414 GdkWindowObject *private;
2416 g_return_if_fail (GDK_IS_WINDOW (window));
2418 if (GDK_WINDOW_DESTROYED (window))
2421 private = (GdkWindowObject*) window;
2423 private->modal_hint = modal;
2425 if (GDK_WINDOW_IS_MAPPED (window))
2426 gdk_wmspec_change_state (modal, window,
2427 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
2432 * gdk_window_set_skip_taskbar_hint:
2433 * @window: a toplevel #GdkWindow
2434 * @skips_taskbar: %TRUE to skip the taskbar
2436 * Toggles whether a window should appear in a task list or window
2437 * list. If a window's semantic type as specified with
2438 * gdk_window_set_type_hint() already fully describes the window, this
2439 * function should <emphasis>not</emphasis> be called in addition,
2440 * instead you should allow the window to be treated according to
2441 * standard policy for its semantic type.
2446 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2447 gboolean skips_taskbar)
2449 GdkToplevelX11 *toplevel;
2451 g_return_if_fail (GDK_IS_WINDOW (window));
2452 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2454 if (GDK_WINDOW_DESTROYED (window))
2457 toplevel = _gdk_x11_window_get_toplevel (window);
2458 toplevel->skip_taskbar_hint = skips_taskbar;
2460 if (GDK_WINDOW_IS_MAPPED (window))
2461 gdk_wmspec_change_state (skips_taskbar, window,
2462 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
2467 * gdk_window_set_skip_pager_hint:
2468 * @window: a toplevel #GdkWindow
2469 * @skips_pager: %TRUE to skip the pager
2471 * Toggles whether a window should appear in a pager (workspace
2472 * switcher, or other desktop utility program that displays a small
2473 * thumbnail representation of the windows on the desktop). If a
2474 * window's semantic type as specified with gdk_window_set_type_hint()
2475 * already fully describes the window, this function should
2476 * <emphasis>not</emphasis> be called in addition, instead you should
2477 * allow the window to be treated according to standard policy for
2478 * its semantic type.
2483 gdk_window_set_skip_pager_hint (GdkWindow *window,
2484 gboolean skips_pager)
2486 GdkToplevelX11 *toplevel;
2488 g_return_if_fail (GDK_IS_WINDOW (window));
2489 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2491 if (GDK_WINDOW_DESTROYED (window))
2494 toplevel = _gdk_x11_window_get_toplevel (window);
2495 toplevel->skip_pager_hint = skips_pager;
2497 if (GDK_WINDOW_IS_MAPPED (window))
2498 gdk_wmspec_change_state (skips_pager, window,
2499 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2504 * gdk_window_set_urgency_hint:
2505 * @window: a toplevel #GdkWindow
2506 * @urgent: %TRUE if the window is urgent
2508 * Toggles whether a window needs the user's
2514 gdk_window_set_urgency_hint (GdkWindow *window,
2517 GdkToplevelX11 *toplevel;
2519 g_return_if_fail (GDK_IS_WINDOW (window));
2520 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2522 if (GDK_WINDOW_DESTROYED (window))
2525 toplevel = _gdk_x11_window_get_toplevel (window);
2526 toplevel->urgency_hint = urgent;
2528 update_wm_hints (window, FALSE);
2532 * gdk_window_set_geometry_hints:
2533 * @window: a toplevel #GdkWindow
2534 * @geometry: geometry hints
2535 * @geom_mask: bitmask indicating fields of @geometry to pay attention to
2537 * Sets the geometry hints for @window. Hints flagged in @geom_mask
2538 * are set, hints not flagged in @geom_mask are unset.
2539 * To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL.
2541 * This function provides hints to the windowing system about
2542 * acceptable sizes for a toplevel window. The purpose of
2543 * this is to constrain user resizing, but the windowing system
2544 * will typically (but is not required to) also constrain the
2545 * current size of the window to the provided values and
2546 * constrain programatic resizing via gdk_window_resize() or
2547 * gdk_window_move_resize().
2549 * Note that on X11, this effect has no effect on windows
2550 * of type %GDK_WINDOW_TEMP or windows where override redirect
2551 * has been turned on via gdk_window_set_override_redirect()
2552 * since these windows are not resizable by the user.
2554 * Since you can't count on the windowing system doing the
2555 * constraints for programmatic resizes, you should generally
2556 * call gdk_window_constrain_size() yourself to determine
2557 * appropriate sizes.
2561 gdk_window_set_geometry_hints (GdkWindow *window,
2562 GdkGeometry *geometry,
2563 GdkWindowHints geom_mask)
2565 XSizeHints size_hints;
2567 g_return_if_fail (GDK_IS_WINDOW (window));
2569 if (GDK_WINDOW_DESTROYED (window))
2572 size_hints.flags = 0;
2574 if (geom_mask & GDK_HINT_POS)
2576 size_hints.flags |= PPosition;
2577 /* We need to initialize the following obsolete fields because KWM
2578 * apparently uses these fields if they are non-zero.
2585 if (geom_mask & GDK_HINT_USER_POS)
2587 size_hints.flags |= USPosition;
2590 if (geom_mask & GDK_HINT_USER_SIZE)
2592 size_hints.flags |= USSize;
2595 if (geom_mask & GDK_HINT_MIN_SIZE)
2597 size_hints.flags |= PMinSize;
2598 size_hints.min_width = geometry->min_width;
2599 size_hints.min_height = geometry->min_height;
2602 if (geom_mask & GDK_HINT_MAX_SIZE)
2604 size_hints.flags |= PMaxSize;
2605 size_hints.max_width = MAX (geometry->max_width, 1);
2606 size_hints.max_height = MAX (geometry->max_height, 1);
2609 if (geom_mask & GDK_HINT_BASE_SIZE)
2611 size_hints.flags |= PBaseSize;
2612 size_hints.base_width = geometry->base_width;
2613 size_hints.base_height = geometry->base_height;
2616 if (geom_mask & GDK_HINT_RESIZE_INC)
2618 size_hints.flags |= PResizeInc;
2619 size_hints.width_inc = geometry->width_inc;
2620 size_hints.height_inc = geometry->height_inc;
2623 if (geom_mask & GDK_HINT_ASPECT)
2625 size_hints.flags |= PAspect;
2626 if (geometry->min_aspect <= 1)
2628 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2629 size_hints.min_aspect.y = 65536;
2633 size_hints.min_aspect.x = 65536;
2634 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2636 if (geometry->max_aspect <= 1)
2638 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2639 size_hints.max_aspect.y = 65536;
2643 size_hints.max_aspect.x = 65536;
2644 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2648 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2650 size_hints.flags |= PWinGravity;
2651 size_hints.win_gravity = geometry->win_gravity;
2654 /* FIXME: Would it be better to delete this property if
2655 * geom_mask == 0? It would save space on the server
2657 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2658 GDK_WINDOW_XID (window),
2663 gdk_window_get_geometry_hints (GdkWindow *window,
2664 GdkGeometry *geometry,
2665 GdkWindowHints *geom_mask)
2667 XSizeHints *size_hints;
2668 glong junk_supplied_mask = 0;
2670 g_return_if_fail (GDK_IS_WINDOW (window));
2671 g_return_if_fail (geometry != NULL);
2672 g_return_if_fail (geom_mask != NULL);
2676 if (GDK_WINDOW_DESTROYED (window))
2679 size_hints = XAllocSizeHints ();
2683 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2684 GDK_WINDOW_XID (window),
2686 &junk_supplied_mask))
2687 size_hints->flags = 0;
2689 if (size_hints->flags & PMinSize)
2691 *geom_mask |= GDK_HINT_MIN_SIZE;
2692 geometry->min_width = size_hints->min_width;
2693 geometry->min_height = size_hints->min_height;
2696 if (size_hints->flags & PMaxSize)
2698 *geom_mask |= GDK_HINT_MAX_SIZE;
2699 geometry->max_width = MAX (size_hints->max_width, 1);
2700 geometry->max_height = MAX (size_hints->max_height, 1);
2703 if (size_hints->flags & PResizeInc)
2705 *geom_mask |= GDK_HINT_RESIZE_INC;
2706 geometry->width_inc = size_hints->width_inc;
2707 geometry->height_inc = size_hints->height_inc;
2710 if (size_hints->flags & PAspect)
2712 *geom_mask |= GDK_HINT_ASPECT;
2714 geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
2715 geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
2718 if (size_hints->flags & PWinGravity)
2720 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2721 geometry->win_gravity = size_hints->win_gravity;
2728 utf8_is_latin1 (const gchar *str)
2730 const char *p = str;
2734 gunichar ch = g_utf8_get_char (p);
2739 p = g_utf8_next_char (p);
2745 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2746 * convertable to STRING, otherwise, set it as compound text
2749 set_text_property (GdkDisplay *display,
2752 const gchar *utf8_str)
2754 gchar *prop_text = NULL;
2758 gboolean is_compound_text;
2760 if (utf8_is_latin1 (utf8_str))
2762 prop_type = XA_STRING;
2763 prop_text = gdk_utf8_to_string_target (utf8_str);
2764 prop_length = prop_text ? strlen (prop_text) : 0;
2766 is_compound_text = FALSE;
2772 gdk_utf8_to_compound_text_for_display (display,
2773 utf8_str, &gdk_type, &prop_format,
2774 (guchar **)&prop_text, &prop_length);
2775 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2776 is_compound_text = TRUE;
2781 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2784 prop_type, prop_format,
2785 PropModeReplace, (guchar *)prop_text,
2788 if (is_compound_text)
2789 gdk_free_compound_text ((guchar *)prop_text);
2795 /* Set WM_NAME and _NET_WM_NAME
2798 set_wm_name (GdkDisplay *display,
2802 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2803 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2804 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2805 PropModeReplace, (guchar *)name, strlen (name));
2807 set_text_property (display, xwindow,
2808 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2813 * gdk_window_set_title:
2814 * @window: a toplevel #GdkWindow
2815 * @title: title of @window
2817 * Sets the title of a toplevel window, to be displayed in the titlebar.
2818 * If you haven't explicitly set the icon name for the window
2819 * (using gdk_window_set_icon_name()), the icon name will be set to
2820 * @title as well. @title must be in UTF-8 encoding (as with all
2821 * user-readable strings in GDK/GTK+). @title may not be %NULL.
2824 gdk_window_set_title (GdkWindow *window,
2827 GdkDisplay *display;
2831 g_return_if_fail (GDK_IS_WINDOW (window));
2832 g_return_if_fail (title != NULL);
2834 if (GDK_WINDOW_DESTROYED (window))
2837 display = gdk_drawable_get_display (window);
2838 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2839 xwindow = GDK_WINDOW_XID (window);
2841 set_wm_name (display, xwindow, title);
2843 if (!gdk_window_icon_name_set (window))
2845 XChangeProperty (xdisplay, xwindow,
2846 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2847 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2848 PropModeReplace, (guchar *)title, strlen (title));
2850 set_text_property (display, xwindow,
2851 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2857 * gdk_window_set_role:
2858 * @window: a toplevel #GdkWindow
2859 * @role: a string indicating its role
2861 * When using GTK+, typically you should use gtk_window_set_role() instead
2862 * of this low-level function.
2864 * The window manager and session manager use a window's role to
2865 * distinguish it from other kinds of window in the same application.
2866 * When an application is restarted after being saved in a previous
2867 * session, all windows with the same title and role are treated as
2868 * interchangeable. So if you have two windows with the same title
2869 * that should be distinguished for session management purposes, you
2870 * should set the role on those windows. It doesn't matter what string
2871 * you use for the role, as long as you have a different role for each
2872 * non-interchangeable kind of window.
2876 gdk_window_set_role (GdkWindow *window,
2879 GdkDisplay *display;
2881 g_return_if_fail (GDK_IS_WINDOW (window));
2883 display = gdk_drawable_get_display (window);
2885 if (!GDK_WINDOW_DESTROYED (window))
2888 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2889 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2890 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2892 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2893 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2898 * gdk_window_set_transient_for:
2899 * @window: a toplevel #GdkWindow
2900 * @parent: another toplevel #GdkWindow
2902 * Indicates to the window manager that @window is a transient dialog
2903 * associated with the application window @parent. This allows the
2904 * window manager to do things like center @window on @parent and
2905 * keep @window above @parent.
2907 * See gtk_window_set_transient_for() if you're using #GtkWindow or
2912 gdk_window_set_transient_for (GdkWindow *window,
2915 g_return_if_fail (GDK_IS_WINDOW (window));
2917 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
2918 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2919 GDK_WINDOW_XID (window),
2920 GDK_WINDOW_XID (parent));
2924 * gdk_window_set_background:
2925 * @window: a #GdkWindow
2926 * @color: an allocated #GdkColor
2928 * Sets the background color of @window. (However, when using GTK+,
2929 * set the background of a widget with gtk_widget_modify_bg() - if
2930 * you're an application - or gtk_style_set_background() - if you're
2931 * implementing a custom widget.)
2933 * The @color must be allocated; gdk_rgb_find_color() is the best way
2934 * to allocate a color.
2936 * See also gdk_window_set_back_pixmap().
2940 gdk_window_set_background (GdkWindow *window,
2941 const GdkColor *color)
2943 GdkWindowObject *private = (GdkWindowObject *)window;
2944 GdkColormap *colormap = gdk_drawable_get_colormap (window);
2946 g_return_if_fail (GDK_IS_WINDOW (window));
2948 if (!GDK_WINDOW_DESTROYED (window))
2949 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2950 GDK_WINDOW_XID (window), color->pixel);
2952 private->bg_color = *color;
2953 gdk_colormap_query_color (colormap, private->bg_color.pixel, &private->bg_color);
2955 if (private->bg_pixmap &&
2956 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
2957 private->bg_pixmap != GDK_NO_BG)
2958 g_object_unref (private->bg_pixmap);
2960 private->bg_pixmap = NULL;
2964 * gdk_window_set_back_pixmap:
2965 * @window: a #GdkWindow
2966 * @pixmap: a #GdkPixmap, or %NULL
2967 * @parent_relative: whether the tiling origin is at the origin of @window's parent
2969 * Sets the background pixmap of @window. May also be used to set a background of
2970 * "None" on @window, by setting a background pixmap of %NULL.
2971 * A background pixmap will be tiled, positioning the first tile at the origin of
2972 * @window, or if @parent_relative is %TRUE, the tiling will be done based on the
2973 * origin of the parent window (useful to align tiles in a parent with tiles
2976 * A background pixmap of %NULL means that the window will have no
2977 * background. A window with no background will never have its
2978 * background filled by the windowing system, instead the window will
2979 * contain whatever pixels were already in the corresponding area of
2982 * The windowing system will normally fill a window with its background
2983 * when the window is obscured then exposed, and when you call
2984 * gdk_window_clear().
2988 gdk_window_set_back_pixmap (GdkWindow *window,
2990 gboolean parent_relative)
2992 GdkWindowObject *private = (GdkWindowObject *)window;
2995 g_return_if_fail (GDK_IS_WINDOW (window));
2996 g_return_if_fail (pixmap == NULL || !parent_relative);
2997 g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));
2999 if (pixmap && !gdk_drawable_get_colormap (pixmap))
3001 g_warning ("gdk_window_set_back_pixmap(): pixmap must have a colormap");
3005 if (private->bg_pixmap &&
3006 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
3007 private->bg_pixmap != GDK_NO_BG)
3008 g_object_unref (private->bg_pixmap);
3010 if (parent_relative)
3012 xpixmap = ParentRelative;
3013 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
3019 g_object_ref (pixmap);
3020 private->bg_pixmap = pixmap;
3021 xpixmap = GDK_PIXMAP_XID (pixmap);
3026 private->bg_pixmap = GDK_NO_BG;
3030 if (!GDK_WINDOW_DESTROYED (window))
3031 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
3032 GDK_WINDOW_XID (window), xpixmap);
3036 * gdk_window_set_cursor:
3037 * @window: a #GdkWindow
3040 * Sets the mouse pointer for a #GdkWindow. Use gdk_cursor_new() or
3041 * gdk_cursor_new_from_pixmap() to create the cursor.
3042 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
3043 * a cursor with no pixels in it. Passing %NULL for the @cursor argument
3044 * to gdk_window_set_cursor() means that @window will use the cursor of
3045 * its parent window. Most windows should use this default.
3049 gdk_window_set_cursor (GdkWindow *window,
3052 GdkWindowObject *private;
3053 GdkWindowImplX11 *impl;
3054 GdkCursorPrivate *cursor_private;
3057 g_return_if_fail (GDK_IS_WINDOW (window));
3059 private = (GdkWindowObject *)window;
3060 impl = GDK_WINDOW_IMPL_X11 (private->impl);
3061 cursor_private = (GdkCursorPrivate*) cursor;
3065 gdk_cursor_unref (impl->cursor);
3066 impl->cursor = NULL;
3073 _gdk_x11_cursor_update_theme (cursor);
3074 xcursor = cursor_private->xcursor;
3077 if (!GDK_WINDOW_DESTROYED (window))
3079 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
3080 GDK_WINDOW_XID (window),
3084 impl->cursor = gdk_cursor_ref (cursor);
3089 _gdk_x11_window_get_cursor (GdkWindow *window)
3091 GdkWindowObject *private;
3092 GdkWindowImplX11 *impl;
3094 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
3096 private = (GdkWindowObject *)window;
3097 impl = GDK_WINDOW_IMPL_X11 (private->impl);
3099 return impl->cursor;
3103 * gdk_window_get_geometry:
3104 * @window: a #GdkWindow
3105 * @x: return location for X coordinate of window (relative to its parent)
3106 * @y: return location for Y coordinate of window (relative to its parent)
3107 * @width: return location for width of window
3108 * @height: return location for height of window
3109 * @depth: return location for bit depth of window
3111 * Any of the return location arguments to this function may be %NULL,
3112 * if you aren't interested in getting the value of that field.
3114 * The X and Y coordinates returned are relative to the parent window
3115 * of @window, which for toplevels usually means relative to the
3116 * window decorations (titlebar, etc.) rather than relative to the
3117 * root window (screen-size background window).
3119 * On the X11 platform, the geometry is obtained from the X server,
3120 * so reflects the latest position of @window; this may be out-of-sync
3121 * with the position of @window delivered in the most-recently-processed
3122 * #GdkEventConfigure. gdk_window_get_position() in contrast gets the
3123 * position from the most recent configure event.
3126 * If @window is not a toplevel, it is <emphasis>much</emphasis> better
3127 * to call gdk_window_get_position() and gdk_drawable_get_size() instead,
3128 * because it avoids the roundtrip to the X server and because
3129 * gdk_drawable_get_size() supports the full 32-bit coordinate space,
3130 * whereas gdk_window_get_geometry() is restricted to the 16-bit
3131 * coordinates of X11.
3135 gdk_window_get_geometry (GdkWindow *window,
3147 guint tborder_width;
3150 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
3154 GDK_NOTE (MULTIHEAD,
3155 g_message ("gdk_window_get_geometry(): Window needs to be non-NULL to be multi head safe"));
3156 window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
3159 if (!GDK_WINDOW_DESTROYED (window))
3161 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
3162 GDK_WINDOW_XID (window),
3163 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
3179 * gdk_window_get_origin:
3180 * @window: a #GdkWindow
3181 * @x: return location for X coordinate
3182 * @y: return location for Y coordinate
3184 * Obtains the position of a window in root window coordinates.
3185 * (Compare with gdk_window_get_position() and
3186 * gdk_window_get_geometry() which return the position of a window
3187 * relative to its parent window.)
3189 * Return value: not meaningful, ignore
3192 gdk_window_get_origin (GdkWindow *window,
3201 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
3203 if (!GDK_WINDOW_DESTROYED (window))
3205 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
3206 GDK_WINDOW_XID (window),
3207 GDK_WINDOW_XROOTWIN (window),
3223 * gdk_window_get_deskrelative_origin:
3224 * @window: a toplevel #GdkWindow
3225 * @x: return location for X coordinate
3226 * @y: return location for Y coordinate
3228 * This gets the origin of a #GdkWindow relative to
3229 * an Enlightenment-window-manager desktop. As long as you don't
3230 * assume that the user's desktop/workspace covers the entire
3231 * root window (i.e. you don't assume that the desktop begins
3232 * at root window coordinate 0,0) this function is not necessary.
3233 * It's deprecated for that reason.
3235 * Return value: not meaningful
3238 gdk_window_get_deskrelative_origin (GdkWindow *window,
3242 gboolean return_val = FALSE;
3243 gint num_children, format_return;
3244 Window win, *child, parent, root;
3249 gulong number_return, bytes_after_return;
3250 guchar *data_return;
3252 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3254 if (!GDK_WINDOW_DESTROYED (window))
3256 atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3257 "ENLIGHTENMENT_DESKTOP");
3258 win = GDK_WINDOW_XID (window);
3260 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
3261 &child, (unsigned int *)&num_children))
3263 if ((child) && (num_children > 0))
3275 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
3276 False, XA_CARDINAL, &type_return, &format_return,
3277 &number_return, &bytes_after_return, &data_return);
3279 if (type_return == XA_CARDINAL)
3281 XFree (data_return);
3286 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
3287 GDK_WINDOW_XID (window),
3302 * gdk_window_get_root_origin:
3303 * @window: a toplevel #GdkWindow
3304 * @x: return location for X position of window frame
3305 * @y: return location for Y position of window frame
3307 * Obtains the top-left corner of the window manager frame in root
3308 * window coordinates.
3312 gdk_window_get_root_origin (GdkWindow *window,
3318 g_return_if_fail (GDK_IS_WINDOW (window));
3320 gdk_window_get_frame_extents (window, &rect);
3330 * gdk_window_get_frame_extents:
3331 * @window: a toplevel #GdkWindow
3332 * @rect: rectangle to fill with bounding box of the window frame
3334 * Obtains the bounding box of the window, including window manager
3335 * titlebar/borders if any. The frame position is given in root window
3336 * coordinates. To get the position of the window itself (rather than
3337 * the frame) in root window coordinates, use gdk_window_get_origin().
3341 gdk_window_get_frame_extents (GdkWindow *window,
3344 GdkDisplay *display;
3345 GdkWindowObject *private;
3355 gulong nitems_return;
3356 gulong bytes_after_return;
3359 guint ww, wh, wb, wd;
3362 g_return_if_fail (GDK_IS_WINDOW (window));
3363 g_return_if_fail (rect != NULL);
3365 private = (GdkWindowObject*) window;
3372 if (GDK_WINDOW_DESTROYED (window))
3375 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
3376 private = (GdkWindowObject*) private->parent;
3378 /* Refine our fallback answer a bit using local information */
3379 rect->x = private->x;
3380 rect->y = private->y;
3381 gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height);
3383 if (GDK_WINDOW_DESTROYED (private))
3386 gdk_error_trap_push();
3388 /* use NETWM_VIRTUAL_ROOTS if available */
3389 display = gdk_drawable_get_display (window);
3390 root = GDK_WINDOW_XROOTWIN (window);
3395 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
3396 gdk_x11_get_xatom_by_name_for_display (display,
3397 "_NET_VIRTUAL_ROOTS"),
3398 0, G_MAXLONG, False, XA_WINDOW, &type_return,
3399 &format_return, &nitems_return, &bytes_after_return,
3403 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
3405 nvroots = nitems_return;
3406 vroots = (Window *)data;
3410 xparent = GDK_WINDOW_XID (window);
3416 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
3418 &children, &nchildren))
3424 /* check virtual roots */
3425 for (i = 0; i < nvroots; i++)
3427 if (xparent == vroots[i])
3434 while (xparent != root);
3436 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
3437 &root, &wx, &wy, &ww, &wh, &wb, &wd))
3449 gdk_error_trap_pop ();
3453 _gdk_windowing_get_pointer (GdkDisplay *display,
3457 GdkModifierType *mask)
3459 GdkScreen *default_screen;
3469 if (display->closed)
3472 default_screen = gdk_display_get_default_screen (display);
3474 xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
3475 xwindow = GDK_SCREEN_XROOTWIN (default_screen);
3477 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3479 XQueryPointer (xdisplay, xwindow,
3480 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3484 XSetWindowAttributes attributes;
3487 w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
3488 CopyFromParent, InputOnly, CopyFromParent,
3490 XQueryPointer (xdisplay, w,
3491 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3492 XDestroyWindow (xdisplay, w);
3497 GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root);
3498 *screen = gdk_drawable_get_screen (gdk_root);
3507 _gdk_windowing_window_get_pointer (GdkDisplay *display,
3511 GdkModifierType *mask)
3513 GdkWindow *return_val;
3519 unsigned int xmask = 0;
3520 gint xoffset, yoffset;
3522 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
3524 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3527 if (!GDK_WINDOW_DESTROYED (window))
3529 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3531 if (XQueryPointer (GDK_WINDOW_XDISPLAY (window),
3532 GDK_WINDOW_XID (window),
3533 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
3536 return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child);
3542 int originx, originy;
3543 _gdk_windowing_get_pointer (gdk_drawable_get_display (window), &screen,
3544 &rootx, &rooty, &xmask);
3545 gdk_window_get_origin (window, &originx, &originy);
3546 winx = rootx - originx;
3547 winy = rooty - originy;
3551 *x = winx + xoffset;
3552 *y = winy + yoffset;
3559 * gdk_display_warp_pointer:
3560 * @display: a #GdkDisplay
3561 * @screen: the screen of @display to warp the pointer to
3562 * @x: the x coordinate of the destination
3563 * @y: the y coordinate of the destination
3565 * Warps the pointer of @display to the point @x,@y on
3566 * the screen @screen, unless the pointer is confined
3567 * to a window by a grab, in which case it will be moved
3568 * as far as allowed by the grab. Warping the pointer
3569 * creates events as if the user had moved the mouse
3570 * instantaneously to the destination.
3572 * Note that the pointer should normally be under the
3573 * control of the user. This function was added to cover
3574 * some rare use cases like keyboard navigation support
3575 * for the color picker in the #GtkColorSelectionDialog.
3580 gdk_display_warp_pointer (GdkDisplay *display,
3588 xdisplay = GDK_DISPLAY_XDISPLAY (display);
3589 dest = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen));
3591 XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, x, y);
3595 _gdk_windowing_window_at_pointer (GdkDisplay *display,
3604 Window xwindow_last = 0;
3606 int rootx = -1, rooty = -1;
3610 screen = gdk_display_get_default_screen (display);
3612 xwindow = GDK_SCREEN_XROOTWIN (screen);
3613 xdisplay = GDK_SCREEN_XDISPLAY (screen);
3615 /* This function really only works if the mouse pointer is held still
3616 * during its operation. If it moves from one leaf window to another
3617 * than we'll end up with inaccurate values for win_x, win_y
3620 gdk_x11_display_grab (display);
3621 if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
3623 XQueryPointer (xdisplay, xwindow,
3624 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3625 if (root == xwindow)
3632 xwindow_last = xwindow;
3633 XQueryPointer (xdisplay, xwindow,
3634 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3639 gint i, screens, width, height;
3640 GList *toplevels, *list;
3641 Window pointer_window;
3643 pointer_window = None;
3644 screens = gdk_display_get_n_screens (display);
3645 for (i = 0; i < screens; ++i) {
3646 screen = gdk_display_get_screen (display, i);
3647 toplevels = gdk_screen_get_toplevel_windows (screen);
3648 for (list = toplevels; list != NULL; list = g_list_next (list)) {
3649 window = GDK_WINDOW (list->data);
3650 xwindow = GDK_WINDOW_XWINDOW (window);
3651 gdk_error_trap_push ();
3652 XQueryPointer (xdisplay, xwindow,
3653 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3655 if (gdk_error_trap_pop ())
3659 pointer_window = child;
3662 gdk_window_get_geometry (window, NULL, NULL, &width, &height, NULL);
3663 if (winx >= 0 && winy >= 0 && winx < width && winy < height)
3665 /* A childless toplevel, or below another window? */
3666 XSetWindowAttributes attributes;
3669 w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
3670 CopyFromParent, InputOnly, CopyFromParent,
3672 XMapWindow (xdisplay, w);
3673 XQueryPointer (xdisplay, xwindow,
3674 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
3675 XDestroyWindow (xdisplay, w);
3678 pointer_window = xwindow;
3683 g_list_free (toplevels);
3684 if (pointer_window != None)
3687 xwindow = pointer_window;
3691 xwindow_last = xwindow;
3692 gdk_error_trap_push ();
3693 XQueryPointer (xdisplay, xwindow,
3694 &root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask);
3696 if (gdk_error_trap_pop ())
3701 gdk_x11_display_ungrab (display);
3703 window = gdk_window_lookup_for_display (display, xwindow_last);
3704 *win_x = window ? winx : -1;
3705 *win_y = window ? winy : -1;
3711 * gdk_window_get_events:
3712 * @window: a #GdkWindow
3714 * Gets the event mask for @window. See gdk_window_set_events().
3716 * Return value: event mask for @window
3719 gdk_window_get_events (GdkWindow *window)
3721 XWindowAttributes attrs;
3722 GdkEventMask event_mask;
3724 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
3726 if (GDK_WINDOW_DESTROYED (window))
3730 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3731 GDK_WINDOW_XID (window),
3734 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
3735 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3742 * gdk_window_set_events:
3743 * @window: a #GdkWindow
3744 * @event_mask: event mask for @window
3746 * The event mask for a window determines which events will be reported
3747 * for that window. For example, an event mask including #GDK_BUTTON_PRESS_MASK
3748 * means the window should report button press events. The event mask
3749 * is the bitwise OR of values from the #GdkEventMask enumeration.
3753 gdk_window_set_events (GdkWindow *window,
3754 GdkEventMask event_mask)
3759 g_return_if_fail (GDK_IS_WINDOW (window));
3761 if (!GDK_WINDOW_DESTROYED (window))
3763 GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
3764 xevent_mask = StructureNotifyMask | PropertyChangeMask;
3765 for (i = 0; i < _gdk_nenvent_masks; i++)
3767 if (event_mask & (1 << (i + 1)))
3768 xevent_mask |= _gdk_event_mask_table[i];
3771 XSelectInput (GDK_WINDOW_XDISPLAY (window),
3772 GDK_WINDOW_XID (window),
3778 gdk_window_add_colormap_windows (GdkWindow *window)
3780 GdkWindow *toplevel;
3781 Window *old_windows;
3782 Window *new_windows;
3785 g_return_if_fail (GDK_IS_WINDOW (window));
3787 if (GDK_WINDOW_DESTROYED (window))
3789 toplevel = gdk_window_get_toplevel (window);
3792 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3793 GDK_WINDOW_XID (toplevel),
3794 &old_windows, &count))
3799 for (i = 0; i < count; i++)
3800 if (old_windows[i] == GDK_WINDOW_XID (window))
3802 XFree (old_windows);
3806 new_windows = g_new (Window, count + 1);
3808 for (i = 0; i < count; i++)
3809 new_windows[i] = old_windows[i];
3810 new_windows[count] = GDK_WINDOW_XID (window);
3812 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
3813 GDK_WINDOW_XID (toplevel),
3814 new_windows, count + 1);
3816 g_free (new_windows);
3818 XFree (old_windows);
3821 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
3824 * This needs the X11 shape extension.
3825 * If not available, shaped windows will look
3826 * ugly, but programs still work. Stefan Wille
3829 do_shape_combine_mask (GdkWindow *window,
3835 GdkWindowObject *private = (GdkWindowObject *)window;
3837 gint xoffset, yoffset;
3839 g_return_if_fail (GDK_IS_WINDOW (window));
3841 #ifdef HAVE_SHAPE_EXT
3842 if (GDK_WINDOW_DESTROYED (window))
3845 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3847 if (xoffset != 0 || yoffset != 0)
3849 WARN_SHAPE_TOO_BIG ();
3853 if (shape == ShapeBounding
3854 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3855 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3859 pixmap = GDK_PIXMAP_XID (mask);
3861 private->shaped = (shape == ShapeBounding);
3869 private->shaped = FALSE;
3872 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
3873 GDK_WINDOW_XID (window),
3879 #endif /* HAVE_SHAPE_EXT */
3883 * gdk_window_shape_combine_mask:
3884 * @window: a #GdkWindow
3886 * @x: X position of shape mask with respect to @window
3887 * @y: Y position of shape mask with respect to @window
3889 * Applies a shape mask to @window. Pixels in @window corresponding to
3890 * set bits in the @mask will be visible; pixels in @window
3891 * corresponding to unset bits in the @mask will be transparent. This
3892 * gives a non-rectangular window.
3894 * If @mask is %NULL, the shape mask will be unset, and the @x/@y
3895 * parameters are not used.
3897 * On the X11 platform, this uses an X server extension which is
3898 * widely available on most common platforms, but not available on
3899 * very old X servers, and occasionally the implementation will be
3900 * buggy. On servers without the shape extension, this function
3903 * On the Win32 platform the functionality is always present.
3905 * This function works on both toplevel and child windows.
3909 gdk_window_shape_combine_mask (GdkWindow *window,
3914 do_shape_combine_mask (window, mask, x, y, ShapeBounding);
3918 * gdk_window_input_shape_combine_mask:
3919 * @window: a #GdkWindow
3921 * @x: X position of shape mask with respect to @window
3922 * @y: Y position of shape mask with respect to @window
3924 * Like gdk_window_shape_combine_mask(), but the shape applies
3925 * only to event handling. Mouse events which happen while
3926 * the pointer position corresponds to an unset bit in the
3927 * mask will be passed on the window below @window.
3929 * An input shape is typically used with RGBA windows.
3930 * The alpha channel of the window defines which pixels are
3931 * invisible and allows for nicely antialiased borders,
3932 * and the input shape controls where the window is
3935 * On the X11 platform, this requires version 1.1 of the
3938 * On the Win32 platform, this functionality is not present and the
3939 * function does nothing.
3944 gdk_window_input_shape_combine_mask (GdkWindow *window,
3950 do_shape_combine_mask (window, mask, x, y, ShapeInput);
3956 do_shape_combine_region (GdkWindow *window,
3957 GdkRegion *shape_region,
3962 GdkWindowObject *private = (GdkWindowObject *)window;
3963 gint xoffset, yoffset;
3965 g_return_if_fail (GDK_IS_WINDOW (window));
3967 #ifdef HAVE_SHAPE_EXT
3968 if (GDK_WINDOW_DESTROYED (window))
3971 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
3973 if (xoffset != 0 || yoffset != 0)
3975 WARN_SHAPE_TOO_BIG ();
3979 if (shape_region == NULL)
3981 /* Use NULL mask to unset the shape */
3982 gdk_window_shape_combine_mask (window, NULL, 0, 0);
3986 if (shape == ShapeBounding
3987 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
3988 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
3991 XRectangle *xrects = NULL;
3993 private->shaped = shape == ShapeBounding;
3995 _gdk_region_get_xrectangles (shape_region,
3999 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
4000 GDK_WINDOW_XID (window),
4009 #endif /* HAVE_SHAPE_EXT */
4013 * gdk_window_shape_combine_region:
4014 * @window: a #GdkWindow
4015 * @shape_region: region of window to be non-transparent
4016 * @offset_x: X position of @shape_region in @window coordinates
4017 * @offset_y: Y position of @shape_region in @window coordinates
4019 * Makes pixels in @window outside @shape_region be transparent,
4020 * so that the window may be nonrectangular. See also
4021 * gdk_window_shape_combine_mask() to use a bitmap as the mask.
4023 * If @shape_region is %NULL, the shape will be unset, so the whole
4024 * window will be opaque again. @offset_x and @offset_y are ignored
4025 * if @shape_region is %NULL.
4027 * On the X11 platform, this uses an X server extension which is
4028 * widely available on most common platforms, but not available on
4029 * very old X servers, and occasionally the implementation will be
4030 * buggy. On servers without the shape extension, this function
4033 * On the Win32 platform, this functionality is always present.
4035 * This function works on both toplevel and child windows.
4039 gdk_window_shape_combine_region (GdkWindow *window,
4040 GdkRegion *shape_region,
4044 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
4048 * gdk_window_input_shape_combine_region:
4049 * @window: a #GdkWindow
4050 * @shape_region: region of window to be non-transparent
4051 * @offset_x: X position of @shape_region in @window coordinates
4052 * @offset_y: Y position of @shape_region in @window coordinates
4054 * Like gdk_window_shape_combine_region(), but the shape applies
4055 * only to event handling. Mouse events which happen while
4056 * the pointer position corresponds to an unset bit in the
4057 * mask will be passed on the window below @window.
4059 * An input shape is typically used with RGBA windows.
4060 * The alpha channel of the window defines which pixels are
4061 * invisible and allows for nicely antialiased borders,
4062 * and the input shape controls where the window is
4065 * On the X11 platform, this requires version 1.1 of the
4068 * On the Win32 platform, this functionality is not present and the
4069 * function does nothing.
4074 gdk_window_input_shape_combine_region (GdkWindow *window,
4075 GdkRegion *shape_region,
4080 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
4086 * gdk_window_set_override_redirect:
4087 * @window: a toplevel #GdkWindow
4088 * @override_redirect: %TRUE if window should be override redirect
4090 * An override redirect window is not under the control of the window manager.
4091 * This means it won't have a titlebar, won't be minimizable, etc. - it will
4092 * be entirely under the control of the application. The window manager
4093 * can't see the override redirect window at all.
4095 * Override redirect should only be used for short-lived temporary
4096 * windows, such as popup menus. #GtkMenu uses an override redirect
4097 * window in its implementation, for example.
4101 gdk_window_set_override_redirect (GdkWindow *window,
4102 gboolean override_redirect)
4104 XSetWindowAttributes attr;
4106 g_return_if_fail (GDK_IS_WINDOW (window));
4108 if (!GDK_WINDOW_DESTROYED (window))
4110 GdkWindowObject *private = (GdkWindowObject *)window;
4111 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
4113 attr.override_redirect = (override_redirect? True : False);
4114 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
4115 GDK_WINDOW_XID (window),
4119 impl->override_redirect = attr.override_redirect;
4124 * gdk_window_set_accept_focus:
4125 * @window: a toplevel #GdkWindow
4126 * @accept_focus: %TRUE if the window should receive input focus
4128 * Setting @accept_focus to %FALSE hints the desktop environment that the
4129 * window doesn't want to receive input focus.
4131 * On X, it is the responsibility of the window manager to interpret this
4132 * hint. ICCCM-compliant window manager usually respect it.
4137 gdk_window_set_accept_focus (GdkWindow *window,
4138 gboolean accept_focus)
4140 GdkWindowObject *private;
4142 g_return_if_fail (GDK_IS_WINDOW (window));
4144 private = (GdkWindowObject *)window;
4146 accept_focus = accept_focus != FALSE;
4148 if (private->accept_focus != accept_focus)
4150 private->accept_focus = accept_focus;
4152 if (!GDK_WINDOW_DESTROYED (window))
4153 update_wm_hints (window, FALSE);
4158 * gdk_window_set_focus_on_map:
4159 * @window: a toplevel #GdkWindow
4160 * @focus_on_map: %TRUE if the window should receive input focus when mapped
4162 * Setting @focus_on_map to %FALSE hints the desktop environment that the
4163 * window doesn't want to receive input focus when it is mapped.
4164 * focus_on_map should be turned off for windows that aren't triggered
4165 * interactively (such as popups from network activity).
4167 * On X, it is the responsibility of the window manager to interpret
4168 * this hint. Window managers following the freedesktop.org window
4169 * manager extension specification should respect it.
4174 gdk_window_set_focus_on_map (GdkWindow *window,
4175 gboolean focus_on_map)
4177 GdkWindowObject *private;
4179 g_return_if_fail (GDK_IS_WINDOW (window));
4181 private = (GdkWindowObject *)window;
4183 focus_on_map = focus_on_map != FALSE;
4185 if (private->focus_on_map != focus_on_map)
4187 private->focus_on_map = focus_on_map;
4189 if ((!GDK_WINDOW_DESTROYED (window)) && (!private->focus_on_map))
4190 gdk_x11_window_set_user_time (window, 0);
4195 * gdk_x11_window_set_user_time:
4196 * @window: A toplevel #GdkWindow
4197 * @timestamp: An XServer timestamp to which the property should be set
4199 * The application can use this call to update the _NET_WM_USER_TIME
4200 * property on a toplevel window. This property stores an Xserver
4201 * time which represents the time of the last user input event
4202 * received for this window. This property may be used by the window
4203 * manager to alter the focus, stacking, and/or placement behavior of
4204 * windows when they are mapped depending on whether the new window
4205 * was created by a user action or is a "pop-up" window activated by a
4206 * timer or some other event.
4208 * Note that this property is automatically updated by GDK, so this
4209 * function should only be used by applications which handle input
4210 * events bypassing GDK.
4215 gdk_x11_window_set_user_time (GdkWindow *window,
4218 GdkDisplay *display;
4219 GdkDisplayX11 *display_x11;
4220 GdkToplevelX11 *toplevel;
4221 glong timestamp_long = (glong)timestamp;
4223 g_return_if_fail (GDK_IS_WINDOW (window));
4225 if (GDK_WINDOW_DESTROYED (window))
4228 display = gdk_drawable_get_display (window);
4229 display_x11 = GDK_DISPLAY_X11 (display);
4230 toplevel = _gdk_x11_window_get_toplevel (window);
4232 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4233 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
4234 XA_CARDINAL, 32, PropModeReplace,
4235 (guchar *)×tamp_long, 1);
4237 if (timestamp_long != GDK_CURRENT_TIME)
4238 display_x11->user_time = timestamp_long;
4240 toplevel->user_time = timestamp_long;
4243 #define GDK_SELECTION_MAX_SIZE(display) \
4245 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
4246 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
4247 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
4250 * gdk_window_set_icon_list:
4251 * @window: The #GdkWindow toplevel window to set the icon of.
4252 * @pixbufs: A list of pixbufs, of different sizes.
4254 * Sets a list of icons for the window. One of these will be used
4255 * to represent the window when it has been iconified. The icon is
4256 * usually shown in an icon box or some sort of task bar. Which icon
4257 * size is shown depends on the window manager. The window manager
4258 * can scale the icon but setting several size icons can give better
4259 * image quality since the window manager may only need to scale the
4260 * icon by a small amount or not at all.
4264 gdk_window_set_icon_list (GdkWindow *window,
4273 gint width, height, stride;
4276 GdkDisplay *display;
4279 g_return_if_fail (GDK_IS_WINDOW (window));
4281 if (GDK_WINDOW_DESTROYED (window))
4284 display = gdk_drawable_get_display (window);
4292 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
4294 width = gdk_pixbuf_get_width (pixbuf);
4295 height = gdk_pixbuf_get_height (pixbuf);
4297 /* silently ignore overlarge icons */
4298 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
4300 g_warning ("gdk_window_set_icon_list: icons too large");
4305 size += 2 + width * height;
4307 l = g_list_next (l);
4310 data = g_malloc (size * sizeof (gulong));
4318 width = gdk_pixbuf_get_width (pixbuf);
4319 height = gdk_pixbuf_get_height (pixbuf);
4320 stride = gdk_pixbuf_get_rowstride (pixbuf);
4321 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
4326 pixels = gdk_pixbuf_get_pixels (pixbuf);
4328 for (y = 0; y < height; y++)
4330 for (x = 0; x < width; x++)
4334 r = pixels[y*stride + x*n_channels + 0];
4335 g = pixels[y*stride + x*n_channels + 1];
4336 b = pixels[y*stride + x*n_channels + 2];
4337 if (n_channels >= 4)
4338 a = pixels[y*stride + x*n_channels + 3];
4342 *p++ = a << 24 | r << 16 | g << 8 | b ;
4346 l = g_list_next (l);
4352 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
4353 GDK_WINDOW_XID (window),
4354 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
4357 (guchar*) data, size);
4361 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
4362 GDK_WINDOW_XID (window),
4363 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
4370 * gdk_window_set_icon:
4371 * @window: a toplevel #GdkWindow
4372 * @icon_window: a #GdkWindow to use for the icon, or %NULL to unset
4373 * @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset
4374 * @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none
4376 * Sets the icon of @window as a pixmap or window. If using GTK+, investigate
4377 * gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list()
4378 * and gtk_window_set_icon(). If those don't meet your needs, look at
4379 * gdk_window_set_icon_list(). Only if all those are too high-level do you
4380 * want to fall back to gdk_window_set_icon().
4384 gdk_window_set_icon (GdkWindow *window,
4385 GdkWindow *icon_window,
4389 GdkToplevelX11 *toplevel;
4391 g_return_if_fail (GDK_IS_WINDOW (window));
4392 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4394 if (GDK_WINDOW_DESTROYED (window))
4397 toplevel = _gdk_x11_window_get_toplevel (window);
4399 if (toplevel->icon_window != icon_window)
4401 if (toplevel->icon_window)
4402 g_object_unref (toplevel->icon_window);
4403 toplevel->icon_window = g_object_ref (icon_window);
4406 if (toplevel->icon_pixmap != pixmap)
4409 g_object_ref (pixmap);
4410 if (toplevel->icon_pixmap)
4411 g_object_unref (toplevel->icon_pixmap);
4412 toplevel->icon_pixmap = pixmap;
4415 if (toplevel->icon_mask != mask)
4418 g_object_ref (mask);
4419 if (toplevel->icon_mask)
4420 g_object_unref (toplevel->icon_mask);
4421 toplevel->icon_mask = mask;
4424 update_wm_hints (window, FALSE);
4428 gdk_window_icon_name_set (GdkWindow *window)
4430 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
4431 g_quark_from_static_string ("gdk-icon-name-set")));
4435 * gdk_window_set_icon_name:
4436 * @window: a toplevel #GdkWindow
4437 * @name: name of window while iconified (minimized)
4439 * Windows may have a name used while minimized, distinct from the
4440 * name they display in their titlebar. Most of the time this is a bad
4441 * idea from a user interface standpoint. But you can set such a name
4442 * with this function, if you like.
4446 gdk_window_set_icon_name (GdkWindow *window,
4449 GdkDisplay *display;
4451 g_return_if_fail (GDK_IS_WINDOW (window));
4453 if (GDK_WINDOW_DESTROYED (window))
4456 display = gdk_drawable_get_display (window);
4458 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
4459 GUINT_TO_POINTER (TRUE));
4461 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
4462 GDK_WINDOW_XID (window),
4463 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
4464 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
4465 PropModeReplace, (guchar *)name, strlen (name));
4467 set_text_property (display, GDK_WINDOW_XID (window),
4468 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
4473 * gdk_window_iconify:
4474 * @window: a toplevel #GdkWindow
4476 * Asks to iconify (minimize) @window. The window manager may choose
4477 * to ignore the request, but normally will honor it. Using
4478 * gtk_window_iconify() is preferred, if you have a #GtkWindow widget.
4480 * This function only makes sense when @window is a toplevel window.
4484 gdk_window_iconify (GdkWindow *window)
4486 g_return_if_fail (GDK_IS_WINDOW (window));
4488 if (GDK_WINDOW_DESTROYED (window))
4491 if (GDK_WINDOW_IS_MAPPED (window))
4493 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
4494 GDK_WINDOW_XWINDOW (window),
4495 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
4499 /* Flip our client side flag, the real work happens on map. */
4500 gdk_synthesize_window_state (window,
4502 GDK_WINDOW_STATE_ICONIFIED);
4507 * gdk_window_deiconify:
4508 * @window: a toplevel #GdkWindow
4510 * Attempt to deiconify (unminimize) @window. On X11 the window manager may
4511 * choose to ignore the request to deiconify. When using GTK+,
4512 * use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet,
4513 * you probably want to use gtk_window_present(), which raises the window, focuses it,
4514 * unminimizes it, and puts it on the current desktop.
4518 gdk_window_deiconify (GdkWindow *window)
4520 g_return_if_fail (GDK_IS_WINDOW (window));
4522 if (GDK_WINDOW_DESTROYED (window))
4525 if (GDK_WINDOW_IS_MAPPED (window))
4527 gdk_window_show (window);
4531 /* Flip our client side flag, the real work happens on map. */
4532 gdk_synthesize_window_state (window,
4533 GDK_WINDOW_STATE_ICONIFIED,
4540 * @window: a toplevel #GdkWindow
4542 * "Pins" a window such that it's on all workspaces and does not scroll
4543 * with viewports, for window managers that have scrollable viewports.
4544 * (When using #GtkWindow, gtk_window_stick() may be more useful.)
4546 * On the X11 platform, this function depends on window manager
4547 * support, so may have no effect with many window managers. However,
4548 * GDK will do the best it can to convince the window manager to stick
4549 * the window. For window managers that don't support this operation,
4550 * there's nothing you can do to force it to happen.
4554 gdk_window_stick (GdkWindow *window)
4556 g_return_if_fail (GDK_IS_WINDOW (window));
4558 if (GDK_WINDOW_DESTROYED (window))
4561 if (GDK_WINDOW_IS_MAPPED (window))
4563 /* "stick" means stick to all desktops _and_ do not scroll with the
4564 * viewport. i.e. glue to the monitor glass in all cases.
4569 /* Request stick during viewport scroll */
4570 gdk_wmspec_change_state (TRUE, window,
4571 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4574 /* Request desktop 0xFFFFFFFF */
4575 xev.xclient.type = ClientMessage;
4576 xev.xclient.serial = 0;
4577 xev.xclient.send_event = True;
4578 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
4579 xev.xclient.display = GDK_WINDOW_XDISPLAY (window);
4580 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
4582 xev.xclient.format = 32;
4584 xev.xclient.data.l[0] = 0xFFFFFFFF;
4585 xev.xclient.data.l[1] = 0;
4586 xev.xclient.data.l[2] = 0;
4587 xev.xclient.data.l[3] = 0;
4588 xev.xclient.data.l[4] = 0;
4590 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
4591 SubstructureRedirectMask | SubstructureNotifyMask,
4596 /* Flip our client side flag, the real work happens on map. */
4597 gdk_synthesize_window_state (window,
4599 GDK_WINDOW_STATE_STICKY);
4604 * gdk_window_unstick:
4605 * @window: a toplevel #GdkWindow
4607 * Reverse operation for gdk_window_stick(); see gdk_window_stick(),
4608 * and gtk_window_unstick().
4612 gdk_window_unstick (GdkWindow *window)
4614 g_return_if_fail (GDK_IS_WINDOW (window));
4616 if (GDK_WINDOW_DESTROYED (window))
4619 if (GDK_WINDOW_IS_MAPPED (window))
4621 /* Request unstick from viewport */
4622 gdk_wmspec_change_state (FALSE, window,
4623 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
4626 move_to_current_desktop (window);
4630 /* Flip our client side flag, the real work happens on map. */
4631 gdk_synthesize_window_state (window,
4632 GDK_WINDOW_STATE_STICKY,
4639 * gdk_window_maximize:
4640 * @window: a toplevel #GdkWindow
4642 * Maximizes the window. If the window was already maximized, then
4643 * this function does nothing.
4645 * On X11, asks the window manager to maximize @window, if the window
4646 * manager supports this operation. Not all window managers support
4647 * this, and some deliberately ignore it or don't have a concept of
4648 * "maximized"; so you can't rely on the maximization actually
4649 * happening. But it will happen with most standard window managers,
4650 * and GDK makes a best effort to get it to happen.
4652 * On Windows, reliably maximizes the window.
4656 gdk_window_maximize (GdkWindow *window)
4658 g_return_if_fail (GDK_IS_WINDOW (window));
4660 if (GDK_WINDOW_DESTROYED (window))
4663 if (GDK_WINDOW_IS_MAPPED (window))
4664 gdk_wmspec_change_state (TRUE, window,
4665 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4666 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4668 gdk_synthesize_window_state (window,
4670 GDK_WINDOW_STATE_MAXIMIZED);
4674 * gdk_window_unmaximize:
4675 * @window: a toplevel #GdkWindow
4677 * Unmaximizes the window. If the window wasn't maximized, then this
4678 * function does nothing.
4680 * On X11, asks the window manager to unmaximize @window, if the
4681 * window manager supports this operation. Not all window managers
4682 * support this, and some deliberately ignore it or don't have a
4683 * concept of "maximized"; so you can't rely on the unmaximization
4684 * actually happening. But it will happen with most standard window
4685 * managers, and GDK makes a best effort to get it to happen.
4687 * On Windows, reliably unmaximizes the window.
4691 gdk_window_unmaximize (GdkWindow *window)
4693 g_return_if_fail (GDK_IS_WINDOW (window));
4695 if (GDK_WINDOW_DESTROYED (window))
4698 if (GDK_WINDOW_IS_MAPPED (window))
4699 gdk_wmspec_change_state (FALSE, window,
4700 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
4701 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
4703 gdk_synthesize_window_state (window,
4704 GDK_WINDOW_STATE_MAXIMIZED,
4709 * gdk_window_fullscreen:
4710 * @window: a toplevel #GdkWindow
4712 * Moves the window into fullscreen mode. This means the
4713 * window covers the entire screen and is above any panels
4716 * If the window was already fullscreen, then this function does nothing.
4718 * On X11, asks the window manager to put @window in a fullscreen
4719 * state, if the window manager supports this operation. Not all
4720 * window managers support this, and some deliberately ignore it or
4721 * don't have a concept of "fullscreen"; so you can't rely on the
4722 * fullscreenification actually happening. But it will happen with
4723 * most standard window managers, and GDK makes a best effort to get
4729 gdk_window_fullscreen (GdkWindow *window)
4731 g_return_if_fail (GDK_IS_WINDOW (window));
4733 if (GDK_WINDOW_DESTROYED (window))
4736 if (GDK_WINDOW_IS_MAPPED (window))
4737 gdk_wmspec_change_state (TRUE, window,
4738 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4742 gdk_synthesize_window_state (window,
4744 GDK_WINDOW_STATE_FULLSCREEN);
4748 * gdk_window_unfullscreen:
4749 * @window: a toplevel #GdkWindow
4751 * Moves the window out of fullscreen mode. If the window was not
4752 * fullscreen, does nothing.
4754 * On X11, asks the window manager to move @window out of the fullscreen
4755 * state, if the window manager supports this operation. Not all
4756 * window managers support this, and some deliberately ignore it or
4757 * don't have a concept of "fullscreen"; so you can't rely on the
4758 * unfullscreenification actually happening. But it will happen with
4759 * most standard window managers, and GDK makes a best effort to get
4765 gdk_window_unfullscreen (GdkWindow *window)
4767 g_return_if_fail (GDK_IS_WINDOW (window));
4769 if (GDK_WINDOW_DESTROYED (window))
4772 if (GDK_WINDOW_IS_MAPPED (window))
4773 gdk_wmspec_change_state (FALSE, window,
4774 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
4778 gdk_synthesize_window_state (window,
4779 GDK_WINDOW_STATE_FULLSCREEN,
4784 * gdk_window_set_keep_above:
4785 * @window: a toplevel #GdkWindow
4786 * @setting: whether to keep @window above other windows
4788 * Set if @window must be kept above other windows. If the
4789 * window was already above, then this function does nothing.
4791 * On X11, asks the window manager to keep @window above, if the window
4792 * manager supports this operation. Not all window managers support
4793 * this, and some deliberately ignore it or don't have a concept of
4794 * "keep above"; so you can't rely on the window being kept above.
4795 * But it will happen with most standard window managers,
4796 * and GDK makes a best effort to get it to happen.
4801 gdk_window_set_keep_above (GdkWindow *window, gboolean setting)
4803 g_return_if_fail (GDK_IS_WINDOW (window));
4805 if (GDK_WINDOW_DESTROYED (window))
4808 if (GDK_WINDOW_IS_MAPPED (window))
4811 gdk_wmspec_change_state (FALSE, window,
4812 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4814 gdk_wmspec_change_state (setting, window,
4815 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4819 gdk_synthesize_window_state (window,
4820 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
4821 setting ? GDK_WINDOW_STATE_ABOVE : 0);
4825 * gdk_window_set_keep_below:
4826 * @window: a toplevel #GdkWindow
4827 * @setting: whether to keep @window below other windows
4829 * Set if @window must be kept below other windows. If the
4830 * window was already below, then this function does nothing.
4832 * On X11, asks the window manager to keep @window below, if the window
4833 * manager supports this operation. Not all window managers support
4834 * this, and some deliberately ignore it or don't have a concept of
4835 * "keep below"; so you can't rely on the window being kept below.
4836 * But it will happen with most standard window managers,
4837 * and GDK makes a best effort to get it to happen.
4842 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
4844 g_return_if_fail (GDK_IS_WINDOW (window));
4846 if (GDK_WINDOW_DESTROYED (window))
4849 if (GDK_WINDOW_IS_MAPPED (window))
4852 gdk_wmspec_change_state (FALSE, window,
4853 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
4855 gdk_wmspec_change_state (setting, window,
4856 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
4860 gdk_synthesize_window_state (window,
4861 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
4862 setting ? GDK_WINDOW_STATE_BELOW : 0);
4866 * gdk_window_get_group:
4867 * @window: a toplevel #GdkWindow
4869 * Returns the group leader window for @window. See gdk_window_set_group().
4871 * Return value: the group leader window for @window
4876 gdk_window_get_group (GdkWindow *window)
4878 GdkToplevelX11 *toplevel;
4880 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
4881 g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);
4883 if (GDK_WINDOW_DESTROYED (window))
4886 toplevel = _gdk_x11_window_get_toplevel (window);
4888 return toplevel->group_leader;
4892 * gdk_window_set_group:
4893 * @window: a toplevel #GdkWindow
4894 * @leader: group leader window, or %NULL to restore the default group leader window
4896 * Sets the group leader window for @window. By default,
4897 * GDK sets the group leader for all toplevel windows
4898 * to a global window implicitly created by GDK. With this function
4899 * you can override this default.
4901 * The group leader window allows the window manager to distinguish
4902 * all windows that belong to a single application. It may for example
4903 * allow users to minimize/unminimize all windows belonging to an
4904 * application at once. You should only set a non-default group window
4905 * if your application pretends to be multiple applications.
4908 gdk_window_set_group (GdkWindow *window,
4911 GdkToplevelX11 *toplevel;
4913 g_return_if_fail (GDK_IS_WINDOW (window));
4914 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
4915 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
4917 if (GDK_WINDOW_DESTROYED (window) || (leader != NULL && GDK_WINDOW_DESTROYED (leader)))
4920 toplevel = _gdk_x11_window_get_toplevel (window);
4923 leader = gdk_display_get_default_group (gdk_drawable_get_display (window));
4925 if (toplevel->group_leader != leader)
4927 if (toplevel->group_leader)
4928 g_object_unref (toplevel->group_leader);
4929 toplevel->group_leader = g_object_ref (leader);
4930 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
4933 update_wm_hints (window, FALSE);
4936 static MotifWmHints *
4937 gdk_window_get_mwm_hints (GdkWindow *window)
4939 GdkDisplay *display;
4940 Atom hints_atom = None;
4947 if (GDK_WINDOW_DESTROYED (window))
4950 display = gdk_drawable_get_display (window);
4952 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4954 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
4955 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4956 False, AnyPropertyType, &type, &format, &nitems,
4957 &bytes_after, &data);
4962 return (MotifWmHints *)data;
4966 gdk_window_set_mwm_hints (GdkWindow *window,
4967 MotifWmHints *new_hints)
4969 GdkDisplay *display;
4970 Atom hints_atom = None;
4972 MotifWmHints *hints;
4978 if (GDK_WINDOW_DESTROYED (window))
4981 display = gdk_drawable_get_display (window);
4983 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
4985 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
4986 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
4987 False, AnyPropertyType, &type, &format, &nitems,
4988 &bytes_after, &data);
4994 hints = (MotifWmHints *)data;
4996 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
4998 hints->flags |= MWM_HINTS_FUNCTIONS;
4999 hints->functions = new_hints->functions;
5001 if (new_hints->flags & MWM_HINTS_DECORATIONS)
5003 hints->flags |= MWM_HINTS_DECORATIONS;
5004 hints->decorations = new_hints->decorations;
5008 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
5009 hints_atom, hints_atom, 32, PropModeReplace,
5010 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
5012 if (hints != new_hints)
5017 * gdk_window_set_decorations:
5018 * @window: a toplevel #GdkWindow
5019 * @decorations: decoration hint mask
5021 * "Decorations" are the features the window manager adds to a toplevel #GdkWindow.
5022 * This function sets the traditional Motif window manager hints that tell the
5023 * window manager which decorations you would like your window to have.
5024 * Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of
5025 * using the GDK function directly.
5027 * The @decorations argument is the logical OR of the fields in
5028 * the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the
5029 * mask, the other bits indicate which decorations should be turned off.
5030 * If #GDK_DECOR_ALL is not included, then the other bits indicate
5031 * which decorations should be turned on.
5033 * Most window managers honor a decorations hint of 0 to disable all decorations,
5034 * but very few honor all possible combinations of bits.
5038 gdk_window_set_decorations (GdkWindow *window,
5039 GdkWMDecoration decorations)
5043 g_return_if_fail (GDK_IS_WINDOW (window));
5045 /* initialize to zero to avoid writing uninitialized data to socket */
5046 memset(&hints, 0, sizeof(hints));
5047 hints.flags = MWM_HINTS_DECORATIONS;
5048 hints.decorations = decorations;
5050 gdk_window_set_mwm_hints (window, &hints);
5054 * gdk_window_get_decorations:
5055 * @window: The toplevel #GdkWindow to get the decorations from
5056 * @decorations: The window decorations will be written here
5058 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
5059 * Returns: TRUE if the window has decorations set, FALSE otherwise.
5062 gdk_window_get_decorations(GdkWindow *window,
5063 GdkWMDecoration *decorations)
5065 MotifWmHints *hints;
5066 gboolean result = FALSE;
5068 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5070 hints = gdk_window_get_mwm_hints (window);
5074 if (hints->flags & MWM_HINTS_DECORATIONS)
5077 *decorations = hints->decorations;
5088 * gdk_window_set_functions:
5089 * @window: a toplevel #GdkWindow
5090 * @functions: bitmask of operations to allow on @window
5092 * Sets hints about the window management functions to make available
5093 * via buttons on the window frame.
5095 * On the X backend, this function sets the traditional Motif window
5096 * manager hint for this purpose. However, few window managers do
5097 * anything reliable or interesting with this hint. Many ignore it
5100 * The @functions argument is the logical OR of values from the
5101 * #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL,
5102 * then the other bits indicate which functions to disable; if
5103 * it doesn't include #GDK_FUNC_ALL, it indicates which functions to
5108 gdk_window_set_functions (GdkWindow *window,
5109 GdkWMFunction functions)
5113 g_return_if_fail (GDK_IS_WINDOW (window));
5115 /* initialize to zero to avoid writing uninitialized data to socket */
5116 memset(&hints, 0, sizeof(hints));
5117 hints.flags = MWM_HINTS_FUNCTIONS;
5118 hints.functions = functions;
5120 gdk_window_set_mwm_hints (window, &hints);
5123 #ifdef HAVE_SHAPE_EXT
5126 * propagate the shapes from all child windows of a GDK window to the parent
5127 * window. Shamelessly ripped from Enlightenment's code
5135 struct _gdk_span *next;
5139 gdk_add_to_span (struct _gdk_span **s,
5143 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
5150 /* scan the spans for this line */
5153 /* -- -> new span */
5154 /* == -> existing span */
5155 /* ## -> spans intersect */
5156 /* if we are in the middle of spanning the span into the line */
5159 /* case: ---- ==== */
5160 if (xx < ptr1->start - 1)
5162 /* ends before next span - extend to here */
5166 /* case: ----##=== */
5167 else if (xx <= ptr1->end)
5169 /* crosses into next span - delete next span and append */
5170 ss->end = ptr1->end;
5171 ss->next = ptr1->next;
5175 /* case: ---###--- */
5178 /* overlaps next span - delete and keep checking */
5179 ss->next = ptr1->next;
5184 /* otherwise havent started spanning it in yet */
5187 /* case: ---- ==== */
5188 if (xx < ptr1->start - 1)
5190 /* insert span here in list */
5191 noo = g_malloc (sizeof (struct _gdk_span));
5205 /* case: ----##=== */
5206 else if ((x < ptr1->start) && (xx <= ptr1->end))
5208 /* expand this span to the left point of the new one */
5212 /* case: ===###=== */
5213 else if ((x >= ptr1->start) && (xx <= ptr1->end))
5215 /* throw the span away */
5218 /* case: ---###--- */
5219 else if ((x < ptr1->start) && (xx > ptr1->end))
5226 /* case: ===##---- */
5227 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
5233 /* case: ==== ---- */
5234 /* case handled by next loop iteration - first case */
5239 /* it started in the middle but spans beyond your current list */
5245 /* it does not start inside a span or in the middle, so add it to the end */
5246 noo = g_malloc (sizeof (struct _gdk_span));
5254 noo->next = ptr2->next;
5267 gdk_add_rectangles (Display *disp,
5269 struct _gdk_span **spans,
5276 gint x1, y1, x2, y2;
5280 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
5283 /* go through all clip rects in this window's shape */
5284 for (k = 0; k < rn; k++)
5286 /* for each clip rect, add it to each line's spans */
5288 x2 = x + rl[k].x + (rl[k].width - 1);
5290 y2 = y + rl[k].y + (rl[k].height - 1);
5299 for (a = y1; a <= y2; a++)
5302 gdk_add_to_span (&spans[a], x1, x2);
5310 gdk_propagate_shapes (Display *disp,
5315 Window rt, par, *list = NULL;
5316 gint i, j, num = 0, num_rects = 0;
5320 XRectangle *rects = NULL;
5321 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
5322 XWindowAttributes xatt;
5324 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
5329 spans = g_malloc (sizeof (struct _gdk_span *) * h);
5331 for (i = 0; i < h; i++)
5333 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
5336 /* go through all child windows and create/insert spans */
5337 for (i = 0; i < num; i++)
5339 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
5340 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
5341 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
5344 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
5346 /* go through the spans list and build a list of rects */
5347 rects = g_malloc (sizeof (XRectangle) * 256);
5349 for (i = 0; i < baseh; i++)
5352 /* go through the line for all spans */
5355 rects[num_rects].x = ptr1->start;
5356 rects[num_rects].y = i;
5357 rects[num_rects].width = ptr1->end - ptr1->start + 1;
5358 rects[num_rects].height = 1;
5360 /* if there are more lines */
5362 /* while contigous rects (same start/end coords) exist */
5363 while ((contig) && (j < baseh))
5365 /* search next line for spans matching this one */
5371 /* if we have an exact span match set contig */
5372 if ((ptr2->start == ptr1->start) &&
5373 (ptr2->end == ptr1->end))
5376 /* remove the span - not needed */
5379 ptr3->next = ptr2->next;
5385 spans[j] = ptr2->next;
5391 /* gone past the span point no point looking */
5392 else if (ptr2->start < ptr1->start)
5400 /* if a contiguous span was found increase the rect h */
5403 rects[num_rects].height++;
5407 /* up the rect count */
5409 /* every 256 new rects increase the rect array */
5410 if ((num_rects % 256) == 0)
5411 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
5415 /* set the rects as the shape mask */
5418 XShapeCombineRectangles (disp, win, shape, 0, 0, rects, num_rects,
5419 ShapeSet, YXSorted);
5424 /* free up all the spans we made */
5425 for (i = 0; i < baseh; i++)
5438 #endif /* HAVE_SHAPE_EXT */
5441 * gdk_window_set_child_shapes:
5442 * @window: a #GdkWindow
5444 * Sets the shape mask of @window to the union of shape masks
5445 * for all children of @window, ignoring the shape mask of @window
5446 * itself. Contrast with gdk_window_merge_child_shapes() which includes
5447 * the shape mask of @window in the masks to be merged.
5450 gdk_window_set_child_shapes (GdkWindow *window)
5452 g_return_if_fail (GDK_IS_WINDOW (window));
5455 #ifdef HAVE_SHAPE_EXT
5456 if (!GDK_WINDOW_DESTROYED (window) &&
5457 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
5458 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5459 GDK_WINDOW_XID (window), FALSE, ShapeBounding);
5464 * gdk_window_merge_child_shapes:
5465 * @window: a #GdkWindow
5467 * Merges the shape masks for any child windows into the
5468 * shape mask for @window. i.e. the union of all masks
5469 * for @window and its children will become the new mask
5470 * for @window. See gdk_window_shape_combine_mask().
5472 * This function is distinct from gdk_window_set_child_shapes()
5473 * because it includes @window's shape mask in the set of shapes to
5477 gdk_window_merge_child_shapes (GdkWindow *window)
5479 g_return_if_fail (GDK_IS_WINDOW (window));
5481 #ifdef HAVE_SHAPE_EXT
5482 if (!GDK_WINDOW_DESTROYED (window) &&
5483 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
5484 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5485 GDK_WINDOW_XID (window), TRUE, ShapeBounding);
5490 * gdk_window_set_child_input_shapes:
5491 * @window: a #GdkWindow
5493 * Sets the input shape mask of @window to the union of input shape masks
5494 * for all children of @window, ignoring the input shape mask of @window
5495 * itself. Contrast with gdk_window_merge_child_input_shapes() which includes
5496 * the input shape mask of @window in the masks to be merged.
5501 gdk_window_set_child_input_shapes (GdkWindow *window)
5503 g_return_if_fail (GDK_IS_WINDOW (window));
5505 #ifdef HAVE_SHAPE_EXT
5507 if (!GDK_WINDOW_DESTROYED (window) &&
5508 gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
5509 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5510 GDK_WINDOW_XID (window), FALSE, ShapeInput);
5516 * gdk_window_merge_child_input_shapes:
5517 * @window: a #GdkWindow
5519 * Merges the input shape masks for any child windows into the
5520 * input shape mask for @window. i.e. the union of all input masks
5521 * for @window and its children will become the new input mask
5522 * for @window. See gdk_window_input_shape_combine_mask().
5524 * This function is distinct from gdk_window_set_child_input_shapes()
5525 * because it includes @window's input shape mask in the set of
5526 * shapes to be merged.
5531 gdk_window_merge_child_input_shapes (GdkWindow *window)
5533 g_return_if_fail (GDK_IS_WINDOW (window));
5535 #ifdef HAVE_SHAPE_EXT
5537 if (!GDK_WINDOW_DESTROYED (window) &&
5538 gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
5539 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
5540 GDK_WINDOW_XID (window), TRUE, ShapeInput);
5547 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
5549 XSetWindowAttributes xattributes;
5550 GdkWindowObject *private;
5551 guint xattributes_mask = 0;
5553 g_return_if_fail (GDK_IS_WINDOW (window));
5555 private = GDK_WINDOW_OBJECT (window);
5556 if (private->input_only)
5559 xattributes.bit_gravity = StaticGravity;
5560 xattributes_mask |= CWBitGravity;
5561 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
5562 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
5563 GDK_WINDOW_XID (window),
5564 CWBitGravity, &xattributes);
5568 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
5570 XSetWindowAttributes xattributes;
5572 g_return_if_fail (GDK_IS_WINDOW (window));
5574 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
5576 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
5577 GDK_WINDOW_XID (window),
5578 CWWinGravity, &xattributes);
5582 * gdk_window_set_static_gravities:
5583 * @window: a #GdkWindow
5584 * @use_static: %TRUE to turn on static gravity
5586 * Set the bit gravity of the given window to static, and flag it so
5587 * all children get static subwindow gravity. This is used if you are
5588 * implementing scary features that involve deep knowledge of the
5589 * windowing system. Don't worry about it unless you have to.
5591 * Return value: %TRUE if the server supports static gravity
5594 gdk_window_set_static_gravities (GdkWindow *window,
5595 gboolean use_static)
5597 GdkWindowObject *private = (GdkWindowObject *)window;
5600 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5602 if (!use_static == !private->guffaw_gravity)
5605 private->guffaw_gravity = use_static;
5607 if (!GDK_WINDOW_DESTROYED (window))
5609 gdk_window_set_static_bit_gravity (window, use_static);
5611 tmp_list = private->children;
5614 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
5616 tmp_list = tmp_list->next;
5624 wmspec_moveresize (GdkWindow *window,
5630 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
5634 /* Release passive grab */
5635 gdk_display_pointer_ungrab (display, timestamp);
5637 xev.xclient.type = ClientMessage;
5638 xev.xclient.serial = 0;
5639 xev.xclient.send_event = True;
5640 xev.xclient.window = GDK_WINDOW_XID (window);
5641 xev.xclient.message_type =
5642 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
5643 xev.xclient.format = 32;
5644 xev.xclient.data.l[0] = root_x;
5645 xev.xclient.data.l[1] = root_y;
5646 xev.xclient.data.l[2] = direction;
5647 xev.xclient.data.l[3] = 0;
5648 xev.xclient.data.l[4] = 0;
5650 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
5651 SubstructureRedirectMask | SubstructureNotifyMask,
5655 typedef struct _MoveResizeData MoveResizeData;
5657 struct _MoveResizeData
5659 GdkDisplay *display;
5661 GdkWindow *moveresize_window;
5662 GdkWindow *moveresize_emulation_window;
5664 GdkWindowEdge resize_edge;
5665 gint moveresize_button;
5668 gint moveresize_orig_x;
5669 gint moveresize_orig_y;
5670 gint moveresize_orig_width;
5671 gint moveresize_orig_height;
5672 GdkWindowHints moveresize_geom_mask;
5673 GdkGeometry moveresize_geometry;
5674 Time moveresize_process_time;
5675 XEvent *moveresize_pending_event;
5678 /* From the WM spec */
5679 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
5680 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
5681 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
5682 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
5683 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
5684 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
5685 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
5686 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
5687 #define _NET_WM_MOVERESIZE_MOVE 8
5690 wmspec_resize_drag (GdkWindow *window,
5699 /* Let the compiler turn a switch into a table, instead
5700 * of doing the table manually, this way is easier to verify.
5704 case GDK_WINDOW_EDGE_NORTH_WEST:
5705 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
5708 case GDK_WINDOW_EDGE_NORTH:
5709 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
5712 case GDK_WINDOW_EDGE_NORTH_EAST:
5713 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
5716 case GDK_WINDOW_EDGE_WEST:
5717 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
5720 case GDK_WINDOW_EDGE_EAST:
5721 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
5724 case GDK_WINDOW_EDGE_SOUTH_WEST:
5725 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
5728 case GDK_WINDOW_EDGE_SOUTH:
5729 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
5732 case GDK_WINDOW_EDGE_SOUTH_EAST:
5733 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
5737 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
5743 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
5746 static MoveResizeData *
5747 get_move_resize_data (GdkDisplay *display,
5750 MoveResizeData *mv_resize;
5751 static GQuark move_resize_quark = 0;
5753 if (!move_resize_quark)
5754 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
5756 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
5758 if (!mv_resize && create)
5760 mv_resize = g_new0 (MoveResizeData, 1);
5761 mv_resize->display = display;
5763 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
5770 update_pos (MoveResizeData *mv_resize,
5776 dx = new_root_x - mv_resize->moveresize_x;
5777 dy = new_root_y - mv_resize->moveresize_y;
5779 if (mv_resize->is_resize)
5783 x = mv_resize->moveresize_orig_x;
5784 y = mv_resize->moveresize_orig_y;
5786 w = mv_resize->moveresize_orig_width;
5787 h = mv_resize->moveresize_orig_height;
5789 switch (mv_resize->resize_edge)
5791 case GDK_WINDOW_EDGE_NORTH_WEST:
5797 case GDK_WINDOW_EDGE_NORTH:
5801 case GDK_WINDOW_EDGE_NORTH_EAST:
5806 case GDK_WINDOW_EDGE_SOUTH_WEST:
5811 case GDK_WINDOW_EDGE_SOUTH_EAST:
5815 case GDK_WINDOW_EDGE_SOUTH:
5818 case GDK_WINDOW_EDGE_EAST:
5821 case GDK_WINDOW_EDGE_WEST:
5832 if (mv_resize->moveresize_geom_mask)
5834 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
5835 mv_resize->moveresize_geom_mask,
5839 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
5845 x = mv_resize->moveresize_orig_x + dx;
5846 y = mv_resize->moveresize_orig_y + dy;
5848 gdk_window_move (mv_resize->moveresize_window, x, y);
5853 finish_drag (MoveResizeData *mv_resize)
5855 gdk_window_destroy (mv_resize->moveresize_emulation_window);
5856 mv_resize->moveresize_emulation_window = NULL;
5857 g_object_unref (mv_resize->moveresize_window);
5858 mv_resize->moveresize_window = NULL;
5860 if (mv_resize->moveresize_pending_event)
5862 g_free (mv_resize->moveresize_pending_event);
5863 mv_resize->moveresize_pending_event = NULL;
5868 lookahead_motion_predicate (Display *xdisplay,
5872 gboolean *seen_release = (gboolean *)arg;
5873 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
5874 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5879 switch (event->xany.type)
5882 *seen_release = TRUE;
5885 mv_resize->moveresize_process_time = event->xmotion.time;
5895 moveresize_lookahead (MoveResizeData *mv_resize,
5899 gboolean seen_release = FALSE;
5901 if (mv_resize->moveresize_process_time)
5903 if (event->xmotion.time == mv_resize->moveresize_process_time)
5905 mv_resize->moveresize_process_time = 0;
5912 XCheckIfEvent (event->xany.display, &tmp_event,
5913 lookahead_motion_predicate, (XPointer) & seen_release);
5915 return mv_resize->moveresize_process_time == 0;
5919 _gdk_moveresize_handle_event (XEvent *event)
5921 guint button_mask = 0;
5922 GdkWindowObject *window_private;
5923 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
5924 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5926 if (!mv_resize || !mv_resize->moveresize_window)
5929 window_private = (GdkWindowObject *) mv_resize->moveresize_window;
5931 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
5933 switch (event->xany.type)
5936 if (window_private->resize_count > 0)
5938 if (mv_resize->moveresize_pending_event)
5939 *mv_resize->moveresize_pending_event = *event;
5941 mv_resize->moveresize_pending_event =
5942 g_memdup (event, sizeof (XEvent));
5946 if (!moveresize_lookahead (mv_resize, event))
5949 update_pos (mv_resize,
5950 event->xmotion.x_root,
5951 event->xmotion.y_root);
5953 /* This should never be triggered in normal cases, but in the
5954 * case where the drag started without an implicit grab being
5955 * in effect, we could miss the release if it occurs before
5956 * we grab the pointer; this ensures that we will never
5957 * get a permanently stuck grab.
5959 if ((event->xmotion.state & button_mask) == 0)
5960 finish_drag (mv_resize);
5964 update_pos (mv_resize,
5965 event->xbutton.x_root,
5966 event->xbutton.y_root);
5968 if (event->xbutton.button == mv_resize->moveresize_button)
5969 finish_drag (mv_resize);
5976 _gdk_moveresize_configure_done (GdkDisplay *display,
5980 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
5982 if (!mv_resize || window != mv_resize->moveresize_window)
5985 if (mv_resize->moveresize_pending_event)
5987 tmp_event = mv_resize->moveresize_pending_event;
5988 mv_resize->moveresize_pending_event = NULL;
5989 _gdk_moveresize_handle_event (tmp_event);
5997 create_moveresize_window (MoveResizeData *mv_resize,
6000 GdkWindowAttr attributes;
6001 gint attributes_mask;
6002 GdkGrabStatus status;
6004 g_assert (mv_resize->moveresize_emulation_window == NULL);
6006 attributes.x = -100;
6007 attributes.y = -100;
6008 attributes.width = 10;
6009 attributes.height = 10;
6010 attributes.window_type = GDK_WINDOW_TEMP;
6011 attributes.wclass = GDK_INPUT_ONLY;
6012 attributes.override_redirect = TRUE;
6013 attributes.event_mask = 0;
6015 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
6017 mv_resize->moveresize_emulation_window =
6018 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
6022 gdk_window_show (mv_resize->moveresize_emulation_window);
6024 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
6026 GDK_BUTTON_RELEASE_MASK |
6027 GDK_POINTER_MOTION_MASK,
6032 if (status != GDK_GRAB_SUCCESS)
6034 /* If this fails, some other client has grabbed the window
6037 finish_drag (mv_resize);
6040 mv_resize->moveresize_process_time = 0;
6044 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
6045 so that calling XMoveWindow with these coordinates will not move the
6047 Note that this depends on the WM to implement ICCCM-compliant reference
6051 calculate_unmoving_origin (MoveResizeData *mv_resize)
6056 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
6057 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
6059 gdk_window_get_origin (mv_resize->moveresize_window,
6060 &mv_resize->moveresize_orig_x,
6061 &mv_resize->moveresize_orig_y);
6065 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
6066 gdk_window_get_geometry (mv_resize->moveresize_window,
6067 NULL, NULL, &width, &height, NULL);
6069 switch (mv_resize->moveresize_geometry.win_gravity)
6071 case GDK_GRAVITY_NORTH_WEST:
6072 mv_resize->moveresize_orig_x = rect.x;
6073 mv_resize->moveresize_orig_y = rect.y;
6075 case GDK_GRAVITY_NORTH:
6076 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
6077 mv_resize->moveresize_orig_y = rect.y;
6079 case GDK_GRAVITY_NORTH_EAST:
6080 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
6081 mv_resize->moveresize_orig_y = rect.y;
6083 case GDK_GRAVITY_WEST:
6084 mv_resize->moveresize_orig_x = rect.x;
6085 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
6087 case GDK_GRAVITY_CENTER:
6088 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
6089 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
6091 case GDK_GRAVITY_EAST:
6092 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
6093 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
6095 case GDK_GRAVITY_SOUTH_WEST:
6096 mv_resize->moveresize_orig_x = rect.x;
6097 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
6099 case GDK_GRAVITY_SOUTH:
6100 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
6101 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
6103 case GDK_GRAVITY_SOUTH_EAST:
6104 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
6105 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
6108 mv_resize->moveresize_orig_x = rect.x;
6109 mv_resize->moveresize_orig_y = rect.y;
6116 emulate_resize_drag (GdkWindow *window,
6123 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
6125 mv_resize->is_resize = TRUE;
6126 mv_resize->moveresize_button = button;
6127 mv_resize->resize_edge = edge;
6128 mv_resize->moveresize_x = root_x;
6129 mv_resize->moveresize_y = root_y;
6130 mv_resize->moveresize_window = g_object_ref (window);
6132 gdk_drawable_get_size (window,
6133 &mv_resize->moveresize_orig_width,
6134 &mv_resize->moveresize_orig_height);
6136 mv_resize->moveresize_geom_mask = 0;
6137 gdk_window_get_geometry_hints (window,
6138 &mv_resize->moveresize_geometry,
6139 &mv_resize->moveresize_geom_mask);
6141 calculate_unmoving_origin (mv_resize);
6143 create_moveresize_window (mv_resize, timestamp);
6147 emulate_move_drag (GdkWindow *window,
6153 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
6155 mv_resize->is_resize = FALSE;
6156 mv_resize->moveresize_button = button;
6157 mv_resize->moveresize_x = root_x;
6158 mv_resize->moveresize_y = root_y;
6160 mv_resize->moveresize_window = g_object_ref (window);
6162 calculate_unmoving_origin (mv_resize);
6164 create_moveresize_window (mv_resize, timestamp);
6168 * gdk_window_begin_resize_drag:
6169 * @window: a toplevel #GdkWindow
6170 * @edge: the edge or corner from which the drag is started
6171 * @button: the button being used to drag
6172 * @root_x: root window X coordinate of mouse click that began the drag
6173 * @root_y: root window Y coordinate of mouse click that began the drag
6174 * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
6176 * Begins a window resize operation (for a toplevel window).
6177 * You might use this function to implement a "window resize grip," for
6178 * example; in fact #GtkStatusbar uses it. The function works best
6179 * with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a
6180 * fallback implementation for other window managers.
6184 gdk_window_begin_resize_drag (GdkWindow *window,
6191 g_return_if_fail (GDK_IS_WINDOW (window));
6193 if (GDK_WINDOW_DESTROYED (window))
6196 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
6197 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
6198 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
6200 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
6204 * gdk_window_begin_move_drag:
6205 * @window: a toplevel #GdkWindow
6206 * @button: the button being used to drag
6207 * @root_x: root window X coordinate of mouse click that began the drag
6208 * @root_y: root window Y coordinate of mouse click that began the drag
6209 * @timestamp: timestamp of mouse click that began the drag
6211 * Begins a window move operation (for a toplevel window). You might
6212 * use this function to implement a "window move grip," for
6213 * example. The function works best with window managers that support
6214 * the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
6215 * Window Manager Hints</ulink>, but has a fallback implementation for
6216 * other window managers.
6220 gdk_window_begin_move_drag (GdkWindow *window,
6226 g_return_if_fail (GDK_IS_WINDOW (window));
6228 if (GDK_WINDOW_DESTROYED (window))
6231 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
6232 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
6233 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
6236 emulate_move_drag (window, button, root_x, root_y, timestamp);
6240 * gdk_window_enable_synchronized_configure:
6241 * @window: a toplevel #GdkWindow
6243 * Indicates that the application will cooperate with the window
6244 * system in synchronizing the window repaint with the window
6245 * manager during resizing operations. After an application calls
6246 * this function, it must call gdk_window_configure_finished() every
6247 * time it has finished all processing associated with a set of
6248 * Configure events. Toplevel GTK+ windows automatically use this
6251 * On X, calling this function makes @window participate in the
6252 * _NET_WM_SYNC_REQUEST window manager protocol.
6257 gdk_window_enable_synchronized_configure (GdkWindow *window)
6259 GdkWindowObject *private = (GdkWindowObject *)window;
6260 GdkWindowImplX11 *impl;
6262 g_return_if_fail (GDK_IS_WINDOW (window));
6264 impl = GDK_WINDOW_IMPL_X11 (private->impl);
6266 if (!impl->use_synchronized_configure)
6268 impl->use_synchronized_configure = TRUE;
6269 ensure_sync_counter (window);
6274 * gdk_window_configure_finished:
6275 * @window: a toplevel #GdkWindow
6277 * Signal to the window system that the application has finished
6278 * handling Configure events it has received. Window Managers can
6279 * use this to better synchronize the frame repaint with the
6280 * application. GTK+ applications will automatically call this
6281 * function when appropriate.
6283 * This function can only be called if gdk_window_enable_synchronized_configure()
6284 * was called previously.
6289 gdk_window_configure_finished (GdkWindow *window)
6291 GdkWindowImplX11 *impl;
6293 g_return_if_fail (GDK_IS_WINDOW (window));
6295 impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
6296 if (!impl->use_synchronized_configure)
6300 if (!GDK_WINDOW_DESTROYED (window))
6302 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
6303 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
6305 if (toplevel && toplevel->update_counter != None &&
6306 GDK_DISPLAY_X11 (display)->use_sync &&
6307 !XSyncValueIsZero (toplevel->current_counter_value))
6309 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
6310 toplevel->update_counter,
6311 toplevel->current_counter_value);
6313 XSyncIntToValue (&toplevel->current_counter_value, 0);
6321 * @window: a toplevel #GdkWindow
6323 * Emits a short beep associated to @window in the appropriate
6324 * display, if supported. Otherwise, emits a short beep on
6325 * the display just as gdk_display_beep().
6330 gdk_window_beep (GdkWindow *window)
6332 GdkDisplay *display;
6334 display = GDK_WINDOW_DISPLAY (window);
6337 if (GDK_DISPLAY_X11 (display)->use_xkb)
6338 XkbBell (GDK_DISPLAY_XDISPLAY (display),
6339 GDK_WINDOW_XID (window),
6344 gdk_display_beep (display);
6347 #define __GDK_WINDOW_X11_C__
6348 #include "gdkaliasdef.c"