From 97e2b4666b5551a7ac0e290bf3d62a5eb2d5ac8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 24 Jun 2010 20:41:28 +0200 Subject: [PATCH] Implement side-by-side tiling When dragging a window over a screen edge and dropping it there, maximize it vertically and scale it horizontally to cover the corresponding half of the current monitor. Whenever a "hot area" which triggers this behavior is entered, an indication of window's target size is displayed after a short delay to avoid distraction when moving a window between monitors. https://bugzilla.gnome.org/show_bug.cgi?id=606260 --- src/Makefile.am | 2 + src/core/constraints.c | 66 +++++++++- src/core/core.c | 35 +++++ src/core/prefs.c | 15 +++ src/core/screen-private.h | 6 + src/core/screen.c | 72 ++++++++++ src/core/window-private.h | 19 ++- src/core/window.c | 196 +++++++++++++++++++++++---- src/include/core.h | 4 + src/include/prefs.h | 2 + src/include/tile-preview.h | 39 ++++++ src/include/ui.h | 1 + src/ui/tile-preview.c | 262 +++++++++++++++++++++++++++++++++++++ 13 files changed, 692 insertions(+), 27 deletions(-) create mode 100644 src/include/tile-preview.h create mode 100644 src/ui/tile-preview.c diff --git a/src/Makefile.am b/src/Makefile.am index 43916e533..c9d92aa56 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -118,6 +118,8 @@ mutter_SOURCES= \ include/resizepopup.h \ ui/tabpopup.c \ include/tabpopup.h \ + ui/tile-preview.c \ + include/tile-preview.h \ ui/theme-parser.c \ ui/theme-parser.h \ ui/theme.c \ diff --git a/src/core/constraints.c b/src/core/constraints.c index 4fe747e17..6cddb4d7b 100644 --- a/src/core/constraints.c +++ b/src/core/constraints.c @@ -98,6 +98,7 @@ typedef enum PRIORITY_ENTIRELY_VISIBLE_ON_WORKAREA = 1, PRIORITY_SIZE_HINTS_INCREMENTS = 1, PRIORITY_MAXIMIZATION = 2, + PRIORITY_TILING = 2, PRIORITY_FULLSCREEN = 2, PRIORITY_SIZE_HINTS_LIMITS = 3, PRIORITY_TITLEBAR_VISIBLE = 4, @@ -148,6 +149,10 @@ static gboolean constrain_maximization (MetaWindow *window, ConstraintInfo *info, ConstraintPriority priority, gboolean check_only); +static gboolean constrain_tiling (MetaWindow *window, + ConstraintInfo *info, + ConstraintPriority priority, + gboolean check_only); static gboolean constrain_fullscreen (MetaWindow *window, ConstraintInfo *info, ConstraintPriority priority, @@ -215,6 +220,7 @@ typedef struct { static const Constraint all_constraints[] = { {constrain_modal_dialog, "constrain_modal_dialog"}, {constrain_maximization, "constrain_maximization"}, + {constrain_tiling, "constrain_tiling"}, {constrain_fullscreen, "constrain_fullscreen"}, {constrain_size_increments, "constrain_size_increments"}, {constrain_size_limits, "constrain_size_limits"}, @@ -788,7 +794,8 @@ constrain_maximization (MetaWindow *window, return TRUE; /* Determine whether constraint applies; exit if it doesn't */ - if (!window->maximized_horizontally && !window->maximized_vertically) + if ((!window->maximized_horizontally && !window->maximized_vertically) || + META_WINDOW_TILED (window)) return TRUE; /* Calculate target_size = maximized size of (window + frame) */ @@ -856,6 +863,59 @@ constrain_maximization (MetaWindow *window, return TRUE; } +static gboolean +constrain_tiling (MetaWindow *window, + ConstraintInfo *info, + ConstraintPriority priority, + gboolean check_only) +{ + MetaRectangle target_size; + MetaRectangle min_size, max_size; + gboolean hminbad, vminbad; + gboolean horiz_equal, vert_equal; + gboolean constraint_already_satisfied; + + if (priority > PRIORITY_TILING) + return TRUE; + + /* Determine whether constraint applies; exit if it doesn't */ + if (!META_WINDOW_TILED (window)) + return TRUE; + + /* Calculate target_size - as the tile previews need this as well, we + * use an external function for the actual calculation + */ + meta_window_get_current_tile_area (window, &target_size); + unextend_by_frame (&target_size, info->fgeom); + + /* Check min size constraints; max size constraints are ignored as for + * maximized windows. + */ + get_size_limits (window, info->fgeom, FALSE, &min_size, &max_size); + hminbad = target_size.width < min_size.width; + vminbad = target_size.height < min_size.height; + if (hminbad || vminbad) + return TRUE; + + /* Determine whether constraint is already satisfied; exit if it is */ + horiz_equal = target_size.x == info->current.x && + target_size.width == info->current.width; + vert_equal = target_size.y == info->current.y && + target_size.height == info->current.height; + constraint_already_satisfied = horiz_equal && vert_equal; + if (check_only || constraint_already_satisfied) + return constraint_already_satisfied; + + /*** Enforce constraint ***/ + info->current.x = target_size.x; + info->current.width = target_size.width; + info->current.y = target_size.y; + info->current.height = target_size.height; + + return TRUE; +} + + static gboolean constrain_fullscreen (MetaWindow *window, ConstraintInfo *info, @@ -907,7 +967,7 @@ constrain_size_increments (MetaWindow *window, /* Determine whether constraint applies; exit if it doesn't */ if (META_WINDOW_MAXIMIZED (window) || window->fullscreen || - info->action_type == ACTION_MOVE) + META_WINDOW_TILED (window) || info->action_type == ACTION_MOVE) return TRUE; /* Determine whether constraint is already satisfied; exit if it is */ @@ -1038,7 +1098,7 @@ constrain_aspect_ratio (MetaWindow *window, constraints_are_inconsistent = minr > maxr; if (constraints_are_inconsistent || META_WINDOW_MAXIMIZED (window) || window->fullscreen || - info->action_type == ACTION_MOVE) + META_WINDOW_TILED (window) || info->action_type == ACTION_MOVE) return TRUE; /* Determine whether constraint is already satisfied; exit if it is. We diff --git a/src/core/core.c b/src/core/core.c index 9464b0d78..68807eb96 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -28,6 +28,7 @@ #include "frame-private.h" #include "workspace-private.h" #include "prefs.h" +#include "errors.h" /* Looks up the MetaWindow representing the frame of the given X window. * Used as a helper function by a bunch of the functions below. @@ -316,6 +317,40 @@ meta_core_user_lower_and_unfocus (Display *xdisplay, timestamp); } +void +meta_core_lower_beneath_focus_window (Display *xdisplay, + Window xwindow, + guint32 timestamp) +{ + XWindowChanges changes; + MetaDisplay *display; + MetaScreen *screen; + MetaWindow *focus_window; + + display = meta_display_for_x_display (xdisplay); + screen = meta_display_screen_for_xwindow (display, xwindow); + focus_window = meta_stack_get_top (screen->stack); + + if (focus_window == NULL) + return; + + changes.stack_mode = Below; + changes.sibling = focus_window->frame ? focus_window->frame->xwindow + : focus_window->xwindow; + + meta_stack_tracker_record_lower_below (screen->stack_tracker, + xwindow, + changes.sibling, + XNextRequest (screen->display->xdisplay)); + + meta_error_trap_push (display); + XConfigureWindow (xdisplay, + xwindow, + CWSibling | CWStackMode, + &changes); + meta_error_trap_pop (display, FALSE); +} + void meta_core_user_focus (Display *xdisplay, Window frame_xwindow, diff --git a/src/core/prefs.c b/src/core/prefs.c index 6d3e4f086..edc1fa1da 100644 --- a/src/core/prefs.c +++ b/src/core/prefs.c @@ -104,6 +104,7 @@ static char *cursor_theme = NULL; static int cursor_size = 24; static gboolean compositing_manager = FALSE; static gboolean resize_with_right_button = FALSE; +static gboolean side_by_side_tiling = FALSE; static gboolean force_fullscreen = TRUE; static MetaVisualBellType visual_bell_type = META_VISUAL_BELL_FULLSCREEN_FLASH; @@ -422,6 +423,11 @@ static MetaBoolPreference preferences_bool[] = &resize_with_right_button, FALSE, }, + { "/apps/metacity/general/side_by_side_tiling", + META_PREF_SIDE_BY_SIDE_TILING, + &side_by_side_tiling, + FALSE, + }, { "/apps/mutter/general/live_hidden_windows", META_PREF_LIVE_HIDDEN_WINDOWS, &live_hidden_windows, @@ -2004,6 +2010,9 @@ meta_preference_to_string (MetaPreference pref) case META_PREF_RESIZE_WITH_RIGHT_BUTTON: return "RESIZE_WITH_RIGHT_BUTTON"; + case META_PREF_SIDE_BY_SIDE_TILING: + return "SIDE_BY_SIDE_TILING"; + case META_PREF_FORCE_FULLSCREEN: return "FORCE_FULLSCREEN"; @@ -2914,6 +2923,12 @@ meta_prefs_get_gnome_animations () return gnome_animations; } +gboolean +meta_prefs_get_side_by_side_tiling () +{ + return side_by_side_tiling; +} + MetaKeyBindingAction meta_prefs_get_keybinding_action (const char *name) { diff --git a/src/core/screen-private.h b/src/core/screen-private.h index 52007cbaa..49867f275 100644 --- a/src/core/screen-private.h +++ b/src/core/screen-private.h @@ -82,6 +82,9 @@ 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; MetaWorkspace *active_workspace; @@ -179,6 +182,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, + gboolean delay); + 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 a50ca97d7..02a717313 100644 --- a/src/core/screen.c +++ b/src/core/screen.c @@ -770,6 +770,9 @@ meta_screen_new (MetaDisplay *display, screen->tab_popup = NULL; screen->ws_popup = NULL; + screen->tile_preview = NULL; + + screen->tile_preview_timeout_id = 0; screen->stack = meta_stack_new (screen); screen->stack_tracker = meta_stack_tracker_new (screen); @@ -867,6 +870,12 @@ meta_screen_free (MetaScreen *screen, if (screen->monitor_infos) g_free (screen->monitor_infos); + + 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); @@ -1743,6 +1752,69 @@ meta_screen_workspace_popup_destroy (MetaScreen *screen) } } +static gboolean +meta_screen_tile_preview_update_timeout (gpointer data) +{ + MetaScreen *screen = data; + MetaWindow *window = screen->display->grab_window; + gboolean composited = screen->display->compositor != NULL; + + screen->tile_preview_timeout_id = 0; + + if (!screen->tile_preview) + { + Window xwindow; + gulong create_serial; + + screen->tile_preview = meta_tile_preview_new (screen->number, + composited); + xwindow = meta_tile_preview_get_xwindow (screen->tile_preview, + &create_serial); + meta_stack_tracker_record_add (screen->stack_tracker, + xwindow, + create_serial); + } + + if (window + && !META_WINDOW_TILED (window) + && window->tile_mode != META_TILE_NONE) + { + MetaRectangle tile_rect; + + meta_window_get_current_tile_area (window, &tile_rect); + meta_tile_preview_show (screen->tile_preview, &tile_rect); + } + else + meta_tile_preview_hide (screen->tile_preview); + + return FALSE; +} + +#define TILE_PREVIEW_TIMEOUT_MS 200 + +void +meta_screen_tile_preview_update (MetaScreen *screen, + gboolean delay) +{ + if (delay) + { + if (screen->tile_preview_timeout_id > 0) + return; + + screen->tile_preview_timeout_id = + g_timeout_add (TILE_PREVIEW_TIMEOUT_MS, + meta_screen_tile_preview_update_timeout, + screen); + } + else + { + if (screen->tile_preview_timeout_id > 0) + g_source_remove (screen->tile_preview_timeout_id); + + meta_screen_tile_preview_update_timeout ((gpointer)screen); + } +} + MetaWindow* meta_screen_get_mouse_window (MetaScreen *screen, MetaWindow *not_this_one) diff --git a/src/core/window-private.h b/src/core/window-private.h index 207145ed4..b2c903f38 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -61,6 +61,12 @@ typedef enum { #define NUMBER_OF_QUEUES 3 +typedef enum { + META_TILE_NONE, + META_TILE_LEFT, + META_TILE_RIGHT +} MetaTileMode; + struct _MetaWindow { GObject parent_instance; @@ -122,6 +128,11 @@ struct _MetaWindow guint maximize_vertically_after_placement : 1; guint minimize_after_placement : 1; + /* The current or requested tile mode. If maximized_vertically is true, + * this is the current mode. If not, it is the mode which will be + * requested after the window grab is released */ + guint tile_mode : 2; + /* Whether we're shaded */ guint shaded : 1; @@ -398,8 +409,11 @@ struct _MetaWindowClass (w)->maximized_vertically) #define META_WINDOW_MAXIMIZED_VERTICALLY(w) ((w)->maximized_vertically) #define META_WINDOW_MAXIMIZED_HORIZONTALLY(w) ((w)->maximized_horizontally) +#define META_WINDOW_TILED(w) ((w)->maximized_vertically && \ + !(w)->maximized_horizontally && \ + (w)->tile_mode != META_TILE_NONE) #define META_WINDOW_ALLOWS_MOVE(w) ((w)->has_move_func && !(w)->fullscreen) -#define META_WINDOW_ALLOWS_RESIZE_EXCEPT_HINTS(w) ((w)->has_resize_func && !META_WINDOW_MAXIMIZED (w) && !(w)->fullscreen && !(w)->shaded) +#define META_WINDOW_ALLOWS_RESIZE_EXCEPT_HINTS(w) ((w)->has_resize_func && !META_WINDOW_MAXIMIZED (w) && !META_WINDOW_TILED(w) && !(w)->fullscreen && !(w)->shaded) #define META_WINDOW_ALLOWS_RESIZE(w) (META_WINDOW_ALLOWS_RESIZE_EXCEPT_HINTS (w) && \ (((w)->size_hints.min_width < (w)->size_hints.max_width) || \ ((w)->size_hints.min_height < (w)->size_hints.max_height))) @@ -563,6 +577,9 @@ void meta_window_get_work_area_for_monitor (MetaWindow *window, void meta_window_get_work_area_all_monitors (MetaWindow *window, MetaRectangle *area); +void meta_window_get_current_tile_area (MetaWindow *window, + MetaRectangle *tile_area); + gboolean meta_window_same_application (MetaWindow *window, MetaWindow *other_window); diff --git a/src/core/window.c b/src/core/window.c index c58a9c896..123435fa2 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -772,6 +772,7 @@ meta_window_new_with_attrs (MetaDisplay *display, window->require_on_single_monitor = TRUE; window->require_titlebar_visible = TRUE; window->on_all_workspaces = FALSE; + window->tile_mode = META_TILE_NONE; window->shaded = FALSE; window->initially_iconic = FALSE; window->minimized = FALSE; @@ -2970,7 +2971,7 @@ ensure_size_hints_satisfied (MetaRectangle *rect, static void meta_window_save_rect (MetaWindow *window) { - if (!(META_WINDOW_MAXIMIZED (window) || window->fullscreen)) + if (!(META_WINDOW_MAXIMIZED (window) || META_WINDOW_TILED (window) || window->fullscreen)) { /* save size/pos as appropriate args for move_resize */ if (!window->maximized_horizontally) @@ -3012,7 +3013,7 @@ force_save_user_window_placement (MetaWindow *window) static void save_user_window_placement (MetaWindow *window) { - if (!(META_WINDOW_MAXIMIZED (window) || window->fullscreen)) + if (!(META_WINDOW_MAXIMIZED (window) || META_WINDOW_TILED (window) || window->fullscreen)) { MetaRectangle user_rect; @@ -3082,6 +3083,7 @@ void meta_window_maximize (MetaWindow *window, MetaMaximizeFlags directions) { + MetaRectangle *saved_rect = NULL; gboolean maximize_horizontally, maximize_vertically; g_return_if_fail (!window->override_redirect); @@ -3120,9 +3122,16 @@ meta_window_maximize (MetaWindow *window, return; } + if (window->tile_mode != META_TILE_NONE) + { + saved_rect = &window->saved_rect; + + window->maximized_vertically = FALSE; + } + meta_window_maximize_internal (window, directions, - NULL); + saved_rect); if (window->display->compositor) { @@ -3148,6 +3157,67 @@ meta_window_maximize (MetaWindow *window, } } +static void +meta_window_tile (MetaWindow *window) +{ + /* Don't do anything if no tiling is requested */ + if (window->tile_mode == META_TILE_NONE) + return; + + meta_window_maximize_internal (window, META_MAXIMIZE_VERTICAL, NULL); + meta_screen_tile_preview_update (window->screen, FALSE); + + if (window->display->compositor) + { + MetaRectangle old_rect; + MetaRectangle new_rect; + + meta_window_get_outer_rect (window, &old_rect); + + meta_window_move_resize_now (window); + + meta_window_get_outer_rect (window, &new_rect); + meta_compositor_maximize_window (window->display->compositor, + window, + &old_rect, + &new_rect); + } + else + { + /* move_resize with new tiling constraints + */ + meta_window_queue (window, META_QUEUE_MOVE_RESIZE); + } +} + +static gboolean +meta_window_can_tile (MetaWindow *window) +{ + const MetaMonitorInfo *monitor; + MetaRectangle tile_area; + + if (!META_WINDOW_ALLOWS_RESIZE (window)) + return FALSE; + + monitor = meta_screen_get_current_monitor (window->screen); + meta_window_get_work_area_for_monitor (window, monitor->number, &tile_area); + + tile_area.width /= 2; + + if (window->frame) + { + MetaFrameGeometry fgeom; + + meta_frame_calc_geometry (window->frame, &fgeom); + + tile_area.width -= (fgeom.left_width + fgeom.right_width); + tile_area.height -= (fgeom.top_height + fgeom.bottom_height); + } + + return tile_area.width >= window->size_hints.min_width && + tile_area.height >= window->size_hints.min_height; +} + static void unmaximize_window_before_freeing (MetaWindow *window) { @@ -3188,6 +3258,14 @@ meta_window_unmaximize (MetaWindow *window, g_return_if_fail (!window->override_redirect); + /* Restore tiling if necessary */ + if (window->tile_mode != META_TILE_NONE) + { + window->maximized_horizontally = FALSE; + meta_window_tile (window); + return; + } + /* At least one of the two directions ought to be set */ unmaximize_horizontally = directions & META_MAXIMIZE_HORIZONTAL; unmaximize_vertically = directions & META_MAXIMIZE_VERTICAL; @@ -3233,17 +3311,6 @@ meta_window_unmaximize (MetaWindow *window, */ ensure_size_hints_satisfied (&target_rect, &window->size_hints); - /* When we unmaximize, if we're doing a mouse move also we could - * get the window suddenly jumping to the upper left corner of - * the workspace, since that's where it was when the grab op - * started. So we need to update the grab state. - */ - if (meta_grab_op_is_moving (window->display->grab_op) && - window->display->grab_window == window) - { - window->display->grab_anchor_window_pos = target_rect; - } - if (window->display->compositor) { MetaRectangle old_rect, new_rect; @@ -3277,6 +3344,19 @@ meta_window_unmaximize (MetaWindow *window, */ force_save_user_window_placement (window); + /* When we unmaximize, if we're doing a mouse move also we could + * get the window suddenly jumping to the upper left corner of + * the workspace, since that's where it was when the grab op + * started. So we need to update the grab state. We have to do + * it after the actual operation, as the window may have been moved + * by constraints. + */ + if (meta_grab_op_is_moving (window->display->grab_op) && + window->display->grab_window == window) + { + window->display->grab_anchor_window_pos = window->user_rect; + } + recalc_window_features (window); set_net_wm_state (window); } @@ -7637,20 +7717,56 @@ update_move (MetaWindow *window, if (dx == 0 && dy == 0) return; - /* shake loose (unmaximize) maximized window if dragged beyond the threshold - * in the Y direction. You can't pull a window loose via X motion. + /* Originally for detaching maximized windows, but we use this + * for the zones at the sides of the monitor where trigger tiling + * because it's about the right size */ - #define DRAG_THRESHOLD_TO_SHAKE_THRESHOLD_FACTOR 6 shake_threshold = meta_ui_get_drag_threshold (window->screen->ui) * DRAG_THRESHOLD_TO_SHAKE_THRESHOLD_FACTOR; - if (META_WINDOW_MAXIMIZED (window) && ABS (dy) >= shake_threshold) + if (meta_prefs_get_side_by_side_tiling () && + meta_window_can_tile (window)) + { + const MetaMonitorInfo *monitor; + MetaRectangle work_area; + + /* For tiling we are interested in the work area of the monitor where + * the pointer is located. + * Also see comment in meta_window_get_current_tile_area() + */ + monitor = meta_screen_get_current_monitor (window->screen); + meta_window_get_work_area_for_monitor (window, + monitor->number, + &work_area); + + if (y >= monitor->rect.y && + y < (monitor->rect.y + monitor->rect.height)) + { + /* check if cursor is near an edge of the work area */ + if (x >= monitor->rect.x && x < (work_area.x + shake_threshold)) + window->tile_mode = META_TILE_LEFT; + else if (x >= work_area.x + work_area.width - shake_threshold && + x < (monitor->rect.x + monitor->rect.width)) + window->tile_mode = META_TILE_RIGHT; + else + window->tile_mode = META_TILE_NONE; + } + } + + /* shake loose (unmaximize) maximized or tiled window if dragged beyond + * the threshold in the Y direction. Tiled windows can also be pulled + * loose via X motion. + */ + + if ((META_WINDOW_MAXIMIZED (window) && ABS (dy) >= shake_threshold) || + (META_WINDOW_TILED (window) && (MAX (ABS (dx), ABS (dy)) >= shake_threshold))) { double prop; /* Shake loose */ - window->shaken_loose = TRUE; + window->shaken_loose = !META_WINDOW_TILED (window); + window->tile_mode = META_TILE_NONE; /* move the unmaximized window to the cursor */ prop = @@ -7677,10 +7793,12 @@ update_move (MetaWindow *window, return; } + /* remaximize window on another monitor if window has been shaken * loose or it is still maximized (then move straight) */ - else if (window->shaken_loose || META_WINDOW_MAXIMIZED (window)) + else if ((window->shaken_loose || META_WINDOW_MAXIMIZED (window)) && + window->tile_mode == META_TILE_NONE) { const MetaMonitorInfo *wmonitor; MetaRectangle work_area; @@ -7734,10 +7852,17 @@ update_move (MetaWindow *window, } } + /* Delay showing the tile preview slightly to make it more unlikely to + * trigger it unwittingly, e.g. when shaking loose the window or moving + * it to another monitor. + */ + meta_screen_tile_preview_update (window->screen, + window->tile_mode != META_TILE_NONE); + meta_window_get_client_root_coords (window, &old); - /* Don't allow movement in the maximized directions */ - if (window->maximized_horizontally) + /* Don't allow movement in the maximized directions or while tiled */ + if (window->maximized_horizontally || META_WINDOW_TILED (window)) new_x = old.x; if (window->maximized_vertically) new_y = old.y; @@ -8106,7 +8231,9 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window, { if (meta_grab_op_is_moving (window->display->grab_op)) { - if (event->xbutton.root == window->screen->xroot) + if (window->tile_mode != META_TILE_NONE) + meta_window_tile (window); + else if (event->xbutton.root == window->screen->xroot) update_move (window, event->xbutton.state & ShiftMask, event->xbutton.x_root, event->xbutton.y_root); } @@ -8264,6 +8391,29 @@ meta_window_get_work_area_all_monitors (MetaWindow *window, window->desc, area->x, area->y, area->width, area->height); } +void +meta_window_get_current_tile_area (MetaWindow *window, + MetaRectangle *tile_area) +{ + const MetaMonitorInfo *monitor; + + g_return_if_fail (window->tile_mode != META_TILE_NONE); + + /* The definition of "current" of meta_window_get_work_area_current_monitor() + * and meta_screen_get_current_monitor() is slightly different: the former + * refers to the monitor which contains the largest part of the window, the + * latter to the one where the pointer is located. + */ + monitor = meta_screen_get_current_monitor (window->screen); + meta_window_get_work_area_for_monitor (window, monitor->number, tile_area); + + if (window->tile_mode == META_TILE_LEFT || + window->tile_mode == META_TILE_RIGHT) + tile_area->width /= 2; + + if (window->tile_mode == META_TILE_RIGHT) + tile_area->x += tile_area->width; +} gboolean meta_window_same_application (MetaWindow *window, diff --git a/src/include/core.h b/src/include/core.h index 54abbfc0d..045d9c5f6 100644 --- a/src/include/core.h +++ b/src/include/core.h @@ -116,6 +116,10 @@ void meta_core_user_focus (Display *xdisplay, Window frame_xwindow, guint32 timestamp); +void meta_core_lower_beneath_focus_window (Display *xdisplay, + Window xwindow, + guint32 timestamp); + void meta_core_minimize (Display *xdisplay, Window frame_xwindow); void meta_core_toggle_maximize (Display *xdisplay, diff --git a/src/include/prefs.h b/src/include/prefs.h index 77aab0cc9..521a5f199 100644 --- a/src/include/prefs.h +++ b/src/include/prefs.h @@ -60,6 +60,7 @@ typedef enum META_PREF_CURSOR_SIZE, META_PREF_COMPOSITING_MANAGER, META_PREF_RESIZE_WITH_RIGHT_BUTTON, + META_PREF_SIDE_BY_SIDE_TILING, META_PREF_FORCE_FULLSCREEN, META_PREF_CLUTTER_PLUGINS, META_PREF_LIVE_HIDDEN_WINDOWS, @@ -98,6 +99,7 @@ gboolean meta_prefs_get_auto_raise (void); int meta_prefs_get_auto_raise_delay (void); gboolean meta_prefs_get_gnome_accessibility (void); gboolean meta_prefs_get_gnome_animations (void); +gboolean meta_prefs_get_side_by_side_tiling (void); const char* meta_prefs_get_command (int i); diff --git a/src/include/tile-preview.h b/src/include/tile-preview.h new file mode 100644 index 000000000..24b4f0248 --- /dev/null +++ b/src/include/tile-preview.h @@ -0,0 +1,39 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* Meta tile preview */ + +/* + * Copyright (C) 2010 Florian Müllner + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#ifndef META_TILE_PREVIEW_H +#define META_TILE_PREVIEW_H + +#include "boxes.h" + +typedef struct _MetaTilePreview MetaTilePreview; + +MetaTilePreview *meta_tile_preview_new (int screen_number, + gboolean composited); +void meta_tile_preview_free (MetaTilePreview *preview); +void meta_tile_preview_show (MetaTilePreview *preview, + MetaRectangle *rect); +void meta_tile_preview_hide (MetaTilePreview *preview); +Window meta_tile_preview_get_xwindow (MetaTilePreview *preview, + gulong *create_serial); + +#endif /* META_TILE_PREVIEW_H */ diff --git a/src/include/ui.h b/src/include/ui.h index c66d06f80..89743d4e5 100644 --- a/src/include/ui.h +++ b/src/include/ui.h @@ -203,5 +203,6 @@ MetaUIDirection meta_ui_get_direction (void); GdkPixbuf *meta_ui_get_pixbuf_from_pixmap (Pixmap pmap); #include "tabpopup.h" +#include "tile-preview.h" #endif diff --git a/src/ui/tile-preview.c b/src/ui/tile-preview.c new file mode 100644 index 000000000..a9ef07d73 --- /dev/null +++ b/src/ui/tile-preview.c @@ -0,0 +1,262 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* Mutter tile-preview marks the area a window will *ehm* snap to */ + +/* + * Copyright (C) 2010 Florian Müllner + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include + +#include +#include + +#include "tile-preview.h" +#include "core.h" +#include "region.h" + +#define OUTLINE_WIDTH 5 /* frame width in non-composite case */ + + +struct _MetaTilePreview { + GtkWidget *preview_window; + gulong create_serial; + + GdkColor *preview_color; + guchar preview_alpha; + + MetaRectangle tile_rect; + + gboolean has_alpha: 1; +}; + +static gboolean +meta_tile_preview_expose (GtkWidget *widget, + GdkEventExpose *event, + gpointer user_data) +{ + MetaTilePreview *preview = user_data; + GdkWindow *window; + cairo_t *cr; + + window = gtk_widget_get_window (widget); + cr = gdk_cairo_create (window); + + cairo_set_line_width (cr, 1.0); + + if (preview->has_alpha) + { + /* Fill the preview area with a transparent color */ + cairo_set_source_rgba (cr, + (double)preview->preview_color->red / 0xFFFF, + (double)preview->preview_color->green / 0xFFFF, + (double)preview->preview_color->blue / 0xFFFF, + (double)preview->preview_alpha / 0xFF); + + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_paint (cr); + + /* Use the opaque color for the border */ + gdk_cairo_set_source_color (cr, preview->preview_color); + } + else + { + GtkStyle *style = gtk_widget_get_style (preview->preview_window); + + gdk_cairo_set_source_color (cr, &style->white); + + cairo_rectangle (cr, + OUTLINE_WIDTH - 0.5, OUTLINE_WIDTH - 0.5, + preview->tile_rect.width - 2 * (OUTLINE_WIDTH - 1) - 1, + preview->tile_rect.height - 2 * (OUTLINE_WIDTH - 1) - 1); + cairo_stroke (cr); + } + + cairo_rectangle (cr, + 0.5, 0.5, + preview->tile_rect.width - 1, + preview->tile_rect.height - 1); + cairo_stroke (cr); + + cairo_destroy (cr); + + return FALSE; +} + +static void +on_preview_window_style_set (GtkWidget *widget, + GtkStyle *previous, + gpointer user_data) +{ + MetaTilePreview *preview = user_data; + GtkStyle *style; + + style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), + "GtkWindow.GtkIconView", + "GtkWindow.GtkIconView", + GTK_TYPE_ICON_VIEW); + + gtk_style_get (style, GTK_TYPE_ICON_VIEW, + "selection-box-color", &preview->preview_color, + "selection-box-alpha", &preview->preview_alpha, + NULL); + if (!preview->preview_color) + { + GdkColor selection = style->base[GTK_STATE_SELECTED]; + preview->preview_color = gdk_color_copy (&selection); + } +} + +MetaTilePreview * +meta_tile_preview_new (int screen_number, + gboolean composited) +{ + MetaTilePreview *preview; + GdkColormap *rgba_colormap; + GdkScreen *screen; + + screen = gdk_display_get_screen (gdk_display_get_default (), screen_number); + rgba_colormap = gdk_screen_get_rgba_colormap (screen); + + preview = g_new (MetaTilePreview, 1); + + preview->preview_window = gtk_window_new (GTK_WINDOW_POPUP); + + gtk_window_set_screen (GTK_WINDOW (preview->preview_window), screen); + gtk_widget_set_app_paintable (preview->preview_window, TRUE); + + preview->preview_color = NULL; + preview->preview_alpha = 0xFF; + + preview->tile_rect.x = preview->tile_rect.y = 0; + preview->tile_rect.width = preview->tile_rect.height = 0; + + preview->has_alpha = rgba_colormap && composited; + + if (preview->has_alpha) + { + gtk_widget_set_colormap (preview->preview_window, rgba_colormap); + + g_signal_connect (preview->preview_window, "style-set", + G_CALLBACK (on_preview_window_style_set), preview); + } + + /* We make an assumption that XCreateWindow will be the first operation + * when calling gtk_widget_realize() (via gdk_window_new()), or that it + * is at least "close enough". + */ + preview->create_serial = XNextRequest (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); + gtk_widget_realize (preview->preview_window); + gdk_window_set_back_pixmap (gtk_widget_get_window (preview->preview_window), + NULL, FALSE); + + g_signal_connect (preview->preview_window, "expose-event", + G_CALLBACK (meta_tile_preview_expose), preview); + + return preview; +} + +void +meta_tile_preview_free (MetaTilePreview *preview) +{ + gtk_widget_destroy (preview->preview_window); + + if (preview->preview_color) + gdk_color_free (preview->preview_color); + + g_free (preview); +} + +void +meta_tile_preview_show (MetaTilePreview *preview, + MetaRectangle *tile_rect) +{ + GdkWindow *window; + GdkRectangle old_rect; + + if (gtk_widget_get_visible (preview->preview_window) + && 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 */ + + gtk_widget_show (preview->preview_window); + window = gtk_widget_get_window (preview->preview_window); + meta_core_lower_beneath_focus_window (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), + GDK_WINDOW_XWINDOW (window), + gtk_get_current_event_time ()); + + old_rect.x = old_rect.y = 0; + old_rect.width = preview->tile_rect.width; + old_rect.height = preview->tile_rect.height; + + gdk_window_invalidate_rect (window, &old_rect, FALSE); + + preview->tile_rect = *tile_rect; + + gdk_window_move_resize (window, + preview->tile_rect.x, preview->tile_rect.y, + preview->tile_rect.width, preview->tile_rect.height); + + if (!preview->has_alpha) + { + GdkRectangle outer_rect, inner_rect; + MetaRegion *outer_region, *inner_region; + GdkColor black; + + black = gtk_widget_get_style (preview->preview_window)->black; + gdk_window_set_background (window, &black); + + outer_rect.x = outer_rect.y = 0; + outer_rect.width = preview->tile_rect.width; + outer_rect.height = preview->tile_rect.height; + + inner_rect.x = OUTLINE_WIDTH; + inner_rect.y = OUTLINE_WIDTH; + inner_rect.width = outer_rect.width - 2 * OUTLINE_WIDTH; + inner_rect.height = outer_rect.height - 2 * OUTLINE_WIDTH; + + outer_region = meta_region_new_from_rectangle (&outer_rect); + inner_region = meta_region_new_from_rectangle (&inner_rect); + + meta_region_subtract (outer_region, inner_region); + meta_region_destroy (inner_region); + + gdk_window_shape_combine_region (window, outer_region, 0, 0); + meta_region_destroy (outer_region); + } +} + +void +meta_tile_preview_hide (MetaTilePreview *preview) +{ + gtk_widget_hide (preview->preview_window); +} + +Window +meta_tile_preview_get_xwindow (MetaTilePreview *preview, + gulong *create_serial) +{ + GdkWindow *window = gtk_widget_get_window (preview->preview_window); + + if (create_serial) + *create_serial = preview->create_serial; + + return GDK_WINDOW_XWINDOW (window); +}