From 63b5e65ebd535ca272cf7fbfabcc614dae0c7d34 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 26 Aug 2008 16:07:53 +0200 Subject: [PATCH] placement: deprecate in favor of awful.placement Signed-off-by: Julien Danjou --- CMakeLists.txt | 1 - awesomerc.lua.in | 2 - client.c | 84 ++++++++-------------- client.h | 2 +- common/draw.c | 69 ------------------ common/draw.h | 24 ------- common/tokenize.gperf | 1 - event.c | 3 +- placement.c | 159 ------------------------------------------ placement.h | 31 -------- structs.h | 3 - 11 files changed, 33 insertions(+), 346 deletions(-) delete mode 100644 placement.c delete mode 100644 placement.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a4972825d..0826759e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,6 @@ set(AWE_SRCS ${SOURCE_DIR}/layout.c ${SOURCE_DIR}/lua.c ${SOURCE_DIR}/mouse.c - ${SOURCE_DIR}/placement.c ${SOURCE_DIR}/screen.c ${SOURCE_DIR}/stack.c ${SOURCE_DIR}/statusbar.c diff --git a/awesomerc.lua.in b/awesomerc.lua.in index fa2d03424..3f201dce9 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -366,8 +366,6 @@ end) -- Hook function to execute when a new client appears. awful.hooks.manage.register(function (c) - -- Set floating placement to be smart! - c.floating_placement = "smart" if use_titlebar then -- Add a titlebar awful.titlebar.add(c, { modkey = modkey }) diff --git a/client.c b/client.c index 7e6e6d81f..ae68f7d35 100644 --- a/client.c +++ b/client.c @@ -40,7 +40,6 @@ #include "common/atoms.h" extern awesome_t globalconf; -extern const name_func_link_t FloatingPlacementList[]; /** Create a new client userdata. * \param L The Lua VM state. @@ -389,8 +388,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen) xcb_get_property_cookie_t ewmh_icon_cookie; client_t *c, *t = NULL; xcb_window_t trans; - bool rettrans, retloadprops, is_size_hints; - xcb_size_hints_t size_hints; + bool rettrans, retloadprops; const uint32_t select_input_val[] = { XCB_EVENT_MASK_STRUCTURE_NOTIFY @@ -428,7 +426,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen) c->icon = ewmh_window_icon_get_reply(ewmh_icon_cookie); /* update hints */ - is_size_hints = client_updatesizehints(c, &size_hints); + client_updatesizehints(c); client_updatewmhints(c); /* Try to load props if any */ @@ -470,18 +468,6 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen) /* call hook */ luaA_client_userdata_new(globalconf.L, c); luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0); - - if(c->floating_placement - && !retloadprops - && is_size_hints - && !(size_hints.flags & (XCB_SIZE_HINT_US_POSITION - | XCB_SIZE_HINT_P_POSITION))) - { - if(c->isfloating) - client_resize(c, c->floating_placement(c), false); - else - c->f_geometry = c->floating_placement(c); - } } /** Compute client geometry with respect to its geometry hints. @@ -891,63 +877,65 @@ client_updatewmhints(client_t *c) * \param c The client. * \return A pointer to a xcb_size_hints_t. */ -bool -client_updatesizehints(client_t *c, xcb_size_hints_t *size_hints) +void +client_updatesizehints(client_t *c) { + xcb_size_hints_t size_hints; + if(!xcb_get_wm_normal_hints_reply(globalconf.connection, xcb_get_wm_normal_hints_unchecked(globalconf.connection, c->win), - size_hints, NULL)) - return false; + &size_hints, NULL)) + return; - if((size_hints->flags & XCB_SIZE_HINT_P_SIZE)) + if((size_hints.flags & XCB_SIZE_HINT_P_SIZE)) { - c->basew = size_hints->base_width; - c->baseh = size_hints->base_height; + c->basew = size_hints.base_width; + c->baseh = size_hints.base_height; } - else if((size_hints->flags & XCB_SIZE_HINT_P_MIN_SIZE)) + else if((size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)) { - c->basew = size_hints->min_width; - c->baseh = size_hints->min_height; + c->basew = size_hints.min_width; + c->baseh = size_hints.min_height; } else c->basew = c->baseh = 0; - if((size_hints->flags & XCB_SIZE_HINT_P_RESIZE_INC)) + if((size_hints.flags & XCB_SIZE_HINT_P_RESIZE_INC)) { - c->incw = size_hints->width_inc; - c->inch = size_hints->height_inc; + c->incw = size_hints.width_inc; + c->inch = size_hints.height_inc; } else c->incw = c->inch = 0; - if((size_hints->flags & XCB_SIZE_HINT_P_MAX_SIZE)) + if((size_hints.flags & XCB_SIZE_HINT_P_MAX_SIZE)) { - c->maxw = size_hints->max_width; - c->maxh = size_hints->max_height; + c->maxw = size_hints.max_width; + c->maxh = size_hints.max_height; } else c->maxw = c->maxh = 0; - if((size_hints->flags & XCB_SIZE_HINT_P_MIN_SIZE)) + if((size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)) { - c->minw = size_hints->min_width; - c->minh = size_hints->min_height; + c->minw = size_hints.min_width; + c->minh = size_hints.min_height; } - else if((size_hints->flags & XCB_SIZE_HINT_BASE_SIZE)) + else if((size_hints.flags & XCB_SIZE_HINT_BASE_SIZE)) { - c->minw = size_hints->base_width; - c->minh = size_hints->base_height; + c->minw = size_hints.base_width; + c->minh = size_hints.base_height; } else c->minw = c->minh = 0; - if((size_hints->flags & XCB_SIZE_HINT_P_ASPECT)) + if((size_hints.flags & XCB_SIZE_HINT_P_ASPECT)) { - c->minax = size_hints->min_aspect_num; - c->minay = size_hints->min_aspect_den; - c->maxax = size_hints->max_aspect_num; - c->maxay = size_hints->max_aspect_den; + c->minax = size_hints.min_aspect_num; + c->minay = size_hints.min_aspect_den; + c->maxax = size_hints.max_aspect_num; + c->maxay = size_hints.max_aspect_den; } else c->minax = c->maxax = c->minay = c->maxay = 0; @@ -959,7 +947,6 @@ client_updatesizehints(client_t *c, xcb_size_hints_t *size_hints) c->hassizehints = !(!c->basew && !c->baseh && !c->incw && !c->inch && !c->maxw && !c->maxh && !c->minw && !c->minh && !c->minax && !c->maxax && !c->minax && !c->minay); - return true; } /** Kill a client via a WM_DELETE_WINDOW request or XKillClient if not @@ -1324,10 +1311,6 @@ luaA_client_newindex(lua_State *L) a_iso2utf8(&(*c)->name, buf, len); widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS); break; - case A_TK_FLOATING_PLACEMENT: - (*c)->floating_placement = name_func_lookup(luaL_checkstring(L, 3), - FloatingPlacementList); - break; case A_TK_SCREEN: if(globalconf.screens_info->xinerama_is_active) { @@ -1434,7 +1417,6 @@ luaA_client_newindex(lua_State *L) * \lfield role The window role, if available. * \lfield machine The machine client is running on. * \lfield icon_name The client name when iconified. - * \lfield floating_placement The floating placement used for this client. * \lfield screen Client screen number. * \lfield hide Define if the client must be hidden, i.e. never mapped. * \lfield icon_path Path to the icon used to identify. @@ -1525,10 +1507,6 @@ luaA_client_index(lua_State *L) lua_pushlstring(L, value, slen); p_delete(&value); break; - case A_TK_FLOATING_PLACEMENT: - lua_pushstring(L, name_func_rlookup((*c)->floating_placement, - FloatingPlacementList)); - break; case A_TK_SCREEN: lua_pushnumber(L, 1 + (*c)->screen); break; diff --git a/client.h b/client.h index ad7cedfa9..f60f74f17 100644 --- a/client.h +++ b/client.h @@ -46,7 +46,7 @@ area_t client_geometry_hints(client_t *, area_t); bool client_resize(client_t *, area_t, bool); void client_unmanage(client_t *); void client_updatewmhints(client_t *); -bool client_updatesizehints(client_t *, xcb_size_hints_t *); +void client_updatesizehints(client_t *); bool client_updatetitle(client_t *); void client_saveprops_tags(client_t *); void client_kill(client_t *); diff --git a/common/draw.c b/common/draw.c index 205d6118c..f16010e5c 100644 --- a/common/draw.c +++ b/common/draw.c @@ -1238,73 +1238,4 @@ xcolor_init_reply(xcb_connection_t *conn, return false; } -/** Remove a area from a list of them, - * spliting the space between several area that can overlap - * \param areas Array of areas. - * \param elem Area to remove. - */ -void -area_array_remove(area_array_t *areas, area_t elem) -{ - /* loop from the end because: - * (1) we remove elements ; - * (2) the one we add to the end are okay wrt the invariants - */ - for(int i = areas->len - 1; i >= 0; i--) - if(area_intersect_area(areas->tab[i], elem)) - { - /* remove it from the list */ - area_t r = area_array_take(areas, i); - area_t inter = area_get_intersect_area(r, elem); - - if(AREA_LEFT(inter) > AREA_LEFT(r)) - { - area_t extra = - { - .x = r.x, - .y = r.y, - .width = AREA_LEFT(inter) - AREA_LEFT(r), - .height = r.height, - }; - area_array_append(areas, extra); - } - - if(AREA_TOP(inter) > AREA_TOP(r)) - { - area_t extra = - { - .x = r.x, - .y = r.y, - .width = r.width, - .height = AREA_TOP(inter) - AREA_TOP(r), - }; - area_array_append(areas, extra); - } - - if(AREA_RIGHT(inter) < AREA_RIGHT(r)) - { - area_t extra = - { - .x = AREA_RIGHT(inter), - .y = r.y, - .width = AREA_RIGHT(r) - AREA_RIGHT(inter), - .height = r.height, - }; - area_array_append(areas, extra); - } - - if(AREA_BOTTOM(inter) < AREA_BOTTOM(r)) - { - area_t extra = - { - .x = r.x, - .y = AREA_BOTTOM(inter), - .width = r.width, - .height = AREA_BOTTOM(r) - AREA_BOTTOM(inter), - }; - area_array_append(areas, extra); - } - } -} - // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/draw.h b/common/draw.h index 39f7eebb5..8ee88c6da 100644 --- a/common/draw.h +++ b/common/draw.h @@ -78,28 +78,6 @@ DO_ARRAY(area_t, area, DO_NOTHING) #define AREA_RIGHT(a) ((a).x + (a).width) #define AREA_BOTTOM(a) ((a).y + (a).height) -static inline bool -area_intersect_area(area_t a, area_t b) -{ - return (b.x < a.x + a.width - && b.x + b.width > a.x - && b.y < a.y + a.height - && b.y + b.height > a.y); -} - -static inline area_t -area_get_intersect_area(area_t a, area_t b) -{ - area_t g; - - g.x = MAX(a.x, b.x); - g.y = MAX(a.y, b.y); - g.width = MIN(a.x + a.width, b.x + b.width) - g.x; - g.height = MIN(a.y + a.height, b.y + b.height) - g.y; - - return g; -} - typedef struct { PangoFontDescription *desc; @@ -242,8 +220,6 @@ xcolor_init_request_t xcolor_init_unchecked(xcb_connection_t *, xcolor_t *, int, bool xcolor_init_reply(xcb_connection_t *, xcolor_init_request_t); -void area_array_remove(area_array_t *, area_t); - static inline void draw_parser_data_init(draw_parser_data_t *pdata) { diff --git a/common/tokenize.gperf b/common/tokenize.gperf index 229a55d31..faa4e8b27 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -17,7 +17,6 @@ coords fg flex floating -floating_placement focus fullscreen gap diff --git a/event.c b/event.c index 8aa0dadb7..3270c955b 100644 --- a/event.c +++ b/event.c @@ -632,7 +632,6 @@ event_handle_propertynotify(void *data __attribute__ ((unused)), { client_t *c; xembed_window_t *emwin; - xcb_size_hints_t size_hints; if(ev->state == XCB_PROPERTY_DELETE) return 0; /* ignore */ @@ -654,7 +653,7 @@ event_handle_propertynotify(void *data __attribute__ ((unused)), } } else if (ev->atom == WM_NORMAL_HINTS) - client_updatesizehints(c, &size_hints); + client_updatesizehints(c); else if (ev->atom == WM_HINTS) client_updatewmhints(c); else if(ev->atom == WM_NAME || ev->atom == _NET_WM_NAME) diff --git a/placement.c b/placement.c deleted file mode 100644 index 066feeb8d..000000000 --- a/placement.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * placement.c - client placement management - * - * Copyright © 2008 Julien Danjou - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "placement.h" -#include "screen.h" -#include "client.h" -#include "titlebar.h" -#include "layouts/floating.h" - -extern awesome_t globalconf; - -const name_func_link_t FloatingPlacementList[] = -{ - { "smart", placement_smart }, - { "under_mouse", placement_under_mouse }, - { NULL, NULL } -}; - -static area_t -placement_fix_offscreen(area_t geometry, int screen) -{ - area_t screen_geometry; - - screen_geometry = screen_area_get(&globalconf.screens[screen].geometry, - globalconf.screens[screen].statusbar, - &globalconf.screens[screen].padding); - - /* fix offscreen */ - if(AREA_RIGHT(geometry) > AREA_RIGHT(screen_geometry)) - geometry.x = screen_geometry.x + screen_geometry.width - geometry.width; - else if(AREA_LEFT(geometry) < AREA_LEFT(screen_geometry)) - geometry.x = screen_geometry.x; - - if(AREA_BOTTOM(geometry) > AREA_BOTTOM(screen_geometry)) - geometry.y = screen_geometry.y + screen_geometry.height - geometry.height; - else if(AREA_TOP(geometry) < AREA_TOP(screen_geometry)) - geometry.y = screen_geometry.y; - - return geometry; -} - -/** Compute smart coordinates for a client window - * \param c The client to place. - * \return new geometry - */ -area_t -placement_smart(client_t *c) -{ - client_t *client; - area_t newgeometry = { 0, 0, 0, 0 }; - area_t screen_geometry; - area_array_t areas; - bool found = false; - layout_t *layout; - int i; - - area_array_init(&areas); - screen_geometry = screen_area_get(&globalconf.screens[c->screen].geometry, - globalconf.screens[c->screen].statusbar, - &globalconf.screens[c->screen].padding); - - layout = layout_get_current(c->screen); - area_array_append(&areas, screen_geometry); - - for(client = globalconf.clients; client; client = client->next) - if(client != c && (client->isfloating || layout == layout_floating) - && client_isvisible(client, c->screen)) - { - newgeometry = client->f_geometry; - newgeometry = titlebar_geometry_add(c->titlebar, c->border, newgeometry); - area_array_remove(&areas, newgeometry); - } - - newgeometry.x = c->f_geometry.x; - newgeometry.y = c->f_geometry.y; - newgeometry.width = 0; - newgeometry.height = 0; - - for(i = areas.len - 1; i >= 0; i--) - { - area_t *r = &areas.tab[i]; - - if(r->width >= c->f_geometry.width && r->height >= c->f_geometry.height - && r->width * r->height > newgeometry.width * newgeometry.height) - { - found = true; - newgeometry = *r; - } - } - - /* we did not found a space with enough space for our size: - * just take the biggest available and go in */ - if(!found) - for(i = 0; i < areas.len; i++) - { - area_t *r = &areas.tab[i]; - if(r->width * r->height > newgeometry.width * newgeometry.height) - newgeometry = *r; - } - - /* restore height and width */ - newgeometry.width = c->f_geometry.width; - newgeometry.height = c->f_geometry.height; - - newgeometry = titlebar_geometry_add(c->titlebar, c->border, newgeometry); - newgeometry = placement_fix_offscreen(newgeometry, c->screen); - newgeometry = titlebar_geometry_remove(c->titlebar, c->border, newgeometry); - - area_array_wipe(&areas); - return newgeometry; -} - -/** Compute placement for a window centered under the mouse. - * \param c The client. - * \return The proposed geometry. - */ -area_t -placement_under_mouse(client_t *c) -{ - xcb_query_pointer_cookie_t qp_c; - xcb_query_pointer_reply_t *qp_r; - area_t finalgeometry = c->f_geometry; - - qp_c = xcb_query_pointer_unchecked(globalconf.connection, - xutil_screen_get(globalconf.connection, - c->phys_screen)->root); - if((qp_r = xcb_query_pointer_reply(globalconf.connection, qp_c, NULL))) - { - finalgeometry.x = qp_r->root_x - c->f_geometry.width / 2; - finalgeometry.y = qp_r->root_y - c->f_geometry.height / 2; - - p_delete(&qp_r); - } - - finalgeometry = titlebar_geometry_add(c->titlebar, c->border, finalgeometry); - finalgeometry = placement_fix_offscreen(finalgeometry, c->screen); - finalgeometry = titlebar_geometry_remove(c->titlebar, c->border, finalgeometry); - - return finalgeometry; -} -// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/placement.h b/placement.h deleted file mode 100644 index 7c51dc5ba..000000000 --- a/placement.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * placement.h - client placement management header - * - * Copyright © 2008 Julien Danjou - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef AWESOME_PLACEMENT_H -#define AWESOME_PLACEMENT_H - -#include "structs.h" - -floating_placement_t placement_smart; -floating_placement_t placement_under_mouse; - -#endif -// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/structs.h b/structs.h index 0f969f271..f12ba0efd 100644 --- a/structs.h +++ b/structs.h @@ -64,7 +64,6 @@ typedef struct titlebar_t titlebar_t; typedef struct client_node_t client_node_t; typedef struct _tag_t tag_t; typedef struct tag_client_node_t tag_client_node_t; -typedef area_t (floating_placement_t)(client_t *); typedef widget_t *(widget_constructor_t)(alignment_t); typedef void (widget_destructor_t)(widget_t *); typedef struct awesome_t awesome_t; @@ -314,8 +313,6 @@ struct client_t titlebar_t *titlebar; /** Button bindings */ button_array_t buttons; - /** Floating window placement algo */ - floating_placement_t *floating_placement; /** Icon */ netwm_icon_t *icon; /** Next and previous clients */