Refactoring some icon handling. Dumping trash handling; this should be done by separate application

This commit is contained in:
Sanel Zukan 2011-10-18 08:17:35 +00:00
parent f3ff9ade2d
commit 77c2ce9739
7 changed files with 122 additions and 125 deletions

View File

@ -27,12 +27,9 @@
#include <edelib/Nls.h> #include <edelib/Nls.h>
#include <edelib/Run.h> #include <edelib/Run.h>
#ifdef HAVE_SHAPE
# include <X11/extensions/shape.h>
#endif
#include "ede-desktop.h" #include "ede-desktop.h"
#include "DesktopIcon.h" #include "DesktopIcon.h"
#include "MovableIcon.h"
#include "IconProperties.h" #include "IconProperties.h"
#include "Utils.h" #include "Utils.h"
@ -91,7 +88,6 @@ static void rename_cb(Fl_Widget*, void* d) {
static void props_cb(Fl_Widget*, void* d) { static void props_cb(Fl_Widget*, void* d) {
DesktopIcon* di = (DesktopIcon*)d; DesktopIcon* di = (DesktopIcon*)d;
show_icon_properties_dialog(di); show_icon_properties_dialog(di);
} }
@ -431,56 +427,3 @@ int DesktopIcon::handle(int event) {
return 0; return 0;
} }
MovableIcon::MovableIcon(DesktopIcon* ic) : Fl_Window(ic->x(), ic->y(), ic->w(), ic->h()), icon(ic), mask(0) {
E_ASSERT(icon != NULL);
set_override();
color(ic->color());
begin();
/*
* Force box be same width/height as icon so it
* can fit inside masked window.
*/
#ifdef HAVE_SHAPE
Fl_Image* img = ic->icon_image();
if(img)
icon_box = new Fl_Box(0, 0, img->w(), img->h());
else
icon_box = new Fl_Box(0, 0, w(), h());
#else
icon_box = new Fl_Box(0, 0, w(), h());
#endif
icon_box->image(ic->icon_image());
end();
}
MovableIcon::~MovableIcon() {
if(mask)
XFreePixmap(fl_display, mask);
}
void MovableIcon::show(void) {
if(!shown())
Fl_X::make_xid(this);
#ifdef HAVE_SHAPE
if(icon->icon_image()) {
mask = create_mask(icon->icon_image());
if(mask) {
XShapeCombineMask(fl_display, fl_xid(this), ShapeBounding, 0, 0, mask, ShapeSet);
/*
* now set transparency; composite manager should handle the rest (if running)
* TODO: should this be declared as part of the class ?
*/
Atom opacity_atom = XInternAtom(fl_display, "_NET_WM_WINDOW_OPACITY", False);
unsigned int opacity = 0xc0000000;
XChangeProperty(fl_display, fl_xid(this), opacity_atom, XA_CARDINAL, 32, PropModeReplace,
(unsigned char*)&opacity, 1L);
}
}
#endif
}

View File

@ -13,8 +13,6 @@
#ifndef __DESKTOPICON_H__ #ifndef __DESKTOPICON_H__
#define __DESKTOPICON_H__ #define __DESKTOPICON_H__
#include <X11/Xlib.h> // Pixmap
#include <FL/Fl_Widget.H> #include <FL/Fl_Widget.H>
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <FL/Fl_Box.H> #include <FL/Fl_Box.H>
@ -94,16 +92,4 @@ public:
void use_icon2(void); void use_icon2(void);
}; };
class MovableIcon : public Fl_Window {
private:
DesktopIcon* icon;
Fl_Box* icon_box;
Pixmap mask;
public:
MovableIcon(DesktopIcon* i);
~MovableIcon();
virtual void show(void);
};
#endif #endif

View File

@ -12,7 +12,12 @@ SubDir TOP ede-desktop ;
ObjectC++Flags ede-desktop.cpp : -DUSE_EDELIB_WINDOW ; ObjectC++Flags ede-desktop.cpp : -DUSE_EDELIB_WINDOW ;
SOURCE = ede-desktop.cpp Utils.cpp Wallpaper.cpp DesktopIcon.cpp IconProperties.cpp ; SOURCE = ede-desktop.cpp
Utils.cpp
Wallpaper.cpp
DesktopIcon.cpp
MovableIcon.cpp
IconProperties.cpp ;
ObjectC++Flags $(SOURCE) : $(EDELIB_DBUS_INCLUDE) ; ObjectC++Flags $(SOURCE) : $(EDELIB_DBUS_INCLUDE) ;

