Adding padding

This commit is contained in:
Nathan Hüsken 2007-11-27 23:03:55 +01:00 committed by Julien Danjou
parent 355dc7d556
commit 9524f15478
14 changed files with 88 additions and 32 deletions

View File

@ -213,8 +213,8 @@ setup_screen(awesome_config *awesomeconf, const char *confpath)
parse_config(confpath, awesomeconf); parse_config(confpath, awesomeconf);
setup(awesomeconf); setup(awesomeconf);
initstatusbar(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar, initstatusbar(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar,
awesomeconf->cursor[CurNormal], awesomeconf->font, awesomeconf->cursor[CurNormal], awesomeconf->font,
awesomeconf->layouts, awesomeconf->nlayouts); awesomeconf->layouts, awesomeconf->nlayouts,&awesomeconf->padding);
} }
/** Startup Error handler to check if another window manager /** Startup Error handler to check if another window manager

View File

@ -35,6 +35,14 @@ screen 0
# Focused foreground color (statusbar) # Focused foreground color (statusbar)
focus_fg = "#ffffff" focus_fg = "#ffffff"
} }
# Optionnal screen padding
#padding
#{
# left = 10
# right = 0
# top = 0
# bottom = 10
#}
statusbar statusbar
{ {
# Statusbar position # Statusbar position

View File

@ -289,7 +289,7 @@ client_manage(Window w, XWindowAttributes *wa, awesome_config *awesomeconf)
if(!loadprops(c, awesomeconf->ntags)) if(!loadprops(c, awesomeconf->ntags))
tag_client_with_rules(c, current_acf); tag_client_with_rules(c, current_acf);
screen_info = get_screen_info(current_acf->display, current_acf->screen, NULL); screen_info = get_screen_info(current_acf->display, current_acf->screen, NULL, NULL);
/* if window request fullscreen mode */ /* if window request fullscreen mode */
if(c->w == screen_info[current_acf->screen].width && c->h == screen_info[current_acf->screen].height) if(c->w == screen_info[current_acf->screen].width && c->h == screen_info[current_acf->screen].height)
@ -301,7 +301,7 @@ client_manage(Window w, XWindowAttributes *wa, awesome_config *awesomeconf)
} }
else else
{ {
ScreenInfo *display_info = get_display_info(c->display, c->phys_screen, &current_acf->statusbar); ScreenInfo *display_info = get_display_info(c->display, c->phys_screen, &current_acf->statusbar,&awesomeconf->padding);
if(c->x + c->w + 2 * c->border > display_info->x_org + display_info->width) if(c->x + c->w + 2 * c->border > display_info->x_org + display_info->width)
c->x = c->rx = display_info->x_org + display_info->width - c->w - 2 * c->border; c->x = c->rx = display_info->x_org + display_info->width - c->w - 2 * c->border;
@ -419,7 +419,7 @@ client_resize(Client *c, int x, int y, int w, int h, awesome_config *awesomeconf
if(w <= 0 || h <= 0) if(w <= 0 || h <= 0)
return; return;
/* offscreen appearance fixes */ /* offscreen appearance fixes */
si = get_display_info(c->display, c->phys_screen, NULL); si = get_display_info(c->display, c->phys_screen, NULL, &awesomeconf->padding);
if(x > si->width) if(x > si->width)
x = si->width - w - 2 * c->border; x = si->width - w - 2 * c->border;
if(y > si->height) if(y > si->height)

View File

@ -221,6 +221,14 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
CFG_SEC((char *) "layout", layout_opts, CFGF_TITLE | CFGF_MULTI), CFG_SEC((char *) "layout", layout_opts, CFGF_TITLE | CFGF_MULTI),
CFG_END() CFG_END()
}; };
static cfg_opt_t padding_opts[] =
{
CFG_INT((char *) "top", 0, CFGF_NONE),
CFG_INT((char *) "bottom", 0, CFGF_NONE),
CFG_INT((char *) "right", 0, CFGF_NONE),
CFG_INT((char *) "left", 0, CFGF_NONE),
CFG_END()
};
static cfg_opt_t screen_opts[] = static cfg_opt_t screen_opts[] =
{ {
CFG_SEC((char *) "general", general_opts, CFGF_NONE), CFG_SEC((char *) "general", general_opts, CFGF_NONE),
@ -228,6 +236,7 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
CFG_SEC((char *) "tags", tags_opts, CFGF_NONE), CFG_SEC((char *) "tags", tags_opts, CFGF_NONE),
CFG_SEC((char *) "colors", colors_opts, CFGF_NONE), CFG_SEC((char *) "colors", colors_opts, CFGF_NONE),
CFG_SEC((char *) "layouts", layouts_opts, CFGF_NONE), CFG_SEC((char *) "layouts", layouts_opts, CFGF_NONE),
CFG_SEC((char *) "padding", padding_opts, CFGF_NONE),
}; };
static cfg_opt_t rule_opts[] = static cfg_opt_t rule_opts[] =
{ {
@ -287,8 +296,8 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
CFG_SEC((char *) "mouse", mouse_opts, CFGF_NONE), CFG_SEC((char *) "mouse", mouse_opts, CFGF_NONE),
CFG_END() CFG_END()
}; };
cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_screen, *cfg_statusbar, cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_screen, *cfg_statusbar, *cfg_tags,
*cfg_tags, *cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp; *cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp, *cfg_padding;
int i = 0, k = 0, ret; int i = 0, k = 0, ret;
unsigned int j = 0, l = 0; unsigned int j = 0, l = 0;
const char *tmp, *homedir; const char *tmp, *homedir;
@ -335,6 +344,7 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
cfg_colors = cfg_getsec(cfg_screen, "colors"); cfg_colors = cfg_getsec(cfg_screen, "colors");
cfg_general = cfg_getsec(cfg_screen, "general"); cfg_general = cfg_getsec(cfg_screen, "general");
cfg_layouts = cfg_getsec(cfg_screen, "layouts"); cfg_layouts = cfg_getsec(cfg_screen, "layouts");
cfg_padding = cfg_getsec(cfg_screen, "padding");
/* get general sections */ /* get general sections */
cfg_rules = cfg_getsec(cfg, "rules"); cfg_rules = cfg_getsec(cfg, "rules");
@ -447,6 +457,11 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
awesomeconf->tags[i].ncol = cfg_getint(cfgsectmp, "ncol"); awesomeconf->tags[i].ncol = cfg_getint(cfgsectmp, "ncol");
} }
/* padding */
awesomeconf->padding.top = cfg_getint(cfg_padding, "top");
awesomeconf->padding.bottom = cfg_getint(cfg_padding, "bottom");
awesomeconf->padding.left = cfg_getint(cfg_padding, "left");
awesomeconf->padding.right = cfg_getint(cfg_padding, "right");
if(!awesomeconf->ntags) if(!awesomeconf->ntags)
eprint("awesome: fatal: no tags found in configuration file\n"); eprint("awesome: fatal: no tags found in configuration file\n");

