Work,work...

This commit is contained in:
Sanel Zukan 2007-05-23 12:43:50 +00:00
parent 5d3300c410
commit 78c471744c
6 changed files with 188 additions and 55 deletions

View File

@ -22,16 +22,8 @@
#include <fltk/draw.h>
#include <fltk/x11.h>
#include <string.h> // strdup
#include <stdlib.h> // free
#define MAX_DESKTOPS 32
void close_cb(fltk::Widget*, void* w) {
DesktopConfig* dc = (DesktopConfig*)w;
EDEBUG("ws: %i\n", net_get_workspace_count());
EDEBUG("cd: %i\n", net_get_current_desktop());
dc->hide();
}
@ -73,12 +65,6 @@ void PreviewBox::draw(void) {
fltk::Image* im = (fltk::Image*)image();
im->draw(ir);
}
/*
if(image()) {
fltk::Image* im = (fltk::Image*)image();
fltk::drawimage(im->buffer(), im->buffer_pixeltype(), fltk::Rectangle(im->width(), im->height()));
}*/
}
DesktopConfig::DesktopConfig() : fltk::Window(540, 265, _("Background settings")) {
@ -103,7 +89,6 @@ DesktopConfig::DesktopConfig() : fltk::Window(540, 265, _("Background settings")
new fltk::Item(_("All desktops"));
//char* names[MAX_DESKTOPS];
char** names;
int nsz = net_get_workspace_names(names);
EDEBUG("nsz: %i\n", nsz);
@ -112,7 +97,6 @@ DesktopConfig::DesktopConfig() : fltk::Window(540, 265, _("Background settings")
for(int i = 0; i < nsz; i++) {
fltk::Item* item = new fltk::Item();
item->copy_label(names[i]);
//free(names[i]);
}
XFreeStringList(names);

View File

@ -17,12 +17,14 @@
#include <edelib/IconTheme.h>
#include <edelib/Nls.h>
#include <edelib/Item.h>
#include <edelib/Ask.h>
#include <fltk/SharedImage.h>
#include <fltk/Color.h>
#include <fltk/Divider.h>
#include <fltk/draw.h>
#include <fltk/events.h>
#include <fltk/damage.h>
#include <fltk/x11.h> // Pixmap
@ -38,14 +40,10 @@
#define OFFSET_W 16
#define OFFSET_H 16
#if 0
inline int calc_pitch(int bytespp, int width) {
if(!bytespp || !width)
return 0;
int p = bytespp * width;
return ((p + 3) & ~3); // word aligning
void icon_delete_cb(fltk::Widget*, void* di) {
DesktopIcon* dicon = (DesktopIcon*)di;
edelib::ask(_("Delete '%s' ?"), dicon->label());
}
#endif
DesktopIcon::DesktopIcon(GlobalIconSettings* gisett, IconSettings* isett, int icon_type) :
fltk::Widget(isett->x, isett->y, ICONSIZE, ICONSIZE), settings(NULL)
@ -124,6 +122,7 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gisett, IconSettings* isett, int ic
it->offset_x(12, 12);
it = new edelib::Item(_("&Delete"));
it->offset_x(12, 12);
it->callback(icon_delete_cb, this);
new fltk::Divider();
it = new edelib::Item(_("&Properties"));
it->offset_x(12, 12);
@ -141,6 +140,9 @@ DesktopIcon::~DesktopIcon()
if(micon)
delete micon;
if(pmenu)
delete pmenu;
}
void DesktopIcon::update_label_size(void) {
@ -191,7 +193,7 @@ int DesktopIcon::drag_icon_y(void) {
}
void DesktopIcon::draw(void) {
if(image()) {
if(image() && (damage() & fltk::DAMAGE_ALL)) {
fltk::Image* ii = (fltk::Image*)image();
int ix = (w()/2) - (ii->w()/2);
/*
@ -206,7 +208,7 @@ void DesktopIcon::draw(void) {
ii->draw(ir);
}
if(globals->label_draw) {
if(globals->label_draw && (damage() & (fltk::DAMAGE_ALL | fltk::DAMAGE_CHILD_LABEL))) {
int X = w()-(w()/2)-(lwidth/2);
int Y = h()+2;
@ -243,18 +245,19 @@ void DesktopIcon::draw(void) {
// revert to default line style
fltk::line_style(0);
}
set_damage(damage() & ~fltk::DAMAGE_CHILD_LABEL);
}
}
int DesktopIcon::handle(int event) {
//EDEBUG("Event %i on child\n", event);
switch(event) {
case fltk::ENTER:
EDEBUG(ESTRLOC ": ENTER\n");
case fltk::FOCUS:
case fltk::UNFOCUS:
return 1;
case fltk::ENTER:
case fltk::LEAVE:
EDEBUG(ESTRLOC ": LEAVE\n");
return 1;
/*
* We have to handle fltk::MOVE too, if
@ -272,8 +275,17 @@ int DesktopIcon::handle(int event) {
EDEBUG(ESTRLOC ": EXECUTE: %s\n", settings->cmd.c_str());
return 1;
case fltk::FOCUS:
case fltk::UNFOCUS:
case fltk::DND_ENTER:
EDEBUG("Icon DND_ENTER\n");
return 1;
case fltk::DND_DRAG:
EDEBUG("Icon DND_DRAG\n");
return 1;
case fltk::DND_LEAVE:
EDEBUG("Icon DND_LEAVE\n");
return 1;
case fltk::DND_RELEASE:
EDEBUG("Icon DND_RELEASE\n");
return 1;
}
@ -286,15 +298,9 @@ MovableIcon::MovableIcon(DesktopIcon* ic) : fltk::Window(ic->x(), ic->y(), ic->w
set_override();
create();
fltk::Image* img = icon->icon_image();
if(img)
image(img);
/*
* Disabled until icon -> icon mask conversion be finished
*/
#if 0
if(img) {
#ifdef SHAPE
@ -310,4 +316,3 @@ MovableIcon::MovableIcon(DesktopIcon* ic) : fltk::Window(ic->x(), ic->y(), ic->w
MovableIcon::~MovableIcon()
{
}

View File

@ -64,6 +64,7 @@ class DesktopIcon : public fltk::Widget {
fltk::Image* icon_image(void) { return (fltk::Image*)image(); }
};
class MovableIcon : public fltk::Window {
private:
DesktopIcon* icon;

View File

@ -10,7 +10,7 @@
Label Foreground=7
Gridspacing=10
OneClickExec=0
Label Transparent=0
Label Transparent=True
Label Background=216
AutoArrange=0
Label Maxwidth=55

View File

@ -38,7 +38,6 @@
#include <stdlib.h> // rand, srand
#include <time.h> // time
/*
* NOTE: DO NOT set 'using namespace fltk' here
* since fltk::Window will collide with Window from X11
@ -54,12 +53,26 @@
(fltk::get_key_state(fltk::LeftShiftKey) ||\
fltk::get_key_state(fltk::RightShiftKey)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
/*
* Added since fltk DAMAGE_OVERLAY value is used in few different contexts
* and re-using it will do nothing. Yuck!
*/
#define EDAMAGE_OVERLAY 2
bool running = true;
inline unsigned int random_pos(int max) {
return (rand() % max);
}
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));
}
inline void dpy_sizes(int& width, int& height) {
fltk::open_display();
width = DisplayWidth(fltk::xdisplay, fltk::xscreen);
@ -162,7 +175,6 @@ void Desktop::update_workarea(void) {
int X,Y,W,H;
if(net_get_workarea(X, Y, W, H))
resize(X,Y,W,H);
EDEBUG(ESTRLOC ": area: %i %i %i %i\n", X,Y,W,H);
}
void Desktop::read_config(void) {
@ -417,8 +429,9 @@ void Desktop::unfocus_all(void) {
}
bool Desktop::in_selection(const DesktopIcon* ic) {
unsigned int sz = selectionbuff.size();
EASSERT(ic != NULL);
unsigned int sz = selectionbuff.size();
for(unsigned int i = 0; i < sz; i++) {
if(ic == selectionbuff[i])
return true;
@ -438,8 +451,17 @@ void Desktop::select(DesktopIcon* ic) {
if(!ic->is_focused()) {
ic->do_focus();
ic->redraw();
redraw();
}
redraw();
}
void Desktop::select_noredraw(DesktopIcon* ic) {
EASSERT(ic != NULL);
if(in_selection(ic))
return;
selectionbuff.push_back(ic);
}
void Desktop::select_only(DesktopIcon* ic) {
@ -456,20 +478,98 @@ void Desktop::select_only(DesktopIcon* ic) {
redraw();
}
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();
ic->redraw();
}
} else {
if(ic->is_focused()) {
ic->do_unfocus();
ic->redraw();
}
}
}
}
/*
* Tries to figure out icon below mouse (used for DND)
* If fails, return NULL
*/
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;
}
void Desktop::draw(void) {
if(damage() & fltk::DAMAGE_ALL)
fltk::Window::draw();
if(damage() & (fltk::DAMAGE_ALL|fltk::DAMAGE_VALUE)) {
if(damage() & (fltk::DAMAGE_ALL|EDAMAGE_OVERLAY)) {
clear_xoverlay();
if(selbox->show)
draw_xoverlay(selbox->x, selbox->y, selbox->w, selbox->h);
/*
* 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++) {
if(child(i)->damage() == fltk::DAMAGE_ALL) {
child(i)->set_damage(fltk::DAMAGE_CHILD_LABEL);
update_child(*child(i));
}
}
}
}
int Desktop::handle(int event) {
switch(event) {
case fltk::FOCUS:
case fltk::UNFOCUS:
return 1;
case fltk::PUSH: {
/*
* First check where we clicked. If we do it on desktop
@ -494,7 +594,6 @@ int Desktop::handle(int event) {
selbox->x = fltk::event_x();
selbox->y = fltk::event_y();
}
EDEBUG("overlay: %i %i %i %i\n", selbox->x, selbox->y, selbox->w, selbox->h);
return 1;
}
@ -543,17 +642,23 @@ int Desktop::handle(int event) {
} else {
EDEBUG(ESTRLOC ": DRAG from desktop\n");
// moving is started
/*
* 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 = fltk::event_x() - selbox->x;
selbox->h = fltk::event_y() - selbox->y;
selbox->show = true;
redraw(fltk::DAMAGE_VALUE);
// see if there some icons inside selection area
select_in_area();
// redraw selection box
redraw(EDAMAGE_OVERLAY);
}
}
return 1;
case fltk::RELEASE:
@ -561,10 +666,25 @@ int Desktop::handle(int event) {
EDEBUG(ESTRLOC ": clicks: %i\n", fltk::event_is_click());
if(selbox->show) {
EDEBUG("overlay: %i %i %i %i\n", selbox->x, selbox->y, selbox->w, selbox->h);
selbox->w = selbox->h = 0;
selbox->show = false;
redraw(fltk::DAMAGE_VALUE);
redraw(EDAMAGE_OVERLAY);
/*
* Now pickup those who are in is_focused() state.
* Here is not used select() since it will fill selectionbuff with
* redrawing whole window each time. This is not what we want.
*
* 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())
select_noredraw(icons[i]);
}
return 1;
}
@ -588,9 +708,27 @@ int Desktop::handle(int event) {
moving = false;
return 1;
case fltk::FOCUS:
case fltk::UNFOCUS:
case fltk::DND_ENTER:
EDEBUG("DND_ENTER\n");
return 1;
case fltk::DND_DRAG:
EDEBUG("DND_DRAG\n");
return 1;
case fltk::DND_LEAVE:
EDEBUG("DND_LEAVE\n");
return 1;
case fltk::DND_RELEASE: {
// fltk::belowmouse() can't be used within DND context :)
DesktopIcon* di = below_mouse(fltk::event_x_root(), fltk::event_y_root());
if(di) {
di->handle(event);
} else {
EDEBUG("DND on DESKTOP\n");
}
return 1;
}
case fltk::PASTE:
EDEBUG("PASTE on desktop with %s\n", fltk::event_text());
return 1;
default:

View File

@ -93,8 +93,13 @@ class Desktop : public fltk::Window {
void select_only(DesktopIcon* ic);
bool in_selection(const DesktopIcon* ic);
void select_in_area(void);
void select_noredraw(DesktopIcon* ic);
void move_selection(int x, int y, bool apply);
DesktopIcon* below_mouse(int x, int y);
public:
Desktop();
~Desktop();