floating placement can be chosen by config
This commit is contained in:
parent
4ff0dae17e
commit
1e3f3d9300
|
@ -112,6 +112,7 @@ AM_CPPFLAGS = $(XFT_CFLAGS) $(X_CFLAGS) $(CAIRO_CFLAGS) $(CONFUSE_CFLAGS) $(XRAN
|
||||||
bin_PROGRAMS += awesome
|
bin_PROGRAMS += awesome
|
||||||
awesome_SOURCES = \
|
awesome_SOURCES = \
|
||||||
client.c client.h \
|
client.c client.h \
|
||||||
|
placement.c placement.h \
|
||||||
common/awesome-version.c common/awesome-version.h \
|
common/awesome-version.c common/awesome-version.h \
|
||||||
focus.c focus.h \
|
focus.c focus.h \
|
||||||
common/draw.c common/draw.h \
|
common/draw.c common/draw.h \
|
||||||
|
|
72
client.c
72
client.c
|
@ -233,75 +233,6 @@ client_focus(Client *c, int screen, Bool raise)
|
||||||
globalconf.drop_events |= EnterWindowMask;
|
globalconf.drop_events |= EnterWindowMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute smart coordinates for a client window
|
|
||||||
* \param geometry current/requested client geometry
|
|
||||||
* \param screen screen used
|
|
||||||
* \return new geometry
|
|
||||||
*/
|
|
||||||
static Area
|
|
||||||
client_get_smart_geometry(Area geometry, int border, int screen)
|
|
||||||
{
|
|
||||||
Client *c;
|
|
||||||
Area newgeometry = { 0, 0, 0, 0, NULL };
|
|
||||||
Area *screen_geometry, *tmp, *arealist = NULL, *r;
|
|
||||||
Bool found = False;
|
|
||||||
|
|
||||||
screen_geometry = p_new(Area, 1);
|
|
||||||
tmp = p_new(Area, 1);
|
|
||||||
|
|
||||||
/* we need tmp because it may be free'd by in
|
|
||||||
* the area_list_remove process */
|
|
||||||
*screen_geometry = *tmp = screen_get_area(screen,
|
|
||||||
globalconf.screens[screen].statusbar,
|
|
||||||
&globalconf.screens[screen].padding);
|
|
||||||
|
|
||||||
area_list_push(&arealist, tmp);
|
|
||||||
|
|
||||||
for(c = globalconf.clients; c; c = c->next)
|
|
||||||
if(client_isvisible(c, screen))
|
|
||||||
{
|
|
||||||
newgeometry = c->f_geometry;
|
|
||||||
newgeometry.width += 2 * c->border;
|
|
||||||
newgeometry.height += 2 * c->border;
|
|
||||||
area_list_remove(&arealist, &newgeometry);
|
|
||||||
}
|
|
||||||
|
|
||||||
newgeometry.x = geometry.x;
|
|
||||||
newgeometry.y = geometry.y;
|
|
||||||
newgeometry.width = 0;
|
|
||||||
newgeometry.height = 0;
|
|
||||||
|
|
||||||
for(r = arealist; r; r = r->next)
|
|
||||||
if(r->width >= geometry.width && r->height >= 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(r = arealist; r; r = r->next)
|
|
||||||
if(r->width * r->height > newgeometry.width * newgeometry.height)
|
|
||||||
newgeometry = *r;
|
|
||||||
|
|
||||||
/* restore height and width */
|
|
||||||
newgeometry.width = geometry.width;
|
|
||||||
newgeometry.height = geometry.height;
|
|
||||||
|
|
||||||
/* fix offscreen */
|
|
||||||
if(AREA_RIGHT(newgeometry) > AREA_RIGHT(*screen_geometry))
|
|
||||||
newgeometry.x = screen_geometry->x + screen_geometry->width - (newgeometry.width + 2 * border);
|
|
||||||
|
|
||||||
if(AREA_BOTTOM(newgeometry) > AREA_BOTTOM(*screen_geometry))
|
|
||||||
newgeometry.y = screen_geometry->y + screen_geometry->height - (newgeometry.height + 2 * border);
|
|
||||||
area_list_wipe(&arealist);
|
|
||||||
p_delete(&screen_geometry);
|
|
||||||
|
|
||||||
return newgeometry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Manage a new client
|
/** Manage a new client
|
||||||
* \param w The window
|
* \param w The window
|
||||||
* \param wa Window attributes
|
* \param wa Window attributes
|
||||||
|
@ -400,7 +331,8 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
|
||||||
client_setfloating(c, rettrans || c->isfixed);
|
client_setfloating(c, rettrans || c->isfixed);
|
||||||
|
|
||||||
if(!(flags & (USPosition | PPosition)))
|
if(!(flags & (USPosition | PPosition)))
|
||||||
c->f_geometry = client_get_smart_geometry(c->f_geometry, c->border, c->screen);
|
c->f_geometry =
|
||||||
|
globalconf.screens[c->screen].floating_placement(c->f_geometry, c->border, c->screen);
|
||||||
|
|
||||||
XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
|
XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ cfg_opt_t general_opts[] =
|
||||||
CFG_BOOL((char *) "new_get_focus", cfg_true, CFGF_NONE),
|
CFG_BOOL((char *) "new_get_focus", cfg_true, CFGF_NONE),
|
||||||
CFG_STR((char *) "font", (char *) "vera-10", CFGF_NONE),
|
CFG_STR((char *) "font", (char *) "vera-10", CFGF_NONE),
|
||||||
CFG_INT((char *) "opacity_unfocused", -1, CFGF_NONE),
|
CFG_INT((char *) "opacity_unfocused", -1, CFGF_NONE),
|
||||||
|
CFG_STR((char *) "floating_placement", (char *) "smart", CFGF_NONE),
|
||||||
CFG_END()
|
CFG_END()
|
||||||
};
|
};
|
||||||
cfg_opt_t colors_opts[] =
|
cfg_opt_t colors_opts[] =
|
||||||
|
|
4
config.c
4
config.c
|
@ -62,6 +62,7 @@ typedef struct
|
||||||
extern const name_func_link_t UicbList[];
|
extern const name_func_link_t UicbList[];
|
||||||
extern const name_func_link_t WidgetList[];
|
extern const name_func_link_t WidgetList[];
|
||||||
extern const name_func_link_t LayoutList[];
|
extern const name_func_link_t LayoutList[];
|
||||||
|
extern const name_func_link_t FloatingPlacementList[];
|
||||||
|
|
||||||
/** Lookup for a key mask from its name
|
/** Lookup for a key mask from its name
|
||||||
* \param keyname Key name
|
* \param keyname Key name
|
||||||
|
@ -317,6 +318,9 @@ config_parse_screen(cfg_t *cfg, int screen)
|
||||||
virtscreen->font = XftFontOpenName(globalconf.display,
|
virtscreen->font = XftFontOpenName(globalconf.display,
|
||||||
phys_screen,
|
phys_screen,
|
||||||
cfg_getstr(cfg_general, "font"));
|
cfg_getstr(cfg_general, "font"));
|
||||||
|
virtscreen->floating_placement =
|
||||||
|
name_func_lookup(cfg_getstr(cfg_general, "floating_placement"),
|
||||||
|
FloatingPlacementList);
|
||||||
if(!virtscreen->font)
|
if(!virtscreen->font)
|
||||||
eprint("awesome: cannot init font\n");
|
eprint("awesome: cannot init font\n");
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "placement.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "client.h"
|
||||||
|
|
||||||
|
extern AwesomeConf globalconf;
|
||||||
|
|
||||||
|
name_func_link_t FloatingPlacementList[] =
|
||||||
|
{
|
||||||
|
{ "smart", placement_smart },
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Compute smart coordinates for a client window
|
||||||
|
* \param geometry current/requested client geometry
|
||||||
|
* \param screen screen used
|
||||||
|
* \return new geometry
|
||||||
|
*/
|
||||||
|
Area
|
||||||
|
placement_smart(Area geometry, int border, int screen)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
Area newgeometry = { 0, 0, 0, 0, NULL };
|
||||||
|
Area *screen_geometry, *tmp, *arealist = NULL, *r;
|
||||||
|
Bool found = False;
|
||||||
|
|
||||||
|
screen_geometry = p_new(Area, 1);
|
||||||
|
tmp = p_new(Area, 1);
|
||||||
|
|
||||||
|
/* we need tmp because it may be free'd by in
|
||||||
|
* the area_list_remove process */
|
||||||
|
*screen_geometry = *tmp = screen_get_area(screen,
|
||||||
|
globalconf.screens[screen].statusbar,
|
||||||
|
&globalconf.screens[screen].padding);
|
||||||
|
|
||||||
|
area_list_push(&arealist, tmp);
|
||||||
|
|
||||||
|
for(c = globalconf.clients; c; c = c->next)
|
||||||
|
if(client_isvisible(c, screen))
|
||||||
|
{
|
||||||
|
newgeometry = c->f_geometry;
|
||||||
|
newgeometry.width += 2 * c->border;
|
||||||
|
newgeometry.height += 2 * c->border;
|
||||||
|
area_list_remove(&arealist, &newgeometry);
|
||||||
|
}
|
||||||
|
|
||||||
|
newgeometry.x = geometry.x;
|
||||||
|
newgeometry.y = geometry.y;
|
||||||
|
newgeometry.width = 0;
|
||||||
|
newgeometry.height = 0;
|
||||||
|
|
||||||
|
for(r = arealist; r; r = r->next)
|
||||||
|
if(r->width >= geometry.width && r->height >= 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(r = arealist; r; r = r->next)
|
||||||
|
if(r->width * r->height > newgeometry.width * newgeometry.height)
|
||||||
|
newgeometry = *r;
|
||||||
|
|
||||||
|
/* restore height and width */
|
||||||
|
newgeometry.width = geometry.width;
|
||||||
|
newgeometry.height = geometry.height;
|
||||||
|
|
||||||
|
/* fix offscreen */
|
||||||
|
if(AREA_RIGHT(newgeometry) > AREA_RIGHT(*screen_geometry))
|
||||||
|
newgeometry.x = screen_geometry->x + screen_geometry->width - (newgeometry.width + 2 * border);
|
||||||
|
|
||||||
|
if(AREA_BOTTOM(newgeometry) > AREA_BOTTOM(*screen_geometry))
|
||||||
|
newgeometry.y = screen_geometry->y + screen_geometry->height - (newgeometry.height + 2 * border);
|
||||||
|
area_list_wipe(&arealist);
|
||||||
|
p_delete(&screen_geometry);
|
||||||
|
|
||||||
|
return newgeometry;
|
||||||
|
}
|
||||||
|
|
||||||
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* placement.h - client placement management header
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef AWESOME_PLACEMENT_H
|
||||||
|
#define AWESOME_PLACEMENT_H
|
||||||
|
|
||||||
|
#include "structs.h"
|
||||||
|
|
||||||
|
FloatingPlacement placement_smart;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
|
@ -244,6 +244,7 @@ typedef struct
|
||||||
int right;
|
int right;
|
||||||
} Padding;
|
} Padding;
|
||||||
|
|
||||||
|
typedef Area (FloatingPlacement)(Area, int, int);
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
/** Screen geometry */
|
/** Screen geometry */
|
||||||
|
@ -252,6 +253,8 @@ typedef struct
|
||||||
int snap;
|
int snap;
|
||||||
/** Border size */
|
/** Border size */
|
||||||
int borderpx;
|
int borderpx;
|
||||||
|
/** Floating window placement algo */
|
||||||
|
FloatingPlacement *floating_placement;
|
||||||
/** Respect resize hints */
|
/** Respect resize hints */
|
||||||
Bool resize_hints;
|
Bool resize_hints;
|
||||||
/** Sloppy focus: focus follow mouse */
|
/** Sloppy focus: focus follow mouse */
|
||||||
|
|
Loading…
Reference in New Issue