From c5d1d2db62e1ed689692187f4e486084f0c69b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Mon, 21 Mar 2011 12:36:01 +0100 Subject: [PATCH] Add and export meta_window_move_to_monitor This is useful for DnD to another monitor in gnome-shell. In addition to a normal move it corrects the saved rect for maximized and fullscreened windows. https://bugzilla.gnome.org/show_bug.cgi?id=645032 --- src/core/window.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/meta/window.h | 1 + 2 files changed, 44 insertions(+) diff --git a/src/core/window.c b/src/core/window.c index 1aa13c5b3..7f43aa398 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -4776,6 +4776,49 @@ meta_window_move_frame (MetaWindow *window, meta_window_move (window, user_op, x, y); } +/** + * meta_window_move_to_monitor: + * @window: a #MetaWindow + * @monitor: desired monitor index + * + * Moves the window to the monitor with index @monitor, keeping + * the relative position of the window's top left corner. + */ +void +meta_window_move_to_monitor (MetaWindow *window, + int monitor) +{ + MetaRectangle old_area, new_area; + int rel_x, rel_y; + double scale_x, scale_y; + + if (monitor == window->monitor->number) + return; + + meta_window_get_work_area_for_monitor (window, + window->monitor->number, + &old_area); + meta_window_get_work_area_for_monitor (window, + monitor, + &new_area); + + rel_x = window->user_rect.x - old_area.x; + rel_y = window->user_rect.y - old_area.y; + scale_x = (double)new_area.width / old_area.width; + scale_y = (double)new_area.height / old_area.height; + + window->user_rect.x = new_area.x + rel_x * scale_x; + window->user_rect.y = new_area.y + rel_y * scale_y; + window->saved_rect.x = window->user_rect.x; + window->saved_rect.y = window->user_rect.y; + + meta_window_move_resize (window, FALSE, + window->user_rect.x, + window->user_rect.y, + window->user_rect.width, + window->user_rect.height); +} + void meta_window_move_resize (MetaWindow *window, gboolean user_op, diff --git a/src/meta/window.h b/src/meta/window.h index af5602c21..a1c4b75b8 100644 --- a/src/meta/window.h +++ b/src/meta/window.h @@ -95,6 +95,7 @@ gboolean meta_window_showing_on_its_workspace (MetaWindow *window); void meta_window_move(MetaWindow *window, gboolean user_op, int root_x_nw, int root_y_nw); void meta_window_move_frame(MetaWindow *window, gboolean user_op, int root_x_nw, int root_y_nw); +void meta_window_move_to_monitor (MetaWindow *window, int monitor); void meta_window_resize(MetaWindow *window, gboolean user_op, int w, int h); void meta_window_set_demands_attention (MetaWindow *window);