window-props.c 62.1 KB
Newer Older
1 2
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

Tomeu Vizoso's avatar
Tomeu Vizoso committed
3
/*
Jasper St. Pierre's avatar
Jasper St. Pierre committed
4 5
 * SECTION:window-props
 * @short_description: #MetaWindow property handling
Thomas Thurman's avatar
Thomas Thurman committed
6 7 8 9 10 11 12
 *
 * A system which can inspect sets of properties of given windows
 * and take appropriate action given their values.
 *
 * Note that all the meta_window_reload_propert* functions require a
 * round trip to the server.
 *
13 14 15
 * The guts of this system are in meta_display_init_window_prop_hooks().
 * Reading this function will give you insight into how this all fits
 * together.
Thomas Thurman's avatar
Thomas Thurman committed
16
 */
17 18

/* 
19
 * Copyright (C) 2001, 2002, 2003 Red Hat, Inc.
20
 * Copyright (C) 2004, 2005 Elijah Newren
21
 * Copyright (C) 2009 Thomas Thurman
22 23 24 25 26 27 28 29 30 31 32 33
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
34
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
35 36
 */

37
#define _GNU_SOURCE
38
#define _XOPEN_SOURCE 500 /* for gethostname() */
39

40 41
#include <config.h>
#include "window-props.h"
42
#include "window-x11.h"
43
#include "window-x11-private.h"
44
#include <meta/errors.h>
45
#include "xprops.h"
46
#include "frame.h"
47
#include "group.h"
48
#include <X11/Xatom.h>
49 50
#include <unistd.h>
#include <string.h>
51
#include "util-private.h"
52

53 54 55 56 57
#ifndef HOST_NAME_MAX
/* Solaris headers apparently don't define this so do so manually; #326745 */
#define HOST_NAME_MAX 255
#endif

58
typedef void (* ReloadValueFunc) (MetaWindow    *window,
59 60
                                  MetaPropValue *value,
                                  gboolean       initial);
61

62
struct _MetaWindowPropHooks
63 64
{
  Atom property;
65
  MetaPropValueType type;
66
  ReloadValueFunc reload_func;
67 68 69
  gboolean load_initially;
  gboolean include_override_redirect;
};
70

71
static void init_prop_value            (MetaWindow          *window,
72 73 74 75 76 77
                                        MetaWindowPropHooks *hooks,
                                        MetaPropValue       *value);
static void reload_prop_value          (MetaWindow          *window,
                                        MetaWindowPropHooks *hooks,
                                        MetaPropValue       *value,
                                        gboolean             initial);
78 79 80 81 82
static MetaWindowPropHooks* find_hooks (MetaDisplay *display,
                                        Atom         property);


void
83 84 85 86
meta_window_reload_property_from_xwindow (MetaWindow      *window,
                                          Window           xwindow,
                                          Atom             property,
                                          gboolean         initial)
87
{
88 89
  MetaPropValue value = { 0, };
  MetaWindowPropHooks *hooks;
90

91 92 93
  hooks = find_hooks (window->display, property);
  if (!hooks)
    return;
94

95
  init_prop_value (window, hooks, &value);
96 97

  meta_prop_get_values (window->display, xwindow,
98
                        &value, 1);
99

100 101 102 103 104
  reload_prop_value (window, hooks, &value,
                     initial);

  meta_prop_free_values (&value, 1);
}
105

106 107 108 109 110 111 112 113 114
static void
meta_window_reload_property (MetaWindow      *window,
                             Atom             property,
                             gboolean         initial)
{
  meta_window_reload_property_from_xwindow (window,
                                            window->xwindow,
                                            property,
                                            initial);
115 116
}

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
void
meta_window_load_initial_properties (MetaWindow *window)
{
  int i, j;
  MetaPropValue *values;
  int n_properties = 0;

  values = g_new0 (MetaPropValue, window->display->n_prop_hooks);

  j = 0;
  for (i = 0; i < window->display->n_prop_hooks; i++)
    {
      MetaWindowPropHooks *hooks = &window->display->prop_hooks_table[i];
      if (hooks->load_initially)
        {
          init_prop_value (window, hooks, &values[j]);
          ++j;
        }
    }
  n_properties = j;

  meta_prop_get_values (window->display, window->xwindow,
                        values, n_properties);

  j = 0;
  for (i = 0; i < window->display->n_prop_hooks; i++)
    {
      MetaWindowPropHooks *hooks = &window->display->prop_hooks_table[i];
      if (hooks->load_initially)
        {
          /* If we didn't actually manage to load anything then we don't need
           * to call the reload function; this is different from a notification
           * where disappearance of a previously present value is significant.
           */
          if (values[j].type != META_PROP_VALUE_INVALID)
            reload_prop_value (window, hooks, &values[j], TRUE);
          ++j;
        }
    }

  meta_prop_free_values (values, n_properties);

  g_free (values);
}

162 163
/* Fill in the MetaPropValue used to get the value of "property" */
static void
164
init_prop_value (MetaWindow          *window,
165 166
                 MetaWindowPropHooks *hooks,
                 MetaPropValue       *value)
