LOCAL_SYMBOL void meta_stack_set_positions (MetaStack *stack, GList *windows) { int i; GList *tmp; /* Make sure any adds or removes aren't in limbo -- is this needed? */ stack_ensure_sorted (stack); if (!lists_contain_same_windows (windows, stack->sorted)) { meta_warning ("This list of windows has somehow changed; not resetting " "positions of the windows.\n"); return; } g_list_free (stack->sorted); stack->sorted = g_list_copy (windows); stack->need_resort = TRUE; stack->need_constrain = TRUE; i = 0; tmp = windows; while (tmp != NULL) { MetaWindow *w = tmp->data; w->stack_position = i++; tmp = tmp->next; } meta_topic (META_DEBUG_STACK, "Reset the stack positions of (nearly) all windows\n"); stack_sync_to_server (stack); meta_stack_update_window_tile_matches (stack, NULL); }
static gboolean effects_draw_box_animation_timeout (BoxAnimationContext *context) { double elapsed; GTimeVal current_time; MetaRectangle draw_rect; double fraction; #ifndef HAVE_SHAPE if (!context->first_time) { /* Restore the previously drawn background */ XDrawRectangle (context->screen->display->xdisplay, context->screen->xroot, context->gc, context->last_rect.x, context->last_rect.y, context->last_rect.width, context->last_rect.height); } else context->first_time = FALSE; #endif /* !HAVE_SHAPE */ g_get_current_time (¤t_time); /* We use milliseconds for all times */ elapsed = ((((double)current_time.tv_sec - context->start_time.tv_sec) * G_USEC_PER_SEC + (current_time.tv_usec - context->start_time.tv_usec))) / 1000.0; if (elapsed < 0) { /* Probably the system clock was set backwards? */ meta_warning ("System clock seemed to go backwards?\n"); elapsed = G_MAXDOUBLE; /* definitely done. */ } if (elapsed > context->millisecs_duration) { /* All done */ #ifdef HAVE_SHAPE XDestroyWindow (context->screen->display->xdisplay, context->wireframe_xwindow); #else meta_display_ungrab (context->screen->display); meta_ui_pop_delay_exposes (context->screen->ui); XFreeGC (context->screen->display->xdisplay, context->gc); #endif /* !HAVE_SHAPE */ graphics_sync (context); g_free (context); return FALSE; } g_assert (context->millisecs_duration > 0.0); fraction = elapsed / context->millisecs_duration; draw_rect = context->start_rect; /* Now add a delta proportional to elapsed time. */ draw_rect.x += (context->end_rect.x - context->start_rect.x) * fraction; draw_rect.y += (context->end_rect.y - context->start_rect.y) * fraction; draw_rect.width += (context->end_rect.width - context->start_rect.width) * fraction; draw_rect.height += (context->end_rect.height - context->start_rect.height) * fraction; /* don't confuse X or gdk-pixbuf with bogus rectangles */ if (draw_rect.width < 1) draw_rect.width = 1; if (draw_rect.height < 1) draw_rect.height = 1; #ifdef HAVE_SHAPE update_wireframe_window (context->screen->display, context->wireframe_xwindow, &draw_rect); #else context->last_rect = draw_rect; /* Draw the rectangle */ XDrawRectangle (context->screen->display->xdisplay, context->screen->xroot, context->gc, draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height); #endif /* !HAVE_SHAPE */ /* kick changes onto the server */ graphics_sync (context); return TRUE; }
static void ensure_xfixes_cursor (MetaCursorTracker *tracker) { MetaDisplay *display = meta_get_display (); XFixesCursorImage *cursor_image; CoglTexture2D *sprite; guint8 *cursor_data; gboolean free_cursor_data; CoglContext *ctx; CoglError *error = NULL; if (tracker->xfixes_cursor) return; cursor_image = XFixesGetCursorImage (display->xdisplay); if (!cursor_image) return; /* Like all X APIs, XFixesGetCursorImage() returns arrays of 32-bit * quantities as arrays of long; we need to convert on 64 bit */ if (sizeof(long) == 4) { cursor_data = (guint8 *)cursor_image->pixels; free_cursor_data = FALSE; } else { int i, j; guint32 *cursor_words; gulong *p; guint32 *q; cursor_words = g_new (guint32, cursor_image->width * cursor_image->height); cursor_data = (guint8 *)cursor_words; p = cursor_image->pixels; q = cursor_words; for (j = 0; j < cursor_image->height; j++) for (i = 0; i < cursor_image->width; i++) *(q++) = *(p++); free_cursor_data = TRUE; } ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); sprite = cogl_texture_2d_new_from_data (ctx, cursor_image->width, cursor_image->height, CLUTTER_CAIRO_FORMAT_ARGB32, cursor_image->width * 4, /* stride */ cursor_data, &error); if (free_cursor_data) g_free (cursor_data); if (error != NULL) { meta_warning ("Failed to allocate cursor sprite texture: %s\n", error->message); cogl_error_free (error); } if (sprite != NULL) { MetaCursorSprite *cursor_sprite = meta_cursor_sprite_new (); meta_cursor_sprite_set_texture (cursor_sprite, sprite, cursor_image->xhot, cursor_image->yhot); cogl_object_unref (sprite); tracker->xfixes_cursor = cursor_sprite; } XFree (cursor_image); }
/** * meta_init: (skip) * * Initialize mutter. Call this after meta_get_option_context() and * meta_plugin_manager_set_plugin_type(), and before meta_run(). */ void meta_init (void) { struct sigaction act; sigset_t empty_mask; sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif g_unix_signal_add (SIGTERM, on_sigterm, NULL); if (g_getenv ("MUTTER_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("MUTTER_DEBUG")) meta_set_debugging (TRUE); #if defined(CLUTTER_WINDOWING_EGL) && defined(HAVE_NATIVE_BACKEND) if (opt_display_server) clutter_set_windowing_backend (CLUTTER_WINDOWING_EGL); else #endif clutter_set_windowing_backend (CLUTTER_WINDOWING_X11); #ifdef HAVE_WAYLAND meta_set_is_wayland_compositor (opt_wayland); #endif if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); #ifdef HAVE_INTROSPECTION g_irepository_prepend_search_path (MUTTER_PKGLIBDIR); #endif #ifdef HAVE_WAYLAND if (meta_is_wayland_compositor ()) meta_wayland_pre_clutter_init (); #endif /* NB: When running as a hybrid wayland compositor we run our own headless X * server so the user can't control the X display to connect too. */ if (!meta_is_wayland_compositor ()) meta_select_display (opt_display_name); meta_clutter_init (); #ifdef HAVE_WAYLAND /* Bring up Wayland. This also launches Xwayland and sets DISPLAY as well... */ if (meta_is_wayland_compositor ()) meta_wayland_init (); #endif meta_set_syncing (opt_sync || (g_getenv ("MUTTER_SYNC") != NULL)); if (opt_replace_wm) meta_set_replace_current_wm (TRUE); if (opt_save_file && opt_client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (); meta_restart_init (); }
static gboolean find_preferred_position (MetaWindow *window, MetaFrameBorders *borders, /* visible windows on relevant workspaces */ GList *windows, int xinerama, int x, int y, int *new_x, int *new_y) { MetaRectangle rect; MetaRectangle work_area; MetaPlacementMode placement_mode_pref = meta_prefs_get_placement_mode (); /* If first_fit placement is the preference, just pass all the * options through to the original find_first_fit function. * Otherwise, process the user preference here. */ if (placement_mode_pref == META_PLACEMENT_MODE_SMART) { return find_first_fit (window, borders, windows, xinerama, x, y, new_x, new_y); } else if (placement_mode_pref == META_PLACEMENT_MODE_CASCADE) { /* This is an abuse of find_next_cascade(), because it was not * intended for this use, and because it is not designed to * deal with placement on multiple Xineramas. */ find_next_cascade (window, borders, windows, x, y, new_x, new_y); return TRUE; } rect.width = window->rect.width; rect.height = window->rect.height; if (borders) { rect.width += borders->visible.left + borders->visible.right; rect.height += borders->visible.top + borders->visible.bottom; } meta_window_get_work_area_for_xinerama (window, xinerama, &work_area); /* Cannot use rect_fits_in_work_area here because that function * also checks the x & y position of rect, but those are not set * yet in this case. */ if ((rect.width <= work_area.width) && (rect.height <= work_area.height)) { switch (placement_mode_pref) { case META_PLACEMENT_MODE_CENTER: /* This is a plain centering, different from center_tile */ *new_x = work_area.x + ((work_area.width - rect.width) / 2); *new_y = work_area.y + ((work_area.height - rect.height) / 2); break; case META_PLACEMENT_MODE_ORIGIN: *new_x = work_area.x; *new_y = work_area.y; break; case META_PLACEMENT_MODE_RANDOM: *new_x = (int) ((float) (work_area.width - rect.width) * ((float) rand() / (float) RAND_MAX)); *new_y = (int) ((float) (work_area.height - rect.height) * ((float) rand() / (float) RAND_MAX)); *new_x += work_area.x; *new_y += work_area.y; break; case META_PLACEMENT_MODE_SMART: case META_PLACEMENT_MODE_CASCADE: break; default: meta_warning ("Unknown window-placement option chosen.\n"); return FALSE; break; } if (borders) { *new_x += borders->visible.left; *new_y += borders->visible.top; } return TRUE; } return FALSE; }
/** * meta_run: (skip) * * Runs muffin. Call this after completing your own initialization. * * Return value: muffin's exit status */ int meta_run (void) { const gchar *log_domains[] = { NULL, G_LOG_DOMAIN, "Gtk", "Gdk", "GLib", "Pango", "GLib-GObject", "GThread" }; guint i; /* Load prefs */ meta_prefs_init (); meta_prefs_add_listener (prefs_changed_callback, NULL); for (i=0; i<G_N_ELEMENTS(log_domains); i++) g_log_set_handler (log_domains[i], G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, log_handler, NULL); if (g_getenv ("MUFFIN_G_FATAL_WARNINGS") != NULL) g_log_set_always_fatal (G_LOG_LEVEL_MASK); meta_ui_set_current_theme (meta_prefs_get_theme (), FALSE); if (!meta_ui_have_a_theme ()) { meta_ui_set_current_theme ("Default", FALSE); meta_warning (_("Could not find theme %s. Falling back to default theme."), meta_prefs_get_theme ()); } /* Connect to SM as late as possible - but before managing display, * or we might try to manage a window before we have the session * info */ if (!opt_disable_sm) { if (opt_client_id == NULL) { const gchar *desktop_autostart_id; desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID"); if (desktop_autostart_id != NULL) opt_client_id = g_strdup (desktop_autostart_id); } /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to * use the same client id. */ g_unsetenv ("DESKTOP_AUTOSTART_ID"); meta_session_init (opt_client_id, opt_save_file); } /* Free memory possibly allocated by the argument parsing which are * no longer needed. */ g_free (opt_save_file); g_free (opt_display_name); g_free (opt_client_id); if (!meta_display_open ()) meta_exit (META_EXIT_ERROR); g_main_loop_run (meta_main_loop); meta_finalize (); return meta_exit_code; }
void meta_workspace_focus_default_window (MetaWorkspace *workspace, MetaWindow *not_this_one, guint32 timestamp) { if (timestamp == CurrentTime) { meta_warning ("CurrentTime used to choose focus window; " "focus window may not be correct.\n"); } if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_CLICK || !workspace->screen->display->mouse_mode) focus_ancestor_or_top_window (workspace, not_this_one, timestamp); else { MetaWindow * window; window = meta_screen_get_mouse_window (workspace->screen, not_this_one); if (window && window->type != META_WINDOW_DOCK && window->type != META_WINDOW_DESKTOP) { if (timestamp == CurrentTime) { /* We would like for this to never happen. However, if * it does happen then we kludge since using CurrentTime * can mean ugly race conditions--and we can avoid these * by allowing EnterNotify events (which come with * timestamps) to handle focus. */ meta_topic (META_DEBUG_FOCUS, "Not focusing mouse window %s because EnterNotify events should handle that\n", window->desc); } else { meta_topic (META_DEBUG_FOCUS, "Focusing mouse window %s\n", window->desc); meta_window_focus (window, timestamp); } if (workspace->screen->display->autoraise_window != window && meta_prefs_get_auto_raise ()) { meta_display_queue_autoraise_callback (workspace->screen->display, window); } } else if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_SLOPPY) focus_ancestor_or_top_window (workspace, not_this_one, timestamp); else if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_MOUSE) { meta_topic (META_DEBUG_FOCUS, "Setting focus to no_focus_window, since no valid " "window to focus found.\n"); meta_display_focus_the_no_focus_window (workspace->screen->display, workspace->screen, timestamp); } } }
static char* load_state (const char *previous_save_file) { GMarkupParseContext *context; GError *error; ParseData parse_data; char *text; gsize length; char *session_file; session_file = g_strconcat (g_get_user_config_dir (), G_DIR_SEPARATOR_S "consortium" G_DIR_SEPARATOR_S "sessions" G_DIR_SEPARATOR_S, previous_save_file, NULL); error = NULL; if (!g_file_get_contents (session_file, &text, &length, &error)) { char *canonical_session_file = session_file; /* Maybe they were doing it the old way, with ~/.consortium */ session_file = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S ".consortium" G_DIR_SEPARATOR_S "sessions" G_DIR_SEPARATOR_S, previous_save_file, NULL); if (!g_file_get_contents (session_file, &text, &length, NULL)) { /* oh, just give up */ g_error_free (error); g_free (session_file); g_free (canonical_session_file); return NULL; } g_free (canonical_session_file); } meta_topic (META_DEBUG_SM, "Parsing saved session file %s\n", session_file); g_free (session_file); session_file = NULL; parse_data.info = NULL; parse_data.previous_id = NULL; context = g_markup_parse_context_new (&consortium_session_parser, 0, &parse_data, NULL); error = NULL; if (!g_markup_parse_context_parse (context, text, length, &error)) goto error; error = NULL; if (!g_markup_parse_context_end_parse (context, &error)) goto error; g_markup_parse_context_free (context); goto out; error: meta_warning (_("Failed to parse saved session file: %s\n"), error->message); g_error_free (error); if (parse_data.info) session_info_free (parse_data.info); g_free (parse_data.previous_id); parse_data.previous_id = NULL; out: g_free (text); return parse_data.previous_id; }
static void save_state (void) { char *consortium_dir; char *session_dir; FILE *outfile; GSList *windows; GSList *tmp; int stack_position; g_assert (client_id); outfile = NULL; /* * g_get_user_config_dir() is guaranteed to return an existing directory. * Eventually, if SM stays with the WM, I'd like to make this * something like <config>/window_placement in a standard format. * Future optimisers should note also that by the time we get here * we probably already have full_save_path figured out and therefore * can just use the directory name from that. */ consortium_dir = g_strconcat (g_get_user_config_dir (), G_DIR_SEPARATOR_S "consortium", NULL); session_dir = g_strconcat (consortium_dir, G_DIR_SEPARATOR_S "sessions", NULL); if (mkdir (consortium_dir, 0700) < 0 && errno != EEXIST) { meta_warning (_("Could not create directory '%s': %s\n"), consortium_dir, g_strerror (errno)); } if (mkdir (session_dir, 0700) < 0 && errno != EEXIST) { meta_warning (_("Could not create directory '%s': %s\n"), session_dir, g_strerror (errno)); } meta_topic (META_DEBUG_SM, "Saving session to '%s'\n", full_save_file ()); outfile = fopen (full_save_file (), "w"); if (outfile == NULL) { meta_warning (_("Could not open session file '%s' for writing: %s\n"), full_save_file (), g_strerror (errno)); goto out; } /* The file format is: * <consortium_session id="foo"> * <window id="bar" class="XTerm" name="xterm" title="/foo/bar" role="blah" type="normal" stacking="5"> * <workspace index="2"/> * <workspace index="4"/> * <sticky/> <minimized/> <maximized/> * <geometry x="100" y="100" width="200" height="200" gravity="northwest"/> * </window> * </consortium_session> * * Note that attributes on <window> are the match info we use to * see if the saved state applies to a restored window, and * child elements are the saved state to be applied. * */ fprintf (outfile, "<consortium_session id=\"%s\">\n", client_id); windows = meta_display_list_windows (meta_get_display ()); stack_position = 0; windows = g_slist_sort (windows, meta_display_stack_cmp); tmp = windows; stack_position = 0; while (tmp != NULL) { MetaWindow *window; window = tmp->data; if (window->sm_client_id) { char *sm_client_id; char *res_class; char *res_name; char *role; char *title; /* client id, class, name, role are not expected to be * in UTF-8 (I think they are in XPCS which is Latin-1? * in practice they are always ascii though.) */ sm_client_id = encode_text_as_utf8_markup (window->sm_client_id); res_class = window->res_class ? encode_text_as_utf8_markup (window->res_class) : NULL; res_name = window->res_name ? encode_text_as_utf8_markup (window->res_name) : NULL; role = window->role ? encode_text_as_utf8_markup (window->role) : NULL; if (window->title) title = g_markup_escape_text (window->title, -1); else title = NULL; meta_topic (META_DEBUG_SM, "Saving session managed window %s, client ID '%s'\n", window->desc, window->sm_client_id); fprintf (outfile, " <window id=\"%s\" class=\"%s\" name=\"%s\" title=\"%s\" role=\"%s\" type=\"%s\" stacking=\"%d\">\n", sm_client_id, res_class ? res_class : "", res_name ? res_name : "", title ? title : "", role ? role : "", window_type_to_string (window->type), stack_position); g_free (sm_client_id); g_free (res_class); g_free (res_name); g_free (role); g_free (title); /* Sticky */ if (window->on_all_workspaces) fputs (" <sticky/>\n", outfile); /* Minimized */ if (window->minimized) fputs (" <minimized/>\n", outfile); /* Maximized */ if (META_WINDOW_MAXIMIZED (window)) { fprintf (outfile, " <maximized saved_x=\"%d\" saved_y=\"%d\" saved_width=\"%d\" saved_height=\"%d\"/>\n", window->saved_rect.x, window->saved_rect.y, window->saved_rect.width, window->saved_rect.height); } /* Workspaces we're on */ { int n; n = meta_workspace_index (window->workspace); fprintf (outfile, " <workspace index=\"%d\"/>\n", n); } /* Gravity */ { int x, y, w, h; meta_window_get_geometry (window, &x, &y, &w, &h); fprintf (outfile, " <geometry x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" gravity=\"%s\"/>\n", x, y, w, h, meta_gravity_to_string (window->size_hints.win_gravity)); } fputs (" </window>\n", outfile); } else { meta_topic (META_DEBUG_SM, "Not saving window '%s', not session managed\n", window->desc); } tmp = tmp->next; ++stack_position; } g_slist_free (windows); fputs ("</consortium_session>\n", outfile); out: if (outfile) { /* FIXME need a dialog for this */ if (ferror (outfile)) { meta_warning (_("Error writing session file '%s': %s\n"), full_save_file (), g_strerror (errno)); } if (fclose (outfile)) { meta_warning (_("Error closing session file '%s': %s\n"), full_save_file (), g_strerror (errno)); } } g_free (consortium_dir); g_free (session_dir); }
static gboolean meta_display_handle_event (MetaDisplay *display, const ClutterEvent *event) { MetaWindow *window; gboolean bypass_clutter = FALSE; G_GNUC_UNUSED gboolean bypass_wayland = FALSE; MetaGestureTracker *tracker; ClutterEventSequence *sequence; sequence = clutter_event_get_event_sequence (event); /* Set the pointer emulating sequence on touch begin, if eligible */ if (event->type == CLUTTER_TOUCH_BEGIN && !display->pointer_emulating_sequence && sequence_is_pointer_emulated (display, event)) display->pointer_emulating_sequence = sequence; #ifdef HAVE_WAYLAND MetaWaylandCompositor *compositor = NULL; if (meta_is_wayland_compositor ()) { compositor = meta_wayland_compositor_get_default (); meta_wayland_compositor_update (compositor, event); } #endif if (meta_is_wayland_compositor () && event->type == CLUTTER_MOTION) { MetaCursorTracker *tracker = meta_cursor_tracker_get_for_screen (NULL); meta_cursor_tracker_update_position (tracker, event->motion.x, event->motion.y); } handle_idletime_for_event (event); window = get_window_for_event (display, event); display->current_time = event->any.time; if (window && !window->override_redirect && (event->type == CLUTTER_KEY_PRESS || event->type == CLUTTER_BUTTON_PRESS || event->type == CLUTTER_TOUCH_BEGIN)) { if (CurrentTime == display->current_time) { /* We can't use missing (i.e. invalid) timestamps to set user time, * nor do we want to use them to sanity check other timestamps. * See bug 313490 for more details. */ meta_warning ("Event has no timestamp! You may be using a broken " "program such as xse. Please ask the authors of that " "program to fix it.\n"); } else { meta_window_set_user_time (window, display->current_time); meta_display_sanity_check_timestamps (display, display->current_time); } } tracker = meta_display_get_gesture_tracker (display); if (meta_gesture_tracker_handle_event (tracker, event)) { bypass_wayland = bypass_clutter = TRUE; goto out; } if (display->event_route == META_EVENT_ROUTE_WINDOW_OP) { if (meta_window_handle_mouse_grab_op_event (window, event)) { bypass_clutter = TRUE; bypass_wayland = TRUE; goto out; } } /* For key events, it's important to enforce single-handling, or * we can get into a confused state. So if a keybinding is * handled (because it's one of our hot-keys, or because we are * in a keyboard-grabbed mode like moving a window, we don't * want to pass the key event to the compositor or Wayland at all. */ if (meta_keybindings_process_event (display, window, event)) { bypass_clutter = TRUE; bypass_wayland = TRUE; goto out; } if (window) { if (!clutter_event_get_event_sequence (event)) { /* Swallow all non-touch events on windows that come our way. * Touch events that reach here aren't yet in an accepted state, * so Clutter must see them to maybe trigger gestures into * recognition. */ bypass_clutter = TRUE; } meta_window_handle_ungrabbed_event (window, event); /* This might start a grab op. If it does, then filter out the * event, and if it doesn't, replay the event to release our * own sync grab. */ if (display->event_route == META_EVENT_ROUTE_WINDOW_OP) { bypass_clutter = TRUE; bypass_wayland = TRUE; } else { /* Only replay button press events, since that's where we * have the synchronous grab. */ if (event->type == CLUTTER_BUTTON_PRESS) { MetaBackend *backend = meta_get_backend (); if (META_IS_BACKEND_X11 (backend)) { Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); meta_verbose ("Allowing events time %u\n", (unsigned int)event->button.time); XIAllowEvents (xdisplay, clutter_event_get_device_id (event), XIReplayDevice, event->button.time); } } } goto out; } out: /* If the compositor has a grab, don't pass that through to Wayland */ if (display->event_route == META_EVENT_ROUTE_COMPOSITOR_GRAB) bypass_wayland = TRUE; /* If a Wayland client has a grab, don't pass that through to Clutter */ if (display->event_route == META_EVENT_ROUTE_WAYLAND_POPUP) bypass_clutter = TRUE; #ifdef HAVE_WAYLAND if (compositor && !bypass_wayland) { if (meta_wayland_compositor_handle_event (compositor, event)) bypass_clutter = TRUE; } #endif /* Unset the pointer emulating sequence after its end event is processed */ if (event->type == CLUTTER_TOUCH_END && display->pointer_emulating_sequence == sequence) display->pointer_emulating_sequence = NULL; display->current_time = CurrentTime; return bypass_clutter; }
static gboolean update_binding (MetaKeyPref *binding, gchar **strokes) { unsigned int keysym; unsigned int keycode; MetaVirtualModifier mods; gboolean changed = FALSE; MetaKeyCombo *combo; int i; meta_topic (META_DEBUG_KEYBINDINGS, "Binding \"%s\" has new GSettings value\n", binding->name); /* Okay, so, we're about to provide a new list of key combos for this * action. Delete any pre-existing list. */ g_slist_foreach (binding->bindings, (GFunc) g_free, NULL); g_slist_free (binding->bindings); binding->bindings = NULL; for (i = 0; strokes && strokes[i]; i++) { keysym = 0; keycode = 0; mods = 0; if (!meta_ui_parse_accelerator (strokes[i], &keysym, &keycode, &mods)) { meta_topic (META_DEBUG_KEYBINDINGS, "Failed to parse new GSettings value\n"); meta_warning (_("\"%s\" found in configuration database is not a valid value for keybinding \"%s\"\n"), strokes[i], binding->name); /* Value is kept and will thus be removed next time we save the key. * Changing the key in response to a modification could lead to cyclic calls. */ continue; } /* Bug 329676: Bindings which can be shifted must not have no modifiers, * nor only SHIFT as a modifier. */ if (binding->add_shift && 0 != keysym && (META_VIRTUAL_SHIFT_MASK == mods || 0 == mods)) { meta_warning ("Cannot bind \"%s\" to %s: it needs a modifier " "such as Ctrl or Alt.\n", binding->name, strokes[i]); /* Value is kept and will thus be removed next time we save the key. * Changing the key in response to a modification could lead to cyclic calls. */ continue; } changed = TRUE; combo = g_malloc0 (sizeof (MetaKeyCombo)); combo->keysym = keysym; combo->keycode = keycode; combo->modifiers = mods; binding->bindings = g_slist_prepend (binding->bindings, combo); meta_topic (META_DEBUG_KEYBINDINGS, "New keybinding for \"%s\" is keysym = 0x%x keycode = 0x%x mods = 0x%x\n", binding->name, keysym, keycode, mods); } return changed; }
void 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); return; } 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; if (!*((gboolean*)answer)) return; /* see above */ 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: *((MetaFrameType*)answer) = meta_window_get_frame_type (window); break; 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; case META_CORE_GET_THEME_VARIANT: *((char**)answer) = window->gtk_theme_variant; break; 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: meta_warning(_("Unknown window information request: %d"), request); } request = va_arg (args, MetaCoreGetType); } va_end (args); }
/** * This is where the story begins. It parses commandline options and * environment variables, sets up the screen, hands control off to * GTK, and cleans up afterwards. * * \param argc Number of arguments (as usual) * \param argv Array of arguments (as usual) * * \bug It's a bit long. It would be good to split it out into separate * functions. */ int main (int argc, char **argv) { struct sigaction act; sigset_t empty_mask; MetaArguments meta_args; const gchar *log_domains[] = { NULL, G_LOG_DOMAIN, "Gtk", "Gdk", "GLib", "Pango", "GLib-GObject", "GThread" }; guint i; GIOChannel *channel; if (setlocale (LC_ALL, "") == NULL) meta_warning ("Locale not understood by C library, internationalization will not work\n"); sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif if (pipe (sigterm_pipe_fds) != 0) g_printerr ("Failed to create SIGTERM pipe: %s\n", g_strerror (errno)); channel = g_io_channel_unix_new (sigterm_pipe_fds[0]); g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch (channel, G_IO_IN, (GIOFunc) on_sigterm, NULL); g_io_channel_set_close_on_unref (channel, TRUE); g_io_channel_unref (channel); act.sa_handler = &sigterm_handler; if (sigaction (SIGTERM, &act, NULL) < 0) g_printerr ("Failed to register SIGTERM handler: %s\n", g_strerror (errno)); if (g_getenv ("METACITY_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("METACITY_DEBUG")) meta_set_debugging (TRUE); if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); bindtextdomain (GETTEXT_PACKAGE, METACITY_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Parse command line arguments.*/ meta_parse_options (&argc, &argv, &meta_args); meta_set_syncing (meta_args.sync || (g_getenv ("METACITY_SYNC") != NULL)); if (meta_args.print_version) version (); meta_select_display (meta_args.display_name); if (meta_args.replace_wm) meta_set_replace_current_wm (TRUE); if (meta_args.save_file && meta_args.client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (&argc, &argv); /* must be after UI init so we can override GDK handlers */ meta_errors_init (); /* Load prefs */ meta_prefs_init (); meta_prefs_add_listener (prefs_changed_callback, NULL); #if 1 for (i=0; i<G_N_ELEMENTS(log_domains); i++) g_log_set_handler (log_domains[i], G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, log_handler, NULL); #endif if (g_getenv ("METACITY_G_FATAL_WARNINGS") != NULL) g_log_set_always_fatal (G_LOG_LEVEL_MASK); meta_ui_set_current_theme (meta_prefs_get_theme (), FALSE); /* Try to find some theme that'll work if the theme preference * doesn't exist. First try Simple (the default theme) then just * try anything in the themes directory. */ if (!meta_ui_have_a_theme ()) meta_ui_set_current_theme ("Simple", FALSE); if (!meta_ui_have_a_theme ()) { const char *dir_entry = NULL; GError *err = NULL; GDir *themes_dir = NULL; if (!(themes_dir = g_dir_open (METACITY_DATADIR"/themes", 0, &err))) { meta_fatal (_("Failed to scan themes directory: %s\n"), err->message); g_error_free (err); } else { while (((dir_entry = g_dir_read_name (themes_dir)) != NULL) && (!meta_ui_have_a_theme ())) { meta_ui_set_current_theme (dir_entry, FALSE); } g_dir_close (themes_dir); } } if (!meta_ui_have_a_theme ()) meta_fatal (_("Could not find a theme! Be sure %s exists and contains the usual themes.\n"), METACITY_DATADIR"/themes"); /* Connect to SM as late as possible - but before managing display, * or we might try to manage a window before we have the session * info */ if (!meta_args.disable_sm) { if (meta_args.client_id == NULL) { const gchar *desktop_autostart_id; desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID"); if (desktop_autostart_id != NULL) meta_args.client_id = g_strdup (desktop_autostart_id); } /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to * use the same client id. */ g_unsetenv ("DESKTOP_AUTOSTART_ID"); meta_session_init (meta_args.client_id, meta_args.save_file); } /* Free memory possibly allocated by the argument parsing which are * no longer needed. */ g_free (meta_args.save_file); g_free (meta_args.display_name); g_free (meta_args.client_id); if (meta_args.composite || meta_args.no_composite) meta_prefs_set_compositing_manager (meta_args.composite); if (meta_args.no_force_fullscreen) meta_prefs_set_force_fullscreen (FALSE); if (!meta_display_open ()) meta_exit (META_EXIT_ERROR); g_main_loop_run (meta_main_loop); meta_finalize (); if (meta_restart_after_quit) { GError *err; err = NULL; if (!g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &err)) { meta_fatal (_("Failed to restart: %s\n"), err->message); g_error_free (err); /* not reached anyhow */ meta_exit_code = META_EXIT_ERROR; } } return meta_exit_code; }
/** * meta_init: (skip) * * Initialize mutter. Call this after meta_get_option_context() and * meta_plugin_manager_set_plugin_type(), and before meta_run(). */ void meta_init (void) { struct sigaction act; sigset_t empty_mask; ClutterSettings *clutter_settings; sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif g_unix_signal_add (SIGTERM, on_sigterm, NULL); if (g_getenv ("MUTTER_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("MUTTER_DEBUG")) meta_set_debugging (TRUE); #if defined(CLUTTER_WINDOWING_EGL) && defined(HAVE_NATIVE_BACKEND) if (opt_display_server) clutter_set_windowing_backend (CLUTTER_WINDOWING_EGL); #endif meta_set_is_wayland_compositor (opt_wayland); if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); #ifdef HAVE_INTROSPECTION g_irepository_prepend_search_path (MUTTER_PKGLIBDIR); #endif if (meta_is_wayland_compositor ()) { /* NB: When running as a hybrid wayland compositor we run our own headless X * server so the user can't control the X display to connect too. */ meta_wayland_init (); } else meta_select_display (opt_display_name); meta_set_syncing (opt_sync || (g_getenv ("MUTTER_SYNC") != NULL)); if (opt_replace_wm) meta_set_replace_current_wm (TRUE); if (opt_save_file && opt_client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (); /* If we are running with wayland then we don't wait until we have * an X connection before initializing clutter we instead initialize * it earlier since we need to initialize the GL driver so the driver * can register any needed wayland extensions. */ if (!meta_is_wayland_compositor ()) { /* * Clutter can only be initialized after the UI. */ meta_clutter_init (); } meta_restart_init (); /* * XXX: We cannot handle high dpi scaling yet, so fix the scale to 1 * for now. */ clutter_settings = clutter_settings_get_default (); g_object_set (clutter_settings, "window-scaling-factor", 1, NULL); }
static gboolean meta_display_handle_event (MetaDisplay *display, const ClutterEvent *event) { MetaWindow *window; gboolean bypass_clutter = FALSE; G_GNUC_UNUSED gboolean bypass_wayland = FALSE; MetaGestureTracker *tracker; ClutterEventSequence *sequence; ClutterInputDevice *source; sequence = clutter_event_get_event_sequence (event); /* Set the pointer emulating sequence on touch begin, if eligible */ if (event->type == CLUTTER_TOUCH_BEGIN) { if (sequence_is_pointer_emulated (display, event)) { /* This is the new pointer emulating sequence */ display->pointer_emulating_sequence = sequence; } else if (display->pointer_emulating_sequence == sequence) { /* This sequence was "pointer emulating" in a prior incarnation, * but now it isn't. We unset the pointer emulating sequence at * this point so the current sequence is not mistaken as pointer * emulating, while we've ensured that it's been deemed * "pointer emulating" throughout all of the event processing * of the previous incarnation. */ display->pointer_emulating_sequence = NULL; } } #ifdef HAVE_WAYLAND MetaWaylandCompositor *compositor = NULL; if (meta_is_wayland_compositor ()) { compositor = meta_wayland_compositor_get_default (); meta_wayland_compositor_update (compositor, event); } #endif if (!display->current_pad_osd && (event->type == CLUTTER_PAD_BUTTON_PRESS || event->type == CLUTTER_PAD_BUTTON_RELEASE)) { MetaBackend *backend = meta_get_backend (); if (meta_input_settings_handle_pad_button (meta_backend_get_input_settings (backend), clutter_event_get_source_device (event), event->type == CLUTTER_PAD_BUTTON_PRESS, event->pad_button.button)) { bypass_wayland = bypass_clutter = TRUE; goto out; } } source = clutter_event_get_source_device (event); if (source) { meta_backend_update_last_device (meta_get_backend (), clutter_input_device_get_device_id (source)); } #ifdef HAVE_WAYLAND if (meta_is_wayland_compositor () && event->type == CLUTTER_MOTION) { MetaWaylandCompositor *compositor; compositor = meta_wayland_compositor_get_default (); if (meta_wayland_tablet_manager_consumes_event (compositor->tablet_manager, event)) { meta_wayland_tablet_manager_update_cursor_position (compositor->tablet_manager, event); } else { MetaCursorTracker *tracker = meta_cursor_tracker_get_for_screen (NULL); meta_cursor_tracker_update_position (tracker, event->motion.x, event->motion.y); } display->monitor_cache_invalidated = TRUE; } #endif handle_idletime_for_event (event); window = get_window_for_event (display, event); display->current_time = event->any.time; if (window && !window->override_redirect && (event->type == CLUTTER_KEY_PRESS || event->type == CLUTTER_BUTTON_PRESS || event->type == CLUTTER_TOUCH_BEGIN)) { if (CurrentTime == display->current_time) { /* We can't use missing (i.e. invalid) timestamps to set user time, * nor do we want to use them to sanity check other timestamps. * See bug 313490 for more details. */ meta_warning ("Event has no timestamp! You may be using a broken " "program such as xse. Please ask the authors of that " "program to fix it.\n"); } else { meta_window_set_user_time (window, display->current_time); meta_display_sanity_check_timestamps (display, display->current_time); } } tracker = meta_display_get_gesture_tracker (display); if (meta_gesture_tracker_handle_event (tracker, event)) { bypass_wayland = bypass_clutter = TRUE; goto out; } if (display->event_route == META_EVENT_ROUTE_WINDOW_OP) { if (meta_window_handle_mouse_grab_op_event (window, event)) { bypass_clutter = TRUE; bypass_wayland = TRUE; goto out; } } /* For key events, it's important to enforce single-handling, or * we can get into a confused state. So if a keybinding is * handled (because it's one of our hot-keys, or because we are * in a keyboard-grabbed mode like moving a window, we don't * want to pass the key event to the compositor or Wayland at all. */ if (meta_keybindings_process_event (display, window, event)) { bypass_clutter = TRUE; bypass_wayland = TRUE; goto out; } /* Do not pass keyboard events to Wayland if key focus is not on the * stage in normal mode (e.g. during keynav in the panel) */ if (display->event_route == META_EVENT_ROUTE_NORMAL) { if (IS_KEY_EVENT (event) && !stage_has_key_focus ()) { bypass_wayland = TRUE; goto out; } } if (display->current_pad_osd) { bypass_wayland = TRUE; goto out; } if (window) { /* Events that are likely to trigger compositor gestures should * be known to clutter so they can propagate along the hierarchy. * Gesture-wise, there's two groups of events we should be getting * here: * - CLUTTER_TOUCH_* with a touch sequence that's not yet accepted * by the gesture tracker, these might trigger gesture actions * into recognition. Already accepted touch sequences are handled * directly by meta_gesture_tracker_handle_event(). * - CLUTTER_TOUCHPAD_* events over windows. These can likewise * trigger ::captured-event handlers along the way. */ bypass_clutter = !IS_GESTURE_EVENT (event); meta_window_handle_ungrabbed_event (window, event); /* This might start a grab op. If it does, then filter out the * event, and if it doesn't, replay the event to release our * own sync grab. */ if (display->event_route == META_EVENT_ROUTE_WINDOW_OP || display->event_route == META_EVENT_ROUTE_FRAME_BUTTON) { bypass_clutter = TRUE; bypass_wayland = TRUE; } else { /* Only replay button press events, since that's where we * have the synchronous grab. */ if (event->type == CLUTTER_BUTTON_PRESS) { MetaBackend *backend = meta_get_backend (); if (META_IS_BACKEND_X11 (backend)) { Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); meta_verbose ("Allowing events time %u\n", (unsigned int)event->button.time); XIAllowEvents (xdisplay, clutter_event_get_device_id (event), XIReplayDevice, event->button.time); } } } goto out; } out: /* If the compositor has a grab, don't pass that through to Wayland */ if (display->event_route == META_EVENT_ROUTE_COMPOSITOR_GRAB) bypass_wayland = TRUE; /* If a Wayland client has a grab, don't pass that through to Clutter */ if (display->event_route == META_EVENT_ROUTE_WAYLAND_POPUP) bypass_clutter = TRUE; #ifdef HAVE_WAYLAND if (compositor && !bypass_wayland) { if (meta_wayland_compositor_handle_event (compositor, event)) bypass_clutter = TRUE; } #endif display->current_time = CurrentTime; return bypass_clutter; }
static gboolean validate_or_free_results (GetPropertyResults *results, int expected_format, Atom expected_type, gboolean must_have_items) { char *type_name; char *expected_name; char *prop_name; const char *title; const char *res_class; const char *res_name; MetaWindow *w; if (expected_format == results->format && expected_type == results->type && (!must_have_items || results->n_items > 0)) return TRUE; meta_error_trap_push (results->display); type_name = XGetAtomName (results->display->xdisplay, results->type); expected_name = XGetAtomName (results->display->xdisplay, expected_type); prop_name = XGetAtomName (results->display->xdisplay, results->xatom); meta_error_trap_pop (results->display, TRUE); w = meta_display_lookup_x_window (results->display, results->xwindow); if (w != NULL) { title = w->title; res_class = w->res_class; res_name = w->res_name; } else { title = NULL; res_class = NULL; res_name = NULL; } if (title == NULL) title = "unknown"; if (res_class == NULL) res_class = "unknown"; if (res_name == NULL) res_name = "unknown"; meta_warning (_("Window 0x%lx has property %s\nthat was expected to have type %s format %d\nand actually has type %s format %d n_items %d.\nThis is most likely an application bug, not a window manager bug.\nThe window has title=\"%s\" class=\"%s\" name=\"%s\"\n"), results->xwindow, prop_name ? prop_name : "(bad atom)", expected_name ? expected_name : "(bad atom)", expected_format, type_name ? type_name : "(bad atom)", results->format, (int) results->n_items, title, res_class, res_name); if (type_name) XFree (type_name); if (expected_name) XFree (expected_name); if (prop_name) XFree (prop_name); if (results->prop) { XFree (results->prop); results->prop = NULL; } return FALSE; }
/** * meta_init: (skip) * * Initialize muffin. Call this after meta_get_option_context() and * meta_plugin_manager_set_plugin_type(), and before meta_run(). */ void meta_init (void) { struct sigaction act; sigset_t empty_mask; GIOChannel *channel; sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif if (pipe (sigterm_pipe_fds) != 0) g_printerr ("Failed to create SIGTERM pipe: %s\n", g_strerror (errno)); channel = g_io_channel_unix_new (sigterm_pipe_fds[0]); g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch (channel, G_IO_IN, (GIOFunc) on_sigterm, NULL); g_io_channel_set_close_on_unref (channel, TRUE); g_io_channel_unref (channel); act.sa_handler = &sigterm_handler; if (sigaction (SIGTERM, &act, NULL) < 0) g_printerr ("Failed to register SIGTERM handler: %s\n", g_strerror (errno)); if (g_getenv ("MUFFIN_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("MUFFIN_DEBUG")) meta_set_debugging (TRUE); if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); #ifdef HAVE_INTROSPECTION g_irepository_prepend_search_path (MUFFIN_PKGLIBDIR); #endif meta_set_syncing (opt_sync || (g_getenv ("MUFFIN_SYNC") != NULL)); meta_select_display (opt_display_name); if (opt_replace_wm) meta_set_replace_current_wm (TRUE); if (opt_save_file && opt_client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (); /* * Clutter can only be initialized after the UI. */ meta_clutter_init (); const char *renderer = (const char *) glGetString (GL_RENDERER); if (strstr (renderer, "llvmpipe") || strstr (renderer, "Rasterizer") || strstr (renderer, "softpipe")) { /* Clutter envs not set, since they won't work after Clutter init */ g_setenv ("CINNAMON_SOFTWARE_RENDERING", "1", FALSE); g_setenv ("CINNAMON_SLOWDOWN_FACTOR", "0.0001", FALSE); g_setenv ("MUFFIN_NO_SHADOWS", "1", FALSE); meta_warning ("Software rendering detected: %s\n", renderer); } }
/* this one freakishly returns g_malloc memory */ static gboolean utf8_list_from_results (GetPropertyResults *results, char ***str_p, int *n_str_p) { int i; int n_strings; char **retval; const char *p; *str_p = NULL; *n_str_p = 0; if (!validate_or_free_results (results, 8, results->display->atom_UTF8_STRING, FALSE)) return FALSE; /* I'm not sure this is right, but I'm guessing the * property is nul-separated */ i = 0; n_strings = 0; while (i < (int) results->n_items) { if (results->prop[i] == '\0') ++n_strings; ++i; } if (results->prop[results->n_items - 1] != '\0') ++n_strings; /* we're guaranteed that results->prop has a nul on the end * by XGetWindowProperty */ retval = g_new0 (char*, n_strings + 1); p = (char *)results->prop; i = 0; while (i < n_strings) { if (!g_utf8_validate (p, -1, NULL)) { char *name; meta_error_trap_push (results->display); name = XGetAtomName (results->display->xdisplay, results->xatom); meta_error_trap_pop (results->display, TRUE); meta_warning (_("Property %s on window 0x%lx contained invalid UTF-8 for item %d in the list\n"), name, results->xwindow, i); meta_XFree (name); meta_XFree (results->prop); results->prop = NULL; g_strfreev (retval); return FALSE; } retval[i] = g_strdup (p); p = p + strlen (p) + 1; ++i; } *str_p = retval; *n_str_p = i; meta_XFree (results->prop); results->prop = NULL; return TRUE; }
void 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); return; } 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; if (!*((gboolean*)answer)) return; /* see above */ 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_IS_TITLEBAR_ONSCREEN: *((gboolean*)answer) = meta_window_titlebar_is_onscreen (window); 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: { MetaFrameType base_type = META_FRAME_TYPE_LAST; switch (window->type) { case META_WINDOW_NORMAL: base_type = META_FRAME_TYPE_NORMAL; break; case META_WINDOW_DIALOG: base_type = META_FRAME_TYPE_DIALOG; break; case META_WINDOW_MODAL_DIALOG: base_type = META_FRAME_TYPE_MODAL_DIALOG; break; case META_WINDOW_MENU: base_type = META_FRAME_TYPE_MENU; break; case META_WINDOW_UTILITY: base_type = META_FRAME_TYPE_UTILITY; break; case META_WINDOW_DESKTOP: case META_WINDOW_DOCK: case META_WINDOW_TOOLBAR: case META_WINDOW_SPLASHSCREEN: /* No frame */ base_type = META_FRAME_TYPE_LAST; break; } if (base_type == META_FRAME_TYPE_LAST) { /* can't add border if undecorated */ *((MetaFrameType*)answer) = META_FRAME_TYPE_LAST; } else if (window->border_only) { /* override base frame type */ *((MetaFrameType*)answer) = META_FRAME_TYPE_BORDER; } else { *((MetaFrameType*)answer) = base_type; } break; } 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; 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: meta_warning(_("Unknown window information request: %d"), request); } request = va_arg (args, MetaCoreGetType); } va_end (args); }
/** * meta_init: (skip) * * Initialize muffin. Call this after meta_get_option_context() and * meta_plugin_type_register(), and before meta_run(). */ void meta_init (void) { struct sigaction act; sigset_t empty_mask; GIOChannel *channel; g_type_init (); sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; act.sa_flags = 0; if (sigaction (SIGPIPE, &act, NULL) < 0) g_printerr ("Failed to register SIGPIPE handler: %s\n", g_strerror (errno)); #ifdef SIGXFSZ if (sigaction (SIGXFSZ, &act, NULL) < 0) g_printerr ("Failed to register SIGXFSZ handler: %s\n", g_strerror (errno)); #endif if (pipe (sigterm_pipe_fds) != 0) g_printerr ("Failed to create SIGTERM pipe: %s\n", g_strerror (errno)); channel = g_io_channel_unix_new (sigterm_pipe_fds[0]); g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch (channel, G_IO_IN, (GIOFunc) on_sigterm, NULL); g_io_channel_set_close_on_unref (channel, TRUE); g_io_channel_unref (channel); act.sa_handler = &sigterm_handler; if (sigaction (SIGTERM, &act, NULL) < 0) g_printerr ("Failed to register SIGTERM handler: %s\n", g_strerror (errno)); if (g_getenv ("MUFFIN_VERBOSE")) meta_set_verbose (TRUE); if (g_getenv ("MUFFIN_DEBUG")) meta_set_debugging (TRUE); if (g_get_home_dir ()) if (chdir (g_get_home_dir ()) < 0) meta_warning ("Could not change to home directory %s.\n", g_get_home_dir ()); meta_print_self_identity (); #ifdef HAVE_INTROSPECTION g_irepository_prepend_search_path (MUFFIN_PKGLIBDIR); #endif meta_set_syncing (opt_sync || (g_getenv ("MUFFIN_SYNC") != NULL)); meta_select_display (opt_display_name); if (opt_replace_wm) meta_set_replace_current_wm (TRUE); if (opt_save_file && opt_client_id) meta_fatal ("Can't specify both SM save file and SM client id\n"); meta_main_loop = g_main_loop_new (NULL, FALSE); meta_ui_init (); /* * Clutter can only be initialized after the UI. */ meta_clutter_init (); }
static void ensure_work_areas_validated (MetaWorkspace *workspace) { GList *windows; GList *tmp; MetaRectangle work_area; int i; /* C89 absolutely sucks... */ if (!workspace->work_areas_invalid) return; g_assert (workspace->all_struts == NULL); g_assert (workspace->monitor_region == NULL); g_assert (workspace->screen_region == NULL); g_assert (workspace->screen_edges == NULL); g_assert (workspace->monitor_edges == NULL); /* STEP 1: Get the list of struts */ workspace->all_struts = copy_strut_list (workspace->builtin_struts); windows = meta_workspace_list_windows (workspace); for (tmp = windows; tmp != NULL; tmp = tmp->next) { MetaWindow *win = tmp->data; GSList *s_iter; for (s_iter = win->struts; s_iter != NULL; s_iter = s_iter->next) { workspace->all_struts = g_slist_prepend (workspace->all_struts, copy_strut(s_iter->data)); } } g_list_free (windows); /* STEP 2: Get the maximal/spanning rects for the onscreen and * on-single-monitor regions */ g_assert (workspace->monitor_region == NULL); g_assert (workspace->screen_region == NULL); workspace->monitor_region = g_new (GList*, workspace->screen->n_monitor_infos); for (i = 0; i < workspace->screen->n_monitor_infos; i++) { workspace->monitor_region[i] = meta_rectangle_get_minimal_spanning_set_for_region ( &workspace->screen->monitor_infos[i].rect, workspace->all_struts); } workspace->screen_region = meta_rectangle_get_minimal_spanning_set_for_region ( &workspace->screen->rect, workspace->all_struts); /* STEP 3: Get the work areas (region-to-maximize-to) for the screen and * monitors. */ work_area = workspace->screen->rect; /* start with the screen */ if (workspace->screen_region == NULL) work_area = meta_rect (0, 0, -1, -1); else meta_rectangle_clip_to_region (workspace->screen_region, FIXED_DIRECTION_NONE, &work_area); /* Lots of paranoia checks, forcing work_area_screen to be sane */ #define MIN_SANE_AREA 100 if (work_area.width < MIN_SANE_AREA) { meta_warning ("struts occupy an unusually large percentage of the screen; " "available remaining width = %d < %d", work_area.width, MIN_SANE_AREA); if (work_area.width < 1) { work_area.x = (workspace->screen->rect.width - MIN_SANE_AREA)/2; work_area.width = MIN_SANE_AREA; } else { int amount = (MIN_SANE_AREA - work_area.width)/2; work_area.x -= amount; work_area.width += 2*amount; } } if (work_area.height < MIN_SANE_AREA) { meta_warning ("struts occupy an unusually large percentage of the screen; " "available remaining height = %d < %d", work_area.height, MIN_SANE_AREA); if (work_area.height < 1) { work_area.y = (workspace->screen->rect.height - MIN_SANE_AREA)/2; work_area.height = MIN_SANE_AREA; } else { int amount = (MIN_SANE_AREA - work_area.height)/2; work_area.y -= amount; work_area.height += 2*amount; } } workspace->work_area_screen = work_area; meta_topic (META_DEBUG_WORKAREA, "Computed work area for workspace %d: %d,%d %d x %d\n", meta_workspace_index (workspace), workspace->work_area_screen.x, workspace->work_area_screen.y, workspace->work_area_screen.width, workspace->work_area_screen.height); /* Now find the work areas for each monitor */ g_free (workspace->work_area_monitor); workspace->work_area_monitor = g_new (MetaRectangle, workspace->screen->n_monitor_infos); for (i = 0; i < workspace->screen->n_monitor_infos; i++) { work_area = workspace->screen->monitor_infos[i].rect; if (workspace->monitor_region[i] == NULL) /* FIXME: constraints.c untested with this, but it might be nice for * a screen reader or magnifier. */ work_area = meta_rect (work_area.x, work_area.y, -1, -1); else meta_rectangle_clip_to_region (workspace->monitor_region[i], FIXED_DIRECTION_NONE, &work_area); workspace->work_area_monitor[i] = work_area; meta_topic (META_DEBUG_WORKAREA, "Computed work area for workspace %d " "monitor %d: %d,%d %d x %d\n", meta_workspace_index (workspace), i, workspace->work_area_monitor[i].x, workspace->work_area_monitor[i].y, workspace->work_area_monitor[i].width, workspace->work_area_monitor[i].height); } /* STEP 4: Make sure the screen_region is nonempty (separate from step 2 * since it relies on step 3). */ if (workspace->screen_region == NULL) { MetaRectangle *nonempty_region; nonempty_region = g_new (MetaRectangle, 1); *nonempty_region = workspace->work_area_screen; workspace->screen_region = g_list_prepend (NULL, nonempty_region); } /* STEP 5: Cache screen and monitor edges for edge resistance and snapping */ g_assert (workspace->screen_edges == NULL); g_assert (workspace->monitor_edges == NULL); workspace->screen_edges = meta_rectangle_find_onscreen_edges (&workspace->screen->rect, workspace->all_struts); tmp = NULL; for (i = 0; i < workspace->screen->n_monitor_infos; i++) tmp = g_list_prepend (tmp, &workspace->screen->monitor_infos[i].rect); workspace->monitor_edges = meta_rectangle_find_nonintersected_monitor_edges (tmp, workspace->all_struts); g_list_free (tmp); /* We're all done, YAAY! Record that everything has been validated. */ workspace->work_areas_invalid = FALSE; { /* * Notify the compositor that the workspace geometry has changed. */ MetaScreen *screen = workspace->screen; MetaDisplay *display = meta_screen_get_display (screen); MetaCompositor *comp = meta_display_get_compositor (display); if (comp) meta_compositor_update_workspace_geometry (comp, workspace); } }
static void make_shadow (MetaShadow *shadow, cairo_region_t *region) { ClutterBackend *backend = clutter_get_default_backend (); CoglContext *ctx = clutter_backend_get_cogl_context (backend); CoglError *error = NULL; int d = get_box_filter_size (shadow->key.radius); int spread = get_shadow_spread (shadow->key.radius); cairo_rectangle_int_t extents; cairo_region_t *row_convolve_region; cairo_region_t *column_convolve_region; guchar *buffer; int buffer_width; int buffer_height; int x_offset; int y_offset; int n_rectangles, j, k; cairo_region_get_extents (region, &extents); /* In the case where top_fade >= 0 and the portion above the top * edge of the shape will be cropped, it seems like we could create * a smaller buffer and omit the top portion, but actually, in our * multi-pass blur algorithm, the blur into the area above the window * in the first pass will contribute back to the final pixel values * for the top pixels, so we create a buffer as if we weren't cropping * and only crop when creating the CoglTexture. */ buffer_width = extents.width + 2 * spread; buffer_height = extents.height + 2 * spread; /* Round up so we have aligned rows/columns */ buffer_width = (buffer_width + 3) & ~3; buffer_height = (buffer_height + 3) & ~3; /* Square buffer allows in-place swaps, which are roughly 70% faster, but we * don't want to over-allocate too much memory. */ if (buffer_height < buffer_width && buffer_height > (3 * buffer_width) / 4) buffer_height = buffer_width; if (buffer_width < buffer_height && buffer_width > (3 * buffer_height) / 4) buffer_width = buffer_height; buffer = g_malloc0 (buffer_width * buffer_height); /* Blurring with multiple box-blur passes is fast, but (especially for * large shadow sizes) we can improve efficiency by restricting the blur * to the region that actually needs to be blurred. */ row_convolve_region = meta_make_border_region (region, spread, spread, FALSE); column_convolve_region = meta_make_border_region (region, 0, spread, TRUE); /* Offsets between coordinates of the regions and coordinates in the buffer */ x_offset = spread; y_offset = spread; /* Step 1: unblurred image */ n_rectangles = cairo_region_num_rectangles (region); for (k = 0; k < n_rectangles; k++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (region, k, &rect); for (j = y_offset + rect.y; j < y_offset + rect.y + rect.height; j++) memset (buffer + buffer_width * j + x_offset + rect.x, 255, rect.width); } /* Step 2: swap rows and columns */ buffer = flip_buffer (buffer, buffer_width, buffer_height); /* Step 3: blur rows (really columns) */ blur_rows (column_convolve_region, y_offset, x_offset, buffer, buffer_height, buffer_width, d); /* Step 4: swap rows and columns */ buffer = flip_buffer (buffer, buffer_height, buffer_width); /* Step 5: blur rows */ blur_rows (row_convolve_region, x_offset, y_offset, buffer, buffer_width, buffer_height, d); /* Step 6: fade out the top, if applicable */ if (shadow->key.top_fade >= 0) { for (j = y_offset; j < y_offset + MIN (shadow->key.top_fade, extents.height + shadow->outer_border_bottom); j++) fade_bytes(buffer + j * buffer_width, buffer_width, j - y_offset, shadow->key.top_fade); } /* We offset the passed in pixels to crop off the extra area we allocated at the top * in the case of top_fade >= 0. We also account for padding at the left for symmetry * though that doesn't currently occur. */ shadow->texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, shadow->outer_border_left + extents.width + shadow->outer_border_right, shadow->outer_border_top + extents.height + shadow->outer_border_bottom, COGL_PIXEL_FORMAT_A_8, buffer_width, (buffer + (y_offset - shadow->outer_border_top) * buffer_width + (x_offset - shadow->outer_border_left)), &error)); if (error) { meta_warning ("Failed to allocate shadow texture: %s\n", error->message); cogl_error_free (error); } cairo_region_destroy (row_convolve_region); cairo_region_destroy (column_convolve_region); g_free (buffer); shadow->pipeline = meta_create_texture_pipeline (shadow->texture); }