common: move draw, xscreen and swindow out

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-09-11 14:11:13 +02:00
parent 313e0ce8a5
commit 6a5ad6af9b
22 changed files with 248 additions and 359 deletions

View File

@ -59,16 +59,16 @@ set(AWE_SRCS
${SOURCE_DIR}/titlebar.c ${SOURCE_DIR}/titlebar.c
${SOURCE_DIR}/widget.c ${SOURCE_DIR}/widget.c
${SOURCE_DIR}/window.c ${SOURCE_DIR}/window.c
${SOURCE_DIR}/draw.c
${SOURCE_DIR}/swindow.c
${SOURCE_DIR}/xscreen.c
${SOURCE_DIR}/common/buffer.c ${SOURCE_DIR}/common/buffer.c
${SOURCE_DIR}/common/atoms.c ${SOURCE_DIR}/common/atoms.c
${SOURCE_DIR}/common/draw.c
${SOURCE_DIR}/common/markup.c ${SOURCE_DIR}/common/markup.c
${SOURCE_DIR}/common/socket.c ${SOURCE_DIR}/common/socket.c
${SOURCE_DIR}/common/swindow.c
${SOURCE_DIR}/common/util.c ${SOURCE_DIR}/common/util.c
${SOURCE_DIR}/common/version.c ${SOURCE_DIR}/common/version.c
${SOURCE_DIR}/common/xembed.c ${SOURCE_DIR}/common/xembed.c
${SOURCE_DIR}/common/xscreen.c
${SOURCE_DIR}/common/xutil.c ${SOURCE_DIR}/common/xutil.c
${SOURCE_DIR}/layouts/fibonacci.c ${SOURCE_DIR}/layouts/fibonacci.c
${SOURCE_DIR}/layouts/floating.c ${SOURCE_DIR}/layouts/floating.c

View File

@ -426,7 +426,7 @@ main(int argc, char **argv)
atoms_init(globalconf.connection); atoms_init(globalconf.connection);
/* init screens struct */ /* init screens struct */
globalconf.screens_info = screensinfo_new(globalconf.connection); globalconf.screens_info = screensinfo_new();
globalconf.screen_focus = globalconf.screens = p_new(screen_t, globalconf.screens_info->nscreen); globalconf.screen_focus = globalconf.screens = p_new(screen_t, globalconf.screens_info->nscreen);
/* \todo stop duplicating this */ /* \todo stop duplicating this */
for(screen_nbr = 0; screen_nbr < globalconf.screens_info->nscreen; screen_nbr++) for(screen_nbr = 0; screen_nbr < globalconf.screens_info->nscreen; screen_nbr++)
@ -436,15 +436,13 @@ main(int argc, char **argv)
} }
/* init default font and colors */ /* init default font and colors */
colors_reqs[0] = xcolor_init_unchecked(globalconf.connection, &globalconf.colors.fg, colors_reqs[0] = xcolor_init_unchecked(&globalconf.colors.fg,
globalconf.default_screen, "black", "black", sizeof("black") - 1);
sizeof("black")-1);
colors_reqs[1] = xcolor_init_unchecked(globalconf.connection, &globalconf.colors.bg, colors_reqs[1] = xcolor_init_unchecked(&globalconf.colors.bg,
globalconf.default_screen, "white", "white", sizeof("white") - 1);
sizeof("white")-1);
globalconf.font = draw_font_new(globalconf.connection, globalconf.default_screen, "sans 8"); globalconf.font = draw_font_new(globalconf.default_screen, "sans 8");
/* init cursors */ /* init cursors */
globalconf.cursor[CurNormal] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_LEFT_PTR); globalconf.cursor[CurNormal] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_LEFT_PTR);
@ -458,7 +456,7 @@ main(int argc, char **argv)
globalconf.cursor[CurBotLeft] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_BOTTOM_LEFT_CORNER); globalconf.cursor[CurBotLeft] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_BOTTOM_LEFT_CORNER);
for(colors_nbr = 0; colors_nbr < 2; colors_nbr++) for(colors_nbr = 0; colors_nbr < 2; colors_nbr++)
xcolor_init_reply(globalconf.connection, colors_reqs[colors_nbr]); xcolor_init_reply(colors_reqs[colors_nbr]);
/* Process the reply of previously sent mapping request */ /* Process the reply of previously sent mapping request */
xutil_lock_mask_get(globalconf.connection, xmapping_cookie, xutil_lock_mask_get(globalconf.connection, xmapping_cookie,

View File

@ -1350,11 +1350,7 @@ luaA_client_newindex(lua_State *L)
break; break;
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if((buf = luaL_checklstring(L, 3, &len)) if((buf = luaL_checklstring(L, 3, &len))
&& xcolor_init_reply(globalconf.connection, && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
xcolor_init_unchecked(globalconf.connection,
&(*c)->border_color,
(*c)->phys_screen, buf,
len)))
xcb_change_window_attributes(globalconf.connection, (*c)->win, xcb_change_window_attributes(globalconf.connection, (*c)->win,
XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel); XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
break; break;

View File

@ -1,103 +0,0 @@
/*
* swindow.h - simple window handling functions 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_COMMON_SWINDOW_H
#define AWESOME_COMMON_SWINDOW_H
#include "common/draw.h"
/** A simple window. */
typedef struct simple_window_t
{
/** The display connection. */
xcb_connection_t *connection;
/** The physical screen number the window is on. */
int phys_screen;
/** The window object. */
xcb_window_t window;
/** The pixmap copied to the window object. */
xcb_pixmap_t pixmap;
/** The graphic context. */
xcb_gcontext_t gc;
/** The window geometry. */
area_t geometry;
/** The window border width */
int border_width;
} simple_window_t;
simple_window_t * simplewindow_new(xcb_connection_t *, int, int, int, unsigned int, unsigned int, unsigned int);
/** Destroy a simple window and all its resources.
* \param sw The simple_window_t to delete.
*/
static inline void
simplewindow_delete(simple_window_t **sw)
{
if(*sw)
{
xcb_destroy_window((*sw)->connection, (*sw)->window);
xcb_free_pixmap((*sw)->connection, (*sw)->pixmap);
xcb_free_gc((*sw)->connection, (*sw)->gc);
p_delete(sw);
}
}
void simplewindow_move(simple_window_t *, int, int);
void simplewindow_resize(simple_window_t *, int, int);
void simplewindow_moveresize(simple_window_t *, int, int, int, int);
/** Refresh the window content by copying its pixmap data to its window.
* \param sw The simple window to refresh.
*/
static inline void
simplewindow_refresh_pixmap(simple_window_t *sw)
{
xcb_copy_area(sw->connection, sw->pixmap,
sw->window, sw->gc, 0, 0, 0, 0,
sw->geometry.width,
sw->geometry.height);
}
/** Set a simple window border width.
* \param sw The simple window to change border width.
* \param border_width The border width in pixel.
*/
static inline void
simplewindow_border_width_set(simple_window_t *sw, uint32_t border_width)
{
xcb_configure_window(sw->connection, sw->window, XCB_CONFIG_WINDOW_BORDER_WIDTH,
&border_width);
sw->border_width = border_width;
}
/** Set a simple window border color.
* \param sw The simple window to change border width.
* \param color The border color.
*/
static inline void
simplewindow_border_color_set(simple_window_t *sw, const xcolor_t *color)
{
xcb_change_window_attributes(sw->connection, sw->window,
XCB_CW_BORDER_PIXEL, &color->pixel);
}
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -29,8 +29,6 @@
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#endif #endif
#include <xcb/xcb.h>
#include <langinfo.h> #include <langinfo.h>
#include <iconv.h> #include <iconv.h>
#include <errno.h> #include <errno.h>
@ -38,10 +36,12 @@
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#include "structs.h"
#include "common/tokenize.h" #include "common/tokenize.h"
#include "common/draw.h"
#include "common/markup.h" #include "common/markup.h"
#include "common/xutil.h"
extern awesome_t globalconf;
static iconv_t iso2utf8 = (iconv_t) -1; static iconv_t iso2utf8 = (iconv_t) -1;
@ -109,7 +109,6 @@ draw_screen_default_visual(xcb_screen_t *s)
} }
/** Create a new draw context. /** Create a new draw context.
* \param conn Connection ref.
* \param phys_screen Physical screen id. * \param phys_screen Physical screen id.
* \param width Width. * \param width Width.
* \param height Height. * \param height Height.
@ -119,21 +118,20 @@ draw_screen_default_visual(xcb_screen_t *s)
* \return A draw context pointer. * \return A draw context pointer.
*/ */
draw_context_t * draw_context_t *
draw_context_new(xcb_connection_t *conn, int phys_screen, draw_context_new(int phys_screen,
int width, int height, xcb_pixmap_t px, int width, int height, xcb_pixmap_t px,
const xcolor_t *fg, const xcolor_t *bg) const xcolor_t *fg, const xcolor_t *bg)
{ {
draw_context_t *d = p_new(draw_context_t, 1); draw_context_t *d = p_new(draw_context_t, 1);
xcb_screen_t *s = xutil_screen_get(conn, phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
d->connection = conn;
d->phys_screen = phys_screen; d->phys_screen = phys_screen;
d->width = width; d->width = width;
d->height = height; d->height = height;
d->depth = s->root_depth; d->depth = s->root_depth;
d->visual = draw_screen_default_visual(s); d->visual = draw_screen_default_visual(s);
d->pixmap = px; d->pixmap = px;
d->surface = cairo_xcb_surface_create(conn, px, d->visual, width, height); d->surface = cairo_xcb_surface_create(globalconf.connection, px, d->visual, width, height);
d->cr = cairo_create(d->surface); d->cr = cairo_create(d->surface);
d->layout = pango_cairo_create_layout(d->cr); d->layout = pango_cairo_create_layout(d->cr);
d->fg = *fg; d->fg = *fg;
@ -143,23 +141,22 @@ draw_context_new(xcb_connection_t *conn, int phys_screen,
}; };
/** Create a new Pango font /** Create a new Pango font
* \param conn Connection ref
* \param phys_screen The physical screen number. * \param phys_screen The physical screen number.
* \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]) * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE])
* \return a new font * \return a new font
*/ */
font_t * font_t *
draw_font_new(xcb_connection_t *conn, int phys_screen, const char *fontname) draw_font_new(int phys_screen, const char *fontname)
{ {
cairo_surface_t *surface; cairo_surface_t *surface;
xcb_screen_t *s = xutil_screen_get(conn, phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
cairo_t *cr; cairo_t *cr;
PangoLayout *layout; PangoLayout *layout;
font_t *font = p_new(font_t, 1); font_t *font = p_new(font_t, 1);
/* Create a dummy cairo surface, cairo context and pango layout in /* Create a dummy cairo surface, cairo context and pango layout in
* order to get font informations */ * order to get font informations */
surface = cairo_xcb_surface_create(conn, surface = cairo_xcb_surface_create(globalconf.connection,
phys_screen, phys_screen,
draw_screen_default_visual(s), draw_screen_default_visual(s),
s->width_in_pixels, s->width_in_pixels,
@ -226,11 +223,9 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
switch(a_tokenize(*names, -1)) switch(a_tokenize(*names, -1))
{ {
case A_TK_COLOR: case A_TK_COLOR:
reqs[++reqs_nbr] = xcolor_init_unchecked(data->connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&data->bg_color,
&data->bg_color, *values,
data->phys_screen, a_strlen(*values));
*values,
a_strlen(*values));
bg_color_nbr = reqs_nbr; bg_color_nbr = reqs_nbr;
break; break;
@ -254,11 +249,9 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
switch(a_tokenize(*names, -1)) switch(a_tokenize(*names, -1))
{ {
case A_TK_COLOR: case A_TK_COLOR:
reqs[++reqs_nbr] = xcolor_init_unchecked(data->connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&data->border.color,
&data->border.color, *values,
data->phys_screen, a_strlen(*values));
*values,
a_strlen(*values));
break; break;
case A_TK_WIDTH: case A_TK_WIDTH:
data->border.width = atoi(*values); data->border.width = atoi(*values);
@ -275,11 +268,9 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
data->align = draw_align_fromstr(*values, -1); data->align = draw_align_fromstr(*values, -1);
break; break;
case A_TK_SHADOW: case A_TK_SHADOW:
reqs[++reqs_nbr] = xcolor_init_unchecked(data->connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&data->shadow.color,
&data->shadow.color, *values,
data->phys_screen, a_strlen(*values));
*values,
a_strlen(*values));
break; break;
case A_TK_SHADOW_OFFSET: case A_TK_SHADOW_OFFSET:
data->shadow.offset = atoi(*values); data->shadow.offset = atoi(*values);
@ -308,9 +299,9 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
for(i = 0; i <= reqs_nbr; i++) for(i = 0; i <= reqs_nbr; i++)
if(i == bg_color_nbr) if(i == bg_color_nbr)
data->has_bg_color = xcolor_init_reply(data->connection, reqs[i]); data->has_bg_color = xcolor_init_reply(reqs[i]);
else else
xcolor_init_reply(data->connection, reqs[i]); xcolor_init_reply(reqs[i]);
} }
bool bool
@ -367,8 +358,6 @@ draw_text(draw_context_t *ctx, font_t *font,
if(!pdata) if(!pdata)
{ {
draw_parser_data_init(&parser_data); draw_parser_data_init(&parser_data);
parser_data.connection = ctx->connection;
parser_data.phys_screen = ctx->phys_screen;
if(draw_text_markup_expand(&parser_data, text, len)) if(draw_text_markup_expand(&parser_data, text, len))
{ {
text = parser_data.text; text = parser_data.text;
@ -754,7 +743,7 @@ draw_graph_line(draw_context_t *ctx, area_t rect, int *to, int cur_index,
* \param wanted_h Wanted height: if > 0, image will be resized. * \param wanted_h Wanted height: if > 0, image will be resized.
* \param data The image pixels array. * \param data The image pixels array.
*/ */
void static void
draw_image_from_argb_data(draw_context_t *ctx, int x, int y, int w, int h, draw_image_from_argb_data(draw_context_t *ctx, int x, int y, int w, int h,
int wanted_h, unsigned char *data) int wanted_h, unsigned char *data)
{ {
@ -1006,9 +995,9 @@ draw_rotate(draw_context_t *ctx,
cairo_surface_t *surface, *source; cairo_surface_t *surface, *source;
cairo_t *cr; cairo_t *cr;
surface = cairo_xcb_surface_create(ctx->connection, dest, surface = cairo_xcb_surface_create(globalconf.connection, dest,
ctx->visual, dest_w, dest_h); ctx->visual, dest_w, dest_h);
source = cairo_xcb_surface_create(ctx->connection, src, source = cairo_xcb_surface_create(globalconf.connection, src,
ctx->visual, src_w, src_h); ctx->visual, src_w, src_h);
cr = cairo_create (surface); cr = cairo_create (surface);
@ -1024,7 +1013,6 @@ draw_rotate(draw_context_t *ctx,
} }
/** Return the width and height of a text in pixel. /** Return the width and height of a text in pixel.
* \param conn Connection ref.
* \param phys_screen Physical screen number. * \param phys_screen Physical screen number.
* \param font Font to use. * \param font Font to use.
* \param text The text. * \param text The text.
@ -1033,26 +1021,23 @@ draw_rotate(draw_context_t *ctx,
* \return Text height and width. * \return Text height and width.
*/ */
area_t area_t
draw_text_extents(xcb_connection_t *conn, int phys_screen, font_t *font, draw_text_extents(int phys_screen, font_t *font,
const char *text, ssize_t len, draw_parser_data_t *parser_data) const char *text, ssize_t len, draw_parser_data_t *parser_data)
{ {
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
PangoLayout *layout; PangoLayout *layout;
PangoRectangle ext; PangoRectangle ext;
xcb_screen_t *s = xutil_screen_get(conn, phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
area_t geom = { 0, 0, 0, 0 }; area_t geom = { 0, 0, 0, 0 };
if(!len) if(!len)
return geom; return geom;
parser_data->connection = conn;
parser_data->phys_screen = phys_screen;
if(!draw_text_markup_expand(parser_data, text, len)) if(!draw_text_markup_expand(parser_data, text, len))
return geom; return geom;
surface = cairo_xcb_surface_create(conn, phys_screen, surface = cairo_xcb_surface_create(globalconf.connection, phys_screen,
draw_screen_default_visual(s), draw_screen_default_visual(s),
s->width_in_pixels, s->width_in_pixels,
s->height_in_pixels); s->height_in_pixels);
@ -1114,17 +1099,14 @@ draw_align_tostr(alignment_t a)
#define RGB_COLOR_8_TO_16(i) (65535 * ((i) & 0xff) / 255) #define RGB_COLOR_8_TO_16(i) (65535 * ((i) & 0xff) / 255)
/** Send a request to initialize a X color. /** Send a request to initialize a X color.
* \param conn Connection ref.
* \param color xcolor_t struct to store color into. * \param color xcolor_t struct to store color into.
* \param phys_screen Physical screen number.
* \param colstr Color specification. * \param colstr Color specification.
* \return request informations. * \return request informations.
*/ */
xcolor_init_request_t xcolor_init_request_t
xcolor_init_unchecked(xcb_connection_t *conn, xcolor_t *color, int phys_screen, xcolor_init_unchecked(xcolor_t *color, const char *colstr, ssize_t len)
const char *colstr, ssize_t len)
{ {
xcb_screen_t *s = xutil_screen_get(conn, phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcolor_init_request_t req; xcolor_init_request_t req;
unsigned long colnum; unsigned long colnum;
uint16_t red, green, blue; uint16_t red, green, blue;
@ -1173,13 +1155,15 @@ xcolor_init_unchecked(xcb_connection_t *conn, xcolor_t *color, int phys_screen,
blue = RGB_COLOR_8_TO_16(colnum); blue = RGB_COLOR_8_TO_16(colnum);
req.is_hexa = true; req.is_hexa = true;
req.cookie_hexa = xcb_alloc_color_unchecked(conn, s->default_colormap, req.cookie_hexa = xcb_alloc_color_unchecked(globalconf.connection,
red, green, blue); s->default_colormap,
red, green, blue);
} }
else else
{ {
req.is_hexa = false; req.is_hexa = false;
req.cookie_named = xcb_alloc_named_color_unchecked(conn, s->default_colormap, len, req.cookie_named = xcb_alloc_named_color_unchecked(globalconf.connection,
s->default_colormap, len,
colstr); colstr);
} }
@ -1190,13 +1174,11 @@ xcolor_init_unchecked(xcb_connection_t *conn, xcolor_t *color, int phys_screen,
} }
/** Initialize a X color. /** Initialize a X color.
* \param conn Connection ref.
* \param req xcolor_init request. * \param req xcolor_init request.
* \return True if color allocation was successfull. * \return True if color allocation was successfull.
*/ */
bool bool
xcolor_init_reply(xcb_connection_t *conn, xcolor_init_reply(xcolor_init_request_t req)
xcolor_init_request_t req)
{ {
if(req.has_error) if(req.has_error)
return false; return false;
@ -1205,7 +1187,8 @@ xcolor_init_reply(xcb_connection_t *conn,
{ {
xcb_alloc_color_reply_t *hexa_color; xcb_alloc_color_reply_t *hexa_color;
if((hexa_color = xcb_alloc_color_reply(conn, req.cookie_hexa, NULL))) if((hexa_color = xcb_alloc_color_reply(globalconf.connection,
req.cookie_hexa, NULL)))
{ {
req.color->pixel = hexa_color->pixel; req.color->pixel = hexa_color->pixel;
req.color->red = hexa_color->red; req.color->red = hexa_color->red;
@ -1221,7 +1204,8 @@ xcolor_init_reply(xcb_connection_t *conn,
{ {
xcb_alloc_named_color_reply_t *named_color; xcb_alloc_named_color_reply_t *named_color;
if((named_color = xcb_alloc_named_color_reply(conn, req.cookie_named, NULL))) if((named_color = xcb_alloc_named_color_reply(globalconf.connection,
req.cookie_named, NULL)))
{ {
req.color->pixel = named_color->pixel; req.color->pixel = named_color->pixel;
req.color->red = named_color->visual_red; req.color->red = named_color->visual_red;

View File

@ -86,7 +86,6 @@ typedef struct
typedef struct typedef struct
{ {
xcb_connection_t *connection;
xcb_pixmap_t pixmap; xcb_pixmap_t pixmap;
xcb_visualtype_t *visual; xcb_visualtype_t *visual;
int width; int width;
@ -108,7 +107,7 @@ typedef struct
} draw_image_t; } draw_image_t;
draw_context_t * draw_context_t *
draw_context_new(xcb_connection_t *, int, int, int, xcb_drawable_t, draw_context_new(int, int, int, xcb_drawable_t,
const xcolor_t *, const xcolor_t*); const xcolor_t *, const xcolor_t*);
/** Delete a draw context. /** Delete a draw context.
@ -129,7 +128,7 @@ draw_context_delete(draw_context_t **ctx)
} }
} }
font_t *draw_font_new(xcb_connection_t *, int, const char *); font_t *draw_font_new(int, const char *);
void draw_font_delete(font_t **); void draw_font_delete(font_t **);
char * draw_iso2utf8(const char *, size_t); char * draw_iso2utf8(const char *, size_t);
@ -149,9 +148,7 @@ a_iso2utf8(char **dest, const char *str, ssize_t len)
typedef struct typedef struct
{ {
xcb_connection_t *connection;
PangoAttrList *attr_list; PangoAttrList *attr_list;
int phys_screen;
char *text; char *text;
ssize_t len; ssize_t len;
alignment_t align; alignment_t align;
@ -195,9 +192,8 @@ void draw_graph_line(draw_context_t *, area_t, int *, int, position_t, vector_t,
draw_image_t *draw_image_new(const char *); draw_image_t *draw_image_new(const char *);
void draw_image_delete(draw_image_t **); void draw_image_delete(draw_image_t **);
void draw_image(draw_context_t *, int, int, int, draw_image_t *); void draw_image(draw_context_t *, int, int, int, draw_image_t *);
void draw_image_from_argb_data(draw_context_t *, int, int, int, int, int, unsigned char *);
void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int); void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int);
area_t draw_text_extents(xcb_connection_t *, int, font_t *, const char *, ssize_t, draw_parser_data_t *); area_t draw_text_extents(int, font_t *, const char *, ssize_t, draw_parser_data_t *);
alignment_t draw_align_fromstr(const char *, ssize_t); alignment_t draw_align_fromstr(const char *, ssize_t);
const char *draw_align_tostr(alignment_t); const char *draw_align_tostr(alignment_t);
@ -215,10 +211,8 @@ typedef struct
const char *colstr; const char *colstr;
} xcolor_init_request_t; } xcolor_init_request_t;
xcolor_init_request_t xcolor_init_unchecked(xcb_connection_t *, xcolor_t *, int, xcolor_init_request_t xcolor_init_unchecked(xcolor_t *, const char *, ssize_t);
const char *, ssize_t); bool xcolor_init_reply(xcolor_init_request_t);
bool xcolor_init_reply(xcb_connection_t *, xcolor_init_request_t);
static inline void static inline void
draw_parser_data_init(draw_parser_data_t *pdata) draw_parser_data_init(draw_parser_data_t *pdata)

30
lua.c
View File

@ -269,8 +269,7 @@ luaA_font_set(lua_State *L)
deprecate(); deprecate();
const char *font = luaL_checkstring(L, 1); const char *font = luaL_checkstring(L, 1);
draw_font_delete(&globalconf.font); draw_font_delete(&globalconf.font);
globalconf.font = draw_font_new(globalconf.connection, globalconf.font = draw_font_new(globalconf.default_screen, font);
globalconf.default_screen, font);
return 0; return 0;
} }
@ -290,8 +289,7 @@ luaA_font(lua_State *L)
{ {
const char *newfont = luaL_checkstring(L, 1); const char *newfont = luaL_checkstring(L, 1);
draw_font_delete(&globalconf.font); draw_font_delete(&globalconf.font);
globalconf.font = draw_font_new(globalconf.connection, globalconf.font = draw_font_new(globalconf.default_screen, newfont);
globalconf.default_screen, newfont);
} }
font = pango_font_description_to_string(globalconf.font->desc); font = pango_font_description_to_string(globalconf.font->desc);
@ -319,19 +317,13 @@ luaA_colors_set(lua_State *L)
luaA_checktable(L, 1); luaA_checktable(L, 1);
if((buf = luaA_getopt_lstring(L, 1, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 1, "fg", NULL, &len)))
reqs[++colors_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++colors_nbr] = xcolor_init_unchecked(&globalconf.colors.fg, buf, len);
&globalconf.colors.fg,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 1, "bg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 1, "bg", NULL, &len)))
reqs[++colors_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++colors_nbr] = xcolor_init_unchecked(&globalconf.colors.bg, buf, len);
&globalconf.colors.bg,
globalconf.default_screen,
buf, len);
for(i = 0; i <= colors_nbr; i++) for(i = 0; i <= colors_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]); xcolor_init_reply(reqs[i]);
return 0; return 0;
} }
@ -349,19 +341,13 @@ luaA_colors(lua_State *L)
luaA_checktable(L, 1); luaA_checktable(L, 1);
if((buf = luaA_getopt_lstring(L, 1, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 1, "fg", NULL, &len)))
reqs[++colors_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++colors_nbr] = xcolor_init_unchecked(&globalconf.colors.fg, buf, len);
&globalconf.colors.fg,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 1, "bg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 1, "bg", NULL, &len)))
reqs[++colors_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++colors_nbr] = xcolor_init_unchecked(&globalconf.colors.bg, buf, len);
&globalconf.colors.bg,
globalconf.default_screen,
buf, len);
for(i = 0; i <= colors_nbr; i++) for(i = 0; i <= colors_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]); xcolor_init_reply(reqs[i]);
} }
lua_newtable(L); lua_newtable(L);

2
lua.h
View File

@ -26,8 +26,8 @@
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
#include "draw.h"
#include "common/util.h" #include "common/util.h"
#include "common/draw.h"
/** Object types */ /** Object types */
typedef enum typedef enum

View File

@ -278,8 +278,7 @@ mouse_infobox_new(int phys_screen, int border, area_t geometry,
draw_parser_data_init(&pdata); draw_parser_data_init(&pdata);
geom = draw_text_extents(globalconf.connection, geom = draw_text_extents(globalconf.default_screen,
globalconf.default_screen,
globalconf.font, globalconf.font,
MOUSE_INFOBOX_STRING_DEFAULT, MOUSE_INFOBOX_STRING_DEFAULT,
sizeof(MOUSE_INFOBOX_STRING_DEFAULT)-1, sizeof(MOUSE_INFOBOX_STRING_DEFAULT)-1,
@ -287,11 +286,11 @@ mouse_infobox_new(int phys_screen, int border, area_t geometry,
geom.x = geometry.x + ((2 * border + geometry.width) - geom.width) / 2; geom.x = geometry.x + ((2 * border + geometry.width) - geom.width) / 2;
geom.y = geometry.y + ((2 * border + geometry.height) - geom.height) / 2; geom.y = geometry.y + ((2 * border + geometry.height) - geom.height) / 2;
sw = simplewindow_new(globalconf.connection, phys_screen, sw = simplewindow_new(phys_screen,
geom.x, geom.y, geom.x, geom.y,
geom.width, geom.height, 0); geom.width, geom.height, 0);
*ctx = draw_context_new(globalconf.connection, sw->phys_screen, *ctx = draw_context_new(sw->phys_screen,
sw->geometry.width, sw->geometry.height, sw->geometry.width, sw->geometry.height,
sw->pixmap, sw->pixmap,
&globalconf.colors.fg, &globalconf.colors.fg,

View File

@ -454,7 +454,7 @@ statusbar_position_update(statusbar_t *statusbar)
statusbar_clean(statusbar); statusbar_clean(statusbar);
statusbar->sw = statusbar->sw =
simplewindow_new(globalconf.connection, statusbar->phys_screen, 0, 0, simplewindow_new(statusbar->phys_screen, 0, 0,
wingeometry.width, wingeometry.height, 0); wingeometry.width, wingeometry.height, 0);
switch(statusbar->position) switch(statusbar->position)
@ -468,8 +468,7 @@ statusbar_position_update(statusbar_t *statusbar)
xcb_create_pixmap(globalconf.connection, xcb_create_pixmap(globalconf.connection,
s->root_depth, dw, s->root, s->root_depth, dw, s->root,
statusbar->width, statusbar->height); statusbar->width, statusbar->height);
statusbar->ctx = draw_context_new(globalconf.connection, statusbar->ctx = draw_context_new(statusbar->phys_screen,
statusbar->phys_screen,
statusbar->width, statusbar->width,
statusbar->height, statusbar->height,
dw, dw,
@ -478,8 +477,7 @@ statusbar_position_update(statusbar_t *statusbar)
break; break;
default: default:
statusbar->width = wingeometry.width; statusbar->width = wingeometry.width;
statusbar->ctx = draw_context_new(globalconf.connection, statusbar->ctx = draw_context_new(statusbar->phys_screen,
statusbar->phys_screen,
statusbar->width, statusbar->width,
statusbar->height, statusbar->height,
statusbar->sw->pixmap, statusbar->sw->pixmap,
@ -541,17 +539,11 @@ luaA_statusbar_new(lua_State *L)
sb->colors.fg = globalconf.colors.fg; sb->colors.fg = globalconf.colors.fg;
if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&sb->colors.fg, buf, len);
&sb->colors.fg,
globalconf.default_screen,
buf, len);
sb->colors.bg = globalconf.colors.bg; sb->colors.bg = globalconf.colors.bg;
if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&sb->colors.bg, buf, len);
&sb->colors.bg,
globalconf.default_screen,
buf, len);
buf = luaA_getopt_lstring(L, 2, "align", "left", &len); buf = luaA_getopt_lstring(L, 2, "align", "left", &len);
sb->align = draw_align_fromstr(buf, len); sb->align = draw_align_fromstr(buf, len);
@ -570,7 +562,7 @@ luaA_statusbar_new(lua_State *L)
sb->screen = SCREEN_UNDEF; sb->screen = SCREEN_UNDEF;
for(i = 0; i <= reqs_nbr; i++) for(i = 0; i <= reqs_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]); xcolor_init_reply(reqs[i]);
return luaA_statusbar_userdata_new(L, sb); return luaA_statusbar_userdata_new(L, sb);
} }
@ -725,11 +717,7 @@ luaA_statusbar_newindex(lua_State *L)
break; break;
case A_TK_FG: case A_TK_FG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(globalconf.connection, if(xcolor_init_reply(xcolor_init_unchecked(&(*statusbar)->colors.fg, buf, len)))
xcolor_init_unchecked(globalconf.connection,
&(*statusbar)->colors.fg,
globalconf.default_screen,
buf, len)))
{ {
if((*statusbar)->ctx) if((*statusbar)->ctx)
(*statusbar)->ctx->fg = (*statusbar)->colors.fg; (*statusbar)->ctx->fg = (*statusbar)->colors.fg;
@ -738,10 +726,7 @@ luaA_statusbar_newindex(lua_State *L)
break; break;
case A_TK_BG: case A_TK_BG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(globalconf.connection, if(xcolor_init_reply(xcolor_init_unchecked(&(*statusbar)->colors.bg, buf, len)))
xcolor_init_unchecked(globalconf.connection,
&(*statusbar)->colors.bg,
globalconf.default_screen, buf, len)))
{ {
if((*statusbar)->ctx) if((*statusbar)->ctx)
(*statusbar)->ctx->bg = (*statusbar)->colors.bg; (*statusbar)->ctx->bg = (*statusbar)->colors.bg;

View File

@ -23,8 +23,8 @@
#define AWESOME_STATUSBAR_H #define AWESOME_STATUSBAR_H
#include "structs.h" #include "structs.h"
#include "swindow.h"
#include "common/refcount.h" #include "common/refcount.h"
#include "common/swindow.h"
static inline void static inline void
statusbar_delete(statusbar_t **statusbar) statusbar_delete(statusbar_t **statusbar)

View File

@ -28,12 +28,12 @@
#include "lua.h" #include "lua.h"
#include "layout.h" #include "layout.h"
#include "swindow.h"
#include "xscreen.h"
#include "common/xutil.h" #include "common/xutil.h"
#include "common/draw.h"
#include "common/swindow.h"
#include "common/xscreen.h"
#include "common/xembed.h" #include "common/xembed.h"
#include "common/refcount.h" #include "common/refcount.h"
#include "draw.h"
/** Stacking layout layers */ /** Stacking layout layers */
typedef enum typedef enum

View File

@ -21,11 +21,13 @@
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include "common/swindow.h" #include "structs.h"
#include "swindow.h"
#include "common/xutil.h" #include "common/xutil.h"
extern awesome_t globalconf;
/** Create a simple window. /** Create a simple window.
* \param conn Connection ref.
* \param phys_screen Physical screen number. * \param phys_screen Physical screen number.
* \param x x coordinate. * \param x x coordinate.
* \param y y coordinate. * \param y y coordinate.
@ -36,12 +38,12 @@
* with simplewindow_delete(). * with simplewindow_delete().
*/ */
simple_window_t * simple_window_t *
simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y, simplewindow_new(int phys_screen, int x, int y,
unsigned int w, unsigned int h, unsigned int w, unsigned int h,
unsigned int border_width) unsigned int border_width)
{ {
simple_window_t *sw; simple_window_t *sw;
xcb_screen_t *s = xutil_screen_get(conn, phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
uint32_t create_win_val[3]; uint32_t create_win_val[3];
const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND; const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel }; const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel };
@ -52,7 +54,6 @@ simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y,
sw->geometry.y = y; sw->geometry.y = y;
sw->geometry.width = w; sw->geometry.width = w;
sw->geometry.height = h; sw->geometry.height = h;
sw->connection = conn;
sw->phys_screen = phys_screen; sw->phys_screen = phys_screen;
create_win_val[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE; create_win_val[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE;
@ -63,25 +64,42 @@ simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y,
| XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
| XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_EXPOSURE; | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_EXPOSURE;
sw->window = xcb_generate_id(conn); sw->window = xcb_generate_id(globalconf.connection);
xcb_create_window(conn, s->root_depth, sw->window, s->root, x, y, w, h, xcb_create_window(globalconf.connection, s->root_depth, sw->window, s->root, x, y, w, h,
border_width, XCB_COPY_FROM_PARENT, s->root_visual, border_width, XCB_COPY_FROM_PARENT, s->root_visual,
XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK, XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
create_win_val); create_win_val);
sw->pixmap = xcb_generate_id(conn); sw->pixmap = xcb_generate_id(globalconf.connection);
xcb_create_pixmap(conn, s->root_depth, sw->pixmap, s->root, w, h); xcb_create_pixmap(globalconf.connection, s->root_depth, sw->pixmap, s->root, w, h);
/* The default GC is just a newly created associated to the root /* The default GC is just a newly created associated to the root
* bal
* gg
* window */ * window */
sw->gc = xcb_generate_id(sw->connection); sw->gc = xcb_generate_id(globalconf.connection);
xcb_create_gc(sw->connection, sw->gc, s->root, gc_mask, gc_values); xcb_create_gc(globalconf.connection, sw->gc, s->root, gc_mask, gc_values);
sw->border_width = border_width; sw->border_width = border_width;
return sw; return sw;
} }
/** Destroy a simple window and all its resources.
* \param sw The simple_window_t to delete.
*/
void
simplewindow_delete(simple_window_t **sw)
{
if(*sw)
{
xcb_destroy_window(globalconf.connection, (*sw)->window);
xcb_free_pixmap(globalconf.connection, (*sw)->pixmap);
xcb_free_gc(globalconf.connection, (*sw)->gc);
p_delete(sw);
}
}
/** Move a simple window. /** Move a simple window.
* \param sw The simple window to move. * \param sw The simple window to move.
* \param x New x coordinate. * \param x New x coordinate.
@ -94,7 +112,7 @@ simplewindow_move(simple_window_t *sw, int x, int y)
sw->geometry.x = x; sw->geometry.x = x;
sw->geometry.y = y; sw->geometry.y = y;
xcb_configure_window(sw->connection, sw->window, xcb_configure_window(globalconf.connection, sw->window,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
move_win_vals); move_win_vals);
} }
@ -107,7 +125,7 @@ simplewindow_move(simple_window_t *sw, int x, int y)
void void
simplewindow_resize(simple_window_t *sw, int w, int h) simplewindow_resize(simple_window_t *sw, int w, int h)
{ {
xcb_screen_t *s = xutil_screen_get(sw->connection, sw->phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, sw->phys_screen);
uint32_t resize_win_vals[2]; uint32_t resize_win_vals[2];
xcb_pixmap_t d; xcb_pixmap_t d;
@ -116,12 +134,12 @@ simplewindow_resize(simple_window_t *sw, int w, int h)
sw->geometry.width = resize_win_vals[0] = w; sw->geometry.width = resize_win_vals[0] = w;
sw->geometry.height = resize_win_vals[1] = h; sw->geometry.height = resize_win_vals[1] = h;
d = sw->pixmap; d = sw->pixmap;
sw->pixmap = xcb_generate_id(sw->connection); sw->pixmap = xcb_generate_id(globalconf.connection);
xcb_create_pixmap(sw->connection, s->root_depth, sw->pixmap, s->root, w, h); xcb_create_pixmap(globalconf.connection, s->root_depth, sw->pixmap, s->root, w, h);
xcb_configure_window(sw->connection, sw->window, xcb_configure_window(globalconf.connection, sw->window,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
resize_win_vals); resize_win_vals);
xcb_free_pixmap(sw->connection, d); xcb_free_pixmap(globalconf.connection, d);
} }
} }
@ -137,7 +155,7 @@ simplewindow_moveresize(simple_window_t *sw, int x, int y, int w, int h)
{ {
uint32_t moveresize_win_vals[4], mask_vals = 0; uint32_t moveresize_win_vals[4], mask_vals = 0;
xcb_pixmap_t d; xcb_pixmap_t d;
xcb_screen_t *s = xutil_screen_get(sw->connection, sw->phys_screen); xcb_screen_t *s = xutil_screen_get(globalconf.connection, sw->phys_screen);
if(sw->geometry.x != x || sw->geometry.y != y) if(sw->geometry.x != x || sw->geometry.y != y)
{ {
@ -160,12 +178,47 @@ simplewindow_moveresize(simple_window_t *sw, int x, int y, int w, int h)
} }
mask_vals |= XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; mask_vals |= XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
d = sw->pixmap; d = sw->pixmap;
sw->pixmap = xcb_generate_id(sw->connection); sw->pixmap = xcb_generate_id(globalconf.connection);
xcb_create_pixmap(sw->connection, s->root_depth, sw->pixmap, s->root, w, h); xcb_create_pixmap(globalconf.connection, s->root_depth, sw->pixmap, s->root, w, h);
xcb_free_pixmap(sw->connection, d); xcb_free_pixmap(globalconf.connection, d);
} }
xcb_configure_window(sw->connection, sw->window, mask_vals, moveresize_win_vals); xcb_configure_window(globalconf.connection, sw->window, mask_vals, moveresize_win_vals);
}
/** Refresh the window content by copying its pixmap data to its window.
* \param sw The simple window to refresh.
*/
void
simplewindow_refresh_pixmap(simple_window_t *sw)
{
xcb_copy_area(globalconf.connection, sw->pixmap,
sw->window, sw->gc, 0, 0, 0, 0,
sw->geometry.width,
sw->geometry.height);
}
/** Set a simple window border width.
* \param sw The simple window to change border width.
* \param border_width The border width in pixel.
*/
void
simplewindow_border_width_set(simple_window_t *sw, uint32_t border_width)
{
xcb_configure_window(globalconf.connection, sw->window, XCB_CONFIG_WINDOW_BORDER_WIDTH,
&border_width);
sw->border_width = border_width;
}
/** Set a simple window border color.
* \param sw The simple window to change border width.
* \param color The border color.
*/
void
simplewindow_border_color_set(simple_window_t *sw, const xcolor_t *color)
{
xcb_change_window_attributes(globalconf.connection, sw->window,
XCB_CW_BORDER_PIXEL, &color->pixel);
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

55
swindow.h Normal file
View File

@ -0,0 +1,55 @@
/*
* swindow.h - simple window handling functions 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_COMMON_SWINDOW_H
#define AWESOME_COMMON_SWINDOW_H
#include "draw.h"
/** A simple window. */
typedef struct simple_window_t
{
/** The physical screen number the window is on. */
int phys_screen;
/** The window object. */
xcb_window_t window;
/** The pixmap copied to the window object. */
xcb_pixmap_t pixmap;
/** The graphic context. */
xcb_gcontext_t gc;
/** The window geometry. */
area_t geometry;
/** The window border width */
int border_width;
} simple_window_t;
simple_window_t * simplewindow_new(int, int, int, unsigned int, unsigned int, unsigned int);
void simplewindow_delete(simple_window_t **);
void simplewindow_move(simple_window_t *, int, int);
void simplewindow_resize(simple_window_t *, int, int);
void simplewindow_moveresize(simple_window_t *, int, int, int, int);
void simplewindow_refresh_pixmap(simple_window_t *);
void simplewindow_border_width_set(simple_window_t *, uint32_t);
void simplewindow_border_color_set(simple_window_t *, const xcolor_t *);
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -93,7 +93,7 @@ titlebar_draw(client_t *c)
s->root, s->root,
c->titlebar->sw->geometry.height, c->titlebar->sw->geometry.height,
c->titlebar->sw->geometry.width); c->titlebar->sw->geometry.width);
ctx = draw_context_new(globalconf.connection, c->titlebar->sw->phys_screen, ctx = draw_context_new(c->titlebar->sw->phys_screen,
c->titlebar->sw->geometry.height, c->titlebar->sw->geometry.height,
c->titlebar->sw->geometry.width, c->titlebar->sw->geometry.width,
dw, dw,
@ -101,7 +101,7 @@ titlebar_draw(client_t *c)
&c->titlebar->colors.bg); &c->titlebar->colors.bg);
break; break;
default: default:
ctx = draw_context_new(globalconf.connection, c->titlebar->sw->phys_screen, ctx = draw_context_new(c->titlebar->sw->phys_screen,
c->titlebar->sw->geometry.width, c->titlebar->sw->geometry.width,
c->titlebar->sw->geometry.height, c->titlebar->sw->geometry.height,
c->titlebar->sw->pixmap, c->titlebar->sw->pixmap,
@ -283,7 +283,7 @@ titlebar_init(client_t *c)
titlebar_geometry_compute(c, c->geometry, &geom); titlebar_geometry_compute(c, c->geometry, &geom);
c->titlebar->sw = simplewindow_new(globalconf.connection, c->phys_screen, geom.x, geom.y, c->titlebar->sw = simplewindow_new(c->phys_screen, geom.x, geom.y,
geom.width, geom.height, c->titlebar->border.width); geom.width, geom.height, c->titlebar->border.width);
if(c->titlebar->border.width) if(c->titlebar->border.width)
@ -331,29 +331,20 @@ luaA_titlebar_new(lua_State *L)
tb->colors.fg = globalconf.colors.fg; tb->colors.fg = globalconf.colors.fg;
if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&tb->colors.fg, buf, len);
&tb->colors.fg,
globalconf.default_screen,
buf, len);
tb->colors.bg = globalconf.colors.bg; tb->colors.bg = globalconf.colors.bg;
if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&tb->colors.bg, buf, len);
&tb->colors.bg,
globalconf.default_screen,
buf, len);
tb->border.color = globalconf.colors.fg; tb->border.color = globalconf.colors.fg;
if((buf = luaA_getopt_lstring(L, 2, "border_color", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "border_color", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&tb->border.color, buf, len);
&tb->border.color,
globalconf.default_screen,
buf, len);
tb->border.width = luaA_getopt_number(L, 2, "border_width", 0); tb->border.width = luaA_getopt_number(L, 2, "border_width", 0);
for(i = 0; i <= reqs_nbr; i++) for(i = 0; i <= reqs_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]); xcolor_init_reply(reqs[i]);
return luaA_titlebar_userdata_new(globalconf.L, tb); return luaA_titlebar_userdata_new(globalconf.L, tb);
} }
@ -422,30 +413,19 @@ luaA_titlebar_newindex(lua_State *L)
break; break;
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(globalconf.connection, if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->border.color, buf, len)))
xcolor_init_unchecked(globalconf.connection,
&(*titlebar)->border.color,
globalconf.default_screen, buf, len)))
if((*titlebar)->sw) if((*titlebar)->sw)
xcb_change_window_attributes(globalconf.connection, (*titlebar)->sw->window, xcb_change_window_attributes(globalconf.connection, (*titlebar)->sw->window,
XCB_CW_BORDER_PIXEL, &(*titlebar)->border.color.pixel); XCB_CW_BORDER_PIXEL, &(*titlebar)->border.color.pixel);
return 0; return 0;
case A_TK_FG: case A_TK_FG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(globalconf.connection, if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->colors.fg, buf, len)))
xcolor_init_unchecked(globalconf.connection,
&(*titlebar)->colors.fg,
globalconf.default_screen,
buf, len)))
(*titlebar)->need_update = true; (*titlebar)->need_update = true;
return 0; return 0;
case A_TK_BG: case A_TK_BG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(globalconf.connection, if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->colors.bg, buf, len)))
xcolor_init_unchecked(globalconf.connection,
&(*titlebar)->colors.bg,
globalconf.default_screen,
buf, len)))
(*titlebar)->need_update = true; (*titlebar)->need_update = true;
break; break;
case A_TK_POSITION: case A_TK_POSITION:

View File

@ -24,7 +24,6 @@
#include "widget.h" #include "widget.h"
#include "common/tokenize.h" #include "common/tokenize.h"
#include "common/draw.h"
extern awesome_t globalconf; extern awesome_t globalconf;
@ -302,22 +301,13 @@ luaA_graph_plot_properties_set(lua_State *L)
plot = graph_plot_add(d, title); plot = graph_plot_add(d, title);
if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&plot->color_start, buf, len);
&plot->color_start,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&plot->pcolor_center, buf, len);
&plot->pcolor_center,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&plot->pcolor_end, buf, len);
&plot->pcolor_end,
globalconf.default_screen,
buf, len);
plot->vertical_gradient = luaA_getopt_boolean(L, 3, "vertical_gradient", plot->vertical_gradient); plot->vertical_gradient = luaA_getopt_boolean(L, 3, "vertical_gradient", plot->vertical_gradient);
plot->scale = luaA_getopt_boolean(L, 3, "scale", plot->scale); plot->scale = luaA_getopt_boolean(L, 3, "scale", plot->scale);
@ -343,7 +333,7 @@ luaA_graph_plot_properties_set(lua_State *L)
} }
for(i = 0; i <= reqs_nbr; i++) for(i = 0; i <= reqs_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]); xcolor_init_reply(reqs[i]);
widget_invalidate_bywidget(*widget); widget_invalidate_bywidget(*widget);
@ -529,11 +519,7 @@ luaA_graph_newindex(lua_State *L, awesome_token_t token)
case A_TK_BG: case A_TK_BG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
{ {
if(xcolor_init_reply(globalconf.connection, if(xcolor_init_reply(xcolor_init_unchecked(&color, buf, len)))
xcolor_init_unchecked(globalconf.connection,
&color,
globalconf.default_screen,
buf, len)))
d->bg = color; d->bg = color;
else else
return 0; return 0;
@ -542,11 +528,7 @@ luaA_graph_newindex(lua_State *L, awesome_token_t token)
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
{ {
if(xcolor_init_reply(globalconf.connection, if(xcolor_init_reply(xcolor_init_unchecked(&color, buf, len)))
xcolor_init_unchecked(globalconf.connection,
&color,
globalconf.default_screen,
buf, len)))
d->border_color = color; d->border_color = color;
else else
return 0; return 0;

View File

@ -431,40 +431,22 @@ luaA_progressbar_bar_properties_set(lua_State *L)
bar = progressbar_bar_add(d, title); bar = progressbar_bar_add(d, title);
if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&bar->fg, buf, len);
&bar->fg,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_off", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_off", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&bar->fg_off, buf, len);
&bar->fg_off,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "bg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "bg", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&bar->bg, buf, len);
&bar->bg,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "border_color", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "border_color", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&bar->border_color, buf, len);
&bar->border_color,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&bar->fg_center, buf, len);
&bar->fg_center,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len)))
reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(&bar->fg_end, buf, len);
&bar->fg_end,
globalconf.default_screen,
buf, len);
bar->min_value = luaA_getopt_number(L, 3, "min_value", bar->min_value); bar->min_value = luaA_getopt_number(L, 3, "min_value", bar->min_value);
/* hack to prevent max_value beeing less than min_value /* hack to prevent max_value beeing less than min_value
@ -484,7 +466,7 @@ luaA_progressbar_bar_properties_set(lua_State *L)
bar->reverse = luaA_getopt_boolean(L, 3, "reverse", bar->reverse); bar->reverse = luaA_getopt_boolean(L, 3, "reverse", bar->reverse);
for(i = 0; i <= reqs_nbr; i++) for(i = 0; i <= reqs_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]); xcolor_init_reply(reqs[i]);
widget_invalidate_bywidget(*widget); widget_invalidate_bywidget(*widget);

View File

@ -126,7 +126,7 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w,
lua_pop(globalconf.L, 1); lua_pop(globalconf.L, 1);
draw_parser_data_init(&pdata[i]); draw_parser_data_init(&pdata[i]);
area = draw_text_extents(ctx->connection, ctx->phys_screen, area = draw_text_extents(ctx->phys_screen,
globalconf.font, text[i], len[i], &pdata[i]); globalconf.font, text[i], len[i], &pdata[i]);
if(pdata[i].bg_image) if(pdata[i].bg_image)

View File

@ -122,9 +122,6 @@ tasklist_draw_item(draw_context_t *ctx,
{ {
draw_parser_data_init(&pdata); draw_parser_data_init(&pdata);
pdata.connection = ctx->connection;
pdata.phys_screen = ctx->phys_screen;
/* Actually look for the proper background color, since /* Actually look for the proper background color, since
* otherwise the background statusbar color is used instead */ * otherwise the background statusbar color is used instead */
if(draw_text_markup_expand(&pdata, if(draw_text_markup_expand(&pdata,

View File

@ -153,7 +153,7 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
if(buf) if(buf)
{ {
a_iso2utf8(&d->text, buf, len); a_iso2utf8(&d->text, buf, len);
d->extents = draw_text_extents(globalconf.connection, globalconf.default_screen, d->extents = draw_text_extents(globalconf.default_screen,
globalconf.font, d->text, d->len, &d->pdata).width; globalconf.font, d->text, d->len, &d->pdata).width;
} }
else else

View File

@ -1,5 +1,5 @@
/* /*
* common/xscreen.c - common X screen management * xscreen.c - common X screen management
* *
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info> * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
* *
@ -22,8 +22,10 @@
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xinerama.h> #include <xcb/xinerama.h>
#include "common/xscreen.h" #include "xscreen.h"
#include "common/xutil.h" #include "structs.h"
extern awesome_t globalconf;
static inline area_t static inline area_t
screen_xsitoarea(xcb_xinerama_screen_info_t si) screen_xsitoarea(xcb_xinerama_screen_info_t si)
@ -46,11 +48,10 @@ screensinfo_delete(screens_info_t **si)
} }
/** Get screens informations. /** Get screens informations.
* \param conn X connection.
* \return A pointer to complete screens_info_t structure. * \return A pointer to complete screens_info_t structure.
*/ */
screens_info_t * screens_info_t *
screensinfo_new(xcb_connection_t *conn) screensinfo_new(void)
{ {
screens_info_t *si; screens_info_t *si;
xcb_xinerama_query_screens_reply_t *xsq; xcb_xinerama_query_screens_reply_t *xsq;
@ -63,17 +64,17 @@ screensinfo_new(xcb_connection_t *conn)
si = p_new(screens_info_t, 1); si = p_new(screens_info_t, 1);
/* Check for extension before checking for Xinerama */ /* Check for extension before checking for Xinerama */
if(xcb_get_extension_data(conn, &xcb_xinerama_id)->present) if(xcb_get_extension_data(globalconf.connection, &xcb_xinerama_id)->present)
{ {
xia = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL); xia = xcb_xinerama_is_active_reply(globalconf.connection, xcb_xinerama_is_active(globalconf.connection), NULL);
si->xinerama_is_active = xia->state; si->xinerama_is_active = xia->state;
p_delete(&xia); p_delete(&xia);
} }
if(si->xinerama_is_active) if(si->xinerama_is_active)
{ {
xsq = xcb_xinerama_query_screens_reply(conn, xsq = xcb_xinerama_query_screens_reply(globalconf.connection,
xcb_xinerama_query_screens_unchecked(conn), xcb_xinerama_query_screens_unchecked(globalconf.connection),
NULL); NULL);
xsi = xcb_xinerama_query_screens_screen_info(xsq); xsi = xcb_xinerama_query_screens_screen_info(xsq);
@ -115,11 +116,11 @@ screensinfo_new(xcb_connection_t *conn)
} }
else else
{ {
si->nscreen = xcb_setup_roots_length(xcb_get_setup(conn)); si->nscreen = xcb_setup_roots_length(xcb_get_setup(globalconf.connection));
si->geometry = p_new(area_t, si->nscreen); si->geometry = p_new(area_t, si->nscreen);
for(screen = 0; screen < si->nscreen; screen++) for(screen = 0; screen < si->nscreen; screen++)
{ {
s = xutil_screen_get(conn, screen); s = xutil_screen_get(globalconf.connection, screen);
si->geometry[screen].x = 0; si->geometry[screen].x = 0;
si->geometry[screen].y = 0; si->geometry[screen].y = 0;
si->geometry[screen].width = s->width_in_pixels; si->geometry[screen].width = s->width_in_pixels;

View File

@ -22,7 +22,7 @@
#ifndef AWESOME_COMMON_XSCREEN_H #ifndef AWESOME_COMMON_XSCREEN_H
#define AWESOME_COMMON_XSCREEN_H #define AWESOME_COMMON_XSCREEN_H
#include "common/draw.h" #include "draw.h"
typedef struct typedef struct
{ {
@ -32,7 +32,7 @@ typedef struct
} screens_info_t; } screens_info_t;
void screensinfo_delete(screens_info_t **); void screensinfo_delete(screens_info_t **);
screens_info_t * screensinfo_new(xcb_connection_t *); screens_info_t * screensinfo_new(void);
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80