2006-08-20 22:43:09 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-05-22 18:53:17 +04:00
|
|
|
* Eiconman, desktop and icon manager
|
2006-08-20 22:43:09 +04:00
|
|
|
* Part of Equinox Desktop Environment (EDE).
|
2007-05-22 18:53:17 +04:00
|
|
|
* Copyright (c) 2000-2007 EDE Authors.
|
2006-08-20 22:43:09 +04:00
|
|
|
*
|
2007-05-22 18:53:17 +04:00
|
|
|
* This program is licensed under terms of the
|
|
|
|
* GNU General Public License version 2 or newer.
|
2006-08-20 22:43:09 +04:00
|
|
|
* See COPYING for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "eiconman.h"
|
2007-05-22 18:53:17 +04:00
|
|
|
#include "DesktopIcon.h"
|
|
|
|
#include "Utils.h"
|
2007-06-18 18:18:35 +04:00
|
|
|
#include "Wallpaper.h"
|
2007-06-18 20:46:27 +04:00
|
|
|
#include "NotifyBox.h"
|
2007-07-30 16:46:37 +04:00
|
|
|
#include "Utf8.h"
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
#include <edelib/Debug.h>
|
2007-06-18 18:18:35 +04:00
|
|
|
#include <edelib/File.h>
|
2007-06-25 13:20:49 +04:00
|
|
|
#include <edelib/DesktopFile.h>
|
2007-05-22 18:53:17 +04:00
|
|
|
#include <edelib/Directory.h>
|
2007-06-18 18:18:35 +04:00
|
|
|
#include <edelib/MimeType.h>
|
2007-05-22 18:53:17 +04:00
|
|
|
#include <edelib/StrUtil.h>
|
|
|
|
#include <edelib/IconTheme.h>
|
2007-07-02 14:28:18 +04:00
|
|
|
#include <edelib/Nls.h>
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
#include <FL/Fl.h>
|
|
|
|
#include <FL/x.h>
|
2007-07-02 14:28:18 +04:00
|
|
|
#include <FL/fl_draw.h>
|
2007-06-18 18:18:35 +04:00
|
|
|
#include <FL/Fl_Box.h>
|
2007-07-02 14:28:18 +04:00
|
|
|
#include <FL/Fl_Shared_Image.h>
|
|
|
|
#include <FL/Fl_Menu_Button.h>
|
|
|
|
#include <FL/fl_ask.h>
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#include <X11/extensions/Xdamage.h>
|
|
|
|
#endif
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h> // rand, srand
|
|
|
|
#include <time.h> // time
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
#define CONFIG_NAME "eiconman.conf"
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
#define SELECTION_SINGLE (Fl::event_button() == 1)
|
2007-06-29 15:22:29 +04:00
|
|
|
#define SELECTION_MULTI (Fl::event_button() == 1 && (Fl::event_key(FL_Shift_L) || Fl::event_key(FL_Shift_R)))
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-23 16:43:50 +04:00
|
|
|
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
|
|
|
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
/*
|
|
|
|
* Which widgets Fl::belowmouse() should skip. This should be updated
|
|
|
|
* when new non-icon child is added to Desktop window.
|
|
|
|
*/
|
2007-07-02 14:28:18 +04:00
|
|
|
#define NOT_SELECTABLE(widget) ((widget == this) || (widget == wallpaper) || (widget == dmenu))
|
|
|
|
|
|
|
|
Fl_Menu_Item desktop_menu[] = {
|
|
|
|
{_(" &New desktop item "), 0, 0, 0, FL_SUBMENU},
|
|
|
|
{_(" &Application... "), 0, 0},
|
|
|
|
{_(" &Directory... "), 0, 0},
|
|
|
|
{_(" &URL... "), 0, 0},
|
|
|
|
{_(" &Link... "), 0, 0},
|
|
|
|
{0},
|
|
|
|
{_(" &Arrange "), 0, 0, 0, FL_SUBMENU | FL_MENU_DIVIDER},
|
|
|
|
{_(" &By name "), 0, 0},
|
|
|
|
{_(" &Vertical line up "), 0, 0},
|
|
|
|
{_(" &Horizontal line up "), 0, 0},
|
|
|
|
{0},
|
|
|
|
{_(" &Copy "), 0, 0},
|
|
|
|
{_(" &Paste "), 0, 0, 0, FL_MENU_DIVIDER},
|
|
|
|
{_(" &Icons settings... "), 0, 0},
|
|
|
|
{_(" &Background... "), 0, 0},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
XserverRegion xregion;
|
|
|
|
XserverRegion xpart;
|
|
|
|
Damage xdamage;
|
|
|
|
int xevent_base, xerror_base;
|
|
|
|
#endif
|
2007-05-23 16:43:50 +04:00
|
|
|
|
2007-05-24 16:53:03 +04:00
|
|
|
Desktop* Desktop::pinstance = NULL;
|
2007-06-18 18:18:35 +04:00
|
|
|
bool running = false;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
inline unsigned int random_pos(int max) {
|
|
|
|
return (rand() % max);
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-23 16:43:50 +04:00
|
|
|
inline bool intersects(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) {
|
|
|
|
return (MAX(x1, x2) <= MIN(w1, w2) &&
|
|
|
|
MAX(y1, y2) <= MIN(h1, h2));
|
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
// assume fl_open_display() is called before
|
2007-05-22 18:53:17 +04:00
|
|
|
inline void dpy_sizes(int& width, int& height) {
|
2007-06-18 18:18:35 +04:00
|
|
|
width = DisplayWidth(fl_display, fl_screen);
|
|
|
|
height = DisplayHeight(fl_display, fl_screen);
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void exit_signal(int signum) {
|
|
|
|
EDEBUG(ESTRLOC ": Exiting (got signal %d)\n", signum);
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
void restart_signal(int signum) {
|
|
|
|
EDEBUG(ESTRLOC ": Restarting (got signal %d)\n", signum);
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
int desktop_xmessage_handler(int event) {
|
2007-07-02 14:28:18 +04:00
|
|
|
#if 0
|
|
|
|
if(fl_xevent->type == xevent_base + XDamageNotify) {
|
|
|
|
XDamageNotifyEvent* xdev = (XDamageNotifyEvent*)fl_xevent;
|
|
|
|
|
|
|
|
EDEBUG(ESTRLOC ": Damaged region %i %i %i %i on 0x%lx\n", xdev->area.x, xdev->area.y,
|
|
|
|
xdev->area.width, xdev->area.height, xdev->drawable);
|
|
|
|
|
|
|
|
//XDamageSubtract(fl_display, xdev->damage, None, None);
|
|
|
|
XFixesSetRegion(fl_display, xpart, &xdev->area, 1);
|
|
|
|
XFixesUnionRegion(fl_display, xregion, xregion, xpart);
|
|
|
|
}
|
|
|
|
|
|
|
|
XDamageSubtract(fl_display, xdamage, xregion, None);
|
|
|
|
XFixesSetRegion(fl_display, xregion, 0, 0);
|
|
|
|
#endif
|
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
if(fl_xevent->type == PropertyNotify) {
|
|
|
|
if(fl_xevent->xproperty.atom == _XA_NET_CURRENT_DESKTOP) {
|
|
|
|
Desktop::instance()->notify_desktop_changed();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fl_xevent->xproperty.atom == _XA_EDE_DESKTOP_NOTIFY) {
|
|
|
|
char buff[256];
|
|
|
|
if(ede_get_desktop_notify(buff, 256) && buff[0] != '\0')
|
|
|
|
Desktop::instance()->notify_box(buff, true);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-20 14:58:07 +04:00
|
|
|
if(fl_xevent->xproperty.atom == _XA_EDE_DESKTOP_NOTIFY_COLOR) {
|
2007-06-19 13:59:15 +04:00
|
|
|
Desktop::instance()->notify_box_color(ede_get_desktop_notify_color());
|
|
|
|
return 1;
|
|
|
|
}
|
2007-06-20 14:58:07 +04:00
|
|
|
|
|
|
|
if(fl_xevent->xproperty.atom == _XA_NET_WORKAREA) {
|
|
|
|
Desktop::instance()->update_workarea();
|
|
|
|
return 1;
|
|
|
|
}
|
2007-06-19 13:59:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-05-24 16:53:03 +04:00
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
Desktop::Desktop() : DESKTOP_WINDOW(0, 0, 100, 100, "") {
|
2007-06-18 18:18:35 +04:00
|
|
|
selection_x = selection_y = 0;
|
|
|
|
moving = false;
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
selbox = new SelectionOverlay;
|
|
|
|
selbox->x = selbox->y = selbox->w = selbox->h = 0;
|
|
|
|
selbox->show = false;
|
|
|
|
|
2007-05-24 16:53:03 +04:00
|
|
|
dsett = new DesktopSettings;
|
2007-06-18 18:18:35 +04:00
|
|
|
dsett->color = FL_GRAY;
|
2007-05-24 16:53:03 +04:00
|
|
|
dsett->wp_use = false;
|
2007-06-29 15:22:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Desktop::~Desktop() {
|
|
|
|
EDEBUG("Desktop::~Desktop()\n");
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-29 15:22:29 +04:00
|
|
|
delete dsett;
|
|
|
|
delete selbox;
|
|
|
|
delete notify;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Desktop::init_internals(void) {
|
2007-06-19 13:59:15 +04:00
|
|
|
init_atoms();
|
2007-05-22 18:53:17 +04:00
|
|
|
update_workarea();
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
/*
|
|
|
|
* NOTE: order how childs are added is important. First
|
|
|
|
* non iconable ones should be added (wallpaper, menu, ...)
|
|
|
|
* then icons, so they can be drawn at top of them.
|
|
|
|
*/
|
2007-05-22 18:53:17 +04:00
|
|
|
begin();
|
2007-07-02 14:28:18 +04:00
|
|
|
dmenu = new Fl_Menu_Button(0, 0, 0, 0);
|
|
|
|
dmenu->menu(desktop_menu);
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
wallpaper = new Wallpaper(0, 0, w(), h());
|
2007-07-02 14:28:18 +04:00
|
|
|
wallpaper->set("/home/sanel/wallpapers/katebig.jpg");
|
2007-06-26 20:33:25 +04:00
|
|
|
//wallpaper->set_tiled("/home/sanel/wallpapers/katesmall.jpg");
|
|
|
|
//wallpaper->set_tiled("/home/sanelz/walls/katesmall.jpg");
|
|
|
|
//wallpaper->set_tiled("/home/sanelz/walls/kate.jpg");
|
2007-07-02 14:28:18 +04:00
|
|
|
//wallpaper->set("/home/sanelz/walls/katebig.jpg");
|
2007-06-26 20:33:25 +04:00
|
|
|
//wallpaper->hide();
|
2007-06-29 15:22:29 +04:00
|
|
|
//wallpaper->set("/home/sanelz/walls/katesmall.jpg");
|
|
|
|
//wallpaper->set("/home/sanelz/walls/nin/1024x768-04.jpg");
|
2007-06-20 14:58:07 +04:00
|
|
|
//wallpaper->set("/home/sanelz/walls/nin/1024x768-02.jpg");
|
2007-05-22 18:53:17 +04:00
|
|
|
end();
|
2007-05-24 16:53:03 +04:00
|
|
|
|
2007-06-28 15:21:24 +04:00
|
|
|
notify = new NotifyBox(w(), h());
|
2007-06-29 15:22:29 +04:00
|
|
|
set_bg_color(dsett->color, false);
|
2007-06-28 15:21:24 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
read_config();
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
running = true;
|
|
|
|
}
|
2007-05-25 21:45:17 +04:00
|
|
|
|
2007-05-24 16:53:03 +04:00
|
|
|
void Desktop::init(void) {
|
|
|
|
if(Desktop::pinstance != NULL)
|
|
|
|
return;
|
|
|
|
Desktop::pinstance = new Desktop();
|
2007-06-29 15:22:29 +04:00
|
|
|
Desktop::pinstance->init_internals();
|
2007-05-24 16:53:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Desktop::shutdown(void) {
|
|
|
|
if(Desktop::pinstance == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
delete Desktop::pinstance;
|
|
|
|
Desktop::pinstance = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Desktop* Desktop::instance(void) {
|
|
|
|
EASSERT(Desktop::pinstance != NULL && "Desktop::init() should be run first");
|
|
|
|
return Desktop::pinstance;
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
/*
|
|
|
|
* This function must be overriden so window can inform
|
|
|
|
* wm to see it as desktop. It will send data when window
|
|
|
|
* is created, but before is shown.
|
|
|
|
*/
|
|
|
|
void Desktop::show(void) {
|
|
|
|
if(!shown()) {
|
|
|
|
Fl_X::make_xid(this);
|
|
|
|
net_make_me_desktop(this);
|
2007-07-02 14:28:18 +04:00
|
|
|
#if 0
|
|
|
|
XDamageQueryExtension(fl_display, &xevent_base, &xerror_base);
|
|
|
|
|
|
|
|
xdamage = XDamageCreate(fl_display, fl_xid(this), XDamageReportBoundingBox);
|
|
|
|
xregion = XFixesCreateRegionFromWindow(fl_display, fl_xid(this), 0);
|
|
|
|
xpart = XFixesCreateRegionFromWindow(fl_display, fl_xid(this), 0);
|
|
|
|
#endif
|
2007-06-18 18:18:35 +04:00
|
|
|
}
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
/*
|
|
|
|
* If someone intentionaly hide desktop
|
|
|
|
* then quit from it.
|
|
|
|
*/
|
|
|
|
void Desktop::hide(void) {
|
|
|
|
running = false;
|
2007-05-24 16:53:03 +04:00
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
void Desktop::update_workarea(void) {
|
|
|
|
int X, Y, W, H;
|
|
|
|
if(!net_get_workarea(X, Y, W, H)) {
|
|
|
|
EWARNING(ESTRLOC ": wm does not support _NET_WM_WORKAREA; using screen sizes...\n");
|
|
|
|
X = Y = 0;
|
|
|
|
dpy_sizes(W, H);
|
|
|
|
}
|
2007-05-24 16:53:03 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
resize(X, Y, W, H);
|
2007-05-24 16:53:03 +04:00
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
void Desktop::set_bg_color(int c, bool do_redraw) {
|
|
|
|
if(color() == c)
|
2007-05-24 16:53:03 +04:00
|
|
|
return;
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
dsett->color = c;
|
|
|
|
color(c);
|
2007-05-24 16:53:03 +04:00
|
|
|
if(do_redraw)
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
void Desktop::read_config(void) {
|
|
|
|
edelib::Config conf;
|
|
|
|
if(!conf.load(CONFIG_NAME)) {
|
2007-06-18 18:18:35 +04:00
|
|
|
EWARNING(ESTRLOC ": Can't load %s, using default...\n", CONFIG_NAME);
|
2007-05-22 18:53:17 +04:00
|
|
|
return;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* Add IconArea[X,Y,W,H] so icons can live
|
|
|
|
* inside that area only (aka margins).
|
|
|
|
*/
|
2007-06-18 18:18:35 +04:00
|
|
|
int default_bg_color = FL_BLUE;
|
2007-05-24 16:53:03 +04:00
|
|
|
int default_wp_use = false;
|
|
|
|
char wpath[256];
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
// read Desktop section
|
2007-05-24 16:53:03 +04:00
|
|
|
conf.get("Desktop", "Color", dsett->color, default_bg_color);
|
|
|
|
|
|
|
|
if(conf.error() != edelib::CONF_ERR_SECTION) {
|
|
|
|
conf.get("Desktop", "WallpaperUse", dsett->wp_use, default_wp_use);
|
|
|
|
conf.get("Desktop", "Wallpaper", wpath, sizeof(wpath));
|
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
// keep path but disable wallpaper if file does not exists
|
|
|
|
if(!edelib::file_exists(wpath)) {
|
|
|
|
EDEBUG(ESTRLOC ": %s as wallpaper does not exists\n", wpath);
|
|
|
|
dsett->wp_use = false;
|
|
|
|
}
|
2007-05-24 16:53:03 +04:00
|
|
|
} else {
|
|
|
|
// color is already filled
|
|
|
|
dsett->wp_use = default_wp_use;
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
// read Icons section
|
2007-06-18 18:18:35 +04:00
|
|
|
conf.get("Icons", "Label Background", gisett.label_background, FL_BLUE);
|
|
|
|
conf.get("Icons", "Label Foreground", gisett.label_foreground, FL_WHITE);
|
2007-05-22 18:53:17 +04:00
|
|
|
conf.get("Icons", "Label Fontsize", gisett.label_fontsize, 12);
|
|
|
|
conf.get("Icons", "Label Maxwidth", gisett.label_maxwidth, 75);
|
|
|
|
conf.get("Icons", "Label Transparent",gisett.label_transparent, false);
|
|
|
|
conf.get("Icons", "Label Visible", gisett.label_draw, true);
|
|
|
|
conf.get("Icons", "OneClickExec", gisett.one_click_exec, false);
|
2007-06-18 18:18:35 +04:00
|
|
|
conf.get("Icons", "AutoArrange", gisett.auto_arrange, true);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now try to load icons, first looking inside ~/Desktop directory
|
|
|
|
* then inside config since config could contain removed entries
|
|
|
|
* from $HOME/Desktop
|
|
|
|
*
|
|
|
|
* FIXME: dir_exists() can't handle '~/Desktop' ???
|
|
|
|
*/
|
|
|
|
edelib::String dd = edelib::dir_home();
|
2007-06-18 18:18:35 +04:00
|
|
|
if(dd.empty()) {
|
|
|
|
EWARNING(ESTRLOC ": Can't read home directory; icons will not be loaded\n");
|
|
|
|
return;
|
|
|
|
}
|
2007-05-22 18:53:17 +04:00
|
|
|
dd += "/Desktop";
|
|
|
|
load_icons(dd.c_str(), conf);
|
2007-06-18 18:18:35 +04:00
|
|
|
}
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
void Desktop::save_config(void) {
|
|
|
|
// TODO
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
void Desktop::load_icons(const char* path, edelib::Config& conf) {
|
|
|
|
EASSERT(path != NULL);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
if(!edelib::dir_exists(path)) {
|
|
|
|
EDEBUG(ESTRLOC ": %s does not exists\n", path);
|
|
|
|
return;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
edelib::vector<edelib::String> lst;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
// list without full path, so we can use name as entry in config file
|
|
|
|
if(!dir_list(path, lst)) {
|
|
|
|
EDEBUG(ESTRLOC ": Can't read %s\n", path);
|
|
|
|
return;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
const char* name = NULL;
|
|
|
|
int icon_x = 0;
|
|
|
|
int icon_y = 0;
|
|
|
|
edelib::String full_path;
|
|
|
|
full_path.reserve(256);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
bool can_add = false;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
edelib::MimeType mt;
|
|
|
|
|
|
|
|
unsigned int sz = lst.size();
|
|
|
|
for(unsigned int i = 0; i < sz; i++) {
|
|
|
|
name = lst[i].c_str();
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
full_path = path;
|
|
|
|
full_path += '/';
|
|
|
|
full_path += name;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
can_add = false;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
IconSettings is;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
// see is possible .desktop file, icon, name fields are filled from read_desktop_file()
|
|
|
|
if(edelib::str_ends(name, ".desktop")) {
|
|
|
|
if(read_desktop_file(full_path.c_str(), is))
|
|
|
|
can_add = true;
|
|
|
|
} else {
|
|
|
|
// then try to figure out it's mime; if fails, ignore it
|
|
|
|
if(mt.set(full_path.c_str())) {
|
2007-06-23 15:31:36 +04:00
|
|
|
EDEBUG(ESTRLOC ": Loading icon as mime-type %s\n", mt.icon_name().c_str());
|
2007-06-18 18:18:35 +04:00
|
|
|
is.icon = mt.icon_name();
|
2007-05-25 21:45:17 +04:00
|
|
|
// icon label is name of file
|
|
|
|
is.name = name;
|
|
|
|
is.type = ICON_FILE;
|
|
|
|
|
|
|
|
can_add = true;
|
|
|
|
} else {
|
|
|
|
EDEBUG(ESTRLOC ": Failed mime-type for %s, ignoring...\n", name);
|
|
|
|
can_add = false;
|
|
|
|
}
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
if(can_add) {
|
|
|
|
is.key_name = name;
|
|
|
|
// random_pos() is used if X/Y keys are not found
|
|
|
|
conf.get(name, "X", icon_x, random_pos(w() - 10));
|
|
|
|
conf.get(name, "Y", icon_y, random_pos(h() - 10));
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
EDEBUG(ESTRLOC ": %s found with: %i %i\n", name, icon_x, icon_y);
|
|
|
|
is.x = icon_x;
|
|
|
|
is.y = icon_y;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
DesktopIcon* dic = new DesktopIcon(&gisett, &is, dsett->color);
|
2007-05-25 21:45:17 +04:00
|
|
|
add_icon(dic);
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
// read .desktop files
|
2007-05-25 21:45:17 +04:00
|
|
|
bool Desktop::read_desktop_file(const char* path, IconSettings& is) {
|
2007-05-22 18:53:17 +04:00
|
|
|
EASSERT(path != NULL);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
if(!edelib::file_exists(path)) {
|
|
|
|
EDEBUG(ESTRLOC ": %s don't exists\n");
|
|
|
|
return false;
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
edelib::DesktopFile dconf;
|
2007-05-22 18:53:17 +04:00
|
|
|
if(!dconf.load(path)) {
|
2007-06-25 13:20:49 +04:00
|
|
|
EWARNING(ESTRLOC ": Can't read %s\n", path);
|
2007-05-22 18:53:17 +04:00
|
|
|
return false;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
char buff[128];
|
|
|
|
int buffsz = sizeof(buff);
|
|
|
|
|
|
|
|
/*
|
2007-06-25 13:20:49 +04:00
|
|
|
* Check for 'EmptyIcon' key since via it is determined
|
2007-05-22 18:53:17 +04:00
|
|
|
* is icon trash type or not (in case of trash, 'Icon' key is used for full trash).
|
|
|
|
* FIXME: any other way to check for trash icons ???
|
|
|
|
*/
|
|
|
|
if(dconf.get("Desktop Entry", "EmptyIcon", buff, buffsz)) {
|
2007-05-25 21:45:17 +04:00
|
|
|
is.type = ICON_TRASH;
|
2007-05-22 18:53:17 +04:00
|
|
|
is.icon = buff;
|
2007-05-24 16:53:03 +04:00
|
|
|
} else
|
2007-05-25 21:45:17 +04:00
|
|
|
is.type = ICON_NORMAL;
|
2007-06-25 13:20:49 +04:00
|
|
|
|
|
|
|
if(!dconf.icon(buff, buffsz)) {
|
|
|
|
EWARNING(ESTRLOC ": No Icon key, balling out\n");
|
2007-05-22 18:53:17 +04:00
|
|
|
return false;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-25 21:45:17 +04:00
|
|
|
if(is.type == ICON_TRASH)
|
2007-05-22 18:53:17 +04:00
|
|
|
is.icon2 = buff;
|
2007-06-25 13:20:49 +04:00
|
|
|
else
|
2007-05-22 18:53:17 +04:00
|
|
|
is.icon = buff;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
edelib::DesktopFileType dtype = dconf.type();
|
|
|
|
if(dtype == edelib::DESK_FILE_TYPE_LINK) {
|
2007-05-22 18:53:17 +04:00
|
|
|
is.cmd_is_url = true;
|
2007-06-25 13:20:49 +04:00
|
|
|
dconf.url(buff, buffsz);
|
|
|
|
}
|
|
|
|
else {
|
2007-05-22 18:53:17 +04:00
|
|
|
is.cmd_is_url = false;
|
2007-06-25 13:20:49 +04:00
|
|
|
dconf.exec(buff, buffsz);
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
is.cmd = buff;
|
|
|
|
|
|
|
|
if(!dconf.name(buff, buffsz)) {
|
|
|
|
EDEBUG(ESTRLOC ": No Name key\n");
|
|
|
|
is.name = "(none)";
|
|
|
|
} else
|
|
|
|
is.name = buff;
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
return true;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
void Desktop::add_icon(DesktopIcon* ic) {
|
|
|
|
EASSERT(ic != NULL);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
icons.push_back(ic);
|
2007-06-18 18:18:35 +04:00
|
|
|
add((Fl_Widget*)ic);
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
void Desktop::unfocus_all(void) {
|
2007-05-22 18:53:17 +04:00
|
|
|
unsigned int sz = icons.size();
|
2007-06-18 18:18:35 +04:00
|
|
|
DesktopIcon* ic;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
for(unsigned int i = 0; i < sz; i++) {
|
2007-06-18 18:18:35 +04:00
|
|
|
ic = icons[i];
|
|
|
|
if(ic->is_focused()) {
|
|
|
|
ic->do_unfocus();
|
|
|
|
ic->fast_redraw();
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
void Desktop::select(DesktopIcon* ic, bool do_redraw) {
|
2007-05-22 18:53:17 +04:00
|
|
|
EASSERT(ic != NULL);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
if(in_selection(ic))
|
|
|
|
return;
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
selectionbuff.push_back(ic);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
if(!ic->is_focused()) {
|
|
|
|
ic->do_focus();
|
2007-07-02 14:28:18 +04:00
|
|
|
|
|
|
|
if(do_redraw)
|
|
|
|
ic->fast_redraw();
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
2007-05-23 16:43:50 +04:00
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
void Desktop::select_only(DesktopIcon* ic) {
|
2007-05-22 18:53:17 +04:00
|
|
|
EASSERT(ic != NULL);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
unfocus_all();
|
|
|
|
selectionbuff.clear();
|
|
|
|
selectionbuff.push_back(ic);
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
ic->do_focus();
|
2007-06-18 18:18:35 +04:00
|
|
|
ic->fast_redraw();
|
|
|
|
}
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
bool Desktop::in_selection(const DesktopIcon* ic) {
|
|
|
|
EASSERT(ic != NULL);
|
|
|
|
|
|
|
|
unsigned int sz = selectionbuff.size();
|
|
|
|
for(unsigned int i = 0; i < sz; i++) {
|
|
|
|
if(ic == selectionbuff[i])
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
void Desktop::move_selection(int x, int y, bool apply) {
|
|
|
|
unsigned int sz = selectionbuff.size();
|
|
|
|
if(sz == 0)
|
2007-05-23 16:43:50 +04:00
|
|
|
return;
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
int prev_x, prev_y, tmp_x, tmp_y;
|
|
|
|
DesktopIcon* ic;
|
2007-05-23 16:43:50 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
for(unsigned int i = 0; i < sz; i++) {
|
|
|
|
ic = selectionbuff[i];
|
2007-05-23 16:43:50 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
prev_x = ic->drag_icon_x();
|
|
|
|
prev_y = ic->drag_icon_y();
|
2007-05-23 16:43:50 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
tmp_x = x - selection_x;
|
|
|
|
tmp_y = y - selection_y;
|
2007-05-23 16:43:50 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
ic->drag(prev_x + tmp_x, prev_y + tmp_y, apply);
|
2007-05-23 16:43:50 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
// very slow if not checked
|
2007-07-02 14:28:18 +04:00
|
|
|
//if(apply == true)
|
|
|
|
// ic->fast_redraw();
|
2007-05-23 16:43:50 +04:00
|
|
|
}
|
2007-06-18 18:18:35 +04:00
|
|
|
|
|
|
|
selection_x = x;
|
|
|
|
selection_y = y;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Redraw whole screen so it reflects
|
|
|
|
* new icon position
|
|
|
|
*/
|
|
|
|
if(apply)
|
|
|
|
redraw();
|
2007-05-23 16:43:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-06-18 18:18:35 +04:00
|
|
|
* Tries to figure out icon below mouse. It is alternative to
|
|
|
|
* Fl::belowmouse() since with this we hunt only icons, not other
|
|
|
|
* childs (wallpaper, menu), which can be returned by Fl::belowmouse()
|
|
|
|
* and bad things be hapened.
|
2007-05-23 16:43:50 +04:00
|
|
|
*/
|
|
|
|
DesktopIcon* Desktop::below_mouse(int px, int py) {
|
|
|
|
unsigned int sz = icons.size();
|
|
|
|
|
|
|
|
DesktopIcon* ic = NULL;
|
|
|
|
for(unsigned int i = 0; i < sz; i++) {
|
|
|
|
ic = icons[i];
|
|
|
|
if(ic->x() < px && ic->y() < py && px < (ic->x() + ic->h()) && py < (ic->y() + ic->h()))
|
|
|
|
return ic;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-05-24 16:53:03 +04:00
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
void Desktop::select_in_area(void) {
|
|
|
|
if(!selbox->show)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int ax = selbox->x;
|
|
|
|
int ay = selbox->y;
|
|
|
|
int aw = selbox->w;
|
|
|
|
int ah = selbox->h;
|
|
|
|
|
|
|
|
if(aw < 0) {
|
|
|
|
ax += aw;
|
|
|
|
aw = -aw;
|
|
|
|
} else if(!aw)
|
|
|
|
aw = 1;
|
|
|
|
|
|
|
|
if(ah < 0) {
|
|
|
|
ay += ah;
|
|
|
|
ah = -ah;
|
|
|
|
} else if(!ah)
|
|
|
|
ah = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: This function can fail since icon coordinates are absolute (event_x_root)
|
|
|
|
* but selbox use relative (event_root). It will work as expected if desktop is at x=0 y=0.
|
|
|
|
* This should be checked further.
|
|
|
|
*/
|
|
|
|
unsigned int sz = icons.size();
|
|
|
|
DesktopIcon* ic = NULL;
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < sz; i++) {
|
|
|
|
ic = icons[i];
|
|
|
|
EASSERT(ic != NULL && "Impossible to happen");
|
|
|
|
|
|
|
|
if(intersects(ax, ay, ax+aw, ay+ah, ic->x(), ic->y(), ic->w()+ic->x(), ic->h()+ic->y())) {
|
|
|
|
if(!ic->is_focused()) {
|
|
|
|
ic->do_focus();
|
2007-06-26 20:33:25 +04:00
|
|
|
// updated from Desktop::draw()
|
|
|
|
ic->damage(EDAMAGE_CHILD_LABEL);
|
2007-06-25 13:20:49 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(ic->is_focused()) {
|
|
|
|
ic->do_unfocus();
|
2007-06-26 20:33:25 +04:00
|
|
|
// updated from Desktop::draw()
|
2007-07-02 14:28:18 +04:00
|
|
|
ic->fast_redraw();
|
|
|
|
//ic->damage(EDAMAGE_CHILD_LABEL);
|
|
|
|
//ic->redraw();
|
|
|
|
//ic->damage(EDAMAGE_CHILD_LABEL);
|
2007-06-25 13:20:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
void Desktop::notify_box(const char* msg, bool copy) {
|
|
|
|
if(!msg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(copy)
|
|
|
|
notify->copy_label(msg);
|
|
|
|
else
|
|
|
|
notify->label(msg);
|
|
|
|
|
2007-06-28 15:21:24 +04:00
|
|
|
if(!notify->shown())
|
|
|
|
notify->show();
|
2007-06-18 20:46:27 +04:00
|
|
|
}
|
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
void Desktop::notify_box_color(Fl_Color col) {
|
|
|
|
notify->color(col);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Desktop::notify_desktop_changed(void) {
|
|
|
|
int num = net_get_current_desktop();
|
|
|
|
if(num == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
char** names;
|
|
|
|
int ret = net_get_workspace_names(names);
|
|
|
|
if(num >= ret) {
|
|
|
|
XFreeStringList(names);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
notify_box(names[num], true);
|
|
|
|
XFreeStringList(names);
|
|
|
|
}
|
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
void Desktop::drop_source(const char* src, int src_len, int x, int y) {
|
2007-06-23 15:31:36 +04:00
|
|
|
if(!src)
|
|
|
|
return;
|
2007-07-02 14:28:18 +04:00
|
|
|
|
|
|
|
if(src_len < 1)
|
|
|
|
return;
|
|
|
|
|
2007-07-30 16:46:37 +04:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Commented for now since is_utf16() does not works as expected;
|
|
|
|
* on other hand, UTF-16 conversion is fine
|
|
|
|
*/
|
|
|
|
if(is_utf16((unsigned short*)src, src_len)) {
|
|
|
|
char* utf_src = new char[src_len * 5];
|
|
|
|
if(utf16_to_utf8_str((unsigned short*)src, src_len, utf_src)) {
|
|
|
|
utf_src[src_len] = '\0';
|
|
|
|
EDEBUG(ESTRLOC ":==========> %s|\n", utf_src);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] utf_src;
|
|
|
|
}
|
|
|
|
#endif
|
2007-07-02 14:28:18 +04:00
|
|
|
char* src_copy = new char[src_len + 1];
|
|
|
|
int real_len = 0;
|
|
|
|
|
2007-07-30 16:46:37 +04:00
|
|
|
// mozilla sends UTF-16 form; for now use this hack untill Utf8.cpp code is ready
|
2007-07-02 14:28:18 +04:00
|
|
|
for(int i = 0, j = 0; i < src_len; i++) {
|
|
|
|
if(src[i] != 0) {
|
|
|
|
src_copy[j++] = src[i];
|
|
|
|
real_len++;
|
|
|
|
}
|
2007-06-25 13:20:49 +04:00
|
|
|
}
|
2007-07-02 14:28:18 +04:00
|
|
|
src_copy[real_len] = '\0';
|
2007-06-25 13:20:49 +04:00
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
if(real_len < 1) {
|
|
|
|
delete [] src_copy;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-25 13:20:49 +04:00
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
EDEBUG(ESTRLOC ": DND on Desktop, got: %s\n", src_copy);
|
2007-06-25 13:20:49 +04:00
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
// valid url's (if got) ends with \r\n, clean that
|
|
|
|
char* pp = strstr(src_copy, "\r\n");
|
|
|
|
if(pp)
|
|
|
|
*pp = '\0';
|
|
|
|
|
|
|
|
char* sptr = 0;
|
|
|
|
if((real_len > 7) && (strncmp(src_copy, "file://", 7) == 0))
|
|
|
|
sptr = src_copy + 7;
|
|
|
|
else
|
|
|
|
sptr = src_copy;
|
|
|
|
|
|
|
|
if(!edelib::file_exists(sptr) && !edelib::dir_exists(sptr)) {
|
|
|
|
fl_message("Droping file content is not implemented yet. Soon, soon... :)");
|
|
|
|
delete [] src_copy;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-25 13:20:49 +04:00
|
|
|
|
2007-06-23 15:31:36 +04:00
|
|
|
IconSettings is;
|
|
|
|
is.x = x;
|
|
|
|
is.y = y;
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
bool is_read = false;
|
2007-06-23 15:31:36 +04:00
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
if(edelib::str_ends(src_copy, ".desktop")) {
|
|
|
|
edelib::DesktopFile dconf;
|
2007-06-23 15:31:36 +04:00
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
edelib::String path = sptr;
|
|
|
|
edelib::DesktopFile dfile;
|
|
|
|
|
|
|
|
if(dfile.load(path.c_str())) {
|
|
|
|
char buff[256];
|
|
|
|
if(dfile.type() == edelib::DESK_FILE_TYPE_LINK) {
|
|
|
|
dfile.url(buff, 256);
|
|
|
|
is.cmd_is_url = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dfile.exec(buff, 256);
|
|
|
|
is.cmd_is_url = false;
|
|
|
|
}
|
|
|
|
is.cmd = buff;
|
|
|
|
is.type = ICON_NORMAL;
|
|
|
|
|
|
|
|
dfile.name(buff, 256);
|
|
|
|
is.name = buff;
|
|
|
|
dfile.icon(buff, 256);
|
|
|
|
is.icon = buff;
|
|
|
|
|
|
|
|
is_read = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!is_read) {
|
|
|
|
// absolute path is (for now) seen as non-url
|
|
|
|
if(sptr[0] == '/')
|
|
|
|
is.cmd_is_url = false;
|
|
|
|
else
|
|
|
|
is.cmd_is_url = true;
|
|
|
|
|
|
|
|
is.cmd = "(none)";
|
|
|
|
is.type = ICON_NORMAL;
|
|
|
|
|
|
|
|
edelib::MimeType mt;
|
|
|
|
if(!mt.set(sptr)) {
|
|
|
|
EWARNING(ESTRLOC ": MimeType for %s (%s) failed, not dropping icon\n", sptr, src_copy);
|
|
|
|
delete [] src_copy;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
is.name = get_basename(sptr);
|
|
|
|
is.icon = mt.icon_name();
|
2007-06-23 15:31:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopIcon* dic = new DesktopIcon(&gisett, &is, color());
|
|
|
|
add_icon(dic);
|
2007-07-02 14:28:18 +04:00
|
|
|
|
|
|
|
delete [] src_copy;
|
|
|
|
|
|
|
|
redraw();
|
2007-06-23 15:31:36 +04:00
|
|
|
}
|
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
void Desktop::draw(void) {
|
2007-07-02 14:28:18 +04:00
|
|
|
if(!damage())
|
|
|
|
return;
|
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
if(damage() & (FL_DAMAGE_ALL | FL_DAMAGE_EXPOSE)) {
|
2007-06-26 20:33:25 +04:00
|
|
|
/*
|
|
|
|
* If any overlay was previously visible during full
|
|
|
|
* redraw, it will not be cleared because of fast flip.
|
|
|
|
* This will assure that does not happened.
|
|
|
|
*/
|
|
|
|
clear_xoverlay();
|
|
|
|
|
|
|
|
DESKTOP_WINDOW::draw();
|
2007-07-02 14:28:18 +04:00
|
|
|
EDEBUG(ESTRLOC ": REDRAW ALL\n");
|
2007-06-25 13:20:49 +04:00
|
|
|
}
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
if(damage() & EDAMAGE_OVERLAY) {
|
|
|
|
if(selbox->show)
|
2007-06-25 13:20:49 +04:00
|
|
|
draw_xoverlay(selbox->x, selbox->y, selbox->w, selbox->h);
|
2007-07-02 14:28:18 +04:00
|
|
|
else
|
2007-06-26 20:33:25 +04:00
|
|
|
clear_xoverlay();
|
2007-06-25 13:20:49 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now scan all icons and see if they needs redraw, and if do
|
|
|
|
* just update their label since it is indicator of selection
|
|
|
|
*/
|
|
|
|
for(int i = 0; i < children(); i++) {
|
2007-07-02 14:28:18 +04:00
|
|
|
if(child(i)->damage() == EDAMAGE_CHILD_LABEL) {
|
2007-06-25 13:20:49 +04:00
|
|
|
update_child(*child(i));
|
2007-07-02 14:28:18 +04:00
|
|
|
child(i)->clear_damage();
|
|
|
|
EDEBUG(ESTRLOC ": ICON REDRAW \n");
|
|
|
|
}
|
2007-06-25 13:20:49 +04:00
|
|
|
}
|
|
|
|
}
|
2007-07-02 14:28:18 +04:00
|
|
|
|
|
|
|
clear_damage();
|
2007-06-25 13:20:49 +04:00
|
|
|
}
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
int Desktop::handle(int event) {
|
|
|
|
switch(event) {
|
2007-06-18 18:18:35 +04:00
|
|
|
case FL_FOCUS:
|
|
|
|
case FL_UNFOCUS:
|
2007-06-19 14:10:42 +04:00
|
|
|
case FL_SHORTCUT:
|
2007-05-23 16:43:50 +04:00
|
|
|
return 1;
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
case FL_PUSH: {
|
2007-05-22 18:53:17 +04:00
|
|
|
/*
|
|
|
|
* First check where we clicked. If we do it on desktop
|
|
|
|
* unfocus any possible focused childs, and handle
|
|
|
|
* specific clicks. Otherwise, do rest for childs.
|
|
|
|
*/
|
2007-06-18 18:18:35 +04:00
|
|
|
Fl_Widget* clicked = Fl::belowmouse();
|
|
|
|
|
|
|
|
if(NOT_SELECTABLE(clicked)) {
|
2007-05-22 18:53:17 +04:00
|
|
|
EDEBUG(ESTRLOC ": DESKTOP CLICK !!!\n");
|
2007-06-18 18:18:35 +04:00
|
|
|
if(!selectionbuff.empty()) {
|
|
|
|
/*
|
2007-06-25 13:20:49 +04:00
|
|
|
* Only focused are in selectionbuff, so this is
|
|
|
|
* fine to do; also will prevent full redraw when is clicked on desktop
|
2007-06-18 18:18:35 +04:00
|
|
|
*/
|
|
|
|
unfocus_all();
|
2007-05-22 18:53:17 +04:00
|
|
|
selectionbuff.clear();
|
|
|
|
}
|
2007-06-25 13:20:49 +04:00
|
|
|
|
|
|
|
// track position so moving can be deduced
|
|
|
|
if(Fl::event_button() == 1) {
|
|
|
|
selbox->x = Fl::event_x();
|
|
|
|
selbox->y = Fl::event_y();
|
2007-07-02 14:28:18 +04:00
|
|
|
} else if(Fl::event_button() == 3) {
|
|
|
|
dmenu->menu()->popup(Fl::event_x(), Fl::event_y());
|
2007-06-25 13:20:49 +04:00
|
|
|
}
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2007-05-24 16:53:03 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
// 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
|
|
|
|
*/
|
|
|
|
if(!tmp_icon)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if(SELECTION_MULTI) {
|
2007-06-18 18:18:35 +04:00
|
|
|
Fl::event_is_click(0);
|
2007-05-22 18:53:17 +04:00
|
|
|
select(tmp_icon);
|
|
|
|
return 1;
|
2007-06-18 18:18:35 +04:00
|
|
|
} else if(SELECTION_SINGLE) {
|
2007-06-18 20:46:27 +04:00
|
|
|
if(!in_selection(tmp_icon)) {
|
2007-06-19 13:59:15 +04:00
|
|
|
/*
|
2007-06-25 13:20:49 +04:00
|
|
|
* for testing:
|
2007-06-19 13:59:15 +04:00
|
|
|
* notify_box(tmp_icon->label());
|
|
|
|
*/
|
2007-05-22 18:53:17 +04:00
|
|
|
select_only(tmp_icon);
|
2007-06-18 20:46:27 +04:00
|
|
|
}
|
|
|
|
} else if(Fl::event_button() == 3) {
|
2007-05-22 18:53:17 +04:00
|
|
|
select_only(tmp_icon);
|
2007-06-19 13:59:15 +04:00
|
|
|
/*
|
2007-06-25 13:20:49 +04:00
|
|
|
* for testing:
|
2007-06-19 13:59:15 +04:00
|
|
|
* notify_box(tmp_icon->label());
|
|
|
|
*/
|
2007-06-18 20:46:27 +04:00
|
|
|
}
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Let child handle the rest.
|
|
|
|
* Also prevent click on other mouse buttons during move.
|
|
|
|
*/
|
|
|
|
if(!moving)
|
2007-06-18 18:18:35 +04:00
|
|
|
tmp_icon->handle(FL_PUSH);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
EDEBUG(ESTRLOC ": FL_PUSH from desktop\n");
|
|
|
|
selection_x = Fl::event_x_root();
|
|
|
|
selection_y = Fl::event_y_root();
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
case FL_DRAG:
|
2007-05-22 18:53:17 +04:00
|
|
|
moving = true;
|
|
|
|
if(!selectionbuff.empty()) {
|
|
|
|
EDEBUG(ESTRLOC ": DRAG icon from desktop\n");
|
2007-06-18 18:18:35 +04:00
|
|
|
move_selection(Fl::event_x_root(), Fl::event_y_root(), false);
|
2007-05-22 18:53:17 +04:00
|
|
|
} else {
|
|
|
|
EDEBUG(ESTRLOC ": DRAG from desktop\n");
|
2007-06-25 13:20:49 +04:00
|
|
|
/*
|
|
|
|
* Moving is started with pushed button.
|
|
|
|
* From this point selection box is created and is rolled until release
|
|
|
|
*/
|
|
|
|
if(selbox->x != 0 || selbox->y != 0) {
|
|
|
|
selbox->w = Fl::event_x() - selbox->x;
|
|
|
|
selbox->h = Fl::event_y() - selbox->y;
|
|
|
|
|
|
|
|
selbox->show = true;
|
|
|
|
|
|
|
|
// see if there some icons inside selection area
|
|
|
|
select_in_area();
|
|
|
|
|
|
|
|
// redraw selection box
|
|
|
|
damage(EDAMAGE_OVERLAY);
|
|
|
|
}
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
2007-06-18 18:18:35 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
return 1;
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
case FL_RELEASE:
|
2007-05-22 18:53:17 +04:00
|
|
|
EDEBUG(ESTRLOC ": RELEASE from desktop\n");
|
2007-06-18 18:18:35 +04:00
|
|
|
EDEBUG(ESTRLOC ": clicks: %i\n", Fl::event_is_click());
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-25 13:20:49 +04:00
|
|
|
if(selbox->show) {
|
|
|
|
selbox->x = selbox->y = selbox->w = selbox->h = 0;
|
|
|
|
selbox->show = false;
|
|
|
|
damage(EDAMAGE_OVERLAY);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now pickup those who are in is_focused() state.
|
|
|
|
*
|
|
|
|
* Possible flickers due overlay will be later removed when is
|
|
|
|
* called move_selection(), which will in turn redraw icons again
|
|
|
|
* after position them.
|
|
|
|
*/
|
|
|
|
if(!selectionbuff.empty())
|
|
|
|
selectionbuff.clear();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < icons.size(); i++) {
|
|
|
|
if(icons[i]->is_focused())
|
2007-07-02 14:28:18 +04:00
|
|
|
select(icons[i], false);
|
2007-06-25 13:20:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-05-24 16:53:03 +04:00
|
|
|
if(!selectionbuff.empty() && moving)
|
2007-06-18 18:18:35 +04:00
|
|
|
move_selection(Fl::event_x_root(), Fl::event_y_root(), true);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
/*
|
2007-06-18 18:18:35 +04:00
|
|
|
* Do not send FL_RELEASE during move
|
2007-05-22 18:53:17 +04:00
|
|
|
*
|
2007-06-18 18:18:35 +04:00
|
|
|
* TODO: should be alowed FL_RELEASE to multiple icons? (aka. run
|
2007-05-22 18:53:17 +04:00
|
|
|
* command for all selected icons ?
|
|
|
|
*/
|
|
|
|
if(selectionbuff.size() == 1 && !moving)
|
2007-06-18 18:18:35 +04:00
|
|
|
selectionbuff[0]->handle(FL_RELEASE);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
moving = false;
|
|
|
|
return 1;
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2007-06-23 15:31:36 +04:00
|
|
|
case FL_DND_ENTER:
|
|
|
|
case FL_DND_DRAG:
|
|
|
|
case FL_DND_LEAVE:
|
|
|
|
return 1;
|
2007-07-02 14:28:18 +04:00
|
|
|
|
|
|
|
case FL_DND_RELEASE: {
|
|
|
|
DesktopIcon* di = below_mouse(Fl::event_x(), Fl::event_y());
|
|
|
|
if(di)
|
|
|
|
return di->handle(event);
|
2007-06-23 15:31:36 +04:00
|
|
|
return 1;
|
2007-07-02 14:28:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case FL_PASTE: {
|
|
|
|
DesktopIcon* di = below_mouse(Fl::event_x(), Fl::event_y());
|
|
|
|
if(di)
|
|
|
|
return di->handle(event);
|
2007-06-23 15:31:36 +04:00
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
drop_source(Fl::event_text(), Fl::event_length(), Fl::event_x(), Fl::event_y());
|
2007-06-23 15:31:36 +04:00
|
|
|
return 1;
|
2007-07-02 14:28:18 +04:00
|
|
|
}
|
2007-06-27 18:42:47 +04:00
|
|
|
|
|
|
|
case FL_ENTER:
|
|
|
|
case FL_LEAVE:
|
|
|
|
case FL_MOVE:
|
|
|
|
return DESKTOP_WINDOW::handle(event);
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-08-20 22:43:09 +04:00
|
|
|
|
2007-06-27 18:42:47 +04:00
|
|
|
return 0;
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
int main() {
|
|
|
|
signal(SIGTERM, exit_signal);
|
|
|
|
signal(SIGKILL, exit_signal);
|
2007-06-18 18:18:35 +04:00
|
|
|
signal(SIGINT, exit_signal);
|
|
|
|
signal(SIGHUP, restart_signal);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
srand(time(NULL));
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
// a lot of preparing code depends on this
|
|
|
|
fl_open_display();
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
fl_register_images();
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
edelib::IconTheme::init("edeneu");
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-05-24 16:53:03 +04:00
|
|
|
Desktop::init();
|
|
|
|
Desktop::instance()->show();
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XSelectInput will redirect PropertyNotify messages, which
|
2007-06-18 18:18:35 +04:00
|
|
|
* are listened for
|
2007-05-22 18:53:17 +04:00
|
|
|
*/
|
2007-06-19 13:59:15 +04:00
|
|
|
XSelectInput(fl_display, RootWindow(fl_display, fl_screen), PropertyChangeMask | StructureNotifyMask | ClientMessage);
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
Fl::add_handler(desktop_xmessage_handler);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
while(running)
|
2007-06-18 18:18:35 +04:00
|
|
|
Fl::wait();
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-05-24 16:53:03 +04:00
|
|
|
Desktop::shutdown();
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2007-05-24 16:53:03 +04:00
|
|
|
edelib::IconTheme::shutdown();
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
return 0;
|
2006-08-20 22:43:09 +04:00
|
|
|
}
|