From 9524f15478a3c16fdf266daeec23f10c1b217cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20H=C3=BCsken?= Date: Tue, 27 Nov 2007 23:03:55 +0100 Subject: [PATCH] Adding padding --- awesome.c | 4 ++-- awesomerc | 8 ++++++++ client.c | 6 +++--- config.c | 21 ++++++++++++++++++--- config.h | 15 +++++++++++++++ event.c | 4 ++-- layout.c | 6 +++--- layouts/max.c | 2 +- layouts/tile.c | 2 +- mouse.c | 2 +- screen.c | 30 ++++++++++++++++++++++++------ screen.h | 4 ++-- statusbar.c | 12 ++++++------ statusbar.h | 4 ++-- 14 files changed, 88 insertions(+), 32 deletions(-) diff --git a/awesome.c b/awesome.c index 56ca2b9b..cea512a5 100644 --- a/awesome.c +++ b/awesome.c @@ -213,8 +213,8 @@ setup_screen(awesome_config *awesomeconf, const char *confpath) parse_config(confpath, awesomeconf); setup(awesomeconf); initstatusbar(awesomeconf->display, awesomeconf->screen, &awesomeconf->statusbar, - awesomeconf->cursor[CurNormal], awesomeconf->font, - awesomeconf->layouts, awesomeconf->nlayouts); + awesomeconf->cursor[CurNormal], awesomeconf->font, + awesomeconf->layouts, awesomeconf->nlayouts,&awesomeconf->padding); } /** Startup Error handler to check if another window manager diff --git a/awesomerc b/awesomerc index 59fad88b..843c52ad 100644 --- a/awesomerc +++ b/awesomerc @@ -35,6 +35,14 @@ screen 0 # Focused foreground color (statusbar) focus_fg = "#ffffff" } + # Optionnal screen padding + #padding + #{ + # left = 10 + # right = 0 + # top = 0 + # bottom = 10 + #} statusbar { # Statusbar position diff --git a/client.c b/client.c index c9fe7b9c..2c95b209 100644 --- a/client.c +++ b/client.c @@ -289,7 +289,7 @@ client_manage(Window w, XWindowAttributes *wa, awesome_config *awesomeconf) if(!loadprops(c, awesomeconf->ntags)) 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(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 { - ScreenInfo *display_info = get_display_info(c->display, c->phys_screen, ¤t_acf->statusbar); + ScreenInfo *display_info = get_display_info(c->display, c->phys_screen, ¤t_acf->statusbar,&awesomeconf->padding); 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; @@ -419,7 +419,7 @@ client_resize(Client *c, int x, int y, int w, int h, awesome_config *awesomeconf if(w <= 0 || h <= 0) return; /* 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) x = si->width - w - 2 * c->border; if(y > si->height) diff --git a/config.c b/config.c index 312d3cee..94bd7eee 100644 --- a/config.c +++ b/config.c @@ -221,6 +221,14 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) CFG_SEC((char *) "layout", layout_opts, CFGF_TITLE | CFGF_MULTI), 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[] = { 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 *) "colors", colors_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[] = { @@ -287,8 +296,8 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) CFG_SEC((char *) "mouse", mouse_opts, CFGF_NONE), CFG_END() }; - cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_screen, *cfg_statusbar, - *cfg_tags, *cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp; + cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_screen, *cfg_statusbar, *cfg_tags, + *cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp, *cfg_padding; int i = 0, k = 0, ret; unsigned int j = 0, l = 0; const char *tmp, *homedir; @@ -335,6 +344,7 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) cfg_colors = cfg_getsec(cfg_screen, "colors"); cfg_general = cfg_getsec(cfg_screen, "general"); cfg_layouts = cfg_getsec(cfg_screen, "layouts"); + cfg_padding = cfg_getsec(cfg_screen, "padding"); /* get general sections */ cfg_rules = cfg_getsec(cfg, "rules"); @@ -446,7 +456,12 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) awesomeconf->tags[i].nmaster = cfg_getint(cfgsectmp, "nmaster"); 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) eprint("awesome: fatal: no tags found in configuration file\n"); diff --git a/config.h b/config.h index 6a32e579..7c3ad3e5 100644 --- a/config.h +++ b/config.h @@ -153,6 +153,19 @@ typedef struct int ncol; } 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 */ struct awesome_config { @@ -210,6 +223,8 @@ struct awesome_config XColor colors_selected[ColLast]; /** Cursors */ Cursor cursor[CurLast]; + /** Padding */ + Padding padding; /** Font */ XftFont *font; /** Clients list */ diff --git a/event.c b/event.c index c0da5711..c1cfef0a 100644 --- a/event.c +++ b/event.c @@ -200,7 +200,7 @@ handle_event_configurenotify(XEvent * e, awesome_config *awesomeconf) DisplayHeight(e->xany.display, screen) = ev->height; /* 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; p_delete(&si); @@ -209,7 +209,7 @@ handle_event_configurenotify(XEvent * e, awesome_config *awesomeconf) awesomeconf[screen].statusbar.width, awesomeconf[screen].statusbar.height); - updatebarpos(e->xany.display, awesomeconf[screen].statusbar); + updatebarpos(e->xany.display, awesomeconf[screen].statusbar, &awesomeconf[screen].padding); arrange(&awesomeconf[screen]); } } diff --git a/layout.c b/layout.c index c67e9953..30b7a5bc 100644 --- a/layout.c +++ b/layout.c @@ -254,7 +254,7 @@ void uicb_client_togglemax(awesome_config *awesomeconf, 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, si[awesomeconf->screen].width - 2 * awesomeconf->borderpx, @@ -268,7 +268,7 @@ uicb_client_toggleverticalmax(awesome_config *awesomeconf, const char *arg __attribute__ ((unused))) { 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) maximize(sel->x, @@ -285,7 +285,7 @@ uicb_client_togglehorizontalmax(awesome_config *awesomeconf, const char *arg __attribute__ ((unused))) { 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) maximize(si[awesomeconf->screen].x_org, diff --git a/layouts/max.c b/layouts/max.c index 0abb001d..85717f69 100644 --- a/layouts/max.c +++ b/layouts/max.c @@ -28,7 +28,7 @@ void layout_max(awesome_config *awesomeconf) { 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) if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags)) diff --git a/layouts/tile.c b/layouts/tile.c index 7f2a962b..5af26748 100644 --- a/layouts/tile.c +++ b/layouts/tile.c @@ -104,7 +104,7 @@ _tile(awesome_config *awesomeconf, const Bool right) Client *c; 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) if(IS_TILED(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags)) diff --git a/mouse.c b/mouse.c index 20c948ab..e75eb043 100644 --- a/mouse.c +++ b/mouse.c @@ -47,7 +47,7 @@ uicb_client_movemouse(awesome_config *awesomeconf, const char *arg __attribute__ else 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; ocy = ny = c->y; diff --git a/screen.c b/screen.c index 75a32217..0a7ad063 100644 --- a/screen.c +++ b/screen.c @@ -32,7 +32,7 @@ * \return ScreenInfo struct array with all screens info */ 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; ScreenInfo *si; @@ -50,6 +50,15 @@ get_screen_info(Display *disp, int screen, Statusbar *statusbar) 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) for(i = 0; i < screen_number; i++) switch(statusbar->position) @@ -76,7 +85,7 @@ get_screen_info(Display *disp, int screen, Statusbar *statusbar) * \return ScreenInfo struct pointer with all display info */ ScreenInfo * -get_display_info(Display *disp, int screen, Statusbar *statusbar) +get_display_info(Display *disp, int screen, Statusbar *statusbar, Padding *padding) { ScreenInfo *si; @@ -88,6 +97,15 @@ get_display_info(Display *disp, int screen, Statusbar *statusbar) si->height = DisplayHeight(disp, screen) - (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; } @@ -107,7 +125,7 @@ get_screen_bycoord(Display *disp, int x, int y) if(!XineramaIsActive(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++) 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; - si = get_screen_info(c->display, c->screen, NULL); - si_old = get_screen_info(c->display, old_screen, NULL); + si = get_screen_info(c->display, c->screen, NULL, NULL); + si_old = get_screen_info(c->display, old_screen, NULL, NULL); /* compute new coords in new screen */ 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)) { - 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); p_delete(&si); } diff --git a/screen.h b/screen.h index 8cb59141..b6f8a803 100644 --- a/screen.h +++ b/screen.h @@ -28,8 +28,8 @@ typedef XineramaScreenInfo ScreenInfo; -ScreenInfo * get_screen_info(Display *, int, Statusbar *); -ScreenInfo * get_display_info(Display *, int, Statusbar *); +ScreenInfo * get_screen_info(Display *, int, Statusbar *, Padding *); +ScreenInfo * get_display_info(Display *, int, Statusbar *, Padding *); int get_screen_bycoord(Display *, int, int); int get_screen_count(Display *); int get_phys_screen(Display *, int); diff --git a/statusbar.c b/statusbar.c index eed524d3..6cc90b4e 100644 --- a/statusbar.c +++ b/statusbar.c @@ -197,11 +197,11 @@ drawstatusbar(awesome_config *awesomeconf) } 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; 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; @@ -235,7 +235,7 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, Xf DefaultVisual(disp, phys_screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(disp, statusbar->window, cursor); - updatebarpos(disp, *statusbar); + updatebarpos(disp, *statusbar, padding); XMapRaised(disp, statusbar->window); for(i = 0; i < nlayouts; i++) @@ -244,10 +244,10 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, Xf } void -updatebarpos(Display *disp, Statusbar statusbar) +updatebarpos(Display *disp, Statusbar statusbar, Padding *padding) { 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); switch (statusbar.position) @@ -278,7 +278,7 @@ uicb_togglebar(awesome_config *awesomeconf, awesomeconf->statusbar.position = (awesomeconf->statusbar.dposition == BarOff) ? BarTop : awesomeconf->statusbar.dposition; else awesomeconf->statusbar.position = BarOff; - updatebarpos(awesomeconf->display, awesomeconf->statusbar); + updatebarpos(awesomeconf->display, awesomeconf->statusbar, &awesomeconf->padding); arrange(awesomeconf); } diff --git a/statusbar.h b/statusbar.h index b833eb53..56a169e1 100644 --- a/statusbar.h +++ b/statusbar.h @@ -24,9 +24,9 @@ #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 updatebarpos(Display *, Statusbar); +void updatebarpos(Display *, Statusbar, Padding *); UICB_PROTO(uicb_togglebar); UICB_PROTO(uicb_setstatustext);