167
{
168 169
  if (!hooks || hooks->type == META_PROP_VALUE_INVALID ||
      (window->override_redirect && !hooks->include_override_redirect))
170
    {
171 172
      value->type = META_PROP_VALUE_INVALID;
      value->atom = None;
173 174 175 176
    }
  else
    {
      value->type = hooks->type;
177
      value->atom = hooks->property;
178
    }
179 180 181
}

static void
182 183 184 185
reload_prop_value (MetaWindow          *window,
                   MetaWindowPropHooks *hooks,
                   MetaPropValue       *value,
                   gboolean             initial)
186
{
187 188
  if (hooks && hooks->reload_func != NULL &&
      !(window->override_redirect && !hooks->include_override_redirect))
189
    (* hooks->reload_func) (window, value, initial);
190 191 192 193
}

static void
reload_wm_client_machine (MetaWindow    *window,
194 195
                          MetaPropValue *value,
                          gboolean       initial)
196 197 198 199 200 201 202 203 204
{
  g_free (window->wm_client_machine);
  window->wm_client_machine = NULL;
  
  if (value->type != META_PROP_VALUE_INVALID)
    window->wm_client_machine = g_strdup (value->v.str);

  meta_verbose ("Window has client machine \"%s\"\n",
                window->wm_client_machine ? window->wm_client_machine : "unset");
205 206 207 208 209 210 211 212 213 214 215 216 217

  if (window->wm_client_machine == NULL)
    {
      window->is_remote = FALSE;
    }
  else
    {
      char hostname[HOST_NAME_MAX + 1] = "";

      gethostname (hostname, HOST_NAME_MAX + 1);

      window->is_remote = g_strcmp0 (window->wm_client_machine, hostname) != 0;
    }
218 219 220
}

static void
221 222 223 224 225 226 227 228 229 230 231 232 233
complain_about_broken_client (MetaWindow    *window,
                              MetaPropValue *value,
                              gboolean       initial)
{
  meta_warning ("Broken client! Window %s changed client leader window or SM client ID\n",
                window->desc);
}

static void
reload_net_wm_window_type (MetaWindow    *window,
                           MetaPropValue *value,
                           gboolean       initial)
{
234
  meta_window_x11_update_net_wm_type (window);
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
}

static void
reload_icon (MetaWindow    *window,
             Atom           atom)
{
  meta_icon_cache_property_changed (&window->icon_cache,
                                    window->display,
                                    atom);
  meta_window_queue(window, META_QUEUE_UPDATE_ICON);
}

static void
reload_net_wm_icon (MetaWindow    *window,
                    MetaPropValue *value,
                    gboolean       initial)
{
  reload_icon (window, window->display->atom__NET_WM_ICON);
}

static void
reload_kwm_win_icon (MetaWindow    *window,
                     MetaPropValue *value,
                     gboolean       initial)
{
  reload_icon (window, window->display->atom__KWM_WIN_ICON);
}

263 264 265 266 267 268 269 270 271 272 273 274 275 276
static void
reload_icon_geometry (MetaWindow    *window,
                      MetaPropValue *value,
                      gboolean       initial)
{
  if (value->type != META_PROP_VALUE_INVALID)
    {
      if (value->v.cardinal_list.n_cardinals != 4)
        {
          meta_verbose ("_NET_WM_ICON_GEOMETRY on %s has %d values instead of 4\n",
                        window->desc, value->v.cardinal_list.n_cardinals);
        }
      else
        {
277 278 279 280 281 282 283 284
          MetaRectangle geometry;

          geometry.x = (int)value->v.cardinal_list.cardinals[0];
          geometry.y = (int)value->v.cardinal_list.cardinals[1];
          geometry.width = (int)value->v.cardinal_list.cardinals[2];
          geometry.height = (int)value->v.cardinal_list.cardinals[3];

          meta_window_set_icon_geometry (window, &geometry);
285 286 287 288
        }
    }
  else
    {
289
      meta_window_set_icon_geometry (window, NULL);
290 291 292
    }
}

Jasper St. Pierre's avatar
Jasper St. Pierre committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306
static void
reload_gtk_frame_extents (MetaWindow    *window,
                          MetaPropValue *value,
                          gboolean       initial)
{
  if (value->type != META_PROP_VALUE_INVALID)
    {
      if (value->v.cardinal_list.n_cardinals != 4)
        {
          meta_verbose ("_GTK_FRAME_EXTENTS on %s has %d values instead of 4\n",
                        window->desc, value->v.cardinal_list.n_cardinals);
        }
      else
        {
307 308 309 310 311 312
          GtkBorder extents;
          extents.left   = (int)value->v.cardinal_list.cardinals[0];
          extents.right  = (int)value->v.cardinal_list.cardinals[1];
          extents.top    = (int)value->v.cardinal_list.cardinals[2];
          extents.bottom = (int)value->v.cardinal_list.cardinals[3];
          meta_window_set_custom_frame_extents (window, &extents);
Jasper St. Pierre's avatar
Jasper St. Pierre committed
313 314 315 316
        }
    }
  else
    {
317
      meta_window_set_custom_frame_extents (window, NULL);
Jasper St. Pierre's avatar
Jasper St. Pierre committed
318 319 320
    }
}

