mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Some refactoring so icon properties does not get's copied
Added some hack to make valgrind silent in wallpaper code
This commit is contained in:
parent
12acd9ea6c
commit
ffee0edd57
@ -46,7 +46,6 @@
|
|||||||
// label offset from icon y()+h(), so selection box can be drawn nicely
|
// label offset from icon y()+h(), so selection box can be drawn nicely
|
||||||
#define LABEL_OFFSET 2
|
#define LABEL_OFFSET 2
|
||||||
|
|
||||||
|
|
||||||
static void rename_cb(Fl_Widget*, void* d);
|
static void rename_cb(Fl_Widget*, void* d);
|
||||||
static void props_cb(Fl_Widget*, void* d);
|
static void props_cb(Fl_Widget*, void* d);
|
||||||
|
|
||||||
@ -93,25 +92,10 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) :
|
|||||||
micon = NULL;
|
micon = NULL;
|
||||||
darker_img = NULL;
|
darker_img = NULL;
|
||||||
|
|
||||||
/*
|
gsettings = gs;
|
||||||
* GlobalIconSettings is shared from desktop so we only
|
settings = is;
|
||||||
* reference it. On other hand IconSettings is not shared
|
|
||||||
* and we must construct a copy from given parameter
|
|
||||||
*/
|
|
||||||
globals = gs;
|
|
||||||
|
|
||||||
settings = new IconSettings;
|
/* setting fonts is TODO :P */
|
||||||
settings->name = is->name;
|
|
||||||
settings->cmd = is->cmd;
|
|
||||||
settings->icon = is->icon;
|
|
||||||
settings->icon2 = is->icon2;
|
|
||||||
settings->type = is->type;
|
|
||||||
settings->key_name= is->key_name;
|
|
||||||
settings->full_path = is->full_path;
|
|
||||||
|
|
||||||
// x,y are not needed since x(), y() are filled with it
|
|
||||||
|
|
||||||
// setting fonts is TODO :P
|
|
||||||
#if 0
|
#if 0
|
||||||
Fl::set_font((Fl_Font)20, "-windows-*-medium-r-*-*-14-*-*-*-*-*-*-*");
|
Fl::set_font((Fl_Font)20, "-windows-*-medium-r-*-*-14-*-*-*-*-*-*-*");
|
||||||
labelfont((Fl_Font)20);
|
labelfont((Fl_Font)20);
|
||||||
@ -128,7 +112,7 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) :
|
|||||||
load_icon(ICON_FACE_ONE);
|
load_icon(ICON_FACE_ONE);
|
||||||
fix_position(x(), y());
|
fix_position(x(), y());
|
||||||
|
|
||||||
//Use desktop color as color for icon background
|
/* use desktop color as color for icon background */
|
||||||
color(bg);
|
color(bg);
|
||||||
|
|
||||||
align(FL_ALIGN_WRAP);
|
align(FL_ALIGN_WRAP);
|
||||||
@ -138,11 +122,8 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) :
|
|||||||
DesktopIcon::~DesktopIcon() {
|
DesktopIcon::~DesktopIcon() {
|
||||||
E_DEBUG("DesktopIcon::~DesktopIcon()\n");
|
E_DEBUG("DesktopIcon::~DesktopIcon()\n");
|
||||||
|
|
||||||
if(settings)
|
delete settings;
|
||||||
delete settings;
|
delete micon;
|
||||||
if(micon)
|
|
||||||
delete micon;
|
|
||||||
|
|
||||||
delete darker_img;
|
delete darker_img;
|
||||||
delete imenu;
|
delete imenu;
|
||||||
}
|
}
|
||||||
@ -184,8 +165,8 @@ void DesktopIcon::load_icon(int face) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DesktopIcon::update_label_size(void) {
|
void DesktopIcon::update_label_size(void) {
|
||||||
labelsize(globals->label_fontsize);
|
labelsize(gsettings->label_fontsize);
|
||||||
lwidth = globals->label_maxwidth;
|
lwidth = gsettings->label_maxwidth;
|
||||||
lheight= 0;
|
lheight= 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -344,14 +325,14 @@ void DesktopIcon::draw(void) {
|
|||||||
E_DEBUG(E_STRLOC ": DesktopIcon icon redraw\n");
|
E_DEBUG(E_STRLOC ": DesktopIcon icon redraw\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(globals->label_draw && (damage() & (FL_DAMAGE_ALL | EDAMAGE_CHILD_LABEL))) {
|
if(gsettings->label_draw && (damage() & (FL_DAMAGE_ALL | EDAMAGE_CHILD_LABEL))) {
|
||||||
int X = x() + w()-(w()/2)-(lwidth/2);
|
int X = x() + w()-(w()/2)-(lwidth/2);
|
||||||
int Y = y() + h() + LABEL_OFFSET;
|
int Y = y() + h() + LABEL_OFFSET;
|
||||||
|
|
||||||
Fl_Color old = fl_color();
|
Fl_Color old = fl_color();
|
||||||
|
|
||||||
if(!globals->label_transparent) {
|
if(!gsettings->label_transparent) {
|
||||||
fl_color(globals->label_background);
|
fl_color(gsettings->label_background);
|
||||||
fl_rectf(X, Y, lwidth, lheight);
|
fl_rectf(X, Y, lwidth, lheight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,7 +346,7 @@ void DesktopIcon::draw(void) {
|
|||||||
fl_color(FL_BLACK);
|
fl_color(FL_BLACK);
|
||||||
fl_draw(label(), X+1, Y+1, lwidth, lheight, align(), 0, 0);
|
fl_draw(label(), X+1, Y+1, lwidth, lheight, align(), 0, 0);
|
||||||
|
|
||||||
fl_color(globals->label_foreground);
|
fl_color(gsettings->label_foreground);
|
||||||
fl_draw(label(), X, Y, lwidth, lheight, align(), 0, 0);
|
fl_draw(label(), X, Y, lwidth, lheight, align(), 0, 0);
|
||||||
|
|
||||||
/* restore old font */
|
/* restore old font */
|
||||||
@ -373,7 +354,7 @@ void DesktopIcon::draw(void) {
|
|||||||
|
|
||||||
if(is_focused()) {
|
if(is_focused()) {
|
||||||
/* draw focused box on our way so later this can be used to draw customised boxes */
|
/* draw focused box on our way so later this can be used to draw customised boxes */
|
||||||
fl_color(globals->label_foreground);
|
fl_color(gsettings->label_foreground);
|
||||||
fl_line_style(FL_DOT);
|
fl_line_style(FL_DOT);
|
||||||
|
|
||||||
fl_push_matrix();
|
fl_push_matrix();
|
||||||
|
@ -31,8 +31,8 @@ class Fl_Menu_Button;
|
|||||||
|
|
||||||
class DesktopIcon : public Fl_Widget {
|
class DesktopIcon : public Fl_Widget {
|
||||||
private:
|
private:
|
||||||
IconSettings* settings;
|
IconSettings* settings;
|
||||||
const GlobalIconSettings* globals;
|
const GlobalIconSettings* gsettings;
|
||||||
|
|
||||||
int lwidth;
|
int lwidth;
|
||||||
int lheight;
|
int lheight;
|
||||||
|
@ -363,6 +363,8 @@ static void create_tile(Fl_Image* orig, Fl_RGB_Image** copied, int X, int Y, int
|
|||||||
Wallpaper::~Wallpaper() {
|
Wallpaper::~Wallpaper() {
|
||||||
if(rootpmap_pixmap)
|
if(rootpmap_pixmap)
|
||||||
XFreePixmap(fl_display, rootpmap_pixmap);
|
XFreePixmap(fl_display, rootpmap_pixmap);
|
||||||
|
|
||||||
|
delete stretched_alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wallpaper::set_rootpmap(void) {
|
void Wallpaper::set_rootpmap(void) {
|
||||||
@ -396,13 +398,18 @@ bool Wallpaper::load(const char* path, WallpaperState s) {
|
|||||||
create_tile((Fl_Image*)i, &tiled, x(), y(), w(), h());
|
create_tile((Fl_Image*)i, &tiled, x(), y(), w(), h());
|
||||||
image(tiled);
|
image(tiled);
|
||||||
} else if(s == WALLPAPER_STRETCH) {
|
} else if(s == WALLPAPER_STRETCH) {
|
||||||
Fl_Image* stretched;
|
Fl_Image* stretched = NULL;
|
||||||
|
|
||||||
if(i->w() == w() && i->h() == h())
|
if(i->w() == w() && i->h() == h())
|
||||||
stretched = i;
|
stretched = i;
|
||||||
else {
|
else {
|
||||||
|
/* valgrind reports it as possible lost, but FLTK should free it */
|
||||||
|
delete stretched_alloc;
|
||||||
|
|
||||||
stretched = i->copy(w(), h());
|
stretched = i->copy(w(), h());
|
||||||
i->release();
|
i->release();
|
||||||
|
|
||||||
|
stretched_alloc = stretched;
|
||||||
}
|
}
|
||||||
|
|
||||||
image(stretched);
|
image(stretched);
|
||||||
|
@ -22,14 +22,19 @@ enum WallpaperState {
|
|||||||
WALLPAPER_TILE
|
WALLPAPER_TILE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Fl_Image;
|
||||||
|
|
||||||
class Wallpaper : public Fl_Box {
|
class Wallpaper : public Fl_Box {
|
||||||
private:
|
private:
|
||||||
Pixmap rootpmap_pixmap;
|
Pixmap rootpmap_pixmap;
|
||||||
WallpaperState state;
|
WallpaperState state;
|
||||||
|
Fl_Image* stretched_alloc; /* FLTK issue */
|
||||||
|
|
||||||
void set_rootpmap(void);
|
void set_rootpmap(void);
|
||||||
public:
|
public:
|
||||||
Wallpaper(int X, int Y, int W, int H) : Fl_Box(X, Y, W, H), rootpmap_pixmap(0), state(WALLPAPER_CENTER) { }
|
Wallpaper(int X, int Y, int W, int H) : Fl_Box(X, Y, W, H),
|
||||||
|
rootpmap_pixmap(0), state(WALLPAPER_CENTER), stretched_alloc(NULL) { }
|
||||||
|
|
||||||
~Wallpaper();
|
~Wallpaper();
|
||||||
|
|
||||||
bool load(const char* path, WallpaperState s);
|
bool load(const char* path, WallpaperState s);
|
||||||
|
@ -376,17 +376,19 @@ void Desktop::save_icons_positions(void) {
|
|||||||
E_WARNING(E_STRLOC ": Unable to store icons positions\n");
|
E_WARNING(E_STRLOC ": Unable to store icons positions\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Desktop::read_desktop_file(const char* path, IconSettings& is) {
|
IconSettings* Desktop::read_desktop_file(const char* path) {
|
||||||
E_ASSERT(path != NULL);
|
E_ASSERT(path != NULL);
|
||||||
|
|
||||||
edelib::DesktopFile dconf;
|
edelib::DesktopFile dconf;
|
||||||
if(!dconf.load(path)) {
|
if(!dconf.load(path)) {
|
||||||
E_WARNING(E_STRLOC ": Can't read %s (%s)\n", path, dconf.strerror());
|
E_WARNING(E_STRLOC ": Can't read %s (%s)\n", path, dconf.strerror());
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[128];
|
char buf[128];
|
||||||
int bufsz = sizeof(buf);
|
int bufsz = sizeof(buf);
|
||||||
|
|
||||||
|
IconSettings* is = new IconSettings;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for 'EmptyIcon' key since via it is determined is icon trash type or not
|
* Check for 'EmptyIcon' key since via it is determined is icon trash type or not
|
||||||
@ -395,47 +397,48 @@ bool Desktop::read_desktop_file(const char* path, IconSettings& is) {
|
|||||||
* FIXME: any other way to check for trash icons ???
|
* FIXME: any other way to check for trash icons ???
|
||||||
*/
|
*/
|
||||||
if(dconf.get("Desktop Entry", "EmptyIcon", buf, bufsz)) {
|
if(dconf.get("Desktop Entry", "EmptyIcon", buf, bufsz)) {
|
||||||
is.type = ICON_TRASH;
|
is->type = ICON_TRASH;
|
||||||
is.icon = buf;
|
is->icon = buf;
|
||||||
} else
|
} else
|
||||||
is.type = ICON_NORMAL;
|
is->type = ICON_NORMAL;
|
||||||
|
|
||||||
if(!dconf.icon(buf, bufsz)) {
|
if(!dconf.icon(buf, bufsz)) {
|
||||||
E_WARNING(E_STRLOC ": No Icon key, balling out\n");
|
E_WARNING(E_STRLOC ": No Icon key, balling out\n");
|
||||||
return false;
|
|
||||||
|
delete is;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is.type == ICON_TRASH)
|
if(is->type == ICON_TRASH)
|
||||||
is.icon2 = buf;
|
is->icon2 = buf;
|
||||||
else
|
else
|
||||||
is.icon = buf;
|
is->icon = buf;
|
||||||
|
|
||||||
edelib::DesktopFileType dtype = dconf.type();
|
edelib::DesktopFileType dtype = dconf.type();
|
||||||
if(dtype == edelib::DESK_FILE_TYPE_LINK) {
|
if(dtype == edelib::DESK_FILE_TYPE_LINK) {
|
||||||
is.cmd_is_url = true;
|
is->cmd_is_url = true;
|
||||||
dconf.url(buf, bufsz);
|
dconf.url(buf, bufsz);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
is.cmd_is_url = false;
|
is->cmd_is_url = false;
|
||||||
dconf.exec(buf, bufsz);
|
dconf.exec(buf, bufsz);
|
||||||
}
|
}
|
||||||
|
|
||||||
is.cmd = buf;
|
is->cmd = buf;
|
||||||
|
|
||||||
if(!dconf.name(buf, bufsz)) {
|
if(!dconf.name(buf, bufsz)) {
|
||||||
E_DEBUG(E_STRLOC ": No Name key\n");
|
E_DEBUG(E_STRLOC ": No Name key\n");
|
||||||
is.name = "(none)";
|
is->name = "(none)";
|
||||||
} else
|
} else
|
||||||
is.name = buf;
|
is->name = buf;
|
||||||
|
|
||||||
return true;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Desktop::add_icon_by_path(const char* path, edelib::Resource* conf) {
|
bool Desktop::add_icon_by_path(const char* path, edelib::Resource* conf) {
|
||||||
E_ASSERT(path != NULL);
|
E_ASSERT(path != NULL);
|
||||||
|
|
||||||
IconSettings is;
|
IconSettings* is = NULL;
|
||||||
bool can_add = false;
|
|
||||||
const char* base = get_basename(path);
|
const char* base = get_basename(path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -445,53 +448,50 @@ bool Desktop::add_icon_by_path(const char* path, edelib::Resource* conf) {
|
|||||||
* to be always present, or .desktop does not have to be Desktop File at all
|
* to be always present, or .desktop does not have to be Desktop File at all
|
||||||
*/
|
*/
|
||||||
if(edelib::str_ends(path, ".desktop")) {
|
if(edelib::str_ends(path, ".desktop")) {
|
||||||
if(read_desktop_file(path, is))
|
is = read_desktop_file(path);
|
||||||
can_add = true;
|
|
||||||
} else {
|
} else {
|
||||||
edelib::MimeType mt;
|
edelib::MimeType mt;
|
||||||
|
|
||||||
/* then try to figure out it's mime; if fails, ignore it */
|
/* then try to figure out it's mime; if fails, ignore it */
|
||||||
if(mt.set(path)) {
|
if(mt.set(path)) {
|
||||||
E_DEBUG(E_STRLOC ": Loading icon as mime-type %s\n", mt.icon_name().c_str());
|
E_DEBUG(E_STRLOC ": Loading icon as mime-type %s\n", mt.icon_name().c_str());
|
||||||
is.icon = mt.icon_name();
|
|
||||||
|
is = new IconSettings;
|
||||||
|
is->icon = mt.icon_name();
|
||||||
/* icon label path's basename */
|
/* icon label path's basename */
|
||||||
is.name = base;
|
is->name = base;
|
||||||
is.type = ICON_FILE;
|
is->type = ICON_FILE;
|
||||||
|
|
||||||
can_add = true;
|
|
||||||
} else {
|
|
||||||
E_DEBUG(E_STRLOC ": Failed mime-type for %s, ignoring...\n", path);
|
|
||||||
can_add = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(can_add) {
|
if(!is)
|
||||||
/*
|
return false;
|
||||||
* key_name is section in config file with icon X/Y values
|
|
||||||
* FIXME: this should be named 'section_name'
|
|
||||||
*/
|
|
||||||
is.key_name = base;
|
|
||||||
|
|
||||||
/* random_pos() is used if X/Y keys are not found */
|
/*
|
||||||
int icon_x = random_pos(w() - 10);
|
* key_name is section in config file with icon X/Y values
|
||||||
int icon_y = random_pos(w() - 10);
|
* FIXME: this should be named 'section_name'
|
||||||
|
*/
|
||||||
|
is->key_name = base;
|
||||||
|
|
||||||
if(conf) {
|
/* random_pos() is used if X/Y keys are not found */
|
||||||
/* we load positions from used ede-desktop-icos.conf only */
|
int icon_x = random_pos(w() - 10);
|
||||||
conf->get(base, "X", icon_x, icon_x, edelib::RES_USER_ONLY);
|
int icon_y = random_pos(w() - 10);
|
||||||
conf->get(base, "Y", icon_y, icon_y, edelib::RES_USER_ONLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
E_DEBUG(E_STRLOC ": %s found with: %i %i\n", base, icon_x, icon_y);
|
if(conf) {
|
||||||
is.x = icon_x;
|
/* we load positions from used ede-desktop-icos.conf only */
|
||||||
is.y = icon_y;
|
conf->get(base, "X", icon_x, icon_x, edelib::RES_USER_ONLY);
|
||||||
is.full_path = path;
|
conf->get(base, "Y", icon_y, icon_y, edelib::RES_USER_ONLY);
|
||||||
|
|
||||||
DesktopIcon* dic = new DesktopIcon(gisett, &is, color());
|
|
||||||
add_icon(dic);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return can_add;
|
E_DEBUG(E_STRLOC ": %s found with: %i %i\n", base, icon_x, icon_y);
|
||||||
|
is->x = icon_x;
|
||||||
|
is->y = icon_y;
|
||||||
|
is->full_path = path;
|
||||||
|
|
||||||
|
DesktopIcon* dic = new DesktopIcon(gisett, is, color());
|
||||||
|
add_icon(dic);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopIcon* Desktop::find_icon_by_path(const char* path, DesktopIconListIter* ret) {
|
DesktopIcon* Desktop::find_icon_by_path(const char* path, DesktopIconListIter* ret) {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* ede-desktop, desktop and icon manager
|
* ede-desktop, desktop and icon manager
|
||||||
* Part of Equinox Desktop Environment (EDE).
|
* Part of Equinox Desktop Environment (EDE).
|
||||||
* Copyright (c) 2006-2008 EDE Authors.
|
* Copyright (c) 2006-2009 EDE Authors.
|
||||||
*
|
*
|
||||||
* This program is licensed under terms of the
|
* This program is licensed under terms of the
|
||||||
* GNU General Public License version 2 or newer.
|
* GNU General Public License version 2 or newer.
|
||||||
@ -38,7 +38,6 @@
|
|||||||
#define ICON_FACE_ONE 1 // use icon
|
#define ICON_FACE_ONE 1 // use icon
|
||||||
#define ICON_FACE_TWO 2 // use icon2
|
#define ICON_FACE_TWO 2 // use icon2
|
||||||
|
|
||||||
|
|
||||||
struct GlobalIconSettings {
|
struct GlobalIconSettings {
|
||||||
int label_background;
|
int label_background;
|
||||||
int label_foreground;
|
int label_foreground;
|
||||||
@ -118,7 +117,7 @@ private:
|
|||||||
|
|
||||||
void load_icons(const char* path);
|
void load_icons(const char* path);
|
||||||
void save_icons_positions(void);
|
void save_icons_positions(void);
|
||||||
bool read_desktop_file(const char* path, IconSettings& is);
|
IconSettings* read_desktop_file(const char* path);
|
||||||
|
|
||||||
void add_icon(DesktopIcon* ic);
|
void add_icon(DesktopIcon* ic);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user