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

3
/* Mutter interface used by GTK+ UI to talk to core */
rhp's avatar
rhp committed
4 5 6

/* 
 * Copyright (C) 2001 Havoc Pennington
7
 * Copyright (C) 2003 Rob Adams
8
 * Copyright (C) 2004-2006 Elijah Newren
rhp's avatar
rhp committed
9 10 11 12 13 14 15 16 17 18 19 20
 * 
 * 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
21
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
rhp's avatar
rhp committed
22 23
 */

Havoc Pennington's avatar
Havoc Pennington committed
24
#include <config.h>
rhp's avatar
rhp committed
25
#include "core.h"
26
#include "frame.h"
27
#include "workspace-private.h"
28 29
#include <meta/prefs.h>
#include <meta/errors.h>
30
#include "util-private.h"
rhp's avatar
rhp committed
31

32 33 34 35 36 37 38 39 40 41 42
/* Looks up the MetaWindow representing the frame of the given X window.
 * Used as a helper function by a bunch of the functions below.
 *
 * FIXME: The functions that use this function throw the result away
 * after use. Many of these functions tend to be called in small groups,
 * which results in get_window() getting called several times in succession
 * with the same parameters. We should profile to see whether this wastes
 * much time, and if it does we should look into a generalised
 * meta_core_get_window_info() which takes a bunch of pointers to variables
 * to put its results in, and only fills in the non-null ones.
 */
43 44
static MetaWindow *
get_window (Display *xdisplay,
45
            Window   frame_xwindow)
rhp's avatar
rhp committed
46 47 48 49 50 51 52 53
{
  MetaDisplay *display;
  MetaWindow *window;
  
  display = meta_display_for_x_display (xdisplay);
  window = meta_display_lookup_x_window (display, frame_xwindow);

  if (window == NULL || window->frame == NULL)
54 55 56 57 58 59 60 61 62
    {
      meta_bug ("No such frame window 0x%lx!\n", frame_xwindow);
      return NULL;
    }

  return window;
}

void
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
meta_core_get (Display *xdisplay,
    Window xwindow,
    ...)
{
  va_list args;
  MetaCoreGetType request;

  MetaDisplay *display = meta_display_for_x_display (xdisplay);
  MetaWindow *window = meta_display_lookup_x_window (display, xwindow);

  va_start (args, xwindow);

  request = va_arg (args, MetaCoreGetType);

  /* Now, we special-case the first request slightly. Mostly, requests
   * for information on windows which have no frame are errors.
   * But sometimes we may want to know *whether* a window has a frame.
   * In this case, pass the key META_CORE_WINDOW_HAS_FRAME
   * as the *first* request, with a pointer to a boolean; if the window
   * has no frame, this will be set to False and meta_core_get will
   * exit immediately (so the values of any other requests will be
   * undefined). Otherwise it will be set to True and meta_core_get will
   * continue happily on its way.
   */

  if (request != META_CORE_WINDOW_HAS_FRAME &&
      (window == NULL || window->frame == NULL)) {
    meta_bug ("No such frame window 0x%lx!\n", xwindow);
91
    goto out;
92 93 94 95 96 97 98 99 100
  }

  while (request != META_CORE_GET_END) {
    
    gpointer answer = va_arg (args, gpointer);

    switch (request) {
      case META_CORE_WINDOW_HAS_FRAME:
        *((gboolean*)answer) = window != NULL && window->frame != NULL;
101
        if (!*((gboolean*)answer)) goto out; /* see above */
102 103 104 105 106 107 108 109 110 111 112 113 114 115
        break; 
      case META_CORE_GET_CLIENT_WIDTH:
        *((gint*)answer) = window->rect.width;
        break;
      case META_CORE_GET_CLIENT_HEIGHT:
        *((gint*)answer) = window->rect.height;
        break;
      case META_CORE_GET_CLIENT_XWINDOW:
        *((Window*)answer) = window->xwindow;
        break;
      case META_CORE_GET_FRAME_FLAGS:
        *((MetaFrameFlags*)answer) = meta_frame_get_flags (window->frame);
        break; 
      case META_CORE_GET_FRAME_TYPE:
116 117
        *((MetaFrameType*)answer) = meta_window_get_frame_type (window);
        break;
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
      case META_CORE_GET_MINI_ICON:
        *((GdkPixbuf**)answer) = window->mini_icon;
        break;
      case META_CORE_GET_ICON:
        *((GdkPixbuf**)answer) = window->icon;
        break;
      case META_CORE_GET_X:
        meta_window_get_position (window, (int*)answer, NULL);
        break;
      case META_CORE_GET_Y:
        meta_window_get_position (window, NULL, (int*)answer);
        break;
      case META_CORE_GET_FRAME_WORKSPACE:
        *((gint*)answer) = meta_window_get_net_wm_desktop (window);
        break;
      case META_CORE_GET_FRAME_X:
        *((gint*)answer) = window->frame->rect.x;
        break;
      case META_CORE_GET_FRAME_Y:
        *((gint*)answer) = window->frame->rect.y;
        break;
      case META_CORE_GET_FRAME_WIDTH:
        *((gint*)answer) = window->frame->rect.width;
        break;
      case META_CORE_GET_FRAME_HEIGHT:
        *((gint*)answer) = window->frame->rect.height;
        break;
145 146 147
      case META_CORE_GET_THEME_VARIANT:
        *((char**)answer) = window->gtk_theme_variant;
        break;
148 149 150 151 152 153 154 155
      case META_CORE_GET_SCREEN_WIDTH:
        *((gint*)answer) = window->screen->rect.width;
        break;
      case META_CORE_GET_SCREEN_HEIGHT:
        *((gint*)answer) = window->screen->rect.height;
        break;

      default:
156
        meta_warning("Unknown window information request: %d\n", request);
157 158
    }

159 160
    request = va_arg (args, MetaCoreGetType);
  } 
161

162
 out:
163
  va_end (args);
164 165
}

