1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2
3 /* Muffin interface used by GTK+ UI to talk to core */
4
5 /*
6 * Copyright (C) 2001 Havoc Pennington
7 * Copyright (C) 2003 Rob Adams
8 * Copyright (C) 2004-2006 Elijah Newren
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of the
13 * License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street - Suite 500, Boston, MA
23 * 02110-1335, USA.
24 */
25
26 #include <config.h>
27 #include "core.h"
28 #include "frame.h"
29 #include "workspace-private.h"
30 #include <meta/prefs.h>
31 #include <meta/errors.h>
32 #include "util-private.h"
33
34 /* Looks up the MetaWindow representing the frame of the given X window.
35 * Used as a helper function by a bunch of the functions below.
36 *
37 * FIXME: The functions that use this function throw the result away
38 * after use. Many of these functions tend to be called in small groups,
39 * which results in get_window() getting called several times in succession
40 * with the same parameters. We should profile to see whether this wastes
41 * much time, and if it does we should look into a generalised
42 * meta_core_get_window_info() which takes a bunch of pointers to variables
43 * to put its results in, and only fills in the non-null ones.
44 */
45 LOCAL_SYMBOL MetaWindow *
meta_core_get_window(Display * xdisplay,Window frame_xwindow)46 meta_core_get_window (Display *xdisplay,
47 Window frame_xwindow)
48 {
49 MetaDisplay *display;
50 MetaWindow *window;
51
52 display = meta_display_for_x_display (xdisplay);
53 window = meta_display_lookup_x_window (display, frame_xwindow);
54
55 if (window == NULL || window->frame == NULL)
56 {
57 meta_bug ("No such frame window 0x%lx!\n", frame_xwindow);
58 return NULL;
59 }
60
61 return window;
62 }
63
64 LOCAL_SYMBOL void
meta_core_get(Display * xdisplay,Window xwindow,...)65 meta_core_get (Display *xdisplay,
66 Window xwindow,
67 ...)
68 {
69 va_list args;
70 MetaCoreGetType request;
71
72 MetaDisplay *display = meta_display_for_x_display (xdisplay);
73 MetaWindow *window = meta_display_lookup_x_window (display, xwindow);
74
75 va_start (args, xwindow);
76
77 request = va_arg (args, MetaCoreGetType);
78
79 /* Now, we special-case the first request slightly. Mostly, requests
80 * for information on windows which have no frame are errors.
81 * But sometimes we may want to know *whether* a window has a frame.
82 * In this case, pass the key META_CORE_WINDOW_HAS_FRAME
83 * as the *first* request, with a pointer to a boolean; if the window
84 * has no frame, this will be set to False and meta_core_get will
85 * exit immediately (so the values of any other requests will be
86 * undefined). Otherwise it will be set to True and meta_core_get will
87 * continue happily on its way.
88 */
89
90 if (request != META_CORE_WINDOW_HAS_FRAME &&
91 (window == NULL || window->frame == NULL)) {
92 meta_bug ("No such frame window 0x%lx!\n", xwindow);
93 va_end (args);
94 return;
95 }
96
97 while (request != META_CORE_GET_END) {
98
99 gpointer answer = va_arg (args, gpointer);
100
101 switch (request) {
102 case META_CORE_WINDOW_HAS_FRAME:
103 *((gboolean*)answer) = window != NULL && window->frame != NULL;
104 if (!*((gboolean*)answer)) return; /* see above */
105 break;
106 case META_CORE_GET_CLIENT_WIDTH:
107 *((gint*)answer) = window->rect.width;
108 break;
109 case META_CORE_GET_CLIENT_HEIGHT:
110 *((gint*)answer) = window->rect.height;
111 break;
112 case META_CORE_GET_CLIENT_XWINDOW:
113 *((Window*)answer) = window->xwindow;
114 break;
115 case META_CORE_GET_FRAME_FLAGS:
116 *((MetaFrameFlags*)answer) = meta_frame_get_flags (window->frame);
117 break;
118 case META_CORE_GET_FRAME_TYPE:
119 *((MetaFrameType*)answer) = meta_window_get_frame_type (window);
120 break;
121 case META_CORE_GET_X:
122 meta_window_get_position (window, (int*)answer, NULL);
123 break;
124 case META_CORE_GET_Y:
125 meta_window_get_position (window, NULL, (int*)answer);
126 break;
127 case META_CORE_GET_FRAME_WORKSPACE:
128 *((gint*)answer) = meta_window_get_net_wm_desktop (window);
129 break;
130 case META_CORE_GET_FRAME_X:
131 *((gint*)answer) = window->frame->rect.x;
132 break;
133 case META_CORE_GET_FRAME_Y:
134 *((gint*)answer) = window->frame->rect.y;
135 break;
136 case META_CORE_GET_FRAME_WIDTH:
137 *((gint*)answer) = window->frame->rect.width;
138 break;
139 case META_CORE_GET_FRAME_HEIGHT:
140 *((gint*)answer) = window->frame->rect.height;
141 break;
142 case META_CORE_GET_THEME_VARIANT:
143 *((char**)answer) = window->gtk_theme_variant;
144 break;
145 case META_CORE_GET_SCREEN_WIDTH:
146 *((gint*)answer) = window->screen->rect.width;
147 break;
148 case META_CORE_GET_SCREEN_HEIGHT:
149 *((gint*)answer) = window->screen->rect.height;
150 break;
151
152 default:
153 meta_warning("Unknown window information request: %d", request);
154 }
155
156 request = va_arg (args, MetaCoreGetType);
157 }
158
159 va_end (args);
160 }
161
162 LOCAL_SYMBOL void
meta_core_queue_frame_resize(Display * xdisplay,Window frame_xwindow)163 meta_core_queue_frame_resize (Display *xdisplay,
164 Window frame_xwindow)
165 {
166 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
167
168 meta_window_queue (window, META_QUEUE_MOVE_RESIZE);
169 meta_window_frame_size_changed (window);
170 }
171
172 LOCAL_SYMBOL void
meta_core_user_move(Display * xdisplay,Window frame_xwindow,int x,int y)173 meta_core_user_move (Display *xdisplay,
174 Window frame_xwindow,
175 int x,
176 int y)
177 {
178 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
179
180 meta_window_move (window, TRUE, x, y);
181 }
182
183 LOCAL_SYMBOL void
meta_core_user_resize(Display * xdisplay,Window frame_xwindow,int gravity,int width,int height)184 meta_core_user_resize (Display *xdisplay,
185 Window frame_xwindow,
186 int gravity,
187 int width,
188 int height)
189 {
190 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
191
192 meta_window_resize_with_gravity (window, TRUE, width, height, gravity);
193 }
194
195 LOCAL_SYMBOL void
meta_core_user_raise(Display * xdisplay,Window frame_xwindow)196 meta_core_user_raise (Display *xdisplay,
197 Window frame_xwindow)
198 {
199 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
200
201 meta_window_raise (window);
202 }
203
204 static gboolean
lower_window_and_transients(MetaWindow * window,gpointer data)205 lower_window_and_transients (MetaWindow *window,
206 gpointer data)
207 {
208 meta_window_lower (window);
209
210 meta_window_foreach_transient (window, lower_window_and_transients, NULL);
211
212 if (meta_prefs_get_focus_mode () == C_DESKTOP_FOCUS_MODE_CLICK &&
213 meta_prefs_get_raise_on_click ())
214 {
215 /* Move window to the back of the focusing workspace's MRU list.
216 * Do extra sanity checks to avoid possible race conditions.
217 * (Borrowed from window.c.)
218 */
219 if (window->screen->active_workspace &&
220 meta_window_located_on_workspace (window,
221 window->screen->active_workspace))
222 {
223 GList* link;
224 link = g_list_find (window->screen->active_workspace->mru_list,
225 window);
226 g_assert (link);
227
228 window->screen->active_workspace->mru_list =
229 g_list_remove_link (window->screen->active_workspace->mru_list,
230 link);
231 g_list_free (link);
232
233 window->screen->active_workspace->mru_list =
234 g_list_append (window->screen->active_workspace->mru_list,
235 window);
236 }
237 }
238
239 return FALSE;
240 }
241
242 LOCAL_SYMBOL void
meta_core_user_lower_and_unfocus(Display * xdisplay,Window frame_xwindow,guint32 timestamp)243 meta_core_user_lower_and_unfocus (Display *xdisplay,
244 Window frame_xwindow,
245 guint32 timestamp)
246 {
247 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
248
249 meta_screen_hide_hud_and_preview (window->screen);
250
251 lower_window_and_transients (window, NULL);
252
253 /* Rather than try to figure that out whether we just lowered
254 * the focus window, assume that's always the case. (Typically,
255 * this will be invoked via keyboard action or by a mouse action;
256 * in either case the window or a modal child will have been focused.) */
257 meta_workspace_focus_default_window (window->screen->active_workspace,
258 NULL,
259 timestamp);
260 }
261
262 LOCAL_SYMBOL void
meta_core_lower_beneath_grab_window(Display * xdisplay,Window xwindow,guint32 timestamp)263 meta_core_lower_beneath_grab_window (Display *xdisplay,
264 Window xwindow,
265 guint32 timestamp)
266 {
267 XWindowChanges changes;
268 MetaDisplay *display;
269 MetaScreen *screen;
270 MetaWindow *grab_window;
271
272 display = meta_display_for_x_display (xdisplay);
273 screen = meta_display_screen_for_xwindow (display, xwindow);
274 grab_window = display->grab_window;
275
276 if (grab_window == NULL)
277 return;
278
279 changes.stack_mode = Below;
280 changes.sibling = grab_window->frame ? grab_window->frame->xwindow
281 : grab_window->xwindow;
282
283 meta_stack_tracker_record_lower_below (screen->stack_tracker,
284 xwindow,
285 changes.sibling,
286 XNextRequest (screen->display->xdisplay));
287
288 meta_error_trap_push (display);
289 XConfigureWindow (xdisplay,
290 xwindow,
291 CWSibling | CWStackMode,
292 &changes);
293 meta_error_trap_pop (display);
294 }
295
296
297 LOCAL_SYMBOL void
meta_core_lower_beneath_sibling(Display * xdisplay,Window xwindow,Window grab_window,guint32 timestamp)298 meta_core_lower_beneath_sibling (Display *xdisplay,
299 Window xwindow,
300 Window grab_window,
301 guint32 timestamp)
302 {
303 XWindowChanges changes;
304 MetaDisplay *display;
305 MetaScreen *screen;
306
307 display = meta_display_for_x_display (xdisplay);
308 screen = meta_display_screen_for_xwindow (display, xwindow);
309
310 changes.stack_mode = Below;
311 changes.sibling = grab_window;
312
313 meta_stack_tracker_record_lower_below (screen->stack_tracker,
314 xwindow,
315 changes.sibling,
316 XNextRequest (screen->display->xdisplay));
317
318 meta_error_trap_push (display);
319 XConfigureWindow (xdisplay,
320 xwindow,
321 CWSibling | CWStackMode,
322 &changes);
323 meta_error_trap_pop (display);
324 }
325
326
327 LOCAL_SYMBOL void
meta_core_user_focus(Display * xdisplay,Window frame_xwindow,guint32 timestamp)328 meta_core_user_focus (Display *xdisplay,
329 Window frame_xwindow,
330 guint32 timestamp)
331 {
332 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
333
334 meta_window_focus (window, timestamp);
335 }
336
337 LOCAL_SYMBOL void
meta_core_minimize(Display * xdisplay,Window frame_xwindow)338 meta_core_minimize (Display *xdisplay,
339 Window frame_xwindow)
340 {
341 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
342
343 meta_screen_hide_hud_and_preview (window->screen);
344
345 meta_window_minimize (window);
346 }
347
348 LOCAL_SYMBOL void
meta_core_maximize(Display * xdisplay,Window frame_xwindow)349 meta_core_maximize (Display *xdisplay,
350 Window frame_xwindow)
351 {
352 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
353
354 meta_screen_hide_hud_and_preview (window->screen);
355
356 if (meta_prefs_get_raise_on_click ())
357 meta_window_raise (window);
358
359 meta_window_maximize (window,
360 META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
361 }
362
363 LOCAL_SYMBOL void
meta_core_toggle_maximize_vertically(Display * xdisplay,Window frame_xwindow)364 meta_core_toggle_maximize_vertically (Display *xdisplay,
365 Window frame_xwindow)
366 {
367 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
368
369 meta_screen_hide_hud_and_preview (window->screen);
370
371 if (meta_prefs_get_raise_on_click ())
372 meta_window_raise (window);
373
374 if (META_WINDOW_MAXIMIZED_VERTICALLY (window))
375 meta_window_unmaximize (window,
376 META_MAXIMIZE_VERTICAL);
377 else
378 meta_window_maximize (window,
379 META_MAXIMIZE_VERTICAL);
380 }
381
382 LOCAL_SYMBOL void
meta_core_toggle_maximize_horizontally(Display * xdisplay,Window frame_xwindow)383 meta_core_toggle_maximize_horizontally (Display *xdisplay,
384 Window frame_xwindow)
385 {
386 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
387
388 meta_screen_hide_hud_and_preview (window->screen);
389
390 if (meta_prefs_get_raise_on_click ())
391 meta_window_raise (window);
392
393 if (META_WINDOW_MAXIMIZED_HORIZONTALLY (window))
394 meta_window_unmaximize (window,
395 META_MAXIMIZE_HORIZONTAL);
396 else
397 meta_window_maximize (window,
398 META_MAXIMIZE_HORIZONTAL);
399 }
400
401 LOCAL_SYMBOL void
meta_core_toggle_maximize(Display * xdisplay,Window frame_xwindow)402 meta_core_toggle_maximize (Display *xdisplay,
403 Window frame_xwindow)
404 {
405 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
406
407 meta_screen_hide_hud_and_preview (window->screen);
408
409 if (meta_prefs_get_raise_on_click ())
410 meta_window_raise (window);
411
412 if (META_WINDOW_MAXIMIZED (window))
413 meta_window_unmaximize (window,
414 META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
415 else
416 meta_window_maximize (window,
417 META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
418 }
419
420 LOCAL_SYMBOL void
meta_core_unmaximize(Display * xdisplay,Window frame_xwindow)421 meta_core_unmaximize (Display *xdisplay,
422 Window frame_xwindow)
423 {
424 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
425
426 if (meta_prefs_get_raise_on_click ())
427 meta_window_raise (window);
428
429 meta_window_unmaximize (window,
430 META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
431 }
432
433 LOCAL_SYMBOL void
meta_core_delete(Display * xdisplay,Window frame_xwindow,guint32 timestamp)434 meta_core_delete (Display *xdisplay,
435 Window frame_xwindow,
436 guint32 timestamp)
437 {
438 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
439
440 meta_window_delete (window, timestamp);
441 }
442
443 LOCAL_SYMBOL void
meta_core_unshade(Display * xdisplay,Window frame_xwindow,guint32 timestamp)444 meta_core_unshade (Display *xdisplay,
445 Window frame_xwindow,
446 guint32 timestamp)
447 {
448 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
449
450 meta_screen_hide_hud_and_preview (window->screen);
451
452 meta_window_unshade (window, timestamp);
453 }
454
455 LOCAL_SYMBOL void
meta_core_shade(Display * xdisplay,Window frame_xwindow,guint32 timestamp)456 meta_core_shade (Display *xdisplay,
457 Window frame_xwindow,
458 guint32 timestamp)
459 {
460 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
461
462 meta_screen_hide_hud_and_preview (window->screen);
463
464 meta_window_shade (window, timestamp);
465 }
466
467 LOCAL_SYMBOL void
meta_core_unstick(Display * xdisplay,Window frame_xwindow)468 meta_core_unstick (Display *xdisplay,
469 Window frame_xwindow)
470 {
471 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
472
473 meta_window_unstick (window);
474 }
475
476 LOCAL_SYMBOL void
meta_core_make_above(Display * xdisplay,Window frame_xwindow)477 meta_core_make_above (Display *xdisplay,
478 Window frame_xwindow)
479 {
480 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
481
482 meta_window_make_above (window);
483 }
484
485 LOCAL_SYMBOL void
meta_core_unmake_above(Display * xdisplay,Window frame_xwindow)486 meta_core_unmake_above (Display *xdisplay,
487 Window frame_xwindow)
488 {
489 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
490
491 meta_window_unmake_above (window);
492 }
493
494 LOCAL_SYMBOL void
meta_core_adjust_opacity(Display * xdisplay,Window frame_xwindow,gboolean increase)495 meta_core_adjust_opacity (Display *xdisplay,
496 Window frame_xwindow,
497 gboolean increase)
498 {
499 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
500
501 meta_window_adjust_opacity (window, increase);
502 }
503
504 LOCAL_SYMBOL void
meta_core_stick(Display * xdisplay,Window frame_xwindow)505 meta_core_stick (Display *xdisplay,
506 Window frame_xwindow)
507 {
508 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
509
510 meta_window_stick (window);
511 }
512
513 LOCAL_SYMBOL void
meta_core_change_workspace(Display * xdisplay,Window frame_xwindow,int new_workspace)514 meta_core_change_workspace (Display *xdisplay,
515 Window frame_xwindow,
516 int new_workspace)
517 {
518 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
519
520 meta_window_change_workspace (window,
521 meta_screen_get_workspace_by_index (window->screen,
522 new_workspace));
523 }
524
525 LOCAL_SYMBOL int
meta_core_get_num_workspaces(Screen * xscreen)526 meta_core_get_num_workspaces (Screen *xscreen)
527 {
528 MetaScreen *screen;
529
530 screen = meta_screen_for_x_screen (xscreen);
531
532 return meta_screen_get_n_workspaces (screen);
533 }
534
535 LOCAL_SYMBOL int
meta_core_get_active_workspace(Screen * xscreen)536 meta_core_get_active_workspace (Screen *xscreen)
537 {
538 MetaScreen *screen;
539
540 screen = meta_screen_for_x_screen (xscreen);
541
542 return meta_workspace_index (screen->active_workspace);
543 }
544
545 LOCAL_SYMBOL void
meta_core_show_window_menu(Display * xdisplay,Window frame_xwindow,int root_x,int root_y,int button,guint32 timestamp)546 meta_core_show_window_menu (Display *xdisplay,
547 Window frame_xwindow,
548 int root_x,
549 int root_y,
550 int button,
551 guint32 timestamp)
552 {
553 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
554
555 meta_screen_hide_hud_and_preview (window->screen);
556
557 if (meta_prefs_get_raise_on_click ())
558 meta_window_raise (window);
559 meta_window_focus (window, timestamp);
560
561 meta_window_show_menu (window, root_x, root_y, button, timestamp);
562 }
563
564 LOCAL_SYMBOL void
meta_core_get_menu_accelerator(MetaMenuOp menu_op,int workspace,unsigned int * keysym,MetaVirtualModifier * modifiers)565 meta_core_get_menu_accelerator (MetaMenuOp menu_op,
566 int workspace,
567 unsigned int *keysym,
568 MetaVirtualModifier *modifiers)
569 {
570 const char *name;
571
572 name = NULL;
573
574 switch (menu_op)
575 {
576 case META_MENU_OP_NONE:
577 /* No keybinding for this one */
578 break;
579 case META_MENU_OP_DELETE:
580 name = "close";
581 break;
582 case META_MENU_OP_MINIMIZE:
583 name = "minimize";
584 break;
585 case META_MENU_OP_UNMAXIMIZE:
586 name = "unmaximize";
587 break;
588 case META_MENU_OP_MAXIMIZE:
589 name = "maximize";
590 break;
591 case META_MENU_OP_UNSHADE:
592 case META_MENU_OP_SHADE:
593 name = "toggle_shaded";
594 break;
595 case META_MENU_OP_UNSTICK:
596 case META_MENU_OP_STICK:
597 name = "toggle-on-all-workspaces";
598 break;
599 case META_MENU_OP_ABOVE:
600 case META_MENU_OP_UNABOVE:
601 name = "toggle-above";
602 break;
603 case META_MENU_OP_WORKSPACES:
604 switch (workspace)
605 {
606 case 1:
607 name = "move-to-workspace-1";
608 break;
609 case 2:
610 name = "move-to-workspace-2";
611 break;
612 case 3:
613 name = "move-to-workspace-3";
614 break;
615 case 4:
616 name = "move-to-workspace-4";
617 break;
618 case 5:
619 name = "move-to-workspace-5";
620 break;
621 case 6:
622 name = "move-to-workspace-6";
623 break;
624 case 7:
625 name = "move-to-workspace-7";
626 break;
627 case 8:
628 name = "move-to-workspace-8";
629 break;
630 case 9:
631 name = "move-to-workspace-9";
632 break;
633 case 10:
634 name = "move-to-workspace-10";
635 break;
636 case 11:
637 name = "move-to-workspace-11";
638 break;
639 case 12:
640 name = "move-to-workspace-12";
641 break;
642 }
643 break;
644 case META_MENU_OP_MOVE:
645 name = "begin-move";
646 break;
647 case META_MENU_OP_RESIZE:
648 name = "begin-resize";
649 break;
650 case META_MENU_OP_MOVE_LEFT:
651 name = "move-to-workspace-left";
652 break;
653 case META_MENU_OP_MOVE_RIGHT:
654 name = "move-to-workspace-right";
655 break;
656 case META_MENU_OP_MOVE_UP:
657 name = "move-to-workspace-up";
658 break;
659 case META_MENU_OP_MOVE_DOWN:
660 name = "move-to-workspace-down";
661 break;
662 case META_MENU_OP_MOVE_NEW:
663 name = "move-to-workspace-new";
664 break;
665 case META_MENU_OP_RECOVER:
666 /* No keybinding for this one */
667 break;
668 default:
669 break;
670 }
671
672 if (name)
673 {
674 meta_prefs_get_window_binding (name, keysym, modifiers);
675 }
676 else
677 {
678 *keysym = 0;
679 *modifiers = 0;
680 }
681 }
682
683 LOCAL_SYMBOL const char*
meta_core_get_workspace_name_with_index(Display * xdisplay,Window xroot,int index)684 meta_core_get_workspace_name_with_index (Display *xdisplay,
685 Window xroot,
686 int index)
687 {
688 MetaDisplay *display;
689 MetaScreen *screen;
690 MetaWorkspace *workspace;
691
692 display = meta_display_for_x_display (xdisplay);
693 screen = meta_display_screen_for_root (display, xroot);
694 g_assert (screen != NULL);
695 workspace = meta_screen_get_workspace_by_index (screen, index);
696 return workspace ? meta_workspace_get_name (workspace) : NULL;
697 }
698
699 LOCAL_SYMBOL gboolean
meta_core_begin_grab_op(Display * xdisplay,Window frame_xwindow,MetaGrabOp op,gboolean pointer_already_grabbed,gboolean frame_action,int button,gulong modmask,guint32 timestamp,int root_x,int root_y)700 meta_core_begin_grab_op (Display *xdisplay,
701 Window frame_xwindow,
702 MetaGrabOp op,
703 gboolean pointer_already_grabbed,
704 gboolean frame_action,
705 int button,
706 gulong modmask,
707 guint32 timestamp,
708 int root_x,
709 int root_y)
710 {
711 MetaWindow *window = meta_core_get_window (xdisplay, frame_xwindow);
712 MetaDisplay *display;
713 MetaScreen *screen;
714
715 display = meta_display_for_x_display (xdisplay);
716 screen = meta_display_screen_for_xwindow (display, frame_xwindow);
717
718 g_assert (screen != NULL);
719
720 return meta_display_begin_grab_op (display, screen, window,
721 op, pointer_already_grabbed,
722 frame_action,
723 button, modmask,
724 timestamp, root_x, root_y);
725 }
726
727 LOCAL_SYMBOL void
meta_core_end_grab_op(Display * xdisplay,guint32 timestamp)728 meta_core_end_grab_op (Display *xdisplay,
729 guint32 timestamp)
730 {
731 MetaDisplay *display;
732
733 display = meta_display_for_x_display (xdisplay);
734
735 meta_display_end_grab_op (display, timestamp);
736 }
737
738 LOCAL_SYMBOL MetaGrabOp
meta_core_get_grab_op(Display * xdisplay)739 meta_core_get_grab_op (Display *xdisplay)
740 {
741 MetaDisplay *display;
742
743 display = meta_display_for_x_display (xdisplay);
744
745 return display->grab_op;
746 }
747
748 LOCAL_SYMBOL Window
meta_core_get_grab_frame(Display * xdisplay)749 meta_core_get_grab_frame (Display *xdisplay)
750 {
751 MetaDisplay *display;
752
753 display = meta_display_for_x_display (xdisplay);
754
755 g_assert (display != NULL);
756 g_assert (display->grab_op == META_GRAB_OP_NONE ||
757 display->grab_screen != NULL);
758 g_assert (display->grab_op == META_GRAB_OP_NONE ||
759 display->grab_screen->display->xdisplay == xdisplay);
760
761 if (display->grab_op != META_GRAB_OP_NONE &&
762 display->grab_window &&
763 display->grab_window->frame)
764 return display->grab_window->frame->xwindow;
765 else
766 return None;
767 }
768
769 LOCAL_SYMBOL int
meta_core_get_grab_button(Display * xdisplay)770 meta_core_get_grab_button (Display *xdisplay)
771 {
772 MetaDisplay *display;
773
774 display = meta_display_for_x_display (xdisplay);
775
776 if (display->grab_op == META_GRAB_OP_NONE)
777 return -1;
778
779 return display->grab_button;
780 }
781
782 LOCAL_SYMBOL void
meta_core_grab_buttons(Display * xdisplay,Window frame_xwindow)783 meta_core_grab_buttons (Display *xdisplay,
784 Window frame_xwindow)
785 {
786 MetaDisplay *display;
787
788 display = meta_display_for_x_display (xdisplay);
789
790 meta_verbose ("Grabbing buttons on frame 0x%lx\n", frame_xwindow);
791 meta_display_grab_window_buttons (display, frame_xwindow);
792 }
793
794 LOCAL_SYMBOL void
meta_core_set_screen_cursor(Display * xdisplay,Window frame_on_screen,MetaCursor cursor)795 meta_core_set_screen_cursor (Display *xdisplay,
796 Window frame_on_screen,
797 MetaCursor cursor)
798 {
799 MetaWindow *window = meta_core_get_window (xdisplay, frame_on_screen);
800
801 meta_frame_set_screen_cursor (window->frame, cursor);
802 }
803
804 LOCAL_SYMBOL void
meta_core_increment_event_serial(Display * xdisplay)805 meta_core_increment_event_serial (Display *xdisplay)
806 {
807 MetaDisplay *display;
808
809 display = meta_display_for_x_display (xdisplay);
810
811 meta_display_increment_event_serial (display);
812 }
813
814