321 322 323 324 325 326 327 328 329 330 331 332
static void
reload_struts (MetaWindow    *window,
               MetaPropValue *value,
               gboolean       initial)
{
  meta_window_update_struts (window);
}

static void
reload_wm_window_role (MetaWindow    *window,
                       MetaPropValue *value,
                       gboolean       initial)
333
{
334
  meta_window_x11_update_role (window);
335 336 337 338
}

static void
reload_net_wm_pid (MetaWindow    *window,
339 340
                   MetaPropValue *value,
                   gboolean       initial)
341 342 343 344 345 346
{
  if (value->type != META_PROP_VALUE_INVALID)
    {
      gulong cardinal = (int) value->v.cardinal;
      
      if (cardinal <= 0)
347
        meta_warning ("Application set a bogus _NET_WM_PID %lu\n",
348 349 350 351 352 353 354 355 356 357
                      cardinal);
      else
        {
          window->net_wm_pid = cardinal;
          meta_verbose ("Window has _NET_WM_PID %d\n",
                        window->net_wm_pid);
        }
    }
}

358 359
static void
reload_net_wm_user_time (MetaWindow    *window,
360 361
                         MetaPropValue *value,
                         gboolean       initial)
362 363 364 365
{
  if (value->type != META_PROP_VALUE_INVALID)
    {
      gulong cardinal = value->v.cardinal;
366
      meta_window_set_user_time (window, cardinal);
367 368 369
    }
}

370 371
static void
reload_net_wm_user_time_window (MetaWindow    *window,
372 373
                                MetaPropValue *value,
                                gboolean       initial)
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
{
  if (value->type != META_PROP_VALUE_INVALID)
    {
      /* Unregister old NET_WM_USER_TIME_WINDOW */
      if (window->user_time_window != None)
        {
          /* See the comment to the meta_display_register_x_window call below. */
          meta_display_unregister_x_window (window->display,
                                            window->user_time_window);
          /* Don't get events on not-managed windows */
          XSelectInput (window->display->xdisplay,
                        window->user_time_window,
                        NoEventMask);
        }


      /* Obtain the new NET_WM_USER_TIME_WINDOW and register it */
      window->user_time_window = value->v.xwindow;
      if (window->user_time_window != None)
        {
          /* Kind of a hack; display.c:event_callback() ignores events
           * for unknown windows.  We make window->user_time_window
           * known by registering it with window (despite the fact
           * that window->xwindow is already registered with window).
           * This basically means that property notifies to either the
           * window->user_time_window or window->xwindow will be
           * treated identically and will result in functions for
           * window being called to update it.  Maybe we should ignore
           * any property notifies to window->user_time_window other
403
           * than atom__NET_WM_USER_TIME ones, but I just don't care
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
           * and it's not specified in the spec anyway.
           */
          meta_display_register_x_window (window->display,
                                          &window->user_time_window,
                                          window);
          /* Just listen for property notify events */
          XSelectInput (window->display->xdisplay,
                        window->user_time_window,
                        PropertyChangeMask);

          /* Manually load the _NET_WM_USER_TIME field from the given window
           * at this time as well.  If the user_time_window ever broadens in
           * scope, we'll probably want to load all relevant properties here.
           */
          meta_window_reload_property_from_xwindow (
            window,
420
            window->user_time_window,
421 422
            window->display->atom__NET_WM_USER_TIME,
            initial);
423 424 425 426
        }
    }
}

427 428
#define MAX_TITLE_LENGTH 512

429
/**
Jasper St. Pierre's avatar
Jasper St. Pierre committed
430 431 432 433
 * set_title_text:
 *
 * Called by set_window_title() and set_icon_title() to set the value of
 * @target to @title. It required and @atom is set, it will update the
434 435
 * appropriate property.
 *
Jasper St. Pierre's avatar
Jasper St. Pierre committed
436
 * Returns: %TRUE if a new title was set.
437 438
 */
static gboolean
439 440 441 442 443
set_title_text (MetaWindow  *window,
                gboolean     previous_was_modified,
                const char  *title,
                Atom         atom,
                char       **target)
