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 struct _GdkX11Window {
135 struct _GdkX11WindowClass {
136 GdkWindowClass parent_class;
139 G_DEFINE_TYPE (GdkX11Window, gdk_x11_window, GDK_TYPE_WINDOW)
142 gdk_x11_window_class_init (GdkX11WindowClass *x11_window_class)
147 gdk_x11_window_init (GdkX11Window *x11_window)
152 G_DEFINE_TYPE (GdkWindowImplX11, gdk_window_impl_x11, GDK_TYPE_WINDOW_IMPL)
155 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
157 impl->toplevel_window_type = -1;
158 impl->device_cursor = g_hash_table_new_full (NULL, NULL,
159 NULL, g_object_unref);
163 _gdk_x11_window_get_toplevel (GdkWindow *window)
165 GdkWindowImplX11 *impl;
167 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
169 if (!WINDOW_IS_TOPLEVEL (window))
172 impl = GDK_WINDOW_IMPL_X11 (window->impl);
175 impl->toplevel = g_new0 (GdkToplevelX11, 1);
177 return impl->toplevel;
180 static const cairo_user_data_key_t gdk_x11_cairo_key;
183 * _gdk_x11_window_update_size:
184 * @impl: a #GdkWindowImplX11.
186 * Updates the state of the window (in particular the drawable's
187 * cairo surface) when its size has changed.
190 _gdk_x11_window_update_size (GdkWindowImplX11 *impl)
192 if (impl->cairo_surface)
194 cairo_xlib_surface_set_size (impl->cairo_surface,
195 gdk_window_get_width (impl->wrapper),
196 gdk_window_get_height (impl->wrapper));
200 /*****************************************************
201 * X11 specific implementations of generic functions *
202 *****************************************************/
205 gdk_x11_cairo_surface_destroy (void *data)
207 GdkWindowImplX11 *impl = data;
209 impl->cairo_surface = NULL;
212 static cairo_surface_t *
213 gdk_x11_create_cairo_surface (GdkWindowImplX11 *impl,
219 visual = gdk_window_get_visual (impl->wrapper);
220 return cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (impl->wrapper),
221 GDK_WINDOW_IMPL_X11 (impl)->xid,
222 GDK_VISUAL_XVISUAL (visual),
226 static cairo_surface_t *
227 gdk_x11_ref_cairo_surface (GdkWindow *window)
229 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
231 if (GDK_WINDOW_DESTROYED (window))
234 if (!impl->cairo_surface)
236 impl->cairo_surface = gdk_x11_create_cairo_surface (impl,
237 gdk_window_get_width (window),
238 gdk_window_get_height (window));
240 if (impl->cairo_surface)
241 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
242 impl, gdk_x11_cairo_surface_destroy);
245 cairo_surface_reference (impl->cairo_surface);
247 return impl->cairo_surface;
251 gdk_window_impl_x11_finalize (GObject *object)
254 GdkWindowImplX11 *impl;
256 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
258 impl = GDK_WINDOW_IMPL_X11 (object);
260 wrapper = impl->wrapper;
262 _gdk_x11_window_grab_check_destroy (wrapper);
264 if (!GDK_WINDOW_DESTROYED (wrapper))
266 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
268 _gdk_x11_display_remove_window (display, impl->xid);
269 if (impl->toplevel && impl->toplevel->focus_window)
270 _gdk_x11_display_remove_window (display, impl->toplevel->focus_window);
273 g_free (impl->toplevel);
276 gdk_cursor_unref (impl->cursor);
278 g_hash_table_destroy (impl->device_cursor);
280 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
289 free_pixmap (gpointer datap)
291 FreePixmapData *data = datap;
293 if (!gdk_display_is_closed (data->display))
295 XFreePixmap (GDK_DISPLAY_XDISPLAY (data->display),
299 g_object_unref (data->display);
300 g_slice_free (FreePixmapData, data);
304 attach_free_pixmap_handler (cairo_surface_t *surface,
308 static const cairo_user_data_key_t key;
309 FreePixmapData *data;
311 data = g_slice_new (FreePixmapData);
312 data->display = g_object_ref (display);
313 data->pixmap = pixmap;
315 cairo_surface_set_user_data (surface, &key, data, free_pixmap);
318 /* Cairo does not guarantee we get an xlib surface if we call
319 * cairo_surface_create_similar(). In some cases however, we must use a
320 * pixmap or bitmap in the X11 API.
321 * These functions ensure an Xlib surface.
324 _gdk_x11_window_create_bitmap_surface (GdkWindow *window,
328 cairo_surface_t *surface;
331 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
332 GDK_WINDOW_XID (window),
334 surface = cairo_xlib_surface_create_for_bitmap (GDK_WINDOW_XDISPLAY (window),
336 GDK_X11_SCREEN (GDK_WINDOW_SCREEN (window))->xscreen,
338 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
343 /* Create a surface backed with a pixmap without alpha on the same screen as window */
344 static cairo_surface_t *
345 gdk_x11_window_create_pixmap_surface (GdkWindow *window,
349 GdkScreen *screen = gdk_window_get_screen (window);
350 GdkVisual *visual = gdk_screen_get_system_visual (screen);
351 cairo_surface_t *surface;
354 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
355 GDK_WINDOW_XID (window),
357 gdk_visual_get_depth (visual));
358 surface = cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (window),
360 GDK_VISUAL_XVISUAL (visual),
362 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
368 tmp_unset_bg (GdkWindow *window)
370 GdkWindowImplX11 *impl;
372 impl = GDK_WINDOW_IMPL_X11 (window->impl);
376 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
377 GDK_WINDOW_XID (window), None);
381 tmp_reset_bg (GdkWindow *window)
383 GdkWindowImplX11 *impl;
385 impl = GDK_WINDOW_IMPL_X11 (window->impl);
389 gdk_window_x11_set_background (window, window->background);
392 /* Unsetting and resetting window backgrounds.
394 * In many cases it is possible to avoid flicker by unsetting the
395 * background of windows. For example if the background of the
396 * parent window is unset when a window is unmapped, a brief flicker
397 * of background painting is avoided.
400 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
403 g_return_if_fail (GDK_IS_WINDOW (window));
405 if (window->input_only || window->destroyed ||
406 (window->window_type != GDK_WINDOW_ROOT &&
407 !GDK_WINDOW_IS_MAPPED (window)))
410 if (_gdk_window_has_impl (window) &&
411 GDK_WINDOW_IS_X11 (window) &&
412 window->window_type != GDK_WINDOW_ROOT &&
413 window->window_type != GDK_WINDOW_FOREIGN)
414 tmp_unset_bg (window);
420 for (l = window->children; l != NULL; l = l->next)
421 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
426 _gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window)
428 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
431 window = _gdk_window_get_impl_window (window->parent);
432 _gdk_x11_window_tmp_unset_bg (window, FALSE);
436 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
439 g_return_if_fail (GDK_IS_WINDOW (window));
441 if (window->input_only || window->destroyed ||
442 (window->window_type != GDK_WINDOW_ROOT &&
443 !GDK_WINDOW_IS_MAPPED (window)))
447 if (_gdk_window_has_impl (window) &&
448 GDK_WINDOW_IS_X11 (window) &&
449 window->window_type != GDK_WINDOW_ROOT &&
450 window->window_type != GDK_WINDOW_FOREIGN)
451 tmp_reset_bg (window);
457 for (l = window->children; l != NULL; l = l->next)
458 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
463 _gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window)
465 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
468 window = _gdk_window_get_impl_window (window->parent);
470 _gdk_x11_window_tmp_reset_bg (window, FALSE);
474 _gdk_x11_screen_init_root_window (GdkScreen *screen)
477 GdkWindowImplX11 *impl;
478 GdkX11Screen *x11_screen;
480 x11_screen = GDK_X11_SCREEN (screen);
482 g_assert (x11_screen->root_window == NULL);
484 window = x11_screen->root_window = _gdk_display_create_window (gdk_screen_get_display (screen));
486 window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
487 window->impl_window = window;
488 window->visual = gdk_screen_get_system_visual (screen);
490 impl = GDK_WINDOW_IMPL_X11 (window->impl);
492 impl->xid = x11_screen->xroot_window;
493 impl->wrapper = window;
495 window->window_type = GDK_WINDOW_ROOT;
496 window->depth = DefaultDepthOfScreen (x11_screen->xscreen);
502 window->width = WidthOfScreen (x11_screen->xscreen);
503 window->height = HeightOfScreen (x11_screen->xscreen);
504 window->viewable = TRUE;
506 /* see init_randr_support() in gdkscreen-x11.c */
507 window->event_mask = GDK_STRUCTURE_MASK;
509 _gdk_window_update_size (x11_screen->root_window);
511 _gdk_x11_display_add_window (x11_screen->display,
512 &x11_screen->xroot_window,
513 x11_screen->root_window);
517 set_wm_protocols (GdkWindow *window)
519 GdkDisplay *display = gdk_window_get_display (window);
523 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
524 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
525 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
528 if (GDK_X11_DISPLAY (display)->use_sync)
529 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
532 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
536 get_default_title (void)
540 title = g_get_application_name ();
542 title = g_get_prgname ();
550 check_leader_window_title (GdkDisplay *display)
552 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
554 if (display_x11->leader_window && !display_x11->leader_window_title_set)
556 set_wm_name (display,
557 display_x11->leader_window,
558 get_default_title ());
560 display_x11->leader_window_title_set = TRUE;
565 create_focus_window (GdkDisplay *display,
568 GdkX11Display *display_x11;
569 GdkEventMask event_mask;
573 xdisplay = GDK_DISPLAY_XDISPLAY (display);
574 display_x11 = GDK_X11_DISPLAY (display);
576 focus_window = XCreateSimpleWindow (xdisplay, parent,
580 /* FIXME: probably better to actually track the requested event mask for the toplevel
582 event_mask = (GDK_KEY_PRESS_MASK |
583 GDK_KEY_RELEASE_MASK |
584 GDK_FOCUS_CHANGE_MASK);
586 gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
590 XMapWindow (xdisplay, focus_window);
596 ensure_sync_counter (GdkWindow *window)
599 if (!GDK_WINDOW_DESTROYED (window))
601 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
602 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
603 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
605 if (toplevel && impl->use_synchronized_configure &&
606 toplevel->update_counter == None &&
607 GDK_X11_DISPLAY (display)->use_sync)
609 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
613 XSyncIntToValue (&value, 0);
615 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
617 atom = gdk_x11_get_xatom_by_name_for_display (display,
618 "_NET_WM_SYNC_REQUEST_COUNTER");
620 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
623 (guchar *)&toplevel->update_counter, 1);
625 XSyncIntToValue (&toplevel->current_counter_value, 0);
632 setup_toplevel_window (GdkWindow *window,
635 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
636 GdkDisplay *display = gdk_window_get_display (window);
637 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
638 XID xid = GDK_WINDOW_XID (window);
639 GdkX11Screen *x11_screen = GDK_X11_SCREEN (GDK_WINDOW_SCREEN (parent));
640 XSizeHints size_hints;
642 Window leader_window;
644 set_wm_protocols (window);
646 if (!window->input_only)
648 /* The focus window is off the visible area, and serves to receive key
649 * press events so they don't get sent to child windows.
651 toplevel->focus_window = create_focus_window (display, xid);
652 _gdk_x11_display_add_window (x11_screen->display,
653 &toplevel->focus_window,
657 check_leader_window_title (x11_screen->display);
659 /* FIXME: Is there any point in doing this? Do any WM's pay
660 * attention to PSize, and even if they do, is this the
663 size_hints.flags = PSize;
664 size_hints.width = window->width;
665 size_hints.height = window->height;
667 XSetWMNormalHints (xdisplay, xid, &size_hints);
669 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
670 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
673 XChangeProperty (xdisplay, xid,
674 gdk_x11_get_xatom_by_name_for_display (x11_screen->display, "_NET_WM_PID"),
679 leader_window = GDK_X11_DISPLAY (x11_screen->display)->leader_window;
682 XChangeProperty (xdisplay, xid,
683 gdk_x11_get_xatom_by_name_for_display (x11_screen->display, "WM_CLIENT_LEADER"),
684 XA_WINDOW, 32, PropModeReplace,
685 (guchar *) &leader_window, 1);
687 if (toplevel->focus_window != None)
688 XChangeProperty (xdisplay, xid,
689 gdk_x11_get_xatom_by_name_for_display (x11_screen->display, "_NET_WM_USER_TIME_WINDOW"),
690 XA_WINDOW, 32, PropModeReplace,
691 (guchar *) &toplevel->focus_window, 1);
693 if (!window->focus_on_map)
694 gdk_x11_window_set_user_time (window, 0);
695 else if (GDK_X11_DISPLAY (x11_screen->display)->user_time != 0)
696 gdk_x11_window_set_user_time (window, GDK_X11_DISPLAY (x11_screen->display)->user_time);
698 ensure_sync_counter (window);
702 _gdk_x11_display_create_window_impl (GdkDisplay *display,
704 GdkWindow *real_parent,
706 GdkEventMask event_mask,
707 GdkWindowAttr *attributes,
708 gint attributes_mask)
710 GdkWindowImplX11 *impl;
711 GdkX11Screen *x11_screen;
712 GdkX11Display *display_x11;
718 XSetWindowAttributes xattributes;
719 long xattributes_mask;
720 XClassHint *class_hint;
725 display_x11 = GDK_X11_DISPLAY (display);
726 xparent = GDK_WINDOW_XID (real_parent);
727 x11_screen = GDK_X11_SCREEN (screen);
729 impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
730 window->impl = GDK_WINDOW_IMPL (impl);
731 impl->wrapper = GDK_WINDOW (window);
733 xdisplay = x11_screen->xdisplay;
735 xattributes_mask = 0;
737 xvisual = gdk_x11_visual_get_xvisual (window->visual);
739 if (attributes_mask & GDK_WA_NOREDIR)
741 xattributes.override_redirect =
742 (attributes->override_redirect == FALSE)?False:True;
743 xattributes_mask |= CWOverrideRedirect;
746 xattributes.override_redirect = False;
748 impl->override_redirect = xattributes.override_redirect;
750 if (window->parent && window->parent->guffaw_gravity)
752 xattributes.win_gravity = StaticGravity;
753 xattributes_mask |= CWWinGravity;
757 switch (window->window_type)
759 case GDK_WINDOW_TOPLEVEL:
760 case GDK_WINDOW_TEMP:
761 if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT)
763 /* The common code warns for this case */
764 xparent = GDK_SCREEN_XROOTWIN (screen);
768 if (!window->input_only)
772 xattributes.background_pixel = BlackPixel (xdisplay, x11_screen->screen_num);
774 xattributes.border_pixel = BlackPixel (xdisplay, x11_screen->screen_num);
775 xattributes_mask |= CWBorderPixel | CWBackPixel;
777 if (window->guffaw_gravity)
778 xattributes.bit_gravity = StaticGravity;
780 xattributes.bit_gravity = NorthWestGravity;
782 xattributes_mask |= CWBitGravity;
784 xattributes.colormap = _gdk_visual_get_x11_colormap (window->visual);
785 xattributes_mask |= CWColormap;
787 if (window->window_type == GDK_WINDOW_TEMP)
789 xattributes.save_under = True;
790 xattributes.override_redirect = True;
791 xattributes.cursor = None;
792 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
794 impl->override_redirect = TRUE;
802 if (window->width > 65535 ||
803 window->height > 65535)
805 g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
807 if (window->width > 65535)
808 window->width = 65535;
809 if (window->height > 65535)
810 window->height = 65535;
813 impl->xid = XCreateWindow (xdisplay, xparent,
814 window->x + window->parent->abs_x,
815 window->y + window->parent->abs_y,
816 window->width, window->height,
817 0, window->depth, class, xvisual,
818 xattributes_mask, &xattributes);
820 g_object_ref (window);
821 _gdk_x11_display_add_window (x11_screen->display, &impl->xid, window);
823 switch (GDK_WINDOW_TYPE (window))
825 case GDK_WINDOW_TOPLEVEL:
826 case GDK_WINDOW_TEMP:
827 if (attributes_mask & GDK_WA_TITLE)
828 title = attributes->title;
830 title = get_default_title ();
832 gdk_window_set_title (window, title);
834 if (attributes_mask & GDK_WA_WMCLASS)
836 class_hint = XAllocClassHint ();
837 class_hint->res_name = attributes->wmclass_name;
838 class_hint->res_class = attributes->wmclass_class;
839 XSetClassHint (xdisplay, impl->xid, class_hint);
843 setup_toplevel_window (window, window->parent);
846 case GDK_WINDOW_CHILD:
851 if (attributes_mask & GDK_WA_TYPE_HINT)
852 gdk_window_set_type_hint (window, attributes->type_hint);
854 gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
855 GDK_WINDOW_XID (window), event_mask,
856 StructureNotifyMask | PropertyChangeMask);
860 x_event_mask_to_gdk_event_mask (long mask)
862 GdkEventMask event_mask = 0;
865 for (i = 0; i < _gdk_x11_event_mask_table_size; i++)
867 if (mask & _gdk_x11_event_mask_table[i])
868 event_mask |= 1 << (i + 1);
875 * gdk_x11_window_foreign_new_for_display:
876 * @display: the #GdkDisplay where the window handle comes from.
877 * @window: an XLib <type>Window</type>
879 * Wraps a native window in a #GdkWindow.
881 * This may fail if the window has been destroyed. If the window
882 * was already known to GDK, a new reference to the existing
883 * #GdkWindow is returned.
885 * Return value: (transfer full): a #GdkWindow wrapper for the native
886 * window, or %NULL if the window has been destroyed. The wrapper
887 * will be newly created, if one doesn't exist already.
892 gdk_x11_window_foreign_new_for_display (GdkDisplay *display,
897 GdkWindowImplX11 *impl;
898 GdkX11Display *display_x11;
899 XWindowAttributes attrs;
901 Window *children = NULL;
905 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
907 display_x11 = GDK_X11_DISPLAY (display);
909 if ((win = gdk_x11_window_lookup_for_display (display, window)) != NULL)
910 return g_object_ref (win);
912 gdk_x11_display_error_trap_push (display);
913 result = XGetWindowAttributes (display_x11->xdisplay, window, &attrs);
914 if (gdk_x11_display_error_trap_pop (display) || !result)
917 /* FIXME: This is pretty expensive.
918 * Maybe the caller should supply the parent
920 gdk_x11_display_error_trap_push (display);
921 result = XQueryTree (display_x11->xdisplay, window, &root, &parent, &children, &nchildren);
922 if (gdk_x11_display_error_trap_pop (display) || !result)
928 screen = _gdk_x11_display_screen_for_xrootwin (display, root);
930 win = _gdk_display_create_window (display);
931 win->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
932 win->impl_window = win;
933 win->visual = gdk_x11_screen_lookup_visual (screen,
934 XVisualIDFromVisual (attrs.visual));
936 impl = GDK_WINDOW_IMPL_X11 (win->impl);
939 win->parent = gdk_x11_window_lookup_for_display (display, parent);
941 if (!win->parent || GDK_WINDOW_TYPE (win->parent) == GDK_WINDOW_FOREIGN)
942 win->parent = gdk_screen_get_root_window (screen);
944 win->parent->children = g_list_prepend (win->parent->children, win);
950 win->width = attrs.width;
951 win->height = attrs.height;
952 win->window_type = GDK_WINDOW_FOREIGN;
953 win->destroyed = FALSE;
955 win->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
957 if (attrs.map_state == IsUnmapped)
958 win->state = GDK_WINDOW_STATE_WITHDRAWN;
961 win->viewable = TRUE;
963 win->depth = attrs.depth;
966 _gdk_x11_display_add_window (display, &GDK_WINDOW_XID (win), win);
968 /* Update the clip region, etc */
969 _gdk_window_update_size (win);
975 gdk_toplevel_x11_free_contents (GdkDisplay *display,
976 GdkToplevelX11 *toplevel)
978 if (toplevel->icon_pixmap)
980 cairo_surface_destroy (toplevel->icon_pixmap);
981 toplevel->icon_pixmap = NULL;
983 if (toplevel->icon_mask)
985 cairo_surface_destroy (toplevel->icon_mask);
986 toplevel->icon_mask = NULL;
988 if (toplevel->group_leader)
990 g_object_unref (toplevel->group_leader);
991 toplevel->group_leader = NULL;
994 if (toplevel->update_counter != None)
996 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
997 toplevel->update_counter);
998 toplevel->update_counter = None;
1000 XSyncIntToValue (&toplevel->current_counter_value, 0);
1006 gdk_x11_window_destroy (GdkWindow *window,
1008 gboolean foreign_destroy)
1010 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1011 GdkToplevelX11 *toplevel;
1013 g_return_if_fail (GDK_IS_WINDOW (window));
1015 _gdk_x11_selection_window_destroyed (window);
1017 toplevel = _gdk_x11_window_get_toplevel (window);
1019 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1021 if (impl->cairo_surface)
1023 cairo_surface_finish (impl->cairo_surface);
1024 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
1028 if (!recursing && !foreign_destroy)
1029 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1032 static cairo_surface_t *
1033 gdk_window_x11_resize_cairo_surface (GdkWindow *window,
1034 cairo_surface_t *surface,
1038 cairo_xlib_surface_set_size (surface, width, height);
1044 gdk_x11_window_destroy_foreign (GdkWindow *window)
1046 /* It's somebody else's window, but in our hierarchy,
1047 * so reparent it to the root window, and then send
1048 * it a delete event, as if we were a WM
1050 XClientMessageEvent xclient;
1051 GdkDisplay *display;
1053 display = GDK_WINDOW_DISPLAY (window);
1054 gdk_x11_display_error_trap_push (display);
1055 gdk_window_hide (window);
1056 gdk_window_reparent (window, NULL, 0, 0);
1058 memset (&xclient, 0, sizeof (xclient));
1059 xclient.type = ClientMessage;
1060 xclient.window = GDK_WINDOW_XID (window);
1061 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "WM_PROTOCOLS");
1062 xclient.format = 32;
1063 xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
1064 xclient.data.l[1] = CurrentTime;
1065 xclient.data.l[2] = 0;
1066 xclient.data.l[3] = 0;
1067 xclient.data.l[4] = 0;
1069 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1070 GDK_WINDOW_XID (window),
1071 False, 0, (XEvent *)&xclient);
1072 gdk_x11_display_error_trap_pop_ignored (display);
1076 get_root (GdkWindow *window)
1078 GdkScreen *screen = gdk_window_get_screen (window);
1080 return gdk_screen_get_root_window (screen);
1083 /* This function is called when the XWindow is really gone.
1086 gdk_x11_window_destroy_notify (GdkWindow *window)
1088 GdkWindowImplX11 *window_impl;
1090 window_impl = GDK_WINDOW_IMPL_X11 ((window)->impl);
1092 if (!GDK_WINDOW_DESTROYED (window))
1094 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1095 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1097 _gdk_window_destroy (window, TRUE);
1100 _gdk_x11_display_remove_window (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1101 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1102 _gdk_x11_display_remove_window (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1104 _gdk_x11_window_grab_check_destroy (window);
1106 g_object_unref (window);
1110 update_wm_hints (GdkWindow *window,
1113 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1114 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1118 !toplevel->is_leader &&
1119 window->state & GDK_WINDOW_STATE_WITHDRAWN)
1122 wm_hints.flags = StateHint | InputHint;
1123 wm_hints.input = window->accept_focus ? True : False;
1124 wm_hints.initial_state = NormalState;
1126 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
1128 wm_hints.flags |= StateHint;
1129 wm_hints.initial_state = IconicState;
1132 if (toplevel->icon_pixmap)
1134 wm_hints.flags |= IconPixmapHint;
1135 wm_hints.icon_pixmap = cairo_xlib_surface_get_drawable (toplevel->icon_pixmap);
1138 if (toplevel->icon_mask)
1140 wm_hints.flags |= IconMaskHint;
1141 wm_hints.icon_mask = cairo_xlib_surface_get_drawable (toplevel->icon_mask);
1144 wm_hints.flags |= WindowGroupHint;
1145 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1147 wm_hints.flags |= WindowGroupHint;
1148 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1151 wm_hints.window_group = GDK_X11_DISPLAY (display)->leader_window;
1153 if (toplevel->urgency_hint)
1154 wm_hints.flags |= XUrgencyHint;
1156 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1157 GDK_WINDOW_XID (window),
1162 set_initial_hints (GdkWindow *window)
1164 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1165 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1166 Window xwindow = GDK_WINDOW_XID (window);
1167 GdkToplevelX11 *toplevel;
1171 toplevel = _gdk_x11_window_get_toplevel (window);
1176 update_wm_hints (window, TRUE);
1178 /* We set the spec hints regardless of whether the spec is supported,
1179 * since it can't hurt and it's kind of expensive to check whether
1185 if (window->state & GDK_WINDOW_STATE_MAXIMIZED)
1187 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1188 "_NET_WM_STATE_MAXIMIZED_VERT");
1190 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1191 "_NET_WM_STATE_MAXIMIZED_HORZ");
1193 toplevel->have_maxhorz = toplevel->have_maxvert = TRUE;
1196 if (window->state & GDK_WINDOW_STATE_ABOVE)
1198 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1199 "_NET_WM_STATE_ABOVE");
1203 if (window->state & GDK_WINDOW_STATE_BELOW)
1205 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1206 "_NET_WM_STATE_BELOW");
1210 if (window->state & GDK_WINDOW_STATE_STICKY)
1212 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1213 "_NET_WM_STATE_STICKY");
1215 toplevel->have_sticky = TRUE;
1218 if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
1220 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1221 "_NET_WM_STATE_FULLSCREEN");
1223 toplevel->have_fullscreen = TRUE;
1226 if (window->modal_hint)
1228 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1229 "_NET_WM_STATE_MODAL");
1233 if (toplevel->skip_taskbar_hint)
1235 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1236 "_NET_WM_STATE_SKIP_TASKBAR");
1240 if (toplevel->skip_pager_hint)
1242 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1243 "_NET_WM_STATE_SKIP_PAGER");
1249 XChangeProperty (xdisplay,
1251 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1252 XA_ATOM, 32, PropModeReplace,
1253 (guchar*) atoms, i);
1257 XDeleteProperty (xdisplay,
1259 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1262 if (window->state & GDK_WINDOW_STATE_STICKY)
1264 atoms[0] = 0xFFFFFFFF;
1265 XChangeProperty (xdisplay,
1267 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1268 XA_CARDINAL, 32, PropModeReplace,
1269 (guchar*) atoms, 1);
1270 toplevel->on_all_desktops = TRUE;
1274 XDeleteProperty (xdisplay,
1276 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1279 toplevel->map_serial = NextRequest (xdisplay);
1283 gdk_window_x11_show (GdkWindow *window, gboolean already_mapped)
1285 GdkDisplay *display;
1286 GdkX11Display *display_x11;
1287 GdkToplevelX11 *toplevel;
1288 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1289 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1290 Window xwindow = GDK_WINDOW_XID (window);
1293 if (!already_mapped)
1294 set_initial_hints (window);
1296 if (WINDOW_IS_TOPLEVEL (window))
1298 display = gdk_window_get_display (window);
1299 display_x11 = GDK_X11_DISPLAY (display);
1300 toplevel = _gdk_x11_window_get_toplevel (window);
1302 if (toplevel->user_time != 0 &&
1303 display_x11->user_time != 0 &&
1304 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1305 gdk_x11_window_set_user_time (window, display_x11->user_time);
1308 unset_bg = !window->input_only &&
1309 (window->window_type == GDK_WINDOW_CHILD ||
1310 impl->override_redirect) &&
1311 gdk_window_is_viewable (window);
1314 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1316 XMapWindow (xdisplay, xwindow);
1319 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1323 pre_unmap (GdkWindow *window)
1325 GdkWindow *start_window = NULL;
1327 if (window->input_only)
1330 if (window->window_type == GDK_WINDOW_CHILD)
1331 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1332 else if (window->window_type == GDK_WINDOW_TEMP)
1333 start_window = get_root (window);
1336 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1340 post_unmap (GdkWindow *window)
1342 GdkWindow *start_window = NULL;
1344 if (window->input_only)
1347 if (window->window_type == GDK_WINDOW_CHILD)
1348 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1349 else if (window->window_type == GDK_WINDOW_TEMP)
1350 start_window = get_root (window);
1354 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1356 if (window->window_type == GDK_WINDOW_CHILD && window->parent)
1358 GdkRectangle invalid_rect;
1360 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1361 invalid_rect.width = gdk_window_get_width (window);
1362 invalid_rect.height = gdk_window_get_height (window);
1363 gdk_window_invalidate_rect ((GdkWindow *)window->parent,
1364 &invalid_rect, TRUE);
1370 gdk_window_x11_hide (GdkWindow *window)
1372 /* We'll get the unmap notify eventually, and handle it then,
1373 * but checking here makes things more consistent if we are
1374 * just doing stuff ourself.
1376 _gdk_x11_window_grab_check_unmap (window,
1377 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1379 /* You can't simply unmap toplevel windows. */
1380 switch (window->window_type)
1382 case GDK_WINDOW_TOPLEVEL:
1383 case GDK_WINDOW_TEMP: /* ? */
1384 gdk_window_withdraw (window);
1387 case GDK_WINDOW_FOREIGN:
1388 case GDK_WINDOW_ROOT:
1389 case GDK_WINDOW_CHILD:
1393 _gdk_window_clear_update_area (window);
1396 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1397 GDK_WINDOW_XID (window));
1398 post_unmap (window);
1402 gdk_window_x11_withdraw (GdkWindow *window)
1404 if (!window->destroyed)
1406 if (GDK_WINDOW_IS_MAPPED (window))
1407 gdk_synthesize_window_state (window,
1409 GDK_WINDOW_STATE_WITHDRAWN);
1411 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1415 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1416 GDK_WINDOW_XID (window), 0);
1418 post_unmap (window);
1423 window_x11_move (GdkWindow *window,
1427 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1429 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1431 _gdk_x11_window_move_resize_child (window,
1433 window->width, window->height);
1437 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1438 GDK_WINDOW_XID (window),
1441 if (impl->override_redirect)
1450 window_x11_resize (GdkWindow *window,
1460 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1462 _gdk_x11_window_move_resize_child (window,
1463 window->x, window->y,
1468 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1470 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1471 GDK_WINDOW_XID (window),
1474 if (impl->override_redirect)
1476 window->width = width;
1477 window->height = height;
1478 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1482 if (width != window->width || height != window->height)
1483 window->resize_count += 1;
1487 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1491 window_x11_move_resize (GdkWindow *window,
1503 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1505 _gdk_x11_window_move_resize_child (window, x, y, width, height);
1506 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1510 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1512 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1513 GDK_WINDOW_XID (window),
1514 x, y, width, height);
1516 if (impl->override_redirect)
1521 window->width = width;
1522 window->height = height;
1524 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1528 if (width != window->width || height != window->height)
1529 window->resize_count += 1;
1535 gdk_window_x11_move_resize (GdkWindow *window,
1542 if (with_move && (width < 0 && height < 0))
1543 window_x11_move (window, x, y);
1547 window_x11_move_resize (window, x, y, width, height);
1549 window_x11_resize (window, width, height);
1554 gdk_window_x11_reparent (GdkWindow *window,
1555 GdkWindow *new_parent,
1559 GdkWindowImplX11 *impl;
1561 impl = GDK_WINDOW_IMPL_X11 (window->impl);
1563 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1564 _gdk_x11_window_tmp_unset_parent_bg (window);
1565 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1566 GDK_WINDOW_XID (window),
1567 GDK_WINDOW_XID (new_parent),
1568 new_parent->abs_x + x, new_parent->abs_y + y);
1569 _gdk_x11_window_tmp_reset_parent_bg (window);
1570 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1572 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1573 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1575 window->parent = new_parent;
1577 /* Switch the window type as appropriate */
1579 switch (GDK_WINDOW_TYPE (new_parent))
1581 case GDK_WINDOW_ROOT:
1582 case GDK_WINDOW_FOREIGN:
1583 /* Reparenting to toplevel */
1585 if (!WINDOW_IS_TOPLEVEL (window) &&
1586 GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1588 /* This is also done in common code at a later stage, but we
1589 need it in setup_toplevel, so do it here too */
1590 if (window->toplevel_window_type != -1)
1591 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1592 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1593 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1595 /* Wasn't a toplevel, set up */
1596 setup_toplevel_window (window, new_parent);
1601 case GDK_WINDOW_TOPLEVEL:
1602 case GDK_WINDOW_CHILD:
1603 case GDK_WINDOW_TEMP:
1604 if (WINDOW_IS_TOPLEVEL (window) &&
1607 if (impl->toplevel->focus_window)
1609 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1610 _gdk_x11_display_remove_window (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1613 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1615 g_free (impl->toplevel);
1616 impl->toplevel = NULL;
1624 gdk_window_x11_raise (GdkWindow *window)
1626 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1630 gdk_window_x11_restack_under (GdkWindow *window,
1631 GList *native_siblings /* in requested order, first is bottom-most */)
1637 n_windows = g_list_length (native_siblings) + 1;
1638 windows = g_new (Window, n_windows);
1640 windows[0] = GDK_WINDOW_XID (window);
1641 /* Reverse order, as input order is bottom-most first */
1643 for (l = native_siblings; l != NULL; l = l->next)
1644 windows[i--] = GDK_WINDOW_XID (l->data);
1646 XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows);
1652 gdk_window_x11_restack_toplevel (GdkWindow *window,
1656 XWindowChanges changes;
1658 changes.sibling = GDK_WINDOW_XID (sibling);
1659 changes.stack_mode = above ? Above : Below;
1660 XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window),
1661 GDK_WINDOW_XID (window),
1662 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)),
1663 CWStackMode | CWSibling, &changes);
1667 gdk_window_x11_lower (GdkWindow *window)
1669 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1673 * gdk_x11_window_move_to_current_desktop:
1674 * @window: a #GdkWindow
1676 * Moves the window to the correct workspace when running under a
1677 * window manager that supports multiple workspaces, as described
1678 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
1679 * Window Manager Hints</ulink>. Will not do anything if the
1680 * window is already on all workspaces.
1685 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
1687 GdkToplevelX11 *toplevel;
1689 g_return_if_fail (GDK_IS_WINDOW (window));
1690 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1692 toplevel = _gdk_x11_window_get_toplevel (window);
1694 if (toplevel->on_all_desktops)
1697 move_to_current_desktop (window);
1701 move_to_current_desktop (GdkWindow *window)
1703 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1704 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
1711 gulong *current_desktop;
1712 GdkDisplay *display;
1714 display = gdk_window_get_display (window);
1716 /* Get current desktop, then set it; this is a race, but not
1717 * one that matters much in practice.
1719 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
1720 GDK_WINDOW_XROOTWIN (window),
1721 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
1723 False, XA_CARDINAL, &type, &format, &nitems,
1724 &bytes_after, &data);
1726 if (type == XA_CARDINAL)
1728 XClientMessageEvent xclient;
1729 current_desktop = (gulong *)data;
1731 memset (&xclient, 0, sizeof (xclient));
1732 xclient.type = ClientMessage;
1734 xclient.send_event = True;
1735 xclient.window = GDK_WINDOW_XID (window);
1736 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
1737 xclient.format = 32;
1739 xclient.data.l[0] = *current_desktop;
1740 xclient.data.l[1] = 0;
1741 xclient.data.l[2] = 0;
1742 xclient.data.l[3] = 0;
1743 xclient.data.l[4] = 0;
1745 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
1746 GDK_WINDOW_XROOTWIN (window),
1748 SubstructureRedirectMask | SubstructureNotifyMask,
1749 (XEvent *)&xclient);
1751 XFree (current_desktop);
1757 gdk_x11_window_focus (GdkWindow *window,
1760 GdkDisplay *display;
1762 g_return_if_fail (GDK_IS_WINDOW (window));
1764 if (GDK_WINDOW_DESTROYED (window) ||
1765 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1768 display = GDK_WINDOW_DISPLAY (window);
1770 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1771 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1773 XClientMessageEvent xclient;
1775 memset (&xclient, 0, sizeof (xclient));
1776 xclient.type = ClientMessage;
1777 xclient.window = GDK_WINDOW_XID (window);
1778 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1779 "_NET_ACTIVE_WINDOW");
1780 xclient.format = 32;
1781 xclient.data.l[0] = 1; /* requestor type; we're an app */
1782 xclient.data.l[1] = timestamp;
1783 xclient.data.l[2] = None; /* currently active window */
1784 xclient.data.l[3] = 0;
1785 xclient.data.l[4] = 0;
1787 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1788 SubstructureRedirectMask | SubstructureNotifyMask,
1789 (XEvent *)&xclient);
1793 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1795 /* There is no way of knowing reliably whether we are viewable;
1796 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1798 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1805 gdk_x11_window_set_type_hint (GdkWindow *window,
1806 GdkWindowTypeHint hint)
1808 GdkDisplay *display;
1811 if (GDK_WINDOW_DESTROYED (window) ||
1812 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1815 display = gdk_window_get_display (window);
1819 case GDK_WINDOW_TYPE_HINT_DIALOG:
1820 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1822 case GDK_WINDOW_TYPE_HINT_MENU:
1823 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1825 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1826 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1828 case GDK_WINDOW_TYPE_HINT_UTILITY:
1829 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1831 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1832 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1834 case GDK_WINDOW_TYPE_HINT_DOCK:
1835 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1837 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1838 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1840 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
1841 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
1843 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
1844 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
1846 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
1847 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
1849 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
1850 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
1852 case GDK_WINDOW_TYPE_HINT_COMBO:
1853 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
1855 case GDK_WINDOW_TYPE_HINT_DND:
1856 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
1859 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1861 case GDK_WINDOW_TYPE_HINT_NORMAL:
1862 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1866 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1867 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1868 XA_ATOM, 32, PropModeReplace,
1869 (guchar *)&atom, 1);
1872 static GdkWindowTypeHint
1873 gdk_x11_window_get_type_hint (GdkWindow *window)
1875 GdkDisplay *display;
1876 GdkWindowTypeHint type;
1879 gulong nitems_return;
1880 gulong bytes_after_return;
1881 guchar *data = NULL;
1883 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
1885 if (GDK_WINDOW_DESTROYED (window) ||
1886 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1887 return GDK_WINDOW_TYPE_HINT_NORMAL;
1889 type = GDK_WINDOW_TYPE_HINT_NORMAL;
1891 display = gdk_window_get_display (window);
1893 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1894 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1895 0, G_MAXLONG, False, XA_ATOM, &type_return,
1896 &format_return, &nitems_return, &bytes_after_return,
1899 if ((type_return == XA_ATOM) && (format_return == 32) &&
1900 (data) && (nitems_return == 1))
1902 Atom atom = *(Atom*)data;
1904 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
1905 type = GDK_WINDOW_TYPE_HINT_DIALOG;
1906 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
1907 type = GDK_WINDOW_TYPE_HINT_MENU;
1908 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
1909 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
1910 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
1911 type = GDK_WINDOW_TYPE_HINT_UTILITY;
1912 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
1913 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
1914 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
1915 type = GDK_WINDOW_TYPE_HINT_DOCK;
1916 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
1917 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
1918 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
1919 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
1920 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
1921 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
1922 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
1923 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
1924 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
1925 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
1926 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
1927 type = GDK_WINDOW_TYPE_HINT_COMBO;
1928 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
1929 type = GDK_WINDOW_TYPE_HINT_DND;
1932 if (type_return != None && data != NULL)
1940 gdk_wmspec_change_state (gboolean add,
1945 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1946 XClientMessageEvent xclient;
1948 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1949 #define _NET_WM_STATE_ADD 1 /* add/set property */
1950 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1952 memset (&xclient, 0, sizeof (xclient));
1953 xclient.type = ClientMessage;
1954 xclient.window = GDK_WINDOW_XID (window);
1955 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1956 xclient.format = 32;
1957 xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1958 xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1959 xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1960 xclient.data.l[3] = 0;
1961 xclient.data.l[4] = 0;
1963 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1964 SubstructureRedirectMask | SubstructureNotifyMask,
1965 (XEvent *)&xclient);
1969 gdk_x11_window_set_modal_hint (GdkWindow *window,
1972 if (GDK_WINDOW_DESTROYED (window) ||
1973 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1976 window->modal_hint = modal;
1978 if (GDK_WINDOW_IS_MAPPED (window))
1979 gdk_wmspec_change_state (modal, window,
1980 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
1985 gdk_x11_window_set_skip_taskbar_hint (GdkWindow *window,
1986 gboolean skips_taskbar)
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_taskbar_hint = skips_taskbar;
1999 if (GDK_WINDOW_IS_MAPPED (window))
2000 gdk_wmspec_change_state (skips_taskbar, window,
2001 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
2006 gdk_x11_window_set_skip_pager_hint (GdkWindow *window,
2007 gboolean skips_pager)
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->skip_pager_hint = skips_pager;
2020 if (GDK_WINDOW_IS_MAPPED (window))
2021 gdk_wmspec_change_state (skips_pager, window,
2022 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2027 gdk_x11_window_set_urgency_hint (GdkWindow *window,
2030 GdkToplevelX11 *toplevel;
2032 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2034 if (GDK_WINDOW_DESTROYED (window) ||
2035 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2038 toplevel = _gdk_x11_window_get_toplevel (window);
2039 toplevel->urgency_hint = urgent;
2041 update_wm_hints (window, FALSE);
2045 gdk_x11_window_set_geometry_hints (GdkWindow *window,
2046 const GdkGeometry *geometry,
2047 GdkWindowHints geom_mask)
2049 XSizeHints size_hints;
2051 if (GDK_WINDOW_DESTROYED (window) ||
2052 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2055 size_hints.flags = 0;
2057 if (geom_mask & GDK_HINT_POS)
2059 size_hints.flags |= PPosition;
2060 /* We need to initialize the following obsolete fields because KWM
2061 * apparently uses these fields if they are non-zero.
2068 if (geom_mask & GDK_HINT_USER_POS)
2070 size_hints.flags |= USPosition;
2073 if (geom_mask & GDK_HINT_USER_SIZE)
2075 size_hints.flags |= USSize;
2078 if (geom_mask & GDK_HINT_MIN_SIZE)
2080 size_hints.flags |= PMinSize;
2081 size_hints.min_width = geometry->min_width;
2082 size_hints.min_height = geometry->min_height;
2085 if (geom_mask & GDK_HINT_MAX_SIZE)
2087 size_hints.flags |= PMaxSize;
2088 size_hints.max_width = MAX (geometry->max_width, 1);
2089 size_hints.max_height = MAX (geometry->max_height, 1);
2092 if (geom_mask & GDK_HINT_BASE_SIZE)
2094 size_hints.flags |= PBaseSize;
2095 size_hints.base_width = geometry->base_width;
2096 size_hints.base_height = geometry->base_height;
2099 if (geom_mask & GDK_HINT_RESIZE_INC)
2101 size_hints.flags |= PResizeInc;
2102 size_hints.width_inc = geometry->width_inc;
2103 size_hints.height_inc = geometry->height_inc;
2106 if (geom_mask & GDK_HINT_ASPECT)
2108 size_hints.flags |= PAspect;
2109 if (geometry->min_aspect <= 1)
2111 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2112 size_hints.min_aspect.y = 65536;
2116 size_hints.min_aspect.x = 65536;
2117 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2119 if (geometry->max_aspect <= 1)
2121 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2122 size_hints.max_aspect.y = 65536;
2126 size_hints.max_aspect.x = 65536;
2127 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2131 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2133 size_hints.flags |= PWinGravity;
2134 size_hints.win_gravity = geometry->win_gravity;
2137 /* FIXME: Would it be better to delete this property if
2138 * geom_mask == 0? It would save space on the server
2140 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2141 GDK_WINDOW_XID (window),
2146 gdk_window_get_geometry_hints (GdkWindow *window,
2147 GdkGeometry *geometry,
2148 GdkWindowHints *geom_mask)
2150 XSizeHints *size_hints;
2151 glong junk_supplied_mask = 0;
2153 g_return_if_fail (GDK_IS_WINDOW (window));
2154 g_return_if_fail (geometry != NULL);
2155 g_return_if_fail (geom_mask != NULL);
2159 if (GDK_WINDOW_DESTROYED (window) ||
2160 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2163 size_hints = XAllocSizeHints ();
2167 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2168 GDK_WINDOW_XID (window),
2170 &junk_supplied_mask))
2171 size_hints->flags = 0;
2173 if (size_hints->flags & PMinSize)
2175 *geom_mask |= GDK_HINT_MIN_SIZE;
2176 geometry->min_width = size_hints->min_width;
2177 geometry->min_height = size_hints->min_height;
2180 if (size_hints->flags & PMaxSize)
2182 *geom_mask |= GDK_HINT_MAX_SIZE;
2183 geometry->max_width = MAX (size_hints->max_width, 1);
2184 geometry->max_height = MAX (size_hints->max_height, 1);
2187 if (size_hints->flags & PResizeInc)
2189 *geom_mask |= GDK_HINT_RESIZE_INC;
2190 geometry->width_inc = size_hints->width_inc;
2191 geometry->height_inc = size_hints->height_inc;
2194 if (size_hints->flags & PAspect)
2196 *geom_mask |= GDK_HINT_ASPECT;
2198 geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
2199 geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
2202 if (size_hints->flags & PWinGravity)
2204 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2205 geometry->win_gravity = size_hints->win_gravity;
2212 utf8_is_latin1 (const gchar *str)
2214 const char *p = str;
2218 gunichar ch = g_utf8_get_char (p);
2223 p = g_utf8_next_char (p);
2229 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2230 * convertable to STRING, otherwise, set it as compound text
2233 set_text_property (GdkDisplay *display,
2236 const gchar *utf8_str)
2238 gchar *prop_text = NULL;
2242 gboolean is_compound_text;
2244 if (utf8_is_latin1 (utf8_str))
2246 prop_type = XA_STRING;
2247 prop_text = gdk_utf8_to_string_target (utf8_str);
2248 prop_length = prop_text ? strlen (prop_text) : 0;
2250 is_compound_text = FALSE;
2256 gdk_x11_display_utf8_to_compound_text (display,
2257 utf8_str, &gdk_type, &prop_format,
2258 (guchar **)&prop_text, &prop_length);
2259 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2260 is_compound_text = TRUE;
2265 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2268 prop_type, prop_format,
2269 PropModeReplace, (guchar *)prop_text,
2272 if (is_compound_text)
2273 gdk_x11_free_compound_text ((guchar *)prop_text);
2279 /* Set WM_NAME and _NET_WM_NAME
2282 set_wm_name (GdkDisplay *display,
2286 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2287 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2288 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2289 PropModeReplace, (guchar *)name, strlen (name));
2291 set_text_property (display, xwindow,
2292 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2297 gdk_x11_window_set_title (GdkWindow *window,
2300 GdkDisplay *display;
2304 g_return_if_fail (title != NULL);
2306 if (GDK_WINDOW_DESTROYED (window) ||
2307 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2310 display = gdk_window_get_display (window);
2311 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2312 xwindow = GDK_WINDOW_XID (window);
2314 set_wm_name (display, xwindow, title);
2316 if (!gdk_window_icon_name_set (window))
2318 XChangeProperty (xdisplay, xwindow,
2319 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2320 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2321 PropModeReplace, (guchar *)title, strlen (title));
2323 set_text_property (display, xwindow,
2324 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2330 gdk_x11_window_set_role (GdkWindow *window,
2333 GdkDisplay *display;
2335 display = gdk_window_get_display (window);
2337 if (GDK_WINDOW_DESTROYED (window) ||
2338 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2342 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2343 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2344 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2346 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2347 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2351 gdk_x11_window_set_startup_id (GdkWindow *window,
2352 const gchar *startup_id)
2354 GdkDisplay *display;
2356 g_return_if_fail (GDK_IS_WINDOW (window));
2358 display = gdk_window_get_display (window);
2360 if (GDK_WINDOW_DESTROYED (window) ||
2361 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2365 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2366 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2367 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2368 PropModeReplace, (unsigned char *)startup_id, strlen (startup_id));
2370 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2371 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"));
2375 gdk_x11_window_set_transient_for (GdkWindow *window,
2378 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) &&
2379 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2380 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2381 GDK_WINDOW_XID (window),
2382 GDK_WINDOW_XID (parent));
2386 gdk_window_x11_set_back_color (GdkWindow *window,
2392 GdkVisual *visual = gdk_window_get_visual (window);
2394 /* I suppose we could handle these, but that'd require fiddling with
2395 * xrender formats... */
2399 switch (visual->type)
2401 case GDK_VISUAL_DIRECT_COLOR:
2402 case GDK_VISUAL_TRUE_COLOR:
2404 /* If bits not used for color are used for something other than padding,
2405 * it's likely alpha, so we set them to 1s.
2407 guint padding, pixel;
2409 /* Shifting by >= width-of-type isn't defined in C */
2410 if (visual->depth >= 32)
2413 padding = ((~(guint32)0)) << visual->depth;
2415 pixel = ~ (visual->red_mask | visual->green_mask | visual->blue_mask | padding);
2417 pixel += (((int) (red * ((1 << visual->red_prec ) - 1))) << visual->red_shift ) +
2418 (((int) (green * ((1 << visual->green_prec) - 1))) << visual->green_shift) +
2419 (((int) (blue * ((1 << visual->blue_prec ) - 1))) << visual->blue_shift );
2421 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2422 GDK_WINDOW_XID (window), pixel);
2426 /* These require fiddling with the colormap, and as they're essentially unused
2427 * we're just gonna skip them for now.
2429 case GDK_VISUAL_PSEUDO_COLOR:
2430 case GDK_VISUAL_GRAYSCALE:
2431 case GDK_VISUAL_STATIC_GRAY:
2432 case GDK_VISUAL_STATIC_COLOR:
2441 matrix_is_identity (cairo_matrix_t *matrix)
2443 return matrix->xx == 1.0 && matrix->yy == 1.0 &&
2444 matrix->yx == 0.0 && matrix->xy == 0.0 &&
2445 matrix->x0 == 0.0 && matrix->y0 == 0.0;
2449 gdk_window_x11_set_background (GdkWindow *window,
2450 cairo_pattern_t *pattern)
2453 cairo_surface_t *surface;
2454 cairo_matrix_t matrix;
2456 if (GDK_WINDOW_DESTROYED (window))
2459 if (pattern == NULL)
2463 /* X throws BadMatch if the parent has a different visual when
2464 * using ParentRelative */
2465 parent = gdk_window_get_parent (window);
2466 if (parent && gdk_window_get_visual (parent) == gdk_window_get_visual (window))
2467 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2468 GDK_WINDOW_XID (window), ParentRelative);
2470 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2471 GDK_WINDOW_XID (window), None);
2475 switch (cairo_pattern_get_type (pattern))
2477 case CAIRO_PATTERN_TYPE_SOLID:
2478 cairo_pattern_get_rgba (pattern, &r, &g, &b, &a);
2479 if (gdk_window_x11_set_back_color (window, r, g, b, a))
2482 case CAIRO_PATTERN_TYPE_SURFACE:
2483 cairo_pattern_get_matrix (pattern, &matrix);
2484 if (cairo_pattern_get_surface (pattern, &surface) == CAIRO_STATUS_SUCCESS &&
2485 matrix_is_identity (&matrix) &&
2486 cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB &&
2487 cairo_xlib_surface_get_visual (surface) == GDK_VISUAL_XVISUAL (gdk_window_get_visual ((window))) &&
2488 cairo_xlib_surface_get_display (surface) == GDK_WINDOW_XDISPLAY (window))
2492 cairo_surface_get_device_offset (surface, &x, &y);
2493 /* XXX: This still bombs for non-pixmaps, but there's no way to
2494 * detect we're not a pixmap in Cairo... */
2495 if (x == 0.0 && y == 0.0)
2497 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2498 GDK_WINDOW_XID (window),
2499 cairo_xlib_surface_get_drawable (surface));
2504 case CAIRO_PATTERN_TYPE_LINEAR:
2505 case CAIRO_PATTERN_TYPE_RADIAL:
2507 /* fallback: just use black */
2511 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2512 GDK_WINDOW_XID (window), None);
2516 gdk_window_x11_set_device_cursor (GdkWindow *window,
2520 GdkWindowImplX11 *impl;
2522 g_return_if_fail (GDK_IS_WINDOW (window));
2523 g_return_if_fail (GDK_IS_DEVICE (device));
2525 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2528 g_hash_table_remove (impl->device_cursor, device);
2531 _gdk_x11_cursor_update_theme (cursor);
2532 g_hash_table_replace (impl->device_cursor,
2533 device, g_object_ref (cursor));
2536 if (!GDK_WINDOW_DESTROYED (window))
2537 GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
2541 _gdk_x11_window_get_cursor (GdkWindow *window)
2543 GdkWindowImplX11 *impl;
2545 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2547 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2549 return impl->cursor;
2553 gdk_window_x11_get_geometry (GdkWindow *window,
2564 guint tborder_width;
2567 if (!GDK_WINDOW_DESTROYED (window))
2569 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2570 GDK_WINDOW_XID (window),
2571 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2585 gdk_window_x11_get_root_coords (GdkWindow *window,
2596 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2597 GDK_WINDOW_XID (window),
2598 GDK_WINDOW_XROOTWIN (window),
2611 gdk_x11_window_get_root_origin (GdkWindow *window,
2617 gdk_window_get_frame_extents (window, &rect);
2627 gdk_x11_window_get_frame_extents (GdkWindow *window,
2630 GdkDisplay *display;
2631 GdkWindowImplX11 *impl;
2642 gulong nitems_return;
2643 gulong bytes_after_return;
2646 guint ww, wh, wb, wd;
2648 gboolean got_frame_extents = FALSE;
2650 g_return_if_fail (rect != NULL);
2657 while (window->parent && (window->parent)->parent)
2658 window = window->parent;
2660 /* Refine our fallback answer a bit using local information */
2661 rect->x = window->x;
2662 rect->y = window->y;
2663 rect->width = window->width;
2664 rect->height = window->height;
2666 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2667 if (GDK_WINDOW_DESTROYED (window) || impl->override_redirect)
2673 display = gdk_window_get_display (window);
2675 gdk_x11_display_error_trap_push (display);
2677 xwindow = GDK_WINDOW_XID (window);
2679 /* first try: use _NET_FRAME_EXTENTS */
2680 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2681 gdk_x11_get_xatom_by_name_for_display (display,
2682 "_NET_FRAME_EXTENTS"),
2683 0, G_MAXLONG, False, XA_CARDINAL, &type_return,
2684 &format_return, &nitems_return, &bytes_after_return,
2688 if ((type_return == XA_CARDINAL) && (format_return == 32) &&
2689 (nitems_return == 4) && (data))
2691 gulong *ldata = (gulong *) data;
2692 got_frame_extents = TRUE;
2694 /* try to get the real client window geometry */
2695 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2696 &root, &wx, &wy, &ww, &wh, &wb, &wd) &&
2697 XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display),
2698 xwindow, root, 0, 0, &wx, &wy, &child))
2706 /* _NET_FRAME_EXTENTS format is left, right, top, bottom */
2707 rect->x -= ldata[0];
2708 rect->y -= ldata[2];
2709 rect->width += ldata[0] + ldata[1];
2710 rect->height += ldata[2] + ldata[3];
2717 if (got_frame_extents)
2720 /* no frame extents property available, which means we either have a WM that
2721 is not EWMH compliant or is broken - try fallback and walk up the window
2722 tree to get our window's parent which hopefully is the window frame */
2724 /* use NETWM_VIRTUAL_ROOTS if available */
2725 root = GDK_WINDOW_XROOTWIN (window);
2727 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
2728 gdk_x11_get_xatom_by_name_for_display (display,
2729 "_NET_VIRTUAL_ROOTS"),
2730 0, G_MAXLONG, False, XA_WINDOW, &type_return,
2731 &format_return, &nitems_return, &bytes_after_return,
2735 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
2737 nvroots = nitems_return;
2738 vroots = (Window *)data;
2742 xparent = GDK_WINDOW_XID (window);
2748 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
2750 &children, &nchildren))
2756 /* check virtual roots */
2757 for (i = 0; i < nvroots; i++)
2759 if (xparent == vroots[i])
2766 while (xparent != root);
2768 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2769 &root, &wx, &wy, &ww, &wh, &wb, &wd))
2781 gdk_x11_display_error_trap_pop_ignored (display);
2785 gdk_window_x11_get_device_state (GdkWindow *window,
2789 GdkModifierType *mask)
2793 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
2795 if (GDK_WINDOW_DESTROYED (window))
2798 GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
2802 return child != NULL;
2806 gdk_window_x11_get_events (GdkWindow *window)
2808 XWindowAttributes attrs;
2809 GdkEventMask event_mask;
2810 GdkEventMask filtered;
2812 if (GDK_WINDOW_DESTROYED (window))
2816 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2817 GDK_WINDOW_XID (window),
2819 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2820 /* if property change was filtered out before, keep it filtered out */
2821 filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK;
2822 window->event_mask = event_mask & ((window->event_mask & filtered) | ~filtered);
2828 gdk_window_x11_set_events (GdkWindow *window,
2829 GdkEventMask event_mask)
2831 long xevent_mask = 0;
2833 if (!GDK_WINDOW_DESTROYED (window))
2835 GdkX11Display *display_x11;
2837 if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
2838 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2840 display_x11 = GDK_X11_DISPLAY (gdk_window_get_display (window));
2841 gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
2842 GDK_WINDOW_XID (window), event_mask,
2848 do_shape_combine_region (GdkWindow *window,
2849 const cairo_region_t *shape_region,
2854 if (GDK_WINDOW_DESTROYED (window))
2857 if (shape_region == NULL)
2859 /* Use NULL mask to unset the shape */
2860 if (shape == ShapeBounding
2861 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
2862 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
2864 if (shape == ShapeBounding)
2866 _gdk_x11_window_tmp_unset_parent_bg (window);
2867 _gdk_x11_window_tmp_unset_bg (window, TRUE);
2869 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2870 GDK_WINDOW_XID (window),
2875 if (shape == ShapeBounding)
2877 _gdk_x11_window_tmp_reset_parent_bg (window);
2878 _gdk_x11_window_tmp_reset_bg (window, TRUE);
2884 if (shape == ShapeBounding
2885 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
2886 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
2889 XRectangle *xrects = NULL;
2891 _gdk_x11_region_get_xrectangles (shape_region,
2895 if (shape == ShapeBounding)
2897 _gdk_x11_window_tmp_unset_parent_bg (window);
2898 _gdk_x11_window_tmp_unset_bg (window, TRUE);
2900 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2901 GDK_WINDOW_XID (window),
2908 if (shape == ShapeBounding)
2910 _gdk_x11_window_tmp_reset_parent_bg (window);
2911 _gdk_x11_window_tmp_reset_bg (window, TRUE);
2919 gdk_window_x11_shape_combine_region (GdkWindow *window,
2920 const cairo_region_t *shape_region,
2924 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
2928 gdk_window_x11_input_shape_combine_region (GdkWindow *window,
2929 const cairo_region_t *shape_region,
2934 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
2940 gdk_x11_window_set_override_redirect (GdkWindow *window,
2941 gboolean override_redirect)
2943 XSetWindowAttributes attr;
2945 if (!GDK_WINDOW_DESTROYED (window) &&
2946 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2948 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
2950 attr.override_redirect = (override_redirect? True : False);
2951 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2952 GDK_WINDOW_XID (window),
2956 impl->override_redirect = attr.override_redirect;
2961 gdk_x11_window_set_accept_focus (GdkWindow *window,
2962 gboolean accept_focus)
2964 accept_focus = accept_focus != FALSE;
2966 if (window->accept_focus != accept_focus)
2968 window->accept_focus = accept_focus;
2970 if (!GDK_WINDOW_DESTROYED (window) &&
2971 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2972 update_wm_hints (window, FALSE);
2977 gdk_x11_window_set_focus_on_map (GdkWindow *window,
2978 gboolean focus_on_map)
2980 focus_on_map = focus_on_map != FALSE;
2982 if (window->focus_on_map != focus_on_map)
2984 window->focus_on_map = focus_on_map;
2986 if ((!GDK_WINDOW_DESTROYED (window)) &&
2987 (!window->focus_on_map) &&
2988 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2989 gdk_x11_window_set_user_time (window, 0);
2994 * gdk_x11_window_set_user_time:
2995 * @window: A toplevel #GdkWindow
2996 * @timestamp: An XServer timestamp to which the property should be set
2998 * The application can use this call to update the _NET_WM_USER_TIME
2999 * property on a toplevel window. This property stores an Xserver
3000 * time which represents the time of the last user input event
3001 * received for this window. This property may be used by the window
3002 * manager to alter the focus, stacking, and/or placement behavior of
3003 * windows when they are mapped depending on whether the new window
3004 * was created by a user action or is a "pop-up" window activated by a
3005 * timer or some other event.
3007 * Note that this property is automatically updated by GDK, so this
3008 * function should only be used by applications which handle input
3009 * events bypassing GDK.
3014 gdk_x11_window_set_user_time (GdkWindow *window,
3017 GdkDisplay *display;
3018 GdkX11Display *display_x11;
3019 GdkToplevelX11 *toplevel;
3020 glong timestamp_long = (glong)timestamp;
3023 if (GDK_WINDOW_DESTROYED (window) ||
3024 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3027 display = gdk_window_get_display (window);
3028 display_x11 = GDK_X11_DISPLAY (display);
3029 toplevel = _gdk_x11_window_get_toplevel (window);
3033 g_warning ("gdk_window_set_user_time called on non-toplevel\n");
3037 if (toplevel->focus_window != None &&
3038 gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
3039 gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW")))
3040 xid = toplevel->focus_window;
3042 xid = GDK_WINDOW_XID (window);
3044 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid,
3045 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3046 XA_CARDINAL, 32, PropModeReplace,
3047 (guchar *)×tamp_long, 1);
3049 if (timestamp_long != GDK_CURRENT_TIME &&
3050 (display_x11->user_time == GDK_CURRENT_TIME ||
3051 XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time)))
3052 display_x11->user_time = timestamp_long;
3055 toplevel->user_time = timestamp_long;
3058 #define GDK_SELECTION_MAX_SIZE(display) \
3060 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
3061 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
3062 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
3065 gdk_window_update_icon (GdkWindow *window,
3068 GdkToplevelX11 *toplevel;
3069 GdkPixbuf *best_icon;
3073 toplevel = _gdk_x11_window_get_toplevel (window);
3075 if (toplevel->icon_pixmap != NULL)
3077 cairo_surface_destroy (toplevel->icon_pixmap);
3078 toplevel->icon_pixmap = NULL;
3081 if (toplevel->icon_mask != NULL)
3083 cairo_surface_destroy (toplevel->icon_mask);
3084 toplevel->icon_mask = NULL;
3087 #define IDEAL_SIZE 48
3089 best_size = G_MAXINT;
3091 for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next)
3093 GdkPixbuf *pixbuf = tmp_list->data;
3096 /* average width and height - if someone passes in a rectangular
3097 * icon they deserve what they get.
3099 this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
3102 if (best_icon == NULL)
3109 /* icon is better if it's 32 pixels or larger, and closer to
3110 * the ideal size than the current best.
3113 (ABS (best_size - IDEAL_SIZE) <
3114 ABS (this - IDEAL_SIZE)))
3124 int width = gdk_pixbuf_get_width (best_icon);
3125 int height = gdk_pixbuf_get_height (best_icon);
3128 toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window,
3132 cr = cairo_create (toplevel->icon_pixmap);
3133 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3134 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3135 if (gdk_pixbuf_get_has_alpha (best_icon))
3137 /* Saturate the image, so it has bilevel alpha */
3138 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
3140 cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
3142 cairo_pop_group_to_source (cr);
3147 if (gdk_pixbuf_get_has_alpha (best_icon))
3149 toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
3153 cr = cairo_create (toplevel->icon_mask);
3154 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3155 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3161 update_wm_hints (window, FALSE);
3165 gdk_x11_window_set_icon_list (GdkWindow *window,
3174 gint width, height, stride;
3177 GdkDisplay *display;
3180 if (GDK_WINDOW_DESTROYED (window) ||
3181 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3184 display = gdk_window_get_display (window);
3192 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3194 width = gdk_pixbuf_get_width (pixbuf);
3195 height = gdk_pixbuf_get_height (pixbuf);
3197 /* silently ignore overlarge icons */
3198 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
3200 g_warning ("gdk_window_set_icon_list: icons too large");
3205 size += 2 + width * height;
3207 l = g_list_next (l);
3210 data = g_malloc (size * sizeof (gulong));
3218 width = gdk_pixbuf_get_width (pixbuf);
3219 height = gdk_pixbuf_get_height (pixbuf);
3220 stride = gdk_pixbuf_get_rowstride (pixbuf);
3221 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3226 pixels = gdk_pixbuf_get_pixels (pixbuf);
3228 for (y = 0; y < height; y++)
3230 for (x = 0; x < width; x++)
3234 r = pixels[y*stride + x*n_channels + 0];
3235 g = pixels[y*stride + x*n_channels + 1];
3236 b = pixels[y*stride + x*n_channels + 2];
3237 if (n_channels >= 4)
3238 a = pixels[y*stride + x*n_channels + 3];
3242 *p++ = a << 24 | r << 16 | g << 8 | b ;
3246 l = g_list_next (l);
3252 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3253 GDK_WINDOW_XID (window),
3254 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3257 (guchar*) data, size);
3261 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3262 GDK_WINDOW_XID (window),
3263 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3268 gdk_window_update_icon (window, pixbufs);
3272 gdk_window_icon_name_set (GdkWindow *window)
3274 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3275 g_quark_from_static_string ("gdk-icon-name-set")));
3279 gdk_x11_window_set_icon_name (GdkWindow *window,
3282 GdkDisplay *display;
3284 if (GDK_WINDOW_DESTROYED (window) ||
3285 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3288 display = gdk_window_get_display (window);
3290 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3291 GUINT_TO_POINTER (name != NULL));
3295 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3296 GDK_WINDOW_XID (window),
3297 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3298 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3299 PropModeReplace, (guchar *)name, strlen (name));
3301 set_text_property (display, GDK_WINDOW_XID (window),
3302 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3307 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3308 GDK_WINDOW_XID (window),
3309 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"));
3310 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3311 GDK_WINDOW_XID (window),
3312 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"));
3317 gdk_x11_window_iconify (GdkWindow *window)
3319 if (GDK_WINDOW_DESTROYED (window) ||
3320 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3323 if (GDK_WINDOW_IS_MAPPED (window))
3325 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3326 GDK_WINDOW_XID (window),
3327 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3331 /* Flip our client side flag, the real work happens on map. */
3332 gdk_synthesize_window_state (window,
3334 GDK_WINDOW_STATE_ICONIFIED);
3339 gdk_x11_window_deiconify (GdkWindow *window)
3341 if (GDK_WINDOW_DESTROYED (window) ||
3342 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3345 if (GDK_WINDOW_IS_MAPPED (window))
3347 gdk_window_show (window);
3351 /* Flip our client side flag, the real work happens on map. */
3352 gdk_synthesize_window_state (window,
3353 GDK_WINDOW_STATE_ICONIFIED,
3359 gdk_x11_window_stick (GdkWindow *window)
3361 if (GDK_WINDOW_DESTROYED (window) ||
3362 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3365 if (GDK_WINDOW_IS_MAPPED (window))
3367 /* "stick" means stick to all desktops _and_ do not scroll with the
3368 * viewport. i.e. glue to the monitor glass in all cases.
3371 XClientMessageEvent xclient;
3373 /* Request stick during viewport scroll */
3374 gdk_wmspec_change_state (TRUE, window,
3375 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
3378 /* Request desktop 0xFFFFFFFF */
3379 memset (&xclient, 0, sizeof (xclient));
3380 xclient.type = ClientMessage;
3381 xclient.window = GDK_WINDOW_XID (window);
3382 xclient.display = GDK_WINDOW_XDISPLAY (window);
3383 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3385 xclient.format = 32;
3387 xclient.data.l[0] = 0xFFFFFFFF;
3388 xclient.data.l[1] = 0;
3389 xclient.data.l[2] = 0;
3390 xclient.data.l[3] = 0;
3391 xclient.data.l[4] = 0;
3393 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3394 SubstructureRedirectMask | SubstructureNotifyMask,
3395 (XEvent *)&xclient);
3399 /* Flip our client side flag, the real work happens on map. */
3400 gdk_synthesize_window_state (window,
3402 GDK_WINDOW_STATE_STICKY);
3407 gdk_x11_window_unstick (GdkWindow *window)
3409 if (GDK_WINDOW_DESTROYED (window) ||
3410 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3413 if (GDK_WINDOW_IS_MAPPED (window))
3415 /* Request unstick from viewport */
3416 gdk_wmspec_change_state (FALSE, window,
3417 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
3420 move_to_current_desktop (window);
3424 /* Flip our client side flag, the real work happens on map. */
3425 gdk_synthesize_window_state (window,
3426 GDK_WINDOW_STATE_STICKY,
3433 gdk_x11_window_maximize (GdkWindow *window)
3435 if (GDK_WINDOW_DESTROYED (window) ||
3436 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3439 if (GDK_WINDOW_IS_MAPPED (window))
3440 gdk_wmspec_change_state (TRUE, window,
3441 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
3442 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
3444 gdk_synthesize_window_state (window,
3446 GDK_WINDOW_STATE_MAXIMIZED);
3450 gdk_x11_window_unmaximize (GdkWindow *window)
3452 if (GDK_WINDOW_DESTROYED (window) ||
3453 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3456 if (GDK_WINDOW_IS_MAPPED (window))
3457 gdk_wmspec_change_state (FALSE, window,
3458 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
3459 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
3461 gdk_synthesize_window_state (window,
3462 GDK_WINDOW_STATE_MAXIMIZED,
3467 gdk_x11_window_fullscreen (GdkWindow *window)
3469 if (GDK_WINDOW_DESTROYED (window) ||
3470 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3473 if (GDK_WINDOW_IS_MAPPED (window))
3474 gdk_wmspec_change_state (TRUE, window,
3475 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
3479 gdk_synthesize_window_state (window,
3481 GDK_WINDOW_STATE_FULLSCREEN);
3485 gdk_x11_window_unfullscreen (GdkWindow *window)
3487 if (GDK_WINDOW_DESTROYED (window) ||
3488 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3491 if (GDK_WINDOW_IS_MAPPED (window))
3492 gdk_wmspec_change_state (FALSE, window,
3493 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
3497 gdk_synthesize_window_state (window,
3498 GDK_WINDOW_STATE_FULLSCREEN,
3503 gdk_x11_window_set_keep_above (GdkWindow *window,
3506 g_return_if_fail (GDK_IS_WINDOW (window));
3508 if (GDK_WINDOW_DESTROYED (window) ||
3509 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3512 if (GDK_WINDOW_IS_MAPPED (window))
3515 gdk_wmspec_change_state (FALSE, window,
3516 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
3518 gdk_wmspec_change_state (setting, window,
3519 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
3523 gdk_synthesize_window_state (window,
3524 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
3525 setting ? GDK_WINDOW_STATE_ABOVE : 0);
3529 gdk_x11_window_set_keep_below (GdkWindow *window, gboolean setting)
3531 g_return_if_fail (GDK_IS_WINDOW (window));
3533 if (GDK_WINDOW_DESTROYED (window) ||
3534 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3537 if (GDK_WINDOW_IS_MAPPED (window))
3540 gdk_wmspec_change_state (FALSE, window,
3541 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
3543 gdk_wmspec_change_state (setting, window,
3544 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
3548 gdk_synthesize_window_state (window,
3549 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
3550 setting ? GDK_WINDOW_STATE_BELOW : 0);
3554 gdk_x11_window_get_group (GdkWindow *window)
3556 GdkToplevelX11 *toplevel;
3558 if (GDK_WINDOW_DESTROYED (window) ||
3559 !WINDOW_IS_TOPLEVEL (window))
3562 toplevel = _gdk_x11_window_get_toplevel (window);
3564 return toplevel->group_leader;
3568 gdk_x11_window_set_group (GdkWindow *window,
3571 GdkToplevelX11 *toplevel;
3573 g_return_if_fail (GDK_IS_WINDOW (window));
3574 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3575 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
3577 if (GDK_WINDOW_DESTROYED (window) ||
3578 (leader != NULL && GDK_WINDOW_DESTROYED (leader)) ||
3579 !WINDOW_IS_TOPLEVEL (window))
3582 toplevel = _gdk_x11_window_get_toplevel (window);
3585 leader = gdk_display_get_default_group (gdk_window_get_display (window));
3587 if (toplevel->group_leader != leader)
3589 if (toplevel->group_leader)
3590 g_object_unref (toplevel->group_leader);
3591 toplevel->group_leader = g_object_ref (leader);
3592 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
3595 update_wm_hints (window, FALSE);
3598 static MotifWmHints *
3599 gdk_window_get_mwm_hints (GdkWindow *window)
3601 GdkDisplay *display;
3602 Atom hints_atom = None;
3609 if (GDK_WINDOW_DESTROYED (window))
3612 display = gdk_window_get_display (window);
3614 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3616 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3617 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3618 False, AnyPropertyType, &type, &format, &nitems,
3619 &bytes_after, &data);
3624 return (MotifWmHints *)data;
3628 gdk_window_set_mwm_hints (GdkWindow *window,
3629 MotifWmHints *new_hints)
3631 GdkDisplay *display;
3632 Atom hints_atom = None;
3634 MotifWmHints *hints;
3640 if (GDK_WINDOW_DESTROYED (window))
3643 display = gdk_window_get_display (window);
3645 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3647 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3648 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3649 False, AnyPropertyType, &type, &format, &nitems,
3650 &bytes_after, &data);
3656 hints = (MotifWmHints *)data;
3658 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3660 hints->flags |= MWM_HINTS_FUNCTIONS;
3661 hints->functions = new_hints->functions;
3663 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3665 hints->flags |= MWM_HINTS_DECORATIONS;
3666 hints->decorations = new_hints->decorations;
3670 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3671 hints_atom, hints_atom, 32, PropModeReplace,
3672 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3674 if (hints != new_hints)
3679 gdk_x11_window_set_decorations (GdkWindow *window,
3680 GdkWMDecoration decorations)
3684 if (GDK_WINDOW_DESTROYED (window) ||
3685 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3688 /* initialize to zero to avoid writing uninitialized data to socket */
3689 memset(&hints, 0, sizeof(hints));
3690 hints.flags = MWM_HINTS_DECORATIONS;
3691 hints.decorations = decorations;
3693 gdk_window_set_mwm_hints (window, &hints);
3697 gdk_x11_window_get_decorations(GdkWindow *window,
3698 GdkWMDecoration *decorations)
3700 MotifWmHints *hints;
3701 gboolean result = FALSE;
3703 if (GDK_WINDOW_DESTROYED (window) ||
3704 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3707 hints = gdk_window_get_mwm_hints (window);
3711 if (hints->flags & MWM_HINTS_DECORATIONS)
3714 *decorations = hints->decorations;
3725 gdk_x11_window_set_functions (GdkWindow *window,
3726 GdkWMFunction functions)
3730 g_return_if_fail (GDK_IS_WINDOW (window));
3732 if (GDK_WINDOW_DESTROYED (window) ||
3733 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3736 /* initialize to zero to avoid writing uninitialized data to socket */
3737 memset(&hints, 0, sizeof(hints));
3738 hints.flags = MWM_HINTS_FUNCTIONS;
3739 hints.functions = functions;
3741 gdk_window_set_mwm_hints (window, &hints);
3745 _gdk_x11_xwindow_get_shape (Display *xdisplay,
3749 cairo_region_t *shape;
3757 xrl = XShapeGetRectangles (xdisplay,
3759 shape_type, &rn, &ord);
3761 if (xrl == NULL || rn == 0)
3762 return cairo_region_create (); /* Empty */
3764 if (ord != YXBanded)
3766 /* This really shouldn't happen with any xserver, as they
3767 generally convert regions to YXBanded internally */
3768 g_warning ("non YXBanded shape masks not supported");
3773 rl = g_new (GdkRectangle, rn);
3774 for (i = 0; i < rn; i++)
3778 rl[i].width = xrl[i].width;
3779 rl[i].height = xrl[i].height;
3783 shape = cairo_region_create_rectangles (rl, rn);
3790 static cairo_region_t *
3791 gdk_x11_window_get_shape (GdkWindow *window)
3793 if (!GDK_WINDOW_DESTROYED (window) &&
3794 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
3795 return _gdk_x11_xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
3796 GDK_WINDOW_XID (window),
3802 static cairo_region_t *
3803 gdk_x11_window_get_input_shape (GdkWindow *window)
3805 #if defined(ShapeInput)
3806 if (!GDK_WINDOW_DESTROYED (window) &&
3807 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
3808 return _gdk_x11_xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
3809 GDK_WINDOW_XID (window),
3817 gdk_window_set_static_bit_gravity (GdkWindow *window,
3820 XSetWindowAttributes xattributes;
3821 guint xattributes_mask = 0;
3823 g_return_if_fail (GDK_IS_WINDOW (window));
3825 if (window->input_only)
3828 xattributes.bit_gravity = StaticGravity;
3829 xattributes_mask |= CWBitGravity;
3830 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
3831 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3832 GDK_WINDOW_XID (window),
3833 CWBitGravity, &xattributes);
3837 gdk_window_set_static_win_gravity (GdkWindow *window,
3840 XSetWindowAttributes xattributes;
3842 g_return_if_fail (GDK_IS_WINDOW (window));
3844 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
3846 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3847 GDK_WINDOW_XID (window),
3848 CWWinGravity, &xattributes);
3852 gdk_window_x11_set_static_gravities (GdkWindow *window,
3853 gboolean use_static)
3857 if (!use_static == !window->guffaw_gravity)
3860 window->guffaw_gravity = use_static;
3862 if (!GDK_WINDOW_DESTROYED (window))
3864 gdk_window_set_static_bit_gravity (window, use_static);
3866 tmp_list = window->children;
3869 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
3871 tmp_list = tmp_list->next;
3879 wmspec_moveresize (GdkWindow *window,
3885 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
3887 XClientMessageEvent xclient;
3889 /* Release passive grab */
3890 gdk_display_pointer_ungrab (display, timestamp);
3892 memset (&xclient, 0, sizeof (xclient));
3893 xclient.type = ClientMessage;
3894 xclient.window = GDK_WINDOW_XID (window);
3895 xclient.message_type =
3896 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
3897 xclient.format = 32;
3898 xclient.data.l[0] = root_x;
3899 xclient.data.l[1] = root_y;
3900 xclient.data.l[2] = direction;
3901 xclient.data.l[3] = 0;
3902 xclient.data.l[4] = 0;
3904 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3905 SubstructureRedirectMask | SubstructureNotifyMask,
3906 (XEvent *)&xclient);
3909 typedef struct _MoveResizeData MoveResizeData;
3911 struct _MoveResizeData
3913 GdkDisplay *display;
3915 GdkWindow *moveresize_window;
3916 GdkWindow *moveresize_emulation_window;
3918 GdkWindowEdge resize_edge;
3919 gint moveresize_button;
3922 gint moveresize_orig_x;
3923 gint moveresize_orig_y;
3924 gint moveresize_orig_width;
3925 gint moveresize_orig_height;
3926 GdkWindowHints moveresize_geom_mask;
3927 GdkGeometry moveresize_geometry;
3928 Time moveresize_process_time;
3929 XEvent *moveresize_pending_event;
3932 /* From the WM spec */
3933 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
3934 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
3935 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
3936 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
3937 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
3938 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
3939 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
3940 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
3941 #define _NET_WM_MOVERESIZE_MOVE 8
3944 wmspec_resize_drag (GdkWindow *window,
3953 /* Let the compiler turn a switch into a table, instead
3954 * of doing the table manually, this way is easier to verify.
3958 case GDK_WINDOW_EDGE_NORTH_WEST:
3959 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
3962 case GDK_WINDOW_EDGE_NORTH:
3963 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
3966 case GDK_WINDOW_EDGE_NORTH_EAST:
3967 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
3970 case GDK_WINDOW_EDGE_WEST:
3971 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
3974 case GDK_WINDOW_EDGE_EAST:
3975 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
3978 case GDK_WINDOW_EDGE_SOUTH_WEST:
3979 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
3982 case GDK_WINDOW_EDGE_SOUTH:
3983 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
3986 case GDK_WINDOW_EDGE_SOUTH_EAST:
3987 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
3991 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
3996 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
3999 static MoveResizeData *
4000 get_move_resize_data (GdkDisplay *display,
4003 MoveResizeData *mv_resize;
4004 static GQuark move_resize_quark = 0;
4006 if (!move_resize_quark)
4007 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4009 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4011 if (!mv_resize && create)
4013 mv_resize = g_new0 (MoveResizeData, 1);
4014 mv_resize->display = display;
4016 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4023 update_pos (MoveResizeData *mv_resize,
4029 dx = new_root_x - mv_resize->moveresize_x;
4030 dy = new_root_y - mv_resize->moveresize_y;
4032 if (mv_resize->is_resize)
4036 x = mv_resize->moveresize_orig_x;
4037 y = mv_resize->moveresize_orig_y;
4039 w = mv_resize->moveresize_orig_width;
4040 h = mv_resize->moveresize_orig_height;
4042 switch (mv_resize->resize_edge)
4044 case GDK_WINDOW_EDGE_NORTH_WEST:
4050 case GDK_WINDOW_EDGE_NORTH:
4054 case GDK_WINDOW_EDGE_NORTH_EAST:
4059 case GDK_WINDOW_EDGE_SOUTH_WEST:
4064 case GDK_WINDOW_EDGE_SOUTH_EAST:
4068 case GDK_WINDOW_EDGE_SOUTH:
4071 case GDK_WINDOW_EDGE_EAST:
4074 case GDK_WINDOW_EDGE_WEST:
4085 if (mv_resize->moveresize_geom_mask)
4087 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4088 mv_resize->moveresize_geom_mask,
4092 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4098 x = mv_resize->moveresize_orig_x + dx;
4099 y = mv_resize->moveresize_orig_y + dy;
4101 gdk_window_move (mv_resize->moveresize_window, x, y);
4106 finish_drag (MoveResizeData *mv_resize)
4108 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4109 mv_resize->moveresize_emulation_window = NULL;
4110 g_object_unref (mv_resize->moveresize_window);
4111 mv_resize->moveresize_window = NULL;
4113 if (mv_resize->moveresize_pending_event)
4115 g_free (mv_resize->moveresize_pending_event);
4116 mv_resize->moveresize_pending_event = NULL;
4121 lookahead_motion_predicate (Display *xdisplay,
4125 gboolean *seen_release = (gboolean *)arg;
4126 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4127 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4132 switch (event->xany.type)
4135 *seen_release = TRUE;
4138 mv_resize->moveresize_process_time = event->xmotion.time;
4148 moveresize_lookahead (MoveResizeData *mv_resize,
4152 gboolean seen_release = FALSE;
4154 if (mv_resize->moveresize_process_time)
4156 if (event->xmotion.time == mv_resize->moveresize_process_time)
4158 mv_resize->moveresize_process_time = 0;
4165 XCheckIfEvent (event->xany.display, &tmp_event,
4166 lookahead_motion_predicate, (XPointer) & seen_release);
4168 return mv_resize->moveresize_process_time == 0;
4172 _gdk_x11_moveresize_handle_event (XEvent *event)
4174 guint button_mask = 0;
4175 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
4176 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4178 if (!mv_resize || !mv_resize->moveresize_window)
4181 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4183 switch (event->xany.type)
4186 if (mv_resize->moveresize_window->resize_count > 0)
4188 if (mv_resize->moveresize_pending_event)
4189 *mv_resize->moveresize_pending_event = *event;
4191 mv_resize->moveresize_pending_event =
4192 g_memdup (event, sizeof (XEvent));
4196 if (!moveresize_lookahead (mv_resize, event))
4199 update_pos (mv_resize,
4200 event->xmotion.x_root,
4201 event->xmotion.y_root);
4203 /* This should never be triggered in normal cases, but in the
4204 * case where the drag started without an implicit grab being
4205 * in effect, we could miss the release if it occurs before
4206 * we grab the pointer; this ensures that we will never
4207 * get a permanently stuck grab.
4209 if ((event->xmotion.state & button_mask) == 0)
4210 finish_drag (mv_resize);
4214 update_pos (mv_resize,
4215 event->xbutton.x_root,
4216 event->xbutton.y_root);
4218 if (event->xbutton.button == mv_resize->moveresize_button)
4219 finish_drag (mv_resize);
4226 _gdk_x11_moveresize_configure_done (GdkDisplay *display,
4230 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4232 if (!mv_resize || window != mv_resize->moveresize_window)
4235 if (mv_resize->moveresize_pending_event)
4237 tmp_event = mv_resize->moveresize_pending_event;
4238 mv_resize->moveresize_pending_event = NULL;
4239 _gdk_x11_moveresize_handle_event (tmp_event);
4247 create_moveresize_window (MoveResizeData *mv_resize,
4250 GdkWindowAttr attributes;
4251 gint attributes_mask;
4252 GdkGrabStatus status;
4254 g_assert (mv_resize->moveresize_emulation_window == NULL);
4256 attributes.x = -100;
4257 attributes.y = -100;
4258 attributes.width = 10;
4259 attributes.height = 10;
4260 attributes.window_type = GDK_WINDOW_TEMP;
4261 attributes.wclass = GDK_INPUT_ONLY;
4262 attributes.override_redirect = TRUE;
4263 attributes.event_mask = 0;
4265 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4267 mv_resize->moveresize_emulation_window =
4268 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4272 gdk_window_show (mv_resize->moveresize_emulation_window);
4274 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4276 GDK_BUTTON_RELEASE_MASK |
4277 GDK_POINTER_MOTION_MASK,
4282 if (status != GDK_GRAB_SUCCESS)
4284 /* If this fails, some other client has grabbed the window
4287 finish_drag (mv_resize);
4290 mv_resize->moveresize_process_time = 0;
4294 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
4295 so that calling XMoveWindow with these coordinates will not move the
4297 Note that this depends on the WM to implement ICCCM-compliant reference
4301 calculate_unmoving_origin (MoveResizeData *mv_resize)
4306 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
4307 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
4309 gdk_window_get_origin (mv_resize->moveresize_window,
4310 &mv_resize->moveresize_orig_x,
4311 &mv_resize->moveresize_orig_y);
4315 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
4316 gdk_window_get_geometry (mv_resize->moveresize_window,
4317 NULL, NULL, &width, &height);
4319 switch (mv_resize->moveresize_geometry.win_gravity)
4321 case GDK_GRAVITY_NORTH_WEST:
4322 mv_resize->moveresize_orig_x = rect.x;
4323 mv_resize->moveresize_orig_y = rect.y;
4325 case GDK_GRAVITY_NORTH:
4326 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4327 mv_resize->moveresize_orig_y = rect.y;
4329 case GDK_GRAVITY_NORTH_EAST:
4330 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4331 mv_resize->moveresize_orig_y = rect.y;
4333 case GDK_GRAVITY_WEST:
4334 mv_resize->moveresize_orig_x = rect.x;
4335 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4337 case GDK_GRAVITY_CENTER:
4338 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4339 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4341 case GDK_GRAVITY_EAST:
4342 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4343 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4345 case GDK_GRAVITY_SOUTH_WEST:
4346 mv_resize->moveresize_orig_x = rect.x;
4347 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
4349 case GDK_GRAVITY_SOUTH:
4350 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4351 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
4353 case GDK_GRAVITY_SOUTH_EAST:
4354 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4355 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
4358 mv_resize->moveresize_orig_x = rect.x;
4359 mv_resize->moveresize_orig_y = rect.y;
4366 emulate_resize_drag (GdkWindow *window,
4373 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4375 mv_resize->is_resize = TRUE;
4376 mv_resize->moveresize_button = button;
4377 mv_resize->resize_edge = edge;
4378 mv_resize->moveresize_x = root_x;
4379 mv_resize->moveresize_y = root_y;
4380 mv_resize->moveresize_window = g_object_ref (window);
4382 mv_resize->moveresize_orig_width = gdk_window_get_width (window);
4383 mv_resize->moveresize_orig_height = gdk_window_get_height (window);
4385 mv_resize->moveresize_geom_mask = 0;
4386 gdk_window_get_geometry_hints (window,
4387 &mv_resize->moveresize_geometry,
4388 &mv_resize->moveresize_geom_mask);
4390 calculate_unmoving_origin (mv_resize);
4392 create_moveresize_window (mv_resize, timestamp);
4396 emulate_move_drag (GdkWindow *window,
4402 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4404 mv_resize->is_resize = FALSE;
4405 mv_resize->moveresize_button = button;
4406 mv_resize->moveresize_x = root_x;
4407 mv_resize->moveresize_y = root_y;
4409 mv_resize->moveresize_window = g_object_ref (window);
4411 calculate_unmoving_origin (mv_resize);
4413 create_moveresize_window (mv_resize, timestamp);
4417 gdk_x11_window_begin_resize_drag (GdkWindow *window,
4424 if (GDK_WINDOW_DESTROYED (window) ||
4425 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4428 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4429 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
4430 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4432 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4436 gdk_x11_window_begin_move_drag (GdkWindow *window,
4442 if (GDK_WINDOW_DESTROYED (window) ||
4443 !WINDOW_IS_TOPLEVEL (window))
4446 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4447 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
4448 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
4451 emulate_move_drag (window, button, root_x, root_y, timestamp);
4455 gdk_x11_window_enable_synchronized_configure (GdkWindow *window)
4457 GdkWindowImplX11 *impl;
4459 if (!GDK_IS_WINDOW_IMPL_X11 (window->impl))
4462 impl = GDK_WINDOW_IMPL_X11 (window->impl);
4464 if (!impl->use_synchronized_configure)
4466 /* This basically means you want to do fancy X specific stuff, so
4467 ensure we have a native window */
4468 gdk_window_ensure_native (window);
4470 impl->use_synchronized_configure = TRUE;
4471 ensure_sync_counter (window);
4476 gdk_x11_window_configure_finished (GdkWindow *window)
4478 GdkWindowImplX11 *impl;
4480 if (!WINDOW_IS_TOPLEVEL (window))
4483 impl = GDK_WINDOW_IMPL_X11 (window->impl);
4484 if (!impl->use_synchronized_configure)
4488 if (!GDK_WINDOW_DESTROYED (window))
4490 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4491 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
4493 if (toplevel && toplevel->update_counter != None &&
4494 GDK_X11_DISPLAY (display)->use_sync &&
4495 !XSyncValueIsZero (toplevel->current_counter_value))
4497 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
4498 toplevel->update_counter,
4499 toplevel->current_counter_value);
4501 XSyncIntToValue (&toplevel->current_counter_value, 0);
4508 gdk_x11_window_beep (GdkWindow *window)
4510 GdkDisplay *display;
4512 display = GDK_WINDOW_DISPLAY (window);
4515 if (GDK_X11_DISPLAY (display)->use_xkb)
4517 XkbBell (GDK_DISPLAY_XDISPLAY (display),
4518 GDK_WINDOW_XID (window),
4529 gdk_x11_window_set_opacity (GdkWindow *window,
4532 GdkDisplay *display;
4535 g_return_if_fail (GDK_IS_WINDOW (window));
4537 if (GDK_WINDOW_DESTROYED (window) ||
4538 !WINDOW_IS_TOPLEVEL (window))
4541 display = gdk_window_get_display (window);
4545 else if (opacity > 1)
4548 cardinal = opacity * 0xffffffff;
4550 if (cardinal == 0xffffffff)
4551 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
4552 GDK_WINDOW_XID (window),
4553 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"));
4555 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
4556 GDK_WINDOW_XID (window),
4557 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
4560 (guchar *) &cardinal, 1);
4564 gdk_x11_window_set_composited (GdkWindow *window,
4565 gboolean composited)
4567 #if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES)
4568 GdkWindowImplX11 *impl;
4569 GdkDisplay *display;
4573 impl = GDK_WINDOW_IMPL_X11 (window->impl);
4575 display = gdk_window_get_display (window);
4576 dpy = GDK_DISPLAY_XDISPLAY (display);
4577 xid = GDK_WINDOW_XID (window);
4581 XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual);
4582 impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox);
4586 XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual);
4587 XDamageDestroy (dpy, impl->damage);
4588 impl->damage = None;
4594 gdk_x11_window_process_updates_recurse (GdkWindow *window,
4595 cairo_region_t *region)
4597 _gdk_window_process_updates_recurse (window, region);
4601 _gdk_x11_display_before_process_all_updates (GdkDisplay *display)
4606 _gdk_x11_display_after_process_all_updates (GdkDisplay *display)
4611 timestamp_predicate (Display *display,
4615 Window xwindow = GPOINTER_TO_UINT (arg);
4616 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
4618 if (xevent->type == PropertyNotify &&
4619 xevent->xproperty.window == xwindow &&
4620 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
4621 "GDK_TIMESTAMP_PROP"))
4628 * gdk_x11_get_server_time:
4629 * @window: a #GdkWindow, used for communication with the server.
4630 * The window must have GDK_PROPERTY_CHANGE_MASK in its
4631 * events mask or a hang will result.
4633 * Routine to get the current X server time stamp.
4635 * Return value: the time stamp.
4638 gdk_x11_get_server_time (GdkWindow *window)
4644 Atom timestamp_prop_atom;
4646 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
4647 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
4649 xdisplay = GDK_WINDOW_XDISPLAY (window);
4650 xwindow = GDK_WINDOW_XID (window);
4651 timestamp_prop_atom =
4652 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
4653 "GDK_TIMESTAMP_PROP");
4655 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
4656 timestamp_prop_atom,
4657 8, PropModeReplace, &c, 1);
4659 XIfEvent (xdisplay, &xevent,
4660 timestamp_predicate, GUINT_TO_POINTER(xwindow));
4662 return xevent.xproperty.time;
4666 * gdk_x11_window_get_xid:
4667 * @window: a native #GdkWindow.
4669 * Returns the X resource (window) belonging to a #GdkWindow.
4671 * Return value: the ID of @drawable's X resource.
4674 gdk_x11_window_get_xid (GdkWindow *window)
4676 /* Try to ensure the window has a native window */
4677 if (!_gdk_window_has_impl (window))
4679 gdk_window_ensure_native (window);
4681 /* We sync here to ensure the window is created in the Xserver when
4682 * this function returns. This is required because the returned XID
4683 * for this window must be valid immediately, even with another
4684 * connection to the Xserver */
4685 gdk_display_sync (gdk_window_get_display (window));
4688 if (!GDK_WINDOW_IS_X11 (window))
4690 g_warning (G_STRLOC " drawable is not a native X11 window");
4694 return GDK_WINDOW_IMPL_X11 (window->impl)->xid;
4697 extern GdkDragContext * _gdk_x11_window_drag_begin (GdkWindow *window,
4702 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
4704 GObjectClass *object_class = G_OBJECT_CLASS (klass);
4705 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass);
4707 object_class->finalize = gdk_window_impl_x11_finalize;
4709 impl_class->ref_cairo_surface = gdk_x11_ref_cairo_surface;
4710 impl_class->show = gdk_window_x11_show;
4711 impl_class->hide = gdk_window_x11_hide;
4712 impl_class->withdraw = gdk_window_x11_withdraw;
4713 impl_class->set_events = gdk_window_x11_set_events;
4714 impl_class->get_events = gdk_window_x11_get_events;
4715 impl_class->raise = gdk_window_x11_raise;
4716 impl_class->lower = gdk_window_x11_lower;
4717 impl_class->restack_under = gdk_window_x11_restack_under;
4718 impl_class->restack_toplevel = gdk_window_x11_restack_toplevel;
4719 impl_class->move_resize = gdk_window_x11_move_resize;
4720 impl_class->set_background = gdk_window_x11_set_background;
4721 impl_class->reparent = gdk_window_x11_reparent;
4722 impl_class->set_device_cursor = gdk_window_x11_set_device_cursor;
4723 impl_class->get_geometry = gdk_window_x11_get_geometry;
4724 impl_class->get_root_coords = gdk_window_x11_get_root_coords;
4725 impl_class->get_device_state = gdk_window_x11_get_device_state;
4726 impl_class->shape_combine_region = gdk_window_x11_shape_combine_region;
4727 impl_class->input_shape_combine_region = gdk_window_x11_input_shape_combine_region;
4728 impl_class->set_static_gravities = gdk_window_x11_set_static_gravities;
4729 impl_class->queue_antiexpose = _gdk_x11_window_queue_antiexpose;
4730 impl_class->translate = _gdk_x11_window_translate;
4731 impl_class->destroy = gdk_x11_window_destroy;
4732 impl_class->destroy_foreign = gdk_x11_window_destroy_foreign;
4733 impl_class->resize_cairo_surface = gdk_window_x11_resize_cairo_surface;
4734 impl_class->get_shape = gdk_x11_window_get_shape;
4735 impl_class->get_input_shape = gdk_x11_window_get_input_shape;
4736 impl_class->beep = gdk_x11_window_beep;
4738 impl_class->focus = gdk_x11_window_focus;
4739 impl_class->set_type_hint = gdk_x11_window_set_type_hint;
4740 impl_class->get_type_hint = gdk_x11_window_get_type_hint;
4741 impl_class->set_modal_hint = gdk_x11_window_set_modal_hint;
4742 impl_class->set_skip_taskbar_hint = gdk_x11_window_set_skip_taskbar_hint;
4743 impl_class->set_skip_pager_hint = gdk_x11_window_set_skip_pager_hint;
4744 impl_class->set_urgency_hint = gdk_x11_window_set_urgency_hint;
4745 impl_class->set_geometry_hints = gdk_x11_window_set_geometry_hints;
4746 impl_class->set_title = gdk_x11_window_set_title;
4747 impl_class->set_role = gdk_x11_window_set_role;
4748 impl_class->set_startup_id = gdk_x11_window_set_startup_id;
4749 impl_class->set_transient_for = gdk_x11_window_set_transient_for;
4750 impl_class->get_root_origin = gdk_x11_window_get_root_origin;
4751 impl_class->get_frame_extents = gdk_x11_window_get_frame_extents;
4752 impl_class->set_override_redirect = gdk_x11_window_set_override_redirect;
4753 impl_class->set_accept_focus = gdk_x11_window_set_accept_focus;
4754 impl_class->set_focus_on_map = gdk_x11_window_set_focus_on_map;
4755 impl_class->set_icon_list = gdk_x11_window_set_icon_list;
4756 impl_class->set_icon_name = gdk_x11_window_set_icon_name;
4757 impl_class->iconify = gdk_x11_window_iconify;
4758 impl_class->deiconify = gdk_x11_window_deiconify;
4759 impl_class->stick = gdk_x11_window_stick;
4760 impl_class->unstick = gdk_x11_window_unstick;
4761 impl_class->maximize = gdk_x11_window_maximize;
4762 impl_class->unmaximize = gdk_x11_window_unmaximize;
4763 impl_class->fullscreen = gdk_x11_window_fullscreen;
4764 impl_class->unfullscreen = gdk_x11_window_unfullscreen;
4765 impl_class->set_keep_above = gdk_x11_window_set_keep_above;
4766 impl_class->set_keep_below = gdk_x11_window_set_keep_below;
4767 impl_class->get_group = gdk_x11_window_get_group;
4768 impl_class->set_group = gdk_x11_window_set_group;
4769 impl_class->set_decorations = gdk_x11_window_set_decorations;
4770 impl_class->get_decorations = gdk_x11_window_get_decorations;
4771 impl_class->set_functions = gdk_x11_window_set_functions;
4772 impl_class->set_functions = gdk_x11_window_set_functions;
4773 impl_class->begin_resize_drag = gdk_x11_window_begin_resize_drag;
4774 impl_class->begin_move_drag = gdk_x11_window_begin_move_drag;
4775 impl_class->enable_synchronized_configure = gdk_x11_window_enable_synchronized_configure;
4776 impl_class->configure_finished = gdk_x11_window_configure_finished;
4777 impl_class->set_opacity = gdk_x11_window_set_opacity;
4778 impl_class->set_composited = gdk_x11_window_set_composited;
4779 impl_class->destroy_notify = gdk_x11_window_destroy_notify;
4780 impl_class->register_dnd = _gdk_x11_window_register_dnd;
4781 impl_class->drag_begin = _gdk_x11_window_drag_begin;
4782 impl_class->process_updates_recurse = gdk_x11_window_process_updates_recurse;
4783 impl_class->sync_rendering = _gdk_x11_window_sync_rendering;
4784 impl_class->simulate_key = _gdk_x11_window_simulate_key;
4785 impl_class->simulate_button = _gdk_x11_window_simulate_button;
4786 impl_class->get_property = _gdk_x11_window_get_property;
4787 impl_class->change_property = _gdk_x11_window_change_property;
4788 impl_class->delete_property = _gdk_x11_window_delete_property;