From d466c615ed067a04155143dd764ce2530c9da4ce Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 25 May 2002 16:30:14 +0000 Subject: [PATCH] Take Xinerama screen edges into consideration. 2002-05-25 Anders Carlsson * src/place.c: (get_vertical_edges), (get_horizontal_edges): Take Xinerama screen edges into consideration. * src/screen.c: (meta_rectangle_intersect), (meta_screen_get_xinerama_for_window): * src/screen.h: Add a new function that returns the xinerama monitor that a window is on. --- ChangeLog | 11 +++++++++ src/place.c | 22 +++++++++++++---- src/screen.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/screen.h | 2 ++ 4 files changed, 99 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index d25eb2959..24314e6f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-05-25 Anders Carlsson + + * src/place.c: (get_vertical_edges), (get_horizontal_edges): + Take Xinerama screen edges into consideration. + + * src/screen.c: (meta_rectangle_intersect), + (meta_screen_get_xinerama_for_window): + * src/screen.h: + Add a new function that returns the xinerama monitor that + a window is on. + 2002-05-24 Havoc Pennington * src/window.c (menu_callback): follow windows to their new diff --git a/src/place.c b/src/place.c index bcf9371e6..a9ffd6ba8 100644 --- a/src/place.c +++ b/src/place.c @@ -546,7 +546,7 @@ get_vertical_edges (MetaWindow *window, GSList *tmp; int n_windows; int *edges; - int i; + int i, j; int n_edges; MetaRectangle rect; MetaRectangle work_area; @@ -554,7 +554,7 @@ get_vertical_edges (MetaWindow *window, windows = get_windows_on_same_workspace (window, &n_windows); i = 0; - n_edges = n_windows * 2 + 4; /* 4 = workspace/screen edges */ + n_edges = n_windows * 2 + 4 + window->screen->n_xinerama_infos - 1; /* 4 = workspace/screen edges */ edges = g_new (int, n_edges); /* workspace/screen edges */ @@ -573,6 +573,13 @@ get_vertical_edges (MetaWindow *window, g_assert (i == 4); + /* Now get the xinerama screen edges */ + for (j = 0; j < window->screen->n_xinerama_infos - 1; j++) { + edges[i] = window->screen->xinerama_infos[j].x_origin + + window->screen->xinerama_infos[j].width; + ++i; + } + meta_window_get_outer_rect (window, &rect); /* get window edges */ @@ -612,7 +619,7 @@ get_horizontal_edges (MetaWindow *window, GSList *tmp; int n_windows; int *edges; - int i; + int i, j; int n_edges; MetaRectangle rect; MetaRectangle work_area; @@ -620,7 +627,7 @@ get_horizontal_edges (MetaWindow *window, windows = get_windows_on_same_workspace (window, &n_windows); i = 0; - n_edges = n_windows * 2 + 4; /* 4 = workspace/screen edges */ + n_edges = n_windows * 2 + 4 + window->screen->n_xinerama_infos - 1; /* 4 = workspace/screen edges */ edges = g_new (int, n_edges); /* workspace/screen edges */ @@ -638,6 +645,13 @@ get_horizontal_edges (MetaWindow *window, ++i; g_assert (i == 4); + + /* Now get the xinerama screen edges */ + for (j = 0; j < window->screen->n_xinerama_infos - 1; j++) { + edges[i] = window->screen->xinerama_infos[j].y_origin + + window->screen->xinerama_infos[j].height; + ++i; + } meta_window_get_outer_rect (window, &rect); diff --git a/src/screen.c b/src/screen.c index 7505ab29a..22a070eb5 100644 --- a/src/screen.c +++ b/src/screen.c @@ -800,6 +800,74 @@ meta_screen_focus_top_window (MetaScreen *screen, } } +static gboolean +meta_rectangle_intersect (MetaRectangle *src1, + MetaRectangle *src2, + MetaRectangle *dest) +{ + int dest_x, dest_y; + int dest_w, dest_h; + int return_val; + + g_return_val_if_fail (src1 != NULL, FALSE); + g_return_val_if_fail (src2 != NULL, FALSE); + g_return_val_if_fail (dest != NULL, FALSE); + + return_val = FALSE; + + dest_x = MAX (src1->x, src2->x); + dest_y = MAX (src1->y, src2->y); + dest_w = MIN (src1->x + src1->width, src2->x + src2->width) - dest_x; + dest_h = MIN (src1->y + src1->height, src2->y + src2->height) - dest_y; + + if (dest_w > 0 && dest_h > 0) + { + dest->x = dest_x; + dest->y = dest_y; + dest->width = dest_w; + dest->height = dest_h; + return_val = TRUE; + } + else + { + dest->width = 0; + dest->height = 0; + } + + return return_val; +} + +const MetaXineramaScreenInfo* +meta_screen_get_xinerama_for_window (MetaScreen *screen, + MetaWindow *window) +{ + int i; + int best_xinerama, xinerama_score; + + best_xinerama = 0; + xinerama_score = 0; + + for (i = 0; i < screen->n_xinerama_infos; i++) { + MetaRectangle dest, screen_info; + + screen_info.x = screen->xinerama_infos[i].x_origin; + screen_info.y = screen->xinerama_infos[i].y_origin; + screen_info.width = screen->xinerama_infos[i].width; + screen_info.height = screen->xinerama_infos[i].height; + + if (meta_rectangle_intersect (&screen_info, &window->rect, &dest)) + { + if (dest.width * dest.height > xinerama_score) + { + xinerama_score = dest.width * dest.height; + best_xinerama = i; + } + } + } + + return &screen->xinerama_infos[best_xinerama]; +} + const MetaXineramaScreenInfo* meta_screen_get_current_xinerama (MetaScreen *screen) { diff --git a/src/screen.h b/src/screen.h index ca84cf896..9ab5e43b8 100644 --- a/src/screen.h +++ b/src/screen.h @@ -95,6 +95,8 @@ void meta_screen_focus_top_window (MetaScreen *scree MetaWindow *not_this_one); const MetaXineramaScreenInfo* meta_screen_get_current_xinerama (MetaScreen *screen); +const MetaXineramaScreenInfo* meta_screen_get_xinerama_for_window (MetaScreen *screen, + MetaWindow *window); void meta_screen_update_workspace_layout (MetaScreen *screen);