444
{
445
  gboolean modified = FALSE;
446
  
447 448
  if (!target)
    return FALSE;
449
  
450 451 452 453 454
  g_free (*target);
  
  if (!title)
    *target = g_strdup ("");
  else if (g_utf8_strlen (title, MAX_TITLE_LENGTH + 1) > MAX_TITLE_LENGTH)
455
    {
456 457 458 459 460
      *target = meta_g_utf8_strndup (title, MAX_TITLE_LENGTH);
      modified = TRUE;
    }
  /* if WM_CLIENT_MACHINE indicates this machine is on a remote host
   * lets place that hostname in the title */
461
  else if (meta_window_is_remote (window))
462
    {
463
      *target = g_strdup_printf (_("%s (on %s)"),
464 465
                      title, window->wm_client_machine);
      modified = TRUE;
466
    }
467 468 469 470 471
  else
    *target = g_strdup (title);

  if (modified && atom != None)
    meta_prop_set_utf8_string_hint (window->display,
472 473 474 475 476
                                    window->xwindow,
                                    atom, *target);

  /* Bug 330671 -- Don't forget to clear _NET_WM_VISIBLE_(ICON_)NAME */
  if (!modified && previous_was_modified)
477 478 479 480 481
    {
      meta_error_trap_push (window->display);
      XDeleteProperty (window->display->xdisplay,
                       window->xwindow,
                       atom);
482
      meta_error_trap_pop (window->display);
483
    }
484 485 486 487 488 489 490 491

  return modified;
}

static void
set_window_title (MetaWindow *window,
                  const char *title)
{
492 493 494
  MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
  MetaWindowX11Private *priv = window_x11->priv;

495
  char *new_title = NULL;
496

497 498
  gboolean modified =
    set_title_text (window,
499
                    priv->using_net_wm_visible_name,
500
                    title,
501
                    window->display->atom__NET_WM_VISIBLE_NAME,
502
                    &new_title);
503
  priv->using_net_wm_visible_name = modified;
504
  
505 506 507
  meta_window_set_title (window, new_title);

  g_free (new_title);
508 509 510 511
}

static void
reload_net_wm_name (MetaWindow    *window,
512 513
                    MetaPropValue *value,
                    gboolean       initial)
514
{
515 516 517
  MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
  MetaWindowX11Private *priv = window_x11->priv;

518 519 520
  if (value->type != META_PROP_VALUE_INVALID)
    {
      set_window_title (window, value->v.str);
521
      priv->using_net_wm_name = TRUE;
522 523 524 525 526 527 528

      meta_verbose ("Using _NET_WM_NAME for new title of %s: \"%s\"\n",
                    window->desc, window->title);
    }
  else
    {
      set_window_title (window, NULL);
529
      priv->using_net_wm_name = FALSE;
530 531
      if (!initial)
        meta_window_reload_property (window, XA_WM_NAME, FALSE);
532 533 534 535 536
    }
}

static void
reload_wm_name (MetaWindow    *window,
537 538
                MetaPropValue *value,
                gboolean       initial)
539
{
540 541 542 543
  MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
  MetaWindowX11Private *priv = window_x11->priv;

  if (priv->using_net_wm_name)
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
    {
      meta_verbose ("Ignoring WM_NAME \"%s\" as _NET_WM_NAME is set\n",
                    value->v.str);
      return;
    }
  
  if (value->type != META_PROP_VALUE_INVALID)
    {
      set_window_title (window, value->v.str);

      meta_verbose ("Using WM_NAME for new title of %s: \"%s\"\n",
                    window->desc, window->title);
    }
  else
    {
      set_window_title (window, NULL);
    }
}

563 564 565 566 567
static void
reload_opaque_region (MetaWindow    *window,
                      MetaPropValue *value,
                      gboolean       initial)
{
568
  meta_window_x11_update_opaque_region (window);
569 570
}

Tomas Frydrych's avatar
Tomas Frydrych committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
static void
reload_mutter_hints (MetaWindow    *window,
                     MetaPropValue *value,
                     gboolean       initial)
{
  if (value->type != META_PROP_VALUE_INVALID)
    {
      char     *new_hints = value->v.str;
      char     *old_hints = window->mutter_hints;
      gboolean  changed   = FALSE;

      if (new_hints)
        {
          if (!old_hints || strcmp (new_hints, old_hints))
            changed = TRUE;
        }
      else
        {
          if (old_hints)
            changed = TRUE;
        }

      if (changed)
        {
          g_free (old_hints);

          if (new_hints)
            window->mutter_hints = g_strdup (new_hints);
          else
            window->mutter_hints = NULL;

          g_object_notify (G_OBJECT (window), "mutter-hints");
        }
    }
  else if (window->mutter_hints)
    {
      g_free (window->mutter_hints);
      window->mutter_hints = NULL;

      g_object_notify (G_OBJECT (window), "mutter-hints");
    }
}

614 615 616 617
static void
set_icon_title (MetaWindow *window,
                const char *title)
{
618 619 620
  MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
  MetaWindowX11Private *priv = window_x11->priv;

621 622
  gboolean modified =
    set_title_text (window,
623
                    priv->using_net_wm_visible_icon_name,
624
                    title,
625
                    window->display->atom__NET_WM_VISIBLE_ICON_NAME,
626
                    &window->icon_name);
627
  priv->using_net_wm_visible_icon_name = modified;
628 629 630 631
}

static void
reload_net_wm_icon_name (MetaWindow    *window,
632 633
                         MetaPropValue *value,
                         gboolean       initial)