rhp's avatar
rhp committed
166 167 168 169
void
meta_core_queue_frame_resize (Display *xdisplay,
                              Window   frame_xwindow)
{
170
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
171

172
  meta_window_queue (window, META_QUEUE_MOVE_RESIZE);
173
  meta_window_frame_size_changed (window);
rhp's avatar
rhp committed
174 175
}

rhp's avatar
rhp committed
176 177 178 179 180 181
void
meta_core_user_move (Display *xdisplay,
                     Window   frame_xwindow,
                     int      x,
                     int      y)
{
182
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
183

184
  meta_window_move (window, TRUE, x, y);
rhp's avatar
rhp committed
185 186
}

rhp's avatar
rhp committed
187 188 189
void
meta_core_user_resize  (Display *xdisplay,
                        Window   frame_xwindow,
rhp's avatar
rhp committed
190
                        int      gravity,
rhp's avatar
rhp committed
191 192 193
                        int      width,
                        int      height)
{
194
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
195

196
  meta_window_resize_with_gravity (window, TRUE, width, height, gravity);
rhp's avatar
rhp committed
197 198 199 200 201 202
}

void
meta_core_user_raise (Display *xdisplay,
                      Window   frame_xwindow)
{
203
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
204 205 206 207
  
  meta_window_raise (window);
}

208 209 210
static gboolean
lower_window_and_transients (MetaWindow *window,
                             gpointer   data)
211 212
{
  meta_window_lower (window);
213

214 215
  meta_window_foreach_transient (window, lower_window_and_transients, NULL);

216
  if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_CLICK &&
217
      meta_prefs_get_raise_on_click ())
218 219 220 221 222 223
    {
      /* Move window to the back of the focusing workspace's MRU list.
       * Do extra sanity checks to avoid possible race conditions.
       * (Borrowed from window.c.)
       */
      if (window->screen->active_workspace &&
224
          meta_window_located_on_workspace (window, 
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
                                            window->screen->active_workspace))
        {
          GList* link;
          link = g_list_find (window->screen->active_workspace->mru_list, 
                              window);
          g_assert (link);

          window->screen->active_workspace->mru_list = 
            g_list_remove_link (window->screen->active_workspace->mru_list,
                                link);
          g_list_free (link);

          window->screen->active_workspace->mru_list = 
            g_list_append (window->screen->active_workspace->mru_list, 
                           window);
        }
    }
242

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
  return FALSE;
}

