From 6b1719de1c8891da1ea7f1e1d6c1528030c8c2a6 Mon Sep 17 00:00:00 2001 From: Tomas Frydrych Date: Thu, 9 Oct 2008 17:57:12 +0100 Subject: [PATCH] Added direction parameter to plugin switch_workspace() To facilitate nicer effects; extended direction defined in workspace.h so we can represent up-left, etc. --- .../clutter/clutter-plugins/default.c | 6 ++- .../clutter/clutter-plugins/moblin.c | 6 ++- .../compositor-clutter-plugin-manager.c | 5 +- .../compositor-clutter-plugin-manager.h | 3 +- src/compositor/clutter/compositor-clutter.c | 8 ++- src/compositor/compositor-private.h | 9 ++-- src/compositor/compositor.c | 11 ++-- src/core/workspace-private.h | 11 ---- src/core/workspace.c | 52 ++++++++++++++++++- src/include/compositor-clutter-plugin.h | 3 +- src/include/compositor.h | 9 ++-- src/include/workspace.h | 16 ++++++ 12 files changed, 104 insertions(+), 35 deletions(-) diff --git a/src/compositor/clutter/clutter-plugins/default.c b/src/compositor/clutter/clutter-plugins/default.c index 88d3ea73c..d4c8e7208 100644 --- a/src/compositor/clutter/clutter-plugins/default.c +++ b/src/compositor/clutter/clutter-plugins/default.c @@ -52,7 +52,8 @@ static void maximize (MetaCompWindow *actor, static void unmaximize (MetaCompWindow *actor, gint x, gint y, gint width, gint height); -static void switch_workspace (const GList **actors, gint from, gint to); +static void switch_workspace (const GList **actors, gint from, gint to, + MetaMotionDirection direction); static void kill_effect (MetaCompWindow *actor, gulong event); @@ -197,7 +198,8 @@ on_switch_workspace_effect_complete (ClutterActor *group, gpointer data) } static void -switch_workspace (const GList **actors, gint from, gint to) +switch_workspace (const GList **actors, gint from, gint to, + MetaMotionDirection direction) { MetaCompositorClutterPlugin *plugin = get_plugin (); PluginPrivate *ppriv = plugin->plugin_private; diff --git a/src/compositor/clutter/clutter-plugins/moblin.c b/src/compositor/clutter/clutter-plugins/moblin.c index 6cb2d89c3..c237a2b2d 100644 --- a/src/compositor/clutter/clutter-plugins/moblin.c +++ b/src/compositor/clutter/clutter-plugins/moblin.c @@ -52,7 +52,8 @@ static void maximize (MetaCompWindow *actor, static void unmaximize (MetaCompWindow *actor, gint x, gint y, gint width, gint height); -static void switch_workspace (const GList **actors, gint from, gint to); +static void switch_workspace (const GList **actors, gint from, gint to, + MetaMotionDirection direction); static void kill_effect (MetaCompWindow *actor, gulong event); @@ -197,7 +198,8 @@ on_switch_workspace_effect_complete (ClutterActor *group, gpointer data) } static void -switch_workspace (const GList **actors, gint from, gint to) +switch_workspace (const GList **actors, gint from, gint to, + MetaMotionDirection direction) { MetaCompositorClutterPlugin *plugin = get_plugin (); PluginPrivate *ppriv = plugin->plugin_private; diff --git a/src/compositor/clutter/compositor-clutter-plugin-manager.c b/src/compositor/clutter/compositor-clutter-plugin-manager.c index 7b289d59e..c148c8c62 100644 --- a/src/compositor/clutter/compositor-clutter-plugin-manager.c +++ b/src/compositor/clutter/compositor-clutter-plugin-manager.c @@ -627,7 +627,8 @@ gboolean meta_compositor_clutter_plugin_manager_switch_workspace (MetaCompositorClutterPluginManager *mgr, const GList **actors, gint from, - gint to) + gint to, + MetaMotionDirection direction) { GList *l = mgr->plugins; gboolean retval = FALSE; @@ -647,7 +648,7 @@ meta_compositor_clutter_plugin_manager_switch_workspace (MetaCompositorClutterPl meta_compositor_clutter_plugin_manager_kill_effect (mgr, META_COMP_WINDOW ((*actors)->data), META_COMPOSITOR_CLUTTER_PLUGIN_SWITCH_WORKSPACE); - plg->switch_workspace (actors, from, to); + plg->switch_workspace (actors, from, to, direction); } } diff --git a/src/compositor/clutter/compositor-clutter-plugin-manager.h b/src/compositor/clutter/compositor-clutter-plugin-manager.h index e2b5dde81..6e75470ed 100644 --- a/src/compositor/clutter/compositor-clutter-plugin-manager.h +++ b/src/compositor/clutter/compositor-clutter-plugin-manager.h @@ -49,7 +49,8 @@ void meta_compositor_clutter_plugin_manager_update_workspace (MetaCompositorClut gboolean meta_compositor_clutter_plugin_manager_switch_workspace (MetaCompositorClutterPluginManager *mgr, const GList **actors, gint from, - gint to); + gint to, + MetaMotionDirection direction); gboolean meta_compositor_clutter_plugin_manager_xevent_filter (MetaCompositorClutterPluginManager *mgr, XEvent *xev); diff --git a/src/compositor/clutter/compositor-clutter.c b/src/compositor/clutter/compositor-clutter.c index 9b5e0bfff..38f223c8d 100644 --- a/src/compositor/clutter/compositor-clutter.c +++ b/src/compositor/clutter/compositor-clutter.c @@ -2108,7 +2108,8 @@ static void clutter_cmp_switch_workspace (MetaCompositor *compositor, MetaScreen *screen, MetaWorkspace *from, - MetaWorkspace *to) + MetaWorkspace *to, + MetaMotionDirection direction) { #ifdef HAVE_COMPOSITE_EXTENSIONS MetaCompScreen *info; @@ -2119,6 +2120,8 @@ clutter_cmp_switch_workspace (MetaCompositor *compositor, to_indx = meta_workspace_index (to); from_indx = meta_workspace_index (from); + printf ("Direction of switch %d\n", direction); + l = info->windows; while (l) { @@ -2161,7 +2164,8 @@ clutter_cmp_switch_workspace (MetaCompositor *compositor, info->plugin_mgr, (const GList **)&info->windows, from_indx, - to_indx)) + to_indx, + direction)) { info->switch_workspace_in_progress--; } diff --git a/src/compositor/compositor-private.h b/src/compositor/compositor-private.h index aeccda417..037235416 100644 --- a/src/compositor/compositor-private.h +++ b/src/compositor/compositor-private.h @@ -73,10 +73,11 @@ struct _MetaCompositor void (*update_workspace_geometry) (MetaCompositor *compositor, MetaWorkspace *workspace); - void (*switch_workspace) (MetaCompositor *compositor, - MetaScreen *screen, - MetaWorkspace *from, - MetaWorkspace *to); + void (*switch_workspace) (MetaCompositor *compositor, + MetaScreen *screen, + MetaWorkspace *from, + MetaWorkspace *to, + MetaMotionDirection direction); }; #endif diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c index 5567e4344..0c21d5e91 100644 --- a/src/compositor/compositor.c +++ b/src/compositor/compositor.c @@ -230,14 +230,15 @@ meta_compositor_update_workspace_geometry (MetaCompositor *compositor, } void -meta_compositor_switch_workspace (MetaCompositor *compositor, - MetaScreen *screen, - MetaWorkspace *from, - MetaWorkspace *to) +meta_compositor_switch_workspace (MetaCompositor *compositor, + MetaScreen *screen, + MetaWorkspace *from, + MetaWorkspace *to, + MetaMotionDirection direction) { #ifdef HAVE_COMPOSITE_EXTENSIONS if (compositor && compositor->switch_workspace) - compositor->switch_workspace (compositor, screen, from, to); + compositor->switch_workspace (compositor, screen, from, to, direction); #endif } diff --git a/src/core/workspace-private.h b/src/core/workspace-private.h index 54f7c8146..b589274b7 100644 --- a/src/core/workspace-private.h +++ b/src/core/workspace-private.h @@ -36,17 +36,6 @@ #include "workspace.h" #include "window-private.h" -/* Negative to avoid conflicting with real workspace - * numbers - */ -typedef enum -{ - META_MOTION_UP = -1, - META_MOTION_DOWN = -2, - META_MOTION_LEFT = -3, - META_MOTION_RIGHT = -4 -} MetaMotionDirection; - struct _MetaWorkspace { MetaScreen *screen; diff --git a/src/core/workspace.c b/src/core/workspace.c index 9f4cb7231..a2e3ed1e1 100644 --- a/src/core/workspace.c +++ b/src/core/workspace.c @@ -398,8 +398,49 @@ meta_workspace_activate_with_focus (MetaWorkspace *workspace, MetaScreen *screen = workspace->screen; MetaDisplay *display = meta_screen_get_display (screen); MetaCompositor *comp = meta_display_get_compositor (display); + MetaWorkspaceLayout layout1, layout2; + gint num_workspaces, current_space, new_space; + MetaMotionDirection direction = 0; - meta_compositor_switch_workspace (comp, screen, old, workspace); + current_space = meta_workspace_index (old); + new_space = meta_workspace_index (workspace); + + num_workspaces = meta_screen_get_n_workspaces (workspace->screen); + meta_screen_calc_workspace_layout (workspace->screen, num_workspaces, + current_space, &layout1); + + meta_screen_calc_workspace_layout (workspace->screen, num_workspaces, + new_space, &layout2); + + if (layout1.current_col < layout2.current_col) + direction = META_MOTION_RIGHT; + if (layout1.current_col > layout2.current_col) + direction = META_MOTION_LEFT; + + if (layout1.current_row < layout2.current_row) + { + if (!direction) + direction = META_MOTION_DOWN; + else if (direction == META_MOTION_RIGHT) + direction = META_MOTION_DOWN_RIGHT; + else + direction = META_MOTION_DOWN_LEFT; + } + + if (layout1.current_row > layout2.current_row) + { + if (!direction) + direction = META_MOTION_UP; + else if (direction == META_MOTION_RIGHT) + direction = META_MOTION_UP_RIGHT; + else + direction = META_MOTION_UP_LEFT; + } + + meta_screen_free_workspace_layout (&layout1); + meta_screen_free_workspace_layout (&layout2); + + meta_compositor_switch_workspace (comp, screen, old, workspace, direction); } #endif } @@ -769,6 +810,14 @@ meta_motion_direction_to_string (MetaMotionDirection direction) return "Left"; case META_MOTION_RIGHT: return "Right"; + case META_MOTION_UP_RIGHT: + return "Up-Right"; + case META_MOTION_DOWN_RIGHT: + return "Down-Right"; + case META_MOTION_UP_LEFT: + return "Up-Left"; + case META_MOTION_DOWN_LEFT: + return "Down-Left"; } return "Unknown"; @@ -807,6 +856,7 @@ meta_workspace_get_neighbor (MetaWorkspace *workspace, case META_MOTION_DOWN: layout.current_row += 1; break; + default:; } if (layout.current_col < 0) diff --git a/src/include/compositor-clutter-plugin.h b/src/include/compositor-clutter-plugin.h index 6f03c1c9b..b9bb65bf9 100644 --- a/src/include/compositor-clutter-plugin.h +++ b/src/include/compositor-clutter-plugin.h @@ -156,7 +156,8 @@ struct MetaCompositorClutterPlugin */ void (*switch_workspace) (const GList **actors, gint from, - gint to); + gint to, + MetaMotionDirection direction); /* * Called if an effect should be killed prematurely; the plugin must diff --git a/src/include/compositor.h b/src/include/compositor.h index 18b271ed5..736a1d2a3 100644 --- a/src/include/compositor.h +++ b/src/include/compositor.h @@ -122,10 +122,11 @@ meta_compositor_update_workspace_geometry (MetaCompositor *compositor, MetaWorkspace *workspace); void -meta_compositor_switch_workspace (MetaCompositor *compositor, - MetaScreen *screen, - MetaWorkspace *from, - MetaWorkspace *to); +meta_compositor_switch_workspace (MetaCompositor *compositor, + MetaScreen *screen, + MetaWorkspace *from, + MetaWorkspace *to, + MetaMotionDirection direction); #endif diff --git a/src/include/workspace.h b/src/include/workspace.h index a7e54fcfa..e4e4c5d23 100644 --- a/src/include/workspace.h +++ b/src/include/workspace.h @@ -37,6 +37,22 @@ #include "boxes.h" #include "screen.h" +/* Negative to avoid conflicting with real workspace + * numbers + */ +typedef enum +{ + META_MOTION_UP = -1, + META_MOTION_DOWN = -2, + META_MOTION_LEFT = -3, + META_MOTION_RIGHT = -4, + /* These are only used for effects */ + META_MOTION_UP_LEFT = -5, + META_MOTION_UP_RIGHT = -6, + META_MOTION_DOWN_LEFT = -7, + META_MOTION_DOWN_RIGHT = -8 +} MetaMotionDirection; + int meta_workspace_index (MetaWorkspace *workspace); MetaScreen *meta_workspace_get_screen (MetaWorkspace *workspace); void meta_workspace_get_work_area_all_xineramas (MetaWorkspace *workspace,