Custom netwm icons, scaling icons!
I hacked together support for custom netwm icons set in the rules section of .awesomerc, and for iconboxes and netwm icons to be scaled to fit into the statusbar. It could probably be done a bit more cleanly than I've done it, though :) Rob
This commit is contained in:
parent
bf5d5fa17e
commit
eb65306127
4
config.c
4
config.c
|
@ -588,6 +588,7 @@ config_parse(const char *confpatharg)
|
||||||
{
|
{
|
||||||
CFG_STR((char *) "name", (char *) "", CFGF_NONE),
|
CFG_STR((char *) "name", (char *) "", CFGF_NONE),
|
||||||
CFG_STR((char *) "tags", (char *) "", CFGF_NONE),
|
CFG_STR((char *) "tags", (char *) "", CFGF_NONE),
|
||||||
|
CFG_STR((char *) "icon", (char *) "", CFGF_NONE),
|
||||||
CFG_BOOL((char *) "float", cfg_false, CFGF_NONE),
|
CFG_BOOL((char *) "float", cfg_false, CFGF_NONE),
|
||||||
CFG_INT((char *) "screen", RULE_NOSCREEN, CFGF_NONE),
|
CFG_INT((char *) "screen", RULE_NOSCREEN, CFGF_NONE),
|
||||||
CFG_END()
|
CFG_END()
|
||||||
|
@ -689,6 +690,9 @@ config_parse(const char *confpatharg)
|
||||||
rule->tags = a_strdup(cfg_getstr(cfgsectmp, "tags"));
|
rule->tags = a_strdup(cfg_getstr(cfgsectmp, "tags"));
|
||||||
if(!a_strlen(rule->tags))
|
if(!a_strlen(rule->tags))
|
||||||
rule->tags = NULL;
|
rule->tags = NULL;
|
||||||
|
rule->icon = a_strdup(cfg_getstr(cfgsectmp, "icon"));
|
||||||
|
if (!a_strlen(rule->icon))
|
||||||
|
rule->icon = NULL;
|
||||||
rule->isfloating = cfg_getbool(cfgsectmp, "float");
|
rule->isfloating = cfg_getbool(cfgsectmp, "float");
|
||||||
rule->screen = cfg_getint(cfgsectmp, "screen");
|
rule->screen = cfg_getint(cfgsectmp, "screen");
|
||||||
if(rule->screen >= get_screen_count())
|
if(rule->screen >= get_screen_count())
|
||||||
|
|
1
config.h
1
config.h
|
@ -43,6 +43,7 @@ struct Rule
|
||||||
{
|
{
|
||||||
char *prop;
|
char *prop;
|
||||||
char *tags;
|
char *tags;
|
||||||
|
char *icon;
|
||||||
int screen;
|
int screen;
|
||||||
Bool isfloating;
|
Bool isfloating;
|
||||||
regex_t *propregex;
|
regex_t *propregex;
|
||||||
|
|
14
draw.c
14
draw.c
|
@ -218,6 +218,20 @@ draw_get_image_width(const char *filename)
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
draw_get_image_height(const char* filename)
|
||||||
|
{
|
||||||
|
int height;
|
||||||
|
cairo_surface_t *surface;
|
||||||
|
|
||||||
|
surface = cairo_image_surface_create_from_png(filename);
|
||||||
|
cairo_image_surface_get_height(surface);
|
||||||
|
height = cairo_image_surface_get_height(surface);
|
||||||
|
cairo_surface_destroy(surface);
|
||||||
|
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
Drawable
|
Drawable
|
||||||
draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty)
|
draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty)
|
||||||
{
|
{
|
||||||
|
|
1
draw.h
1
draw.h
|
@ -41,6 +41,7 @@ void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
|
||||||
void draw_image(DrawCtx *, int, int, int, const char *);
|
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 *);
|
||||||
int draw_get_image_width(const char *filename);
|
int draw_get_image_width(const char *filename);
|
||||||
|
int draw_get_image_height(const char *filename);
|
||||||
Drawable draw_rotate(DrawCtx *, int, double, int, int);
|
Drawable draw_rotate(DrawCtx *, int, double, int, int);
|
||||||
unsigned short textwidth(XftFont *, char *);
|
unsigned short textwidth(XftFont *, char *);
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,16 @@ static int
|
||||||
iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
|
iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
int used __attribute__ ((unused)))
|
int used __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
|
int height;
|
||||||
widget->width = draw_get_image_width(widget->data);
|
widget->width = draw_get_image_width(widget->data);
|
||||||
|
height = draw_get_image_height(widget->data);
|
||||||
|
widget->width = ((double) widget->statusbar->height / height) * widget->width;
|
||||||
widget->location = widget_calculate_offset(widget->statusbar->width,
|
widget->location = widget_calculate_offset(widget->statusbar->width,
|
||||||
widget->width,
|
widget->width,
|
||||||
offset,
|
offset,
|
||||||
widget->alignment);
|
widget->alignment);
|
||||||
|
|
||||||
draw_image(ctx, widget->location, 0, 0, widget->data);
|
draw_image(ctx, widget->location, 0, widget->statusbar->height, widget->data);
|
||||||
|
|
||||||
return widget->width;
|
return widget->width;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "focus.h"
|
#include "focus.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "widget.h"
|
#include "widget.h"
|
||||||
|
#include "rules.h"
|
||||||
|
|
||||||
extern AwesomeConf globalconf;
|
extern AwesomeConf globalconf;
|
||||||
|
|
||||||
|
@ -39,11 +40,31 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
int format, width, height, size, i;
|
int format, width, height, size, i;
|
||||||
unsigned long items, rest;
|
unsigned long items, rest;
|
||||||
unsigned char *image, *imgdata;
|
unsigned char *image, *imgdata;
|
||||||
|
char* icon;
|
||||||
|
Rule* r;
|
||||||
Client *sel = focus_get_current_client(widget->statusbar->screen);
|
Client *sel = focus_get_current_client(widget->statusbar->screen);
|
||||||
|
|
||||||
if(!sel)
|
if(!sel)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
for(r = globalconf.rules; r; r = r->next)
|
||||||
|
if(client_match_rule(sel, r))
|
||||||
|
{
|
||||||
|
if(!r->icon)
|
||||||
|
continue;
|
||||||
|
icon = r->icon;
|
||||||
|
width = draw_get_image_width(icon);
|
||||||
|
height = draw_get_image_height(icon);
|
||||||
|
width = ((double) widget->statusbar->height / (double) height) * width;
|
||||||
|
widget->location = widget_calculate_offset(widget->statusbar->width,
|
||||||
|
width,
|
||||||
|
offset,
|
||||||
|
widget->alignment);
|
||||||
|
draw_image(ctx, widget->location, 0, widget->statusbar->height, icon);
|
||||||
|
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
if(XGetWindowProperty(ctx->display, sel->win,
|
if(XGetWindowProperty(ctx->display, sel->win,
|
||||||
XInternAtom(ctx->display, "_NET_WM_ICON", False),
|
XInternAtom(ctx->display, "_NET_WM_ICON", False),
|
||||||
0L, LONG_MAX, False, XA_CARDINAL, &type, &format,
|
0L, LONG_MAX, False, XA_CARDINAL, &type, &format,
|
||||||
|
|
Loading…
Reference in New Issue