1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
30 #include <netinet/in.h>
34 #include "gdkwindow.h"
35 #include "gdkinputprivate.h"
36 #include "gdkprivate-x11.h"
37 #include "gdkregion.h"
38 #include "gdkinternals.h"
40 #include "gdkwindow-x11.h"
48 #include <X11/extensions/shape.h>
51 const int gdk_event_mask_table[21] =
55 PointerMotionHintMask,
72 SubstructureNotifyMask,
73 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
75 const int gdk_nevent_masks = sizeof (gdk_event_mask_table) / sizeof (int);
77 /* Forward declarations */
78 static gboolean gdk_window_gravity_works (void);
79 static void gdk_window_set_static_win_gravity (GdkWindow *window,
81 static gboolean gdk_window_have_shape_ext (void);
82 static gboolean gdk_window_icon_name_set (GdkWindow *window);
84 static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable);
85 static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
87 static void gdk_window_impl_x11_get_size (GdkDrawable *drawable,
90 static GdkRegion* gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable);
91 static void gdk_window_impl_x11_init (GdkWindowImplX11 *window);
92 static void gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass);
93 static void gdk_window_impl_x11_finalize (GObject *object);
95 static gpointer parent_class = NULL;
98 gdk_window_impl_x11_get_type (void)
100 static GType object_type = 0;
104 static const GTypeInfo object_info =
106 sizeof (GdkWindowImplX11Class),
107 (GBaseInitFunc) NULL,
108 (GBaseFinalizeFunc) NULL,
109 (GClassInitFunc) gdk_window_impl_x11_class_init,
110 NULL, /* class_finalize */
111 NULL, /* class_data */
112 sizeof (GdkWindowImplX11),
114 (GInstanceInitFunc) gdk_window_impl_x11_init,
117 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
126 _gdk_window_impl_get_type (void)
128 return gdk_window_impl_x11_get_type ();
132 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
139 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
141 GObjectClass *object_class = G_OBJECT_CLASS (klass);
142 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
144 parent_class = g_type_class_peek_parent (klass);
146 object_class->finalize = gdk_window_impl_x11_finalize;
148 drawable_class->set_colormap = gdk_window_impl_x11_set_colormap;
149 drawable_class->get_colormap = gdk_window_impl_x11_get_colormap;
150 drawable_class->get_size = gdk_window_impl_x11_get_size;
152 /* Visible and clip regions are the same */
153 drawable_class->get_clip_region = gdk_window_impl_x11_get_visible_region;
154 drawable_class->get_visible_region = gdk_window_impl_x11_get_visible_region;
158 gdk_window_impl_x11_finalize (GObject *object)
160 GdkWindowObject *wrapper;
161 GdkDrawableImplX11 *draw_impl;
162 GdkWindowImplX11 *window_impl;
164 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
166 draw_impl = GDK_DRAWABLE_IMPL_X11 (object);
167 window_impl = GDK_WINDOW_IMPL_X11 (object);
169 wrapper = (GdkWindowObject*) draw_impl->wrapper;
171 if (!GDK_WINDOW_DESTROYED (wrapper))
173 gdk_xid_table_remove (draw_impl->xid);
174 if (window_impl->focus_window)
175 gdk_xid_table_remove (window_impl->focus_window);
178 G_OBJECT_CLASS (parent_class)->finalize (object);
182 gdk_window_impl_x11_get_colormap (GdkDrawable *drawable)
184 GdkDrawableImplX11 *drawable_impl;
185 GdkWindowImplX11 *window_impl;
187 g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL);
189 drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
190 window_impl = GDK_WINDOW_IMPL_X11 (drawable);
192 if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only &&
193 drawable_impl->colormap == NULL)
195 XWindowAttributes window_attributes;
197 XGetWindowAttributes (drawable_impl->xdisplay,
200 drawable_impl->colormap =
201 gdk_colormap_lookup (window_attributes.colormap);
204 return drawable_impl->colormap;
208 gdk_window_impl_x11_set_colormap (GdkDrawable *drawable,
211 GdkWindowImplX11 *impl;
212 GdkDrawableImplX11 *draw_impl;
214 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
216 impl = GDK_WINDOW_IMPL_X11 (drawable);
217 draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable);
220 GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, cmap);
224 XSetWindowColormap (draw_impl->xdisplay,
226 GDK_COLORMAP_XCOLORMAP (cmap));
228 if (((GdkWindowObject*)draw_impl->wrapper)->window_type !=
230 gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper));
236 gdk_window_impl_x11_get_size (GdkDrawable *drawable,
240 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable));
243 *width = GDK_WINDOW_IMPL_X11 (drawable)->width;
245 *height = GDK_WINDOW_IMPL_X11 (drawable)->height;
249 gdk_window_impl_x11_get_visible_region (GdkDrawable *drawable)
251 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (drawable);
252 GdkRectangle result_rect;
256 result_rect.width = impl->width;
257 result_rect.height = impl->height;
259 gdk_rectangle_intersect (&result_rect, &impl->position_info.clip_rect, &result_rect);
261 return gdk_region_rectangle (&result_rect);
265 _gdk_windowing_window_init (void)
267 GdkWindowObject *private;
268 GdkWindowImplX11 *impl;
269 GdkDrawableImplX11 *draw_impl;
270 XWindowAttributes xattributes;
273 unsigned int border_width;
277 g_assert (gdk_parent_root == NULL);
279 XGetGeometry (gdk_display, gdk_root_window, &gdk_root_window,
280 &x, &y, &width, &height, &border_width, &depth);
281 XGetWindowAttributes (gdk_display, gdk_root_window, &xattributes);
283 gdk_parent_root = g_object_new (GDK_TYPE_WINDOW, NULL);
284 private = (GdkWindowObject *)gdk_parent_root;
285 impl = GDK_WINDOW_IMPL_X11 (private->impl);
286 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
288 draw_impl->xdisplay = gdk_display;
289 draw_impl->xid = gdk_root_window;
290 draw_impl->wrapper = GDK_DRAWABLE (private);
292 private->window_type = GDK_WINDOW_ROOT;
293 private->depth = depth;
295 impl->height = height;
297 gdk_xid_table_insert (&gdk_root_window, gdk_parent_root);
300 static GdkAtom wm_client_leader_atom = GDK_NONE;
303 gdk_window_new (GdkWindow *parent,
304 GdkWindowAttr *attributes,
305 gint attributes_mask)
308 GdkWindowObject *private;
309 GdkWindowObject *parent_private;
310 GdkWindowImplX11 *impl;
311 GdkDrawableImplX11 *draw_impl;
319 XSetWindowAttributes xattributes;
320 long xattributes_mask;
321 XSizeHints size_hints;
323 XClassHint *class_hint;
330 g_return_val_if_fail (attributes != NULL, NULL);
333 parent = gdk_parent_root;
335 g_return_val_if_fail (GDK_IS_WINDOW (parent), NULL);
337 parent_private = (GdkWindowObject*) parent;
338 if (GDK_WINDOW_DESTROYED (parent))
341 xparent = GDK_WINDOW_XID (parent);
343 window = g_object_new (GDK_TYPE_WINDOW, NULL);
344 private = (GdkWindowObject *)window;
345 impl = GDK_WINDOW_IMPL_X11 (private->impl);
346 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
347 draw_impl->wrapper = GDK_DRAWABLE (window);
349 xdisplay = draw_impl->xdisplay = GDK_WINDOW_XDISPLAY (parent);
351 private->parent = (GdkWindowObject *)parent;
353 xattributes_mask = 0;
355 if (attributes_mask & GDK_WA_X)
360 if (attributes_mask & GDK_WA_Y)
367 impl->width = (attributes->width > 1) ? (attributes->width) : (1);
368 impl->height = (attributes->height > 1) ? (attributes->height) : (1);
369 private->window_type = attributes->window_type;
371 _gdk_window_init_position (GDK_WINDOW (private));
372 if (impl->position_info.big)
373 private->guffaw_gravity = TRUE;
375 if (attributes_mask & GDK_WA_VISUAL)
376 visual = attributes->visual;
378 visual = gdk_visual_get_system ();
379 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
381 xattributes.event_mask = StructureNotifyMask;
382 for (i = 0; i < gdk_nevent_masks; i++)
384 if (attributes->event_mask & (1 << (i + 1)))
385 xattributes.event_mask |= gdk_event_mask_table[i];
388 if (xattributes.event_mask)
389 xattributes_mask |= CWEventMask;
391 if (attributes_mask & GDK_WA_NOREDIR)
393 xattributes.override_redirect =
394 (attributes->override_redirect == FALSE)?False:True;
395 xattributes_mask |= CWOverrideRedirect;
398 xattributes.override_redirect = False;
400 if (parent_private && parent_private->guffaw_gravity)
402 xattributes.win_gravity = StaticGravity;
403 xattributes_mask |= CWWinGravity;
406 if (attributes->wclass == GDK_INPUT_OUTPUT)
409 depth = visual->depth;
411 private->input_only = FALSE;
412 private->depth = depth;
414 if (attributes_mask & GDK_WA_COLORMAP)
416 draw_impl->colormap = attributes->colormap;
417 gdk_colormap_ref (attributes->colormap);
421 if ((((GdkVisualPrivate*)gdk_visual_get_system ())->xvisual) == xvisual)
423 draw_impl->colormap =
424 gdk_colormap_get_system ();
425 gdk_colormap_ref (draw_impl->colormap);
429 draw_impl->colormap =
430 gdk_colormap_new (visual, FALSE);
434 private->bg_color.pixel = BlackPixel (gdk_display, gdk_screen);
435 xattributes.background_pixel = private->bg_color.pixel;
437 private->bg_pixmap = NULL;
439 xattributes.border_pixel = BlackPixel (gdk_display, gdk_screen);
440 xattributes_mask |= CWBorderPixel | CWBackPixel;
442 if (private->guffaw_gravity)
443 xattributes.bit_gravity = StaticGravity;
445 xattributes.bit_gravity = NorthWestGravity;
447 xattributes_mask |= CWBitGravity;
449 switch (private->window_type)
451 case GDK_WINDOW_TOPLEVEL:
452 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
453 xattributes_mask |= CWColormap;
455 xparent = gdk_root_window;
458 case GDK_WINDOW_CHILD:
459 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
460 xattributes_mask |= CWColormap;
463 case GDK_WINDOW_DIALOG:
464 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
465 xattributes_mask |= CWColormap;
467 xparent = gdk_root_window;
470 case GDK_WINDOW_TEMP:
471 xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
472 xattributes_mask |= CWColormap;
474 xparent = gdk_root_window;
476 xattributes.save_under = True;
477 xattributes.override_redirect = True;
478 xattributes.cursor = None;
479 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
481 case GDK_WINDOW_ROOT:
482 g_error ("cannot make windows of type GDK_WINDOW_ROOT");
491 private->input_only = TRUE;
492 draw_impl->colormap = gdk_colormap_get_system ();
493 gdk_colormap_ref (draw_impl->colormap);
496 xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
497 impl->position_info.x, impl->position_info.y,
498 impl->position_info.width, impl->position_info.height,
499 0, depth, class, xvisual,
500 xattributes_mask, &xattributes);
502 gdk_drawable_ref (window);
503 gdk_xid_table_insert (&draw_impl->xid, window);
505 gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
506 (attributes->cursor) :
510 parent_private->children = g_list_prepend (parent_private->children, window);
512 switch (GDK_WINDOW_TYPE (private))
514 case GDK_WINDOW_DIALOG:
515 XSetTransientForHint (xdisplay, xid, xparent);
516 case GDK_WINDOW_TOPLEVEL:
517 case GDK_WINDOW_TEMP:
518 XSetWMProtocols (xdisplay, xid,
519 gdk_wm_window_protocols, 3);
521 case GDK_WINDOW_CHILD:
522 if ((attributes->wclass == GDK_INPUT_OUTPUT) &&
523 (draw_impl->colormap != gdk_colormap_get_system ()) &&
524 (draw_impl->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window))))
526 GDK_NOTE (MISC, g_message ("adding colormap window\n"));
527 gdk_window_add_colormap_windows (window);
536 if (class != InputOnly)
538 /* The focus window is off the visible area, and serves to receive key
539 * press events so they don't get sent to child windows.
541 impl->focus_window = XCreateSimpleWindow (xdisplay, xid,
543 xattributes.background_pixel,
544 xattributes.background_pixel);
545 /* FIXME: probably better to actually track the requested event mask for the toplevel
547 XSelectInput (xdisplay, impl->focus_window,
548 KeyPressMask | KeyReleaseMask | FocusChangeMask);
550 XMapWindow (xdisplay, impl->focus_window);
551 gdk_xid_table_insert (&impl->focus_window, window);
554 size_hints.flags = PSize;
555 size_hints.width = impl->width;
556 size_hints.height = impl->height;
558 wm_hints.flags = StateHint | WindowGroupHint;
559 wm_hints.window_group = gdk_leader_window;
560 wm_hints.input = True;
561 wm_hints.initial_state = NormalState;
563 /* FIXME: Is there any point in doing this? Do any WM's pay
564 * attention to PSize, and even if they do, is this the
567 XSetWMNormalHints (xdisplay, xid, &size_hints);
569 XSetWMHints (xdisplay, xid, &wm_hints);
571 if (!wm_client_leader_atom)
572 wm_client_leader_atom = gdk_atom_intern ("WM_CLIENT_LEADER", FALSE);
574 XChangeProperty (xdisplay, xid,
575 wm_client_leader_atom,
576 XA_WINDOW, 32, PropModeReplace,
577 (guchar*) &gdk_leader_window, 1);
579 if (attributes_mask & GDK_WA_TITLE)
580 title = attributes->title;
582 title = g_get_prgname ();
584 gdk_window_set_title (window, title);
586 if (attributes_mask & GDK_WA_WMCLASS)
588 class_hint = XAllocClassHint ();
589 class_hint->res_name = attributes->wmclass_name;
590 class_hint->res_class = attributes->wmclass_class;
591 XSetClassHint (xdisplay, xid, class_hint);
599 gdk_window_foreign_new (GdkNativeWindow anid)
602 GdkWindowObject *private;
603 GdkWindowObject *parent_private;
604 GdkWindowImplX11 *impl;
605 GdkDrawableImplX11 *draw_impl;
606 XWindowAttributes attrs;
608 Window *children = NULL;
612 gdk_error_trap_push ();
613 result = XGetWindowAttributes (gdk_display, anid, &attrs);
614 if (gdk_error_trap_pop () || !result)
617 /* FIXME: This is pretty expensive. Maybe the caller should supply
619 gdk_error_trap_push ();
620 result = XQueryTree (gdk_display, anid, &root, &parent, &children, &nchildren);
621 if (gdk_error_trap_pop () || !result)
627 window = g_object_new (GDK_TYPE_WINDOW, NULL);
628 private = (GdkWindowObject *)window;
629 impl = GDK_WINDOW_IMPL_X11 (private->impl);
630 draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
631 draw_impl->wrapper = GDK_DRAWABLE (window);
633 private->parent = gdk_xid_table_lookup (parent);
635 parent_private = (GdkWindowObject *)private->parent;
638 parent_private->children = g_list_prepend (parent_private->children, window);
640 draw_impl->xid = anid;
641 draw_impl->xdisplay = gdk_display;
643 private->x = attrs.x;
644 private->y = attrs.y;
645 impl->width = attrs.width;
646 impl->height = attrs.height;
647 private->window_type = GDK_WINDOW_FOREIGN;
648 private->destroyed = FALSE;
650 if (attrs.map_state == IsUnmapped)
651 private->state = GDK_WINDOW_STATE_WITHDRAWN;
655 private->depth = attrs.depth;
657 _gdk_window_init_position (GDK_WINDOW (private));
659 gdk_drawable_ref (window);
660 gdk_xid_table_insert (&GDK_WINDOW_XID (window), window);
666 _gdk_windowing_window_destroy (GdkWindow *window,
668 gboolean foreign_destroy)
670 GdkWindowObject *private = (GdkWindowObject *)window;
672 g_return_if_fail (GDK_IS_WINDOW (window));
674 _gdk_selection_window_destroyed (window);
676 if (private->extension_events != 0)
677 gdk_input_window_destroy (window);
679 if (private->window_type == GDK_WINDOW_FOREIGN)
681 if (!foreign_destroy && (private->parent != NULL))
683 /* It's somebody else's window, but in our heirarchy,
684 * so reparent it to the root window, and then send
685 * it a delete event, as if we were a WM
687 XClientMessageEvent xevent;
689 gdk_error_trap_push ();
690 gdk_window_hide (window);
691 gdk_window_reparent (window, NULL, 0, 0);
693 xevent.type = ClientMessage;
694 xevent.window = GDK_WINDOW_XID (window);
695 xevent.message_type = gdk_wm_protocols;
697 xevent.data.l[0] = gdk_wm_delete_window;
698 xevent.data.l[1] = CurrentTime;
700 XSendEvent (GDK_WINDOW_XDISPLAY (window),
701 GDK_WINDOW_XID (window),
702 False, 0, (XEvent *)&xevent);
704 gdk_error_trap_pop ();
707 else if (!recursing && !foreign_destroy)
708 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
711 /* This function is called when the XWindow is really gone.
714 gdk_window_destroy_notify (GdkWindow *window)
716 GdkWindowImplX11 *window_impl;
718 g_return_if_fail (window != NULL);
720 window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl);
722 if (!GDK_WINDOW_DESTROYED (window))
724 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
725 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
727 _gdk_window_destroy (window, TRUE);
730 gdk_xid_table_remove (GDK_WINDOW_XID (window));
731 if (window_impl->focus_window)
732 gdk_xid_table_remove (window_impl->focus_window);
734 gdk_drawable_unref (window);
738 set_initial_hints (GdkWindow *window)
740 GdkWindowObject *private;
744 private = (GdkWindowObject*) window;
746 if (private->state & GDK_WINDOW_STATE_ICONIFIED)
750 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
751 GDK_WINDOW_XID (window));
753 wm_hints = XAllocWMHints ();
755 wm_hints->flags |= StateHint;
756 wm_hints->initial_state = IconicState;
758 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
759 GDK_WINDOW_XID (window), wm_hints);
763 /* We set the spec hints regardless of whether the spec is supported,
764 * since it can't hurt and it's kind of expensive to check whether
770 if (private->state & GDK_WINDOW_STATE_MAXIMIZED)
772 atoms[i] = gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE);
774 atoms[i] = gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE);
778 if (private->state & GDK_WINDOW_STATE_STICKY)
780 atoms[i] = gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE);
784 if (private->modal_hint)
786 atoms[i] = gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE);
792 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
793 GDK_WINDOW_XID (window),
794 gdk_atom_intern ("_NET_WM_STATE", FALSE),
795 XA_ATOM, 32, PropModeReplace,
799 if (private->state & GDK_WINDOW_STATE_STICKY)
801 atoms[0] = 0xFFFFFFFF;
802 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
803 GDK_WINDOW_XID (window),
804 gdk_atom_intern ("_NET_WM_DESKTOP", FALSE),
805 XA_CARDINAL, 32, PropModeReplace,
811 show_window_internal (GdkWindow *window,
814 GdkWindowObject *private;
816 g_return_if_fail (GDK_IS_WINDOW (window));
818 private = (GdkWindowObject*) window;
819 if (!private->destroyed)
822 XRaiseWindow (GDK_WINDOW_XDISPLAY (window),
823 GDK_WINDOW_XID (window));
825 if (!GDK_WINDOW_IS_MAPPED (window))
827 set_initial_hints (window);
829 gdk_synthesize_window_state (window,
830 GDK_WINDOW_STATE_WITHDRAWN,
834 g_assert (GDK_WINDOW_IS_MAPPED (window));
836 if (GDK_WINDOW_IMPL_X11 (private->impl)->position_info.mapped)
837 XMapWindow (GDK_WINDOW_XDISPLAY (window),
838 GDK_WINDOW_XID (window));
843 * gdk_window_show_unraised:
844 * @window: a #GdkWindow
846 * Shows a #GdkWindow onscreen, but does not modify its stacking
847 * order. In contrast, gdk_window_show() will raise the window
848 * to the top of the window stack.
852 gdk_window_show_unraised (GdkWindow *window)
854 g_return_if_fail (GDK_IS_WINDOW (window));
856 show_window_internal (window, FALSE);
860 gdk_window_show (GdkWindow *window)
862 g_return_if_fail (GDK_IS_WINDOW (window));
864 show_window_internal (window, TRUE);
868 gdk_window_hide (GdkWindow *window)
870 GdkWindowObject *private;
872 g_return_if_fail (window != NULL);
874 private = (GdkWindowObject*) window;
876 /* You can't simply unmap toplevel windows. */
877 switch (private->window_type)
879 case GDK_WINDOW_TOPLEVEL:
880 case GDK_WINDOW_DIALOG:
881 case GDK_WINDOW_TEMP: /* ? */
882 gdk_window_withdraw (window);
886 case GDK_WINDOW_FOREIGN:
887 case GDK_WINDOW_ROOT:
888 case GDK_WINDOW_CHILD:
892 if (!private->destroyed)
894 if (GDK_WINDOW_IS_MAPPED (window))
895 gdk_synthesize_window_state (window,
897 GDK_WINDOW_STATE_WITHDRAWN);
899 g_assert (!GDK_WINDOW_IS_MAPPED (window));
901 _gdk_window_clear_update_area (window);
903 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
904 GDK_WINDOW_XID (window));
909 gdk_window_withdraw (GdkWindow *window)
911 GdkWindowObject *private;
913 g_return_if_fail (window != NULL);
915 private = (GdkWindowObject*) window;
916 if (!private->destroyed)
918 if (GDK_WINDOW_IS_MAPPED (window))
919 gdk_synthesize_window_state (window,
921 GDK_WINDOW_STATE_WITHDRAWN);
923 g_assert (!GDK_WINDOW_IS_MAPPED (window));
925 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
926 GDK_WINDOW_XID (window), 0);
931 gdk_window_move (GdkWindow *window,
935 GdkWindowObject *private = (GdkWindowObject *)window;
936 GdkWindowImplX11 *impl;
938 g_return_if_fail (window != NULL);
939 g_return_if_fail (GDK_IS_WINDOW (window));
941 impl = GDK_WINDOW_IMPL_X11 (private->impl);
943 if (!GDK_WINDOW_DESTROYED (window))
945 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
946 _gdk_window_move_resize_child (window, x, y,
947 impl->width, impl->height);
950 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
951 GDK_WINDOW_XID (window),
958 gdk_window_resize (GdkWindow *window,
962 GdkWindowObject *private;
964 g_return_if_fail (window != NULL);
965 g_return_if_fail (GDK_IS_WINDOW (window));
972 private = (GdkWindowObject*) window;
974 if (!GDK_WINDOW_DESTROYED (window))
976 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
977 _gdk_window_move_resize_child (window, private->x, private->y,
981 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
983 if (width != impl->width || height != impl->height)
984 private->resize_count += 1;
986 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
987 GDK_WINDOW_XID (window),
994 gdk_window_move_resize (GdkWindow *window,
1000 GdkWindowObject *private;
1002 g_return_if_fail (window != NULL);
1003 g_return_if_fail (GDK_IS_WINDOW (window));
1010 private = (GdkWindowObject*) window;
1012 if (!GDK_WINDOW_DESTROYED (window))
1014 if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD)
1015 _gdk_window_move_resize_child (window, x, y, width, height);
1018 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl);
1020 if (width != impl->width || height != impl->height)
1021 private->resize_count += 1;
1023 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1024 GDK_WINDOW_XID (window),
1025 x, y, width, height);
1031 gdk_window_reparent (GdkWindow *window,
1032 GdkWindow *new_parent,
1036 GdkWindowObject *window_private;
1037 GdkWindowObject *parent_private;
1038 GdkWindowObject *old_parent_private;
1040 g_return_if_fail (window != NULL);
1041 g_return_if_fail (GDK_IS_WINDOW (window));
1042 g_return_if_fail (new_parent == NULL || GDK_IS_WINDOW (new_parent));
1045 new_parent = gdk_parent_root;
1047 window_private = (GdkWindowObject*) window;
1048 old_parent_private = (GdkWindowObject*)window_private->parent;
1049 parent_private = (GdkWindowObject*) new_parent;
1051 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (new_parent))
1052 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1053 GDK_WINDOW_XID (window),
1054 GDK_WINDOW_XID (new_parent),
1057 window_private->parent = (GdkWindowObject *)new_parent;
1059 if (old_parent_private)
1060 old_parent_private->children = g_list_remove (old_parent_private->children, window);
1062 if ((old_parent_private &&
1063 (!old_parent_private->guffaw_gravity != !parent_private->guffaw_gravity)) ||
1064 (!old_parent_private && parent_private->guffaw_gravity))
1065 gdk_window_set_static_win_gravity (window, parent_private->guffaw_gravity);
1067 parent_private->children = g_list_prepend (parent_private->children, window);
1068 _gdk_window_init_position (GDK_WINDOW (window_private));
1072 _gdk_windowing_window_clear_area (GdkWindow *window,
1078 g_return_if_fail (window != NULL);
1079 g_return_if_fail (GDK_IS_WINDOW (window));
1081 if (!GDK_WINDOW_DESTROYED (window))
1082 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1083 x, y, width, height, False);
1087 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1093 g_return_if_fail (window != NULL);
1094 g_return_if_fail (GDK_IS_WINDOW (window));
1096 if (!GDK_WINDOW_DESTROYED (window))
1097 XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1098 x, y, width, height, True);
1102 gdk_window_raise (GdkWindow *window)
1104 g_return_if_fail (window != NULL);
1105 g_return_if_fail (GDK_IS_WINDOW (window));
1107 if (!GDK_WINDOW_DESTROYED (window))
1108 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1112 gdk_window_lower (GdkWindow *window)
1114 g_return_if_fail (window != NULL);
1115 g_return_if_fail (GDK_IS_WINDOW (window));
1117 if (!GDK_WINDOW_DESTROYED (window))
1118 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1122 gdk_window_focus (GdkWindow *window,
1125 g_return_if_fail (GDK_IS_WINDOW (window));
1127 if (GDK_WINDOW_DESTROYED (window))
1130 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
1134 xev.xclient.type = ClientMessage;
1135 xev.xclient.serial = 0;
1136 xev.xclient.send_event = True;
1137 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
1138 xev.xclient.display = gdk_display;
1139 xev.xclient.message_type = gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE);
1140 xev.xclient.format = 32;
1141 xev.xclient.data.l[0] = 0;
1143 XSendEvent (gdk_display, gdk_root_window, False,
1144 SubstructureRedirectMask | SubstructureNotifyMask,
1149 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1151 /* There is no way of knowing reliably whether we are viewable so we need
1152 * to trap errors so we don't cause a BadMatch.
1154 gdk_error_trap_push ();
1155 XSetInputFocus (GDK_WINDOW_XDISPLAY (window),
1156 GDK_WINDOW_XWINDOW (window),
1159 XSync (GDK_WINDOW_XDISPLAY (window), False);
1160 gdk_error_trap_pop ();
1165 gdk_window_set_hints (GdkWindow *window,
1174 XSizeHints size_hints;
1176 g_return_if_fail (window != NULL);
1177 g_return_if_fail (GDK_IS_WINDOW (window));
1179 if (GDK_WINDOW_DESTROYED (window))
1182 size_hints.flags = 0;
1184 if (flags & GDK_HINT_POS)
1186 size_hints.flags |= PPosition;
1191 if (flags & GDK_HINT_MIN_SIZE)
1193 size_hints.flags |= PMinSize;
1194 size_hints.min_width = min_width;
1195 size_hints.min_height = min_height;
1198 if (flags & GDK_HINT_MAX_SIZE)
1200 size_hints.flags |= PMaxSize;
1201 size_hints.max_width = max_width;
1202 size_hints.max_height = max_height;
1205 /* FIXME: Would it be better to delete this property if
1206 * flags == 0? It would save space on the server
1208 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1209 GDK_WINDOW_XID (window),
1214 * gdk_window_set_type_hint:
1215 * @window: A #GdkWindow
1216 * @hint: A hint of the function this window will have
1218 * The application can use this call to provide a hint to the window
1219 * manager about the functionality of a window. The window manager
1220 * can use this information when determining the decoration and behaviour
1223 * The hint must be set before the window is mapped.
1226 gdk_window_set_type_hint (GdkWindow *window,
1227 GdkWindowTypeHint hint)
1231 g_return_if_fail (window != NULL);
1232 g_return_if_fail (GDK_IS_WINDOW (window));
1234 if (GDK_WINDOW_DESTROYED (window))
1239 case GDK_WINDOW_TYPE_HINT_DIALOG:
1240 atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_DIALOG", FALSE);
1242 case GDK_WINDOW_TYPE_HINT_MENU:
1243 atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_MENU", FALSE);
1245 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1246 atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_TOOLBAR", FALSE);
1249 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1251 case GDK_WINDOW_TYPE_HINT_NORMAL:
1252 atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_NORMAL", FALSE);
1256 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1257 GDK_WINDOW_XID (window),
1258 gdk_atom_intern ("_NET_WM_WINDOW_TYPE", FALSE),
1259 XA_ATOM, 32, PropModeReplace,
1260 (guchar *)&atom, 1);
1265 gdk_wmspec_change_state (gboolean add,
1274 op = gdk_atom_intern ("_NET_WM_STATE_ADD", FALSE);
1276 op = gdk_atom_intern ("_NET_WM_STATE_REMOVE", FALSE);
1278 xev.xclient.type = ClientMessage;
1279 xev.xclient.serial = 0;
1280 xev.xclient.send_event = True;
1281 xev.xclient.display = gdk_display;
1282 xev.xclient.window = GDK_WINDOW_XID (window);
1283 xev.xclient.message_type = gdk_atom_intern ("_NET_WM_STATE", FALSE);
1284 xev.xclient.format = 32;
1285 xev.xclient.data.l[0] = op;
1286 xev.xclient.data.l[1] = state1;
1287 xev.xclient.data.l[2] = state2;
1289 XSendEvent (gdk_display, gdk_root_window, False,
1290 SubstructureRedirectMask | SubstructureNotifyMask,
1294 * gdk_window_set_modal_hint:
1295 * @window: A #GdkWindow
1296 * @modal: TRUE if the window is modal, FALSE otherwise.
1298 * The application can use this hint to tell the window manager
1299 * that a certain window has modal behaviour. The window manager
1300 * can use this information to handle modal windows in a special
1303 * You should only use this on windows for which you have
1304 * previously called #gdk_window_set_transient_for()
1307 gdk_window_set_modal_hint (GdkWindow *window,
1310 GdkWindowObject *private;
1312 g_return_if_fail (window != NULL);
1313 g_return_if_fail (GDK_IS_WINDOW (window));
1315 if (GDK_WINDOW_DESTROYED (window))
1318 private = (GdkWindowObject*) window;
1320 private->modal_hint = modal;
1322 if (GDK_WINDOW_IS_MAPPED (window))
1323 gdk_wmspec_change_state (modal, window,
1324 gdk_atom_intern ("_NET_WM_STATE_MODAL", FALSE),
1329 gdk_window_set_geometry_hints (GdkWindow *window,
1330 GdkGeometry *geometry,
1331 GdkWindowHints geom_mask)
1333 XSizeHints size_hints;
1335 g_return_if_fail (window != NULL);
1336 g_return_if_fail (GDK_IS_WINDOW (window));
1338 if (GDK_WINDOW_DESTROYED (window))
1341 size_hints.flags = 0;
1343 if (geom_mask & GDK_HINT_POS)
1345 size_hints.flags |= PPosition;
1346 /* We need to initialize the following obsolete fields because KWM
1347 * apparently uses these fields if they are non-zero.
1354 if (geom_mask & GDK_HINT_MIN_SIZE)
1356 size_hints.flags |= PMinSize;
1357 size_hints.min_width = geometry->min_width;
1358 size_hints.min_height = geometry->min_height;
1361 if (geom_mask & GDK_HINT_MAX_SIZE)
1363 size_hints.flags |= PMaxSize;
1364 size_hints.max_width = MAX (geometry->max_width, 1);
1365 size_hints.max_height = MAX (geometry->max_height, 1);
1368 if (geom_mask & GDK_HINT_BASE_SIZE)
1370 size_hints.flags |= PBaseSize;
1371 size_hints.base_width = geometry->base_width;
1372 size_hints.base_height = geometry->base_height;
1375 if (geom_mask & GDK_HINT_RESIZE_INC)
1377 size_hints.flags |= PResizeInc;
1378 size_hints.width_inc = geometry->width_inc;
1379 size_hints.height_inc = geometry->height_inc;
1382 if (geom_mask & GDK_HINT_ASPECT)
1384 size_hints.flags |= PAspect;
1385 if (geometry->min_aspect <= 1)
1387 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
1388 size_hints.min_aspect.y = 65536;
1392 size_hints.min_aspect.x = 65536;
1393 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
1395 if (geometry->max_aspect <= 1)
1397 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
1398 size_hints.max_aspect.y = 65536;
1402 size_hints.max_aspect.x = 65536;
1403 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
1407 if (geom_mask & GDK_HINT_WIN_GRAVITY)
1409 size_hints.flags |= PWinGravity;
1410 size_hints.win_gravity = geometry->win_gravity;
1413 /* FIXME: Would it be better to delete this property if
1414 * geom_mask == 0? It would save space on the server
1416 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1417 GDK_WINDOW_XID (window),
1422 gdk_window_get_geometry_hints (GdkWindow *window,
1423 GdkGeometry *geometry,
1424 GdkWindowHints *geom_mask)
1426 XSizeHints size_hints;
1427 glong junk_size_mask = 0;
1429 g_return_if_fail (GDK_IS_WINDOW (window));
1430 g_return_if_fail (geometry != NULL);
1431 g_return_if_fail (geom_mask != NULL);
1435 if (GDK_WINDOW_DESTROYED (window))
1438 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
1439 GDK_WINDOW_XID (window),
1444 if (size_hints.flags & PMinSize)
1446 *geom_mask |= GDK_HINT_MIN_SIZE;
1447 geometry->min_width = size_hints.min_width;
1448 geometry->min_height = size_hints.min_height;
1451 if (size_hints.flags & PMaxSize)
1453 *geom_mask |= GDK_HINT_MAX_SIZE;
1454 geometry->max_width = MAX (size_hints.max_width, 1);
1455 geometry->max_height = MAX (size_hints.max_height, 1);
1458 if (size_hints.flags & PResizeInc)
1460 *geom_mask |= GDK_HINT_RESIZE_INC;
1461 geometry->width_inc = size_hints.width_inc;
1462 geometry->height_inc = size_hints.height_inc;
1465 if (size_hints.flags & PAspect)
1467 *geom_mask |= GDK_HINT_ASPECT;
1469 geometry->min_aspect = (gdouble) size_hints.min_aspect.x / (gdouble) size_hints.min_aspect.y;
1470 geometry->max_aspect = (gdouble) size_hints.max_aspect.x / (gdouble) size_hints.max_aspect.y;
1473 if (size_hints.flags & PWinGravity)
1475 *geom_mask |= GDK_HINT_WIN_GRAVITY;
1476 geometry->win_gravity = size_hints.win_gravity;
1481 utf8_is_latin1 (const gchar *str)
1483 const char *p = str;
1487 gunichar ch = g_utf8_get_char (p);
1492 p = g_utf8_next_char (p);
1498 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
1499 * convertable to STRING, otherwise, set it as compound text
1502 set_text_property (GdkWindow *window,
1504 const gchar *utf8_str)
1506 guchar *prop_text = NULL;
1511 if (utf8_is_latin1 (utf8_str))
1513 prop_type = GDK_TARGET_STRING;
1514 prop_text = gdk_utf8_to_string_target (utf8_str);
1515 prop_length = strlen (prop_text);
1520 gdk_utf8_to_compound_text (utf8_str, &prop_type, &prop_format,
1521 &prop_text, &prop_length);
1526 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1527 GDK_WINDOW_XID (window),
1529 prop_type, prop_format,
1530 PropModeReplace, prop_text,
1538 gdk_window_set_title (GdkWindow *window,
1541 g_return_if_fail (window != NULL);
1542 g_return_if_fail (GDK_IS_WINDOW (window));
1544 if (GDK_WINDOW_DESTROYED (window))
1547 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1548 GDK_WINDOW_XID (window),
1549 gdk_atom_intern ("_NET_WM_NAME", FALSE),
1550 gdk_atom_intern ("UTF8_STRING", FALSE), 8,
1551 PropModeReplace, title,
1554 set_text_property (window, gdk_atom_intern ("WM_NAME", FALSE), title);
1555 if (!gdk_window_icon_name_set (window))
1557 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
1558 GDK_WINDOW_XID (window),
1559 gdk_atom_intern ("_NET_WM_ICON_NAME", FALSE),
1560 gdk_atom_intern ("UTF8_STRING", FALSE), 8,
1561 PropModeReplace, title,
1563 set_text_property (window, gdk_atom_intern ("WM_ICON_NAME", FALSE), title);
1568 gdk_window_set_role (GdkWindow *window,
1571 g_return_if_fail (window != NULL);
1572 g_return_if_fail (GDK_IS_WINDOW (window));
1574 if (!GDK_WINDOW_DESTROYED (window))
1577 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1578 gdk_atom_intern ("WM_WINDOW_ROLE", FALSE), XA_STRING,
1579 8, PropModeReplace, role, strlen (role));
1581 XDeleteProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
1582 gdk_atom_intern ("WM_WINDOW_ROLE", FALSE));
1587 gdk_window_set_transient_for (GdkWindow *window,
1590 GdkWindowObject *private;
1591 GdkWindowObject *parent_private;
1593 g_return_if_fail (window != NULL);
1594 g_return_if_fail (GDK_IS_WINDOW (window));
1596 private = (GdkWindowObject*) window;
1597 parent_private = (GdkWindowObject*) parent;
1599 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent))
1600 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
1601 GDK_WINDOW_XID (window),
1602 GDK_WINDOW_XID (parent));
1606 gdk_window_set_background (GdkWindow *window,
1609 GdkWindowObject *private = (GdkWindowObject *)window;
1611 g_return_if_fail (window != NULL);
1612 g_return_if_fail (GDK_IS_WINDOW (window));
1614 if (!GDK_WINDOW_DESTROYED (window))
1615 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
1616 GDK_WINDOW_XID (window), color->pixel);
1618 private->bg_color = *color;
1620 if (private->bg_pixmap &&
1621 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1622 private->bg_pixmap != GDK_NO_BG)
1624 gdk_pixmap_unref (private->bg_pixmap);
1625 private->bg_pixmap = NULL;
1630 gdk_window_set_back_pixmap (GdkWindow *window,
1632 gboolean parent_relative)
1634 GdkWindowObject *private = (GdkWindowObject *)window;
1637 g_return_if_fail (window != NULL);
1638 g_return_if_fail (GDK_IS_WINDOW (window));
1639 g_return_if_fail (pixmap == NULL || !parent_relative);
1641 if (private->bg_pixmap &&
1642 private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1643 private->bg_pixmap != GDK_NO_BG)
1644 gdk_pixmap_unref (private->bg_pixmap);
1646 if (parent_relative)
1648 xpixmap = ParentRelative;
1649 private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
1655 gdk_pixmap_ref (pixmap);
1656 private->bg_pixmap = pixmap;
1657 xpixmap = GDK_PIXMAP_XID (pixmap);
1662 private->bg_pixmap = GDK_NO_BG;
1666 if (!GDK_WINDOW_DESTROYED (window))
1667 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
1668 GDK_WINDOW_XID (window), xpixmap);
1672 gdk_window_set_cursor (GdkWindow *window,
1675 GdkCursorPrivate *cursor_private;
1678 g_return_if_fail (window != NULL);
1679 g_return_if_fail (GDK_IS_WINDOW (window));
1681 cursor_private = (GdkCursorPrivate*) cursor;
1686 xcursor = cursor_private->xcursor;
1688 if (!GDK_WINDOW_DESTROYED (window))
1689 XDefineCursor (GDK_WINDOW_XDISPLAY (window),
1690 GDK_WINDOW_XID (window),
1695 gdk_window_get_geometry (GdkWindow *window,
1707 guint tborder_width;
1710 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
1713 window = gdk_parent_root;
1715 if (!GDK_WINDOW_DESTROYED (window))
1717 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
1718 GDK_WINDOW_XID (window),
1719 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
1735 * gdk_window_get_origin:
1736 * @window: a #GdkWindow
1737 * @x: return location for X coordinate
1738 * @y: return location for Y coordinate
1740 * Obtains the position of a window in root window coordinates.
1741 * (Compare with gdk_window_get_position() and
1742 * gdk_window_get_geometry() which return the position of a window
1743 * relative to its parent window.)
1745 * Return value: not meaningful, ignore
1748 gdk_window_get_origin (GdkWindow *window,
1757 g_return_val_if_fail (window != NULL, 0);
1759 if (!GDK_WINDOW_DESTROYED (window))
1761 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
1762 GDK_WINDOW_XID (window),
1780 * gdk_window_get_deskrelative_origin:
1781 * @window: a #GdkWindow
1782 * @x: return location for X coordinate
1783 * @y: return location for Y coordinate
1785 * This gets the origin of a #GdkWindow relative to
1786 * an Enlightenment-window-manager desktop. As long as you don't
1787 * assume that the user's desktop/workspace covers the entire
1788 * root window (i.e. you don't assume that the desktop begins
1789 * at root window coordinate 0,0) this function is not necessary.
1790 * It's deprecated for that reason.
1792 * Return value: not meaningful
1795 gdk_window_get_deskrelative_origin (GdkWindow *window,
1799 gboolean return_val = FALSE;
1800 gint num_children, format_return;
1801 Window win, *child, parent, root;
1805 static Atom atom = 0;
1806 gulong number_return, bytes_after_return;
1807 guchar *data_return;
1809 g_return_val_if_fail (window != NULL, 0);
1810 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
1812 if (!GDK_WINDOW_DESTROYED (window))
1815 atom = gdk_atom_intern ("ENLIGHTENMENT_DESKTOP", FALSE);
1816 win = GDK_WINDOW_XID (window);
1818 while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent,
1819 &child, (unsigned int *)&num_children))
1821 if ((child) && (num_children > 0))
1833 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0,
1834 False, XA_CARDINAL, &type_return, &format_return,
1835 &number_return, &bytes_after_return, &data_return);
1836 if (type_return == XA_CARDINAL)
1838 XFree (data_return);
1843 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
1844 GDK_WINDOW_XID (window),
1859 * gdk_window_get_root_origin:
1860 * @window: a #GdkWindow
1861 * @x: return location for X position of window frame
1862 * @y: return location for Y position of window frame
1864 * Obtains the top-left corner of the window manager frame in root
1865 * window coordinates.
1869 gdk_window_get_root_origin (GdkWindow *window,
1875 g_return_if_fail (GDK_IS_WINDOW (window));
1877 gdk_window_get_frame_extents (window, &rect);
1887 * gdk_window_get_frame_extents:
1888 * @window: a #GdkWindow
1889 * @rect: rectangle to fill with bounding box of the window frame
1891 * Obtains the bounding box of the window, including window manager
1892 * titlebar/borders if any. The frame position is given in root window
1893 * coordinates. To get the position of the window itself (rather than
1894 * the frame) in root window coordinates, use gdk_window_get_origin().
1898 gdk_window_get_frame_extents (GdkWindow *window,
1901 GdkWindowObject *private;
1906 unsigned int nchildren;
1908 g_return_if_fail (GDK_IS_WINDOW (window));
1909 g_return_if_fail (rect != NULL);
1911 private = (GdkWindowObject*) window;
1918 if (GDK_WINDOW_DESTROYED (window))
1921 while (private->parent && ((GdkWindowObject*) private->parent)->parent)
1922 private = (GdkWindowObject*) private->parent;
1923 if (GDK_WINDOW_DESTROYED (window))
1926 xparent = GDK_WINDOW_XID (window);
1930 if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), xwindow,
1932 &children, &nchildren))
1938 while (xparent != root);
1940 if (xparent == root)
1942 unsigned int ww, wh, wb, wd;
1945 if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
1956 gdk_window_get_pointer (GdkWindow *window,
1959 GdkModifierType *mask)
1961 GdkWindow *return_val;
1967 unsigned int xmask = 0;
1968 gint xoffset, yoffset;
1970 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
1973 window = gdk_parent_root;
1975 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
1978 if (!GDK_WINDOW_DESTROYED (window) &&
1979 XQueryPointer (GDK_WINDOW_XDISPLAY (window),
1980 GDK_WINDOW_XID (window),
1981 &root, &child, &rootx, &rooty, &winx, &winy, &xmask))
1984 return_val = gdk_window_lookup (child);
1988 *x = winx + xoffset;
1990 *y = winy + yoffset;
1998 gdk_window_at_pointer (gint *win_x,
2004 Window xwindow_last = 0;
2006 int rootx = -1, rooty = -1;
2010 xwindow = GDK_ROOT_WINDOW ();
2011 xdisplay = GDK_DISPLAY ();
2013 gdk_x11_grab_server ();
2016 xwindow_last = xwindow;
2017 XQueryPointer (xdisplay, xwindow,
2023 gdk_x11_ungrab_server ();
2025 window = gdk_window_lookup (xwindow_last);
2028 *win_x = window ? winx : -1;
2030 *win_y = window ? winy : -1;
2036 gdk_window_get_events (GdkWindow *window)
2038 XWindowAttributes attrs;
2039 GdkEventMask event_mask;
2042 g_return_val_if_fail (window != NULL, 0);
2043 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2045 if (GDK_WINDOW_DESTROYED (window))
2049 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2050 GDK_WINDOW_XID (window),
2054 for (i = 0; i < gdk_nevent_masks; i++)
2056 if (attrs.your_event_mask & gdk_event_mask_table[i])
2057 event_mask |= 1 << (i + 1);
2065 gdk_window_set_events (GdkWindow *window,
2066 GdkEventMask event_mask)
2071 g_return_if_fail (window != NULL);
2072 g_return_if_fail (GDK_IS_WINDOW (window));
2074 if (!GDK_WINDOW_DESTROYED (window))
2076 xevent_mask = StructureNotifyMask;
2077 for (i = 0; i < gdk_nevent_masks; i++)
2079 if (event_mask & (1 << (i + 1)))
2080 xevent_mask |= gdk_event_mask_table[i];
2083 XSelectInput (GDK_WINDOW_XDISPLAY (window),
2084 GDK_WINDOW_XID (window),
2090 gdk_window_add_colormap_windows (GdkWindow *window)
2092 GdkWindow *toplevel;
2093 Window *old_windows;
2094 Window *new_windows;
2097 g_return_if_fail (window != NULL);
2098 g_return_if_fail (GDK_IS_WINDOW (window));
2100 toplevel = gdk_window_get_toplevel (window);
2101 if (GDK_WINDOW_DESTROYED (toplevel))
2105 if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2106 GDK_WINDOW_XID (toplevel),
2107 &old_windows, &count))
2112 for (i = 0; i < count; i++)
2113 if (old_windows[i] == GDK_WINDOW_XID (window))
2115 XFree (old_windows);
2119 new_windows = g_new (Window, count + 1);
2121 for (i = 0; i < count; i++)
2122 new_windows[i] = old_windows[i];
2123 new_windows[count] = GDK_WINDOW_XID (window);
2125 XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel),
2126 GDK_WINDOW_XID (toplevel),
2127 new_windows, count + 1);
2129 g_free (new_windows);
2131 XFree (old_windows);
2135 gdk_window_have_shape_ext (void)
2137 enum { UNKNOWN, NO, YES };
2138 static gint have_shape = UNKNOWN;
2140 if (have_shape == UNKNOWN)
2143 if (XQueryExtension (gdk_display, "SHAPE", &ignore, &ignore, &ignore))
2149 return (have_shape == YES);
2152 #define WARN_SHAPE_TOO_BIG() g_warning ("GdkWindow is too large to allow the use of shape masks or shape regions.")
2155 * This needs the X11 shape extension.
2156 * If not available, shaped windows will look
2157 * ugly, but programs still work. Stefan Wille
2160 gdk_window_shape_combine_mask (GdkWindow *window,
2165 gint xoffset, yoffset;
2167 g_return_if_fail (window != NULL);
2168 g_return_if_fail (GDK_IS_WINDOW (window));
2170 #ifdef HAVE_SHAPE_EXT
2171 if (GDK_WINDOW_DESTROYED (window))
2174 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2176 if (xoffset != 0 || yoffset != 0)
2178 WARN_SHAPE_TOO_BIG ();
2182 if (gdk_window_have_shape_ext ())
2186 pixmap = GDK_PIXMAP_XID (mask);
2195 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2196 GDK_WINDOW_XID (window),
2202 #endif /* HAVE_SHAPE_EXT */
2206 gdk_window_shape_combine_region (GdkWindow *window,
2207 GdkRegion *shape_region,
2211 gint xoffset, yoffset;
2213 g_return_if_fail (GDK_IS_WINDOW (window));
2215 #ifdef HAVE_SHAPE_EXT
2216 if (GDK_WINDOW_DESTROYED (window))
2219 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
2221 if (xoffset != 0 || yoffset != 0)
2223 WARN_SHAPE_TOO_BIG ();
2227 if (shape_region == NULL)
2229 /* Use NULL mask to unset the shape */
2230 gdk_window_shape_combine_mask (window, NULL, 0, 0);
2234 if (gdk_window_have_shape_ext ())
2237 XRectangle *xrects = NULL;
2239 _gdk_region_get_xrectangles (shape_region,
2243 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2244 GDK_WINDOW_XID (window),
2253 #endif /* HAVE_SHAPE_EXT */
2258 gdk_window_set_override_redirect (GdkWindow *window,
2259 gboolean override_redirect)
2261 XSetWindowAttributes attr;
2263 g_return_if_fail (window != NULL);
2264 g_return_if_fail (GDK_IS_WINDOW (window));
2266 if (GDK_WINDOW_DESTROYED (window))
2268 attr.override_redirect = (override_redirect == FALSE)?False:True;
2269 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2270 GDK_WINDOW_XID (window),
2278 * gdk_window_set_icon_list:
2279 * @window: The #GdkWindow toplevel window to set the icon of.
2280 * @pixbufs: A list of pixbufs, of different sizes.
2281 * @Returns: TRUE if the icons were set, false otherwise
2283 * Sets a list of icons for the window. One of these will be used
2284 * to represent the window when it has been iconified. The icon is
2285 * usually shown in an icon box or some sort of task bar. Which icon
2286 * size is shown depends on the window manager. The window manager
2287 * can scale the icon but setting several size icons can give better
2288 * image quality since the window manager may only need to scale the
2289 * icon by a small amount or not at all.
2291 * On the X11 backend this call might fail if the window manager
2292 * doesn't support the Extended Window Manager Hints. Then this
2293 * function returns FALSE, and the application should fall back
2294 * to #gdk_window_set_icon().
2297 gdk_window_set_icon_list (GdkWindow *window,
2306 gint width, height, stride;
2310 g_return_val_if_fail (window != NULL, FALSE);
2311 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2313 if (GDK_WINDOW_DESTROYED (window))
2316 if (!gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_ICON", FALSE)))
2325 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
2327 width = gdk_pixbuf_get_width (pixbuf);
2328 height = gdk_pixbuf_get_height (pixbuf);
2330 size += 2 + width * height;
2332 l = g_list_next (l);
2335 data = g_malloc (size*4);
2343 width = gdk_pixbuf_get_width (pixbuf);
2344 height = gdk_pixbuf_get_height (pixbuf);
2345 stride = gdk_pixbuf_get_rowstride (pixbuf);
2346 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
2351 pixels = gdk_pixbuf_get_pixels (pixbuf);
2353 for (y = 0; y < height; y++)
2355 for (x = 0; x < width; x++)
2359 r = pixels[y*stride + x*n_channels + 0];
2360 g = pixels[y*stride + x*n_channels + 1];
2361 b = pixels[y*stride + x*n_channels + 2];
2362 if (n_channels >= 4)
2363 a = pixels[y*stride + x*n_channels + 3];
2367 *p++ = a << 24 | r << 16 | g << 8 | b ;
2371 l = g_list_next (l);
2374 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2375 GDK_WINDOW_XID (window),
2376 gdk_atom_intern ("_NET_WM_ICON", FALSE),
2379 (guchar*) data, size);
2385 gdk_window_set_icon (GdkWindow *window,
2386 GdkWindow *icon_window,
2392 g_return_if_fail (window != NULL);
2393 g_return_if_fail (GDK_IS_WINDOW (window));
2395 if (GDK_WINDOW_DESTROYED (window))
2398 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
2399 GDK_WINDOW_XID (window));
2401 wm_hints = XAllocWMHints ();
2403 if (icon_window != NULL)
2405 wm_hints->flags |= IconWindowHint;
2406 wm_hints->icon_window = GDK_WINDOW_XID (icon_window);
2411 wm_hints->flags |= IconPixmapHint;
2412 wm_hints->icon_pixmap = GDK_PIXMAP_XID (pixmap);
2417 wm_hints->flags |= IconMaskHint;
2418 wm_hints->icon_mask = GDK_PIXMAP_XID (mask);
2421 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
2422 GDK_WINDOW_XID (window), wm_hints);
2427 gdk_window_icon_name_set (GdkWindow *window)
2429 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
2430 g_quark_from_static_string ("gdk-icon-name-set")));
2434 gdk_window_set_icon_name (GdkWindow *window,
2437 g_return_if_fail (window != NULL);
2438 g_return_if_fail (GDK_IS_WINDOW (window));
2440 if (GDK_WINDOW_DESTROYED (window))
2443 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
2444 GUINT_TO_POINTER (TRUE));
2446 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2447 GDK_WINDOW_XID (window),
2448 gdk_atom_intern ("_NET_WM_ICON_NAME", FALSE),
2449 gdk_atom_intern ("UTF8_STRING", FALSE), 8,
2450 PropModeReplace, name,
2452 set_text_property (window, gdk_atom_intern ("WM_ICON_NAME", FALSE), name);
2456 gdk_window_iconify (GdkWindow *window)
2459 GdkWindowObject *private;
2461 g_return_if_fail (window != NULL);
2462 g_return_if_fail (GDK_IS_WINDOW (window));
2464 if (GDK_WINDOW_DESTROYED (window))
2467 display = GDK_WINDOW_XDISPLAY (window);
2469 private = (GdkWindowObject*) window;
2471 if (GDK_WINDOW_IS_MAPPED (window))
2473 XIconifyWindow (display, GDK_WINDOW_XWINDOW (window), DefaultScreen (display));
2478 /* Flip our client side flag, the real work happens on map. */
2479 gdk_synthesize_window_state (window,
2481 GDK_WINDOW_STATE_ICONIFIED);
2486 gdk_window_deiconify (GdkWindow *window)
2489 GdkWindowObject *private;
2491 g_return_if_fail (window != NULL);
2492 g_return_if_fail (GDK_IS_WINDOW (window));
2494 if (GDK_WINDOW_DESTROYED (window))
2497 display = GDK_WINDOW_XDISPLAY (window);
2499 private = (GdkWindowObject*) window;
2501 if (GDK_WINDOW_IS_MAPPED (window))
2503 gdk_window_show (window);
2507 /* Flip our client side flag, the real work happens on map. */
2508 gdk_synthesize_window_state (window,
2509 GDK_WINDOW_STATE_ICONIFIED,
2515 gdk_window_stick (GdkWindow *window)
2517 g_return_if_fail (GDK_IS_WINDOW (window));
2519 if (GDK_WINDOW_DESTROYED (window))
2522 if (GDK_WINDOW_IS_MAPPED (window))
2524 /* "stick" means stick to all desktops _and_ do not scroll with the
2525 * viewport. i.e. glue to the monitor glass in all cases.
2530 /* Request stick during viewport scroll */
2531 gdk_wmspec_change_state (TRUE, window,
2532 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
2535 /* Request desktop 0xFFFFFFFF */
2536 xev.xclient.type = ClientMessage;
2537 xev.xclient.serial = 0;
2538 xev.xclient.send_event = True;
2539 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
2540 xev.xclient.display = gdk_display;
2541 xev.xclient.message_type = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE);
2542 xev.xclient.format = 32;
2544 xev.xclient.data.l[0] = 0xFFFFFFFF;
2546 XSendEvent (gdk_display, gdk_root_window, False,
2547 SubstructureRedirectMask | SubstructureNotifyMask,
2552 /* Flip our client side flag, the real work happens on map. */
2553 gdk_synthesize_window_state (window,
2555 GDK_WINDOW_STATE_STICKY);
2560 gdk_window_unstick (GdkWindow *window)
2562 g_return_if_fail (GDK_IS_WINDOW (window));
2564 if (GDK_WINDOW_DESTROYED (window))
2567 if (GDK_WINDOW_IS_MAPPED (window))
2574 gulong *current_desktop;
2576 /* Request unstick from viewport */
2577 gdk_wmspec_change_state (FALSE, window,
2578 gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE),
2581 /* Get current desktop, then set it; this is a race, but not
2582 * one that matters much in practice.
2584 XGetWindowProperty (gdk_display, gdk_root_window,
2585 gdk_atom_intern ("_NET_CURRENT_DESKTOP", FALSE),
2587 False, XA_CARDINAL, &type, &format, &nitems,
2588 &bytes_after, (guchar **)¤t_desktop);
2590 if (type == XA_CARDINAL)
2592 xev.xclient.type = ClientMessage;
2593 xev.xclient.serial = 0;
2594 xev.xclient.send_event = True;
2595 xev.xclient.window = GDK_WINDOW_XWINDOW (window);
2596 xev.xclient.display = gdk_display;
2597 xev.xclient.message_type = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE);
2598 xev.xclient.format = 32;
2600 xev.xclient.data.l[0] = *current_desktop;
2602 XSendEvent (gdk_display, gdk_root_window, False,
2603 SubstructureRedirectMask | SubstructureNotifyMask,
2606 XFree (current_desktop);
2611 /* Flip our client side flag, the real work happens on map. */
2612 gdk_synthesize_window_state (window,
2613 GDK_WINDOW_STATE_STICKY,
2620 gdk_window_maximize (GdkWindow *window)
2622 g_return_if_fail (GDK_IS_WINDOW (window));
2624 if (GDK_WINDOW_DESTROYED (window))
2627 if (GDK_WINDOW_IS_MAPPED (window))
2628 gdk_wmspec_change_state (TRUE, window,
2629 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
2630 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
2632 gdk_synthesize_window_state (window,
2634 GDK_WINDOW_STATE_MAXIMIZED);
2638 gdk_window_unmaximize (GdkWindow *window)
2640 g_return_if_fail (GDK_IS_WINDOW (window));
2642 if (GDK_WINDOW_DESTROYED (window))
2645 if (GDK_WINDOW_IS_MAPPED (window))
2646 gdk_wmspec_change_state (FALSE, window,
2647 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE),
2648 gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE));
2650 gdk_synthesize_window_state (window,
2651 GDK_WINDOW_STATE_MAXIMIZED,
2656 gdk_window_set_group (GdkWindow *window,
2661 g_return_if_fail (window != NULL);
2662 g_return_if_fail (GDK_IS_WINDOW (window));
2663 g_return_if_fail (leader != NULL);
2664 g_return_if_fail (GDK_IS_WINDOW (leader));
2666 if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader))
2669 wm_hints = XGetWMHints (GDK_WINDOW_XDISPLAY (window),
2670 GDK_WINDOW_XID (window));
2672 wm_hints = XAllocWMHints ();
2674 wm_hints->flags |= WindowGroupHint;
2675 wm_hints->window_group = GDK_WINDOW_XID (leader);
2677 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
2678 GDK_WINDOW_XID (window), wm_hints);
2682 static MotifWmHints *
2683 gdk_window_get_mwm_hints (GdkWindow *window)
2685 static Atom hints_atom = None;
2686 MotifWmHints *hints;
2692 if (GDK_WINDOW_DESTROYED (window))
2696 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
2697 _XA_MOTIF_WM_HINTS, FALSE);
2699 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
2700 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
2701 False, AnyPropertyType, &type, &format, &nitems,
2702 &bytes_after, (guchar **)&hints);
2711 gdk_window_set_mwm_hints (GdkWindow *window,
2712 MotifWmHints *new_hints)
2714 static Atom hints_atom = None;
2715 MotifWmHints *hints;
2721 if (GDK_WINDOW_DESTROYED (window))
2725 hints_atom = XInternAtom (GDK_WINDOW_XDISPLAY (window),
2726 _XA_MOTIF_WM_HINTS, FALSE);
2728 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
2729 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
2730 False, AnyPropertyType, &type, &format, &nitems,
2731 &bytes_after, (guchar **)&hints);
2737 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
2739 hints->flags |= MWM_HINTS_FUNCTIONS;
2740 hints->functions = new_hints->functions;
2742 if (new_hints->flags & MWM_HINTS_DECORATIONS)
2744 hints->flags |= MWM_HINTS_DECORATIONS;
2745 hints->decorations = new_hints->decorations;
2749 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
2750 hints_atom, hints_atom, 32, PropModeReplace,
2751 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
2753 if (hints != new_hints)
2758 gdk_window_set_decorations (GdkWindow *window,
2759 GdkWMDecoration decorations)
2763 g_return_if_fail (window != NULL);
2764 g_return_if_fail (GDK_IS_WINDOW (window));
2766 hints.flags = MWM_HINTS_DECORATIONS;
2767 hints.decorations = decorations;
2769 gdk_window_set_mwm_hints (window, &hints);
2773 * gdk_window_get_decorations:
2774 * @window: The #GdkWindow to get the decorations from
2775 * @decorations: The window decorations will be written here
2777 * Returns the decorations set on the GdkWindow with #gdk_window_set_decorations
2778 * Returns: TRUE if the window has decorations set, FALSE otherwise.
2781 gdk_window_get_decorations(GdkWindow *window,
2782 GdkWMDecoration *decorations)
2784 MotifWmHints *hints;
2785 gboolean result = FALSE;
2787 hints = gdk_window_get_mwm_hints (window);
2791 if (hints->flags & MWM_HINTS_DECORATIONS)
2793 *decorations = hints->decorations;
2804 gdk_window_set_functions (GdkWindow *window,
2805 GdkWMFunction functions)
2809 g_return_if_fail (window != NULL);
2810 g_return_if_fail (GDK_IS_WINDOW (window));
2812 hints.flags = MWM_HINTS_FUNCTIONS;
2813 hints.functions = functions;
2815 gdk_window_set_mwm_hints (window, &hints);
2818 #ifdef HAVE_SHAPE_EXT
2821 * propagate the shapes from all child windows of a GDK window to the parent
2822 * window. Shamelessly ripped from Enlightenment's code
2830 struct _gdk_span *next;
2834 gdk_add_to_span (struct _gdk_span **s,
2838 struct _gdk_span *ptr1, *ptr2, *noo, *ss;
2845 /* scan the spans for this line */
2848 /* -- -> new span */
2849 /* == -> existing span */
2850 /* ## -> spans intersect */
2851 /* if we are in the middle of spanning the span into the line */
2854 /* case: ---- ==== */
2855 if (xx < ptr1->start - 1)
2857 /* ends before next span - extend to here */
2861 /* case: ----##=== */
2862 else if (xx <= ptr1->end)
2864 /* crosses into next span - delete next span and append */
2865 ss->end = ptr1->end;
2866 ss->next = ptr1->next;
2870 /* case: ---###--- */
2873 /* overlaps next span - delete and keep checking */
2874 ss->next = ptr1->next;
2879 /* otherwise havent started spanning it in yet */
2882 /* case: ---- ==== */
2883 if (xx < ptr1->start - 1)
2885 /* insert span here in list */
2886 noo = g_malloc (sizeof (struct _gdk_span));
2900 /* case: ----##=== */
2901 else if ((x < ptr1->start) && (xx <= ptr1->end))
2903 /* expand this span to the left point of the new one */
2907 /* case: ===###=== */
2908 else if ((x >= ptr1->start) && (xx <= ptr1->end))
2910 /* throw the span away */
2913 /* case: ---###--- */
2914 else if ((x < ptr1->start) && (xx > ptr1->end))
2921 /* case: ===##---- */
2922 else if ((x >= ptr1->start) && (x <= ptr1->end + 1) && (xx > ptr1->end))
2928 /* case: ==== ---- */
2929 /* case handled by next loop iteration - first case */
2934 /* it started in the middle but spans beyond your current list */
2940 /* it does not start inside a span or in the middle, so add it to the end */
2941 noo = g_malloc (sizeof (struct _gdk_span));
2949 noo->next = ptr2->next;
2962 gdk_add_rectangles (Display *disp,
2964 struct _gdk_span **spans,
2971 gint x1, y1, x2, y2;
2975 rl = XShapeGetRectangles (disp, win, ShapeBounding, &rn, &ord);
2978 /* go through all clip rects in this window's shape */
2979 for (k = 0; k < rn; k++)
2981 /* for each clip rect, add it to each line's spans */
2983 x2 = x + rl[k].x + (rl[k].width - 1);
2985 y2 = y + rl[k].y + (rl[k].height - 1);
2994 for (a = y1; a <= y2; a++)
2997 gdk_add_to_span (&spans[a], x1, x2);
3005 gdk_propagate_shapes (Display *disp,
3009 Window rt, par, *list = NULL;
3010 gint i, j, num = 0, num_rects = 0;
3014 XRectangle *rects = NULL;
3015 struct _gdk_span **spans = NULL, *ptr1, *ptr2, *ptr3;
3016 XWindowAttributes xatt;
3018 XGetGeometry (disp, win, &rt, &x, &y, &w, &h, &d, &d);
3023 spans = g_malloc (sizeof (struct _gdk_span *) * h);
3025 for (i = 0; i < h; i++)
3027 XQueryTree (disp, win, &rt, &par, &list, (unsigned int *)&num);
3030 /* go through all child windows and create/insert spans */
3031 for (i = 0; i < num; i++)
3033 if (XGetWindowAttributes (disp, list[i], &xatt) && (xatt.map_state != IsUnmapped))
3034 if (XGetGeometry (disp, list[i], &rt, &x, &y, &w, &h, &d, &d))
3035 gdk_add_rectangles (disp, list[i], spans, basew, baseh, x, y);
3038 gdk_add_rectangles (disp, win, spans, basew, baseh, x, y);
3040 /* go through the spans list and build a list of rects */
3041 rects = g_malloc (sizeof (XRectangle) * 256);
3043 for (i = 0; i < baseh; i++)
3046 /* go through the line for all spans */
3049 rects[num_rects].x = ptr1->start;
3050 rects[num_rects].y = i;
3051 rects[num_rects].width = ptr1->end - ptr1->start + 1;
3052 rects[num_rects].height = 1;
3054 /* if there are more lines */
3056 /* while contigous rects (same start/end coords) exist */
3057 while ((contig) && (j < baseh))
3059 /* search next line for spans matching this one */
3065 /* if we have an exact span match set contig */
3066 if ((ptr2->start == ptr1->start) &&
3067 (ptr2->end == ptr1->end))
3070 /* remove the span - not needed */
3073 ptr3->next = ptr2->next;
3079 spans[j] = ptr2->next;
3085 /* gone past the span point no point looking */
3086 else if (ptr2->start < ptr1->start)
3094 /* if a contiguous span was found increase the rect h */
3097 rects[num_rects].height++;
3101 /* up the rect count */
3103 /* every 256 new rects increase the rect array */
3104 if ((num_rects % 256) == 0)
3105 rects = g_realloc (rects, sizeof (XRectangle) * (num_rects + 256));
3109 /* set the rects as the shape mask */
3112 XShapeCombineRectangles (disp, win, ShapeBounding, 0, 0, rects, num_rects,
3113 ShapeSet, YXSorted);
3118 /* free up all the spans we made */
3119 for (i = 0; i < baseh; i++)
3132 #endif /* HAVE_SHAPE_EXT */
3135 gdk_window_set_child_shapes (GdkWindow *window)
3137 g_return_if_fail (window != NULL);
3138 g_return_if_fail (GDK_IS_WINDOW (window));
3140 #ifdef HAVE_SHAPE_EXT
3141 if (!GDK_WINDOW_DESTROYED (window) &&
3142 gdk_window_have_shape_ext ())
3143 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3144 GDK_WINDOW_XID (window), FALSE);
3149 gdk_window_merge_child_shapes (GdkWindow *window)
3151 g_return_if_fail (window != NULL);
3152 g_return_if_fail (GDK_IS_WINDOW (window));
3154 #ifdef HAVE_SHAPE_EXT
3155 if (!GDK_WINDOW_DESTROYED (window) &&
3156 gdk_window_have_shape_ext ())
3157 gdk_propagate_shapes (GDK_WINDOW_XDISPLAY (window),
3158 GDK_WINDOW_XID (window), TRUE);
3162 /* Support for windows that can be guffaw-scrolled
3163 * (See http://www.gtk.org/~otaylor/whitepapers/guffaw-scrolling.txt)
3167 gdk_window_gravity_works (void)
3169 enum { UNKNOWN, NO, YES };
3170 static gint gravity_works = UNKNOWN;
3172 if (gravity_works == UNKNOWN)
3179 /* This particular server apparently has a bug so that the test
3180 * works but the actual code crashes it
3182 if ((!strcmp (XServerVendor (gdk_display), "Sun Microsystems, Inc.")) &&
3183 (VendorRelease (gdk_display) == 3400))
3189 attr.window_type = GDK_WINDOW_TEMP;
3190 attr.wclass = GDK_INPUT_OUTPUT;
3195 attr.event_mask = 0;
3197 parent = gdk_window_new (NULL, &attr, GDK_WA_X | GDK_WA_Y);
3199 attr.window_type = GDK_WINDOW_CHILD;
3200 child = gdk_window_new (parent, &attr, GDK_WA_X | GDK_WA_Y);
3202 gdk_window_set_static_win_gravity (child, TRUE);
3204 gdk_window_resize (parent, 100, 110);
3205 gdk_window_move (parent, 0, -10);
3206 gdk_window_move_resize (parent, 0, 0, 100, 100);
3208 gdk_window_resize (parent, 100, 110);
3209 gdk_window_move (parent, 0, -10);
3210 gdk_window_move_resize (parent, 0, 0, 100, 100);
3212 gdk_window_get_geometry (child, NULL, &y, NULL, NULL, NULL);
3214 gdk_window_destroy (parent);
3215 gdk_window_destroy (child);
3217 gravity_works = ((y == -20) ? YES : NO);
3220 return (gravity_works == YES);
3224 gdk_window_set_static_bit_gravity (GdkWindow *window, gboolean on)
3226 XSetWindowAttributes xattributes;
3227 guint xattributes_mask = 0;
3229 g_return_if_fail (window != NULL);
3231 xattributes.bit_gravity = StaticGravity;
3232 xattributes_mask |= CWBitGravity;
3233 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
3234 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3235 GDK_WINDOW_XID (window),
3236 CWBitGravity, &xattributes);
3240 gdk_window_set_static_win_gravity (GdkWindow *window, gboolean on)
3242 XSetWindowAttributes xattributes;
3244 g_return_if_fail (window != NULL);
3246 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
3248 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3249 GDK_WINDOW_XID (window),
3250 CWWinGravity, &xattributes);
3253 /*************************************************************
3254 * gdk_window_set_static_gravities:
3255 * Set the bit gravity of the given window to static,
3256 * and flag it so all children get static subwindow
3259 * window: window for which to set static gravity
3260 * use_static: Whether to turn static gravity on or off.
3262 * Does the XServer support static gravity?
3263 *************************************************************/
3266 gdk_window_set_static_gravities (GdkWindow *window,
3267 gboolean use_static)
3269 GdkWindowObject *private = (GdkWindowObject *)window;
3272 g_return_val_if_fail (window != NULL, FALSE);
3273 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
3275 if (!use_static == !private->guffaw_gravity)
3278 if (use_static && !gdk_window_gravity_works ())
3281 private->guffaw_gravity = use_static;
3283 if (!GDK_WINDOW_DESTROYED (window))
3285 gdk_window_set_static_bit_gravity (window, use_static);
3287 tmp_list = private->children;
3290 gdk_window_set_static_win_gravity (window, use_static);
3292 tmp_list = tmp_list->next;
3299 /* internal function created for and used by gdk_window_xid_at_coords */
3301 gdk_window_xid_at (Window base,
3307 gboolean excl_child)
3310 Window *list = NULL;
3311 Window child = 0, parent_win = 0, root_win = 0;
3313 unsigned int ww, wh, wb, wd, num;
3316 xdisplay = GDK_DISPLAY ();
3317 if (!XGetGeometry (xdisplay, base, &root_win, &wx, &wy, &ww, &wh, &wb, &wd))
3324 (x < (int) (wx + ww)) &&
3325 (y < (int) (wy + wh))))
3328 if (!XQueryTree (xdisplay, base, &root_win, &parent_win, &list, &num))
3333 for (i = num - 1; ; i--)
3335 if ((!excl_child) || (!g_list_find (excludes, (gpointer *) list[i])))
3337 if ((child = gdk_window_xid_at (list[i], wx, wy, x, y, excludes, excl_child)) != 0)
3352 * The following fucntion by The Rasterman <raster@redhat.com>
3353 * This function returns the X Window ID in which the x y location is in
3354 * (x and y being relative to the root window), excluding any windows listed
3355 * in the GList excludes (this is a list of X Window ID's - gpointer being
3358 * This is primarily designed for internal gdk use - for DND for example
3359 * when using a shaped icon window as the drag object - you exclude the
3360 * X Window ID of the "icon" (perhaps more if excludes may be needed) and
3361 * You can get back an X Window ID as to what X Window ID is infact under
3362 * those X,Y co-ordinates.
3365 gdk_window_xid_at_coords (gint x,
3368 gboolean excl_child)
3372 Window *list = NULL;
3373 Window root, child = 0, parent_win = 0, root_win = 0;
3377 window = gdk_parent_root;
3378 xdisplay = GDK_WINDOW_XDISPLAY (window);
3379 root = GDK_WINDOW_XID (window);
3380 num = g_list_length (excludes);
3382 gdk_x11_grab_server ();
3383 if (!XQueryTree (xdisplay, root, &root_win, &parent_win, &list, &num))
3385 gdk_x11_ungrab_server ();
3393 XWindowAttributes xwa;
3395 XGetWindowAttributes (xdisplay, list [i], &xwa);
3397 if (xwa.map_state != IsViewable)
3400 if (excl_child && g_list_find (excludes, (gpointer *) list[i]))
3403 if ((child = gdk_window_xid_at (list[i], 0, 0, x, y, excludes, excl_child)) == 0)
3408 if (!g_list_find (excludes, (gpointer *) child))
3411 gdk_x11_ungrab_server ();
3418 gdk_x11_ungrab_server ();
3424 gdk_x11_ungrab_server ();
3429 wmspec_moveresize (GdkWindow *window,
3437 /* Release passive grab */
3438 gdk_pointer_ungrab (timestamp);
3440 xev.xclient.type = ClientMessage;
3441 xev.xclient.serial = 0;
3442 xev.xclient.send_event = True;
3443 xev.xclient.display = gdk_display;
3444 xev.xclient.window = GDK_WINDOW_XID (window);
3445 xev.xclient.message_type = gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE);
3446 xev.xclient.format = 32;
3447 xev.xclient.data.l[0] = root_x;
3448 xev.xclient.data.l[1] = root_y;
3449 xev.xclient.data.l[2] = direction;
3450 xev.xclient.data.l[3] = 0;
3451 xev.xclient.data.l[4] = 0;
3453 XSendEvent (gdk_display, gdk_root_window, False,
3454 SubstructureRedirectMask | SubstructureNotifyMask,
3458 /* From the WM spec */
3459 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
3460 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
3461 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
3462 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
3463 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
3464 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
3465 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
3466 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
3467 #define _NET_WM_MOVERESIZE_MOVE 8
3470 wmspec_resize_drag (GdkWindow *window,
3479 /* Let the compiler turn a switch into a table, instead
3480 * of doing the table manually, this way is easier to verify.
3484 case GDK_WINDOW_EDGE_NORTH_WEST:
3485 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
3488 case GDK_WINDOW_EDGE_NORTH:
3489 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
3492 case GDK_WINDOW_EDGE_NORTH_EAST:
3493 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
3496 case GDK_WINDOW_EDGE_WEST:
3497 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
3500 case GDK_WINDOW_EDGE_EAST:
3501 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
3504 case GDK_WINDOW_EDGE_SOUTH_WEST:
3505 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
3508 case GDK_WINDOW_EDGE_SOUTH:
3509 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
3512 case GDK_WINDOW_EDGE_SOUTH_EAST:
3513 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
3517 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
3523 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
3526 /* This is global for use in gdkevents-x11.c */
3527 GdkWindow *_gdk_moveresize_window;
3529 static GdkWindow *moveresize_emulation_window = NULL;
3530 static gboolean is_resize = FALSE;
3531 static GdkWindowEdge resize_edge;
3532 static gint moveresize_button;
3533 static gint moveresize_x;
3534 static gint moveresize_y;
3535 static gint moveresize_orig_x;
3536 static gint moveresize_orig_y;
3537 static gint moveresize_orig_width;
3538 static gint moveresize_orig_height;
3539 static GdkWindowHints moveresize_geom_mask = 0;
3540 static GdkGeometry moveresize_geometry;
3541 static Time moveresize_process_time;
3543 static XEvent *moveresize_pending_event;
3546 update_pos (gint new_root_x,
3551 dx = new_root_x - moveresize_x;
3552 dy = new_root_y - moveresize_y;
3558 w = moveresize_orig_width;
3559 h = moveresize_orig_height;
3561 switch (resize_edge)
3563 case GDK_WINDOW_EDGE_SOUTH_EAST:
3572 if (moveresize_geom_mask)
3574 gdk_window_constrain_size (&moveresize_geometry,
3575 moveresize_geom_mask,
3580 gdk_window_resize (_gdk_moveresize_window, w, h);
3586 x = moveresize_orig_x + dx;
3587 y = moveresize_orig_y + dy;
3589 gdk_window_move (_gdk_moveresize_window, x, y);
3596 gdk_window_destroy (moveresize_emulation_window);
3597 moveresize_emulation_window = NULL;
3598 _gdk_moveresize_window = NULL;
3600 if (moveresize_pending_event)
3602 g_free (moveresize_pending_event);
3603 moveresize_pending_event = NULL;
3608 lookahead_motion_predicate (Display *display,
3612 gboolean *seen_release = (gboolean *)arg;
3617 switch (event->xany.type)
3620 *seen_release = TRUE;
3623 moveresize_process_time = event->xmotion.time;
3633 moveresize_lookahead (XEvent *event)
3636 gboolean seen_release = FALSE;
3638 if (moveresize_process_time)
3640 if (event->xmotion.time == moveresize_process_time)
3642 moveresize_process_time = 0;
3649 XCheckIfEvent (gdk_display, &tmp_event,
3650 lookahead_motion_predicate, (XPointer)&seen_release);
3652 return moveresize_process_time == 0;
3656 _gdk_moveresize_handle_event (XEvent *event)
3658 guint button_mask = 0;
3659 GdkWindowObject *window_private = (GdkWindowObject *) _gdk_moveresize_window;
3661 button_mask = GDK_BUTTON1_MASK << (moveresize_button - 1);
3663 switch (event->xany.type)
3666 if (window_private->resize_count > 0)
3668 if (moveresize_pending_event)
3669 *moveresize_pending_event = *event;
3671 moveresize_pending_event = g_memdup (event, sizeof (XEvent));
3675 if (!moveresize_lookahead (event))
3678 update_pos (event->xmotion.x_root,
3679 event->xmotion.y_root);
3681 /* This should never be triggered in normal cases, but in the
3682 * case where the drag started without an implicit grab being
3683 * in effect, we could miss the release if it occurs before
3684 * we grab the pointer; this ensures that we will never
3685 * get a permanently stuck grab.
3687 if ((event->xmotion.state & button_mask) == 0)
3692 update_pos (event->xbutton.x_root,
3693 event->xbutton.y_root);
3695 if (event->xbutton.button == moveresize_button)
3702 _gdk_moveresize_configure_done (void)
3706 if (moveresize_pending_event)
3708 tmp_event = moveresize_pending_event;
3709 moveresize_pending_event = NULL;
3710 _gdk_moveresize_handle_event (tmp_event);
3716 create_moveresize_window (guint32 timestamp)
3718 GdkWindowAttr attributes;
3719 gint attributes_mask;
3720 GdkGrabStatus status;
3722 g_assert (moveresize_emulation_window == NULL);
3724 attributes.x = -100;
3725 attributes.y = -100;
3726 attributes.width = 10;
3727 attributes.height = 10;
3728 attributes.window_type = GDK_WINDOW_TEMP;
3729 attributes.wclass = GDK_INPUT_ONLY;
3730 attributes.override_redirect = TRUE;
3731 attributes.event_mask = 0;
3733 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
3735 moveresize_emulation_window =
3736 gdk_window_new (NULL, &attributes, attributes_mask);
3738 gdk_window_show (moveresize_emulation_window);
3740 status = gdk_pointer_grab (moveresize_emulation_window,
3742 GDK_BUTTON_RELEASE_MASK |
3743 GDK_POINTER_MOTION_MASK,
3748 if (status != GDK_GRAB_SUCCESS)
3750 /* If this fails, some other client has grabbed the window
3753 gdk_window_destroy (moveresize_emulation_window);
3754 moveresize_emulation_window = NULL;
3757 moveresize_process_time = 0;
3761 emulate_resize_drag (GdkWindow *window,
3769 moveresize_button = button;
3771 moveresize_x = root_x;
3772 moveresize_y = root_y;
3773 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
3775 gdk_window_get_size (window, &moveresize_orig_width, &moveresize_orig_height);
3777 moveresize_geom_mask = 0;
3778 gdk_window_get_geometry_hints (window,
3779 &moveresize_geometry,
3780 &moveresize_geom_mask);
3782 create_moveresize_window (timestamp);
3786 emulate_move_drag (GdkWindow *window,
3793 moveresize_button = button;
3794 moveresize_x = root_x;
3795 moveresize_y = root_y;
3796 _gdk_moveresize_window = GDK_WINDOW (g_object_ref (G_OBJECT (window)));
3798 gdk_window_get_deskrelative_origin (_gdk_moveresize_window,
3800 &moveresize_orig_y);
3802 create_moveresize_window (timestamp);
3806 gdk_window_begin_resize_drag (GdkWindow *window,
3813 g_return_if_fail (GDK_IS_WINDOW (window));
3814 g_return_if_fail (moveresize_emulation_window == NULL);
3816 if (GDK_WINDOW_DESTROYED (window))
3819 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
3820 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
3822 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
3826 gdk_window_begin_move_drag (GdkWindow *window,
3832 g_return_if_fail (GDK_IS_WINDOW (window));
3833 g_return_if_fail (moveresize_emulation_window == NULL);
3835 if (GDK_WINDOW_DESTROYED (window))
3838 if (gdk_net_wm_supports (gdk_atom_intern ("_NET_WM_MOVERESIZE", FALSE)))
3839 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE,
3840 root_x, root_y, timestamp);
3842 emulate_move_drag (window, button, root_x, root_y, timestamp);