View File

@ -153,6 +153,19 @@ typedef struct
int ncol; int ncol;
} Tag; } Tag;
/** Padding type */
typedef struct
{
/** Padding at top */
int top;
/** Padding at bottom */
int bottom;
/** Padding at left */
int left;
/** Padding at right */
int right;
} Padding;
/** Main configuration structure */ /** Main configuration structure */
struct awesome_config struct awesome_config
{ {
@ -210,6 +223,8 @@ struct awesome_config
XColor colors_selected[ColLast]; XColor colors_selected[ColLast];
/** Cursors */ /** Cursors */
Cursor cursor[CurLast]; Cursor cursor[CurLast];
/** Padding */
Padding padding;
/** Font */ /** Font */
XftFont *font; XftFont *font;
/** Clients list */ /** Clients list */

View File

@ -200,7 +200,7 @@ handle_event_configurenotify(XEvent * e, awesome_config *awesomeconf)
DisplayHeight(e->xany.display, screen) = ev->height; DisplayHeight(e->xany.display, screen) = ev->height;
/* update statusbar */ /* update statusbar */
si = get_screen_info(e->xany.display, screen, NULL); si = get_screen_info(e->xany.display, screen, NULL, &awesomeconf->padding);
awesomeconf[screen].statusbar.width = si[screen].width; awesomeconf[screen].statusbar.width = si[screen].width;
p_delete(&si); p_delete(&si);
@ -209,7 +209,7 @@ handle_event_configurenotify(XEvent * e, awesome_config *awesomeconf)
awesomeconf[screen].statusbar.width, awesomeconf[screen].statusbar.width,
awesomeconf[screen].statusbar.height); awesomeconf[screen].statusbar.height);
updatebarpos(e->xany.display, awesomeconf[screen].statusbar); updatebarpos(e->xany.display, awesomeconf[screen].statusbar, &awesomeconf[screen].padding);
arrange(&awesomeconf[screen]); arrange(&awesomeconf[screen]);
} }
} }