void
meta_core_user_lower_and_unfocus (Display *xdisplay,
                                  Window   frame_xwindow,
                                  guint32  timestamp)
{
  MetaWindow *window = get_window (xdisplay, frame_xwindow);

  lower_window_and_transients (window, NULL);

 /* Rather than try to figure that out whether we just lowered
  * the focus window, assume that's always the case. (Typically,
  * this will be invoked via keyboard action or by a mouse action;
  * in either case the window or a modal child will have been focused.) */
  meta_workspace_focus_default_window (window->screen->active_workspace,
                                       NULL,
                                       timestamp);
262 263
}

264
void
265 266 267
meta_core_lower_beneath_grab_window (Display *xdisplay,
                                     Window   xwindow,
                                     guint32  timestamp)
268 269 270 271
{
  XWindowChanges changes;
  MetaDisplay *display;
  MetaScreen *screen;
272
  MetaWindow *grab_window;
273 274
  MetaStackWindow stack_window;
  MetaStackWindow stack_sibling;
275 276 277

  display = meta_display_for_x_display (xdisplay);
  screen = meta_display_screen_for_xwindow (display, xwindow);
278
  grab_window = display->grab_window;
279

280
  if (grab_window == NULL)
281 282 283
    return;

  changes.stack_mode = Below;
284
  changes.sibling = meta_window_get_toplevel_xwindow (grab_window);
285

286 287 288 289
  stack_window.any.type = META_WINDOW_CLIENT_TYPE_X11;
  stack_window.x11.xwindow = xwindow;
  stack_sibling.any.type = META_WINDOW_CLIENT_TYPE_X11;
  stack_sibling.x11.xwindow = changes.sibling;
290
  meta_stack_tracker_record_lower_below (screen->stack_tracker,
291 292
                                         &stack_window,
                                         &stack_sibling,
293 294 295 296 297 298 299
                                         XNextRequest (screen->display->xdisplay));

  meta_error_trap_push (display);
  XConfigureWindow (xdisplay,
                    xwindow,
                    CWSibling | CWStackMode,
                    &changes);
300
  meta_error_trap_pop (display);
301 302
}

rhp's avatar
rhp committed
303 304 305
void
meta_core_user_focus (Display *xdisplay,
                      Window   frame_xwindow,
306
                      guint32  timestamp)
rhp's avatar
rhp committed
307
{
308
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
309 310 311 312
  
  meta_window_focus (window, timestamp);
}

rhp's avatar
rhp committed
313 314 315 316
void
meta_core_minimize (Display *xdisplay,
                    Window   frame_xwindow)
{
317
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
318 319 320 321 322 323 324 325

  meta_window_minimize (window);
}

