Permalink
Browse files

Do not use the default stage

  • Loading branch information...
1 parent e7cb88e commit c1f7191429ccd5f88f413b5cf27bb326b71bdd9e @magcius magcius committed with rat4 Nov 21, 2011
Showing with 271 additions and 261 deletions.
  1. +1 −1 js/ui/magnifier.js
  2. +248 −0 src/cinnamon-global.c
  3. +1 −1 src/cinnamon-plugin.c
  4. +17 −7 src/cinnamon-xfixes-cursor.c
  5. +1 −1 src/cinnamon-xfixes-cursor.h
  6. +0 −249 src/main.c
  7. +1 −1 src/st/test-theme.c
  8. +2 −1 src/test-recorder.c
View
@@ -61,7 +61,7 @@ Magnifier.prototype = {
this._zoomRegions = [];
// Create small clutter tree for the magnified mouse.
- let xfixesCursor = Cinnamon.XFixesCursor.get_default();
+ let xfixesCursor = Cinnamon.XFixesCursor.get_for_stage(global.stage);
this._mouseSprite = new Clutter.Texture();
xfixesCursor.update_texture_image(this._mouseSprite);
this._cursorRoot = new Clutter.Group();
View
@@ -15,6 +15,7 @@
#endif
#include <X11/extensions/Xfixes.h>
+#include <cogl-pango/cogl-pango.h>
#include <canberra.h>
#include <clutter/glx/clutter-glx.h>
#include <clutter/x11/clutter-x11.h>
@@ -803,6 +804,249 @@ global_stage_after_paint (ClutterStage *stage,
"clutter.stagePaintDone");
}
+static void
+constrain_tooltip (StTooltip *tooltip,
+ const ClutterGeometry *geometry,
+ ClutterGeometry *adjusted_geometry,
+ gpointer data)
+{
+ const ClutterGeometry *tip_area = st_tooltip_get_tip_area (tooltip);
+ CinnamonGlobal *global = cinnamon_global_get ();
+ MetaScreen *screen = cinnamon_global_get_screen (global);
+ int n_monitors = meta_screen_get_n_monitors (screen);
+ int i;
+
+ *adjusted_geometry = *geometry;
+
+ /* A point that determines what screen we'll constrain to */
+ int x = tip_area->x + tip_area->width / 2;
+ int y = tip_area->y + tip_area->height / 2;
+
+ for (i = 0; i < n_monitors; i++)
+ {
+ MetaRectangle rect;
+ meta_screen_get_monitor_geometry (screen, i, &rect);
+ if (x >= rect.x && x < rect.x + rect.width &&
+ y >= rect.y && y < rect.y + rect.height)
+ {
+ if (adjusted_geometry->x + adjusted_geometry->width > rect.x + rect.width)
+ adjusted_geometry->x = rect.x + rect.width - adjusted_geometry->width;
+ if (adjusted_geometry->x < rect.x)
+ adjusted_geometry->x = rect.x;
+
+ if (adjusted_geometry->y + adjusted_geometry->height > rect.y + rect.height)
+ adjusted_geometry->y = rect.y + rect.height - adjusted_geometry->height;
+ if (adjusted_geometry->y < rect.y)
+ adjusted_geometry->y = rect.y;
+
+ return;
+ }
+ }
+}
+
+static void
+update_font_options (GtkSettings *settings,
+ ClutterStage *stage)
+{
+ StThemeContext *context;
+ ClutterBackend *backend;
+ gint dpi;
+ gint hinting;
+ gchar *hint_style_str;
+ cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
+ gint antialias;
+ cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_NONE;
+ cairo_font_options_t *options;
+
+ g_object_get (settings,
+ "gtk-xft-dpi", &dpi,
+ "gtk-xft-antialias", &antialias,
+ "gtk-xft-hinting", &hinting,
+ "gtk-xft-hintstyle", &hint_style_str,
+ NULL);
+
+ context = st_theme_context_get_for_stage (stage);
+
+ if (dpi != -1)
+ /* GTK stores resolution as 1024 * dots/inch */
+ st_theme_context_set_resolution (context, dpi / 1024);
+ else
+ st_theme_context_set_default_resolution (context);
+
+ st_tooltip_set_constrain_func (stage, constrain_tooltip, NULL, NULL);
+
+ /* Clutter (as of 0.9) passes comprehensively wrong font options
+ * override whatever set_font_flags() did above.
+ *
+ * http://bugzilla.openedhand.com/show_bug.cgi?id=1456
+ */
+ backend = clutter_get_default_backend ();
+ options = cairo_font_options_create ();
+
+ cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
+
+ if (hinting >= 0 && !hinting)
+ {
+ hint_style = CAIRO_HINT_STYLE_NONE;
+ }
+ else if (hint_style_str)
+ {
+ if (strcmp (hint_style_str, "hintnone") == 0)
+ hint_style = CAIRO_HINT_STYLE_NONE;
+ else if (strcmp (hint_style_str, "hintslight") == 0)
+ hint_style = CAIRO_HINT_STYLE_SLIGHT;
+ else if (strcmp (hint_style_str, "hintmedium") == 0)
+ hint_style = CAIRO_HINT_STYLE_MEDIUM;
+ else if (strcmp (hint_style_str, "hintfull") == 0)
+ hint_style = CAIRO_HINT_STYLE_FULL;
+ }
+
+ g_free (hint_style_str);
+
+ cairo_font_options_set_hint_style (options, hint_style);
+
+ /* We don't want to turn on subpixel anti-aliasing; since Clutter
+ * doesn't currently have the code to support ARGB masks,
+ * generating them then squashing them back to A8 is pointless.
+ */
+ antialias_mode = (antialias < 0 || antialias) ? CAIRO_ANTIALIAS_GRAY
+ : CAIRO_ANTIALIAS_NONE;
+
+ cairo_font_options_set_antialias (options, antialias_mode);
+
+ clutter_backend_set_font_options (backend, options);
+ cairo_font_options_destroy (options);
+}
+
+static void
+settings_notify_cb (GtkSettings *settings,
+ GParamSpec *pspec,
+ gpointer data)
+{
+ update_font_options (settings, CLUTTER_STAGE (data));
+}
+
+static void
+cinnamon_fonts_init (ClutterStage *stage)
+{
+ GtkSettings *settings;
+ CoglPangoFontMap *fontmap;
+
+ /* Disable text mipmapping; it causes problems on pre-GEM Intel
+ * drivers and we should just be rendering text at the right
+ * size rather than scaling it. If we do effects where we dynamically
+ * zoom labels, then we might want to reconsider.
+ */
+ fontmap = COGL_PANGO_FONT_MAP (clutter_get_font_map ());
+ cogl_pango_font_map_set_use_mipmapping (fontmap, FALSE);
+
+ settings = gtk_settings_get_default ();
+ g_object_connect (settings,
+ "signal::notify::gtk-xft-dpi",
+ G_CALLBACK (settings_notify_cb), stage,
+ "signal::notify::gtk-xft-antialias",
+ G_CALLBACK (settings_notify_cb), stage,
+ "signal::notify::gtk-xft-hinting",
+ G_CALLBACK (settings_notify_cb), stage,
+ "signal::notify::gtk-xft-hintstyle",
+ G_CALLBACK (settings_notify_cb), stage,
+ NULL);
+ update_font_options (settings, stage);
+}
+
+/* This is an IBus workaround. The flow of events with IBus is that every time
+ * it gets gets a key event, it:
+ *
+ * Sends it to the daemon via D-Bus asynchronously
+ * When it gets an reply, synthesizes a new GdkEvent and puts it into the
+ * GDK event queue with gdk_event_put(), including
+ * IBUS_FORWARD_MASK = 1 << 25 in the state to prevent a loop.
+ *
+ * (Normally, IBus uses the GTK+ key snooper mechanism to get the key
+ * events early, but since our key events aren't visible to GTK+ key snoopers,
+ * IBus will instead get the events via the standard
+ * GtkIMContext.filter_keypress() mechanism.)
+ *
+ * There are a number of potential problems here; probably the worst
+ * problem is that IBus doesn't forward the timestamp with the event
+ * so that every key event that gets delivered ends up with
+ * GDK_CURRENT_TIME. This creates some very subtle bugs; for example
+ * if you have IBus running and a keystroke is used to trigger
+ * launching an application, focus stealing prevention won't work
+ * right. http://code.google.com/p/ibus/issues/detail?id=1184
+ *
+ * In any case, our normal flow of key events is:
+ *
+ * GDK filter function => clutter_x11_handle_event => clutter actor
+ *
+ * So, if we see a key event that gets delivered via the GDK event handler
+ * function - then we know it must be one of these synthesized events, and
+ * we should push it back to clutter.
+ *
+ * To summarize, the full key event flow with IBus is:
+ *
+ * GDK filter function
+ * => Mutter
+ * => gnome_cinnamon_plugin_xevent_filter()
+ * => clutter_x11_handle_event()
+ * => clutter event delivery to actor
+ * => gtk_im_context_filter_event()
+ * => sent to IBus daemon
+ * => response received from IBus daemon
+ * => gdk_event_put()
+ * => GDK event handler
+ * => <this function>
+ * => clutter_event_put()
+ * => clutter event delivery to actor
+ *
+ * Anything else we see here we just pass on to the normal GDK event handler
+ * gtk_main_do_event().
+ */
+static void
+gnome_cinnamon_gdk_event_handler (GdkEvent *event_gdk,
+ gpointer data)
+{
+ if (event_gdk->type == GDK_KEY_PRESS || event_gdk->type == GDK_KEY_RELEASE)
+ {
+ ClutterActor *stage;
+ Window stage_xwindow;
+
+ stage = CLUTTER_ACTOR (data);
+ stage_xwindow = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
+
+ if (GDK_WINDOW_XID (event_gdk->key.window) == stage_xwindow)
+ {
+ ClutterDeviceManager *device_manager = clutter_device_manager_get_default ();
+ ClutterInputDevice *keyboard = clutter_device_manager_get_core_device (device_manager,
+ CLUTTER_KEYBOARD_DEVICE);
+
+ ClutterEvent *event_clutter = clutter_event_new ((event_gdk->type == GDK_KEY_PRESS) ?
+ CLUTTER_KEY_PRESS : CLUTTER_KEY_RELEASE);
+ event_clutter->key.time = event_gdk->key.time;
+ event_clutter->key.flags = CLUTTER_EVENT_NONE;
+ event_clutter->key.stage = CLUTTER_STAGE (stage);
+ event_clutter->key.source = NULL;
+
+ /* This depends on ClutterModifierType and GdkModifierType being
+ * identical, which they are currently. (They both match the X
+ * modifier state in the low 16-bits and have the same extensions.) */
+ event_clutter->key.modifier_state = event_gdk->key.state;
+
+ event_clutter->key.keyval = event_gdk->key.keyval;
+ event_clutter->key.hardware_keycode = event_gdk->key.hardware_keycode;
+ event_clutter->key.unicode_value = gdk_keyval_to_unicode (event_clutter->key.keyval);
+ event_clutter->key.device = keyboard;
+
+ clutter_event_put (event_clutter);
+ clutter_event_free (event_clutter);
+
+ return;
+ }
+ }
+
+ gtk_main_do_event (event_gdk);
+}
+
void
_cinnamon_global_set_plugin (CinnamonGlobal *global,
MetaPlugin *plugin)
@@ -848,6 +1092,10 @@ _cinnamon_global_set_plugin (CinnamonGlobal *global,
g_signal_connect (global->meta_display, "notify::focus-window",
G_CALLBACK (focus_window_changed), global);
+ cinnamon_fonts_init (global->stage);
+
+ gdk_event_handler_set (gnome_cinnamon_gdk_event_handler, global->stage, NULL);
+
global->focus_manager = st_focus_manager_get_for_stage (global->stage);
}
@@ -336,7 +336,7 @@ gnome_cinnamon_plugin_xevent_filter (MetaPlugin *plugin,
#endif
if ((xev->xany.type == EnterNotify || xev->xany.type == LeaveNotify)
- && xev->xcrossing.window == clutter_x11_get_stage_window (CLUTTER_STAGE (clutter_stage_get_default ())))
+ && xev->xcrossing.window == clutter_x11_get_stage_window (CLUTTER_STAGE (meta_plugin_get_stage (plugin))))
{
/* If the pointer enters a child of the stage window (eg, a
* trayicon), we want to consider it to still be in the stage,
@@ -321,19 +321,29 @@ cinnamon_xfixes_cursor_class_init (CinnamonXFixesCursorClass *klass)
}
/**
- * cinnamon_xfixes_cursor_get_default:
+ * cinnamon_xfixes_cursor_get_for_stage:
+ * @stage: (transfer none): The #ClutterStage to get the cursor for
*
- * Return value: (transfer none): The global #CinnamonXFixesCursor singleton
+ * Return value: (transfer none): A #CinnamonXFixesCursor instance
*/
CinnamonXFixesCursor *
-cinnamon_xfixes_cursor_get_default ()
+cinnamon_xfixes_cursor_get_for_stage (ClutterStage *stage)
{
- static CinnamonXFixesCursor *instance = NULL;
+ CinnamonXFixesCursor *instance;
+ static GQuark xfixes_cursor_quark;
+
+ if (G_UNLIKELY (xfixes_cursor_quark == 0))
+ xfixes_cursor_quark = g_quark_from_static_string ("cinnamon-xfixes-cursor");
+
+ instance = g_object_get_qdata (G_OBJECT (stage), xfixes_cursor_quark);
if (instance == NULL)
- instance = g_object_new (CINNAMON_TYPE_XFIXES_CURSOR,
- "stage", clutter_stage_get_default (),
- NULL);
+ {
+ instance = g_object_new (CINNAMON_TYPE_XFIXES_CURSOR,
+ "stage", stage,
+ NULL);
+ g_object_set_qdata (G_OBJECT (stage), xfixes_cursor_quark, instance);
+ }
return instance;
}
@@ -19,7 +19,7 @@ typedef struct _CinnamonXFixesCursorClass CinnamonXFixesCursorClass;
GType cinnamon_xfixes_cursor_get_type (void) G_GNUC_CONST;
-CinnamonXFixesCursor *cinnamon_xfixes_cursor_get_default (void);
+CinnamonXFixesCursor *cinnamon_xfixes_cursor_get_for_stage (ClutterStage *stage);
void cinnamon_xfixes_cursor_show (CinnamonXFixesCursor *xfixes_cursor);
void cinnamon_xfixes_cursor_hide (CinnamonXFixesCursor *xfixes_cursor);
Oops, something went wrong.

0 comments on commit c1f7191

Please sign in to comment.