2008-02-13 18:04:20 +01:00
|
|
|
/*
|
|
|
|
* placement.c - client placement management
|
|
|
|
*
|
|
|
|
* Copyright © 2008 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-03-27 16:05:37 +01:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
|
2008-02-13 18:04:20 +01:00
|
|
|
#include "placement.h"
|
|
|
|
#include "screen.h"
|
|
|
|
#include "client.h"
|
2008-03-25 14:45:13 +01:00
|
|
|
#include "titlebar.h"
|
2008-04-03 09:04:57 +02:00
|
|
|
#include "layouts/floating.h"
|
2008-02-13 18:04:20 +01:00
|
|
|
|
|
|
|
extern AwesomeConf globalconf;
|
|
|
|
|
|
|
|
name_func_link_t FloatingPlacementList[] =
|
|
|
|
{
|
|
|
|
{ "smart", placement_smart },
|
2008-02-13 18:14:34 +01:00
|
|
|
{ "under_mouse", placement_under_mouse },
|
2008-02-13 18:23:32 +01:00
|
|
|
{ NULL, NULL }
|
2008-02-13 18:04:20 +01:00
|
|
|
};
|
|
|
|
|
2008-03-14 09:37:25 +01:00
|
|
|
static area_t
|
|
|
|
placement_fix_offscreen(area_t geometry, int screen, int border)
|
2008-02-13 18:14:34 +01:00
|
|
|
{
|
2008-03-17 19:26:28 +01:00
|
|
|
area_t screen_geometry;
|
2008-02-13 18:14:34 +01:00
|
|
|
|
|
|
|
screen_geometry = screen_get_area(screen,
|
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
|
|
|
|
|
|
|
/* fix offscreen */
|
2008-03-17 19:26:28 +01:00
|
|
|
if(AREA_RIGHT(geometry) > AREA_RIGHT(screen_geometry))
|
|
|
|
geometry.x = screen_geometry.x + screen_geometry.width - (geometry.width + 2 * border);
|
|
|
|
else if(AREA_LEFT(geometry) < AREA_LEFT(screen_geometry))
|
|
|
|
geometry.x = screen_geometry.x;
|
2008-02-13 18:14:34 +01:00
|
|
|
|
2008-03-17 19:26:28 +01:00
|
|
|
if(AREA_BOTTOM(geometry) > AREA_BOTTOM(screen_geometry))
|
|
|
|
geometry.y = screen_geometry.y + screen_geometry.height - (geometry.height + 2 * border);
|
|
|
|
else if(AREA_TOP(geometry) < AREA_TOP(screen_geometry))
|
|
|
|
geometry.y = screen_geometry.y;
|
2008-02-13 18:14:34 +01:00
|
|
|
|
2008-03-17 19:26:28 +01:00
|
|
|
return geometry;
|
2008-02-13 18:14:34 +01:00
|
|
|
}
|
|
|
|
|
2008-02-13 18:04:20 +01:00
|
|
|
/** Compute smart coordinates for a client window
|
|
|
|
* \param geometry current/requested client geometry
|
|
|
|
* \param screen screen used
|
|
|
|
* \return new geometry
|
|
|
|
*/
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t
|
2008-04-11 11:35:11 +02:00
|
|
|
placement_smart(client_t *c)
|
2008-02-13 18:04:20 +01:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *client;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t newgeometry = { 0, 0, 0, 0, NULL, NULL };
|
|
|
|
area_t *screen_geometry, *arealist = NULL, *r;
|
2008-03-21 16:50:17 +01:00
|
|
|
bool found = false;
|
2008-05-20 15:39:47 +02:00
|
|
|
LayoutArrange *layout;
|
2008-02-13 18:04:20 +01:00
|
|
|
|
2008-03-14 09:37:25 +01:00
|
|
|
screen_geometry = p_new(area_t, 1);
|
2008-02-13 18:04:20 +01:00
|
|
|
|
2008-03-17 19:26:28 +01:00
|
|
|
*screen_geometry = screen_get_area(c->screen,
|
|
|
|
globalconf.screens[c->screen].statusbar,
|
|
|
|
&globalconf.screens[c->screen].padding);
|
2008-02-13 18:04:20 +01:00
|
|
|
|
2008-04-03 09:04:57 +02:00
|
|
|
layout = layout_get_current(c->screen);
|
|
|
|
|
2008-02-13 18:14:34 +01:00
|
|
|
area_list_push(&arealist, screen_geometry);
|
2008-02-13 18:04:20 +01:00
|
|
|
|
2008-03-17 19:26:28 +01:00
|
|
|
for(client = globalconf.clients; client; client = client->next)
|
2008-05-20 15:39:47 +02:00
|
|
|
if((client->isfloating || layout == layout_floating)
|
2008-04-03 09:04:57 +02:00
|
|
|
&& client_isvisible(client, c->screen))
|
2008-02-13 18:04:20 +01:00
|
|
|
{
|
2008-03-17 19:26:28 +01:00
|
|
|
newgeometry = client->f_geometry;
|
|
|
|
newgeometry.width += 2 * client->border;
|
|
|
|
newgeometry.height += 2 * client->border;
|
2008-03-25 14:45:13 +01:00
|
|
|
newgeometry = titlebar_geometry_add(&client->titlebar, newgeometry);
|
2008-02-13 18:04:20 +01:00
|
|
|
area_list_remove(&arealist, &newgeometry);
|
|
|
|
}
|
|
|
|
|
2008-03-17 19:26:28 +01:00
|
|
|
newgeometry.x = c->f_geometry.x;
|
|
|
|
newgeometry.y = c->f_geometry.y;
|
2008-02-13 18:04:20 +01:00
|
|
|
newgeometry.width = 0;
|
|
|
|
newgeometry.height = 0;
|
|
|
|
|
|
|
|
for(r = arealist; r; r = r->next)
|
2008-03-17 19:26:28 +01:00
|
|
|
if(r->width >= c->f_geometry.width && r->height >= c->f_geometry.height
|
2008-02-13 18:04:20 +01:00
|
|
|
&& r->width * r->height > newgeometry.width * newgeometry.height)
|
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
found = true;
|
2008-02-13 18:04:20 +01:00
|
|
|
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(r = arealist; r; r = r->next)
|
|
|
|
if(r->width * r->height > newgeometry.width * newgeometry.height)
|
|
|
|
newgeometry = *r;
|
|
|
|
|
|
|
|
/* restore height and width */
|
2008-03-17 19:26:28 +01:00
|
|
|
newgeometry.width = c->f_geometry.width;
|
|
|
|
newgeometry.height = c->f_geometry.height;
|
|
|
|
|
2008-03-25 14:45:13 +01:00
|
|
|
newgeometry = titlebar_geometry_add(&c->titlebar, newgeometry);
|
2008-03-17 19:26:28 +01:00
|
|
|
newgeometry = placement_fix_offscreen(newgeometry, c->screen, c->border);
|
2008-03-27 10:38:33 +01:00
|
|
|
newgeometry = titlebar_geometry_remove(&c->titlebar, newgeometry);
|
2008-02-13 18:04:20 +01:00
|
|
|
|
|
|
|
area_list_wipe(&arealist);
|
|
|
|
|
|
|
|
return newgeometry;
|
|
|
|
}
|
|
|
|
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t
|
2008-04-11 11:35:11 +02:00
|
|
|
placement_under_mouse(client_t *c)
|
2008-02-13 18:14:34 +01:00
|
|
|
{
|
2008-04-10 11:38:35 +02:00
|
|
|
xcb_query_pointer_cookie_t qp_c;
|
|
|
|
xcb_query_pointer_reply_t *qp_r;
|
2008-03-17 19:26:28 +01:00
|
|
|
area_t finalgeometry = c->f_geometry;
|
2008-02-13 18:14:34 +01:00
|
|
|
|
2008-04-10 11:38:35 +02:00
|
|
|
qp_c = xcb_query_pointer(globalconf.connection,
|
|
|
|
xcb_aux_get_screen(globalconf.connection, c->phys_screen)->root);
|
|
|
|
if((qp_r = xcb_query_pointer_reply(globalconf.connection, qp_c, NULL)))
|
2008-02-13 18:14:34 +01:00
|
|
|
{
|
2008-04-10 11:38:35 +02:00
|
|
|
finalgeometry.x = qp_r->root_x - c->f_geometry.width / 2;
|
|
|
|
finalgeometry.y = qp_r->root_y - c->f_geometry.height / 2;
|
2008-03-30 15:46:58 +02:00
|
|
|
|
2008-04-10 11:38:35 +02:00
|
|
|
p_delete(&qp_r);
|
2008-02-13 18:14:34 +01:00
|
|
|
}
|
|
|
|
|
2008-03-25 14:45:13 +01:00
|
|
|
finalgeometry = titlebar_geometry_add(&c->titlebar, finalgeometry);
|
2008-03-17 19:26:28 +01:00
|
|
|
finalgeometry = placement_fix_offscreen(finalgeometry, c->screen, c->border);
|
2008-03-27 10:38:33 +01:00
|
|
|
finalgeometry = titlebar_geometry_remove(&c->titlebar, finalgeometry);
|
2008-02-13 18:14:34 +01:00
|
|
|
|
|
|
|
return finalgeometry;
|
|
|
|
}
|
2008-02-13 18:04:20 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|