1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
3 * Josh MacDonald, Ryan Lortie
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gdkwindow-x11.h"
32 #include "gdkwindow.h"
33 #include "gdkwindowimpl.h"
34 #include "gdkvisualprivate.h"
35 #include "gdkinternals.h"
36 #include "gdkdeviceprivate.h"
38 #include "gdkeventsource.h"
39 #include "gdkdisplay-x11.h"
40 #include "gdkprivate-x11.h"
45 #include <netinet/in.h>
48 #include <cairo-xlib.h>
53 #include <X11/Xutil.h>
54 #include <X11/Xatom.h>
56 #include <X11/extensions/shape.h>
59 #include <X11/XKBlib.h>
62 #ifdef HAVE_XCOMPOSITE
63 #include <X11/extensions/Xcomposite.h>
67 #include <X11/extensions/Xfixes.h>
71 #include <X11/extensions/Xdamage.h>
74 const int _gdk_x11_event_mask_table[21] =
78 PointerMotionHintMask,
95 SubstructureNotifyMask,
96 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
99 const gint _gdk_x11_event_mask_table_size = G_N_ELEMENTS (_gdk_x11_event_mask_table);
101 /* Forward declarations */
102 static void gdk_window_set_static_win_gravity (GdkWindow *window,
104 static gboolean gdk_window_icon_name_set (GdkWindow *window);
105 static void set_wm_name (GdkDisplay *display,
108 static void move_to_current_desktop (GdkWindow *window);
109 static void gdk_window_x11_set_background (GdkWindow *window,
110 cairo_pattern_t *pattern);
112 static void gdk_window_impl_x11_finalize (GObject *object);
114 #define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \
115 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
116 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
118 #define WINDOW_IS_TOPLEVEL(window) \
119 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
120 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
121 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
123 /* Return whether time1 is considered later than time2 as far as xserver
124 * time is concerned. Accounts for wraparound.
126 #define XSERVER_TIME_IS_LATER(time1, time2) \
127 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
128 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
131 G_DEFINE_TYPE (GdkWindowImplX11, gdk_window_impl_x11, GDK_TYPE_WINDOW_IMPL)
134 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
136 impl->toplevel_window_type = -1;
137 impl->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
138 (GDestroyNotify) gdk_cursor_unref);
142 _gdk_x11_window_get_toplevel (GdkWindow *window)
144 GdkWindowImplX11 *impl;
146 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
148 if (!WINDOW_IS_TOPLEVEL (window))
151 impl = GDK_WINDOW_IMPL_X11 (window->impl);
154 impl->toplevel = g_new0 (GdkToplevelX11, 1);
156 return impl->toplevel;
159 static const cairo_user_data_key_t gdk_x11_cairo_key;
162 * _gdk_x11_window_update_size:
163 * @impl: a #GdkWindowImplX11.
165 * Updates the state of the window (in particular the drawable's
166 * cairo surface) when its size has changed.
169 _gdk_x11_window_update_size (GdkWindowImplX11 *impl)
171 if (impl->cairo_surface)
173 cairo_xlib_surface_set_size (impl->cairo_surface,
174 gdk_window_get_width (impl->wrapper),
175 gdk_window_get_height (impl->wrapper));
179 /*****************************************************
180 * X11 specific implementations of generic functions *
181 *****************************************************/
184 gdk_x11_cairo_surface_destroy (void *data)
186 GdkWindowImplX11 *impl = data;
188 impl->cairo_surface = NULL;
191 static cairo_surface_t *
192 gdk_x11_create_cairo_surface (GdkWindowImplX11 *impl,
198 visual = gdk_window_get_visual (impl->wrapper);
199 return cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (impl->wrapper),
200 GDK_WINDOW_IMPL_X11 (impl)->xid,
201 GDK_VISUAL_XVISUAL (visual),
205 static cairo_surface_t *
206 gdk_x11_ref_cairo_surface (GdkWindow *window)
208 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
210 if (GDK_WINDOW_DESTROYED (window))
213 if (!impl->cairo_surface)
215 impl->cairo_surface = gdk_x11_create_cairo_surface (impl,
216 gdk_window_get_width (window),
217 gdk_window_get_height (window));
219 if (impl->cairo_surface)
220 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
221 impl, gdk_x11_cairo_surface_destroy);
224 cairo_surface_reference (impl->cairo_surface);
226 return impl->cairo_surface;
230 gdk_window_impl_x11_finalize (GObject *object)
233 GdkWindowImplX11 *impl;
235 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
237 impl = GDK_WINDOW_IMPL_X11 (object);
239 wrapper = impl->wrapper;
241 _gdk_x11_window_grab_check_destroy (wrapper);
243 if (!GDK_WINDOW_DESTROYED (wrapper))
245 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
247 _gdk_x11_display_remove_window (display, impl->xid);
248 if (impl->toplevel && impl->toplevel->focus_window)
249 _gdk_x11_display_remove_window (display, impl->toplevel->focus_window);
252 g_free (impl->toplevel);
255 gdk_cursor_unref (impl->cursor);
257 g_hash_table_destroy (impl->device_cursor);
259 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
268 free_pixmap (gpointer datap)
270 FreePixmapData *data = datap;
272 if (!gdk_display_is_closed (data->display))
274 XFreePixmap (GDK_DISPLAY_XDISPLAY (data->display),
278 g_object_unref (data->display);
279 g_slice_free (FreePixmapData, data);
283 attach_free_pixmap_handler (cairo_surface_t *surface,
287 static const cairo_user_data_key_t key;
288 FreePixmapData *data;
290 data = g_slice_new (FreePixmapData);
291 data->display = g_object_ref (display);
292 data->pixmap = pixmap;
294 cairo_surface_set_user_data (surface, &key, data, free_pixmap);
297 /* Cairo does not guarantee we get an xlib surface if we call
298 * cairo_surface_create_similar(). In some cases however, we must use a
299 * pixmap or bitmap in the X11 API.
300 * These functions ensure an Xlib surface.
303 _gdk_x11_window_create_bitmap_surface (GdkWindow *window,
307 cairo_surface_t *surface;
310 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
311 GDK_WINDOW_XID (window),
313 surface = cairo_xlib_surface_create_for_bitmap (GDK_WINDOW_XDISPLAY (window),
315 GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (window))->xscreen,
317 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
322 /* Create a surface backed with a pixmap without alpha on the same screen as window */
323 static cairo_surface_t *
324 gdk_x11_window_create_pixmap_surface (GdkWindow *window,
328 GdkScreen *screen = gdk_window_get_screen (window);
329 GdkVisual *visual = gdk_screen_get_system_visual (screen);
330 cairo_surface_t *surface;
333 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
334 GDK_WINDOW_XID (window),
336 gdk_visual_get_depth (visual));
337 surface = cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (window),
339 GDK_VISUAL_XVISUAL (visual),
341 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
347 tmp_unset_bg (GdkWindow *window)
349 GdkWindowImplX11 *impl;
351 impl = GDK_WINDOW_IMPL_X11 (window->impl);
355 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
356 GDK_WINDOW_XID (window), None);
360 tmp_reset_bg (GdkWindow *window)
362 GdkWindowImplX11 *impl;
364 impl = GDK_WINDOW_IMPL_X11 (window->impl);
368 gdk_window_x11_set_background (window, window->background);
371 /* Unsetting and resetting window backgrounds.
373 * In many cases it is possible to avoid flicker by unsetting the
374 * background of windows. For example if the background of the
375 * parent window is unset when a window is unmapped, a brief flicker
376 * of background painting is avoided.
379 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
382 g_return_if_fail (GDK_IS_WINDOW (window));
384 if (window->input_only || window->destroyed ||
385 (window->window_type != GDK_WINDOW_ROOT &&
386 !GDK_WINDOW_IS_MAPPED (window)))
389 if (_gdk_window_has_impl (window) &&
390 GDK_WINDOW_IS_X11 (window) &&
391 window->window_type != GDK_WINDOW_ROOT &&
392 window->window_type != GDK_WINDOW_FOREIGN)
393 tmp_unset_bg (window);
399 for (l = window->children; l != NULL; l = l->next)
400 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
405 _gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window)
407 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
410 window = _gdk_window_get_impl_window (window->parent);
411 _gdk_x11_window_tmp_unset_bg (window, FALSE);
415 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
418 g_return_if_fail (GDK_IS_WINDOW (window));
420 if (window->input_only || window->destroyed ||
421 (window->window_type != GDK_WINDOW_ROOT &&
422 !GDK_WINDOW_IS_MAPPED (window)))
426 if (_gdk_window_has_impl (window) &&
427 GDK_WINDOW_IS_X11 (window) &&
428 window->window_type != GDK_WINDOW_ROOT &&
429 window->window_type != GDK_WINDOW_FOREIGN)
430 tmp_reset_bg (window);
436 for (l = window->children; l != NULL; l = l->next)
437 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
442 _gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window)
444 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
447 window = _gdk_window_get_impl_window (window->parent);
449 _gdk_x11_window_tmp_reset_bg (window, FALSE);
453 _gdk_x11_screen_init_root_window (GdkScreen *screen)
456 GdkWindowImplX11 *impl;
457 GdkScreenX11 *screen_x11;
459 screen_x11 = GDK_SCREEN_X11 (screen);
461 g_assert (screen_x11->root_window == NULL);
463 window = screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
465 window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
466 window->impl_window = window;
467 window->visual = gdk_screen_get_system_visual (screen);
469 impl = GDK_WINDOW_IMPL_X11 (window->impl);
471 impl->xid = screen_x11->xroot_window;
472 impl->wrapper = window;
474 window->window_type = GDK_WINDOW_ROOT;
475 window->depth = DefaultDepthOfScreen (screen_x11->xscreen);
481 window->width = WidthOfScreen (screen_x11->xscreen);
482 window->height = HeightOfScreen (screen_x11->xscreen);
483 window->viewable = TRUE;
485 /* see init_randr_support() in gdkscreen-x11.c */
486 window->event_mask = GDK_STRUCTURE_MASK;
488 _gdk_window_update_size (screen_x11->root_window);
490 _gdk_x11_display_add_window (screen_x11->display,
491 &screen_x11->xroot_window,
492 screen_x11->root_window);
496 set_wm_protocols (GdkWindow *window)
498 GdkDisplay *display = gdk_window_get_display (window);
502 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
503 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
504 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
507 if (GDK_DISPLAY_X11 (display)->use_sync)
508 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
511 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
515 get_default_title (void)
519 title = g_get_application_name ();
521 title = g_get_prgname ();
529 check_leader_window_title (GdkDisplay *display)
531 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
533 if (display_x11->leader_window && !display_x11->leader_window_title_set)
535 set_wm_name (display,
536 display_x11->leader_window,
537 get_default_title ());
539 display_x11->leader_window_title_set = TRUE;
544 create_focus_window (GdkDisplay *display,
547 GdkDisplayX11 *display_x11;
548 GdkEventMask event_mask;
552 xdisplay = GDK_DISPLAY_XDISPLAY (display);
553 display_x11 = GDK_DISPLAY_X11 (display);
555 focus_window = XCreateSimpleWindow (xdisplay, parent,
559 /* FIXME: probably better to actually track the requested event mask for the toplevel
561 event_mask = (GDK_KEY_PRESS_MASK |
562 GDK_KEY_RELEASE_MASK |
563 GDK_FOCUS_CHANGE_MASK);
565 gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
569 XMapWindow (xdisplay, focus_window);
575 ensure_sync_counter (GdkWindow *window)
578 if (!GDK_WINDOW_DESTROYED (window))
580 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
581 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
582 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
584 if (toplevel && impl->use_synchronized_configure &&
585 toplevel->update_counter == None &&
586 GDK_DISPLAY_X11 (display)->use_sync)
588 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
592 XSyncIntToValue (&value, 0);
594 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
596 atom = gdk_x11_get_xatom_by_name_for_display (display,
597 "_NET_WM_SYNC_REQUEST_COUNTER");
599 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
602 (guchar *)&toplevel->update_counter, 1);
604 XSyncIntToValue (&toplevel->current_counter_value, 0);
611 setup_toplevel_window (GdkWindow *window,
614 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
615 GdkDisplay *display = gdk_window_get_display (window);
616 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
617 XID xid = GDK_WINDOW_XID (window);
618 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
619 XSizeHints size_hints;
621 Window leader_window;
623 set_wm_protocols (window);
625 if (!window->input_only)
627 /* The focus window is off the visible area, and serves to receive key
628 * press events so they don't get sent to child windows.
630 toplevel->focus_window = create_focus_window (display, xid);
631 _gdk_x11_display_add_window (screen_x11->display,
632 &toplevel->focus_window,
636 check_leader_window_title (screen_x11->display);
638 /* FIXME: Is there any point in doing this? Do any WM's pay
639 * attention to PSize, and even if they do, is this the
642 size_hints.flags = PSize;
643 size_hints.width = window->width;
644 size_hints.height = window->height;
646 XSetWMNormalHints (xdisplay, xid, &size_hints);
648 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
649 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
652 XChangeProperty (xdisplay, xid,
653 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
658 leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
661 XChangeProperty (xdisplay, xid,
662 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
663 XA_WINDOW, 32, PropModeReplace,
664 (guchar *) &leader_window, 1);
666 if (toplevel->focus_window != None)
667 XChangeProperty (xdisplay, xid,
668 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_USER_TIME_WINDOW"),
669 XA_WINDOW, 32, PropModeReplace,
670 (guchar *) &toplevel->focus_window, 1);
672 if (!window->focus_on_map)
673 gdk_x11_window_set_user_time (window, 0);
674 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
675 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
677 ensure_sync_counter (window);
681 _gdk_x11_display_create_window_impl (GdkDisplay *display,
683 GdkWindow *real_parent,
685 GdkEventMask event_mask,
686 GdkWindowAttr *attributes,
687 gint attributes_mask)
689 GdkWindowImplX11 *impl;
690 GdkScreenX11 *screen_x11;
691 GdkDisplayX11 *display_x11;
697 XSetWindowAttributes xattributes;
698 long xattributes_mask;
699 XClassHint *class_hint;
704 display_x11 = GDK_DISPLAY_X11 (display);
705 xparent = GDK_WINDOW_XID (real_parent);
706 screen_x11 = GDK_SCREEN_X11 (screen);
708 impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
709 window->impl = GDK_WINDOW_IMPL (impl);
710 impl->wrapper = GDK_WINDOW (window);
712 xdisplay = screen_x11->xdisplay;
714 xattributes_mask = 0;
716 xvisual = gdk_x11_visual_get_xvisual (window->visual);
718 if (attributes_mask & GDK_WA_NOREDIR)
720 xattributes.override_redirect =
721 (attributes->override_redirect == FALSE)?False:True;
722 xattributes_mask |= CWOverrideRedirect;
725 xattributes.override_redirect = False;
727 impl->override_redirect = xattributes.override_redirect;
729 if (window->parent && window->parent->guffaw_gravity)
731 xattributes.win_gravity = StaticGravity;
732 xattributes_mask |= CWWinGravity;
736 switch (window->window_type)
738 case GDK_WINDOW_TOPLEVEL:
739 case GDK_WINDOW_TEMP:
740 if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT)
742 /* The common code warns for this case */
743 xparent = GDK_SCREEN_XROOTWIN (screen);
747 if (!window->input_only)
751 xattributes.background_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
753 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
754 xattributes_mask |= CWBorderPixel | CWBackPixel;
756 if (window->guffaw_gravity)
757 xattributes.bit_gravity = StaticGravity;
759 xattributes.bit_gravity = NorthWestGravity;
761 xattributes_mask |= CWBitGravity;
763 xattributes.colormap = _gdk_visual_get_x11_colormap (window->visual);
764 xattributes_mask |= CWColormap;
766 if (window->window_type == GDK_WINDOW_TEMP)
768 xattributes.save_under = True;
769 xattributes.override_redirect = True;
770 xattributes.cursor = None;
771 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
773 impl->override_redirect = TRUE;
781 if (window->width > 65535 ||
782 window->height > 65535)
784 g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
786 if (window->width > 65535)
787 window->width = 65535;
788 if (window->height > 65535)
789 window->height = 65535;
792 impl->xid = XCreateWindow (xdisplay, xparent,
793 window->x + window->parent->abs_x,
794 window->y + window->parent->abs_y,
795 window->width, window->height,
796 0, window->depth, class, xvisual,
797 xattributes_mask, &xattributes);
799 g_object_ref (window);
800 _gdk_x11_display_add_window (screen_x11->display, &impl->xid, window);
802 switch (GDK_WINDOW_TYPE (window))
804 case GDK_WINDOW_TOPLEVEL:
805 case GDK_WINDOW_TEMP:
806 if (attributes_mask & GDK_WA_TITLE)
807 title = attributes->title;
809 title = get_default_title ();
811 gdk_window_set_title (window, title);
813 if (attributes_mask & GDK_WA_WMCLASS)
815 class_hint = XAllocClassHint ();
816 class_hint->res_name = attributes->wmclass_name;
817 class_hint->res_class = attributes->wmclass_class;
818 XSetClassHint (xdisplay, impl->xid, class_hint);
822 setup_toplevel_window (window, window->parent);
825 case GDK_WINDOW_CHILD:
830 if (attributes_mask & GDK_WA_TYPE_HINT)
831 gdk_window_set_type_hint (window, attributes->type_hint);
833 gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
834 GDK_WINDOW_XID (window), event_mask,
835 StructureNotifyMask | PropertyChangeMask);
839 x_event_mask_to_gdk_event_mask (long mask)
841 GdkEventMask event_mask = 0;
844 for (i = 0; i < _gdk_x11_event_mask_table_size; i++)
846 if (mask & _gdk_x11_event_mask_table[i])
847 event_mask |= 1 << (i + 1);
854 * gdk_x11_window_foreign_new_for_display:
855 * @display: the #GdkDisplay where the window handle comes from.
856 * @window: an XLib <type>Window</type>
858 * Wraps a native window in a #GdkWindow.
860 * This may fail if the window has been destroyed. If the window
861 * was already known to GDK, a new reference to the existing
862 * #GdkWindow is returned.
864 * Return value: (transfer full): a #GdkWindow wrapper for the native
865 * window, or %NULL if the window has been destroyed. The wrapper
866 * will be newly created, if one doesn't exist already.
871 gdk_x11_window_foreign_new_for_display (GdkDisplay *display,
876 GdkWindowImplX11 *impl;
877 GdkDisplayX11 *display_x11;
878 XWindowAttributes attrs;
880 Window *children = NULL;
884 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
886 display_x11 = GDK_DISPLAY_X11 (display);
888 if ((win = gdk_x11_window_lookup_for_display (display, window)) != NULL)
889 return g_object_ref (win);
891 gdk_x11_display_error_trap_push (display);
892 result = XGetWindowAttributes (display_x11->xdisplay, window, &attrs);
893 if (gdk_x11_display_error_trap_pop (display) || !result)
896 /* FIXME: This is pretty expensive.
897 * Maybe the caller should supply the parent
899 gdk_x11_display_error_trap_push (display);
900 result = XQueryTree (display_x11->xdisplay, window, &root, &parent, &children, &nchildren);
901 if (gdk_x11_display_error_trap_pop (display) || !result)
907 screen = _gdk_x11_display_screen_for_xrootwin (display, root);
909 win = g_object_new (GDK_TYPE_WINDOW, NULL);
910 win->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
911 win->impl_window = win;
912 win->visual = gdk_x11_screen_lookup_visual (screen,
913 XVisualIDFromVisual (attrs.visual));
915 impl = GDK_WINDOW_IMPL_X11 (win->impl);
918 win->parent = gdk_x11_window_lookup_for_display (display, parent);
920 if (!win->parent || GDK_WINDOW_TYPE (win->parent) == GDK_WINDOW_FOREIGN)
921 win->parent = gdk_screen_get_root_window (screen);
923 win->parent->children = g_list_prepend (win->parent->children, win);
929 win->width = attrs.width;
930 win->height = attrs.height;
931 win->window_type = GDK_WINDOW_FOREIGN;
932 win->destroyed = FALSE;
934 win->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
936 if (attrs.map_state == IsUnmapped)
937 win->state = GDK_WINDOW_STATE_WITHDRAWN;
940 win->viewable = TRUE;
942 win->depth = attrs.depth;
945 _gdk_x11_display_add_window (display, &GDK_WINDOW_XID (win), win);
947 /* Update the clip region, etc */
948 _gdk_window_update_size (win);
954 gdk_toplevel_x11_free_contents (GdkDisplay *display,
955 GdkToplevelX11 *toplevel)
957 if (toplevel->icon_pixmap)
959 cairo_surface_destroy (toplevel->icon_pixmap);
960 toplevel->icon_pixmap = NULL;
962 if (toplevel->icon_mask)
964 cairo_surface_destroy (toplevel->icon_mask);
965 toplevel->icon_mask = NULL;
967 if (toplevel->group_leader)
969 g_object_unref (toplevel->group_leader);
970 toplevel->group_leader = NULL;
973 if (toplevel->update_counter != None)
975 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
976 toplevel->update_counter);
977 toplevel->update_counter = None;
979 XSyncIntToValue (&toplevel->current_counter_value, 0);
985 gdk_x11_window_destroy (GdkWindow *window,
987 gboolean foreign_destroy)
989 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
990 GdkToplevelX11 *toplevel;
992 g_return_if_fail (GDK_IS_WINDOW (window));
994 _gdk_selection_window_destroyed (window);
996 toplevel = _gdk_x11_window_get_toplevel (window);
998 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1000 if (impl->cairo_surface)
1002 cairo_surface_finish (impl->cairo_surface);
1003 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
1007 if (!recursing && !foreign_destroy)
1008 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1011 static cairo_surface_t *
1012 gdk_window_x11_resize_cairo_surface (GdkWindow *window,
1013 cairo_surface_t *surface,
1017 cairo_xlib_surface_set_size (surface, width, height);
1023 gdk_x11_window_destroy_foreign (GdkWindow *window)
1025 /* It's somebody else's window, but in our hierarchy,
1026 * so reparent it to the root window, and then send
1027 * it a delete event, as if we were a WM
1029 XClientMessageEvent xclient;
1030 GdkDisplay *display;
1032 display = GDK_WINDOW_DISPLAY (window);
1033 gdk_x11_display_error_trap_push (display);
1034 gdk_window_hide (window);
1035 gdk_window_reparent (window, NULL, 0, 0);
1037 memset (&xclient, 0, sizeof (xclient));
1038 xclient.type = ClientMessage;
1039 xclient.window = GDK_WINDOW_XID (window);
1040 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "WM_PROTOCOLS");
1041 xclient.format = 32;
1042 xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
1043 xclient.data.l[1] = CurrentTime;
1044 xclient.data.l[2] = 0;
1045 xclient.data.l[3] = 0;
1046 xclient.data.l[4] = 0;
1048 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1049 GDK_WINDOW_XID (window),
1050 False, 0, (XEvent *)&xclient);
1051 gdk_x11_display_error_trap_pop_ignored (display);
1055 get_root (GdkWindow *window)
1057 GdkScreen *screen = gdk_window_get_screen (window);
1059 return gdk_screen_get_root_window (screen);
1062 /* This function is called when the XWindow is really gone.
1065 gdk_x11_window_destroy_notify (GdkWindow *window)
1067 GdkWindowImplX11 *window_impl;
1069 window_impl = GDK_WINDOW_IMPL_X11 ((window)->impl);
1071 if (!GDK_WINDOW_DESTROYED (window))
1073 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1074 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1076 _gdk_window_destroy (window, TRUE);
1079 _gdk_x11_display_remove_window (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1080 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1081 _gdk_x11_display_remove_window (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1083 _gdk_x11_window_grab_check_destroy (window);
1085 g_object_unref (window);
1089 update_wm_hints (GdkWindow *window,
1092 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1093 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1097 !toplevel->is_leader &&
1098 window->state & GDK_WINDOW_STATE_WITHDRAWN)
1101 wm_hints.flags = StateHint | InputHint;
1102 wm_hints.input = window->accept_focus ? True : False;
1103 wm_hints.initial_state = NormalState;
1105 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
1107 wm_hints.flags |= StateHint;
1108 wm_hints.initial_state = IconicState;
1111 if (toplevel->icon_pixmap)
1113 wm_hints.flags |= IconPixmapHint;
1114 wm_hints.icon_pixmap = cairo_xlib_surface_get_drawable (toplevel->icon_pixmap);
1117 if (toplevel->icon_mask)
1119 wm_hints.flags |= IconMaskHint;
1120 wm_hints.icon_mask = cairo_xlib_surface_get_drawable (toplevel->icon_mask);
1123 wm_hints.flags |= WindowGroupHint;
1124 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1126 wm_hints.flags |= WindowGroupHint;
1127 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1130 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1132 if (toplevel->urgency_hint)
1133 wm_hints.flags |= XUrgencyHint;
1135 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1136 GDK_WINDOW_XID (window),
1141 set_initial_hints (GdkWindow *window)
1143 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1144 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1145 Window xwindow = GDK_WINDOW_XID (window);
1146 GdkToplevelX11 *toplevel;
1150 toplevel = _gdk_x11_window_get_toplevel (window);
1155 update_wm_hints (window, TRUE);
1157 /* We set the spec hints regardless of whether the spec is supported,
1158 * since it can't hurt and it's kind of expensive to check whether
1164 if (window->state & GDK_WINDOW_STATE_MAXIMIZED)
1166 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1167 "_NET_WM_STATE_MAXIMIZED_VERT");
1169 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1170 "_NET_WM_STATE_MAXIMIZED_HORZ");
1172 toplevel->have_maxhorz = toplevel->have_maxvert = TRUE;
1175 if (window->state & GDK_WINDOW_STATE_ABOVE)
1177 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1178 "_NET_WM_STATE_ABOVE");
1182 if (window->state & GDK_WINDOW_STATE_BELOW)
1184 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1185 "_NET_WM_STATE_BELOW");
1189 if (window->state & GDK_WINDOW_STATE_STICKY)
1191 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1192 "_NET_WM_STATE_STICKY");
1194 toplevel->have_sticky = TRUE;
1197 if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
1199 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1200 "_NET_WM_STATE_FULLSCREEN");
1202 toplevel->have_fullscreen = TRUE;
1205 if (window->modal_hint)
1207 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1208 "_NET_WM_STATE_MODAL");
1212 if (toplevel->skip_taskbar_hint)
1214 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1215 "_NET_WM_STATE_SKIP_TASKBAR");
1219 if (toplevel->skip_pager_hint)
1221 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1222 "_NET_WM_STATE_SKIP_PAGER");
1228 XChangeProperty (xdisplay,
1230 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1231 XA_ATOM, 32, PropModeReplace,
1232 (guchar*) atoms, i);
1236 XDeleteProperty (xdisplay,
1238 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1241 if (window->state & GDK_WINDOW_STATE_STICKY)
1243 atoms[0] = 0xFFFFFFFF;
1244 XChangeProperty (xdisplay,
1246 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1247 XA_CARDINAL, 32, PropModeReplace,
1248 (guchar*) atoms, 1);
1249 toplevel->on_all_desktops = TRUE;
1253 XDeleteProperty (xdisplay,
1255 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1258 toplevel->map_serial = NextRequest (xdisplay);
1262 gdk_window_x11_show (GdkWindow *window, gboolean already_mapped)
1264 GdkDisplay *display;
1265 GdkDisplayX11 *display_x11;
1266 GdkToplevelX11 *toplevel;
1267 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1268 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1269 Window xwindow = GDK_WINDOW_XID (window);
1272 if (!already_mapped)
1273 set_initial_hints (window);
1275 if (WINDOW_IS_TOPLEVEL (window))
1277 display = gdk_window_get_display (window);
1278 display_x11 = GDK_DISPLAY_X11 (display);
1279 toplevel = _gdk_x11_window_get_toplevel (window);
1281 if (toplevel->user_time != 0 &&
1282 display_x11->user_time != 0 &&
1283 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1284 gdk_x11_window_set_user_time (window, display_x11->user_time);
1287 unset_bg = !window->input_only &&
1288 (window->window_type == GDK_WINDOW_CHILD ||
1289 impl->override_redirect) &&
1290 gdk_window_is_viewable (window);
1293 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1295 XMapWindow (xdisplay, xwindow);
1298 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1302 pre_unmap (GdkWindow *window)
1304 GdkWindow *start_window = NULL;
1306 if (window->input_only)
1309 if (window->window_type == GDK_WINDOW_CHILD)
1310 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1311 else if (window->window_type == GDK_WINDOW_TEMP)
1312 start_window = get_root (window);
1315 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1319 post_unmap (GdkWindow *window)
1321 GdkWindow *start_window = NULL;
1323 if (window->input_only)
1326 if (window->window_type == GDK_WINDOW_CHILD)
1327 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1328 else if (window->window_type == GDK_WINDOW_TEMP)
1329 start_window = get_root (window);
1333 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1335 if (window->window_type == GDK_WINDOW_CHILD && window->parent)
1337 GdkRectangle invalid_rect;
1339 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1340 invalid_rect.width = gdk_window_get_width (window);
1341 invalid_rect.height = gdk_window_get_height (window);
1342 gdk_window_invalidate_rect ((GdkWindow *)window->parent,
1343 &invalid_rect, TRUE);
1349 gdk_window_x11_hide (GdkWindow *window)
1351 /* We'll get the unmap notify eventually, and handle it then,
1352 * but checking here makes things more consistent if we are
1353 * just doing stuff ourself.
1355 _gdk_x11_window_grab_check_unmap (window,
1356 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1358 /* You can't simply unmap toplevel windows. */
1359 switch (window->window_type)
1361 case GDK_WINDOW_TOPLEVEL:
1362 case GDK_WINDOW_TEMP: /* ? */
1363 gdk_window_withdraw (window);
1366 case GDK_WINDOW_FOREIGN:
1367 case GDK_WINDOW_ROOT:
1368 case GDK_WINDOW_CHILD:
1372 _gdk_window_clear_update_area (window);
1375 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1376 GDK_WINDOW_XID (window));
1377 post_unmap (window);
1381 gdk_window_x11_withdraw (GdkWindow *window)
1383 if (!window->destroyed)
1385 if (GDK_WINDOW_IS_MAPPED (window))
1386 gdk_synthesize_window_state (window,
1388 GDK_WINDOW_STATE_WITHDRAWN);
1390 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1394 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1395 GDK_WINDOW_XID (window), 0);
1397 post_unmap (window);
1402 window_x11_move (GdkWindow *window,
1406 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1408 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1410 _gdk_x11_window_move_resize_child (window,
1412 window->width, window->height);
1416 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1417 GDK_WINDOW_XID (window),
1420 if (impl->override_redirect)
1429 window_x11_resize (GdkWindow *window,
1439 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1441 _gdk_x11_window_move_resize_child (window,
1442 window->x, window->y,
1447 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1449 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1450 GDK_WINDOW_XID (window),
1453 if (impl->override_redirect)
1455 window->width = width;
1456 window->height = height;
1457 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1461 if (width != window->width || height != window->height)
1462 window->resize_count += 1;
1466 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1470 window_x11_move_resize (GdkWindow *window,
1482 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1484 _gdk_x11_window_move_resize_child (window, x, y, width, height);
1485 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1489 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1491 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1492 GDK_WINDOW_XID (window),
1493 x, y, width, height);
1495 if (impl->override_redirect)
1500 window->width = width;
1501 window->height = height;
1503 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1507 if (width != window->width || height != window->height)
1508 window->resize_count += 1;
1514 gdk_window_x11_move_resize (GdkWindow *window,
1521 if (with_move && (width < 0 && height < 0))
1522 window_x11_move (window, x, y);
1526 window_x11_move_resize (window, x, y, width, height);
1528 window_x11_resize (window, width, height);
1533 gdk_window_x11_reparent (GdkWindow *window,
1534 GdkWindow *new_parent,
1538 GdkWindowImplX11 *impl;
1540 impl = GDK_WINDOW_IMPL_X11 (window->impl);
1542 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1543 _gdk_x11_window_tmp_unset_parent_bg (window);
1544 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1545 GDK_WINDOW_XID (window),
1546 GDK_WINDOW_XID (new_parent),
1547 new_parent->abs_x + x, new_parent->abs_y + y);
1548 _gdk_x11_window_tmp_reset_parent_bg (window);
1549 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1551 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1552 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1554 window->parent = new_parent;
1556 /* Switch the window type as appropriate */
1558 switch (GDK_WINDOW_TYPE (new_parent))
1560 case GDK_WINDOW_ROOT:
1561 case GDK_WINDOW_FOREIGN:
1562 /* Reparenting to toplevel */
1564 if (!WINDOW_IS_TOPLEVEL (window) &&
1565 GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1567 /* This is also done in common code at a later stage, but we
1568 need it in setup_toplevel, so do it here too */
1569 if (window->toplevel_window_type != -1)
1570 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1571 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1572 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1574 /* Wasn't a toplevel, set up */
1575 setup_toplevel_window (window, new_parent);
1580 case GDK_WINDOW_TOPLEVEL:
1581 case GDK_WINDOW_CHILD:
1582 case GDK_WINDOW_TEMP:
1583 if (WINDOW_IS_TOPLEVEL (window) &&
1586 if (impl->toplevel->focus_window)
1588 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1589 _gdk_x11_display_remove_window (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1592 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1594 g_free (impl->toplevel);
1595 impl->toplevel = NULL;
1603 gdk_window_x11_raise (GdkWindow *window)
1605 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1609 gdk_window_x11_restack_under (GdkWindow *window,
1610 GList *native_siblings /* in requested order, first is bottom-most */)
1616 n_windows = g_list_length (native_siblings) + 1;
1617 windows = g_new (Window, n_windows);
1619 windows[0] = GDK_WINDOW_XID (window);
1620 /* Reverse order, as input order is bottom-most first */
1622 for (l = native_siblings; l != NULL; l = l->next)
1623 windows[i--] = GDK_WINDOW_XID (l->data);
1625 XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows);
1631 gdk_window_x11_restack_toplevel (GdkWindow *window,
1635 XWindowChanges changes;
1637 changes.sibling = GDK_WINDOW_XID (sibling);
1638 changes.stack_mode = above ? Above : Below;
1639 XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window),
1640 GDK_WINDOW_XID (window),
1641 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)),
1642 CWStackMode | CWSibling, &changes);
1646 gdk_window_x11_lower (GdkWindow *window)
1648 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1652 * gdk_x11_window_move_to_current_desktop:
1653 * @window: a #GdkWindow
1655 * Moves the window to the correct workspace when running under a
1656 * window manager that supports multiple workspaces, as described
1657 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
1658 * Window Manager Hints</ulink>. Will not do anything if the
1659 * window is already on all workspaces.
1664 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
1666 GdkToplevelX11 *toplevel;
1668 g_return_if_fail (GDK_IS_WINDOW (window));
1669 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1671 toplevel = _gdk_x11_window_get_toplevel (window);
1673 if (toplevel->on_all_desktops)
1676 move_to_current_desktop (window);
1680 move_to_current_desktop (GdkWindow *window)
1682 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1683 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
1690 gulong *current_desktop;
1691 GdkDisplay *display;
1693 display = gdk_window_get_display (window);
1695 /* Get current desktop, then set it; this is a race, but not
1696 * one that matters much in practice.
1698 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
1699 GDK_WINDOW_XROOTWIN (window),
1700 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
1702 False, XA_CARDINAL, &type, &format, &nitems,
1703 &bytes_after, &data);
1705 if (type == XA_CARDINAL)
1707 XClientMessageEvent xclient;
1708 current_desktop = (gulong *)data;
1710 memset (&xclient, 0, sizeof (xclient));
1711 xclient.type = ClientMessage;
1713 xclient.send_event = True;
1714 xclient.window = GDK_WINDOW_XID (window);
1715 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
1716 xclient.format = 32;
1718 xclient.data.l[0] = *current_desktop;
1719 xclient.data.l[1] = 0;
1720 xclient.data.l[2] = 0;
1721 xclient.data.l[3] = 0;
1722 xclient.data.l[4] = 0;
1724 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
1725 GDK_WINDOW_XROOTWIN (window),
1727 SubstructureRedirectMask | SubstructureNotifyMask,
1728 (XEvent *)&xclient);
1730 XFree (current_desktop);
1736 gdk_x11_window_focus (GdkWindow *window,
1739 GdkDisplay *display;
1741 g_return_if_fail (GDK_IS_WINDOW (window));
1743 if (GDK_WINDOW_DESTROYED (window) ||
1744 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1747 display = GDK_WINDOW_DISPLAY (window);
1749 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1750 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1752 XClientMessageEvent xclient;
1754 memset (&xclient, 0, sizeof (xclient));
1755 xclient.type = ClientMessage;
1756 xclient.window = GDK_WINDOW_XID (window);
1757 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1758 "_NET_ACTIVE_WINDOW");
1759 xclient.format = 32;
1760 xclient.data.l[0] = 1; /* requestor type; we're an app */
1761 xclient.data.l[1] = timestamp;
1762 xclient.data.l[2] = None; /* currently active window */
1763 xclient.data.l[3] = 0;
1764 xclient.data.l[4] = 0;
1766 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1767 SubstructureRedirectMask | SubstructureNotifyMask,
1768 (XEvent *)&xclient);
1772 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1774 /* There is no way of knowing reliably whether we are viewable;
1775 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1777 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1784 gdk_x11_window_set_type_hint (GdkWindow *window,
1785 GdkWindowTypeHint hint)
1787 GdkDisplay *display;
1790 if (GDK_WINDOW_DESTROYED (window) ||
1791 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1794 display = gdk_window_get_display (window);
1798 case GDK_WINDOW_TYPE_HINT_DIALOG:
1799 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1801 case GDK_WINDOW_TYPE_HINT_MENU:
1802 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1804 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1805 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1807 case GDK_WINDOW_TYPE_HINT_UTILITY:
1808 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1810 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1811 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1813 case GDK_WINDOW_TYPE_HINT_DOCK:
1814 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1816 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1817 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1819 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
1820 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
1822 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
1823 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
1825 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
1826 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
1828 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
1829 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
1831 case GDK_WINDOW_TYPE_HINT_COMBO:
1832 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
1834 case GDK_WINDOW_TYPE_HINT_DND:
1835 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
1838 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1840 case GDK_WINDOW_TYPE_HINT_NORMAL:
1841 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1845 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1846 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1847 XA_ATOM, 32, PropModeReplace,
1848 (guchar *)&atom, 1);
1851 static GdkWindowTypeHint
1852 gdk_x11_window_get_type_hint (GdkWindow *window)
1854 GdkDisplay *display;
1855 GdkWindowTypeHint type;
1858 gulong nitems_return;
1859 gulong bytes_after_return;
1860 guchar *data = NULL;
1862 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
1864 if (GDK_WINDOW_DESTROYED (window) ||
1865 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1866 return GDK_WINDOW_TYPE_HINT_NORMAL;
1868 type = GDK_WINDOW_TYPE_HINT_NORMAL;
1870 display = gdk_window_get_display (window);
1872 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1873 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1874 0, G_MAXLONG, False, XA_ATOM, &type_return,
1875 &format_return, &nitems_return, &bytes_after_return,
1878 if ((type_return == XA_ATOM) && (format_return == 32) &&
1879 (data) && (nitems_return == 1))
1881 Atom atom = *(Atom*)data;
1883 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
1884 type = GDK_WINDOW_TYPE_HINT_DIALOG;
1885 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
1886 type = GDK_WINDOW_TYPE_HINT_MENU;
1887 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
1888 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
1889 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
1890 type = GDK_WINDOW_TYPE_HINT_UTILITY;
1891 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
1892 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
1893 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
1894 type = GDK_WINDOW_TYPE_HINT_DOCK;
1895 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
1896 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
1897 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
1898 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
1899 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
1900 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
1901 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
1902 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
1903 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
1904 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
1905 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
1906 type = GDK_WINDOW_TYPE_HINT_COMBO;
1907 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
1908 type = GDK_WINDOW_TYPE_HINT_DND;
1911 if (type_return != None && data != NULL)
1919 gdk_wmspec_change_state (gboolean add,
1924 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1925 XClientMessageEvent xclient;
1927 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1928 #define _NET_WM_STATE_ADD 1 /* add/set property */
1929 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1931 memset (&xclient, 0, sizeof (xclient));
1932 xclient.type = ClientMessage;
1933 xclient.window = GDK_WINDOW_XID (window);
1934 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1935 xclient.format = 32;
1936 xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1937 xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1938 xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1939 xclient.data.l[3] = 0;
1940 xclient.data.l[4] = 0;
1942 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1943 SubstructureRedirectMask | SubstructureNotifyMask,
1944 (XEvent *)&xclient);
1948 gdk_x11_window_set_modal_hint (GdkWindow *window,
1951 if (GDK_WINDOW_DESTROYED (window) ||
1952 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1955 window->modal_hint = modal;
1957 if (GDK_WINDOW_IS_MAPPED (window))
1958 gdk_wmspec_change_state (modal, window,
1959 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
1964 gdk_x11_window_set_skip_taskbar_hint (GdkWindow *window,
1965 gboolean skips_taskbar)
1967 GdkToplevelX11 *toplevel;
1969 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1971 if (GDK_WINDOW_DESTROYED (window) ||
1972 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1975 toplevel = _gdk_x11_window_get_toplevel (window);
1976 toplevel->skip_taskbar_hint = skips_taskbar;
1978 if (GDK_WINDOW_IS_MAPPED (window))
1979 gdk_wmspec_change_state (skips_taskbar, window,
1980 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
1985 gdk_x11_window_set_skip_pager_hint (GdkWindow *window,
1986 gboolean skips_pager)
1988 GdkToplevelX11 *toplevel;
1990 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1992 if (GDK_WINDOW_DESTROYED (window) ||
1993 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1996 toplevel = _gdk_x11_window_get_toplevel (window);
1997 toplevel->skip_pager_hint = skips_pager;
1999 if (GDK_WINDOW_IS_MAPPED (window))
2000 gdk_wmspec_change_state (skips_pager, window,
2001 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2006 gdk_x11_window_set_urgency_hint (GdkWindow *window,
2009 GdkToplevelX11 *toplevel;
2011 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2013 if (GDK_WINDOW_DESTROYED (window) ||
2014 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2017 toplevel = _gdk_x11_window_get_toplevel (window);
2018 toplevel->urgency_hint = urgent;
2020 update_wm_hints (window, FALSE);
2024 gdk_x11_window_set_geometry_hints (GdkWindow *window,
2025 const GdkGeometry *geometry,
2026 GdkWindowHints geom_mask)
2028 XSizeHints size_hints;
2030 if (GDK_WINDOW_DESTROYED (window) ||
2031 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2034 size_hints.flags = 0;
2036 if (geom_mask & GDK_HINT_POS)
2038 size_hints.flags |= PPosition;
2039 /* We need to initialize the following obsolete fields because KWM
2040 * apparently uses these fields if they are non-zero.
2047 if (geom_mask & GDK_HINT_USER_POS)
2049 size_hints.flags |= USPosition;
2052 if (geom_mask & GDK_HINT_USER_SIZE)
2054 size_hints.flags |= USSize;
2057 if (geom_mask & GDK_HINT_MIN_SIZE)
2059 size_hints.flags |= PMinSize;
2060 size_hints.min_width = geometry->min_width;
2061 size_hints.min_height = geometry->min_height;
2064 if (geom_mask & GDK_HINT_MAX_SIZE)
2066 size_hints.flags |= PMaxSize;
2067 size_hints.max_width = MAX (geometry->max_width, 1);
2068 size_hints.max_height = MAX (geometry->max_height, 1);
2071 if (geom_mask & GDK_HINT_BASE_SIZE)
2073 size_hints.flags |= PBaseSize;
2074 size_hints.base_width = geometry->base_width;
2075 size_hints.base_height = geometry->base_height;
2078 if (geom_mask & GDK_HINT_RESIZE_INC)
2080 size_hints.flags |= PResizeInc;
2081 size_hints.width_inc = geometry->width_inc;
2082 size_hints.height_inc = geometry->height_inc;
2085 if (geom_mask & GDK_HINT_ASPECT)
2087 size_hints.flags |= PAspect;
2088 if (geometry->min_aspect <= 1)
2090 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2091 size_hints.min_aspect.y = 65536;
2095 size_hints.min_aspect.x = 65536;
2096 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2098 if (geometry->max_aspect <= 1)
2100 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2101 size_hints.max_aspect.y = 65536;
2105 size_hints.max_aspect.x = 65536;
2106 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2110 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2112 size_hints.flags |= PWinGravity;
2113 size_hints.win_gravity = geometry->win_gravity;
2116 /* FIXME: Would it be better to delete this property if
2117 * geom_mask == 0? It would save space on the server
2119 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2120 GDK_WINDOW_XID (window),
2125 gdk_window_get_geometry_hints (GdkWindow *window,
2126 GdkGeometry *geometry,
2127 GdkWindowHints *geom_mask)
2129 XSizeHints *size_hints;
2130 glong junk_supplied_mask = 0;
2132 g_return_if_fail (GDK_IS_WINDOW (window));
2133 g_return_if_fail (geometry != NULL);
2134 g_return_if_fail (geom_mask != NULL);
2138 if (GDK_WINDOW_DESTROYED (window) ||
2139 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2142 size_hints = XAllocSizeHints ();
2146 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2147 GDK_WINDOW_XID (window),
2149 &junk_supplied_mask))
2150 size_hints->flags = 0;
2152 if (size_hints->flags & PMinSize)
2154 *geom_mask |= GDK_HINT_MIN_SIZE;
2155 geometry->min_width = size_hints->min_width;
2156 geometry->min_height = size_hints->min_height;
2159 if (size_hints->flags & PMaxSize)
2161 *geom_mask |= GDK_HINT_MAX_SIZE;
2162 geometry->max_width = MAX (size_hints->max_width, 1);
2163 geometry->max_height = MAX (size_hints->max_height, 1);
2166 if (size_hints->flags & PResizeInc)
2168 *geom_mask |= GDK_HINT_RESIZE_INC;
2169 geometry->width_inc = size_hints->width_inc;
2170 geometry->height_inc = size_hints->height_inc;
2173 if (size_hints->flags & PAspect)
2175 *geom_mask |= GDK_HINT_ASPECT;
2177 geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
2178 geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
2181 if (size_hints->flags & PWinGravity)
2183 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2184 geometry->win_gravity = size_hints->win_gravity;
2191 utf8_is_latin1 (const gchar *str)
2193 const char *p = str;
2197 gunichar ch = g_utf8_get_char (p);
2202 p = g_utf8_next_char (p);
2208 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2209 * convertable to STRING, otherwise, set it as compound text
2212 set_text_property (GdkDisplay *display,
2215 const gchar *utf8_str)
2217 gchar *prop_text = NULL;
2221 gboolean is_compound_text;
2223 if (utf8_is_latin1 (utf8_str))
2225 prop_type = XA_STRING;
2226 prop_text = gdk_utf8_to_string_target (utf8_str);
2227 prop_length = prop_text ? strlen (prop_text) : 0;
2229 is_compound_text = FALSE;
2235 gdk_utf8_to_compound_text_for_display (display,
2236 utf8_str, &gdk_type, &prop_format,
2237 (guchar **)&prop_text, &prop_length);
2238 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2239 is_compound_text = TRUE;
2244 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2247 prop_type, prop_format,
2248 PropModeReplace, (guchar *)prop_text,
2251 if (is_compound_text)
2252 gdk_free_compound_text ((guchar *)prop_text);
2258 /* Set WM_NAME and _NET_WM_NAME
2261 set_wm_name (GdkDisplay *display,
2265 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2266 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2267 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2268 PropModeReplace, (guchar *)name, strlen (name));
2270 set_text_property (display, xwindow,
2271 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2276 gdk_x11_window_set_title (GdkWindow *window,
2279 GdkDisplay *display;
2283 g_return_if_fail (title != NULL);
2285 if (GDK_WINDOW_DESTROYED (window) ||
2286 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2289 display = gdk_window_get_display (window);
2290 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2291 xwindow = GDK_WINDOW_XID (window);
2293 set_wm_name (display, xwindow, title);
2295 if (!gdk_window_icon_name_set (window))
2297 XChangeProperty (xdisplay, xwindow,
2298 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2299 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2300 PropModeReplace, (guchar *)title, strlen (title));
2302 set_text_property (display, xwindow,
2303 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2309 gdk_x11_window_set_role (GdkWindow *window,
2312 GdkDisplay *display;
2314 display = gdk_window_get_display (window);
2316 if (GDK_WINDOW_DESTROYED (window) ||
2317 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2321 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2322 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2323 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2325 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2326 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2330 gdk_x11_window_set_startup_id (GdkWindow *window,
2331 const gchar *startup_id)
2333 GdkDisplay *display;
2335 g_return_if_fail (GDK_IS_WINDOW (window));
2337 display = gdk_window_get_display (window);
2339 if (GDK_WINDOW_DESTROYED (window) ||
2340 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2344 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2345 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2346 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2347 PropModeReplace, (unsigned char *)startup_id, strlen (startup_id));
2349 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2350 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"));
2354 gdk_x11_window_set_transient_for (GdkWindow *window,
2357 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) &&
2358 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2359 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2360 GDK_WINDOW_XID (window),
2361 GDK_WINDOW_XID (parent));
2365 gdk_window_x11_set_back_color (GdkWindow *window,
2371 GdkVisual *visual = gdk_window_get_visual (window);
2373 /* I suppose we could handle these, but that'd require fiddling with
2374 * xrender formats... */
2378 switch (visual->type)
2380 case GDK_VISUAL_DIRECT_COLOR:
2381 case GDK_VISUAL_TRUE_COLOR:
2383 /* If bits not used for color are used for something other than padding,
2384 * it's likely alpha, so we set them to 1s.
2386 guint padding, pixel;
2388 /* Shifting by >= width-of-type isn't defined in C */
2389 if (visual->depth >= 32)
2392 padding = ((~(guint32)0)) << visual->depth;
2394 pixel = ~ (visual->red_mask | visual->green_mask | visual->blue_mask | padding);
2396 pixel += (((int) (red * ((1 << visual->red_prec ) - 1))) << visual->red_shift ) +
2397 (((int) (green * ((1 << visual->green_prec) - 1))) << visual->green_shift) +
2398 (((int) (blue * ((1 << visual->blue_prec ) - 1))) << visual->blue_shift );
2400 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2401 GDK_WINDOW_XID (window), pixel);
2405 /* These require fiddling with the colormap, and as they're essentially unused
2406 * we're just gonna skip them for now.
2408 case GDK_VISUAL_PSEUDO_COLOR:
2409 case GDK_VISUAL_GRAYSCALE:
2410 case GDK_VISUAL_STATIC_GRAY:
2411 case GDK_VISUAL_STATIC_COLOR:
2420 matrix_is_identity (cairo_matrix_t *matrix)
2422 return matrix->xx == 1.0 && matrix->yy == 1.0 &&
2423 matrix->yx == 0.0 && matrix->xy == 0.0 &&
2424 matrix->x0 == 0.0 && matrix->y0 == 0.0;
2428 gdk_window_x11_set_background (GdkWindow *window,
2429 cairo_pattern_t *pattern)
2432 cairo_surface_t *surface;
2433 cairo_matrix_t matrix;
2435 if (GDK_WINDOW_DESTROYED (window))
2438 if (pattern == NULL)
2442 /* X throws BadMatch if the parent has a different visual when
2443 * using ParentRelative */
2444 parent = gdk_window_get_parent (window);
2445 if (parent && gdk_window_get_visual (parent) == gdk_window_get_visual (window))
2446 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2447 GDK_WINDOW_XID (window), ParentRelative);
2449 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2450 GDK_WINDOW_XID (window), None);
2454 switch (cairo_pattern_get_type (pattern))
2456 case CAIRO_PATTERN_TYPE_SOLID:
2457 cairo_pattern_get_rgba (pattern, &r, &g, &b, &a);
2458 if (gdk_window_x11_set_back_color (window, r, g, b, a))
2461 case CAIRO_PATTERN_TYPE_SURFACE:
2462 cairo_pattern_get_matrix (pattern, &matrix);
2463 if (cairo_pattern_get_surface (pattern, &surface) == CAIRO_STATUS_SUCCESS &&
2464 matrix_is_identity (&matrix) &&
2465 cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB &&
2466 cairo_xlib_surface_get_visual (surface) == GDK_VISUAL_XVISUAL (gdk_window_get_visual ((window))) &&
2467 cairo_xlib_surface_get_display (surface) == GDK_WINDOW_XDISPLAY (window))
2471 cairo_surface_get_device_offset (surface, &x, &y);
2472 /* XXX: This still bombs for non-pixmaps, but there's no way to
2473 * detect we're not a pixmap in Cairo... */
2474 if (x == 0.0 && y == 0.0)
2476 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2477 GDK_WINDOW_XID (window),
2478 cairo_xlib_surface_get_drawable (surface));
2483 case CAIRO_PATTERN_TYPE_LINEAR:
2484 case CAIRO_PATTERN_TYPE_RADIAL:
2486 /* fallback: just use black */
2490 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2491 GDK_WINDOW_XID (window), None);
2495 gdk_window_x11_set_device_cursor (GdkWindow *window,
2499 GdkWindowImplX11 *impl;
2501 g_return_if_fail (GDK_IS_WINDOW (window));
2502 g_return_if_fail (GDK_IS_DEVICE (device));
2504 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2507 g_hash_table_remove (impl->device_cursor, device);
2510 _gdk_x11_cursor_update_theme (cursor);
2511 g_hash_table_replace (impl->device_cursor,
2512 device, gdk_cursor_ref (cursor));
2515 if (!GDK_WINDOW_DESTROYED (window))
2516 GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
2520 _gdk_x11_window_get_cursor (GdkWindow *window)
2522 GdkWindowImplX11 *impl;
2524 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2526 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2528 return impl->cursor;
2532 gdk_window_x11_get_geometry (GdkWindow *window,
2543 guint tborder_width;
2546 if (!GDK_WINDOW_DESTROYED (window))
2548 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2549 GDK_WINDOW_XID (window),
2550 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2564 gdk_window_x11_get_root_coords (GdkWindow *window,
2575 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2576 GDK_WINDOW_XID (window),
2577 GDK_WINDOW_XROOTWIN (window),
2590 gdk_x11_window_get_root_origin (GdkWindow *window,
2596 gdk_window_get_frame_extents (window, &rect);
2606 gdk_x11_window_get_frame_extents (GdkWindow *window,
2609 GdkDisplay *display;
2610 GdkWindowImplX11 *impl;
2621 gulong nitems_return;
2622 gulong bytes_after_return;
2625 guint ww, wh, wb, wd;
2627 gboolean got_frame_extents = FALSE;
2629 g_return_if_fail (rect != NULL);
2636 while (window->parent && (window->parent)->parent)
2637 window = window->parent;
2639 /* Refine our fallback answer a bit using local information */
2640 rect->x = window->x;
2641 rect->y = window->y;
2642 rect->width = window->width;
2643 rect->height = window->height;
2645 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2646 if (GDK_WINDOW_DESTROYED (window) || impl->override_redirect)
2652 display = gdk_window_get_display (window);
2654 gdk_x11_display_error_trap_push (display);
2656 xwindow = GDK_WINDOW_XID (window);
2658 /* first try: use _NET_FRAME_EXTENTS */
2659 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2660 gdk_x11_get_xatom_by_name_for_display (display,
2661 "_NET_FRAME_EXTENTS"),
2662 0, G_MAXLONG, False, XA_CARDINAL, &type_return,
2663 &format_return, &nitems_return, &bytes_after_return,
2667 if ((type_return == XA_CARDINAL) && (format_return == 32) &&
2668 (nitems_return == 4) && (data))
2670 gulong *ldata = (gulong *) data;
2671 got_frame_extents = TRUE;
2673 /* try to get the real client window geometry */
2674 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2675 &root, &wx, &wy, &ww, &wh, &wb, &wd) &&
2676 XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display),
2677 xwindow, root, 0, 0, &wx, &wy, &child))
2685 /* _NET_FRAME_EXTENTS format is left, right, top, bottom */
2686 rect->x -= ldata[0];
2687 rect->y -= ldata[2];
2688 rect->width += ldata[0] + ldata[1];
2689 rect->height += ldata[2] + ldata[3];
2696 if (got_frame_extents)
2699 /* no frame extents property available, which means we either have a WM that
2700 is not EWMH compliant or is broken - try fallback and walk up the window
2701 tree to get our window's parent which hopefully is the window frame */
2703 /* use NETWM_VIRTUAL_ROOTS if available */
2704 root = GDK_WINDOW_XROOTWIN (window);
2706 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
2707 gdk_x11_get_xatom_by_name_for_display (display,
2708 "_NET_VIRTUAL_ROOTS"),
2709 0, G_MAXLONG, False, XA_WINDOW, &type_return,
2710 &format_return, &nitems_return, &bytes_after_return,
2714 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
2716 nvroots = nitems_return;
2717 vroots = (Window *)data;
2721 xparent = GDK_WINDOW_XID (window);
2727 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
2729 &children, &nchildren))
2735 /* check virtual roots */
2736 for (i = 0; i < nvroots; i++)
2738 if (xparent == vroots[i])
2745 while (xparent != root);
2747 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2748 &root, &wx, &wy, &ww, &wh, &wb, &wd))
2760 gdk_x11_display_error_trap_pop_ignored (display);
2764 gdk_window_x11_get_device_state (GdkWindow *window,
2768 GdkModifierType *mask)
2772 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
2774 if (GDK_WINDOW_DESTROYED (window))
2777 GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
2781 return child != NULL;
2785 gdk_window_x11_get_events (GdkWindow *window)
2787 XWindowAttributes attrs;
2788 GdkEventMask event_mask;
2789 GdkEventMask filtered;
2791 if (GDK_WINDOW_DESTROYED (window))
2795 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2796 GDK_WINDOW_XID (window),
2798 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2799 /* if property change was filtered out before, keep it filtered out */
2800 filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK;
2801 window->event_mask = event_mask & ((window->event_mask & filtered) | ~filtered);
2807 gdk_window_x11_set_events (GdkWindow *window,
2808 GdkEventMask event_mask)
2810 long xevent_mask = 0;
2812 if (!GDK_WINDOW_DESTROYED (window))
2814 GdkDisplayX11 *display_x11;
2816 if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
2817 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2819 display_x11 = GDK_DISPLAY_X11 (gdk_window_get_display (window));
2820 gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
2821 GDK_WINDOW_XID (window), event_mask,
2827 do_shape_combine_region (GdkWindow *window,
2828 const cairo_region_t *shape_region,
2833 if (GDK_WINDOW_DESTROYED (window))
2836 if (shape_region == NULL)
2838 /* Use NULL mask to unset the shape */
2839 if (shape == ShapeBounding
2840 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
2841 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
2843 if (shape == ShapeBounding)
2845 _gdk_x11_window_tmp_unset_parent_bg (window);
2846 _gdk_x11_window_tmp_unset_bg (window, TRUE);
2848 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2849 GDK_WINDOW_XID (window),
2854 if (shape == ShapeBounding)
2856 _gdk_x11_window_tmp_reset_parent_bg (window);
2857 _gdk_x11_window_tmp_reset_bg (window, TRUE);
2863 if (shape == ShapeBounding
2864 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
2865 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
2868 XRectangle *xrects = NULL;
2870 _gdk_x11_region_get_xrectangles (shape_region,
2874 if (shape == ShapeBounding)
2876 _gdk_x11_window_tmp_unset_parent_bg (window);
2877 _gdk_x11_window_tmp_unset_bg (window, TRUE);
2879 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2880 GDK_WINDOW_XID (window),
2887 if (shape == ShapeBounding)
2889 _gdk_x11_window_tmp_reset_parent_bg (window);
2890 _gdk_x11_window_tmp_reset_bg (window, TRUE);
2898 gdk_window_x11_shape_combine_region (GdkWindow *window,
2899 const cairo_region_t *shape_region,
2903 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
2907 gdk_window_x11_input_shape_combine_region (GdkWindow *window,
2908 const cairo_region_t *shape_region,
2913 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
2919 gdk_x11_window_set_override_redirect (GdkWindow *window,
2920 gboolean override_redirect)
2922 XSetWindowAttributes attr;
2924 if (!GDK_WINDOW_DESTROYED (window) &&
2925 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2927 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
2929 attr.override_redirect = (override_redirect? True : False);
2930 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2931 GDK_WINDOW_XID (window),
2935 impl->override_redirect = attr.override_redirect;
2940 gdk_x11_window_set_accept_focus (GdkWindow *window,
2941 gboolean accept_focus)
2943 accept_focus = accept_focus != FALSE;
2945 if (window->accept_focus != accept_focus)
2947 window->accept_focus = accept_focus;
2949 if (!GDK_WINDOW_DESTROYED (window) &&
2950 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2951 update_wm_hints (window, FALSE);
2956 gdk_x11_window_set_focus_on_map (GdkWindow *window,
2957 gboolean focus_on_map)
2959 focus_on_map = focus_on_map != FALSE;
2961 if (window->focus_on_map != focus_on_map)
2963 window->focus_on_map = focus_on_map;
2965 if ((!GDK_WINDOW_DESTROYED (window)) &&
2966 (!window->focus_on_map) &&
2967 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2968 gdk_x11_window_set_user_time (window, 0);
2973 * gdk_x11_window_set_user_time:
2974 * @window: A toplevel #GdkWindow
2975 * @timestamp: An XServer timestamp to which the property should be set
2977 * The application can use this call to update the _NET_WM_USER_TIME
2978 * property on a toplevel window. This property stores an Xserver
2979 * time which represents the time of the last user input event
2980 * received for this window. This property may be used by the window
2981 * manager to alter the focus, stacking, and/or placement behavior of
2982 * windows when they are mapped depending on whether the new window
2983 * was created by a user action or is a "pop-up" window activated by a
2984 * timer or some other event.
2986 * Note that this property is automatically updated by GDK, so this
2987 * function should only be used by applications which handle input
2988 * events bypassing GDK.
2993 gdk_x11_window_set_user_time (GdkWindow *window,
2996 GdkDisplay *display;
2997 GdkDisplayX11 *display_x11;
2998 GdkToplevelX11 *toplevel;
2999 glong timestamp_long = (glong)timestamp;
3002 if (GDK_WINDOW_DESTROYED (window) ||
3003 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3006 display = gdk_window_get_display (window);
3007 display_x11 = GDK_DISPLAY_X11 (display);
3008 toplevel = _gdk_x11_window_get_toplevel (window);
3012 g_warning ("gdk_window_set_user_time called on non-toplevel\n");
3016 if (toplevel->focus_window != None &&
3017 gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
3018 gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW")))
3019 xid = toplevel->focus_window;
3021 xid = GDK_WINDOW_XID (window);
3023 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid,
3024 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3025 XA_CARDINAL, 32, PropModeReplace,
3026 (guchar *)×tamp_long, 1);
3028 if (timestamp_long != GDK_CURRENT_TIME &&
3029 (display_x11->user_time == GDK_CURRENT_TIME ||
3030 XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time)))
3031 display_x11->user_time = timestamp_long;
3034 toplevel->user_time = timestamp_long;
3037 #define GDK_SELECTION_MAX_SIZE(display) \
3039 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
3040 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
3041 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
3044 gdk_window_update_icon (GdkWindow *window,
3047 GdkToplevelX11 *toplevel;
3048 GdkPixbuf *best_icon;
3052 toplevel = _gdk_x11_window_get_toplevel (window);
3054 if (toplevel->icon_pixmap != NULL)
3056 cairo_surface_destroy (toplevel->icon_pixmap);
3057 toplevel->icon_pixmap = NULL;
3060 if (toplevel->icon_mask != NULL)
3062 cairo_surface_destroy (toplevel->icon_mask);
3063 toplevel->icon_mask = NULL;
3066 #define IDEAL_SIZE 48
3068 best_size = G_MAXINT;
3070 for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next)
3072 GdkPixbuf *pixbuf = tmp_list->data;
3075 /* average width and height - if someone passes in a rectangular
3076 * icon they deserve what they get.
3078 this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
3081 if (best_icon == NULL)
3088 /* icon is better if it's 32 pixels or larger, and closer to
3089 * the ideal size than the current best.
3092 (ABS (best_size - IDEAL_SIZE) <
3093 ABS (this - IDEAL_SIZE)))
3103 int width = gdk_pixbuf_get_width (best_icon);
3104 int height = gdk_pixbuf_get_height (best_icon);
3107 toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window,
3111 cr = cairo_create (toplevel->icon_pixmap);
3112 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3113 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3114 if (gdk_pixbuf_get_has_alpha (best_icon))
3116 /* Saturate the image, so it has bilevel alpha */
3117 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
3119 cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
3121 cairo_pop_group_to_source (cr);
3126 if (gdk_pixbuf_get_has_alpha (best_icon))
3128 toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
3132 cr = cairo_create (toplevel->icon_mask);
3133 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3134 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3140 update_wm_hints (window, FALSE);
3144 gdk_x11_window_set_icon_list (GdkWindow *window,
3153 gint width, height, stride;
3156 GdkDisplay *display;
3159 if (GDK_WINDOW_DESTROYED (window) ||
3160 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3163 display = gdk_window_get_display (window);
3171 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3173 width = gdk_pixbuf_get_width (pixbuf);
3174 height = gdk_pixbuf_get_height (pixbuf);
3176 /* silently ignore overlarge icons */
3177 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
3179 g_warning ("gdk_window_set_icon_list: icons too large");
3184 size += 2 + width * height;
3186 l = g_list_next (l);
3189 data = g_malloc (size * sizeof (gulong));
3197 width = gdk_pixbuf_get_width (pixbuf);
3198 height = gdk_pixbuf_get_height (pixbuf);
3199 stride = gdk_pixbuf_get_rowstride (pixbuf);
3200 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3205 pixels = gdk_pixbuf_get_pixels (pixbuf);
3207 for (y = 0; y < height; y++)
3209 for (x = 0; x < width; x++)
3213 r = pixels[y*stride + x*n_channels + 0];
3214 g = pixels[y*stride + x*n_channels + 1];
3215 b = pixels[y*stride + x*n_channels + 2];
3216 if (n_channels >= 4)
3217 a = pixels[y*stride + x*n_channels + 3];
3221 *p++ = a << 24 | r << 16 | g << 8 | b ;
3225 l = g_list_next (l);
3231 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3232 GDK_WINDOW_XID (window),
3233 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3236 (guchar*) data, size);
3240 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3241 GDK_WINDOW_XID (window),
3242 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3247 gdk_window_update_icon (window, pixbufs);
3251 gdk_window_icon_name_set (GdkWindow *window)
3253 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3254 g_quark_from_static_string ("gdk-icon-name-set")));
3258 gdk_x11_window_set_icon_name (GdkWindow *window,
3261 GdkDisplay *display;
3263 if (GDK_WINDOW_DESTROYED (window) ||
3264 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3267 display = gdk_window_get_display (window);
3269 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3270 GUINT_TO_POINTER (name != NULL));
3274 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3275 GDK_WINDOW_XID (window),
3276 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3277 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3278 PropModeReplace, (guchar *)name, strlen (name));
3280 set_text_property (display, GDK_WINDOW_XID (window),
3281 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3286 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3287 GDK_WINDOW_XID (window),
3288 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"));
3289 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3290 GDK_WINDOW_XID (window),
3291 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"));
3296 gdk_x11_window_iconify (GdkWindow *window)
3298 if (GDK_WINDOW_DESTROYED (window) ||
3299 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3302 if (GDK_WINDOW_IS_MAPPED (window))
3304 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3305 GDK_WINDOW_XID (window),
3306 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3310 /* Flip our client side flag, the real work happens on map. */
3311 gdk_synthesize_window_state (window,
3313 GDK_WINDOW_STATE_ICONIFIED);
3318 gdk_x11_window_deiconify (GdkWindow *window)
3320 if (GDK_WINDOW_DESTROYED (window) ||
3321 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3324 if (GDK_WINDOW_IS_MAPPED (window))
3326 gdk_window_show (window);
3330 /* Flip our client side flag, the real work happens on map. */
3331 gdk_synthesize_window_state (window,
3332 GDK_WINDOW_STATE_ICONIFIED,
3338 gdk_x11_window_stick (GdkWindow *window)
3340 if (GDK_WINDOW_DESTROYED (window) ||
3341 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3344 if (GDK_WINDOW_IS_MAPPED (window))
3346 /* "stick" means stick to all desktops _and_ do not scroll with the
3347 * viewport. i.e. glue to the monitor glass in all cases.
3350 XClientMessageEvent xclient;
3352 /* Request stick during viewport scroll */
3353 gdk_wmspec_change_state (TRUE, window,
3354 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
3357 /* Request desktop 0xFFFFFFFF */
3358 memset (&xclient, 0, sizeof (xclient));
3359 xclient.type = ClientMessage;
3360 xclient.window = GDK_WINDOW_XID (window);
3361 xclient.display = GDK_WINDOW_XDISPLAY (window);
3362 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3364 xclient.format = 32;
3366 xclient.data.l[0] = 0xFFFFFFFF;
3367 xclient.data.l[1] = 0;
3368 xclient.data.l[2] = 0;
3369 xclient.data.l[3] = 0;
3370 xclient.data.l[4] = 0;
3372 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3373 SubstructureRedirectMask | SubstructureNotifyMask,
3374 (XEvent *)&xclient);
3378 /* Flip our client side flag, the real work happens on map. */
3379 gdk_synthesize_window_state (window,
3381 GDK_WINDOW_STATE_STICKY);
3386 gdk_x11_window_unstick (GdkWindow *window)
3388 if (GDK_WINDOW_DESTROYED (window) ||
3389 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3392 if (GDK_WINDOW_IS_MAPPED (window))
3394 /* Request unstick from viewport */
3395 gdk_wmspec_change_state (FALSE, window,
3396 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
3399 move_to_current_desktop (window);
3403 /* Flip our client side flag, the real work happens on map. */
3404 gdk_synthesize_window_state (window,
3405 GDK_WINDOW_STATE_STICKY,
3412 gdk_x11_window_maximize (GdkWindow *window)
3414 if (GDK_WINDOW_DESTROYED (window) ||
3415 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3418 if (GDK_WINDOW_IS_MAPPED (window))
3419 gdk_wmspec_change_state (TRUE, window,
3420 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
3421 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
3423 gdk_synthesize_window_state (window,
3425 GDK_WINDOW_STATE_MAXIMIZED);
3429 gdk_x11_window_unmaximize (GdkWindow *window)
3431 if (GDK_WINDOW_DESTROYED (window) ||
3432 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3435 if (GDK_WINDOW_IS_MAPPED (window))
3436 gdk_wmspec_change_state (FALSE, window,
3437 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
3438 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
3440 gdk_synthesize_window_state (window,
3441 GDK_WINDOW_STATE_MAXIMIZED,
3446 gdk_x11_window_fullscreen (GdkWindow *window)
3448 if (GDK_WINDOW_DESTROYED (window) ||
3449 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3452 if (GDK_WINDOW_IS_MAPPED (window))
3453 gdk_wmspec_change_state (TRUE, window,
3454 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
3458 gdk_synthesize_window_state (window,
3460 GDK_WINDOW_STATE_FULLSCREEN);
3464 gdk_x11_window_unfullscreen (GdkWindow *window)
3466 if (GDK_WINDOW_DESTROYED (window) ||
3467 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3470 if (GDK_WINDOW_IS_MAPPED (window))
3471 gdk_wmspec_change_state (FALSE, window,
3472 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
3476 gdk_synthesize_window_state (window,
3477 GDK_WINDOW_STATE_FULLSCREEN,
3482 gdk_x11_window_set_keep_above (GdkWindow *window,
3485 g_return_if_fail (GDK_IS_WINDOW (window));
3487 if (GDK_WINDOW_DESTROYED (window) ||
3488 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3491 if (GDK_WINDOW_IS_MAPPED (window))
3494 gdk_wmspec_change_state (FALSE, window,
3495 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
3497 gdk_wmspec_change_state (setting, window,
3498 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
3502 gdk_synthesize_window_state (window,
3503 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
3504 setting ? GDK_WINDOW_STATE_ABOVE : 0);
3508 gdk_x11_window_set_keep_below (GdkWindow *window, gboolean setting)
3510 g_return_if_fail (GDK_IS_WINDOW (window));
3512 if (GDK_WINDOW_DESTROYED (window) ||
3513 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3516 if (GDK_WINDOW_IS_MAPPED (window))
3519 gdk_wmspec_change_state (FALSE, window,
3520 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
3522 gdk_wmspec_change_state (setting, window,
3523 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
3527 gdk_synthesize_window_state (window,
3528 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
3529 setting ? GDK_WINDOW_STATE_BELOW : 0);
3533 gdk_x11_window_get_group (GdkWindow *window)
3535 GdkToplevelX11 *toplevel;
3537 if (GDK_WINDOW_DESTROYED (window) ||
3538 !WINDOW_IS_TOPLEVEL (window))
3541 toplevel = _gdk_x11_window_get_toplevel (window);
3543 return toplevel->group_leader;
3547 gdk_x11_window_set_group (GdkWindow *window,
3550 GdkToplevelX11 *toplevel;
3552 g_return_if_fail (GDK_IS_WINDOW (window));
3553 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3554 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
3556 if (GDK_WINDOW_DESTROYED (window) ||
3557 (leader != NULL && GDK_WINDOW_DESTROYED (leader)) ||
3558 !WINDOW_IS_TOPLEVEL (window))
3561 toplevel = _gdk_x11_window_get_toplevel (window);
3564 leader = gdk_display_get_default_group (gdk_window_get_display (window));
3566 if (toplevel->group_leader != leader)
3568 if (toplevel->group_leader)
3569 g_object_unref (toplevel->group_leader);
3570 toplevel->group_leader = g_object_ref (leader);
3571 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
3574 update_wm_hints (window, FALSE);
3577 static MotifWmHints *
3578 gdk_window_get_mwm_hints (GdkWindow *window)
3580 GdkDisplay *display;
3581 Atom hints_atom = None;
3588 if (GDK_WINDOW_DESTROYED (window))
3591 display = gdk_window_get_display (window);
3593 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3595 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3596 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3597 False, AnyPropertyType, &type, &format, &nitems,
3598 &bytes_after, &data);
3603 return (MotifWmHints *)data;
3607 gdk_window_set_mwm_hints (GdkWindow *window,
3608 MotifWmHints *new_hints)
3610 GdkDisplay *display;
3611 Atom hints_atom = None;
3613 MotifWmHints *hints;
3619 if (GDK_WINDOW_DESTROYED (window))
3622 display = gdk_window_get_display (window);
3624 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3626 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3627 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3628 False, AnyPropertyType, &type, &format, &nitems,
3629 &bytes_after, &data);
3635 hints = (MotifWmHints *)data;
3637 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3639 hints->flags |= MWM_HINTS_FUNCTIONS;
3640 hints->functions = new_hints->functions;
3642 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3644 hints->flags |= MWM_HINTS_DECORATIONS;
3645 hints->decorations = new_hints->decorations;
3649 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3650 hints_atom, hints_atom, 32, PropModeReplace,
3651 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3653 if (hints != new_hints)
3658 gdk_x11_window_set_decorations (GdkWindow *window,
3659 GdkWMDecoration decorations)
3663 if (GDK_WINDOW_DESTROYED (window) ||
3664 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3667 /* initialize to zero to avoid writing uninitialized data to socket */
3668 memset(&hints, 0, sizeof(hints));
3669 hints.flags = MWM_HINTS_DECORATIONS;
3670 hints.decorations = decorations;
3672 gdk_window_set_mwm_hints (window, &hints);
3676 gdk_x11_window_get_decorations(GdkWindow *window,
3677 GdkWMDecoration *decorations)
3679 MotifWmHints *hints;
3680 gboolean result = FALSE;
3682 if (GDK_WINDOW_DESTROYED (window) ||
3683 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3686 hints = gdk_window_get_mwm_hints (window);
3690 if (hints->flags & MWM_HINTS_DECORATIONS)
3693 *decorations = hints->decorations;
3704 gdk_x11_window_set_functions (GdkWindow *window,
3705 GdkWMFunction functions)
3709 g_return_if_fail (GDK_IS_WINDOW (window));
3711 if (GDK_WINDOW_DESTROYED (window) ||
3712 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3715 /* initialize to zero to avoid writing uninitialized data to socket */
3716 memset(&hints, 0, sizeof(hints));
3717 hints.flags = MWM_HINTS_FUNCTIONS;
3718 hints.functions = functions;
3720 gdk_window_set_mwm_hints (window, &hints);
3724 _gdk_x11_xwindow_get_shape (Display *xdisplay,
3728 cairo_region_t *shape;
3736 xrl = XShapeGetRectangles (xdisplay,
3738 shape_type, &rn, &ord);
3740 if (xrl == NULL || rn == 0)
3741 return cairo_region_create (); /* Empty */
3743 if (ord != YXBanded)
3745 /* This really shouldn't happen with any xserver, as they
3746 generally convert regions to YXBanded internally */
3747 g_warning ("non YXBanded shape masks not supported");
3752 rl = g_new (GdkRectangle, rn);
3753 for (i = 0; i < rn; i++)
3757 rl[i].width = xrl[i].width;
3758 rl[i].height = xrl[i].height;
3762 shape = cairo_region_create_rectangles (rl, rn);
3769 static cairo_region_t *
3770 gdk_x11_window_get_shape (GdkWindow *window)
3772 if (!GDK_WINDOW_DESTROYED (window) &&
3773 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
3774 return _gdk_x11_xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
3775 GDK_WINDOW_XID (window),
3781 static cairo_region_t *
3782 gdk_x11_window_get_input_shape (GdkWindow *window)
3784 #if defined(ShapeInput)
3785 if (!GDK_WINDOW_DESTROYED (window) &&
3786 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
3787 return _gdk_x11_xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
3788 GDK_WINDOW_XID (window),
3796 gdk_window_set_static_bit_gravity (GdkWindow *window,
3799 XSetWindowAttributes xattributes;
3800 guint xattributes_mask = 0;
3802 g_return_if_fail (GDK_IS_WINDOW (window));
3804 if (window->input_only)
3807 xattributes.bit_gravity = StaticGravity;
3808 xattributes_mask |= CWBitGravity;
3809 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
3810 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3811 GDK_WINDOW_XID (window),
3812 CWBitGravity, &xattributes);
3816 gdk_window_set_static_win_gravity (GdkWindow *window,
3819 XSetWindowAttributes xattributes;
3821 g_return_if_fail (GDK_IS_WINDOW (window));
3823 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
3825 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3826 GDK_WINDOW_XID (window),
3827 CWWinGravity, &xattributes);
3831 gdk_window_x11_set_static_gravities (GdkWindow *window,
3832 gboolean use_static)
3836 if (!use_static == !window->guffaw_gravity)
3839 window->guffaw_gravity = use_static;
3841 if (!GDK_WINDOW_DESTROYED (window))
3843 gdk_window_set_static_bit_gravity (window, use_static);
3845 tmp_list = window->children;
3848 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
3850 tmp_list = tmp_list->next;
3858 wmspec_moveresize (GdkWindow *window,
3864 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
3866 XClientMessageEvent xclient;
3868 /* Release passive grab */
3869 gdk_display_pointer_ungrab (display, timestamp);
3871 memset (&xclient, 0, sizeof (xclient));
3872 xclient.type = ClientMessage;
3873 xclient.window = GDK_WINDOW_XID (window);
3874 xclient.message_type =
3875 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
3876 xclient.format = 32;
3877 xclient.data.l[0] = root_x;
3878 xclient.data.l[1] = root_y;
3879 xclient.data.l[2] = direction;
3880 xclient.data.l[3] = 0;
3881 xclient.data.l[4] = 0;
3883 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3884 SubstructureRedirectMask | SubstructureNotifyMask,
3885 (XEvent *)&xclient);
3888 typedef struct _MoveResizeData MoveResizeData;
3890 struct _MoveResizeData
3892 GdkDisplay *display;
3894 GdkWindow *moveresize_window;
3895 GdkWindow *moveresize_emulation_window;
3897 GdkWindowEdge resize_edge;
3898 gint moveresize_button;
3901 gint moveresize_orig_x;
3902 gint moveresize_orig_y;
3903 gint moveresize_orig_width;
3904 gint moveresize_orig_height;
3905 GdkWindowHints moveresize_geom_mask;
3906 GdkGeometry moveresize_geometry;
3907 Time moveresize_process_time;
3908 XEvent *moveresize_pending_event;
3911 /* From the WM spec */
3912 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
3913 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
3914 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
3915 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
3916 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
3917 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
3918 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
3919 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
3920 #define _NET_WM_MOVERESIZE_MOVE 8
3923 wmspec_resize_drag (GdkWindow *window,
3932 /* Let the compiler turn a switch into a table, instead
3933 * of doing the table manually, this way is easier to verify.
3937 case GDK_WINDOW_EDGE_NORTH_WEST:
3938 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
3941 case GDK_WINDOW_EDGE_NORTH:
3942 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
3945 case GDK_WINDOW_EDGE_NORTH_EAST:
3946 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
3949 case GDK_WINDOW_EDGE_WEST:
3950 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
3953 case GDK_WINDOW_EDGE_EAST:
3954 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
3957 case GDK_WINDOW_EDGE_SOUTH_WEST:
3958 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
3961 case GDK_WINDOW_EDGE_SOUTH:
3962 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
3965 case GDK_WINDOW_EDGE_SOUTH_EAST:
3966 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
3970 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
3975 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
3978 static MoveResizeData *
3979 get_move_resize_data (GdkDisplay *display,
3982 MoveResizeData *mv_resize;
3983 static GQuark move_resize_quark = 0;
3985 if (!move_resize_quark)
3986 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
3988 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
3990 if (!mv_resize && create)
3992 mv_resize = g_new0 (MoveResizeData, 1);
3993 mv_resize->display = display;
3995 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4002 update_pos (MoveResizeData *mv_resize,
4008 dx = new_root_x - mv_resize->moveresize_x;
4009 dy = new_root_y - mv_resize->moveresize_y;
4011 if (mv_resize->is_resize)
4015 x = mv_resize->moveresize_orig_x;
4016 y = mv_resize->moveresize_orig_y;
4018 w = mv_resize->moveresize_orig_width;
4019 h = mv_resize->moveresize_orig_height;
4021 switch (mv_resize->resize_edge)
4023 case GDK_WINDOW_EDGE_NORTH_WEST:
4029 case GDK_WINDOW_EDGE_NORTH:
4033 case GDK_WINDOW_EDGE_NORTH_EAST:
4038 case GDK_WINDOW_EDGE_SOUTH_WEST:
4043 case GDK_WINDOW_EDGE_SOUTH_EAST:
4047 case GDK_WINDOW_EDGE_SOUTH:
4050 case GDK_WINDOW_EDGE_EAST:
4053 case GDK_WINDOW_EDGE_WEST:
4064 if (mv_resize->moveresize_geom_mask)
4066 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4067 mv_resize->moveresize_geom_mask,
4071 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4077 x = mv_resize->moveresize_orig_x + dx;
4078 y = mv_resize->moveresize_orig_y + dy;
4080 gdk_window_move (mv_resize->moveresize_window, x, y);
4085 finish_drag (MoveResizeData *mv_resize)
4087 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4088 mv_resize->moveresize_emulation_window = NULL;
4089 g_object_unref (mv_resize->moveresize_window);
4090 mv_resize->moveresize_window = NULL;
4092 if (mv_resize->moveresize_pending_event)
4094 g_free (mv_resize->moveresize_pending_event);
4095 mv_resize->moveresize_pending_event = NULL;
4100 lookahead_motion_predicate (Display *xdisplay,
4104 gboolean *seen_release = (gboolean *)arg;
4105 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4106 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4111 switch (event->xany.type)
4114 *seen_release = TRUE;
4117 mv_resize->moveresize_process_time = event->xmotion.time;
4127 moveresize_lookahead (MoveResizeData *mv_resize,
4131 gboolean seen_release = FALSE;
4133 if (mv_resize->moveresize_process_time)
4135 if (event->xmotion.time == mv_resize->moveresize_process_time)
4137 mv_resize->moveresize_process_time = 0;
4144 XCheckIfEvent (event->xany.display, &tmp_event,
4145 lookahead_motion_predicate, (XPointer) & seen_release);
4147 return mv_resize->moveresize_process_time == 0;
4151 _gdk_x11_moveresize_handle_event (XEvent *event)
4153 guint button_mask = 0;
4154 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
4155 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4157 if (!mv_resize || !mv_resize->moveresize_window)
4160 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4162 switch (event->xany.type)
4165 if (mv_resize->moveresize_window->resize_count > 0)
4167 if (mv_resize->moveresize_pending_event)
4168 *mv_resize->moveresize_pending_event = *event;
4170 mv_resize->moveresize_pending_event =
4171 g_memdup (event, sizeof (XEvent));
4175 if (!moveresize_lookahead (mv_resize, event))
4178 update_pos (mv_resize,
4179 event->xmotion.x_root,
4180 event->xmotion.y_root);
4182 /* This should never be triggered in normal cases, but in the
4183 * case where the drag started without an implicit grab being
4184 * in effect, we could miss the release if it occurs before
4185 * we grab the pointer; this ensures that we will never
4186 * get a permanently stuck grab.
4188 if ((event->xmotion.state & button_mask) == 0)
4189 finish_drag (mv_resize);
4193 update_pos (mv_resize,
4194 event->xbutton.x_root,
4195 event->xbutton.y_root);
4197 if (event->xbutton.button == mv_resize->moveresize_button)
4198 finish_drag (mv_resize);
4205 _gdk_x11_moveresize_configure_done (GdkDisplay *display,
4209 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4211 if (!mv_resize || window != mv_resize->moveresize_window)
4214 if (mv_resize->moveresize_pending_event)
4216 tmp_event = mv_resize->moveresize_pending_event;
4217 mv_resize->moveresize_pending_event = NULL;
4218 _gdk_x11_moveresize_handle_event (tmp_event);
4226 create_moveresize_window (MoveResizeData *mv_resize,
4229 GdkWindowAttr attributes;
4230 gint attributes_mask;
4231 GdkGrabStatus status;
4233 g_assert (mv_resize->moveresize_emulation_window == NULL);
4235 attributes.x = -100;
4236 attributes.y = -100;
4237 attributes.width = 10;
4238 attributes.height = 10;
4239 attributes.window_type = GDK_WINDOW_TEMP;
4240 attributes.wclass = GDK_INPUT_ONLY;
4241 attributes.override_redirect = TRUE;
4242 attributes.event_mask = 0;
4244 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4246 mv_resize->moveresize_emulation_window =
4247 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4251 gdk_window_show (mv_resize->moveresize_emulation_window);
4253 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4255 GDK_BUTTON_RELEASE_MASK |
4256 GDK_POINTER_MOTION_MASK,
4261 if (status != GDK_GRAB_SUCCESS)
4263 /* If this fails, some other client has grabbed the window
4266 finish_drag (mv_resize);
4269 mv_resize->moveresize_process_time = 0;
4273 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
4274 so that calling XMoveWindow with these coordinates will not move the
4276 Note that this depends on the WM to implement ICCCM-compliant reference
4280 calculate_unmoving_origin (MoveResizeData *mv_resize)
4285 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
4286 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
4288 gdk_window_get_origin (mv_resize->moveresize_window,
4289 &mv_resize->moveresize_orig_x,
4290 &mv_resize->moveresize_orig_y);
4294 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
4295 gdk_window_get_geometry (mv_resize->moveresize_window,
4296 NULL, NULL, &width, &height);
4298 switch (mv_resize->moveresize_geometry.win_gravity)
4300 case GDK_GRAVITY_NORTH_WEST:
4301 mv_resize->moveresize_orig_x = rect.x;
4302 mv_resize->moveresize_orig_y = rect.y;
4304 case GDK_GRAVITY_NORTH:
4305 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4306 mv_resize->moveresize_orig_y = rect.y;
4308 case GDK_GRAVITY_NORTH_EAST:
4309 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4310 mv_resize->moveresize_orig_y = rect.y;
4312 case GDK_GRAVITY_WEST:
4313 mv_resize->moveresize_orig_x = rect.x;
4314 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4316 case GDK_GRAVITY_CENTER:
4317 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4318 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4320 case GDK_GRAVITY_EAST:
4321 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4322 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4324 case GDK_GRAVITY_SOUTH_WEST:
4325 mv_resize->moveresize_orig_x = rect.x;
4326 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
4328 case GDK_GRAVITY_SOUTH:
4329 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4330 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
4332 case GDK_GRAVITY_SOUTH_EAST:
4333 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4334 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
4337 mv_resize->moveresize_orig_x = rect.x;
4338 mv_resize->moveresize_orig_y = rect.y;
4345 emulate_resize_drag (GdkWindow *window,
4352 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4354 mv_resize->is_resize = TRUE;
4355 mv_resize->moveresize_button = button;
4356 mv_resize->resize_edge = edge;
4357 mv_resize->moveresize_x = root_x;
4358 mv_resize->moveresize_y = root_y;
4359 mv_resize->moveresize_window = g_object_ref (window);
4361 mv_resize->moveresize_orig_width = gdk_window_get_width (window);
4362 mv_resize->moveresize_orig_height = gdk_window_get_height (window);
4364 mv_resize->moveresize_geom_mask = 0;
4365 gdk_window_get_geometry_hints (window,
4366 &mv_resize->moveresize_geometry,
4367 &mv_resize->moveresize_geom_mask);
4369 calculate_unmoving_origin (mv_resize);
4371 create_moveresize_window (mv_resize, timestamp);
4375 emulate_move_drag (GdkWindow *window,
4381 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4383 mv_resize->is_resize = FALSE;
4384 mv_resize->moveresize_button = button;
4385 mv_resize->moveresize_x = root_x;
4386 mv_resize->moveresize_y = root_y;
4388 mv_resize->moveresize_window = g_object_ref (window);
4390 calculate_unmoving_origin (mv_resize);
4392 create_moveresize_window (mv_resize, timestamp);
4396 gdk_x11_window_begin_resize_drag (GdkWindow *window,
4403 if (GDK_WINDOW_DESTROYED (window) ||
4404 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4407 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4408 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
4409 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4411 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4415 gdk_x11_window_begin_move_drag (GdkWindow *window,
4421 if (GDK_WINDOW_DESTROYED (window) ||
4422 !WINDOW_IS_TOPLEVEL (window))
4425 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4426 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
4427 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
4430 emulate_move_drag (window, button, root_x, root_y, timestamp);
4434 gdk_x11_window_enable_synchronized_configure (GdkWindow *window)
4436 GdkWindowImplX11 *impl;
4438 if (!GDK_IS_WINDOW_IMPL_X11 (window->impl))
4441 impl = GDK_WINDOW_IMPL_X11 (window->impl);
4443 if (!impl->use_synchronized_configure)
4445 /* This basically means you want to do fancy X specific stuff, so
4446 ensure we have a native window */
4447 gdk_window_ensure_native (window);
4449 impl->use_synchronized_configure = TRUE;
4450 ensure_sync_counter (window);
4455 gdk_x11_window_configure_finished (GdkWindow *window)
4457 GdkWindowImplX11 *impl;
4459 if (!WINDOW_IS_TOPLEVEL (window))
4462 impl = GDK_WINDOW_IMPL_X11 (window->impl);
4463 if (!impl->use_synchronized_configure)
4467 if (!GDK_WINDOW_DESTROYED (window))
4469 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4470 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
4472 if (toplevel && toplevel->update_counter != None &&
4473 GDK_DISPLAY_X11 (display)->use_sync &&
4474 !XSyncValueIsZero (toplevel->current_counter_value))
4476 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
4477 toplevel->update_counter,
4478 toplevel->current_counter_value);
4480 XSyncIntToValue (&toplevel->current_counter_value, 0);
4487 gdk_x11_window_beep (GdkWindow *window)
4489 GdkDisplay *display;
4491 display = GDK_WINDOW_DISPLAY (window);
4494 if (GDK_DISPLAY_X11 (display)->use_xkb)
4496 XkbBell (GDK_DISPLAY_XDISPLAY (display),
4497 GDK_WINDOW_XID (window),
4508 gdk_x11_window_set_opacity (GdkWindow *window,
4511 GdkDisplay *display;
4514 g_return_if_fail (GDK_IS_WINDOW (window));
4516 if (GDK_WINDOW_DESTROYED (window) ||
4517 !WINDOW_IS_TOPLEVEL (window))
4520 display = gdk_window_get_display (window);
4524 else if (opacity > 1)
4527 cardinal = opacity * 0xffffffff;
4529 if (cardinal == 0xffffffff)
4530 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
4531 GDK_WINDOW_XID (window),
4532 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"));
4534 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
4535 GDK_WINDOW_XID (window),
4536 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
4539 (guchar *) &cardinal, 1);
4543 gdk_x11_window_set_composited (GdkWindow *window,
4544 gboolean composited)
4546 #if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES)
4547 GdkWindowImplX11 *impl;
4548 GdkDisplay *display;
4552 impl = GDK_WINDOW_IMPL_X11 (window->impl);
4554 display = gdk_window_get_display (window);
4555 dpy = GDK_DISPLAY_XDISPLAY (display);
4556 xid = GDK_WINDOW_XID (window);
4560 XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual);
4561 impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox);
4565 XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual);
4566 XDamageDestroy (dpy, impl->damage);
4567 impl->damage = None;
4573 gdk_x11_window_process_updates_recurse (GdkWindow *window,
4574 cairo_region_t *region)
4576 _gdk_window_process_updates_recurse (window, region);
4580 _gdk_x11_display_before_process_all_updates (GdkDisplay *display)
4585 _gdk_x11_display_after_process_all_updates (GdkDisplay *display)
4590 timestamp_predicate (Display *display,
4594 Window xwindow = GPOINTER_TO_UINT (arg);
4595 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
4597 if (xevent->type == PropertyNotify &&
4598 xevent->xproperty.window == xwindow &&
4599 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
4600 "GDK_TIMESTAMP_PROP"))
4607 * gdk_x11_get_server_time:
4608 * @window: a #GdkWindow, used for communication with the server.
4609 * The window must have GDK_PROPERTY_CHANGE_MASK in its
4610 * events mask or a hang will result.
4612 * Routine to get the current X server time stamp.
4614 * Return value: the time stamp.
4617 gdk_x11_get_server_time (GdkWindow *window)
4623 Atom timestamp_prop_atom;
4625 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
4626 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
4628 xdisplay = GDK_WINDOW_XDISPLAY (window);
4629 xwindow = GDK_WINDOW_XID (window);
4630 timestamp_prop_atom =
4631 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
4632 "GDK_TIMESTAMP_PROP");
4634 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
4635 timestamp_prop_atom,
4636 8, PropModeReplace, &c, 1);
4638 XIfEvent (xdisplay, &xevent,
4639 timestamp_predicate, GUINT_TO_POINTER(xwindow));
4641 return xevent.xproperty.time;
4645 * gdk_x11_window_get_xid:
4646 * @window: a native #GdkWindow.
4648 * Returns the X resource (window) belonging to a #GdkWindow.
4650 * Return value: the ID of @drawable's X resource.
4653 gdk_x11_window_get_xid (GdkWindow *window)
4655 /* Try to ensure the window has a native window */
4656 if (!_gdk_window_has_impl (window))
4658 gdk_window_ensure_native (window);
4660 /* We sync here to ensure the window is created in the Xserver when
4661 * this function returns. This is required because the returned XID
4662 * for this window must be valid immediately, even with another
4663 * connection to the Xserver */
4664 gdk_display_sync (gdk_window_get_display (window));
4667 if (!GDK_WINDOW_IS_X11 (window))
4669 g_warning (G_STRLOC " drawable is not a native X11 window");
4673 return GDK_WINDOW_IMPL_X11 (window->impl)->xid;
4676 extern GdkDragContext * _gdk_x11_window_drag_begin (GdkWindow *window,
4681 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
4683 GObjectClass *object_class = G_OBJECT_CLASS (klass);
4684 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass);
4686 object_class->finalize = gdk_window_impl_x11_finalize;
4688 impl_class->ref_cairo_surface = gdk_x11_ref_cairo_surface;
4689 impl_class->show = gdk_window_x11_show;
4690 impl_class->hide = gdk_window_x11_hide;
4691 impl_class->withdraw = gdk_window_x11_withdraw;
4692 impl_class->set_events = gdk_window_x11_set_events;
4693 impl_class->get_events = gdk_window_x11_get_events;
4694 impl_class->raise = gdk_window_x11_raise;
4695 impl_class->lower = gdk_window_x11_lower;
4696 impl_class->restack_under = gdk_window_x11_restack_under;
4697 impl_class->restack_toplevel = gdk_window_x11_restack_toplevel;
4698 impl_class->move_resize = gdk_window_x11_move_resize;
4699 impl_class->set_background = gdk_window_x11_set_background;
4700 impl_class->reparent = gdk_window_x11_reparent;
4701 impl_class->set_device_cursor = gdk_window_x11_set_device_cursor;
4702 impl_class->get_geometry = gdk_window_x11_get_geometry;
4703 impl_class->get_root_coords = gdk_window_x11_get_root_coords;
4704 impl_class->get_device_state = gdk_window_x11_get_device_state;
4705 impl_class->shape_combine_region = gdk_window_x11_shape_combine_region;
4706 impl_class->input_shape_combine_region = gdk_window_x11_input_shape_combine_region;
4707 impl_class->set_static_gravities = gdk_window_x11_set_static_gravities;
4708 impl_class->queue_antiexpose = _gdk_x11_window_queue_antiexpose;
4709 impl_class->translate = _gdk_x11_window_translate;
4710 impl_class->destroy = gdk_x11_window_destroy;
4711 impl_class->destroy_foreign = gdk_x11_window_destroy_foreign;
4712 impl_class->resize_cairo_surface = gdk_window_x11_resize_cairo_surface;
4713 impl_class->get_shape = gdk_x11_window_get_shape;
4714 impl_class->get_input_shape = gdk_x11_window_get_input_shape;
4715 impl_class->beep = gdk_x11_window_beep;
4717 impl_class->focus = gdk_x11_window_focus;
4718 impl_class->set_type_hint = gdk_x11_window_set_type_hint;
4719 impl_class->get_type_hint = gdk_x11_window_get_type_hint;
4720 impl_class->set_modal_hint = gdk_x11_window_set_modal_hint;
4721 impl_class->set_skip_taskbar_hint = gdk_x11_window_set_skip_taskbar_hint;
4722 impl_class->set_skip_pager_hint = gdk_x11_window_set_skip_pager_hint;
4723 impl_class->set_urgency_hint = gdk_x11_window_set_urgency_hint;
4724 impl_class->set_geometry_hints = gdk_x11_window_set_geometry_hints;
4725 impl_class->set_title = gdk_x11_window_set_title;
4726 impl_class->set_role = gdk_x11_window_set_role;
4727 impl_class->set_startup_id = gdk_x11_window_set_startup_id;
4728 impl_class->set_transient_for = gdk_x11_window_set_transient_for;
4729 impl_class->get_root_origin = gdk_x11_window_get_root_origin;
4730 impl_class->get_frame_extents = gdk_x11_window_get_frame_extents;
4731 impl_class->set_override_redirect = gdk_x11_window_set_override_redirect;
4732 impl_class->set_accept_focus = gdk_x11_window_set_accept_focus;
4733 impl_class->set_focus_on_map = gdk_x11_window_set_focus_on_map;
4734 impl_class->set_icon_list = gdk_x11_window_set_icon_list;
4735 impl_class->set_icon_name = gdk_x11_window_set_icon_name;
4736 impl_class->iconify = gdk_x11_window_iconify;
4737 impl_class->deiconify = gdk_x11_window_deiconify;
4738 impl_class->stick = gdk_x11_window_stick;
4739 impl_class->unstick = gdk_x11_window_unstick;
4740 impl_class->maximize = gdk_x11_window_maximize;
4741 impl_class->unmaximize = gdk_x11_window_unmaximize;
4742 impl_class->fullscreen = gdk_x11_window_fullscreen;
4743 impl_class->unfullscreen = gdk_x11_window_unfullscreen;
4744 impl_class->set_keep_above = gdk_x11_window_set_keep_above;
4745 impl_class->set_keep_below = gdk_x11_window_set_keep_below;
4746 impl_class->get_group = gdk_x11_window_get_group;
4747 impl_class->set_group = gdk_x11_window_set_group;
4748 impl_class->set_decorations = gdk_x11_window_set_decorations;
4749 impl_class->get_decorations = gdk_x11_window_get_decorations;
4750 impl_class->set_functions = gdk_x11_window_set_functions;
4751 impl_class->set_functions = gdk_x11_window_set_functions;
4752 impl_class->begin_resize_drag = gdk_x11_window_begin_resize_drag;
4753 impl_class->begin_move_drag = gdk_x11_window_begin_move_drag;
4754 impl_class->enable_synchronized_configure = gdk_x11_window_enable_synchronized_configure;
4755 impl_class->configure_finished = gdk_x11_window_configure_finished;
4756 impl_class->set_opacity = gdk_x11_window_set_opacity;
4757 impl_class->set_composited = gdk_x11_window_set_composited;
4758 impl_class->destroy_notify = gdk_x11_window_destroy_notify;
4759 impl_class->register_dnd = _gdk_x11_window_register_dnd;
4760 impl_class->drag_begin = _gdk_x11_window_drag_begin;
4761 impl_class->process_updates_recurse = gdk_x11_window_process_updates_recurse;
4762 impl_class->sync_rendering = _gdk_x11_window_sync_rendering;
4763 impl_class->simulate_key = _gdk_x11_window_simulate_key;
4764 impl_class->simulate_button = _gdk_x11_window_simulate_button;