634
{
635 636 637
  MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
  MetaWindowX11Private *priv = window_x11->priv;

638 639 640
  if (value->type != META_PROP_VALUE_INVALID)
    {
      set_icon_title (window, value->v.str);
641
      priv->using_net_wm_icon_name = TRUE;
642 643 644 645 646 647 648

      meta_verbose ("Using _NET_WM_ICON_NAME for new title of %s: \"%s\"\n",
                    window->desc, window->title);
    }
  else
    {
      set_icon_title (window, NULL);
649
      priv->using_net_wm_icon_name = FALSE;
650 651
      if (!initial)
        meta_window_reload_property (window, XA_WM_ICON_NAME, FALSE);
652 653 654 655 656
    }
}

static void
reload_wm_icon_name (MetaWindow    *window,
657 658
                     MetaPropValue *value,
                     gboolean       initial)
659
{
660 661 662 663
  MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
  MetaWindowX11Private *priv = window_x11->priv;

  if (priv->using_net_wm_icon_name)
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
    {
      meta_verbose ("Ignoring WM_ICON_NAME \"%s\" as _NET_WM_ICON_NAME is set\n",
                    value->v.str);
      return;
    }
  
  if (value->type != META_PROP_VALUE_INVALID)
    {
      set_icon_title (window, value->v.str);
      
      meta_verbose ("Using WM_ICON_NAME for new title of %s: \"%s\"\n",
                    window->desc, window->title);
    }
  else
    {
      set_icon_title (window, NULL);
    }
}

683 684
static void
reload_net_wm_state (MetaWindow    *window,
685 686
                     MetaPropValue *value,
                     gboolean       initial)
687
{
688 689 690
  MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
  MetaWindowX11Private *priv = window_x11->priv;

691 692 693 694 695 696
  int i;

  /* We know this is only an initial window creation,
   * clients don't change the property.
   */

697 698 699 700 701 702 703
  if (!initial) {
    /* no, they DON'T change the property */
    meta_verbose ("Ignoring _NET_WM_STATE: we should be the one who set "
                  "the property in the first place\n");
    return;
  }

704 705 706
  window->shaded = FALSE;
  window->maximized_horizontally = FALSE;
  window->maximized_vertically = FALSE;
707
  window->fullscreen = FALSE;
708
  priv->wm_state_modal = FALSE;
709 710
  priv->wm_state_skip_taskbar = FALSE;
  priv->wm_state_skip_pager = FALSE;
711 712 713 714 715 716 717 718 719 720
  window->wm_state_above = FALSE;
  window->wm_state_below = FALSE;
  window->wm_state_demands_attention = FALSE;

  if (value->type == META_PROP_VALUE_INVALID)
    return;

  i = 0;
  while (i < value->v.atom_list.n_atoms)
    {
721
      if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_SHADED)
722
        window->shaded = TRUE;
723
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_MAXIMIZED_HORZ)
724
        window->maximize_horizontally_after_placement = TRUE;
725
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_MAXIMIZED_VERT)
726
        window->maximize_vertically_after_placement = TRUE;
727
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_HIDDEN)
728
        window->minimize_after_placement = TRUE;
729
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_MODAL)
730
        priv->wm_state_modal = TRUE;
731
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_SKIP_TASKBAR)
732
        priv->wm_state_skip_taskbar = TRUE;
733
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_SKIP_PAGER)
734
        priv->wm_state_skip_pager = TRUE;
735
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_FULLSCREEN)
736
        window->fullscreen_after_placement = TRUE;
737
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_ABOVE)
738
        window->wm_state_above = TRUE;
739
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_BELOW)
740
        window->wm_state_below = TRUE;
741
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_DEMANDS_ATTENTION)
742
        window->wm_state_demands_attention = TRUE;
743
      else if (value->v.atom_list.atoms[i] == window->display->atom__NET_WM_STATE_STICKY)
744
        window->on_all_workspaces_requested = TRUE;
745 746 747 748 749 750 751

      ++i;
    }

  meta_verbose ("Reloaded _NET_WM_STATE for %s\n",
                window->desc);

752
  meta_window_x11_recalc_window_type (window);
753
  meta_window_recalc_features (window);
754 755 756 757
}

static void
reload_mwm_hints (MetaWindow    *window,
758 759
                  MetaPropValue *value,
                  gboolean       initial)