View File

@ -254,7 +254,7 @@ void
uicb_client_togglemax(awesome_config *awesomeconf, uicb_client_togglemax(awesome_config *awesomeconf,
const char *arg __attribute__ ((unused))) const char *arg __attribute__ ((unused)))
{ {
ScreenInfo *si = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar); ScreenInfo *si = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar, &awesomeconf->padding);
maximize(si[awesomeconf->screen].x_org, si[awesomeconf->screen].y_org, maximize(si[awesomeconf->screen].x_org, si[awesomeconf->screen].y_org,
si[awesomeconf->screen].width - 2 * awesomeconf->borderpx, si[awesomeconf->screen].width - 2 * awesomeconf->borderpx,
@ -268,7 +268,7 @@ uicb_client_toggleverticalmax(awesome_config *awesomeconf,
const char *arg __attribute__ ((unused))) const char *arg __attribute__ ((unused)))
{ {
Client *sel = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel; Client *sel = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel;
ScreenInfo *si = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar); ScreenInfo *si = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar, &awesomeconf->padding);
if(sel) if(sel)
maximize(sel->x, maximize(sel->x,
@ -285,7 +285,7 @@ uicb_client_togglehorizontalmax(awesome_config *awesomeconf,
const char *arg __attribute__ ((unused))) const char *arg __attribute__ ((unused)))
{ {
Client *sel = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel; Client *sel = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel;
ScreenInfo *si = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar); ScreenInfo *si = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar, &awesomeconf->padding);
if(sel) if(sel)
maximize(si[awesomeconf->screen].x_org, maximize(si[awesomeconf->screen].x_org,

View File

@ -28,7 +28,7 @@ void
layout_max(awesome_config *awesomeconf) layout_max(awesome_config *awesomeconf)
{ {
Client *c; Client *c;
ScreenInfo *si = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar); ScreenInfo *si = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar, &awesomeconf->padding);
for(c = *awesomeconf->clients; c; c = c->next) for(c = *awesomeconf->clients; c; c = c->next)
if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags)) if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))

View File

@ -104,7 +104,7 @@ _tile(awesome_config *awesomeconf, const Bool right)
Client *c; Client *c;
Tag *curtag = get_current_tag(awesomeconf->tags, awesomeconf->ntags); Tag *curtag = get_current_tag(awesomeconf->tags, awesomeconf->ntags);
screens_info = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar); screens_info = get_screen_info(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar, &awesomeconf->padding);
for(n = 0, c = *awesomeconf->clients; c; c = c->next) for(n = 0, c = *awesomeconf->clients; c; c = c->next)
if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags)) if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags))

View File

