make draw functions more independant
This commit is contained in:
parent
82d9cec79d
commit
35803aff4c
4
client.h
4
client.h
|
@ -27,11 +27,11 @@
|
||||||
Bool client_isvisible(Client *, int);
|
Bool client_isvisible(Client *, int);
|
||||||
Client * get_client_bywin(Client *, Window);
|
Client * get_client_bywin(Client *, Window);
|
||||||
Client * get_client_byname(Client *, char *);
|
Client * get_client_byname(Client *, char *);
|
||||||
void client_ban(Client *);
|
|
||||||
void focus(Client *, Bool, int);
|
void focus(Client *, Bool, int);
|
||||||
|
void client_ban(Client *);
|
||||||
|
void client_unban(Client *);
|
||||||
void client_manage(Window, XWindowAttributes *, int);
|
void client_manage(Window, XWindowAttributes *, int);
|
||||||
Bool client_resize(Client *, Area, Bool);
|
Bool client_resize(Client *, Area, Bool);
|
||||||
void client_unban(Client *);
|
|
||||||
void client_unmanage(Client *);
|
void client_unmanage(Client *);
|
||||||
void client_updatewmhints(Client *);
|
void client_updatewmhints(Client *);
|
||||||
void client_updatesizehints(Client *);
|
void client_updatesizehints(Client *);
|
||||||
|
|
43
draw.c
43
draw.c
|
@ -23,11 +23,9 @@
|
||||||
#include <cairo-ft.h>
|
#include <cairo-ft.h>
|
||||||
#include <cairo-xlib.h>
|
#include <cairo-xlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "structs.h"
|
#include "draw.h"
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
|
|
||||||
extern AwesomeConf globalconf;
|
|
||||||
|
|
||||||
/** Get a draw context
|
/** Get a draw context
|
||||||
* \param phys_screen physical screen id
|
* \param phys_screen physical screen id
|
||||||
* \param width width
|
* \param width width
|
||||||
|
@ -35,15 +33,16 @@ extern AwesomeConf globalconf;
|
||||||
* \return draw context ref
|
* \return draw context ref
|
||||||
*/
|
*/
|
||||||
DrawCtx *
|
DrawCtx *
|
||||||
draw_get_context(int phys_screen, int width, int height, Drawable dw)
|
draw_get_context(Display *disp, int phys_screen, int width, int height, Drawable dw)
|
||||||
{
|
{
|
||||||
DrawCtx *d = p_new(DrawCtx, 1);
|
DrawCtx *d = p_new(DrawCtx, 1);
|
||||||
|
|
||||||
|
d->display = disp;
|
||||||
d->phys_screen = phys_screen;
|
d->phys_screen = phys_screen;
|
||||||
d->width = width;
|
d->width = width;
|
||||||
d->height = height;
|
d->height = height;
|
||||||
d->depth = DefaultDepth(globalconf.display, phys_screen);
|
d->depth = DefaultDepth(disp, phys_screen);
|
||||||
d->visual = DefaultVisual(globalconf.display, phys_screen);
|
d->visual = DefaultVisual(disp, phys_screen);
|
||||||
d->drawable = dw;
|
d->drawable = dw;
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
|
@ -83,7 +82,7 @@ draw_text(DrawCtx *ctx,
|
||||||
if(!len)
|
if(!len)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
||||||
cr = cairo_create(surface);
|
cr = cairo_create(surface);
|
||||||
font_face = cairo_ft_font_face_create_for_pattern(font->pattern);
|
font_face = cairo_ft_font_face_create_for_pattern(font->pattern);
|
||||||
cairo_set_font_face(cr, font_face);
|
cairo_set_font_face(cr, font_face);
|
||||||
|
@ -94,7 +93,7 @@ draw_text(DrawCtx *ctx,
|
||||||
len = sizeof(buf) - 1;
|
len = sizeof(buf) - 1;
|
||||||
memcpy(buf, text, len);
|
memcpy(buf, text, len);
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
while(len && (nw = (draw_textwidth(font, buf)) + padding * 2) > area.width)
|
while(len && (nw = (draw_textwidth(ctx->display, font, buf)) + padding * 2) > area.width)
|
||||||
buf[--len] = 0;
|
buf[--len] = 0;
|
||||||
if(nw > area.width)
|
if(nw > area.width)
|
||||||
return; /* too long */
|
return; /* too long */
|
||||||
|
@ -141,7 +140,7 @@ draw_rectangle(DrawCtx *ctx, Area geometry, Bool filled, XColor color)
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
|
|
||||||
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
||||||
cr = cairo_create (surface);
|
cr = cairo_create (surface);
|
||||||
|
|
||||||
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
|
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
|
||||||
|
@ -172,7 +171,7 @@ draw_graph(DrawCtx *ctx, int x, int y, int w, int *h, int h_index, XColor color)
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
||||||
cr = cairo_create (surface);
|
cr = cairo_create (surface);
|
||||||
|
|
||||||
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
|
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
|
||||||
|
@ -202,7 +201,7 @@ draw_circle(DrawCtx *ctx, int x, int y, int r, Bool filled, XColor color)
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
|
|
||||||
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
||||||
cr = cairo_create (surface);
|
cr = cairo_create (surface);
|
||||||
cairo_set_line_width(cr, 1.0);
|
cairo_set_line_width(cr, 1.0);
|
||||||
cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
|
cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
|
||||||
|
@ -227,7 +226,7 @@ void draw_image_from_argb_data(DrawCtx *ctx, int x, int y, int w, int h,
|
||||||
cairo_surface_t *surface, *source;
|
cairo_surface_t *surface, *source;
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
|
|
||||||
surface = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
||||||
source = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, w, h, 0);
|
source = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, w, h, 0);
|
||||||
cr = cairo_create (surface);
|
cr = cairo_create (surface);
|
||||||
if(wanted_h > 0 && h > 0)
|
if(wanted_h > 0 && h > 0)
|
||||||
|
@ -254,7 +253,7 @@ draw_image(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename)
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
cairo_status_t cairo_st;
|
cairo_status_t cairo_st;
|
||||||
|
|
||||||
source = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
||||||
surface = cairo_image_surface_create_from_png(filename);
|
surface = cairo_image_surface_create_from_png(filename);
|
||||||
if((cairo_st = cairo_surface_status(surface)))
|
if((cairo_st = cairo_surface_status(surface)))
|
||||||
{
|
{
|
||||||
|
@ -307,12 +306,12 @@ draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty)
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
Drawable newdrawable;
|
Drawable newdrawable;
|
||||||
|
|
||||||
newdrawable = XCreatePixmap(globalconf.display,
|
newdrawable = XCreatePixmap(ctx->display,
|
||||||
RootWindow(globalconf.display, screen),
|
RootWindow(ctx->display, screen),
|
||||||
ctx->height, ctx->width,
|
ctx->height, ctx->width,
|
||||||
ctx->depth);
|
ctx->depth);
|
||||||
surface = cairo_xlib_surface_create(globalconf.display, newdrawable, ctx->visual, ctx->height, ctx->width);
|
surface = cairo_xlib_surface_create(ctx->display, newdrawable, ctx->visual, ctx->height, ctx->width);
|
||||||
source = cairo_xlib_surface_create(globalconf.display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height);
|
||||||
cr = cairo_create (surface);
|
cr = cairo_create (surface);
|
||||||
|
|
||||||
cairo_translate(cr, tx, ty);
|
cairo_translate(cr, tx, ty);
|
||||||
|
@ -329,7 +328,7 @@ draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short
|
unsigned short
|
||||||
draw_textwidth(XftFont *font, char *text)
|
draw_textwidth(Display *disp, XftFont *font, char *text)
|
||||||
{
|
{
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
|
@ -339,10 +338,10 @@ draw_textwidth(XftFont *font, char *text)
|
||||||
if (!a_strlen(text))
|
if (!a_strlen(text))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
surface = cairo_xlib_surface_create(globalconf.display, DefaultScreen(globalconf.display),
|
surface = cairo_xlib_surface_create(disp, DefaultScreen(disp),
|
||||||
DefaultVisual(globalconf.display, DefaultScreen(globalconf.display)),
|
DefaultVisual(disp, DefaultScreen(disp)),
|
||||||
DisplayWidth(globalconf.display, DefaultScreen(globalconf.display)),
|
DisplayWidth(disp, DefaultScreen(disp)),
|
||||||
DisplayHeight(globalconf.display, DefaultScreen(globalconf.display)));
|
DisplayHeight(disp, DefaultScreen(disp)));
|
||||||
cr = cairo_create(surface);
|
cr = cairo_create(surface);
|
||||||
font_face = cairo_ft_font_face_create_for_pattern(font->pattern);
|
font_face = cairo_ft_font_face_create_for_pattern(font->pattern);
|
||||||
cairo_set_font_face(cr, font_face);
|
cairo_set_font_face(cr, font_face);
|
||||||
|
|
5
draw.h
5
draw.h
|
@ -44,6 +44,7 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
Display *display;
|
||||||
Drawable drawable;
|
Drawable drawable;
|
||||||
Visual *visual;
|
Visual *visual;
|
||||||
int width;
|
int width;
|
||||||
|
@ -52,7 +53,7 @@ typedef struct
|
||||||
int depth;
|
int depth;
|
||||||
} DrawCtx;
|
} DrawCtx;
|
||||||
|
|
||||||
DrawCtx *draw_get_context(int, int, int, Drawable);
|
DrawCtx *draw_get_context(Display *, int, int, int, Drawable);
|
||||||
void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, const char *, XColor fg, XColor bg);
|
void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, const char *, XColor fg, XColor bg);
|
||||||
void draw_rectangle(DrawCtx *, Area, Bool, XColor);
|
void draw_rectangle(DrawCtx *, Area, Bool, XColor);
|
||||||
void draw_graph(DrawCtx *, int, int, int, int *, int, XColor);
|
void draw_graph(DrawCtx *, int, int, int, int *, int, XColor);
|
||||||
|
@ -61,7 +62,7 @@ void draw_image(DrawCtx *, int, int, int, const char *);
|
||||||
void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *);
|
void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *);
|
||||||
Area draw_get_image_size(const char *filename);
|
Area draw_get_image_size(const char *filename);
|
||||||
Drawable draw_rotate(DrawCtx *, int, double, int, int);
|
Drawable draw_rotate(DrawCtx *, int, double, int, int);
|
||||||
unsigned short draw_textwidth(XftFont *, char *);
|
unsigned short draw_textwidth(Display *, XftFont *, char *);
|
||||||
Alignment draw_get_align(const char *);
|
Alignment draw_get_align(const char *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -98,7 +98,8 @@ statusbar_draw(Statusbar *statusbar)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawCtx *ctx = draw_get_context(phys_screen,
|
DrawCtx *ctx = draw_get_context(globalconf.display,
|
||||||
|
phys_screen,
|
||||||
statusbar->width,
|
statusbar->width,
|
||||||
statusbar->height,
|
statusbar->height,
|
||||||
statusbar->sw->drawable);
|
statusbar->sw->drawable);
|
||||||
|
|
|
@ -75,7 +75,8 @@ taglist_draw(Widget *widget,
|
||||||
widget->area.width = 0;
|
widget->area.width = 0;
|
||||||
|
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next)
|
for(tag = vscreen.tags; tag; tag = tag->next)
|
||||||
widget->area.width += draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
|
widget->area.width += draw_textwidth(ctx->display, vscreen.font, tag->name)
|
||||||
|
+ vscreen.font->height;
|
||||||
|
|
||||||
if(!widget->user_supplied_x)
|
if(!widget->user_supplied_x)
|
||||||
widget->area.x = widget_calculate_offset(widget->statusbar->width,
|
widget->area.x = widget_calculate_offset(widget->statusbar->width,
|
||||||
|
@ -89,7 +90,7 @@ taglist_draw(Widget *widget,
|
||||||
widget->area.width = 0;
|
widget->area.width = 0;
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next)
|
for(tag = vscreen.tags; tag; tag = tag->next)
|
||||||
{
|
{
|
||||||
w = draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
|
w = draw_textwidth(ctx->display, vscreen.font, tag->name) + vscreen.font->height;
|
||||||
if(tag->selected)
|
if(tag->selected)
|
||||||
colors = vscreen.colors_selected;
|
colors = vscreen.colors_selected;
|
||||||
else if(isurgent(tag))
|
else if(isurgent(tag))
|
||||||
|
@ -139,7 +140,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
||||||
case Bottom:
|
case Bottom:
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
||||||
{
|
{
|
||||||
width = draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
|
width = draw_textwidth(globalconf.display, vscreen.font, tag->name)
|
||||||
|
+ vscreen.font->height;
|
||||||
if(ev->x >= widget->area.x + prev_width
|
if(ev->x >= widget->area.x + prev_width
|
||||||
&& ev->x < widget->area.x + prev_width + width)
|
&& ev->x < widget->area.x + prev_width + width)
|
||||||
{
|
{
|
||||||
|
@ -153,7 +155,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
||||||
case Right:
|
case Right:
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
||||||
{
|
{
|
||||||
width = draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
|
width = draw_textwidth(globalconf.display, vscreen.font, tag->name) + vscreen.font->height;
|
||||||
if(ev->y >= widget->area.x + prev_width
|
if(ev->y >= widget->area.x + prev_width
|
||||||
&& ev->y < widget->area.x + prev_width + width)
|
&& ev->y < widget->area.x + prev_width + width)
|
||||||
{
|
{
|
||||||
|
@ -167,7 +169,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
|
||||||
default:
|
default:
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
||||||
{
|
{
|
||||||
width = draw_textwidth(vscreen.font, tag->name) + vscreen.font->height;
|
width = draw_textwidth(globalconf.display, vscreen.font, tag->name) + vscreen.font->height;
|
||||||
if(widget->statusbar->width - ev->y >= widget->area.x + prev_width
|
if(widget->statusbar->width - ev->y >= widget->area.x + prev_width
|
||||||
&& widget->statusbar->width - ev->y < widget->area.x + prev_width + width)
|
&& widget->statusbar->width - ev->y < widget->area.x + prev_width + width)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
||||||
if(d->width)
|
if(d->width)
|
||||||
widget->area.width = d->width;
|
widget->area.width = d->width;
|
||||||
else
|
else
|
||||||
widget->area.width = MIN(draw_textwidth(widget->font, d->text),
|
widget->area.width = MIN(draw_textwidth(ctx->display, widget->font, d->text),
|
||||||
widget->statusbar->width - used);
|
widget->statusbar->width - used);
|
||||||
|
|
||||||
widget->area.height = widget->statusbar->height;
|
widget->area.height = widget->statusbar->height;
|
||||||
|
|
Loading…
Reference in New Issue