From 1d468c55831a29bfd3a0b379da20ca999ef09ec9 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 21 Mar 2008 11:26:56 +0100 Subject: [PATCH] Lot of cosmetic changes: proto change, etc. Signed-off-by: Julien Danjou --- awesome-client.c | 4 +-- awesome-menu.c | 6 ++-- awesome-message.c | 2 +- awesome.c | 4 +-- client.c | 2 +- common/draw.c | 74 ++++++++++++++++++++++++++++++----------------- common/draw.h | 5 ++-- common/socket.c | 4 +-- common/socket.h | 4 +-- common/swindow.c | 15 +++------- common/swindow.h | 11 +++++-- common/xscreen.c | 4 +-- common/xutil.c | 2 +- common/xutil.h | 2 +- config.c | 2 +- titlebar.c | 2 +- widgets/textbox.c | 2 +- 17 files changed, 84 insertions(+), 61 deletions(-) diff --git a/awesome-client.c b/awesome-client.c index fa1a7f885..0345c25d5 100644 --- a/awesome-client.c +++ b/awesome-client.c @@ -40,8 +40,8 @@ send_msg(char *msg, ssize_t msg_len) { struct sockaddr_un *addr; int csfd, ret_value = EXIT_SUCCESS; - csfd = get_client_socket(); - addr = get_client_addr(getenv("DISPLAY")); + csfd = socket_getclient(); + addr = socket_getaddr(getenv("DISPLAY")); if(!addr || csfd < 0) return EXIT_FAILURE; diff --git a/awesome-menu.c b/awesome-menu.c index 09ffe7a75..ec77d6a91 100644 --- a/awesome-menu.c +++ b/awesome-menu.c @@ -643,7 +643,7 @@ main(int argc, char **argv) globalconf.prompt = a_strdup(argv[optind]); /* Get the numlock mask */ - globalconf.numlockmask = get_numlockmask(disp); + globalconf.numlockmask = xgetnumlockmask(disp); si = screensinfo_new(disp); if(si->xinerama_is_active) @@ -748,8 +748,8 @@ main(int argc, char **argv) } p_delete(&globalconf.text); - draw_context_delete(globalconf.ctx); - simplewindow_delete(globalconf.sw); + draw_context_delete(&globalconf.ctx); + simplewindow_delete(&globalconf.sw); XCloseDisplay(disp); return EXIT_SUCCESS; diff --git a/awesome-message.c b/awesome-message.c index 106a2ea92..a84d0ea9c 100644 --- a/awesome-message.c +++ b/awesome-message.c @@ -237,7 +237,7 @@ main(int argc, char **argv) usleep(100000); } - simplewindow_delete(sw); + simplewindow_delete(&sw); XCloseDisplay(disp); return EXIT_SUCCESS; diff --git a/awesome.c b/awesome.c index 5b2d46782..3b4f81d18 100644 --- a/awesome.c +++ b/awesome.c @@ -334,8 +334,8 @@ main(int argc, char *argv[]) XSync(dpy, False); /* get socket fd */ - csfd = get_client_socket(); - addr = get_client_addr(getenv("DISPLAY")); + csfd = socket_getclient(); + addr = socket_getaddr(getenv("DISPLAY")); if(bind(csfd, (const struct sockaddr *) addr, SUN_LEN(addr))) { diff --git a/client.c b/client.c index c74291be1..6c910975c 100644 --- a/client.c +++ b/client.c @@ -649,7 +649,7 @@ client_unmanage(Client *c) XUngrabServer(globalconf.display); if(c->titlebar.sw) - simplewindow_delete(c->titlebar.sw); + simplewindow_delete(&c->titlebar.sw); p_delete(&c); } diff --git a/common/draw.c b/common/draw.c index 835870e57..8129e7326 100644 --- a/common/draw.c +++ b/common/draw.c @@ -107,17 +107,18 @@ draw_context_new(Display *disp, int phys_screen, int width, int height, Drawable * \param ctx DrawCtx to delete */ void -draw_context_delete(DrawCtx *ctx) +draw_context_delete(DrawCtx **ctx) { - g_object_unref(ctx->layout); - cairo_surface_destroy(ctx->surface); - cairo_destroy(ctx->cr); - p_delete(&ctx); + g_object_unref((*ctx)->layout); + cairo_surface_destroy((*ctx)->surface); + cairo_destroy((*ctx)->cr); + p_delete(ctx); } /** Create a new Pango font * \param disp Display ref * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]) + * \return a new font */ font_t * draw_font_new(Display *disp, char *fontname) @@ -173,10 +174,10 @@ draw_font_new(Display *disp, char *fontname) * \param font font_t to delete */ void -draw_font_free(font_t *font) +draw_font_delete(font_t **font) { - pango_font_description_free(font->desc); - p_delete(&font); + pango_font_description_free((*font)->desc); + p_delete(font); } /** Draw text into a draw context @@ -289,7 +290,8 @@ draw_text(DrawCtx *ctx, */ static cairo_pattern_t * draw_setup_cairo_color_source(DrawCtx *ctx, area_t rect, - XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) + XColor *pcolor, XColor *pcolor_center, + XColor *pcolor_end) { cairo_pattern_t *pat = NULL; @@ -330,18 +332,24 @@ draw_rectangle(DrawCtx *ctx, area_t geometry, Bool filled, XColor color) { cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE); cairo_set_line_width(ctx->cr, 1.0); - cairo_set_source_rgb(ctx->cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0); + cairo_set_source_rgb(ctx->cr, + color.red / 65535.0, + color.green / 65535.0, + color.blue / 65535.0); if(filled) { - cairo_rectangle(ctx->cr, geometry.x, geometry.y, geometry.width, geometry.height); + cairo_rectangle(ctx->cr, geometry.x, geometry.y, + geometry.width, geometry.height); cairo_fill(ctx->cr); } else { - cairo_rectangle(ctx->cr, geometry.x + 1, geometry.y, geometry.width - 1, geometry.height - 1); + cairo_rectangle(ctx->cr, geometry.x + 1, geometry.y, + geometry.width - 1, geometry.height - 1); cairo_stroke(ctx->cr); } } + /** Draw rectangle with gradient colors * \param ctx Draw context * \param geometry geometry @@ -354,7 +362,8 @@ draw_rectangle(DrawCtx *ctx, area_t geometry, Bool filled, XColor color) */ void draw_rectangle_gradient(DrawCtx *ctx, area_t geometry, Bool filled, - area_t pattern_rect, XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) + area_t pattern_rect, XColor *pcolor, + XColor *pcolor_center, XColor *pcolor_end) { cairo_pattern_t *pat; @@ -404,13 +413,15 @@ draw_graph_setup(DrawCtx *ctx) * \param pcolor_end color at the right */ void -draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index, Position grow, - area_t patt_rect, XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) +draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index, + Position grow, area_t patt_rect, + XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) { int i, x, y, w; cairo_pattern_t *pat; - pat = draw_setup_cairo_color_source(ctx, patt_rect, pcolor, pcolor_center, pcolor_end); + pat = draw_setup_cairo_color_source(ctx, patt_rect, + pcolor, pcolor_center, pcolor_end); x = rect.x; y = rect.y; @@ -462,8 +473,9 @@ draw_graph(DrawCtx *ctx, area_t rect, int *from, int *to, int cur_index, Positio * \param pcolor_end color at the right */ void -draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index, Position grow, - area_t patt_rect, XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) +draw_graph_line(DrawCtx *ctx, area_t rect, int *to, int cur_index, + Position grow, area_t patt_rect, + XColor *pcolor, XColor *pcolor_center, XColor *pcolor_end) { int i, x, y, w; int flag = 0; /* used to prevent drawing a line from 0 to 0 values */ @@ -664,8 +676,10 @@ draw_rotate(DrawCtx *ctx, Drawable dest, int dest_w, int dest_h, cairo_surface_t *surface, *source; cairo_t *cr; - surface = cairo_xlib_surface_create(ctx->display, dest, ctx->visual, dest_w, dest_h); - source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); + surface = cairo_xlib_surface_create(ctx->display, dest, + ctx->visual, dest_w, dest_h); + source = cairo_xlib_surface_create(ctx->display, ctx->drawable, + ctx->visual, ctx->width, ctx->height); cr = cairo_create (surface); cairo_translate(cr, tx, ty); @@ -693,7 +707,7 @@ draw_textwidth(Display *disp, font_t *font, char *text) PangoLayout *layout; PangoRectangle ext; - if (!a_strlen(text)) + if(!a_strlen(text)) return 0; surface = cairo_xlib_surface_create(disp, DefaultScreen(disp), @@ -721,13 +735,13 @@ draw_textwidth(Display *disp, font_t *font, char *text) Alignment draw_align_get_from_str(const char *align) { - if(!a_strncmp(align, "left", 4)) + if(!a_strcmp(align, "left")) return AlignLeft; - else if(!a_strncmp(align, "center", 6)) + else if(!a_strcmp(align, "center")) return AlignCenter; - else if(!a_strncmp(align, "right", 5)) + else if(!a_strcmp(align, "right")) return AlignRight; - else if(!a_strncmp(align, "flex", 4)) + else if(!a_strcmp(align, "flex")) return AlignFlex; return AlignAuto; @@ -759,6 +773,14 @@ draw_color_new(Display *disp, int phys_screen, const char *colstr, XColor *color return ret; } +/** Init a style struct. Every value will be inherited from m + * if they are not set in the configuration section cfg. + * \param disp Display ref + * \param phys_screen Physical screen number + * \param cfg style configuration section + * \param c style to fill + * \param m style to use as template + */ void draw_style_init(Display *disp, int phys_screen, cfg_t *cfg, style_t *c, style_t *m) @@ -790,7 +812,7 @@ draw_style_init(Display *disp, int phys_screen, cfg_t *cfg, } /** Remove a area from a list of them, - * spliting the space between several area that can overlaps + * spliting the space between several area that can overlap * \param head list head * \param elem area to remove */ diff --git a/common/draw.h b/common/draw.h index 2a49a159c..6024dadf7 100644 --- a/common/draw.h +++ b/common/draw.h @@ -118,10 +118,11 @@ typedef struct } DrawCtx; DrawCtx *draw_context_new(Display *, int, int, int, Drawable); -void draw_context_delete(DrawCtx *); +void draw_context_delete(DrawCtx **); font_t *draw_font_new(Display *disp, char *fontname); -void draw_font_free(font_t *); +void draw_font_delete(font_t **); + void draw_text(DrawCtx *, area_t, Alignment, int, char *, style_t); void draw_rectangle(DrawCtx *, area_t, Bool, XColor); void draw_rectangle_gradient(DrawCtx *, area_t, Bool, area_t, XColor *, XColor *, XColor *); diff --git a/common/socket.c b/common/socket.c index f3652bb48..acff7a1dd 100644 --- a/common/socket.c +++ b/common/socket.c @@ -36,7 +36,7 @@ * \return sockaddr_un struct ready to be used or NULL if a problem occured */ struct sockaddr_un * -get_client_addr(const char *display) +socket_getaddr(const char *display) { char *homedir, *tmp; const char *real_display = NULL; @@ -82,7 +82,7 @@ get_client_addr(const char *display) * \return the socket file descriptor */ int -get_client_socket(void) +socket_getclient(void) { int csfd; diff --git a/common/socket.h b/common/socket.h index bb01ee010..df131c1eb 100644 --- a/common/socket.h +++ b/common/socket.h @@ -22,8 +22,8 @@ #ifndef AWESOME_COMMON_SOCKET_H #define AWESOME_COMMON_SOCKET_H -struct sockaddr_un * get_client_addr(const char *); -int get_client_socket(void); +struct sockaddr_un * socket_getaddr(const char *); +int socket_getclient(void); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/swindow.c b/common/swindow.c index cc1ad1b12..19121f322 100644 --- a/common/swindow.c +++ b/common/swindow.c @@ -78,11 +78,11 @@ simplewindow_new(Display *disp, int phys_screen, int x, int y, * \param sw the SimpleWindow to delete */ void -simplewindow_delete(SimpleWindow *sw) +simplewindow_delete(SimpleWindow **sw) { - XDestroyWindow(sw->display, sw->window); - XFreePixmap(sw->display, sw->drawable); - p_delete(&sw); + XDestroyWindow((*sw)->display, (*sw)->window); + XFreePixmap((*sw)->display, (*sw)->drawable); + p_delete(sw); } /** Move a simple window @@ -118,13 +118,6 @@ simplewindow_resize(SimpleWindow *sw, unsigned int w, unsigned int h) return XResizeWindow(sw->display, sw->window, w, h); } -int simplewindow_move_resize(SimpleWindow *sw, int x, int y, - unsigned int w, unsigned int h) -{ - return (simplewindow_move(sw, x, y) - && simplewindow_resize(sw, w, h)); -} - /** Refresh the window content * \param sw the SimpleWindow to refresh * \param phys_screen physical screen id diff --git a/common/swindow.h b/common/swindow.h index f0dcc5d2e..e8d3b8c27 100644 --- a/common/swindow.h +++ b/common/swindow.h @@ -35,11 +35,18 @@ typedef struct SimpleWindow } SimpleWindow; SimpleWindow * simplewindow_new(Display *, int, int, int, unsigned int, unsigned int, unsigned int); -void simplewindow_delete(SimpleWindow *); +void simplewindow_delete(SimpleWindow **); int simplewindow_move(SimpleWindow *, int, int); int simplewindow_resize(SimpleWindow *, unsigned int, unsigned int); int simplewindow_refresh_drawable(SimpleWindow *, int); -int simplewindow_move_resize(SimpleWindow *, int, int, unsigned int, unsigned int); + +static inline int +simplewindow_move_resize(SimpleWindow *sw, int x, int y, + unsigned int w, unsigned int h) +{ + return (simplewindow_move(sw, x, y) + && simplewindow_resize(sw, w, h)); +} #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/xscreen.c b/common/xscreen.c index 568ae5590..74e80d2cb 100644 --- a/common/xscreen.c +++ b/common/xscreen.c @@ -47,7 +47,7 @@ screen_get_bycoord(ScreensInfo *si, int screen, int x, int y) } static inline area_t -screen_xsi_to_area(XineramaScreenInfo si) +screen_xsitoarea(XineramaScreenInfo si) { area_t a; @@ -100,7 +100,7 @@ screensinfo_new(Display *disp) MAX(xsi[screen].height, xsi[screen_to_test].height); } if(!drop) - si->geometry[si->nscreen++] = screen_xsi_to_area(xsi[screen]); + si->geometry[si->nscreen++] = screen_xsitoarea(xsi[screen]); } /* realloc smaller if xinerama_screen_number != screen registered */ diff --git a/common/xutil.c b/common/xutil.c index b1ee741b5..0d6ad9a46 100644 --- a/common/xutil.c +++ b/common/xutil.c @@ -57,7 +57,7 @@ xgettextprop(Display *disp, Window w, Atom atom, char *text, ssize_t textlen) } unsigned int -get_numlockmask(Display *disp) +xgetnumlockmask(Display *disp) { XModifierKeymap *modmap; unsigned int mask = 0; diff --git a/common/xutil.h b/common/xutil.h index e7d6b85f8..16a90f79e 100644 --- a/common/xutil.h +++ b/common/xutil.h @@ -25,7 +25,7 @@ #include Bool xgettextprop(Display *, Window, Atom, char *, ssize_t); -unsigned int get_numlockmask(Display *); +unsigned int xgetnumlockmask(Display *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/config.c b/config.c index 84586af8c..99d8cbfcc 100644 --- a/config.c +++ b/config.c @@ -550,7 +550,7 @@ config_parse(const char *confpatharg) globalconf.buttons.titlebar = parse_mouse_bindings(cfg_mouse, "titlebar", True); /* Keys */ - globalconf.numlockmask = get_numlockmask(globalconf.display); + globalconf.numlockmask = xgetnumlockmask(globalconf.display); globalconf.keys = section_keys(cfg_keys); diff --git a/titlebar.c b/titlebar.c index 2b55dfb8d..e4209089a 100644 --- a/titlebar.c +++ b/titlebar.c @@ -153,7 +153,7 @@ titlebar_update(Client *c) simplewindow_refresh_drawable(c->titlebar.sw, c->titlebar.sw->phys_screen); - draw_context_delete(ctx); + draw_context_delete(&ctx); } void diff --git a/widgets/textbox.c b/widgets/textbox.c index 239d27363..df33c66fc 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -92,7 +92,7 @@ textbox_tell(Widget *widget, char *property, char *command) if((newfont = draw_font_new(globalconf.display, command))) { if(d->style.font != globalconf.screens[widget->statusbar->screen].styles.normal.font) - draw_font_free(d->style.font); + draw_font_delete(&d->style.font); d->style.font = newfont; } else