move NetWMIcon get to ewmh.c

This commit is contained in:
Julien Danjou 2008-01-03 19:02:23 +01:00
parent 675b6e6255
commit 62d5711a7e
3 changed files with 70 additions and 45 deletions

51
ewmh.c
View File

@ -325,4 +325,55 @@ ewmh_check_client_hints(Client *c)
} }
} }
NetWMIcon *
ewmh_get_window_icon(Window w)
{
NetWMIcon *icon;
Atom type;
int format, size, i;
unsigned long items, rest, *data, pixel;
unsigned char *imgdata, *wdata;
if(XGetWindowProperty(globalconf.display, w,
net_wm_icon, 0L, LONG_MAX, False, XA_CARDINAL, &type, &format,
&items, &rest, &wdata) != Success
|| !wdata)
return NULL;
if(type != XA_CARDINAL || format != 32 || items < 2)
{
XFree(wdata);
return NULL;
}
icon = p_new(NetWMIcon, 1);
data = (unsigned long *) wdata;
icon->width = data[0];
icon->height = data[1];
size = icon->width * icon->height;
if(!size)
{
p_delete(&icon);
XFree(wdata);
return NULL;
}
icon->image = p_new(unsigned char, size * 4);
for(imgdata = icon->image, i = 2; i < size + 2; i++, imgdata += 4)
{
pixel = data[i];
imgdata[3] = (pixel >> 24) & 0xff; /* A */
imgdata[0] = (pixel >> 16) & 0xff; /* R */
imgdata[1] = (pixel >> 8) & 0xff; /* G */
imgdata[2] = pixel & 0xff; /* B */
}
XFree(wdata);
return icon;
}
// 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

8
ewmh.h
View File

@ -24,6 +24,13 @@
#include "config.h" #include "config.h"
typedef struct
{
int height;
int width;
unsigned char *image;
} NetWMIcon;
void ewmh_init_atoms(void); void ewmh_init_atoms(void);
void ewmh_set_supported_hints(int); void ewmh_set_supported_hints(int);
void ewmh_update_net_client_list(int); void ewmh_update_net_client_list(int);
@ -33,6 +40,7 @@ void ewmh_update_net_desktop_names(int);
void ewmh_update_net_active_window(int); void ewmh_update_net_active_window(int);
void ewmh_process_client_message(XClientMessageEvent *); void ewmh_process_client_message(XClientMessageEvent *);
void ewmh_check_client_hints(Client *); void ewmh_check_client_hints(Client *);
NetWMIcon * ewmh_get_window_icon(Window);
#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

View File

@ -26,6 +26,7 @@
#include "tag.h" #include "tag.h"
#include "widget.h" #include "widget.h"
#include "rules.h" #include "rules.h"
#include "ewmh.h"
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
@ -33,15 +34,10 @@ static int
netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
unsigned long *data, pixel;
unsigned char *wdata;
Atom type;
int format, width, height, size, i;
Area area; Area area;
unsigned long items, rest;
unsigned char *image, *imgdata;
Rule* r; Rule* r;
Client *sel = focus_get_current_client(widget->statusbar->screen); Client *sel = focus_get_current_client(widget->statusbar->screen);
NetWMIcon *icon;
if(!sel) if(!sel)
return 0; return 0;
@ -60,53 +56,23 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
return widget->width; return widget->width;
} }
if(XGetWindowProperty(globalconf.display, sel->win,
XInternAtom(globalconf.display, "_NET_WM_ICON", False), if(!(icon = ewmh_get_window_icon(sel->win)))
0L, LONG_MAX, False, XA_CARDINAL, &type, &format,
&items, &rest, &wdata) != Success
|| !wdata)
return 0; return 0;
if(type != XA_CARDINAL || format != 32 || items < 2) widget->width = ((double) widget->statusbar->height / (double) icon->height) * icon->width;
{
XFree(wdata);
return 0;
}
data = (unsigned long *) wdata;
width = data[0];
height = data[1];
size = width * height;
if(!size)
{
XFree(wdata);
return 0;
}
image = p_new(unsigned char, size * 4);
for(imgdata = image, i = 2; i < size + 2; i++, imgdata += 4)
{
pixel = data[i];
imgdata[3] = (pixel >> 24) & 0xff; /* A */
imgdata[0] = (pixel >> 16) & 0xff; /* R */
imgdata[1] = (pixel >> 8) & 0xff; /* G */
imgdata[2] = pixel & 0xff; /* B */
}
widget->location = widget_calculate_offset(widget->statusbar->width, widget->location = widget_calculate_offset(widget->statusbar->width,
width, widget->width,
offset, offset,
widget->alignment); widget->alignment);
draw_image_from_argb_data(ctx, widget->location, 0, width, height, widget->statusbar->height, image); draw_image_from_argb_data(ctx,
widget->location, 0,
icon->width, icon->height,
widget->statusbar->height, icon->image);
p_delete(&icon);
p_delete(&image);
XFree(wdata);
widget->width = widget->statusbar->height;
return widget->width; return widget->width;
} }