View File

@ -0,0 +1,75 @@
/*
* $Id: DesktopIcon.cpp 3032 2011-08-03 12:20:37Z karijes $
*
* ede-desktop, desktop and icon manager
* Part of Equinox Desktop Environment (EDE).
* Copyright (c) 2006-2011 EDE Authors.
*
* This program is licensed under terms of the
* GNU General Public License version 2 or newer.
* See COPYING for details.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#define FL_LIBRARY 1
#include <FL/Fl.H>
#include <FL/x.H>
#include <edelib/Debug.h>
#ifdef HAVE_SHAPE
# include <X11/extensions/shape.h>
#endif
#include "MovableIcon.h"
#include "DesktopIcon.h"
#include "Utils.h"
MovableIcon::MovableIcon(DesktopIcon* ic) : Fl_Window(ic->x(), ic->y(), ic->w(), ic->h()), icon(ic), mask(0), opacity_atom(0) {
E_ASSERT(icon != NULL);
set_override();
color(ic->color());
begin();
/* force box be same width/height as icon so it can fit inside masked window */
#ifdef HAVE_SHAPE
Fl_Image* img = ic->icon_image();
if(img)
icon_box = new Fl_Box(0, 0, img->w(), img->h());
else
icon_box = new Fl_Box(0, 0, w(), h());
#else
icon_box = new Fl_Box(0, 0, w(), h());
#endif
icon_box->image(ic->icon_image());
end();
opacity_atom = XInternAtom(fl_display, "_NET_WM_WINDOW_OPACITY", False);
}
MovableIcon::~MovableIcon() {
if(mask)
XFreePixmap(fl_display, mask);
}
void MovableIcon::show(void) {
if(!shown())
Fl_X::make_xid(this);
#ifdef HAVE_SHAPE
if(icon->icon_image()) {
mask = create_mask(icon->icon_image());
if(mask) {
XShapeCombineMask(fl_display, fl_xid(this), ShapeBounding, 0, 0, mask, ShapeSet);
/* now set transparency; composite manager should handle the rest (if running) */
unsigned int opacity = 0xc0000000;
XChangeProperty(fl_display, fl_xid(this), opacity_atom, XA_CARDINAL, 32, PropModeReplace,
(unsigned char*)&opacity, 1L);
}
}
#endif
}

34
ede-desktop/MovableIcon.h Normal file
View File

@ -0,0 +1,34 @@
/*
* $Id: DesktopIcon.h 2742 2009-07-09 13:59:51Z karijes $
*
* ede-desktop, desktop and icon manager
* Part of Equinox Desktop Environment (EDE).
* Copyright (c) 2006-2011 EDE Authors.
*
* This program is licensed under terms of the
* GNU General Public License version 2 or newer.
* See COPYING for details.
*/
#ifndef __MOVABLEICON_H__
#define __MOVABLEICON_H__
#include <X11/Xlib.h> // Pixmap
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
class DesktopIcon;
class MovableIcon : public Fl_Window {
private:
DesktopIcon* icon;
Fl_Box* icon_box;
Pixmap mask;
Atom opacity_atom;
public:
MovableIcon(DesktopIcon* i);
~MovableIcon();
virtual void show(void);
};
#endif

View File

