draw: merge draw context into swindow
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
69d06723df
commit
fcc93e5f88
61
draw.c
61
draw.c
|
@ -101,38 +101,6 @@ draw_screen_default_visual(xcb_screen_t *s)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/** Create a new draw context.
|
||||
* \param phys_screen Physical screen id.
|
||||
* \param width Width.
|
||||
* \param height Height.
|
||||
* \param px Pixmap object to store.
|
||||
* \param fg Foreground color.
|
||||
* \param bg Background color.
|
||||
* \return A draw context pointer.
|
||||
*/
|
||||
draw_context_t *
|
||||
draw_context_new(int phys_screen,
|
||||
int width, int height, xcb_pixmap_t px,
|
||||
const xcolor_t *fg, const xcolor_t *bg)
|
||||
{
|
||||
draw_context_t *d = p_new(draw_context_t, 1);
|
||||
xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
|
||||
|
||||
d->phys_screen = phys_screen;
|
||||
d->width = width;
|
||||
d->height = height;
|
||||
d->depth = s->root_depth;
|
||||
d->visual = draw_screen_default_visual(s);
|
||||
d->pixmap = px;
|
||||
d->surface = cairo_xcb_surface_create(globalconf.connection, px, d->visual, width, height);
|
||||
d->cr = cairo_create(d->surface);
|
||||
d->layout = pango_cairo_create_layout(d->cr);
|
||||
d->fg = *fg;
|
||||
d->bg = *bg;
|
||||
|
||||
return d;
|
||||
};
|
||||
|
||||
/** Create a new Pango font
|
||||
* \param phys_screen The physical screen number.
|
||||
* \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE])
|
||||
|
@ -332,6 +300,35 @@ draw_text_markup_expand(draw_parser_data_t *data,
|
|||
return ret;
|
||||
}
|
||||
|
||||
/** Initialize a new draw context.
|
||||
* \param d The draw context to initialize.
|
||||
* \param phys_screen Physical screen id.
|
||||
* \param width Width.
|
||||
* \param height Height.
|
||||
* \param px Pixmap object to store.
|
||||
* \param fg Foreground color.
|
||||
* \param bg Background color.
|
||||
*/
|
||||
void
|
||||
draw_context_init(draw_context_t *d, int phys_screen,
|
||||
int width, int height, xcb_pixmap_t px,
|
||||
const xcolor_t *fg, const xcolor_t *bg)
|
||||
{
|
||||
xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
|
||||
|
||||
d->phys_screen = phys_screen;
|
||||
d->width = width;
|
||||
d->height = height;
|
||||
d->depth = s->root_depth;
|
||||
d->visual = draw_screen_default_visual(s);
|
||||
d->pixmap = px;
|
||||
d->surface = cairo_xcb_surface_create(globalconf.connection, px, d->visual, width, height);
|
||||
d->cr = cairo_create(d->surface);
|
||||
d->layout = pango_cairo_create_layout(d->cr);
|
||||
d->fg = *fg;
|
||||
d->bg = *bg;
|
||||
};
|
||||
|
||||
/** Draw text into a draw context.
|
||||
* \param ctx Draw context to draw to.
|
||||
* \param font The font to use.
|
||||
|
|
25
draw.h
25
draw.h
|
@ -31,6 +31,7 @@
|
|||
#include "common/array.h"
|
||||
#include "common/list.h"
|
||||
#include "common/buffer.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -100,26 +101,18 @@ typedef struct
|
|||
xcolor_t bg;
|
||||
} draw_context_t;
|
||||
|
||||
draw_context_t *
|
||||
draw_context_new(int, int, int, xcb_drawable_t,
|
||||
const xcolor_t *, const xcolor_t*);
|
||||
void draw_context_init(draw_context_t *, int, int, int,
|
||||
xcb_pixmap_t, const xcolor_t *, const xcolor_t *);
|
||||
|
||||
/** Delete a draw context.
|
||||
* \param ctx The draw_context_t to delete.
|
||||
/** Wipe a draw context.
|
||||
* \param ctx The draw_context_t to wipe.
|
||||
*/
|
||||
static inline void
|
||||
draw_context_delete(draw_context_t **ctx)
|
||||
draw_context_wipe(draw_context_t *ctx)
|
||||
{
|
||||
if(*ctx)
|
||||
{
|
||||
if((*ctx)->layout)
|
||||
g_object_unref((*ctx)->layout);
|
||||
if((*ctx)->surface)
|
||||
cairo_surface_destroy((*ctx)->surface);
|
||||
if((*ctx)->cr)
|
||||
cairo_destroy((*ctx)->cr);
|
||||
p_delete(ctx);
|
||||
}
|
||||
g_object_unref(ctx->layout);
|
||||
cairo_surface_destroy(ctx->surface);
|
||||
cairo_destroy(ctx->cr);
|
||||
}
|
||||
|
||||
font_t *draw_font_new(int, const char *);
|
||||
|
|
49
mouse.c
49
mouse.c
|
@ -234,24 +234,22 @@ mouse_snap_to_corner(area_t a, int *x, int *y, corner_t corner)
|
|||
}
|
||||
|
||||
/** Redraw the infobox.
|
||||
* \param ctx Draw context.
|
||||
* \param sw The simple window.
|
||||
* \param geometry The geometry to use for the box.
|
||||
* \param border The client border size.
|
||||
*/
|
||||
static void
|
||||
mouse_infobox_draw(draw_context_t *ctx,
|
||||
simple_window_t *sw,
|
||||
mouse_infobox_draw(simple_window_t *sw,
|
||||
area_t geometry, int border)
|
||||
{
|
||||
area_t draw_geometry = { 0, 0, ctx->width, ctx->height };
|
||||
area_t draw_geometry = { 0, 0, sw->ctx.width, sw->ctx.height };
|
||||
char size[64];
|
||||
size_t len;
|
||||
|
||||
len = snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d",
|
||||
geometry.width, geometry.height, geometry.x, geometry.y);
|
||||
draw_rectangle(ctx, draw_geometry, 1.0, true, &globalconf.colors.bg);
|
||||
draw_text(ctx, globalconf.font, draw_geometry, size, len, NULL);
|
||||
draw_rectangle(&sw->ctx, draw_geometry, 1.0, true, &globalconf.colors.bg);
|
||||
draw_text(&sw->ctx, globalconf.font, draw_geometry, size, len, NULL);
|
||||
simplewindow_move(sw,
|
||||
geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2,
|
||||
geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2);
|
||||
|
@ -265,12 +263,10 @@ mouse_infobox_draw(draw_context_t *ctx,
|
|||
* \param phys_screen Physical screen number.
|
||||
* \param border Border size of the client.
|
||||
* \param geometry Client geometry.
|
||||
* \param ctx Draw context to create.
|
||||
* \return The simple window.
|
||||
*/
|
||||
static simple_window_t *
|
||||
mouse_infobox_new(int phys_screen, int border, area_t geometry,
|
||||
draw_context_t **ctx)
|
||||
mouse_infobox_new(int phys_screen, int border, area_t geometry)
|
||||
{
|
||||
simple_window_t *sw;
|
||||
area_t geom;
|
||||
|
@ -288,16 +284,11 @@ mouse_infobox_new(int phys_screen, int border, area_t geometry,
|
|||
|
||||
sw = simplewindow_new(phys_screen,
|
||||
geom.x, geom.y,
|
||||
geom.width, geom.height, 0);
|
||||
|
||||
*ctx = draw_context_new(sw->phys_screen,
|
||||
sw->geometry.width, sw->geometry.height,
|
||||
sw->pixmap,
|
||||
&globalconf.colors.fg,
|
||||
&globalconf.colors.bg);
|
||||
geom.width, geom.height, 0,
|
||||
Top, &globalconf.colors.fg, &globalconf.colors.bg);
|
||||
|
||||
xcb_map_window(globalconf.connection, sw->window);
|
||||
mouse_infobox_draw(*ctx, sw, geometry, border);
|
||||
mouse_infobox_draw(sw, geometry, border);
|
||||
|
||||
draw_parser_data_wipe(&pdata);
|
||||
|
||||
|
@ -487,7 +478,6 @@ mouse_client_move(client_t *c, int snap, bool infobox)
|
|||
layout_t *layout;
|
||||
/* the infobox */
|
||||
simple_window_t *sw = NULL;
|
||||
draw_context_t *ctx;
|
||||
/* the root window */
|
||||
xcb_window_t root;
|
||||
|
||||
|
@ -506,7 +496,7 @@ mouse_client_move(client_t *c, int snap, bool infobox)
|
|||
return;
|
||||
|
||||
if(infobox && (client_isfloating(c) || layout == layout_floating))
|
||||
sw = mouse_infobox_new(c->phys_screen, c->border, c->geometry, &ctx);
|
||||
sw = mouse_infobox_new(c->phys_screen, c->border, c->geometry);
|
||||
|
||||
/* for each motion event */
|
||||
while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
|
||||
|
@ -528,7 +518,7 @@ mouse_client_move(client_t *c, int snap, bool infobox)
|
|||
|
||||
/* draw the infobox */
|
||||
if(sw)
|
||||
mouse_infobox_draw(ctx, sw, c->geometry, c->border);
|
||||
mouse_infobox_draw(sw, c->geometry, c->border);
|
||||
|
||||
statusbar_refresh();
|
||||
|
||||
|
@ -571,10 +561,7 @@ mouse_client_move(client_t *c, int snap, bool infobox)
|
|||
|
||||
/* free the infobox */
|
||||
if(sw)
|
||||
{
|
||||
draw_context_delete(&ctx);
|
||||
simplewindow_delete(&sw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -593,7 +580,6 @@ mouse_client_resize_floating(client_t *c, corner_t corner, bool infobox)
|
|||
int mouse_x = 0, mouse_y = 0;
|
||||
/* the infobox */
|
||||
simple_window_t *sw = NULL;
|
||||
draw_context_t *ctx;
|
||||
size_t cursor = CurResize;
|
||||
int top, bottom, left, right;
|
||||
|
||||
|
@ -640,7 +626,7 @@ mouse_client_resize_floating(client_t *c, corner_t corner, bool infobox)
|
|||
|
||||
/* create the infobox */
|
||||
if(infobox)
|
||||
sw = mouse_infobox_new(c->phys_screen, c->border, c->geometry, &ctx);
|
||||
sw = mouse_infobox_new(c->phys_screen, c->border, c->geometry);
|
||||
|
||||
/* for each motion event */
|
||||
while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
|
||||
|
@ -714,7 +700,7 @@ mouse_client_resize_floating(client_t *c, corner_t corner, bool infobox)
|
|||
|
||||
/* draw the infobox */
|
||||
if(sw)
|
||||
mouse_infobox_draw(ctx, sw, c->geometry, c->border);
|
||||
mouse_infobox_draw(sw, c->geometry, c->border);
|
||||
}
|
||||
|
||||
/* relase pointer */
|
||||
|
@ -722,10 +708,7 @@ mouse_client_resize_floating(client_t *c, corner_t corner, bool infobox)
|
|||
|
||||
/* free the infobox */
|
||||
if(sw)
|
||||
{
|
||||
draw_context_delete(&ctx);
|
||||
simplewindow_delete(&sw);
|
||||
}
|
||||
}
|
||||
|
||||
/** Resize the master column/row of a tiled layout
|
||||
|
@ -846,7 +829,6 @@ mouse_client_resize_magnified(client_t *c, bool infobox)
|
|||
tag_t *tag;
|
||||
/* the infobox */
|
||||
simple_window_t *sw = NULL;
|
||||
draw_context_t *ctx;
|
||||
xcb_window_t root;
|
||||
|
||||
tag = tags_get_current(c->screen)[0];
|
||||
|
@ -897,7 +879,7 @@ mouse_client_resize_magnified(client_t *c, bool infobox)
|
|||
|
||||
/* create the infobox */
|
||||
if(infobox)
|
||||
sw = mouse_infobox_new(c->phys_screen, c->border, c->geometry, &ctx);
|
||||
sw = mouse_infobox_new(c->phys_screen, c->border, c->geometry);
|
||||
|
||||
/* for each motion event */
|
||||
while(mouse_track_mouse_drag(&mouse_x, &mouse_y))
|
||||
|
@ -927,7 +909,7 @@ mouse_client_resize_magnified(client_t *c, bool infobox)
|
|||
|
||||
/* draw the infobox */
|
||||
if(sw)
|
||||
mouse_infobox_draw(ctx, sw, c->geometry, c->border);
|
||||
mouse_infobox_draw(sw, c->geometry, c->border);
|
||||
}
|
||||
|
||||
/* ungrab pointer */
|
||||
|
@ -935,10 +917,7 @@ mouse_client_resize_magnified(client_t *c, bool infobox)
|
|||
|
||||
/* free the infobox */
|
||||
if(sw)
|
||||
{
|
||||
draw_context_delete(&ctx);
|
||||
simplewindow_delete(&sw);
|
||||
}
|
||||
}
|
||||
|
||||
/** Resize a client with the mouse.
|
||||
|
|
48
statusbar.c
48
statusbar.c
|
@ -157,7 +157,7 @@ statusbar_systray_refresh(statusbar_t *statusbar)
|
|||
for(em = globalconf.embedded; em; em = em->next)
|
||||
if(em->phys_screen == phys_screen)
|
||||
{
|
||||
if(config_win_vals[1] + config_win_vals[3] <= (uint32_t) statusbar->sw->geometry.y + statusbar->ctx->width)
|
||||
if(config_win_vals[1] + config_win_vals[3] <= (uint32_t) statusbar->sw->geometry.y + statusbar->sw->geometry.width)
|
||||
{
|
||||
xcb_map_window(globalconf.connection, em->win);
|
||||
xcb_configure_window(globalconf.connection, em->win,
|
||||
|
@ -218,7 +218,7 @@ statusbar_draw(statusbar_t *statusbar)
|
|||
|
||||
if(statusbar->position)
|
||||
{
|
||||
widget_render(statusbar->widgets, statusbar->ctx, statusbar->sw->gc,
|
||||
widget_render(statusbar->widgets, &statusbar->sw->ctx, statusbar->sw->gc,
|
||||
statusbar->sw->pixmap,
|
||||
statusbar->screen, statusbar->position,
|
||||
statusbar->sw->geometry.x, statusbar->sw->geometry.y,
|
||||
|
@ -270,7 +270,6 @@ statusbar_clean(statusbar_t *statusbar)
|
|||
statusbar_systray_kickout(statusbar->sw->phys_screen);
|
||||
|
||||
simplewindow_delete(&statusbar->sw);
|
||||
draw_context_delete(&statusbar->ctx);
|
||||
}
|
||||
|
||||
/** Update the statusbar position. It deletes every statusbar resources and
|
||||
|
@ -281,8 +280,6 @@ void
|
|||
statusbar_position_update(statusbar_t *statusbar)
|
||||
{
|
||||
area_t area, wingeometry;
|
||||
xcb_pixmap_t dw;
|
||||
xcb_screen_t *s = NULL;
|
||||
bool ignore = false;
|
||||
|
||||
if(statusbar->position == Off)
|
||||
|
@ -461,36 +458,10 @@ statusbar_position_update(statusbar_t *statusbar)
|
|||
|
||||
statusbar->sw =
|
||||
simplewindow_new(phys_screen, 0, 0,
|
||||
wingeometry.width, wingeometry.height, 0);
|
||||
wingeometry.width, wingeometry.height, 0,
|
||||
statusbar->position,
|
||||
&statusbar->colors.fg, &statusbar->colors.bg);
|
||||
|
||||
switch(statusbar->position)
|
||||
{
|
||||
case Right:
|
||||
case Left:
|
||||
statusbar->width = wingeometry.height;
|
||||
s = xutil_screen_get(globalconf.connection, phys_screen);
|
||||
/* we need a new pixmap this way [ ] to render */
|
||||
dw = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_pixmap(globalconf.connection,
|
||||
s->root_depth, dw, s->root,
|
||||
statusbar->width, statusbar->height);
|
||||
statusbar->ctx = draw_context_new(phys_screen,
|
||||
statusbar->width,
|
||||
statusbar->height,
|
||||
dw,
|
||||
&statusbar->colors.fg,
|
||||
&statusbar->colors.bg);
|
||||
break;
|
||||
default:
|
||||
statusbar->width = wingeometry.width;
|
||||
statusbar->ctx = draw_context_new(phys_screen,
|
||||
statusbar->width,
|
||||
statusbar->height,
|
||||
statusbar->sw->pixmap,
|
||||
&statusbar->colors.fg,
|
||||
&statusbar->colors.bg);
|
||||
break;
|
||||
}
|
||||
simplewindow_move(statusbar->sw, wingeometry.x, wingeometry.y);
|
||||
xcb_map_window(globalconf.connection, statusbar->sw->window);
|
||||
statusbar->need_update = true;
|
||||
|
@ -733,8 +704,8 @@ luaA_statusbar_newindex(lua_State *L)
|
|||
if((buf = luaL_checklstring(L, 3, &len)))
|
||||
if(xcolor_init_reply(xcolor_init_unchecked(&(*statusbar)->colors.fg, buf, len)))
|
||||
{
|
||||
if((*statusbar)->ctx)
|
||||
(*statusbar)->ctx->fg = (*statusbar)->colors.fg;
|
||||
if((*statusbar)->sw)
|
||||
(*statusbar)->sw->ctx.fg = (*statusbar)->colors.fg;
|
||||
(*statusbar)->need_update = true;
|
||||
}
|
||||
break;
|
||||
|
@ -742,9 +713,8 @@ luaA_statusbar_newindex(lua_State *L)
|
|||
if((buf = luaL_checklstring(L, 3, &len)))
|
||||
if(xcolor_init_reply(xcolor_init_unchecked(&(*statusbar)->colors.bg, buf, len)))
|
||||
{
|
||||
if((*statusbar)->ctx)
|
||||
(*statusbar)->ctx->bg = (*statusbar)->colors.bg;
|
||||
|
||||
if((*statusbar)->sw)
|
||||
(*statusbar)->sw->ctx.bg = (*statusbar)->colors.bg;
|
||||
(*statusbar)->need_update = true;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -234,8 +234,6 @@ struct statusbar_t
|
|||
int screen;
|
||||
/** Widget list */
|
||||
widget_node_t *widgets;
|
||||
/** Draw context */
|
||||
draw_context_t *ctx;
|
||||
/** Need update */
|
||||
bool need_update;
|
||||
/** Default colors */
|
||||
|
|
82
swindow.c
82
swindow.c
|
@ -19,10 +19,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "structs.h"
|
||||
#include "swindow.h"
|
||||
#include "draw.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
extern awesome_t globalconf;
|
||||
|
@ -34,13 +37,18 @@ extern awesome_t globalconf;
|
|||
* \param w Width.
|
||||
* \param h Height.
|
||||
* \param border_width Window border width.
|
||||
* \param position The rendering position.
|
||||
* \param bg Default foreground color.
|
||||
* \param bg Default background color.
|
||||
* \return A pointer to a newly allocated simple window, which must be deleted
|
||||
* with simplewindow_delete().
|
||||
*/
|
||||
simple_window_t *
|
||||
simplewindow_new(int phys_screen, int x, int y,
|
||||
unsigned int w, unsigned int h,
|
||||
unsigned int border_width)
|
||||
unsigned int border_width,
|
||||
position_t position,
|
||||
const xcolor_t *fg, const xcolor_t *bg)
|
||||
{
|
||||
simple_window_t *sw;
|
||||
xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
|
||||
|
@ -73,14 +81,31 @@ simplewindow_new(int phys_screen, int x, int y,
|
|||
sw->pixmap = xcb_generate_id(globalconf.connection);
|
||||
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
|
||||
* bal
|
||||
* gg
|
||||
* window */
|
||||
switch(position)
|
||||
{
|
||||
xcb_pixmap_t pixmap;
|
||||
case Left:
|
||||
case Right:
|
||||
/* we need a new pixmap this way [ ] to render */
|
||||
pixmap = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_pixmap(globalconf.connection,
|
||||
s->root_depth,
|
||||
pixmap, s->root, h, w);
|
||||
draw_context_init(&sw->ctx, phys_screen,
|
||||
h, w, pixmap, fg, bg);
|
||||
break;
|
||||
default:
|
||||
draw_context_init(&sw->ctx, phys_screen,
|
||||
w, h, sw->pixmap, fg, bg);
|
||||
break;
|
||||
}
|
||||
|
||||
/* The default GC is just a newly created associated to the root window */
|
||||
sw->gc = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_gc(globalconf.connection, sw->gc, s->root, gc_mask, gc_values);
|
||||
|
||||
sw->border_width = border_width;
|
||||
sw->position = position;
|
||||
|
||||
return sw;
|
||||
}
|
||||
|
@ -96,6 +121,7 @@ simplewindow_delete(simple_window_t **sw)
|
|||
xcb_destroy_window(globalconf.connection, (*sw)->window);
|
||||
xcb_free_pixmap(globalconf.connection, (*sw)->pixmap);
|
||||
xcb_free_gc(globalconf.connection, (*sw)->gc);
|
||||
draw_context_wipe(&(*sw)->ctx);
|
||||
p_delete(sw);
|
||||
}
|
||||
}
|
||||
|
@ -117,6 +143,36 @@ simplewindow_move(simple_window_t *sw, int x, int y)
|
|||
move_win_vals);
|
||||
}
|
||||
|
||||
static void
|
||||
simplewindow_draw_context_update(simple_window_t *sw, xcb_screen_t *s)
|
||||
{
|
||||
xcolor_t fg = sw->ctx.fg, bg = sw->ctx.bg;
|
||||
|
||||
draw_context_wipe(&sw->ctx);
|
||||
|
||||
/* update draw context */
|
||||
switch(sw->position)
|
||||
{
|
||||
case Left:
|
||||
case Right:
|
||||
/* we need a new pixmap this way [ ] to render */
|
||||
sw->ctx.pixmap = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_pixmap(globalconf.connection,
|
||||
s->root_depth,
|
||||
sw->ctx.pixmap, s->root,
|
||||
sw->geometry.height, sw->geometry.width);
|
||||
draw_context_init(&sw->ctx, sw->phys_screen,
|
||||
sw->geometry.height, sw->geometry.width,
|
||||
sw->ctx.pixmap, &fg, &bg);
|
||||
break;
|
||||
default:
|
||||
draw_context_init(&sw->ctx, sw->phys_screen,
|
||||
sw->geometry.width, sw->geometry.height,
|
||||
sw->pixmap, &fg, &bg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Resize a simple window.
|
||||
* \param sw The simple_window_t to resize.
|
||||
* \param w New width.
|
||||
|
@ -125,21 +181,20 @@ simplewindow_move(simple_window_t *sw, int x, int y)
|
|||
void
|
||||
simplewindow_resize(simple_window_t *sw, int w, int h)
|
||||
{
|
||||
xcb_screen_t *s = xutil_screen_get(globalconf.connection, sw->phys_screen);
|
||||
uint32_t resize_win_vals[2];
|
||||
xcb_pixmap_t d;
|
||||
|
||||
if(w > 0 && h > 0 && (sw->geometry.width != w || sw->geometry.height != h))
|
||||
{
|
||||
xcb_screen_t *s = xutil_screen_get(globalconf.connection, sw->phys_screen);
|
||||
uint32_t resize_win_vals[2];
|
||||
|
||||
sw->geometry.width = resize_win_vals[0] = w;
|
||||
sw->geometry.height = resize_win_vals[1] = h;
|
||||
d = sw->pixmap;
|
||||
xcb_free_pixmap(globalconf.connection, sw->pixmap);
|
||||
sw->pixmap = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_pixmap(globalconf.connection, s->root_depth, sw->pixmap, s->root, w, h);
|
||||
xcb_configure_window(globalconf.connection, sw->window,
|
||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||
resize_win_vals);
|
||||
xcb_free_pixmap(globalconf.connection, d);
|
||||
simplewindow_draw_context_update(sw, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +209,6 @@ void
|
|||
simplewindow_moveresize(simple_window_t *sw, int x, int y, int w, int h)
|
||||
{
|
||||
uint32_t moveresize_win_vals[4], mask_vals = 0;
|
||||
xcb_pixmap_t d;
|
||||
xcb_screen_t *s = xutil_screen_get(globalconf.connection, sw->phys_screen);
|
||||
|
||||
if(sw->geometry.x != x || sw->geometry.y != y)
|
||||
|
@ -177,10 +231,10 @@ simplewindow_moveresize(simple_window_t *sw, int x, int y, int w, int h)
|
|||
sw->geometry.height = moveresize_win_vals[1] = h;
|
||||
}
|
||||
mask_vals |= XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
|
||||
d = sw->pixmap;
|
||||
xcb_free_pixmap(globalconf.connection, sw->pixmap);
|
||||
sw->pixmap = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_pixmap(globalconf.connection, s->root_depth, sw->pixmap, s->root, w, h);
|
||||
xcb_free_pixmap(globalconf.connection, d);
|
||||
simplewindow_draw_context_update(sw, s);
|
||||
}
|
||||
|
||||
xcb_configure_window(globalconf.connection, sw->window, mask_vals, moveresize_win_vals);
|
||||
|
|
14
swindow.h
14
swindow.h
|
@ -19,14 +19,17 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef AWESOME_COMMON_SWINDOW_H
|
||||
#define AWESOME_COMMON_SWINDOW_H
|
||||
#ifndef AWESOME_SWINDOW_H
|
||||
#define AWESOME_SWINDOW_H
|
||||
|
||||
#include "draw.h"
|
||||
#include "common/util.h"
|
||||
|
||||
/** A simple window. */
|
||||
typedef struct simple_window_t
|
||||
{
|
||||
/** Orientation */
|
||||
|
||||
/** The physical screen number the window is on. */
|
||||
int phys_screen;
|
||||
/** The window object. */
|
||||
|
@ -39,9 +42,14 @@ typedef struct simple_window_t
|
|||
area_t geometry;
|
||||
/** The window border width */
|
||||
int border_width;
|
||||
/** Draw context */
|
||||
draw_context_t ctx;
|
||||
/** Position */
|
||||
position_t position;
|
||||
} simple_window_t;
|
||||
|
||||
simple_window_t * simplewindow_new(int, int, int, unsigned int, unsigned int, unsigned int);
|
||||
simple_window_t * simplewindow_new(int, int, int, unsigned int, unsigned int, unsigned int,
|
||||
position_t, const xcolor_t *, const xcolor_t *);
|
||||
void simplewindow_delete(simple_window_t **);
|
||||
|
||||
void simplewindow_move(simple_window_t *, int, int);
|
||||
|
|
79
titlebar.c
79
titlebar.c
|
@ -21,8 +21,6 @@
|
|||
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "titlebar.h"
|
||||
#include "client.h"
|
||||
#include "widget.h"
|
||||
|
@ -71,73 +69,17 @@ client_getbytitlebarwin(xcb_window_t win)
|
|||
void
|
||||
titlebar_draw(client_t *c)
|
||||
{
|
||||
xcb_drawable_t dw = 0;
|
||||
draw_context_t *ctx;
|
||||
xcb_screen_t *s;
|
||||
|
||||
if(!c || !c->titlebar || !c->titlebar->sw || !c->titlebar->position)
|
||||
return;
|
||||
|
||||
s = xutil_screen_get(globalconf.connection,
|
||||
c->titlebar->sw->phys_screen);
|
||||
|
||||
switch(c->titlebar->position)
|
||||
{
|
||||
case Off:
|
||||
return;
|
||||
case Right:
|
||||
case Left:
|
||||
dw = xcb_generate_id(globalconf.connection);
|
||||
xcb_create_pixmap(globalconf.connection, s->root_depth,
|
||||
dw,
|
||||
s->root,
|
||||
c->titlebar->sw->geometry.height,
|
||||
c->titlebar->sw->geometry.width);
|
||||
ctx = draw_context_new(c->titlebar->sw->phys_screen,
|
||||
c->titlebar->sw->geometry.height,
|
||||
c->titlebar->sw->geometry.width,
|
||||
dw,
|
||||
&c->titlebar->colors.fg,
|
||||
&c->titlebar->colors.bg);
|
||||
break;
|
||||
default:
|
||||
ctx = draw_context_new(c->titlebar->sw->phys_screen,
|
||||
c->titlebar->sw->geometry.width,
|
||||
c->titlebar->sw->geometry.height,
|
||||
c->titlebar->sw->pixmap,
|
||||
&c->titlebar->colors.fg,
|
||||
&c->titlebar->colors.bg);
|
||||
break;
|
||||
}
|
||||
|
||||
widget_render(c->titlebar->widgets, ctx, c->titlebar->sw->gc, c->titlebar->sw->pixmap,
|
||||
widget_render(c->titlebar->widgets, &c->titlebar->sw->ctx,
|
||||
c->titlebar->sw->gc, c->titlebar->sw->pixmap,
|
||||
c->screen, c->titlebar->position,
|
||||
c->titlebar->sw->geometry.x, c->titlebar->sw->geometry.y,
|
||||
c->titlebar, AWESOME_TYPE_TITLEBAR);
|
||||
|
||||
switch(c->titlebar->position)
|
||||
{
|
||||
case Left:
|
||||
draw_rotate(ctx, ctx->pixmap, c->titlebar->sw->pixmap,
|
||||
ctx->width, ctx->height,
|
||||
ctx->height, ctx->width,
|
||||
- M_PI_2, 0, c->titlebar->sw->geometry.height);
|
||||
xcb_free_pixmap(globalconf.connection, dw);
|
||||
break;
|
||||
case Right:
|
||||
draw_rotate(ctx, ctx->pixmap, c->titlebar->sw->pixmap,
|
||||
ctx->width, ctx->height,
|
||||
ctx->height, ctx->width,
|
||||
M_PI_2, c->titlebar->sw->geometry.width, 0);
|
||||
xcb_free_pixmap(globalconf.connection, dw);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
simplewindow_refresh_pixmap(c->titlebar->sw);
|
||||
|
||||
draw_context_delete(&ctx);
|
||||
|
||||
c->titlebar->need_update = false;
|
||||
}
|
||||
|
||||
|
@ -284,11 +226,12 @@ titlebar_init(client_t *c)
|
|||
titlebar_geometry_compute(c, c->geometry, &geom);
|
||||
|
||||
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,
|
||||
c->titlebar->position,
|
||||
&c->titlebar->colors.fg, &c->titlebar->colors.bg);
|
||||
|
||||
if(c->titlebar->border.width)
|
||||
xcb_change_window_attributes(globalconf.connection, c->titlebar->sw->window,
|
||||
XCB_CW_BORDER_PIXEL, &c->titlebar->border.color.pixel);
|
||||
simplewindow_border_color_set(c->titlebar->sw, &c->titlebar->border.color);
|
||||
|
||||
client_need_arrange(c);
|
||||
|
||||
|
@ -421,12 +364,20 @@ luaA_titlebar_newindex(lua_State *L)
|
|||
case A_TK_FG:
|
||||
if((buf = luaL_checklstring(L, 3, &len)))
|
||||
if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->colors.fg, buf, len)))
|
||||
{
|
||||
if((*titlebar)->sw)
|
||||
(*titlebar)->sw->ctx.fg = (*titlebar)->colors.fg;
|
||||
(*titlebar)->need_update = true;
|
||||
}
|
||||
return 0;
|
||||
case A_TK_BG:
|
||||
if((buf = luaL_checklstring(L, 3, &len)))
|
||||
if(xcolor_init_reply(xcolor_init_unchecked(&(*titlebar)->colors.bg, buf, len)))
|
||||
{
|
||||
if((*titlebar)->sw)
|
||||
(*titlebar)->sw->ctx.bg = (*titlebar)->colors.bg;
|
||||
(*titlebar)->need_update = true;
|
||||
}
|
||||
break;
|
||||
case A_TK_POSITION:
|
||||
buf = luaL_checklstring(L, 3, &len);
|
||||
|
|
Loading…
Reference in New Issue