760 761
{
  MotifWmHints *hints;
762
  gboolean old_decorated = window->decorated;
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866

  window->mwm_decorated = TRUE;
  window->mwm_border_only = FALSE;
  window->mwm_has_close_func = TRUE;
  window->mwm_has_minimize_func = TRUE;
  window->mwm_has_maximize_func = TRUE;
  window->mwm_has_move_func = TRUE;
  window->mwm_has_resize_func = TRUE;

  if (value->type == META_PROP_VALUE_INVALID)
    {
      meta_verbose ("Window %s has no MWM hints\n", window->desc);
      meta_window_recalc_features (window);
      return;
    }

  hints = value->v.motif_hints;

  /* We support those MWM hints deemed non-stupid */

  meta_verbose ("Window %s has MWM hints\n",
                window->desc);

  if (hints->flags & MWM_HINTS_DECORATIONS)
    {
      meta_verbose ("Window %s sets MWM_HINTS_DECORATIONS 0x%lx\n",
          window->desc, hints->decorations);

      if (hints->decorations == 0)
        window->mwm_decorated = FALSE;
      /* some input methods use this */
      else if (hints->decorations == MWM_DECOR_BORDER)
        window->mwm_border_only = TRUE;
    }
  else
    meta_verbose ("Decorations flag unset\n");

  if (hints->flags & MWM_HINTS_FUNCTIONS)
    {
      gboolean toggle_value;

      meta_verbose ("Window %s sets MWM_HINTS_FUNCTIONS 0x%lx\n",
                    window->desc, hints->functions);

      /* If _ALL is specified, then other flags indicate what to turn off;
       * if ALL is not specified, flags are what to turn on.
       * at least, I think so
       */

      if ((hints->functions & MWM_FUNC_ALL) == 0)
        {
          toggle_value = TRUE;

          meta_verbose ("Window %s disables all funcs then reenables some\n",
                        window->desc);
          window->mwm_has_close_func = FALSE;
          window->mwm_has_minimize_func = FALSE;
          window->mwm_has_maximize_func = FALSE;
          window->mwm_has_move_func = FALSE;
          window->mwm_has_resize_func = FALSE;
        }
      else
        {
          meta_verbose ("Window %s enables all funcs then disables some\n",
                        window->desc);
          toggle_value = FALSE;
        }

      if ((hints->functions & MWM_FUNC_CLOSE) != 0)
        {
          meta_verbose ("Window %s toggles close via MWM hints\n",
                        window->desc);
          window->mwm_has_close_func = toggle_value;
        }
      if ((hints->functions & MWM_FUNC_MINIMIZE) != 0)
        {
          meta_verbose ("Window %s toggles minimize via MWM hints\n",
                        window->desc);
          window->mwm_has_minimize_func = toggle_value;
        }
      if ((hints->functions & MWM_FUNC_MAXIMIZE) != 0)
        {
          meta_verbose ("Window %s toggles maximize via MWM hints\n",
                        window->desc);
          window->mwm_has_maximize_func = toggle_value;
        }
      if ((hints->functions & MWM_FUNC_MOVE) != 0)
        {
          meta_verbose ("Window %s toggles move via MWM hints\n",
                        window->desc);
          window->mwm_has_move_func = toggle_value;
        }
      if ((hints->functions & MWM_FUNC_RESIZE) != 0)
        {
          meta_verbose ("Window %s toggles resize via MWM hints\n",
                        window->desc);
          window->mwm_has_resize_func = toggle_value;
        }
    }
  else
    meta_verbose ("Functions flag unset\n");

  meta_window_recalc_features (window);
  
867
  /* We do all this anyhow at the end of meta_window_x11_new() */
868 869 870 871 872 873 874
  if (!window->constructing)
    {
      if (window->decorated)
        meta_window_ensure_frame (window);
      else
        meta_window_destroy_frame (window);
      
875 876 877 878
      meta_window_queue (window,
                         META_QUEUE_MOVE_RESIZE |
                         /* because ensure/destroy frame may unmap: */
                         META_QUEUE_CALC_SHOWING);
879 880 881

      if (old_decorated != window->decorated)
        g_object_notify (G_OBJECT (window), "decorated");
882 883 884 885 886
    }
}

static void
reload_wm_class (MetaWindow    *window,
887 888
                 MetaPropValue *value,
                 gboolean       initial)
889 890
{
  if (value->type != META_PROP_VALUE_INVALID)
891 892 893 894 895 896 897 898
    {
      meta_window_set_wm_class (window,
                                value->v.class_hint.res_class,
                                value->v.class_hint.res_name);
    }
  else
    {
      meta_window_set_wm_class (window, NULL, NULL);
899 900 901 902 903 904 905 906
    }

  meta_verbose ("Window %s class: '%s' name: '%s'\n",
      window->desc,
      window->res_class ? window->res_class : "none",
      window->res_name ? window->res_name : "none");
}

907 908
static void
reload_net_wm_desktop (MetaWindow    *window,
909 910
                       MetaPropValue *value,
                       gboolean       initial)
911 912 913 914 915 916 917 918 919 920 921
{
  if (value->type != META_PROP_VALUE_INVALID)
    {
      window->initial_workspace_set = TRUE;
      window->initial_workspace = value->v.cardinal;
      meta_topic (META_DEBUG_PLACEMENT,
                  "Read initial workspace prop %d for %s\n",
                  window->initial_workspace, window->desc);
    }
}

Havoc Pennington's avatar
Havoc Pennington committed
922 923
static void
reload_net_startup_id (MetaWindow    *window,
924 925
                       MetaPropValue *value,
                       gboolean       initial)
