Compare commits

...

2 Commits

Author SHA1 Message Date
Georges Basile Stavracas Neto
66910ab422 compositor: Introduce tile picker API
Plugins might want to know when they should show
a tile picker UI and, since we control the tiling
state from the window manager side, we just need
to tell the compositor when they should do that.

This commit adds the necessary plumbing to let the
compositor and plugins know when a tile picker should
be shown.
2017-12-29 14:12:25 -02:00
Georges Basile Stavracas Neto
17b56e9604 window: Export tiling as public API
So that consumers of Mutter APIs can monitor the tile
mode of any given window. This commit also adds the
tile mode as a property of the window.
2017-12-29 14:12:25 -02:00
9 changed files with 131 additions and 12 deletions

View File

@@ -1456,6 +1456,14 @@ meta_compositor_hide_tile_preview (MetaCompositor *compositor)
meta_plugin_manager_hide_tile_preview (compositor->plugin_mgr);
}
void
meta_compositor_show_tile_picker (MetaCompositor *compositor,
MetaWindow *window,
int tile_monitor_number)
{
meta_plugin_manager_show_tile_picker (compositor->plugin_mgr, window, tile_monitor_number);
}
void
meta_compositor_show_window_menu (MetaCompositor *compositor,
MetaWindow *window,

View File

@@ -404,3 +404,24 @@ meta_plugin_manager_create_inhibit_shortcuts_dialog (MetaPluginManager *plugin_m
return meta_inhibit_shortcuts_dialog_default_new (window);
}
gboolean
meta_plugin_manager_show_tile_picker (MetaPluginManager *plugin_mgr,
MetaWindow *window,
int tile_monitor_number)
{
MetaPlugin *plugin = plugin_mgr->plugin;
MetaPluginClass *klass = META_PLUGIN_GET_CLASS (plugin);
MetaDisplay *display = plugin_mgr->compositor->display;
if (display->display_opening)
return FALSE;
if (klass->show_tile_picker)
{
klass->show_tile_picker (plugin, window, tile_monitor_number);
return TRUE;
}
return FALSE;
}

View File

@@ -98,4 +98,9 @@ MetaInhibitShortcutsDialog *
meta_plugin_manager_create_inhibit_shortcuts_dialog (MetaPluginManager *plugin_mgr,
MetaWindow *window);
gboolean meta_plugin_manager_show_tile_picker (MetaPluginManager *plugin_mgr,
MetaWindow *window,
int tile_monitor_number);
#endif

View File

@@ -74,13 +74,6 @@ typedef enum {
*/
#define N_IGNORED_CROSSING_SERIALS 10
typedef enum {
META_TILE_NONE,
META_TILE_LEFT,
META_TILE_RIGHT,
META_TILE_MAXIMIZED
} MetaTileMode;
typedef enum {
/* Normal interaction where you're interacting with windows.
* Events go to windows normally. */

View File

@@ -593,8 +593,6 @@ void meta_window_unmanage (MetaWindow *window,
guint32 timestamp);
void meta_window_queue (MetaWindow *window,
guint queuebits);
void meta_window_tile (MetaWindow *window,
MetaTileMode mode);
void meta_window_restore_tile (MetaWindow *window,
MetaTileMode mode,
int width,
@@ -712,7 +710,6 @@ void meta_window_update_for_monitors_changed (MetaWindow *window);
void meta_window_on_all_workspaces_changed (MetaWindow *window);
gboolean meta_window_should_attach_to_parent (MetaWindow *window);
gboolean meta_window_can_tile_side_by_side (MetaWindow *window);
void meta_window_compute_tile_match (MetaWindow *window);

View File

@@ -179,6 +179,7 @@ enum {
PROP_GTK_APP_MENU_OBJECT_PATH,
PROP_GTK_MENUBAR_OBJECT_PATH,
PROP_ON_ALL_WORKSPACES,
PROP_TILE_MODE,
LAST_PROP,
};
@@ -399,6 +400,9 @@ meta_window_get_property(GObject *object,
case PROP_ON_ALL_WORKSPACES:
g_value_set_boolean (value, win->on_all_workspaces);
break;
case PROP_TILE_MODE:
g_value_set_enum (value, win->tile_mode);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -413,6 +417,9 @@ meta_window_set_property(GObject *object,
{
switch (prop_id)
{
case PROP_TILE_MODE:
meta_window_tile (META_WINDOW (object), g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -588,6 +595,13 @@ meta_window_class_init (MetaWindowClass *klass)
"Whether the window is set to appear on all workspaces",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_TILE_MODE] =
g_param_spec_enum ("tile-mode",
"Tile mode",
"The tile state of the window",
META_TYPE_TILE_MODE,
META_TILE_NONE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, obj_props);
@@ -2833,6 +2847,7 @@ meta_window_maximize (MetaWindow *window,
window->maximized_vertically = FALSE;
window->tile_mode = META_TILE_NONE;
g_object_notify_by_pspec (G_OBJECT (window), obj_props[PROP_TILE_MODE]);
}
meta_window_maximize_internal (window,
@@ -3085,19 +3100,30 @@ update_edge_constraints (MetaWindow *window)
}
}
/**
* meta_window_tile:
* @window: a #MetaWindow
* @tile_mode: the new #MetaTileMode
*
* Tiles @window according to @tile_mode.
*/
void
meta_window_tile (MetaWindow *window,
MetaTileMode tile_mode)
{
MetaMaximizeFlags directions;
MetaRectangle old_frame_rect, old_buffer_rect;
gboolean should_notify;
should_notify = window->tile_mode != tile_mode;
meta_window_get_tile_fraction (window, tile_mode, &window->tile_hfraction);
window->tile_mode = tile_mode;
/* Don't do anything if no tiling is requested */
if (window->tile_mode == META_TILE_NONE)
return;
goto out;
if (window->tile_mode == META_TILE_MAXIMIZED)
directions = META_MAXIMIZE_BOTH;
@@ -3126,6 +3152,16 @@ meta_window_tile (MetaWindow *window,
if (window->frame)
meta_frame_queue_draw (window->frame);
/* If the window doesn't have a tile match after being tiled, ask the
* compositor to show the tile picker.
*/
if (META_WINDOW_TILED_SIDE_BY_SIDE (window) && !window->tile_match)
meta_compositor_show_tile_picker (window->display->compositor, window, window->monitor->number);
out:
if (should_notify)
g_object_notify_by_pspec (G_OBJECT (window), obj_props[PROP_TILE_MODE]);
}
void
@@ -3144,6 +3180,15 @@ meta_window_can_tile_maximized (MetaWindow *window)
return window->has_maximize_func;
}
/**
* meta_window_can_tile_side_by_side:
* @window: a #MetaWindow
*
* Retrieves whether @window can be tiled horizontally.
*
* Returns: %TRUE if @window can be tiled horizontally, %FALSE
* otherwise.
*/
gboolean
meta_window_can_tile_side_by_side (MetaWindow *window)
{
@@ -3169,6 +3214,20 @@ meta_window_can_tile_side_by_side (MetaWindow *window)
client_rect.height >= window->size_hints.min_height;
}
/**
* meta_window_get_tile_mode:
* @window: a #MetaWindow
*
* Retrieves the current tile mode of @window.
*
* Returns: a #MetaTileMode enum value
*/
MetaTileMode
meta_window_get_tile_mode (MetaWindow *window)
{
return window->tile_mode;
}
static void
unmaximize_window_before_freeing (MetaWindow *window)
{
@@ -3237,7 +3296,10 @@ meta_window_unmaximize (MetaWindow *window,
meta_window_get_buffer_rect (window, &old_buffer_rect);
if (unmaximize_vertically)
window->tile_mode = META_TILE_NONE;
{
window->tile_mode = META_TILE_NONE;
g_object_notify_by_pspec (G_OBJECT (window), obj_props[PROP_TILE_MODE]);
}
meta_topic (META_DEBUG_WINDOW_OPS,
"Unmaximizing %s%s\n",

View File

@@ -122,6 +122,10 @@ void meta_compositor_show_tile_preview (MetaCompositor *compositor,
MetaRectangle *tile_rect,
int tile_monitor_number);
void meta_compositor_hide_tile_preview (MetaCompositor *compositor);
void meta_compositor_show_tile_picker (MetaCompositor *compositor,
MetaWindow *window,
int tile_monitor_number);
void meta_compositor_show_window_menu (MetaCompositor *compositor,
MetaWindow *window,
MetaWindowMenuType menu,

View File

@@ -251,6 +251,14 @@ struct _MetaPluginClass
*/
MetaInhibitShortcutsDialog * (* create_inhibit_shortcuts_dialog) (MetaPlugin *plugin,
MetaWindow *window);
/**
* MetaPluginClass::show_tile_picker:
*
*/
void * (* show_tile_picker) (MetaPlugin *plugin,
MetaWindow *window,
int tile_monitor_number);
};
/**

View File

@@ -91,6 +91,21 @@ typedef enum {
META_WINDOW_CLIENT_TYPE_X11
} MetaWindowClientType;
/**
* MetaTileMode:
* @META_TILE_NONE: the window is not tiled
* @META_TILE_LEFT: the window is tiled at the left side of the monitor
* @META_TILE_RIGHT: the window is tiled at the right side of the monitor
* @META_TILE_MAXIMIZED: the window is maximized (i.e. both left and right sides)
*/
typedef enum {
META_TILE_NONE,
META_TILE_LEFT,
META_TILE_RIGHT,
META_TILE_MAXIMIZED
} MetaTileMode;
#define META_TYPE_WINDOW (meta_window_get_type ())
#define META_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_WINDOW, MetaWindow))
#define META_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_WINDOW, MetaWindowClass))
@@ -260,4 +275,10 @@ gboolean meta_window_is_client_decorated (MetaWindow *window);
gboolean meta_window_titlebar_is_onscreen (MetaWindow *window);
void meta_window_shove_titlebar_onscreen (MetaWindow *window);
gboolean meta_window_can_tile_side_by_side (MetaWindow *window);
MetaTileMode meta_window_get_tile_mode (MetaWindow *window);
void meta_window_tile (MetaWindow *window,
MetaTileMode mode);
#endif