From 50982fc0827a7a1868e23fc7124db1a38adfe275 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 21 Jul 2015 15:16:37 +0200 Subject: [PATCH 1/2] client_resize_do: prefer client's current screen In case of an overlapping screen configuration, prefer the client's current screen. Without this, clients would be moved to the first matching screen. --- objects/client.c | 5 ++++- objects/screen.c | 19 +++++++++++++++---- objects/screen.h | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/objects/client.c b/objects/client.c index e58d2b26f..7f39eaed5 100644 --- a/objects/client.c +++ b/objects/client.c @@ -795,7 +795,10 @@ client_resize_do(client_t *c, area_t geometry, bool force_notice, bool honor_hin lua_State *L = globalconf_get_lua_State(); bool send_notice = force_notice; bool hide_titlebars = c->fullscreen; - screen_t *new_screen = screen_getbycoord(geometry.x, geometry.y); + + screen_t *new_screen = c->screen; + if(!screen_coord_in_screen(new_screen, geometry.x, geometry.y)) + new_screen = screen_getbycoord(geometry.x, geometry.y); if (honor_hints) geometry = client_apply_size_hints(c, geometry); diff --git a/objects/screen.c b/objects/screen.c index 5f3af3549..5f7ab3902 100644 --- a/objects/screen.c +++ b/objects/screen.c @@ -285,8 +285,7 @@ screen_scan(void) screen_scan_x11(); } -/** Return the Xinerama screen number where the coordinates belongs to. - * \param screen The logical screen number. +/** Return the first screen number where the coordinates belong to. * \param x X coordinate * \param y Y coordinate * \return Screen pointer or screen param if no match or no multi-head. @@ -295,14 +294,26 @@ screen_t * screen_getbycoord(int x, int y) { foreach(s, globalconf.screens) - if((x < 0 || (x >= (*s)->geometry.x && x < (*s)->geometry.x + (*s)->geometry.width)) - && (y < 0 || (y >= (*s)->geometry.y && y < (*s)->geometry.y + (*s)->geometry.height))) + if(screen_coord_in_screen(*s, x, y)) return *s; /* No screen found, let's be creative. */ return globalconf.screens.tab[0]; } +/** Are the given coordinates in a given screen? + * \param screen The logical screen number. + * \param x X coordinate + * \param y Y coordinate + * \return True if the X/Y coordinates are in the given screen. + */ +bool +screen_coord_in_screen(screen_t *s, int x, int y) +{ + return (x < 0 || (x >= s->geometry.x && x < s->geometry.x + s->geometry.width)) + && (y < 0 || (y >= s->geometry.y && y < s->geometry.y + s->geometry.height)); +} + /** Get screens info. * \param screen Screen. * \param strut Honor windows strut. diff --git a/objects/screen.h b/objects/screen.h index 1e1e4c7cc..009c64d4d 100644 --- a/objects/screen.h +++ b/objects/screen.h @@ -43,6 +43,7 @@ ARRAY_FUNCS(screen_t *, screen, DO_NOTHING) void screen_class_setup(lua_State *L); void screen_scan(void); screen_t *screen_getbycoord(int, int); +bool screen_coord_in_screen(screen_t *, int, int); int screen_get_index(screen_t *); area_t display_area_get(void); void screen_client_moveto(client_t *, screen_t *, bool); From 27fb1707444b7767e569bb43cad5ab6402b8224b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 25 Jul 2015 20:12:45 +0200 Subject: [PATCH 2/2] screen_getbycoord: fallback to nearest screen This removes the handling of negative x/y from `screen_coord_in_screen`, which was added in 0f840d2e and does not make sense in screen_coord_in_screen. Ref: https://github.com/blueyed/awesome/commit/50982fc0827a7a1868e23fc7124db1a38adfe275#commitcomment-12358053. Ref: https://github.com/awesomeWM/awesome/pull/331. --- objects/screen.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/objects/screen.c b/objects/screen.c index 5f7ab3902..eeb8385f3 100644 --- a/objects/screen.c +++ b/objects/screen.c @@ -35,6 +35,7 @@ #include "objects/client.h" #include "objects/drawin.h" +#include #include #include @@ -297,8 +298,19 @@ screen_getbycoord(int x, int y) if(screen_coord_in_screen(*s, x, y)) return *s; - /* No screen found, let's be creative. */ - return globalconf.screens.tab[0]; + /* No screen found, find nearest screen. */ + screen_t * nearest_screen = globalconf.screens.tab[0]; + int nearest_dist = INT_MAX; + foreach(s, globalconf.screens) + { + int dist = sqrt(pow((*s)->geometry.x - x, 2) + pow((*s)->geometry.y - y, 2)); + if( dist < nearest_dist ) + { + nearest_dist = dist; + nearest_screen = (*s); + } + } + return nearest_screen; } /** Are the given coordinates in a given screen? @@ -310,8 +322,8 @@ screen_getbycoord(int x, int y) bool screen_coord_in_screen(screen_t *s, int x, int y) { - return (x < 0 || (x >= s->geometry.x && x < s->geometry.x + s->geometry.width)) - && (y < 0 || (y >= s->geometry.y && y < s->geometry.y + s->geometry.height)); + return (x >= s->geometry.x && x < s->geometry.x + s->geometry.width) + && (y >= s->geometry.y && y < s->geometry.y + s->geometry.height); } /** Get screens info.