| 1 |
/* GDK - The GIMP Drawing Kit |
| 2 |
* Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball, |
| 3 |
* Josh MacDonald, Ryan Lortie |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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. |
| 19 |
*/ |
| 20 |
|
| 21 |
/* |
| 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/. |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "config.h" |
| 29 |
|
| 30 |
#include <X11/Xlib.h> |
| 31 |
#include <X11/Xutil.h> |
| 32 |
#include <X11/Xatom.h> |
| 33 |
|
| 34 |
#ifdef HAVE_XKB |
| 35 |
#include <X11/XKBlib.h> |
| 36 |
#endif |
| 37 |
|
| 38 |
#include <netinet/in.h> |
| 39 |
#include <unistd.h> |
| 40 |
|
| 41 |
#include "gdk.h" |
| 42 |
|
| 43 |
#include "gdkwindow.h" |
| 44 |
#include "gdkwindowimpl.h" |
| 45 |
#include "gdkasync.h" |
| 46 |
#include "gdkinputprivate.h" |
| 47 |
#include "gdkdisplay-x11.h" |
| 48 |
#include "gdkprivate-x11.h" |
| 49 |
#include "gdkregion.h" |
| 50 |
#include "gdkinternals.h" |
| 51 |
#include "MwmUtil.h" |
| 52 |
#include "gdkwindow-x11.h" |
| 53 |
#include "gdkalias.h" |
| 54 |
|
| 55 |
#include <stdlib.h> |
| 56 |
#include <stdio.h> |
| 57 |
#include <string.h> |
| 58 |
|
| 59 |
|
| 60 |
#include <X11/extensions/shape.h> |
| 61 |
|
| 62 |
#ifdef HAVE_XCOMPOSITE |
| 63 |
#include <X11/extensions/Xcomposite.h> |
| 64 |
#endif |
| 65 |
|
| 66 |
#ifdef HAVE_XFIXES |
| 67 |
#include <X11/extensions/Xfixes.h> |
| 68 |
#endif |
| 69 |
|
| 70 |
#ifdef HAVE_XDAMAGE |
| 71 |
#include <X11/extensions/Xdamage.h> |
| 72 |
#endif |
| 73 |
|
| 74 |
const int _gdk_event_mask_table[21] = |
| 75 |
{ |
| 76 |
ExposureMask, |
| 77 |
PointerMotionMask, |
| 78 |
PointerMotionHintMask, |
| 79 |
ButtonMotionMask, |
| 80 |
Button1MotionMask, |
| 81 |
Button2MotionMask, |
| 82 |
Button3MotionMask, |
| 83 |
ButtonPressMask, |
| 84 |
ButtonReleaseMask, |
| 85 |
KeyPressMask, |
| 86 |
KeyReleaseMask, |
| 87 |
EnterWindowMask, |
| 88 |
LeaveWindowMask, |
| 89 |
FocusChangeMask, |
| 90 |
StructureNotifyMask, |
| 91 |
PropertyChangeMask, |
| 92 |
VisibilityChangeMask, |
| 93 |
0, /* PROXIMITY_IN */ |
| 94 |
0, /* PROXIMTY_OUT */ |
| 95 |
SubstructureNotifyMask, |
| 96 |
ButtonPressMask /* SCROLL; on X mouse wheel events is treated as mouse button 4/5 */ |
| 97 |
}; |
| 98 |
const int _gdk_nenvent_masks = sizeof (_gdk_event_mask_table) / sizeof (int); |
| 99 |
|
| 100 |
/* Forward declarations */ |
| 101 |
static void gdk_window_set_static_win_gravity (GdkWindow *window, |
| 102 |
gboolean on); |
| 103 |
static gboolean gdk_window_icon_name_set (GdkWindow *window); |
| 104 |
static void gdk_window_add_colormap_windows (GdkWindow *window); |
| 105 |
static void set_wm_name (GdkDisplay *display, |
| 106 |
Window xwindow, |
| 107 |
const gchar *name); |
| 108 |
static void move_to_current_desktop (GdkWindow *window); |
| 109 |
|
| 110 |
static GdkColormap* gdk_window_impl_x11_get_colormap (GdkDrawable *drawable); |
| 111 |
static void gdk_window_impl_x11_set_colormap (GdkDrawable *drawable, |
| 112 |
GdkColormap *cmap); |
| 113 |
static void gdk_window_impl_x11_finalize (GObject *object); |
| 114 |
static void gdk_window_impl_iface_init (GdkWindowImplIface *iface); |
| 115 |
|
| 116 |
#define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \ |
| 117 |
(GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \ |
| 118 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN) |
| 119 |
|
| 120 |
#define WINDOW_IS_TOPLEVEL(window) \ |
| 121 |
(GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \ |
| 122 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \ |
| 123 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN) |
| 124 |
|
| 125 |
/* Return whether time1 is considered later than time2 as far as xserver |
| 126 |
* time is concerned. Accounts for wraparound. |
| 127 |
*/ |
| 128 |
#define XSERVER_TIME_IS_LATER(time1, time2) \ |
| 129 |
( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \ |
| 130 |
(( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \ |
| 131 |
) |
| 132 |
|
| 133 |
G_DEFINE_TYPE_WITH_CODE (GdkWindowImplX11, |
| 134 |
gdk_window_impl_x11, |
| 135 |
GDK_TYPE_DRAWABLE_IMPL_X11, |
| 136 |
G_IMPLEMENT_INTERFACE (GDK_TYPE_WINDOW_IMPL, |
| 137 |
gdk_window_impl_iface_init)); |
| 138 |
|
| 139 |
GType |
| 140 |
_gdk_window_impl_get_type (void) |
| 141 |
{ |
| 142 |
return gdk_window_impl_x11_get_type (); |
| 143 |
} |
| 144 |
|
| 145 |
static void |
| 146 |
gdk_window_impl_x11_init (GdkWindowImplX11 *impl) |
| 147 |
{ |
| 148 |
impl->toplevel_window_type = -1; |
| 149 |
} |
| 150 |
|
| 151 |
GdkToplevelX11 * |
| 152 |
_gdk_x11_window_get_toplevel (GdkWindow *window) |
| 153 |
{ |
| 154 |
GdkWindowObject *private; |
| 155 |
GdkWindowImplX11 *impl; |
| 156 |
|
| 157 |
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); |
| 158 |
|
| 159 |
if (!WINDOW_IS_TOPLEVEL (window)) |
| 160 |
return NULL; |
| 161 |
|
| 162 |
private = (GdkWindowObject *)window; |
| 163 |
impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 164 |
|
| 165 |
if (!impl->toplevel) |
| 166 |
impl->toplevel = g_new0 (GdkToplevelX11, 1); |
| 167 |
|
| 168 |
return impl->toplevel; |
| 169 |
} |
| 170 |
|
| 171 |
static void |
| 172 |
gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass) |
| 173 |
{ |
| 174 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 175 |
GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass); |
| 176 |
|
| 177 |
object_class->finalize = gdk_window_impl_x11_finalize; |
| 178 |
|
| 179 |
drawable_class->set_colormap = gdk_window_impl_x11_set_colormap; |
| 180 |
drawable_class->get_colormap = gdk_window_impl_x11_get_colormap; |
| 181 |
} |
| 182 |
|
| 183 |
static void |
| 184 |
gdk_window_impl_x11_finalize (GObject *object) |
| 185 |
{ |
| 186 |
GdkWindowObject *wrapper; |
| 187 |
GdkDrawableImplX11 *draw_impl; |
| 188 |
GdkWindowImplX11 *window_impl; |
| 189 |
|
| 190 |
g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (object)); |
| 191 |
|
| 192 |
draw_impl = GDK_DRAWABLE_IMPL_X11 (object); |
| 193 |
window_impl = GDK_WINDOW_IMPL_X11 (object); |
| 194 |
|
| 195 |
wrapper = (GdkWindowObject*) draw_impl->wrapper; |
| 196 |
|
| 197 |
_gdk_xgrab_check_destroy (GDK_WINDOW (wrapper)); |
| 198 |
|
| 199 |
if (!GDK_WINDOW_DESTROYED (wrapper)) |
| 200 |
{ |
| 201 |
GdkDisplay *display = GDK_WINDOW_DISPLAY (wrapper); |
| 202 |
|
| 203 |
_gdk_xid_table_remove (display, draw_impl->xid); |
| 204 |
if (window_impl->toplevel && window_impl->toplevel->focus_window) |
| 205 |
_gdk_xid_table_remove (display, window_impl->toplevel->focus_window); |
| 206 |
} |
| 207 |
|
| 208 |
g_free (window_impl->toplevel); |
| 209 |
|
| 210 |
if (window_impl->cursor) |
| 211 |
gdk_cursor_unref (window_impl->cursor); |
| 212 |
|
| 213 |
G_OBJECT_CLASS (gdk_window_impl_x11_parent_class)->finalize (object); |
| 214 |
} |
| 215 |
|
| 216 |
static void |
| 217 |
tmp_unset_bg (GdkWindow *window) |
| 218 |
{ |
| 219 |
GdkWindowImplX11 *impl; |
| 220 |
GdkWindowObject *obj; |
| 221 |
|
| 222 |
obj = (GdkWindowObject *) window; |
| 223 |
impl = GDK_WINDOW_IMPL_X11 (obj->impl); |
| 224 |
|
| 225 |
impl->no_bg = TRUE; |
| 226 |
|
| 227 |
if (obj->bg_pixmap != GDK_NO_BG) |
| 228 |
XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window), |
| 229 |
GDK_DRAWABLE_XID (window), None); |
| 230 |
} |
| 231 |
|
| 232 |
static void |
| 233 |
tmp_reset_bg (GdkWindow *window) |
| 234 |
{ |
| 235 |
GdkWindowImplX11 *impl; |
| 236 |
GdkWindowObject *obj; |
| 237 |
|
| 238 |
obj = (GdkWindowObject *) window; |
| 239 |
impl = GDK_WINDOW_IMPL_X11 (obj->impl); |
| 240 |
|
| 241 |
impl->no_bg = FALSE; |
| 242 |
|
| 243 |
if (obj->bg_pixmap == GDK_NO_BG) |
| 244 |
return; |
| 245 |
|
| 246 |
if (obj->bg_pixmap) |
| 247 |
{ |
| 248 |
Pixmap xpixmap; |
| 249 |
|
| 250 |
if (obj->bg_pixmap == GDK_PARENT_RELATIVE_BG) |
| 251 |
xpixmap = ParentRelative; |
| 252 |
else |
| 253 |
xpixmap = GDK_DRAWABLE_XID (obj->bg_pixmap); |
| 254 |
|
| 255 |
XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window), |
| 256 |
GDK_DRAWABLE_XID (window), xpixmap); |
| 257 |
} |
| 258 |
else |
| 259 |
{ |
| 260 |
XSetWindowBackground (GDK_DRAWABLE_XDISPLAY (window), |
| 261 |
GDK_DRAWABLE_XID (window), |
| 262 |
obj->bg_color.pixel); |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
/* Unsetting and resetting window backgrounds. |
| 267 |
* |
| 268 |
* In many cases it is possible to avoid flicker by unsetting the |
| 269 |
* background of windows. For example if the background of the |
| 270 |
* parent window is unset when a window is unmapped, a brief flicker |
| 271 |
* of background painting is avoided. |
| 272 |
*/ |
| 273 |
void |
| 274 |
_gdk_x11_window_tmp_unset_bg (GdkWindow *window, |
| 275 |
gboolean recurse) |
| 276 |
{ |
| 277 |
GdkWindowObject *private; |
| 278 |
|
| 279 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 280 |
|
| 281 |
private = (GdkWindowObject *)window; |
| 282 |
|
| 283 |
if (private->input_only || private->destroyed || |
| 284 |
(private->window_type != GDK_WINDOW_ROOT && |
| 285 |
!GDK_WINDOW_IS_MAPPED (window))) |
| 286 |
return; |
| 287 |
|
| 288 |
if (_gdk_window_has_impl (window) && |
| 289 |
GDK_WINDOW_IS_X11 (window) && |
| 290 |
private->window_type != GDK_WINDOW_ROOT && |
| 291 |
private->window_type != GDK_WINDOW_FOREIGN) |
| 292 |
tmp_unset_bg (window); |
| 293 |
|
| 294 |
if (recurse) |
| 295 |
{ |
| 296 |
GList *l; |
| 297 |
|
| 298 |
for (l = private->children; l != NULL; l = l->next) |
| 299 |
_gdk_x11_window_tmp_unset_bg (l->data, TRUE); |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
void |
| 304 |
_gdk_x11_window_tmp_unset_parent_bg (GdkWindow *window) |
| 305 |
{ |
| 306 |
GdkWindowObject *private; |
| 307 |
private = (GdkWindowObject*) window; |
| 308 |
|
| 309 |
if (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT) |
| 310 |
return; |
| 311 |
|
| 312 |
window = _gdk_window_get_impl_window ((GdkWindow *)private->parent); |
| 313 |
_gdk_x11_window_tmp_unset_bg (window, FALSE); |
| 314 |
} |
| 315 |
|
| 316 |
void |
| 317 |
_gdk_x11_window_tmp_reset_bg (GdkWindow *window, |
| 318 |
gboolean recurse) |
| 319 |
{ |
| 320 |
GdkWindowObject *private; |
| 321 |
|
| 322 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 323 |
|
| 324 |
private = (GdkWindowObject *)window; |
| 325 |
|
| 326 |
if (private->input_only || private->destroyed || |
| 327 |
(private->window_type != GDK_WINDOW_ROOT && |
| 328 |
!GDK_WINDOW_IS_MAPPED (window))) |
| 329 |
return; |
| 330 |
|
| 331 |
|
| 332 |
if (_gdk_window_has_impl (window) && |
| 333 |
GDK_WINDOW_IS_X11 (window) && |
| 334 |
private->window_type != GDK_WINDOW_ROOT && |
| 335 |
private->window_type != GDK_WINDOW_FOREIGN) |
| 336 |
tmp_reset_bg (window); |
| 337 |
|
| 338 |
if (recurse) |
| 339 |
{ |
| 340 |
GList *l; |
| 341 |
|
| 342 |
for (l = private->children; l != NULL; l = l->next) |
| 343 |
_gdk_x11_window_tmp_reset_bg (l->data, TRUE); |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
void |
| 348 |
_gdk_x11_window_tmp_reset_parent_bg (GdkWindow *window) |
| 349 |
{ |
| 350 |
GdkWindowObject *private; |
| 351 |
private = (GdkWindowObject*) window; |
| 352 |
|
| 353 |
if (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT) |
| 354 |
return; |
| 355 |
|
| 356 |
window = _gdk_window_get_impl_window ((GdkWindow *)private->parent); |
| 357 |
|
| 358 |
_gdk_x11_window_tmp_reset_bg (window, FALSE); |
| 359 |
} |
| 360 |
|
| 361 |
static GdkColormap* |
| 362 |
gdk_window_impl_x11_get_colormap (GdkDrawable *drawable) |
| 363 |
{ |
| 364 |
GdkDrawableImplX11 *drawable_impl; |
| 365 |
|
| 366 |
g_return_val_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable), NULL); |
| 367 |
|
| 368 |
drawable_impl = GDK_DRAWABLE_IMPL_X11 (drawable); |
| 369 |
|
| 370 |
if (!((GdkWindowObject *) drawable_impl->wrapper)->input_only && |
| 371 |
drawable_impl->colormap == NULL) |
| 372 |
{ |
| 373 |
XWindowAttributes window_attributes; |
| 374 |
GdkVisual *visual; |
| 375 |
|
| 376 |
XGetWindowAttributes (GDK_SCREEN_XDISPLAY (drawable_impl->screen), |
| 377 |
drawable_impl->xid, |
| 378 |
&window_attributes); |
| 379 |
|
| 380 |
visual = gdk_x11_screen_lookup_visual (drawable_impl->screen, |
| 381 |
window_attributes.visual->visualid); |
| 382 |
drawable_impl->colormap = gdk_x11_colormap_foreign_new (visual, |
| 383 |
window_attributes.colormap); |
| 384 |
} |
| 385 |
|
| 386 |
return drawable_impl->colormap; |
| 387 |
} |
| 388 |
|
| 389 |
static void |
| 390 |
gdk_window_impl_x11_set_colormap (GdkDrawable *drawable, |
| 391 |
GdkColormap *cmap) |
| 392 |
{ |
| 393 |
GdkDrawableImplX11 *draw_impl; |
| 394 |
|
| 395 |
g_return_if_fail (GDK_IS_WINDOW_IMPL_X11 (drawable)); |
| 396 |
|
| 397 |
draw_impl = GDK_DRAWABLE_IMPL_X11 (drawable); |
| 398 |
|
| 399 |
if (cmap && GDK_WINDOW_DESTROYED (draw_impl->wrapper)) |
| 400 |
return; |
| 401 |
|
| 402 |
/* chain up */ |
| 403 |
GDK_DRAWABLE_CLASS (gdk_window_impl_x11_parent_class)->set_colormap (drawable, cmap); |
| 404 |
|
| 405 |
if (cmap) |
| 406 |
{ |
| 407 |
XSetWindowColormap (GDK_SCREEN_XDISPLAY (draw_impl->screen), |
| 408 |
draw_impl->xid, |
| 409 |
GDK_COLORMAP_XCOLORMAP (cmap)); |
| 410 |
|
| 411 |
if (((GdkWindowObject*)draw_impl->wrapper)->window_type != |
| 412 |
GDK_WINDOW_TOPLEVEL) |
| 413 |
gdk_window_add_colormap_windows (GDK_WINDOW (draw_impl->wrapper)); |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
void |
| 419 |
_gdk_windowing_window_init (GdkScreen * screen) |
| 420 |
{ |
| 421 |
GdkWindowObject *private; |
| 422 |
GdkDrawableImplX11 *draw_impl; |
| 423 |
GdkScreenX11 *screen_x11; |
| 424 |
|
| 425 |
screen_x11 = GDK_SCREEN_X11 (screen); |
| 426 |
|
| 427 |
g_assert (screen_x11->root_window == NULL); |
| 428 |
|
| 429 |
gdk_screen_set_default_colormap (screen, |
| 430 |
gdk_screen_get_system_colormap (screen)); |
| 431 |
|
| 432 |
screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL); |
| 433 |
|
| 434 |
private = (GdkWindowObject *) screen_x11->root_window; |
| 435 |
private->impl = g_object_new (_gdk_window_impl_get_type (), NULL); |
| 436 |
private->impl_window = private; |
| 437 |
|
| 438 |
draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl); |
| 439 |
|
| 440 |
draw_impl->screen = screen; |
| 441 |
draw_impl->xid = screen_x11->xroot_window; |
| 442 |
draw_impl->wrapper = GDK_DRAWABLE (private); |
| 443 |
draw_impl->colormap = gdk_screen_get_system_colormap (screen); |
| 444 |
g_object_ref (draw_impl->colormap); |
| 445 |
|
| 446 |
private->window_type = GDK_WINDOW_ROOT; |
| 447 |
private->depth = DefaultDepthOfScreen (screen_x11->xscreen); |
| 448 |
|
| 449 |
private->x = 0; |
| 450 |
private->y = 0; |
| 451 |
private->abs_x = 0; |
| 452 |
private->abs_y = 0; |
| 453 |
private->width = WidthOfScreen (screen_x11->xscreen); |
| 454 |
private->height = HeightOfScreen (screen_x11->xscreen); |
| 455 |
private->viewable = TRUE; |
| 456 |
|
| 457 |
/* see init_randr_support() in gdkscreen-x11.c */ |
| 458 |
private->event_mask = GDK_STRUCTURE_MASK; |
| 459 |
|
| 460 |
_gdk_window_update_size (screen_x11->root_window); |
| 461 |
|
| 462 |
_gdk_xid_table_insert (screen_x11->display, |
| 463 |
&screen_x11->xroot_window, |
| 464 |
screen_x11->root_window); |
| 465 |
} |
| 466 |
|
| 467 |
static void |
| 468 |
set_wm_protocols (GdkWindow *window) |
| 469 |
{ |
| 470 |
GdkDisplay *display = gdk_drawable_get_display (window); |
| 471 |
Atom protocols[4]; |
| 472 |
int n = 0; |
| 473 |
|
| 474 |
protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"); |
| 475 |
protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"); |
| 476 |
protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING"); |
| 477 |
|
| 478 |
#ifdef HAVE_XSYNC |
| 479 |
if (GDK_DISPLAY_X11 (display)->use_sync) |
| 480 |
protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST"); |
| 481 |
#endif |
| 482 |
|
| 483 |
XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n); |
| 484 |
} |
| 485 |
|
| 486 |
static const gchar * |
| 487 |
get_default_title (void) |
| 488 |
{ |
| 489 |
const char *title; |
| 490 |
|
| 491 |
title = g_get_application_name (); |
| 492 |
if (!title) |
| 493 |
title = g_get_prgname (); |
| 494 |
if (!title) |
| 495 |
title = ""; |
| 496 |
|
| 497 |
return title; |
| 498 |
} |
| 499 |
|
| 500 |
static void |
| 501 |
check_leader_window_title (GdkDisplay *display) |
| 502 |
{ |
| 503 |
GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display); |
| 504 |
|
| 505 |
if (display_x11->leader_window && !display_x11->leader_window_title_set) |
| 506 |
{ |
| 507 |
set_wm_name (display, |
| 508 |
display_x11->leader_window, |
| 509 |
get_default_title ()); |
| 510 |
|
| 511 |
display_x11->leader_window_title_set = TRUE; |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
static Window |
| 516 |
create_focus_window (Display *xdisplay, |
| 517 |
XID parent) |
| 518 |
{ |
| 519 |
Window focus_window = XCreateSimpleWindow (xdisplay, parent, |
| 520 |
-1, -1, 1, 1, 0, |
| 521 |
0, 0); |
| 522 |
|
| 523 |
/* FIXME: probably better to actually track the requested event mask for the toplevel |
| 524 |
*/ |
| 525 |
XSelectInput (xdisplay, focus_window, |
| 526 |
KeyPressMask | KeyReleaseMask | FocusChangeMask); |
| 527 |
|
| 528 |
XMapWindow (xdisplay, focus_window); |
| 529 |
|
| 530 |
return focus_window; |
| 531 |
} |
| 532 |
|
| 533 |
static void |
| 534 |
ensure_sync_counter (GdkWindow *window) |
| 535 |
{ |
| 536 |
#ifdef HAVE_XSYNC |
| 537 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 538 |
{ |
| 539 |
GdkDisplay *display = GDK_WINDOW_DISPLAY (window); |
| 540 |
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window); |
| 541 |
GdkWindowObject *private = (GdkWindowObject *)window; |
| 542 |
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 543 |
|
| 544 |
if (toplevel && impl->use_synchronized_configure && |
| 545 |
toplevel->update_counter == None && |
| 546 |
GDK_DISPLAY_X11 (display)->use_sync) |
| 547 |
{ |
| 548 |
Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); |
| 549 |
XSyncValue value; |
| 550 |
Atom atom; |
| 551 |
|
| 552 |
XSyncIntToValue (&value, 0); |
| 553 |
|
| 554 |
toplevel->update_counter = XSyncCreateCounter (xdisplay, value); |
| 555 |
|
| 556 |
atom = gdk_x11_get_xatom_by_name_for_display (display, |
| 557 |
"_NET_WM_SYNC_REQUEST_COUNTER"); |
| 558 |
|
| 559 |
XChangeProperty (xdisplay, GDK_WINDOW_XID (window), |
| 560 |
atom, XA_CARDINAL, |
| 561 |
32, PropModeReplace, |
| 562 |
(guchar *)&toplevel->update_counter, 1); |
| 563 |
|
| 564 |
XSyncIntToValue (&toplevel->current_counter_value, 0); |
| 565 |
} |
| 566 |
} |
| 567 |
#endif |
| 568 |
} |
| 569 |
|
| 570 |
static void |
| 571 |
setup_toplevel_window (GdkWindow *window, |
| 572 |
GdkWindow *parent) |
| 573 |
{ |
| 574 |
GdkWindowObject *obj = (GdkWindowObject *)window; |
| 575 |
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window); |
| 576 |
Display *xdisplay = GDK_WINDOW_XDISPLAY (window); |
| 577 |
XID xid = GDK_WINDOW_XID (window); |
| 578 |
XID xparent = GDK_WINDOW_XID (parent); |
| 579 |
GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (GDK_WINDOW_SCREEN (parent)); |
| 580 |
XSizeHints size_hints; |
| 581 |
long pid; |
| 582 |
Window leader_window; |
| 583 |
|
| 584 |
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_DIALOG) |
| 585 |
XSetTransientForHint (xdisplay, xid, xparent); |
| 586 |
|
| 587 |
set_wm_protocols (window); |
| 588 |
|
| 589 |
if (!obj->input_only) |
| 590 |
{ |
| 591 |
/* The focus window is off the visible area, and serves to receive key |
| 592 |
* press events so they don't get sent to child windows. |
| 593 |
*/ |
| 594 |
toplevel->focus_window = create_focus_window (xdisplay, xid); |
| 595 |
_gdk_xid_table_insert (screen_x11->display, &toplevel->focus_window, window); |
| 596 |
} |
| 597 |
|
| 598 |
check_leader_window_title (screen_x11->display); |
| 599 |
|
| 600 |
/* FIXME: Is there any point in doing this? Do any WM's pay |
| 601 |
* attention to PSize, and even if they do, is this the |
| 602 |
* correct value??? |
| 603 |
*/ |
| 604 |
size_hints.flags = PSize; |
| 605 |
size_hints.width = obj->width; |
| 606 |
size_hints.height = obj->height; |
| 607 |
|
| 608 |
XSetWMNormalHints (xdisplay, xid, &size_hints); |
| 609 |
|
| 610 |
/* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */ |
| 611 |
XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL); |
| 612 |
|
| 613 |
pid = getpid (); |
| 614 |
XChangeProperty (xdisplay, xid, |
| 615 |
gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"), |
| 616 |
XA_CARDINAL, 32, |
| 617 |
PropModeReplace, |
| 618 |
(guchar *)&pid, 1); |
| 619 |
|
| 620 |
leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window; |
| 621 |
if (!leader_window) |
| 622 |
leader_window = xid; |
| 623 |
XChangeProperty (xdisplay, xid, |
| 624 |
gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"), |
| 625 |
XA_WINDOW, 32, PropModeReplace, |
| 626 |
(guchar *) &leader_window, 1); |
| 627 |
|
| 628 |
if (toplevel->focus_window != None) |
| 629 |
XChangeProperty (xdisplay, xid, |
| 630 |
gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_USER_TIME_WINDOW"), |
| 631 |
XA_WINDOW, 32, PropModeReplace, |
| 632 |
(guchar *) &toplevel->focus_window, 1); |
| 633 |
|
| 634 |
if (!obj->focus_on_map) |
| 635 |
gdk_x11_window_set_user_time (window, 0); |
| 636 |
else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0) |
| 637 |
gdk_x11_window_set_user_time (window, GDK_DISPLAY_X11 (screen_x11->display)->user_time); |
| 638 |
|
| 639 |
ensure_sync_counter (window); |
| 640 |
} |
| 641 |
|
| 642 |
void |
| 643 |
_gdk_window_impl_new (GdkWindow *window, |
| 644 |
GdkWindow *real_parent, |
| 645 |
GdkScreen *screen, |
| 646 |
GdkVisual *visual, |
| 647 |
GdkEventMask event_mask, |
| 648 |
GdkWindowAttr *attributes, |
| 649 |
gint attributes_mask) |
| 650 |
{ |
| 651 |
GdkWindowObject *private; |
| 652 |
GdkWindowImplX11 *impl; |
| 653 |
GdkDrawableImplX11 *draw_impl; |
| 654 |
GdkScreenX11 *screen_x11; |
| 655 |
|
| 656 |
Window xparent; |
| 657 |
Visual *xvisual; |
| 658 |
Display *xdisplay; |
| 659 |
Window xid; |
| 660 |
|
| 661 |
XSetWindowAttributes xattributes; |
| 662 |
long xattributes_mask; |
| 663 |
XClassHint *class_hint; |
| 664 |
|
| 665 |
unsigned int class; |
| 666 |
const char *title; |
| 667 |
int i; |
| 668 |
|
| 669 |
private = (GdkWindowObject *) window; |
| 670 |
|
| 671 |
screen_x11 = GDK_SCREEN_X11 (screen); |
| 672 |
xparent = GDK_WINDOW_XID (real_parent); |
| 673 |
|
| 674 |
impl = g_object_new (_gdk_window_impl_get_type (), NULL); |
| 675 |
private->impl = (GdkDrawable *)impl; |
| 676 |
draw_impl = GDK_DRAWABLE_IMPL_X11 (impl); |
| 677 |
draw_impl->wrapper = GDK_DRAWABLE (window); |
| 678 |
|
| 679 |
draw_impl->screen = screen; |
| 680 |
xdisplay = screen_x11->xdisplay; |
| 681 |
|
| 682 |
xattributes_mask = 0; |
| 683 |
|
| 684 |
xvisual = ((GdkVisualPrivate*) visual)->xvisual; |
| 685 |
|
| 686 |
xattributes.event_mask = StructureNotifyMask | PropertyChangeMask; |
| 687 |
for (i = 0; i < _gdk_nenvent_masks; i++) |
| 688 |
{ |
| 689 |
if (event_mask & (1 << (i + 1))) |
| 690 |
xattributes.event_mask |= _gdk_event_mask_table[i]; |
| 691 |
} |
| 692 |
if (xattributes.event_mask) |
| 693 |
xattributes_mask |= CWEventMask; |
| 694 |
|
| 695 |
if (attributes_mask & GDK_WA_NOREDIR) |
| 696 |
{ |
| 697 |
xattributes.override_redirect = |
| 698 |
(attributes->override_redirect == FALSE)?False:True; |
| 699 |
xattributes_mask |= CWOverrideRedirect; |
| 700 |
} |
| 701 |
else |
| 702 |
xattributes.override_redirect = False; |
| 703 |
|
| 704 |
impl->override_redirect = xattributes.override_redirect; |
| 705 |
|
| 706 |
if (private->parent && private->parent->guffaw_gravity) |
| 707 |
{ |
| 708 |
xattributes.win_gravity = StaticGravity; |
| 709 |
xattributes_mask |= CWWinGravity; |
| 710 |
} |
| 711 |
|
| 712 |
/* Sanity checks */ |
| 713 |
switch (private->window_type) |
| 714 |
{ |
| 715 |
case GDK_WINDOW_TOPLEVEL: |
| 716 |
case GDK_WINDOW_DIALOG: |
| 717 |
case GDK_WINDOW_TEMP: |
| 718 |
if (GDK_WINDOW_TYPE (private->parent) != GDK_WINDOW_ROOT) |
| 719 |
{ |
| 720 |
/* The common code warns for this case */ |
| 721 |
xparent = GDK_SCREEN_XROOTWIN (screen); |
| 722 |
} |
| 723 |
} |
| 724 |
|
| 725 |
if (!private->input_only) |
| 726 |
{ |
| 727 |
class = InputOutput; |
| 728 |
|
| 729 |
if (attributes_mask & GDK_WA_COLORMAP) |
| 730 |
{ |
| 731 |
draw_impl->colormap = attributes->colormap; |
| 732 |
g_object_ref (attributes->colormap); |
| 733 |
} |
| 734 |
else |
| 735 |
{ |
| 736 |
if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual) |
| 737 |
{ |
| 738 |
draw_impl->colormap = gdk_screen_get_system_colormap (screen); |
| 739 |
g_object_ref (draw_impl->colormap); |
| 740 |
} |
| 741 |
else |
| 742 |
{ |
| 743 |
draw_impl->colormap = gdk_colormap_new (visual, FALSE); |
| 744 |
} |
| 745 |
} |
| 746 |
|
| 747 |
xattributes.background_pixel = private->bg_color.pixel; |
| 748 |
|
| 749 |
xattributes.border_pixel = BlackPixel (xdisplay, screen_x11->screen_num); |
| 750 |
xattributes_mask |= CWBorderPixel | CWBackPixel; |
| 751 |
|
| 752 |
if (private->guffaw_gravity) |
| 753 |
xattributes.bit_gravity = StaticGravity; |
| 754 |
else |
| 755 |
xattributes.bit_gravity = NorthWestGravity; |
| 756 |
|
| 757 |
xattributes_mask |= CWBitGravity; |
| 758 |
|
| 759 |
xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap); |
| 760 |
xattributes_mask |= CWColormap; |
| 761 |
|
| 762 |
if (private->window_type == GDK_WINDOW_TEMP) |
| 763 |
{ |
| 764 |
xattributes.save_under = True; |
| 765 |
xattributes.override_redirect = True; |
| 766 |
xattributes.cursor = None; |
| 767 |
xattributes_mask |= CWSaveUnder | CWOverrideRedirect; |
| 768 |
|
| 769 |
impl->override_redirect = TRUE; |
| 770 |
} |
| 771 |
} |
| 772 |
else |
| 773 |
{ |
| 774 |
class = InputOnly; |
| 775 |
draw_impl->colormap = gdk_screen_get_system_colormap (screen); |
| 776 |
g_object_ref (draw_impl->colormap); |
| 777 |
} |
| 778 |
|
| 779 |
if (private->width > 32767 || |
| 780 |
private->height > 32767) |
| 781 |
{ |
| 782 |
g_warning ("Native Windows wider or taller than 32767 pixels are not supported"); |
| 783 |
|
| 784 |
if (private->width > 32767) |
| 785 |
private->width = 32767; |
| 786 |
if (private->height > 32767) |
| 787 |
private->height = 32767; |
| 788 |
} |
| 789 |
|
| 790 |
xid = draw_impl->xid = XCreateWindow (xdisplay, xparent, |
| 791 |
private->x + private->parent->abs_x, |
| 792 |
private->y + private->parent->abs_y, |
| 793 |
private->width, private->height, |
| 794 |
0, private->depth, class, xvisual, |
| 795 |
xattributes_mask, &xattributes); |
| 796 |
|
| 797 |
g_object_ref (window); |
| 798 |
_gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window); |
| 799 |
|
| 800 |
switch (GDK_WINDOW_TYPE (private)) |
| 801 |
{ |
| 802 |
case GDK_WINDOW_DIALOG: |
| 803 |
case GDK_WINDOW_TOPLEVEL: |
| 804 |
case GDK_WINDOW_TEMP: |
| 805 |
if (attributes_mask & GDK_WA_TITLE) |
| 806 |
title = attributes->title; |
| 807 |
else |
| 808 |
title = get_default_title (); |
| 809 |
|
| 810 |
gdk_window_set_title (window, title); |
| 811 |
|
| 812 |
if (attributes_mask & GDK_WA_WMCLASS) |
| 813 |
{ |
| 814 |
class_hint = XAllocClassHint (); |
| 815 |
class_hint->res_name = attributes->wmclass_name; |
| 816 |
class_hint->res_class = attributes->wmclass_class; |
| 817 |
XSetClassHint (xdisplay, xid, class_hint); |
| 818 |
XFree (class_hint); |
| 819 |
} |
| 820 |
|
| 821 |
setup_toplevel_window (window, (GdkWindow *)private->parent); |
| 822 |
break; |
| 823 |
|
| 824 |
case GDK_WINDOW_CHILD: |
| 825 |
if (!private->input_only && |
| 826 |
(draw_impl->colormap != gdk_screen_get_system_colormap (screen)) && |
| 827 |
(draw_impl->colormap != gdk_drawable_get_colormap (gdk_window_get_toplevel (window)))) |
| 828 |
{ |
| 829 |
GDK_NOTE (MISC, g_message ("adding colormap window\n")); |
| 830 |
gdk_window_add_colormap_windows (window); |
| 831 |
} |
| 832 |
break; |
| 833 |
|
| 834 |
default: |
| 835 |
break; |
| 836 |
} |
| 837 |
|
| 838 |
if (attributes_mask & GDK_WA_TYPE_HINT) |
| 839 |
gdk_window_set_type_hint (window, attributes->type_hint); |
| 840 |
} |
| 841 |
|
| 842 |
static GdkEventMask |
| 843 |
x_event_mask_to_gdk_event_mask (long mask) |
| 844 |
{ |
| 845 |
GdkEventMask event_mask = 0; |
| 846 |
int i; |
| 847 |
|
| 848 |
for (i = 0; i < _gdk_nenvent_masks; i++) |
| 849 |
{ |
| 850 |
if (mask & _gdk_event_mask_table[i]) |
| 851 |
event_mask |= 1 << (i + 1); |
| 852 |
} |
| 853 |
|
| 854 |
return event_mask; |
| 855 |
} |
| 856 |
|
| 857 |
/** |
| 858 |
* gdk_window_foreign_new_for_display: |
| 859 |
* @display: the #GdkDisplay where the window handle comes from. |
| 860 |
* @anid: a native window handle. |
| 861 |
* |
| 862 |
* Wraps a native window in a #GdkWindow. |
| 863 |
* This may fail if the window has been destroyed. If the window |
| 864 |
* was already known to GDK, a new reference to the existing |
| 865 |
* #GdkWindow is returned. |
| 866 |
* |
| 867 |
* For example in the X backend, a native window handle is an Xlib |
| 868 |
* <type>XID</type>. |
| 869 |
* |
| 870 |
* Return value: a #GdkWindow wrapper for the native window or |
| 871 |
* %NULL if the window has been destroyed. The wrapper will be |
| 872 |
* newly created, if one doesn't exist already. |
| 873 |
* |
| 874 |
* Since: 2.2 |
| 875 |
* |
| 876 |
* Deprecated:2.24: Use gdk_x11_window_foreign_new_for_display() or |
| 877 |
* equivalent backend-specific API instead |
| 878 |
**/ |
| 879 |
GdkWindow * |
| 880 |
gdk_window_foreign_new_for_display (GdkDisplay *display, |
| 881 |
GdkNativeWindow anid) |
| 882 |
{ |
| 883 |
return gdk_x11_window_foreign_new_for_display (display, anid); |
| 884 |
} |
| 885 |
|
| 886 |
/** |
| 887 |
* gdk_x11_window_foreign_new_for_display: |
| 888 |
* @display: the #GdkDisplay where the window handle comes from. |
| 889 |
* @window: an XLib <type>Window</type> |
| 890 |
* |
| 891 |
* Wraps a native window in a #GdkWindow. |
| 892 |
* |
| 893 |
* This may fail if the window has been destroyed. If the window |
| 894 |
* was already known to GDK, a new reference to the existing |
| 895 |
* #GdkWindow is returned. |
| 896 |
* |
| 897 |
* Return value: a #GdkWindow wrapper for the native window or |
| 898 |
* %NULL if the window has been destroyed. The wrapper will be |
| 899 |
* newly created, if one doesn't exist already. |
| 900 |
* |
| 901 |
* Since: 2.24 |
| 902 |
*/ |
| 903 |
GdkWindow * |
| 904 |
gdk_x11_window_foreign_new_for_display (GdkDisplay *display, |
| 905 |
Window window) |
| 906 |
{ |
| 907 |
GdkWindow *win; |
| 908 |
GdkWindowObject *private; |
| 909 |
GdkWindowImplX11 *impl; |
| 910 |
GdkDrawableImplX11 *draw_impl; |
| 911 |
GdkDisplayX11 *display_x11; |
| 912 |
XWindowAttributes attrs; |
| 913 |
Window root, parent; |
| 914 |
Window *children = NULL; |
| 915 |
guint nchildren; |
| 916 |
gboolean result; |
| 917 |
|
| 918 |
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); |
| 919 |
|
| 920 |
display_x11 = GDK_DISPLAY_X11 (display); |
| 921 |
|
| 922 |
if ((win = gdk_xid_table_lookup_for_display (display, window)) != NULL) |
| 923 |
return g_object_ref (win); |
| 924 |
|
| 925 |
gdk_error_trap_push (); |
| 926 |
result = XGetWindowAttributes (display_x11->xdisplay, window, &attrs); |
| 927 |
if (gdk_error_trap_pop () || !result) |
| 928 |
return NULL; |
| 929 |
|
| 930 |
/* FIXME: This is pretty expensive. Maybe the caller should supply |
| 931 |
* the parent */ |
| 932 |
gdk_error_trap_push (); |
| 933 |
result = XQueryTree (display_x11->xdisplay, window, &root, &parent, &children, &nchildren); |
| 934 |
if (gdk_error_trap_pop () || !result) |
| 935 |
return NULL; |
| 936 |
|
| 937 |
if (children) |
| 938 |
XFree (children); |
| 939 |
|
| 940 |
win = g_object_new (GDK_TYPE_WINDOW, NULL); |
| 941 |
|
| 942 |
private = (GdkWindowObject *) win; |
| 943 |
private->impl = g_object_new (_gdk_window_impl_get_type (), NULL); |
| 944 |
private->impl_window = private; |
| 945 |
|
| 946 |
impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 947 |
draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl); |
| 948 |
draw_impl->wrapper = GDK_DRAWABLE (win); |
| 949 |
draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root); |
| 950 |
|
| 951 |
private->parent = gdk_xid_table_lookup_for_display (display, parent); |
| 952 |
|
| 953 |
if (!private->parent || GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_FOREIGN) |
| 954 |
private->parent = (GdkWindowObject *) gdk_screen_get_root_window (draw_impl->screen); |
| 955 |
|
| 956 |
private->parent->children = g_list_prepend (private->parent->children, win); |
| 957 |
|
| 958 |
draw_impl->xid = window; |
| 959 |
|
| 960 |
private->x = attrs.x; |
| 961 |
private->y = attrs.y; |
| 962 |
private->width = attrs.width; |
| 963 |
private->height = attrs.height; |
| 964 |
private->window_type = GDK_WINDOW_FOREIGN; |
| 965 |
private->destroyed = FALSE; |
| 966 |
|
| 967 |
private->event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask); |
| 968 |
|
| 969 |
if (attrs.map_state == IsUnmapped) |
| 970 |
private->state = GDK_WINDOW_STATE_WITHDRAWN; |
| 971 |
else |
| 972 |
private->state = 0; |
| 973 |
private->viewable = TRUE; |
| 974 |
|
| 975 |
private->depth = attrs.depth; |
| 976 |
|
| 977 |
g_object_ref (win); |
| 978 |
_gdk_xid_table_insert (display, &GDK_WINDOW_XID (win), win); |
| 979 |
|
| 980 |
/* Update the clip region, etc */ |
| 981 |
_gdk_window_update_size (win); |
| 982 |
|
| 983 |
return win; |
| 984 |
} |
| 985 |
|
| 986 |
/** |
| 987 |
* gdk_window_lookup_for_display: |
| 988 |
* @display: the #GdkDisplay corresponding to the window handle |
| 989 |
* @anid: a native window handle. |
| 990 |
* |
| 991 |
* Looks up the #GdkWindow that wraps the given native window handle. |
| 992 |
* |
| 993 |
* For example in the X backend, a native window handle is an Xlib |
| 994 |
* <type>XID</type>. |
| 995 |
* |
| 996 |
* Return value: the #GdkWindow wrapper for the native window, |
| 997 |
* or %NULL if there is none. |
| 998 |
* |
| 999 |
* Since: 2.2 |
| 1000 |
* |
| 1001 |
* Deprecated:2.24: Use gdk_x11_window_lookup_for_display() instead |
| 1002 |
**/ |
| 1003 |
GdkWindow * |
| 1004 |
gdk_window_lookup_for_display (GdkDisplay *display, |
| 1005 |
GdkNativeWindow anid) |
| 1006 |
{ |
| 1007 |
return gdk_x11_window_lookup_for_display (display, anid); |
| 1008 |
} |
| 1009 |
|
| 1010 |
/** |
| 1011 |
* gdk_x11_window_lookup_for_display: |
| 1012 |
* @display: the #GdkDisplay corresponding to the window handle |
| 1013 |
* @window: an XLib <type>Window</type> |
| 1014 |
* |
| 1015 |
* Looks up the #GdkWindow that wraps the given native window handle. |
| 1016 |
* |
| 1017 |
* Return value: the #GdkWindow wrapper for the native window, |
| 1018 |
* or %NULL if there is none. |
| 1019 |
* |
| 1020 |
* Since: 2.24 |
| 1021 |
*/ |
| 1022 |
GdkWindow * |
| 1023 |
gdk_x11_window_lookup_for_display (GdkDisplay *display, |
| 1024 |
Window window) |
| 1025 |
{ |
| 1026 |
return (GdkWindow*) gdk_xid_table_lookup_for_display (display, window); |
| 1027 |
} |
| 1028 |
|
| 1029 |
/** |
| 1030 |
* gdk_window_lookup: |
| 1031 |
* @anid: a native window handle. |
| 1032 |
* |
| 1033 |
* Looks up the #GdkWindow that wraps the given native window handle. |
| 1034 |
* |
| 1035 |
* For example in the X backend, a native window handle is an Xlib |
| 1036 |
* <type>XID</type>. |
| 1037 |
* |
| 1038 |
* Return value: the #GdkWindow wrapper for the native window, |
| 1039 |
* or %NULL if there is none. |
| 1040 |
* |
| 1041 |
* Deprecated: 2.24: Use gdk_x11_window_lookup_for_display() or equivalent |
| 1042 |
* backend-specific functionality instead |
| 1043 |
**/ |
| 1044 |
GdkWindow * |
| 1045 |
gdk_window_lookup (GdkNativeWindow anid) |
| 1046 |
{ |
| 1047 |
return (GdkWindow*) gdk_xid_table_lookup (anid); |
| 1048 |
} |
| 1049 |
|
| 1050 |
static void |
| 1051 |
gdk_toplevel_x11_free_contents (GdkDisplay *display, |
| 1052 |
GdkToplevelX11 *toplevel) |
| 1053 |
{ |
| 1054 |
if (toplevel->icon_window) |
| 1055 |
{ |
| 1056 |
g_object_unref (toplevel->icon_window); |
| 1057 |
toplevel->icon_window = NULL; |
| 1058 |
} |
| 1059 |
if (toplevel->icon_pixmap) |
| 1060 |
{ |
| 1061 |
g_object_unref (toplevel->icon_pixmap); |
| 1062 |
toplevel->icon_pixmap = NULL; |
| 1063 |
} |
| 1064 |
if (toplevel->icon_mask) |
| 1065 |
{ |
| 1066 |
g_object_unref (toplevel->icon_mask); |
| 1067 |
toplevel->icon_mask = NULL; |
| 1068 |
} |
| 1069 |
if (toplevel->group_leader) |
| 1070 |
{ |
| 1071 |
g_object_unref (toplevel->group_leader); |
| 1072 |
toplevel->group_leader = NULL; |
| 1073 |
} |
| 1074 |
#ifdef HAVE_XSYNC |
| 1075 |
if (toplevel->update_counter != None) |
| 1076 |
{ |
| 1077 |
XSyncDestroyCounter (GDK_DISPLAY_XDISPLAY (display), |
| 1078 |
toplevel->update_counter); |
| 1079 |
toplevel->update_counter = None; |
| 1080 |
|
| 1081 |
XSyncIntToValue (&toplevel->current_counter_value, 0); |
| 1082 |
} |
| 1083 |
#endif |
| 1084 |
} |
| 1085 |
|
| 1086 |
static void |
| 1087 |
_gdk_x11_window_destroy (GdkWindow *window, |
| 1088 |
gboolean recursing, |
| 1089 |
gboolean foreign_destroy) |
| 1090 |
{ |
| 1091 |
GdkWindowObject *private = (GdkWindowObject *)window; |
| 1092 |
GdkToplevelX11 *toplevel; |
| 1093 |
|
| 1094 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1095 |
|
| 1096 |
_gdk_selection_window_destroyed (window); |
| 1097 |
|
| 1098 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 1099 |
if (toplevel) |
| 1100 |
gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), toplevel); |
| 1101 |
|
| 1102 |
_gdk_x11_drawable_finish (private->impl); |
| 1103 |
|
| 1104 |
if (!recursing && !foreign_destroy) |
| 1105 |
{ |
| 1106 |
XDestroyWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window)); |
| 1107 |
} |
| 1108 |
} |
| 1109 |
|
| 1110 |
void |
| 1111 |
_gdk_windowing_window_destroy_foreign (GdkWindow *window) |
| 1112 |
{ |
| 1113 |
/* It's somebody else's window, but in our hierarchy, |
| 1114 |
* so reparent it to the root window, and then send |
| 1115 |
* it a delete event, as if we were a WM |
| 1116 |
*/ |
| 1117 |
XClientMessageEvent xclient; |
| 1118 |
|
| 1119 |
gdk_error_trap_push (); |
| 1120 |
gdk_window_hide (window); |
| 1121 |
gdk_window_reparent (window, NULL, 0, 0); |
| 1122 |
|
| 1123 |
memset (&xclient, 0, sizeof (xclient)); |
| 1124 |
xclient.type = ClientMessage; |
| 1125 |
xclient.window = GDK_WINDOW_XID (window); |
| 1126 |
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), |
| 1127 |
"WM_PROTOCOLS"); |
| 1128 |
xclient.format = 32; |
| 1129 |
xclient.data.l[0] = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), |
| 1130 |
"WM_DELETE_WINDOW"); |
| 1131 |
xclient.data.l[1] = CurrentTime; |
| 1132 |
xclient.data.l[2] = 0; |
| 1133 |
xclient.data.l[3] = 0; |
| 1134 |
xclient.data.l[4] = 0; |
| 1135 |
|
| 1136 |
XSendEvent (GDK_WINDOW_XDISPLAY (window), |
| 1137 |
GDK_WINDOW_XID (window), |
| 1138 |
False, 0, (XEvent *)&xclient); |
| 1139 |
gdk_display_sync (GDK_WINDOW_DISPLAY (window)); |
| 1140 |
gdk_error_trap_pop (); |
| 1141 |
} |
| 1142 |
|
| 1143 |
static GdkWindow * |
| 1144 |
get_root (GdkWindow *window) |
| 1145 |
{ |
| 1146 |
GdkScreen *screen = gdk_drawable_get_screen (window); |
| 1147 |
|
| 1148 |
return gdk_screen_get_root_window (screen); |
| 1149 |
} |
| 1150 |
|
| 1151 |
/* This function is called when the XWindow is really gone. |
| 1152 |
*/ |
| 1153 |
void |
| 1154 |
gdk_window_destroy_notify (GdkWindow *window) |
| 1155 |
{ |
| 1156 |
GdkWindowImplX11 *window_impl; |
| 1157 |
|
| 1158 |
window_impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl); |
| 1159 |
|
| 1160 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 1161 |
{ |
| 1162 |
if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN) |
| 1163 |
g_warning ("GdkWindow %#lx unexpectedly destroyed", GDK_WINDOW_XID (window)); |
| 1164 |
|
| 1165 |
_gdk_window_destroy (window, TRUE); |
| 1166 |
} |
| 1167 |
|
| 1168 |
_gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), GDK_WINDOW_XID (window)); |
| 1169 |
if (window_impl->toplevel && window_impl->toplevel->focus_window) |
| 1170 |
_gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), window_impl->toplevel->focus_window); |
| 1171 |
|
| 1172 |
_gdk_xgrab_check_destroy (window); |
| 1173 |
|
| 1174 |
g_object_unref (window); |
| 1175 |
} |
| 1176 |
|
| 1177 |
static void |
| 1178 |
update_wm_hints (GdkWindow *window, |
| 1179 |
gboolean force) |
| 1180 |
{ |
| 1181 |
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window); |
| 1182 |
GdkWindowObject *private = (GdkWindowObject *)window; |
| 1183 |
GdkDisplay *display = GDK_WINDOW_DISPLAY (window); |
| 1184 |
XWMHints wm_hints; |
| 1185 |
|
| 1186 |
if (!force && |
| 1187 |
!toplevel->is_leader && |
| 1188 |
private->state & GDK_WINDOW_STATE_WITHDRAWN) |
| 1189 |
return; |
| 1190 |
|
| 1191 |
wm_hints.flags = StateHint | InputHint; |
| 1192 |
wm_hints.input = private->accept_focus ? True : False; |
| 1193 |
wm_hints.initial_state = NormalState; |
| 1194 |
|
| 1195 |
if (private->state & GDK_WINDOW_STATE_ICONIFIED) |
| 1196 |
{ |
| 1197 |
wm_hints.flags |= StateHint; |
| 1198 |
wm_hints.initial_state = IconicState; |
| 1199 |
} |
| 1200 |
|
| 1201 |
if (toplevel->icon_window && !GDK_WINDOW_DESTROYED (toplevel->icon_window)) |
| 1202 |
{ |
| 1203 |
wm_hints.flags |= IconWindowHint; |
| 1204 |
wm_hints.icon_window = GDK_WINDOW_XID (toplevel->icon_window); |
| 1205 |
} |
| 1206 |
|
| 1207 |
if (toplevel->icon_pixmap) |
| 1208 |
{ |
| 1209 |
wm_hints.flags |= IconPixmapHint; |
| 1210 |
wm_hints.icon_pixmap = GDK_PIXMAP_XID (toplevel->icon_pixmap); |
| 1211 |
} |
| 1212 |
|
| 1213 |
if (toplevel->icon_mask) |
| 1214 |
{ |
| 1215 |
wm_hints.flags |= IconMaskHint; |
| 1216 |
wm_hints.icon_mask = GDK_PIXMAP_XID (toplevel->icon_mask); |
| 1217 |
} |
| 1218 |
|
| 1219 |
wm_hints.flags |= WindowGroupHint; |
| 1220 |
if (toplevel->group_leader && !GDK_WINDOW_DESTROYED (toplevel->group_leader)) |
| 1221 |
{ |
| 1222 |
wm_hints.flags |= WindowGroupHint; |
| 1223 |
wm_hints.window_group = GDK_WINDOW_XID (toplevel->group_leader); |
| 1224 |
} |
| 1225 |
else |
| 1226 |
wm_hints.window_group = GDK_DISPLAY_X11 (display)->leader_window; |
| 1227 |
|
| 1228 |
if (toplevel->urgency_hint) |
| 1229 |
wm_hints.flags |= XUrgencyHint; |
| 1230 |
|
| 1231 |
XSetWMHints (GDK_WINDOW_XDISPLAY (window), |
| 1232 |
GDK_WINDOW_XID (window), |
| 1233 |
&wm_hints); |
| 1234 |
} |
| 1235 |
|
| 1236 |
static void |
| 1237 |
set_initial_hints (GdkWindow *window) |
| 1238 |
{ |
| 1239 |
GdkDisplay *display = GDK_WINDOW_DISPLAY (window); |
| 1240 |
Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); |
| 1241 |
Window xwindow = GDK_WINDOW_XID (window); |
| 1242 |
GdkWindowObject *private; |
| 1243 |
GdkToplevelX11 *toplevel; |
| 1244 |
Atom atoms[9]; |
| 1245 |
gint i; |
| 1246 |
|
| 1247 |
private = (GdkWindowObject*) window; |
| 1248 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 1249 |
|
| 1250 |
if (!toplevel) |
| 1251 |
return; |
| 1252 |
|
| 1253 |
update_wm_hints (window, TRUE); |
| 1254 |
|
| 1255 |
/* We set the spec hints regardless of whether the spec is supported, |
| 1256 |
* since it can't hurt and it's kind of expensive to check whether |
| 1257 |
* it's supported. |
| 1258 |
*/ |
| 1259 |
|
| 1260 |
i = 0; |
| 1261 |
|
| 1262 |
if (private->state & GDK_WINDOW_STATE_MAXIMIZED) |
| 1263 |
{ |
| 1264 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1265 |
"_NET_WM_STATE_MAXIMIZED_VERT"); |
| 1266 |
++i; |
| 1267 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1268 |
"_NET_WM_STATE_MAXIMIZED_HORZ"); |
| 1269 |
++i; |
| 1270 |
toplevel->have_maxhorz = toplevel->have_maxvert = TRUE; |
| 1271 |
} |
| 1272 |
|
| 1273 |
if (private->state & GDK_WINDOW_STATE_ABOVE) |
| 1274 |
{ |
| 1275 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1276 |
"_NET_WM_STATE_ABOVE"); |
| 1277 |
++i; |
| 1278 |
} |
| 1279 |
|
| 1280 |
if (private->state & GDK_WINDOW_STATE_BELOW) |
| 1281 |
{ |
| 1282 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1283 |
"_NET_WM_STATE_BELOW"); |
| 1284 |
++i; |
| 1285 |
} |
| 1286 |
|
| 1287 |
if (private->state & GDK_WINDOW_STATE_STICKY) |
| 1288 |
{ |
| 1289 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1290 |
"_NET_WM_STATE_STICKY"); |
| 1291 |
++i; |
| 1292 |
toplevel->have_sticky = TRUE; |
| 1293 |
} |
| 1294 |
|
| 1295 |
if (private->state & GDK_WINDOW_STATE_FULLSCREEN) |
| 1296 |
{ |
| 1297 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1298 |
"_NET_WM_STATE_FULLSCREEN"); |
| 1299 |
++i; |
| 1300 |
toplevel->have_fullscreen = TRUE; |
| 1301 |
} |
| 1302 |
|
| 1303 |
if (private->modal_hint) |
| 1304 |
{ |
| 1305 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1306 |
"_NET_WM_STATE_MODAL"); |
| 1307 |
++i; |
| 1308 |
} |
| 1309 |
|
| 1310 |
if (toplevel->skip_taskbar_hint) |
| 1311 |
{ |
| 1312 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1313 |
"_NET_WM_STATE_SKIP_TASKBAR"); |
| 1314 |
++i; |
| 1315 |
} |
| 1316 |
|
| 1317 |
if (toplevel->skip_pager_hint) |
| 1318 |
{ |
| 1319 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1320 |
"_NET_WM_STATE_SKIP_PAGER"); |
| 1321 |
++i; |
| 1322 |
} |
| 1323 |
|
| 1324 |
if (private->state & GDK_WINDOW_STATE_ICONIFIED) |
| 1325 |
{ |
| 1326 |
atoms[i] = gdk_x11_get_xatom_by_name_for_display (display, |
| 1327 |
"_NET_WM_STATE_HIDDEN"); |
| 1328 |
++i; |
| 1329 |
toplevel->have_hidden = TRUE; |
| 1330 |
} |
| 1331 |
|
| 1332 |
if (i > 0) |
| 1333 |
{ |
| 1334 |
XChangeProperty (xdisplay, |
| 1335 |
xwindow, |
| 1336 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"), |
| 1337 |
XA_ATOM, 32, PropModeReplace, |
| 1338 |
(guchar*) atoms, i); |
| 1339 |
} |
| 1340 |
else |
| 1341 |
{ |
| 1342 |
XDeleteProperty (xdisplay, |
| 1343 |
xwindow, |
| 1344 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE")); |
| 1345 |
} |
| 1346 |
|
| 1347 |
if (private->state & GDK_WINDOW_STATE_STICKY) |
| 1348 |
{ |
| 1349 |
atoms[0] = 0xFFFFFFFF; |
| 1350 |
XChangeProperty (xdisplay, |
| 1351 |
xwindow, |
| 1352 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"), |
| 1353 |
XA_CARDINAL, 32, PropModeReplace, |
| 1354 |
(guchar*) atoms, 1); |
| 1355 |
toplevel->on_all_desktops = TRUE; |
| 1356 |
} |
| 1357 |
else |
| 1358 |
{ |
| 1359 |
XDeleteProperty (xdisplay, |
| 1360 |
xwindow, |
| 1361 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP")); |
| 1362 |
} |
| 1363 |
|
| 1364 |
toplevel->map_serial = NextRequest (xdisplay); |
| 1365 |
} |
| 1366 |
|
| 1367 |
static void |
| 1368 |
gdk_window_x11_show (GdkWindow *window, gboolean already_mapped) |
| 1369 |
{ |
| 1370 |
GdkWindowObject *private = (GdkWindowObject*) window; |
| 1371 |
GdkDisplay *display; |
| 1372 |
GdkDisplayX11 *display_x11; |
| 1373 |
GdkToplevelX11 *toplevel; |
| 1374 |
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 1375 |
Display *xdisplay = GDK_WINDOW_XDISPLAY (window); |
| 1376 |
Window xwindow = GDK_WINDOW_XID (window); |
| 1377 |
gboolean unset_bg; |
| 1378 |
|
| 1379 |
if (!already_mapped) |
| 1380 |
set_initial_hints (window); |
| 1381 |
|
| 1382 |
if (WINDOW_IS_TOPLEVEL (window)) |
| 1383 |
{ |
| 1384 |
display = gdk_drawable_get_display (window); |
| 1385 |
display_x11 = GDK_DISPLAY_X11 (display); |
| 1386 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 1387 |
|
| 1388 |
if (toplevel->user_time != 0 && |
| 1389 |
display_x11->user_time != 0 && |
| 1390 |
XSERVER_TIME_IS_LATER (display_x11->user_time, toplevel->user_time)) |
| 1391 |
gdk_x11_window_set_user_time (window, display_x11->user_time); |
| 1392 |
} |
| 1393 |
|
| 1394 |
unset_bg = !private->input_only && |
| 1395 |
(private->window_type == GDK_WINDOW_CHILD || |
| 1396 |
impl->override_redirect) && |
| 1397 |
gdk_window_is_viewable (window); |
| 1398 |
|
| 1399 |
if (unset_bg) |
| 1400 |
_gdk_x11_window_tmp_unset_bg (window, TRUE); |
| 1401 |
|
| 1402 |
XMapWindow (xdisplay, xwindow); |
| 1403 |
|
| 1404 |
if (unset_bg) |
| 1405 |
_gdk_x11_window_tmp_reset_bg (window, TRUE); |
| 1406 |
} |
| 1407 |
|
| 1408 |
static void |
| 1409 |
pre_unmap (GdkWindow *window) |
| 1410 |
{ |
| 1411 |
GdkWindow *start_window = NULL; |
| 1412 |
GdkWindowObject *private = (GdkWindowObject *)window; |
| 1413 |
|
| 1414 |
if (private->input_only) |
| 1415 |
return; |
| 1416 |
|
| 1417 |
if (private->window_type == GDK_WINDOW_CHILD) |
| 1418 |
start_window = _gdk_window_get_impl_window ((GdkWindow *)private->parent); |
| 1419 |
else if (private->window_type == GDK_WINDOW_TEMP) |
| 1420 |
start_window = get_root (window); |
| 1421 |
|
| 1422 |
if (start_window) |
| 1423 |
_gdk_x11_window_tmp_unset_bg (start_window, TRUE); |
| 1424 |
} |
| 1425 |
|
| 1426 |
static void |
| 1427 |
post_unmap (GdkWindow *window) |
| 1428 |
{ |
| 1429 |
GdkWindow *start_window = NULL; |
| 1430 |
GdkWindowObject *private = (GdkWindowObject *)window; |
| 1431 |
|
| 1432 |
if (private->input_only) |
| 1433 |
return; |
| 1434 |
|
| 1435 |
if (private->window_type == GDK_WINDOW_CHILD) |
| 1436 |
start_window = _gdk_window_get_impl_window ((GdkWindow *)private->parent); |
| 1437 |
else if (private->window_type == GDK_WINDOW_TEMP) |
| 1438 |
start_window = get_root (window); |
| 1439 |
|
| 1440 |
if (start_window) |
| 1441 |
{ |
| 1442 |
_gdk_x11_window_tmp_reset_bg (start_window, TRUE); |
| 1443 |
|
| 1444 |
if (private->window_type == GDK_WINDOW_CHILD && private->parent) |
| 1445 |
{ |
| 1446 |
GdkRectangle invalid_rect; |
| 1447 |
|
| 1448 |
gdk_window_get_position (window, &invalid_rect.x, &invalid_rect.y); |
| 1449 |
gdk_drawable_get_size (GDK_DRAWABLE (window), |
| 1450 |
&invalid_rect.width, &invalid_rect.height); |
| 1451 |
gdk_window_invalidate_rect ((GdkWindow *)private->parent, |
| 1452 |
&invalid_rect, TRUE); |
| 1453 |
} |
| 1454 |
} |
| 1455 |
} |
| 1456 |
|
| 1457 |
static void |
| 1458 |
gdk_window_x11_hide (GdkWindow *window) |
| 1459 |
{ |
| 1460 |
GdkWindowObject *private; |
| 1461 |
|
| 1462 |
private = (GdkWindowObject*) window; |
| 1463 |
|
| 1464 |
/* We'll get the unmap notify eventually, and handle it then, |
| 1465 |
* but checking here makes things more consistent if we are |
| 1466 |
* just doing stuff ourself. |
| 1467 |
*/ |
| 1468 |
_gdk_xgrab_check_unmap (window, |
| 1469 |
NextRequest (GDK_WINDOW_XDISPLAY (window))); |
| 1470 |
|
| 1471 |
/* You can't simply unmap toplevel windows. */ |
| 1472 |
switch (private->window_type) |
| 1473 |
{ |
| 1474 |
case GDK_WINDOW_TOPLEVEL: |
| 1475 |
case GDK_WINDOW_DIALOG: |
| 1476 |
case GDK_WINDOW_TEMP: /* ? */ |
| 1477 |
gdk_window_withdraw (window); |
| 1478 |
return; |
| 1479 |
|
| 1480 |
case GDK_WINDOW_FOREIGN: |
| 1481 |
case GDK_WINDOW_ROOT: |
| 1482 |
case GDK_WINDOW_CHILD: |
| 1483 |
break; |
| 1484 |
} |
| 1485 |
|
| 1486 |
_gdk_window_clear_update_area (window); |
| 1487 |
|
| 1488 |
pre_unmap (window); |
| 1489 |
XUnmapWindow (GDK_WINDOW_XDISPLAY (window), |
| 1490 |
GDK_WINDOW_XID (window)); |
| 1491 |
post_unmap (window); |
| 1492 |
} |
| 1493 |
|
| 1494 |
static void |
| 1495 |
gdk_window_x11_withdraw (GdkWindow *window) |
| 1496 |
{ |
| 1497 |
GdkWindowObject *private; |
| 1498 |
|
| 1499 |
private = (GdkWindowObject*) window; |
| 1500 |
if (!private->destroyed) |
| 1501 |
{ |
| 1502 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 1503 |
gdk_synthesize_window_state (window, |
| 1504 |
0, |
| 1505 |
GDK_WINDOW_STATE_WITHDRAWN); |
| 1506 |
|
| 1507 |
g_assert (!GDK_WINDOW_IS_MAPPED (window)); |
| 1508 |
|
| 1509 |
pre_unmap (window); |
| 1510 |
|
| 1511 |
XWithdrawWindow (GDK_WINDOW_XDISPLAY (window), |
| 1512 |
GDK_WINDOW_XID (window), 0); |
| 1513 |
|
| 1514 |
post_unmap (window); |
| 1515 |
} |
| 1516 |
} |
| 1517 |
|
| 1518 |
static inline void |
| 1519 |
window_x11_move (GdkWindow *window, |
| 1520 |
gint x, |
| 1521 |
gint y) |
| 1522 |
{ |
| 1523 |
GdkWindowObject *private = (GdkWindowObject *) window; |
| 1524 |
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 1525 |
|
| 1526 |
if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD) |
| 1527 |
{ |
| 1528 |
_gdk_window_move_resize_child (window, |
| 1529 |
x, y, |
| 1530 |
private->width, private->height); |
| 1531 |
} |
| 1532 |
else |
| 1533 |
{ |
| 1534 |
XMoveWindow (GDK_WINDOW_XDISPLAY (window), |
| 1535 |
GDK_WINDOW_XID (window), |
| 1536 |
x, y); |
| 1537 |
|
| 1538 |
if (impl->override_redirect) |
| 1539 |
{ |
| 1540 |
private->x = x; |
| 1541 |
private->y = y; |
| 1542 |
} |
| 1543 |
} |
| 1544 |
} |
| 1545 |
|
| 1546 |
static inline void |
| 1547 |
window_x11_resize (GdkWindow *window, |
| 1548 |
gint width, |
| 1549 |
gint height) |
| 1550 |
{ |
| 1551 |
GdkWindowObject *private = (GdkWindowObject *) window; |
| 1552 |
|
| 1553 |
if (width < 1) |
| 1554 |
width = 1; |
| 1555 |
|
| 1556 |
if (height < 1) |
| 1557 |
height = 1; |
| 1558 |
|
| 1559 |
if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD) |
| 1560 |
{ |
| 1561 |
_gdk_window_move_resize_child (window, |
| 1562 |
private->x, private->y, |
| 1563 |
width, height); |
| 1564 |
} |
| 1565 |
else |
| 1566 |
{ |
| 1567 |
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 1568 |
|
| 1569 |
XResizeWindow (GDK_WINDOW_XDISPLAY (window), |
| 1570 |
GDK_WINDOW_XID (window), |
| 1571 |
width, height); |
| 1572 |
|
| 1573 |
if (impl->override_redirect) |
| 1574 |
{ |
| 1575 |
private->width = width; |
| 1576 |
private->height = height; |
| 1577 |
_gdk_x11_drawable_update_size (private->impl); |
| 1578 |
} |
| 1579 |
else |
| 1580 |
{ |
| 1581 |
if (width != private->width || height != private->height) |
| 1582 |
private->resize_count += 1; |
| 1583 |
} |
| 1584 |
} |
| 1585 |
|
| 1586 |
_gdk_x11_drawable_update_size (private->impl); |
| 1587 |
} |
| 1588 |
|
| 1589 |
static inline void |
| 1590 |
window_x11_move_resize (GdkWindow *window, |
| 1591 |
gint x, |
| 1592 |
gint y, |
| 1593 |
gint width, |
| 1594 |
gint height) |
| 1595 |
{ |
| 1596 |
GdkWindowObject *private = (GdkWindowObject *) window;; |
| 1597 |
|
| 1598 |
if (width < 1) |
| 1599 |
width = 1; |
| 1600 |
|
| 1601 |
if (height < 1) |
| 1602 |
height = 1; |
| 1603 |
|
| 1604 |
if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD) |
| 1605 |
{ |
| 1606 |
_gdk_window_move_resize_child (window, x, y, width, height); |
| 1607 |
_gdk_x11_drawable_update_size (private->impl); |
| 1608 |
} |
| 1609 |
else |
| 1610 |
{ |
| 1611 |
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 1612 |
|
| 1613 |
XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window), |
| 1614 |
GDK_WINDOW_XID (window), |
| 1615 |
x, y, width, height); |
| 1616 |
|
| 1617 |
if (impl->override_redirect) |
| 1618 |
{ |
| 1619 |
private->x = x; |
| 1620 |
private->y = y; |
| 1621 |
|
| 1622 |
private->width = width; |
| 1623 |
private->height = height; |
| 1624 |
|
| 1625 |
_gdk_x11_drawable_update_size (private->impl); |
| 1626 |
} |
| 1627 |
else |
| 1628 |
{ |
| 1629 |
if (width != private->width || height != private->height) |
| 1630 |
private->resize_count += 1; |
| 1631 |
} |
| 1632 |
} |
| 1633 |
} |
| 1634 |
|
| 1635 |
static void |
| 1636 |
gdk_window_x11_move_resize (GdkWindow *window, |
| 1637 |
gboolean with_move, |
| 1638 |
gint x, |
| 1639 |
gint y, |
| 1640 |
gint width, |
| 1641 |
gint height) |
| 1642 |
{ |
| 1643 |
if (with_move && (width < 0 && height < 0)) |
| 1644 |
window_x11_move (window, x, y); |
| 1645 |
else |
| 1646 |
{ |
| 1647 |
if (with_move) |
| 1648 |
window_x11_move_resize (window, x, y, width, height); |
| 1649 |
else |
| 1650 |
window_x11_resize (window, width, height); |
| 1651 |
} |
| 1652 |
} |
| 1653 |
|
| 1654 |
static gboolean |
| 1655 |
gdk_window_x11_reparent (GdkWindow *window, |
| 1656 |
GdkWindow *new_parent, |
| 1657 |
gint x, |
| 1658 |
gint y) |
| 1659 |
{ |
| 1660 |
GdkWindowObject *window_private; |
| 1661 |
GdkWindowObject *parent_private; |
| 1662 |
GdkWindowImplX11 *impl; |
| 1663 |
|
| 1664 |
window_private = (GdkWindowObject*) window; |
| 1665 |
parent_private = (GdkWindowObject*) new_parent; |
| 1666 |
impl = GDK_WINDOW_IMPL_X11 (window_private->impl); |
| 1667 |
|
| 1668 |
_gdk_x11_window_tmp_unset_bg (window, TRUE); |
| 1669 |
_gdk_x11_window_tmp_unset_parent_bg (window); |
| 1670 |
XReparentWindow (GDK_WINDOW_XDISPLAY (window), |
| 1671 |
GDK_WINDOW_XID (window), |
| 1672 |
GDK_WINDOW_XID (new_parent), |
| 1673 |
parent_private->abs_x + x, parent_private->abs_y + y); |
| 1674 |
_gdk_x11_window_tmp_reset_parent_bg (window); |
| 1675 |
_gdk_x11_window_tmp_reset_bg (window, TRUE); |
| 1676 |
|
| 1677 |
if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN) |
| 1678 |
new_parent = gdk_screen_get_root_window (GDK_WINDOW_SCREEN (window)); |
| 1679 |
|
| 1680 |
window_private->parent = parent_private; |
| 1681 |
|
| 1682 |
/* Switch the window type as appropriate */ |
| 1683 |
|
| 1684 |
switch (GDK_WINDOW_TYPE (new_parent)) |
| 1685 |
{ |
| 1686 |
case GDK_WINDOW_ROOT: |
| 1687 |
case GDK_WINDOW_FOREIGN: |
| 1688 |
/* Reparenting to toplevel */ |
| 1689 |
|
| 1690 |
if (!WINDOW_IS_TOPLEVEL (window) && |
| 1691 |
GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN) |
| 1692 |
{ |
| 1693 |
/* This is also done in common code at a later stage, but we |
| 1694 |
need it in setup_toplevel, so do it here too */ |
| 1695 |
if (window_private->toplevel_window_type != -1) |
| 1696 |
GDK_WINDOW_TYPE (window) = window_private->toplevel_window_type; |
| 1697 |
else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD) |
| 1698 |
GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL; |
| 1699 |
|
| 1700 |
/* Wasn't a toplevel, set up */ |
| 1701 |
setup_toplevel_window (window, new_parent); |
| 1702 |
} |
| 1703 |
|
| 1704 |
break; |
| 1705 |
|
| 1706 |
case GDK_WINDOW_TOPLEVEL: |
| 1707 |
case GDK_WINDOW_CHILD: |
| 1708 |
case GDK_WINDOW_DIALOG: |
| 1709 |
case GDK_WINDOW_TEMP: |
| 1710 |
if (WINDOW_IS_TOPLEVEL (window) && |
| 1711 |
impl->toplevel) |
| 1712 |
{ |
| 1713 |
if (impl->toplevel->focus_window) |
| 1714 |
{ |
| 1715 |
XDestroyWindow (GDK_WINDOW_XDISPLAY (window), impl->toplevel->focus_window); |
| 1716 |
_gdk_xid_table_remove (GDK_WINDOW_DISPLAY (window), impl->toplevel->focus_window); |
| 1717 |
} |
| 1718 |
|
| 1719 |
gdk_toplevel_x11_free_contents (GDK_WINDOW_DISPLAY (window), |
| 1720 |
impl->toplevel); |
| 1721 |
g_free (impl->toplevel); |
| 1722 |
impl->toplevel = NULL; |
| 1723 |
} |
| 1724 |
} |
| 1725 |
|
| 1726 |
return FALSE; |
| 1727 |
} |
| 1728 |
|
| 1729 |
static void |
| 1730 |
gdk_window_x11_clear_region (GdkWindow *window, |
| 1731 |
GdkRegion *region, |
| 1732 |
gboolean send_expose) |
| 1733 |
{ |
| 1734 |
GdkRectangle *rectangles; |
| 1735 |
int n_rectangles, i; |
| 1736 |
|
| 1737 |
gdk_region_get_rectangles (region, |
| 1738 |
&rectangles, |
| 1739 |
&n_rectangles); |
| 1740 |
|
| 1741 |
for (i = 0; i < n_rectangles; i++) |
| 1742 |
XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), |
| 1743 |
rectangles[i].x, rectangles[i].y, |
| 1744 |
rectangles[i].width, rectangles[i].height, |
| 1745 |
send_expose); |
| 1746 |
|
| 1747 |
g_free (rectangles); |
| 1748 |
} |
| 1749 |
|
| 1750 |
static void |
| 1751 |
gdk_window_x11_raise (GdkWindow *window) |
| 1752 |
{ |
| 1753 |
XRaiseWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window)); |
| 1754 |
} |
| 1755 |
|
| 1756 |
static void |
| 1757 |
gdk_window_x11_restack_under (GdkWindow *window, |
| 1758 |
GList *native_siblings /* in requested order, first is bottom-most */) |
| 1759 |
{ |
| 1760 |
Window *windows; |
| 1761 |
int n_windows, i; |
| 1762 |
GList *l; |
| 1763 |
|
| 1764 |
n_windows = g_list_length (native_siblings) + 1; |
| 1765 |
windows = g_new (Window, n_windows); |
| 1766 |
|
| 1767 |
windows[0] = GDK_WINDOW_XID (window); |
| 1768 |
/* Reverse order, as input order is bottom-most first */ |
| 1769 |
i = n_windows - 1; |
| 1770 |
for (l = native_siblings; l != NULL; l = l->next) |
| 1771 |
windows[i--] = GDK_WINDOW_XID (l->data); |
| 1772 |
|
| 1773 |
XRestackWindows (GDK_WINDOW_XDISPLAY (window), windows, n_windows); |
| 1774 |
|
| 1775 |
g_free (windows); |
| 1776 |
} |
| 1777 |
|
| 1778 |
static void |
| 1779 |
gdk_window_x11_restack_toplevel (GdkWindow *window, |
| 1780 |
GdkWindow *sibling, |
| 1781 |
gboolean above) |
| 1782 |
{ |
| 1783 |
XWindowChanges changes; |
| 1784 |
|
| 1785 |
changes.sibling = GDK_WINDOW_XID (sibling); |
| 1786 |
changes.stack_mode = above ? Above : Below; |
| 1787 |
XReconfigureWMWindow (GDK_WINDOW_XDISPLAY (window), |
| 1788 |
GDK_WINDOW_XID (window), |
| 1789 |
gdk_screen_get_number (GDK_WINDOW_SCREEN (window)), |
| 1790 |
CWStackMode | CWSibling, &changes); |
| 1791 |
} |
| 1792 |
|
| 1793 |
static void |
| 1794 |
gdk_window_x11_lower (GdkWindow *window) |
| 1795 |
{ |
| 1796 |
XLowerWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window)); |
| 1797 |
} |
| 1798 |
|
| 1799 |
/** |
| 1800 |
* gdk_x11_window_move_to_current_desktop: |
| 1801 |
* @window: a #GdkWindow |
| 1802 |
* |
| 1803 |
* Moves the window to the correct workspace when running under a |
| 1804 |
* window manager that supports multiple workspaces, as described |
| 1805 |
* in the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended |
| 1806 |
* Window Manager Hints</ulink>. Will not do anything if the |
| 1807 |
* window is already on all workspaces. |
| 1808 |
* |
| 1809 |
* Since: 2.8 |
| 1810 |
*/ |
| 1811 |
void |
| 1812 |
gdk_x11_window_move_to_current_desktop (GdkWindow *window) |
| 1813 |
{ |
| 1814 |
GdkToplevelX11 *toplevel; |
| 1815 |
|
| 1816 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1817 |
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD); |
| 1818 |
|
| 1819 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 1820 |
|
| 1821 |
if (toplevel->on_all_desktops) |
| 1822 |
return; |
| 1823 |
|
| 1824 |
move_to_current_desktop (window); |
| 1825 |
} |
| 1826 |
|
| 1827 |
static void |
| 1828 |
move_to_current_desktop (GdkWindow *window) |
| 1829 |
{ |
| 1830 |
if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window), |
| 1831 |
gdk_atom_intern_static_string ("_NET_WM_DESKTOP"))) |
| 1832 |
{ |
| 1833 |
Atom type; |
| 1834 |
gint format; |
| 1835 |
gulong nitems; |
| 1836 |
gulong bytes_after; |
| 1837 |
guchar *data; |
| 1838 |
gulong *current_desktop; |
| 1839 |
GdkDisplay *display; |
| 1840 |
|
| 1841 |
display = gdk_drawable_get_display (window); |
| 1842 |
|
| 1843 |
/* Get current desktop, then set it; this is a race, but not |
| 1844 |
* one that matters much in practice. |
| 1845 |
*/ |
| 1846 |
XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), |
| 1847 |
GDK_WINDOW_XROOTWIN (window), |
| 1848 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"), |
| 1849 |
0, G_MAXLONG, |
| 1850 |
False, XA_CARDINAL, &type, &format, &nitems, |
| 1851 |
&bytes_after, &data); |
| 1852 |
|
| 1853 |
if (type == XA_CARDINAL) |
| 1854 |
{ |
| 1855 |
XClientMessageEvent xclient; |
| 1856 |
current_desktop = (gulong *)data; |
| 1857 |
|
| 1858 |
memset (&xclient, 0, sizeof (xclient)); |
| 1859 |
xclient.type = ClientMessage; |
| 1860 |
xclient.serial = 0; |
| 1861 |
xclient.send_event = True; |
| 1862 |
xclient.window = GDK_WINDOW_XWINDOW (window); |
| 1863 |
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"); |
| 1864 |
xclient.format = 32; |
| 1865 |
|
| 1866 |
xclient.data.l[0] = *current_desktop; |
| 1867 |
xclient.data.l[1] = 0; |
| 1868 |
xclient.data.l[2] = 0; |
| 1869 |
xclient.data.l[3] = 0; |
| 1870 |
xclient.data.l[4] = 0; |
| 1871 |
|
| 1872 |
XSendEvent (GDK_DISPLAY_XDISPLAY (display), |
| 1873 |
GDK_WINDOW_XROOTWIN (window), |
| 1874 |
False, |
| 1875 |
SubstructureRedirectMask | SubstructureNotifyMask, |
| 1876 |
(XEvent *)&xclient); |
| 1877 |
|
| 1878 |
XFree (current_desktop); |
| 1879 |
} |
| 1880 |
} |
| 1881 |
} |
| 1882 |
|
| 1883 |
/** |
| 1884 |
* gdk_window_focus: |
| 1885 |
* @window: a #GdkWindow |
| 1886 |
* @timestamp: timestamp of the event triggering the window focus |
| 1887 |
* |
| 1888 |
* Sets keyboard focus to @window. In most cases, gtk_window_present() |
| 1889 |
* should be used on a #GtkWindow, rather than calling this function. |
| 1890 |
* |
| 1891 |
**/ |
| 1892 |
void |
| 1893 |
gdk_window_focus (GdkWindow *window, |
| 1894 |
guint32 timestamp) |
| 1895 |
{ |
| 1896 |
GdkDisplay *display; |
| 1897 |
|
| 1898 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1899 |
|
| 1900 |
if (GDK_WINDOW_DESTROYED (window) || |
| 1901 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 1902 |
return; |
| 1903 |
|
| 1904 |
display = GDK_WINDOW_DISPLAY (window); |
| 1905 |
|
| 1906 |
if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window), |
| 1907 |
gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW"))) |
| 1908 |
{ |
| 1909 |
XClientMessageEvent xclient; |
| 1910 |
|
| 1911 |
memset (&xclient, 0, sizeof (xclient)); |
| 1912 |
xclient.type = ClientMessage; |
| 1913 |
xclient.window = GDK_WINDOW_XWINDOW (window); |
| 1914 |
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, |
| 1915 |
"_NET_ACTIVE_WINDOW"); |
| 1916 |
xclient.format = 32; |
| 1917 |
xclient.data.l[0] = 1; /* requestor type; we're an app */ |
| 1918 |
xclient.data.l[1] = timestamp; |
| 1919 |
xclient.data.l[2] = None; /* currently active window */ |
| 1920 |
xclient.data.l[3] = 0; |
| 1921 |
xclient.data.l[4] = 0; |
| 1922 |
|
| 1923 |
XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False, |
| 1924 |
SubstructureRedirectMask | SubstructureNotifyMask, |
| 1925 |
(XEvent *)&xclient); |
| 1926 |
} |
| 1927 |
else |
| 1928 |
{ |
| 1929 |
XRaiseWindow (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window)); |
| 1930 |
|
| 1931 |
/* There is no way of knowing reliably whether we are viewable; |
| 1932 |
* _gdk_x11_set_input_focus_safe() traps errors asynchronously. |
| 1933 |
*/ |
| 1934 |
_gdk_x11_set_input_focus_safe (display, GDK_WINDOW_XID (window), |
| 1935 |
RevertToParent, |
| 1936 |
timestamp); |
| 1937 |
} |
| 1938 |
} |
| 1939 |
|
| 1940 |
/** |
| 1941 |
* gdk_window_set_hints: |
| 1942 |
* @window: a #GdkWindow |
| 1943 |
* @x: ignored field, does not matter |
| 1944 |
* @y: ignored field, does not matter |
| 1945 |
* @min_width: minimum width hint |
| 1946 |
* @min_height: minimum height hint |
| 1947 |
* @max_width: max width hint |
| 1948 |
* @max_height: max height hint |
| 1949 |
* @flags: logical OR of GDK_HINT_POS, GDK_HINT_MIN_SIZE, and/or GDK_HINT_MAX_SIZE |
| 1950 |
* |
| 1951 |
* This function is broken and useless and you should ignore it. |
| 1952 |
* If using GTK+, use functions such as gtk_window_resize(), gtk_window_set_size_request(), |
| 1953 |
* gtk_window_move(), gtk_window_parse_geometry(), and gtk_window_set_geometry_hints(), |
| 1954 |
* depending on what you're trying to do. |
| 1955 |
* |
| 1956 |
* If using GDK directly, use gdk_window_set_geometry_hints(). |
| 1957 |
* |
| 1958 |
**/ |
| 1959 |
void |
| 1960 |
gdk_window_set_hints (GdkWindow *window, |
| 1961 |
gint x, |
| 1962 |
gint y, |
| 1963 |
gint min_width, |
| 1964 |
gint min_height, |
| 1965 |
gint max_width, |
| 1966 |
gint max_height, |
| 1967 |
gint flags) |
| 1968 |
{ |
| 1969 |
XSizeHints size_hints; |
| 1970 |
|
| 1971 |
if (GDK_WINDOW_DESTROYED (window) || |
| 1972 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 1973 |
return; |
| 1974 |
|
| 1975 |
size_hints.flags = 0; |
| 1976 |
|
| 1977 |
if (flags & GDK_HINT_POS) |
| 1978 |
{ |
| 1979 |
size_hints.flags |= PPosition; |
| 1980 |
size_hints.x = x; |
| 1981 |
size_hints.y = y; |
| 1982 |
} |
| 1983 |
|
| 1984 |
if (flags & GDK_HINT_MIN_SIZE) |
| 1985 |
{ |
| 1986 |
size_hints.flags |= PMinSize; |
| 1987 |
size_hints.min_width = min_width; |
| 1988 |
size_hints.min_height = min_height; |
| 1989 |
} |
| 1990 |
|
| 1991 |
if (flags & GDK_HINT_MAX_SIZE) |
| 1992 |
{ |
| 1993 |
size_hints.flags |= PMaxSize; |
| 1994 |
size_hints.max_width = max_width; |
| 1995 |
size_hints.max_height = max_height; |
| 1996 |
} |
| 1997 |
|
| 1998 |
/* FIXME: Would it be better to delete this property if |
| 1999 |
* flags == 0? It would save space on the server |
| 2000 |
*/ |
| 2001 |
XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window), |
| 2002 |
GDK_WINDOW_XID (window), |
| 2003 |
&size_hints); |
| 2004 |
} |
| 2005 |
|
| 2006 |
/** |
| 2007 |
* gdk_window_set_type_hint: |
| 2008 |
* @window: A toplevel #GdkWindow |
| 2009 |
* @hint: A hint of the function this window will have |
| 2010 |
* |
| 2011 |
* The application can use this call to provide a hint to the window |
| 2012 |
* manager about the functionality of a window. The window manager |
| 2013 |
* can use this information when determining the decoration and behaviour |
| 2014 |
* of the window. |
| 2015 |
* |
| 2016 |
* The hint must be set before the window is mapped. |
| 2017 |
**/ |
| 2018 |
void |
| 2019 |
gdk_window_set_type_hint (GdkWindow *window, |
| 2020 |
GdkWindowTypeHint hint) |
| 2021 |
{ |
| 2022 |
GdkDisplay *display; |
| 2023 |
Atom atom; |
| 2024 |
|
| 2025 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2026 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2027 |
return; |
| 2028 |
|
| 2029 |
display = gdk_drawable_get_display (window); |
| 2030 |
|
| 2031 |
switch (hint) |
| 2032 |
{ |
| 2033 |
case GDK_WINDOW_TYPE_HINT_DIALOG: |
| 2034 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG"); |
| 2035 |
break; |
| 2036 |
case GDK_WINDOW_TYPE_HINT_MENU: |
| 2037 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU"); |
| 2038 |
break; |
| 2039 |
case GDK_WINDOW_TYPE_HINT_TOOLBAR: |
| 2040 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR"); |
| 2041 |
break; |
| 2042 |
case GDK_WINDOW_TYPE_HINT_UTILITY: |
| 2043 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY"); |
| 2044 |
break; |
| 2045 |
case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN: |
| 2046 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH"); |
| 2047 |
break; |
| 2048 |
case GDK_WINDOW_TYPE_HINT_DOCK: |
| 2049 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK"); |
| 2050 |
break; |
| 2051 |
case GDK_WINDOW_TYPE_HINT_DESKTOP: |
| 2052 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP"); |
| 2053 |
break; |
| 2054 |
case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU: |
| 2055 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"); |
| 2056 |
break; |
| 2057 |
case GDK_WINDOW_TYPE_HINT_POPUP_MENU: |
| 2058 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU"); |
| 2059 |
break; |
| 2060 |
case GDK_WINDOW_TYPE_HINT_TOOLTIP: |
| 2061 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP"); |
| 2062 |
break; |
| 2063 |
case GDK_WINDOW_TYPE_HINT_NOTIFICATION: |
| 2064 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION"); |
| 2065 |
break; |
| 2066 |
case GDK_WINDOW_TYPE_HINT_COMBO: |
| 2067 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO"); |
| 2068 |
break; |
| 2069 |
case GDK_WINDOW_TYPE_HINT_DND: |
| 2070 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND"); |
| 2071 |
break; |
| 2072 |
default: |
| 2073 |
g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint); |
| 2074 |
/* Fall thru */ |
| 2075 |
case GDK_WINDOW_TYPE_HINT_NORMAL: |
| 2076 |
atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NORMAL"); |
| 2077 |
break; |
| 2078 |
} |
| 2079 |
|
| 2080 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), |
| 2081 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"), |
| 2082 |
XA_ATOM, 32, PropModeReplace, |
| 2083 |
(guchar *)&atom, 1); |
| 2084 |
} |
| 2085 |
|
| 2086 |
/** |
| 2087 |
* gdk_window_get_type_hint: |
| 2088 |
* @window: A toplevel #GdkWindow |
| 2089 |
* |
| 2090 |
* This function returns the type hint set for a window. |
| 2091 |
* |
| 2092 |
* Return value: The type hint set for @window |
| 2093 |
* |
| 2094 |
* Since: 2.10 |
| 2095 |
**/ |
| 2096 |
GdkWindowTypeHint |
| 2097 |
gdk_window_get_type_hint (GdkWindow *window) |
| 2098 |
{ |
| 2099 |
GdkDisplay *display; |
| 2100 |
GdkWindowTypeHint type; |
| 2101 |
Atom type_return; |
| 2102 |
gint format_return; |
| 2103 |
gulong nitems_return; |
| 2104 |
gulong bytes_after_return; |
| 2105 |
guchar *data = NULL; |
| 2106 |
|
| 2107 |
g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL); |
| 2108 |
|
| 2109 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2110 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2111 |
return GDK_WINDOW_TYPE_HINT_NORMAL; |
| 2112 |
|
| 2113 |
type = GDK_WINDOW_TYPE_HINT_NORMAL; |
| 2114 |
|
| 2115 |
display = gdk_drawable_get_display (window); |
| 2116 |
|
| 2117 |
if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), |
| 2118 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"), |
| 2119 |
0, G_MAXLONG, False, XA_ATOM, &type_return, |
| 2120 |
&format_return, &nitems_return, &bytes_after_return, |
| 2121 |
&data) == Success) |
| 2122 |
{ |
| 2123 |
if ((type_return == XA_ATOM) && (format_return == 32) && |
| 2124 |
(data) && (nitems_return == 1)) |
| 2125 |
{ |
| 2126 |
Atom atom = *(Atom*)data; |
| 2127 |
|
| 2128 |
if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DIALOG")) |
| 2129 |
type = GDK_WINDOW_TYPE_HINT_DIALOG; |
| 2130 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_MENU")) |
| 2131 |
type = GDK_WINDOW_TYPE_HINT_MENU; |
| 2132 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLBAR")) |
| 2133 |
type = GDK_WINDOW_TYPE_HINT_TOOLBAR; |
| 2134 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_UTILITY")) |
| 2135 |
type = GDK_WINDOW_TYPE_HINT_UTILITY; |
| 2136 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_SPLASH")) |
| 2137 |
type = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN; |
| 2138 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DOCK")) |
| 2139 |
type = GDK_WINDOW_TYPE_HINT_DOCK; |
| 2140 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DESKTOP")) |
| 2141 |
type = GDK_WINDOW_TYPE_HINT_DESKTOP; |
| 2142 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU")) |
| 2143 |
type = GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU; |
| 2144 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_POPUP_MENU")) |
| 2145 |
type = GDK_WINDOW_TYPE_HINT_POPUP_MENU; |
| 2146 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_TOOLTIP")) |
| 2147 |
type = GDK_WINDOW_TYPE_HINT_TOOLTIP; |
| 2148 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_NOTIFICATION")) |
| 2149 |
type = GDK_WINDOW_TYPE_HINT_NOTIFICATION; |
| 2150 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_COMBO")) |
| 2151 |
type = GDK_WINDOW_TYPE_HINT_COMBO; |
| 2152 |
else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE_DND")) |
| 2153 |
type = GDK_WINDOW_TYPE_HINT_DND; |
| 2154 |
} |
| 2155 |
|
| 2156 |
if (type_return != None && data != NULL) |
| 2157 |
XFree (data); |
| 2158 |
} |
| 2159 |
|
| 2160 |
return type; |
| 2161 |
} |
| 2162 |
|
| 2163 |
static void |
| 2164 |
gdk_wmspec_change_state (gboolean add, |
| 2165 |
GdkWindow *window, |
| 2166 |
GdkAtom state1, |
| 2167 |
GdkAtom state2) |
| 2168 |
{ |
| 2169 |
GdkDisplay *display = GDK_WINDOW_DISPLAY (window); |
| 2170 |
XClientMessageEvent xclient; |
| 2171 |
|
| 2172 |
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */ |
| 2173 |
#define _NET_WM_STATE_ADD 1 /* add/set property */ |
| 2174 |
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */ |
| 2175 |
|
| 2176 |
memset (&xclient, 0, sizeof (xclient)); |
| 2177 |
xclient.type = ClientMessage; |
| 2178 |
xclient.window = GDK_WINDOW_XID (window); |
| 2179 |
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"); |
| 2180 |
xclient.format = 32; |
| 2181 |
xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; |
| 2182 |
xclient.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, state1); |
| 2183 |
xclient.data.l[2] = gdk_x11_atom_to_xatom_for_display (display, state2); |
| 2184 |
xclient.data.l[3] = 0; |
| 2185 |
xclient.data.l[4] = 0; |
| 2186 |
|
| 2187 |
XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False, |
| 2188 |
SubstructureRedirectMask | SubstructureNotifyMask, |
| 2189 |
(XEvent *)&xclient); |
| 2190 |
} |
| 2191 |
|
| 2192 |
/** |
| 2193 |
* gdk_window_set_modal_hint: |
| 2194 |
* @window: A toplevel #GdkWindow |
| 2195 |
* @modal: %TRUE if the window is modal, %FALSE otherwise. |
| 2196 |
* |
| 2197 |
* The application can use this hint to tell the window manager |
| 2198 |
* that a certain window has modal behaviour. The window manager |
| 2199 |
* can use this information to handle modal windows in a special |
| 2200 |
* way. |
| 2201 |
* |
| 2202 |
* You should only use this on windows for which you have |
| 2203 |
* previously called gdk_window_set_transient_for() |
| 2204 |
**/ |
| 2205 |
void |
| 2206 |
gdk_window_set_modal_hint (GdkWindow *window, |
| 2207 |
gboolean modal) |
| 2208 |
{ |
| 2209 |
GdkWindowObject *private; |
| 2210 |
|
| 2211 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2212 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2213 |
return; |
| 2214 |
|
| 2215 |
private = (GdkWindowObject*) window; |
| 2216 |
|
| 2217 |
private->modal_hint = modal; |
| 2218 |
|
| 2219 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 2220 |
gdk_wmspec_change_state (modal, window, |
| 2221 |
gdk_atom_intern_static_string ("_NET_WM_STATE_MODAL"), |
| 2222 |
GDK_NONE); |
| 2223 |
} |
| 2224 |
|
| 2225 |
/** |
| 2226 |
* gdk_window_set_skip_taskbar_hint: |
| 2227 |
* @window: a toplevel #GdkWindow |
| 2228 |
* @skips_taskbar: %TRUE to skip the taskbar |
| 2229 |
* |
| 2230 |
* Toggles whether a window should appear in a task list or window |
| 2231 |
* list. If a window's semantic type as specified with |
| 2232 |
* gdk_window_set_type_hint() already fully describes the window, this |
| 2233 |
* function should <emphasis>not</emphasis> be called in addition, |
| 2234 |
* instead you should allow the window to be treated according to |
| 2235 |
* standard policy for its semantic type. |
| 2236 |
* |
| 2237 |
* Since: 2.2 |
| 2238 |
**/ |
| 2239 |
void |
| 2240 |
gdk_window_set_skip_taskbar_hint (GdkWindow *window, |
| 2241 |
gboolean skips_taskbar) |
| 2242 |
{ |
| 2243 |
GdkToplevelX11 *toplevel; |
| 2244 |
|
| 2245 |
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD); |
| 2246 |
|
| 2247 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2248 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2249 |
return; |
| 2250 |
|
| 2251 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 2252 |
toplevel->skip_taskbar_hint = skips_taskbar; |
| 2253 |
|
| 2254 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 2255 |
gdk_wmspec_change_state (skips_taskbar, window, |
| 2256 |
gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_TASKBAR"), |
| 2257 |
GDK_NONE); |
| 2258 |
} |
| 2259 |
|
| 2260 |
/** |
| 2261 |
* gdk_window_set_skip_pager_hint: |
| 2262 |
* @window: a toplevel #GdkWindow |
| 2263 |
* @skips_pager: %TRUE to skip the pager |
| 2264 |
* |
| 2265 |
* Toggles whether a window should appear in a pager (workspace |
| 2266 |
* switcher, or other desktop utility program that displays a small |
| 2267 |
* thumbnail representation of the windows on the desktop). If a |
| 2268 |
* window's semantic type as specified with gdk_window_set_type_hint() |
| 2269 |
* already fully describes the window, this function should |
| 2270 |
* <emphasis>not</emphasis> be called in addition, instead you should |
| 2271 |
* allow the window to be treated according to standard policy for |
| 2272 |
* its semantic type. |
| 2273 |
* |
| 2274 |
* Since: 2.2 |
| 2275 |
**/ |
| 2276 |
void |
| 2277 |
gdk_window_set_skip_pager_hint (GdkWindow *window, |
| 2278 |
gboolean skips_pager) |
| 2279 |
{ |
| 2280 |
GdkToplevelX11 *toplevel; |
| 2281 |
|
| 2282 |
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD); |
| 2283 |
|
| 2284 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2285 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2286 |
return; |
| 2287 |
|
| 2288 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 2289 |
toplevel->skip_pager_hint = skips_pager; |
| 2290 |
|
| 2291 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 2292 |
gdk_wmspec_change_state (skips_pager, window, |
| 2293 |
gdk_atom_intern_static_string ("_NET_WM_STATE_SKIP_PAGER"), |
| 2294 |
GDK_NONE); |
| 2295 |
} |
| 2296 |
|
| 2297 |
/** |
| 2298 |
* gdk_window_set_urgency_hint: |
| 2299 |
* @window: a toplevel #GdkWindow |
| 2300 |
* @urgent: %TRUE if the window is urgent |
| 2301 |
* |
| 2302 |
* Toggles whether a window needs the user's |
| 2303 |
* urgent attention. |
| 2304 |
* |
| 2305 |
* Since: 2.8 |
| 2306 |
**/ |
| 2307 |
void |
| 2308 |
gdk_window_set_urgency_hint (GdkWindow *window, |
| 2309 |
gboolean urgent) |
| 2310 |
{ |
| 2311 |
GdkToplevelX11 *toplevel; |
| 2312 |
|
| 2313 |
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD); |
| 2314 |
|
| 2315 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2316 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2317 |
return; |
| 2318 |
|
| 2319 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 2320 |
toplevel->urgency_hint = urgent; |
| 2321 |
|
| 2322 |
update_wm_hints (window, FALSE); |
| 2323 |
} |
| 2324 |
|
| 2325 |
/** |
| 2326 |
* gdk_window_set_geometry_hints: |
| 2327 |
* @window: a toplevel #GdkWindow |
| 2328 |
* @geometry: geometry hints |
| 2329 |
* @geom_mask: bitmask indicating fields of @geometry to pay attention to |
| 2330 |
* |
| 2331 |
* Sets the geometry hints for @window. Hints flagged in @geom_mask |
| 2332 |
* are set, hints not flagged in @geom_mask are unset. |
| 2333 |
* To unset all hints, use a @geom_mask of 0 and a @geometry of %NULL. |
| 2334 |
* |
| 2335 |
* This function provides hints to the windowing system about |
| 2336 |
* acceptable sizes for a toplevel window. The purpose of |
| 2337 |
* this is to constrain user resizing, but the windowing system |
| 2338 |
* will typically (but is not required to) also constrain the |
| 2339 |
* current size of the window to the provided values and |
| 2340 |
* constrain programatic resizing via gdk_window_resize() or |
| 2341 |
* gdk_window_move_resize(). |
| 2342 |
* |
| 2343 |
* Note that on X11, this effect has no effect on windows |
| 2344 |
* of type %GDK_WINDOW_TEMP or windows where override redirect |
| 2345 |
* has been turned on via gdk_window_set_override_redirect() |
| 2346 |
* since these windows are not resizable by the user. |
| 2347 |
* |
| 2348 |
* Since you can't count on the windowing system doing the |
| 2349 |
* constraints for programmatic resizes, you should generally |
| 2350 |
* call gdk_window_constrain_size() yourself to determine |
| 2351 |
* appropriate sizes. |
| 2352 |
* |
| 2353 |
**/ |
| 2354 |
void |
| 2355 |
gdk_window_set_geometry_hints (GdkWindow *window, |
| 2356 |
const GdkGeometry *geometry, |
| 2357 |
GdkWindowHints geom_mask) |
| 2358 |
{ |
| 2359 |
XSizeHints size_hints; |
| 2360 |
|
| 2361 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2362 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2363 |
return; |
| 2364 |
|
| 2365 |
size_hints.flags = 0; |
| 2366 |
|
| 2367 |
if (geom_mask & GDK_HINT_POS) |
| 2368 |
{ |
| 2369 |
size_hints.flags |= PPosition; |
| 2370 |
/* We need to initialize the following obsolete fields because KWM |
| 2371 |
* apparently uses these fields if they are non-zero. |
| 2372 |
* #@#!#!$!. |
| 2373 |
*/ |
| 2374 |
size_hints.x = 0; |
| 2375 |
size_hints.y = 0; |
| 2376 |
} |
| 2377 |
|
| 2378 |
if (geom_mask & GDK_HINT_USER_POS) |
| 2379 |
{ |
| 2380 |
size_hints.flags |= USPosition; |
| 2381 |
} |
| 2382 |
|
| 2383 |
if (geom_mask & GDK_HINT_USER_SIZE) |
| 2384 |
{ |
| 2385 |
size_hints.flags |= USSize; |
| 2386 |
} |
| 2387 |
|
| 2388 |
if (geom_mask & GDK_HINT_MIN_SIZE) |
| 2389 |
{ |
| 2390 |
size_hints.flags |= PMinSize; |
| 2391 |
size_hints.min_width = geometry->min_width; |
| 2392 |
size_hints.min_height = geometry->min_height; |
| 2393 |
} |
| 2394 |
|
| 2395 |
if (geom_mask & GDK_HINT_MAX_SIZE) |
| 2396 |
{ |
| 2397 |
size_hints.flags |= PMaxSize; |
| 2398 |
size_hints.max_width = MAX (geometry->max_width, 1); |
| 2399 |
size_hints.max_height = MAX (geometry->max_height, 1); |
| 2400 |
} |
| 2401 |
|
| 2402 |
if (geom_mask & GDK_HINT_BASE_SIZE) |
| 2403 |
{ |
| 2404 |
size_hints.flags |= PBaseSize; |
| 2405 |
size_hints.base_width = geometry->base_width; |
| 2406 |
size_hints.base_height = geometry->base_height; |
| 2407 |
} |
| 2408 |
|
| 2409 |
if (geom_mask & GDK_HINT_RESIZE_INC) |
| 2410 |
{ |
| 2411 |
size_hints.flags |= PResizeInc; |
| 2412 |
size_hints.width_inc = geometry->width_inc; |
| 2413 |
size_hints.height_inc = geometry->height_inc; |
| 2414 |
} |
| 2415 |
|
| 2416 |
if (geom_mask & GDK_HINT_ASPECT) |
| 2417 |
{ |
| 2418 |
size_hints.flags |= PAspect; |
| 2419 |
if (geometry->min_aspect <= 1) |
| 2420 |
{ |
| 2421 |
size_hints.min_aspect.x = 65536 * geometry->min_aspect; |
| 2422 |
size_hints.min_aspect.y = 65536; |
| 2423 |
} |
| 2424 |
else |
| 2425 |
{ |
| 2426 |
size_hints.min_aspect.x = 65536; |
| 2427 |
size_hints.min_aspect.y = 65536 / geometry->min_aspect;; |
| 2428 |
} |
| 2429 |
if (geometry->max_aspect <= 1) |
| 2430 |
{ |
| 2431 |
size_hints.max_aspect.x = 65536 * geometry->max_aspect; |
| 2432 |
size_hints.max_aspect.y = 65536; |
| 2433 |
} |
| 2434 |
else |
| 2435 |
{ |
| 2436 |
size_hints.max_aspect.x = 65536; |
| 2437 |
size_hints.max_aspect.y = 65536 / geometry->max_aspect;; |
| 2438 |
} |
| 2439 |
} |
| 2440 |
|
| 2441 |
if (geom_mask & GDK_HINT_WIN_GRAVITY) |
| 2442 |
{ |
| 2443 |
size_hints.flags |= PWinGravity; |
| 2444 |
size_hints.win_gravity = geometry->win_gravity; |
| 2445 |
} |
| 2446 |
|
| 2447 |
/* FIXME: Would it be better to delete this property if |
| 2448 |
* geom_mask == 0? It would save space on the server |
| 2449 |
*/ |
| 2450 |
XSetWMNormalHints (GDK_WINDOW_XDISPLAY (window), |
| 2451 |
GDK_WINDOW_XID (window), |
| 2452 |
&size_hints); |
| 2453 |
} |
| 2454 |
|
| 2455 |
static void |
| 2456 |
gdk_window_get_geometry_hints (GdkWindow *window, |
| 2457 |
GdkGeometry *geometry, |
| 2458 |
GdkWindowHints *geom_mask) |
| 2459 |
{ |
| 2460 |
XSizeHints *size_hints; |
| 2461 |
glong junk_supplied_mask = 0; |
| 2462 |
|
| 2463 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2464 |
g_return_if_fail (geometry != NULL); |
| 2465 |
g_return_if_fail (geom_mask != NULL); |
| 2466 |
|
| 2467 |
*geom_mask = 0; |
| 2468 |
|
| 2469 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2470 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2471 |
return; |
| 2472 |
|
| 2473 |
size_hints = XAllocSizeHints (); |
| 2474 |
if (!size_hints) |
| 2475 |
return; |
| 2476 |
|
| 2477 |
if (!XGetWMNormalHints (GDK_WINDOW_XDISPLAY (window), |
| 2478 |
GDK_WINDOW_XID (window), |
| 2479 |
size_hints, |
| 2480 |
&junk_supplied_mask)) |
| 2481 |
size_hints->flags = 0; |
| 2482 |
|
| 2483 |
if (size_hints->flags & PMinSize) |
| 2484 |
{ |
| 2485 |
*geom_mask |= GDK_HINT_MIN_SIZE; |
| 2486 |
geometry->min_width = size_hints->min_width; |
| 2487 |
geometry->min_height = size_hints->min_height; |
| 2488 |
} |
| 2489 |
|
| 2490 |
if (size_hints->flags & PMaxSize) |
| 2491 |
{ |
| 2492 |
*geom_mask |= GDK_HINT_MAX_SIZE; |
| 2493 |
geometry->max_width = MAX (size_hints->max_width, 1); |
| 2494 |
geometry->max_height = MAX (size_hints->max_height, 1); |
| 2495 |
} |
| 2496 |
|
| 2497 |
if (size_hints->flags & PResizeInc) |
| 2498 |
{ |
| 2499 |
*geom_mask |= GDK_HINT_RESIZE_INC; |
| 2500 |
geometry->width_inc = size_hints->width_inc; |
| 2501 |
geometry->height_inc = size_hints->height_inc; |
| 2502 |
} |
| 2503 |
|
| 2504 |
if (size_hints->flags & PAspect) |
| 2505 |
{ |
| 2506 |
*geom_mask |= GDK_HINT_ASPECT; |
| 2507 |
|
| 2508 |
geometry->min_aspect = (gdouble) size_hints->min_aspect.x / (gdouble) size_hints->min_aspect.y; |
| 2509 |
geometry->max_aspect = (gdouble) size_hints->max_aspect.x / (gdouble) size_hints->max_aspect.y; |
| 2510 |
} |
| 2511 |
|
| 2512 |
if (size_hints->flags & PWinGravity) |
| 2513 |
{ |
| 2514 |
*geom_mask |= GDK_HINT_WIN_GRAVITY; |
| 2515 |
geometry->win_gravity = size_hints->win_gravity; |
| 2516 |
} |
| 2517 |
|
| 2518 |
XFree (size_hints); |
| 2519 |
} |
| 2520 |
|
| 2521 |
static gboolean |
| 2522 |
utf8_is_latin1 (const gchar *str) |
| 2523 |
{ |
| 2524 |
const char *p = str; |
| 2525 |
|
| 2526 |
while (*p) |
| 2527 |
{ |
| 2528 |
gunichar ch = g_utf8_get_char (p); |
| 2529 |
|
| 2530 |
if (ch > 0xff) |
| 2531 |
return FALSE; |
| 2532 |
|
| 2533 |
p = g_utf8_next_char (p); |
| 2534 |
} |
| 2535 |
|
| 2536 |
return TRUE; |
| 2537 |
} |
| 2538 |
|
| 2539 |
/* Set the property to @utf8_str as STRING if the @utf8_str is fully |
| 2540 |
* convertable to STRING, otherwise, set it as compound text |
| 2541 |
*/ |
| 2542 |
static void |
| 2543 |
set_text_property (GdkDisplay *display, |
| 2544 |
Window xwindow, |
| 2545 |
Atom property, |
| 2546 |
const gchar *utf8_str) |
| 2547 |
{ |
| 2548 |
gchar *prop_text = NULL; |
| 2549 |
Atom prop_type; |
| 2550 |
gint prop_length; |
| 2551 |
gint prop_format; |
| 2552 |
gboolean is_compound_text; |
| 2553 |
|
| 2554 |
if (utf8_is_latin1 (utf8_str)) |
| 2555 |
{ |
| 2556 |
prop_type = XA_STRING; |
| 2557 |
prop_text = gdk_utf8_to_string_target (utf8_str); |
| 2558 |
prop_length = prop_text ? strlen (prop_text) : 0; |
| 2559 |
prop_format = 8; |
| 2560 |
is_compound_text = FALSE; |
| 2561 |
} |
| 2562 |
else |
| 2563 |
{ |
| 2564 |
GdkAtom gdk_type; |
| 2565 |
|
| 2566 |
gdk_utf8_to_compound_text_for_display (display, |
| 2567 |
utf8_str, &gdk_type, &prop_format, |
| 2568 |
(guchar **)&prop_text, &prop_length); |
| 2569 |
prop_type = gdk_x11_atom_to_xatom_for_display (display, gdk_type); |
| 2570 |
is_compound_text = TRUE; |
| 2571 |
} |
| 2572 |
|
| 2573 |
if (prop_text) |
| 2574 |
{ |
| 2575 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), |
| 2576 |
xwindow, |
| 2577 |
property, |
| 2578 |
prop_type, prop_format, |
| 2579 |
PropModeReplace, (guchar *)prop_text, |
| 2580 |
prop_length); |
| 2581 |
|
| 2582 |
if (is_compound_text) |
| 2583 |
gdk_free_compound_text ((guchar *)prop_text); |
| 2584 |
else |
| 2585 |
g_free (prop_text); |
| 2586 |
} |
| 2587 |
} |
| 2588 |
|
| 2589 |
/* Set WM_NAME and _NET_WM_NAME |
| 2590 |
*/ |
| 2591 |
static void |
| 2592 |
set_wm_name (GdkDisplay *display, |
| 2593 |
Window xwindow, |
| 2594 |
const gchar *name) |
| 2595 |
{ |
| 2596 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow, |
| 2597 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"), |
| 2598 |
gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8, |
| 2599 |
PropModeReplace, (guchar *)name, strlen (name)); |
| 2600 |
|
| 2601 |
set_text_property (display, xwindow, |
| 2602 |
gdk_x11_get_xatom_by_name_for_display (display, "WM_NAME"), |
| 2603 |
name); |
| 2604 |
} |
| 2605 |
|
| 2606 |
/** |
| 2607 |
* gdk_window_set_title: |
| 2608 |
* @window: a toplevel #GdkWindow |
| 2609 |
* @title: title of @window |
| 2610 |
* |
| 2611 |
* Sets the title of a toplevel window, to be displayed in the titlebar. |
| 2612 |
* If you haven't explicitly set the icon name for the window |
| 2613 |
* (using gdk_window_set_icon_name()), the icon name will be set to |
| 2614 |
* @title as well. @title must be in UTF-8 encoding (as with all |
| 2615 |
* user-readable strings in GDK/GTK+). @title may not be %NULL. |
| 2616 |
**/ |
| 2617 |
void |
| 2618 |
gdk_window_set_title (GdkWindow *window, |
| 2619 |
const gchar *title) |
| 2620 |
{ |
| 2621 |
GdkDisplay *display; |
| 2622 |
Display *xdisplay; |
| 2623 |
Window xwindow; |
| 2624 |
|
| 2625 |
g_return_if_fail (title != NULL); |
| 2626 |
|
| 2627 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2628 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2629 |
return; |
| 2630 |
|
| 2631 |
display = gdk_drawable_get_display (window); |
| 2632 |
xdisplay = GDK_DISPLAY_XDISPLAY (display); |
| 2633 |
xwindow = GDK_WINDOW_XID (window); |
| 2634 |
|
| 2635 |
set_wm_name (display, xwindow, title); |
| 2636 |
|
| 2637 |
if (!gdk_window_icon_name_set (window)) |
| 2638 |
{ |
| 2639 |
XChangeProperty (xdisplay, xwindow, |
| 2640 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"), |
| 2641 |
gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8, |
| 2642 |
PropModeReplace, (guchar *)title, strlen (title)); |
| 2643 |
|
| 2644 |
set_text_property (display, xwindow, |
| 2645 |
gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"), |
| 2646 |
title); |
| 2647 |
} |
| 2648 |
} |
| 2649 |
|
| 2650 |
/** |
| 2651 |
* gdk_window_set_role: |
| 2652 |
* @window: a toplevel #GdkWindow |
| 2653 |
* @role: a string indicating its role |
| 2654 |
* |
| 2655 |
* When using GTK+, typically you should use gtk_window_set_role() instead |
| 2656 |
* of this low-level function. |
| 2657 |
* |
| 2658 |
* The window manager and session manager use a window's role to |
| 2659 |
* distinguish it from other kinds of window in the same application. |
| 2660 |
* When an application is restarted after being saved in a previous |
| 2661 |
* session, all windows with the same title and role are treated as |
| 2662 |
* interchangeable. So if you have two windows with the same title |
| 2663 |
* that should be distinguished for session management purposes, you |
| 2664 |
* should set the role on those windows. It doesn't matter what string |
| 2665 |
* you use for the role, as long as you have a different role for each |
| 2666 |
* non-interchangeable kind of window. |
| 2667 |
* |
| 2668 |
**/ |
| 2669 |
void |
| 2670 |
gdk_window_set_role (GdkWindow *window, |
| 2671 |
const gchar *role) |
| 2672 |
{ |
| 2673 |
GdkDisplay *display; |
| 2674 |
|
| 2675 |
display = gdk_drawable_get_display (window); |
| 2676 |
|
| 2677 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2678 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2679 |
return; |
| 2680 |
|
| 2681 |
if (role) |
| 2682 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), |
| 2683 |
gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE"), |
| 2684 |
XA_STRING, 8, PropModeReplace, (guchar *)role, strlen (role)); |
| 2685 |
else |
| 2686 |
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), |
| 2687 |
gdk_x11_get_xatom_by_name_for_display (display, "WM_WINDOW_ROLE")); |
| 2688 |
} |
| 2689 |
|
| 2690 |
/** |
| 2691 |
* gdk_window_set_startup_id: |
| 2692 |
* @window: a toplevel #GdkWindow |
| 2693 |
* @startup_id: a string with startup-notification identifier |
| 2694 |
* |
| 2695 |
* When using GTK+, typically you should use gtk_window_set_startup_id() |
| 2696 |
* instead of this low-level function. |
| 2697 |
* |
| 2698 |
* Since: 2.12 |
| 2699 |
* |
| 2700 |
**/ |
| 2701 |
void |
| 2702 |
gdk_window_set_startup_id (GdkWindow *window, |
| 2703 |
const gchar *startup_id) |
| 2704 |
{ |
| 2705 |
GdkDisplay *display; |
| 2706 |
|
| 2707 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2708 |
|
| 2709 |
display = gdk_drawable_get_display (window); |
| 2710 |
|
| 2711 |
if (GDK_WINDOW_DESTROYED (window) || |
| 2712 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2713 |
return; |
| 2714 |
|
| 2715 |
if (startup_id) |
| 2716 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), |
| 2717 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"), |
| 2718 |
gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8, |
| 2719 |
PropModeReplace, (unsigned char *)startup_id, strlen (startup_id)); |
| 2720 |
else |
| 2721 |
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), |
| 2722 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID")); |
| 2723 |
} |
| 2724 |
|
| 2725 |
/** |
| 2726 |
* gdk_window_set_transient_for: |
| 2727 |
* @window: a toplevel #GdkWindow |
| 2728 |
* @parent: another toplevel #GdkWindow |
| 2729 |
* |
| 2730 |
* Indicates to the window manager that @window is a transient dialog |
| 2731 |
* associated with the application window @parent. This allows the |
| 2732 |
* window manager to do things like center @window on @parent and |
| 2733 |
* keep @window above @parent. |
| 2734 |
* |
| 2735 |
* See gtk_window_set_transient_for() if you're using #GtkWindow or |
| 2736 |
* #GtkDialog. |
| 2737 |
**/ |
| 2738 |
void |
| 2739 |
gdk_window_set_transient_for (GdkWindow *window, |
| 2740 |
GdkWindow *parent) |
| 2741 |
{ |
| 2742 |
if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) && |
| 2743 |
WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 2744 |
XSetTransientForHint (GDK_WINDOW_XDISPLAY (window), |
| 2745 |
GDK_WINDOW_XID (window), |
| 2746 |
GDK_WINDOW_XID (parent)); |
| 2747 |
} |
| 2748 |
|
| 2749 |
static void |
| 2750 |
gdk_window_x11_set_background (GdkWindow *window, |
| 2751 |
const GdkColor *color) |
| 2752 |
{ |
| 2753 |
XSetWindowBackground (GDK_WINDOW_XDISPLAY (window), |
| 2754 |
GDK_WINDOW_XID (window), color->pixel); |
| 2755 |
} |
| 2756 |
|
| 2757 |
static void |
| 2758 |
gdk_window_x11_set_back_pixmap (GdkWindow *window, |
| 2759 |
GdkPixmap *pixmap) |
| 2760 |
{ |
| 2761 |
Pixmap xpixmap; |
| 2762 |
|
| 2763 |
if (pixmap == GDK_PARENT_RELATIVE_BG) |
| 2764 |
xpixmap = ParentRelative; |
| 2765 |
else if (pixmap == GDK_NO_BG) |
| 2766 |
xpixmap = None; |
| 2767 |
else |
| 2768 |
xpixmap = GDK_PIXMAP_XID (pixmap); |
| 2769 |
|
| 2770 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 2771 |
XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window), |
| 2772 |
GDK_WINDOW_XID (window), xpixmap); |
| 2773 |
} |
| 2774 |
|
| 2775 |
static void |
| 2776 |
gdk_window_x11_set_cursor (GdkWindow *window, |
| 2777 |
GdkCursor *cursor) |
| 2778 |
{ |
| 2779 |
GdkWindowObject *private; |
| 2780 |
GdkWindowImplX11 *impl; |
| 2781 |
GdkCursorPrivate *cursor_private; |
| 2782 |
Cursor xcursor; |
| 2783 |
|
| 2784 |
private = (GdkWindowObject *)window; |
| 2785 |
impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 2786 |
cursor_private = (GdkCursorPrivate*) cursor; |
| 2787 |
|
| 2788 |
if (impl->cursor) |
| 2789 |
{ |
| 2790 |
gdk_cursor_unref (impl->cursor); |
| 2791 |
impl->cursor = NULL; |
| 2792 |
} |
| 2793 |
|
| 2794 |
if (!cursor) |
| 2795 |
xcursor = None; |
| 2796 |
else |
| 2797 |
{ |
| 2798 |
_gdk_x11_cursor_update_theme (cursor); |
| 2799 |
xcursor = cursor_private->xcursor; |
| 2800 |
} |
| 2801 |
|
| 2802 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 2803 |
{ |
| 2804 |
XDefineCursor (GDK_WINDOW_XDISPLAY (window), |
| 2805 |
GDK_WINDOW_XID (window), |
| 2806 |
xcursor); |
| 2807 |
|
| 2808 |
if (cursor) |
| 2809 |
impl->cursor = gdk_cursor_ref (cursor); |
| 2810 |
} |
| 2811 |
} |
| 2812 |
|
| 2813 |
GdkCursor * |
| 2814 |
_gdk_x11_window_get_cursor (GdkWindow *window) |
| 2815 |
{ |
| 2816 |
GdkWindowObject *private; |
| 2817 |
GdkWindowImplX11 *impl; |
| 2818 |
|
| 2819 |
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); |
| 2820 |
|
| 2821 |
private = (GdkWindowObject *)window; |
| 2822 |
impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 2823 |
|
| 2824 |
return impl->cursor; |
| 2825 |
} |
| 2826 |
|
| 2827 |
static void |
| 2828 |
gdk_window_x11_get_geometry (GdkWindow *window, |
| 2829 |
gint *x, |
| 2830 |
gint *y, |
| 2831 |
gint *width, |
| 2832 |
gint *height, |
| 2833 |
gint *depth) |
| 2834 |
{ |
| 2835 |
Window root; |
| 2836 |
gint tx; |
| 2837 |
gint ty; |
| 2838 |
guint twidth; |
| 2839 |
guint theight; |
| 2840 |
guint tborder_width; |
| 2841 |
guint tdepth; |
| 2842 |
|
| 2843 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 2844 |
{ |
| 2845 |
XGetGeometry (GDK_WINDOW_XDISPLAY (window), |
| 2846 |
GDK_WINDOW_XID (window), |
| 2847 |
&root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth); |
| 2848 |
|
| 2849 |
if (x) |
| 2850 |
*x = tx; |
| 2851 |
if (y) |
| 2852 |
*y = ty; |
| 2853 |
if (width) |
| 2854 |
*width = twidth; |
| 2855 |
if (height) |
| 2856 |
*height = theight; |
| 2857 |
if (depth) |
| 2858 |
*depth = tdepth; |
| 2859 |
} |
| 2860 |
} |
| 2861 |
|
| 2862 |
static gint |
| 2863 |
gdk_window_x11_get_root_coords (GdkWindow *window, |
| 2864 |
gint x, |
| 2865 |
gint y, |
| 2866 |
gint *root_x, |
| 2867 |
gint *root_y) |
| 2868 |
{ |
| 2869 |
gint return_val; |
| 2870 |
Window child; |
| 2871 |
gint tx; |
| 2872 |
gint ty; |
| 2873 |
|
| 2874 |
return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window), |
| 2875 |
GDK_WINDOW_XID (window), |
| 2876 |
GDK_WINDOW_XROOTWIN (window), |
| 2877 |
x, y, &tx, &ty, |
| 2878 |
&child); |
| 2879 |
|
| 2880 |
if (root_x) |
| 2881 |
*root_x = tx; |
| 2882 |
if (root_y) |
| 2883 |
*root_y = ty; |
| 2884 |
|
| 2885 |
return return_val; |
| 2886 |
} |
| 2887 |
|
| 2888 |
static gboolean |
| 2889 |
gdk_window_x11_get_deskrelative_origin (GdkWindow *window, |
| 2890 |
gint *x, |
| 2891 |
gint *y) |
| 2892 |
{ |
| 2893 |
gboolean return_val = FALSE; |
| 2894 |
gint num_children, format_return; |
| 2895 |
Window win, *child, parent, root; |
| 2896 |
Atom type_return; |
| 2897 |
Atom atom; |
| 2898 |
gulong number_return, bytes_after_return; |
| 2899 |
guchar *data_return; |
| 2900 |
|
| 2901 |
atom = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), |
| 2902 |
"ENLIGHTENMENT_DESKTOP"); |
| 2903 |
win = GDK_WINDOW_XID (window); |
| 2904 |
|
| 2905 |
while (XQueryTree (GDK_WINDOW_XDISPLAY (window), win, &root, &parent, |
| 2906 |
&child, (unsigned int *)&num_children)) |
| 2907 |
{ |
| 2908 |
if ((child) && (num_children > 0)) |
| 2909 |
XFree (child); |
| 2910 |
|
| 2911 |
if (!parent) |
| 2912 |
break; |
| 2913 |
else |
| 2914 |
win = parent; |
| 2915 |
|
| 2916 |
if (win == root) |
| 2917 |
break; |
| 2918 |
|
| 2919 |
data_return = NULL; |
| 2920 |
XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), win, atom, 0, 0, |
| 2921 |
False, XA_CARDINAL, &type_return, &format_return, |
| 2922 |
&number_return, &bytes_after_return, &data_return); |
| 2923 |
|
| 2924 |
if (type_return == XA_CARDINAL) |
| 2925 |
{ |
| 2926 |
XFree (data_return); |
| 2927 |
break; |
| 2928 |
} |
| 2929 |
} |
| 2930 |
|
| 2931 |
return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window), |
| 2932 |
GDK_WINDOW_XID (window), |
| 2933 |
win, |
| 2934 |
0, 0, x, y, |
| 2935 |
&root); |
| 2936 |
|
| 2937 |
return return_val; |
| 2938 |
} |
| 2939 |
|
| 2940 |
/** |
| 2941 |
* gdk_window_get_root_origin: |
| 2942 |
* @window: a toplevel #GdkWindow |
| 2943 |
* @x: return location for X position of window frame |
| 2944 |
* @y: return location for Y position of window frame |
| 2945 |
* |
| 2946 |
* Obtains the top-left corner of the window manager frame in root |
| 2947 |
* window coordinates. |
| 2948 |
* |
| 2949 |
**/ |
| 2950 |
void |
| 2951 |
gdk_window_get_root_origin (GdkWindow *window, |
| 2952 |
gint *x, |
| 2953 |
gint *y) |
| 2954 |
{ |
| 2955 |
GdkRectangle rect; |
| 2956 |
|
| 2957 |
gdk_window_get_frame_extents (window, &rect); |
| 2958 |
|
| 2959 |
if (x) |
| 2960 |
*x = rect.x; |
| 2961 |
|
| 2962 |
if (y) |
| 2963 |
*y = rect.y; |
| 2964 |
} |
| 2965 |
|
| 2966 |
/** |
| 2967 |
* gdk_window_get_frame_extents: |
| 2968 |
* @window: a toplevel #GdkWindow |
| 2969 |
* @rect: rectangle to fill with bounding box of the window frame |
| 2970 |
* |
| 2971 |
* Obtains the bounding box of the window, including window manager |
| 2972 |
* titlebar/borders if any. The frame position is given in root window |
| 2973 |
* coordinates. To get the position of the window itself (rather than |
| 2974 |
* the frame) in root window coordinates, use gdk_window_get_origin(). |
| 2975 |
* |
| 2976 |
**/ |
| 2977 |
void |
| 2978 |
gdk_window_get_frame_extents (GdkWindow *window, |
| 2979 |
GdkRectangle *rect) |
| 2980 |
{ |
| 2981 |
GdkDisplay *display; |
| 2982 |
GdkWindowObject *private; |
| 2983 |
GdkWindowImplX11 *impl; |
| 2984 |
Window xwindow; |
| 2985 |
Window xparent; |
| 2986 |
Window root; |
| 2987 |
Window child; |
| 2988 |
Window *children; |
| 2989 |
guchar *data; |
| 2990 |
Window *vroots; |
| 2991 |
Atom type_return; |
| 2992 |
guint nchildren; |
| 2993 |
guint nvroots; |
| 2994 |
gulong nitems_return; |
| 2995 |
gulong bytes_after_return; |
| 2996 |
gint format_return; |
| 2997 |
gint i; |
| 2998 |
guint ww, wh, wb, wd; |
| 2999 |
gint wx, wy; |
| 3000 |
gboolean got_frame_extents = FALSE; |
| 3001 |
|
| 3002 |
g_return_if_fail (rect != NULL); |
| 3003 |
|
| 3004 |
private = (GdkWindowObject*) window; |
| 3005 |
|
| 3006 |
rect->x = 0; |
| 3007 |
rect->y = 0; |
| 3008 |
rect->width = 1; |
| 3009 |
rect->height = 1; |
| 3010 |
|
| 3011 |
while (private->parent && ((GdkWindowObject*) private->parent)->parent) |
| 3012 |
private = (GdkWindowObject*) private->parent; |
| 3013 |
|
| 3014 |
/* Refine our fallback answer a bit using local information */ |
| 3015 |
rect->x = private->x; |
| 3016 |
rect->y = private->y; |
| 3017 |
gdk_drawable_get_size ((GdkDrawable *)private, &rect->width, &rect->height); |
| 3018 |
|
| 3019 |
impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 3020 |
if (GDK_WINDOW_DESTROYED (private) || impl->override_redirect) |
| 3021 |
return; |
| 3022 |
|
| 3023 |
nvroots = 0; |
| 3024 |
vroots = NULL; |
| 3025 |
|
| 3026 |
gdk_error_trap_push(); |
| 3027 |
|
| 3028 |
display = gdk_drawable_get_display (window); |
| 3029 |
xwindow = GDK_WINDOW_XID (window); |
| 3030 |
|
| 3031 |
/* first try: use _NET_FRAME_EXTENTS */ |
| 3032 |
if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xwindow, |
| 3033 |
gdk_x11_get_xatom_by_name_for_display (display, |
| 3034 |
"_NET_FRAME_EXTENTS"), |
| 3035 |
0, G_MAXLONG, False, XA_CARDINAL, &type_return, |
| 3036 |
&format_return, &nitems_return, &bytes_after_return, |
| 3037 |
&data) |
| 3038 |
== Success) |
| 3039 |
{ |
| 3040 |
if ((type_return == XA_CARDINAL) && (format_return == 32) && |
| 3041 |
(nitems_return == 4) && (data)) |
| 3042 |
{ |
| 3043 |
gulong *ldata = (gulong *) data; |
| 3044 |
got_frame_extents = TRUE; |
| 3045 |
|
| 3046 |
/* try to get the real client window geometry */ |
| 3047 |
if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow, |
| 3048 |
&root, &wx, &wy, &ww, &wh, &wb, &wd) && |
| 3049 |
XTranslateCoordinates (GDK_DISPLAY_XDISPLAY (display), |
| 3050 |
xwindow, root, 0, 0, &wx, &wy, &child)) |
| 3051 |
{ |
| 3052 |
rect->x = wx; |
| 3053 |
rect->y = wy; |
| 3054 |
rect->width = ww; |
| 3055 |
rect->height = wh; |
| 3056 |
} |
| 3057 |
|
| 3058 |
/* _NET_FRAME_EXTENTS format is left, right, top, bottom */ |
| 3059 |
rect->x -= ldata[0]; |
| 3060 |
rect->y -= ldata[2]; |
| 3061 |
rect->width += ldata[0] + ldata[1]; |
| 3062 |
rect->height += ldata[2] + ldata[3]; |
| 3063 |
} |
| 3064 |
|
| 3065 |
if (data) |
| 3066 |
XFree (data); |
| 3067 |
} |
| 3068 |
|
| 3069 |
if (got_frame_extents) |
| 3070 |
goto out; |
| 3071 |
|
| 3072 |
/* no frame extents property available, which means we either have a WM that |
| 3073 |
is not EWMH compliant or is broken - try fallback and walk up the window |
| 3074 |
tree to get our window's parent which hopefully is the window frame */ |
| 3075 |
|
| 3076 |
/* use NETWM_VIRTUAL_ROOTS if available */ |
| 3077 |
root = GDK_WINDOW_XROOTWIN (window); |
| 3078 |
|
| 3079 |
if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), root, |
| 3080 |
gdk_x11_get_xatom_by_name_for_display (display, |
| 3081 |
"_NET_VIRTUAL_ROOTS"), |
| 3082 |
0, G_MAXLONG, False, XA_WINDOW, &type_return, |
| 3083 |
&format_return, &nitems_return, &bytes_after_return, |
| 3084 |
&data) |
| 3085 |
== Success) |
| 3086 |
{ |
| 3087 |
if ((type_return == XA_WINDOW) && (format_return == 32) && (data)) |
| 3088 |
{ |
| 3089 |
nvroots = nitems_return; |
| 3090 |
vroots = (Window *)data; |
| 3091 |
} |
| 3092 |
} |
| 3093 |
|
| 3094 |
xparent = GDK_WINDOW_XID (window); |
| 3095 |
|
| 3096 |
do |
| 3097 |
{ |
| 3098 |
xwindow = xparent; |
| 3099 |
|
| 3100 |
if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xwindow, |
| 3101 |
&root, &xparent, |
| 3102 |
&children, &nchildren)) |
| 3103 |
goto out; |
| 3104 |
|
| 3105 |
if (children) |
| 3106 |
XFree (children); |
| 3107 |
|
| 3108 |
/* check virtual roots */ |
| 3109 |
for (i = 0; i < nvroots; i++) |
| 3110 |
{ |
| 3111 |
if (xparent == vroots[i]) |
| 3112 |
{ |
| 3113 |
root = xparent; |
| 3114 |
break; |
| 3115 |
} |
| 3116 |
} |
| 3117 |
} |
| 3118 |
while (xparent != root); |
| 3119 |
|
| 3120 |
if (XGetGeometry (GDK_DISPLAY_XDISPLAY (display), xwindow, |
| 3121 |
&root, &wx, &wy, &ww, &wh, &wb, &wd)) |
| 3122 |
{ |
| 3123 |
rect->x = wx; |
| 3124 |
rect->y = wy; |
| 3125 |
rect->width = ww; |
| 3126 |
rect->height = wh; |
| 3127 |
} |
| 3128 |
|
| 3129 |
out: |
| 3130 |
if (vroots) |
| 3131 |
XFree (vroots); |
| 3132 |
|
| 3133 |
gdk_error_trap_pop (); |
| 3134 |
} |
| 3135 |
|
| 3136 |
void |
| 3137 |
_gdk_windowing_get_pointer (GdkDisplay *display, |
| 3138 |
GdkScreen **screen, |
| 3139 |
gint *x, |
| 3140 |
gint *y, |
| 3141 |
GdkModifierType *mask) |
| 3142 |
{ |
| 3143 |
GdkScreen *default_screen; |
| 3144 |
Display *xdisplay; |
| 3145 |
Window xwindow; |
| 3146 |
Window root = None; |
| 3147 |
Window child; |
| 3148 |
int rootx, rooty; |
| 3149 |
int winx; |
| 3150 |
int winy; |
| 3151 |
unsigned int xmask; |
| 3152 |
|
| 3153 |
if (display->closed) |
| 3154 |
return; |
| 3155 |
|
| 3156 |
default_screen = gdk_display_get_default_screen (display); |
| 3157 |
|
| 3158 |
xdisplay = GDK_SCREEN_XDISPLAY (default_screen); |
| 3159 |
xwindow = GDK_SCREEN_XROOTWIN (default_screen); |
| 3160 |
|
| 3161 |
if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client)) |
| 3162 |
{ |
| 3163 |
XQueryPointer (xdisplay, xwindow, |
| 3164 |
&root, &child, &rootx, &rooty, &winx, &winy, &xmask); |
| 3165 |
} |
| 3166 |
else |
| 3167 |
{ |
| 3168 |
XSetWindowAttributes attributes; |
| 3169 |
Window w; |
| 3170 |
|
| 3171 |
w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0, |
| 3172 |
CopyFromParent, InputOnly, CopyFromParent, |
| 3173 |
0, &attributes); |
| 3174 |
XQueryPointer (xdisplay, w, |
| 3175 |
&root, &child, &rootx, &rooty, &winx, &winy, &xmask); |
| 3176 |
XDestroyWindow (xdisplay, w); |
| 3177 |
} |
| 3178 |
|
| 3179 |
if (root != None) |
| 3180 |
{ |
| 3181 |
GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root); |
| 3182 |
*screen = gdk_drawable_get_screen (gdk_root); |
| 3183 |
} |
| 3184 |
|
| 3185 |
*x = rootx; |
| 3186 |
*y = rooty; |
| 3187 |
*mask = xmask; |
| 3188 |
} |
| 3189 |
|
| 3190 |
static gboolean |
| 3191 |
gdk_window_x11_get_pointer (GdkWindow *window, |
| 3192 |
gint *x, |
| 3193 |
gint *y, |
| 3194 |
GdkModifierType *mask) |
| 3195 |
{ |
| 3196 |
GdkDisplay *display = GDK_WINDOW_DISPLAY (window); |
| 3197 |
gboolean return_val; |
| 3198 |
Window root; |
| 3199 |
Window child; |
| 3200 |
int rootx, rooty; |
| 3201 |
int winx = 0; |
| 3202 |
int winy = 0; |
| 3203 |
unsigned int xmask = 0; |
| 3204 |
|
| 3205 |
g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE); |
| 3206 |
|
| 3207 |
|
| 3208 |
return_val = TRUE; |
| 3209 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 3210 |
{ |
| 3211 |
if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client)) |
| 3212 |
{ |
| 3213 |
if (XQueryPointer (GDK_WINDOW_XDISPLAY (window), |
| 3214 |
GDK_WINDOW_XID (window), |
| 3215 |
&root, &child, &rootx, &rooty, &winx, &winy, &xmask)) |
| 3216 |
{ |
| 3217 |
if (child) |
| 3218 |
return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child) != NULL; |
| 3219 |
} |
| 3220 |
} |
| 3221 |
else |
| 3222 |
{ |
| 3223 |
GdkScreen *screen; |
| 3224 |
int originx, originy; |
| 3225 |
_gdk_windowing_get_pointer (gdk_drawable_get_display (window), &screen, |
| 3226 |
&rootx, &rooty, &xmask); |
| 3227 |
gdk_window_get_origin (window, &originx, &originy); |
| 3228 |
winx = rootx - originx; |
| 3229 |
winy = rooty - originy; |
| 3230 |
} |
| 3231 |
} |
| 3232 |
|
| 3233 |
*x = winx; |
| 3234 |
*y = winy; |
| 3235 |
*mask = xmask; |
| 3236 |
|
| 3237 |
return return_val; |
| 3238 |
} |
| 3239 |
|
| 3240 |
/** |
| 3241 |
* gdk_display_warp_pointer: |
| 3242 |
* @display: a #GdkDisplay |
| 3243 |
* @screen: the screen of @display to warp the pointer to |
| 3244 |
* @x: the x coordinate of the destination |
| 3245 |
* @y: the y coordinate of the destination |
| 3246 |
* |
| 3247 |
* Warps the pointer of @display to the point @x,@y on |
| 3248 |
* the screen @screen, unless the pointer is confined |
| 3249 |
* to a window by a grab, in which case it will be moved |
| 3250 |
* as far as allowed by the grab. Warping the pointer |
| 3251 |
* creates events as if the user had moved the mouse |
| 3252 |
* instantaneously to the destination. |
| 3253 |
* |
| 3254 |
* Note that the pointer should normally be under the |
| 3255 |
* control of the user. This function was added to cover |
| 3256 |
* some rare use cases like keyboard navigation support |
| 3257 |
* for the color picker in the #GtkColorSelectionDialog. |
| 3258 |
* |
| 3259 |
* Since: 2.8 |
| 3260 |
*/ |
| 3261 |
void |
| 3262 |
gdk_display_warp_pointer (GdkDisplay *display, |
| 3263 |
GdkScreen *screen, |
| 3264 |
gint x, |
| 3265 |
gint y) |
| 3266 |
{ |
| 3267 |
Display *xdisplay; |
| 3268 |
Window dest; |
| 3269 |
|
| 3270 |
xdisplay = GDK_DISPLAY_XDISPLAY (display); |
| 3271 |
dest = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen)); |
| 3272 |
|
| 3273 |
XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, x, y); |
| 3274 |
} |
| 3275 |
|
| 3276 |
GdkWindow* |
| 3277 |
_gdk_windowing_window_at_pointer (GdkDisplay *display, |
| 3278 |
gint *win_x, |
| 3279 |
gint *win_y, |
| 3280 |
GdkModifierType *mask, |
| 3281 |
gboolean get_toplevel) |
| 3282 |
{ |
| 3283 |
GdkWindow *window; |
| 3284 |
GdkScreen *screen; |
| 3285 |
Window root; |
| 3286 |
Window xwindow; |
| 3287 |
Window child; |
| 3288 |
Window xwindow_last = 0; |
| 3289 |
Display *xdisplay; |
| 3290 |
int rootx = -1, rooty = -1; |
| 3291 |
int winx, winy; |
| 3292 |
unsigned int xmask; |
| 3293 |
|
| 3294 |
screen = gdk_display_get_default_screen (display); |
| 3295 |
|
| 3296 |
xwindow = GDK_SCREEN_XROOTWIN (screen); |
| 3297 |
xdisplay = GDK_SCREEN_XDISPLAY (screen); |
| 3298 |
|
| 3299 |
/* This function really only works if the mouse pointer is held still |
| 3300 |
* during its operation. If it moves from one leaf window to another |
| 3301 |
* than we'll end up with inaccurate values for win_x, win_y |
| 3302 |
* and the result. |
| 3303 |
*/ |
| 3304 |
gdk_x11_display_grab (display); |
| 3305 |
if (G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client)) |
| 3306 |
{ |
| 3307 |
XQueryPointer (xdisplay, xwindow, |
| 3308 |
&root, &child, &rootx, &rooty, &winx, &winy, &xmask); |
| 3309 |
if (root == xwindow) |
| 3310 |
xwindow = child; |
| 3311 |
else |
| 3312 |
xwindow = root; |
| 3313 |
|
| 3314 |
while (xwindow) |
| 3315 |
{ |
| 3316 |
xwindow_last = xwindow; |
| 3317 |
XQueryPointer (xdisplay, xwindow, |
| 3318 |
&root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask); |
| 3319 |
if (get_toplevel && xwindow_last != root && |
| 3320 |
(window = gdk_window_lookup_for_display (display, xwindow_last)) != NULL && |
| 3321 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN) |
| 3322 |
{ |
| 3323 |
xwindow = xwindow_last; |
| 3324 |
break; |
| 3325 |
} |
| 3326 |
} |
| 3327 |
} |
| 3328 |
else |
| 3329 |
{ |
| 3330 |
gint i, screens, width, height; |
| 3331 |
GList *toplevels, *list; |
| 3332 |
Window pointer_window; |
| 3333 |
|
| 3334 |
pointer_window = None; |
| 3335 |
screens = gdk_display_get_n_screens (display); |
| 3336 |
for (i = 0; i < screens; ++i) { |
| 3337 |
screen = gdk_display_get_screen (display, i); |
| 3338 |
toplevels = gdk_screen_get_toplevel_windows (screen); |
| 3339 |
for (list = toplevels; list != NULL; list = g_list_next (list)) { |
| 3340 |
window = GDK_WINDOW (list->data); |
| 3341 |
xwindow = GDK_WINDOW_XWINDOW (window); |
| 3342 |
gdk_error_trap_push (); |
| 3343 |
XQueryPointer (xdisplay, xwindow, |
| 3344 |
&root, &child, &rootx, &rooty, &winx, &winy, &xmask); |
| 3345 |
gdk_flush (); |
| 3346 |
if (gdk_error_trap_pop ()) |
| 3347 |
continue; |
| 3348 |
if (child != None) |
| 3349 |
{ |
| 3350 |
pointer_window = child; |
| 3351 |
break; |
| 3352 |
} |
| 3353 |
gdk_window_get_geometry (window, NULL, NULL, &width, &height, NULL); |
| 3354 |
if (winx >= 0 && winy >= 0 && winx < width && winy < height) |
| 3355 |
{ |
| 3356 |
/* A childless toplevel, or below another window? */ |
| 3357 |
XSetWindowAttributes attributes; |
| 3358 |
Window w; |
| 3359 |
|
| 3360 |
w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0, |
| 3361 |
CopyFromParent, InputOnly, CopyFromParent, |
| 3362 |
0, &attributes); |
| 3363 |
XMapWindow (xdisplay, w); |
| 3364 |
XQueryPointer (xdisplay, xwindow, |
| 3365 |
&root, &child, &rootx, &rooty, &winx, &winy, &xmask); |
| 3366 |
XDestroyWindow (xdisplay, w); |
| 3367 |
if (child == w) |
| 3368 |
{ |
| 3369 |
pointer_window = xwindow; |
| 3370 |
break; |
| 3371 |
} |
| 3372 |
} |
| 3373 |
} |
| 3374 |
g_list_free (toplevels); |
| 3375 |
if (pointer_window != None) |
| 3376 |
break; |
| 3377 |
} |
| 3378 |
xwindow = pointer_window; |
| 3379 |
|
| 3380 |
while (xwindow) |
| 3381 |
{ |
| 3382 |
xwindow_last = xwindow; |
| 3383 |
gdk_error_trap_push (); |
| 3384 |
XQueryPointer (xdisplay, xwindow, |
| 3385 |
&root, &xwindow, &rootx, &rooty, &winx, &winy, &xmask); |
| 3386 |
gdk_flush (); |
| 3387 |
if (gdk_error_trap_pop ()) |
| 3388 |
break; |
| 3389 |
if (get_toplevel && xwindow_last != root && |
| 3390 |
(window = gdk_window_lookup_for_display (display, xwindow_last)) != NULL && |
| 3391 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN) |
| 3392 |
break; |
| 3393 |
} |
| 3394 |
} |
| 3395 |
|
| 3396 |
gdk_x11_display_ungrab (display); |
| 3397 |
|
| 3398 |
window = gdk_window_lookup_for_display (display, xwindow_last); |
| 3399 |
*win_x = window ? winx : -1; |
| 3400 |
*win_y = window ? winy : -1; |
| 3401 |
if (mask) |
| 3402 |
*mask = xmask; |
| 3403 |
|
| 3404 |
return window; |
| 3405 |
} |
| 3406 |
|
| 3407 |
static GdkEventMask |
| 3408 |
gdk_window_x11_get_events (GdkWindow *window) |
| 3409 |
{ |
| 3410 |
XWindowAttributes attrs; |
| 3411 |
GdkEventMask event_mask; |
| 3412 |
GdkEventMask filtered; |
| 3413 |
|
| 3414 |
if (GDK_WINDOW_DESTROYED (window)) |
| 3415 |
return 0; |
| 3416 |
else |
| 3417 |
{ |
| 3418 |
XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window), |
| 3419 |
GDK_WINDOW_XID (window), |
| 3420 |
&attrs); |
| 3421 |
event_mask = x_event_mask_to_gdk_event_mask (attrs.your_event_mask); |
| 3422 |
/* if property change was filtered out before, keep it filtered out */ |
| 3423 |
filtered = GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK; |
| 3424 |
GDK_WINDOW_OBJECT (window)->event_mask = event_mask & ((GDK_WINDOW_OBJECT (window)->event_mask & filtered) | ~filtered); |
| 3425 |
|
| 3426 |
return event_mask; |
| 3427 |
} |
| 3428 |
} |
| 3429 |
static void |
| 3430 |
gdk_window_x11_set_events (GdkWindow *window, |
| 3431 |
GdkEventMask event_mask) |
| 3432 |
{ |
| 3433 |
long xevent_mask = 0; |
| 3434 |
int i; |
| 3435 |
|
| 3436 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 3437 |
{ |
| 3438 |
if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window)) |
| 3439 |
xevent_mask = StructureNotifyMask | PropertyChangeMask; |
| 3440 |
for (i = 0; i < _gdk_nenvent_masks; i++) |
| 3441 |
{ |
| 3442 |
if (event_mask & (1 << (i + 1))) |
| 3443 |
xevent_mask |= _gdk_event_mask_table[i]; |
| 3444 |
} |
| 3445 |
|
| 3446 |
XSelectInput (GDK_WINDOW_XDISPLAY (window), |
| 3447 |
GDK_WINDOW_XID (window), |
| 3448 |
xevent_mask); |
| 3449 |
} |
| 3450 |
} |
| 3451 |
|
| 3452 |
static void |
| 3453 |
gdk_window_add_colormap_windows (GdkWindow *window) |
| 3454 |
{ |
| 3455 |
GdkWindow *toplevel; |
| 3456 |
Window *old_windows; |
| 3457 |
Window *new_windows; |
| 3458 |
int i, count; |
| 3459 |
|
| 3460 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 3461 |
|
| 3462 |
if (GDK_WINDOW_DESTROYED (window)) |
| 3463 |
return; |
| 3464 |
|
| 3465 |
toplevel = gdk_window_get_toplevel (window); |
| 3466 |
|
| 3467 |
old_windows = NULL; |
| 3468 |
if (!XGetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel), |
| 3469 |
GDK_WINDOW_XID (toplevel), |
| 3470 |
&old_windows, &count)) |
| 3471 |
{ |
| 3472 |
count = 0; |
| 3473 |
} |
| 3474 |
|
| 3475 |
for (i = 0; i < count; i++) |
| 3476 |
if (old_windows[i] == GDK_WINDOW_XID (window)) |
| 3477 |
{ |
| 3478 |
XFree (old_windows); |
| 3479 |
return; |
| 3480 |
} |
| 3481 |
|
| 3482 |
new_windows = g_new (Window, count + 1); |
| 3483 |
|
| 3484 |
for (i = 0; i < count; i++) |
| 3485 |
new_windows[i] = old_windows[i]; |
| 3486 |
new_windows[count] = GDK_WINDOW_XID (window); |
| 3487 |
|
| 3488 |
XSetWMColormapWindows (GDK_WINDOW_XDISPLAY (toplevel), |
| 3489 |
GDK_WINDOW_XID (toplevel), |
| 3490 |
new_windows, count + 1); |
| 3491 |
|
| 3492 |
g_free (new_windows); |
| 3493 |
if (old_windows) |
| 3494 |
XFree (old_windows); |
| 3495 |
} |
| 3496 |
|
| 3497 |
static inline void |
| 3498 |
do_shape_combine_region (GdkWindow *window, |
| 3499 |
const GdkRegion *shape_region, |
| 3500 |
gint offset_x, |
| 3501 |
gint offset_y, |
| 3502 |
gint shape) |
| 3503 |
{ |
| 3504 |
if (GDK_WINDOW_DESTROYED (window)) |
| 3505 |
return; |
| 3506 |
|
| 3507 |
if (shape_region == NULL) |
| 3508 |
{ |
| 3509 |
/* Use NULL mask to unset the shape */ |
| 3510 |
if (shape == ShapeBounding |
| 3511 |
? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)) |
| 3512 |
: gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window))) |
| 3513 |
{ |
| 3514 |
if (shape == ShapeBounding) |
| 3515 |
{ |
| 3516 |
_gdk_x11_window_tmp_unset_parent_bg (window); |
| 3517 |
_gdk_x11_window_tmp_unset_bg (window, TRUE); |
| 3518 |
} |
| 3519 |
XShapeCombineMask (GDK_WINDOW_XDISPLAY (window), |
| 3520 |
GDK_WINDOW_XID (window), |
| 3521 |
shape, |
| 3522 |
0, 0, |
| 3523 |
None, |
| 3524 |
ShapeSet); |
| 3525 |
if (shape == ShapeBounding) |
| 3526 |
{ |
| 3527 |
_gdk_x11_window_tmp_reset_parent_bg (window); |
| 3528 |
_gdk_x11_window_tmp_reset_bg (window, TRUE); |
| 3529 |
} |
| 3530 |
} |
| 3531 |
return; |
| 3532 |
} |
| 3533 |
|
| 3534 |
if (shape == ShapeBounding |
| 3535 |
? gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window)) |
| 3536 |
: gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window))) |
| 3537 |
{ |
| 3538 |
gint n_rects = 0; |
| 3539 |
XRectangle *xrects = NULL; |
| 3540 |
|
| 3541 |
_gdk_region_get_xrectangles (shape_region, |
| 3542 |
0, 0, |
| 3543 |
&xrects, &n_rects); |
| 3544 |
|
| 3545 |
if (shape == ShapeBounding) |
| 3546 |
{ |
| 3547 |
_gdk_x11_window_tmp_unset_parent_bg (window); |
| 3548 |
_gdk_x11_window_tmp_unset_bg (window, TRUE); |
| 3549 |
} |
| 3550 |
XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window), |
| 3551 |
GDK_WINDOW_XID (window), |
| 3552 |
shape, |
| 3553 |
offset_x, offset_y, |
| 3554 |
xrects, n_rects, |
| 3555 |
ShapeSet, |
| 3556 |
YXBanded); |
| 3557 |
|
| 3558 |
if (shape == ShapeBounding) |
| 3559 |
{ |
| 3560 |
_gdk_x11_window_tmp_reset_parent_bg (window); |
| 3561 |
_gdk_x11_window_tmp_reset_bg (window, TRUE); |
| 3562 |
} |
| 3563 |
|
| 3564 |
g_free (xrects); |
| 3565 |
} |
| 3566 |
} |
| 3567 |
|
| 3568 |
static void |
| 3569 |
gdk_window_x11_shape_combine_region (GdkWindow *window, |
| 3570 |
const GdkRegion *shape_region, |
| 3571 |
gint offset_x, |
| 3572 |
gint offset_y) |
| 3573 |
{ |
| 3574 |
do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeBounding); |
| 3575 |
} |
| 3576 |
|
| 3577 |
static void |
| 3578 |
gdk_window_x11_input_shape_combine_region (GdkWindow *window, |
| 3579 |
const GdkRegion *shape_region, |
| 3580 |
gint offset_x, |
| 3581 |
gint offset_y) |
| 3582 |
{ |
| 3583 |
#ifdef ShapeInput |
| 3584 |
do_shape_combine_region (window, shape_region, offset_x, offset_y, ShapeInput); |
| 3585 |
#endif |
| 3586 |
} |
| 3587 |
|
| 3588 |
|
| 3589 |
/** |
| 3590 |
* gdk_window_set_override_redirect: |
| 3591 |
* @window: a toplevel #GdkWindow |
| 3592 |
* @override_redirect: %TRUE if window should be override redirect |
| 3593 |
* |
| 3594 |
* An override redirect window is not under the control of the window manager. |
| 3595 |
* This means it won't have a titlebar, won't be minimizable, etc. - it will |
| 3596 |
* be entirely under the control of the application. The window manager |
| 3597 |
* can't see the override redirect window at all. |
| 3598 |
* |
| 3599 |
* Override redirect should only be used for short-lived temporary |
| 3600 |
* windows, such as popup menus. #GtkMenu uses an override redirect |
| 3601 |
* window in its implementation, for example. |
| 3602 |
* |
| 3603 |
**/ |
| 3604 |
void |
| 3605 |
gdk_window_set_override_redirect (GdkWindow *window, |
| 3606 |
gboolean override_redirect) |
| 3607 |
{ |
| 3608 |
XSetWindowAttributes attr; |
| 3609 |
|
| 3610 |
if (!GDK_WINDOW_DESTROYED (window) && |
| 3611 |
WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 3612 |
{ |
| 3613 |
GdkWindowObject *private = (GdkWindowObject *)window; |
| 3614 |
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 3615 |
|
| 3616 |
attr.override_redirect = (override_redirect? True : False); |
| 3617 |
XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window), |
| 3618 |
GDK_WINDOW_XID (window), |
| 3619 |
CWOverrideRedirect, |
| 3620 |
&attr); |
| 3621 |
|
| 3622 |
impl->override_redirect = attr.override_redirect; |
| 3623 |
} |
| 3624 |
} |
| 3625 |
|
| 3626 |
/** |
| 3627 |
* gdk_window_set_accept_focus: |
| 3628 |
* @window: a toplevel #GdkWindow |
| 3629 |
* @accept_focus: %TRUE if the window should receive input focus |
| 3630 |
* |
| 3631 |
* Setting @accept_focus to %FALSE hints the desktop environment that the |
| 3632 |
* window doesn't want to receive input focus. |
| 3633 |
* |
| 3634 |
* On X, it is the responsibility of the window manager to interpret this |
| 3635 |
* hint. ICCCM-compliant window manager usually respect it. |
| 3636 |
* |
| 3637 |
* Since: 2.4 |
| 3638 |
**/ |
| 3639 |
void |
| 3640 |
gdk_window_set_accept_focus (GdkWindow *window, |
| 3641 |
gboolean accept_focus) |
| 3642 |
{ |
| 3643 |
GdkWindowObject *private; |
| 3644 |
|
| 3645 |
private = (GdkWindowObject *)window; |
| 3646 |
|
| 3647 |
accept_focus = accept_focus != FALSE; |
| 3648 |
|
| 3649 |
if (private->accept_focus != accept_focus) |
| 3650 |
{ |
| 3651 |
private->accept_focus = accept_focus; |
| 3652 |
|
| 3653 |
if (!GDK_WINDOW_DESTROYED (window) && |
| 3654 |
WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 3655 |
update_wm_hints (window, FALSE); |
| 3656 |
} |
| 3657 |
} |
| 3658 |
|
| 3659 |
/** |
| 3660 |
* gdk_window_set_focus_on_map: |
| 3661 |
* @window: a toplevel #GdkWindow |
| 3662 |
* @focus_on_map: %TRUE if the window should receive input focus when mapped |
| 3663 |
* |
| 3664 |
* Setting @focus_on_map to %FALSE hints the desktop environment that the |
| 3665 |
* window doesn't want to receive input focus when it is mapped. |
| 3666 |
* focus_on_map should be turned off for windows that aren't triggered |
| 3667 |
* interactively (such as popups from network activity). |
| 3668 |
* |
| 3669 |
* On X, it is the responsibility of the window manager to interpret |
| 3670 |
* this hint. Window managers following the freedesktop.org window |
| 3671 |
* manager extension specification should respect it. |
| 3672 |
* |
| 3673 |
* Since: 2.6 |
| 3674 |
**/ |
| 3675 |
void |
| 3676 |
gdk_window_set_focus_on_map (GdkWindow *window, |
| 3677 |
gboolean focus_on_map) |
| 3678 |
{ |
| 3679 |
GdkWindowObject *private; |
| 3680 |
|
| 3681 |
private = (GdkWindowObject *)window; |
| 3682 |
|
| 3683 |
focus_on_map = focus_on_map != FALSE; |
| 3684 |
|
| 3685 |
if (private->focus_on_map != focus_on_map) |
| 3686 |
{ |
| 3687 |
private->focus_on_map = focus_on_map; |
| 3688 |
|
| 3689 |
if ((!GDK_WINDOW_DESTROYED (window)) && |
| 3690 |
(!private->focus_on_map) && |
| 3691 |
WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 3692 |
gdk_x11_window_set_user_time (window, 0); |
| 3693 |
} |
| 3694 |
} |
| 3695 |
|
| 3696 |
/** |
| 3697 |
* gdk_x11_window_set_user_time: |
| 3698 |
* @window: A toplevel #GdkWindow |
| 3699 |
* @timestamp: An XServer timestamp to which the property should be set |
| 3700 |
* |
| 3701 |
* The application can use this call to update the _NET_WM_USER_TIME |
| 3702 |
* property on a toplevel window. This property stores an Xserver |
| 3703 |
* time which represents the time of the last user input event |
| 3704 |
* received for this window. This property may be used by the window |
| 3705 |
* manager to alter the focus, stacking, and/or placement behavior of |
| 3706 |
* windows when they are mapped depending on whether the new window |
| 3707 |
* was created by a user action or is a "pop-up" window activated by a |
| 3708 |
* timer or some other event. |
| 3709 |
* |
| 3710 |
* Note that this property is automatically updated by GDK, so this |
| 3711 |
* function should only be used by applications which handle input |
| 3712 |
* events bypassing GDK. |
| 3713 |
* |
| 3714 |
* Since: 2.6 |
| 3715 |
**/ |
| 3716 |
void |
| 3717 |
gdk_x11_window_set_user_time (GdkWindow *window, |
| 3718 |
guint32 timestamp) |
| 3719 |
{ |
| 3720 |
GdkDisplay *display; |
| 3721 |
GdkDisplayX11 *display_x11; |
| 3722 |
GdkToplevelX11 *toplevel; |
| 3723 |
glong timestamp_long = (glong)timestamp; |
| 3724 |
Window xid; |
| 3725 |
|
| 3726 |
if (GDK_WINDOW_DESTROYED (window) || |
| 3727 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 3728 |
return; |
| 3729 |
|
| 3730 |
display = gdk_drawable_get_display (window); |
| 3731 |
display_x11 = GDK_DISPLAY_X11 (display); |
| 3732 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 3733 |
|
| 3734 |
if (!toplevel) |
| 3735 |
{ |
| 3736 |
g_warning ("gdk_window_set_user_time called on non-toplevel\n"); |
| 3737 |
return; |
| 3738 |
} |
| 3739 |
|
| 3740 |
if (toplevel->focus_window != None && |
| 3741 |
gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window), |
| 3742 |
gdk_atom_intern_static_string ("_NET_WM_USER_TIME_WINDOW"))) |
| 3743 |
xid = toplevel->focus_window; |
| 3744 |
else |
| 3745 |
xid = GDK_WINDOW_XID (window); |
| 3746 |
|
| 3747 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xid, |
| 3748 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"), |
| 3749 |
XA_CARDINAL, 32, PropModeReplace, |
| 3750 |
(guchar *)×tamp_long, 1); |
| 3751 |
|
| 3752 |
if (timestamp_long != GDK_CURRENT_TIME && |
| 3753 |
(display_x11->user_time == GDK_CURRENT_TIME || |
| 3754 |
XSERVER_TIME_IS_LATER (timestamp_long, display_x11->user_time))) |
| 3755 |
display_x11->user_time = timestamp_long; |
| 3756 |
|
| 3757 |
if (toplevel) |
| 3758 |
toplevel->user_time = timestamp_long; |
| 3759 |
} |
| 3760 |
|
| 3761 |
#define GDK_SELECTION_MAX_SIZE(display) \ |
| 3762 |
MIN(262144, \ |
| 3763 |
XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \ |
| 3764 |
? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \ |
| 3765 |
: XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100) |
| 3766 |
|
| 3767 |
/** |
| 3768 |
* gdk_window_set_icon_list: |
| 3769 |
* @window: The #GdkWindow toplevel window to set the icon of. |
| 3770 |
* @pixbufs: (transfer none) (element-type GdkPixbuf): |
| 3771 |
* A list of pixbufs, of different sizes. |
| 3772 |
* |
| 3773 |
* Sets a list of icons for the window. One of these will be used |
| 3774 |
* to represent the window when it has been iconified. The icon is |
| 3775 |
* usually shown in an icon box or some sort of task bar. Which icon |
| 3776 |
* size is shown depends on the window manager. The window manager |
| 3777 |
* can scale the icon but setting several size icons can give better |
| 3778 |
* image quality since the window manager may only need to scale the |
| 3779 |
* icon by a small amount or not at all. |
| 3780 |
* |
| 3781 |
**/ |
| 3782 |
void |
| 3783 |
gdk_window_set_icon_list (GdkWindow *window, |
| 3784 |
GList *pixbufs) |
| 3785 |
{ |
| 3786 |
gulong *data; |
| 3787 |
guchar *pixels; |
| 3788 |
gulong *p; |
| 3789 |
gint size; |
| 3790 |
GList *l; |
| 3791 |
GdkPixbuf *pixbuf; |
| 3792 |
gint width, height, stride; |
| 3793 |
gint x, y; |
| 3794 |
gint n_channels; |
| 3795 |
GdkDisplay *display; |
| 3796 |
gint n; |
| 3797 |
|
| 3798 |
if (GDK_WINDOW_DESTROYED (window) || |
| 3799 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 3800 |
return; |
| 3801 |
|
| 3802 |
display = gdk_drawable_get_display (window); |
| 3803 |
|
| 3804 |
l = pixbufs; |
| 3805 |
size = 0; |
| 3806 |
n = 0; |
| 3807 |
while (l) |
| 3808 |
{ |
| 3809 |
pixbuf = l->data; |
| 3810 |
g_return_if_fail (GDK_IS_PIXBUF (pixbuf)); |
| 3811 |
|
| 3812 |
width = gdk_pixbuf_get_width (pixbuf); |
| 3813 |
height = gdk_pixbuf_get_height (pixbuf); |
| 3814 |
|
| 3815 |
/* silently ignore overlarge icons */ |
| 3816 |
if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display)) |
| 3817 |
{ |
| 3818 |
g_warning ("gdk_window_set_icon_list: icons too large"); |
| 3819 |
break; |
| 3820 |
} |
| 3821 |
|
| 3822 |
n++; |
| 3823 |
size += 2 + width * height; |
| 3824 |
|
| 3825 |
l = g_list_next (l); |
| 3826 |
} |
| 3827 |
|
| 3828 |
data = g_malloc (size * sizeof (gulong)); |
| 3829 |
|
| 3830 |
l = pixbufs; |
| 3831 |
p = data; |
| 3832 |
while (l && n > 0) |
| 3833 |
{ |
| 3834 |
pixbuf = l->data; |
| 3835 |
|
| 3836 |
width = gdk_pixbuf_get_width (pixbuf); |
| 3837 |
height = gdk_pixbuf_get_height (pixbuf); |
| 3838 |
stride = gdk_pixbuf_get_rowstride (pixbuf); |
| 3839 |
n_channels = gdk_pixbuf_get_n_channels (pixbuf); |
| 3840 |
|
| 3841 |
*p++ = width; |
| 3842 |
*p++ = height; |
| 3843 |
|
| 3844 |
pixels = gdk_pixbuf_get_pixels (pixbuf); |
| 3845 |
|
| 3846 |
for (y = 0; y < height; y++) |
| 3847 |
{ |
| 3848 |
for (x = 0; x < width; x++) |
| 3849 |
{ |
| 3850 |
guchar r, g, b, a; |
| 3851 |
|
| 3852 |
r = pixels[y*stride + x*n_channels + 0]; |
| 3853 |
g = pixels[y*stride + x*n_channels + 1]; |
| 3854 |
b = pixels[y*stride + x*n_channels + 2]; |
| 3855 |
if (n_channels >= 4) |
| 3856 |
a = pixels[y*stride + x*n_channels + 3]; |
| 3857 |
else |
| 3858 |
a = 255; |
| 3859 |
|
| 3860 |
*p++ = a << 24 | r << 16 | g << 8 | b ; |
| 3861 |
} |
| 3862 |
} |
| 3863 |
|
| 3864 |
l = g_list_next (l); |
| 3865 |
n--; |
| 3866 |
} |
| 3867 |
|
| 3868 |
if (size > 0) |
| 3869 |
{ |
| 3870 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), |
| 3871 |
GDK_WINDOW_XID (window), |
| 3872 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"), |
| 3873 |
XA_CARDINAL, 32, |
| 3874 |
PropModeReplace, |
| 3875 |
(guchar*) data, size); |
| 3876 |
} |
| 3877 |
else |
| 3878 |
{ |
| 3879 |
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), |
| 3880 |
GDK_WINDOW_XID (window), |
| 3881 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON")); |
| 3882 |
} |
| 3883 |
|
| 3884 |
g_free (data); |
| 3885 |
} |
| 3886 |
|
| 3887 |
/** |
| 3888 |
* gdk_window_set_icon: |
| 3889 |
* @window: a toplevel #GdkWindow |
| 3890 |
* @icon_window: a #GdkWindow to use for the icon, or %NULL to unset |
| 3891 |
* @pixmap: a #GdkPixmap to use as the icon, or %NULL to unset |
| 3892 |
* @mask: a 1-bit pixmap (#GdkBitmap) to use as mask for @pixmap, or %NULL to have none |
| 3893 |
* |
| 3894 |
* Sets the icon of @window as a pixmap or window. If using GTK+, investigate |
| 3895 |
* gtk_window_set_default_icon_list() first, and then gtk_window_set_icon_list() |
| 3896 |
* and gtk_window_set_icon(). If those don't meet your needs, look at |
| 3897 |
* gdk_window_set_icon_list(). Only if all those are too high-level do you |
| 3898 |
* want to fall back to gdk_window_set_icon(). |
| 3899 |
* |
| 3900 |
**/ |
| 3901 |
void |
| 3902 |
gdk_window_set_icon (GdkWindow *window, |
| 3903 |
GdkWindow *icon_window, |
| 3904 |
GdkPixmap *pixmap, |
| 3905 |
GdkBitmap *mask) |
| 3906 |
{ |
| 3907 |
GdkToplevelX11 *toplevel; |
| 3908 |
|
| 3909 |
if (GDK_WINDOW_DESTROYED (window) || |
| 3910 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 3911 |
return; |
| 3912 |
|
| 3913 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 3914 |
|
| 3915 |
if (toplevel->icon_window != icon_window) |
| 3916 |
{ |
| 3917 |
if (toplevel->icon_window) |
| 3918 |
g_object_unref (toplevel->icon_window); |
| 3919 |
toplevel->icon_window = g_object_ref (icon_window); |
| 3920 |
} |
| 3921 |
|
| 3922 |
if (toplevel->icon_pixmap != pixmap) |
| 3923 |
{ |
| 3924 |
if (pixmap) |
| 3925 |
g_object_ref (pixmap); |
| 3926 |
if (toplevel->icon_pixmap) |
| 3927 |
g_object_unref (toplevel->icon_pixmap); |
| 3928 |
toplevel->icon_pixmap = pixmap; |
| 3929 |
} |
| 3930 |
|
| 3931 |
if (toplevel->icon_mask != mask) |
| 3932 |
{ |
| 3933 |
if (mask) |
| 3934 |
g_object_ref (mask); |
| 3935 |
if (toplevel->icon_mask) |
| 3936 |
g_object_unref (toplevel->icon_mask); |
| 3937 |
toplevel->icon_mask = mask; |
| 3938 |
} |
| 3939 |
|
| 3940 |
update_wm_hints (window, FALSE); |
| 3941 |
} |
| 3942 |
|
| 3943 |
static gboolean |
| 3944 |
gdk_window_icon_name_set (GdkWindow *window) |
| 3945 |
{ |
| 3946 |
return GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (window), |
| 3947 |
g_quark_from_static_string ("gdk-icon-name-set"))); |
| 3948 |
} |
| 3949 |
|
| 3950 |
/** |
| 3951 |
* gdk_window_set_icon_name: |
| 3952 |
* @window: a toplevel #GdkWindow |
| 3953 |
* @name: name of window while iconified (minimized) |
| 3954 |
* |
| 3955 |
* Windows may have a name used while minimized, distinct from the |
| 3956 |
* name they display in their titlebar. Most of the time this is a bad |
| 3957 |
* idea from a user interface standpoint. But you can set such a name |
| 3958 |
* with this function, if you like. |
| 3959 |
* |
| 3960 |
* After calling this with a non-%NULL @name, calls to gdk_window_set_title() |
| 3961 |
* will not update the icon title. |
| 3962 |
* |
| 3963 |
* Using %NULL for @name unsets the icon title; further calls to |
| 3964 |
* gdk_window_set_title() will again update the icon title as well. |
| 3965 |
**/ |
| 3966 |
void |
| 3967 |
gdk_window_set_icon_name (GdkWindow *window, |
| 3968 |
const gchar *name) |
| 3969 |
{ |
| 3970 |
GdkDisplay *display; |
| 3971 |
|
| 3972 |
if (GDK_WINDOW_DESTROYED (window) || |
| 3973 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 3974 |
return; |
| 3975 |
|
| 3976 |
display = gdk_drawable_get_display (window); |
| 3977 |
|
| 3978 |
g_object_set_qdata (G_OBJECT (window), g_quark_from_static_string ("gdk-icon-name-set"), |
| 3979 |
GUINT_TO_POINTER (name != NULL)); |
| 3980 |
|
| 3981 |
if (name != NULL) |
| 3982 |
{ |
| 3983 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), |
| 3984 |
GDK_WINDOW_XID (window), |
| 3985 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME"), |
| 3986 |
gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8, |
| 3987 |
PropModeReplace, (guchar *)name, strlen (name)); |
| 3988 |
|
| 3989 |
set_text_property (display, GDK_WINDOW_XID (window), |
| 3990 |
gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME"), |
| 3991 |
name); |
| 3992 |
} |
| 3993 |
else |
| 3994 |
{ |
| 3995 |
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), |
| 3996 |
GDK_WINDOW_XID (window), |
| 3997 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON_NAME")); |
| 3998 |
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), |
| 3999 |
GDK_WINDOW_XID (window), |
| 4000 |
gdk_x11_get_xatom_by_name_for_display (display, "WM_ICON_NAME")); |
| 4001 |
} |
| 4002 |
} |
| 4003 |
|
| 4004 |
/** |
| 4005 |
* gdk_window_iconify: |
| 4006 |
* @window: a toplevel #GdkWindow |
| 4007 |
* |
| 4008 |
* Asks to iconify (minimize) @window. The window manager may choose |
| 4009 |
* to ignore the request, but normally will honor it. Using |
| 4010 |
* gtk_window_iconify() is preferred, if you have a #GtkWindow widget. |
| 4011 |
* |
| 4012 |
* This function only makes sense when @window is a toplevel window. |
| 4013 |
* |
| 4014 |
**/ |
| 4015 |
void |
| 4016 |
gdk_window_iconify (GdkWindow *window) |
| 4017 |
{ |
| 4018 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4019 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4020 |
return; |
| 4021 |
|
| 4022 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4023 |
{ |
| 4024 |
XIconifyWindow (GDK_WINDOW_XDISPLAY (window), |
| 4025 |
GDK_WINDOW_XWINDOW (window), |
| 4026 |
gdk_screen_get_number (GDK_WINDOW_SCREEN (window))); |
| 4027 |
} |
| 4028 |
else |
| 4029 |
{ |
| 4030 |
/* Flip our client side flag, the real work happens on map. */ |
| 4031 |
gdk_synthesize_window_state (window, |
| 4032 |
0, |
| 4033 |
GDK_WINDOW_STATE_ICONIFIED); |
| 4034 |
gdk_wmspec_change_state (TRUE, window, |
| 4035 |
gdk_atom_intern_static_string ("_NET_WM_STATE_HIDDEN"), |
| 4036 |
GDK_NONE); |
| 4037 |
} |
| 4038 |
} |
| 4039 |
|
| 4040 |
/** |
| 4041 |
* gdk_window_deiconify: |
| 4042 |
* @window: a toplevel #GdkWindow |
| 4043 |
* |
| 4044 |
* Attempt to deiconify (unminimize) @window. On X11 the window manager may |
| 4045 |
* choose to ignore the request to deiconify. When using GTK+, |
| 4046 |
* use gtk_window_deiconify() instead of the #GdkWindow variant. Or better yet, |
| 4047 |
* you probably want to use gtk_window_present(), which raises the window, focuses it, |
| 4048 |
* unminimizes it, and puts it on the current desktop. |
| 4049 |
* |
| 4050 |
**/ |
| 4051 |
void |
| 4052 |
gdk_window_deiconify (GdkWindow *window) |
| 4053 |
{ |
| 4054 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4055 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4056 |
return; |
| 4057 |
|
| 4058 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4059 |
{ |
| 4060 |
gdk_window_show (window); |
| 4061 |
gdk_wmspec_change_state (FALSE, window, |
| 4062 |
gdk_atom_intern_static_string ("_NET_WM_STATE_HIDDEN"), |
| 4063 |
GDK_NONE); |
| 4064 |
} |
| 4065 |
else |
| 4066 |
{ |
| 4067 |
/* Flip our client side flag, the real work happens on map. */ |
| 4068 |
gdk_synthesize_window_state (window, |
| 4069 |
GDK_WINDOW_STATE_ICONIFIED, |
| 4070 |
0); |
| 4071 |
gdk_wmspec_change_state (FALSE, window, |
| 4072 |
gdk_atom_intern_static_string ("_NET_WM_STATE_HIDDEN"), |
| 4073 |
GDK_NONE); |
| 4074 |
} |
| 4075 |
} |
| 4076 |
|
| 4077 |
/** |
| 4078 |
* gdk_window_stick: |
| 4079 |
* @window: a toplevel #GdkWindow |
| 4080 |
* |
| 4081 |
* "Pins" a window such that it's on all workspaces and does not scroll |
| 4082 |
* with viewports, for window managers that have scrollable viewports. |
| 4083 |
* (When using #GtkWindow, gtk_window_stick() may be more useful.) |
| 4084 |
* |
| 4085 |
* On the X11 platform, this function depends on window manager |
| 4086 |
* support, so may have no effect with many window managers. However, |
| 4087 |
* GDK will do the best it can to convince the window manager to stick |
| 4088 |
* the window. For window managers that don't support this operation, |
| 4089 |
* there's nothing you can do to force it to happen. |
| 4090 |
* |
| 4091 |
**/ |
| 4092 |
void |
| 4093 |
gdk_window_stick (GdkWindow *window) |
| 4094 |
{ |
| 4095 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4096 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4097 |
return; |
| 4098 |
|
| 4099 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4100 |
{ |
| 4101 |
/* "stick" means stick to all desktops _and_ do not scroll with the |
| 4102 |
* viewport. i.e. glue to the monitor glass in all cases. |
| 4103 |
*/ |
| 4104 |
|
| 4105 |
XClientMessageEvent xclient; |
| 4106 |
|
| 4107 |
/* Request stick during viewport scroll */ |
| 4108 |
gdk_wmspec_change_state (TRUE, window, |
| 4109 |
gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"), |
| 4110 |
GDK_NONE); |
| 4111 |
|
| 4112 |
/* Request desktop 0xFFFFFFFF */ |
| 4113 |
memset (&xclient, 0, sizeof (xclient)); |
| 4114 |
xclient.type = ClientMessage; |
| 4115 |
xclient.window = GDK_WINDOW_XWINDOW (window); |
| 4116 |
xclient.display = GDK_WINDOW_XDISPLAY (window); |
| 4117 |
xclient.message_type = gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window), |
| 4118 |
"_NET_WM_DESKTOP"); |
| 4119 |
xclient.format = 32; |
| 4120 |
|
| 4121 |
xclient.data.l[0] = 0xFFFFFFFF; |
| 4122 |
xclient.data.l[1] = 0; |
| 4123 |
xclient.data.l[2] = 0; |
| 4124 |
xclient.data.l[3] = 0; |
| 4125 |
xclient.data.l[4] = 0; |
| 4126 |
|
| 4127 |
XSendEvent (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XROOTWIN (window), False, |
| 4128 |
SubstructureRedirectMask | SubstructureNotifyMask, |
| 4129 |
(XEvent *)&xclient); |
| 4130 |
} |
| 4131 |
else |
| 4132 |
{ |
| 4133 |
/* Flip our client side flag, the real work happens on map. */ |
| 4134 |
gdk_synthesize_window_state (window, |
| 4135 |
0, |
| 4136 |
GDK_WINDOW_STATE_STICKY); |
| 4137 |
} |
| 4138 |
} |
| 4139 |
|
| 4140 |
/** |
| 4141 |
* gdk_window_unstick: |
| 4142 |
* @window: a toplevel #GdkWindow |
| 4143 |
* |
| 4144 |
* Reverse operation for gdk_window_stick(); see gdk_window_stick(), |
| 4145 |
* and gtk_window_unstick(). |
| 4146 |
* |
| 4147 |
**/ |
| 4148 |
void |
| 4149 |
gdk_window_unstick (GdkWindow *window) |
| 4150 |
{ |
| 4151 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4152 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4153 |
return; |
| 4154 |
|
| 4155 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4156 |
{ |
| 4157 |
/* Request unstick from viewport */ |
| 4158 |
gdk_wmspec_change_state (FALSE, window, |
| 4159 |
gdk_atom_intern_static_string ("_NET_WM_STATE_STICKY"), |
| 4160 |
GDK_NONE); |
| 4161 |
|
| 4162 |
move_to_current_desktop (window); |
| 4163 |
} |
| 4164 |
else |
| 4165 |
{ |
| 4166 |
/* Flip our client side flag, the real work happens on map. */ |
| 4167 |
gdk_synthesize_window_state (window, |
| 4168 |
GDK_WINDOW_STATE_STICKY, |
| 4169 |
0); |
| 4170 |
|
| 4171 |
} |
| 4172 |
} |
| 4173 |
|
| 4174 |
/** |
| 4175 |
* gdk_window_maximize: |
| 4176 |
* @window: a toplevel #GdkWindow |
| 4177 |
* |
| 4178 |
* Maximizes the window. If the window was already maximized, then |
| 4179 |
* this function does nothing. |
| 4180 |
* |
| 4181 |
* On X11, asks the window manager to maximize @window, if the window |
| 4182 |
* manager supports this operation. Not all window managers support |
| 4183 |
* this, and some deliberately ignore it or don't have a concept of |
| 4184 |
* "maximized"; so you can't rely on the maximization actually |
| 4185 |
* happening. But it will happen with most standard window managers, |
| 4186 |
* and GDK makes a best effort to get it to happen. |
| 4187 |
* |
| 4188 |
* On Windows, reliably maximizes the window. |
| 4189 |
* |
| 4190 |
**/ |
| 4191 |
void |
| 4192 |
gdk_window_maximize (GdkWindow *window) |
| 4193 |
{ |
| 4194 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4195 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4196 |
return; |
| 4197 |
|
| 4198 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4199 |
gdk_wmspec_change_state (TRUE, window, |
| 4200 |
gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"), |
| 4201 |
gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ")); |
| 4202 |
else |
| 4203 |
gdk_synthesize_window_state (window, |
| 4204 |
0, |
| 4205 |
GDK_WINDOW_STATE_MAXIMIZED); |
| 4206 |
} |
| 4207 |
|
| 4208 |
/** |
| 4209 |
* gdk_window_unmaximize: |
| 4210 |
* @window: a toplevel #GdkWindow |
| 4211 |
* |
| 4212 |
* Unmaximizes the window. If the window wasn't maximized, then this |
| 4213 |
* function does nothing. |
| 4214 |
* |
| 4215 |
* On X11, asks the window manager to unmaximize @window, if the |
| 4216 |
* window manager supports this operation. Not all window managers |
| 4217 |
* support this, and some deliberately ignore it or don't have a |
| 4218 |
* concept of "maximized"; so you can't rely on the unmaximization |
| 4219 |
* actually happening. But it will happen with most standard window |
| 4220 |
* managers, and GDK makes a best effort to get it to happen. |
| 4221 |
* |
| 4222 |
* On Windows, reliably unmaximizes the window. |
| 4223 |
* |
| 4224 |
**/ |
| 4225 |
void |
| 4226 |
gdk_window_unmaximize (GdkWindow *window) |
| 4227 |
{ |
| 4228 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4229 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4230 |
return; |
| 4231 |
|
| 4232 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4233 |
gdk_wmspec_change_state (FALSE, window, |
| 4234 |
gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_VERT"), |
| 4235 |
gdk_atom_intern_static_string ("_NET_WM_STATE_MAXIMIZED_HORZ")); |
| 4236 |
else |
| 4237 |
gdk_synthesize_window_state (window, |
| 4238 |
GDK_WINDOW_STATE_MAXIMIZED, |
| 4239 |
0); |
| 4240 |
} |
| 4241 |
|
| 4242 |
/** |
| 4243 |
* gdk_window_fullscreen: |
| 4244 |
* @window: a toplevel #GdkWindow |
| 4245 |
* |
| 4246 |
* Moves the window into fullscreen mode. This means the |
| 4247 |
* window covers the entire screen and is above any panels |
| 4248 |
* or task bars. |
| 4249 |
* |
| 4250 |
* If the window was already fullscreen, then this function does nothing. |
| 4251 |
* |
| 4252 |
* On X11, asks the window manager to put @window in a fullscreen |
| 4253 |
* state, if the window manager supports this operation. Not all |
| 4254 |
* window managers support this, and some deliberately ignore it or |
| 4255 |
* don't have a concept of "fullscreen"; so you can't rely on the |
| 4256 |
* fullscreenification actually happening. But it will happen with |
| 4257 |
* most standard window managers, and GDK makes a best effort to get |
| 4258 |
* it to happen. |
| 4259 |
* |
| 4260 |
* Since: 2.2 |
| 4261 |
**/ |
| 4262 |
void |
| 4263 |
gdk_window_fullscreen (GdkWindow *window) |
| 4264 |
{ |
| 4265 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4266 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4267 |
return; |
| 4268 |
|
| 4269 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4270 |
gdk_wmspec_change_state (TRUE, window, |
| 4271 |
gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"), |
| 4272 |
GDK_NONE); |
| 4273 |
|
| 4274 |
else |
| 4275 |
gdk_synthesize_window_state (window, |
| 4276 |
0, |
| 4277 |
GDK_WINDOW_STATE_FULLSCREEN); |
| 4278 |
} |
| 4279 |
|
| 4280 |
/** |
| 4281 |
* gdk_window_unfullscreen: |
| 4282 |
* @window: a toplevel #GdkWindow |
| 4283 |
* |
| 4284 |
* Moves the window out of fullscreen mode. If the window was not |
| 4285 |
* fullscreen, does nothing. |
| 4286 |
* |
| 4287 |
* On X11, asks the window manager to move @window out of the fullscreen |
| 4288 |
* state, if the window manager supports this operation. Not all |
| 4289 |
* window managers support this, and some deliberately ignore it or |
| 4290 |
* don't have a concept of "fullscreen"; so you can't rely on the |
| 4291 |
* unfullscreenification actually happening. But it will happen with |
| 4292 |
* most standard window managers, and GDK makes a best effort to get |
| 4293 |
* it to happen. |
| 4294 |
* |
| 4295 |
* Since: 2.2 |
| 4296 |
**/ |
| 4297 |
void |
| 4298 |
gdk_window_unfullscreen (GdkWindow *window) |
| 4299 |
{ |
| 4300 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4301 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4302 |
return; |
| 4303 |
|
| 4304 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4305 |
gdk_wmspec_change_state (FALSE, window, |
| 4306 |
gdk_atom_intern_static_string ("_NET_WM_STATE_FULLSCREEN"), |
| 4307 |
GDK_NONE); |
| 4308 |
|
| 4309 |
else |
| 4310 |
gdk_synthesize_window_state (window, |
| 4311 |
GDK_WINDOW_STATE_FULLSCREEN, |
| 4312 |
0); |
| 4313 |
} |
| 4314 |
|
| 4315 |
/** |
| 4316 |
* gdk_window_set_keep_above: |
| 4317 |
* @window: a toplevel #GdkWindow |
| 4318 |
* @setting: whether to keep @window above other windows |
| 4319 |
* |
| 4320 |
* Set if @window must be kept above other windows. If the |
| 4321 |
* window was already above, then this function does nothing. |
| 4322 |
* |
| 4323 |
* On X11, asks the window manager to keep @window above, if the window |
| 4324 |
* manager supports this operation. Not all window managers support |
| 4325 |
* this, and some deliberately ignore it or don't have a concept of |
| 4326 |
* "keep above"; so you can't rely on the window being kept above. |
| 4327 |
* But it will happen with most standard window managers, |
| 4328 |
* and GDK makes a best effort to get it to happen. |
| 4329 |
* |
| 4330 |
* Since: 2.4 |
| 4331 |
**/ |
| 4332 |
void |
| 4333 |
gdk_window_set_keep_above (GdkWindow *window, |
| 4334 |
gboolean setting) |
| 4335 |
{ |
| 4336 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 4337 |
|
| 4338 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4339 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4340 |
return; |
| 4341 |
|
| 4342 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4343 |
{ |
| 4344 |
if (setting) |
| 4345 |
gdk_wmspec_change_state (FALSE, window, |
| 4346 |
gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"), |
| 4347 |
GDK_NONE); |
| 4348 |
gdk_wmspec_change_state (setting, window, |
| 4349 |
gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"), |
| 4350 |
GDK_NONE); |
| 4351 |
} |
| 4352 |
else |
| 4353 |
gdk_synthesize_window_state (window, |
| 4354 |
setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE, |
| 4355 |
setting ? GDK_WINDOW_STATE_ABOVE : 0); |
| 4356 |
} |
| 4357 |
|
| 4358 |
/** |
| 4359 |
* gdk_window_set_keep_below: |
| 4360 |
* @window: a toplevel #GdkWindow |
| 4361 |
* @setting: whether to keep @window below other windows |
| 4362 |
* |
| 4363 |
* Set if @window must be kept below other windows. If the |
| 4364 |
* window was already below, then this function does nothing. |
| 4365 |
* |
| 4366 |
* On X11, asks the window manager to keep @window below, if the window |
| 4367 |
* manager supports this operation. Not all window managers support |
| 4368 |
* this, and some deliberately ignore it or don't have a concept of |
| 4369 |
* "keep below"; so you can't rely on the window being kept below. |
| 4370 |
* But it will happen with most standard window managers, |
| 4371 |
* and GDK makes a best effort to get it to happen. |
| 4372 |
* |
| 4373 |
* Since: 2.4 |
| 4374 |
**/ |
| 4375 |
void |
| 4376 |
gdk_window_set_keep_below (GdkWindow *window, gboolean setting) |
| 4377 |
{ |
| 4378 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 4379 |
|
| 4380 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4381 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4382 |
return; |
| 4383 |
|
| 4384 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4385 |
{ |
| 4386 |
if (setting) |
| 4387 |
gdk_wmspec_change_state (FALSE, window, |
| 4388 |
gdk_atom_intern_static_string ("_NET_WM_STATE_ABOVE"), |
| 4389 |
GDK_NONE); |
| 4390 |
gdk_wmspec_change_state (setting, window, |
| 4391 |
gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"), |
| 4392 |
GDK_NONE); |
| 4393 |
} |
| 4394 |
else |
| 4395 |
gdk_synthesize_window_state (window, |
| 4396 |
setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW, |
| 4397 |
setting ? GDK_WINDOW_STATE_BELOW : 0); |
| 4398 |
} |
| 4399 |
|
| 4400 |
/** |
| 4401 |
* gdk_window_get_group: |
| 4402 |
* @window: a toplevel #GdkWindow |
| 4403 |
* |
| 4404 |
* Returns the group leader window for @window. See gdk_window_set_group(). |
| 4405 |
* |
| 4406 |
* Return value: the group leader window for @window |
| 4407 |
* |
| 4408 |
* Since: 2.4 |
| 4409 |
**/ |
| 4410 |
GdkWindow * |
| 4411 |
gdk_window_get_group (GdkWindow *window) |
| 4412 |
{ |
| 4413 |
GdkToplevelX11 *toplevel; |
| 4414 |
|
| 4415 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4416 |
!WINDOW_IS_TOPLEVEL (window)) |
| 4417 |
return NULL; |
| 4418 |
|
| 4419 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 4420 |
|
| 4421 |
return toplevel->group_leader; |
| 4422 |
} |
| 4423 |
|
| 4424 |
/** |
| 4425 |
* gdk_window_set_group: |
| 4426 |
* @window: a toplevel #GdkWindow |
| 4427 |
* @leader: group leader window, or %NULL to restore the default group leader window |
| 4428 |
* |
| 4429 |
* Sets the group leader window for @window. By default, |
| 4430 |
* GDK sets the group leader for all toplevel windows |
| 4431 |
* to a global window implicitly created by GDK. With this function |
| 4432 |
* you can override this default. |
| 4433 |
* |
| 4434 |
* The group leader window allows the window manager to distinguish |
| 4435 |
* all windows that belong to a single application. It may for example |
| 4436 |
* allow users to minimize/unminimize all windows belonging to an |
| 4437 |
* application at once. You should only set a non-default group window |
| 4438 |
* if your application pretends to be multiple applications. |
| 4439 |
**/ |
| 4440 |
void |
| 4441 |
gdk_window_set_group (GdkWindow *window, |
| 4442 |
GdkWindow *leader) |
| 4443 |
{ |
| 4444 |
GdkToplevelX11 *toplevel; |
| 4445 |
|
| 4446 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 4447 |
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD); |
| 4448 |
g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader)); |
| 4449 |
|
| 4450 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4451 |
(leader != NULL && GDK_WINDOW_DESTROYED (leader)) || |
| 4452 |
!WINDOW_IS_TOPLEVEL (window)) |
| 4453 |
return; |
| 4454 |
|
| 4455 |
toplevel = _gdk_x11_window_get_toplevel (window); |
| 4456 |
|
| 4457 |
if (leader == NULL) |
| 4458 |
leader = gdk_display_get_default_group (gdk_drawable_get_display (window)); |
| 4459 |
|
| 4460 |
if (toplevel->group_leader != leader) |
| 4461 |
{ |
| 4462 |
if (toplevel->group_leader) |
| 4463 |
g_object_unref (toplevel->group_leader); |
| 4464 |
toplevel->group_leader = g_object_ref (leader); |
| 4465 |
(_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE; |
| 4466 |
} |
| 4467 |
|
| 4468 |
update_wm_hints (window, FALSE); |
| 4469 |
} |
| 4470 |
|
| 4471 |
static MotifWmHints * |
| 4472 |
gdk_window_get_mwm_hints (GdkWindow *window) |
| 4473 |
{ |
| 4474 |
GdkDisplay *display; |
| 4475 |
Atom hints_atom = None; |
| 4476 |
guchar *data; |
| 4477 |
Atom type; |
| 4478 |
gint format; |
| 4479 |
gulong nitems; |
| 4480 |
gulong bytes_after; |
| 4481 |
|
| 4482 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4483 |
return NULL; |
| 4484 |
|
| 4485 |
display = gdk_drawable_get_display (window); |
| 4486 |
|
| 4487 |
hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS); |
| 4488 |
|
| 4489 |
XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), |
| 4490 |
hints_atom, 0, sizeof (MotifWmHints)/sizeof (long), |
| 4491 |
False, AnyPropertyType, &type, &format, &nitems, |
| 4492 |
&bytes_after, &data); |
| 4493 |
|
| 4494 |
if (type == None) |
| 4495 |
return NULL; |
| 4496 |
|
| 4497 |
return (MotifWmHints *)data; |
| 4498 |
} |
| 4499 |
|
| 4500 |
static void |
| 4501 |
gdk_window_set_mwm_hints (GdkWindow *window, |
| 4502 |
MotifWmHints *new_hints) |
| 4503 |
{ |
| 4504 |
GdkDisplay *display; |
| 4505 |
Atom hints_atom = None; |
| 4506 |
guchar *data; |
| 4507 |
MotifWmHints *hints; |
| 4508 |
Atom type; |
| 4509 |
gint format; |
| 4510 |
gulong nitems; |
| 4511 |
gulong bytes_after; |
| 4512 |
|
| 4513 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4514 |
return; |
| 4515 |
|
| 4516 |
display = gdk_drawable_get_display (window); |
| 4517 |
|
| 4518 |
hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS); |
| 4519 |
|
| 4520 |
XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), |
| 4521 |
hints_atom, 0, sizeof (MotifWmHints)/sizeof (long), |
| 4522 |
False, AnyPropertyType, &type, &format, &nitems, |
| 4523 |
&bytes_after, &data); |
| 4524 |
|
| 4525 |
if (type == None) |
| 4526 |
hints = new_hints; |
| 4527 |
else |
| 4528 |
{ |
| 4529 |
hints = (MotifWmHints *)data; |
| 4530 |
|
| 4531 |
if (new_hints->flags & MWM_HINTS_FUNCTIONS) |
| 4532 |
{ |
| 4533 |
hints->flags |= MWM_HINTS_FUNCTIONS; |
| 4534 |
hints->functions = new_hints->functions; |
| 4535 |
} |
| 4536 |
if (new_hints->flags & MWM_HINTS_DECORATIONS) |
| 4537 |
{ |
| 4538 |
hints->flags |= MWM_HINTS_DECORATIONS; |
| 4539 |
hints->decorations = new_hints->decorations; |
| 4540 |
} |
| 4541 |
} |
| 4542 |
|
| 4543 |
XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), |
| 4544 |
hints_atom, hints_atom, 32, PropModeReplace, |
| 4545 |
(guchar *)hints, sizeof (MotifWmHints)/sizeof (long)); |
| 4546 |
|
| 4547 |
if (hints != new_hints) |
| 4548 |
XFree (hints); |
| 4549 |
} |
| 4550 |
|
| 4551 |
/** |
| 4552 |
* gdk_window_set_decorations: |
| 4553 |
* @window: a toplevel #GdkWindow |
| 4554 |
* @decorations: decoration hint mask |
| 4555 |
* |
| 4556 |
* "Decorations" are the features the window manager adds to a toplevel #GdkWindow. |
| 4557 |
* This function sets the traditional Motif window manager hints that tell the |
| 4558 |
* window manager which decorations you would like your window to have. |
| 4559 |
* Usually you should use gtk_window_set_decorated() on a #GtkWindow instead of |
| 4560 |
* using the GDK function directly. |
| 4561 |
* |
| 4562 |
* The @decorations argument is the logical OR of the fields in |
| 4563 |
* the #GdkWMDecoration enumeration. If #GDK_DECOR_ALL is included in the |
| 4564 |
* mask, the other bits indicate which decorations should be turned off. |
| 4565 |
* If #GDK_DECOR_ALL is not included, then the other bits indicate |
| 4566 |
* which decorations should be turned on. |
| 4567 |
* |
| 4568 |
* Most window managers honor a decorations hint of 0 to disable all decorations, |
| 4569 |
* but very few honor all possible combinations of bits. |
| 4570 |
* |
| 4571 |
**/ |
| 4572 |
void |
| 4573 |
gdk_window_set_decorations (GdkWindow *window, |
| 4574 |
GdkWMDecoration decorations) |
| 4575 |
{ |
| 4576 |
MotifWmHints hints; |
| 4577 |
|
| 4578 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4579 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4580 |
return; |
| 4581 |
|
| 4582 |
/* initialize to zero to avoid writing uninitialized data to socket */ |
| 4583 |
memset(&hints, 0, sizeof(hints)); |
| 4584 |
hints.flags = MWM_HINTS_DECORATIONS; |
| 4585 |
hints.decorations = decorations; |
| 4586 |
|
| 4587 |
gdk_window_set_mwm_hints (window, &hints); |
| 4588 |
} |
| 4589 |
|
| 4590 |
/** |
| 4591 |
* gdk_window_get_decorations: |
| 4592 |
* @window: The toplevel #GdkWindow to get the decorations from |
| 4593 |
* @decorations: The window decorations will be written here |
| 4594 |
* |
| 4595 |
* Returns the decorations set on the GdkWindow with #gdk_window_set_decorations |
| 4596 |
* Returns: TRUE if the window has decorations set, FALSE otherwise. |
| 4597 |
**/ |
| 4598 |
gboolean |
| 4599 |
gdk_window_get_decorations(GdkWindow *window, |
| 4600 |
GdkWMDecoration *decorations) |
| 4601 |
{ |
| 4602 |
MotifWmHints *hints; |
| 4603 |
gboolean result = FALSE; |
| 4604 |
|
| 4605 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4606 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4607 |
return FALSE; |
| 4608 |
|
| 4609 |
hints = gdk_window_get_mwm_hints (window); |
| 4610 |
|
| 4611 |
if (hints) |
| 4612 |
{ |
| 4613 |
if (hints->flags & MWM_HINTS_DECORATIONS) |
| 4614 |
{ |
| 4615 |
if (decorations) |
| 4616 |
*decorations = hints->decorations; |
| 4617 |
result = TRUE; |
| 4618 |
} |
| 4619 |
|
| 4620 |
XFree (hints); |
| 4621 |
} |
| 4622 |
|
| 4623 |
return result; |
| 4624 |
} |
| 4625 |
|
| 4626 |
/** |
| 4627 |
* gdk_window_set_functions: |
| 4628 |
* @window: a toplevel #GdkWindow |
| 4629 |
* @functions: bitmask of operations to allow on @window |
| 4630 |
* |
| 4631 |
* Sets hints about the window management functions to make available |
| 4632 |
* via buttons on the window frame. |
| 4633 |
* |
| 4634 |
* On the X backend, this function sets the traditional Motif window |
| 4635 |
* manager hint for this purpose. However, few window managers do |
| 4636 |
* anything reliable or interesting with this hint. Many ignore it |
| 4637 |
* entirely. |
| 4638 |
* |
| 4639 |
* The @functions argument is the logical OR of values from the |
| 4640 |
* #GdkWMFunction enumeration. If the bitmask includes #GDK_FUNC_ALL, |
| 4641 |
* then the other bits indicate which functions to disable; if |
| 4642 |
* it doesn't include #GDK_FUNC_ALL, it indicates which functions to |
| 4643 |
* enable. |
| 4644 |
* |
| 4645 |
**/ |
| 4646 |
void |
| 4647 |
gdk_window_set_functions (GdkWindow *window, |
| 4648 |
GdkWMFunction functions) |
| 4649 |
{ |
| 4650 |
MotifWmHints hints; |
| 4651 |
|
| 4652 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 4653 |
|
| 4654 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4655 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4656 |
return; |
| 4657 |
|
| 4658 |
/* initialize to zero to avoid writing uninitialized data to socket */ |
| 4659 |
memset(&hints, 0, sizeof(hints)); |
| 4660 |
hints.flags = MWM_HINTS_FUNCTIONS; |
| 4661 |
hints.functions = functions; |
| 4662 |
|
| 4663 |
gdk_window_set_mwm_hints (window, &hints); |
| 4664 |
} |
| 4665 |
|
| 4666 |
GdkRegion * |
| 4667 |
_xwindow_get_shape (Display *xdisplay, |
| 4668 |
Window window, |
| 4669 |
gint shape_type) |
| 4670 |
{ |
| 4671 |
GdkRegion *shape; |
| 4672 |
GdkRectangle *rl; |
| 4673 |
XRectangle *xrl; |
| 4674 |
gint rn, ord, i; |
| 4675 |
|
| 4676 |
shape = NULL; |
| 4677 |
rn = 0; |
| 4678 |
|
| 4679 |
/* Note that XShapeGetRectangles returns NULL in two situations: |
| 4680 |
* - the server doesn't support the SHAPE extension |
| 4681 |
* - the shape is empty |
| 4682 |
* |
| 4683 |
* Since we can't discriminate these here, we always return |
| 4684 |
* an empty shape. It is the callers responsibility to check |
| 4685 |
* whether the server supports the SHAPE extensions beforehand. |
| 4686 |
*/ |
| 4687 |
xrl = XShapeGetRectangles (xdisplay, window, shape_type, &rn, &ord); |
| 4688 |
|
| 4689 |
if (rn == 0) |
| 4690 |
return gdk_region_new (); /* Empty */ |
| 4691 |
|
| 4692 |
if (ord != YXBanded) |
| 4693 |
{ |
| 4694 |
/* This really shouldn't happen with any xserver, as they |
| 4695 |
* generally convert regions to YXBanded internally |
| 4696 |
*/ |
| 4697 |
g_warning ("non YXBanded shape masks not supported"); |
| 4698 |
XFree (xrl); |
| 4699 |
return NULL; |
| 4700 |
} |
| 4701 |
|
| 4702 |
rl = g_new (GdkRectangle, rn); |
| 4703 |
for (i = 0; i < rn; i++) |
| 4704 |
{ |
| 4705 |
rl[i].x = xrl[i].x; |
| 4706 |
rl[i].y = xrl[i].y; |
| 4707 |
rl[i].width = xrl[i].width; |
| 4708 |
rl[i].height = xrl[i].height; |
| 4709 |
} |
| 4710 |
XFree (xrl); |
| 4711 |
|
| 4712 |
shape = _gdk_region_new_from_yxbanded_rects (rl, rn); |
| 4713 |
g_free (rl); |
| 4714 |
|
| 4715 |
return shape; |
| 4716 |
} |
| 4717 |
|
| 4718 |
|
| 4719 |
GdkRegion * |
| 4720 |
_gdk_windowing_get_shape_for_mask (GdkBitmap *mask) |
| 4721 |
{ |
| 4722 |
GdkDisplay *display; |
| 4723 |
Window window; |
| 4724 |
GdkRegion *region; |
| 4725 |
|
| 4726 |
display = gdk_drawable_get_display (GDK_DRAWABLE (mask)); |
| 4727 |
|
| 4728 |
window = XCreateSimpleWindow (GDK_DISPLAY_XDISPLAY (display), |
| 4729 |
GDK_SCREEN_XROOTWIN (gdk_drawable_get_screen (mask)), |
| 4730 |
-1, -1, 1, 1, 0, |
| 4731 |
0, 0); |
| 4732 |
XShapeCombineMask (GDK_DISPLAY_XDISPLAY (display), |
| 4733 |
window, |
| 4734 |
ShapeBounding, |
| 4735 |
0, 0, |
| 4736 |
GDK_PIXMAP_XID (mask), |
| 4737 |
ShapeSet); |
| 4738 |
|
| 4739 |
region = _xwindow_get_shape (GDK_DISPLAY_XDISPLAY (display), |
| 4740 |
window, ShapeBounding); |
| 4741 |
|
| 4742 |
XDestroyWindow (GDK_DISPLAY_XDISPLAY (display), window); |
| 4743 |
|
| 4744 |
return region; |
| 4745 |
} |
| 4746 |
|
| 4747 |
GdkRegion * |
| 4748 |
_gdk_windowing_window_get_shape (GdkWindow *window) |
| 4749 |
{ |
| 4750 |
if (!GDK_WINDOW_DESTROYED (window) && |
| 4751 |
gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))) |
| 4752 |
return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window), |
| 4753 |
GDK_WINDOW_XID (window), ShapeBounding); |
| 4754 |
|
| 4755 |
return NULL; |
| 4756 |
} |
| 4757 |
|
| 4758 |
GdkRegion * |
| 4759 |
_gdk_windowing_window_get_input_shape (GdkWindow *window) |
| 4760 |
{ |
| 4761 |
#if defined(ShapeInput) |
| 4762 |
if (!GDK_WINDOW_DESTROYED (window) && |
| 4763 |
gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window))) |
| 4764 |
return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window), |
| 4765 |
GDK_WINDOW_XID (window), |
| 4766 |
ShapeInput); |
| 4767 |
#endif |
| 4768 |
|
| 4769 |
return NULL; |
| 4770 |
} |
| 4771 |
|
| 4772 |
static void |
| 4773 |
gdk_window_set_static_bit_gravity (GdkWindow *window, |
| 4774 |
gboolean on) |
| 4775 |
{ |
| 4776 |
XSetWindowAttributes xattributes; |
| 4777 |
GdkWindowObject *private; |
| 4778 |
guint xattributes_mask = 0; |
| 4779 |
|
| 4780 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 4781 |
|
| 4782 |
private = GDK_WINDOW_OBJECT (window); |
| 4783 |
if (private->input_only) |
| 4784 |
return; |
| 4785 |
|
| 4786 |
xattributes.bit_gravity = StaticGravity; |
| 4787 |
xattributes_mask |= CWBitGravity; |
| 4788 |
xattributes.bit_gravity = on ? StaticGravity : ForgetGravity; |
| 4789 |
XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window), |
| 4790 |
GDK_WINDOW_XID (window), |
| 4791 |
CWBitGravity, &xattributes); |
| 4792 |
} |
| 4793 |
|
| 4794 |
static void |
| 4795 |
gdk_window_set_static_win_gravity (GdkWindow *window, |
| 4796 |
gboolean on) |
| 4797 |
{ |
| 4798 |
XSetWindowAttributes xattributes; |
| 4799 |
|
| 4800 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 4801 |
|
| 4802 |
xattributes.win_gravity = on ? StaticGravity : NorthWestGravity; |
| 4803 |
|
| 4804 |
XChangeWindowAttributes (GDK_WINDOW_XDISPLAY (window), |
| 4805 |
GDK_WINDOW_XID (window), |
| 4806 |
CWWinGravity, &xattributes); |
| 4807 |
} |
| 4808 |
|
| 4809 |
static gboolean |
| 4810 |
gdk_window_x11_set_static_gravities (GdkWindow *window, |
| 4811 |
gboolean use_static) |
| 4812 |
{ |
| 4813 |
GdkWindowObject *private = (GdkWindowObject *)window; |
| 4814 |
GList *tmp_list; |
| 4815 |
|
| 4816 |
if (!use_static == !private->guffaw_gravity) |
| 4817 |
return TRUE; |
| 4818 |
|
| 4819 |
private->guffaw_gravity = use_static; |
| 4820 |
|
| 4821 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 4822 |
{ |
| 4823 |
gdk_window_set_static_bit_gravity (window, use_static); |
| 4824 |
|
| 4825 |
tmp_list = private->children; |
| 4826 |
while (tmp_list) |
| 4827 |
{ |
| 4828 |
gdk_window_set_static_win_gravity (tmp_list->data, use_static); |
| 4829 |
|
| 4830 |
tmp_list = tmp_list->next; |
| 4831 |
} |
| 4832 |
} |
| 4833 |
|
| 4834 |
return TRUE; |
| 4835 |
} |
| 4836 |
|
| 4837 |
static void |
| 4838 |
wmspec_moveresize (GdkWindow *window, |
| 4839 |
gint direction, |
| 4840 |
gint root_x, |
| 4841 |
gint root_y, |
| 4842 |
guint32 timestamp) |
| 4843 |
{ |
| 4844 |
GdkDisplay *display = GDK_WINDOW_DISPLAY (window); |
| 4845 |
|
| 4846 |
XClientMessageEvent xclient; |
| 4847 |
|
| 4848 |
/* Release passive grab */ |
| 4849 |
gdk_display_pointer_ungrab (display, timestamp); |
| 4850 |
|
| 4851 |
memset (&xclient, 0, sizeof (xclient)); |
| 4852 |
xclient.type = ClientMessage; |
| 4853 |
xclient.window = GDK_WINDOW_XID (window); |
| 4854 |
xclient.message_type = |
| 4855 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE"); |
| 4856 |
xclient.format = 32; |
| 4857 |
xclient.data.l[0] = root_x; |
| 4858 |
xclient.data.l[1] = root_y; |
| 4859 |
xclient.data.l[2] = direction; |
| 4860 |
xclient.data.l[3] = 0; |
| 4861 |
xclient.data.l[4] = 0; |
| 4862 |
|
| 4863 |
XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False, |
| 4864 |
SubstructureRedirectMask | SubstructureNotifyMask, |
| 4865 |
(XEvent *)&xclient); |
| 4866 |
} |
| 4867 |
|
| 4868 |
typedef struct _MoveResizeData MoveResizeData; |
| 4869 |
|
| 4870 |
struct _MoveResizeData |
| 4871 |
{ |
| 4872 |
GdkDisplay *display; |
| 4873 |
|
| 4874 |
GdkWindow *moveresize_window; |
| 4875 |
GdkWindow *moveresize_emulation_window; |
| 4876 |
gboolean is_resize; |
| 4877 |
GdkWindowEdge resize_edge; |
| 4878 |
gint moveresize_button; |
| 4879 |
gint moveresize_x; |
| 4880 |
gint moveresize_y; |
| 4881 |
gint moveresize_orig_x; |
| 4882 |
gint moveresize_orig_y; |
| 4883 |
gint moveresize_orig_width; |
| 4884 |
gint moveresize_orig_height; |
| 4885 |
GdkWindowHints moveresize_geom_mask; |
| 4886 |
GdkGeometry moveresize_geometry; |
| 4887 |
Time moveresize_process_time; |
| 4888 |
XEvent *moveresize_pending_event; |
| 4889 |
}; |
| 4890 |
|
| 4891 |
/* From the WM spec */ |
| 4892 |
#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0 |
| 4893 |
#define _NET_WM_MOVERESIZE_SIZE_TOP 1 |
| 4894 |
#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2 |
| 4895 |
#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3 |
| 4896 |
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4 |
| 4897 |
#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5 |
| 4898 |
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6 |
| 4899 |
#define _NET_WM_MOVERESIZE_SIZE_LEFT 7 |
| 4900 |
#define _NET_WM_MOVERESIZE_MOVE 8 |
| 4901 |
|
| 4902 |
static void |
| 4903 |
wmspec_resize_drag (GdkWindow *window, |
| 4904 |
GdkWindowEdge edge, |
| 4905 |
gint button, |
| 4906 |
gint root_x, |
| 4907 |
gint root_y, |
| 4908 |
guint32 timestamp) |
| 4909 |
{ |
| 4910 |
gint direction; |
| 4911 |
|
| 4912 |
/* Let the compiler turn a switch into a table, instead |
| 4913 |
* of doing the table manually, this way is easier to verify. |
| 4914 |
*/ |
| 4915 |
switch (edge) |
| 4916 |
{ |
| 4917 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 4918 |
direction = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; |
| 4919 |
break; |
| 4920 |
|
| 4921 |
case GDK_WINDOW_EDGE_NORTH: |
| 4922 |
direction = _NET_WM_MOVERESIZE_SIZE_TOP; |
| 4923 |
break; |
| 4924 |
|
| 4925 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 4926 |
direction = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; |
| 4927 |
break; |
| 4928 |
|
| 4929 |
case GDK_WINDOW_EDGE_WEST: |
| 4930 |
direction = _NET_WM_MOVERESIZE_SIZE_LEFT; |
| 4931 |
break; |
| 4932 |
|
| 4933 |
case GDK_WINDOW_EDGE_EAST: |
| 4934 |
direction = _NET_WM_MOVERESIZE_SIZE_RIGHT; |
| 4935 |
break; |
| 4936 |
|
| 4937 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 4938 |
direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; |
| 4939 |
break; |
| 4940 |
|
| 4941 |
case GDK_WINDOW_EDGE_SOUTH: |
| 4942 |
direction = _NET_WM_MOVERESIZE_SIZE_BOTTOM; |
| 4943 |
break; |
| 4944 |
|
| 4945 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 4946 |
direction = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; |
| 4947 |
break; |
| 4948 |
|
| 4949 |
default: |
| 4950 |
g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!", |
| 4951 |
edge); |
| 4952 |
return; |
| 4953 |
} |
| 4954 |
|
| 4955 |
wmspec_moveresize (window, direction, root_x, root_y, timestamp); |
| 4956 |
} |
| 4957 |
|
| 4958 |
static MoveResizeData * |
| 4959 |
get_move_resize_data (GdkDisplay *display, |
| 4960 |
gboolean create) |
| 4961 |
{ |
| 4962 |
MoveResizeData *mv_resize; |
| 4963 |
static GQuark move_resize_quark = 0; |
| 4964 |
|
| 4965 |
if (!move_resize_quark) |
| 4966 |
move_resize_quark = g_quark_from_static_string ("gdk-window-moveresize"); |
| 4967 |
|
| 4968 |
mv_resize = g_object_get_qdata (G_OBJECT (display), move_resize_quark); |
| 4969 |
|
| 4970 |
if (!mv_resize && create) |
| 4971 |
{ |
| 4972 |
mv_resize = g_new0 (MoveResizeData, 1); |
| 4973 |
mv_resize->display = display; |
| 4974 |
|
| 4975 |
g_object_set_qdata (G_OBJECT (display), move_resize_quark, mv_resize); |
| 4976 |
} |
| 4977 |
|
| 4978 |
return mv_resize; |
| 4979 |
} |
| 4980 |
|
| 4981 |
static void |
| 4982 |
update_pos (MoveResizeData *mv_resize, |
| 4983 |
gint new_root_x, |
| 4984 |
gint new_root_y) |
| 4985 |
{ |
| 4986 |
gint dx, dy; |
| 4987 |
|
| 4988 |
dx = new_root_x - mv_resize->moveresize_x; |
| 4989 |
dy = new_root_y - mv_resize->moveresize_y; |
| 4990 |
|
| 4991 |
if (mv_resize->is_resize) |
| 4992 |
{ |
| 4993 |
gint x, y, w, h; |
| 4994 |
|
| 4995 |
x = mv_resize->moveresize_orig_x; |
| 4996 |
y = mv_resize->moveresize_orig_y; |
| 4997 |
|
| 4998 |
w = mv_resize->moveresize_orig_width; |
| 4999 |
h = mv_resize->moveresize_orig_height; |
| 5000 |
|
| 5001 |
switch (mv_resize->resize_edge) |
| 5002 |
{ |
| 5003 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 5004 |
x += dx; |
| 5005 |
y += dy; |
| 5006 |
w -= dx; |
| 5007 |
h -= dy; |
| 5008 |
break; |
| 5009 |
case GDK_WINDOW_EDGE_NORTH: |
| 5010 |
y += dy; |
| 5011 |
h -= dy; |
| 5012 |
break; |
| 5013 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 5014 |
y += dy; |
| 5015 |
h -= dy; |
| 5016 |
w += dx; |
| 5017 |
break; |
| 5018 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 5019 |
h += dy; |
| 5020 |
x += dx; |
| 5021 |
w -= dx; |
| 5022 |
break; |
| 5023 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 5024 |
w += dx; |
| 5025 |
h += dy; |
| 5026 |
break; |
| 5027 |
case GDK_WINDOW_EDGE_SOUTH: |
| 5028 |
h += dy; |
| 5029 |
break; |
| 5030 |
case GDK_WINDOW_EDGE_EAST: |
| 5031 |
w += dx; |
| 5032 |
break; |
| 5033 |
case GDK_WINDOW_EDGE_WEST: |
| 5034 |
x += dx; |
| 5035 |
w -= dx; |
| 5036 |
break; |
| 5037 |
} |
| 5038 |
|
| 5039 |
x = MAX (x, 0); |
| 5040 |
y = MAX (y, 0); |
| 5041 |
w = MAX (w, 1); |
| 5042 |
h = MAX (h, 1); |
| 5043 |
|
| 5044 |
if (mv_resize->moveresize_geom_mask) |
| 5045 |
{ |
| 5046 |
gdk_window_constrain_size (&mv_resize->moveresize_geometry, |
| 5047 |
mv_resize->moveresize_geom_mask, |
| 5048 |
w, h, &w, &h); |
| 5049 |
} |
| 5050 |
|
| 5051 |
gdk_window_move_resize (mv_resize->moveresize_window, x, y, w, h); |
| 5052 |
} |
| 5053 |
else |
| 5054 |
{ |
| 5055 |
gint x, y; |
| 5056 |
|
| 5057 |
x = mv_resize->moveresize_orig_x + dx; |
| 5058 |
y = mv_resize->moveresize_orig_y + dy; |
| 5059 |
|
| 5060 |
gdk_window_move (mv_resize->moveresize_window, x, y); |
| 5061 |
} |
| 5062 |
} |
| 5063 |
|
| 5064 |
static void |
| 5065 |
finish_drag (MoveResizeData *mv_resize) |
| 5066 |
{ |
| 5067 |
gdk_window_destroy (mv_resize->moveresize_emulation_window); |
| 5068 |
mv_resize->moveresize_emulation_window = NULL; |
| 5069 |
g_object_unref (mv_resize->moveresize_window); |
| 5070 |
mv_resize->moveresize_window = NULL; |
| 5071 |
|
| 5072 |
if (mv_resize->moveresize_pending_event) |
| 5073 |
{ |
| 5074 |
g_free (mv_resize->moveresize_pending_event); |
| 5075 |
mv_resize->moveresize_pending_event = NULL; |
| 5076 |
} |
| 5077 |
} |
| 5078 |
|
| 5079 |
static int |
| 5080 |
lookahead_motion_predicate (Display *xdisplay, |
| 5081 |
XEvent *event, |
| 5082 |
XPointer arg) |
| 5083 |
{ |
| 5084 |
gboolean *seen_release = (gboolean *)arg; |
| 5085 |
GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay); |
| 5086 |
MoveResizeData *mv_resize = get_move_resize_data (display, FALSE); |
| 5087 |
|
| 5088 |
if (*seen_release) |
| 5089 |
return False; |
| 5090 |
|
| 5091 |
switch (event->xany.type) |
| 5092 |
{ |
| 5093 |
case ButtonRelease: |
| 5094 |
*seen_release = TRUE; |
| 5095 |
break; |
| 5096 |
case MotionNotify: |
| 5097 |
mv_resize->moveresize_process_time = event->xmotion.time; |
| 5098 |
break; |
| 5099 |
default: |
| 5100 |
break; |
| 5101 |
} |
| 5102 |
|
| 5103 |
return False; |
| 5104 |
} |
| 5105 |
|
| 5106 |
static gboolean |
| 5107 |
moveresize_lookahead (MoveResizeData *mv_resize, |
| 5108 |
XEvent *event) |
| 5109 |
{ |
| 5110 |
XEvent tmp_event; |
| 5111 |
gboolean seen_release = FALSE; |
| 5112 |
|
| 5113 |
if (mv_resize->moveresize_process_time) |
| 5114 |
{ |
| 5115 |
if (event->xmotion.time == mv_resize->moveresize_process_time) |
| 5116 |
{ |
| 5117 |
mv_resize->moveresize_process_time = 0; |
| 5118 |
return TRUE; |
| 5119 |
} |
| 5120 |
else |
| 5121 |
return FALSE; |
| 5122 |
} |
| 5123 |
|
| 5124 |
XCheckIfEvent (event->xany.display, &tmp_event, |
| 5125 |
lookahead_motion_predicate, (XPointer) & seen_release); |
| 5126 |
|
| 5127 |
return mv_resize->moveresize_process_time == 0; |
| 5128 |
} |
| 5129 |
|
| 5130 |
gboolean |
| 5131 |
_gdk_moveresize_handle_event (XEvent *event) |
| 5132 |
{ |
| 5133 |
guint button_mask = 0; |
| 5134 |
GdkWindowObject *window_private; |
| 5135 |
GdkDisplay *display = gdk_x11_lookup_xdisplay (event->xany.display); |
| 5136 |
MoveResizeData *mv_resize = get_move_resize_data (display, FALSE); |
| 5137 |
|
| 5138 |
if (!mv_resize || !mv_resize->moveresize_window) |
| 5139 |
return FALSE; |
| 5140 |
|
| 5141 |
window_private = (GdkWindowObject *) mv_resize->moveresize_window; |
| 5142 |
|
| 5143 |
button_mask = GDK_BUTTON1_MASK << (mv_resize->moveresize_button - 1); |
| 5144 |
|
| 5145 |
switch (event->xany.type) |
| 5146 |
{ |
| 5147 |
case MotionNotify: |
| 5148 |
if (window_private->resize_count > 0) |
| 5149 |
{ |
| 5150 |
if (mv_resize->moveresize_pending_event) |
| 5151 |
*mv_resize->moveresize_pending_event = *event; |
| 5152 |
else |
| 5153 |
mv_resize->moveresize_pending_event = |
| 5154 |
g_memdup (event, sizeof (XEvent)); |
| 5155 |
|
| 5156 |
break; |
| 5157 |
} |
| 5158 |
if (!moveresize_lookahead (mv_resize, event)) |
| 5159 |
break; |
| 5160 |
|
| 5161 |
update_pos (mv_resize, |
| 5162 |
event->xmotion.x_root, |
| 5163 |
event->xmotion.y_root); |
| 5164 |
|
| 5165 |
/* This should never be triggered in normal cases, but in the |
| 5166 |
* case where the drag started without an implicit grab being |
| 5167 |
* in effect, we could miss the release if it occurs before |
| 5168 |
* we grab the pointer; this ensures that we will never |
| 5169 |
* get a permanently stuck grab. |
| 5170 |
*/ |
| 5171 |
if ((event->xmotion.state & button_mask) == 0) |
| 5172 |
finish_drag (mv_resize); |
| 5173 |
break; |
| 5174 |
|
| 5175 |
case ButtonRelease: |
| 5176 |
update_pos (mv_resize, |
| 5177 |
event->xbutton.x_root, |
| 5178 |
event->xbutton.y_root); |
| 5179 |
|
| 5180 |
if (event->xbutton.button == mv_resize->moveresize_button) |
| 5181 |
finish_drag (mv_resize); |
| 5182 |
break; |
| 5183 |
} |
| 5184 |
return TRUE; |
| 5185 |
} |
| 5186 |
|
| 5187 |
gboolean |
| 5188 |
_gdk_moveresize_configure_done (GdkDisplay *display, |
| 5189 |
GdkWindow *window) |
| 5190 |
{ |
| 5191 |
XEvent *tmp_event; |
| 5192 |
MoveResizeData *mv_resize = get_move_resize_data (display, FALSE); |
| 5193 |
|
| 5194 |
if (!mv_resize || window != mv_resize->moveresize_window) |
| 5195 |
return FALSE; |
| 5196 |
|
| 5197 |
if (mv_resize->moveresize_pending_event) |
| 5198 |
{ |
| 5199 |
tmp_event = mv_resize->moveresize_pending_event; |
| 5200 |
mv_resize->moveresize_pending_event = NULL; |
| 5201 |
_gdk_moveresize_handle_event (tmp_event); |
| 5202 |
g_free (tmp_event); |
| 5203 |
} |
| 5204 |
|
| 5205 |
return TRUE; |
| 5206 |
} |
| 5207 |
|
| 5208 |
static void |
| 5209 |
create_moveresize_window (MoveResizeData *mv_resize, |
| 5210 |
guint32 timestamp) |
| 5211 |
{ |
| 5212 |
GdkWindowAttr attributes; |
| 5213 |
gint attributes_mask; |
| 5214 |
GdkGrabStatus status; |
| 5215 |
|
| 5216 |
g_assert (mv_resize->moveresize_emulation_window == NULL); |
| 5217 |
|
| 5218 |
attributes.x = -100; |
| 5219 |
attributes.y = -100; |
| 5220 |
attributes.width = 10; |
| 5221 |
attributes.height = 10; |
| 5222 |
attributes.window_type = GDK_WINDOW_TEMP; |
| 5223 |
attributes.wclass = GDK_INPUT_ONLY; |
| 5224 |
attributes.override_redirect = TRUE; |
| 5225 |
attributes.event_mask = 0; |
| 5226 |
|
| 5227 |
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR; |
| 5228 |
|
| 5229 |
mv_resize->moveresize_emulation_window = |
| 5230 |
gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (mv_resize->display)), |
| 5231 |
&attributes, |
| 5232 |
attributes_mask); |
| 5233 |
|
| 5234 |
gdk_window_show (mv_resize->moveresize_emulation_window); |
| 5235 |
|
| 5236 |
status = gdk_pointer_grab (mv_resize->moveresize_emulation_window, |
| 5237 |
FALSE, |
| 5238 |
GDK_BUTTON_RELEASE_MASK | |
| 5239 |
GDK_POINTER_MOTION_MASK, |
| 5240 |
NULL, |
| 5241 |
NULL, |
| 5242 |
timestamp); |
| 5243 |
|
| 5244 |
if (status != GDK_GRAB_SUCCESS) |
| 5245 |
{ |
| 5246 |
/* If this fails, some other client has grabbed the window |
| 5247 |
* already. |
| 5248 |
*/ |
| 5249 |
finish_drag (mv_resize); |
| 5250 |
} |
| 5251 |
|
| 5252 |
mv_resize->moveresize_process_time = 0; |
| 5253 |
} |
| 5254 |
|
| 5255 |
/* |
| 5256 |
Calculate mv_resize->moveresize_orig_x and mv_resize->moveresize_orig_y |
| 5257 |
so that calling XMoveWindow with these coordinates will not move the |
| 5258 |
window. |
| 5259 |
Note that this depends on the WM to implement ICCCM-compliant reference |
| 5260 |
point handling. |
| 5261 |
*/ |
| 5262 |
static void |
| 5263 |
calculate_unmoving_origin (MoveResizeData *mv_resize) |
| 5264 |
{ |
| 5265 |
GdkRectangle rect; |
| 5266 |
gint width, height; |
| 5267 |
|
| 5268 |
if (mv_resize->moveresize_geom_mask & GDK_HINT_WIN_GRAVITY && |
| 5269 |
mv_resize->moveresize_geometry.win_gravity == GDK_GRAVITY_STATIC) |
| 5270 |
{ |
| 5271 |
gdk_window_get_origin (mv_resize->moveresize_window, |
| 5272 |
&mv_resize->moveresize_orig_x, |
| 5273 |
&mv_resize->moveresize_orig_y); |
| 5274 |
} |
| 5275 |
else |
| 5276 |
{ |
| 5277 |
gdk_window_get_frame_extents (mv_resize->moveresize_window, &rect); |
| 5278 |
gdk_window_get_geometry (mv_resize->moveresize_window, |
| 5279 |
NULL, NULL, &width, &height, NULL); |
| 5280 |
|
| 5281 |
switch (mv_resize->moveresize_geometry.win_gravity) |
| 5282 |
{ |
| 5283 |
case GDK_GRAVITY_NORTH_WEST: |
| 5284 |
mv_resize->moveresize_orig_x = rect.x; |
| 5285 |
mv_resize->moveresize_orig_y = rect.y; |
| 5286 |
break; |
| 5287 |
case GDK_GRAVITY_NORTH: |
| 5288 |
mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2; |
| 5289 |
mv_resize->moveresize_orig_y = rect.y; |
| 5290 |
break; |
| 5291 |
case GDK_GRAVITY_NORTH_EAST: |
| 5292 |
mv_resize->moveresize_orig_x = rect.x + rect.width - width; |
| 5293 |
mv_resize->moveresize_orig_y = rect.y; |
| 5294 |
break; |
| 5295 |
case GDK_GRAVITY_WEST: |
| 5296 |
mv_resize->moveresize_orig_x = rect.x; |
| 5297 |
mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2; |
| 5298 |
break; |
| 5299 |
case GDK_GRAVITY_CENTER: |
| 5300 |
mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2; |
| 5301 |
mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2; |
| 5302 |
break; |
| 5303 |
case GDK_GRAVITY_EAST: |
| 5304 |
mv_resize->moveresize_orig_x = rect.x + rect.width - width; |
| 5305 |
mv_resize->moveresize_orig_y = rect.y + rect.height / 2 - height / 2; |
| 5306 |
break; |
| 5307 |
case GDK_GRAVITY_SOUTH_WEST: |
| 5308 |
mv_resize->moveresize_orig_x = rect.x; |
| 5309 |
mv_resize->moveresize_orig_y = rect.y + rect.height - height; |
| 5310 |
break; |
| 5311 |
case GDK_GRAVITY_SOUTH: |
| 5312 |
mv_resize->moveresize_orig_x = rect.x + rect.width / 2 - width / 2; |
| 5313 |
mv_resize->moveresize_orig_y = rect.y + rect.height - height; |
| 5314 |
break; |
| 5315 |
case GDK_GRAVITY_SOUTH_EAST: |
| 5316 |
mv_resize->moveresize_orig_x = rect.x + rect.width - width; |
| 5317 |
mv_resize->moveresize_orig_y = rect.y + rect.height - height; |
| 5318 |
break; |
| 5319 |
default: |
| 5320 |
mv_resize->moveresize_orig_x = rect.x; |
| 5321 |
mv_resize->moveresize_orig_y = rect.y; |
| 5322 |
break; |
| 5323 |
} |
| 5324 |
} |
| 5325 |
} |
| 5326 |
|
| 5327 |
static void |
| 5328 |
emulate_resize_drag (GdkWindow *window, |
| 5329 |
GdkWindowEdge edge, |
| 5330 |
gint button, |
| 5331 |
gint root_x, |
| 5332 |
gint root_y, |
| 5333 |
guint32 timestamp) |
| 5334 |
{ |
| 5335 |
MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE); |
| 5336 |
|
| 5337 |
mv_resize->is_resize = TRUE; |
| 5338 |
mv_resize->moveresize_button = button; |
| 5339 |
mv_resize->resize_edge = edge; |
| 5340 |
mv_resize->moveresize_x = root_x; |
| 5341 |
mv_resize->moveresize_y = root_y; |
| 5342 |
mv_resize->moveresize_window = g_object_ref (window); |
| 5343 |
|
| 5344 |
gdk_drawable_get_size (window, |
| 5345 |
&mv_resize->moveresize_orig_width, |
| 5346 |
&mv_resize->moveresize_orig_height); |
| 5347 |
|
| 5348 |
mv_resize->moveresize_geom_mask = 0; |
| 5349 |
gdk_window_get_geometry_hints (window, |
| 5350 |
&mv_resize->moveresize_geometry, |
| 5351 |
&mv_resize->moveresize_geom_mask); |
| 5352 |
|
| 5353 |
calculate_unmoving_origin (mv_resize); |
| 5354 |
|
| 5355 |
create_moveresize_window (mv_resize, timestamp); |
| 5356 |
} |
| 5357 |
|
| 5358 |
static void |
| 5359 |
emulate_move_drag (GdkWindow *window, |
| 5360 |
gint button, |
| 5361 |
gint root_x, |
| 5362 |
gint root_y, |
| 5363 |
guint32 timestamp) |
| 5364 |
{ |
| 5365 |
MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE); |
| 5366 |
|
| 5367 |
mv_resize->is_resize = FALSE; |
| 5368 |
mv_resize->moveresize_button = button; |
| 5369 |
mv_resize->moveresize_x = root_x; |
| 5370 |
mv_resize->moveresize_y = root_y; |
| 5371 |
|
| 5372 |
mv_resize->moveresize_window = g_object_ref (window); |
| 5373 |
|
| 5374 |
calculate_unmoving_origin (mv_resize); |
| 5375 |
|
| 5376 |
create_moveresize_window (mv_resize, timestamp); |
| 5377 |
} |
| 5378 |
|
| 5379 |
/** |
| 5380 |
* gdk_window_begin_resize_drag: |
| 5381 |
* @window: a toplevel #GdkWindow |
| 5382 |
* @edge: the edge or corner from which the drag is started |
| 5383 |
* @button: the button being used to drag |
| 5384 |
* @root_x: root window X coordinate of mouse click that began the drag |
| 5385 |
* @root_y: root window Y coordinate of mouse click that began the drag |
| 5386 |
* @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time()) |
| 5387 |
* |
| 5388 |
* Begins a window resize operation (for a toplevel window). |
| 5389 |
* You might use this function to implement a "window resize grip," for |
| 5390 |
* example; in fact #GtkStatusbar uses it. The function works best |
| 5391 |
* with window managers that support the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended Window Manager Hints</ulink>, but has a |
| 5392 |
* fallback implementation for other window managers. |
| 5393 |
* |
| 5394 |
**/ |
| 5395 |
void |
| 5396 |
gdk_window_begin_resize_drag (GdkWindow *window, |
| 5397 |
GdkWindowEdge edge, |
| 5398 |
gint button, |
| 5399 |
gint root_x, |
| 5400 |
gint root_y, |
| 5401 |
guint32 timestamp) |
| 5402 |
{ |
| 5403 |
if (GDK_WINDOW_DESTROYED (window) || |
| 5404 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 5405 |
return; |
| 5406 |
|
| 5407 |
if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window), |
| 5408 |
gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE"))) |
| 5409 |
wmspec_resize_drag (window, edge, button, root_x, root_y, timestamp); |
| 5410 |
else |
| 5411 |
emulate_resize_drag (window, edge, button, root_x, root_y, timestamp); |
| 5412 |
} |
| 5413 |
|
| 5414 |
/** |
| 5415 |
* gdk_window_begin_move_drag: |
| 5416 |
* @window: a toplevel #GdkWindow |
| 5417 |
* @button: the button being used to drag |
| 5418 |
* @root_x: root window X coordinate of mouse click that began the drag |
| 5419 |
* @root_y: root window Y coordinate of mouse click that began the drag |
| 5420 |
* @timestamp: timestamp of mouse click that began the drag |
| 5421 |
* |
| 5422 |
* Begins a window move operation (for a toplevel window). You might |
| 5423 |
* use this function to implement a "window move grip," for |
| 5424 |
* example. The function works best with window managers that support |
| 5425 |
* the <ulink url="http://www.freedesktop.org/Standards/wm-spec">Extended |
| 5426 |
* Window Manager Hints</ulink>, but has a fallback implementation for |
| 5427 |
* other window managers. |
| 5428 |
* |
| 5429 |
**/ |
| 5430 |
void |
| 5431 |
gdk_window_begin_move_drag (GdkWindow *window, |
| 5432 |
gint button, |
| 5433 |
gint root_x, |
| 5434 |
gint root_y, |
| 5435 |
guint32 timestamp) |
| 5436 |
{ |
| 5437 |
if (GDK_WINDOW_DESTROYED (window) || |
| 5438 |
!WINDOW_IS_TOPLEVEL (window)) |
| 5439 |
return; |
| 5440 |
|
| 5441 |
if (gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window), |
| 5442 |
gdk_atom_intern_static_string ("_NET_WM_MOVERESIZE"))) |
| 5443 |
wmspec_moveresize (window, _NET_WM_MOVERESIZE_MOVE, root_x, root_y, |
| 5444 |
timestamp); |
| 5445 |
else |
| 5446 |
emulate_move_drag (window, button, root_x, root_y, timestamp); |
| 5447 |
} |
| 5448 |
|
| 5449 |
/** |
| 5450 |
* gdk_window_enable_synchronized_configure: |
| 5451 |
* @window: a toplevel #GdkWindow |
| 5452 |
* |
| 5453 |
* Indicates that the application will cooperate with the window |
| 5454 |
* system in synchronizing the window repaint with the window |
| 5455 |
* manager during resizing operations. After an application calls |
| 5456 |
* this function, it must call gdk_window_configure_finished() every |
| 5457 |
* time it has finished all processing associated with a set of |
| 5458 |
* Configure events. Toplevel GTK+ windows automatically use this |
| 5459 |
* protocol. |
| 5460 |
* |
| 5461 |
* On X, calling this function makes @window participate in the |
| 5462 |
* _NET_WM_SYNC_REQUEST window manager protocol. |
| 5463 |
* |
| 5464 |
* Since: 2.6 |
| 5465 |
**/ |
| 5466 |
void |
| 5467 |
gdk_window_enable_synchronized_configure (GdkWindow *window) |
| 5468 |
{ |
| 5469 |
GdkWindowObject *private = (GdkWindowObject *)window; |
| 5470 |
GdkWindowImplX11 *impl; |
| 5471 |
|
| 5472 |
if (!GDK_IS_WINDOW_IMPL_X11 (private->impl)) |
| 5473 |
return; |
| 5474 |
|
| 5475 |
impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 5476 |
|
| 5477 |
if (!impl->use_synchronized_configure) |
| 5478 |
{ |
| 5479 |
/* This basically means you want to do fancy X specific stuff, so |
| 5480 |
ensure we have a native window */ |
| 5481 |
gdk_window_ensure_native (window); |
| 5482 |
|
| 5483 |
impl->use_synchronized_configure = TRUE; |
| 5484 |
ensure_sync_counter (window); |
| 5485 |
} |
| 5486 |
} |
| 5487 |
|
| 5488 |
/** |
| 5489 |
* gdk_window_configure_finished: |
| 5490 |
* @window: a toplevel #GdkWindow |
| 5491 |
* |
| 5492 |
* Signal to the window system that the application has finished |
| 5493 |
* handling Configure events it has received. Window Managers can |
| 5494 |
* use this to better synchronize the frame repaint with the |
| 5495 |
* application. GTK+ applications will automatically call this |
| 5496 |
* function when appropriate. |
| 5497 |
* |
| 5498 |
* This function can only be called if gdk_window_enable_synchronized_configure() |
| 5499 |
* was called previously. |
| 5500 |
* |
| 5501 |
* Since: 2.6 |
| 5502 |
**/ |
| 5503 |
void |
| 5504 |
gdk_window_configure_finished (GdkWindow *window) |
| 5505 |
{ |
| 5506 |
GdkWindowImplX11 *impl; |
| 5507 |
|
| 5508 |
if (!WINDOW_IS_TOPLEVEL (window)) |
| 5509 |
return; |
| 5510 |
|
| 5511 |
impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)window)->impl); |
| 5512 |
if (!impl->use_synchronized_configure) |
| 5513 |
return; |
| 5514 |
|
| 5515 |
#ifdef HAVE_XSYNC |
| 5516 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 5517 |
{ |
| 5518 |
GdkDisplay *display = GDK_WINDOW_DISPLAY (window); |
| 5519 |
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window); |
| 5520 |
|
| 5521 |
if (toplevel && toplevel->update_counter != None && |
| 5522 |
GDK_DISPLAY_X11 (display)->use_sync && |
| 5523 |
!XSyncValueIsZero (toplevel->current_counter_value)) |
| 5524 |
{ |
| 5525 |
XSyncSetCounter (GDK_WINDOW_XDISPLAY (window), |
| 5526 |
toplevel->update_counter, |
| 5527 |
toplevel->current_counter_value); |
| 5528 |
|
| 5529 |
XSyncIntToValue (&toplevel->current_counter_value, 0); |
| 5530 |
} |
| 5531 |
} |
| 5532 |
#endif |
| 5533 |
} |
| 5534 |
|
| 5535 |
void |
| 5536 |
_gdk_windowing_window_beep (GdkWindow *window) |
| 5537 |
{ |
| 5538 |
GdkDisplay *display; |
| 5539 |
|
| 5540 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5541 |
|
| 5542 |
display = GDK_WINDOW_DISPLAY (window); |
| 5543 |
|
| 5544 |
#ifdef HAVE_XKB |
| 5545 |
if (GDK_DISPLAY_X11 (display)->use_xkb) |
| 5546 |
XkbBell (GDK_DISPLAY_XDISPLAY (display), |
| 5547 |
GDK_WINDOW_XID (window), |
| 5548 |
0, |
| 5549 |
None); |
| 5550 |
else |
| 5551 |
#endif |
| 5552 |
gdk_display_beep (display); |
| 5553 |
} |
| 5554 |
|
| 5555 |
/** |
| 5556 |
* gdk_window_set_opacity: |
| 5557 |
* @window: a top-level #GdkWindow |
| 5558 |
* @opacity: opacity |
| 5559 |
* |
| 5560 |
* Request the windowing system to make @window partially transparent, |
| 5561 |
* with opacity 0 being fully transparent and 1 fully opaque. (Values |
| 5562 |
* of the opacity parameter are clamped to the [0,1] range.) |
| 5563 |
* |
| 5564 |
* On X11, this works only on X screens with a compositing manager |
| 5565 |
* running. |
| 5566 |
* |
| 5567 |
* For setting up per-pixel alpha, see gdk_screen_get_rgba_colormap(). |
| 5568 |
* For making non-toplevel windows translucent, see |
| 5569 |
* gdk_window_set_composited(). |
| 5570 |
* |
| 5571 |
* Since: 2.12 |
| 5572 |
*/ |
| 5573 |
void |
| 5574 |
gdk_window_set_opacity (GdkWindow *window, |
| 5575 |
gdouble opacity) |
| 5576 |
{ |
| 5577 |
GdkDisplay *display; |
| 5578 |
gulong cardinal; |
| 5579 |
|
| 5580 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5581 |
|
| 5582 |
if (GDK_WINDOW_DESTROYED (window) || |
| 5583 |
!WINDOW_IS_TOPLEVEL (window)) |
| 5584 |
return; |
| 5585 |
|
| 5586 |
display = gdk_drawable_get_display (window); |
| 5587 |
|
| 5588 |
if (opacity < 0) |
| 5589 |
opacity = 0; |
| 5590 |
else if (opacity > 1) |
| 5591 |
opacity = 1; |
| 5592 |
|
| 5593 |
cardinal = opacity * 0xffffffff; |
| 5594 |
|
| 5595 |
if (cardinal == 0xffffffff) |
| 5596 |
XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), |
| 5597 |
GDK_WINDOW_XID (window), |
| 5598 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY")); |
| 5599 |
else |
| 5600 |
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), |
| 5601 |
GDK_WINDOW_XID (window), |
| 5602 |
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"), |
| 5603 |
XA_CARDINAL, 32, |
| 5604 |
PropModeReplace, |
| 5605 |
(guchar *) &cardinal, 1); |
| 5606 |
} |
| 5607 |
|
| 5608 |
void |
| 5609 |
_gdk_windowing_window_set_composited (GdkWindow *window, |
| 5610 |
gboolean composited) |
| 5611 |
{ |
| 5612 |
#if defined(HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES) |
| 5613 |
GdkWindowObject *private = (GdkWindowObject *) window; |
| 5614 |
GdkWindowImplX11 *impl; |
| 5615 |
GdkDisplay *display; |
| 5616 |
Display *dpy; |
| 5617 |
Window xid; |
| 5618 |
|
| 5619 |
impl = GDK_WINDOW_IMPL_X11 (private->impl); |
| 5620 |
|
| 5621 |
display = gdk_screen_get_display (GDK_DRAWABLE_IMPL_X11 (impl)->screen); |
| 5622 |
dpy = GDK_DISPLAY_XDISPLAY (display); |
| 5623 |
xid = GDK_WINDOW_XWINDOW (private); |
| 5624 |
|
| 5625 |
if (composited) |
| 5626 |
{ |
| 5627 |
XCompositeRedirectWindow (dpy, xid, CompositeRedirectManual); |
| 5628 |
impl->damage = XDamageCreate (dpy, xid, XDamageReportBoundingBox); |
| 5629 |
} |
| 5630 |
else |
| 5631 |
{ |
| 5632 |
XCompositeUnredirectWindow (dpy, xid, CompositeRedirectManual); |
| 5633 |
XDamageDestroy (dpy, impl->damage); |
| 5634 |
impl->damage = None; |
| 5635 |
} |
| 5636 |
#endif |
| 5637 |
} |
| 5638 |
|
| 5639 |
void |
| 5640 |
_gdk_windowing_window_process_updates_recurse (GdkWindow *window, |
| 5641 |
GdkRegion *region) |
| 5642 |
{ |
| 5643 |
_gdk_window_process_updates_recurse (window, region); |
| 5644 |
} |
| 5645 |
|
| 5646 |
void |
| 5647 |
_gdk_windowing_before_process_all_updates (void) |
| 5648 |
{ |
| 5649 |
} |
| 5650 |
|
| 5651 |
void |
| 5652 |
_gdk_windowing_after_process_all_updates (void) |
| 5653 |
{ |
| 5654 |
} |
| 5655 |
|
| 5656 |
static void |
| 5657 |
gdk_window_impl_iface_init (GdkWindowImplIface *iface) |
| 5658 |
{ |
| 5659 |
iface->show = gdk_window_x11_show; |
| 5660 |
iface->hide = gdk_window_x11_hide; |
| 5661 |
iface->withdraw = gdk_window_x11_withdraw; |
| 5662 |
iface->set_events = gdk_window_x11_set_events; |
| 5663 |
iface->get_events = gdk_window_x11_get_events; |
| 5664 |
iface->raise = gdk_window_x11_raise; |
| 5665 |
iface->lower = gdk_window_x11_lower; |
| 5666 |
iface->restack_under = gdk_window_x11_restack_under; |
| 5667 |
iface->restack_toplevel = gdk_window_x11_restack_toplevel; |
| 5668 |
iface->move_resize = gdk_window_x11_move_resize; |
| 5669 |
iface->set_background = gdk_window_x11_set_background; |
| 5670 |
iface->set_back_pixmap = gdk_window_x11_set_back_pixmap; |
| 5671 |
iface->reparent = gdk_window_x11_reparent; |
| 5672 |
iface->clear_region = gdk_window_x11_clear_region; |
| 5673 |
iface->set_cursor = gdk_window_x11_set_cursor; |
| 5674 |
iface->get_geometry = gdk_window_x11_get_geometry; |
| 5675 |
iface->get_root_coords = gdk_window_x11_get_root_coords; |
| 5676 |
iface->get_pointer = gdk_window_x11_get_pointer; |
| 5677 |
iface->get_deskrelative_origin = gdk_window_x11_get_deskrelative_origin; |
| 5678 |
iface->shape_combine_region = gdk_window_x11_shape_combine_region; |
| 5679 |
iface->input_shape_combine_region = gdk_window_x11_input_shape_combine_region; |
| 5680 |
iface->set_static_gravities = gdk_window_x11_set_static_gravities; |
| 5681 |
iface->queue_antiexpose = _gdk_x11_window_queue_antiexpose; |
| 5682 |
iface->queue_translation = _gdk_x11_window_queue_translation; |
| 5683 |
iface->destroy = _gdk_x11_window_destroy; |
| 5684 |
iface->input_window_destroy = _gdk_input_window_destroy; |
| 5685 |
iface->input_window_crossing = _gdk_input_crossing_event; |
| 5686 |
iface->supports_native_bg = TRUE; |
| 5687 |
} |
| 5688 |
|
| 5689 |
#define __GDK_WINDOW_X11_C__ |
| 5690 |
#include "gdkaliasdef.c" |