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"
33 #include "gdkwindow.h"
34 #include "gdkwindowimpl.h"
36 #include "gdkdisplay-x11.h"
37 #include "gdkprivate-x11.h"
38 #include "gdkvisualprivate.h"
39 #include "gdkinternals.h"
40 #include "gdkdeviceprivate.h"
41 #include "gdkeventsource.h"
46 #include <netinet/in.h>
49 #include <cairo-xlib.h>
54 #include <X11/Xutil.h>
55 #include <X11/Xatom.h>
57 #include <X11/extensions/shape.h>
60 #include <X11/XKBlib.h>
63 #ifdef HAVE_XCOMPOSITE
64 #include <X11/extensions/Xcomposite.h>
68 #include <X11/extensions/Xfixes.h>
72 #include <X11/extensions/Xdamage.h>
75 const int _gdk_x11_event_mask_table[21] =
79 PointerMotionHintMask,
96 SubstructureNotifyMask,
97 ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */
100 const gint _gdk_x11_event_mask_table_size = G_N_ELEMENTS (_gdk_x11_event_mask_table);
102 /* Forward declarations */
103 static void gdk_window_set_static_win_gravity (GdkWindow *window,
105 static gboolean gdk_window_icon_name_set (GdkWindow *window);
106 static void set_wm_name (GdkDisplay *display,
109 static void move_to_current_desktop (GdkWindow *window);
110 static void gdk_window_x11_set_background (GdkWindow *window,
111 cairo_pattern_t *pattern);
113 static void gdk_window_impl_x11_finalize (GObject *object);
115 #define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \
116 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
117 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
119 #define WINDOW_IS_TOPLEVEL(window) \
120 (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
121 GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
122 GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
124 /* Return whether time1 is considered later than time2 as far as xserver
125 * time is concerned. Accounts for wraparound.
127 #define XSERVER_TIME_IS_LATER(time1, time2) \
128 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
129 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
132 G_DEFINE_TYPE (GdkWindowImplX11, gdk_window_impl_x11, GDK_TYPE_WINDOW_IMPL)
135 gdk_window_impl_x11_init (GdkWindowImplX11 *impl)
137 impl->toplevel_window_type = -1;
138 impl->device_cursor = g_hash_table_new_full (NULL, NULL, NULL,
139 (GDestroyNotify) gdk_cursor_unref);
143 _gdk_x11_window_get_toplevel (GdkWindow *window)
145 GdkWindowImplX11 *impl;
147 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
149 if (!WINDOW_IS_TOPLEVEL (window))
152 impl = GDK_WINDOW_IMPL_X11 (window->impl);
155 impl->toplevel = g_new0 (GdkToplevelX11, 1);
157 return impl->toplevel;
160 static const cairo_user_data_key_t gdk_x11_cairo_key;
163 * _gdk_x11_window_update_size:
164 * @impl: a #GdkWindowImplX11.
166 * Updates the state of the window (in particular the drawable's
167 * cairo surface) when its size has changed.
170 _gdk_x11_window_update_size (GdkWindowImplX11 *impl)
172 if (impl->cairo_surface)
174 cairo_xlib_surface_set_size (impl->cairo_surface,
175 gdk_window_get_width (impl->wrapper),
176 gdk_window_get_height (impl->wrapper));
180 /*****************************************************
181 * X11 specific implementations of generic functions *
182 *****************************************************/
185 gdk_x11_cairo_surface_destroy (void *data)
187 GdkWindowImplX11 *impl = data;
189 impl->cairo_surface = NULL;
192 static cairo_surface_t *
193 gdk_x11_create_cairo_surface (GdkWindowImplX11 *impl,
199 visual = gdk_window_get_visual (impl->wrapper);
200 return cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (impl->wrapper),
201 GDK_WINDOW_IMPL_X11 (impl)->xid,
202 GDK_VISUAL_XVISUAL (visual),
206 static cairo_surface_t *
207 gdk_x11_ref_cairo_surface (GdkWindow *window)
209 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
211 if (GDK_WINDOW_DESTROYED (window))
214 if (!impl->cairo_surface)
216 impl->cairo_surface = gdk_x11_create_cairo_surface (impl,
217 gdk_window_get_width (window),
218 gdk_window_get_height (window));
220 if (impl->cairo_surface)
221 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
222 impl, gdk_x11_cairo_surface_destroy);
225 cairo_surface_reference (impl->cairo_surface);
227 return impl->cairo_surface;
231 gdk_window_impl_x11_finalize (GObject *object)
234 GdkWindowImplX11 *impl;
236 g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object));
238 impl = GDK_WINDOW_IMPL_X11 (object);
240 wrapper = impl->wrapper;
242 _gdk_xgrab_check_destroy (wrapper);
244 if (!GDK_WINDOW_DESTROYED (wrapper))
246 GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper);
248 _gdk_xid_table_remove (display, impl->xid);
249 if (impl->toplevel && impl->toplevel->focus_window)
250 _gdk_xid_table_remove (display, impl->toplevel->focus_window);
253 g_free (impl->toplevel);
256 gdk_cursor_unref (impl->cursor);
258 g_hash_table_destroy (impl->device_cursor);
260 G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object);
269 free_pixmap (gpointer datap)
271 FreePixmapData *data = datap;
273 if (!gdk_display_is_closed (data->display))
275 XFreePixmap (GDK_DISPLAY_XDISPLAY (data->display),
279 g_object_unref (data->display);
280 g_slice_free (FreePixmapData, data);
284 attach_free_pixmap_handler (cairo_surface_t *surface,
288 static const cairo_user_data_key_t key;
289 FreePixmapData *data;
291 data = g_slice_new (FreePixmapData);
292 data->display = g_object_ref (display);
293 data->pixmap = pixmap;
295 cairo_surface_set_user_data (surface, &key, data, free_pixmap);
298 /* Cairo does not guarantee we get an xlib surface if we call
299 * cairo_surface_create_similar(). In some cases however, we must use a
300 * pixmap or bitmap in the X11 API.
301 * These functions ensure an Xlib surface.
304 _gdk_x11_window_create_bitmap_surface (GdkWindow *window,
308 cairo_surface_t *surface;
311 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
312 GDK_WINDOW_XID (window),
314 surface = cairo_xlib_surface_create_for_bitmap (GDK_WINDOW_XDISPLAY (window),
316 GDK_SCREEN_XSCREEN (GDK_WINDOW_SCREEN (window)),
318 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
323 /* Create a surface backed with a pixmap without alpha on the same screen as window */
324 static cairo_surface_t *
325 gdk_x11_window_create_pixmap_surface (GdkWindow *window,
329 GdkScreen *screen = gdk_window_get_screen (window);
330 GdkVisual *visual = gdk_screen_get_system_visual (screen);
331 cairo_surface_t *surface;
334 pixmap = XCreatePixmap (GDK_WINDOW_XDISPLAY (window),
335 GDK_WINDOW_XID (window),
337 gdk_visual_get_depth (visual));
338 surface = cairo_xlib_surface_create (GDK_WINDOW_XDISPLAY (window),
340 GDK_VISUAL_XVISUAL (visual),
342 attach_free_pixmap_handler (surface, GDK_WINDOW_DISPLAY (window), pixmap);
348 tmp_unset_bg (GdkWindow *window)
350 GdkWindowImplX11 *impl;
352 impl = GDK_WINDOW_IMPL_X11 (window->impl);
356 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
357 GDK_WINDOW_XID (window), None);
361 tmp_reset_bg (GdkWindow *window)
363 GdkWindowImplX11 *impl;
365 impl = GDK_WINDOW_IMPL_X11 (window->impl);
369 gdk_window_x11_set_background (window, window->background);
372 /* Unsetting and resetting window backgrounds.
374 * In many cases it is possible to avoid flicker by unsetting the
375 * background of windows. For example if the background of the
376 * parent window is unset when a window is unmapped, a brief flicker
377 * of background painting is avoided.
380 _gdk_x11_window_tmp_unset_bg (GdkWindow *window,
383 g_return_if_fail (GDK_IS_WINDOW (window));
385 if (window->input_only || window->destroyed ||
386 (window->window_type != GDK_WINDOW_ROOT &&
387 !GDK_WINDOW_IS_MAPPED (window)))
390 if (_gdk_window_has_impl (window) &&
391 GDK_WINDOW_IS_X11 (window) &&
392 window->window_type != GDK_WINDOW_ROOT &&
393 window->window_type != GDK_WINDOW_FOREIGN)
394 tmp_unset_bg (window);
400 for (l = window->children; l != NULL; l = l->next)
401 _gdk_x11_window_tmp_unset_bg (l->data, TRUE);
406 _gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window)
408 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
411 window = _gdk_window_get_impl_window (window->parent);
412 _gdk_x11_window_tmp_unset_bg (window, FALSE);
416 _gdk_x11_window_tmp_reset_bg (GdkWindow *window,
419 g_return_if_fail (GDK_IS_WINDOW (window));
421 if (window->input_only || window->destroyed ||
422 (window->window_type != GDK_WINDOW_ROOT &&
423 !GDK_WINDOW_IS_MAPPED (window)))
427 if (_gdk_window_has_impl (window) &&
428 GDK_WINDOW_IS_X11 (window) &&
429 window->window_type != GDK_WINDOW_ROOT &&
430 window->window_type != GDK_WINDOW_FOREIGN)
431 tmp_reset_bg (window);
437 for (l = window->children; l != NULL; l = l->next)
438 _gdk_x11_window_tmp_reset_bg (l->data, TRUE);
443 _gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window)
445 if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
448 window = _gdk_window_get_impl_window (window->parent);
450 _gdk_x11_window_tmp_reset_bg (window, FALSE);
454 _gdk_x11_screen_init_root_window (GdkScreen *screen)
457 GdkWindowImplX11 *impl;
458 GdkScreenX11 *screen_x11;
460 screen_x11 = GDK_SCREEN_X11 (screen);
462 g_assert (screen_x11->root_window == NULL);
464 window = screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
466 window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
467 window->impl_window = window;
468 window->visual = gdk_screen_get_system_visual (screen);
470 impl = GDK_WINDOW_IMPL_X11 (window->impl);
472 impl->xid = screen_x11->xroot_window;
473 impl->wrapper = window;
475 window->window_type = GDK_WINDOW_ROOT;
476 window->depth = DefaultDepthOfScreen (screen_x11->xscreen);
482 window->width = WidthOfScreen (screen_x11->xscreen);
483 window->height = HeightOfScreen (screen_x11->xscreen);
484 window->viewable = TRUE;
486 /* see init_randr_support() in gdkscreen-x11.c */
487 window->event_mask = GDK_STRUCTURE_MASK;
489 _gdk_window_update_size (screen_x11->root_window);
491 _gdk_xid_table_insert (screen_x11->display,
492 &screen_x11->xroot_window,
493 screen_x11->root_window);
497 set_wm_protocols (GdkWindow *window)
499 GdkDisplay *display = gdk_window_get_display (window);
503 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
504 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS");
505 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING");
508 if (GDK_DISPLAY_X11 (display)->use_sync)
509 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST");
512 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
516 get_default_title (void)
520 title = g_get_application_name ();
522 title = g_get_prgname ();
530 check_leader_window_title (GdkDisplay *display)
532 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
534 if (display_x11->leader_window && !display_x11->leader_window_title_set)
536 set_wm_name (display,
537 display_x11->leader_window,
538 get_default_title ());
540 display_x11->leader_window_title_set = TRUE;
545 create_focus_window (GdkDisplay *display,
548 GdkDisplayX11 *display_x11;
549 GdkEventMask event_mask;
553 xdisplay = GDK_DISPLAY_XDISPLAY (display);
554 display_x11 = GDK_DISPLAY_X11 (display);
556 focus_window = XCreateSimpleWindow (xdisplay, parent,
560 /* FIXME: probably better to actually track the requested event mask for the toplevel
562 event_mask = (GDK_KEY_PRESS_MASK |
563 GDK_KEY_RELEASE_MASK |
564 GDK_FOCUS_CHANGE_MASK);
566 gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
570 XMapWindow (xdisplay, focus_window);
576 ensure_sync_counter (GdkWindow *window)
579 if (!GDK_WINDOW_DESTROYED (window))
581 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
582 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
583 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
585 if (toplevel && impl->use_synchronized_configure &&
586 toplevel->update_counter == None &&
587 GDK_DISPLAY_X11 (display)->use_sync)
589 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
593 XSyncIntToValue (&value, 0);
595 toplevel->update_counter = XSyncCreateCounter (xdisplay, value);
597 atom = gdk_x11_get_xatom_by_name_for_display (display,
598 "_NET_WM_SYNC_REQUEST_COUNTER");
600 XChangeProperty (xdisplay, GDK_WINDOW_XID (window),
603 (guchar *)&toplevel->update_counter, 1);
605 XSyncIntToValue (&toplevel->current_counter_value, 0);
612 setup_toplevel_window (GdkWindow *window,
615 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
616 GdkDisplay *display = gdk_window_get_display (window);
617 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
618 XID xid = GDK_WINDOW_XID (window);
619 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent));
620 XSizeHints size_hints;
622 Window leader_window;
624 set_wm_protocols (window);
626 if (!window->input_only)
628 /* The focus window is off the visible area, and serves to receive key
629 * press events so they don't get sent to child windows.
631 toplevel->focus_window = create_focus_window (display, xid);
632 _gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window);
635 check_leader_window_title (screen_x11->display);
637 /* FIXME: Is there any point in doing this? Do any WM's pay
638 * attention to PSize, and even if they do, is this the
641 size_hints.flags = PSize;
642 size_hints.width = window->width;
643 size_hints.height = window->height;
645 XSetWMNormalHints (xdisplay, xid, &size_hints);
647 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
648 XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
651 XChangeProperty (xdisplay, xid,
652 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"),
657 leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window;
660 XChangeProperty (xdisplay, xid,
661 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
662 XA_WINDOW, 32, PropModeReplace,
663 (guchar *) &leader_window, 1);
665 if (toplevel->focus_window != None)
666 XChangeProperty (xdisplay, xid,
667 gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_USER_TIME_WINDOW"),
668 XA_WINDOW, 32, PropModeReplace,
669 (guchar *) &toplevel->focus_window, 1);
671 if (!window->focus_on_map)
672 gdk_x11_window_set_user_time (window, 0);
673 else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
674 gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
676 ensure_sync_counter (window);
680 _gdk_window_impl_new (GdkWindow *window,
681 GdkWindow *real_parent,
683 GdkEventMask event_mask,
684 GdkWindowAttr *attributes,
685 gint attributes_mask)
687 GdkWindowImplX11 *impl;
688 GdkScreenX11 *screen_x11;
689 GdkDisplayX11 *display_x11;
695 XSetWindowAttributes xattributes;
696 long xattributes_mask;
697 XClassHint *class_hint;
702 screen_x11 = GDK_SCREEN_X11 (screen);
703 xparent = GDK_WINDOW_XID (real_parent);
704 display_x11 = GDK_DISPLAY_X11 (GDK_SCREEN_DISPLAY (screen));
706 impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
707 window->impl = GDK_WINDOW_IMPL (impl);
708 impl->wrapper = GDK_WINDOW (window);
710 xdisplay = screen_x11->xdisplay;
712 xattributes_mask = 0;
714 xvisual = gdk_x11_visual_get_xvisual (window->visual);
716 if (attributes_mask & GDK_WA_NOREDIR)
718 xattributes.override_redirect =
719 (attributes->override_redirect == FALSE)?False:True;
720 xattributes_mask |= CWOverrideRedirect;
723 xattributes.override_redirect = False;
725 impl->override_redirect = xattributes.override_redirect;
727 if (window->parent && window->parent->guffaw_gravity)
729 xattributes.win_gravity = StaticGravity;
730 xattributes_mask |= CWWinGravity;
734 switch (window->window_type)
736 case GDK_WINDOW_TOPLEVEL:
737 case GDK_WINDOW_TEMP:
738 if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT)
740 /* The common code warns for this case */
741 xparent = GDK_SCREEN_XROOTWIN (screen);
745 if (!window->input_only)
749 xattributes.background_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
751 xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num);
752 xattributes_mask |= CWBorderPixel | CWBackPixel;
754 if (window->guffaw_gravity)
755 xattributes.bit_gravity = StaticGravity;
757 xattributes.bit_gravity = NorthWestGravity;
759 xattributes_mask |= CWBitGravity;
761 xattributes.colormap = _gdk_visual_get_x11_colormap (window->visual);
762 xattributes_mask |= CWColormap;
764 if (window->window_type == GDK_WINDOW_TEMP)
766 xattributes.save_under = True;
767 xattributes.override_redirect = True;
768 xattributes.cursor = None;
769 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
771 impl->override_redirect = TRUE;
779 if (window->width > 65535 ||
780 window->height > 65535)
782 g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
784 if (window->width > 65535)
785 window->width = 65535;
786 if (window->height > 65535)
787 window->height = 65535;
790 impl->xid = XCreateWindow (xdisplay, xparent,
791 window->x + window->parent->abs_x,
792 window->y + window->parent->abs_y,
793 window->width, window->height,
794 0, window->depth, class, xvisual,
795 xattributes_mask, &xattributes);
797 g_object_ref (window);
798 _gdk_xid_table_insert (screen_x11->display, &impl->xid, window);
800 switch (GDK_WINDOW_TYPE (window))
802 case GDK_WINDOW_TOPLEVEL:
803 case GDK_WINDOW_TEMP:
804 if (attributes_mask & GDK_WA_TITLE)
805 title = attributes->title;
807 title = get_default_title ();
809 gdk_window_set_title (window, title);
811 if (attributes_mask & GDK_WA_WMCLASS)
813 class_hint = XAllocClassHint ();
814 class_hint->res_name = attributes->wmclass_name;
815 class_hint->res_class = attributes->wmclass_class;
816 XSetClassHint (xdisplay, impl->xid, class_hint);
820 setup_toplevel_window (window, window->parent);
823 case GDK_WINDOW_CHILD:
828 if (attributes_mask & GDK_WA_TYPE_HINT)
829 gdk_window_set_type_hint (window, attributes->type_hint);
831 gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
832 GDK_WINDOW_XID (window), event_mask,
833 StructureNotifyMask | PropertyChangeMask);
837 x_event_mask_to_gdk_event_mask (long mask)
839 GdkEventMask event_mask = 0;
842 for (i = 0; i < _gdk_x11_event_mask_table_size; i++)
844 if (mask & _gdk_x11_event_mask_table[i])
845 event_mask |= 1 << (i + 1);
852 * gdk_x11_window_foreign_new_for_display:
853 * @display: the #GdkDisplay where the window handle comes from.
854 * @window: an XLib <type>Window</type>
856 * Wraps a native window in a #GdkWindow.
858 * This may fail if the window has been destroyed. If the window
859 * was already known to GDK, a new reference to the existing
860 * #GdkWindow is returned.
862 * Return value: (transfer full): a #GdkWindow wrapper for the native
863 * window, or %NULL if the window has been destroyed. The wrapper
864 * will be newly created, if one doesn't exist already.
869 gdk_x11_window_foreign_new_for_display (GdkDisplay *display,
874 GdkWindowImplX11 *impl;
875 GdkDisplayX11 *display_x11;
876 XWindowAttributes attrs;
878 Window *children = NULL;
882 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
884 display_x11 = GDK_DISPLAY_X11 (display);
886 if ((win = _gdk_xid_table_lookup (display, window)) != NULL)
887 return g_object_ref (win);
889 gdk_x11_display_error_trap_push (display);
890 result = XGetWindowAttributes (display_x11->xdisplay, window, &attrs);
891 if (gdk_x11_display_error_trap_pop (display) || !result)
894 /* FIXME: This is pretty expensive.
895 * Maybe the caller should supply the parent
897 gdk_x11_display_error_trap_push (display);
898 result = XQueryTree (display_x11->xdisplay, window, &root, &parent, &children, &nchildren);
899 if (gdk_x11_display_error_trap_pop (display) || !result)
905 screen = _gdk_x11_display_screen_for_xrootwin (display, root);
907 win = g_object_new (GDK_TYPE_WINDOW, NULL);
908 win->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
909 win->impl_window = win;
910 win->visual = gdk_x11_screen_lookup_visual (screen,
911 XVisualIDFromVisual (attrs.visual));
913 impl = GDK_WINDOW_IMPL_X11 (win->impl);
916 win->parent = _gdk_xid_table_lookup (display, parent);
918 if (!win->parent || GDK_WINDOW_TYPE (win->parent) == GDK_WINDOW_FOREIGN)
919 win->parent = gdk_screen_get_root_window (screen);
921 win->parent->children = g_list_prepend (win->parent->children, win);
927 win->width = attrs.width;
928 win->height = attrs.height;
929 win->window_type = GDK_WINDOW_FOREIGN;
930 win->destroyed = FALSE;
932 win->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
934 if (attrs.map_state == IsUnmapped)
935 win->state = GDK_WINDOW_STATE_WITHDRAWN;
938 win->viewable = TRUE;
940 win->depth = attrs.depth;
943 _gdk_xid_table_insert (display, &GDK_WINDOW_XID (win), win);
945 /* Update the clip region, etc */
946 _gdk_window_update_size (win);
952 * gdk_x11_window_lookup_for_display:
953 * @display: the #GdkDisplay corresponding to the window handle
954 * @window: an XLib <type>Window</type>
956 * Looks up the #GdkWindow that wraps the given native window handle.
958 * Return value: (transfer none): the #GdkWindow wrapper for the native
959 * window, or %NULL if there is none.
964 gdk_x11_window_lookup_for_display (GdkDisplay *display,
967 return (GdkWindow*) _gdk_xid_table_lookup (display, window);
971 gdk_toplevel_x11_free_contents (GdkDisplay *display,
972 GdkToplevelX11 *toplevel)
974 if (toplevel->icon_pixmap)
976 cairo_surface_destroy (toplevel->icon_pixmap);
977 toplevel->icon_pixmap = NULL;
979 if (toplevel->icon_mask)
981 cairo_surface_destroy (toplevel->icon_mask);
982 toplevel->icon_mask = NULL;
984 if (toplevel->group_leader)
986 g_object_unref (toplevel->group_leader);
987 toplevel->group_leader = NULL;
990 if (toplevel->update_counter != None)
992 XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display),
993 toplevel->update_counter);
994 toplevel->update_counter = None;
996 XSyncIntToValue (&toplevel->current_counter_value, 0);
1002 gdk_x11_window_destroy (GdkWindow *window,
1004 gboolean foreign_destroy)
1006 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1007 GdkToplevelX11 *toplevel;
1009 g_return_if_fail (GDK_IS_WINDOW (window));
1011 _gdk_selection_window_destroyed (window);
1013 toplevel = _gdk_x11_window_get_toplevel (window);
1015 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel);
1017 if (impl->cairo_surface)
1019 cairo_surface_finish (impl->cairo_surface);
1020 cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
1024 if (!recursing && !foreign_destroy)
1025 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1028 static cairo_surface_t *
1029 gdk_window_x11_resize_cairo_surface (GdkWindow *window,
1030 cairo_surface_t *surface,
1034 cairo_xlib_surface_set_size (surface, width, height);
1040 gdk_x11_window_destroy_foreign (GdkWindow *window)
1042 /* It's somebody else's window, but in our hierarchy,
1043 * so reparent it to the root window, and then send
1044 * it a delete event, as if we were a WM
1046 XClientMessageEvent xclient;
1047 GdkDisplay *display;
1049 display = GDK_WINDOW_DISPLAY (window);
1050 gdk_x11_display_error_trap_push (display);
1051 gdk_window_hide (window);
1052 gdk_window_reparent (window, NULL, 0, 0);
1054 memset (&xclient, 0, sizeof (xclient));
1055 xclient.type = ClientMessage;
1056 xclient.window = GDK_WINDOW_XID (window);
1057 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "WM_PROTOCOLS");
1058 xclient.format = 32;
1059 xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW");
1060 xclient.data.l[1] = CurrentTime;
1061 xclient.data.l[2] = 0;
1062 xclient.data.l[3] = 0;
1063 xclient.data.l[4] = 0;
1065 XSendEvent (GDK_WINDOW_XDISPLAY (window),
1066 GDK_WINDOW_XID (window),
1067 False, 0, (XEvent *)&xclient);
1068 gdk_x11_display_error_trap_pop_ignored (display);
1072 get_root (GdkWindow *window)
1074 GdkScreen *screen = gdk_window_get_screen (window);
1076 return gdk_screen_get_root_window (screen);
1079 /* This function is called when the XWindow is really gone.
1082 gdk_x11_window_destroy_notify (GdkWindow *window)
1084 GdkWindowImplX11 *window_impl;
1086 window_impl = GDK_WINDOW_IMPL_X11 ((window)->impl);
1088 if (!GDK_WINDOW_DESTROYED (window))
1090 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1091 g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window));
1093 _gdk_window_destroy (window, TRUE);
1096 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window));
1097 if (window_impl->toplevel && window_impl->toplevel->focus_window)
1098 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window);
1100 _gdk_xgrab_check_destroy (window);
1102 g_object_unref (window);
1106 update_wm_hints (GdkWindow *window,
1109 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
1110 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1114 !toplevel->is_leader &&
1115 window->state & GDK_WINDOW_STATE_WITHDRAWN)
1118 wm_hints.flags = StateHint | InputHint;
1119 wm_hints.input = window->accept_focus ? True : False;
1120 wm_hints.initial_state = NormalState;
1122 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
1124 wm_hints.flags |= StateHint;
1125 wm_hints.initial_state = IconicState;
1128 if (toplevel->icon_pixmap)
1130 wm_hints.flags |= IconPixmapHint;
1131 wm_hints.icon_pixmap = cairo_xlib_surface_get_drawable (toplevel->icon_pixmap);
1134 if (toplevel->icon_mask)
1136 wm_hints.flags |= IconMaskHint;
1137 wm_hints.icon_mask = cairo_xlib_surface_get_drawable (toplevel->icon_mask);
1140 wm_hints.flags |= WindowGroupHint;
1141 if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader))
1143 wm_hints.flags |= WindowGroupHint;
1144 wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader);
1147 wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window;
1149 if (toplevel->urgency_hint)
1150 wm_hints.flags |= XUrgencyHint;
1152 XSetWMHints (GDK_WINDOW_XDISPLAY (window),
1153 GDK_WINDOW_XID (window),
1158 set_initial_hints (GdkWindow *window)
1160 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1161 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1162 Window xwindow = GDK_WINDOW_XID (window);
1163 GdkToplevelX11 *toplevel;
1167 toplevel = _gdk_x11_window_get_toplevel (window);
1172 update_wm_hints (window, TRUE);
1174 /* We set the spec hints regardless of whether the spec is supported,
1175 * since it can't hurt and it's kind of expensive to check whether
1181 if (window->state & GDK_WINDOW_STATE_MAXIMIZED)
1183 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1184 "_NET_WM_STATE_MAXIMIZED_VERT");
1186 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1187 "_NET_WM_STATE_MAXIMIZED_HORZ");
1189 toplevel->have_maxhorz = toplevel->have_maxvert = TRUE;
1192 if (window->state & GDK_WINDOW_STATE_ABOVE)
1194 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1195 "_NET_WM_STATE_ABOVE");
1199 if (window->state & GDK_WINDOW_STATE_BELOW)
1201 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1202 "_NET_WM_STATE_BELOW");
1206 if (window->state & GDK_WINDOW_STATE_STICKY)
1208 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1209 "_NET_WM_STATE_STICKY");
1211 toplevel->have_sticky = TRUE;
1214 if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
1216 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1217 "_NET_WM_STATE_FULLSCREEN");
1219 toplevel->have_fullscreen = TRUE;
1222 if (window->modal_hint)
1224 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1225 "_NET_WM_STATE_MODAL");
1229 if (toplevel->skip_taskbar_hint)
1231 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1232 "_NET_WM_STATE_SKIP_TASKBAR");
1236 if (toplevel->skip_pager_hint)
1238 atoms[i] = gdk_x11_get_xatom_by_name_for_display (display,
1239 "_NET_WM_STATE_SKIP_PAGER");
1245 XChangeProperty (xdisplay,
1247 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1248 XA_ATOM, 32, PropModeReplace,
1249 (guchar*) atoms, i);
1253 XDeleteProperty (xdisplay,
1255 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"));
1258 if (window->state & GDK_WINDOW_STATE_STICKY)
1260 atoms[0] = 0xFFFFFFFF;
1261 XChangeProperty (xdisplay,
1263 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
1264 XA_CARDINAL, 32, PropModeReplace,
1265 (guchar*) atoms, 1);
1266 toplevel->on_all_desktops = TRUE;
1270 XDeleteProperty (xdisplay,
1272 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"));
1275 toplevel->map_serial = NextRequest (xdisplay);
1279 gdk_window_x11_show (GdkWindow *window, gboolean already_mapped)
1281 GdkDisplay *display;
1282 GdkDisplayX11 *display_x11;
1283 GdkToplevelX11 *toplevel;
1284 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1285 Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
1286 Window xwindow = GDK_WINDOW_XID (window);
1289 if (!already_mapped)
1290 set_initial_hints (window);
1292 if (WINDOW_IS_TOPLEVEL (window))
1294 display = gdk_window_get_display (window);
1295 display_x11 = GDK_DISPLAY_X11 (display);
1296 toplevel = _gdk_x11_window_get_toplevel (window);
1298 if (toplevel->user_time != 0 &&
1299 display_x11->user_time != 0 &&
1300 XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time))
1301 gdk_x11_window_set_user_time (window, display_x11->user_time);
1304 unset_bg = !window->input_only &&
1305 (window->window_type == GDK_WINDOW_CHILD ||
1306 impl->override_redirect) &&
1307 gdk_window_is_viewable (window);
1310 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1312 XMapWindow (xdisplay, xwindow);
1315 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1319 pre_unmap (GdkWindow *window)
1321 GdkWindow *start_window = NULL;
1323 if (window->input_only)
1326 if (window->window_type == GDK_WINDOW_CHILD)
1327 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1328 else if (window->window_type == GDK_WINDOW_TEMP)
1329 start_window = get_root (window);
1332 _gdk_x11_window_tmp_unset_bg (start_window, TRUE);
1336 post_unmap (GdkWindow *window)
1338 GdkWindow *start_window = NULL;
1340 if (window->input_only)
1343 if (window->window_type == GDK_WINDOW_CHILD)
1344 start_window = _gdk_window_get_impl_window ((GdkWindow *)window->parent);
1345 else if (window->window_type == GDK_WINDOW_TEMP)
1346 start_window = get_root (window);
1350 _gdk_x11_window_tmp_reset_bg (start_window, TRUE);
1352 if (window->window_type == GDK_WINDOW_CHILD && window->parent)
1354 GdkRectangle invalid_rect;
1356 gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y);
1357 invalid_rect.width = gdk_window_get_width (window);
1358 invalid_rect.height = gdk_window_get_height (window);
1359 gdk_window_invalidate_rect ((GdkWindow *)window->parent,
1360 &invalid_rect, TRUE);
1366 gdk_window_x11_hide (GdkWindow *window)
1368 /* We'll get the unmap notify eventually, and handle it then,
1369 * but checking here makes things more consistent if we are
1370 * just doing stuff ourself.
1372 _gdk_xgrab_check_unmap (window,
1373 NextRequest (GDK_WINDOW_XDISPLAY (window)));
1375 /* You can't simply unmap toplevel windows. */
1376 switch (window->window_type)
1378 case GDK_WINDOW_TOPLEVEL:
1379 case GDK_WINDOW_TEMP: /* ? */
1380 gdk_window_withdraw (window);
1383 case GDK_WINDOW_FOREIGN:
1384 case GDK_WINDOW_ROOT:
1385 case GDK_WINDOW_CHILD:
1389 _gdk_window_clear_update_area (window);
1392 XUnmapWindow (GDK_WINDOW_XDISPLAY (window),
1393 GDK_WINDOW_XID (window));
1394 post_unmap (window);
1398 gdk_window_x11_withdraw (GdkWindow *window)
1400 if (!window->destroyed)
1402 if (GDK_WINDOW_IS_MAPPED (window))
1403 gdk_synthesize_window_state (window,
1405 GDK_WINDOW_STATE_WITHDRAWN);
1407 g_assert (!GDK_WINDOW_IS_MAPPED (window));
1411 XWithdrawWindow (GDK_WINDOW_XDISPLAY (window),
1412 GDK_WINDOW_XID (window), 0);
1414 post_unmap (window);
1419 window_x11_move (GdkWindow *window,
1423 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1425 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1427 _gdk_window_move_resize_child (window,
1429 window->width, window->height);
1433 XMoveWindow (GDK_WINDOW_XDISPLAY (window),
1434 GDK_WINDOW_XID (window),
1437 if (impl->override_redirect)
1446 window_x11_resize (GdkWindow *window,
1456 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1458 _gdk_window_move_resize_child (window,
1459 window->x, window->y,
1464 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1466 XResizeWindow (GDK_WINDOW_XDISPLAY (window),
1467 GDK_WINDOW_XID (window),
1470 if (impl->override_redirect)
1472 window->width = width;
1473 window->height = height;
1474 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1478 if (width != window->width || height != window->height)
1479 window->resize_count += 1;
1483 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1487 window_x11_move_resize (GdkWindow *window,
1499 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1501 _gdk_window_move_resize_child (window, x, y, width, height);
1502 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1506 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
1508 XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window),
1509 GDK_WINDOW_XID (window),
1510 x, y, width, height);
1512 if (impl->override_redirect)
1517 window->width = width;
1518 window->height = height;
1520 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
1524 if (width != window->width || height != window->height)
1525 window->resize_count += 1;
1531 gdk_window_x11_move_resize (GdkWindow *window,
1538 if (with_move && (width < 0 && height < 0))
1539 window_x11_move (window, x, y);
1543 window_x11_move_resize (window, x, y, width, height);
1545 window_x11_resize (window, width, height);
1550 gdk_window_x11_reparent (GdkWindow *window,
1551 GdkWindow *new_parent,
1555 GdkWindowImplX11 *impl;
1557 impl = GDK_WINDOW_IMPL_X11 (window->impl);
1559 _gdk_x11_window_tmp_unset_bg (window, TRUE);
1560 _gdk_x11_window_tmp_unset_parent_bg (window);
1561 XReparentWindow (GDK_WINDOW_XDISPLAY (window),
1562 GDK_WINDOW_XID (window),
1563 GDK_WINDOW_XID (new_parent),
1564 new_parent->abs_x + x, new_parent->abs_y + y);
1565 _gdk_x11_window_tmp_reset_parent_bg (window);
1566 _gdk_x11_window_tmp_reset_bg (window, TRUE);
1568 if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1569 new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window));
1571 window->parent = new_parent;
1573 /* Switch the window type as appropriate */
1575 switch (GDK_WINDOW_TYPE (new_parent))
1577 case GDK_WINDOW_ROOT:
1578 case GDK_WINDOW_FOREIGN:
1579 /* Reparenting to toplevel */
1581 if (!WINDOW_IS_TOPLEVEL (window) &&
1582 GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN)
1584 /* This is also done in common code at a later stage, but we
1585 need it in setup_toplevel, so do it here too */
1586 if (window->toplevel_window_type != -1)
1587 GDK_WINDOW_TYPE (window) = window->toplevel_window_type;
1588 else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1589 GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL;
1591 /* Wasn't a toplevel, set up */
1592 setup_toplevel_window (window, new_parent);
1597 case GDK_WINDOW_TOPLEVEL:
1598 case GDK_WINDOW_CHILD:
1599 case GDK_WINDOW_TEMP:
1600 if (WINDOW_IS_TOPLEVEL (window) &&
1603 if (impl->toplevel->focus_window)
1605 XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window);
1606 _gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window);
1609 gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window),
1611 g_free (impl->toplevel);
1612 impl->toplevel = NULL;
1620 gdk_window_x11_raise (GdkWindow *window)
1622 XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1626 gdk_window_x11_restack_under (GdkWindow *window,
1627 GList *native_siblings /* in requested order, first is bottom-most */)
1633 n_windows = g_list_length (native_siblings) + 1;
1634 windows = g_new (Window, n_windows);
1636 windows[0] = GDK_WINDOW_XID (window);
1637 /* Reverse order, as input order is bottom-most first */
1639 for (l = native_siblings; l != NULL; l = l->next)
1640 windows[i--] = GDK_WINDOW_XID (l->data);
1642 XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows);
1648 gdk_window_x11_restack_toplevel (GdkWindow *window,
1652 XWindowChanges changes;
1654 changes.sibling = GDK_WINDOW_XID (sibling);
1655 changes.stack_mode = above ? Above : Below;
1656 XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window),
1657 GDK_WINDOW_XID (window),
1658 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)),
1659 CWStackMode | CWSibling, &changes);
1663 gdk_window_x11_lower (GdkWindow *window)
1665 XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window));
1669 * gdk_x11_window_move_to_current_desktop:
1670 * @window: a #GdkWindow
1672 * Moves the window to the correct workspace when running under a
1673 * window manager that supports multiple workspaces, as described
1674 * in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended
1675 * Window Manager Hints</ulink>. Will not do anything if the
1676 * window is already on all workspaces.
1681 gdk_x11_window_move_to_current_desktop (GdkWindow *window)
1683 GdkToplevelX11 *toplevel;
1685 g_return_if_fail (GDK_IS_WINDOW (window));
1686 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1688 toplevel = _gdk_x11_window_get_toplevel (window);
1690 if (toplevel->on_all_desktops)
1693 move_to_current_desktop (window);
1697 move_to_current_desktop (GdkWindow *window)
1699 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1700 gdk_atom_intern_static_string ("_NET_WM_DESKTOP")))
1707 gulong *current_desktop;
1708 GdkDisplay *display;
1710 display = gdk_window_get_display (window);
1712 /* Get current desktop, then set it; this is a race, but not
1713 * one that matters much in practice.
1715 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
1716 GDK_WINDOW_XROOTWIN (window),
1717 gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
1719 False, XA_CARDINAL, &type, &format, &nitems,
1720 &bytes_after, &data);
1722 if (type == XA_CARDINAL)
1724 XClientMessageEvent xclient;
1725 current_desktop = (gulong *)data;
1727 memset (&xclient, 0, sizeof (xclient));
1728 xclient.type = ClientMessage;
1730 xclient.send_event = True;
1731 xclient.window = GDK_WINDOW_XID (window);
1732 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP");
1733 xclient.format = 32;
1735 xclient.data.l[0] = *current_desktop;
1736 xclient.data.l[1] = 0;
1737 xclient.data.l[2] = 0;
1738 xclient.data.l[3] = 0;
1739 xclient.data.l[4] = 0;
1741 XSendEvent (GDK_DISPLAY_XDISPLAY (display),
1742 GDK_WINDOW_XROOTWIN (window),
1744 SubstructureRedirectMask | SubstructureNotifyMask,
1745 (XEvent *)&xclient);
1747 XFree (current_desktop);
1753 gdk_x11_window_focus (GdkWindow *window,
1756 GdkDisplay *display;
1758 g_return_if_fail (GDK_IS_WINDOW (window));
1760 if (GDK_WINDOW_DESTROYED (window) ||
1761 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1764 display = GDK_WINDOW_DISPLAY (window);
1766 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
1767 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1769 XClientMessageEvent xclient;
1771 memset (&xclient, 0, sizeof (xclient));
1772 xclient.type = ClientMessage;
1773 xclient.window = GDK_WINDOW_XID (window);
1774 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
1775 "_NET_ACTIVE_WINDOW");
1776 xclient.format = 32;
1777 xclient.data.l[0] = 1; /* requestor type; we're an app */
1778 xclient.data.l[1] = timestamp;
1779 xclient.data.l[2] = None; /* currently active window */
1780 xclient.data.l[3] = 0;
1781 xclient.data.l[4] = 0;
1783 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
1784 SubstructureRedirectMask | SubstructureNotifyMask,
1785 (XEvent *)&xclient);
1789 XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window));
1791 /* There is no way of knowing reliably whether we are viewable;
1792 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1794 _gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window),
1801 gdk_x11_window_set_type_hint (GdkWindow *window,
1802 GdkWindowTypeHint hint)
1804 GdkDisplay *display;
1807 if (GDK_WINDOW_DESTROYED (window) ||
1808 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1811 display = gdk_window_get_display (window);
1815 case GDK_WINDOW_TYPE_HINT_DIALOG:
1816 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG");
1818 case GDK_WINDOW_TYPE_HINT_MENU:
1819 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU");
1821 case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1822 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR");
1824 case GDK_WINDOW_TYPE_HINT_UTILITY:
1825 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY");
1827 case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1828 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH");
1830 case GDK_WINDOW_TYPE_HINT_DOCK:
1831 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK");
1833 case GDK_WINDOW_TYPE_HINT_DESKTOP:
1834 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP");
1836 case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
1837 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU");
1839 case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
1840 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU");
1842 case GDK_WINDOW_TYPE_HINT_TOOLTIP:
1843 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP");
1845 case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
1846 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION");
1848 case GDK_WINDOW_TYPE_HINT_COMBO:
1849 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO");
1851 case GDK_WINDOW_TYPE_HINT_DND:
1852 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND");
1855 g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1857 case GDK_WINDOW_TYPE_HINT_NORMAL:
1858 atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL");
1862 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1863 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1864 XA_ATOM, 32, PropModeReplace,
1865 (guchar *)&atom, 1);
1868 static GdkWindowTypeHint
1869 gdk_x11_window_get_type_hint (GdkWindow *window)
1871 GdkDisplay *display;
1872 GdkWindowTypeHint type;
1875 gulong nitems_return;
1876 gulong bytes_after_return;
1877 guchar *data = NULL;
1879 g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
1881 if (GDK_WINDOW_DESTROYED (window) ||
1882 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1883 return GDK_WINDOW_TYPE_HINT_NORMAL;
1885 type = GDK_WINDOW_TYPE_HINT_NORMAL;
1887 display = gdk_window_get_display (window);
1889 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
1890 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
1891 0, G_MAXLONG, False, XA_ATOM, &type_return,
1892 &format_return, &nitems_return, &bytes_after_return,
1895 if ((type_return == XA_ATOM) && (format_return == 32) &&
1896 (data) && (nitems_return == 1))
1898 Atom atom = *(Atom*)data;
1900 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"))
1901 type = GDK_WINDOW_TYPE_HINT_DIALOG;
1902 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"))
1903 type = GDK_WINDOW_TYPE_HINT_MENU;
1904 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"))
1905 type = GDK_WINDOW_TYPE_HINT_TOOLBAR;
1906 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"))
1907 type = GDK_WINDOW_TYPE_HINT_UTILITY;
1908 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"))
1909 type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
1910 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"))
1911 type = GDK_WINDOW_TYPE_HINT_DOCK;
1912 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"))
1913 type = GDK_WINDOW_TYPE_HINT_DESKTOP;
1914 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"))
1915 type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU;
1916 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"))
1917 type = GDK_WINDOW_TYPE_HINT_POPUP_MENU;
1918 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"))
1919 type = GDK_WINDOW_TYPE_HINT_TOOLTIP;
1920 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"))
1921 type = GDK_WINDOW_TYPE_HINT_NOTIFICATION;
1922 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"))
1923 type = GDK_WINDOW_TYPE_HINT_COMBO;
1924 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"))
1925 type = GDK_WINDOW_TYPE_HINT_DND;
1928 if (type_return != None && data != NULL)
1936 gdk_wmspec_change_state (gboolean add,
1941 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
1942 XClientMessageEvent xclient;
1944 #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
1945 #define _NET_WM_STATE_ADD 1 /* add/set property */
1946 #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
1948 memset (&xclient, 0, sizeof (xclient));
1949 xclient.type = ClientMessage;
1950 xclient.window = GDK_WINDOW_XID (window);
1951 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE");
1952 xclient.format = 32;
1953 xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1954 xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1);
1955 xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2);
1956 xclient.data.l[3] = 0;
1957 xclient.data.l[4] = 0;
1959 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
1960 SubstructureRedirectMask | SubstructureNotifyMask,
1961 (XEvent *)&xclient);
1965 gdk_x11_window_set_modal_hint (GdkWindow *window,
1968 if (GDK_WINDOW_DESTROYED (window) ||
1969 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1972 window->modal_hint = modal;
1974 if (GDK_WINDOW_IS_MAPPED (window))
1975 gdk_wmspec_change_state (modal, window,
1976 gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"),
1981 gdk_x11_window_set_skip_taskbar_hint (GdkWindow *window,
1982 gboolean skips_taskbar)
1984 GdkToplevelX11 *toplevel;
1986 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1988 if (GDK_WINDOW_DESTROYED (window) ||
1989 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1992 toplevel = _gdk_x11_window_get_toplevel (window);
1993 toplevel->skip_taskbar_hint = skips_taskbar;
1995 if (GDK_WINDOW_IS_MAPPED (window))
1996 gdk_wmspec_change_state (skips_taskbar, window,
1997 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"),
2002 gdk_x11_window_set_skip_pager_hint (GdkWindow *window,
2003 gboolean skips_pager)
2005 GdkToplevelX11 *toplevel;
2007 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2009 if (GDK_WINDOW_DESTROYED (window) ||
2010 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2013 toplevel = _gdk_x11_window_get_toplevel (window);
2014 toplevel->skip_pager_hint = skips_pager;
2016 if (GDK_WINDOW_IS_MAPPED (window))
2017 gdk_wmspec_change_state (skips_pager, window,
2018 gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"),
2023 gdk_x11_window_set_urgency_hint (GdkWindow *window,
2026 GdkToplevelX11 *toplevel;
2028 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2030 if (GDK_WINDOW_DESTROYED (window) ||
2031 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2034 toplevel = _gdk_x11_window_get_toplevel (window);
2035 toplevel->urgency_hint = urgent;
2037 update_wm_hints (window, FALSE);
2041 gdk_x11_window_set_geometry_hints (GdkWindow *window,
2042 const GdkGeometry *geometry,
2043 GdkWindowHints geom_mask)
2045 XSizeHints size_hints;
2047 if (GDK_WINDOW_DESTROYED (window) ||
2048 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2051 size_hints.flags = 0;
2053 if (geom_mask & GDK_HINT_POS)
2055 size_hints.flags |= PPosition;
2056 /* We need to initialize the following obsolete fields because KWM
2057 * apparently uses these fields if they are non-zero.
2064 if (geom_mask & GDK_HINT_USER_POS)
2066 size_hints.flags |= USPosition;
2069 if (geom_mask & GDK_HINT_USER_SIZE)
2071 size_hints.flags |= USSize;
2074 if (geom_mask & GDK_HINT_MIN_SIZE)
2076 size_hints.flags |= PMinSize;
2077 size_hints.min_width = geometry->min_width;
2078 size_hints.min_height = geometry->min_height;
2081 if (geom_mask & GDK_HINT_MAX_SIZE)
2083 size_hints.flags |= PMaxSize;
2084 size_hints.max_width = MAX (geometry->max_width, 1);
2085 size_hints.max_height = MAX (geometry->max_height, 1);
2088 if (geom_mask & GDK_HINT_BASE_SIZE)
2090 size_hints.flags |= PBaseSize;
2091 size_hints.base_width = geometry->base_width;
2092 size_hints.base_height = geometry->base_height;
2095 if (geom_mask & GDK_HINT_RESIZE_INC)
2097 size_hints.flags |= PResizeInc;
2098 size_hints.width_inc = geometry->width_inc;
2099 size_hints.height_inc = geometry->height_inc;
2102 if (geom_mask & GDK_HINT_ASPECT)
2104 size_hints.flags |= PAspect;
2105 if (geometry->min_aspect <= 1)
2107 size_hints.min_aspect.x = 65536 * geometry->min_aspect;
2108 size_hints.min_aspect.y = 65536;
2112 size_hints.min_aspect.x = 65536;
2113 size_hints.min_aspect.y = 65536 / geometry->min_aspect;;
2115 if (geometry->max_aspect <= 1)
2117 size_hints.max_aspect.x = 65536 * geometry->max_aspect;
2118 size_hints.max_aspect.y = 65536;
2122 size_hints.max_aspect.x = 65536;
2123 size_hints.max_aspect.y = 65536 / geometry->max_aspect;;
2127 if (geom_mask & GDK_HINT_WIN_GRAVITY)
2129 size_hints.flags |= PWinGravity;
2130 size_hints.win_gravity = geometry->win_gravity;
2133 /* FIXME: Would it be better to delete this property if
2134 * geom_mask == 0? It would save space on the server
2136 XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2137 GDK_WINDOW_XID (window),
2142 gdk_window_get_geometry_hints (GdkWindow *window,
2143 GdkGeometry *geometry,
2144 GdkWindowHints *geom_mask)
2146 XSizeHints *size_hints;
2147 glong junk_supplied_mask = 0;
2149 g_return_if_fail (GDK_IS_WINDOW (window));
2150 g_return_if_fail (geometry != NULL);
2151 g_return_if_fail (geom_mask != NULL);
2155 if (GDK_WINDOW_DESTROYED (window) ||
2156 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2159 size_hints = XAllocSizeHints ();
2163 if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window),
2164 GDK_WINDOW_XID (window),
2166 &junk_supplied_mask))
2167 size_hints->flags = 0;
2169 if (size_hints->flags & PMinSize)
2171 *geom_mask |= GDK_HINT_MIN_SIZE;
2172 geometry->min_width = size_hints->min_width;
2173 geometry->min_height = size_hints->min_height;
2176 if (size_hints->flags & PMaxSize)
2178 *geom_mask |= GDK_HINT_MAX_SIZE;
2179 geometry->max_width = MAX (size_hints->max_width, 1);
2180 geometry->max_height = MAX (size_hints->max_height, 1);
2183 if (size_hints->flags & PResizeInc)
2185 *geom_mask |= GDK_HINT_RESIZE_INC;
2186 geometry->width_inc = size_hints->width_inc;
2187 geometry->height_inc = size_hints->height_inc;
2190 if (size_hints->flags & PAspect)
2192 *geom_mask |= GDK_HINT_ASPECT;
2194 geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y;
2195 geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y;
2198 if (size_hints->flags & PWinGravity)
2200 *geom_mask |= GDK_HINT_WIN_GRAVITY;
2201 geometry->win_gravity = size_hints->win_gravity;
2208 utf8_is_latin1 (const gchar *str)
2210 const char *p = str;
2214 gunichar ch = g_utf8_get_char (p);
2219 p = g_utf8_next_char (p);
2225 /* Set the property to @utf8_str as STRING if the @utf8_str is fully
2226 * convertable to STRING, otherwise, set it as compound text
2229 set_text_property (GdkDisplay *display,
2232 const gchar *utf8_str)
2234 gchar *prop_text = NULL;
2238 gboolean is_compound_text;
2240 if (utf8_is_latin1 (utf8_str))
2242 prop_type = XA_STRING;
2243 prop_text = gdk_utf8_to_string_target (utf8_str);
2244 prop_length = prop_text ? strlen (prop_text) : 0;
2246 is_compound_text = FALSE;
2252 gdk_utf8_to_compound_text_for_display (display,
2253 utf8_str, &gdk_type, &prop_format,
2254 (guchar **)&prop_text, &prop_length);
2255 prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type);
2256 is_compound_text = TRUE;
2261 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
2264 prop_type, prop_format,
2265 PropModeReplace, (guchar *)prop_text,
2268 if (is_compound_text)
2269 gdk_free_compound_text ((guchar *)prop_text);
2275 /* Set WM_NAME and _NET_WM_NAME
2278 set_wm_name (GdkDisplay *display,
2282 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2283 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
2284 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2285 PropModeReplace, (guchar *)name, strlen (name));
2287 set_text_property (display, xwindow,
2288 gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"),
2293 gdk_x11_window_set_title (GdkWindow *window,
2296 GdkDisplay *display;
2300 g_return_if_fail (title != NULL);
2302 if (GDK_WINDOW_DESTROYED (window) ||
2303 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2306 display = gdk_window_get_display (window);
2307 xdisplay = GDK_DISPLAY_XDISPLAY (display);
2308 xwindow = GDK_WINDOW_XID (window);
2310 set_wm_name (display, xwindow, title);
2312 if (!gdk_window_icon_name_set (window))
2314 XChangeProperty (xdisplay, xwindow,
2315 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
2316 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2317 PropModeReplace, (guchar *)title, strlen (title));
2319 set_text_property (display, xwindow,
2320 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
2326 gdk_x11_window_set_role (GdkWindow *window,
2329 GdkDisplay *display;
2331 display = gdk_window_get_display (window);
2333 if (GDK_WINDOW_DESTROYED (window) ||
2334 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2338 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2339 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"),
2340 XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role));
2342 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2343 gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"));
2347 gdk_x11_window_set_startup_id (GdkWindow *window,
2348 const gchar *startup_id)
2350 GdkDisplay *display;
2352 g_return_if_fail (GDK_IS_WINDOW (window));
2354 display = gdk_window_get_display (window);
2356 if (GDK_WINDOW_DESTROYED (window) ||
2357 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2361 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2362 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2363 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2364 PropModeReplace, (unsigned char *)startup_id, strlen (startup_id));
2366 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
2367 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"));
2371 gdk_x11_window_set_transient_for (GdkWindow *window,
2374 if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) &&
2375 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2376 XSetTransientForHint (GDK_WINDOW_XDISPLAY (window),
2377 GDK_WINDOW_XID (window),
2378 GDK_WINDOW_XID (parent));
2382 gdk_window_x11_set_back_color (GdkWindow *window,
2388 GdkVisual *visual = gdk_window_get_visual (window);
2390 /* I suppose we could handle these, but that'd require fiddling with
2391 * xrender formats... */
2395 switch (visual->type)
2397 case GDK_VISUAL_DIRECT_COLOR:
2398 case GDK_VISUAL_TRUE_COLOR:
2400 /* If bits not used for color are used for something other than padding,
2401 * it's likely alpha, so we set them to 1s.
2403 guint padding, pixel;
2405 /* Shifting by >= width-of-type isn't defined in C */
2406 if (visual->depth >= 32)
2409 padding = ((~(guint32)0)) << visual->depth;
2411 pixel = ~ (visual->red_mask | visual->green_mask | visual->blue_mask | padding);
2413 pixel += (((int) (red * ((1 << visual->red_prec ) - 1))) << visual->red_shift ) +
2414 (((int) (green * ((1 << visual->green_prec) - 1))) << visual->green_shift) +
2415 (((int) (blue * ((1 << visual->blue_prec ) - 1))) << visual->blue_shift );
2417 XSetWindowBackground (GDK_WINDOW_XDISPLAY (window),
2418 GDK_WINDOW_XID (window), pixel);
2422 /* These require fiddling with the colormap, and as they're essentially unused
2423 * we're just gonna skip them for now.
2425 case GDK_VISUAL_PSEUDO_COLOR:
2426 case GDK_VISUAL_GRAYSCALE:
2427 case GDK_VISUAL_STATIC_GRAY:
2428 case GDK_VISUAL_STATIC_COLOR:
2437 matrix_is_identity (cairo_matrix_t *matrix)
2439 return matrix->xx == 1.0 && matrix->yy == 1.0 &&
2440 matrix->yx == 0.0 && matrix->xy == 0.0 &&
2441 matrix->x0 == 0.0 && matrix->y0 == 0.0;
2445 gdk_window_x11_set_background (GdkWindow *window,
2446 cairo_pattern_t *pattern)
2449 cairo_surface_t *surface;
2450 cairo_matrix_t matrix;
2452 if (GDK_WINDOW_DESTROYED (window))
2455 if (pattern == NULL)
2459 /* X throws BadMatch if the parent has a different visual when
2460 * using ParentRelative */
2461 parent = gdk_window_get_parent (window);
2462 if (parent && gdk_window_get_visual (parent) == gdk_window_get_visual (window))
2463 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2464 GDK_WINDOW_XID (window), ParentRelative);
2466 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2467 GDK_WINDOW_XID (window), None);
2471 switch (cairo_pattern_get_type (pattern))
2473 case CAIRO_PATTERN_TYPE_SOLID:
2474 cairo_pattern_get_rgba (pattern, &r, &g, &b, &a);
2475 if (gdk_window_x11_set_back_color (window, r, g, b, a))
2478 case CAIRO_PATTERN_TYPE_SURFACE:
2479 cairo_pattern_get_matrix (pattern, &matrix);
2480 if (cairo_pattern_get_surface (pattern, &surface) == CAIRO_STATUS_SUCCESS &&
2481 matrix_is_identity (&matrix) &&
2482 cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB &&
2483 cairo_xlib_surface_get_visual (surface) == GDK_VISUAL_XVISUAL (gdk_window_get_visual ((window))) &&
2484 cairo_xlib_surface_get_display (surface) == GDK_WINDOW_XDISPLAY (window))
2488 cairo_surface_get_device_offset (surface, &x, &y);
2489 /* XXX: This still bombs for non-pixmaps, but there's no way to
2490 * detect we're not a pixmap in Cairo... */
2491 if (x == 0.0 && y == 0.0)
2493 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2494 GDK_WINDOW_XID (window),
2495 cairo_xlib_surface_get_drawable (surface));
2500 case CAIRO_PATTERN_TYPE_LINEAR:
2501 case CAIRO_PATTERN_TYPE_RADIAL:
2503 /* fallback: just use black */
2507 XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
2508 GDK_WINDOW_XID (window), None);
2512 gdk_window_x11_set_device_cursor (GdkWindow *window,
2516 GdkWindowImplX11 *impl;
2518 g_return_if_fail (GDK_IS_WINDOW (window));
2519 g_return_if_fail (GDK_IS_DEVICE (device));
2521 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2524 g_hash_table_remove (impl->device_cursor, device);
2527 _gdk_x11_cursor_update_theme (cursor);
2528 g_hash_table_replace (impl->device_cursor,
2529 device, gdk_cursor_ref (cursor));
2532 if (!GDK_WINDOW_DESTROYED (window))
2533 GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
2537 _gdk_x11_window_get_cursor (GdkWindow *window)
2539 GdkWindowImplX11 *impl;
2541 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
2543 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2545 return impl->cursor;
2549 gdk_window_x11_get_geometry (GdkWindow *window,
2560 guint tborder_width;
2563 if (!GDK_WINDOW_DESTROYED (window))
2565 XGetGeometry (GDK_WINDOW_XDISPLAY (window),
2566 GDK_WINDOW_XID (window),
2567 &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth);
2581 gdk_window_x11_get_root_coords (GdkWindow *window,
2592 return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
2593 GDK_WINDOW_XID (window),
2594 GDK_WINDOW_XROOTWIN (window),
2607 gdk_x11_window_get_root_origin (GdkWindow *window,
2613 gdk_window_get_frame_extents (window, &rect);
2623 gdk_x11_window_get_frame_extents (GdkWindow *window,
2626 GdkDisplay *display;
2627 GdkWindowImplX11 *impl;
2638 gulong nitems_return;
2639 gulong bytes_after_return;
2642 guint ww, wh, wb, wd;
2644 gboolean got_frame_extents = FALSE;
2646 g_return_if_fail (rect != NULL);
2653 while (window->parent && (window->parent)->parent)
2654 window = window->parent;
2656 /* Refine our fallback answer a bit using local information */
2657 rect->x = window->x;
2658 rect->y = window->y;
2659 rect->width = window->width;
2660 rect->height = window->height;
2662 impl = GDK_WINDOW_IMPL_X11 (window->impl);
2663 if (GDK_WINDOW_DESTROYED (window) || impl->override_redirect)
2669 display = gdk_window_get_display (window);
2671 gdk_x11_display_error_trap_push (display);
2673 xwindow = GDK_WINDOW_XID (window);
2675 /* first try: use _NET_FRAME_EXTENTS */
2676 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow,
2677 gdk_x11_get_xatom_by_name_for_display (display,
2678 "_NET_FRAME_EXTENTS"),
2679 0, G_MAXLONG, False, XA_CARDINAL, &type_return,
2680 &format_return, &nitems_return, &bytes_after_return,
2684 if ((type_return == XA_CARDINAL) && (format_return == 32) &&
2685 (nitems_return == 4) && (data))
2687 gulong *ldata = (gulong *) data;
2688 got_frame_extents = TRUE;
2690 /* try to get the real client window geometry */
2691 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2692 &root, &wx, &wy, &ww, &wh, &wb, &wd) &&
2693 XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display),
2694 xwindow, root, 0, 0, &wx, &wy, &child))
2702 /* _NET_FRAME_EXTENTS format is left, right, top, bottom */
2703 rect->x -= ldata[0];
2704 rect->y -= ldata[2];
2705 rect->width += ldata[0] + ldata[1];
2706 rect->height += ldata[2] + ldata[3];
2713 if (got_frame_extents)
2716 /* no frame extents property available, which means we either have a WM that
2717 is not EWMH compliant or is broken - try fallback and walk up the window
2718 tree to get our window's parent which hopefully is the window frame */
2720 /* use NETWM_VIRTUAL_ROOTS if available */
2721 root = GDK_WINDOW_XROOTWIN (window);
2723 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root,
2724 gdk_x11_get_xatom_by_name_for_display (display,
2725 "_NET_VIRTUAL_ROOTS"),
2726 0, G_MAXLONG, False, XA_WINDOW, &type_return,
2727 &format_return, &nitems_return, &bytes_after_return,
2731 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
2733 nvroots = nitems_return;
2734 vroots = (Window *)data;
2738 xparent = GDK_WINDOW_XID (window);
2744 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow,
2746 &children, &nchildren))
2752 /* check virtual roots */
2753 for (i = 0; i < nvroots; i++)
2755 if (xparent == vroots[i])
2762 while (xparent != root);
2764 if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow,
2765 &root, &wx, &wy, &ww, &wh, &wb, &wd))
2777 gdk_x11_display_error_trap_pop_ignored (display);
2781 gdk_window_x11_get_device_state (GdkWindow *window,
2785 GdkModifierType *mask)
2789 g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
2791 if (GDK_WINDOW_DESTROYED (window))
2794 GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
2798 return child != NULL;
2802 gdk_window_x11_get_events (GdkWindow *window)
2804 XWindowAttributes attrs;
2805 GdkEventMask event_mask;
2806 GdkEventMask filtered;
2808 if (GDK_WINDOW_DESTROYED (window))
2812 XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2813 GDK_WINDOW_XID (window),
2815 event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask);
2816 /* if property change was filtered out before, keep it filtered out */
2817 filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK;
2818 window->event_mask = event_mask & ((window->event_mask & filtered) | ~filtered);
2824 gdk_window_x11_set_events (GdkWindow *window,
2825 GdkEventMask event_mask)
2827 long xevent_mask = 0;
2829 if (!GDK_WINDOW_DESTROYED (window))
2831 GdkDisplayX11 *display_x11;
2833 if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
2834 xevent_mask = StructureNotifyMask | PropertyChangeMask;
2836 display_x11 = GDK_DISPLAY_X11 (gdk_window_get_display (window));
2837 gdk_x11_event_source_select_events ((GdkEventSource *) display_x11->event_source,
2838 GDK_WINDOW_XID (window), event_mask,
2844 do_shape_combine_region (GdkWindow *window,
2845 const cairo_region_t *shape_region,
2850 if (GDK_WINDOW_DESTROYED (window))
2853 if (shape_region == NULL)
2855 /* Use NULL mask to unset the shape */
2856 if (shape == ShapeBounding
2857 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
2858 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
2860 if (shape == ShapeBounding)
2862 _gdk_x11_window_tmp_unset_parent_bg (window);
2863 _gdk_x11_window_tmp_unset_bg (window, TRUE);
2865 XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
2866 GDK_WINDOW_XID (window),
2871 if (shape == ShapeBounding)
2873 _gdk_x11_window_tmp_reset_parent_bg (window);
2874 _gdk_x11_window_tmp_reset_bg (window, TRUE);
2880 if (shape == ShapeBounding
2881 ? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))
2882 : gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window)))
2885 XRectangle *xrects = NULL;
2887 _gdk_x11_region_get_xrectangles (shape_region,
2891 if (shape == ShapeBounding)
2893 _gdk_x11_window_tmp_unset_parent_bg (window);
2894 _gdk_x11_window_tmp_unset_bg (window, TRUE);
2896 XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
2897 GDK_WINDOW_XID (window),
2904 if (shape == ShapeBounding)
2906 _gdk_x11_window_tmp_reset_parent_bg (window);
2907 _gdk_x11_window_tmp_reset_bg (window, TRUE);
2915 gdk_window_x11_shape_combine_region (GdkWindow *window,
2916 const cairo_region_t *shape_region,
2920 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding);
2924 gdk_window_x11_input_shape_combine_region (GdkWindow *window,
2925 const cairo_region_t *shape_region,
2930 do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput);
2936 gdk_x11_window_set_override_redirect (GdkWindow *window,
2937 gboolean override_redirect)
2939 XSetWindowAttributes attr;
2941 if (!GDK_WINDOW_DESTROYED (window) &&
2942 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2944 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
2946 attr.override_redirect = (override_redirect? True : False);
2947 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
2948 GDK_WINDOW_XID (window),
2952 impl->override_redirect = attr.override_redirect;
2957 gdk_x11_window_set_accept_focus (GdkWindow *window,
2958 gboolean accept_focus)
2960 accept_focus = accept_focus != FALSE;
2962 if (window->accept_focus != accept_focus)
2964 window->accept_focus = accept_focus;
2966 if (!GDK_WINDOW_DESTROYED (window) &&
2967 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2968 update_wm_hints (window, FALSE);
2973 gdk_x11_window_set_focus_on_map (GdkWindow *window,
2974 gboolean focus_on_map)
2976 focus_on_map = focus_on_map != FALSE;
2978 if (window->focus_on_map != focus_on_map)
2980 window->focus_on_map = focus_on_map;
2982 if ((!GDK_WINDOW_DESTROYED (window)) &&
2983 (!window->focus_on_map) &&
2984 WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
2985 gdk_x11_window_set_user_time (window, 0);
2990 * gdk_x11_window_set_user_time:
2991 * @window: A toplevel #GdkWindow
2992 * @timestamp: An XServer timestamp to which the property should be set
2994 * The application can use this call to update the _NET_WM_USER_TIME
2995 * property on a toplevel window. This property stores an Xserver
2996 * time which represents the time of the last user input event
2997 * received for this window. This property may be used by the window
2998 * manager to alter the focus, stacking, and/or placement behavior of
2999 * windows when they are mapped depending on whether the new window
3000 * was created by a user action or is a "pop-up" window activated by a
3001 * timer or some other event.
3003 * Note that this property is automatically updated by GDK, so this
3004 * function should only be used by applications which handle input
3005 * events bypassing GDK.
3010 gdk_x11_window_set_user_time (GdkWindow *window,
3013 GdkDisplay *display;
3014 GdkDisplayX11 *display_x11;
3015 GdkToplevelX11 *toplevel;
3016 glong timestamp_long = (glong)timestamp;
3019 if (GDK_WINDOW_DESTROYED (window) ||
3020 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3023 display = gdk_window_get_display (window);
3024 display_x11 = GDK_DISPLAY_X11 (display);
3025 toplevel = _gdk_x11_window_get_toplevel (window);
3029 g_warning ("gdk_window_set_user_time called on non-toplevel\n");
3033 if (toplevel->focus_window != None &&
3034 gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
3035 gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW")))
3036 xid = toplevel->focus_window;
3038 xid = GDK_WINDOW_XID (window);
3040 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid,
3041 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
3042 XA_CARDINAL, 32, PropModeReplace,
3043 (guchar *)×tamp_long, 1);
3045 if (timestamp_long != GDK_CURRENT_TIME &&
3046 (display_x11->user_time == GDK_CURRENT_TIME ||
3047 XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time)))
3048 display_x11->user_time = timestamp_long;
3051 toplevel->user_time = timestamp_long;
3054 #define GDK_SELECTION_MAX_SIZE(display) \
3056 XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
3057 ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
3058 : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
3061 gdk_window_update_icon (GdkWindow *window,
3064 GdkToplevelX11 *toplevel;
3065 GdkPixbuf *best_icon;
3069 toplevel = _gdk_x11_window_get_toplevel (window);
3071 if (toplevel->icon_pixmap != NULL)
3073 cairo_surface_destroy (toplevel->icon_pixmap);
3074 toplevel->icon_pixmap = NULL;
3077 if (toplevel->icon_mask != NULL)
3079 cairo_surface_destroy (toplevel->icon_mask);
3080 toplevel->icon_mask = NULL;
3083 #define IDEAL_SIZE 48
3085 best_size = G_MAXINT;
3087 for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next)
3089 GdkPixbuf *pixbuf = tmp_list->data;
3092 /* average width and height - if someone passes in a rectangular
3093 * icon they deserve what they get.
3095 this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
3098 if (best_icon == NULL)
3105 /* icon is better if it's 32 pixels or larger, and closer to
3106 * the ideal size than the current best.
3109 (ABS (best_size - IDEAL_SIZE) <
3110 ABS (this - IDEAL_SIZE)))
3120 int width = gdk_pixbuf_get_width (best_icon);
3121 int height = gdk_pixbuf_get_height (best_icon);
3124 toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window,
3128 cr = cairo_create (toplevel->icon_pixmap);
3129 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3130 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3131 if (gdk_pixbuf_get_has_alpha (best_icon))
3133 /* Saturate the image, so it has bilevel alpha */
3134 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
3136 cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
3138 cairo_pop_group_to_source (cr);
3143 if (gdk_pixbuf_get_has_alpha (best_icon))
3145 toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
3149 cr = cairo_create (toplevel->icon_mask);
3150 gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);
3151 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
3157 update_wm_hints (window, FALSE);
3161 gdk_x11_window_set_icon_list (GdkWindow *window,
3170 gint width, height, stride;
3173 GdkDisplay *display;
3176 if (GDK_WINDOW_DESTROYED (window) ||
3177 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3180 display = gdk_window_get_display (window);
3188 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
3190 width = gdk_pixbuf_get_width (pixbuf);
3191 height = gdk_pixbuf_get_height (pixbuf);
3193 /* silently ignore overlarge icons */
3194 if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
3196 g_warning ("gdk_window_set_icon_list: icons too large");
3201 size += 2 + width * height;
3203 l = g_list_next (l);
3206 data = g_malloc (size * sizeof (gulong));
3214 width = gdk_pixbuf_get_width (pixbuf);
3215 height = gdk_pixbuf_get_height (pixbuf);
3216 stride = gdk_pixbuf_get_rowstride (pixbuf);
3217 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
3222 pixels = gdk_pixbuf_get_pixels (pixbuf);
3224 for (y = 0; y < height; y++)
3226 for (x = 0; x < width; x++)
3230 r = pixels[y*stride + x*n_channels + 0];
3231 g = pixels[y*stride + x*n_channels + 1];
3232 b = pixels[y*stride + x*n_channels + 2];
3233 if (n_channels >= 4)
3234 a = pixels[y*stride + x*n_channels + 3];
3238 *p++ = a << 24 | r << 16 | g << 8 | b ;
3242 l = g_list_next (l);
3248 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3249 GDK_WINDOW_XID (window),
3250 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"),
3253 (guchar*) data, size);
3257 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3258 GDK_WINDOW_XID (window),
3259 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"));
3264 gdk_window_update_icon (window, pixbufs);
3268 gdk_window_icon_name_set (GdkWindow *window)
3270 return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window),
3271 g_quark_from_static_string ("gdk-icon-name-set")));
3275 gdk_x11_window_set_icon_name (GdkWindow *window,
3278 GdkDisplay *display;
3280 if (GDK_WINDOW_DESTROYED (window) ||
3281 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3284 display = gdk_window_get_display (window);
3286 g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"),
3287 GUINT_TO_POINTER (name != NULL));
3291 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3292 GDK_WINDOW_XID (window),
3293 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"),
3294 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
3295 PropModeReplace, (guchar *)name, strlen (name));
3297 set_text_property (display, GDK_WINDOW_XID (window),
3298 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"),
3303 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3304 GDK_WINDOW_XID (window),
3305 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"));
3306 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
3307 GDK_WINDOW_XID (window),
3308 gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"));
3313 gdk_x11_window_iconify (GdkWindow *window)
3315 if (GDK_WINDOW_DESTROYED (window) ||
3316 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3319 if (GDK_WINDOW_IS_MAPPED (window))
3321 XIconifyWindow (GDK_WINDOW_XDISPLAY (window),
3322 GDK_WINDOW_XID (window),
3323 gdk_screen_get_number (GDK_WINDOW_SCREEN (window)));
3327 /* Flip our client side flag, the real work happens on map. */
3328 gdk_synthesize_window_state (window,
3330 GDK_WINDOW_STATE_ICONIFIED);
3335 gdk_x11_window_deiconify (GdkWindow *window)
3337 if (GDK_WINDOW_DESTROYED (window) ||
3338 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3341 if (GDK_WINDOW_IS_MAPPED (window))
3343 gdk_window_show (window);
3347 /* Flip our client side flag, the real work happens on map. */
3348 gdk_synthesize_window_state (window,
3349 GDK_WINDOW_STATE_ICONIFIED,
3355 gdk_x11_window_stick (GdkWindow *window)
3357 if (GDK_WINDOW_DESTROYED (window) ||
3358 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3361 if (GDK_WINDOW_IS_MAPPED (window))
3363 /* "stick" means stick to all desktops _and_ do not scroll with the
3364 * viewport. i.e. glue to the monitor glass in all cases.
3367 XClientMessageEvent xclient;
3369 /* Request stick during viewport scroll */
3370 gdk_wmspec_change_state (TRUE, window,
3371 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
3374 /* Request desktop 0xFFFFFFFF */
3375 memset (&xclient, 0, sizeof (xclient));
3376 xclient.type = ClientMessage;
3377 xclient.window = GDK_WINDOW_XID (window);
3378 xclient.display = GDK_WINDOW_XDISPLAY (window);
3379 xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
3381 xclient.format = 32;
3383 xclient.data.l[0] = 0xFFFFFFFF;
3384 xclient.data.l[1] = 0;
3385 xclient.data.l[2] = 0;
3386 xclient.data.l[3] = 0;
3387 xclient.data.l[4] = 0;
3389 XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False,
3390 SubstructureRedirectMask | SubstructureNotifyMask,
3391 (XEvent *)&xclient);
3395 /* Flip our client side flag, the real work happens on map. */
3396 gdk_synthesize_window_state (window,
3398 GDK_WINDOW_STATE_STICKY);
3403 gdk_x11_window_unstick (GdkWindow *window)
3405 if (GDK_WINDOW_DESTROYED (window) ||
3406 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3409 if (GDK_WINDOW_IS_MAPPED (window))
3411 /* Request unstick from viewport */
3412 gdk_wmspec_change_state (FALSE, window,
3413 gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"),
3416 move_to_current_desktop (window);
3420 /* Flip our client side flag, the real work happens on map. */
3421 gdk_synthesize_window_state (window,
3422 GDK_WINDOW_STATE_STICKY,
3429 gdk_x11_window_maximize (GdkWindow *window)
3431 if (GDK_WINDOW_DESTROYED (window) ||
3432 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3435 if (GDK_WINDOW_IS_MAPPED (window))
3436 gdk_wmspec_change_state (TRUE, window,
3437 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
3438 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
3440 gdk_synthesize_window_state (window,
3442 GDK_WINDOW_STATE_MAXIMIZED);
3446 gdk_x11_window_unmaximize (GdkWindow *window)
3448 if (GDK_WINDOW_DESTROYED (window) ||
3449 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3452 if (GDK_WINDOW_IS_MAPPED (window))
3453 gdk_wmspec_change_state (FALSE, window,
3454 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"),
3455 gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ"));
3457 gdk_synthesize_window_state (window,
3458 GDK_WINDOW_STATE_MAXIMIZED,
3463 gdk_x11_window_fullscreen (GdkWindow *window)
3465 if (GDK_WINDOW_DESTROYED (window) ||
3466 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3469 if (GDK_WINDOW_IS_MAPPED (window))
3470 gdk_wmspec_change_state (TRUE, window,
3471 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
3475 gdk_synthesize_window_state (window,
3477 GDK_WINDOW_STATE_FULLSCREEN);
3481 gdk_x11_window_unfullscreen (GdkWindow *window)
3483 if (GDK_WINDOW_DESTROYED (window) ||
3484 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3487 if (GDK_WINDOW_IS_MAPPED (window))
3488 gdk_wmspec_change_state (FALSE, window,
3489 gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"),
3493 gdk_synthesize_window_state (window,
3494 GDK_WINDOW_STATE_FULLSCREEN,
3499 gdk_x11_window_set_keep_above (GdkWindow *window,
3502 g_return_if_fail (GDK_IS_WINDOW (window));
3504 if (GDK_WINDOW_DESTROYED (window) ||
3505 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3508 if (GDK_WINDOW_IS_MAPPED (window))
3511 gdk_wmspec_change_state (FALSE, window,
3512 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
3514 gdk_wmspec_change_state (setting, window,
3515 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
3519 gdk_synthesize_window_state (window,
3520 setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE,
3521 setting ? GDK_WINDOW_STATE_ABOVE : 0);
3525 gdk_x11_window_set_keep_below (GdkWindow *window, gboolean setting)
3527 g_return_if_fail (GDK_IS_WINDOW (window));
3529 if (GDK_WINDOW_DESTROYED (window) ||
3530 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3533 if (GDK_WINDOW_IS_MAPPED (window))
3536 gdk_wmspec_change_state (FALSE, window,
3537 gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"),
3539 gdk_wmspec_change_state (setting, window,
3540 gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
3544 gdk_synthesize_window_state (window,
3545 setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW,
3546 setting ? GDK_WINDOW_STATE_BELOW : 0);
3550 gdk_x11_window_get_group (GdkWindow *window)
3552 GdkToplevelX11 *toplevel;
3554 if (GDK_WINDOW_DESTROYED (window) ||
3555 !WINDOW_IS_TOPLEVEL (window))
3558 toplevel = _gdk_x11_window_get_toplevel (window);
3560 return toplevel->group_leader;
3564 gdk_x11_window_set_group (GdkWindow *window,
3567 GdkToplevelX11 *toplevel;
3569 g_return_if_fail (GDK_IS_WINDOW (window));
3570 g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
3571 g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
3573 if (GDK_WINDOW_DESTROYED (window) ||
3574 (leader != NULL && GDK_WINDOW_DESTROYED (leader)) ||
3575 !WINDOW_IS_TOPLEVEL (window))
3578 toplevel = _gdk_x11_window_get_toplevel (window);
3581 leader = gdk_display_get_default_group (gdk_window_get_display (window));
3583 if (toplevel->group_leader != leader)
3585 if (toplevel->group_leader)
3586 g_object_unref (toplevel->group_leader);
3587 toplevel->group_leader = g_object_ref (leader);
3588 (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;
3591 update_wm_hints (window, FALSE);
3594 static MotifWmHints *
3595 gdk_window_get_mwm_hints (GdkWindow *window)
3597 GdkDisplay *display;
3598 Atom hints_atom = None;
3605 if (GDK_WINDOW_DESTROYED (window))
3608 display = gdk_window_get_display (window);
3610 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3612 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
3613 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3614 False, AnyPropertyType, &type, &format, &nitems,
3615 &bytes_after, &data);
3620 return (MotifWmHints *)data;
3624 gdk_window_set_mwm_hints (GdkWindow *window,
3625 MotifWmHints *new_hints)
3627 GdkDisplay *display;
3628 Atom hints_atom = None;
3630 MotifWmHints *hints;
3636 if (GDK_WINDOW_DESTROYED (window))
3639 display = gdk_window_get_display (window);
3641 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
3643 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3644 hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
3645 False, AnyPropertyType, &type, &format, &nitems,
3646 &bytes_after, &data);
3652 hints = (MotifWmHints *)data;
3654 if (new_hints->flags & MWM_HINTS_FUNCTIONS)
3656 hints->flags |= MWM_HINTS_FUNCTIONS;
3657 hints->functions = new_hints->functions;
3659 if (new_hints->flags & MWM_HINTS_DECORATIONS)
3661 hints->flags |= MWM_HINTS_DECORATIONS;
3662 hints->decorations = new_hints->decorations;
3666 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
3667 hints_atom, hints_atom, 32, PropModeReplace,
3668 (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
3670 if (hints != new_hints)
3675 gdk_x11_window_set_decorations (GdkWindow *window,
3676 GdkWMDecoration decorations)
3680 if (GDK_WINDOW_DESTROYED (window) ||
3681 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3684 /* initialize to zero to avoid writing uninitialized data to socket */
3685 memset(&hints, 0, sizeof(hints));
3686 hints.flags = MWM_HINTS_DECORATIONS;
3687 hints.decorations = decorations;
3689 gdk_window_set_mwm_hints (window, &hints);
3693 gdk_x11_window_get_decorations(GdkWindow *window,
3694 GdkWMDecoration *decorations)
3696 MotifWmHints *hints;
3697 gboolean result = FALSE;
3699 if (GDK_WINDOW_DESTROYED (window) ||
3700 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3703 hints = gdk_window_get_mwm_hints (window);
3707 if (hints->flags & MWM_HINTS_DECORATIONS)
3710 *decorations = hints->decorations;
3721 gdk_x11_window_set_functions (GdkWindow *window,
3722 GdkWMFunction functions)
3726 g_return_if_fail (GDK_IS_WINDOW (window));
3728 if (GDK_WINDOW_DESTROYED (window) ||
3729 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
3732 /* initialize to zero to avoid writing uninitialized data to socket */
3733 memset(&hints, 0, sizeof(hints));
3734 hints.flags = MWM_HINTS_FUNCTIONS;
3735 hints.functions = functions;
3737 gdk_window_set_mwm_hints (window, &hints);
3741 _gdk_x11_xwindow_get_shape (Display *xdisplay,
3745 cairo_region_t *shape;
3753 xrl = XShapeGetRectangles (xdisplay,
3755 shape_type, &rn, &ord);
3757 if (xrl == NULL || rn == 0)
3758 return cairo_region_create (); /* Empty */
3760 if (ord != YXBanded)
3762 /* This really shouldn't happen with any xserver, as they
3763 generally convert regions to YXBanded internally */
3764 g_warning ("non YXBanded shape masks not supported");
3769 rl = g_new (GdkRectangle, rn);
3770 for (i = 0; i < rn; i++)
3774 rl[i].width = xrl[i].width;
3775 rl[i].height = xrl[i].height;
3779 shape = cairo_region_create_rectangles (rl, rn);
3786 static cairo_region_t *
3787 gdk_x11_window_get_shape (GdkWindow *window)
3789 if (!GDK_WINDOW_DESTROYED (window) &&
3790 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
3791 return _gdk_x11_xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
3792 GDK_WINDOW_XID (window),
3798 static cairo_region_t *
3799 gdk_x11_window_get_input_shape (GdkWindow *window)
3801 #if defined(ShapeInput)
3802 if (!GDK_WINDOW_DESTROYED (window) &&
3803 gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)))
3804 return _gdk_x11_xwindow_get_shape (GDK_WINDOW_XDISPLAY (window),
3805 GDK_WINDOW_XID (window),
3813 gdk_window_set_static_bit_gravity (GdkWindow *window,
3816 XSetWindowAttributes xattributes;
3817 guint xattributes_mask = 0;
3819 g_return_if_fail (GDK_IS_WINDOW (window));
3821 if (window->input_only)
3824 xattributes.bit_gravity = StaticGravity;
3825 xattributes_mask |= CWBitGravity;
3826 xattributes.bit_gravity = on ? StaticGravity : ForgetGravity;
3827 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3828 GDK_WINDOW_XID (window),
3829 CWBitGravity, &xattributes);
3833 gdk_window_set_static_win_gravity (GdkWindow *window,
3836 XSetWindowAttributes xattributes;
3838 g_return_if_fail (GDK_IS_WINDOW (window));
3840 xattributes.win_gravity = on ? StaticGravity : NorthWestGravity;
3842 XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window),
3843 GDK_WINDOW_XID (window),
3844 CWWinGravity, &xattributes);
3848 gdk_window_x11_set_static_gravities (GdkWindow *window,
3849 gboolean use_static)
3853 if (!use_static == !window->guffaw_gravity)
3856 window->guffaw_gravity = use_static;
3858 if (!GDK_WINDOW_DESTROYED (window))
3860 gdk_window_set_static_bit_gravity (window, use_static);
3862 tmp_list = window->children;
3865 gdk_window_set_static_win_gravity (tmp_list->data, use_static);
3867 tmp_list = tmp_list->next;
3875 wmspec_moveresize (GdkWindow *window,
3881 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
3883 XClientMessageEvent xclient;
3885 /* Release passive grab */
3886 gdk_display_pointer_ungrab (display, timestamp);
3888 memset (&xclient, 0, sizeof (xclient));
3889 xclient.type = ClientMessage;
3890 xclient.window = GDK_WINDOW_XID (window);
3891 xclient.message_type =
3892 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE");
3893 xclient.format = 32;
3894 xclient.data.l[0] = root_x;
3895 xclient.data.l[1] = root_y;
3896 xclient.data.l[2] = direction;
3897 xclient.data.l[3] = 0;
3898 xclient.data.l[4] = 0;
3900 XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False,
3901 SubstructureRedirectMask | SubstructureNotifyMask,
3902 (XEvent *)&xclient);
3905 typedef struct _MoveResizeData MoveResizeData;
3907 struct _MoveResizeData
3909 GdkDisplay *display;
3911 GdkWindow *moveresize_window;
3912 GdkWindow *moveresize_emulation_window;
3914 GdkWindowEdge resize_edge;
3915 gint moveresize_button;
3918 gint moveresize_orig_x;
3919 gint moveresize_orig_y;
3920 gint moveresize_orig_width;
3921 gint moveresize_orig_height;
3922 GdkWindowHints moveresize_geom_mask;
3923 GdkGeometry moveresize_geometry;
3924 Time moveresize_process_time;
3925 XEvent *moveresize_pending_event;
3928 /* From the WM spec */
3929 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
3930 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
3931 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
3932 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
3933 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
3934 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
3935 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
3936 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
3937 #define _NET_WM_MOVERESIZE_MOVE 8
3940 wmspec_resize_drag (GdkWindow *window,
3949 /* Let the compiler turn a switch into a table, instead
3950 * of doing the table manually, this way is easier to verify.
3954 case GDK_WINDOW_EDGE_NORTH_WEST:
3955 direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT;
3958 case GDK_WINDOW_EDGE_NORTH:
3959 direction = _NET_WM_MOVERESIZE_SIZE_TOP;
3962 case GDK_WINDOW_EDGE_NORTH_EAST:
3963 direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT;
3966 case GDK_WINDOW_EDGE_WEST:
3967 direction = _NET_WM_MOVERESIZE_SIZE_LEFT;
3970 case GDK_WINDOW_EDGE_EAST:
3971 direction = _NET_WM_MOVERESIZE_SIZE_RIGHT;
3974 case GDK_WINDOW_EDGE_SOUTH_WEST:
3975 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT;
3978 case GDK_WINDOW_EDGE_SOUTH:
3979 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM;
3982 case GDK_WINDOW_EDGE_SOUTH_EAST:
3983 direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
3987 g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
3992 wmspec_moveresize (window, direction, root_x, root_y, timestamp);
3995 static MoveResizeData *
3996 get_move_resize_data (GdkDisplay *display,
3999 MoveResizeData *mv_resize;
4000 static GQuark move_resize_quark = 0;
4002 if (!move_resize_quark)
4003 move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize");
4005 mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark);
4007 if (!mv_resize && create)
4009 mv_resize = g_new0 (MoveResizeData, 1);
4010 mv_resize->display = display;
4012 g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize);
4019 update_pos (MoveResizeData *mv_resize,
4025 dx = new_root_x - mv_resize->moveresize_x;
4026 dy = new_root_y - mv_resize->moveresize_y;
4028 if (mv_resize->is_resize)
4032 x = mv_resize->moveresize_orig_x;
4033 y = mv_resize->moveresize_orig_y;
4035 w = mv_resize->moveresize_orig_width;
4036 h = mv_resize->moveresize_orig_height;
4038 switch (mv_resize->resize_edge)
4040 case GDK_WINDOW_EDGE_NORTH_WEST:
4046 case GDK_WINDOW_EDGE_NORTH:
4050 case GDK_WINDOW_EDGE_NORTH_EAST:
4055 case GDK_WINDOW_EDGE_SOUTH_WEST:
4060 case GDK_WINDOW_EDGE_SOUTH_EAST:
4064 case GDK_WINDOW_EDGE_SOUTH:
4067 case GDK_WINDOW_EDGE_EAST:
4070 case GDK_WINDOW_EDGE_WEST:
4081 if (mv_resize->moveresize_geom_mask)
4083 gdk_window_constrain_size (&mv_resize->moveresize_geometry,
4084 mv_resize->moveresize_geom_mask,
4088 gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h);
4094 x = mv_resize->moveresize_orig_x + dx;
4095 y = mv_resize->moveresize_orig_y + dy;
4097 gdk_window_move (mv_resize->moveresize_window, x, y);
4102 finish_drag (MoveResizeData *mv_resize)
4104 gdk_window_destroy (mv_resize->moveresize_emulation_window);
4105 mv_resize->moveresize_emulation_window = NULL;
4106 g_object_unref (mv_resize->moveresize_window);
4107 mv_resize->moveresize_window = NULL;
4109 if (mv_resize->moveresize_pending_event)
4111 g_free (mv_resize->moveresize_pending_event);
4112 mv_resize->moveresize_pending_event = NULL;
4117 lookahead_motion_predicate (Display *xdisplay,
4121 gboolean *seen_release = (gboolean *)arg;
4122 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
4123 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4128 switch (event->xany.type)
4131 *seen_release = TRUE;
4134 mv_resize->moveresize_process_time = event->xmotion.time;
4144 moveresize_lookahead (MoveResizeData *mv_resize,
4148 gboolean seen_release = FALSE;
4150 if (mv_resize->moveresize_process_time)
4152 if (event->xmotion.time == mv_resize->moveresize_process_time)
4154 mv_resize->moveresize_process_time = 0;
4161 XCheckIfEvent (event->xany.display, &tmp_event,
4162 lookahead_motion_predicate, (XPointer) & seen_release);
4164 return mv_resize->moveresize_process_time == 0;
4168 _gdk_moveresize_handle_event (XEvent *event)
4170 guint button_mask = 0;
4171 GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display);
4172 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4174 if (!mv_resize || !mv_resize->moveresize_window)
4177 button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1);
4179 switch (event->xany.type)
4182 if (mv_resize->moveresize_window->resize_count > 0)
4184 if (mv_resize->moveresize_pending_event)
4185 *mv_resize->moveresize_pending_event = *event;
4187 mv_resize->moveresize_pending_event =
4188 g_memdup (event, sizeof (XEvent));
4192 if (!moveresize_lookahead (mv_resize, event))
4195 update_pos (mv_resize,
4196 event->xmotion.x_root,
4197 event->xmotion.y_root);
4199 /* This should never be triggered in normal cases, but in the
4200 * case where the drag started without an implicit grab being
4201 * in effect, we could miss the release if it occurs before
4202 * we grab the pointer; this ensures that we will never
4203 * get a permanently stuck grab.
4205 if ((event->xmotion.state & button_mask) == 0)
4206 finish_drag (mv_resize);
4210 update_pos (mv_resize,
4211 event->xbutton.x_root,
4212 event->xbutton.y_root);
4214 if (event->xbutton.button == mv_resize->moveresize_button)
4215 finish_drag (mv_resize);
4222 _gdk_moveresize_configure_done (GdkDisplay *display,
4226 MoveResizeData *mv_resize = get_move_resize_data (display, FALSE);
4228 if (!mv_resize || window != mv_resize->moveresize_window)
4231 if (mv_resize->moveresize_pending_event)
4233 tmp_event = mv_resize->moveresize_pending_event;
4234 mv_resize->moveresize_pending_event = NULL;
4235 _gdk_moveresize_handle_event (tmp_event);
4243 create_moveresize_window (MoveResizeData *mv_resize,
4246 GdkWindowAttr attributes;
4247 gint attributes_mask;
4248 GdkGrabStatus status;
4250 g_assert (mv_resize->moveresize_emulation_window == NULL);
4252 attributes.x = -100;
4253 attributes.y = -100;
4254 attributes.width = 10;
4255 attributes.height = 10;
4256 attributes.window_type = GDK_WINDOW_TEMP;
4257 attributes.wclass = GDK_INPUT_ONLY;
4258 attributes.override_redirect = TRUE;
4259 attributes.event_mask = 0;
4261 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
4263 mv_resize->moveresize_emulation_window =
4264 gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)),
4268 gdk_window_show (mv_resize->moveresize_emulation_window);
4270 status = gdk_pointer_grab (mv_resize->moveresize_emulation_window,
4272 GDK_BUTTON_RELEASE_MASK |
4273 GDK_POINTER_MOTION_MASK,
4278 if (status != GDK_GRAB_SUCCESS)
4280 /* If this fails, some other client has grabbed the window
4283 finish_drag (mv_resize);
4286 mv_resize->moveresize_process_time = 0;
4290 Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y
4291 so that calling XMoveWindow with these coordinates will not move the
4293 Note that this depends on the WM to implement ICCCM-compliant reference
4297 calculate_unmoving_origin (MoveResizeData *mv_resize)
4302 if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY &&
4303 mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC)
4305 gdk_window_get_origin (mv_resize->moveresize_window,
4306 &mv_resize->moveresize_orig_x,
4307 &mv_resize->moveresize_orig_y);
4311 gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect);
4312 gdk_window_get_geometry (mv_resize->moveresize_window,
4313 NULL, NULL, &width, &height);
4315 switch (mv_resize->moveresize_geometry.win_gravity)
4317 case GDK_GRAVITY_NORTH_WEST:
4318 mv_resize->moveresize_orig_x = rect.x;
4319 mv_resize->moveresize_orig_y = rect.y;
4321 case GDK_GRAVITY_NORTH:
4322 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4323 mv_resize->moveresize_orig_y = rect.y;
4325 case GDK_GRAVITY_NORTH_EAST:
4326 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4327 mv_resize->moveresize_orig_y = rect.y;
4329 case GDK_GRAVITY_WEST:
4330 mv_resize->moveresize_orig_x = rect.x;
4331 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4333 case GDK_GRAVITY_CENTER:
4334 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4335 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4337 case GDK_GRAVITY_EAST:
4338 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4339 mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2;
4341 case GDK_GRAVITY_SOUTH_WEST:
4342 mv_resize->moveresize_orig_x = rect.x;
4343 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
4345 case GDK_GRAVITY_SOUTH:
4346 mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2;
4347 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
4349 case GDK_GRAVITY_SOUTH_EAST:
4350 mv_resize->moveresize_orig_x = rect.x + rect.width - width;
4351 mv_resize->moveresize_orig_y = rect.y + rect.height - height;
4354 mv_resize->moveresize_orig_x = rect.x;
4355 mv_resize->moveresize_orig_y = rect.y;
4362 emulate_resize_drag (GdkWindow *window,
4369 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4371 mv_resize->is_resize = TRUE;
4372 mv_resize->moveresize_button = button;
4373 mv_resize->resize_edge = edge;
4374 mv_resize->moveresize_x = root_x;
4375 mv_resize->moveresize_y = root_y;
4376 mv_resize->moveresize_window = g_object_ref (window);
4378 mv_resize->moveresize_orig_width = gdk_window_get_width (window);
4379 mv_resize->moveresize_orig_height = gdk_window_get_height (window);
4381 mv_resize->moveresize_geom_mask = 0;
4382 gdk_window_get_geometry_hints (window,
4383 &mv_resize->moveresize_geometry,
4384 &mv_resize->moveresize_geom_mask);
4386 calculate_unmoving_origin (mv_resize);
4388 create_moveresize_window (mv_resize, timestamp);
4392 emulate_move_drag (GdkWindow *window,
4398 MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE);
4400 mv_resize->is_resize = FALSE;
4401 mv_resize->moveresize_button = button;
4402 mv_resize->moveresize_x = root_x;
4403 mv_resize->moveresize_y = root_y;
4405 mv_resize->moveresize_window = g_object_ref (window);
4407 calculate_unmoving_origin (mv_resize);
4409 create_moveresize_window (mv_resize, timestamp);
4413 gdk_x11_window_begin_resize_drag (GdkWindow *window,
4420 if (GDK_WINDOW_DESTROYED (window) ||
4421 !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
4424 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4425 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
4426 wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp);
4428 emulate_resize_drag (window, edge, button, root_x, root_y, timestamp);
4432 gdk_x11_window_begin_move_drag (GdkWindow *window,
4438 if (GDK_WINDOW_DESTROYED (window) ||
4439 !WINDOW_IS_TOPLEVEL (window))
4442 if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
4443 gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE")))
4444 wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y,
4447 emulate_move_drag (window, button, root_x, root_y, timestamp);
4451 gdk_x11_window_enable_synchronized_configure (GdkWindow *window)
4453 GdkWindowImplX11 *impl;
4455 if (!GDK_IS_WINDOW_IMPL_X11 (window->impl))
4458 impl = GDK_WINDOW_IMPL_X11 (window->impl);
4460 if (!impl->use_synchronized_configure)
4462 /* This basically means you want to do fancy X specific stuff, so
4463 ensure we have a native window */
4464 gdk_window_ensure_native (window);
4466 impl->use_synchronized_configure = TRUE;
4467 ensure_sync_counter (window);
4472 gdk_x11_window_configure_finished (GdkWindow *window)
4474 GdkWindowImplX11 *impl;
4476 if (!WINDOW_IS_TOPLEVEL (window))
4479 impl = GDK_WINDOW_IMPL_X11 (window->impl);
4480 if (!impl->use_synchronized_configure)
4484 if (!GDK_WINDOW_DESTROYED (window))
4486 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
4487 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
4489 if (toplevel && toplevel->update_counter != None &&
4490 GDK_DISPLAY_X11 (display)->use_sync &&
4491 !XSyncValueIsZero (toplevel->current_counter_value))
4493 XSyncSetCounter (GDK_WINDOW_XDISPLAY (window),
4494 toplevel->update_counter,
4495 toplevel->current_counter_value);
4497 XSyncIntToValue (&toplevel->current_counter_value, 0);
4504 gdk_x11_window_beep (GdkWindow *window)
4506 GdkDisplay *display;
4508 display = GDK_WINDOW_DISPLAY (window);
4511 if (GDK_DISPLAY_X11 (display)->use_xkb)
4513 XkbBell (GDK_DISPLAY_XDISPLAY (display),
4514 GDK_WINDOW_XID (window),
4525 gdk_x11_window_set_opacity (GdkWindow *window,
4528 GdkDisplay *display;
4531 g_return_if_fail (GDK_IS_WINDOW (window));
4533 if (GDK_WINDOW_DESTROYED (window) ||
4534 !WINDOW_IS_TOPLEVEL (window))
4537 display = gdk_window_get_display (window);
4541 else if (opacity > 1)
4544 cardinal = opacity * 0xffffffff;
4546 if (cardinal == 0xffffffff)
4547 XDeleteProperty (GDK_DISPLAY_XDISPLAY (display),
4548 GDK_WINDOW_XID (window),
4549 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"));
4551 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
4552 GDK_WINDOW_XID (window),
4553 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"),
4556 (guchar *) &cardinal, 1);
4560 gdk_x11_window_set_composited (GdkWindow *window,
4561 gboolean composited)
4563 #if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES)
4564 GdkWindowImplX11 *impl;
4565 GdkDisplay *display;
4569 impl = GDK_WINDOW_IMPL_X11 (window->impl);
4571 display = gdk_window_get_display (window);
4572 dpy = GDK_DISPLAY_XDISPLAY (display);
4573 xid = GDK_WINDOW_XID (window);
4577 XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual);
4578 impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox);
4582 XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual);
4583 XDamageDestroy (dpy, impl->damage);
4584 impl->damage = None;
4590 gdk_x11_window_process_updates_recurse (GdkWindow *window,
4591 cairo_region_t *region)
4593 _gdk_window_process_updates_recurse (window, region);
4597 _gdk_x11_display_before_process_all_updates (GdkDisplay *display)
4602 _gdk_x11_display_after_process_all_updates (GdkDisplay *display)
4607 timestamp_predicate (Display *display,
4611 Window xwindow = GPOINTER_TO_UINT (arg);
4612 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
4614 if (xevent->type == PropertyNotify &&
4615 xevent->xproperty.window == xwindow &&
4616 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
4617 "GDK_TIMESTAMP_PROP"))
4624 * gdk_x11_get_server_time:
4625 * @window: a #GdkWindow, used for communication with the server.
4626 * The window must have GDK_PROPERTY_CHANGE_MASK in its
4627 * events mask or a hang will result.
4629 * Routine to get the current X server time stamp.
4631 * Return value: the time stamp.
4634 gdk_x11_get_server_time (GdkWindow *window)
4640 Atom timestamp_prop_atom;
4642 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
4643 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
4645 xdisplay = GDK_WINDOW_XDISPLAY (window);
4646 xwindow = GDK_WINDOW_XID (window);
4647 timestamp_prop_atom =
4648 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
4649 "GDK_TIMESTAMP_PROP");
4651 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
4652 timestamp_prop_atom,
4653 8, PropModeReplace, &c, 1);
4655 XIfEvent (xdisplay, &xevent,
4656 timestamp_predicate, GUINT_TO_POINTER(xwindow));
4658 return xevent.xproperty.time;
4662 * gdk_x11_window_get_xid:
4663 * @window: a native #GdkWindow.
4665 * Returns the X resource (window) belonging to a #GdkWindow.
4667 * Return value: the ID of @drawable's X resource.
4670 gdk_x11_window_get_xid (GdkWindow *window)
4672 /* Try to ensure the window has a native window */
4673 if (!_gdk_window_has_impl (window))
4675 gdk_window_ensure_native (window);
4677 /* We sync here to ensure the window is created in the Xserver when
4678 * this function returns. This is required because the returned XID
4679 * for this window must be valid immediately, even with another
4680 * connection to the Xserver */
4681 gdk_display_sync (gdk_window_get_display (window));
4684 if (!GDK_WINDOW_IS_X11 (window))
4686 g_warning (G_STRLOC " drawable is not a native X11 window");
4690 return GDK_WINDOW_IMPL_X11 (window->impl)->xid;
4693 extern GdkDragContext * _gdk_x11_window_drag_begin (GdkWindow *window,
4698 gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
4700 GObjectClass *object_class = G_OBJECT_CLASS (klass);
4701 GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass);
4703 object_class->finalize = gdk_window_impl_x11_finalize;
4705 impl_class->ref_cairo_surface = gdk_x11_ref_cairo_surface;
4706 impl_class->show = gdk_window_x11_show;
4707 impl_class->hide = gdk_window_x11_hide;
4708 impl_class->withdraw = gdk_window_x11_withdraw;
4709 impl_class->set_events = gdk_window_x11_set_events;
4710 impl_class->get_events = gdk_window_x11_get_events;
4711 impl_class->raise = gdk_window_x11_raise;
4712 impl_class->lower = gdk_window_x11_lower;
4713 impl_class->restack_under = gdk_window_x11_restack_under;
4714 impl_class->restack_toplevel = gdk_window_x11_restack_toplevel;
4715 impl_class->move_resize = gdk_window_x11_move_resize;
4716 impl_class->set_background = gdk_window_x11_set_background;
4717 impl_class->reparent = gdk_window_x11_reparent;
4718 impl_class->set_device_cursor = gdk_window_x11_set_device_cursor;
4719 impl_class->get_geometry = gdk_window_x11_get_geometry;
4720 impl_class->get_root_coords = gdk_window_x11_get_root_coords;
4721 impl_class->get_device_state = gdk_window_x11_get_device_state;
4722 impl_class->shape_combine_region = gdk_window_x11_shape_combine_region;
4723 impl_class->input_shape_combine_region = gdk_window_x11_input_shape_combine_region;
4724 impl_class->set_static_gravities = gdk_window_x11_set_static_gravities;
4725 impl_class->queue_antiexpose = _gdk_x11_window_queue_antiexpose;
4726 impl_class->translate = _gdk_x11_window_translate;
4727 impl_class->destroy = gdk_x11_window_destroy;
4728 impl_class->destroy_foreign = gdk_x11_window_destroy_foreign;
4729 impl_class->resize_cairo_surface = gdk_window_x11_resize_cairo_surface;
4730 impl_class->get_shape = gdk_x11_window_get_shape;
4731 impl_class->get_input_shape = gdk_x11_window_get_input_shape;
4732 impl_class->beep = gdk_x11_window_beep;
4734 impl_class->focus = gdk_x11_window_focus;
4735 impl_class->set_type_hint = gdk_x11_window_set_type_hint;
4736 impl_class->get_type_hint = gdk_x11_window_get_type_hint;
4737 impl_class->set_modal_hint = gdk_x11_window_set_modal_hint;
4738 impl_class->set_skip_taskbar_hint = gdk_x11_window_set_skip_taskbar_hint;
4739 impl_class->set_skip_pager_hint = gdk_x11_window_set_skip_pager_hint;
4740 impl_class->set_urgency_hint = gdk_x11_window_set_urgency_hint;
4741 impl_class->set_geometry_hints = gdk_x11_window_set_geometry_hints;
4742 impl_class->set_title = gdk_x11_window_set_title;
4743 impl_class->set_role = gdk_x11_window_set_role;
4744 impl_class->set_startup_id = gdk_x11_window_set_startup_id;
4745 impl_class->set_transient_for = gdk_x11_window_set_transient_for;
4746 impl_class->get_root_origin = gdk_x11_window_get_root_origin;
4747 impl_class->get_frame_extents = gdk_x11_window_get_frame_extents;
4748 impl_class->set_override_redirect = gdk_x11_window_set_override_redirect;
4749 impl_class->set_accept_focus = gdk_x11_window_set_accept_focus;
4750 impl_class->set_focus_on_map = gdk_x11_window_set_focus_on_map;
4751 impl_class->set_icon_list = gdk_x11_window_set_icon_list;
4752 impl_class->set_icon_name = gdk_x11_window_set_icon_name;
4753 impl_class->iconify = gdk_x11_window_iconify;
4754 impl_class->deiconify = gdk_x11_window_deiconify;
4755 impl_class->stick = gdk_x11_window_stick;
4756 impl_class->unstick = gdk_x11_window_unstick;
4757 impl_class->maximize = gdk_x11_window_maximize;
4758 impl_class->unmaximize = gdk_x11_window_unmaximize;
4759 impl_class->fullscreen = gdk_x11_window_fullscreen;
4760 impl_class->unfullscreen = gdk_x11_window_unfullscreen;
4761 impl_class->set_keep_above = gdk_x11_window_set_keep_above;
4762 impl_class->set_keep_below = gdk_x11_window_set_keep_below;
4763 impl_class->get_group = gdk_x11_window_get_group;
4764 impl_class->set_group = gdk_x11_window_set_group;
4765 impl_class->set_decorations = gdk_x11_window_set_decorations;
4766 impl_class->get_decorations = gdk_x11_window_get_decorations;
4767 impl_class->set_functions = gdk_x11_window_set_functions;
4768 impl_class->set_functions = gdk_x11_window_set_functions;
4769 impl_class->begin_resize_drag = gdk_x11_window_begin_resize_drag;
4770 impl_class->begin_move_drag = gdk_x11_window_begin_move_drag;
4771 impl_class->enable_synchronized_configure = gdk_x11_window_enable_synchronized_configure;
4772 impl_class->configure_finished = gdk_x11_window_configure_finished;
4773 impl_class->set_opacity = gdk_x11_window_set_opacity;
4774 impl_class->set_composited = gdk_x11_window_set_composited;
4775 impl_class->destroy_notify = gdk_x11_window_destroy_notify;
4776 impl_class->register_dnd = _gdk_x11_window_register_dnd;
4777 impl_class->drag_begin = _gdk_x11_window_drag_begin;
4778 impl_class->process_updates_recurse = gdk_x11_window_process_updates_recurse;