[mutter] Make tile preview a compositor plugin effect
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] Make tile preview a compositor plugin effect
- Date: Thu, 12 Dec 2013 08:08:49 +0000 (UTC)
commit 21e94ed1094a31b90007089eca5174205d4861c9
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sat Mar 24 11:29:39 2012 +0100
Make tile preview a compositor plugin effect
https://bugzilla.gnome.org/show_bug.cgi?id=665758
src/Makefile.am | 2 -
src/compositor/compositor.c | 28 +++++
src/compositor/meta-plugin-manager.c | 41 +++++++
src/compositor/meta-plugin-manager.h | 5 +
src/compositor/plugins/default.c | 95 ++++++++++++++++
src/core/keybindings.c | 2 +-
src/core/screen-private.h | 5 +-
src/core/screen.c | 39 +++-----
src/core/window-private.h | 1 +
src/core/window.c | 28 +++--
src/meta/compositor.h | 8 ++
src/meta/meta-plugin.h | 5 +
src/ui/tile-preview.c | 198 ----------------------------------
src/ui/tile-preview.h | 38 -------
src/ui/ui.h | 1 -
15 files changed, 216 insertions(+), 280 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ba4122e..1baf764 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -163,8 +163,6 @@ libmutter_la_SOURCES = \
ui/resizepopup.h \
ui/tabpopup.c \
ui/tabpopup.h \
- ui/tile-preview.c \
- ui/tile-preview.h \
ui/theme-parser.c \
ui/theme.c \
meta/theme.h \
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index ef13188..580b0b8 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -1647,3 +1647,31 @@ meta_compositor_monotonic_time_to_server_time (MetaDisplay *display,
else
return monotonic_time + compositor->server_time_offset;
}
+
+void
+meta_compositor_show_tile_preview (MetaCompositor *compositor,
+ MetaScreen *screen,
+ MetaWindow *window,
+ MetaRectangle *tile_rect,
+ int tile_monitor_number)
+{
+ MetaCompScreen *info = meta_screen_get_compositor_data (screen);
+
+ if (!info->plugin_mgr)
+ return;
+
+ meta_plugin_manager_show_tile_preview (info->plugin_mgr,
+ window, tile_rect, tile_monitor_number);
+}
+
+void
+meta_compositor_hide_tile_preview (MetaCompositor *compositor,
+ MetaScreen *screen)
+{
+ MetaCompScreen *info = meta_screen_get_compositor_data (screen);
+
+ if (!info->plugin_mgr)
+ return;
+
+ meta_plugin_manager_hide_tile_preview (info->plugin_mgr);
+}
diff --git a/src/compositor/meta-plugin-manager.c b/src/compositor/meta-plugin-manager.c
index dee1b08..899dcfe 100644
--- a/src/compositor/meta-plugin-manager.c
+++ b/src/compositor/meta-plugin-manager.c
@@ -326,3 +326,44 @@ meta_plugin_manager_confirm_display_change (MetaPluginManager *plugin_mgr)
else
return meta_plugin_complete_display_change (plugin, TRUE);
}
+
+gboolean
+meta_plugin_manager_show_tile_preview (MetaPluginManager *plugin_mgr,
+ MetaWindow *window,
+ MetaRectangle *tile_rect,
+ int tile_monitor_number)
+{
+ MetaPlugin *plugin = plugin_mgr->plugin;
+ MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
+ MetaDisplay *display = meta_screen_get_display (plugin_mgr->screen);
+
+ if (display->display_opening)
+ return FALSE;
+
+ if (klass->show_tile_preview)
+ {
+ klass->show_tile_preview (plugin, window, tile_rect, tile_monitor_number);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+gboolean
+meta_plugin_manager_hide_tile_preview (MetaPluginManager *plugin_mgr)
+{
+ MetaPlugin *plugin = plugin_mgr->plugin;
+ MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
+ MetaDisplay *display = meta_screen_get_display (plugin_mgr->screen);
+
+ if (display->display_opening)
+ return FALSE;
+
+ if (klass->hide_tile_preview)
+ {
+ klass->hide_tile_preview (plugin);
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/src/compositor/meta-plugin-manager.h b/src/compositor/meta-plugin-manager.h
index f39f5ca..0b94459 100644
--- a/src/compositor/meta-plugin-manager.h
+++ b/src/compositor/meta-plugin-manager.h
@@ -77,4 +77,9 @@ gboolean _meta_plugin_xevent_filter (MetaPlugin *plugin,
void meta_plugin_manager_confirm_display_change (MetaPluginManager *mgr);
+gboolean meta_plugin_manager_show_tile_preview (MetaPluginManager *mgr,
+ MetaWindow *window,
+ MetaRectangle *tile_rect,
+ int tile_monitor_number);
+gboolean meta_plugin_manager_hide_tile_preview (MetaPluginManager *mgr);
#endif
diff --git a/src/compositor/plugins/default.c b/src/compositor/plugins/default.c
index 404302c..3ea1b53 100644
--- a/src/compositor/plugins/default.c
+++ b/src/compositor/plugins/default.c
@@ -42,6 +42,7 @@
#define SWITCH_TIMEOUT 500
#define ACTOR_DATA_KEY "MCCP-Default-actor-data"
+#define SCREEN_TILE_PREVIEW_DATA_KEY "MCCP-Default-screen-tile-preview-data"
#define META_TYPE_DEFAULT_PLUGIN (meta_default_plugin_get_type ())
#define META_DEFAULT_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_DEFAULT_PLUGIN,
MetaDefaultPlugin))
@@ -70,6 +71,7 @@ struct _MetaDefaultPluginClass
};
static GQuark actor_data_quark = 0;
+static GQuark screen_tile_preview_data_quark = 0;
static void start (MetaPlugin *plugin);
static void minimize (MetaPlugin *plugin,
@@ -100,6 +102,12 @@ static void kill_window_effects (MetaPlugin *plugin,
MetaWindowActor *actor);
static void kill_switch_workspace (MetaPlugin *plugin);
+static void show_tile_preview (MetaPlugin *plugin,
+ MetaWindow *window,
+ MetaRectangle *tile_rect,
+ int tile_monitor_number);
+static void hide_tile_preview (MetaPlugin *plugin);
+
static void confirm_display_change (MetaPlugin *plugin);
static const MetaPluginInfo * plugin_info (MetaPlugin *plugin);
@@ -146,6 +154,15 @@ typedef struct
} EffectCompleteData;
+typedef struct _ScreenTilePreview
+{
+ ClutterActor *actor;
+
+ GdkRGBA *preview_color;
+
+ MetaRectangle tile_rect;
+} ScreenTilePreview;
+
static void
meta_default_plugin_dispose (GObject *object)
{
@@ -206,6 +223,8 @@ meta_default_plugin_class_init (MetaDefaultPluginClass *klass)
plugin_class->unmaximize = unmaximize;
plugin_class->destroy = destroy;
plugin_class->switch_workspace = switch_workspace;
+ plugin_class->show_tile_preview = show_tile_preview;
+ plugin_class->hide_tile_preview = hide_tile_preview;
plugin_class->plugin_info = plugin_info;
plugin_class->kill_window_effects = kill_window_effects;
plugin_class->kill_switch_workspace = kill_switch_workspace;
@@ -785,6 +804,82 @@ destroy (MetaPlugin *plugin, MetaWindowActor *window_actor)
meta_plugin_destroy_completed (plugin, window_actor);
}
+/*
+ * Tile preview private data accessor
+ */
+static void
+free_screen_tile_preview (gpointer data)
+{
+ ScreenTilePreview *preview = data;
+
+ if (G_LIKELY (preview != NULL)) {
+ clutter_actor_destroy (preview->actor);
+ g_slice_free (ScreenTilePreview, preview);
+ }
+}
+
+static ScreenTilePreview *
+get_screen_tile_preview (MetaScreen *screen)
+{
+ ScreenTilePreview *preview = g_object_get_qdata (G_OBJECT (screen), screen_tile_preview_data_quark);
+
+ if (G_UNLIKELY (screen_tile_preview_data_quark == 0))
+ screen_tile_preview_data_quark = g_quark_from_static_string (SCREEN_TILE_PREVIEW_DATA_KEY);
+
+ if (G_UNLIKELY (!preview))
+ {
+ preview = g_slice_new0 (ScreenTilePreview);
+
+ preview->actor = clutter_actor_new ();
+ clutter_actor_set_background_color (preview->actor, CLUTTER_COLOR_Blue);
+ clutter_actor_set_opacity (preview->actor, 100);
+
+ clutter_actor_add_child (meta_get_window_group_for_screen (screen), preview->actor);
+ g_object_set_qdata_full (G_OBJECT (screen),
+ screen_tile_preview_data_quark, preview,
+ free_screen_tile_preview);
+ }
+
+ return preview;
+}
+
+static void
+show_tile_preview (MetaPlugin *plugin,
+ MetaWindow *window,
+ MetaRectangle *tile_rect,
+ int tile_monitor_number)
+{
+ MetaScreen *screen = meta_plugin_get_screen (plugin);
+ ScreenTilePreview *preview = get_screen_tile_preview (screen);
+ ClutterActor *window_actor;
+
+ if (CLUTTER_ACTOR_IS_VISIBLE (preview->actor)
+ && preview->tile_rect.x == tile_rect->x
+ && preview->tile_rect.y == tile_rect->y
+ && preview->tile_rect.width == tile_rect->width
+ && preview->tile_rect.height == tile_rect->height)
+ return; /* nothing to do */
+
+ clutter_actor_set_position (preview->actor, tile_rect->x, tile_rect->y);
+ clutter_actor_set_size (preview->actor, tile_rect->width, tile_rect->height);
+
+ clutter_actor_show (preview->actor);
+
+ window_actor = CLUTTER_ACTOR (meta_window_get_compositor_private (window));
+ clutter_actor_lower (preview->actor, window_actor);
+
+ preview->tile_rect = *tile_rect;
+}
+
+static void
+hide_tile_preview (MetaPlugin *plugin)
+{
+ MetaScreen *screen = meta_plugin_get_screen (plugin);
+ ScreenTilePreview *preview = get_screen_tile_preview (screen);
+
+ clutter_actor_hide (preview->actor);
+}
+
static void
kill_switch_workspace (MetaPlugin *plugin)
{
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index bd557ba..3effe09 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -2209,7 +2209,7 @@ process_mouse_move_resize_grab (MetaDisplay *display,
{
/* Hide the tiling preview if necessary */
if (window->tile_mode != META_TILE_NONE)
- meta_screen_tile_preview_hide (screen);
+ meta_screen_hide_tile_preview (screen);
/* Restore the original tile mode */
window->tile_mode = display->grab_tile_mode;
diff --git a/src/core/screen-private.h b/src/core/screen-private.h
index 426f561..1aa0d24 100644
--- a/src/core/screen-private.h
+++ b/src/core/screen-private.h
@@ -67,7 +67,6 @@ struct _MetaScreen
MetaRectangle rect; /* Size of screen; rect.x & rect.y are always 0 */
MetaUI *ui;
MetaTabPopup *tab_popup, *ws_popup;
- MetaTilePreview *tile_preview;
guint tile_preview_timeout_id;
@@ -169,9 +168,9 @@ void meta_screen_workspace_popup_select (MetaScreen *screen,
MetaWorkspace*meta_screen_workspace_popup_get_selected (MetaScreen *screen);
void meta_screen_workspace_popup_destroy (MetaScreen *screen);
-void meta_screen_tile_preview_update (MetaScreen *screen,
+void meta_screen_update_tile_preview (MetaScreen *screen,
gboolean delay);
-void meta_screen_tile_preview_hide (MetaScreen *screen);
+void meta_screen_hide_tile_preview (MetaScreen *screen);
MetaWindow* meta_screen_get_mouse_window (MetaScreen *screen,
MetaWindow *not_this_one);
diff --git a/src/core/screen.c b/src/core/screen.c
index fc0c3ae..b1b264d 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -763,7 +763,6 @@ meta_screen_new (MetaDisplay *display,
screen->tab_popup = NULL;
screen->ws_popup = NULL;
- screen->tile_preview = NULL;
screen->tile_preview_timeout_id = 0;
@@ -869,9 +868,6 @@ meta_screen_free (MetaScreen *screen,
if (screen->tile_preview_timeout_id)
g_source_remove (screen->tile_preview_timeout_id);
- if (screen->tile_preview)
- meta_tile_preview_free (screen->tile_preview);
-
g_free (screen->screen_name);
g_object_unref (screen);
@@ -1730,7 +1726,7 @@ meta_screen_workspace_popup_destroy (MetaScreen *screen)
}
static gboolean
-meta_screen_tile_preview_update_timeout (gpointer data)
+meta_screen_update_tile_preview_timeout (gpointer data)
{
MetaScreen *screen = data;
MetaWindow *window = screen->display->grab_window;
@@ -1738,19 +1734,6 @@ meta_screen_tile_preview_update_timeout (gpointer data)
screen->tile_preview_timeout_id = 0;
- if (!screen->tile_preview)
- {
- Window xwindow;
- gulong create_serial;
-
- screen->tile_preview = meta_tile_preview_new (screen->number);
- xwindow = meta_tile_preview_get_xwindow (screen->tile_preview,
- &create_serial);
- meta_stack_tracker_record_add (screen->stack_tracker,
- xwindow,
- create_serial);
- }
-
if (window)
{
switch (window->tile_mode)
@@ -1775,12 +1758,16 @@ meta_screen_tile_preview_update_timeout (gpointer data)
if (needs_preview)
{
MetaRectangle tile_rect;
+ int monitor;
+ monitor = meta_window_get_current_tile_monitor_number (window);
meta_window_get_current_tile_area (window, &tile_rect);
- meta_tile_preview_show (screen->tile_preview, &tile_rect);
+ meta_compositor_show_tile_preview (screen->display->compositor,
+ screen, window, &tile_rect, monitor);
}
else
- meta_tile_preview_hide (screen->tile_preview);
+ meta_compositor_hide_tile_preview (screen->display->compositor,
+ screen);
return FALSE;
}
@@ -1788,7 +1775,7 @@ meta_screen_tile_preview_update_timeout (gpointer data)
#define TILE_PREVIEW_TIMEOUT_MS 200
void
-meta_screen_tile_preview_update (MetaScreen *screen,
+meta_screen_update_tile_preview (MetaScreen *screen,
gboolean delay)
{
if (delay)
@@ -1798,7 +1785,7 @@ meta_screen_tile_preview_update (MetaScreen *screen,
screen->tile_preview_timeout_id =
g_timeout_add (TILE_PREVIEW_TIMEOUT_MS,
- meta_screen_tile_preview_update_timeout,
+ meta_screen_update_tile_preview_timeout,
screen);
}
else
@@ -1806,18 +1793,18 @@ meta_screen_tile_preview_update (MetaScreen *screen,
if (screen->tile_preview_timeout_id > 0)
g_source_remove (screen->tile_preview_timeout_id);
- meta_screen_tile_preview_update_timeout ((gpointer)screen);
+ meta_screen_update_tile_preview_timeout ((gpointer)screen);
}
}
void
-meta_screen_tile_preview_hide (MetaScreen *screen)
+meta_screen_hide_tile_preview (MetaScreen *screen)
{
if (screen->tile_preview_timeout_id > 0)
g_source_remove (screen->tile_preview_timeout_id);
- if (screen->tile_preview)
- meta_tile_preview_hide (screen->tile_preview);
+ meta_compositor_hide_tile_preview (screen->display->compositor,
+ screen);
}
MetaWindow*
diff --git a/src/core/window-private.h b/src/core/window-private.h
index 774b6ab..90afce8 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -629,6 +629,7 @@ void meta_window_handle_mouse_grab_op_event (MetaWindow *window,
GList* meta_window_get_workspaces (MetaWindow *window);
+int meta_window_get_current_tile_monitor_number (MetaWindow *window);
void meta_window_get_current_tile_area (MetaWindow *window,
MetaRectangle *tile_area);
diff --git a/src/core/window.c b/src/core/window.c
index a3ba385..1c54b22 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -1404,9 +1404,6 @@ meta_window_new_with_attrs (MetaDisplay *display,
if (!window->override_redirect)
meta_stack_add (window->screen->stack,
window);
- else if (window->screen->tile_preview != NULL &&
- meta_tile_preview_get_xwindow (window->screen->tile_preview, NULL) == xwindow)
- window->layer = META_LAYER_NORMAL;
else
window->layer = META_LAYER_OVERRIDE_REDIRECT; /* otherwise set by MetaStack */
@@ -3784,7 +3781,7 @@ meta_window_tile (MetaWindow *window)
directions = META_MAXIMIZE_VERTICAL;
meta_window_maximize_internal (window, directions, NULL);
- meta_screen_tile_preview_update (window->screen, FALSE);
+ meta_screen_update_tile_preview (window->screen, FALSE);
if (window->display->compositor)
{
@@ -9352,7 +9349,7 @@ update_move (MetaWindow *window,
* trigger it unwittingly, e.g. when shaking loose the window or moving
* it to another monitor.
*/
- meta_screen_tile_preview_update (window->screen,
+ meta_screen_update_tile_preview (window->screen,
window->tile_mode != META_TILE_NONE);
meta_window_get_client_root_coords (window, &old);
@@ -10108,6 +10105,20 @@ meta_window_get_work_area_all_monitors (MetaWindow *window,
window->desc, area->x, area->y, area->width, area->height);
}
+int
+meta_window_get_current_tile_monitor_number (MetaWindow *window)
+{
+ int tile_monitor_number = window->tile_monitor_number;
+
+ if (tile_monitor_number < 0)
+ {
+ meta_warning ("%s called with an invalid monitor number; using 0 instead\n", G_STRFUNC);
+ tile_monitor_number = 0;
+ }
+
+ return tile_monitor_number;
+}
+
void
meta_window_get_current_tile_area (MetaWindow *window,
MetaRectangle *tile_area)
@@ -10116,12 +10127,7 @@ meta_window_get_current_tile_area (MetaWindow *window,
g_return_if_fail (window->tile_mode != META_TILE_NONE);
- tile_monitor_number = window->tile_monitor_number;
- if (tile_monitor_number < 0)
- {
- meta_warning ("%s called with an invalid monitor number; using 0 instead\n", G_STRFUNC);
- tile_monitor_number = 0;
- }
+ tile_monitor_number = meta_window_get_current_tile_monitor_number (window);
meta_window_get_work_area_for_monitor (window, tile_monitor_number, tile_area);
diff --git a/src/meta/compositor.h b/src/meta/compositor.h
index b0e5455..adf1654 100644
--- a/src/meta/compositor.h
+++ b/src/meta/compositor.h
@@ -128,4 +128,12 @@ void meta_compositor_sync_screen_size (MetaCompositor *compositor,
void meta_compositor_flash_screen (MetaCompositor *compositor,
MetaScreen *screen);
+void meta_compositor_show_tile_preview (MetaCompositor *compositor,
+ MetaScreen *screen,
+ MetaWindow *window,
+ MetaRectangle *tile_rect,
+ int tile_monitor_number);
+void meta_compositor_hide_tile_preview (MetaCompositor *compositor,
+ MetaScreen *screen);
+
#endif /* META_COMPOSITOR_H */
diff --git a/src/meta/meta-plugin.h b/src/meta/meta-plugin.h
index 0587551..e03daa1 100644
--- a/src/meta/meta-plugin.h
+++ b/src/meta/meta-plugin.h
@@ -160,6 +160,11 @@ struct _MetaPluginClass
gint to,
MetaMotionDirection direction);
+ void (*show_tile_preview) (MetaPlugin *plugin,
+ MetaWindow *window,
+ MetaRectangle *tile_rect,
+ int tile_monitor_number);
+ void (*hide_tile_preview) (MetaPlugin *plugin);
/**
* MetaPluginClass::kill_window_effects:
diff --git a/src/ui/ui.h b/src/ui/ui.h
index e397c43..ac33d40 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -181,6 +181,5 @@ int meta_ui_get_drag_threshold (MetaUI *ui);
MetaUIDirection meta_ui_get_direction (void);
#include "tabpopup.h"
-#include "tile-preview.h"
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]