Havoc Pennington's avatar
Havoc Pennington committed
926
{
927 928 929
  guint32 timestamp = window->net_wm_user_time;
  MetaWorkspace *workspace = NULL;
  
Havoc Pennington's avatar
Havoc Pennington committed
930 931 932 933 934 935
  g_free (window->startup_id);
  
  if (value->type != META_PROP_VALUE_INVALID)
    window->startup_id = g_strdup (value->v.str);
  else
    window->startup_id = NULL;
936 937 938 939 940 941 942
    
  /* Update timestamp and workspace on a running window */
  if (!window->constructing)
  {
    window->initial_timestamp_set = 0;  
    window->initial_workspace_set = 0;
    
943 944
    if (meta_screen_apply_startup_properties (window->screen, window))
      {
945
  
946 947 948 949
        if (window->initial_timestamp_set)
          timestamp = window->initial_timestamp;
        if (window->initial_workspace_set)
          workspace = meta_screen_get_workspace_by_index (window->screen, window->initial_workspace);
950
    
951 952
        meta_window_activate_with_workspace (window, timestamp, workspace);
      }
953
  }
Havoc Pennington's avatar
Havoc Pennington committed
954 955 956 957 958 959
  
  meta_verbose ("New _NET_STARTUP_ID \"%s\" for %s\n",
                window->startup_id ? window->startup_id : "unset",
                window->desc);
}

960 961
static void
reload_update_counter (MetaWindow    *window,
962 963
                       MetaPropValue *value,
                       gboolean       initial)
964 965 966
{
  if (value->type != META_PROP_VALUE_INVALID)
    {
967
      meta_window_destroy_sync_request_alarm (window);
968
      window->sync_request_counter = None;
969

970
#ifdef HAVE_XSYNC
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
      if (value->v.xcounter_list.n_counters == 0)
        {
          meta_warning ("_NET_WM_SYNC_REQUEST_COUNTER is empty\n");
          return;
        }

      if (value->v.xcounter_list.n_counters == 1)
        {
          window->sync_request_counter = value->v.xcounter_list.counters[0];
          window->extended_sync_request_counter = FALSE;
        }
      else
        {
          window->sync_request_counter = value->v.xcounter_list.counters[1];
          window->extended_sync_request_counter = TRUE;
        }
      meta_verbose ("Window has _NET_WM_SYNC_REQUEST_COUNTER 0x%lx (extended=%s)\n",
                    window->sync_request_counter,
                    window->extended_sync_request_counter ? "true" : "false");
990

991 992
      if (window->extended_sync_request_counter)
        meta_window_create_sync_request_alarm (window);
993 994 995 996
#endif
    }
}

997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
#define FLAG_TOGGLED_ON(old,new,flag) \
 (((old)->flags & (flag)) == 0 &&     \
  ((new)->flags & (flag)) != 0)

#define FLAG_TOGGLED_OFF(old,new,flag) \
 (((old)->flags & (flag)) != 0 &&      \
  ((new)->flags & (flag)) == 0)

#define FLAG_CHANGED(old,new,flag) \
  (FLAG_TOGGLED_ON(old,new,flag) || FLAG_TOGGLED_OFF(old,new,flag))

static void
spew_size_hints_differences (const XSizeHints *old,
                             const XSizeHints *new)
{
  if (FLAG_CHANGED (old, new, USPosition))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: USPosition now %s\n",
                FLAG_TOGGLED_ON (old, new, USPosition) ? "set" : "unset");
  if (FLAG_CHANGED (old, new, USSize))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: USSize now %s\n",
                FLAG_TOGGLED_ON (old, new, USSize) ? "set" : "unset");
  if (FLAG_CHANGED (old, new, PPosition))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: PPosition now %s\n",
                FLAG_TOGGLED_ON (old, new, PPosition) ? "set" : "unset");
  if (FLAG_CHANGED (old, new, PSize))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: PSize now %s\n",
                FLAG_TOGGLED_ON (old, new, PSize) ? "set" : "unset");
  if (FLAG_CHANGED (old, new, PMinSize))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: PMinSize now %s (%d x %d -> %d x %d)\n",
                FLAG_TOGGLED_ON (old, new, PMinSize) ? "set" : "unset",
                old->min_width, old->min_height,
                new->min_width, new->min_height);
  if (FLAG_CHANGED (old, new, PMaxSize))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: PMaxSize now %s (%d x %d -> %d x %d)\n",
                FLAG_TOGGLED_ON (old, new, PMaxSize) ? "set" : "unset",
                old->max_width, old->max_height,
                new->max_width, new->max_height);
  if (FLAG_CHANGED (old, new, PResizeInc))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: PResizeInc now %s (width_inc %d -> %d height_inc %d -> %d)\n",
                FLAG_TOGGLED_ON (old, new, PResizeInc) ? "set" : "unset",
                old->width_inc, new->width_inc,
                old->height_inc, new->height_inc);
  if (FLAG_CHANGED (old, new, PAspect))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: PAspect now %s (min %d/%d -> %d/%d max %d/%d -> %d/%d)\n",
                FLAG_TOGGLED_ON (old, new, PAspect) ? "set" : "unset",
                old->min_aspect.x, old->min_aspect.y,
                new->min_aspect.x, new->min_aspect.y,
                old->max_aspect.x, old->max_aspect.y,
                new->max_aspect.x, new->max_aspect.y);
  if (FLAG_CHANGED (old, new, PBaseSize))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: PBaseSize now %s (%d x %d -> %d x %d)\n",
                FLAG_TOGGLED_ON (old, new, PBaseSize) ? "set" : "unset",
                old->base_width, old->base_height,
                new->base_width, new->base_height);
  if (FLAG_CHANGED (old, new, PWinGravity))
    meta_topic (META_DEBUG_GEOMETRY, "XSizeHints: PWinGravity now %s  (%d -> %d)\n",
                FLAG_TOGGLED_ON (old, new, PWinGravity) ? "set" : "unset",
                old->win_gravity, new->win_gravity);  
}