@ -233,21 +233,6 @@ void Desktop::init_internals(void) {
} }
} }
/*
* For watching Trash, we will check Trash/files only with create/delete flags and
* in callback will be checked if directory is empty (trash empty) or not (trash full).
*/
p = edelib::user_data_dir();
trash_path = edelib::build_filename(p.c_str(), "Trash/files");
if(edelib::file_test(trash_path.c_str(), edelib::FILE_TEST_IS_DIR)) {
if(!edelib::DirWatch::add(trash_path.c_str(), edelib::DW_CREATE | edelib::DW_DELETE))
E_WARNING(E_STRLOC ": Unable to watch %s\n", trash_path.c_str());
}
/* draw appropriate trash icon */
update_trash_icons();
edelib::DirWatch::callback(dir_watch_cb); edelib::DirWatch::callback(dir_watch_cb);
running = true; running = true;
} }
@ -576,20 +561,6 @@ void Desktop::auto_arrange(void) {
} }
} }
void Desktop::update_trash_icons(void) {
bool is_empty = edelib::dir_empty(trash_path.c_str());
DesktopIconListIter it = icons.begin(), it_end = icons.end();
for(; it != it_end; ++it) {
if((*it)->icon_type() == ICON_TRASH) {
if(is_empty)
(*it)->use_icon1();
else
(*it)->use_icon2();
}
}
}
void Desktop::add_icon(DesktopIcon* ic) { void Desktop::add_icon(DesktopIcon* ic) {
E_ASSERT(ic != NULL); E_ASSERT(ic != NULL);
@ -936,12 +907,6 @@ void Desktop::dir_watch(const char* dir, const char* changed, int flags) {
if(is_temp_filename(changed)) if(is_temp_filename(changed))
return; return;
if(trash_path == dir) {
update_trash_icons();
E_DEBUG(E_STRLOC ": event on trash dir %s\n", dir);
return;
}
if(flags == edelib::DW_REPORT_CREATE) { if(flags == edelib::DW_REPORT_CREATE) {
E_DEBUG(E_STRLOC ": adding %s\n", changed); E_DEBUG(E_STRLOC ": adding %s\n", changed);
@ -1003,10 +968,7 @@ int Desktop::handle(int event) {
// from here, all events are managed for icons // from here, all events are managed for icons
DesktopIcon* tmp_icon = (DesktopIcon*)clicked; DesktopIcon* tmp_icon = (DesktopIcon*)clicked;
/* /* do no use assertion on this, since fltk::belowmouse() can miss our icon */
* do no use assertion on this, since
* fltk::belowmouse() can miss our icon
*/
if(!tmp_icon) if(!tmp_icon)
return 1; return 1;

View File

@ -14,10 +14,12 @@
#define __EDE_DESKTOP_H__ #define __EDE_DESKTOP_H__
#ifdef USE_EDELIB_WINDOW #ifdef USE_EDELIB_WINDOW
#include <edelib/Window.h> # include <edelib/Window.h>
# define DESKTOP_WINDOW edelib::Window
#else #else
#include <FL/Fl_Window.H> # include <FL/Fl_Window.H>
#include <FL/Fl_Double_Window.H> # include <FL/Fl_Double_Window.H>
# define DESKTOP_WINDOW Fl_Window
#endif #endif
#include <FL/Fl_Image.H> #include <FL/Fl_Image.H>
@ -86,12 +88,6 @@ typedef edelib::list<DesktopIcon*>::iterator DesktopIconListIter;
typedef edelib::list<edelib::String> StringList; typedef edelib::list<edelib::String> StringList;
typedef edelib::list<edelib::String>::iterator StringListIter; typedef edelib::list<edelib::String>::iterator StringListIter;
#ifdef USE_EDELIB_WINDOW
#define DESKTOP_WINDOW edelib::Window
#else
#define DESKTOP_WINDOW Fl_Window
#endif
class Desktop : public DESKTOP_WINDOW { class Desktop : public DESKTOP_WINDOW {
private: private:
static Desktop* pinstance; static Desktop* pinstance;
@ -111,8 +107,6 @@ private:
DesktopIconList icons; DesktopIconList icons;
DesktopIconList selectionbuf; DesktopIconList selectionbuf;
edelib::String trash_path;
void init_internals(void); void init_internals(void);
void load_icons(const char* path); void load_icons(const char* path);
@ -127,8 +121,6 @@ private:
void auto_arrange(void); void auto_arrange(void);
void update_trash_icons(void);
void unfocus_all(void); void unfocus_all(void);
void select(DesktopIcon* ic, bool do_redraw = true); void select(DesktopIcon* ic, bool do_redraw = true);