Let panel taskbar tries to fetch icons of desired size, if possible. Also squashed a small memory leak in keyboard applet.

This commit is contained in:
Sanel Zukan 2012-08-24 14:15:04 +00:00
parent b4ad2fb11b
commit 2d028fe4a6
2 changed files with 34 additions and 61 deletions

View File

@ -1,3 +1,23 @@
/*
* $Id$
*
* Copyright (C) 2011-2012 Sanel Zukan
*
* 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.
*/
#include "Applet.h"
#ifdef HAVE_CONFIG_H
@ -61,11 +81,12 @@ static KeyLayoutList keylayout_objects;
#ifdef HAVE_XKBRULES
/* Xkb does not provide this */
static void xkbrf_names_prop_free(XkbRF_VarDefsRec &vd, char *tmp) {
XFree(tmp);
XFree(vd.model);
XFree(vd.layout);
XFree(vd.options);
XFree(vd.variant);
if(tmp) free(tmp);
if(vd.model) XFree(vd.model);
if(vd.layout) XFree(vd.layout);
if(vd.options) XFree(vd.options);
if(vd.variant) XFree(vd.variant);
if(vd.extra_names) XFree(vd.extra_names);
}
#endif
@ -172,8 +193,10 @@ void KeyLayout::do_key_layout(void) {
if(XkbRF_GetNamesProp(fl_display, &tmp, &vd)) {
/* do nothing if layout do not exists or the same was catched */
if(!vd.layout || (curr_layout == vd.layout))
if(!vd.layout || (curr_layout == vd.layout)) {
xkbrf_names_prop_free(vd, tmp);
return;
}
/* just store it, so update_flag() can do the rest */
curr_layout = vd.layout;

View File

@ -45,6 +45,7 @@ EDELIB_NS_USING(ICON_SIZE_TINY)
EDELIB_NS_USING(netwm_window_close)
EDELIB_NS_USING(netwm_window_set_active)
EDELIB_NS_USING(netwm_window_get_title)
EDELIB_NS_USING(netwm_window_get_icon)
EDELIB_NS_USING(netwm_window_set_state)
EDELIB_NS_USING(wm_window_ede_restore)
EDELIB_NS_USING(wm_window_get_state)
@ -203,64 +204,13 @@ void TaskButton::update_title_from_xid(void) {
}
}
/* stolen from pekwm */
void TaskButton::update_image_from_xid(void) {
E_RETURN_IF_FAIL(xid >= 0);
Atom real;
int format;
unsigned long n, extra;
unsigned char *prop = 0;
long len = 2;
int status = XGetWindowProperty(fl_display, xid,
net_wm_icon , 0L, len, False, XA_CARDINAL, &real, &format, &n, &extra, (unsigned char**)&prop);
if((status != Success) || (real != XA_CARDINAL)) {
if(prop) XFree(prop);
return;
}
long *data = (long*)prop;
unsigned int width, height;
width = data[0];
height = data[1];
XFree(prop);
len += width * height;
format = 0;
prop = 0;
real = 0;
status = XGetWindowProperty(fl_display, xid,
net_wm_icon , 0L, len, False, XA_CARDINAL, &real, &format, &n, &extra, (unsigned char**)&prop);
if((status != Success) || (real != XA_CARDINAL)) {
if(prop) XFree(prop);
return;
}
data = (long*)prop;
unsigned char *img_data = new unsigned char[width * height * 4];
unsigned char *ptr = img_data;
int pixel;
for(int i = 2; i < len; i++) {
pixel = data[i];
*ptr++ = pixel >> 16 & 0xff;
*ptr++ = pixel >> 8 & 0xff;
*ptr++ = pixel & 0xff;
*ptr++ = pixel >> 24 & 0xff;
}
XFree(prop);
Fl_RGB_Image *img = new Fl_RGB_Image(img_data, width, height, 4);
img->alloc_array = 1;
Fl_RGB_Image *img = netwm_window_get_icon(xid, TASKBUTTON_ICON_W);
if(!img) return;
int width = img->w(), height = img->h();
/* some safety, scale it if needed */
if((width > TASKBUTTON_ICON_W) || (height > TASKBUTTON_ICON_H)) {