1057 1058
void
meta_set_normal_hints (MetaWindow *window,
1059
                       XSizeHints *hints)
1060 1061
{
  int x, y, w, h;
1062 1063 1064 1065 1066
  double minr, maxr;
  /* Some convenience vars */
  int minw, minh, maxw, maxh;   /* min/max width/height                      */
  int basew, baseh, winc, hinc; /* base width/height, width/height increment */

1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
  /* Save the last ConfigureRequest, which we put here.
   * Values here set in the hints are supposed to
   * be ignored.
   */
  x = window->size_hints.x;
  y = window->size_hints.y;
  w = window->size_hints.width;
  h = window->size_hints.height;

  /* as far as I can tell, value->v.size_hints.flags is just to
   * check whether we had old-style normal hints without gravity,
   * base size as returned by XGetNormalHints(), so we don't
   * really use it as we fixup window->size_hints to have those
   * fields if they're missing.
   */

  /*
   * When the window is first created, NULL hints will
   * be passed in which will initialize all of the fields
   * as if flags were zero
   */
  if (hints)
    window->size_hints = *hints;
  else
    window->size_hints.flags = 0;

  /* Put back saved ConfigureRequest. */
  window->size_hints.x = x;
  window->size_hints.y = y;
  window->size_hints.width = w;
  window->size_hints.height = h;

1099
  /* Get base size hints */
1100 1101 1102
  if (window->size_hints.flags & PBaseSize)
    {
      meta_topic (META_DEBUG_GEOMETRY, "Window %s sets base size %d x %d\n",
1103 1104 1105
                  window->desc,
                  window->size_hints.base_width,
                  window->size_hints.base_height);
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
    }
  else if (window->size_hints.flags & PMinSize)
    {
      window->size_hints.base_width = window->size_hints.min_width;
      window->size_hints.base_height = window->size_hints.min_height;
    }
  else
    {
      window->size_hints.base_width = 0;
      window->size_hints.base_height = 0;
    }
  window->size_hints.flags |= PBaseSize;

1119
  /* Get min size hints */
1120 1121 1122
  if (window->size_hints.flags & PMinSize)
    {
      meta_topic (META_DEBUG_GEOMETRY, "Window %s sets min size %d x %d\n",
1123 1124 1125
                  window->desc,
                  window->size_hints.min_width,
                  window->size_hints.min_height);
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
    }
  else if (window->size_hints.flags & PBaseSize)
    {
      window->size_hints.min_width = window->size_hints.base_width;
      window->size_hints.min_height = window->size_hints.base_height;
    }
  else
    {
      window->size_hints.min_width = 0;
      window->size_hints.min_height = 0;
    }
  window->size_hints.flags |= PMinSize;

1139
  /* Get max size hints */
1140 1141 1142
  if (window->size_hints.flags & PMaxSize)
    {
      meta_topic (META_DEBUG_GEOMETRY, "Window %s sets max size %d x %d\n",
1143 1144 1145
                  window->desc,
                  window->size_hints.max_width,
                  window->size_hints.max_height);
1146 1147 1148 1149 1150 1151 1152 1153
    }
  else
    {
      window->size_hints.max_width = G_MAXINT;
      window->size_hints.max_height = G_MAXINT;
      window->size_hints.flags |= PMaxSize;
    }

1154 1155
  /* Get resize increment hints */
  if (window->size_hints.flags & PResizeInc)
1156 1157
    {
      meta_topic (META_DEBUG_GEOMETRY,
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
                  "Window %s sets resize width inc: %d height inc: %d\n",
                  window->desc,
                  window->size_hints.width_inc,
                  window->size_hints.height_inc);
    }
  else
    {
      window->size_hints.width_inc = 1;
      window->size_hints.height_inc = 1;
      window->size_hints.flags |= PResizeInc;
1168 1169
    }

1170 1171
  /* Get aspect ratio hints */
  if (window->size_hints.flags & PAspect)
1172 1173
    {
      meta_topic (META_DEBUG_GEOMETRY,
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186