00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <config.h>
00027 #include "core.h"
00028 #include "frame-private.h"
00029 #include "workspace.h"
00030 #include "prefs.h"
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 static MetaWindow *
00044 get_window (Display *xdisplay,
00045 Window frame_xwindow)
00046 {
00047 MetaDisplay *display;
00048 MetaWindow *window;
00049
00050 display = meta_display_for_x_display (xdisplay);
00051 window = meta_display_lookup_x_window (display, frame_xwindow);
00052
00053 if (window == NULL || window->frame == NULL)
00054 {
00055 meta_bug ("No such frame window 0x%lx!\n", frame_xwindow);
00056 return NULL;
00057 }
00058
00059 return window;
00060 }
00061
00062 void
00063 meta_core_get (Display *xdisplay,
00064 Window xwindow,
00065 ...)
00066 {
00067 va_list args;
00068 MetaCoreGetType request;
00069
00070 MetaDisplay *display = meta_display_for_x_display (xdisplay);
00071 MetaWindow *window = meta_display_lookup_x_window (display, xwindow);
00072
00073 va_start (args, xwindow);
00074
00075 request = va_arg (args, MetaCoreGetType);
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 if (request != META_CORE_WINDOW_HAS_FRAME &&
00089 (window == NULL || window->frame == NULL)) {
00090 meta_bug ("No such frame window 0x%lx!\n", xwindow);
00091 return;
00092 }
00093
00094 while (request != META_CORE_GET_END) {
00095
00096 gpointer answer = va_arg (args, gpointer);
00097
00098 switch (request) {
00099 case META_CORE_WINDOW_HAS_FRAME:
00100 *((gboolean*)answer) = window != NULL && window->frame != NULL;
00101 if (!*((gboolean*)answer)) return;
00102 break;
00103 case META_CORE_GET_CLIENT_WIDTH:
00104 *((gint*)answer) = window->rect.width;
00105 break;
00106 case META_CORE_GET_CLIENT_HEIGHT:
00107 *((gint*)answer) = window->rect.height;
00108 break;
00109 case META_CORE_IS_TITLEBAR_ONSCREEN:
00110 *((gboolean*)answer) = meta_window_titlebar_is_onscreen (window);
00111 break;
00112 case META_CORE_GET_CLIENT_XWINDOW:
00113 *((Window*)answer) = window->xwindow;
00114 break;
00115 case META_CORE_GET_FRAME_FLAGS:
00116 *((MetaFrameFlags*)answer) = meta_frame_get_flags (window->frame);
00117 break;
00118 case META_CORE_GET_FRAME_TYPE:
00119 {
00120 MetaFrameType base_type = META_FRAME_TYPE_LAST;
00121
00122 switch (window->type)
00123 {
00124 case META_WINDOW_NORMAL:
00125 base_type = META_FRAME_TYPE_NORMAL;
00126 break;
00127
00128 case META_WINDOW_DIALOG:
00129 base_type = META_FRAME_TYPE_DIALOG;
00130 break;
00131
00132 case META_WINDOW_MODAL_DIALOG:
00133 base_type = META_FRAME_TYPE_MODAL_DIALOG;
00134 break;
00135
00136 case META_WINDOW_MENU:
00137 base_type = META_FRAME_TYPE_MENU;
00138 break;
00139
00140 case META_WINDOW_UTILITY:
00141 base_type = META_FRAME_TYPE_UTILITY;
00142 break;
00143
00144 case META_WINDOW_DESKTOP:
00145 case META_WINDOW_DOCK:
00146 case META_WINDOW_TOOLBAR:
00147 case META_WINDOW_SPLASHSCREEN:
00148
00149 base_type = META_FRAME_TYPE_LAST;
00150 break;
00151
00152 }
00153
00154 if (base_type == META_FRAME_TYPE_LAST)
00155 {
00156
00157 *((MetaFrameType*)answer) = META_FRAME_TYPE_LAST;
00158 }
00159 else if (window->border_only)
00160 {
00161
00162 *((MetaFrameType*)answer) = META_FRAME_TYPE_BORDER;
00163 }
00164 else
00165 {
00166 *((MetaFrameType*)answer) = base_type;
00167 }
00168
00169 break;
00170 }
00171 case META_CORE_GET_MINI_ICON:
00172 *((GdkPixbuf**)answer) = window->mini_icon;
00173 break;
00174 case META_CORE_GET_ICON:
00175 *((GdkPixbuf**)answer) = window->icon;
00176 break;
00177 case META_CORE_GET_X:
00178 meta_window_get_position (window, (int*)answer, NULL);
00179 break;
00180 case META_CORE_GET_Y:
00181 meta_window_get_position (window, NULL, (int*)answer);
00182 break;
00183 case META_CORE_GET_FRAME_WORKSPACE:
00184 *((gint*)answer) = meta_window_get_net_wm_desktop (window);
00185 break;
00186 case META_CORE_GET_FRAME_X:
00187 *((gint*)answer) = window->frame->rect.x;
00188 break;
00189 case META_CORE_GET_FRAME_Y:
00190 *((gint*)answer) = window->frame->rect.y;
00191 break;
00192 case META_CORE_GET_FRAME_WIDTH:
00193 *((gint*)answer) = window->frame->rect.width;
00194 break;
00195 case META_CORE_GET_FRAME_HEIGHT:
00196 *((gint*)answer) = window->frame->rect.height;
00197 break;
00198 case META_CORE_GET_SCREEN_WIDTH:
00199 *((gint*)answer) = window->screen->rect.width;
00200 break;
00201 case META_CORE_GET_SCREEN_HEIGHT:
00202 *((gint*)answer) = window->screen->rect.height;
00203 break;
00204
00205 default:
00206 meta_warning(_("Unknown window information request: %d"), request);
00207 }
00208
00209 request = va_arg (args, MetaCoreGetType);
00210 }
00211
00212 va_end (args);
00213 }
00214
00215 void
00216 meta_core_queue_frame_resize (Display *xdisplay,
00217 Window frame_xwindow)
00218 {
00219 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00220
00221 meta_window_queue (window, META_QUEUE_MOVE_RESIZE);
00222 }
00223
00224 void
00225 meta_core_user_move (Display *xdisplay,
00226 Window frame_xwindow,
00227 int x,
00228 int y)
00229 {
00230 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00231
00232 meta_window_move (window, TRUE, x, y);
00233 }
00234
00235 void
00236 meta_core_user_resize (Display *xdisplay,
00237 Window frame_xwindow,
00238 int gravity,
00239 int width,
00240 int height)
00241 {
00242 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00243
00244 meta_window_resize_with_gravity (window, TRUE, width, height, gravity);
00245 }
00246
00247 void
00248 meta_core_user_raise (Display *xdisplay,
00249 Window frame_xwindow)
00250 {
00251 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00252
00253 meta_window_raise (window);
00254 }
00255
00256 void
00257 meta_core_user_lower_and_unfocus (Display *xdisplay,
00258 Window frame_xwindow,
00259 guint32 timestamp)
00260 {
00261 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00262
00263 meta_window_lower (window);
00264
00265 if (meta_prefs_get_focus_mode () == META_FOCUS_MODE_CLICK &&
00266 meta_prefs_get_raise_on_click ())
00267 {
00268
00269
00270
00271
00272 if (window->screen->active_workspace &&
00273 meta_window_located_on_workspace (window,
00274 window->screen->active_workspace))
00275 {
00276 GList* link;
00277 link = g_list_find (window->screen->active_workspace->mru_list,
00278 window);
00279 g_assert (link);
00280
00281 window->screen->active_workspace->mru_list =
00282 g_list_remove_link (window->screen->active_workspace->mru_list,
00283 link);
00284 g_list_free (link);
00285
00286 window->screen->active_workspace->mru_list =
00287 g_list_append (window->screen->active_workspace->mru_list,
00288 window);
00289 }
00290 }
00291
00292
00293 if (window->has_focus)
00294 meta_workspace_focus_default_window (window->screen->active_workspace,
00295 NULL,
00296 timestamp);
00297 }
00298
00299 void
00300 meta_core_user_focus (Display *xdisplay,
00301 Window frame_xwindow,
00302 guint32 timestamp)
00303 {
00304 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00305
00306 meta_window_focus (window, timestamp);
00307 }
00308
00309 void
00310 meta_core_minimize (Display *xdisplay,
00311 Window frame_xwindow)
00312 {
00313 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00314
00315 meta_window_minimize (window);
00316 }
00317
00318 void
00319 meta_core_maximize (Display *xdisplay,
00320 Window frame_xwindow)
00321 {
00322 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00323
00324 if (meta_prefs_get_raise_on_click ())
00325 meta_window_raise (window);
00326
00327 meta_window_maximize (window,
00328 META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
00329 }
00330
00331 void
00332 meta_core_toggle_maximize_vertically (Display *xdisplay,
00333 Window frame_xwindow)
00334 {
00335 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00336
00337 if (meta_prefs_get_raise_on_click ())
00338 meta_window_raise (window);
00339
00340 if (META_WINDOW_MAXIMIZED_VERTICALLY (window))
00341 meta_window_unmaximize (window,
00342 META_MAXIMIZE_VERTICAL);
00343 else
00344 meta_window_maximize (window,
00345 META_MAXIMIZE_VERTICAL);
00346 }
00347
00348 void
00349 meta_core_toggle_maximize_horizontally (Display *xdisplay,
00350 Window frame_xwindow)
00351 {
00352 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00353
00354 if (meta_prefs_get_raise_on_click ())
00355 meta_window_raise (window);
00356
00357 if (META_WINDOW_MAXIMIZED_HORIZONTALLY (window))
00358 meta_window_unmaximize (window,
00359 META_MAXIMIZE_HORIZONTAL);
00360 else
00361 meta_window_maximize (window,
00362 META_MAXIMIZE_HORIZONTAL);
00363 }
00364
00365 void
00366 meta_core_toggle_maximize (Display *xdisplay,
00367 Window frame_xwindow)
00368 {
00369 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00370
00371 if (meta_prefs_get_raise_on_click ())
00372 meta_window_raise (window);
00373
00374 if (META_WINDOW_MAXIMIZED (window))
00375 meta_window_unmaximize (window,
00376 META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
00377 else
00378 meta_window_maximize (window,
00379 META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
00380 }
00381
00382 void
00383 meta_core_unmaximize (Display *xdisplay,
00384 Window frame_xwindow)
00385 {
00386 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00387
00388 if (meta_prefs_get_raise_on_click ())
00389 meta_window_raise (window);
00390
00391 meta_window_unmaximize (window,
00392 META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
00393 }
00394
00395 void
00396 meta_core_delete (Display *xdisplay,
00397 Window frame_xwindow,
00398 guint32 timestamp)
00399 {
00400 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00401
00402 meta_window_delete (window, timestamp);
00403 }
00404
00405 void
00406 meta_core_unshade (Display *xdisplay,
00407 Window frame_xwindow,
00408 guint32 timestamp)
00409 {
00410 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00411
00412 meta_window_unshade (window, timestamp);
00413 }
00414
00415 void
00416 meta_core_shade (Display *xdisplay,
00417 Window frame_xwindow,
00418 guint32 timestamp)
00419 {
00420 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00421
00422 meta_window_shade (window, timestamp);
00423 }
00424
00425 void
00426 meta_core_unstick (Display *xdisplay,
00427 Window frame_xwindow)
00428 {
00429 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00430
00431 meta_window_unstick (window);
00432 }
00433
00434 void
00435 meta_core_make_above (Display *xdisplay,
00436 Window frame_xwindow)
00437 {
00438 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00439
00440 meta_window_make_above (window);
00441 }
00442
00443 void
00444 meta_core_unmake_above (Display *xdisplay,
00445 Window frame_xwindow)
00446 {
00447 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00448
00449 meta_window_unmake_above (window);
00450 }
00451
00452 void
00453 meta_core_stick (Display *xdisplay,
00454 Window frame_xwindow)
00455 {
00456 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00457
00458 meta_window_stick (window);
00459 }
00460
00461 void
00462 meta_core_change_workspace (Display *xdisplay,
00463 Window frame_xwindow,
00464 int new_workspace)
00465 {
00466 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00467
00468 meta_window_change_workspace (window,
00469 meta_screen_get_workspace_by_index (window->screen,
00470 new_workspace));
00471 }
00472
00473 int
00474 meta_core_get_num_workspaces (Screen *xscreen)
00475 {
00476 MetaScreen *screen;
00477
00478 screen = meta_screen_for_x_screen (xscreen);
00479
00480 return meta_screen_get_n_workspaces (screen);
00481 }
00482
00483 int
00484 meta_core_get_active_workspace (Screen *xscreen)
00485 {
00486 MetaScreen *screen;
00487
00488 screen = meta_screen_for_x_screen (xscreen);
00489
00490 return meta_workspace_index (screen->active_workspace);
00491 }
00492
00493 void
00494 meta_core_show_window_menu (Display *xdisplay,
00495 Window frame_xwindow,
00496 int root_x,
00497 int root_y,
00498 int button,
00499 guint32 timestamp)
00500 {
00501 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00502
00503 if (meta_prefs_get_raise_on_click ())
00504 meta_window_raise (window);
00505 meta_window_focus (window, timestamp);
00506
00507 meta_window_show_menu (window, root_x, root_y, button, timestamp);
00508 }
00509
00510 void
00511 meta_core_get_menu_accelerator (MetaMenuOp menu_op,
00512 int workspace,
00513 unsigned int *keysym,
00514 MetaVirtualModifier *modifiers)
00515 {
00516 const char *name;
00517
00518 name = NULL;
00519
00520 switch (menu_op)
00521 {
00522 case META_MENU_OP_DELETE:
00523 name = META_KEYBINDING_CLOSE;
00524 break;
00525 case META_MENU_OP_MINIMIZE:
00526 name = META_KEYBINDING_MINIMIZE;
00527 break;
00528 case META_MENU_OP_UNMAXIMIZE:
00529 name = META_KEYBINDING_UNMAXIMIZE;
00530 break;
00531 case META_MENU_OP_MAXIMIZE:
00532 name = META_KEYBINDING_MAXIMIZE;
00533 break;
00534 case META_MENU_OP_UNSHADE:
00535 case META_MENU_OP_SHADE:
00536 name = META_KEYBINDING_TOGGLE_SHADE;
00537 break;
00538 case META_MENU_OP_UNSTICK:
00539 case META_MENU_OP_STICK:
00540 name = META_KEYBINDING_TOGGLE_STICKY;
00541 break;
00542 case META_MENU_OP_ABOVE:
00543 case META_MENU_OP_UNABOVE:
00544 name = META_KEYBINDING_TOGGLE_ABOVE;
00545 break;
00546 case META_MENU_OP_WORKSPACES:
00547 switch (workspace)
00548 {
00549 case 1:
00550 name = META_KEYBINDING_MOVE_WORKSPACE_1;
00551 break;
00552 case 2:
00553 name = META_KEYBINDING_MOVE_WORKSPACE_2;
00554 break;
00555 case 3:
00556 name = META_KEYBINDING_MOVE_WORKSPACE_3;
00557 break;
00558 case 4:
00559 name = META_KEYBINDING_MOVE_WORKSPACE_4;
00560 break;
00561 case 5:
00562 name = META_KEYBINDING_MOVE_WORKSPACE_5;
00563 break;
00564 case 6:
00565 name = META_KEYBINDING_MOVE_WORKSPACE_6;
00566 break;
00567 case 7:
00568 name = META_KEYBINDING_MOVE_WORKSPACE_7;
00569 break;
00570 case 8:
00571 name = META_KEYBINDING_MOVE_WORKSPACE_8;
00572 break;
00573 case 9:
00574 name = META_KEYBINDING_MOVE_WORKSPACE_9;
00575 break;
00576 case 10:
00577 name = META_KEYBINDING_MOVE_WORKSPACE_10;
00578 break;
00579 case 11:
00580 name = META_KEYBINDING_MOVE_WORKSPACE_11;
00581 break;
00582 case 12:
00583 name = META_KEYBINDING_MOVE_WORKSPACE_12;
00584 break;
00585 }
00586 break;
00587 case META_MENU_OP_MOVE:
00588 name = META_KEYBINDING_BEGIN_MOVE;
00589 break;
00590 case META_MENU_OP_RESIZE:
00591 name = META_KEYBINDING_BEGIN_RESIZE;
00592 break;
00593 case META_MENU_OP_MOVE_LEFT:
00594 name = META_KEYBINDING_MOVE_WORKSPACE_LEFT;
00595 break;
00596 case META_MENU_OP_MOVE_RIGHT:
00597 name = META_KEYBINDING_MOVE_WORKSPACE_RIGHT;
00598 break;
00599 case META_MENU_OP_MOVE_UP:
00600 name = META_KEYBINDING_MOVE_WORKSPACE_UP;
00601 break;
00602 case META_MENU_OP_MOVE_DOWN:
00603 name = META_KEYBINDING_MOVE_WORKSPACE_DOWN;
00604 break;
00605 case META_MENU_OP_RECOVER:
00606
00607 break;
00608 }
00609
00610 if (name)
00611 {
00612 meta_prefs_get_window_binding (name, keysym, modifiers);
00613 }
00614 else
00615 {
00616 *keysym = 0;
00617 *modifiers = 0;
00618 }
00619 }
00620
00621 const char*
00622 meta_core_get_workspace_name_with_index (Display *xdisplay,
00623 Window xroot,
00624 int index)
00625 {
00626 MetaDisplay *display;
00627 MetaScreen *screen;
00628 MetaWorkspace *workspace;
00629
00630 display = meta_display_for_x_display (xdisplay);
00631 screen = meta_display_screen_for_root (display, xroot);
00632 g_assert (screen != NULL);
00633 workspace = meta_screen_get_workspace_by_index (screen, index);
00634 return workspace ? meta_workspace_get_name (workspace) : NULL;
00635 }
00636
00637 gboolean
00638 meta_core_begin_grab_op (Display *xdisplay,
00639 Window frame_xwindow,
00640 MetaGrabOp op,
00641 gboolean pointer_already_grabbed,
00642 gboolean frame_action,
00643 int button,
00644 gulong modmask,
00645 guint32 timestamp,
00646 int root_x,
00647 int root_y)
00648 {
00649 MetaWindow *window = get_window (xdisplay, frame_xwindow);
00650 MetaDisplay *display;
00651 MetaScreen *screen;
00652
00653 display = meta_display_for_x_display (xdisplay);
00654 screen = meta_display_screen_for_xwindow (display, frame_xwindow);
00655
00656 g_assert (screen != NULL);
00657
00658 return meta_display_begin_grab_op (display, screen, window,
00659 op, pointer_already_grabbed,
00660 frame_action,
00661 button, modmask,
00662 timestamp, root_x, root_y);
00663 }
00664
00665 void
00666 meta_core_end_grab_op (Display *xdisplay,
00667 guint32 timestamp)
00668 {
00669 MetaDisplay *display;
00670
00671 display = meta_display_for_x_display (xdisplay);
00672
00673 meta_display_end_grab_op (display, timestamp);
00674 }
00675
00676 MetaGrabOp
00677 meta_core_get_grab_op (Display *xdisplay)
00678 {
00679 MetaDisplay *display;
00680
00681 display = meta_display_for_x_display (xdisplay);
00682
00683 return display->grab_op;
00684 }
00685
00686 Window
00687 meta_core_get_grab_frame (Display *xdisplay)
00688 {
00689 MetaDisplay *display;
00690
00691 display = meta_display_for_x_display (xdisplay);
00692
00693 g_assert (display != NULL);
00694 g_assert (display->grab_op == META_GRAB_OP_NONE ||
00695 display->grab_screen != NULL);
00696 g_assert (display->grab_op == META_GRAB_OP_NONE ||
00697 display->grab_screen->display->xdisplay == xdisplay);
00698
00699 if (display->grab_op != META_GRAB_OP_NONE &&
00700 display->grab_window &&
00701 display->grab_window->frame)
00702 return display->grab_window->frame->xwindow;
00703 else
00704 return None;
00705 }
00706
00707 int
00708 meta_core_get_grab_button (Display *xdisplay)
00709 {
00710 MetaDisplay *display;
00711
00712 display = meta_display_for_x_display (xdisplay);
00713
00714 if (display->grab_op == META_GRAB_OP_NONE)
00715 return -1;
00716
00717 return display->grab_button;
00718 }
00719
00720 void
00721 meta_core_grab_buttons (Display *xdisplay,
00722 Window frame_xwindow)
00723 {
00724 MetaDisplay *display;
00725
00726 display = meta_display_for_x_display (xdisplay);
00727
00728 meta_verbose ("Grabbing buttons on frame 0x%lx\n", frame_xwindow);
00729 meta_display_grab_window_buttons (display, frame_xwindow);
00730 }
00731
00732 void
00733 meta_core_set_screen_cursor (Display *xdisplay,
00734 Window frame_on_screen,
00735 MetaCursor cursor)
00736 {
00737 MetaWindow *window = get_window (xdisplay, frame_on_screen);
00738
00739 meta_frame_set_screen_cursor (window->frame, cursor);
00740 }
00741
00742 void
00743 meta_core_increment_event_serial (Display *xdisplay)
00744 {
00745 MetaDisplay *display;
00746
00747 display = meta_display_for_x_display (xdisplay);
00748
00749 meta_display_increment_event_serial (display);
00750 }
00751
00752 void
00753 meta_invalidate_default_icons (void)
00754 {
00755 MetaDisplay *display = meta_get_display ();
00756 GSList *windows;
00757 GSList *l;
00758
00759 if (display == NULL)
00760 return;
00761
00762 windows = meta_display_list_windows (display);
00763 for (l = windows; l != NULL; l = l->next)
00764 {
00765 MetaWindow *window = (MetaWindow*)l->data;
00766
00767 if (window->icon_cache.origin == USING_FALLBACK_ICON)
00768 {
00769 meta_icon_cache_free (&(window->icon_cache));
00770 meta_window_update_icon_now (window);
00771 }
00772 }
00773
00774 g_slist_free (windows);
00775 }
00776