@ -47,7 +47,7 @@ uicb_client_movemouse(awesome_config *awesomeconf, const char *arg __attribute__
else else
restack(awesomeconf); restack(awesomeconf);
si = get_screen_info(c->display, c->screen, &awesomeconf->statusbar); si = get_screen_info(c->display, c->screen, &awesomeconf->statusbar, &awesomeconf->padding);
ocx = nx = c->x; ocx = nx = c->x;
ocy = ny = c->y; ocy = ny = c->y;

View File

@ -32,7 +32,7 @@
* \return ScreenInfo struct array with all screens info * \return ScreenInfo struct array with all screens info
*/ */
ScreenInfo * ScreenInfo *
get_screen_info(Display *disp, int screen, Statusbar *statusbar) get_screen_info(Display *disp, int screen, Statusbar *statusbar, Padding *padding)
{ {
int i, screen_number = 0; int i, screen_number = 0;
ScreenInfo *si; ScreenInfo *si;
@ -50,6 +50,15 @@ get_screen_info(Display *disp, int screen, Statusbar *statusbar)
screen_number = screen + 1; screen_number = screen + 1;
} }
/* make padding corrections */
if(padding)
{
si[screen].x_org+=padding->left;
si[screen].y_org+=padding->top;
si[screen].width-=padding->left+padding->right;
si[screen].height-=padding->top+padding->bottom;
}
if(statusbar) if(statusbar)
for(i = 0; i < screen_number; i++) for(i = 0; i < screen_number; i++)
switch(statusbar->position) switch(statusbar->position)
@ -76,7 +85,7 @@ get_screen_info(Display *disp, int screen, Statusbar *statusbar)
* \return ScreenInfo struct pointer with all display info * \return ScreenInfo struct pointer with all display info
*/ */
ScreenInfo * ScreenInfo *
get_display_info(Display *disp, int screen, Statusbar *statusbar) get_display_info(Display *disp, int screen, Statusbar *statusbar, Padding *padding)
{ {
ScreenInfo *si; ScreenInfo *si;
@ -88,6 +97,15 @@ get_display_info(Display *disp, int screen, Statusbar *statusbar)
si->height = DisplayHeight(disp, screen) - si->height = DisplayHeight(disp, screen) -
(statusbar && (statusbar->position == BarTop || statusbar->position == BarBot) ? statusbar->height : 0); (statusbar && (statusbar->position == BarTop || statusbar->position == BarBot) ? statusbar->height : 0);
/* make padding corrections */
if(padding)
{
si[screen].x_org+=padding->left;
si[screen].y_org+=padding->top;
si[screen].width-=padding->left+padding->right;
si[screen].height-=padding->top+padding->bottom;
}
return si; return si;
} }
@ -107,7 +125,7 @@ get_screen_bycoord(Display *disp, int x, int y)
if(!XineramaIsActive(disp)) if(!XineramaIsActive(disp))
return DefaultScreen(disp); return DefaultScreen(disp);
si = get_screen_info(disp, 0, NULL); si = get_screen_info(disp, 0, NULL, NULL);
for(i = 0; i < get_screen_count(disp); i++) for(i = 0; i < get_screen_count(disp); i++)
if((x < 0 || (x >= si[i].x_org && x < si[i].x_org + si[i].width)) if((x < 0 || (x >= si[i].x_org && x < si[i].x_org + si[i].width))
@ -177,8 +195,8 @@ move_client_to_screen(Client *c, awesome_config *acf_new, Bool doresize)
{ {
ScreenInfo *si, *si_old; ScreenInfo *si, *si_old;
si = get_screen_info(c->display, c->screen, NULL); si = get_screen_info(c->display, c->screen, NULL, NULL);
si_old = get_screen_info(c->display, old_screen, NULL); si_old = get_screen_info(c->display, old_screen, NULL, NULL);
/* compute new coords in new screen */ /* compute new coords in new screen */
c->rx = (c->rx - si_old[old_screen].x_org) + si[c->screen].x_org; c->rx = (c->rx - si_old[old_screen].x_org) + si[c->screen].x_org;
@ -215,7 +233,7 @@ move_mouse_pointer_to_screen(Display *disp, int screen)
{ {
if(XineramaIsActive(disp)) if(XineramaIsActive(disp))
{ {
ScreenInfo *si = get_screen_info(disp, screen, NULL); ScreenInfo *si = get_screen_info(disp, screen, NULL, NULL);
XWarpPointer(disp, None, DefaultRootWindow(disp), 0, 0, 0, 0, si[screen].x_org, si[screen].y_org); XWarpPointer(disp, None, DefaultRootWindow(disp), 0, 0, 0, 0, si[screen].x_org, si[screen].y_org);
p_delete(&si); p_delete(&si);
} }

View File

@ -28,8 +28,8 @@
typedef XineramaScreenInfo ScreenInfo; typedef XineramaScreenInfo ScreenInfo;
ScreenInfo * get_screen_info(Display *, int, Statusbar *); ScreenInfo * get_screen_info(Display *, int, Statusbar *, Padding *);
ScreenInfo * get_display_info(Display *, int, Statusbar *); ScreenInfo * get_display_info(Display *, int, Statusbar *, Padding *);
int get_screen_bycoord(Display *, int, int); int get_screen_bycoord(Display *, int, int);
int get_screen_count(Display *); int get_screen_count(Display *);
int get_phys_screen(Display *, int); int get_phys_screen(Display *, int);

View File

@ -197,11 +197,11 @@ drawstatusbar(awesome_config *awesomeconf)
} }
void void
initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, XftFont *font, Layout *layouts, int nlayouts) initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, XftFont *font, Layout *layouts, int nlayouts, Padding *padding)
{ {
XSetWindowAttributes wa; XSetWindowAttributes wa;
int i, phys_screen = get_phys_screen(disp, screen); int i, phys_screen = get_phys_screen(disp, screen);
ScreenInfo *si = get_screen_info(disp, screen, NULL); ScreenInfo *si = get_screen_info(disp, screen, NULL, padding);
statusbar->height = font->height * 1.5; statusbar->height = font->height * 1.5;
@ -235,7 +235,7 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, Xf
DefaultVisual(disp, phys_screen), DefaultVisual(disp, phys_screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
XDefineCursor(disp, statusbar->window, cursor); XDefineCursor(disp, statusbar->window, cursor);
updatebarpos(disp, *statusbar); updatebarpos(disp, *statusbar, padding);
XMapRaised(disp, statusbar->window); XMapRaised(disp, statusbar->window);
for(i = 0; i < nlayouts; i++) for(i = 0; i < nlayouts; i++)
@ -244,10 +244,10 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, Xf
} }
void void
updatebarpos(Display *disp, Statusbar statusbar) updatebarpos(Display *disp, Statusbar statusbar, Padding *padding)
{ {
XEvent ev; XEvent ev;
ScreenInfo *si = get_screen_info(disp, statusbar.screen, NULL); ScreenInfo *si = get_screen_info(disp, statusbar.screen, NULL, padding);
XMapRaised(disp, statusbar.window); XMapRaised(disp, statusbar.window);
switch (statusbar.position) switch (statusbar.position)
@ -278,7 +278,7 @@ uicb_togglebar(awesome_config *awesomeconf,
awesomeconf->statusbar.position = (awesomeconf->statusbar.dposition == BarOff) ? BarTop : awesomeconf->statusbar.dposition; awesomeconf->statusbar.position = (awesomeconf->statusbar.dposition == BarOff) ? BarTop : awesomeconf->statusbar.dposition;
else else
awesomeconf->statusbar.position = BarOff; awesomeconf->statusbar.position = BarOff;
updatebarpos(awesomeconf->display, awesomeconf->statusbar); updatebarpos(awesomeconf->display, awesomeconf->statusbar, &awesomeconf->padding);
arrange(awesomeconf); arrange(awesomeconf);
} }

View File

@ -24,9 +24,9 @@
#include "common.h" #include "common.h"
void initstatusbar(Display *, int, Statusbar *, Cursor, XftFont *, Layout *, int); void initstatusbar(Display *, int, Statusbar *, Cursor, XftFont *, Layout *, int, Padding *);
void drawstatusbar(awesome_config *); void drawstatusbar(awesome_config *);
void updatebarpos(Display *, Statusbar); void updatebarpos(Display *, Statusbar, Padding *);
UICB_PROTO(uicb_togglebar); UICB_PROTO(uicb_togglebar);
UICB_PROTO(uicb_setstatustext); UICB_PROTO(uicb_setstatustext);