void
meta_core_maximize (Display *xdisplay,
                    Window   frame_xwindow)
{
326
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
327

328 329 330
  if (meta_prefs_get_raise_on_click ())
    meta_window_raise (window);

331 332
  meta_window_maximize (window, 
                        META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
333 334
}

335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
void
meta_core_toggle_maximize_vertically (Display *xdisplay,
				      Window   frame_xwindow)
{
  MetaWindow *window = get_window (xdisplay, frame_xwindow);

  if (meta_prefs_get_raise_on_click ())
    meta_window_raise (window);

  if (META_WINDOW_MAXIMIZED_VERTICALLY (window))
    meta_window_unmaximize (window, 
                            META_MAXIMIZE_VERTICAL);
  else
    meta_window_maximize (window,
    			    META_MAXIMIZE_VERTICAL);
}

void
meta_core_toggle_maximize_horizontally (Display *xdisplay,
				        Window   frame_xwindow)
{
  MetaWindow *window = get_window (xdisplay, frame_xwindow);

  if (meta_prefs_get_raise_on_click ())
    meta_window_raise (window);

  if (META_WINDOW_MAXIMIZED_HORIZONTALLY (window))
    meta_window_unmaximize (window, 
                            META_MAXIMIZE_HORIZONTAL);
  else
    meta_window_maximize (window,
    			    META_MAXIMIZE_HORIZONTAL);
}

369 370 371 372
void
meta_core_toggle_maximize (Display *xdisplay,
                           Window   frame_xwindow)
{
373
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
374

375 376 377
  if (meta_prefs_get_raise_on_click ())
    meta_window_raise (window);

378 379 380
  if (META_WINDOW_MAXIMIZED (window))
    meta_window_unmaximize (window, 
                            META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
381
  else
382 383
    meta_window_maximize (window,
                          META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
rhp's avatar
rhp committed
384 385 386 387 388 389
}

void
meta_core_unmaximize (Display *xdisplay,
                      Window   frame_xwindow)
{
390
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
391

392 393 394
  if (meta_prefs_get_raise_on_click ())
    meta_window_raise (window);

395 396
  meta_window_unmaximize (window,
                          META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
rhp's avatar
rhp committed
397 398 399 400 401 402 403
}

void
meta_core_delete (Display *xdisplay,
                  Window   frame_xwindow,
                  guint32  timestamp)
{
404
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
405 406 407 408
     
  meta_window_delete (window, timestamp);
}

rhp's avatar
rhp committed
409 410
void
meta_core_unshade (Display *xdisplay,
411 412
                   Window   frame_xwindow,
                   guint32  timestamp)
rhp's avatar
rhp committed
413
{
414
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
415

416
  meta_window_unshade (window, timestamp);
rhp's avatar
rhp committed
417 418 419 420
}

void
meta_core_shade (Display *xdisplay,
421 422
                 Window   frame_xwindow,
                 guint32  timestamp)
rhp's avatar
rhp committed
423
{
424
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
425
  
426
  meta_window_shade (window, timestamp);
rhp's avatar
rhp committed
427 428 429 430 431 432
}

void
meta_core_unstick (Display *xdisplay,
                   Window   frame_xwindow)
{
433
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
434 435 436 437

  meta_window_unstick (window);
}

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
void
meta_core_make_above (Display *xdisplay,
                      Window   frame_xwindow)
{
  MetaWindow *window = get_window (xdisplay, frame_xwindow);

  meta_window_make_above (window);
}

void
meta_core_unmake_above (Display *xdisplay,
                        Window   frame_xwindow)
{
  MetaWindow *window = get_window (xdisplay, frame_xwindow);

  meta_window_unmake_above (window);
}

rhp's avatar
rhp committed
456 457 458 459
void
meta_core_stick (Display *xdisplay,
                 Window   frame_xwindow)
{
460
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
461 462 463 464 465 466 467 468 469

  meta_window_stick (window);
}

void
meta_core_change_workspace (Display *xdisplay,
                            Window   frame_xwindow,
                            int      new_workspace)
{
470
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
471 472

  meta_window_change_workspace (window,
473 474
                                meta_screen_get_workspace_by_index (window->screen,
                                                                    new_workspace));
rhp's avatar
rhp committed
475 476
}

rhp's avatar
rhp committed
477 478 479 480 481 482
void
meta_core_show_window_menu (Display *xdisplay,
                            Window   frame_xwindow,
                            int      root_x,
                            int      root_y,
                            int      button,
483
                            guint32  timestamp)
rhp's avatar
rhp committed
484
{
485
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
486
  
487 488
  if (meta_prefs_get_raise_on_click ())
    meta_window_raise (window);
489 490
  meta_window_focus (window, timestamp);

rhp's avatar
rhp committed
491 492 493
  meta_window_show_menu (window, root_x, root_y, button, timestamp);
}

494 495 496 497 498 499 500 501 502 503 504 505
void
meta_core_get_menu_accelerator (MetaMenuOp           menu_op,
                                int                  workspace,
                                unsigned int        *keysym,
                                MetaVirtualModifier *modifiers)
{
  const char *name;

  name = NULL;
  
  switch (menu_op)
    {
Vincent Untz's avatar
Vincent Untz committed
506
    case META_MENU_OP_NONE:
507
      /* No keybinding for this one */
Vincent Untz's avatar
Vincent Untz committed
508
      break;
509
    case META_MENU_OP_DELETE:
510
      name = "close";
511 512
      break;
    case META_MENU_OP_MINIMIZE:
513
      name = "minimize";
514 515
      break;
    case META_MENU_OP_UNMAXIMIZE:
516
      name = "unmaximize";
517 518
      break;
    case META_MENU_OP_MAXIMIZE:
519
      name = "maximize";
520 521 522
      break;
    case META_MENU_OP_UNSHADE:
    case META_MENU_OP_SHADE:
523
      name = "toggle_shaded";
524 525 526
      break;
    case META_MENU_OP_UNSTICK:
    case META_MENU_OP_STICK:
527
      name = "toggle-on-all-workspaces";
528
      break;
529
    case META_MENU_OP_ABOVE:
530
    case META_MENU_OP_UNABOVE:
531
      name = "toggle-above";
532
      break;
533 534 535 536
    case META_MENU_OP_WORKSPACES:
      switch (workspace)
        {
        case 1:
537
          name = "move-to-workspace-1";
538 539
          break;
        case 2:
540
          name = "move-to-workspace-2";
541 542
          break;
        case 3:
543
          name = "move-to-workspace-3";
544 545
          break; 
        case 4:
546
          name = "move-to-workspace-4";
547 548
          break; 
        case 5:
549
          name = "move-to-workspace-5";
550 551
          break; 
        case 6:
552
          name = "move-to-workspace-6";
553 554
          break; 
        case 7:
555
          name = "move-to-workspace-7";
556 557
          break; 
        case 8:
558
          name = "move-to-workspace-8";
559 560
          break; 
        case 9:
561
          name = "move-to-workspace-9";
562 563
          break; 
        case 10:
564
          name = "move-to-workspace-10";
565 566
          break;
        case 11:
567
          name = "move-to-workspace-11";
568 569
          break;
        case 12:
570
          name = "move-to-workspace-12";
571 572 573 574
          break;
        }
      break;
    case META_MENU_OP_MOVE:
575
      name = "begin-move";
576 577
      break;
    case META_MENU_OP_RESIZE:
578
      name = "begin-resize";
579
      break;
580
    case META_MENU_OP_MOVE_LEFT:
581
      name = "move-to-workspace-left";
582 583
      break;
    case META_MENU_OP_MOVE_RIGHT:
584
      name = "move-to-workspace-right";
585 586
      break;
    case META_MENU_OP_MOVE_UP:
587
      name = "move-to-workspace-up";
588 589
      break;
    case META_MENU_OP_MOVE_DOWN:
590
      name = "move-to-workspace-down";
591
      break;
592 593 594
    case META_MENU_OP_RECOVER:
      /* No keybinding for this one */
      break;
595 596 597 598 599 600 601 602 603 604 605 606 607
    }

  if (name)
    {
      meta_prefs_get_window_binding (name, keysym, modifiers);
    }
  else
    {
      *keysym = 0;
      *modifiers = 0;
    }
}

608
const char*
609
meta_core_get_workspace_name_with_index (Display *xdisplay,
610 611
                                         Window   xroot,
                                         int      index)
612 613
{
  MetaDisplay *display;
614
  MetaScreen *screen;
615 616 617
  MetaWorkspace *workspace;

  display = meta_display_for_x_display (xdisplay);
618 619 620
  screen = meta_display_screen_for_root (display, xroot);
  g_assert (screen != NULL);
  workspace = meta_screen_get_workspace_by_index (screen, index);
621
  return workspace ? meta_workspace_get_name (workspace) : NULL;
622 623
}

rhp's avatar
rhp committed
624 625 626 627 628
gboolean
meta_core_begin_grab_op (Display    *xdisplay,
                         Window      frame_xwindow,
                         MetaGrabOp  op,
                         gboolean    pointer_already_grabbed,
629
                         gboolean    frame_action,
rhp's avatar
rhp committed
630 631
                         int         button,
                         gulong      modmask,
632
                         guint32     timestamp,
rhp's avatar
rhp committed
633 634 635
                         int         root_x,
                         int         root_y)
{
636
  MetaWindow *window = get_window (xdisplay, frame_xwindow);
rhp's avatar
rhp committed
637
  MetaDisplay *display;
638
  MetaScreen *screen;
rhp's avatar
rhp committed
639 640
  
  display = meta_display_for_x_display (xdisplay);
641
  screen = meta_display_screen_for_xwindow (display, frame_xwindow);
rhp's avatar
rhp committed
642

643 644
  g_assert (screen != NULL);
  
645
  return meta_display_begin_grab_op (display, screen, window,
rhp's avatar
rhp committed
646
                                     op, pointer_already_grabbed,
647
                                     frame_action,
rhp's avatar
rhp committed
648 649 650 651 652 653
                                     button, modmask,
                                     timestamp, root_x, root_y);
}

void
meta_core_end_grab_op (Display *xdisplay,
654
                       guint32  timestamp)
rhp's avatar
rhp committed
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
{
  MetaDisplay *display;
  
  display = meta_display_for_x_display (xdisplay);

  meta_display_end_grab_op (display, timestamp);
}

MetaGrabOp
meta_core_get_grab_op (Display *xdisplay)
{
  MetaDisplay *display;
  
  display = meta_display_for_x_display (xdisplay);

  return display->grab_op;
}

Window
meta_core_get_grab_frame (Display *xdisplay)
{
  MetaDisplay *display;
  
  display = meta_display_for_x_display (xdisplay);

Havoc Pennington's avatar
Havoc Pennington committed
680
  g_assert (display != NULL);
681
  g_assert (display->grab_op == META_GRAB_OP_NONE || 
682
            display->grab_screen != NULL);
683
  g_assert (display->grab_op == META_GRAB_OP_NONE ||
684
            display->grab_screen->display->xdisplay == xdisplay);
Havoc Pennington's avatar
Havoc Pennington committed
685
  
rhp's avatar
rhp committed
686
  if (display->grab_op != META_GRAB_OP_NONE &&
687
      display->grab_window &&
rhp's avatar
rhp committed
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
      display->grab_window->frame)
    return display->grab_window->frame->xwindow;
  else
    return None;
}

int
meta_core_get_grab_button (Display  *xdisplay)
{
  MetaDisplay *display;
  
  display = meta_display_for_x_display (xdisplay);

  if (display->grab_op == META_GRAB_OP_NONE)
    return -1;
  
  return display->grab_button;
}

void
meta_core_grab_buttons  (Display *xdisplay,
                         Window   frame_xwindow)
{
  MetaDisplay *display;
712
    
rhp's avatar
rhp committed
713
  display = meta_display_for_x_display (xdisplay);
714 715

  meta_verbose ("Grabbing buttons on frame 0x%lx\n", frame_xwindow);
rhp's avatar
rhp committed
716 717 718 719 720 721 722 723
  meta_display_grab_window_buttons (display, frame_xwindow);
}

void
meta_core_set_screen_cursor (Display *xdisplay,
                             Window   frame_on_screen,
                             MetaCursor cursor)
{
724
  MetaWindow *window = get_window (xdisplay, frame_on_screen);
rhp's avatar
rhp committed
725

726
  meta_frame_set_screen_cursor (window->frame, cursor);
rhp's avatar
rhp committed
727
}
728 729 730 731 732 733 734 735 736 737 738

void
meta_core_increment_event_serial (Display *xdisplay)
{
  MetaDisplay *display;
  
  display = meta_display_for_x_display (xdisplay);

  meta_display_increment_event_serial (display);
}

739 740 741
void
meta_invalidate_default_icons (void)
{
742 743 744
  MetaDisplay *display = meta_get_display ();
  GSList *windows;
  GSList *l;
745

746 747 748
  if (display == NULL)
    return; /* We can validly be called before the display is opened. */

749
  windows = meta_display_list_windows (display, META_LIST_DEFAULT);
750
  for (l = windows; l != NULL; l = l->next)
751
    {
752
      MetaWindow *window = (MetaWindow*)l->data;
753

754
      if (window->icon_cache.origin == USING_FALLBACK_ICON)
755
        {
756 757
          meta_icon_cache_free (&(window->icon_cache));
          meta_window_update_icon_now (window);
758 759
        }
    }
760 761

  g_slist_free (windows);
762 763
}

764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
void
meta_core_add_old_event_mask (Display     *xdisplay,
                              Window       xwindow,
                              XIEventMask *mask)
{
  XIEventMask *prev;
  gint n_masks, i, j;

  prev = XIGetSelectedEvents (xdisplay, xwindow, &n_masks);

  for (i = 0; i < n_masks; i++)
    {
      if (prev[i].deviceid != XIAllMasterDevices)
        continue;

      for (j = 0; j < MIN (mask->mask_len, prev[i].mask_len); j++)
        mask->mask[j] |= prev[i].mask[j];
    }

  XFree (prev);
}