From 77c2ce9739a624b678f722102785da60636a5752 Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Tue, 18 Oct 2011 08:17:35 +0000 Subject: [PATCH] Refactoring some icon handling. Dumping trash handling; this should be done by separate application --- ede-desktop/DesktopIcon.cpp | 59 +---------------------------- ede-desktop/DesktopIcon.h | 14 ------- ede-desktop/Jamfile | 7 +++- ede-desktop/MovableIcon.cpp | 75 +++++++++++++++++++++++++++++++++++++ ede-desktop/MovableIcon.h | 34 +++++++++++++++++ ede-desktop/ede-desktop.cpp | 40 +------------------- ede-desktop/ede-desktop.h | 18 +++------ 7 files changed, 122 insertions(+), 125 deletions(-) create mode 100644 ede-desktop/MovableIcon.cpp create mode 100644 ede-desktop/MovableIcon.h diff --git a/ede-desktop/DesktopIcon.cpp b/ede-desktop/DesktopIcon.cpp index e54709c..4db944c 100644 --- a/ede-desktop/DesktopIcon.cpp +++ b/ede-desktop/DesktopIcon.cpp @@ -27,12 +27,9 @@ #include #include -#ifdef HAVE_SHAPE -# include -#endif - #include "ede-desktop.h" #include "DesktopIcon.h" +#include "MovableIcon.h" #include "IconProperties.h" #include "Utils.h" @@ -91,7 +88,6 @@ static void rename_cb(Fl_Widget*, void* d) { static void props_cb(Fl_Widget*, void* d) { DesktopIcon* di = (DesktopIcon*)d; - show_icon_properties_dialog(di); } @@ -431,56 +427,3 @@ int DesktopIcon::handle(int event) { 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 -} diff --git a/ede-desktop/DesktopIcon.h b/ede-desktop/DesktopIcon.h index c28e888..425eb11 100644 --- a/ede-desktop/DesktopIcon.h +++ b/ede-desktop/DesktopIcon.h @@ -13,8 +13,6 @@ #ifndef __DESKTOPICON_H__ #define __DESKTOPICON_H__ -#include // Pixmap - #include #include #include @@ -94,16 +92,4 @@ public: 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 diff --git a/ede-desktop/Jamfile b/ede-desktop/Jamfile index 4b8b837..76559f5 100644 --- a/ede-desktop/Jamfile +++ b/ede-desktop/Jamfile @@ -12,7 +12,12 @@ SubDir TOP ede-desktop ; 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) ; diff --git a/ede-desktop/MovableIcon.cpp b/ede-desktop/MovableIcon.cpp new file mode 100644 index 0000000..c1d16d8 --- /dev/null +++ b/ede-desktop/MovableIcon.cpp @@ -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 +#endif + +#define FL_LIBRARY 1 +#include +#include +#include + +#ifdef HAVE_SHAPE +# include +#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 +} diff --git a/ede-desktop/MovableIcon.h b/ede-desktop/MovableIcon.h new file mode 100644 index 0000000..823adcc --- /dev/null +++ b/ede-desktop/MovableIcon.h @@ -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 // Pixmap +#include +#include + +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 diff --git a/ede-desktop/ede-desktop.cpp b/ede-desktop/ede-desktop.cpp index c2d8cee..2de8b09 100644 --- a/ede-desktop/ede-desktop.cpp +++ b/ede-desktop/ede-desktop.cpp @@ -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); 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) { 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)) 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) { 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 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) return 1; diff --git a/ede-desktop/ede-desktop.h b/ede-desktop/ede-desktop.h index d739266..00ed2da 100644 --- a/ede-desktop/ede-desktop.h +++ b/ede-desktop/ede-desktop.h @@ -14,10 +14,12 @@ #define __EDE_DESKTOP_H__ #ifdef USE_EDELIB_WINDOW - #include +# include +# define DESKTOP_WINDOW edelib::Window #else - #include - #include +# include +# include +# define DESKTOP_WINDOW Fl_Window #endif #include @@ -86,12 +88,6 @@ typedef edelib::list::iterator DesktopIconListIter; typedef edelib::list StringList; typedef edelib::list::iterator StringListIter; -#ifdef USE_EDELIB_WINDOW - #define DESKTOP_WINDOW edelib::Window -#else - #define DESKTOP_WINDOW Fl_Window -#endif - class Desktop : public DESKTOP_WINDOW { private: static Desktop* pinstance; @@ -111,8 +107,6 @@ private: DesktopIconList icons; DesktopIconList selectionbuf; - edelib::String trash_path; - void init_internals(void); void load_icons(const char* path); @@ -127,8 +121,6 @@ private: void auto_arrange(void); - void update_trash_icons(void); - void unfocus_all(void); void select(DesktopIcon* ic, bool do_redraw = true);